@oneblink/sdk-core 0.3.4-beta.2 → 0.3.6-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/formElementsService.d.ts +4 -1
- package/dist/formElementsService.js +15 -1
- package/dist/formElementsService.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/paymentAmountValidation.d.ts +7 -0
- package/dist/paymentAmountValidation.js +44 -0
- package/dist/paymentAmountValidation.js.map +1 -0
- package/dist/typeCastService.d.ts +3 -2
- package/dist/typeCastService.js +12 -0
- package/dist/typeCastService.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,4 +4,7 @@ declare function forEachFormElementWithOptions(elements: FormTypes.FormElement[]
|
|
|
4
4
|
declare function findFormElement(elements: FormTypes.FormElement[], predicate: (element: FormTypes.FormElement, elements: FormTypes.FormElement[]) => boolean, parentElements?: FormTypes.FormElement[]): FormTypes.FormElement | void;
|
|
5
5
|
declare function parseFormElementOptionsSet(data: unknown): FormTypes.ChoiceElementOption[];
|
|
6
6
|
declare function flattenFormElements(elements: FormTypes.FormElement[]): FormTypes.FormElement[];
|
|
7
|
-
|
|
7
|
+
declare function getRootElementValueById(formElementId: string, formElements: FormTypes.FormElement[], submission: {
|
|
8
|
+
readonly [key: string]: unknown;
|
|
9
|
+
}): unknown;
|
|
10
|
+
export { getRootElementValueById, forEachFormElement, forEachFormElementWithOptions, findFormElement, parseFormElementOptionsSet, flattenFormElements, };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flattenFormElements = exports.parseFormElementOptionsSet = exports.findFormElement = exports.forEachFormElementWithOptions = exports.forEachFormElement = void 0;
|
|
3
|
+
exports.flattenFormElements = exports.parseFormElementOptionsSet = exports.findFormElement = exports.forEachFormElementWithOptions = exports.forEachFormElement = exports.getRootElementValueById = void 0;
|
|
4
4
|
function forEachFormElement(elements, forEach) {
|
|
5
5
|
findFormElement(elements, (formElement, parentElements) => {
|
|
6
6
|
forEach(formElement, parentElements);
|
|
@@ -92,4 +92,18 @@ function flattenFormElements(elements) {
|
|
|
92
92
|
}, []);
|
|
93
93
|
}
|
|
94
94
|
exports.flattenFormElements = flattenFormElements;
|
|
95
|
+
function getRootElementValueById(formElementId, formElements, submission) {
|
|
96
|
+
for (const formElement of formElements) {
|
|
97
|
+
if (formElement.type === 'page' || formElement.type === 'section') {
|
|
98
|
+
const value = getRootElementValueById(formElementId, formElement.elements, submission);
|
|
99
|
+
if (value !== undefined) {
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else if (formElement.id === formElementId) {
|
|
104
|
+
return submission[formElement.name];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.getRootElementValueById = getRootElementValueById;
|
|
95
109
|
//# sourceMappingURL=formElementsService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formElementsService.js","sourceRoot":"","sources":["../src/formElementsService.ts"],"names":[],"mappings":";;;AAEA,SAAS,kBAAkB,CACzB,QAAiC,EACjC,OAGS;IAET,eAAe,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,cAAc,EAAE,EAAE;QACxD,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,CAAA;QACpC,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CAAA;AACJ,CAAC;
|
|
1
|
+
{"version":3,"file":"formElementsService.js","sourceRoot":"","sources":["../src/formElementsService.ts"],"names":[],"mappings":";;;AAEA,SAAS,kBAAkB,CACzB,QAAiC,EACjC,OAGS;IAET,eAAe,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,cAAc,EAAE,EAAE;QACxD,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,CAAA;QACpC,OAAO,KAAK,CAAA;IACd,CAAC,CAAC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1B,QAAiC;IAEjC,OAAO,QAAQ,CAAC,MAAM,CACpB,CAAC,iBAAiB,EAAE,OAAO,EAAE,EAAE;QAC7B,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC/B,QAAQ,OAAO,CAAC,IAAI,EAAE;YACpB,KAAK,SAAS,CAAC;YACf,KAAK,MAAM,CAAC,CAAC;gBACX,iBAAiB,CAAC,IAAI,CAAC,GAAG,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;aACjE;SACF;QACD,OAAO,iBAAiB,CAAA;IAC1B,CAAC,EACD,EAAE,CACH,CAAA;AACH,CAAC;AA6BC,kDAAmB;AA3BrB,SAAS,uBAAuB,CAC9B,aAAqB,EACrB,YAAqC,EACrC,UAA+C;IAE/C,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;AAGC,0DAAuB","sourcesContent":["import { FormTypes } from '@oneblink/types'\n\nfunction forEachFormElement(\n elements: FormTypes.FormElement[],\n forEach: (\n element: FormTypes.FormElement,\n elements: FormTypes.FormElement[],\n ) => void,\n): void {\n findFormElement(elements, (formElement, parentElements) => {\n forEach(formElement, parentElements)\n return false\n })\n}\n\nfunction forEachFormElementWithOptions(\n elements: FormTypes.FormElement[],\n forEach: (\n elementWithOptions: FormTypes.FormElementWithOptions,\n elements: FormTypes.FormElement[],\n ) => void,\n): void {\n findFormElement(elements, (formElement, parentElements) => {\n if (\n formElement.type === 'select' ||\n formElement.type === 'autocomplete' ||\n formElement.type === 'checkboxes' ||\n formElement.type === 'radio' ||\n formElement.type === 'compliance'\n ) {\n forEach(formElement, parentElements)\n }\n return false\n })\n}\n\nfunction findFormElement(\n elements: FormTypes.FormElement[],\n predicate: (\n element: FormTypes.FormElement,\n elements: FormTypes.FormElement[],\n ) => boolean,\n parentElements: FormTypes.FormElement[] = [],\n): FormTypes.FormElement | void {\n for (const element of elements) {\n if (predicate(element, parentElements)) {\n return element\n }\n\n if (\n (element.type === 'repeatableSet' ||\n element.type === 'page' ||\n element.type === 'form' ||\n element.type === 'infoPage' ||\n element.type === 'section') &&\n Array.isArray(element.elements)\n ) {\n const nestedElement = findFormElement(element.elements, predicate, [\n ...parentElements,\n element,\n ])\n\n if (nestedElement) {\n return nestedElement\n }\n }\n }\n}\n\nfunction parseFormElementOptionsSet(\n data: unknown,\n): FormTypes.ChoiceElementOption[] {\n if (!Array.isArray(data)) {\n return []\n }\n return data.reduce(\n (\n options: FormTypes.ChoiceElementOption[],\n record: unknown,\n index: number,\n ) => {\n if (typeof record === 'string') {\n options.push({\n id: index.toString(),\n value: record,\n label: record,\n })\n } else if (typeof record === 'object') {\n const option = record as Record<string, unknown>\n const value =\n typeof option.value === 'string' && option.value\n ? option.value\n : index.toString()\n const id =\n typeof option.id === 'string' && option.id ? option.id : value\n const label =\n typeof option.label === 'string' && option.label\n ? option.label\n : value\n const colour =\n typeof option.colour === 'string' && option.colour\n ? option.colour\n : undefined\n options.push({\n ...option,\n id,\n value,\n label,\n colour,\n })\n }\n return options\n },\n [],\n )\n}\n\nfunction flattenFormElements(\n elements: FormTypes.FormElement[],\n): FormTypes.FormElement[] {\n return elements.reduce<FormTypes.FormElement[]>(\n (flattenedElements, element) => {\n flattenedElements.push(element)\n switch (element.type) {\n case 'section':\n case 'page': {\n flattenedElements.push(...flattenFormElements(element.elements))\n }\n }\n return flattenedElements\n },\n [],\n )\n}\n\nfunction getRootElementValueById(\n formElementId: string,\n formElements: FormTypes.FormElement[],\n submission: { readonly [key: string]: unknown },\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\nexport {\n getRootElementValueById,\n forEachFormElement,\n forEachFormElementWithOptions,\n findFormElement,\n parseFormElementOptionsSet,\n flattenFormElements,\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ import replaceCustomValues, { getElementSubmissionValue } from './replaceCustomV
|
|
|
4
4
|
export * as typeCastService from './typeCastService';
|
|
5
5
|
export * as userService from './userService';
|
|
6
6
|
export * as abnService from './abnService';
|
|
7
|
+
export { validatePaymentAmount } from './paymentAmountValidation';
|
|
7
8
|
export { getContentDisposition } from './fileUploadService';
|
|
8
9
|
export { replaceCustomValues, getElementSubmissionValue };
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.getElementSubmissionValue = exports.replaceCustomValues = exports.getContentDisposition = exports.abnService = exports.userService = exports.typeCastService = exports.conditionalLogicService = exports.formElementsService = void 0;
|
|
22
|
+
exports.getElementSubmissionValue = exports.replaceCustomValues = exports.getContentDisposition = exports.validatePaymentAmount = exports.abnService = exports.userService = exports.typeCastService = exports.conditionalLogicService = exports.formElementsService = void 0;
|
|
23
23
|
exports.formElementsService = __importStar(require("./formElementsService"));
|
|
24
24
|
exports.conditionalLogicService = __importStar(require("./conditionalLogicService"));
|
|
25
25
|
const replaceCustomValues_1 = __importStar(require("./replaceCustomValues"));
|
|
@@ -28,6 +28,8 @@ Object.defineProperty(exports, "getElementSubmissionValue", { enumerable: true,
|
|
|
28
28
|
exports.typeCastService = __importStar(require("./typeCastService"));
|
|
29
29
|
exports.userService = __importStar(require("./userService"));
|
|
30
30
|
exports.abnService = __importStar(require("./abnService"));
|
|
31
|
+
var paymentAmountValidation_1 = require("./paymentAmountValidation");
|
|
32
|
+
Object.defineProperty(exports, "validatePaymentAmount", { enumerable: true, get: function () { return paymentAmountValidation_1.validatePaymentAmount; } });
|
|
31
33
|
var fileUploadService_1 = require("./fileUploadService");
|
|
32
34
|
Object.defineProperty(exports, "getContentDisposition", { enumerable: true, get: function () { return fileUploadService_1.getContentDisposition; } });
|
|
33
35
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,6EAA4D;AAC5D,qFAAoE;AACpE,6EAE8B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,6EAA4D;AAC5D,qFAAoE;AACpE,6EAE8B;AAOrB,8BATF,6BAAmB,CASE;AAAE,0GAR5B,+CAAyB,OAQ4B;AANvD,qEAAoD;AACpD,6DAA4C;AAC5C,2DAA0C;AAC1C,qEAAiE;AAAxD,gIAAA,qBAAqB,OAAA;AAC9B,yDAA2D;AAAlD,0HAAA,qBAAqB,OAAA","sourcesContent":["export * as formElementsService from './formElementsService'\nexport * as conditionalLogicService from './conditionalLogicService'\nimport replaceCustomValues, {\n getElementSubmissionValue,\n} from './replaceCustomValues'\nexport * as typeCastService from './typeCastService'\nexport * as userService from './userService'\nexport * as abnService from './abnService'\nexport { validatePaymentAmount } from './paymentAmountValidation'\nexport { getContentDisposition } from './fileUploadService'\n\nexport { replaceCustomValues, getElementSubmissionValue }\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
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;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validatePaymentAmount = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const formElementsService_1 = require("./formElementsService");
|
|
6
|
+
function validatePaymentAmount(definition, submission) {
|
|
7
|
+
const paymentSubmissionEvents = definition.paymentEvents || [];
|
|
8
|
+
const paymentSubmissionEvent = paymentSubmissionEvents.find((paymentSubmissionEvent) => {
|
|
9
|
+
return (paymentSubmissionEvent &&
|
|
10
|
+
_1.conditionalLogicService.evaluateConditionalPredicates({
|
|
11
|
+
isConditional: !!paymentSubmissionEvent.conditionallyExecute,
|
|
12
|
+
requiresAllConditionalPredicates: !!paymentSubmissionEvent.requiresAllConditionallyExecutePredicates,
|
|
13
|
+
conditionalPredicates: paymentSubmissionEvent.conditionallyExecutePredicates || [],
|
|
14
|
+
submission: submission,
|
|
15
|
+
formElements: definition.elements,
|
|
16
|
+
}));
|
|
17
|
+
});
|
|
18
|
+
if (!paymentSubmissionEvent) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
console.log('Checking if submission with payment submission event needs processing');
|
|
22
|
+
const amountElement = _1.formElementsService.findFormElement(definition.elements, (element) => element.id === paymentSubmissionEvent.configuration.elementId);
|
|
23
|
+
if (!amountElement || amountElement.type === 'page') {
|
|
24
|
+
console.log('Form has a payment submission event but the amount element does not exist, throwing error');
|
|
25
|
+
throw new Error('We could not find the configuration required to make a payment. Please contact your administrator to ensure your application configuration has been completed successfully.');
|
|
26
|
+
}
|
|
27
|
+
console.log('Found form element for payment submission event', amountElement);
|
|
28
|
+
const amount = (0, formElementsService_1.getRootElementValueById)(amountElement.id, definition.elements, submission);
|
|
29
|
+
if (!amount) {
|
|
30
|
+
console.log('Form has a payment submission event but the amount has been entered as 0 or not at all, finishing as normal submission');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (typeof amount !== 'number') {
|
|
34
|
+
console.log('Form has a payment submission event but the amount is not a number, throwing error');
|
|
35
|
+
throw new Error('The configuration required to make a payment is incorrect. Please contact your administrator to ensure your application configuration has been completed successfully.');
|
|
36
|
+
}
|
|
37
|
+
const result = {
|
|
38
|
+
paymentSubmissionEvent,
|
|
39
|
+
amount,
|
|
40
|
+
};
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
exports.validatePaymentAmount = validatePaymentAmount;
|
|
44
|
+
//# sourceMappingURL=paymentAmountValidation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paymentAmountValidation.js","sourceRoot":"","sources":["../src/paymentAmountValidation.ts"],"names":[],"mappings":";;;AACA,wBAAgE;AAChE,+DAA+D;AAE/D,SAAgB,qBAAqB,CACnC,UAA0B,EAC1B,UAA+C;IAO/C,MAAM,uBAAuB,GAAG,UAAU,CAAC,aAAa,IAAI,EAAE,CAAA;IAC9D,MAAM,sBAAsB,GAAG,uBAAuB,CAAC,IAAI,CACzD,CAAC,sBAAsB,EAAE,EAAE;QACzB,OAAO,CACL,sBAAsB;YACtB,0BAAuB,CAAC,6BAA6B,CAAC;gBACpD,aAAa,EAAE,CAAC,CAAC,sBAAsB,CAAC,oBAAoB;gBAC5D,gCAAgC,EAC9B,CAAC,CAAC,sBAAsB,CAAC,yCAAyC;gBACpE,qBAAqB,EACnB,sBAAsB,CAAC,8BAA8B,IAAI,EAAE;gBAC7D,UAAU,EAAE,UAAU;gBACtB,YAAY,EAAE,UAAU,CAAC,QAAQ;aAClC,CAAC,CACH,CAAA;IACH,CAAC,CACF,CAAA;IAED,IAAI,CAAC,sBAAsB,EAAE;QAC3B,OAAM;KACP;IACD,OAAO,CAAC,GAAG,CACT,uEAAuE,CACxE,CAAA;IAED,MAAM,aAAa,GAAG,sBAAmB,CAAC,eAAe,CACvD,UAAU,CAAC,QAAQ,EACnB,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,sBAAsB,CAAC,aAAa,CAAC,SAAS,CAC3E,CAAA;IACD,IAAI,CAAC,aAAa,IAAI,aAAa,CAAC,IAAI,KAAK,MAAM,EAAE;QACnD,OAAO,CAAC,GAAG,CACT,2FAA2F,CAC5F,CAAA;QACD,MAAM,IAAI,KAAK,CACb,6KAA6K,CAC9K,CAAA;KACF;IAED,OAAO,CAAC,GAAG,CAAC,iDAAiD,EAAE,aAAa,CAAC,CAAA;IAE7E,MAAM,MAAM,GAAG,IAAA,6CAAuB,EACpC,aAAa,CAAC,EAAE,EAChB,UAAU,CAAC,QAAQ,EACnB,UAAU,CACX,CAAA;IAED,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,CAAC,GAAG,CACT,wHAAwH,CACzH,CAAA;QACD,OAAM;KACP;IAED,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,OAAO,CAAC,GAAG,CACT,oFAAoF,CACrF,CAAA;QACD,MAAM,IAAI,KAAK,CACb,wKAAwK,CACzK,CAAA;KACF;IAED,MAAM,MAAM,GAAG;QACb,sBAAsB;QACtB,MAAM;KACP,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AA7ED,sDA6EC","sourcesContent":["import { FormTypes, SubmissionEventTypes } from '@oneblink/types'\nimport { conditionalLogicService, formElementsService } from '.'\nimport { getRootElementValueById } from './formElementsService'\n\nexport function validatePaymentAmount(\n definition: FormTypes.Form,\n submission: { readonly [key: string]: unknown },\n):\n | {\n paymentSubmissionEvent: SubmissionEventTypes.PaymentSubmissionEvent\n amount: number\n }\n | undefined {\n const paymentSubmissionEvents = definition.paymentEvents || []\n const paymentSubmissionEvent = paymentSubmissionEvents.find(\n (paymentSubmissionEvent) => {\n return (\n paymentSubmissionEvent &&\n conditionalLogicService.evaluateConditionalPredicates({\n isConditional: !!paymentSubmissionEvent.conditionallyExecute,\n requiresAllConditionalPredicates:\n !!paymentSubmissionEvent.requiresAllConditionallyExecutePredicates,\n conditionalPredicates:\n paymentSubmissionEvent.conditionallyExecutePredicates || [],\n submission: submission,\n formElements: definition.elements,\n })\n )\n },\n )\n\n if (!paymentSubmissionEvent) {\n return\n }\n console.log(\n 'Checking if submission with payment submission event needs processing',\n )\n\n const amountElement = formElementsService.findFormElement(\n definition.elements,\n (element) => element.id === paymentSubmissionEvent.configuration.elementId,\n )\n if (!amountElement || amountElement.type === 'page') {\n console.log(\n 'Form has a payment submission event but the amount element does not exist, throwing error',\n )\n throw new Error(\n 'We could not find the configuration required to make a payment. Please contact your administrator to ensure your application configuration has been completed successfully.',\n )\n }\n\n console.log('Found form element for payment submission event', amountElement)\n\n const amount = getRootElementValueById(\n amountElement.id,\n definition.elements,\n submission,\n )\n\n if (!amount) {\n console.log(\n 'Form has a payment submission event but the amount has been entered as 0 or not at all, finishing as normal submission',\n )\n return\n }\n\n if (typeof amount !== 'number') {\n console.log(\n 'Form has a payment submission event but the amount is not a number, throwing error',\n )\n throw new Error(\n 'The configuration required to make a payment is incorrect. Please contact your administrator to ensure your application configuration has been completed successfully.',\n )\n }\n\n const result = {\n paymentSubmissionEvent,\n amount,\n }\n\n return result\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FormTypes, SubmissionEventTypes } from '@oneblink/types';
|
|
2
|
-
declare
|
|
2
|
+
declare function toNamedElement(e: FormTypes.FormElement): FormTypes.FormElementWithName | undefined;
|
|
3
3
|
declare type NonNestedElementsFormElement = FormTypes.NonNestedElementsElement | FormTypes.FormElementWithForm;
|
|
4
4
|
declare const formElements: {
|
|
5
5
|
toOptionsElement: (e: FormTypes.FormElement) => FormTypes.FormElementWithOptions | undefined;
|
|
@@ -7,7 +7,8 @@ declare const formElements: {
|
|
|
7
7
|
toFormElementWithoutForm: (e: FormTypes.FormElement) => FormTypes.FormElementWithoutForm | undefined;
|
|
8
8
|
toLookupElement: (e: FormTypes.FormElement) => FormTypes.LookupFormElement | undefined;
|
|
9
9
|
toNestedElementsElement: (e: FormTypes.FormElement) => FormTypes.NestedElementsElement | undefined;
|
|
10
|
-
toNamelessElement: (e: FormTypes.FormElement) =>
|
|
10
|
+
toNamelessElement: (e: FormTypes.FormElement) => FormTypes.FormElementWithoutName | undefined;
|
|
11
|
+
toNamedElement: typeof toNamedElement;
|
|
11
12
|
toNonNestedElementsElement: (e: FormTypes.FormElement) => NonNestedElementsFormElement | undefined;
|
|
12
13
|
toPageElement: (e: FormTypes.FormElement) => FormTypes.PageElement | undefined;
|
|
13
14
|
toRepeatableSetElement: (e: FormTypes.FormElement) => FormTypes.RepeatableSetElement | undefined;
|
package/dist/typeCastService.js
CHANGED
|
@@ -91,6 +91,17 @@ const toNamelessElement = (e) => {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
|
+
function toNamedElement(e) {
|
|
95
|
+
switch (e.type) {
|
|
96
|
+
case 'page':
|
|
97
|
+
case 'section': {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
default: {
|
|
101
|
+
return e;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
94
105
|
const toNonNestedElementsElement = (e) => {
|
|
95
106
|
switch (e.type) {
|
|
96
107
|
case 'repeatableSet':
|
|
@@ -143,6 +154,7 @@ const formElements = {
|
|
|
143
154
|
toLookupElement,
|
|
144
155
|
toNestedElementsElement,
|
|
145
156
|
toNamelessElement,
|
|
157
|
+
toNamedElement,
|
|
146
158
|
toNonNestedElementsElement,
|
|
147
159
|
toPageElement,
|
|
148
160
|
toRepeatableSetElement,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeCastService.js","sourceRoot":"","sources":["../src/typeCastService.ts"],"names":[],"mappings":";;;A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jB,KAAK,cAAc,CAAC;QACpB,KAAK,iBAAiB,CAAC;QACvB,KAAK,kBAAkB,CAAC;QACxB,KAAK,KAAK,CAAC;QACX,KAAK,cAAc,CAAC;QACpB,KAAK,KAAK,CAAC,CAAC;YACV,OAAO,CAAC,CAAA;SACT;QACD,OAAO,CAAC,CAAC;YACP,OAAM;SACP;KACF;AACH,CAAC,CAAA;AAED,MAAM,uBAAuB,GAAG,CAC9B,CAAwB,EACqB,EAAE;IAC/C,QAAQ,CAAC,CAAC,IAAI,EAAE;QACd,KAAK,eAAe,CAAC;QACrB,KAAK,SAAS,CAAC;QACf,KAAK,MAAM,CAAC,CAAC;YACX,OAAO,CAAC,CAAA;SACT;QACD,OAAO,CAAC,CAAC;YACP,OAAM;SACP;KACF;AACH,CAAC,CAAA;
|
|
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,CAAC;QACpB,KAAK,YAAY,CAAC,CAAC;YACjB,OAAO,CAAC,CAAA;SACT;QACD,OAAO,CAAC,CAAC;YACP,OAAM;SACP;KACF;AACH,CAAC,CAAA;AAED,MAAM,qBAAqB,GAAG,CAC5B,CAAwB,EACmB,EAAE;IAC7C,QAAQ,CAAC,CAAC,IAAI,EAAE;QACd,KAAK,MAAM,CAAC;QACZ,KAAK,UAAU,CAAC,CAAC;YACf,OAAO,CAAC,CAAA;SACT;QACD,OAAO,CAAC,CAAC;YACP,OAAM;SACP;KACF;AACH,CAAC,CAAA;AAED,MAAM,wBAAwB,GAAG,CAC/B,CAAwB,EACsB,EAAE;IAChD,QAAQ,CAAC,CAAC,IAAI,EAAE;QACd,KAAK,MAAM,CAAC;QACZ,KAAK,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AY,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\ntype 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/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.3.
|
|
4
|
+
"version": "0.3.6-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"
|