@oneblink/sdk-core 8.0.0-beta.1 → 8.0.0-beta.2
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/abnService.js.map +1 -1
- package/dist/conditionalLogicService/conditionallyShowElement.js +2 -3
- package/dist/conditionalLogicService/conditionallyShowElement.js.map +1 -1
- package/dist/conditionalLogicService/conditionallyShowOption.js +1 -1
- package/dist/conditionalLogicService/conditionallyShowOption.js.map +1 -1
- package/dist/conditionalLogicService/evaluateConditionalOptionsPredicate.js +1 -1
- package/dist/conditionalLogicService/evaluateConditionalOptionsPredicate.js.map +1 -1
- package/dist/conditionalLogicService/evaluateConditionalPredicate.js +1 -1
- package/dist/conditionalLogicService/evaluateConditionalPredicate.js.map +1 -1
- package/dist/conditionalLogicService/generateFormElementsConditionallyShown.js +3 -4
- package/dist/conditionalLogicService/generateFormElementsConditionallyShown.js.map +1 -1
- package/dist/conditionalLogicService.js +1 -2
- package/dist/conditionalLogicService.js.map +1 -1
- package/dist/fileUploadService.js +1 -2
- package/dist/fileUploadService.js.map +1 -1
- package/dist/form-elements-regex.js +2 -2
- package/dist/form-elements-regex.js.map +1 -1
- package/dist/formElementsService.js +8 -8
- package/dist/formElementsService.js.map +1 -1
- package/dist/freshdeskService.js +3 -3
- package/dist/freshdeskService.js.map +1 -1
- package/dist/index.js +17 -7
- package/dist/index.js.map +1 -1
- package/dist/paymentService.d.ts +3 -1
- package/dist/paymentService.js +2 -2
- package/dist/paymentService.js.map +1 -1
- package/dist/replaceCustomValues.js +4 -5
- package/dist/replaceCustomValues.js.map +1 -1
- package/dist/schedulingService.js +1 -2
- package/dist/schedulingService.js.map +1 -1
- package/dist/sharepointService.js +1 -2
- package/dist/sharepointService.js.map +1 -1
- package/dist/submissionService.js +1 -2
- package/dist/submissionService.js.map +1 -1
- package/dist/typeCastService.js.map +1 -1
- package/dist/userService.js +2 -3
- package/dist/userService.js.map +1 -1
- package/dist/webhookSubscriptionService.js +1 -2
- package/dist/webhookSubscriptionService.js.map +1 -1
- package/package.json +21 -18
package/dist/abnService.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abnService.js","sourceRoot":"","sources":["../src/abnService.ts"],"names":[],"mappings":";;;AAEA,MAAM,eAAe,GAAG,CAAC,EACvB,UAAU,EACV,SAAS,EACT,cAAc,GACsB,EAAE,EAAE;IACxC,IAAI,SAAS,GAAG,EAAE,CAAA;IAClB,mBAAmB;IACnB,IAAI,UAAU;QAAE,SAAS,IAAI,GAAG,UAAU,IAAI,CAAA;IAC9C,oBAAoB;IACpB,IAAI,SAAS;QAAE,SAAS,IAAI,GAAG,SAAS,GAAG,CAAA;IAC3C,qBAAqB;IACrB,IAAI,cAAc;QAAE,SAAS,IAAI,GAAG,cAAc,EAAE,CAAA;IAEpD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAED;;;;;;;;;;;;GAYG;AACI,MAAM,4BAA4B,GAAG,CAC1C,SAAoB,EACA,EAAE;;IACtB,IAAI,SAAS,CAAC,UAAU,CAAC,cAAc,KAAK,KAAK,IAAI,SAAS,CAAC,SAAS,EAAE;
|
|
1
|
+
{"version":3,"file":"abnService.js","sourceRoot":"","sources":["../src/abnService.ts"],"names":[],"mappings":";;;AAEA,MAAM,eAAe,GAAG,CAAC,EACvB,UAAU,EACV,SAAS,EACT,cAAc,GACsB,EAAE,EAAE;IACxC,IAAI,SAAS,GAAG,EAAE,CAAA;IAClB,mBAAmB;IACnB,IAAI,UAAU;QAAE,SAAS,IAAI,GAAG,UAAU,IAAI,CAAA;IAC9C,oBAAoB;IACpB,IAAI,SAAS;QAAE,SAAS,IAAI,GAAG,SAAS,GAAG,CAAA;IAC3C,qBAAqB;IACrB,IAAI,cAAc;QAAE,SAAS,IAAI,GAAG,cAAc,EAAE,CAAA;IAEpD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAED;;;;;;;;;;;;GAYG;AACI,MAAM,4BAA4B,GAA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AE,EAAE,CAAC,GAAG,CAAC,kBAAkB,KAAK,GAAG,CACxC,CAAA;QACD,OAAO,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,eAAe,CAAA;IACrC,CAAC;IACD,OAAO,SAAS,CAAC,GAAG,CAAC,eAAe,CAAA;AACtC,CAAC,CAAA;AAXY,QAAA,yBAAyB,6BAWrC;AAED;;;;;;;;;;;;GAYG;AACI,MAAM,6BAA6B,GAAG,CAAC,SAAoB,EAAU,EAAE;IAC5E,MAAM,SAAS,GAAG,IAAA,iCAAyB,EAAC,SAAS,CAAC,CAAA;IACtD,OAAO,SAAS,IAAI,oBAAoB,CAAA;AAC1C,CAAC,CAAA;AAHY,QAAA,6BAA6B,iCAGzC","sourcesContent":["import { ABNRecord } from '@oneblink/types/typescript/misc'\n\nconst createLegalName = ({\n familyName,\n givenName,\n otherGivenName,\n}: NonNullable<ABNRecord['legalName']>) => {\n let legalName = ''\n // Concat last name\n if (familyName) legalName += `${familyName}, `\n // Concat first name\n if (givenName) legalName += `${givenName} `\n // Concat middle name\n if (otherGivenName) legalName += `${otherGivenName}`\n\n return legalName\n}\n\n/**\n * Attempts to get the most relevant business name from the data returned in an\n * `ABNRecord`. Will return `undefined` if a suitable name is not found.\n *\n * #### Example\n *\n * ```js\n * const businessName = abnService.getBusinessNameFromABNRecord(abnRecord)\n * ```\n *\n * @param abnRecord\n * @returns\n */\nexport const getBusinessNameFromABNRecord = (\n abnRecord: ABNRecord,\n): string | undefined => {\n if (abnRecord.entityType.entityTypeCode === 'IND' && abnRecord.legalName) {\n const legalName = createLegalName(abnRecord.legalName)\n if (legalName) return legalName.trim()\n }\n\n if (abnRecord.mainName?.organisationName) {\n return abnRecord.mainName.organisationName\n }\n if (abnRecord.mainTradingName?.organisationName) {\n return abnRecord.mainTradingName.organisationName\n }\n if (abnRecord.legalName) {\n const legalName = createLegalName(abnRecord.legalName)\n if (legalName) return legalName.trim()\n }\n}\n\n/**\n * Get the most relevant business name from the data returned in an `ABNRecord`.\n * Will return \"Unknown Business Name\" if a suitable name is not found.\n *\n * #### Example\n *\n * ```js\n * const businessName =\n * abnService.displayBusinessNameFromABNRecord(abnRecord)\n * ```\n *\n * @param abnRecord\n * @returns\n */\nexport const displayBusinessNameFromABNRecord = (\n abnRecord: ABNRecord,\n): string => {\n const businessName = getBusinessNameFromABNRecord(abnRecord)\n return businessName || 'ABN Details Suppressed'\n}\n\n/**\n * Attempts to get the most recent ABN number from the data returned in an\n * `ABNRecord`. Will return `undefined` if an ABN is not found.\n *\n * #### Example\n *\n * ```js\n * const ABN = abnService.getABNNumberFromABNRecord(abnRecord)\n * ```\n *\n * @param abnRecord\n * @returns\n */\nexport const getABNNumberFromABNRecord = (\n abnRecord: ABNRecord,\n): string | undefined => {\n if (!abnRecord.ABN) return\n if (Array.isArray(abnRecord.ABN)) {\n const relevantABN = abnRecord.ABN.find(\n (abn) => abn.isCurrentIndicator === 'Y',\n )\n return relevantABN?.identifierValue\n }\n return abnRecord.ABN.identifierValue\n}\n\n/**\n * Attempts to get the most recent ABN number from the data returned in an\n * `ABNRecord`. Will return \"Unknown ABN Number\" if an ABN is not found.\n *\n * #### Example\n *\n * ```js\n * const ABN = abnService.displayABNNumberFromABNRecord(abnRecord)\n * ```\n *\n * @param abnRecord\n * @returns\n */\nexport const displayABNNumberFromABNRecord = (abnRecord: ABNRecord): string => {\n const abnNumber = getABNNumberFromABNRecord(abnRecord)\n return abnNumber || 'Unknown ABN Number'\n}\n"]}
|
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.conditionallyShowByPredicate =
|
|
6
|
+
exports.conditionallyShowByPredicate = conditionallyShowByPredicate;
|
|
7
|
+
exports.default = conditionallyShowElement;
|
|
7
8
|
const evaluateConditionalPredicate_1 = __importDefault(require("./evaluateConditionalPredicate"));
|
|
8
9
|
const getParentFormElements = (formElementsCtrl, childElement) => {
|
|
9
10
|
const parentElement = formElementsCtrl.flattenedElements.find((element) => {
|
|
@@ -42,7 +43,6 @@ function conditionallyShowByPredicate(formElementsCtrl, predicate, elementsEvalu
|
|
|
42
43
|
// Check to see if the model has one of the valid values to show the element
|
|
43
44
|
return conditionallyShowElement(formElementsCtrl, predicateElement, elementsEvaluated);
|
|
44
45
|
}
|
|
45
|
-
exports.conditionallyShowByPredicate = conditionallyShowByPredicate;
|
|
46
46
|
function conditionallyShowElement(formElementsCtrl, elementToEvaluate, elementsEvaluated) {
|
|
47
47
|
// If the element does not have the `conditionallyShow` flag set,
|
|
48
48
|
// we can always show the element.
|
|
@@ -82,5 +82,4 @@ function conditionallyShowElement(formElementsCtrl, elementToEvaluate, elementsE
|
|
|
82
82
|
return conditionallyShowPredicates.some(predicateFunction);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
exports.default = conditionallyShowElement;
|
|
86
85
|
//# sourceMappingURL=conditionallyShowElement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditionallyShowElement.js","sourceRoot":"","sources":["../../src/conditionalLogicService/conditionallyShowElement.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"conditionallyShowElement.js","sourceRoot":"","sources":["../../src/conditionalLogicService/conditionallyShowElement.ts"],"names":[],"mappings":";;;;;AA0BA,oEAsCC;AAED,2CAqDC;AArHD,kGAAyE;AAEzE,MAAM,qBAAqB,GAAG,CAC5B,gBAAkC,EAClC,YAAmC,EACsB,EAAE;IAC3D,MAAM,aAAa,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QACxE,OAAO,CACL,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC;YACvD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAA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2B,CAAC;QAC7D,CAAC,iBAAiB,CAAC,2BAA2B,CAAC,MAAM,EACrD,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IACD,MAAM,2BAA2B,GAC/B,iBAAiB,CAAC,2BAA2B,CAAA;IAE/C,iEAAiE;IACjE,2EAA2E;IAC3E,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,IAAI,CACpD,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,iBAAiB,CAAC,EAAE,CACxC,CAAA;IACD,IAAI,uBAAuB,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CACb,kEAAkE,uBAAuB,CAAC,KAAK,sGAAsG,CACtM,CAAA;IACH,CAAC;SAAM,CAAC;QACN,iBAAiB,CAAC,IAAI,CAAC;YACrB,EAAE,EAAE,iBAAiB,CAAC,EAAE;YACxB,KAAK,EACH,OAAO,IAAI,iBAAiB;gBAC1B,CAAC,CAAC,iBAAiB,CAAC,KAAK;gBACzB,CAAC,CAAC,iBAAiB,CAAC,IAAI;SAC7B,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,iBAAiB,GAAG,CACxB,SAA8C,EAC9C,EAAE;QACF,oEAAoE;QACpE,iEAAiE;QACjE,yBAAyB;QACzB,OAAO,4BAA4B,CAAC,gBAAgB,EAAE,SAAS,EAAE;YAC/D,GAAG,iBAAiB;SACrB,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,IAAI,iBAAiB,CAAC,sCAAsC,EAAE,CAAC;QAC7D,OAAO,2BAA2B,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAA;IAC7D,CAAC;SAAM,CAAC;QACN,OAAO,2BAA2B,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;IAC5D,CAAC;AACH,CAAC","sourcesContent":["import { FormTypes, ConditionTypes } from '@oneblink/types'\nimport { FormElementsCtrl } from './types'\nimport evaluateConditionalPredicate from './evaluateConditionalPredicate'\n\nconst getParentFormElements = (\n formElementsCtrl: FormElementsCtrl,\n childElement: FormTypes.FormElement,\n): Array<FormTypes.SectionElement | FormTypes.PageElement> => {\n const parentElement = formElementsCtrl.flattenedElements.find((element) => {\n return (\n (element.type === 'page' || element.type === 'section') &&\n element.elements.some(({ id }) => id === childElement.id)\n )\n })\n if (\n parentElement &&\n (parentElement.type === 'page' || parentElement.type === 'section')\n ) {\n return [\n parentElement,\n ...getParentFormElements(formElementsCtrl, parentElement),\n ]\n }\n return []\n}\n\nexport function conditionallyShowByPredicate(\n formElementsCtrl: FormElementsCtrl,\n predicate: ConditionTypes.ConditionalPredicate,\n elementsEvaluated: Array<{ id: string; label: string }>,\n): boolean {\n const predicateElement = evaluateConditionalPredicate({\n predicate,\n formElementsCtrl,\n })\n\n if (!predicateElement) {\n return false\n }\n\n // Here we will also need to check if the predicate element\n // is on a page/section element and the page/section element\n // is also hidden. If it is hidden we will treat this\n // predicate element as hidden as well.\n const parentFormElements = getParentFormElements(\n formElementsCtrl,\n predicateElement,\n )\n for (const parentFormElement of parentFormElements) {\n if (\n !conditionallyShowElement(formElementsCtrl, parentFormElement, [\n ...elementsEvaluated,\n ])\n ) {\n return false\n }\n }\n\n // Check to see if the model has one of the valid values to show the element\n return conditionallyShowElement(\n formElementsCtrl,\n predicateElement,\n elementsEvaluated,\n )\n}\n\nexport default function conditionallyShowElement(\n formElementsCtrl: FormElementsCtrl,\n elementToEvaluate: FormTypes.FormElement,\n elementsEvaluated: Array<{ id: string; label: string }>,\n): boolean {\n // If the element does not have the `conditionallyShow` flag set,\n // we can always show the element.\n if (\n !elementToEvaluate ||\n !elementToEvaluate.conditionallyShow ||\n !Array.isArray(elementToEvaluate.conditionallyShowPredicates) ||\n !elementToEvaluate.conditionallyShowPredicates.length\n ) {\n return true\n }\n const conditionallyShowPredicates =\n elementToEvaluate.conditionallyShowPredicates\n\n // Check to see if this element has already been used to evaluate\n // if the element should be shown based on parent element conditional logic\n const elementAlreadyEvaluated = elementsEvaluated.find(\n ({ id }) => id === elementToEvaluate.id,\n )\n if (elementAlreadyEvaluated) {\n throw new Error(\n `Your conditional logic has caused an infinite loop. Check the \"${elementAlreadyEvaluated.label}\" form element to ensure element A does not rely on element B if element B also relies on element A.`,\n )\n } else {\n elementsEvaluated.push({\n id: elementToEvaluate.id,\n label:\n 'label' in elementToEvaluate\n ? elementToEvaluate.label\n : elementToEvaluate.name,\n })\n }\n\n const predicateFunction = (\n predicate: ConditionTypes.ConditionalPredicate,\n ) => {\n // Spread the array of elements evaluated so that each predicate can\n // evaluate the tree without causing false positives for infinite\n // loop conditional logic\n return conditionallyShowByPredicate(formElementsCtrl, predicate, [\n ...elementsEvaluated,\n ])\n }\n\n if (elementToEvaluate.requiresAllConditionallyShowPredicates) {\n return conditionallyShowPredicates.every(predicateFunction)\n } else {\n return conditionallyShowPredicates.some(predicateFunction)\n }\n}\n"]}
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = conditionallyShowOption;
|
|
6
7
|
const evaluateConditionalOptionsPredicate_1 = __importDefault(require("./evaluateConditionalOptionsPredicate"));
|
|
7
8
|
const __1 = require("..");
|
|
8
9
|
const conditionallyShowElement_1 = __importDefault(require("./conditionallyShowElement"));
|
|
@@ -168,5 +169,4 @@ function conditionallyShowOption(formElementsCtrl, elementToEvaluate, optionToEv
|
|
|
168
169
|
return 'HIDE';
|
|
169
170
|
}
|
|
170
171
|
}
|
|
171
|
-
exports.default = conditionallyShowOption;
|
|
172
172
|
//# sourceMappingURL=conditionallyShowOption.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditionallyShowOption.js","sourceRoot":"","sources":["../../src/conditionalLogicService/conditionallyShowOption.ts"],"names":[],"mappings":";;;;;AACA,gHAAuF;AAEvF,0BAAoC;AACpC,0FAAiE;AAQjE,MA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jC,MAAK;aACN;YACD,KAAK,2BAA2B,CAAC,CAAC;gBAChC,yBAAyB,GAAG,IAAI,CAAA;gBAChC,MAAK;aACN;SACF;KACF;IACD,IAAI,0BAA0B,EAAE;QAC9B,OAAO,4BAA4B,CAAA;KACpC;SAAM,IAAI,yBAAyB,EAAE;QACpC,OAAO,2BAA2B,CAAA;KACnC;SAAM;QACL,OAAO,MAAM,CAAA;KACd;AACH,CAAC;AApED,0CAoEC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport evaluateConditionalOptionsPredicate from './evaluateConditionalOptionsPredicate'\nimport { FormElementsCtrl } from './types'\nimport { typeCastService } from '..'\nimport conditionallyShowElement from './conditionallyShowElement'\n\nexport type ShouldShowOption =\n | 'SHOW'\n | 'HIDE'\n | 'LOADING_DYNAMIC_DEPENDENCY'\n | 'LOADING_STATIC_DEPENDENCY'\n\nconst handleAttributePredicate = (\n predicate: FormTypes.ChoiceElementOptionAttribute,\n model: SubmissionTypes.S3SubmissionData['submission'],\n predicateElement: FormTypes.FormElementWithOptions,\n) => {\n const values = model[predicateElement.name]\n if (!values) return true\n\n if (\n Array.isArray(values) &&\n (!values.length ||\n !values.filter((value) => typeof value !== 'undefined').length)\n ) {\n return true\n }\n\n return evaluateConditionalOptionsPredicate({\n predicate: {\n type: 'OPTIONS',\n elementId: predicate.elementId,\n optionIds: predicate.optionIds,\n },\n predicateValue: values,\n predicateElement,\n })\n}\n\nconst conditionallyShowOptionByPredicate = (\n formElementsCtrl: FormElementsCtrl,\n predicate: FormTypes.ChoiceElementOptionAttribute,\n elementsEvaluated: string[],\n): ShouldShowOption => {\n // Validate the predicate data, if it is invalid,\n // we will always show the field\n if (\n !predicate ||\n !predicate.elementId ||\n !predicate.optionIds ||\n !predicate.optionIds.length\n ) {\n return 'SHOW'\n }\n const predicateElement = formElementsCtrl.flattenedElements.find(\n (element) => {\n return element.id === predicate.elementId\n },\n )\n\n // If we cant find the element used for the predicate,\n // we can check to see if the element being evaluated\n // is in a repeatable set and the predicate element is\n // in a parent list of elements.\n if (!predicateElement) {\n if (formElementsCtrl.parentFormElementsCtrl) {\n return conditionallyShowOptionByPredicate(\n formElementsCtrl.parentFormElementsCtrl,\n predicate,\n elementsEvaluated,\n )\n } else {\n return 'HIDE'\n }\n }\n\n const optionsPredicateElement =\n typeCastService.formElements.toOptionsElement(predicateElement)\n if (!optionsPredicateElement) {\n return 'HIDE'\n }\n // If the predicate element does not have any options to evaluate,\n // we will show the element.\n // Unless the predicate element has dynamic options and\n // options have not been fetched yet.\n const isLoadingPredicateElementsOptions = !Array.isArray(\n optionsPredicateElement.options,\n )\n if (isLoadingPredicateElementsOptions) {\n if (optionsPredicateElement.optionsType === 'DYNAMIC') {\n return 'LOADING_DYNAMIC_DEPENDENCY'\n } else {\n return 'LOADING_STATIC_DEPENDENCY'\n }\n }\n\n const everyOptionIsShowing = predicate.optionIds.every((id) => {\n const predicateOption = optionsPredicateElement.options?.find(\n (o) => o.id === id,\n )\n if (!predicateOption) return 'HIDE'\n\n return conditionallyShowOption(\n { model: formElementsCtrl.model, flattenedElements: [] },\n optionsPredicateElement,\n predicateOption,\n elementsEvaluated,\n )\n })\n\n if (!everyOptionIsShowing) {\n return 'HIDE'\n }\n\n // Check to see if the model has one of the valid values to show the element\n const shouldShow = handleAttributePredicate(\n predicate,\n formElementsCtrl.model,\n optionsPredicateElement,\n )\n return shouldShow ? 'SHOW' : 'HIDE'\n}\n\nconst isAttributeFilterValid = (\n formElementsCtrl: FormElementsCtrl,\n predicate: FormTypes.ChoiceElementOptionAttribute,\n elementsEvaluated: string[],\n): boolean => {\n const predicateElement = formElementsCtrl.flattenedElements.find(\n (element) => {\n return element.id === predicate.elementId\n },\n )\n\n // If we cant find the element used for the predicate,\n // we can check to see if the element being evaluated\n // is in a repeatable set and the predicate element is\n // in a parent list of elements.\n if (!predicateElement) {\n if (formElementsCtrl.parentFormElementsCtrl) {\n return isAttributeFilterValid(\n formElementsCtrl.parentFormElementsCtrl,\n predicate,\n elementsEvaluated,\n )\n } else {\n return false\n }\n }\n\n // now we have the model and predicate element, verify that the predicate element\n // is not hidden\n if (\n // Will never be a page, just making typescript happy :)\n predicateElement.type === 'page' ||\n predicateElement.type === 'section' ||\n !conditionallyShowElement(formElementsCtrl, predicateElement, [])\n ) {\n return false\n }\n\n // verify that at least one option is selected\n const values = formElementsCtrl.model[predicateElement.name]\n if (!values) return false\n // if the model value is an array, verify that it has a selection\n if (\n Array.isArray(values) &&\n (!values.length ||\n !values.filter((value) => typeof value !== 'undefined').length)\n ) {\n return false\n }\n\n return true\n}\n\nexport default function conditionallyShowOption(\n formElementsCtrl: FormElementsCtrl,\n elementToEvaluate: FormTypes.FormElementWithOptions,\n optionToEvaluate: FormTypes.ChoiceElementOption,\n optionsEvaluated: string[],\n): ShouldShowOption {\n // If the element does not have the `conditionallyShow` flag set,\n // we can always show the element.\n\n if (\n !elementToEvaluate.conditionallyShowOptions ||\n !optionToEvaluate ||\n !optionToEvaluate.attributes ||\n !Array.isArray(optionToEvaluate.attributes) ||\n !optionToEvaluate.attributes.length\n ) {\n return 'SHOW'\n }\n\n // Check to see if this element has already been used to evaluate\n // if the element should be shown based on parent element conditional logic\n if (optionsEvaluated.some((optionId) => optionId === optionToEvaluate.id)) {\n throw new Error(\n 'Your conditional logic has caused an infinite loop. Check the following Fields to ensure element A does not rely on element B if element B also relies on element A.',\n )\n } else {\n optionsEvaluated.push(optionToEvaluate.id)\n }\n const validPredicates = (optionToEvaluate.attributes || []).filter(\n (predicate) => {\n return isAttributeFilterValid(\n formElementsCtrl,\n predicate,\n optionsEvaluated,\n )\n },\n )\n if (!validPredicates.length) return 'SHOW'\n\n let isLoadingDynamicDEPENDENCY = false\n let isLoadingStaticDEPENDENCY = false\n for (const predicate of validPredicates) {\n const predicateResult = conditionallyShowOptionByPredicate(\n formElementsCtrl,\n predicate,\n optionsEvaluated,\n )\n switch (predicateResult) {\n case 'SHOW': {\n return 'SHOW'\n }\n case 'LOADING_DYNAMIC_DEPENDENCY': {\n isLoadingDynamicDEPENDENCY = true\n break\n }\n case 'LOADING_STATIC_DEPENDENCY': {\n isLoadingStaticDEPENDENCY = true\n break\n }\n }\n }\n if (isLoadingDynamicDEPENDENCY) {\n return 'LOADING_DYNAMIC_DEPENDENCY'\n } else if (isLoadingStaticDEPENDENCY) {\n return 'LOADING_STATIC_DEPENDENCY'\n } else {\n return 'HIDE'\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"conditionallyShowOption.js","sourceRoot":"","sources":["../../src/conditionalLogicService/conditionallyShowOption.ts"],"names":[],"mappings":";;;;;AAgLA,0CAoEC;AAnPD,gHAAuF;AAEvF,0BAAoC;AACpC,0FAAiE;AAQjE,MAAM,wBAAwB,GAAG,CAC/B,SAAiD,EACjD,KAAqD,EACrD,gBAAkD,EAClD,EAAE;IACF,MAAM,MAAM,GAAG,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAA;IAC3C,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,IACE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QACrB,CAAC,CAAC,MAAM,CAAC,MAAM;YACb,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,WAAW,CAAC,CAAC,MAAM,CAAC,EACjE,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,IAAA,6CAAmC,EAAC;QACzC,SAAS,EAAE;YACT,IAAI,EAAE,SAAS;YACf,SAAS,EAAE,SAAS,CAAC,SAAS;YAC9B,SAAS,EAAE,SAAS,CAAC,SAAS;SAC/B;QACD,cAAc,EAAE,MAAM;QACtB,gBAAgB;KACjB,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,MAAM,kCAAkC,GAAG,CACzC,gBAAkC,EAClC,SAAiD,EACjD,iBAA2B,EACT,EAAE;IACpB,iDAAiD;IACjD,gCAAgC;IAChC,IACE,CAAC,SAAS;QAC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AgB,CAAC,EAAE,CAAC,CAAA;IAC5C,CAAC;IACD,MAAM,eAAe,GAAG,CAAC,gBAAgB,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,MAAM,CAChE,CAAC,SAAS,EAAE,EAAE;QACZ,OAAO,sBAAsB,CAC3B,gBAAgB,EAChB,SAAS,EACT,gBAAgB,CACjB,CAAA;IACH,CAAC,CACF,CAAA;IACD,IAAI,CAAC,eAAe,CAAC,MAAM;QAAE,OAAO,MAAM,CAAA;IAE1C,IAAI,0BAA0B,GAAG,KAAK,CAAA;IACtC,IAAI,yBAAyB,GAAG,KAAK,CAAA;IACrC,KAAK,MAAM,SAAS,IAAI,eAAe,EAAE,CAAC;QACxC,MAAM,eAAe,GAAG,kCAAkC,CACxD,gBAAgB,EAChB,SAAS,EACT,gBAAgB,CACjB,CAAA;QACD,QAAQ,eAAe,EAAE,CAAC;YACxB,KAAK,MAAM,CAAC,CAAC,CAAC;gBACZ,OAAO,MAAM,CAAA;YACf,CAAC;YACD,KAAK,4BAA4B,CAAC,CAAC,CAAC;gBAClC,0BAA0B,GAAG,IAAI,CAAA;gBACjC,MAAK;YACP,CAAC;YACD,KAAK,2BAA2B,CAAC,CAAC,CAAC;gBACjC,yBAAyB,GAAG,IAAI,CAAA;gBAChC,MAAK;YACP,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,0BAA0B,EAAE,CAAC;QAC/B,OAAO,4BAA4B,CAAA;IACrC,CAAC;SAAM,IAAI,yBAAyB,EAAE,CAAC;QACrC,OAAO,2BAA2B,CAAA;IACpC,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CAAA;IACf,CAAC;AACH,CAAC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport evaluateConditionalOptionsPredicate from './evaluateConditionalOptionsPredicate'\nimport { FormElementsCtrl } from './types'\nimport { typeCastService } from '..'\nimport conditionallyShowElement from './conditionallyShowElement'\n\nexport type ShouldShowOption =\n | 'SHOW'\n | 'HIDE'\n | 'LOADING_DYNAMIC_DEPENDENCY'\n | 'LOADING_STATIC_DEPENDENCY'\n\nconst handleAttributePredicate = (\n predicate: FormTypes.ChoiceElementOptionAttribute,\n model: SubmissionTypes.S3SubmissionData['submission'],\n predicateElement: FormTypes.FormElementWithOptions,\n) => {\n const values = model[predicateElement.name]\n if (!values) return true\n\n if (\n Array.isArray(values) &&\n (!values.length ||\n !values.filter((value) => typeof value !== 'undefined').length)\n ) {\n return true\n }\n\n return evaluateConditionalOptionsPredicate({\n predicate: {\n type: 'OPTIONS',\n elementId: predicate.elementId,\n optionIds: predicate.optionIds,\n },\n predicateValue: values,\n predicateElement,\n })\n}\n\nconst conditionallyShowOptionByPredicate = (\n formElementsCtrl: FormElementsCtrl,\n predicate: FormTypes.ChoiceElementOptionAttribute,\n elementsEvaluated: string[],\n): ShouldShowOption => {\n // Validate the predicate data, if it is invalid,\n // we will always show the field\n if (\n !predicate ||\n !predicate.elementId ||\n !predicate.optionIds ||\n !predicate.optionIds.length\n ) {\n return 'SHOW'\n }\n const predicateElement = formElementsCtrl.flattenedElements.find(\n (element) => {\n return element.id === predicate.elementId\n },\n )\n\n // If we cant find the element used for the predicate,\n // we can check to see if the element being evaluated\n // is in a repeatable set and the predicate element is\n // in a parent list of elements.\n if (!predicateElement) {\n if (formElementsCtrl.parentFormElementsCtrl) {\n return conditionallyShowOptionByPredicate(\n formElementsCtrl.parentFormElementsCtrl,\n predicate,\n elementsEvaluated,\n )\n } else {\n return 'HIDE'\n }\n }\n\n const optionsPredicateElement =\n typeCastService.formElements.toOptionsElement(predicateElement)\n if (!optionsPredicateElement) {\n return 'HIDE'\n }\n // If the predicate element does not have any options to evaluate,\n // we will show the element.\n // Unless the predicate element has dynamic options and\n // options have not been fetched yet.\n const isLoadingPredicateElementsOptions = !Array.isArray(\n optionsPredicateElement.options,\n )\n if (isLoadingPredicateElementsOptions) {\n if (optionsPredicateElement.optionsType === 'DYNAMIC') {\n return 'LOADING_DYNAMIC_DEPENDENCY'\n } else {\n return 'LOADING_STATIC_DEPENDENCY'\n }\n }\n\n const everyOptionIsShowing = predicate.optionIds.every((id) => {\n const predicateOption = optionsPredicateElement.options?.find(\n (o) => o.id === id,\n )\n if (!predicateOption) return 'HIDE'\n\n return conditionallyShowOption(\n { model: formElementsCtrl.model, flattenedElements: [] },\n optionsPredicateElement,\n predicateOption,\n elementsEvaluated,\n )\n })\n\n if (!everyOptionIsShowing) {\n return 'HIDE'\n }\n\n // Check to see if the model has one of the valid values to show the element\n const shouldShow = handleAttributePredicate(\n predicate,\n formElementsCtrl.model,\n optionsPredicateElement,\n )\n return shouldShow ? 'SHOW' : 'HIDE'\n}\n\nconst isAttributeFilterValid = (\n formElementsCtrl: FormElementsCtrl,\n predicate: FormTypes.ChoiceElementOptionAttribute,\n elementsEvaluated: string[],\n): boolean => {\n const predicateElement = formElementsCtrl.flattenedElements.find(\n (element) => {\n return element.id === predicate.elementId\n },\n )\n\n // If we cant find the element used for the predicate,\n // we can check to see if the element being evaluated\n // is in a repeatable set and the predicate element is\n // in a parent list of elements.\n if (!predicateElement) {\n if (formElementsCtrl.parentFormElementsCtrl) {\n return isAttributeFilterValid(\n formElementsCtrl.parentFormElementsCtrl,\n predicate,\n elementsEvaluated,\n )\n } else {\n return false\n }\n }\n\n // now we have the model and predicate element, verify that the predicate element\n // is not hidden\n if (\n // Will never be a page, just making typescript happy :)\n predicateElement.type === 'page' ||\n predicateElement.type === 'section' ||\n !conditionallyShowElement(formElementsCtrl, predicateElement, [])\n ) {\n return false\n }\n\n // verify that at least one option is selected\n const values = formElementsCtrl.model[predicateElement.name]\n if (!values) return false\n // if the model value is an array, verify that it has a selection\n if (\n Array.isArray(values) &&\n (!values.length ||\n !values.filter((value) => typeof value !== 'undefined').length)\n ) {\n return false\n }\n\n return true\n}\n\nexport default function conditionallyShowOption(\n formElementsCtrl: FormElementsCtrl,\n elementToEvaluate: FormTypes.FormElementWithOptions,\n optionToEvaluate: FormTypes.ChoiceElementOption,\n optionsEvaluated: string[],\n): ShouldShowOption {\n // If the element does not have the `conditionallyShow` flag set,\n // we can always show the element.\n\n if (\n !elementToEvaluate.conditionallyShowOptions ||\n !optionToEvaluate ||\n !optionToEvaluate.attributes ||\n !Array.isArray(optionToEvaluate.attributes) ||\n !optionToEvaluate.attributes.length\n ) {\n return 'SHOW'\n }\n\n // Check to see if this element has already been used to evaluate\n // if the element should be shown based on parent element conditional logic\n if (optionsEvaluated.some((optionId) => optionId === optionToEvaluate.id)) {\n throw new Error(\n 'Your conditional logic has caused an infinite loop. Check the following Fields to ensure element A does not rely on element B if element B also relies on element A.',\n )\n } else {\n optionsEvaluated.push(optionToEvaluate.id)\n }\n const validPredicates = (optionToEvaluate.attributes || []).filter(\n (predicate) => {\n return isAttributeFilterValid(\n formElementsCtrl,\n predicate,\n optionsEvaluated,\n )\n },\n )\n if (!validPredicates.length) return 'SHOW'\n\n let isLoadingDynamicDEPENDENCY = false\n let isLoadingStaticDEPENDENCY = false\n for (const predicate of validPredicates) {\n const predicateResult = conditionallyShowOptionByPredicate(\n formElementsCtrl,\n predicate,\n optionsEvaluated,\n )\n switch (predicateResult) {\n case 'SHOW': {\n return 'SHOW'\n }\n case 'LOADING_DYNAMIC_DEPENDENCY': {\n isLoadingDynamicDEPENDENCY = true\n break\n }\n case 'LOADING_STATIC_DEPENDENCY': {\n isLoadingStaticDEPENDENCY = true\n break\n }\n }\n }\n if (isLoadingDynamicDEPENDENCY) {\n return 'LOADING_DYNAMIC_DEPENDENCY'\n } else if (isLoadingStaticDEPENDENCY) {\n return 'LOADING_STATIC_DEPENDENCY'\n } else {\n return 'HIDE'\n }\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = evaluateConditionalOptionsPredicate;
|
|
3
4
|
function evaluateConditionalOptionsPredicate({ predicate, predicateElement, predicateValue: value, }) {
|
|
4
5
|
return predicate.optionIds.some((optionId) => {
|
|
5
6
|
var _a;
|
|
@@ -22,5 +23,4 @@ function evaluateConditionalOptionsPredicate({ predicate, predicateElement, pred
|
|
|
22
23
|
}
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
|
-
exports.default = evaluateConditionalOptionsPredicate;
|
|
26
26
|
//# sourceMappingURL=evaluateConditionalOptionsPredicate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluateConditionalOptionsPredicate.js","sourceRoot":"","sources":["../../src/conditionalLogicService/evaluateConditionalOptionsPredicate.ts"],"names":[],"mappings":";;AAEA,SAAwB,mCAAmC,CAAC,EAC1D,SAAS,EACT,gBAAgB,EAChB,cAAc,EAAE,KAAK,GAKtB;IACC,OAAO,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;;QAC3C,MAAM,MAAM,GAAG,MAAA,gBAAgB,CAAC,OAAO,0CAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAA;QACvE,IAAI,MAAM,EAAE;
|
|
1
|
+
{"version":3,"file":"evaluateConditionalOptionsPredicate.js","sourceRoot":"","sources":["../../src/conditionalLogicService/evaluateConditionalOptionsPredicate.ts"],"names":[],"mappings":";;AAEA,sDAyBC;AAzBD,SAAwB,mCAAmC,CAAC,EAC1D,SAAS,EACT,gBAAgB,EAChB,cAAc,EAAE,KAAK,GAKtB;IACC,OAAO,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;;QAC3C,MAAM,MAAM,GAAG,MAAA,gBAAgB,CAAC,OAAO,0CAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAA;QACvE,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzB,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;oBAC/B,OAAO,UAAU,KAAK,MAAM,CAAC,KAAK,CAAA;gBACpC,CAAC,CAAC,CAAA;YACJ,CAAC;iBAAM,IAAI,gBAAgB,CAAC,IAAI,KAAK,YAAY,IAAI,KAAK,EAAE,CAAC;gBAC3D,OAAO,MAAM,CAAC,KAAK,KAAM,KAA4B,CAAC,KAAK,CAAA;YAC7D,CAAC;iBAAM,CAAC;gBACN,OAAO,MAAM,CAAC,KAAK,KAAK,KAAK,CAAA;YAC/B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { FormTypes, ConditionTypes } from '@oneblink/types'\n\nexport default function evaluateConditionalOptionsPredicate({\n predicate,\n predicateElement,\n predicateValue: value,\n}: {\n predicate: ConditionTypes.ConditionalPredicateOptions\n predicateValue: unknown\n predicateElement: FormTypes.FormElementWithOptions\n}): boolean {\n return predicate.optionIds.some((optionId) => {\n const option = predicateElement.options?.find((o) => o.id === optionId)\n if (option) {\n if (Array.isArray(value)) {\n return value.some((modelValue) => {\n return modelValue === option.value\n })\n } else if (predicateElement.type === 'compliance' && value) {\n return option.value === (value as { value: unknown }).value\n } else {\n return option.value === value\n }\n } else {\n return false\n }\n })\n}\n"]}
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = evaluateConditionalPredicate;
|
|
6
7
|
const __1 = require("..");
|
|
7
8
|
const evaluateConditionalOptionsPredicate_1 = __importDefault(require("./evaluateConditionalOptionsPredicate"));
|
|
8
9
|
const conditionallyShowElement_1 = require("./conditionallyShowElement");
|
|
@@ -193,5 +194,4 @@ function evaluateConditionalPredicate({ predicate, formElementsCtrl, }) {
|
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
}
|
|
196
|
-
exports.default = evaluateConditionalPredicate;
|
|
197
197
|
//# sourceMappingURL=evaluateConditionalPredicate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluateConditionalPredicate.js","sourceRoot":"","sources":["../../src/conditionalLogicService/evaluateConditionalPredicate.ts"],"names":[],"mappings":";;;;;AAEA,0BAAyD;AACzD,gHAAuF;AACvF,yEAAyE;AACzE,gEAA4D;AAE5D,MAAM,KAAK,GAAG;IACZ,GAAG,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG;IAC5C,IAAI,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG;IAC9C,KAAK,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,KAAK,GAAG;IAChD,KAAK,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,KAAK,GAAG;IAChD,IAAI,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG;IAC9C,GAAG,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG;CAC7C,CAAA;AAED,SAAS,kBAAkB,CACzB,gBAAkC,EAClC,SAAiB;IAEjB,MAAM,WAAW,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,CACzD,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,KAAK,SAAS,CAC9C,CAAA;IACD,IAAI,WAAW,EAAE;QACf,MAAM,mBAAmB,GACvB,mBAAe,CAAC,YAAY,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;QAC1D,IAAI,mBAAmB,EAAE;YACvB,OAAO;gBACL,mBAAmB;gBACnB,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC,m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O,CAAC,uBAAuB,CAAC,OAAO,CAAC,EAAE;gBACnD,OAAO,uBAAuB,CAAC,WAAW,KAAK,SAAS;oBACtD,CAAC,CAAC,gBAAgB;oBAClB,CAAC,CAAC,SAAS,CAAA;aACd;iBAAM;gBACL,OAAO,IAAA,6CAAmC,EAAC;oBACzC,SAAS;oBACT,cAAc;oBACd,gBAAgB,EAAE,uBAAuB;iBAC1C,CAAC;oBACA,CAAC,CAAC,gBAAgB;oBAClB,CAAC,CAAC,SAAS,CAAA;aACd;SACF;KACF;AACH,CAAC;AAjND,+CAiNC","sourcesContent":["import { FormTypes, ConditionTypes } from '@oneblink/types'\nimport { FormElementsCtrl } from './types'\nimport { typeCastService, formElementsService } from '..'\nimport evaluateConditionalOptionsPredicate from './evaluateConditionalOptionsPredicate'\nimport { conditionallyShowByPredicate } from './conditionallyShowElement'\nimport { flattenFormElements } from '../formElementsService'\n\nconst fnMap = {\n '>': (lhs: number, rhs: number) => lhs > rhs,\n '>=': (lhs: number, rhs: number) => lhs >= rhs,\n '===': (lhs: number, rhs: number) => lhs === rhs,\n '!==': (lhs: number, rhs: number) => lhs !== rhs,\n '<=': (lhs: number, rhs: number) => lhs <= rhs,\n '<': (lhs: number, rhs: number) => lhs < rhs,\n}\n\nfunction getElementAndValue(\n formElementsCtrl: FormElementsCtrl,\n elementId: string,\n): { formElementWithName?: FormTypes.FormElementWithName; value?: unknown } {\n const formElement = formElementsCtrl.flattenedElements.find(\n (formElement) => formElement.id === elementId,\n )\n if (formElement) {\n const formElementWithName =\n typeCastService.formElements.toNamedElement(formElement)\n if (formElementWithName) {\n return {\n formElementWithName,\n value: formElementsCtrl.model[formElementWithName.name],\n }\n }\n } else if (formElementsCtrl.parentFormElementsCtrl) {\n return getElementAndValue(\n formElementsCtrl.parentFormElementsCtrl,\n elementId,\n )\n }\n return {}\n}\n\nexport default function evaluateConditionalPredicate({\n predicate,\n formElementsCtrl,\n}: {\n predicate: ConditionTypes.ConditionalPredicate\n formElementsCtrl: FormElementsCtrl\n}): FormTypes.FormElementWithName | undefined {\n const { formElementWithName: predicateElement, value: predicateValue } =\n getElementAndValue(formElementsCtrl, predicate.elementId)\n if (!predicateElement) {\n return\n }\n switch (predicate.type) {\n case 'VALUE': {\n if (Array.isArray(predicateValue)) {\n return !predicate.hasValue === !predicateValue.length\n ? predicateElement\n : undefined\n }\n return !predicate.hasValue === !predicateValue\n ? predicateElement\n : undefined\n }\n case 'NUMERIC': {\n // if the operator fn doesn't exist, hide the control\n const operatorFn = fnMap[predicate.operator]\n if (!operatorFn) return undefined\n\n const lhs = Number.parseFloat(predicateValue as string)\n // if left is not a number, hide the control\n if (isNaN(lhs)) return undefined\n\n let rhsValue = NaN\n switch (predicate.compareWith) {\n case 'ELEMENT': {\n const { value: comparisonValue } = getElementAndValue(\n formElementsCtrl,\n predicate.value,\n )\n rhsValue =\n comparisonValue === 'string'\n ? Number.parseFloat(comparisonValue)\n : (comparisonValue as number)\n break\n }\n case 'VALUE':\n default: {\n rhsValue = predicate.value\n break\n }\n }\n\n const rhs =\n typeof rhsValue === 'string' ? Number.parseFloat(rhsValue) : rhsValue\n\n // if right is not a number, hide the control\n if (isNaN(rhs)) return undefined\n\n return operatorFn(lhs, rhs) ? predicateElement : undefined\n }\n case 'BETWEEN': {\n const value = Number.parseFloat(predicateValue as string)\n if (Number.isNaN(value)) {\n return undefined\n }\n\n return value >= predicate.min && value <= predicate.max\n ? predicateElement\n : undefined\n }\n case 'REPEATABLESET': {\n const {\n formElementWithName: repeatableSetElement,\n value: repeatableSetValue,\n } = getElementAndValue(formElementsCtrl, predicate.elementId)\n\n if (!repeatableSetElement) {\n return\n }\n\n if (\n repeatableSetElement.type !== 'repeatableSet' ||\n !Array.isArray(repeatableSetValue)\n ) {\n return\n }\n\n for (const entry of repeatableSetValue) {\n const result = conditionallyShowByPredicate(\n {\n model: entry,\n flattenedElements: formElementsService.flattenFormElements(\n repeatableSetElement.elements,\n ),\n parentFormElementsCtrl: formElementsCtrl,\n },\n predicate.repeatableSetPredicate,\n [],\n )\n\n if (result) {\n return predicateElement\n }\n }\n return\n }\n case 'FORM':\n if (predicate.predicate) {\n if (\n !predicateElement ||\n predicateElement.type !== 'form' ||\n !predicateElement.elements\n ) {\n return\n }\n const formModel = formElementsCtrl.model[predicateElement.name] as {\n [name: string]: unknown\n }\n const result = conditionallyShowByPredicate(\n {\n model: formModel,\n flattenedElements: flattenFormElements(predicateElement.elements),\n parentFormElementsCtrl: formElementsCtrl,\n },\n predicate.predicate,\n [],\n )\n\n if (result) {\n return predicateElement\n }\n }\n return\n case 'ADDRESS_PROPERTY': {\n // Only element that should work as predicate element should be Point or Geoscape.\n if (\n !(\n predicateElement.type === 'pointAddress' ||\n predicateElement.type === 'geoscapeAddress'\n )\n ) {\n return\n }\n if (predicateValue && typeof predicateValue === 'object') {\n if (predicate.definition.property === 'STATE_EQUALITY') {\n // Validate that it has the properties we want, in case submission data\n // is incorrect but has the right element reference.\n if (\n 'addressDetails' in predicateValue &&\n predicateValue.addressDetails &&\n typeof predicateValue.addressDetails === 'object' &&\n 'stateTerritory' in predicateValue.addressDetails &&\n typeof predicateValue.addressDetails.stateTerritory === 'string'\n ) {\n const result =\n predicateValue.addressDetails.stateTerritory ===\n predicate.definition.value\n if (result) {\n return predicateElement\n }\n }\n return\n }\n // If the property isn't State Equality, we are checking Physical addresses. This only exists for Point.\n if (predicateElement.type === 'pointAddress') {\n // If the value is true, we only want to return the element for PO Boxes. If it's false, then we only want\n // to return element for non mail address addresses.\n if (\n 'dataset' in predicateValue &&\n typeof predicateValue.dataset === 'string'\n ) {\n const result = predicate.definition.value\n ? predicateValue.dataset === 'mailAddress'\n : predicateValue.dataset === 'GNAF'\n if (result) {\n return predicateElement\n }\n }\n }\n }\n return\n }\n case 'OPTIONS':\n default: {\n const optionsPredicateElement =\n typeCastService.formElements.toOptionsElement(predicateElement)\n if (!optionsPredicateElement) {\n return undefined\n }\n\n // If the predicate element does not have any options to evaluate,\n // we will show the element.\n // Unless the predicate element has dynamic options and\n // options have not been fetched yet.\n if (!Array.isArray(optionsPredicateElement.options)) {\n return optionsPredicateElement.optionsType !== 'DYNAMIC'\n ? predicateElement\n : undefined\n } else {\n return evaluateConditionalOptionsPredicate({\n predicate,\n predicateValue,\n predicateElement: optionsPredicateElement,\n })\n ? predicateElement\n : undefined\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"evaluateConditionalPredicate.js","sourceRoot":"","sources":["../../src/conditionalLogicService/evaluateConditionalPredicate.ts"],"names":[],"mappings":";;;;;AAyCA,+CAiNC;AAxPD,0BAAyD;AACzD,gHAAuF;AACvF,yEAAyE;AACzE,gEAA4D;AAE5D,MAAM,KAAK,GAAG;IACZ,GAAG,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG;IAC5C,IAAI,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG;IAC9C,KAAK,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,KAAK,GAAG;IAChD,KAAK,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,KAAK,GAAG;IAChD,IAAI,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG;IAC9C,GAAG,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG;CAC7C,CAAA;AAED,SAAS,kBAAkB,CACzB,gBAAkC,EAClC,SAAiB;IAEjB,MAAM,WAAW,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,CACzD,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,KAAK,SAAS,CAC9C,CAAA;IACD,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,mBAAmB,GACvB,mBAAe,CAAC,YAAY,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;QAC1D,IAAI,m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,KAAK,MAAM,CAAA;wBACrC,IAAI,MAAM,EAAE,CAAC;4BACX,OAAO,gBAAgB,CAAA;wBACzB,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;YACD,OAAM;QACR,CAAC;QACD,KAAK,SAAS,CAAC;QACf,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,uBAAuB,GAC3B,mBAAe,CAAC,YAAY,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAA;YACjE,IAAI,CAAC,uBAAuB,EAAE,CAAC;gBAC7B,OAAO,SAAS,CAAA;YAClB,CAAC;YAED,kEAAkE;YAClE,4BAA4B;YAC5B,uDAAuD;YACvD,qCAAqC;YACrC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,uBAAuB,CAAC,OAAO,CAAC,EAAE,CAAC;gBACpD,OAAO,uBAAuB,CAAC,WAAW,KAAK,SAAS;oBACtD,CAAC,CAAC,gBAAgB;oBAClB,CAAC,CAAC,SAAS,CAAA;YACf,CAAC;iBAAM,CAAC;gBACN,OAAO,IAAA,6CAAmC,EAAC;oBACzC,SAAS;oBACT,cAAc;oBACd,gBAAgB,EAAE,uBAAuB;iBAC1C,CAAC;oBACA,CAAC,CAAC,gBAAgB;oBAClB,CAAC,CAAC,SAAS,CAAA;YACf,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { FormTypes, ConditionTypes } from '@oneblink/types'\nimport { FormElementsCtrl } from './types'\nimport { typeCastService, formElementsService } from '..'\nimport evaluateConditionalOptionsPredicate from './evaluateConditionalOptionsPredicate'\nimport { conditionallyShowByPredicate } from './conditionallyShowElement'\nimport { flattenFormElements } from '../formElementsService'\n\nconst fnMap = {\n '>': (lhs: number, rhs: number) => lhs > rhs,\n '>=': (lhs: number, rhs: number) => lhs >= rhs,\n '===': (lhs: number, rhs: number) => lhs === rhs,\n '!==': (lhs: number, rhs: number) => lhs !== rhs,\n '<=': (lhs: number, rhs: number) => lhs <= rhs,\n '<': (lhs: number, rhs: number) => lhs < rhs,\n}\n\nfunction getElementAndValue(\n formElementsCtrl: FormElementsCtrl,\n elementId: string,\n): { formElementWithName?: FormTypes.FormElementWithName; value?: unknown } {\n const formElement = formElementsCtrl.flattenedElements.find(\n (formElement) => formElement.id === elementId,\n )\n if (formElement) {\n const formElementWithName =\n typeCastService.formElements.toNamedElement(formElement)\n if (formElementWithName) {\n return {\n formElementWithName,\n value: formElementsCtrl.model[formElementWithName.name],\n }\n }\n } else if (formElementsCtrl.parentFormElementsCtrl) {\n return getElementAndValue(\n formElementsCtrl.parentFormElementsCtrl,\n elementId,\n )\n }\n return {}\n}\n\nexport default function evaluateConditionalPredicate({\n predicate,\n formElementsCtrl,\n}: {\n predicate: ConditionTypes.ConditionalPredicate\n formElementsCtrl: FormElementsCtrl\n}): FormTypes.FormElementWithName | undefined {\n const { formElementWithName: predicateElement, value: predicateValue } =\n getElementAndValue(formElementsCtrl, predicate.elementId)\n if (!predicateElement) {\n return\n }\n switch (predicate.type) {\n case 'VALUE': {\n if (Array.isArray(predicateValue)) {\n return !predicate.hasValue === !predicateValue.length\n ? predicateElement\n : undefined\n }\n return !predicate.hasValue === !predicateValue\n ? predicateElement\n : undefined\n }\n case 'NUMERIC': {\n // if the operator fn doesn't exist, hide the control\n const operatorFn = fnMap[predicate.operator]\n if (!operatorFn) return undefined\n\n const lhs = Number.parseFloat(predicateValue as string)\n // if left is not a number, hide the control\n if (isNaN(lhs)) return undefined\n\n let rhsValue = NaN\n switch (predicate.compareWith) {\n case 'ELEMENT': {\n const { value: comparisonValue } = getElementAndValue(\n formElementsCtrl,\n predicate.value,\n )\n rhsValue =\n comparisonValue === 'string'\n ? Number.parseFloat(comparisonValue)\n : (comparisonValue as number)\n break\n }\n case 'VALUE':\n default: {\n rhsValue = predicate.value\n break\n }\n }\n\n const rhs =\n typeof rhsValue === 'string' ? Number.parseFloat(rhsValue) : rhsValue\n\n // if right is not a number, hide the control\n if (isNaN(rhs)) return undefined\n\n return operatorFn(lhs, rhs) ? predicateElement : undefined\n }\n case 'BETWEEN': {\n const value = Number.parseFloat(predicateValue as string)\n if (Number.isNaN(value)) {\n return undefined\n }\n\n return value >= predicate.min && value <= predicate.max\n ? predicateElement\n : undefined\n }\n case 'REPEATABLESET': {\n const {\n formElementWithName: repeatableSetElement,\n value: repeatableSetValue,\n } = getElementAndValue(formElementsCtrl, predicate.elementId)\n\n if (!repeatableSetElement) {\n return\n }\n\n if (\n repeatableSetElement.type !== 'repeatableSet' ||\n !Array.isArray(repeatableSetValue)\n ) {\n return\n }\n\n for (const entry of repeatableSetValue) {\n const result = conditionallyShowByPredicate(\n {\n model: entry,\n flattenedElements: formElementsService.flattenFormElements(\n repeatableSetElement.elements,\n ),\n parentFormElementsCtrl: formElementsCtrl,\n },\n predicate.repeatableSetPredicate,\n [],\n )\n\n if (result) {\n return predicateElement\n }\n }\n return\n }\n case 'FORM':\n if (predicate.predicate) {\n if (\n !predicateElement ||\n predicateElement.type !== 'form' ||\n !predicateElement.elements\n ) {\n return\n }\n const formModel = formElementsCtrl.model[predicateElement.name] as {\n [name: string]: unknown\n }\n const result = conditionallyShowByPredicate(\n {\n model: formModel,\n flattenedElements: flattenFormElements(predicateElement.elements),\n parentFormElementsCtrl: formElementsCtrl,\n },\n predicate.predicate,\n [],\n )\n\n if (result) {\n return predicateElement\n }\n }\n return\n case 'ADDRESS_PROPERTY': {\n // Only element that should work as predicate element should be Point or Geoscape.\n if (\n !(\n predicateElement.type === 'pointAddress' ||\n predicateElement.type === 'geoscapeAddress'\n )\n ) {\n return\n }\n if (predicateValue && typeof predicateValue === 'object') {\n if (predicate.definition.property === 'STATE_EQUALITY') {\n // Validate that it has the properties we want, in case submission data\n // is incorrect but has the right element reference.\n if (\n 'addressDetails' in predicateValue &&\n predicateValue.addressDetails &&\n typeof predicateValue.addressDetails === 'object' &&\n 'stateTerritory' in predicateValue.addressDetails &&\n typeof predicateValue.addressDetails.stateTerritory === 'string'\n ) {\n const result =\n predicateValue.addressDetails.stateTerritory ===\n predicate.definition.value\n if (result) {\n return predicateElement\n }\n }\n return\n }\n // If the property isn't State Equality, we are checking Physical addresses. This only exists for Point.\n if (predicateElement.type === 'pointAddress') {\n // If the value is true, we only want to return the element for PO Boxes. If it's false, then we only want\n // to return element for non mail address addresses.\n if (\n 'dataset' in predicateValue &&\n typeof predicateValue.dataset === 'string'\n ) {\n const result = predicate.definition.value\n ? predicateValue.dataset === 'mailAddress'\n : predicateValue.dataset === 'GNAF'\n if (result) {\n return predicateElement\n }\n }\n }\n }\n return\n }\n case 'OPTIONS':\n default: {\n const optionsPredicateElement =\n typeCastService.formElements.toOptionsElement(predicateElement)\n if (!optionsPredicateElement) {\n return undefined\n }\n\n // If the predicate element does not have any options to evaluate,\n // we will show the element.\n // Unless the predicate element has dynamic options and\n // options have not been fetched yet.\n if (!Array.isArray(optionsPredicateElement.options)) {\n return optionsPredicateElement.optionsType !== 'DYNAMIC'\n ? predicateElement\n : undefined\n } else {\n return evaluateConditionalOptionsPredicate({\n predicate,\n predicateValue,\n predicateElement: optionsPredicateElement,\n })\n ? predicateElement\n : undefined\n }\n }\n }\n}\n"]}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generateFormElementsConditionallyShown =
|
|
6
|
+
exports.generateFormElementsConditionallyShown = generateFormElementsConditionallyShown;
|
|
7
7
|
const formElementsService_1 = require("../formElementsService");
|
|
8
8
|
const conditionallyShowElement_1 = __importDefault(require("./conditionallyShowElement"));
|
|
9
9
|
const conditionallyShowOption_1 = __importDefault(require("./conditionallyShowOption"));
|
|
@@ -13,7 +13,7 @@ const handleConditionallyShowElement = (formElementsCtrl, element, errorCallback
|
|
|
13
13
|
return (0, conditionallyShowElement_1.default)(formElementsCtrl, element, []);
|
|
14
14
|
}
|
|
15
15
|
catch (error) {
|
|
16
|
-
errorCallback
|
|
16
|
+
errorCallback === null || errorCallback === void 0 ? void 0 : errorCallback(error);
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
19
|
};
|
|
@@ -22,7 +22,7 @@ const handleConditionallyShowOption = (formElementsCtrl, element, option, errorC
|
|
|
22
22
|
return (0, conditionallyShowOption_1.default)(formElementsCtrl, element, option, []);
|
|
23
23
|
}
|
|
24
24
|
catch (error) {
|
|
25
|
-
errorCallback
|
|
25
|
+
errorCallback === null || errorCallback === void 0 ? void 0 : errorCallback(error);
|
|
26
26
|
return 'HIDE';
|
|
27
27
|
}
|
|
28
28
|
};
|
|
@@ -236,5 +236,4 @@ const generateFormElementsConditionallyShownWithParent = ({ formElements, submis
|
|
|
236
236
|
function generateFormElementsConditionallyShown(parameters) {
|
|
237
237
|
return generateFormElementsConditionallyShownWithParent(parameters);
|
|
238
238
|
}
|
|
239
|
-
exports.generateFormElementsConditionallyShown = generateFormElementsConditionallyShown;
|
|
240
239
|
//# sourceMappingURL=generateFormElementsConditionallyShown.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateFormElementsConditionallyShown.js","sourceRoot":"","sources":["../../src/conditionalLogicService/generateFormElementsConditionallyShown.ts"],"names":[],"mappings":";;;;;;AAEA,gEAA4D;AAC5D,0FAAiE;AACjE,wFAEkC;AAClC,0BAAoC;AA8BpC,MAAM,8BAA8B,GAAG,CACrC,gBAAkC,EAClC,OAA8B,EAC9B,aAAwC,EACxC,EAAE;IACF,IAAI;QACF,OAAO,IAAA,kCAAwB,EAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE,CAAC,CAAA;KAC/D;IAAC,OAAO,KAAK,EAAE;QACd,aAAa,IAAI,aAAa,CAAC,KAAc,CAAC,CAAA;QAC9C,OAAO,KAAK,CAAA;KACb;AACH,CAAC,CAAA;AAED,MAAM,6BAA6B,GAAG,CACpC,gBAAkC,EAClC,OAAyC,EACzC,MAAqC,EACrC,aAAwC,E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IAAI,CAAA;oCACxD,MAAK;iCACN;gCACD,KAAK,4BAA4B,CAAC,CAAC;oCACjC,6BAA6B,CAAC,mBAAmB,GAAG,IAAI,CAAA;oCACxD,MAAK;iCACN;6BACF;yBACF;wBACD,6BAA6B,CAAC,OAAO,GAAG,UAAU,CAAA;qBACnD;iBACF;gBAED,8BAA8B,CAAC,OAAO,CAAC,IAAI,CAAC;oBAC1C,6BAA6B,CAAA;aAChC;SACF;QAED,OAAO,8BAA8B,CAAA;IACvC,CAAC,EACD,EAAE,CACH,CAAA;AACH,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsFG;AACH,SAAgB,sCAAsC,CACpD,UAAoD;IAEpD,OAAO,gDAAgD,CAAC,UAAU,CAAC,CAAA;AACrE,CAAC;AAJD,wFAIC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { FormElementsCtrl } from './types'\nimport { flattenFormElements } from '../formElementsService'\nimport conditionallyShowElement from './conditionallyShowElement'\nimport conditionallyShowOption, {\n ShouldShowOption,\n} from './conditionallyShowOption'\nimport { typeCastService } from '..'\n\nexport type FormElementsConditionallyShown = Record<\n string,\n FormElementConditionallyShown\n>\n\nexport type FormElementConditionallyShownElement = {\n type: 'formElement'\n isHidden: boolean\n options?: FormTypes.ChoiceElementOption[]\n dependencyIsLoading?: boolean\n}\n\nexport type FormElementConditionallyShown =\n | undefined\n | FormElementConditionallyShownElement\n | {\n type: 'formElements'\n isHidden: boolean\n formElements: FormElementsConditionallyShown | undefined\n }\n | {\n type: 'repeatableSet'\n isHidden: boolean\n entries: Record<string, FormElementsConditionallyShown | undefined>\n }\n\nexport type ErrorCallback = (error: Error) => void\n\nconst handleConditionallyShowElement = (\n formElementsCtrl: FormElementsCtrl,\n element: FormTypes.FormElement,\n errorCallback: ErrorCallback | undefined,\n) => {\n try {\n return conditionallyShowElement(formElementsCtrl, element, [])\n } catch (error) {\n errorCallback && errorCallback(error as Error)\n return false\n }\n}\n\nconst handleConditionallyShowOption = (\n formElementsCtrl: FormElementsCtrl,\n element: FormTypes.FormElementWithOptions,\n option: FormTypes.ChoiceElementOption,\n errorCallback: ErrorCallback | undefined,\n): ShouldShowOption => {\n try {\n return conditionallyShowOption(formElementsCtrl, element, option, [])\n } catch (error) {\n errorCallback && errorCallback(error as Error)\n return 'HIDE'\n }\n}\n\nexport type FormElementsConditionallyShownParameters = {\n /** Form elements to evaluate */\n formElements: FormTypes.FormElement[]\n /** Current submission data */\n submission: SubmissionTypes.S3SubmissionData['submission']\n /** Optional callback for handling errors caught during the evaluation */\n errorCallback?: ErrorCallback\n}\n\nconst generateFormElementsConditionallyShownWithParent = ({\n formElements,\n submission,\n parentFormElementsCtrl,\n errorCallback,\n}: FormElementsConditionallyShownParameters & {\n parentFormElementsCtrl?: FormElementsCtrl['parentFormElementsCtrl']\n}): FormElementsConditionallyShown => {\n const formElementsCtrl = {\n flattenedElements: flattenFormElements(formElements),\n model: submission,\n parentFormElementsCtrl,\n }\n return formElementsCtrl.flattenedElements.reduce<FormElementsConditionallyShown>(\n (formElementsConditionallyShown, element) => {\n switch (element.type) {\n case 'section':\n case 'page': {\n const formElementConditionallyShown =\n formElementsConditionallyShown[element.id]\n const isHidden = formElementConditionallyShown\n ? formElementConditionallyShown.isHidden\n : !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n )\n\n formElementsConditionallyShown[element.id] = {\n type: 'formElement',\n isHidden,\n }\n\n // If the parent element is hidden, hide all the child elements\n if (isHidden) {\n element.elements.forEach((childElement) => {\n switch (childElement.type) {\n case 'section':\n case 'page': {\n formElementsConditionallyShown[childElement.id] = {\n type: 'formElement',\n isHidden: true,\n }\n break\n }\n default: {\n formElementsConditionallyShown[childElement.name] = {\n type: 'formElement',\n isHidden: true,\n }\n }\n }\n })\n }\n break\n }\n case 'infoPage':\n case 'form': {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const nestedModel = submission[element.name] as\n | SubmissionTypes.S3SubmissionData['submission']\n | undefined\n formElementsConditionallyShown[element.name] = {\n type: 'formElements',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n formElements: generateFormElementsConditionallyShownWithParent({\n formElements: element.elements || [],\n submission: nestedModel || {},\n parentFormElementsCtrl: formElementsCtrl,\n }),\n }\n break\n }\n case 'repeatableSet': {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const entries = formElementsCtrl.model[element.name] as\n | Array<SubmissionTypes.S3SubmissionData['submission']>\n | undefined\n formElementsConditionallyShown[element.name] = {\n type: 'repeatableSet',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n entries: (entries || []).reduce(\n (\n result: Record<\n string,\n FormElementsConditionallyShown | undefined\n >,\n entry,\n index,\n ) => {\n result[index.toString()] =\n generateFormElementsConditionallyShownWithParent({\n formElements: element.elements,\n submission: entry,\n parentFormElementsCtrl: formElementsCtrl,\n })\n return result\n },\n {},\n ),\n }\n break\n }\n default: {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const formElementConditionallyShown: FormElementConditionallyShown = {\n type: 'formElement',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n }\n\n if (!formElementConditionallyShown.isHidden) {\n const optionsElement =\n typeCastService.formElements.toOptionsElement(element)\n if (\n optionsElement &&\n optionsElement.conditionallyShowOptions &&\n Array.isArray(optionsElement.options)\n ) {\n const newOptions = []\n for (const option of optionsElement.options) {\n const optionPredicatesResult = handleConditionallyShowOption(\n formElementsCtrl,\n optionsElement,\n option,\n errorCallback,\n )\n switch (optionPredicatesResult) {\n case 'SHOW': {\n newOptions.push(option)\n break\n }\n case 'LOADING_STATIC_DEPENDENCY': {\n newOptions.push(option)\n formElementConditionallyShown.dependencyIsLoading = true\n break\n }\n case 'LOADING_DYNAMIC_DEPENDENCY': {\n formElementConditionallyShown.dependencyIsLoading = true\n break\n }\n }\n }\n formElementConditionallyShown.options = newOptions\n }\n }\n\n formElementsConditionallyShown[element.name] =\n formElementConditionallyShown\n }\n }\n\n return formElementsConditionallyShown\n },\n {},\n )\n}\n\n/**\n * Given a form element and submission data, evaluate which elements are\n * currently shown. The function also takes an optional errorCallback for\n * handling errors caught during the evaluation.\n *\n * #### Example\n *\n * ```js\n * const formElementsConditionallyShown =\n * conditionalLogicService.generateFormElementsConditionallyShown({\n * submission: {\n * radio: ['hide'],\n * text: 'hidden text',\n * },\n * formElements: [\n * {\n * name: 'radio',\n * label: 'Radio',\n * type: 'radio',\n * required: false,\n * id: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',\n * conditionallyShow: false,\n * options: [\n * {\n * id: '9a44e15a-5929-419d-825e-b3dc0a29591f',\n * label: 'Show',\n * value: 'show',\n * },\n * {\n * id: 'd776ed42-072c-4bf8-9879-874b2bef85d3',\n * label: 'Hide',\n * value: 'Hide',\n * },\n * ],\n * readOnly: false,\n * isDataLookup: false,\n * isElementLookup: false,\n * buttons: false,\n * optionsType: 'CUSTOM',\n * conditionallyShowOptions: false,\n * },\n * {\n * name: 'text',\n * label: 'Text',\n * type: 'text',\n * required: false,\n * id: '8fbddb41-348d-494c-904b-56a2c4361f13',\n * requiresAllConditionallyShowPredicates: false,\n * conditionallyShow: true,\n * conditionallyShowPredicates: [\n * {\n * elementId: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',\n * optionIds: ['9a44e15a-5929-419d-825e-b3dc0a29591f'],\n * type: 'OPTIONS',\n * },\n * ],\n * readOnly: false,\n * isDataLookup: false,\n * isElementLookup: false,\n * },\n * ],\n * parentFormElementsCtrl: undefined,\n * errorCallback: (error) => {\n * //do something with the error here\n * console.error(error)\n * },\n * })\n * ```\n *\n * The above example returns an object like below\n *\n * ```json\n * {\n * \"radio\": {\n * \"isHidden\": false,\n * \"type\": \"formElement\"\n * },\n * \"text\": {\n * \"isHidden\": true,\n * \"type\": \"formElement\"\n * }\n * }\n * ```\n *\n * @param parameters\n * @returns\n */\nexport function generateFormElementsConditionallyShown(\n parameters: FormElementsConditionallyShownParameters,\n): FormElementsConditionallyShown {\n return generateFormElementsConditionallyShownWithParent(parameters)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"generateFormElementsConditionallyShown.js","sourceRoot":"","sources":["../../src/conditionalLogicService/generateFormElementsConditionallyShown.ts"],"names":[],"mappings":";;;;;AA+UA,wFAIC;AAjVD,gEAA4D;AAC5D,0FAAiE;AACjE,wFAEkC;AAClC,0BAAoC;AA8BpC,MAAM,8BAA8B,GAAG,CACrC,gBAAkC,EAClC,OAA8B,EAC9B,aAAwC,EACxC,EAAE;IACF,IAAI,CAAC;QACH,OAAO,IAAA,kCAAwB,EAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE,CAAC,CAAA;IAChE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAG,KAAc,CAAC,CAAA;QAC/B,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA;AAED,MAAM,6BAA6B,GAAG,CACpC,gBAAkC,EAClC,OAAyC,EACzC,MAAqC,EACrC,aAAwC,EACtB,EAAE;IACpB,IAAI,CAAC;QACH,OAAO,IAAA,iCAAuB,EAAC,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,CAAA;IACvE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAG,KAAc,CAAC,CAAA;QAC/B,OAAO,MAAM,CAAA;IACf,CAAC;AACH,CAAC,CAAA;AAWD,MAAM,gDAAgD,GAAG,CAAC,EACxD,YAAY,EACZ,UAAU,EACV,sBAAsB,EACtB,aAAa,GAGd,EAAkC,EAAE;IACnC,MAAM,gBAAgB,GAAG;QACvB,iBAAiB,EAAE,IAAA,yCAAmB,EAAC,YAAY,CAAC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ACH,CAAC;gBAED,8BAA8B,CAAC,OAAO,CAAC,IAAI,CAAC;oBAC1C,6BAA6B,CAAA;YACjC,CAAC;QACH,CAAC;QAED,OAAO,8BAA8B,CAAA;IACvC,CAAC,EACD,EAAE,CACH,CAAA;AACH,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsFG;AACH,SAAgB,sCAAsC,CACpD,UAAoD;IAEpD,OAAO,gDAAgD,CAAC,UAAU,CAAC,CAAA;AACrE,CAAC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { FormElementsCtrl } from './types'\nimport { flattenFormElements } from '../formElementsService'\nimport conditionallyShowElement from './conditionallyShowElement'\nimport conditionallyShowOption, {\n ShouldShowOption,\n} from './conditionallyShowOption'\nimport { typeCastService } from '..'\n\nexport type FormElementsConditionallyShown = Record<\n string,\n FormElementConditionallyShown\n>\n\nexport type FormElementConditionallyShownElement = {\n type: 'formElement'\n isHidden: boolean\n options?: FormTypes.ChoiceElementOption[]\n dependencyIsLoading?: boolean\n}\n\nexport type FormElementConditionallyShown =\n | undefined\n | FormElementConditionallyShownElement\n | {\n type: 'formElements'\n isHidden: boolean\n formElements: FormElementsConditionallyShown | undefined\n }\n | {\n type: 'repeatableSet'\n isHidden: boolean\n entries: Record<string, FormElementsConditionallyShown | undefined>\n }\n\nexport type ErrorCallback = (error: Error) => void\n\nconst handleConditionallyShowElement = (\n formElementsCtrl: FormElementsCtrl,\n element: FormTypes.FormElement,\n errorCallback: ErrorCallback | undefined,\n) => {\n try {\n return conditionallyShowElement(formElementsCtrl, element, [])\n } catch (error) {\n errorCallback?.(error as Error)\n return false\n }\n}\n\nconst handleConditionallyShowOption = (\n formElementsCtrl: FormElementsCtrl,\n element: FormTypes.FormElementWithOptions,\n option: FormTypes.ChoiceElementOption,\n errorCallback: ErrorCallback | undefined,\n): ShouldShowOption => {\n try {\n return conditionallyShowOption(formElementsCtrl, element, option, [])\n } catch (error) {\n errorCallback?.(error as Error)\n return 'HIDE'\n }\n}\n\nexport type FormElementsConditionallyShownParameters = {\n /** Form elements to evaluate */\n formElements: FormTypes.FormElement[]\n /** Current submission data */\n submission: SubmissionTypes.S3SubmissionData['submission']\n /** Optional callback for handling errors caught during the evaluation */\n errorCallback?: ErrorCallback\n}\n\nconst generateFormElementsConditionallyShownWithParent = ({\n formElements,\n submission,\n parentFormElementsCtrl,\n errorCallback,\n}: FormElementsConditionallyShownParameters & {\n parentFormElementsCtrl?: FormElementsCtrl['parentFormElementsCtrl']\n}): FormElementsConditionallyShown => {\n const formElementsCtrl = {\n flattenedElements: flattenFormElements(formElements),\n model: submission,\n parentFormElementsCtrl,\n }\n return formElementsCtrl.flattenedElements.reduce<FormElementsConditionallyShown>(\n (formElementsConditionallyShown, element) => {\n switch (element.type) {\n case 'section':\n case 'page': {\n const formElementConditionallyShown =\n formElementsConditionallyShown[element.id]\n const isHidden = formElementConditionallyShown\n ? formElementConditionallyShown.isHidden\n : !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n )\n\n formElementsConditionallyShown[element.id] = {\n type: 'formElement',\n isHidden,\n }\n\n // If the parent element is hidden, hide all the child elements\n if (isHidden) {\n element.elements.forEach((childElement) => {\n switch (childElement.type) {\n case 'section':\n case 'page': {\n formElementsConditionallyShown[childElement.id] = {\n type: 'formElement',\n isHidden: true,\n }\n break\n }\n default: {\n formElementsConditionallyShown[childElement.name] = {\n type: 'formElement',\n isHidden: true,\n }\n }\n }\n })\n }\n break\n }\n case 'infoPage':\n case 'form': {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const nestedModel = submission[element.name] as\n | SubmissionTypes.S3SubmissionData['submission']\n | undefined\n formElementsConditionallyShown[element.name] = {\n type: 'formElements',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n formElements: generateFormElementsConditionallyShownWithParent({\n formElements: element.elements || [],\n submission: nestedModel || {},\n parentFormElementsCtrl: formElementsCtrl,\n }),\n }\n break\n }\n case 'repeatableSet': {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const entries = formElementsCtrl.model[element.name] as\n | Array<SubmissionTypes.S3SubmissionData['submission']>\n | undefined\n formElementsConditionallyShown[element.name] = {\n type: 'repeatableSet',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n entries: (entries || []).reduce(\n (\n result: Record<\n string,\n FormElementsConditionallyShown | undefined\n >,\n entry,\n index,\n ) => {\n result[index.toString()] =\n generateFormElementsConditionallyShownWithParent({\n formElements: element.elements,\n submission: entry,\n parentFormElementsCtrl: formElementsCtrl,\n })\n return result\n },\n {},\n ),\n }\n break\n }\n default: {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const formElementConditionallyShown: FormElementConditionallyShown = {\n type: 'formElement',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n }\n\n if (!formElementConditionallyShown.isHidden) {\n const optionsElement =\n typeCastService.formElements.toOptionsElement(element)\n if (\n optionsElement &&\n optionsElement.conditionallyShowOptions &&\n Array.isArray(optionsElement.options)\n ) {\n const newOptions = []\n for (const option of optionsElement.options) {\n const optionPredicatesResult = handleConditionallyShowOption(\n formElementsCtrl,\n optionsElement,\n option,\n errorCallback,\n )\n switch (optionPredicatesResult) {\n case 'SHOW': {\n newOptions.push(option)\n break\n }\n case 'LOADING_STATIC_DEPENDENCY': {\n newOptions.push(option)\n formElementConditionallyShown.dependencyIsLoading = true\n break\n }\n case 'LOADING_DYNAMIC_DEPENDENCY': {\n formElementConditionallyShown.dependencyIsLoading = true\n break\n }\n }\n }\n formElementConditionallyShown.options = newOptions\n }\n }\n\n formElementsConditionallyShown[element.name] =\n formElementConditionallyShown\n }\n }\n\n return formElementsConditionallyShown\n },\n {},\n )\n}\n\n/**\n * Given a form element and submission data, evaluate which elements are\n * currently shown. The function also takes an optional errorCallback for\n * handling errors caught during the evaluation.\n *\n * #### Example\n *\n * ```js\n * const formElementsConditionallyShown =\n * conditionalLogicService.generateFormElementsConditionallyShown({\n * submission: {\n * radio: ['hide'],\n * text: 'hidden text',\n * },\n * formElements: [\n * {\n * name: 'radio',\n * label: 'Radio',\n * type: 'radio',\n * required: false,\n * id: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',\n * conditionallyShow: false,\n * options: [\n * {\n * id: '9a44e15a-5929-419d-825e-b3dc0a29591f',\n * label: 'Show',\n * value: 'show',\n * },\n * {\n * id: 'd776ed42-072c-4bf8-9879-874b2bef85d3',\n * label: 'Hide',\n * value: 'Hide',\n * },\n * ],\n * readOnly: false,\n * isDataLookup: false,\n * isElementLookup: false,\n * buttons: false,\n * optionsType: 'CUSTOM',\n * conditionallyShowOptions: false,\n * },\n * {\n * name: 'text',\n * label: 'Text',\n * type: 'text',\n * required: false,\n * id: '8fbddb41-348d-494c-904b-56a2c4361f13',\n * requiresAllConditionallyShowPredicates: false,\n * conditionallyShow: true,\n * conditionallyShowPredicates: [\n * {\n * elementId: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',\n * optionIds: ['9a44e15a-5929-419d-825e-b3dc0a29591f'],\n * type: 'OPTIONS',\n * },\n * ],\n * readOnly: false,\n * isDataLookup: false,\n * isElementLookup: false,\n * },\n * ],\n * parentFormElementsCtrl: undefined,\n * errorCallback: (error) => {\n * //do something with the error here\n * console.error(error)\n * },\n * })\n * ```\n *\n * The above example returns an object like below\n *\n * ```json\n * {\n * \"radio\": {\n * \"isHidden\": false,\n * \"type\": \"formElement\"\n * },\n * \"text\": {\n * \"isHidden\": true,\n * \"type\": \"formElement\"\n * }\n * }\n * ```\n *\n * @param parameters\n * @returns\n */\nexport function generateFormElementsConditionallyShown(\n parameters: FormElementsConditionallyShownParameters,\n): FormElementsConditionallyShown {\n return generateFormElementsConditionallyShownWithParent(parameters)\n}\n"]}
|
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.evaluateConditionalPredicates =
|
|
20
|
+
exports.evaluateConditionalPredicates = evaluateConditionalPredicates;
|
|
21
21
|
const evaluateConditionalPredicate_1 = __importDefault(require("./conditionalLogicService/evaluateConditionalPredicate"));
|
|
22
22
|
const formElementsService_1 = require("./formElementsService");
|
|
23
23
|
__exportStar(require("./conditionalLogicService/generateFormElementsConditionallyShown"), exports);
|
|
@@ -102,5 +102,4 @@ function evaluateConditionalPredicates({ isConditional, requiresAllConditionalPr
|
|
|
102
102
|
return conditionalPredicates.some(predicateFn);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
exports.evaluateConditionalPredicates = evaluateConditionalPredicates;
|
|
106
105
|
//# sourceMappingURL=conditionalLogicService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditionalLogicService.js","sourceRoot":"","sources":["../src/conditionalLogicService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"conditionalLogicService.js","sourceRoot":"","sources":["../src/conditionalLogicService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAoEA,sEA+BC;AAnGD,0HAAiG;AACjG,+DAA2D;AAG3D,mGAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,SAAgB,6BAA6B,CAAC,EAC5C,aAAa,EACb,gCAAgC,EAChC,qBAAqB,EACrB,YAAY,EACZ,UAAU,GAOX;IACC,IAAI,CAAC,aAAa,IAAI,CAAC,qBAAqB,CAAC,MAAM,EAAE,CAAC;QACpD,OAAO,IAAI,CAAA;IACb,CAAC;IACD,MAAM,gBAAgB,GAAG;QACvB,iBAAiB,EAAE,IAAA,yCAAmB,EAAC,YAAY,CAAC;QACpD,KAAK,EAAE,UAAU;KAClB,CAAA;IAED,MAAM,WAAW,GAAG,CAAC,SAA8C,EAAE,EAAE,CACrE,IAAA,sCAA4B,EAAC;QAC3B,SAAS;QACT,gBAAgB;KACjB,CAAC,CAAA;IACJ,IAAI,gCAAgC,EAAE,CAAC;QACrC,OAAO,qBAAqB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;IACjD,CAAC;SAAM,CAAC;QACN,OAAO,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;IAChD,CAAC;AACH,CAAC","sourcesContent":["import evaluateConditionalPredicate from './conditionalLogicService/evaluateConditionalPredicate'\nimport { flattenFormElements } from './formElementsService'\nimport { ConditionTypes, FormTypes, SubmissionTypes } from '@oneblink/types'\n\nexport * from './conditionalLogicService/generateFormElementsConditionallyShown'\n\n/**\n * Given a set of form elements and submission data, evaluate if predicates are\n * met or not.\n *\n * #### Example\n *\n * ```js\n * const evaluation = conditionalLogicService.evaluateConditionalPredicates(\n * {\n * isConditional: true,\n * requiresAllConditionalPredicates: false,\n * conditionalPredicates: [\n * {\n * type: 'OPTIONS',\n * elementId: '3534abe4-b0b5-4ffa-a216-49c223ab6f95',\n * optionIds: ['9ce633dd-22d6-4e0e-a9e0-1aa62d435e72'],\n * },\n * ],\n * submission: {\n * checkboxes: ['a'],\n * },\n * formElements: [\n * {\n * name: 'checkboxes',\n * label: 'Checkboxes',\n * type: 'checkboxes',\n * required: false,\n * id: '3534abe4-b0b5-4ffa-a216-49c223ab6f95',\n * options: [\n * {\n * id: '9ce633dd-22d6-4e0e-a9e0-1aa62d435e72',\n * label: 'First',\n * value: 'a',\n * },\n * {\n * id: '5850b32c-3833-4498-a072-47fcc8122242',\n * label: 'Second',\n * value: 'b',\n * },\n * {\n * id: 'ab363e9f-a63f-4923-ba0d-47892fc26a93',\n * label: 'Third',\n * value: 'c',\n * },\n * ],\n * readOnly: false,\n * buttons: false,\n * optionsType: 'CUSTOM',\n * conditionallyShowOptions: false,\n * isDataLookup: false,\n * isElementLookup: false,\n * conditionallyShow: false,\n * requiresAllConditionallyShowPredicates: false,\n * },\n * ],\n * },\n * )\n * ```\n *\n * @param options\n * @returns\n */\nexport function evaluateConditionalPredicates({\n isConditional,\n requiresAllConditionalPredicates,\n conditionalPredicates,\n formElements,\n submission,\n}: {\n isConditional: boolean\n requiresAllConditionalPredicates: boolean\n conditionalPredicates: ConditionTypes.ConditionalPredicate[]\n formElements: FormTypes.FormElement[]\n submission: SubmissionTypes.S3SubmissionData['submission']\n}): boolean {\n if (!isConditional || !conditionalPredicates.length) {\n return true\n }\n const formElementsCtrl = {\n flattenedElements: flattenFormElements(formElements),\n model: submission,\n }\n\n const predicateFn = (predicate: ConditionTypes.ConditionalPredicate) =>\n evaluateConditionalPredicate({\n predicate,\n formElementsCtrl,\n })\n if (requiresAllConditionalPredicates) {\n return conditionalPredicates.every(predicateFn)\n } else {\n return conditionalPredicates.some(predicateFn)\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getContentDisposition =
|
|
3
|
+
exports.getContentDisposition = getContentDisposition;
|
|
4
4
|
/**
|
|
5
5
|
* Attempts to get the content disposition for the header by compiling a string
|
|
6
6
|
* of UTF-8 formatting based on the file name.
|
|
@@ -18,5 +18,4 @@ exports.getContentDisposition = void 0;
|
|
|
18
18
|
function getContentDisposition(filename) {
|
|
19
19
|
return `attachment; filename*=UTF-8''${encodeURIComponent(filename)}`;
|
|
20
20
|
}
|
|
21
|
-
exports.getContentDisposition = getContentDisposition;
|
|
22
21
|
//# sourceMappingURL=fileUploadService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileUploadService.js","sourceRoot":"","sources":["../src/fileUploadService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fileUploadService.js","sourceRoot":"","sources":["../src/fileUploadService.ts"],"names":[],"mappings":";;AAcA,sDAEC;AAhBD;;;;;;;;;;;;;GAaG;AACH,SAAgB,qBAAqB,CAAC,QAAgB;IACpD,OAAO,gCAAgC,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAA;AACvE,CAAC","sourcesContent":["/**\n * Attempts to get the content disposition for the header by compiling a string\n * of UTF-8 formatting based on the file name.\n *\n * #### Example\n *\n * ```js\n * const contentDisposition =\n * fileUploadService.getContentDisposition(fileName)\n * ```\n *\n * @param filename The name of the file being uploaded\n * @returns\n */\nexport function getContentDisposition(filename: string): string {\n return `attachment; filename*=UTF-8''${encodeURIComponent(filename)}`\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.NestedElementRegex = exports.RootElementRegex = void 0;
|
|
4
|
+
exports.matchElementsTagRegex = matchElementsTagRegex;
|
|
4
5
|
/**
|
|
5
6
|
* The regex used for matching `{ELEMENT:<elementName>}` tags in the OneBlink
|
|
6
7
|
* platform. Ignores nested elements based on the '|' character. Will match
|
|
@@ -61,5 +62,4 @@ function matchElementsTagRegex(options, matchHandler) {
|
|
|
61
62
|
matchHandler({ elementName, elementMatch: matches[0] });
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
|
-
exports.matchElementsTagRegex = matchElementsTagRegex;
|
|
65
65
|
//# sourceMappingURL=form-elements-regex.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-elements-regex.js","sourceRoot":"","sources":["../src/form-elements-regex.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"form-elements-regex.js","sourceRoot":"","sources":["../src/form-elements-regex.ts"],"names":[],"mappings":";;;AAkDA,sDAmCC;AArFD;;;;GAIG;AACU,QAAA,gBAAgB,GAAG,yBAAyB,CAAA;AACzD;;;;;GAKG;AACU,QAAA,kBAAkB,GAAG,wBAAwB,CAAA;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,SAAgB,qBAAqB,CACnC,OAcK,EACL,YAGU;IAEV,MAAM,IAAI,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAA;IACjE,MAAM,qBAAqB,GACzB,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAA;IAChE,IAAI,OAAO,CAAA;IACX,OACE,CAAC,OAAO,GAAG,CACT,qBAAqB,CAAC,CAAC,CAAC,wBAAgB,CAAC,CAAC,CAAC,0BAAkB,CAC9D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EACtB,CAAC;QACD,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,IAAG,CAAC;YAAE,SAAQ;QAEjC,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;QAC9B,YAAY,CAAC,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;IACzD,CAAC;AACH,CAAC","sourcesContent":["/**\n * The regex used for matching `{ELEMENT:<elementName>}` tags in the OneBlink\n * platform. Ignores nested elements based on the '|' character. Will match\n * `\"{ELEMENT:Parent_Name}\"` but will NOT match `\"{ELEMENT:Children|Name}\"`.\n */\nexport const RootElementRegex = /({ELEMENT:)([^|}]+)(})/g\n/**\n * The regex used for matching `{ELEMENT:<elementName>|<nestedElementName>}`\n * tags in the OneBlink platform. Includes nested elements based on the '|'\n * character. {ELEMENT:Children|Name} would be matched. Will match\n * `\"{ELEMENT:Parent_Name}\"` and `\"{ELEMENT:Children|Name}\"`.\n */\nexport const NestedElementRegex = /({ELEMENT:)([^}]+)(})/g\n\n/**\n * Takes a string and calls a provided handler function for each found instance\n * of `{ELEMENT:<elementName>}` in the string. Used to replace values in\n * OneBlink calculation and info (HTML) elements.\n *\n * #### Example\n *\n * ```js\n * formElementsService.matchElementsTagRegex(\n * myString,\n * ({ elementName, elementMatch }) => {\n * const v = submission[elementName]\n * myString = myString.replace(elementMatch, v)\n * },\n * )\n * ```\n *\n * Or\n *\n * ```js\n * formElementsService.matchElementsTagRegex(\n * {\n * text: myString,\n * excludeNestedElements: true,\n * },\n * ({ elementName, elementMatch }) => {\n * const v = submission[elementName]\n * myString = myString.replace(elementMatch, v)\n * },\n * )\n * ```\n *\n * @param options\n * @param handler\n * @returns\n */\nexport function matchElementsTagRegex(\n options:\n | string\n | {\n text: string\n /**\n * Determine if only root level elements should be matched.\n *\n * `false` will match `\"{ELEMENT:Parent_Name}\"` and\n * `\"{ELEMENT:Children|Name}\"`.\n *\n * `true` will match `\"{ELEMENT:Parent_Name}\"` but will NOT replace\n * `{ELEMENT:Children|Name}`.\n */\n excludeNestedElements: boolean\n },\n matchHandler: (options: {\n elementName: string\n elementMatch: string\n }) => void,\n) {\n const text = typeof options === 'string' ? options : options.text\n const excludeNestedElements =\n typeof options !== 'string' && !!options.excludeNestedElements\n let matches\n while (\n (matches = (\n excludeNestedElements ? RootElementRegex : NestedElementRegex\n ).exec(text)) !== null\n ) {\n if (matches?.length < 3) continue\n\n const elementName = matches[2]\n matchHandler({ elementName, elementMatch: matches[0] })\n }\n}\n"]}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.fixElementName = exports.matchElementsTagRegex = void 0;
|
|
4
|
+
exports.forEachFormElement = forEachFormElement;
|
|
5
|
+
exports.forEachFormElementWithOptions = forEachFormElementWithOptions;
|
|
6
|
+
exports.findFormElement = findFormElement;
|
|
7
|
+
exports.parseDynamicFormElementOptions = parseDynamicFormElementOptions;
|
|
8
|
+
exports.flattenFormElements = flattenFormElements;
|
|
9
|
+
exports.determineIsInfoPage = determineIsInfoPage;
|
|
10
|
+
exports.injectFormElementsIntoForm = injectFormElementsIntoForm;
|
|
4
11
|
const _1 = require(".");
|
|
5
12
|
var form_elements_regex_1 = require("./form-elements-regex");
|
|
6
13
|
Object.defineProperty(exports, "matchElementsTagRegex", { enumerable: true, get: function () { return form_elements_regex_1.matchElementsTagRegex; } });
|
|
@@ -25,7 +32,6 @@ function forEachFormElement(elements, forEach) {
|
|
|
25
32
|
return false;
|
|
26
33
|
});
|
|
27
34
|
}
|
|
28
|
-
exports.forEachFormElement = forEachFormElement;
|
|
29
35
|
/**
|
|
30
36
|
* Iterate over all form elements that have options (e.g. `'select'` type
|
|
31
37
|
* elements), also iterating over nested form element (e.g. page elements).
|
|
@@ -53,7 +59,6 @@ function forEachFormElementWithOptions(elements, forEach) {
|
|
|
53
59
|
return false;
|
|
54
60
|
});
|
|
55
61
|
}
|
|
56
|
-
exports.forEachFormElementWithOptions = forEachFormElementWithOptions;
|
|
57
62
|
/**
|
|
58
63
|
* Iterate over all form elements and return an element that matches a
|
|
59
64
|
* predicate, also iterating over nested form element (e.g. page elements). Will
|
|
@@ -96,7 +101,6 @@ function findFormElement(elements, predicate, parentElements = []) {
|
|
|
96
101
|
}
|
|
97
102
|
}
|
|
98
103
|
}
|
|
99
|
-
exports.findFormElement = findFormElement;
|
|
100
104
|
/**
|
|
101
105
|
* Parse unknown data as valid dynamic options for a forms element. This will
|
|
102
106
|
* always return an Array of valid dynamic options.
|
|
@@ -170,7 +174,6 @@ function parseDynamicFormElementOptions(data) {
|
|
|
170
174
|
return options;
|
|
171
175
|
}, []);
|
|
172
176
|
}
|
|
173
|
-
exports.parseDynamicFormElementOptions = parseDynamicFormElementOptions;
|
|
174
177
|
/**
|
|
175
178
|
* Takes the nested definition structure and returns all form elements as 1d
|
|
176
179
|
* array.
|
|
@@ -198,7 +201,6 @@ function flattenFormElements(elements) {
|
|
|
198
201
|
return flattenedElements;
|
|
199
202
|
}, []);
|
|
200
203
|
}
|
|
201
|
-
exports.flattenFormElements = flattenFormElements;
|
|
202
204
|
const infoPageElements = [
|
|
203
205
|
'heading',
|
|
204
206
|
'html',
|
|
@@ -222,7 +224,6 @@ function determineIsInfoPage(form) {
|
|
|
222
224
|
});
|
|
223
225
|
return !foundInputElement;
|
|
224
226
|
}
|
|
225
|
-
exports.determineIsInfoPage = determineIsInfoPage;
|
|
226
227
|
/**
|
|
227
228
|
* Remove invalid characters from a form element name.
|
|
228
229
|
*
|
|
@@ -254,7 +255,6 @@ function injectFormElementsIntoForm(form, forms, injectAuthenticatedForms = true
|
|
|
254
255
|
form.elements = elementsWithInjectedForms;
|
|
255
256
|
return form.elements;
|
|
256
257
|
}
|
|
257
|
-
exports.injectFormElementsIntoForm = injectFormElementsIntoForm;
|
|
258
258
|
function injectFormElements(elements, forms, parentIds, injectAuthenticatedForms) {
|
|
259
259
|
return elements.reduce((newElements, element) => {
|
|
260
260
|
if ((element.type === 'page' ||
|