@smvtech/x-flux 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -5280,12 +5280,12 @@ declare const EDCFlowProvider: react__default.FC<TEDCFlowProviderProps>;
5280
5280
  declare const useEDCFlow: () => TEDCFlowContext;
5281
5281
 
5282
5282
  declare const createAllQuestionsWithAnswers: (questionnaire: TQuestionnaire, answers?: TAnswer[]) => TQuestionWithAnswer[];
5283
- declare const filterConditionalQuestions: (questions: TQuestionWithAnswer[], order: TVisaOrder) => TQuestionWithAnswer[];
5284
- declare const getVisibleQuestions: (questions: TQuestionWithAnswer[], order: TVisaOrder) => TQuestionWithAnswer[];
5283
+ declare const filterConditionalQuestions: (questions: TQuestionWithAnswer[], application: TApplication) => TQuestionWithAnswer[];
5284
+ declare const getVisibleQuestions: (questions: TQuestionWithAnswer[], application: TApplication) => TQuestionWithAnswer[];
5285
5285
  declare const formatTravellerFromResponse: (traveller: TTraveller) => TTraveller;
5286
5286
  declare const formatAnswerFromResponse: (updatedAnswer: TAnswer, orderId: string) => TAnswer;
5287
- declare const updateApplicantWithAnswer: (applicant: TEDCApplicant, question_id: string, answer: TAnswer, questionnaire: TQuestionnaire, order: TVisaOrder) => TEDCApplicant;
5288
- declare const createApplicantData: (traveller: TTraveller, answers: TAnswer[], questionnaire: TQuestionnaire, application: TApplication, order: TVisaOrder) => TEDCApplicant | null;
5287
+ declare const updateApplicantWithAnswer: (applicant: TEDCApplicant, question_id: string, answer: TAnswer, questionnaire: TQuestionnaire) => TEDCApplicant;
5288
+ declare const createApplicantData: (traveller: TTraveller, answers: TAnswer[], questionnaire: TQuestionnaire, application: TApplication) => TEDCApplicant | null;
5289
5289
  declare function getSignedUrlFromAsset(docId: string): Promise<string | null>;
5290
5290
 
5291
5291
  declare const initializeEDCFlow: (config: EDCConfig) => void;
package/dist/index.d.ts CHANGED
@@ -5280,12 +5280,12 @@ declare const EDCFlowProvider: react__default.FC<TEDCFlowProviderProps>;
5280
5280
  declare const useEDCFlow: () => TEDCFlowContext;
5281
5281
 
5282
5282
  declare const createAllQuestionsWithAnswers: (questionnaire: TQuestionnaire, answers?: TAnswer[]) => TQuestionWithAnswer[];
5283
- declare const filterConditionalQuestions: (questions: TQuestionWithAnswer[], order: TVisaOrder) => TQuestionWithAnswer[];
5284
- declare const getVisibleQuestions: (questions: TQuestionWithAnswer[], order: TVisaOrder) => TQuestionWithAnswer[];
5283
+ declare const filterConditionalQuestions: (questions: TQuestionWithAnswer[], application: TApplication) => TQuestionWithAnswer[];
5284
+ declare const getVisibleQuestions: (questions: TQuestionWithAnswer[], application: TApplication) => TQuestionWithAnswer[];
5285
5285
  declare const formatTravellerFromResponse: (traveller: TTraveller) => TTraveller;
5286
5286
  declare const formatAnswerFromResponse: (updatedAnswer: TAnswer, orderId: string) => TAnswer;
5287
- declare const updateApplicantWithAnswer: (applicant: TEDCApplicant, question_id: string, answer: TAnswer, questionnaire: TQuestionnaire, order: TVisaOrder) => TEDCApplicant;
5288
- declare const createApplicantData: (traveller: TTraveller, answers: TAnswer[], questionnaire: TQuestionnaire, application: TApplication, order: TVisaOrder) => TEDCApplicant | null;
5287
+ declare const updateApplicantWithAnswer: (applicant: TEDCApplicant, question_id: string, answer: TAnswer, questionnaire: TQuestionnaire) => TEDCApplicant;
5288
+ declare const createApplicantData: (traveller: TTraveller, answers: TAnswer[], questionnaire: TQuestionnaire, application: TApplication) => TEDCApplicant | null;
5289
5289
  declare function getSignedUrlFromAsset(docId: string): Promise<string | null>;
5290
5290
 
5291
5291
  declare const initializeEDCFlow: (config: EDCConfig) => void;
package/dist/index.js CHANGED
@@ -234,7 +234,7 @@ var createAllQuestionsWithAnswers = (questionnaire, answers = []) => {
234
234
  });
235
235
  return questionsWithAnswers;
236
236
  };
237
- var filterConditionalQuestions = (questions, order) => {
237
+ var filterConditionalQuestions = (questions, application) => {
238
238
  const questionMap = /* @__PURE__ */ new Map();
239
239
  questions.forEach((q) => {
240
240
  questionMap.set(q.id, q);
@@ -245,7 +245,7 @@ var filterConditionalQuestions = (questions, order) => {
245
245
  if (!question) return;
246
246
  const answerValue = question.answer_data?.answer || [];
247
247
  question.question.renders?.forEach((render) => {
248
- if (shouldRenderQuestion(render, answerValue, order)) {
248
+ if (shouldRenderQuestion(render, answerValue, application)) {
249
249
  render.question_ids.forEach((id) => {
250
250
  if (!visibleQuestionIds.has(id)) {
251
251
  visibleQuestionIds.add(id);
@@ -267,29 +267,21 @@ var extractDynamicFieldName = (value) => {
267
267
  const match = value.match(/^\{\{([^}]+)\}\}$/);
268
268
  return match ? match[1].trim() : null;
269
269
  };
270
- var isMinor = (dateOfBirth, travelStartDate) => {
271
- if (!dateOfBirth || !travelStartDate) return false;
272
- let dob;
273
- if (dateOfBirth.includes("/")) {
274
- const [day, month, year] = dateOfBirth.split("/").map(Number);
275
- dob = new Date(year, month - 1, day);
276
- } else {
277
- dob = new Date(dateOfBirth);
278
- }
279
- const travelDate = new Date(travelStartDate);
280
- if (isNaN(dob.getTime()) || isNaN(travelDate.getTime())) return false;
281
- const ageDiff = travelDate.getFullYear() - dob.getFullYear();
282
- const monthDiff = travelDate.getMonth() - dob.getMonth();
283
- const dayDiff = travelDate.getDate() - dob.getDate();
284
- const actualAge = monthDiff < 0 || monthDiff === 0 && dayDiff < 0 ? ageDiff - 1 : ageDiff;
285
- return actualAge < 18;
286
- };
287
- var shouldRenderQuestion = (render, answerValue, order) => {
270
+ var shouldRenderQuestion = (render, answerValue, application) => {
288
271
  const dynamicFieldName = extractDynamicFieldName(render.value);
289
272
  if (dynamicFieldName) {
290
273
  switch (dynamicFieldName) {
291
- case "travel_start_date":
292
- return isMinor(answerValue[0], order.travel_start_date);
274
+ case "minor": {
275
+ const hasMinorTag = application.tags?.includes("MINOR" /* MINOR */) ?? false;
276
+ switch (render.operation) {
277
+ case "eq":
278
+ return hasMinorTag;
279
+ case "neq":
280
+ return !hasMinorTag;
281
+ default:
282
+ return false;
283
+ }
284
+ }
293
285
  default:
294
286
  return false;
295
287
  }
@@ -317,8 +309,8 @@ var shouldRenderQuestion = (render, answerValue, order) => {
317
309
  return false;
318
310
  }
319
311
  };
320
- var getVisibleQuestions = (questions, order) => {
321
- return filterConditionalQuestions(questions, order);
312
+ var getVisibleQuestions = (questions, application) => {
313
+ return filterConditionalQuestions(questions, application);
322
314
  };
323
315
  var formatApplicationFromResponse = (application) => {
324
316
  return {
@@ -366,7 +358,7 @@ var formatAnswerFromResponse = (updatedAnswer, orderId) => {
366
358
  updated_at: updatedAnswer.updated_at
367
359
  };
368
360
  };
369
- var updateApplicantWithAnswer = (applicant, question_id, answer, questionnaire, order) => {
361
+ var updateApplicantWithAnswer = (applicant, question_id, answer, questionnaire) => {
370
362
  const answerMap = /* @__PURE__ */ new Map();
371
363
  applicant.questions.forEach((q) => {
372
364
  if (q.answer_data) {
@@ -376,16 +368,16 @@ var updateApplicantWithAnswer = (applicant, question_id, answer, questionnaire,
376
368
  answerMap.set(question_id, answer);
377
369
  const answers = Array.from(answerMap.values());
378
370
  const questions = createAllQuestionsWithAnswers(questionnaire, answers);
379
- const visibleQuestions = getVisibleQuestions(questions, order);
371
+ const visibleQuestions = getVisibleQuestions(questions, applicant.application);
380
372
  return {
381
373
  ...applicant,
382
374
  questions: visibleQuestions
383
375
  };
384
376
  };
385
- var createApplicantData = (traveller, answers, questionnaire, application, order) => {
377
+ var createApplicantData = (traveller, answers, questionnaire, application) => {
386
378
  if (!questionnaire) return null;
387
379
  const questions = createAllQuestionsWithAnswers(questionnaire, answers);
388
- const visibleQuestions = getVisibleQuestions(questions, order);
380
+ const visibleQuestions = getVisibleQuestions(questions, application);
389
381
  return {
390
382
  application_id: application._id,
391
383
  application,
@@ -400,7 +392,7 @@ var transformApplicationResponse = (response) => {
400
392
  answers: (response.answers || []).map((answer) => formatAnswerFromResponse(answer, response.application.visa_order_id))
401
393
  };
402
394
  };
403
- var createApplicantsFromApplications = (applications, questionnaire, order) => {
395
+ var createApplicantsFromApplications = (applications, questionnaire) => {
404
396
  if (!applications || !Array.isArray(applications)) {
405
397
  return {};
406
398
  }
@@ -410,8 +402,7 @@ var createApplicantsFromApplications = (applications, questionnaire, order) => {
410
402
  applicationData.traveller,
411
403
  applicationData.answers,
412
404
  questionnaire,
413
- applicationData.application,
414
- order
405
+ applicationData.application
415
406
  );
416
407
  if (applicant) {
417
408
  applicants[applicationData.application._id] = applicant;
@@ -688,8 +679,7 @@ var EDCFlowProvider = ({ children, orderId }) => {
688
679
  newApplicant.traveller,
689
680
  newApplicant.answers,
690
681
  questionnaire,
691
- newApplicant.application,
692
- order
682
+ newApplicant.application
693
683
  );
694
684
  if (!applicant) {
695
685
  setError("Failed to create applicant data");
@@ -723,8 +713,7 @@ var EDCFlowProvider = ({ children, orderId }) => {
723
713
  refreshedApplicantData.traveller,
724
714
  refreshedApplicantData.answers,
725
715
  questionnaire,
726
- refreshedApplicantData.application,
727
- order
716
+ refreshedApplicantData.application
728
717
  );
729
718
  if (!applicant) return;
730
719
  setApplicants((prev) => {
@@ -769,8 +758,7 @@ var EDCFlowProvider = ({ children, orderId }) => {
769
758
  currentApplicant,
770
759
  updatedAnswerData.answers.visa_questions_id,
771
760
  updatedAnswerData.answers,
772
- questionnaire,
773
- order
761
+ questionnaire
774
762
  );
775
763
  const updatedApplicants = {
776
764
  ...prev,
@@ -875,8 +863,7 @@ var EDCFlowProvider = ({ children, orderId }) => {
875
863
  if (orderData && questionnaireData && applications) {
876
864
  const applicants2 = createApplicantsFromApplications(
877
865
  applications,
878
- questionnaireData,
879
- orderData
866
+ questionnaireData
880
867
  );
881
868
  const dynamicMap = buildDynamicQuestionMap(questionnaireData);
882
869
  const { updatedQuestionnaire, updatedApplicants } = runApplicantSideEffects(applicants2, questionnaireData, dynamicMap);
package/dist/index.mjs CHANGED
@@ -208,7 +208,7 @@ var createAllQuestionsWithAnswers = (questionnaire, answers = []) => {
208
208
  });
209
209
  return questionsWithAnswers;
210
210
  };
211
- var filterConditionalQuestions = (questions, order) => {
211
+ var filterConditionalQuestions = (questions, application) => {
212
212
  const questionMap = /* @__PURE__ */ new Map();
213
213
  questions.forEach((q) => {
214
214
  questionMap.set(q.id, q);
@@ -219,7 +219,7 @@ var filterConditionalQuestions = (questions, order) => {
219
219
  if (!question) return;
220
220
  const answerValue = question.answer_data?.answer || [];
221
221
  question.question.renders?.forEach((render) => {
222
- if (shouldRenderQuestion(render, answerValue, order)) {
222
+ if (shouldRenderQuestion(render, answerValue, application)) {
223
223
  render.question_ids.forEach((id) => {
224
224
  if (!visibleQuestionIds.has(id)) {
225
225
  visibleQuestionIds.add(id);
@@ -241,29 +241,21 @@ var extractDynamicFieldName = (value) => {
241
241
  const match = value.match(/^\{\{([^}]+)\}\}$/);
242
242
  return match ? match[1].trim() : null;
243
243
  };
244
- var isMinor = (dateOfBirth, travelStartDate) => {
245
- if (!dateOfBirth || !travelStartDate) return false;
246
- let dob;
247
- if (dateOfBirth.includes("/")) {
248
- const [day, month, year] = dateOfBirth.split("/").map(Number);
249
- dob = new Date(year, month - 1, day);
250
- } else {
251
- dob = new Date(dateOfBirth);
252
- }
253
- const travelDate = new Date(travelStartDate);
254
- if (isNaN(dob.getTime()) || isNaN(travelDate.getTime())) return false;
255
- const ageDiff = travelDate.getFullYear() - dob.getFullYear();
256
- const monthDiff = travelDate.getMonth() - dob.getMonth();
257
- const dayDiff = travelDate.getDate() - dob.getDate();
258
- const actualAge = monthDiff < 0 || monthDiff === 0 && dayDiff < 0 ? ageDiff - 1 : ageDiff;
259
- return actualAge < 18;
260
- };
261
- var shouldRenderQuestion = (render, answerValue, order) => {
244
+ var shouldRenderQuestion = (render, answerValue, application) => {
262
245
  const dynamicFieldName = extractDynamicFieldName(render.value);
263
246
  if (dynamicFieldName) {
264
247
  switch (dynamicFieldName) {
265
- case "travel_start_date":
266
- return isMinor(answerValue[0], order.travel_start_date);
248
+ case "minor": {
249
+ const hasMinorTag = application.tags?.includes("MINOR" /* MINOR */) ?? false;
250
+ switch (render.operation) {
251
+ case "eq":
252
+ return hasMinorTag;
253
+ case "neq":
254
+ return !hasMinorTag;
255
+ default:
256
+ return false;
257
+ }
258
+ }
267
259
  default:
268
260
  return false;
269
261
  }
@@ -291,8 +283,8 @@ var shouldRenderQuestion = (render, answerValue, order) => {
291
283
  return false;
292
284
  }
293
285
  };
294
- var getVisibleQuestions = (questions, order) => {
295
- return filterConditionalQuestions(questions, order);
286
+ var getVisibleQuestions = (questions, application) => {
287
+ return filterConditionalQuestions(questions, application);
296
288
  };
297
289
  var formatApplicationFromResponse = (application) => {
298
290
  return {
@@ -340,7 +332,7 @@ var formatAnswerFromResponse = (updatedAnswer, orderId) => {
340
332
  updated_at: updatedAnswer.updated_at
341
333
  };
342
334
  };
343
- var updateApplicantWithAnswer = (applicant, question_id, answer, questionnaire, order) => {
335
+ var updateApplicantWithAnswer = (applicant, question_id, answer, questionnaire) => {
344
336
  const answerMap = /* @__PURE__ */ new Map();
345
337
  applicant.questions.forEach((q) => {
346
338
  if (q.answer_data) {
@@ -350,16 +342,16 @@ var updateApplicantWithAnswer = (applicant, question_id, answer, questionnaire,
350
342
  answerMap.set(question_id, answer);
351
343
  const answers = Array.from(answerMap.values());
352
344
  const questions = createAllQuestionsWithAnswers(questionnaire, answers);
353
- const visibleQuestions = getVisibleQuestions(questions, order);
345
+ const visibleQuestions = getVisibleQuestions(questions, applicant.application);
354
346
  return {
355
347
  ...applicant,
356
348
  questions: visibleQuestions
357
349
  };
358
350
  };
359
- var createApplicantData = (traveller, answers, questionnaire, application, order) => {
351
+ var createApplicantData = (traveller, answers, questionnaire, application) => {
360
352
  if (!questionnaire) return null;
361
353
  const questions = createAllQuestionsWithAnswers(questionnaire, answers);
362
- const visibleQuestions = getVisibleQuestions(questions, order);
354
+ const visibleQuestions = getVisibleQuestions(questions, application);
363
355
  return {
364
356
  application_id: application._id,
365
357
  application,
@@ -374,7 +366,7 @@ var transformApplicationResponse = (response) => {
374
366
  answers: (response.answers || []).map((answer) => formatAnswerFromResponse(answer, response.application.visa_order_id))
375
367
  };
376
368
  };
377
- var createApplicantsFromApplications = (applications, questionnaire, order) => {
369
+ var createApplicantsFromApplications = (applications, questionnaire) => {
378
370
  if (!applications || !Array.isArray(applications)) {
379
371
  return {};
380
372
  }
@@ -384,8 +376,7 @@ var createApplicantsFromApplications = (applications, questionnaire, order) => {
384
376
  applicationData.traveller,
385
377
  applicationData.answers,
386
378
  questionnaire,
387
- applicationData.application,
388
- order
379
+ applicationData.application
389
380
  );
390
381
  if (applicant) {
391
382
  applicants[applicationData.application._id] = applicant;
@@ -662,8 +653,7 @@ var EDCFlowProvider = ({ children, orderId }) => {
662
653
  newApplicant.traveller,
663
654
  newApplicant.answers,
664
655
  questionnaire,
665
- newApplicant.application,
666
- order
656
+ newApplicant.application
667
657
  );
668
658
  if (!applicant) {
669
659
  setError("Failed to create applicant data");
@@ -697,8 +687,7 @@ var EDCFlowProvider = ({ children, orderId }) => {
697
687
  refreshedApplicantData.traveller,
698
688
  refreshedApplicantData.answers,
699
689
  questionnaire,
700
- refreshedApplicantData.application,
701
- order
690
+ refreshedApplicantData.application
702
691
  );
703
692
  if (!applicant) return;
704
693
  setApplicants((prev) => {
@@ -743,8 +732,7 @@ var EDCFlowProvider = ({ children, orderId }) => {
743
732
  currentApplicant,
744
733
  updatedAnswerData.answers.visa_questions_id,
745
734
  updatedAnswerData.answers,
746
- questionnaire,
747
- order
735
+ questionnaire
748
736
  );
749
737
  const updatedApplicants = {
750
738
  ...prev,
@@ -849,8 +837,7 @@ var EDCFlowProvider = ({ children, orderId }) => {
849
837
  if (orderData && questionnaireData && applications) {
850
838
  const applicants2 = createApplicantsFromApplications(
851
839
  applications,
852
- questionnaireData,
853
- orderData
840
+ questionnaireData
854
841
  );
855
842
  const dynamicMap = buildDynamicQuestionMap(questionnaireData);
856
843
  const { updatedQuestionnaire, updatedApplicants } = runApplicantSideEffects(applicants2, questionnaireData, dynamicMap);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smvtech/x-flux",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "x-flux - A powerful React package for managing effective document collection flows, visa questionnaires, travellers, and applications",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",