@oneblink/sdk-core 0.3.6-beta.3 → 0.4.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/README.md +2 -8
- package/dist/abnService.d.ts +53 -0
- package/dist/abnService.js +53 -0
- package/dist/abnService.js.map +1 -1
- package/dist/conditionalLogicService/conditionallyShowElement.js +9 -19
- package/dist/conditionalLogicService/conditionallyShowElement.js.map +1 -1
- package/dist/conditionalLogicService/conditionallyShowOption.js +3 -3
- package/dist/conditionalLogicService/conditionallyShowOption.js.map +1 -1
- package/dist/conditionalLogicService/evaluateConditionalOptionsPredicate.d.ts +6 -0
- package/dist/conditionalLogicService/evaluateConditionalOptionsPredicate.js +26 -0
- package/dist/conditionalLogicService/evaluateConditionalOptionsPredicate.js.map +1 -0
- package/dist/conditionalLogicService/evaluateConditionalPredicate.d.ts +6 -0
- package/dist/conditionalLogicService/evaluateConditionalPredicate.js +114 -0
- package/dist/conditionalLogicService/evaluateConditionalPredicate.js.map +1 -0
- package/dist/conditionalLogicService/generateFormElementsConditionallyShown.d.ts +111 -9
- package/dist/conditionalLogicService/generateFormElementsConditionallyShown.js +95 -4
- package/dist/conditionalLogicService/generateFormElementsConditionallyShown.js.map +1 -1
- package/dist/conditionalLogicService.d.ts +71 -0
- package/dist/conditionalLogicService.js +106 -0
- package/dist/conditionalLogicService.js.map +1 -0
- package/dist/fileUploadService.d.ts +14 -0
- package/dist/fileUploadService.js +14 -0
- package/dist/fileUploadService.js.map +1 -1
- package/dist/formElementsService.d.ts +83 -4
- package/dist/formElementsService.js +83 -15
- package/dist/formElementsService.js.map +1 -1
- package/dist/index.d.ts +85 -4
- package/dist/index.js +91 -9
- package/dist/index.js.map +1 -1
- package/dist/paymentService.d.ts +19 -0
- package/dist/{paymentAmountValidation.js → paymentService.js} +20 -6
- package/dist/paymentService.js.map +1 -0
- package/dist/replaceCustomValues.d.ts +98 -3
- package/dist/replaceCustomValues.js +98 -2
- package/dist/replaceCustomValues.js.map +1 -1
- package/dist/schedulingService.d.ts +19 -0
- package/dist/schedulingService.js +33 -0
- package/dist/schedulingService.js.map +1 -0
- package/dist/submissionService.d.ts +22 -0
- package/dist/submissionService.js +52 -0
- package/dist/submissionService.js.map +1 -0
- package/dist/typeCastService.d.ts +1 -1
- package/dist/typeCastService.js.map +1 -1
- package/dist/typedoc.d.ts +2 -0
- package/dist/typedoc.js +19 -0
- package/dist/typedoc.js.map +1 -0
- package/dist/types/index.d.ts +0 -14
- package/dist/types/index.js.map +1 -1
- package/dist/userService.d.ts +35 -0
- package/dist/userService.js +35 -0
- package/dist/userService.js.map +1 -1
- package/package.json +15 -12
- package/dist/conditionalLogicService/evaluationService.d.ts +0 -19
- package/dist/conditionalLogicService/evaluationService.js +0 -139
- package/dist/conditionalLogicService/evaluationService.js.map +0 -1
- package/dist/conditionalLogicService/index.d.ts +0 -2
- package/dist/conditionalLogicService/index.js +0 -13
- package/dist/conditionalLogicService/index.js.map +0 -1
- package/dist/paymentAmountValidation.d.ts +0 -7
- package/dist/paymentAmountValidation.js.map +0 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FormTypes, SubmissionEventTypes, SubmissionTypes } from '@oneblink/types';
|
|
2
|
+
/**
|
|
3
|
+
* Examine a submission and its form definition to validate whether a scheduling
|
|
4
|
+
* workflow event needs to run.
|
|
5
|
+
*
|
|
6
|
+
* #### Example
|
|
7
|
+
*
|
|
8
|
+
* ```js
|
|
9
|
+
* const result = schedulingService.checkFormSchedulingEvent(
|
|
10
|
+
* form,
|
|
11
|
+
* submission,
|
|
12
|
+
* )
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param definition
|
|
16
|
+
* @param submission
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export declare function checkForSchedulingEvent(definition: FormTypes.Form, submission: SubmissionTypes.S3SubmissionData['submission']): SubmissionEventTypes.SchedulingSubmissionEvent | undefined;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkForSchedulingEvent = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
/**
|
|
6
|
+
* Examine a submission and its form definition to validate whether a scheduling
|
|
7
|
+
* workflow event needs to run.
|
|
8
|
+
*
|
|
9
|
+
* #### Example
|
|
10
|
+
*
|
|
11
|
+
* ```js
|
|
12
|
+
* const result = schedulingService.checkFormSchedulingEvent(
|
|
13
|
+
* form,
|
|
14
|
+
* submission,
|
|
15
|
+
* )
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param definition
|
|
19
|
+
* @param submission
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
function checkForSchedulingEvent(definition, submission) {
|
|
23
|
+
const schedulingSubmissionEvents = definition.schedulingEvents || [];
|
|
24
|
+
return schedulingSubmissionEvents.find((schedulingSubmissionEvent) => _1.conditionalLogicService.evaluateConditionalPredicates({
|
|
25
|
+
isConditional: !!schedulingSubmissionEvent.conditionallyExecute,
|
|
26
|
+
requiresAllConditionalPredicates: !!schedulingSubmissionEvent.requiresAllConditionallyExecutePredicates,
|
|
27
|
+
conditionalPredicates: schedulingSubmissionEvent.conditionallyExecutePredicates || [],
|
|
28
|
+
submission: submission,
|
|
29
|
+
formElements: definition.elements,
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
exports.checkForSchedulingEvent = checkForSchedulingEvent;
|
|
33
|
+
//# sourceMappingURL=schedulingService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schedulingService.js","sourceRoot":"","sources":["../src/schedulingService.ts"],"names":[],"mappings":";;;AAKA,wBAA2C;AAE3C;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,uBAAuB,CACrC,UAA0B,EAC1B,UAA0D;IAE1D,MAAM,0BAA0B,GAAG,UAAU,CAAC,gBAAgB,IAAI,EAAE,CAAA;IACpE,OAAO,0BAA0B,CAAC,IAAI,CAAC,CAAC,yBAAyB,EAAE,EAAE,CACnE,0BAAuB,CAAC,6BAA6B,CAAC;QACpD,aAAa,EAAE,CAAC,CAAC,yBAAyB,CAAC,oBAAoB;QAC/D,gCAAgC,EAC9B,CAAC,CAAC,yBAAyB,CAAC,yCAAyC;QACvE,qBAAqB,EACnB,yBAAyB,CAAC,8BAA8B,IAAI,EAAE;QAChE,UAAU,EAAE,UAAU;QACtB,YAAY,EAAE,UAAU,CAAC,QAAQ;KAClC,CAAC,CACH,CAAA;AACH,CAAC;AAhBD,0DAgBC","sourcesContent":["import {\n FormTypes,\n SubmissionEventTypes,\n SubmissionTypes,\n} from '@oneblink/types'\nimport { conditionalLogicService } from '.'\n\n/**\n * Examine a submission and its form definition to validate whether a scheduling\n * workflow event needs to run.\n *\n * #### Example\n *\n * ```js\n * const result = schedulingService.checkFormSchedulingEvent(\n * form,\n * submission,\n * )\n * ```\n *\n * @param definition\n * @param submission\n * @returns\n */\nexport function checkForSchedulingEvent(\n definition: FormTypes.Form,\n submission: SubmissionTypes.S3SubmissionData['submission'],\n): SubmissionEventTypes.SchedulingSubmissionEvent | undefined {\n const schedulingSubmissionEvents = definition.schedulingEvents || []\n return schedulingSubmissionEvents.find((schedulingSubmissionEvent) =>\n conditionalLogicService.evaluateConditionalPredicates({\n isConditional: !!schedulingSubmissionEvent.conditionallyExecute,\n requiresAllConditionalPredicates:\n !!schedulingSubmissionEvent.requiresAllConditionallyExecutePredicates,\n conditionalPredicates:\n schedulingSubmissionEvent.conditionallyExecutePredicates || [],\n submission: submission,\n formElements: definition.elements,\n }),\n )\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FormTypes, SubmissionTypes } from '@oneblink/types';
|
|
2
|
+
export * from './replaceCustomValues';
|
|
3
|
+
/**
|
|
4
|
+
* Takes a form element's id, the form elements and the submission data to
|
|
5
|
+
* return a value from the submission.
|
|
6
|
+
*
|
|
7
|
+
* #### Example
|
|
8
|
+
*
|
|
9
|
+
* ```js
|
|
10
|
+
* const value = formElementsService.getRootElementById(
|
|
11
|
+
* formElementId,
|
|
12
|
+
* form.elements,
|
|
13
|
+
* submission,
|
|
14
|
+
* )
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param formElementId
|
|
18
|
+
* @param formElements
|
|
19
|
+
* @param submission
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export declare function getRootElementValueById(formElementId: string, formElements: FormTypes.FormElement[], submission: SubmissionTypes.S3SubmissionData['submission']): unknown;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.getRootElementValueById = void 0;
|
|
18
|
+
__exportStar(require("./replaceCustomValues"), exports);
|
|
19
|
+
/**
|
|
20
|
+
* Takes a form element's id, the form elements and the submission data to
|
|
21
|
+
* return a value from the submission.
|
|
22
|
+
*
|
|
23
|
+
* #### Example
|
|
24
|
+
*
|
|
25
|
+
* ```js
|
|
26
|
+
* const value = formElementsService.getRootElementById(
|
|
27
|
+
* formElementId,
|
|
28
|
+
* form.elements,
|
|
29
|
+
* submission,
|
|
30
|
+
* )
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param formElementId
|
|
34
|
+
* @param formElements
|
|
35
|
+
* @param submission
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
function getRootElementValueById(formElementId, formElements, submission) {
|
|
39
|
+
for (const formElement of formElements) {
|
|
40
|
+
if (formElement.type === 'page' || formElement.type === 'section') {
|
|
41
|
+
const value = getRootElementValueById(formElementId, formElement.elements, submission);
|
|
42
|
+
if (value !== undefined) {
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (formElement.id === formElementId) {
|
|
47
|
+
return submission[formElement.name];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.getRootElementValueById = getRootElementValueById;
|
|
52
|
+
//# sourceMappingURL=submissionService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submissionService.js","sourceRoot":"","sources":["../src/submissionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,wDAAqC;AAErC;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,uBAAuB,CACrC,aAAqB,EACrB,YAAqC,EACrC,UAA0D;IAE1D,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE;QACtC,IAAI,WAAW,CAAC,IAAI,KAAK,MAAM,IAAI,WAAW,CAAC,IAAI,KAAK,SAAS,EAAE;YACjE,MAAM,KAAK,GAAG,uBAAuB,CACnC,aAAa,EACb,WAAW,CAAC,QAAQ,EACpB,UAAU,CACX,CAAA;YACD,IAAI,KAAK,KAAK,SAAS,EAAE;gBACvB,OAAO,KAAK,CAAA;aACb;SACF;aAAM,IAAI,WAAW,CAAC,EAAE,KAAK,aAAa,EAAE;YAC3C,OAAO,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;SACpC;KACF;AACH,CAAC;AAnBD,0DAmBC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\n\nexport * from './replaceCustomValues'\n\n/**\n * Takes a form element's id, the form elements and the submission data to\n * return a value from the submission.\n *\n * #### Example\n *\n * ```js\n * const value = formElementsService.getRootElementById(\n * formElementId,\n * form.elements,\n * submission,\n * )\n * ```\n *\n * @param formElementId\n * @param formElements\n * @param submission\n * @returns\n */\nexport function getRootElementValueById(\n formElementId: string,\n formElements: FormTypes.FormElement[],\n submission: SubmissionTypes.S3SubmissionData['submission'],\n): unknown {\n for (const formElement of formElements) {\n if (formElement.type === 'page' || formElement.type === 'section') {\n const value = getRootElementValueById(\n formElementId,\n formElement.elements,\n submission,\n )\n if (value !== undefined) {\n return value\n }\n } else if (formElement.id === formElementId) {\n return submission[formElement.name]\n }\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FormTypes, SubmissionEventTypes } from '@oneblink/types';
|
|
2
2
|
declare function toNamedElement(e: FormTypes.FormElement): FormTypes.FormElementWithName | undefined;
|
|
3
|
-
declare type NonNestedElementsFormElement = FormTypes.NonNestedElementsElement | FormTypes.FormElementWithForm;
|
|
3
|
+
export declare type NonNestedElementsFormElement = FormTypes.NonNestedElementsElement | FormTypes.FormElementWithForm;
|
|
4
4
|
declare const formElements: {
|
|
5
5
|
toOptionsElement: (e: FormTypes.FormElement) => FormTypes.FormElementWithOptions | undefined;
|
|
6
6
|
toFormElementWithForm: (e: FormTypes.FormElement) => FormTypes.FormElementWithForm | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeCastService.js","sourceRoot":"","sources":["../src/typeCastService.ts"],"names":[],"mappings":";;;AAEA,MAAM,gBAAgB,GAAG,CACvB,CAAwB,EACsB,EAAE;IAChD,QAAQ,CAAC,CAAC,IAAI,EAAE;QACd,KAAK,QAAQ,CAAC;QACd,KAAK,YAAY,CAAC;QAClB,KAAK,OAAO,CAAC;QACb,KAAK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,sBAAsB,GAAG,CAC7B,CAAwB,EACoB,EAAE;IAC9C,QAAQ,CAAC,CAAC,IAAI,EAAE;QACd,KAAK,eAAe,CAAC,CAAC;YACpB,OAAO,CAAC,CAAA;SACT;QACD,OAAO,CAAC,CAAC;YACP,OAAM;SACP;KACF;AACH,CAAC,CAAA;AAED,MAAM,gBAAgB,GAAG,CACvB,CAAwB,EACc,EAAE;IACxC,QAAQ,CAAC,CAAC,IAAI,EAAE;QACd,KAAK,OAAO,CAAC;QACb,KAAK,MAAM,CAAC;QACZ,KAAK,YAAY,CAAC;QAClB,KAAK,QAAQ,CAAC,CAAC;YACb,OAAO,CAAC,CAAA;SACT;QACD,OAAO,CAAC,CAAC;YACP,OAAM;SACP;KACF;AACH,CAAC,CAAA;AAED,MAAM,YAAY,GAAG;IACnB,gBAAgB;IAChB,qBAAqB;IACrB,wBAAwB;IACxB,eAAe;IACf,uBAAuB;IACvB,iBAAiB;IACjB,cAAc;IACd,0BAA0B;IAC1B,aAAa;IACb,sBAAsB;IACtB,gBAAgB;CACjB,CAAA;AAqBQ,oCAAY;AAnBrB,MAAM,wBAAwB,GAAG,CAC/B,CAAiC,EACwB,EAAE;IAC3D,QAAQ,CAAC,CAAC,IAAI,EAAE;QACd,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ,CAAC;QACd,KAAK,mBAAmB,CAAC,CAAC;YACxB,OAAO,CAAC,CAAA;SACT;QACD,OAAO,CAAC,CAAC;YACP,OAAM;SACP;KACF;AACH,CAAC,CAAA;AAED,MAAM,gBAAgB,GAAG;IACvB,wBAAwB;CACzB,CAAA;AAEsB,4CAAgB","sourcesContent":["import { FormTypes, SubmissionEventTypes } from '@oneblink/types'\n\nconst toOptionsElement = (\n e: FormTypes.FormElement,\n): FormTypes.FormElementWithOptions | undefined => {\n switch (e.type) {\n case 'select':\n case 'compliance':\n case 'radio':\n case 'autocomplete':\n case 'checkboxes': {\n return e\n }\n default: {\n return\n }\n }\n}\n\nconst toFormElementWithForm = (\n e: FormTypes.FormElement,\n): FormTypes.FormElementWithForm | undefined => {\n switch (e.type) {\n case 'form':\n case 'infoPage': {\n return e\n }\n default: {\n return\n }\n }\n}\n\nconst toFormElementWithoutForm = (\n e: FormTypes.FormElement,\n): FormTypes.FormElementWithoutForm | undefined => {\n switch (e.type) {\n case 'form':\n case 'infoPage': {\n return\n }\n default: {\n return e\n }\n }\n}\n\nconst toLookupElement = (\n e: FormTypes.FormElement,\n): FormTypes.LookupFormElement | undefined => {\n switch (e.type) {\n case 'boolean':\n case 'checkboxes':\n case 'date':\n case 'datetime':\n case 'files':\n case 'location':\n case 'number':\n case 'compliance':\n case 'radio':\n case 'select':\n case 'text':\n case 'textarea':\n case 'time':\n case 'barcodeScanner':\n case 'email':\n case 'telephone':\n case 'pointAddress':\n case 'geoscapeAddress':\n case 'civicaStreetName':\n case 'bsb':\n case 'autocomplete':\n case 'abn': {\n return e\n }\n default: {\n return\n }\n }\n}\n\nconst toNestedElementsElement = (\n e: FormTypes.FormElement,\n): FormTypes.NestedElementsElement | undefined => {\n switch (e.type) {\n case 'repeatableSet':\n case 'section':\n case 'page': {\n return e\n }\n default: {\n return\n }\n }\n}\n\nconst toNamelessElement = (\n e: FormTypes.FormElement,\n): FormTypes.FormElementWithoutName | undefined => {\n switch (e.type) {\n case 'section':\n case 'page': {\n return e\n }\n default: {\n return\n }\n }\n}\n\nfunction toNamedElement(\n e: FormTypes.FormElement,\n): FormTypes.FormElementWithName | undefined {\n switch (e.type) {\n case 'page':\n case 'section': {\n return undefined\n }\n default: {\n return e\n }\n }\n}\n\
|
|
1
|
+
{"version":3,"file":"typeCastService.js","sourceRoot":"","sources":["../src/typeCastService.ts"],"names":[],"mappings":";;;AAEA,MAAM,gBAAgB,GAAG,CACvB,CAAwB,EACsB,EAAE;IAChD,QAAQ,CAAC,CAAC,IAAI,EAAE;QACd,KAAK,QAAQ,CAAC;QACd,KAAK,YAAY,CAAC;QAClB,KAAK,OAAO,CAAC;QACb,KAAK,cAAc,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B,GAAG,CAC7B,CAAwB,EACoB,EAAE;IAC9C,QAAQ,CAAC,CAAC,IAAI,EAAE;QACd,KAAK,eAAe,CAAC,CAAC;YACpB,OAAO,CAAC,CAAA;SACT;QACD,OAAO,CAAC,CAAC;YACP,OAAM;SACP;KACF;AACH,CAAC,CAAA;AAED,MAAM,gBAAgB,GAAG,CACvB,CAAwB,EACc,EAAE;IACxC,QAAQ,CAAC,CAAC,IAAI,EAAE;QACd,KAAK,OAAO,CAAC;QACb,KAAK,MAAM,CAAC;QACZ,KAAK,YAAY,CAAC;QAClB,KAAK,QAAQ,CAAC,CAAC;YACb,OAAO,CAAC,CAAA;SACT;QACD,OAAO,CAAC,CAAC;YACP,OAAM;SACP;KACF;AACH,CAAC,CAAA;AAED,MAAM,YAAY,GAAG;IACnB,gBAAgB;IAChB,qBAAqB;IACrB,wBAAwB;IACxB,eAAe;IACf,uBAAuB;IACvB,iBAAiB;IACjB,cAAc;IACd,0BAA0B;IAC1B,aAAa;IACb,sBAAsB;IACtB,gBAAgB;CACjB,CAAA;AAqBQ,oCAAY;AAnBrB,MAAM,wBAAwB,GAAG,CAC/B,CAAiC,EACwB,EAAE;IAC3D,QAAQ,CAAC,CAAC,IAAI,EAAE;QACd,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ,CAAC;QACd,KAAK,mBAAmB,CAAC,CAAC;YACxB,OAAO,CAAC,CAAA;SACT;QACD,OAAO,CAAC,CAAC;YACP,OAAM;SACP;KACF;AACH,CAAC,CAAA;AAED,MAAM,gBAAgB,GAAG;IACvB,wBAAwB;CACzB,CAAA;AAEsB,4CAAgB","sourcesContent":["import { FormTypes, SubmissionEventTypes } from '@oneblink/types'\n\nconst toOptionsElement = (\n e: FormTypes.FormElement,\n): FormTypes.FormElementWithOptions | undefined => {\n switch (e.type) {\n case 'select':\n case 'compliance':\n case 'radio':\n case 'autocomplete':\n case 'checkboxes': {\n return e\n }\n default: {\n return\n }\n }\n}\n\nconst toFormElementWithForm = (\n e: FormTypes.FormElement,\n): FormTypes.FormElementWithForm | undefined => {\n switch (e.type) {\n case 'form':\n case 'infoPage': {\n return e\n }\n default: {\n return\n }\n }\n}\n\nconst toFormElementWithoutForm = (\n e: FormTypes.FormElement,\n): FormTypes.FormElementWithoutForm | undefined => {\n switch (e.type) {\n case 'form':\n case 'infoPage': {\n return\n }\n default: {\n return e\n }\n }\n}\n\nconst toLookupElement = (\n e: FormTypes.FormElement,\n): FormTypes.LookupFormElement | undefined => {\n switch (e.type) {\n case 'boolean':\n case 'checkboxes':\n case 'date':\n case 'datetime':\n case 'files':\n case 'location':\n case 'number':\n case 'compliance':\n case 'radio':\n case 'select':\n case 'text':\n case 'textarea':\n case 'time':\n case 'barcodeScanner':\n case 'email':\n case 'telephone':\n case 'pointAddress':\n case 'geoscapeAddress':\n case 'civicaStreetName':\n case 'bsb':\n case 'autocomplete':\n case 'abn': {\n return e\n }\n default: {\n return\n }\n }\n}\n\nconst toNestedElementsElement = (\n e: FormTypes.FormElement,\n): FormTypes.NestedElementsElement | undefined => {\n switch (e.type) {\n case 'repeatableSet':\n case 'section':\n case 'page': {\n return e\n }\n default: {\n return\n }\n }\n}\n\nconst toNamelessElement = (\n e: FormTypes.FormElement,\n): FormTypes.FormElementWithoutName | undefined => {\n switch (e.type) {\n case 'section':\n case 'page': {\n return e\n }\n default: {\n return\n }\n }\n}\n\nfunction toNamedElement(\n e: FormTypes.FormElement,\n): FormTypes.FormElementWithName | undefined {\n switch (e.type) {\n case 'page':\n case 'section': {\n return undefined\n }\n default: {\n return e\n }\n }\n}\n\nexport type NonNestedElementsFormElement =\n | FormTypes.NonNestedElementsElement\n | FormTypes.FormElementWithForm\nconst toNonNestedElementsElement = (\n e: FormTypes.FormElement,\n): NonNestedElementsFormElement | undefined => {\n switch (e.type) {\n case 'repeatableSet':\n case 'section':\n case 'page': {\n return\n }\n default: {\n return e\n }\n }\n}\n\nconst toPageElement = (\n e: FormTypes.FormElement,\n): FormTypes.PageElement | undefined => {\n switch (e.type) {\n case 'page': {\n return e\n }\n default: {\n return\n }\n }\n}\n\nconst toRepeatableSetElement = (\n e: FormTypes.FormElement,\n): FormTypes.RepeatableSetElement | undefined => {\n switch (e.type) {\n case 'repeatableSet': {\n return e\n }\n default: {\n return\n }\n }\n}\n\nconst toStorageElement = (\n e: FormTypes.FormElement,\n): FormTypes.StorageElement | undefined => {\n switch (e.type) {\n case 'files':\n case 'draw':\n case 'compliance':\n case 'camera': {\n return e\n }\n default: {\n return\n }\n }\n}\n\nconst formElements = {\n toOptionsElement,\n toFormElementWithForm,\n toFormElementWithoutForm,\n toLookupElement,\n toNestedElementsElement,\n toNamelessElement,\n toNamedElement,\n toNonNestedElementsElement,\n toPageElement,\n toRepeatableSetElement,\n toStorageElement,\n}\n\nconst toPaymentSubmissionEvent = (\n e: SubmissionEventTypes.FormEvent,\n): SubmissionEventTypes.PaymentSubmissionEvent | undefined => {\n switch (e.type) {\n case 'BPOINT':\n case 'CP_PAY':\n case 'WESTPAC_QUICK_WEB': {\n return e\n }\n default: {\n return\n }\n }\n}\n\nconst submissionEvents = {\n toPaymentSubmissionEvent,\n}\n\nexport { formElements, submissionEvents }\n"]}
|
package/dist/typedoc.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./index"), exports);
|
|
18
|
+
__exportStar(require("@oneblink/types"), exports);
|
|
19
|
+
//# sourceMappingURL=typedoc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typedoc.js","sourceRoot":"","sources":["../src/typedoc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,kDAA+B","sourcesContent":["export * from './index'\nexport * from '@oneblink/types'\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,17 +3,3 @@ export declare type FormElementsCtrl = {
|
|
|
3
3
|
flattenedElements: import('@oneblink/types').FormTypes.FormElement[];
|
|
4
4
|
parentFormElementsCtrl?: FormElementsCtrl;
|
|
5
5
|
};
|
|
6
|
-
export declare type FormElementsConditionallyShown = Record<string, FormElementConditionallyShown>;
|
|
7
|
-
export declare type FormElementConditionallyShown = undefined | {
|
|
8
|
-
type: 'formElement';
|
|
9
|
-
isHidden: boolean;
|
|
10
|
-
options?: import('@oneblink/types').FormTypes.ChoiceElementOption[];
|
|
11
|
-
} | {
|
|
12
|
-
type: 'formElements';
|
|
13
|
-
isHidden: boolean;
|
|
14
|
-
formElements: FormElementsConditionallyShown | undefined;
|
|
15
|
-
} | {
|
|
16
|
-
type: 'repeatableSet';
|
|
17
|
-
isHidden: boolean;
|
|
18
|
-
entries: Record<string, FormElementsConditionallyShown | undefined>;
|
|
19
|
-
};
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"","sourcesContent":["export type FormElementsCtrl = {\n model: Record<string, unknown>\n flattenedElements: import('@oneblink/types').FormTypes.FormElement[]\n parentFormElementsCtrl?: FormElementsCtrl\n}\n
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"","sourcesContent":["export type FormElementsCtrl = {\n model: Record<string, unknown>\n flattenedElements: import('@oneblink/types').FormTypes.FormElement[]\n parentFormElementsCtrl?: FormElementsCtrl\n}\n"]}
|
package/dist/userService.d.ts
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
1
|
import { MiscTypes } from '@oneblink/types';
|
|
2
|
+
/**
|
|
3
|
+
* Parse a User Profile based on a JWT payload. Will return `undefined` if not a
|
|
4
|
+
* valid JWT payload
|
|
5
|
+
*
|
|
6
|
+
* #### Example
|
|
7
|
+
*
|
|
8
|
+
* ```js
|
|
9
|
+
* import jwtDecode from 'jwt-decode'
|
|
10
|
+
*
|
|
11
|
+
* const jwtPayload = jwtDecode('a valid token from a user')
|
|
12
|
+
* const userProfile = userService.parseUserProfile(jwtPayload)
|
|
13
|
+
* if (userProfile) {
|
|
14
|
+
* // continue
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param data An object containing all parameters to be passed to the function
|
|
19
|
+
*/
|
|
2
20
|
export declare function parseUserProfile(data: unknown): MiscTypes.UserProfile | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* A friendly `string` that represents the a [User Profile](#user-profile). Uses
|
|
23
|
+
* first name, last name, full name, email address or username.
|
|
24
|
+
*
|
|
25
|
+
* #### Example
|
|
26
|
+
*
|
|
27
|
+
* ```js
|
|
28
|
+
* const userProfile = userService.parseUserProfile(jwtPayload)
|
|
29
|
+
* const name = userService.getUserFriendlyName(userProfile)
|
|
30
|
+
* if (name) {
|
|
31
|
+
* // Display current user's name
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @param userProfile
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
3
38
|
export declare function getUserFriendlyName(userProfile: MiscTypes.UserProfile): string;
|
package/dist/userService.js
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getUserFriendlyName = exports.parseUserProfile = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Parse a User Profile based on a JWT payload. Will return `undefined` if not a
|
|
6
|
+
* valid JWT payload
|
|
7
|
+
*
|
|
8
|
+
* #### Example
|
|
9
|
+
*
|
|
10
|
+
* ```js
|
|
11
|
+
* import jwtDecode from 'jwt-decode'
|
|
12
|
+
*
|
|
13
|
+
* const jwtPayload = jwtDecode('a valid token from a user')
|
|
14
|
+
* const userProfile = userService.parseUserProfile(jwtPayload)
|
|
15
|
+
* if (userProfile) {
|
|
16
|
+
* // continue
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @param data An object containing all parameters to be passed to the function
|
|
21
|
+
*/
|
|
4
22
|
function parseUserProfile(data) {
|
|
5
23
|
var _a, _b, _c;
|
|
6
24
|
if (typeof data !== 'object' || !data) {
|
|
@@ -59,6 +77,23 @@ function parseUserProfile(data) {
|
|
|
59
77
|
return userProfile;
|
|
60
78
|
}
|
|
61
79
|
exports.parseUserProfile = parseUserProfile;
|
|
80
|
+
/**
|
|
81
|
+
* A friendly `string` that represents the a [User Profile](#user-profile). Uses
|
|
82
|
+
* first name, last name, full name, email address or username.
|
|
83
|
+
*
|
|
84
|
+
* #### Example
|
|
85
|
+
*
|
|
86
|
+
* ```js
|
|
87
|
+
* const userProfile = userService.parseUserProfile(jwtPayload)
|
|
88
|
+
* const name = userService.getUserFriendlyName(userProfile)
|
|
89
|
+
* if (name) {
|
|
90
|
+
* // Display current user's name
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @param userProfile
|
|
95
|
+
* @returns
|
|
96
|
+
*/
|
|
62
97
|
function getUserFriendlyName(userProfile) {
|
|
63
98
|
if (userProfile.fullName) {
|
|
64
99
|
return userProfile.fullName;
|
package/dist/userService.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userService.js","sourceRoot":"","sources":["../src/userService.ts"],"names":[],"mappings":";;;AAEA,SAAgB,gBAAgB,CAC9B,IAAa;;IAEb,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,EAAE;QACrC,OAAM;KACP;IACD,MAAM,UAAU,GAAG,IAA+B,CAAA;IAClD,IAAI,OAAO,UAAU,CAAC,GAAG,KAAK,QAAQ,EAAE;QACtC,OAAM;KACP;IACD,MAAM,WAAW,GAA0B;QACzC,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,SAAS;QACvB,cAAc,EAAE,UAAU,CAAC,GAAG;QAC9B,MAAM,EAAE,UAAU,CAAC,GAAG;QACtB,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;QAC1E,SAAS,EACP,OAAO,UAAU,CAAC,UAAU,KAAK,QAAQ;YACvC,CAAC,CAAC,UAAU,CAAC,UAAU;YACvB,CAAC,CAAC,SAAS;QACf,QAAQ,EACN,OAAO,UAAU,CAAC,WAAW,KAAK,QAAQ;YACxC,CAAC,CAAC,UAAU,CAAC,WAAW;YACxB,CAAC,CAAC,SAAS;QACf,QAAQ,EAAE,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;QAC3E,OAAO,EACL,OAAO,UAAU,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;QACzE,IAAI,EACF,OAAO,UAAU,CAAC,aAAa,CAAC,KAAK,QAAQ;YAC3C,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC;YAC3B,CAAC,CAAC,SAAS;QACf,QAAQ,EACN,OAAO,UAAU,CAAC,K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/D;KACF;IAED,OAAO,WAAW,CAAA;AACpB,CAAC;AAxED,4CAwEC;AAED,SAAgB,mBAAmB,CACjC,WAAkC;IAElC,IAAI,WAAW,CAAC,QAAQ,EAAE;QACxB,OAAO,WAAW,CAAC,QAAQ,CAAA;KAC5B;IAED,IAAI,WAAW,CAAC,SAAS,IAAI,WAAW,CAAC,QAAQ,EAAE;QACjD,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;KACtE;IAED,IAAI,WAAW,CAAC,KAAK,EAAE;QACrB,OAAO,WAAW,CAAC,KAAK,CAAA;KACzB;IAED,IAAI,WAAW,CAAC,QAAQ,EAAE;QACxB,OAAO,WAAW,CAAC,QAAQ,CAAA;KAC5B;IAED,OAAO,WAAW,CAAC,MAAM,CAAA;AAC3B,CAAC;AApBD,kDAoBC","sourcesContent":["import { MiscTypes } from '@oneblink/types'\n\nexport function parseUserProfile(\n data: unknown,\n): MiscTypes.UserProfile | undefined {\n if (typeof data !== 'object' || !data) {\n return\n }\n const jwtPayload = data as Record<string, unknown>\n if (typeof jwtPayload.sub !== 'string') {\n return\n }\n const userProfile: MiscTypes.UserProfile = {\n isSAMLUser: false,\n providerType: 'Cognito',\n providerUserId: jwtPayload.sub,\n userId: jwtPayload.sub,\n email: typeof jwtPayload.email === 'string' ? jwtPayload.email : undefined,\n firstName:\n typeof jwtPayload.given_name === 'string'\n ? jwtPayload.given_name\n : undefined,\n lastName:\n typeof jwtPayload.family_name === 'string'\n ? jwtPayload.family_name\n : undefined,\n fullName: typeof jwtPayload.name === 'string' ? jwtPayload.name : undefined,\n picture:\n typeof jwtPayload.picture === 'string' ? jwtPayload.picture : undefined,\n role:\n typeof jwtPayload['custom:role'] === 'string'\n ? jwtPayload['custom:role']\n : undefined,\n username:\n typeof jwtPayload.email === 'string' ? jwtPayload.email : jwtPayload.sub,\n supervisor: {\n fullName:\n typeof jwtPayload['custom:supervisor_name'] === 'string'\n ? jwtPayload['custom:supervisor_name']\n : undefined,\n email:\n typeof jwtPayload['custom:supervisor_email'] === 'string'\n ? jwtPayload['custom:supervisor_email']\n : undefined,\n providerUserId:\n typeof jwtPayload['custom:supervisor_user_id'] === 'string'\n ? jwtPayload['custom:supervisor_user_id']\n : undefined,\n },\n }\n\n if (\n !userProfile.supervisor?.fullName &&\n !userProfile.supervisor?.email &&\n !userProfile.supervisor?.providerUserId\n ) {\n userProfile.supervisor = undefined\n }\n\n if (\n jwtPayload.identities &&\n Array.isArray(jwtPayload.identities) &&\n jwtPayload.identities.length\n ) {\n const { providerType, userId } = jwtPayload.identities[0]\n userProfile.providerType = providerType\n userProfile.providerUserId = userId\n userProfile.isSAMLUser = providerType === 'SAML'\n if (userProfile.isSAMLUser) {\n userProfile.username = jwtPayload.preferred_username || userId\n }\n }\n\n return userProfile\n}\n\nexport function getUserFriendlyName(\n userProfile: MiscTypes.UserProfile,\n): string {\n if (userProfile.fullName) {\n return userProfile.fullName\n }\n\n if (userProfile.firstName || userProfile.lastName) {\n return [userProfile.firstName, userProfile.lastName].join(' ').trim()\n }\n\n if (userProfile.email) {\n return userProfile.email\n }\n\n if (userProfile.username) {\n return userProfile.username\n }\n\n return userProfile.userId\n}\n"]}
|
|
1
|
+
{"version":3,"file":"userService.js","sourceRoot":"","sources":["../src/userService.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,gBAAgB,CAC9B,IAAa;;IAEb,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,EAAE;QACrC,OAAM;KACP;IACD,MAAM,UAAU,GAAG,IAA+B,CAAA;IAClD,IAAI,OAAO,UAAU,CAAC,GAAG,KAAK,QAAQ,EAAE;QACtC,OAAM;KACP;IACD,MAAM,WAAW,GAA0B;QACzC,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,SAAS;QACvB,cAAc,EAAE,UAAU,CAAC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AC,KAAK,CAAA;KACzB;IAED,IAAI,WAAW,CAAC,QAAQ,EAAE;QACxB,OAAO,WAAW,CAAC,QAAQ,CAAA;KAC5B;IAED,OAAO,WAAW,CAAC,MAAM,CAAA;AAC3B,CAAC;AApBD,kDAoBC","sourcesContent":["import { MiscTypes } from '@oneblink/types'\n\n/**\n * Parse a User Profile based on a JWT payload. Will return `undefined` if not a\n * valid JWT payload\n *\n * #### Example\n *\n * ```js\n * import jwtDecode from 'jwt-decode'\n *\n * const jwtPayload = jwtDecode('a valid token from a user')\n * const userProfile = userService.parseUserProfile(jwtPayload)\n * if (userProfile) {\n * // continue\n * }\n * ```\n *\n * @param data An object containing all parameters to be passed to the function\n */\nexport function parseUserProfile(\n data: unknown,\n): MiscTypes.UserProfile | undefined {\n if (typeof data !== 'object' || !data) {\n return\n }\n const jwtPayload = data as Record<string, unknown>\n if (typeof jwtPayload.sub !== 'string') {\n return\n }\n const userProfile: MiscTypes.UserProfile = {\n isSAMLUser: false,\n providerType: 'Cognito',\n providerUserId: jwtPayload.sub,\n userId: jwtPayload.sub,\n email: typeof jwtPayload.email === 'string' ? jwtPayload.email : undefined,\n firstName:\n typeof jwtPayload.given_name === 'string'\n ? jwtPayload.given_name\n : undefined,\n lastName:\n typeof jwtPayload.family_name === 'string'\n ? jwtPayload.family_name\n : undefined,\n fullName: typeof jwtPayload.name === 'string' ? jwtPayload.name : undefined,\n picture:\n typeof jwtPayload.picture === 'string' ? jwtPayload.picture : undefined,\n role:\n typeof jwtPayload['custom:role'] === 'string'\n ? jwtPayload['custom:role']\n : undefined,\n username:\n typeof jwtPayload.email === 'string' ? jwtPayload.email : jwtPayload.sub,\n supervisor: {\n fullName:\n typeof jwtPayload['custom:supervisor_name'] === 'string'\n ? jwtPayload['custom:supervisor_name']\n : undefined,\n email:\n typeof jwtPayload['custom:supervisor_email'] === 'string'\n ? jwtPayload['custom:supervisor_email']\n : undefined,\n providerUserId:\n typeof jwtPayload['custom:supervisor_user_id'] === 'string'\n ? jwtPayload['custom:supervisor_user_id']\n : undefined,\n },\n }\n\n if (\n !userProfile.supervisor?.fullName &&\n !userProfile.supervisor?.email &&\n !userProfile.supervisor?.providerUserId\n ) {\n userProfile.supervisor = undefined\n }\n\n if (\n jwtPayload.identities &&\n Array.isArray(jwtPayload.identities) &&\n jwtPayload.identities.length\n ) {\n const { providerType, userId } = jwtPayload.identities[0]\n userProfile.providerType = providerType\n userProfile.providerUserId = userId\n userProfile.isSAMLUser = providerType === 'SAML'\n if (userProfile.isSAMLUser) {\n userProfile.username = jwtPayload.preferred_username || userId\n }\n }\n\n return userProfile\n}\n\n/**\n * A friendly `string` that represents the a [User Profile](#user-profile). Uses\n * first name, last name, full name, email address or username.\n *\n * #### Example\n *\n * ```js\n * const userProfile = userService.parseUserProfile(jwtPayload)\n * const name = userService.getUserFriendlyName(userProfile)\n * if (name) {\n * // Display current user's name\n * }\n * ```\n *\n * @param userProfile\n * @returns\n */\nexport function getUserFriendlyName(\n userProfile: MiscTypes.UserProfile,\n): string {\n if (userProfile.fullName) {\n return userProfile.fullName\n }\n\n if (userProfile.firstName || userProfile.lastName) {\n return [userProfile.firstName, userProfile.lastName].join(' ').trim()\n }\n\n if (userProfile.email) {\n return userProfile.email\n }\n\n if (userProfile.username) {\n return userProfile.username\n }\n\n return userProfile.userId\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneblink/sdk-core",
|
|
3
3
|
"description": "OneBlink SDK for JavaScript (works in Browsers and NodeJS)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0-beta.2",
|
|
5
5
|
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/oneblink/sdk-core-js/issues"
|
|
@@ -9,18 +9,20 @@
|
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@oneblink/release-cli": "^1.0.0",
|
|
11
11
|
"@oneblink/types": "github:oneblink/types",
|
|
12
|
-
"@types/jest": "^27.
|
|
13
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
14
|
-
"@typescript-eslint/parser": "^
|
|
15
|
-
"eslint": "^
|
|
16
|
-
"eslint-config-prettier": "^8.
|
|
12
|
+
"@types/jest": "^27.4.1",
|
|
13
|
+
"@typescript-eslint/eslint-plugin": "^5.19.0",
|
|
14
|
+
"@typescript-eslint/parser": "^5.19.0",
|
|
15
|
+
"eslint": "^8.13.0",
|
|
16
|
+
"eslint-config-prettier": "^8.5.0",
|
|
17
17
|
"eslint-plugin-prettier": "^4.0.0",
|
|
18
18
|
"fixpack": "^4.0.0",
|
|
19
|
-
"jest": "^27.1
|
|
20
|
-
"prettier": "^2.
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
19
|
+
"jest": "^27.5.1",
|
|
20
|
+
"prettier": "^2.6.2",
|
|
21
|
+
"prettier-plugin-jsdoc": "^0.3.38",
|
|
22
|
+
"ts-jest": "^27.1.4",
|
|
23
|
+
"tsc-watch": "^5.0.3",
|
|
24
|
+
"typedoc": "^0.22.15",
|
|
25
|
+
"typescript": "^4.6.3"
|
|
24
26
|
},
|
|
25
27
|
"directories": {
|
|
26
28
|
"doc": "docs"
|
|
@@ -46,12 +48,13 @@
|
|
|
46
48
|
},
|
|
47
49
|
"scripts": {
|
|
48
50
|
"build": "tsc",
|
|
51
|
+
"docs": "typedoc",
|
|
49
52
|
"eslint": "eslint --fix --cache .",
|
|
50
53
|
"fixpack": "fixpack",
|
|
51
54
|
"format": "prettier --write .",
|
|
52
55
|
"prepare": "npm run build",
|
|
53
56
|
"pretest": "npm run fixpack && npm run eslint",
|
|
54
|
-
"release": "oneblink-release",
|
|
57
|
+
"release": "typedoc && oneblink-release",
|
|
55
58
|
"start": "tsc-watch",
|
|
56
59
|
"test": "jest",
|
|
57
60
|
"types": "npm install --save-dev github:oneblink/types",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { FormTypes, ConditionTypes, SubmissionTypes } from '@oneblink/types';
|
|
2
|
-
declare function evaluateConditionalOptionsPredicate({ predicate, predicateElement, submission, }: {
|
|
3
|
-
predicate: ConditionTypes.ConditionalPredicateOptions;
|
|
4
|
-
submission: SubmissionTypes.S3SubmissionData['submission'];
|
|
5
|
-
predicateElement: FormTypes.FormElementWithOptions;
|
|
6
|
-
}): boolean;
|
|
7
|
-
declare function evaluateConditionalPredicate({ predicate, predicateElement, submission, }: {
|
|
8
|
-
predicate: ConditionTypes.ConditionalPredicate;
|
|
9
|
-
predicateElement: FormTypes.FormElement;
|
|
10
|
-
submission: SubmissionTypes.S3SubmissionData['submission'];
|
|
11
|
-
}): boolean;
|
|
12
|
-
declare function evaluateConditionalPredicates({ isConditional, requiresAllConditionalPredicates, conditionalPredicates, formElements, submission, }: {
|
|
13
|
-
isConditional: boolean;
|
|
14
|
-
requiresAllConditionalPredicates: boolean;
|
|
15
|
-
conditionalPredicates: ConditionTypes.ConditionalPredicate[];
|
|
16
|
-
formElements: FormTypes.FormElement[];
|
|
17
|
-
submission: SubmissionTypes.S3SubmissionData['submission'];
|
|
18
|
-
}): boolean;
|
|
19
|
-
export { evaluateConditionalOptionsPredicate, evaluateConditionalPredicate, evaluateConditionalPredicates, };
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluateConditionalPredicates = exports.evaluateConditionalPredicate = exports.evaluateConditionalOptionsPredicate = void 0;
|
|
4
|
-
const fnMap = {
|
|
5
|
-
'>': (lhs, rhs) => lhs > rhs,
|
|
6
|
-
'>=': (lhs, rhs) => lhs >= rhs,
|
|
7
|
-
'===': (lhs, rhs) => lhs === rhs,
|
|
8
|
-
'!==': (lhs, rhs) => lhs !== rhs,
|
|
9
|
-
'<=': (lhs, rhs) => lhs <= rhs,
|
|
10
|
-
'<': (lhs, rhs) => lhs < rhs,
|
|
11
|
-
};
|
|
12
|
-
function evaluateConditionalOptionsPredicate({ predicate, predicateElement, submission, }) {
|
|
13
|
-
return predicate.optionIds.some((optionId) => {
|
|
14
|
-
var _a;
|
|
15
|
-
const option = (_a = predicateElement.options) === null || _a === void 0 ? void 0 : _a.find((o) => o.id === optionId);
|
|
16
|
-
if (option) {
|
|
17
|
-
const value = submission[predicateElement.name];
|
|
18
|
-
if (Array.isArray(value)) {
|
|
19
|
-
return value.some((modelValue) => {
|
|
20
|
-
return modelValue === option.value;
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
else if (predicateElement.type === 'compliance' && value) {
|
|
24
|
-
return option.value === value.value;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
return option.value === value;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
exports.evaluateConditionalOptionsPredicate = evaluateConditionalOptionsPredicate;
|
|
36
|
-
function evaluateConditionalPredicate({ predicate, predicateElement, submission, }) {
|
|
37
|
-
if (!predicateElement ||
|
|
38
|
-
predicateElement.type === 'page' ||
|
|
39
|
-
predicateElement.type === 'section') {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
switch (predicate.type) {
|
|
43
|
-
case 'VALUE': {
|
|
44
|
-
return !predicate.hasValue === !submission[predicateElement.name];
|
|
45
|
-
}
|
|
46
|
-
case 'NUMERIC': {
|
|
47
|
-
const lhs = Number.parseFloat(submission[predicateElement.name]);
|
|
48
|
-
const rhs = typeof predicate.value === 'string'
|
|
49
|
-
? Number.parseFloat(predicate.value)
|
|
50
|
-
: predicate.value;
|
|
51
|
-
// if either of the values is not a number or the operator fn doesn't exist, hide the control
|
|
52
|
-
const operatorFn = fnMap[predicate.operator];
|
|
53
|
-
if (!operatorFn || Number.isNaN(lhs) || Number.isNaN(rhs))
|
|
54
|
-
return false;
|
|
55
|
-
return operatorFn(lhs, rhs);
|
|
56
|
-
}
|
|
57
|
-
case 'BETWEEN': {
|
|
58
|
-
const value = Number.parseFloat(submission[predicateElement.name]);
|
|
59
|
-
if (Number.isNaN(value)) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
return value >= predicate.min && value <= predicate.max;
|
|
63
|
-
}
|
|
64
|
-
case 'OPTIONS':
|
|
65
|
-
default: {
|
|
66
|
-
if (predicateElement.type !== 'select' &&
|
|
67
|
-
predicateElement.type !== 'autocomplete' &&
|
|
68
|
-
predicateElement.type !== 'radio' &&
|
|
69
|
-
predicateElement.type !== 'checkboxes' &&
|
|
70
|
-
predicateElement.type !== 'compliance') {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
// If the predicate element does not have any options to evaluate,
|
|
74
|
-
// we will show the element.
|
|
75
|
-
// Unless the predicate element has dynamic options and
|
|
76
|
-
// options have not been fetched yet.
|
|
77
|
-
if (!Array.isArray(predicateElement.options)) {
|
|
78
|
-
return predicateElement.optionsType !== 'DYNAMIC';
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
return evaluateConditionalOptionsPredicate({
|
|
82
|
-
predicate,
|
|
83
|
-
submission,
|
|
84
|
-
predicateElement,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
exports.evaluateConditionalPredicate = evaluateConditionalPredicate;
|
|
91
|
-
const getPredicateElement = (elements, elementId) => {
|
|
92
|
-
for (const element of elements) {
|
|
93
|
-
if (element.type === 'page' || element.type === 'section') {
|
|
94
|
-
const predicateElement = getPredicateElement(element.elements, elementId);
|
|
95
|
-
if (predicateElement) {
|
|
96
|
-
return predicateElement;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
else if (element.id === elementId) {
|
|
100
|
-
return element;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
function evaluateConditionalPredicates({ isConditional, requiresAllConditionalPredicates, conditionalPredicates, formElements, submission, }) {
|
|
105
|
-
if (!isConditional || !conditionalPredicates.length) {
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
const predicateResults = [];
|
|
109
|
-
for (const predicate of conditionalPredicates) {
|
|
110
|
-
const predicateElement = getPredicateElement(formElements, predicate.elementId);
|
|
111
|
-
if (!predicateElement) {
|
|
112
|
-
throw new Error('Could not find element referenced in execution condition');
|
|
113
|
-
}
|
|
114
|
-
const predicateIsSatisfied = evaluateConditionalPredicate({
|
|
115
|
-
predicate,
|
|
116
|
-
predicateElement,
|
|
117
|
-
submission,
|
|
118
|
-
});
|
|
119
|
-
predicateResults.push(predicateIsSatisfied);
|
|
120
|
-
if (requiresAllConditionalPredicates) {
|
|
121
|
-
if (!predicateIsSatisfied)
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
// Doesn't require all predicates
|
|
126
|
-
if (predicateIsSatisfied)
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (requiresAllConditionalPredicates) {
|
|
131
|
-
return !predicateResults.includes(false);
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
// Doesn't require all predicates
|
|
135
|
-
return predicateResults.includes(true);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
exports.evaluateConditionalPredicates = evaluateConditionalPredicates;
|
|
139
|
-
//# sourceMappingURL=evaluationService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"evaluationService.js","sourceRoot":"","sources":["../../src/conditionalLogicService/evaluationService.ts"],"names":[],"mappings":";;;AAEA,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,EAA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,IAAI,qBAAqB,EAAE;QAC7C,MAAM,gBAAgB,GAAG,mBAAmB,CAC1C,YAAY,EACZ,SAAS,CAAC,SAAS,CACpB,CAAA;QACD,IAAI,CAAC,gBAAgB,EAAE;YACrB,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAA;SACF;QAED,MAAM,oBAAoB,GAAG,4BAA4B,CAAC;YACxD,SAAS;YACT,gBAAgB;YAChB,UAAU;SACX,CAAC,CAAA;QACF,gBAAgB,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAA;QAC3C,IAAI,gCAAgC,EAAE;YACpC,IAAI,CAAC,oBAAoB;gBAAE,MAAK;SACjC;aAAM;YACL,iCAAiC;YACjC,IAAI,oBAAoB;gBAAE,MAAK;SAChC;KACF;IAED,IAAI,gCAAgC,EAAE;QACpC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;KACzC;SAAM;QACL,iCAAiC;QACjC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;KACvC;AACH,CAAC;AAOC,sEAA6B","sourcesContent":["import { FormTypes, ConditionTypes, SubmissionTypes } from '@oneblink/types'\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 evaluateConditionalOptionsPredicate({\n predicate,\n predicateElement,\n submission,\n}: {\n predicate: ConditionTypes.ConditionalPredicateOptions\n submission: SubmissionTypes.S3SubmissionData['submission']\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 const value = submission[predicateElement.name]\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\nfunction evaluateConditionalPredicate({\n predicate,\n predicateElement,\n submission,\n}: {\n predicate: ConditionTypes.ConditionalPredicate\n predicateElement: FormTypes.FormElement\n submission: SubmissionTypes.S3SubmissionData['submission']\n}): boolean {\n if (\n !predicateElement ||\n predicateElement.type === 'page' ||\n predicateElement.type === 'section'\n ) {\n return false\n }\n switch (predicate.type) {\n case 'VALUE': {\n return !predicate.hasValue === !submission[predicateElement.name]\n }\n case 'NUMERIC': {\n const lhs = Number.parseFloat(submission[predicateElement.name] as string)\n const rhs =\n typeof predicate.value === 'string'\n ? Number.parseFloat(predicate.value)\n : predicate.value\n\n // if either of the values is not a number or the operator fn doesn't exist, hide the control\n const operatorFn = fnMap[predicate.operator]\n if (!operatorFn || Number.isNaN(lhs) || Number.isNaN(rhs)) return false\n\n return operatorFn(lhs, rhs)\n }\n case 'BETWEEN': {\n const value = Number.parseFloat(\n submission[predicateElement.name] as string,\n )\n if (Number.isNaN(value)) {\n return false\n }\n\n return value >= predicate.min && value <= predicate.max\n }\n case 'OPTIONS':\n default: {\n if (\n predicateElement.type !== 'select' &&\n predicateElement.type !== 'autocomplete' &&\n predicateElement.type !== 'radio' &&\n predicateElement.type !== 'checkboxes' &&\n predicateElement.type !== 'compliance'\n ) {\n return false\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(predicateElement.options)) {\n return predicateElement.optionsType !== 'DYNAMIC'\n } else {\n return evaluateConditionalOptionsPredicate({\n predicate,\n submission,\n predicateElement,\n })\n }\n }\n }\n}\n\nconst getPredicateElement = (\n elements: Array<FormTypes.FormElement>,\n elementId: string,\n): FormTypes.FormElement | void => {\n for (const element of elements) {\n if (element.type === 'page' || element.type === 'section') {\n const predicateElement = getPredicateElement(element.elements, elementId)\n if (predicateElement) {\n return predicateElement\n }\n } else if (element.id === elementId) {\n return element\n }\n }\n}\n\nfunction 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\n const predicateResults = []\n for (const predicate of conditionalPredicates) {\n const predicateElement = getPredicateElement(\n formElements,\n predicate.elementId,\n )\n if (!predicateElement) {\n throw new Error(\n 'Could not find element referenced in execution condition',\n )\n }\n\n const predicateIsSatisfied = evaluateConditionalPredicate({\n predicate,\n predicateElement,\n submission,\n })\n predicateResults.push(predicateIsSatisfied)\n if (requiresAllConditionalPredicates) {\n if (!predicateIsSatisfied) break\n } else {\n // Doesn't require all predicates\n if (predicateIsSatisfied) break\n }\n }\n\n if (requiresAllConditionalPredicates) {\n return !predicateResults.includes(false)\n } else {\n // Doesn't require all predicates\n return predicateResults.includes(true)\n }\n}\n\n\n\nexport {\n evaluateConditionalOptionsPredicate,\n evaluateConditionalPredicate,\n evaluateConditionalPredicates,\n}\n"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generateFormElementsConditionallyShown = exports.evaluateConditionalPredicates = exports.evaluateConditionalPredicate = exports.evaluateConditionalOptionsPredicate = void 0;
|
|
7
|
-
var evaluationService_1 = require("./evaluationService");
|
|
8
|
-
Object.defineProperty(exports, "evaluateConditionalOptionsPredicate", { enumerable: true, get: function () { return evaluationService_1.evaluateConditionalOptionsPredicate; } });
|
|
9
|
-
Object.defineProperty(exports, "evaluateConditionalPredicate", { enumerable: true, get: function () { return evaluationService_1.evaluateConditionalPredicate; } });
|
|
10
|
-
Object.defineProperty(exports, "evaluateConditionalPredicates", { enumerable: true, get: function () { return evaluationService_1.evaluateConditionalPredicates; } });
|
|
11
|
-
var generateFormElementsConditionallyShown_1 = require("./generateFormElementsConditionallyShown");
|
|
12
|
-
Object.defineProperty(exports, "generateFormElementsConditionallyShown", { enumerable: true, get: function () { return __importDefault(generateFormElementsConditionallyShown_1).default; } });
|
|
13
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/conditionalLogicService/index.ts"],"names":[],"mappings":";;;;;;AAAA,yDAI4B;AAH1B,wIAAA,mCAAmC,OAAA;AACnC,iIAAA,4BAA4B,OAAA;AAC5B,kIAAA,6BAA6B,OAAA;AAG/B,mGAA4G;AAAnG,iLAAA,OAAO,OAA0C","sourcesContent":["export {\n evaluateConditionalOptionsPredicate,\n evaluateConditionalPredicate,\n evaluateConditionalPredicates,\n} from './evaluationService'\n\nexport { default as generateFormElementsConditionallyShown } from './generateFormElementsConditionallyShown'\n"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { FormTypes, SubmissionEventTypes } from '@oneblink/types';
|
|
2
|
-
export declare function validatePaymentAmount(definition: FormTypes.Form, submission: {
|
|
3
|
-
readonly [key: string]: unknown;
|
|
4
|
-
}): {
|
|
5
|
-
paymentSubmissionEvent: SubmissionEventTypes.PaymentSubmissionEvent;
|
|
6
|
-
amount: number;
|
|
7
|
-
} | undefined;
|