@oneblink/sdk-core 0.2.5-beta.1 → 0.3.0-beta.3
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.
|
@@ -10,9 +10,9 @@ declare type CustomValuesOptions = {
|
|
|
10
10
|
formatCurrency: (value: number) => string;
|
|
11
11
|
previousApprovalId?: string;
|
|
12
12
|
};
|
|
13
|
-
export declare function getElementSubmissionValue({ propertyName, submission,
|
|
13
|
+
export declare function getElementSubmissionValue({ propertyName, submission, formElements, formatDate, formatTime, formatNumber, formatCurrency, }: {
|
|
14
14
|
propertyName: string;
|
|
15
|
-
|
|
15
|
+
formElements: FormTypes.FormElement[];
|
|
16
16
|
submission: SubmissionTypes.S3SubmissionData['submission'];
|
|
17
17
|
formatDate: (value: string) => string;
|
|
18
18
|
formatTime: (value: string) => string;
|
|
@@ -45,9 +45,9 @@ const CUSTOM_VALUES = [
|
|
|
45
45
|
value: ({ previousApprovalId }) => previousApprovalId || '',
|
|
46
46
|
},
|
|
47
47
|
];
|
|
48
|
-
function getElementSubmissionValue({ propertyName, submission,
|
|
49
|
-
var _a, _b;
|
|
50
|
-
const formElement = (0, formElementsService_1.findFormElement)(
|
|
48
|
+
function getElementSubmissionValue({ propertyName, submission, formElements, formatDate, formatTime, formatNumber, formatCurrency, }) {
|
|
49
|
+
var _a, _b, _c;
|
|
50
|
+
const formElement = (0, formElementsService_1.findFormElement)(formElements, (element) => element.type !== 'page' &&
|
|
51
51
|
element.type !== 'section' &&
|
|
52
52
|
element.name === propertyName);
|
|
53
53
|
const value = submission[propertyName];
|
|
@@ -118,6 +118,18 @@ function getElementSubmissionValue({ propertyName, submission, form, formatDate,
|
|
|
118
118
|
}
|
|
119
119
|
return undefined;
|
|
120
120
|
}
|
|
121
|
+
case 'pointAddress':
|
|
122
|
+
case 'geoscapeAddress': {
|
|
123
|
+
return ((_c = value === null || value === void 0 ? void 0 : value.addressDetails) === null || _c === void 0 ? void 0 : _c.formattedAddress) || (value === null || value === void 0 ? void 0 : value.addressId);
|
|
124
|
+
}
|
|
125
|
+
case 'civicaStreetName': {
|
|
126
|
+
return value === null || value === void 0 ? void 0 : value.formattedStreet;
|
|
127
|
+
}
|
|
128
|
+
case 'civicaNameRecord': {
|
|
129
|
+
return ([value === null || value === void 0 ? void 0 : value.title, value === null || value === void 0 ? void 0 : value.givenName1, value === null || value === void 0 ? void 0 : value.familyName]
|
|
130
|
+
.filter((t) => t)
|
|
131
|
+
.join(' ') || (value === null || value === void 0 ? void 0 : value.emailAddress));
|
|
132
|
+
}
|
|
121
133
|
default: {
|
|
122
134
|
return value;
|
|
123
135
|
}
|
|
@@ -133,7 +145,7 @@ function replaceElementValues(text, { form, submission, formatDate, formatTime,
|
|
|
133
145
|
const propertyName = match.substring(match.indexOf(':') + 1, match.lastIndexOf('}'));
|
|
134
146
|
const value = getElementSubmissionValue({
|
|
135
147
|
propertyName,
|
|
136
|
-
form,
|
|
148
|
+
formElements: form.elements,
|
|
137
149
|
submission,
|
|
138
150
|
formatDate,
|
|
139
151
|
formatTime,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replaceCustomValues.js","sourceRoot":"","sources":["../src/replaceCustomValues.ts"],"names":[],"mappings":";;;AACA,+DAAuD;AAcvD,MAAM,aAAa,GAAG;IACpB;QACE,MAAM,EAAE,gBAAgB;QACxB,KAAK,EAAE,CAAC,EAAE,IAAI,EAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE;KAC7D;IACD;QACE,MAAM,EAAE,kBAAkB;QAC1B,KAAK,EAAE,CAAC,EAAE,IAAI,EAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI;KACpD;IACD;QACE,MAAM,EAAE,WAAW;QACnB,KAAK,EAAE,CAAC,EAAE,IAAI,EAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE;KAC7D;IACD;QACE,MAAM,EAAE,aAAa;QACrB,K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,EACZ,mBAAmB,EACnB,UAAU,EACV,UAAU,EACV,YAAY,EACZ,cAAc,EACd,kBAAkB,GAGnB;IAED,MAAM,MAAM,GAAG,oBAAoB,CAAC,IAAI,EAAE;QACxC,IAAI;QACJ,UAAU;QACV,UAAU;QACV,UAAU;QACV,YAAY;QACZ,cAAc;KACf,CAAC,CAAA;IACF,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,WAAW,EAAE,EAAE;QACrD,OAAO,SAAS,CAAC,OAAO,CACtB,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,KAAK,CAAC;YAChB,IAAI;YACJ,mBAAmB;YACnB,UAAU;YACV,YAAY;YACZ,UAAU;YACV,UAAU;YACV,YAAY;YACZ,cAAc;YACd,kBAAkB;SACnB,CAAC,CACH,CAAA;IACH,CAAC,EAAE,MAAM,CAAC,CAAA;AACZ,CAAC;AAzCD,sCAyCC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { findFormElement } from './formElementsService'\n\ntype CustomValuesOptions = {\n form: FormTypes.Form\n externalId?: string\n submissionId: string\n submissionTimestamp: string\n formatDate: (value: string) => string\n formatTime: (value: string) => string\n formatNumber: (value: number) => string\n formatCurrency: (value: number) => string\n previousApprovalId?: string\n}\n\nconst CUSTOM_VALUES = [\n {\n string: '{INFO_PAGE_ID}',\n value: ({ form }: CustomValuesOptions) => form.id.toString(),\n },\n {\n string: '{INFO_PAGE_NAME}',\n value: ({ form }: CustomValuesOptions) => form.name,\n },\n {\n string: '{FORM_ID}',\n value: ({ form }: CustomValuesOptions) => form.id.toString(),\n },\n {\n string: '{FORM_NAME}',\n value: ({ form }: CustomValuesOptions) => form.name,\n },\n {\n string: '{DATE}',\n value: ({\n submissionTimestamp,\n formatDate,\n formatTime,\n }: CustomValuesOptions) => {\n if (!submissionTimestamp) {\n return ''\n }\n return `${formatDate(submissionTimestamp)} ${formatTime(\n submissionTimestamp,\n )}`\n },\n },\n {\n string: '{TIMESTAMP}',\n value: ({ submissionTimestamp }: CustomValuesOptions) =>\n submissionTimestamp || '',\n },\n {\n string: '{SUBMISSION_ID}',\n value: ({ submissionId }: CustomValuesOptions) => submissionId || '',\n },\n {\n string: '{EXTERNAL_ID}',\n value: ({ externalId }: CustomValuesOptions) => externalId || '',\n },\n {\n string: '{PREVIOUS_APPROVAL_ID}',\n value: ({ previousApprovalId }: CustomValuesOptions) =>\n previousApprovalId || '',\n },\n]\n\nexport function getElementSubmissionValue({\n propertyName,\n submission,\n form,\n formatDate,\n formatTime,\n formatNumber,\n formatCurrency,\n}: {\n propertyName: string\n form: FormTypes.Form\n submission: SubmissionTypes.S3SubmissionData['submission']\n formatDate: (value: string) => string\n formatTime: (value: string) => string\n formatNumber: (value: number) => string\n formatCurrency: (value: number) => string\n}): unknown {\n const formElement = findFormElement(\n form.elements,\n (element) =>\n element.type !== 'page' &&\n element.type !== 'section' &&\n element.name === propertyName,\n )\n\n const value = submission[propertyName]\n if (value === undefined || value === null) {\n return undefined\n }\n\n switch (formElement?.type) {\n case 'datetime': {\n return `${formatDate(value)} ${formatTime(value)}`\n }\n case 'date': {\n return formatDate(value)\n }\n case 'time': {\n return formatTime(value)\n }\n case 'radio':\n case 'autocomplete': {\n const option = formElement.options?.find((opt) => opt.value === value)\n return option?.label || value\n }\n\n case 'checkboxes': {\n const selectedOptionLabels: string[] = value.reduce(\n (labels: string[], selectedOption: string) => {\n const foundOption = formElement.options?.find(\n (o) => o.value === selectedOption,\n )\n if (foundOption) labels.push(foundOption.label)\n return labels\n },\n [],\n )\n return selectedOptionLabels.length ? selectedOptionLabels : undefined\n }\n case 'compliance': {\n const option = (formElement.options || []).find(\n (option: FormTypes.ChoiceElementOption) => option.value === value.value,\n )\n return {\n ...value,\n value: option?.label || value.value,\n }\n }\n case 'select': {\n if (formElement.multi) {\n const selectedOptionLabels: string[] = value.reduce(\n (labels: string[], selectedOption: string) => {\n const foundOption = formElement.options?.find(\n (o) => o.value === selectedOption,\n )\n if (foundOption) labels.push(foundOption.label)\n return labels\n },\n [],\n )\n return selectedOptionLabels.length ? selectedOptionLabels : undefined\n } else {\n const option = formElement.options?.find((opt) => opt.value === value)\n return option?.label || ''\n }\n }\n case 'boolean': {\n return value ? 'Yes' : 'No'\n }\n case 'calculation': {\n if (!Number.isNaN(value) && Number.isFinite(value)) {\n let text\n if (formElement.displayAsCurrency) {\n text = formatCurrency(value)\n } else {\n text = formatNumber(value)\n }\n return text\n }\n return undefined\n }\n\n default: {\n return value\n }\n }\n}\n\nfunction replaceElementValues(\n text: string,\n {\n form,\n submission,\n formatDate,\n formatTime,\n formatNumber,\n formatCurrency,\n }: {\n form: FormTypes.Form\n submission: SubmissionTypes.S3SubmissionData['submission']\n formatDate: (value: string) => string\n formatTime: (value: string) => string\n formatNumber: (value: number) => string\n formatCurrency: (value: number) => string\n },\n): string {\n const matches = text.match(/({ELEMENT:)([^}]+)(})/g)\n if (!matches) {\n return text\n }\n\n return matches.reduce((newString, match) => {\n const propertyName = match.substring(\n match.indexOf(':') + 1,\n match.lastIndexOf('}'),\n )\n\n const value = getElementSubmissionValue({\n propertyName,\n form,\n submission,\n formatDate,\n formatTime,\n formatNumber,\n formatCurrency,\n })\n\n return newString.replace(\n match,\n value === undefined ? '' : (value as string),\n )\n }, text)\n}\n\nexport default function replaceCustomValues(\n text: string,\n {\n form,\n submission,\n externalId,\n submissionId,\n submissionTimestamp,\n formatDate,\n formatTime,\n formatNumber,\n formatCurrency,\n previousApprovalId,\n }: CustomValuesOptions & {\n submission: SubmissionTypes.S3SubmissionData['submission']\n },\n): string {\n const string = replaceElementValues(text, {\n form,\n submission,\n formatDate,\n formatTime,\n formatNumber,\n formatCurrency,\n })\n return CUSTOM_VALUES.reduce((newString, customValue) => {\n return newString.replace(\n customValue.string,\n customValue.value({\n form,\n submissionTimestamp,\n externalId,\n submissionId,\n formatDate,\n formatTime,\n formatNumber,\n formatCurrency,\n previousApprovalId,\n }),\n )\n }, string)\n}\n"]}
|
|
1
|
+
{"version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mB,EACnB,UAAU,EACV,UAAU,EACV,YAAY,EACZ,cAAc,EACd,kBAAkB,GAGnB;IAED,MAAM,MAAM,GAAG,oBAAoB,CAAC,IAAI,EAAE;QACxC,IAAI;QACJ,UAAU;QACV,UAAU;QACV,UAAU;QACV,YAAY;QACZ,cAAc;KACf,CAAC,CAAA;IACF,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,WAAW,EAAE,EAAE;QACrD,OAAO,SAAS,CAAC,OAAO,CACtB,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,KAAK,CAAC;YAChB,IAAI;YACJ,mBAAmB;YACnB,UAAU;YACV,YAAY;YACZ,UAAU;YACV,UAAU;YACV,YAAY;YACZ,cAAc;YACd,kBAAkB;SACnB,CAAC,CACH,CAAA;IACH,CAAC,EAAE,MAAM,CAAC,CAAA;AACZ,CAAC;AAzCD,sCAyCC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { findFormElement } from './formElementsService'\n\ntype CustomValuesOptions = {\n form: FormTypes.Form\n externalId?: string\n submissionId: string\n submissionTimestamp: string\n formatDate: (value: string) => string\n formatTime: (value: string) => string\n formatNumber: (value: number) => string\n formatCurrency: (value: number) => string\n previousApprovalId?: string\n}\n\nconst CUSTOM_VALUES = [\n {\n string: '{INFO_PAGE_ID}',\n value: ({ form }: CustomValuesOptions) => form.id.toString(),\n },\n {\n string: '{INFO_PAGE_NAME}',\n value: ({ form }: CustomValuesOptions) => form.name,\n },\n {\n string: '{FORM_ID}',\n value: ({ form }: CustomValuesOptions) => form.id.toString(),\n },\n {\n string: '{FORM_NAME}',\n value: ({ form }: CustomValuesOptions) => form.name,\n },\n {\n string: '{DATE}',\n value: ({\n submissionTimestamp,\n formatDate,\n formatTime,\n }: CustomValuesOptions) => {\n if (!submissionTimestamp) {\n return ''\n }\n return `${formatDate(submissionTimestamp)} ${formatTime(\n submissionTimestamp,\n )}`\n },\n },\n {\n string: '{TIMESTAMP}',\n value: ({ submissionTimestamp }: CustomValuesOptions) =>\n submissionTimestamp || '',\n },\n {\n string: '{SUBMISSION_ID}',\n value: ({ submissionId }: CustomValuesOptions) => submissionId || '',\n },\n {\n string: '{EXTERNAL_ID}',\n value: ({ externalId }: CustomValuesOptions) => externalId || '',\n },\n {\n string: '{PREVIOUS_APPROVAL_ID}',\n value: ({ previousApprovalId }: CustomValuesOptions) =>\n previousApprovalId || '',\n },\n]\n\nexport function getElementSubmissionValue({\n propertyName,\n submission,\n formElements,\n formatDate,\n formatTime,\n formatNumber,\n formatCurrency,\n}: {\n propertyName: string\n formElements: FormTypes.FormElement[]\n submission: SubmissionTypes.S3SubmissionData['submission']\n formatDate: (value: string) => string\n formatTime: (value: string) => string\n formatNumber: (value: number) => string\n formatCurrency: (value: number) => string\n}): unknown {\n const formElement = findFormElement(\n formElements,\n (element) =>\n element.type !== 'page' &&\n element.type !== 'section' &&\n element.name === propertyName,\n )\n\n const value = submission[propertyName]\n if (value === undefined || value === null) {\n return undefined\n }\n\n switch (formElement?.type) {\n case 'datetime': {\n return `${formatDate(value)} ${formatTime(value)}`\n }\n case 'date': {\n return formatDate(value)\n }\n case 'time': {\n return formatTime(value)\n }\n case 'radio':\n case 'autocomplete': {\n const option = formElement.options?.find((opt) => opt.value === value)\n return option?.label || value\n }\n\n case 'checkboxes': {\n const selectedOptionLabels: string[] = value.reduce(\n (labels: string[], selectedOption: string) => {\n const foundOption = formElement.options?.find(\n (o) => o.value === selectedOption,\n )\n if (foundOption) labels.push(foundOption.label)\n return labels\n },\n [],\n )\n return selectedOptionLabels.length ? selectedOptionLabels : undefined\n }\n case 'compliance': {\n const option = (formElement.options || []).find(\n (option: FormTypes.ChoiceElementOption) => option.value === value.value,\n )\n return {\n ...value,\n value: option?.label || value.value,\n }\n }\n case 'select': {\n if (formElement.multi) {\n const selectedOptionLabels: string[] = value.reduce(\n (labels: string[], selectedOption: string) => {\n const foundOption = formElement.options?.find(\n (o) => o.value === selectedOption,\n )\n if (foundOption) labels.push(foundOption.label)\n return labels\n },\n [],\n )\n return selectedOptionLabels.length ? selectedOptionLabels : undefined\n } else {\n const option = formElement.options?.find((opt) => opt.value === value)\n return option?.label || ''\n }\n }\n case 'boolean': {\n return value ? 'Yes' : 'No'\n }\n case 'calculation': {\n if (!Number.isNaN(value) && Number.isFinite(value)) {\n let text\n if (formElement.displayAsCurrency) {\n text = formatCurrency(value)\n } else {\n text = formatNumber(value)\n }\n return text\n }\n return undefined\n }\n case 'pointAddress':\n case 'geoscapeAddress': {\n return value?.addressDetails?.formattedAddress || value?.addressId\n }\n case 'civicaStreetName': {\n return value?.formattedStreet\n }\n case 'civicaNameRecord': {\n return (\n [value?.title, value?.givenName1, value?.familyName]\n .filter((t) => t)\n .join(' ') || value?.emailAddress\n )\n }\n default: {\n return value\n }\n }\n}\n\nfunction replaceElementValues(\n text: string,\n {\n form,\n submission,\n formatDate,\n formatTime,\n formatNumber,\n formatCurrency,\n }: {\n form: FormTypes.Form\n submission: SubmissionTypes.S3SubmissionData['submission']\n formatDate: (value: string) => string\n formatTime: (value: string) => string\n formatNumber: (value: number) => string\n formatCurrency: (value: number) => string\n },\n): string {\n const matches = text.match(/({ELEMENT:)([^}]+)(})/g)\n if (!matches) {\n return text\n }\n\n return matches.reduce((newString, match) => {\n const propertyName = match.substring(\n match.indexOf(':') + 1,\n match.lastIndexOf('}'),\n )\n\n const value = getElementSubmissionValue({\n propertyName,\n formElements: form.elements,\n submission,\n formatDate,\n formatTime,\n formatNumber,\n formatCurrency,\n })\n\n return newString.replace(\n match,\n value === undefined ? '' : (value as string),\n )\n }, text)\n}\n\nexport default function replaceCustomValues(\n text: string,\n {\n form,\n submission,\n externalId,\n submissionId,\n submissionTimestamp,\n formatDate,\n formatTime,\n formatNumber,\n formatCurrency,\n previousApprovalId,\n }: CustomValuesOptions & {\n submission: SubmissionTypes.S3SubmissionData['submission']\n },\n): string {\n const string = replaceElementValues(text, {\n form,\n submission,\n formatDate,\n formatTime,\n formatNumber,\n formatCurrency,\n })\n return CUSTOM_VALUES.reduce((newString, customValue) => {\n return newString.replace(\n customValue.string,\n customValue.value({\n form,\n submissionTimestamp,\n externalId,\n submissionId,\n formatDate,\n formatTime,\n formatNumber,\n formatCurrency,\n previousApprovalId,\n }),\n )\n }, string)\n}\n"]}
|
package/dist/typeCastService.js
CHANGED
|
@@ -43,6 +43,7 @@ const toLookupElement = (e) => {
|
|
|
43
43
|
case 'checkboxes':
|
|
44
44
|
case 'date':
|
|
45
45
|
case 'datetime':
|
|
46
|
+
case 'files':
|
|
46
47
|
case 'location':
|
|
47
48
|
case 'number':
|
|
48
49
|
case 'compliance':
|
|
@@ -57,6 +58,7 @@ const toLookupElement = (e) => {
|
|
|
57
58
|
case 'pointAddress':
|
|
58
59
|
case 'geoscapeAddress':
|
|
59
60
|
case 'civicaStreetName':
|
|
61
|
+
case 'bsb':
|
|
60
62
|
case 'autocomplete': {
|
|
61
63
|
return e;
|
|
62
64
|
}
|
|
@@ -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,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,MA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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 '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 'autocomplete': {\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\ntype NamelessElement = FormTypes.PageElement | FormTypes.SectionElement\nconst toNamelessElement = (\n e: FormTypes.FormElement,\n): NamelessElement | undefined => {\n switch (e.type) {\n case 'section':\n case 'page': {\n return e\n }\n default: {\n return\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 formElements = {\n toOptionsElement,\n toFormElementWithForm,\n toFormElementWithoutForm,\n toLookupElement,\n toNestedElementsElement,\n toNamelessElement,\n toNonNestedElementsElement,\n toPageElement,\n toRepeatableSetElement,\n}\n\nconst toPaymentSubmissionEvent = (\n e: SubmissionEventTypes.FormSubmissionEvent,\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"]}
|
|
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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,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 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\ntype NamelessElement = FormTypes.PageElement | FormTypes.SectionElement\nconst toNamelessElement = (\n e: FormTypes.FormElement,\n): NamelessElement | undefined => {\n switch (e.type) {\n case 'section':\n case 'page': {\n return e\n }\n default: {\n return\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 formElements = {\n toOptionsElement,\n toFormElementWithForm,\n toFormElementWithoutForm,\n toLookupElement,\n toNestedElementsElement,\n toNamelessElement,\n toNonNestedElementsElement,\n toPageElement,\n toRepeatableSetElement,\n}\n\nconst toPaymentSubmissionEvent = (\n e: SubmissionEventTypes.FormSubmissionEvent,\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.
|
|
4
|
+
"version": "0.3.0-beta.3",
|
|
5
5
|
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/oneblink/sdk-core-js/issues"
|