@oneblink/sdk-core 8.11.1 → 9.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/abnService.d.ts +5 -5
- package/dist/abnService.js +9 -17
- package/dist/abnService.js.map +1 -1
- package/dist/conditionalLogicService/conditionallyShowElement.d.ts +1 -1
- package/dist/conditionalLogicService/conditionallyShowElement.js +4 -11
- package/dist/conditionalLogicService/conditionallyShowElement.js.map +1 -1
- package/dist/conditionalLogicService/conditionallyShowOption.d.ts +1 -1
- package/dist/conditionalLogicService/conditionallyShowOption.js +10 -18
- package/dist/conditionalLogicService/conditionallyShowOption.js.map +1 -1
- package/dist/conditionalLogicService/evaluateConditionalOptionsPredicate.js +2 -6
- package/dist/conditionalLogicService/evaluateConditionalOptionsPredicate.js.map +1 -1
- package/dist/conditionalLogicService/evaluateConditionalPredicate.d.ts +1 -1
- package/dist/conditionalLogicService/evaluateConditionalPredicate.js +14 -22
- package/dist/conditionalLogicService/evaluateConditionalPredicate.js.map +1 -1
- package/dist/conditionalLogicService/generateFormElementsConditionallyShown.js +12 -19
- package/dist/conditionalLogicService/generateFormElementsConditionallyShown.js.map +1 -1
- package/dist/conditionalLogicService/types.js +1 -2
- package/dist/conditionalLogicService.d.ts +1 -1
- package/dist/conditionalLogicService.js +6 -26
- package/dist/conditionalLogicService.js.map +1 -1
- package/dist/fileUploadService.js +2 -6
- package/dist/fileUploadService.js.map +1 -1
- package/dist/form-elements-regex.js +10 -14
- package/dist/form-elements-regex.js.map +1 -1
- package/dist/formElementsService.d.ts +2 -3
- package/dist/formElementsService.js +4 -15
- package/dist/formElementsService.js.map +1 -1
- package/dist/freshdeskService.d.ts +1 -1
- package/dist/freshdeskService.js +23 -31
- package/dist/freshdeskService.js.map +1 -1
- package/dist/goodToGoService.d.ts +1 -1
- package/dist/goodToGoService.js +2 -6
- package/dist/goodToGoService.js.map +1 -1
- package/dist/index.d.ts +14 -14
- package/dist/index.js +14 -50
- package/dist/index.js.map +1 -1
- package/dist/paymentService.d.ts +1 -1
- package/dist/paymentService.js +11 -18
- package/dist/paymentService.js.map +1 -1
- package/dist/replaceCustomValues.js +42 -50
- package/dist/replaceCustomValues.js.map +1 -1
- package/dist/schedulingService.js +3 -6
- package/dist/schedulingService.js.map +1 -1
- package/dist/sharepointService.d.ts +1 -1
- package/dist/sharepointService.js +4 -8
- package/dist/sharepointService.js.map +1 -1
- package/dist/submissionService.d.ts +1 -1
- package/dist/submissionService.js +4 -21
- package/dist/submissionService.js.map +1 -1
- package/dist/typeCastService.js +1 -5
- package/dist/typeCastService.js.map +1 -1
- package/dist/typedoc.d.ts +1 -1
- package/dist/typedoc.js +2 -18
- package/dist/typedoc.js.map +1 -1
- package/dist/types/resource-definitions.js +1 -2
- package/dist/userService.js +8 -11
- package/dist/userService.js.map +1 -1
- package/dist/webhookSubscriptionService.js +1 -3
- package/dist/webhookSubscriptionService.js.map +1 -1
- package/package.json +25 -27
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"freshdeskService.js","sourceRoot":"","sources":["../src/freshdeskService.ts"],"names":[],"mappings":";;;AAmDA,0FA2GC;AASD,4DA2CC;AA5MY,QAAA,kBAAkB,GAAG,kBAAkB,CAAA;AACvC,QAAA,cAAc,GAAG,mBAAmB,CAAA;AACpC,QAAA,cAAc,GAAG;IAC5B,0BAAkB;IAClB,aAAa;IACb,iBAAiB;IACjB,sBAAc;CACf,CAAA;AAEY,QAAA,gBAAgB,GAAG,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAA;AAEtD,QAAA,aAAa,GAAG,aAAa,CAAA;AAC7B,QAAA,iBAAiB,GAAG,iBAAiB,CAAA;AACrC,QAAA,gBAAgB,GAAG;IAC9B,iBAAiB;IACjB,yBAAiB;IACjB,kBAAkB;IAClB,gBAAgB;IAChB,gBAAgB;IAChB,qBAAqB;IACrB,eAAe;IACf,eAAe;CAChB,CAAA;AAuBD,SAAgB,uCAAuC,CACrD,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AAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;gBAC3D,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;oBAC9B,OAAO;wBACL,KAAK,EAAE,GAAG;wBACV,KAAK;qBACN,CAAA;gBACH,CAAC;qBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;oBAChC,OAAO;wBACL,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;wBACf,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;qBACrB,CAAA;gBACH,CAAC;qBAAM,CAAC;oBACN,OAAO;wBACL,KAAK,EAAE,GAAG;wBACV,KAAK,EAAE,GAAG;wBACV,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;4BAC5D,KAAK,EAAE,WAAW;4BAClB,KAAK,EAAE,WAAW;4BAClB,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gCAC5B,KAAK,EAAE,IAAI;gCACX,KAAK,EAAE,IAAI;6BACZ,CAAC,CAAC;yBACJ,CAAC,CAAC;qBACJ,CAAA;gBACH,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { FreshdeskTypes, SubmissionEventTypes } from '@oneblink/types'\nimport {\n ResourceDefinition,\n ResourceDefinitionChoice,\n} from './types/resource-definitions'\n\nexport const multilineFieldType = 'custom_paragraph'\nexport const emailFieldType = 'default_requester'\nexport const textFieldTypes = [\n multilineFieldType,\n 'custom_text',\n 'default_subject',\n emailFieldType,\n]\n\nexport const numberFieldTypes = ['custom_number', 'custom_decimal']\n\nexport const dateFieldType = 'custom_date'\nexport const checkboxFieldType = 'custom_checkbox'\nexport const choiceFieldTypes = [\n 'custom_dropdown',\n checkboxFieldType,\n 'default_priority',\n 'default_status',\n 'default_source',\n 'default_ticket_type',\n 'default_agent',\n 'default_group',\n]\n\nexport type FreshdeskFieldDefinition =\n | ResourceDefinition<SubmissionEventTypes.BaseFreshdeskSubmissionEventFieldMapping>\n | FreshdeskDependentField\n\nexport type FreshdeskFieldCategory = ResourceDefinitionChoice & {\n subCategories: Array<\n ResourceDefinitionChoice & {\n items: Array<ResourceDefinitionChoice>\n }\n >\n}\n\nexport type FreshdeskDependentField = {\n type: 'DEPENDENT_FIELD'\n id: string\n isRequired: boolean\n displayName: string\n freshdeskFieldName: string\n choices: FreshdeskFieldCategory[]\n}\n\nexport function generateFreshdeskTicketFieldDefinitions(\n fields: FreshdeskTypes.FreshdeskField[],\n) {\n return setFreshdeskFieldOptions(fields).reduce<FreshdeskFieldDefinition[]>(\n (memo, freshdeskField) => {\n const isCheckboxField = freshdeskField.type === checkboxFieldType\n const isRequired =\n freshdeskField.required_for_customers ||\n freshdeskField.name === 'ticket_type'\n const isTextField = textFieldTypes.includes(freshdeskField.type)\n const isMultilineTextField = freshdeskField.type === multilineFieldType\n const isEmailField = freshdeskField.type === emailFieldType\n const isDateField = freshdeskField.type === dateFieldType\n const isNumberField = numberFieldTypes.includes(freshdeskField.type)\n const isChoiceField = choiceFieldTypes.includes(freshdeskField.type)\n\n const baseField = {\n id: freshdeskField.id.toString(),\n displayName: freshdeskField.label_for_customers,\n isRequired,\n freshdeskFieldName: freshdeskField.name,\n }\n if (isCheckboxField) {\n memo.push({\n type: 'BOOLEAN',\n ...baseField,\n })\n } else if (isDateField) {\n memo.push({\n type: 'DATE',\n ...baseField,\n })\n } else if (isNumberField) {\n memo.push({\n type: 'NUMBER',\n ...baseField,\n })\n } else if (isEmailField) {\n memo.push({\n type: 'EMAIL',\n ...baseField,\n })\n } else if (isMultilineTextField) {\n memo.push({\n type: 'TEXT_MULTI_LINE',\n ...baseField,\n })\n } else if (isTextField) {\n memo.push({\n type: 'TEXT_SINGLE_LINE',\n ...baseField,\n })\n } else if (freshdeskField.options && isChoiceField) {\n memo.push({\n type: 'CHOICE_SINGLE',\n ...baseField,\n choices: freshdeskField.options,\n })\n } else if (\n freshdeskField.type === 'nested_field' &&\n freshdeskField.options?.length\n ) {\n const choices = freshdeskField.options.reduce<FreshdeskFieldCategory[]>(\n (categoriesMemo, category) => {\n const subCategories = category.options?.reduce<\n FreshdeskFieldCategory['subCategories']\n >((subCategoriesMemo, subCategory) => {\n if (subCategory.options?.length) {\n subCategoriesMemo.push({\n value: subCategory.value,\n label: subCategory.label,\n items: subCategory.options.map(({ value, label }) => ({\n value,\n label,\n })),\n })\n }\n\n return subCategoriesMemo\n }, [])\n\n if (subCategories?.length) {\n categoriesMemo.push({\n value: category.value,\n label: category.label,\n subCategories,\n })\n }\n\n return categoriesMemo\n },\n [],\n )\n\n if (choices.length) {\n memo.push({\n type: 'DEPENDENT_FIELD',\n ...baseField,\n choices,\n })\n }\n }\n\n return memo\n },\n [],\n )\n}\n\n/**\n * This function is used to transform the `choices` property into the `options`\n * property for freshdesk fields.\n *\n * @param fields\n * @returns\n */\nexport function setFreshdeskFieldOptions(\n fields: FreshdeskTypes.FreshdeskField[],\n): FreshdeskTypes.FreshdeskField[] {\n for (const field of fields) {\n const choices = field.choices\n if (!choices) {\n continue\n }\n if (Array.isArray(choices)) {\n field.options = choices.map((choice) => ({\n label: choice,\n value: choice,\n }))\n } else if (typeof choices === 'object') {\n field.options = Object.entries(choices).map(([key, value]) => {\n if (typeof value === 'number') {\n return {\n label: key,\n value,\n }\n } else if (Array.isArray(value)) {\n return {\n label: value[0],\n value: parseInt(key),\n }\n } else {\n return {\n label: key,\n value: key,\n options: Object.entries(value).map(([subCategory, items]) => ({\n label: subCategory,\n value: subCategory,\n options: items.map((item) => ({\n label: item,\n value: item,\n })),\n })),\n }\n }\n })\n }\n }\n return fields\n}\n"]}
|
|
1
|
+
{"version":3,"file":"freshdeskService.js","sourceRoot":"","sources":["../src/freshdeskService.ts"],"names":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5B,KAAK,EAAE,IAAI;gCACX,KAAK,EAAE,IAAI;6BACZ,CAAC,CAAC;yBACJ,CAAC,CAAC;qBACJ,CAAA;gBACH,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { FreshdeskTypes, SubmissionEventTypes } from '@oneblink/types'\nimport {\n ResourceDefinition,\n ResourceDefinitionChoice,\n} from './types/resource-definitions.js'\n\nexport const multilineFieldType = 'custom_paragraph'\nexport const emailFieldType = 'default_requester'\nexport const textFieldTypes = [\n multilineFieldType,\n 'custom_text',\n 'default_subject',\n emailFieldType,\n]\n\nexport const numberFieldTypes = ['custom_number', 'custom_decimal']\n\nexport const dateFieldType = 'custom_date'\nexport const checkboxFieldType = 'custom_checkbox'\nexport const choiceFieldTypes = [\n 'custom_dropdown',\n checkboxFieldType,\n 'default_priority',\n 'default_status',\n 'default_source',\n 'default_ticket_type',\n 'default_agent',\n 'default_group',\n]\n\nexport type FreshdeskFieldDefinition =\n | ResourceDefinition<SubmissionEventTypes.BaseFreshdeskSubmissionEventFieldMapping>\n | FreshdeskDependentField\n\nexport type FreshdeskFieldCategory = ResourceDefinitionChoice & {\n subCategories: Array<\n ResourceDefinitionChoice & {\n items: Array<ResourceDefinitionChoice>\n }\n >\n}\n\nexport type FreshdeskDependentField = {\n type: 'DEPENDENT_FIELD'\n id: string\n isRequired: boolean\n displayName: string\n freshdeskFieldName: string\n choices: FreshdeskFieldCategory[]\n}\n\nexport function generateFreshdeskTicketFieldDefinitions(\n fields: FreshdeskTypes.FreshdeskField[],\n) {\n return setFreshdeskFieldOptions(fields).reduce<FreshdeskFieldDefinition[]>(\n (memo, freshdeskField) => {\n const isCheckboxField = freshdeskField.type === checkboxFieldType\n const isRequired =\n freshdeskField.required_for_customers ||\n freshdeskField.name === 'ticket_type'\n const isTextField = textFieldTypes.includes(freshdeskField.type)\n const isMultilineTextField = freshdeskField.type === multilineFieldType\n const isEmailField = freshdeskField.type === emailFieldType\n const isDateField = freshdeskField.type === dateFieldType\n const isNumberField = numberFieldTypes.includes(freshdeskField.type)\n const isChoiceField = choiceFieldTypes.includes(freshdeskField.type)\n\n const baseField = {\n id: freshdeskField.id.toString(),\n displayName: freshdeskField.label_for_customers,\n isRequired,\n freshdeskFieldName: freshdeskField.name,\n }\n if (isCheckboxField) {\n memo.push({\n type: 'BOOLEAN',\n ...baseField,\n })\n } else if (isDateField) {\n memo.push({\n type: 'DATE',\n ...baseField,\n })\n } else if (isNumberField) {\n memo.push({\n type: 'NUMBER',\n ...baseField,\n })\n } else if (isEmailField) {\n memo.push({\n type: 'EMAIL',\n ...baseField,\n })\n } else if (isMultilineTextField) {\n memo.push({\n type: 'TEXT_MULTI_LINE',\n ...baseField,\n })\n } else if (isTextField) {\n memo.push({\n type: 'TEXT_SINGLE_LINE',\n ...baseField,\n })\n } else if (freshdeskField.options && isChoiceField) {\n memo.push({\n type: 'CHOICE_SINGLE',\n ...baseField,\n choices: freshdeskField.options,\n })\n } else if (\n freshdeskField.type === 'nested_field' &&\n freshdeskField.options?.length\n ) {\n const choices = freshdeskField.options.reduce<FreshdeskFieldCategory[]>(\n (categoriesMemo, category) => {\n const subCategories = category.options?.reduce<\n FreshdeskFieldCategory['subCategories']\n >((subCategoriesMemo, subCategory) => {\n if (subCategory.options?.length) {\n subCategoriesMemo.push({\n value: subCategory.value,\n label: subCategory.label,\n items: subCategory.options.map(({ value, label }) => ({\n value,\n label,\n })),\n })\n }\n\n return subCategoriesMemo\n }, [])\n\n if (subCategories?.length) {\n categoriesMemo.push({\n value: category.value,\n label: category.label,\n subCategories,\n })\n }\n\n return categoriesMemo\n },\n [],\n )\n\n if (choices.length) {\n memo.push({\n type: 'DEPENDENT_FIELD',\n ...baseField,\n choices,\n })\n }\n }\n\n return memo\n },\n [],\n )\n}\n\n/**\n * This function is used to transform the `choices` property into the `options`\n * property for freshdesk fields.\n *\n * @param fields\n * @returns\n */\nexport function setFreshdeskFieldOptions(\n fields: FreshdeskTypes.FreshdeskField[],\n): FreshdeskTypes.FreshdeskField[] {\n for (const field of fields) {\n const choices = field.choices\n if (!choices) {\n continue\n }\n if (Array.isArray(choices)) {\n field.options = choices.map((choice) => ({\n label: choice,\n value: choice,\n }))\n } else if (typeof choices === 'object') {\n field.options = Object.entries(choices).map(([key, value]) => {\n if (typeof value === 'number') {\n return {\n label: key,\n value,\n }\n } else if (Array.isArray(value)) {\n return {\n label: value[0],\n value: parseInt(key),\n }\n } else {\n return {\n label: key,\n value: key,\n options: Object.entries(value).map(([subCategory, items]) => ({\n label: subCategory,\n value: subCategory,\n options: items.map((item) => ({\n label: item,\n value: item,\n })),\n })),\n }\n }\n })\n }\n }\n return fields\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GetFieldResponse } from '@spotto/contract';
|
|
2
2
|
import { SubmissionEventTypes } from '@oneblink/types';
|
|
3
|
-
import { ResourceDefinition } from './types/resource-definitions';
|
|
3
|
+
import { ResourceDefinition } from './types/resource-definitions.js';
|
|
4
4
|
export type GoodToGoFieldResourceDefinition = ResourceDefinition<SubmissionEventTypes.GoodToGoUpdateAssetResourceDefinition>;
|
|
5
5
|
export declare function generateGoodToGoFieldResourceDefinitions(fieldDefinitions: GetFieldResponse[]): GoodToGoFieldResourceDefinition[];
|
package/dist/goodToGoService.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateGoodToGoFieldResourceDefinitions = generateGoodToGoFieldResourceDefinitions;
|
|
4
1
|
function generateCommonConfig(fieldDefinition) {
|
|
5
|
-
var _a;
|
|
6
2
|
return {
|
|
7
3
|
id: fieldDefinition.id,
|
|
8
4
|
goodToGoCustomFieldName: fieldDefinition.name,
|
|
9
5
|
isRequired: !!fieldDefinition.required,
|
|
10
|
-
displayName:
|
|
6
|
+
displayName: fieldDefinition.label ?? fieldDefinition.name,
|
|
11
7
|
};
|
|
12
8
|
}
|
|
13
|
-
function generateGoodToGoFieldResourceDefinitions(fieldDefinitions) {
|
|
9
|
+
export function generateGoodToGoFieldResourceDefinitions(fieldDefinitions) {
|
|
14
10
|
return fieldDefinitions.reduce((memo, fieldDefinition) => {
|
|
15
11
|
switch (fieldDefinition.inputType) {
|
|
16
12
|
case 'SINGLELINE':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"goodToGoService.js","sourceRoot":"","sources":["../src/goodToGoService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"goodToGoService.js","sourceRoot":"","sources":["../src/goodToGoService.ts"],"names":[],"mappings":"AAQA,SAAS,oBAAoB,CAAC,eAAiC;IAC7D,OAAO;QACL,EAAE,EAAE,eAAe,CAAC,EAAE;QACtB,uBAAuB,EAAE,eAAe,CAAC,IAAI;QAC7C,UAAU,EAAE,CAAC,CAAC,eAAe,CAAC,QAAQ;QACtC,WAAW,EAAE,eAAe,CAAC,KAAK,IAAI,eAAe,CAAC,IAAI;KAC3D,CAAA;AACH,CAAC;AAED,MAAM,UAAU,wCAAwC,CACtD,gBAAoC;IAEpC,OAAO,gBAAgB,CAAC,MAAM,CAC5B,CAAC,IAAI,EAAE,eAAe,EAAE,EAAE;QACxB,QAAQ,eAAe,CAAC,SAAS,EAAE,CAAC;YAClC,KAAK,YAAY;gBACf,IAAI,CAAC,IAAI,CAAC;oBACR,IAAI,EAAE,kBAAkB;oBACxB,GAAG,oBAAoB,CAAC,eAAe,CAAC;iBACzC,CAAC,CAAA;gBACF,MAAK;YACP,KAAK,UAAU,CAAC;YAChB,KAAK,WAAW;gBACd,IAAI,CAAC,IAAI,CAAC;oBACR,IAAI,EAAE,iBAAiB;oBACvB,GAAG,oBAAoB,CAAC,eAAe,CAAC;iBACzC,CAAC,CAAA;gBACF,MAAK;YACP,KAAK,OAAO,CAAC;YACb,KAAK,UAAU;gBACb,IAAI,eAAe,CAAC,OAAO,EAAE,CAA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CAAC;iBACzC,CAAC,CAAA;gBACF,MAAK;YACP,KAAK,MAAM;gBACT,IAAI,CAAC,IAAI,CAAC;oBACR,IAAI,EAAE,KAAK;oBACX,GAAG,oBAAoB,CAAC,eAAe,CAAC;iBACzC,CAAC,CAAA;gBACF,MAAK;YACP,KAAK,SAAS;gBACZ,MAAK;YACP,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,CAAC,GAAU,eAAe,CAAC,SAAS,CAAA;gBAC1C,OAAO,CAAC,CAAA;YACV,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC,EACD,EAAE,CACH,CAAA;AACH,CAAC","sourcesContent":["import { GetFieldResponse } from '@spotto/contract'\nimport { SubmissionEventTypes } from '@oneblink/types'\n\nimport { ResourceDefinition } from './types/resource-definitions.js'\n\nexport type GoodToGoFieldResourceDefinition =\n ResourceDefinition<SubmissionEventTypes.GoodToGoUpdateAssetResourceDefinition>\n\nfunction generateCommonConfig(fieldDefinition: GetFieldResponse) {\n return {\n id: fieldDefinition.id,\n goodToGoCustomFieldName: fieldDefinition.name,\n isRequired: !!fieldDefinition.required,\n displayName: fieldDefinition.label ?? fieldDefinition.name,\n }\n}\n\nexport function generateGoodToGoFieldResourceDefinitions(\n fieldDefinitions: GetFieldResponse[],\n) {\n return fieldDefinitions.reduce<GoodToGoFieldResourceDefinition[]>(\n (memo, fieldDefinition) => {\n switch (fieldDefinition.inputType) {\n case 'SINGLELINE':\n memo.push({\n type: 'TEXT_SINGLE_LINE',\n ...generateCommonConfig(fieldDefinition),\n })\n break\n case 'RICHTEXT':\n case 'MULTILINE':\n memo.push({\n type: 'TEXT_MULTI_LINE',\n ...generateCommonConfig(fieldDefinition),\n })\n break\n case 'RADIO':\n case 'DROPDOWN':\n if (fieldDefinition.options) {\n memo.push({\n type: 'CHOICE_SINGLE',\n ...generateCommonConfig(fieldDefinition),\n choices: fieldDefinition.options.map((option) => ({\n label: option,\n value: option,\n })),\n })\n }\n break\n case 'CHECKBOXES':\n if (fieldDefinition.options) {\n memo.push({\n type: 'CHOICE_MULTIPLE',\n ...generateCommonConfig(fieldDefinition),\n choices: fieldDefinition.options.map((option) => ({\n label: option,\n value: option,\n })),\n })\n }\n break\n case 'DATE':\n case 'DATETIME':\n memo.push({\n type: fieldDefinition.inputType,\n ...generateCommonConfig(fieldDefinition),\n })\n break\n case 'DECIMAL':\n memo.push({\n type: 'NUMBER',\n ...generateCommonConfig(fieldDefinition),\n })\n break\n case 'INTEGER':\n memo.push({\n type: 'INTEGER',\n ...generateCommonConfig(fieldDefinition),\n })\n break\n case 'SWITCH':\n memo.push({\n type: 'BOOLEAN',\n ...generateCommonConfig(fieldDefinition),\n })\n break\n case 'LINK':\n memo.push({\n type: 'URL',\n ...generateCommonConfig(fieldDefinition),\n })\n break\n case undefined:\n break\n default: {\n const n: never = fieldDefinition.inputType\n return n\n }\n }\n\n return memo\n },\n [],\n )\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * as resourceDefinitionTypes from './types/resource-definitions';
|
|
1
|
+
export * as resourceDefinitionTypes from './types/resource-definitions.js';
|
|
2
2
|
/**
|
|
3
3
|
* ## Form Elements Service
|
|
4
4
|
*
|
|
@@ -8,7 +8,7 @@ export * as resourceDefinitionTypes from './types/resource-definitions';
|
|
|
8
8
|
* import { formElementsService } from '@oneblink/sdk-core'
|
|
9
9
|
* ```
|
|
10
10
|
*/
|
|
11
|
-
export * as formElementsService from './formElementsService';
|
|
11
|
+
export * as formElementsService from './formElementsService.js';
|
|
12
12
|
/**
|
|
13
13
|
* ## Conditional Logic Service
|
|
14
14
|
*
|
|
@@ -18,7 +18,7 @@ export * as formElementsService from './formElementsService';
|
|
|
18
18
|
* import { conditionalLogicService } from '@oneblink/sdk-core'
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
|
-
export * as conditionalLogicService from './conditionalLogicService';
|
|
21
|
+
export * as conditionalLogicService from './conditionalLogicService.js';
|
|
22
22
|
/**
|
|
23
23
|
* ## Submission Service
|
|
24
24
|
*
|
|
@@ -28,7 +28,7 @@ export * as conditionalLogicService from './conditionalLogicService';
|
|
|
28
28
|
* import { submissionService } from '@oneblink/sdk-core'
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
export * as submissionService from './submissionService';
|
|
31
|
+
export * as submissionService from './submissionService.js';
|
|
32
32
|
/**
|
|
33
33
|
* ## Submission Service
|
|
34
34
|
*
|
|
@@ -38,7 +38,7 @@ export * as submissionService from './submissionService';
|
|
|
38
38
|
* import { typeCastService } from '@oneblink/sdk-core'
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
|
-
export * as typeCastService from './typeCastService';
|
|
41
|
+
export * as typeCastService from './typeCastService.js';
|
|
42
42
|
/**
|
|
43
43
|
* ## User Service
|
|
44
44
|
*
|
|
@@ -48,7 +48,7 @@ export * as typeCastService from './typeCastService';
|
|
|
48
48
|
* import { userService } from '@oneblink/sdk-core'
|
|
49
49
|
* ```
|
|
50
50
|
*/
|
|
51
|
-
export * as userService from './userService';
|
|
51
|
+
export * as userService from './userService.js';
|
|
52
52
|
/**
|
|
53
53
|
* ## ABN Service
|
|
54
54
|
*
|
|
@@ -58,7 +58,7 @@ export * as userService from './userService';
|
|
|
58
58
|
* import { abnService } from '@oneblink/sdk-core'
|
|
59
59
|
* ```
|
|
60
60
|
*/
|
|
61
|
-
export * as abnService from './abnService';
|
|
61
|
+
export * as abnService from './abnService.js';
|
|
62
62
|
/**
|
|
63
63
|
* ## Payment Service
|
|
64
64
|
*
|
|
@@ -68,7 +68,7 @@ export * as abnService from './abnService';
|
|
|
68
68
|
* import { paymentService } from '@oneblink/sdk-core'
|
|
69
69
|
* ```
|
|
70
70
|
*/
|
|
71
|
-
export * as paymentService from './paymentService';
|
|
71
|
+
export * as paymentService from './paymentService.js';
|
|
72
72
|
/**
|
|
73
73
|
* ## Scheduling Service
|
|
74
74
|
*
|
|
@@ -78,7 +78,7 @@ export * as paymentService from './paymentService';
|
|
|
78
78
|
* import { schedulingService } from '@oneblink/sdk-core'
|
|
79
79
|
* ```
|
|
80
80
|
*/
|
|
81
|
-
export * as schedulingService from './schedulingService';
|
|
81
|
+
export * as schedulingService from './schedulingService.js';
|
|
82
82
|
/**
|
|
83
83
|
* ## File Upload Service
|
|
84
84
|
*
|
|
@@ -88,7 +88,7 @@ export * as schedulingService from './schedulingService';
|
|
|
88
88
|
* import { fileUploadService } from '@oneblink/sdk-core'
|
|
89
89
|
* ```
|
|
90
90
|
*/
|
|
91
|
-
export * as fileUploadService from './fileUploadService';
|
|
91
|
+
export * as fileUploadService from './fileUploadService.js';
|
|
92
92
|
/**
|
|
93
93
|
* ## Webhook Subscription Service
|
|
94
94
|
*
|
|
@@ -98,7 +98,7 @@ export * as fileUploadService from './fileUploadService';
|
|
|
98
98
|
* import { webhookSubscriptionService } from '@oneblink/sdk-core'
|
|
99
99
|
* ```
|
|
100
100
|
*/
|
|
101
|
-
export * as webhookSubscriptionService from './webhookSubscriptionService';
|
|
101
|
+
export * as webhookSubscriptionService from './webhookSubscriptionService.js';
|
|
102
102
|
/**
|
|
103
103
|
* ## SharePoint Service
|
|
104
104
|
*
|
|
@@ -108,7 +108,7 @@ export * as webhookSubscriptionService from './webhookSubscriptionService';
|
|
|
108
108
|
* import { sharepointService } from '@oneblink/sdk-core'
|
|
109
109
|
* ```
|
|
110
110
|
*/
|
|
111
|
-
export * as sharepointService from './sharepointService';
|
|
111
|
+
export * as sharepointService from './sharepointService.js';
|
|
112
112
|
/**
|
|
113
113
|
* ## Freshdesk Service
|
|
114
114
|
*
|
|
@@ -118,7 +118,7 @@ export * as sharepointService from './sharepointService';
|
|
|
118
118
|
* import { freshdeskService } from '@oneblink/sdk-core'
|
|
119
119
|
* ```
|
|
120
120
|
*/
|
|
121
|
-
export * as freshdeskService from './freshdeskService';
|
|
121
|
+
export * as freshdeskService from './freshdeskService.js';
|
|
122
122
|
/**
|
|
123
123
|
* ## GoodToGo Service
|
|
124
124
|
*
|
|
@@ -128,4 +128,4 @@ export * as freshdeskService from './freshdeskService';
|
|
|
128
128
|
* import { goodToGoService } from '@oneblink/sdk-core'
|
|
129
129
|
* ```
|
|
130
130
|
*/
|
|
131
|
-
export * as goodToGoService from './goodToGoService';
|
|
131
|
+
export * as goodToGoService from './goodToGoService.js';
|
package/dist/index.js
CHANGED
|
@@ -1,40 +1,4 @@
|
|
|
1
|
-
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.goodToGoService = exports.freshdeskService = exports.sharepointService = exports.webhookSubscriptionService = exports.fileUploadService = exports.schedulingService = exports.paymentService = exports.abnService = exports.userService = exports.typeCastService = exports.submissionService = exports.conditionalLogicService = exports.formElementsService = exports.resourceDefinitionTypes = void 0;
|
|
37
|
-
exports.resourceDefinitionTypes = __importStar(require("./types/resource-definitions"));
|
|
1
|
+
export * as resourceDefinitionTypes from './types/resource-definitions.js';
|
|
38
2
|
/**
|
|
39
3
|
* ## Form Elements Service
|
|
40
4
|
*
|
|
@@ -44,7 +8,7 @@ exports.resourceDefinitionTypes = __importStar(require("./types/resource-definit
|
|
|
44
8
|
* import { formElementsService } from '@oneblink/sdk-core'
|
|
45
9
|
* ```
|
|
46
10
|
*/
|
|
47
|
-
|
|
11
|
+
export * as formElementsService from './formElementsService.js';
|
|
48
12
|
/**
|
|
49
13
|
* ## Conditional Logic Service
|
|
50
14
|
*
|
|
@@ -54,7 +18,7 @@ exports.formElementsService = __importStar(require("./formElementsService"));
|
|
|
54
18
|
* import { conditionalLogicService } from '@oneblink/sdk-core'
|
|
55
19
|
* ```
|
|
56
20
|
*/
|
|
57
|
-
|
|
21
|
+
export * as conditionalLogicService from './conditionalLogicService.js';
|
|
58
22
|
/**
|
|
59
23
|
* ## Submission Service
|
|
60
24
|
*
|
|
@@ -64,7 +28,7 @@ exports.conditionalLogicService = __importStar(require("./conditionalLogicServic
|
|
|
64
28
|
* import { submissionService } from '@oneblink/sdk-core'
|
|
65
29
|
* ```
|
|
66
30
|
*/
|
|
67
|
-
|
|
31
|
+
export * as submissionService from './submissionService.js';
|
|
68
32
|
/**
|
|
69
33
|
* ## Submission Service
|
|
70
34
|
*
|
|
@@ -74,7 +38,7 @@ exports.submissionService = __importStar(require("./submissionService"));
|
|
|
74
38
|
* import { typeCastService } from '@oneblink/sdk-core'
|
|
75
39
|
* ```
|
|
76
40
|
*/
|
|
77
|
-
|
|
41
|
+
export * as typeCastService from './typeCastService.js';
|
|
78
42
|
/**
|
|
79
43
|
* ## User Service
|
|
80
44
|
*
|
|
@@ -84,7 +48,7 @@ exports.typeCastService = __importStar(require("./typeCastService"));
|
|
|
84
48
|
* import { userService } from '@oneblink/sdk-core'
|
|
85
49
|
* ```
|
|
86
50
|
*/
|
|
87
|
-
|
|
51
|
+
export * as userService from './userService.js';
|
|
88
52
|
/**
|
|
89
53
|
* ## ABN Service
|
|
90
54
|
*
|
|
@@ -94,7 +58,7 @@ exports.userService = __importStar(require("./userService"));
|
|
|
94
58
|
* import { abnService } from '@oneblink/sdk-core'
|
|
95
59
|
* ```
|
|
96
60
|
*/
|
|
97
|
-
|
|
61
|
+
export * as abnService from './abnService.js';
|
|
98
62
|
/**
|
|
99
63
|
* ## Payment Service
|
|
100
64
|
*
|
|
@@ -104,7 +68,7 @@ exports.abnService = __importStar(require("./abnService"));
|
|
|
104
68
|
* import { paymentService } from '@oneblink/sdk-core'
|
|
105
69
|
* ```
|
|
106
70
|
*/
|
|
107
|
-
|
|
71
|
+
export * as paymentService from './paymentService.js';
|
|
108
72
|
/**
|
|
109
73
|
* ## Scheduling Service
|
|
110
74
|
*
|
|
@@ -114,7 +78,7 @@ exports.paymentService = __importStar(require("./paymentService"));
|
|
|
114
78
|
* import { schedulingService } from '@oneblink/sdk-core'
|
|
115
79
|
* ```
|
|
116
80
|
*/
|
|
117
|
-
|
|
81
|
+
export * as schedulingService from './schedulingService.js';
|
|
118
82
|
/**
|
|
119
83
|
* ## File Upload Service
|
|
120
84
|
*
|
|
@@ -124,7 +88,7 @@ exports.schedulingService = __importStar(require("./schedulingService"));
|
|
|
124
88
|
* import { fileUploadService } from '@oneblink/sdk-core'
|
|
125
89
|
* ```
|
|
126
90
|
*/
|
|
127
|
-
|
|
91
|
+
export * as fileUploadService from './fileUploadService.js';
|
|
128
92
|
/**
|
|
129
93
|
* ## Webhook Subscription Service
|
|
130
94
|
*
|
|
@@ -134,7 +98,7 @@ exports.fileUploadService = __importStar(require("./fileUploadService"));
|
|
|
134
98
|
* import { webhookSubscriptionService } from '@oneblink/sdk-core'
|
|
135
99
|
* ```
|
|
136
100
|
*/
|
|
137
|
-
|
|
101
|
+
export * as webhookSubscriptionService from './webhookSubscriptionService.js';
|
|
138
102
|
/**
|
|
139
103
|
* ## SharePoint Service
|
|
140
104
|
*
|
|
@@ -144,7 +108,7 @@ exports.webhookSubscriptionService = __importStar(require("./webhookSubscription
|
|
|
144
108
|
* import { sharepointService } from '@oneblink/sdk-core'
|
|
145
109
|
* ```
|
|
146
110
|
*/
|
|
147
|
-
|
|
111
|
+
export * as sharepointService from './sharepointService.js';
|
|
148
112
|
/**
|
|
149
113
|
* ## Freshdesk Service
|
|
150
114
|
*
|
|
@@ -154,7 +118,7 @@ exports.sharepointService = __importStar(require("./sharepointService"));
|
|
|
154
118
|
* import { freshdeskService } from '@oneblink/sdk-core'
|
|
155
119
|
* ```
|
|
156
120
|
*/
|
|
157
|
-
|
|
121
|
+
export * as freshdeskService from './freshdeskService.js';
|
|
158
122
|
/**
|
|
159
123
|
* ## GoodToGo Service
|
|
160
124
|
*
|
|
@@ -164,5 +128,5 @@ exports.freshdeskService = __importStar(require("./freshdeskService"));
|
|
|
164
128
|
* import { goodToGoService } from '@oneblink/sdk-core'
|
|
165
129
|
* ```
|
|
166
130
|
*/
|
|
167
|
-
|
|
131
|
+
export * as goodToGoService from './goodToGoService.js';
|
|
168
132
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,uBAAuB,MAAM,iCAAiC,CAAA;AAC1E;;;;;;;;GAQG;AACH,OAAO,KAAK,mBAAmB,MAAM,0BAA0B,CAAA;AAC/D;;;;;;;;GAQG;AACH,OAAO,KAAK,uBAAuB,MAAM,8BAA8B,CAAA;AACvE;;;;;;;;GAQG;AACH,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAA;AAC3D;;;;;;;;GAQG;AACH,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AACvD;;;;;;;;GAQG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C;;;;;;;;GAQG;AACH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAC7C;;;;;;;;GAQG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD;;;;;;;;GAQG;AACH,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAA;AAC3D;;;;;;;;GAQG;AACH,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAA;AAC3D;;;;;;;;GAQG;AACH,OAAO,KAAK,0BAA0B,MAAM,iCAAiC,CAAA;AAC7E;;;;;;;;GAQG;AACH,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAA;AAE3D;;;;;;;;GAQG;AACH,OAAO,KAAK,gBAAgB,MAAM,uBAAuB,CAAA;AAEzD;;;;;;;;GAQG;AACH,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA","sourcesContent":["export * as resourceDefinitionTypes from './types/resource-definitions.js'\n/**\n * ## Form Elements Service\n *\n * Helper functions for handling form elements\n *\n * ```js\n * import { formElementsService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as formElementsService from './formElementsService.js'\n/**\n * ## Conditional Logic Service\n *\n * Helper functions for handling conditional logic\n *\n * ```js\n * import { conditionalLogicService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as conditionalLogicService from './conditionalLogicService.js'\n/**\n * ## Submission Service\n *\n * Helper functions for handling form submission data\n *\n * ```js\n * import { submissionService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as submissionService from './submissionService.js'\n/**\n * ## Submission Service\n *\n * Helper functions for casting types\n *\n * ```js\n * import { typeCastService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as typeCastService from './typeCastService.js'\n/**\n * ## User Service\n *\n * Helper functions for handling users\n *\n * ```js\n * import { userService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as userService from './userService.js'\n/**\n * ## ABN Service\n *\n * Helper functions for handling ABN Records\n *\n * ```js\n * import { abnService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as abnService from './abnService.js'\n/**\n * ## Payment Service\n *\n * Helper functions for payments\n *\n * ```js\n * import { paymentService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as paymentService from './paymentService.js'\n/**\n * ## Scheduling Service\n *\n * Helper functions for scheduling\n *\n * ```js\n * import { schedulingService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as schedulingService from './schedulingService.js'\n/**\n * ## File Upload Service\n *\n * Helper functions for handling file uploads\n *\n * ```js\n * import { fileUploadService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as fileUploadService from './fileUploadService.js'\n/**\n * ## Webhook Subscription Service\n *\n * Helper functions for handling Webhook subscriptions\n *\n * ```js\n * import { webhookSubscriptionService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as webhookSubscriptionService from './webhookSubscriptionService.js'\n/**\n * ## SharePoint Service\n *\n * Helper functions for handling SharePoint\n *\n * ```js\n * import { sharepointService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as sharepointService from './sharepointService.js'\n\n/**\n * ## Freshdesk Service\n *\n * Helper functions for handling Freshdesk\n *\n * ```js\n * import { freshdeskService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as freshdeskService from './freshdeskService.js'\n\n/**\n * ## GoodToGo Service\n *\n * Helper functions for handling GoodToGo\n *\n * ```js\n * import { goodToGoService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as goodToGoService from './goodToGoService.js'\n"]}
|
package/dist/paymentService.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FormTypes, SubmissionEventTypes, SubmissionTypes } from '@oneblink/types';
|
|
2
|
-
import { ReplaceInjectablesFormatters } from './submissionService';
|
|
2
|
+
import { ReplaceInjectablesFormatters } from './submissionService.js';
|
|
3
3
|
/**
|
|
4
4
|
* Examine a submission and its form definition to validate whether a payment
|
|
5
5
|
* workflow event needs to run.
|
package/dist/paymentService.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getDisplayDetailsFromFormSubmissionPayment = void 0;
|
|
4
|
-
exports.checkForPaymentEvent = checkForPaymentEvent;
|
|
5
|
-
const _1 = require(".");
|
|
6
|
-
const submissionService_1 = require("./submissionService");
|
|
1
|
+
import { conditionalLogicService, formElementsService } from './index.js';
|
|
2
|
+
import { getRootElementValueById, } from './submissionService.js';
|
|
7
3
|
/**
|
|
8
4
|
* Examine a submission and its form definition to validate whether a payment
|
|
9
5
|
* workflow event needs to run.
|
|
@@ -18,11 +14,11 @@ const submissionService_1 = require("./submissionService");
|
|
|
18
14
|
* @param submission
|
|
19
15
|
* @returns
|
|
20
16
|
*/
|
|
21
|
-
function checkForPaymentEvent(definition, submission) {
|
|
17
|
+
export function checkForPaymentEvent(definition, submission) {
|
|
22
18
|
const paymentSubmissionEvents = definition.paymentEvents || [];
|
|
23
19
|
const paymentSubmissionEvent = paymentSubmissionEvents.find((paymentSubmissionEvent) => {
|
|
24
20
|
return (paymentSubmissionEvent &&
|
|
25
|
-
|
|
21
|
+
conditionalLogicService.evaluateConditionalPredicates({
|
|
26
22
|
isConditional: !!paymentSubmissionEvent.conditionallyExecute,
|
|
27
23
|
requiresAllConditionalPredicates: !!paymentSubmissionEvent.requiresAllConditionallyExecutePredicates,
|
|
28
24
|
conditionalPredicates: paymentSubmissionEvent.conditionallyExecutePredicates || [],
|
|
@@ -34,13 +30,13 @@ function checkForPaymentEvent(definition, submission) {
|
|
|
34
30
|
return;
|
|
35
31
|
}
|
|
36
32
|
console.log('Checking if submission with payment submission event needs processing');
|
|
37
|
-
const amountElement =
|
|
33
|
+
const amountElement = formElementsService.findFormElement(definition.elements, (element) => element.id === paymentSubmissionEvent.configuration.elementId);
|
|
38
34
|
if (!amountElement || amountElement.type === 'page') {
|
|
39
35
|
console.log('Form has a payment submission event but the amount element does not exist, throwing error');
|
|
40
36
|
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.');
|
|
41
37
|
}
|
|
42
38
|
console.log('Found form element for payment submission event', amountElement);
|
|
43
|
-
const amount =
|
|
39
|
+
const amount = getRootElementValueById(amountElement.id, definition.elements, submission);
|
|
44
40
|
if (!amount) {
|
|
45
41
|
console.log('Form has a payment submission event but the amount has been entered as 0 or not at all, finishing as normal submission');
|
|
46
42
|
return;
|
|
@@ -76,10 +72,9 @@ function checkForPaymentEvent(definition, submission) {
|
|
|
76
72
|
* @param options
|
|
77
73
|
* @returns
|
|
78
74
|
*/
|
|
79
|
-
const getDisplayDetailsFromFormSubmissionPayment = (
|
|
75
|
+
export const getDisplayDetailsFromFormSubmissionPayment = (
|
|
80
76
|
/** The form submission payment to get the details from */
|
|
81
77
|
formSubmissionPayment, { formatCurrency, formatDateTime, formatDate, }) => {
|
|
82
|
-
var _a, _b;
|
|
83
78
|
switch (formSubmissionPayment.type) {
|
|
84
79
|
case 'NSW_GOV_PAY': {
|
|
85
80
|
const { paymentTransaction } = formSubmissionPayment;
|
|
@@ -116,7 +111,7 @@ formSubmissionPayment, { formatCurrency, formatDateTime, formatDate, }) => {
|
|
|
116
111
|
},
|
|
117
112
|
...(paymentTransaction.agencyCompletionPayment.paymentMethod ===
|
|
118
113
|
'BPAY' &&
|
|
119
|
-
|
|
114
|
+
paymentTransaction.agencyCompletionPayment.bPay?.billerCode
|
|
120
115
|
? [
|
|
121
116
|
{
|
|
122
117
|
key: 'NSW_GOV_PAY_BPAY_BILLER_CODE',
|
|
@@ -131,7 +126,7 @@ formSubmissionPayment, { formatCurrency, formatDateTime, formatDate, }) => {
|
|
|
131
126
|
{
|
|
132
127
|
key: 'NSW_GOV_PAY_CREDIT_CARD_NUMBER',
|
|
133
128
|
label: 'Card Number',
|
|
134
|
-
value: `xxxx xxxx xxxx ${
|
|
129
|
+
value: `xxxx xxxx xxxx ${paymentTransaction.agencyCompletionPayment.card?.last4Digits}`,
|
|
135
130
|
},
|
|
136
131
|
]
|
|
137
132
|
: []),
|
|
@@ -225,12 +220,11 @@ formSubmissionPayment, { formatCurrency, formatDateTime, formatDate, }) => {
|
|
|
225
220
|
return;
|
|
226
221
|
}
|
|
227
222
|
const determineDetails = () => {
|
|
228
|
-
var _a, _b;
|
|
229
223
|
switch (paymentTransaction.cpPayVersion) {
|
|
230
224
|
case 'v2': {
|
|
231
225
|
return {
|
|
232
226
|
transactionId: paymentTransaction.result.id,
|
|
233
|
-
orderNumber:
|
|
227
|
+
orderNumber: paymentTransaction.result.externalReferenceId ?? undefined,
|
|
234
228
|
paymentType: paymentTransaction.result.paymentType,
|
|
235
229
|
creditCardMask: paymentTransaction.result.lastFour
|
|
236
230
|
? `xxxx xxxx xxxx ${paymentTransaction.result.lastFour}`
|
|
@@ -250,7 +244,7 @@ formSubmissionPayment, { formatCurrency, formatDateTime, formatDate, }) => {
|
|
|
250
244
|
default: {
|
|
251
245
|
return {
|
|
252
246
|
transactionId: paymentTransaction.transactionId,
|
|
253
|
-
orderNumber:
|
|
247
|
+
orderNumber: paymentTransaction.orderNumber ?? undefined,
|
|
254
248
|
paymentType: paymentTransaction.paymentTypeId === 1
|
|
255
249
|
? 'Credit/Debit Card'
|
|
256
250
|
: paymentTransaction.paymentTypeId === 2
|
|
@@ -366,5 +360,4 @@ formSubmissionPayment, { formatCurrency, formatDateTime, formatDate, }) => {
|
|
|
366
360
|
}
|
|
367
361
|
}
|
|
368
362
|
};
|
|
369
|
-
exports.getDisplayDetailsFromFormSubmissionPayment = getDisplayDetailsFromFormSubmissionPayment;
|
|
370
363
|
//# sourceMappingURL=paymentService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paymentService.js","sourceRoot":"","sources":["../src/paymentService.ts"],"names":[],"mappings":";;;AAyBA,oDA6EC;AAjGD,wBAAgE;AAChE,2DAG4B;AAE5B;;;;;;;;;;;;;GAaG;AACH,SAAgB,oBAAoB,CAClC,UAA0B,EAC1B,UAA0D;IAO1D,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,CAAC;QAC5B,OAAM;IACR,CAAC;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,CAAC;QACpD,OAAO,CAAC,GAAG,CACT,2FAA2F,CAC5F,CAAA;QACD,MAAM,IAAI,KAAK,CACb,6KAA6K,CAC9K,CAAA;IACH,CAAC;IAED,OAAO,CAAC,G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AqC;wBAC1C,KAAK,EAAE,gBAAgB;wBACvB,KAAK,EAAE,kBAAkB,CAAC,aAAa;qBACxC;oBACD;wBACE,GAAG,EAAE,+CAA+C;wBACpD,KAAK,EAAE,mBAAmB;wBAC1B,KAAK,EAAE,kBAAkB,CAAC,sBAAsB;qBACjD;oBACD;wBACE,GAAG,EAAE,gDAAgD;wBACrD,KAAK,EAAE,2BAA2B;wBAClC,KAAK,EAAE,kBAAkB,CAAC,uBAAuB;qBAClD;oBACD;wBACE,GAAG,EAAE,6BAA6B;wBAClC,KAAK,EAAE,QAAQ;wBACf,KAAK,EAAE,MAAM,CAAC,SAAS;qBACxB;oBACD,GAAG,CAAC,kBAAkB,CAAC,eAAe,CAAC,MAAM;wBAC3C,CAAC,CAAC;4BACE;gCACE,GAAG,EAAE,uCAAgD;gCACrD,KAAK,EAAE,kBAAkB;gCACzB,KAAK,EAAE,cAAc,CACnB,UAAU,CACR,kBAAkB,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,EAAE,CACrD,CACF;6BACF;yBACF;wBACH,CAAC,CAAC,EAAE,CAAC;oBACP;wBACE,GAAG,EAAE,sCAAsC;wBAC3C,KAAK,EAAE,iBAAiB;wBACxB,KAAK,EAAE,UAAU,CAAC,kBAAkB,CAAC,cAAc,CAAC;qBACrD;iBACF;aACF,CAAA;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAA;AAhVY,QAAA,0CAA0C,8CAgVtD","sourcesContent":["import {\n FormTypes,\n SubmissionEventTypes,\n SubmissionTypes,\n} from '@oneblink/types'\nimport { conditionalLogicService, formElementsService } from '.'\nimport {\n getRootElementValueById,\n ReplaceInjectablesFormatters,\n} from './submissionService'\n\n/**\n * Examine a submission and its form definition to validate whether a payment\n * workflow event needs to run.\n *\n * #### Example\n *\n * ```js\n * const result = paymentService.checkForPaymentEvent(form, submission)\n * ```\n *\n * @param definition\n * @param submission\n * @returns\n */\nexport function checkForPaymentEvent(\n definition: FormTypes.Form,\n submission: SubmissionTypes.S3SubmissionData['submission'],\n):\n | {\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\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\ntype PaymentDisplayDetail = {\n label: string\n value: string\n /** A unique key across payment providers to identify the detail */\n key: SubmissionEventTypes.PaymentDisplayDetailKey\n}\n\n/**\n * Retrieve an array of detail items from a form submission payment.\n *\n * #### Example\n *\n * ```js\n * const detailItems =\n * paymentService.getDisplayDetailsFromFormSubmissionPayment(\n * formSubmissionPayment,\n * {\n * formatCurrency,\n * formatDateTime,\n * formatDate,\n * },\n * )\n * ```\n *\n * @param formSubmissionPayment\n * @param options\n * @returns\n */\nexport const getDisplayDetailsFromFormSubmissionPayment = (\n /** The form submission payment to get the details from */\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment,\n {\n formatCurrency,\n formatDateTime,\n formatDate,\n }: Pick<\n ReplaceInjectablesFormatters,\n 'formatCurrency' | 'formatDate' | 'formatDateTime'\n >,\n):\n | {\n amount: {\n value: number\n formatted: string\n }\n paymentDisplayDetails: PaymentDisplayDetail[]\n }\n | undefined => {\n switch (formSubmissionPayment.type) {\n case 'NSW_GOV_PAY': {\n const { paymentTransaction } = formSubmissionPayment\n if (!paymentTransaction || !paymentTransaction.agencyCompletionPayment) {\n return\n }\n\n const amount = {\n value: paymentTransaction.agencyCompletionPayment.amount,\n formatted: formatCurrency(\n paymentTransaction.agencyCompletionPayment.amount,\n ),\n }\n return {\n amount,\n paymentDisplayDetails: [\n {\n key: 'NSW_GOV_PAY_COMPLETION_REFERENCE',\n label: 'Completion Reference',\n value:\n paymentTransaction.agencyCompletionPayment\n .paymentCompletionReference,\n },\n {\n key: 'NSW_GOV_PAY_PAYMENT_REFERENCE',\n label: 'Payment Reference',\n value: paymentTransaction.agencyCompletionPayment.paymentReference,\n },\n {\n key: 'NSW_GOV_PAY_BANK_REFERENCE',\n label: 'Bank Reference',\n value: paymentTransaction.agencyCompletionPayment.bankReference,\n },\n {\n key: 'NSW_GOV_PAY_PAYMENT_METHOD',\n label: 'Payment Method',\n value: paymentTransaction.agencyCompletionPayment.paymentMethod,\n },\n ...(paymentTransaction.agencyCompletionPayment.paymentMethod ===\n 'BPAY' &&\n paymentTransaction.agencyCompletionPayment.bPay?.billerCode\n ? [\n {\n key: 'NSW_GOV_PAY_BPAY_BILLER_CODE' as const,\n label: 'BPay Biller Code',\n value:\n paymentTransaction.agencyCompletionPayment.bPay.billerCode,\n },\n ]\n : []),\n ...(paymentTransaction.agencyCompletionPayment.paymentMethod ===\n 'CARD'\n ? [\n {\n key: 'NSW_GOV_PAY_CREDIT_CARD_NUMBER' as const,\n label: 'Card Number',\n value: `xxxx xxxx xxxx ${paymentTransaction.agencyCompletionPayment.card?.last4Digits}`,\n },\n ]\n : []),\n {\n key: 'NSW_GOV_PAY_AMOUNT',\n label: 'Amount',\n value: amount.formatted,\n },\n {\n key: 'NSW_GOV_PAY_SURCHARGE_AMOUNT',\n label: 'Surcharge Amount',\n value: formatCurrency(\n paymentTransaction.agencyCompletionPayment.surcharge,\n ),\n },\n {\n key: 'NSW_GOV_PAY_SURCHARGE_GST',\n label: 'Surcharge GST',\n value: formatCurrency(\n paymentTransaction.agencyCompletionPayment.surchargeGst,\n ),\n },\n {\n key: 'NSW_GOV_PAY_CREATED_DATE_TIME',\n label: 'Created Date Time',\n value: formatDateTime(formSubmissionPayment.createdAt),\n },\n ],\n }\n }\n case 'BPOINT': {\n const { paymentTransaction } = formSubmissionPayment\n if (!paymentTransaction) {\n return\n }\n const amountValue = paymentTransaction.Amount / 100\n const amount = {\n value: amountValue,\n formatted: formatCurrency(amountValue),\n }\n return {\n amount,\n paymentDisplayDetails: [\n {\n key: 'BPOINT_RECEIPT_NUMBER',\n label: 'Receipt Number',\n value: paymentTransaction.ReceiptNumber,\n },\n {\n key: 'BPOINT_CRN1',\n label: 'CRN 1',\n value: paymentTransaction.Crn1,\n },\n {\n key: 'BPOINT_CRN2',\n label: 'CRN 2',\n value: paymentTransaction.Crn2,\n },\n {\n key: 'BPOINT_CRN3',\n label: 'CRN 3',\n value: paymentTransaction.Crn3,\n },\n {\n key: 'BPOINT_BILLER_CODE',\n label: 'Biller Code',\n value: paymentTransaction.BillerCode,\n },\n {\n key: 'BPOINT_CREDIT_CARD_MASK',\n label: 'Card Number',\n value: paymentTransaction.CardDetails.MaskedCardNumber,\n },\n {\n key: 'BPOINT_AMOUNT',\n label: 'Amount',\n value: amount.formatted,\n },\n {\n key: 'BPOINT_SURCHARGE_AMOUNT',\n label: 'Surcharge Amount',\n value: formatCurrency(paymentTransaction.AmountSurcharge / 100),\n },\n {\n key: 'BPOINT_PROCESSED_DATE_TIME',\n label: 'Processed Date Time',\n value: formatDateTime(paymentTransaction.ProcessedDateTime),\n },\n ],\n }\n }\n case 'CP_PAY': {\n const { paymentTransaction } = formSubmissionPayment\n if (!paymentTransaction) {\n return\n }\n\n const determineDetails = () => {\n switch (paymentTransaction.cpPayVersion) {\n case 'v2': {\n return {\n transactionId: paymentTransaction.result.id,\n orderNumber:\n paymentTransaction.result.externalReferenceId ?? undefined,\n paymentType: paymentTransaction.result.paymentType,\n creditCardMask: paymentTransaction.result.lastFour\n ? `xxxx xxxx xxxx ${paymentTransaction.result.lastFour}`\n : undefined,\n amount:\n paymentTransaction.result.amount !== undefined\n ? {\n value: paymentTransaction.result.amount,\n formatted: formatCurrency(\n paymentTransaction.result.amount,\n ),\n }\n : {\n value: NaN,\n formatted: 'Unknown',\n },\n createdDateTime: paymentTransaction.result.createdOnUtc,\n }\n }\n default: {\n return {\n transactionId: paymentTransaction.transactionId,\n orderNumber: paymentTransaction.orderNumber ?? undefined,\n paymentType:\n paymentTransaction.paymentTypeId === 1\n ? 'Credit/Debit Card'\n : paymentTransaction.paymentTypeId === 2\n ? 'ACH'\n : undefined,\n creditCardMask: paymentTransaction.lastFour\n ? `xxxx xxxx xxxx ${paymentTransaction.lastFour}`\n : undefined,\n amount: {\n value: paymentTransaction.amount,\n formatted: formatCurrency(paymentTransaction.amount),\n },\n createdDateTime: paymentTransaction.createdAt,\n }\n }\n }\n }\n\n const {\n transactionId,\n orderNumber,\n paymentType,\n creditCardMask,\n amount,\n createdDateTime,\n } = determineDetails()\n const paymentDisplayDetails: PaymentDisplayDetail[] = []\n if (transactionId) {\n paymentDisplayDetails.push({\n key: 'CP_PAY_TRANSACTION_ID',\n label: 'Transaction Id',\n value: transactionId,\n })\n }\n if (orderNumber) {\n paymentDisplayDetails.push({\n key: 'CP_PAY_ORDER_NUMBER',\n label: 'Order Number',\n value: orderNumber,\n })\n }\n if (paymentType) {\n paymentDisplayDetails.push({\n key: 'CP_PAY_PAYMENT_TYPE',\n label: 'Payment Type',\n value: paymentType,\n })\n }\n if (creditCardMask) {\n paymentDisplayDetails.push({\n key: 'CP_PAY_CREDIT_CARD_MASK',\n label: 'Card Number',\n value: creditCardMask,\n })\n }\n paymentDisplayDetails.push({\n key: 'CP_PAY_AMOUNT',\n label: 'Amount',\n value: amount.formatted,\n })\n if (createdDateTime) {\n paymentDisplayDetails.push({\n key: 'CP_PAY_CREATED_DATE_TIME',\n label: 'Created At',\n value: formatDateTime(createdDateTime),\n })\n }\n\n return {\n amount,\n paymentDisplayDetails,\n }\n }\n case 'WESTPAC_QUICK_STREAM': {\n const { paymentTransaction } = formSubmissionPayment\n if (!paymentTransaction) {\n return\n }\n\n const amount = {\n value: paymentTransaction.totalAmount.amount,\n formatted: formatCurrency(\n parseFloat(paymentTransaction.totalAmount.amount.toString()),\n ),\n }\n\n return {\n amount,\n paymentDisplayDetails: [\n {\n key: 'WESTPAC_QUICK_STREAM_RECEIPT_NUMBER',\n label: 'Receipt Number',\n value: paymentTransaction.receiptNumber,\n },\n {\n key: 'WESTPAC_QUICK_STREAM_PAYMENT_REFERENCE_NUMBER',\n label: 'Payment Reference',\n value: paymentTransaction.paymentReferenceNumber,\n },\n {\n key: 'WESTPAC_QUICK_STREAM_CUSTOMER_REFERENCE_NUMBER',\n label: 'Customer Reference Number',\n value: paymentTransaction.customerReferenceNumber,\n },\n {\n key: 'WESTPAC_QUICK_STREAM_AMOUNT',\n label: 'Amount',\n value: amount.formatted,\n },\n ...(paymentTransaction.surchargeAmount.amount\n ? [\n {\n key: 'WESTPAC_QUICK_STREAM_SURCHARGE_AMOUNT' as const,\n label: 'Surcharge Amount',\n value: formatCurrency(\n parseFloat(\n paymentTransaction.surchargeAmount.amount.toString(),\n ),\n ),\n },\n ]\n : []),\n {\n key: 'WESTPAC_QUICK_STREAM_SETTLEMENT_DATE',\n label: 'Settlement Date',\n value: formatDate(paymentTransaction.settlementDate),\n },\n ],\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"paymentService.js","sourceRoot":"","sources":["../src/paymentService.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACzE,OAAO,EACL,uBAAuB,GAExB,MAAM,wBAAwB,CAAA;AAE/B;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,oBAAoB,CAClC,UAA0B,EAC1B,UAA0D;IAO1D,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,uBAAuB,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,CAAC;QAC5B,OAAM;IACR,CAAC;IACD,OAAO,CAAC,GAAG,CACT,uEAAuE,CACxE,CAAA;IAED,MAAM,aAAa,GAAG,mBAAmB,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,CAAC;QACpD,OAAO,CAAC,GAAG,CACT,2FAA2F,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BACL,MAAM;gBACN,qBAAqB,EAAE;oBACrB;wBACE,GAAG,EAAE,qCAAqC;wBAC1C,KAAK,EAAE,gBAAgB;wBACvB,KAAK,EAAE,kBAAkB,CAAC,aAAa;qBACxC;oBACD;wBACE,GAAG,EAAE,+CAA+C;wBACpD,KAAK,EAAE,mBAAmB;wBAC1B,KAAK,EAAE,kBAAkB,CAAC,sBAAsB;qBACjD;oBACD;wBACE,GAAG,EAAE,gDAAgD;wBACrD,KAAK,EAAE,2BAA2B;wBAClC,KAAK,EAAE,kBAAkB,CAAC,uBAAuB;qBAClD;oBACD;wBACE,GAAG,EAAE,6BAA6B;wBAClC,KAAK,EAAE,QAAQ;wBACf,KAAK,EAAE,MAAM,CAAC,SAAS;qBACxB;oBACD,GAAG,CAAC,kBAAkB,CAAC,eAAe,CAAC,MAAM;wBAC3C,CAAC,CAAC;4BACE;gCACE,GAAG,EAAE,uCAAgD;gCACrD,KAAK,EAAE,kBAAkB;gCACzB,KAAK,EAAE,cAAc,CACnB,UAAU,CACR,kBAAkB,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,EAAE,CACrD,CACF;6BACF;yBACF;wBACH,CAAC,CAAC,EAAE,CAAC;oBACP;wBACE,GAAG,EAAE,sCAAsC;wBAC3C,KAAK,EAAE,iBAAiB;wBACxB,KAAK,EAAE,UAAU,CAAC,kBAAkB,CAAC,cAAc,CAAC;qBACrD;iBACF;aACF,CAAA;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import {\n FormTypes,\n SubmissionEventTypes,\n SubmissionTypes,\n} from '@oneblink/types'\nimport { conditionalLogicService, formElementsService } from './index.js'\nimport {\n getRootElementValueById,\n ReplaceInjectablesFormatters,\n} from './submissionService.js'\n\n/**\n * Examine a submission and its form definition to validate whether a payment\n * workflow event needs to run.\n *\n * #### Example\n *\n * ```js\n * const result = paymentService.checkForPaymentEvent(form, submission)\n * ```\n *\n * @param definition\n * @param submission\n * @returns\n */\nexport function checkForPaymentEvent(\n definition: FormTypes.Form,\n submission: SubmissionTypes.S3SubmissionData['submission'],\n):\n | {\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\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\ntype PaymentDisplayDetail = {\n label: string\n value: string\n /** A unique key across payment providers to identify the detail */\n key: SubmissionEventTypes.PaymentDisplayDetailKey\n}\n\n/**\n * Retrieve an array of detail items from a form submission payment.\n *\n * #### Example\n *\n * ```js\n * const detailItems =\n * paymentService.getDisplayDetailsFromFormSubmissionPayment(\n * formSubmissionPayment,\n * {\n * formatCurrency,\n * formatDateTime,\n * formatDate,\n * },\n * )\n * ```\n *\n * @param formSubmissionPayment\n * @param options\n * @returns\n */\nexport const getDisplayDetailsFromFormSubmissionPayment = (\n /** The form submission payment to get the details from */\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment,\n {\n formatCurrency,\n formatDateTime,\n formatDate,\n }: Pick<\n ReplaceInjectablesFormatters,\n 'formatCurrency' | 'formatDate' | 'formatDateTime'\n >,\n):\n | {\n amount: {\n value: number\n formatted: string\n }\n paymentDisplayDetails: PaymentDisplayDetail[]\n }\n | undefined => {\n switch (formSubmissionPayment.type) {\n case 'NSW_GOV_PAY': {\n const { paymentTransaction } = formSubmissionPayment\n if (!paymentTransaction || !paymentTransaction.agencyCompletionPayment) {\n return\n }\n\n const amount = {\n value: paymentTransaction.agencyCompletionPayment.amount,\n formatted: formatCurrency(\n paymentTransaction.agencyCompletionPayment.amount,\n ),\n }\n return {\n amount,\n paymentDisplayDetails: [\n {\n key: 'NSW_GOV_PAY_COMPLETION_REFERENCE',\n label: 'Completion Reference',\n value:\n paymentTransaction.agencyCompletionPayment\n .paymentCompletionReference,\n },\n {\n key: 'NSW_GOV_PAY_PAYMENT_REFERENCE',\n label: 'Payment Reference',\n value: paymentTransaction.agencyCompletionPayment.paymentReference,\n },\n {\n key: 'NSW_GOV_PAY_BANK_REFERENCE',\n label: 'Bank Reference',\n value: paymentTransaction.agencyCompletionPayment.bankReference,\n },\n {\n key: 'NSW_GOV_PAY_PAYMENT_METHOD',\n label: 'Payment Method',\n value: paymentTransaction.agencyCompletionPayment.paymentMethod,\n },\n ...(paymentTransaction.agencyCompletionPayment.paymentMethod ===\n 'BPAY' &&\n paymentTransaction.agencyCompletionPayment.bPay?.billerCode\n ? [\n {\n key: 'NSW_GOV_PAY_BPAY_BILLER_CODE' as const,\n label: 'BPay Biller Code',\n value:\n paymentTransaction.agencyCompletionPayment.bPay.billerCode,\n },\n ]\n : []),\n ...(paymentTransaction.agencyCompletionPayment.paymentMethod ===\n 'CARD'\n ? [\n {\n key: 'NSW_GOV_PAY_CREDIT_CARD_NUMBER' as const,\n label: 'Card Number',\n value: `xxxx xxxx xxxx ${paymentTransaction.agencyCompletionPayment.card?.last4Digits}`,\n },\n ]\n : []),\n {\n key: 'NSW_GOV_PAY_AMOUNT',\n label: 'Amount',\n value: amount.formatted,\n },\n {\n key: 'NSW_GOV_PAY_SURCHARGE_AMOUNT',\n label: 'Surcharge Amount',\n value: formatCurrency(\n paymentTransaction.agencyCompletionPayment.surcharge,\n ),\n },\n {\n key: 'NSW_GOV_PAY_SURCHARGE_GST',\n label: 'Surcharge GST',\n value: formatCurrency(\n paymentTransaction.agencyCompletionPayment.surchargeGst,\n ),\n },\n {\n key: 'NSW_GOV_PAY_CREATED_DATE_TIME',\n label: 'Created Date Time',\n value: formatDateTime(formSubmissionPayment.createdAt),\n },\n ],\n }\n }\n case 'BPOINT': {\n const { paymentTransaction } = formSubmissionPayment\n if (!paymentTransaction) {\n return\n }\n const amountValue = paymentTransaction.Amount / 100\n const amount = {\n value: amountValue,\n formatted: formatCurrency(amountValue),\n }\n return {\n amount,\n paymentDisplayDetails: [\n {\n key: 'BPOINT_RECEIPT_NUMBER',\n label: 'Receipt Number',\n value: paymentTransaction.ReceiptNumber,\n },\n {\n key: 'BPOINT_CRN1',\n label: 'CRN 1',\n value: paymentTransaction.Crn1,\n },\n {\n key: 'BPOINT_CRN2',\n label: 'CRN 2',\n value: paymentTransaction.Crn2,\n },\n {\n key: 'BPOINT_CRN3',\n label: 'CRN 3',\n value: paymentTransaction.Crn3,\n },\n {\n key: 'BPOINT_BILLER_CODE',\n label: 'Biller Code',\n value: paymentTransaction.BillerCode,\n },\n {\n key: 'BPOINT_CREDIT_CARD_MASK',\n label: 'Card Number',\n value: paymentTransaction.CardDetails.MaskedCardNumber,\n },\n {\n key: 'BPOINT_AMOUNT',\n label: 'Amount',\n value: amount.formatted,\n },\n {\n key: 'BPOINT_SURCHARGE_AMOUNT',\n label: 'Surcharge Amount',\n value: formatCurrency(paymentTransaction.AmountSurcharge / 100),\n },\n {\n key: 'BPOINT_PROCESSED_DATE_TIME',\n label: 'Processed Date Time',\n value: formatDateTime(paymentTransaction.ProcessedDateTime),\n },\n ],\n }\n }\n case 'CP_PAY': {\n const { paymentTransaction } = formSubmissionPayment\n if (!paymentTransaction) {\n return\n }\n\n const determineDetails = () => {\n switch (paymentTransaction.cpPayVersion) {\n case 'v2': {\n return {\n transactionId: paymentTransaction.result.id,\n orderNumber:\n paymentTransaction.result.externalReferenceId ?? undefined,\n paymentType: paymentTransaction.result.paymentType,\n creditCardMask: paymentTransaction.result.lastFour\n ? `xxxx xxxx xxxx ${paymentTransaction.result.lastFour}`\n : undefined,\n amount:\n paymentTransaction.result.amount !== undefined\n ? {\n value: paymentTransaction.result.amount,\n formatted: formatCurrency(\n paymentTransaction.result.amount,\n ),\n }\n : {\n value: NaN,\n formatted: 'Unknown',\n },\n createdDateTime: paymentTransaction.result.createdOnUtc,\n }\n }\n default: {\n return {\n transactionId: paymentTransaction.transactionId,\n orderNumber: paymentTransaction.orderNumber ?? undefined,\n paymentType:\n paymentTransaction.paymentTypeId === 1\n ? 'Credit/Debit Card'\n : paymentTransaction.paymentTypeId === 2\n ? 'ACH'\n : undefined,\n creditCardMask: paymentTransaction.lastFour\n ? `xxxx xxxx xxxx ${paymentTransaction.lastFour}`\n : undefined,\n amount: {\n value: paymentTransaction.amount,\n formatted: formatCurrency(paymentTransaction.amount),\n },\n createdDateTime: paymentTransaction.createdAt,\n }\n }\n }\n }\n\n const {\n transactionId,\n orderNumber,\n paymentType,\n creditCardMask,\n amount,\n createdDateTime,\n } = determineDetails()\n const paymentDisplayDetails: PaymentDisplayDetail[] = []\n if (transactionId) {\n paymentDisplayDetails.push({\n key: 'CP_PAY_TRANSACTION_ID',\n label: 'Transaction Id',\n value: transactionId,\n })\n }\n if (orderNumber) {\n paymentDisplayDetails.push({\n key: 'CP_PAY_ORDER_NUMBER',\n label: 'Order Number',\n value: orderNumber,\n })\n }\n if (paymentType) {\n paymentDisplayDetails.push({\n key: 'CP_PAY_PAYMENT_TYPE',\n label: 'Payment Type',\n value: paymentType,\n })\n }\n if (creditCardMask) {\n paymentDisplayDetails.push({\n key: 'CP_PAY_CREDIT_CARD_MASK',\n label: 'Card Number',\n value: creditCardMask,\n })\n }\n paymentDisplayDetails.push({\n key: 'CP_PAY_AMOUNT',\n label: 'Amount',\n value: amount.formatted,\n })\n if (createdDateTime) {\n paymentDisplayDetails.push({\n key: 'CP_PAY_CREATED_DATE_TIME',\n label: 'Created At',\n value: formatDateTime(createdDateTime),\n })\n }\n\n return {\n amount,\n paymentDisplayDetails,\n }\n }\n case 'WESTPAC_QUICK_STREAM': {\n const { paymentTransaction } = formSubmissionPayment\n if (!paymentTransaction) {\n return\n }\n\n const amount = {\n value: paymentTransaction.totalAmount.amount,\n formatted: formatCurrency(\n parseFloat(paymentTransaction.totalAmount.amount.toString()),\n ),\n }\n\n return {\n amount,\n paymentDisplayDetails: [\n {\n key: 'WESTPAC_QUICK_STREAM_RECEIPT_NUMBER',\n label: 'Receipt Number',\n value: paymentTransaction.receiptNumber,\n },\n {\n key: 'WESTPAC_QUICK_STREAM_PAYMENT_REFERENCE_NUMBER',\n label: 'Payment Reference',\n value: paymentTransaction.paymentReferenceNumber,\n },\n {\n key: 'WESTPAC_QUICK_STREAM_CUSTOMER_REFERENCE_NUMBER',\n label: 'Customer Reference Number',\n value: paymentTransaction.customerReferenceNumber,\n },\n {\n key: 'WESTPAC_QUICK_STREAM_AMOUNT',\n label: 'Amount',\n value: amount.formatted,\n },\n ...(paymentTransaction.surchargeAmount.amount\n ? [\n {\n key: 'WESTPAC_QUICK_STREAM_SURCHARGE_AMOUNT' as const,\n label: 'Surcharge Amount',\n value: formatCurrency(\n parseFloat(\n paymentTransaction.surchargeAmount.amount.toString(),\n ),\n ),\n },\n ]\n : []),\n {\n key: 'WESTPAC_QUICK_STREAM_SETTLEMENT_DATE',\n label: 'Settlement Date',\n value: formatDate(paymentTransaction.settlementDate),\n },\n ],\n }\n }\n }\n}\n"]}
|