@oneblink/sdk-core 0.3.6-beta.3 → 0.4.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +2 -8
  2. package/dist/abnService.d.ts +53 -0
  3. package/dist/abnService.js +53 -0
  4. package/dist/abnService.js.map +1 -1
  5. package/dist/conditionalLogicService/conditionallyShowElement.js +9 -19
  6. package/dist/conditionalLogicService/conditionallyShowElement.js.map +1 -1
  7. package/dist/conditionalLogicService/conditionallyShowOption.js +3 -3
  8. package/dist/conditionalLogicService/conditionallyShowOption.js.map +1 -1
  9. package/dist/conditionalLogicService/evaluateConditionalOptionsPredicate.d.ts +6 -0
  10. package/dist/conditionalLogicService/evaluateConditionalOptionsPredicate.js +26 -0
  11. package/dist/conditionalLogicService/evaluateConditionalOptionsPredicate.js.map +1 -0
  12. package/dist/conditionalLogicService/evaluateConditionalPredicate.d.ts +6 -0
  13. package/dist/conditionalLogicService/evaluateConditionalPredicate.js +114 -0
  14. package/dist/conditionalLogicService/evaluateConditionalPredicate.js.map +1 -0
  15. package/dist/conditionalLogicService/generateFormElementsConditionallyShown.d.ts +111 -9
  16. package/dist/conditionalLogicService/generateFormElementsConditionallyShown.js +95 -4
  17. package/dist/conditionalLogicService/generateFormElementsConditionallyShown.js.map +1 -1
  18. package/dist/conditionalLogicService.d.ts +71 -0
  19. package/dist/conditionalLogicService.js +106 -0
  20. package/dist/conditionalLogicService.js.map +1 -0
  21. package/dist/fileUploadService.d.ts +14 -0
  22. package/dist/fileUploadService.js +14 -0
  23. package/dist/fileUploadService.js.map +1 -1
  24. package/dist/formElementsService.d.ts +83 -4
  25. package/dist/formElementsService.js +83 -15
  26. package/dist/formElementsService.js.map +1 -1
  27. package/dist/index.d.ts +85 -4
  28. package/dist/index.js +91 -9
  29. package/dist/index.js.map +1 -1
  30. package/dist/paymentService.d.ts +19 -0
  31. package/dist/{paymentAmountValidation.js → paymentService.js} +20 -6
  32. package/dist/paymentService.js.map +1 -0
  33. package/dist/replaceCustomValues.d.ts +98 -3
  34. package/dist/replaceCustomValues.js +98 -2
  35. package/dist/replaceCustomValues.js.map +1 -1
  36. package/dist/schedulingService.d.ts +19 -0
  37. package/dist/schedulingService.js +33 -0
  38. package/dist/schedulingService.js.map +1 -0
  39. package/dist/submissionService.d.ts +22 -0
  40. package/dist/submissionService.js +52 -0
  41. package/dist/submissionService.js.map +1 -0
  42. package/dist/typeCastService.d.ts +1 -1
  43. package/dist/typeCastService.js.map +1 -1
  44. package/dist/typedoc.d.ts +2 -0
  45. package/dist/typedoc.js +19 -0
  46. package/dist/typedoc.js.map +1 -0
  47. package/dist/types/index.d.ts +0 -14
  48. package/dist/types/index.js.map +1 -1
  49. package/dist/userService.d.ts +35 -0
  50. package/dist/userService.js +35 -0
  51. package/dist/userService.js.map +1 -1
  52. package/package.json +15 -12
  53. package/dist/conditionalLogicService/evaluationService.d.ts +0 -19
  54. package/dist/conditionalLogicService/evaluationService.js +0 -139
  55. package/dist/conditionalLogicService/evaluationService.js.map +0 -1
  56. package/dist/conditionalLogicService/index.d.ts +0 -2
  57. package/dist/conditionalLogicService/index.js +0 -13
  58. package/dist/conditionalLogicService/index.js.map +0 -1
  59. package/dist/paymentAmountValidation.d.ts +0 -7
  60. package/dist/paymentAmountValidation.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"formElementsService.js","sourceRoot":"","sources":["../src/formElementsService.ts"],"names":[],"mappings":";;;AAEA,SAAS,kBAAkB,CACzB,QAAiC,EACjC,OAGS;IAET,eAAe,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,cAAc,EAAE,EAAE;QACxD,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,CAAA;QACpC,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CAAA;AACJ,CAAC;AAiJC,gDAAkB;AA/IpB,SAAS,6BAA6B,CACpC,QAAiC,EACjC,OAGS;IAET,eAAe,CAAC,QAAQ,E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,IAAI,CAAC,OAAO,CAAC,CAAA;QAC/B,QAAQ,OAAO,CAAC,IAAI,EAAE;YACpB,KAAK,SAAS,CAAC;YACf,KAAK,MAAM,CAAC,CAAC;gBACX,iBAAiB,CAAC,IAAI,CAAC,GAAG,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;aACjE;SACF;QACD,OAAO,iBAAiB,CAAA;IAC1B,CAAC,EACD,EAAE,CACH,CAAA;AACH,CAAC;AA6BC,kDAAmB;AA3BrB,SAAS,uBAAuB,CAC9B,aAAqB,EACrB,YAAqC,EACrC,UAA+C;IAE/C,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE;QACtC,IAAI,WAAW,CAAC,IAAI,KAAK,MAAM,IAAI,WAAW,CAAC,IAAI,KAAK,SAAS,EAAE;YACjE,MAAM,KAAK,GAAG,uBAAuB,CACnC,aAAa,EACb,WAAW,CAAC,QAAQ,EACpB,UAAU,CACX,CAAA;YACD,IAAI,KAAK,KAAK,SAAS,EAAE;gBACvB,OAAO,KAAK,CAAA;aACb;SACF;aAAM,IAAI,WAAW,CAAC,EAAE,KAAK,aAAa,EAAE;YAC3C,OAAO,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;SACpC;KACF;AACH,CAAC;AAGC,0DAAuB","sourcesContent":["import { FormTypes } from '@oneblink/types'\n\nfunction forEachFormElement(\n elements: FormTypes.FormElement[],\n forEach: (\n element: FormTypes.FormElement,\n elements: FormTypes.FormElement[],\n ) => void,\n): void {\n findFormElement(elements, (formElement, parentElements) => {\n forEach(formElement, parentElements)\n return false\n })\n}\n\nfunction forEachFormElementWithOptions(\n elements: FormTypes.FormElement[],\n forEach: (\n elementWithOptions: FormTypes.FormElementWithOptions,\n elements: FormTypes.FormElement[],\n ) => void,\n): void {\n findFormElement(elements, (formElement, parentElements) => {\n if (\n formElement.type === 'select' ||\n formElement.type === 'autocomplete' ||\n formElement.type === 'checkboxes' ||\n formElement.type === 'radio' ||\n formElement.type === 'compliance'\n ) {\n forEach(formElement, parentElements)\n }\n return false\n })\n}\n\nfunction findFormElement(\n elements: FormTypes.FormElement[],\n predicate: (\n element: FormTypes.FormElement,\n elements: FormTypes.FormElement[],\n ) => boolean,\n parentElements: FormTypes.FormElement[] = [],\n): FormTypes.FormElement | void {\n for (const element of elements) {\n if (predicate(element, parentElements)) {\n return element\n }\n\n if (\n (element.type === 'repeatableSet' ||\n element.type === 'page' ||\n element.type === 'form' ||\n element.type === 'infoPage' ||\n element.type === 'section') &&\n Array.isArray(element.elements)\n ) {\n const nestedElement = findFormElement(element.elements, predicate, [\n ...parentElements,\n element,\n ])\n\n if (nestedElement) {\n return nestedElement\n }\n }\n }\n}\n\nfunction parseFormElementOptionsSet(\n data: unknown,\n): FormTypes.ChoiceElementOption[] {\n if (!Array.isArray(data)) {\n return []\n }\n return data.reduce(\n (\n options: FormTypes.ChoiceElementOption[],\n record: unknown,\n index: number,\n ) => {\n if (typeof record === 'string') {\n options.push({\n id: index.toString(),\n value: record,\n label: record,\n })\n } else if (typeof record === 'object') {\n const option = record as Record<string, unknown>\n const value =\n typeof option.value === 'string' && option.value\n ? option.value\n : index.toString()\n const id =\n typeof option.id === 'string' && option.id ? option.id : value\n const label =\n typeof option.label === 'string' && option.label\n ? option.label\n : value\n const colour =\n typeof option.colour === 'string' && option.colour\n ? option.colour\n : undefined\n options.push({\n ...option,\n id,\n value,\n label,\n colour,\n })\n }\n return options\n },\n [],\n )\n}\n\nfunction flattenFormElements(\n elements: FormTypes.FormElement[],\n): FormTypes.FormElement[] {\n return elements.reduce<FormTypes.FormElement[]>(\n (flattenedElements, element) => {\n flattenedElements.push(element)\n switch (element.type) {\n case 'section':\n case 'page': {\n flattenedElements.push(...flattenFormElements(element.elements))\n }\n }\n return flattenedElements\n },\n [],\n )\n}\n\nfunction getRootElementValueById(\n formElementId: string,\n formElements: FormTypes.FormElement[],\n submission: { readonly [key: string]: unknown },\n): unknown {\n for (const formElement of formElements) {\n if (formElement.type === 'page' || formElement.type === 'section') {\n const value = getRootElementValueById(\n formElementId,\n formElement.elements,\n submission,\n )\n if (value !== undefined) {\n return value\n }\n } else if (formElement.id === formElementId) {\n return submission[formElement.name]\n }\n }\n}\n\nexport {\n getRootElementValueById,\n forEachFormElement,\n forEachFormElementWithOptions,\n findFormElement,\n parseFormElementOptionsSet,\n flattenFormElements,\n}\n"]}
1
+ {"version":3,"file":"formElementsService.js","sourceRoot":"","sources":["../src/formElementsService.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;GAcG;AACH,SAAS,kBAAkB,CACzB,QAAiC,EACjC,OAGS;IAET,eAAe,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,cAAc,EAAE,EAAE;QACxD,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,CAAA;QACpC,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CAAA;AACJ,CAAC;AA8LC,gDAAkB;AA5LpB;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAS,6BAA6B,CACpC,QAAiC,EACjC,OAGS;IAET,eAAe,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,cAAc,EAAE,EAAE;QACxD,IACE,WAAW,CAAC,IAAI,KAAK,QAAQ;YAC7B,WAAW,CAAC,IAAI,KAAK,cAAc;YACnC,WAAW,CAAC,IAAI,KAAK,YAAY;YACjC,WAAW,CAAC,IAAI,KAAK,OAAO;YAC5B,WAAW,CAAC,IAAI,KAAK,YAAY,EACjC;YACA,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,CAAA;SACrC;QACD,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CAAA;AACJ,CAAC;AAwJC,sEAA6B;AAtJ/B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAS,eAAe,CACtB,QAAiC,EACjC,SAGY,EACZ,iBAA0C,EAAE;IAE5C,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;QAC9B,IAAI,SAAS,CAAC,OAAO,EAAE,cAAc,CAAC,EA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AQ,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAA;YAChE,MAAM,KAAK,GACT,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAK;gBAC9C,CAAC,CAAC,MAAM,CAAC,KAAK;gBACd,CAAC,CAAC,KAAK,CAAA;YACX,MAAM,MAAM,GACV,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM;gBAChD,CAAC,CAAC,MAAM,CAAC,MAAM;gBACf,CAAC,CAAC,SAAS,CAAA;YACf,OAAO,CAAC,IAAI,CAAC;gBACX,GAAG,MAAM;gBACT,EAAE;gBACF,KAAK;gBACL,KAAK;gBACL,MAAM;aACP,CAAC,CAAA;SACH;QACD,OAAO,OAAO,CAAA;IAChB,CAAC,EACD,EAAE,CACH,CAAA;AACH,CAAC;AAsCC,gEAA0B;AApC5B;;;;;;;;;;;;;GAaG;AACH,SAAS,mBAAmB,CAC1B,QAAiC;IAEjC,OAAO,QAAQ,CAAC,MAAM,CACpB,CAAC,iBAAiB,EAAE,OAAO,EAAE,EAAE;QAC7B,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC/B,QAAQ,OAAO,CAAC,IAAI,EAAE;YACpB,KAAK,SAAS,CAAC;YACf,KAAK,MAAM,CAAC,CAAC;gBACX,iBAAiB,CAAC,IAAI,CAAC,GAAG,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;aACjE;SACF;QACD,OAAO,iBAAiB,CAAA;IAC1B,CAAC,EACD,EAAE,CACH,CAAA;AACH,CAAC;AAOC,kDAAmB","sourcesContent":["import { FormTypes } from '@oneblink/types'\n\n/**\n * Iterate over all form elements, also iterating over nested form element (e.g.\n * page elements).\n *\n * #### Example\n *\n * ```js\n * formElementsService.forEachFormElement(form.elements, (formElement) => {\n * // do something with formElement\n * })\n * ```\n *\n * @param elements The form elements to iterate over\n * @param forEach Function to execute on each form element\n */\nfunction forEachFormElement(\n elements: FormTypes.FormElement[],\n forEach: (\n element: FormTypes.FormElement,\n elements: FormTypes.FormElement[],\n ) => void,\n): void {\n findFormElement(elements, (formElement, parentElements) => {\n forEach(formElement, parentElements)\n return false\n })\n}\n\n/**\n * Iterate over all form elements that have options (e.g. `'select'` type\n * elements), also iterating over nested form element (e.g. page elements).\n *\n * #### Example\n *\n * ```js\n * formElementsService.forEachFormElementWithOptions(\n * form.elements,\n * (formElementWithOptions) => {\n * // do something with formElementWithOptions\n * },\n * )\n * ```\n *\n * @param elements The form elements to iterate over\n * @param forEach Function to execute on each form element with options\n */\nfunction forEachFormElementWithOptions(\n elements: FormTypes.FormElement[],\n forEach: (\n elementWithOptions: FormTypes.FormElementWithOptions,\n elements: FormTypes.FormElement[],\n ) => void,\n): void {\n findFormElement(elements, (formElement, parentElements) => {\n if (\n formElement.type === 'select' ||\n formElement.type === 'autocomplete' ||\n formElement.type === 'checkboxes' ||\n formElement.type === 'radio' ||\n formElement.type === 'compliance'\n ) {\n forEach(formElement, parentElements)\n }\n return false\n })\n}\n\n/**\n * Iterate over all form elements and return an element that matches a\n * predicate, also iterating over nested form element (e.g. page elements). Will\n * return `undefined` if no matching element is found.\n *\n * #### Example\n *\n * ```js\n * const formElement = formElementsService.findFormElement(\n * form.elements,\n * (formElement) => {\n * return formElement.id === '123-abc'\n * },\n * )\n * ```\n *\n * @param elements The form elements to iterate over\n * @param predicate Predicate function to execute on each form element\n * @param parentElements\n * @returns\n */\nfunction findFormElement(\n elements: FormTypes.FormElement[],\n predicate: (\n element: FormTypes.FormElement,\n elements: FormTypes.FormElement[],\n ) => boolean,\n parentElements: FormTypes.FormElement[] = [],\n): FormTypes.FormElement | void {\n for (const element of elements) {\n if (predicate(element, parentElements)) {\n return element\n }\n\n if (\n (element.type === 'repeatableSet' ||\n element.type === 'page' ||\n element.type === 'form' ||\n element.type === 'infoPage' ||\n element.type === 'section') &&\n Array.isArray(element.elements)\n ) {\n const nestedElement = findFormElement(element.elements, predicate, [\n ...parentElements,\n element,\n ])\n\n if (nestedElement) {\n return nestedElement\n }\n }\n }\n}\n\n/**\n * Parse unknown data as valid options for a forms element. This will always\n * return an Array of valid options.\n *\n * #### Example\n *\n * ```js\n * const options = formElementsService.parseFormElementOptionsSet(data)\n * // \"options\" are valid for a form element\n * ```\n *\n * @param data\n * @returns\n */\nfunction parseFormElementOptionsSet(\n data: unknown,\n): FormTypes.ChoiceElementOption[] {\n if (!Array.isArray(data)) {\n return []\n }\n return data.reduce(\n (\n options: FormTypes.ChoiceElementOption[],\n record: unknown,\n index: number,\n ) => {\n if (typeof record === 'string') {\n options.push({\n id: index.toString(),\n value: record,\n label: record,\n })\n } else if (typeof record === 'object') {\n const option = record as Record<string, unknown>\n const value =\n typeof option.value === 'string' && option.value\n ? option.value\n : index.toString()\n const id =\n typeof option.id === 'string' && option.id ? option.id : value\n const label =\n typeof option.label === 'string' && option.label\n ? option.label\n : value\n const colour =\n typeof option.colour === 'string' && option.colour\n ? option.colour\n : undefined\n options.push({\n ...option,\n id,\n value,\n label,\n colour,\n })\n }\n return options\n },\n [],\n )\n}\n\n/**\n * Takes the nested definition structure and returns all form elements as 1d array.\n *\n * #### Example\n *\n * ```js\n * const flattenedElements = formElementsService.flattenFormElements(\n * form.elements,\n * )\n * ```\n *\n * @param elements\n * @returns\n */\nfunction flattenFormElements(\n elements: FormTypes.FormElement[],\n): FormTypes.FormElement[] {\n return elements.reduce<FormTypes.FormElement[]>(\n (flattenedElements, element) => {\n flattenedElements.push(element)\n switch (element.type) {\n case 'section':\n case 'page': {\n flattenedElements.push(...flattenFormElements(element.elements))\n }\n }\n return flattenedElements\n },\n [],\n )\n}\n\nexport {\n forEachFormElement,\n forEachFormElementWithOptions,\n findFormElement,\n parseFormElementOptionsSet,\n flattenFormElements,\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,9 +1,90 @@
1
+ /**
2
+ * ## Form Elements Service
3
+ *
4
+ * Helper functions for handling form elements
5
+ *
6
+ * ```js
7
+ * import { formElementsService } from '@oneblink/sdk-core'
8
+ * ```
9
+ */
1
10
  export * as formElementsService from './formElementsService';
11
+ /**
12
+ * ## Conditional Logic Service
13
+ *
14
+ * Helper functions for handling conditional logic
15
+ *
16
+ * ```js
17
+ * import { conditionalLogicService } from '@oneblink/sdk-core'
18
+ * ```
19
+ */
2
20
  export * as conditionalLogicService from './conditionalLogicService';
3
- import replaceCustomValues, { getElementSubmissionValue } from './replaceCustomValues';
21
+ /**
22
+ * ## Submission Service
23
+ *
24
+ * Helper functions for handling form submission data
25
+ *
26
+ * ```js
27
+ * import { submissionService } from '@oneblink/sdk-core'
28
+ * ```
29
+ */
30
+ export * as submissionService from './submissionService';
31
+ /**
32
+ * ## Submission Service
33
+ *
34
+ * Helper functions for casting types
35
+ *
36
+ * ```js
37
+ * import { typeCastService } from '@oneblink/sdk-core'
38
+ * ```
39
+ */
4
40
  export * as typeCastService from './typeCastService';
41
+ /**
42
+ * ## User Service
43
+ *
44
+ * Helper functions for handling users
45
+ *
46
+ * ```js
47
+ * import { userService } from '@oneblink/sdk-core'
48
+ * ```
49
+ */
5
50
  export * as userService from './userService';
51
+ /**
52
+ * ## ABN Service
53
+ *
54
+ * Helper functions for handling ABN Records
55
+ *
56
+ * ```js
57
+ * import { abnService } from '@oneblink/sdk-core'
58
+ * ```
59
+ */
6
60
  export * as abnService from './abnService';
7
- export { validatePaymentAmount } from './paymentAmountValidation';
8
- export { getContentDisposition } from './fileUploadService';
9
- export { replaceCustomValues, getElementSubmissionValue };
61
+ /**
62
+ * ## Payment Service
63
+ *
64
+ * Helper functions for payments
65
+ *
66
+ * ```js
67
+ * import { paymentService } from '@oneblink/sdk-core'
68
+ * ```
69
+ */
70
+ export * as paymentService from './paymentService';
71
+ /**
72
+ * ## Scheduling Service
73
+ *
74
+ * Helper functions for scheduling
75
+ *
76
+ * ```js
77
+ * import { schedulingService } from '@oneblink/sdk-core'
78
+ * ```
79
+ */
80
+ export * as schedulingService from './schedulingService';
81
+ /**
82
+ * ## File Upload Service
83
+ *
84
+ * Helper functions for handling file uploads
85
+ *
86
+ * ```js
87
+ * import { fileUploadService } from '@oneblink/sdk-core'
88
+ * ```
89
+ */
90
+ export * as fileUploadService from './fileUploadService';
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -19,17 +23,95 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
23
  return result;
20
24
  };
21
25
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.getElementSubmissionValue = exports.replaceCustomValues = exports.getContentDisposition = exports.validatePaymentAmount = exports.abnService = exports.userService = exports.typeCastService = exports.conditionalLogicService = exports.formElementsService = void 0;
26
+ exports.fileUploadService = exports.schedulingService = exports.paymentService = exports.abnService = exports.userService = exports.typeCastService = exports.submissionService = exports.conditionalLogicService = exports.formElementsService = void 0;
27
+ /**
28
+ * ## Form Elements Service
29
+ *
30
+ * Helper functions for handling form elements
31
+ *
32
+ * ```js
33
+ * import { formElementsService } from '@oneblink/sdk-core'
34
+ * ```
35
+ */
23
36
  exports.formElementsService = __importStar(require("./formElementsService"));
37
+ /**
38
+ * ## Conditional Logic Service
39
+ *
40
+ * Helper functions for handling conditional logic
41
+ *
42
+ * ```js
43
+ * import { conditionalLogicService } from '@oneblink/sdk-core'
44
+ * ```
45
+ */
24
46
  exports.conditionalLogicService = __importStar(require("./conditionalLogicService"));
25
- const replaceCustomValues_1 = __importStar(require("./replaceCustomValues"));
26
- exports.replaceCustomValues = replaceCustomValues_1.default;
27
- Object.defineProperty(exports, "getElementSubmissionValue", { enumerable: true, get: function () { return replaceCustomValues_1.getElementSubmissionValue; } });
47
+ /**
48
+ * ## Submission Service
49
+ *
50
+ * Helper functions for handling form submission data
51
+ *
52
+ * ```js
53
+ * import { submissionService } from '@oneblink/sdk-core'
54
+ * ```
55
+ */
56
+ exports.submissionService = __importStar(require("./submissionService"));
57
+ /**
58
+ * ## Submission Service
59
+ *
60
+ * Helper functions for casting types
61
+ *
62
+ * ```js
63
+ * import { typeCastService } from '@oneblink/sdk-core'
64
+ * ```
65
+ */
28
66
  exports.typeCastService = __importStar(require("./typeCastService"));
67
+ /**
68
+ * ## User Service
69
+ *
70
+ * Helper functions for handling users
71
+ *
72
+ * ```js
73
+ * import { userService } from '@oneblink/sdk-core'
74
+ * ```
75
+ */
29
76
  exports.userService = __importStar(require("./userService"));
77
+ /**
78
+ * ## ABN Service
79
+ *
80
+ * Helper functions for handling ABN Records
81
+ *
82
+ * ```js
83
+ * import { abnService } from '@oneblink/sdk-core'
84
+ * ```
85
+ */
30
86
  exports.abnService = __importStar(require("./abnService"));
31
- var paymentAmountValidation_1 = require("./paymentAmountValidation");
32
- Object.defineProperty(exports, "validatePaymentAmount", { enumerable: true, get: function () { return paymentAmountValidation_1.validatePaymentAmount; } });
33
- var fileUploadService_1 = require("./fileUploadService");
34
- Object.defineProperty(exports, "getContentDisposition", { enumerable: true, get: function () { return fileUploadService_1.getContentDisposition; } });
87
+ /**
88
+ * ## Payment Service
89
+ *
90
+ * Helper functions for payments
91
+ *
92
+ * ```js
93
+ * import { paymentService } from '@oneblink/sdk-core'
94
+ * ```
95
+ */
96
+ exports.paymentService = __importStar(require("./paymentService"));
97
+ /**
98
+ * ## Scheduling Service
99
+ *
100
+ * Helper functions for scheduling
101
+ *
102
+ * ```js
103
+ * import { schedulingService } from '@oneblink/sdk-core'
104
+ * ```
105
+ */
106
+ exports.schedulingService = __importStar(require("./schedulingService"));
107
+ /**
108
+ * ## File Upload Service
109
+ *
110
+ * Helper functions for handling file uploads
111
+ *
112
+ * ```js
113
+ * import { fileUploadService } from '@oneblink/sdk-core'
114
+ * ```
115
+ */
116
+ exports.fileUploadService = __importStar(require("./fileUploadService"));
35
117
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,6EAA4D;AAC5D,qFAAoE;AACpE,6EAE8B;AAOrB,8BATF,6BAAmB,CASE;AAAE,0GAR5B,+CAAyB,OAQ4B;AANvD,qEAAoD;AACpD,6DAA4C;AAC5C,2DAA0C;AAC1C,qEAAiE;AAAxD,gIAAA,qBAAqB,OAAA;AAC9B,yDAA2D;AAAlD,0HAAA,qBAAqB,OAAA","sourcesContent":["export * as formElementsService from './formElementsService'\nexport * as conditionalLogicService from './conditionalLogicService'\nimport replaceCustomValues, {\n getElementSubmissionValue,\n} from './replaceCustomValues'\nexport * as typeCastService from './typeCastService'\nexport * as userService from './userService'\nexport * as abnService from './abnService'\nexport { validatePaymentAmount } from './paymentAmountValidation'\nexport { getContentDisposition } from './fileUploadService'\n\nexport { replaceCustomValues, getElementSubmissionValue }\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;GAQG;AACH,6EAA4D;AAC5D;;;;;;;;GAQG;AACH,qFAAoE;AACpE;;;;;;;;GAQG;AACH,yEAAwD;AACxD;;;;;;;;GAQG;AACH,qEAAoD;AACpD;;;;;;;;GAQG;AACH,6DAA4C;AAC5C;;;;;;;;GAQG;AACH,2DAA0C;AAC1C;;;;;;;;GAQG;AACH,mEAAkD;AAClD;;;;;;;;GAQG;AACH,yEAAwD;AACxD;;;;;;;;GAQG;AACH,yEAAwD","sourcesContent":["/**\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'\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'\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'\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'\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'\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'\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'\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'\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'\n"]}
@@ -0,0 +1,19 @@
1
+ import { FormTypes, SubmissionEventTypes, SubmissionTypes } from '@oneblink/types';
2
+ /**
3
+ * Examine a submission and its form definition to validate whether a payment
4
+ * workflow event needs to run.
5
+ *
6
+ * #### Example
7
+ *
8
+ * ```js
9
+ * const result = paymentService.checkForPaymentEvent(form, submission)
10
+ * ```
11
+ *
12
+ * @param definition
13
+ * @param submission
14
+ * @returns
15
+ */
16
+ export declare function checkForPaymentEvent(definition: FormTypes.Form, submission: SubmissionTypes.S3SubmissionData['submission']): {
17
+ paymentSubmissionEvent: SubmissionEventTypes.PaymentSubmissionEvent;
18
+ amount: number;
19
+ } | undefined;
@@ -1,9 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validatePaymentAmount = void 0;
3
+ exports.checkForPaymentEvent = void 0;
4
4
  const _1 = require(".");
5
- const formElementsService_1 = require("./formElementsService");
6
- function validatePaymentAmount(definition, submission) {
5
+ const submissionService_1 = require("./submissionService");
6
+ /**
7
+ * Examine a submission and its form definition to validate whether a payment
8
+ * workflow event needs to run.
9
+ *
10
+ * #### Example
11
+ *
12
+ * ```js
13
+ * const result = paymentService.checkForPaymentEvent(form, submission)
14
+ * ```
15
+ *
16
+ * @param definition
17
+ * @param submission
18
+ * @returns
19
+ */
20
+ function checkForPaymentEvent(definition, submission) {
7
21
  const paymentSubmissionEvents = definition.paymentEvents || [];
8
22
  const paymentSubmissionEvent = paymentSubmissionEvents.find((paymentSubmissionEvent) => {
9
23
  return (paymentSubmissionEvent &&
@@ -25,7 +39,7 @@ function validatePaymentAmount(definition, submission) {
25
39
  throw new Error('We could not find the configuration required to make a payment. Please contact your administrator to ensure your application configuration has been completed successfully.');
26
40
  }
27
41
  console.log('Found form element for payment submission event', amountElement);
28
- const amount = (0, formElementsService_1.getRootElementValueById)(amountElement.id, definition.elements, submission);
42
+ const amount = (0, submissionService_1.getRootElementValueById)(amountElement.id, definition.elements, submission);
29
43
  if (!amount) {
30
44
  console.log('Form has a payment submission event but the amount has been entered as 0 or not at all, finishing as normal submission');
31
45
  return;
@@ -40,5 +54,5 @@ function validatePaymentAmount(definition, submission) {
40
54
  };
41
55
  return result;
42
56
  }
43
- exports.validatePaymentAmount = validatePaymentAmount;
44
- //# sourceMappingURL=paymentAmountValidation.js.map
57
+ exports.checkForPaymentEvent = checkForPaymentEvent;
58
+ //# sourceMappingURL=paymentService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paymentService.js","sourceRoot":"","sources":["../src/paymentService.ts"],"names":[],"mappings":";;;AAKA,wBAAgE;AAChE,2DAA6D;AAE7D;;;;;;;;;;;;;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;QAC3B,OAAM;KACP;IACD,OAAO,CAAC,GAAG,CACT,uEAAuE,CACxE,CAAA;IAED,MAAM,aAAa,GAAG,sBAAmB,CAAC,eAAe,CACvD,UAAU,CAAC,QAAQ,EACnB,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,sBAAsB,CAAC,aAAa,CAAC,SAAS,CAC3E,CAAA;IACD,IAAI,CAAC,aAAa,IAAI,aAAa,CAAC,IAAI,KAAK,MAAM,EAAE;QACnD,OAAO,CAAC,GAAG,CACT,2FAA2F,CAC5F,CAAA;QACD,MAAM,IAAI,KAAK,CACb,6KAA6K,CAC9K,CAAA;KACF;IAED,OAAO,CAAC,GAAG,CAAC,iDAAiD,EAAE,aAAa,CAAC,CAAA;IAE7E,MAAM,MAAM,GAAG,IAAA,2CAAuB,EACpC,aAAa,CAAC,EAAE,EAChB,UAAU,CAAC,QAAQ,EACnB,UAAU,CACX,CAAA;IAED,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,CAAC,GAAG,CACT,wHAAwH,CACzH,CAAA;QACD,OAAM;KACP;IAED,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,OAAO,CAAC,GAAG,CACT,oFAAoF,CACrF,CAAA;QACD,MAAM,IAAI,KAAK,CACb,wKAAwK,CACzK,CAAA;KACF;IAED,MAAM,MAAM,GAAG;QACb,sBAAsB;QACtB,MAAM;KACP,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AA7ED,oDA6EC","sourcesContent":["import {\n FormTypes,\n SubmissionEventTypes,\n SubmissionTypes,\n} from '@oneblink/types'\nimport { conditionalLogicService, formElementsService } from '.'\nimport { getRootElementValueById } 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.PaymentSubmissionEvent\n amount: number\n }\n | undefined {\n const paymentSubmissionEvents = definition.paymentEvents || []\n const paymentSubmissionEvent = paymentSubmissionEvents.find(\n (paymentSubmissionEvent) => {\n return (\n paymentSubmissionEvent &&\n conditionalLogicService.evaluateConditionalPredicates({\n isConditional: !!paymentSubmissionEvent.conditionallyExecute,\n requiresAllConditionalPredicates:\n !!paymentSubmissionEvent.requiresAllConditionallyExecutePredicates,\n conditionalPredicates:\n paymentSubmissionEvent.conditionallyExecutePredicates || [],\n submission: submission,\n formElements: definition.elements,\n })\n )\n },\n )\n\n if (!paymentSubmissionEvent) {\n return\n }\n console.log(\n 'Checking if submission with payment submission event needs processing',\n )\n\n const amountElement = formElementsService.findFormElement(\n definition.elements,\n (element) => element.id === paymentSubmissionEvent.configuration.elementId,\n )\n if (!amountElement || amountElement.type === 'page') {\n console.log(\n 'Form has a payment submission event but the amount element does not exist, throwing error',\n )\n throw new Error(\n 'We could not find the configuration required to make a payment. Please contact your administrator to ensure your application configuration has been completed successfully.',\n )\n }\n\n console.log('Found form element for payment submission event', amountElement)\n\n const amount = getRootElementValueById(\n amountElement.id,\n definition.elements,\n submission,\n )\n\n if (!amount) {\n console.log(\n 'Form has a payment submission event but the amount has been entered as 0 or not at all, finishing as normal submission',\n )\n return\n }\n\n if (typeof amount !== 'number') {\n console.log(\n 'Form has a payment submission event but the amount is not a number, throwing error',\n )\n throw new Error(\n 'The configuration required to make a payment is incorrect. Please contact your administrator to ensure your application configuration has been completed successfully.',\n )\n }\n\n const result = {\n paymentSubmissionEvent,\n amount,\n }\n\n return result\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { FormTypes, SubmissionTypes } from '@oneblink/types';
2
- declare type CustomValuesOptions = {
2
+ export declare type CustomValuesOptions = {
3
3
  form: FormTypes.Form;
4
4
  externalId?: string;
5
5
  submissionId: string;
@@ -10,6 +10,50 @@ declare type CustomValuesOptions = {
10
10
  formatCurrency: (value: number) => string;
11
11
  previousApprovalId?: string;
12
12
  };
13
+ /**
14
+ * Function to get the display value of a property in submission
15
+ *
16
+ * #### Example
17
+ *
18
+ * ```typescript
19
+ *
20
+ * const result = submissionService.getElementSubmissionValue({
21
+ * propertyName: 'search',
22
+ * submission: {
23
+ * search: 'Entered By User',
24
+ * },
25
+ * formElements: [
26
+ * {
27
+ * id: 'd4135b47-9004-4d75-aeb3-d2f6232da111',
28
+ * name: 'search',
29
+ * type: 'text',
30
+ * label: 'Search',
31
+ * readOnly: false,
32
+ * required: false,
33
+ * conditionallyShow: false,
34
+ * requiresAllConditionallyShowPredicates: false,
35
+ * isElementLookup: false,
36
+ * isDataLookup: false,
37
+ * },
38
+ * ],
39
+ * formatDate: (value) => new Date(value).toDateString(),
40
+ * formatTime: (value) => new Date(value).toTimeString(),
41
+ * formatNumber: (value) => Number(value).toString(),
42
+ * formatCurrency: (value) => Number(value).toFixed(2),
43
+ * }: {
44
+ * propertyName: string
45
+ * formElements: FormTypes.FormElement[]
46
+ * submission: SubmissionTypes.S3SubmissionData['submission']
47
+ * formatDate: (value: string) => string
48
+ * formatTime: (value: string) => string
49
+ * formatNumber: (value: number) => string
50
+ * formatCurrency: (value: number) => string
51
+ * })
52
+ * ```
53
+ *
54
+ * @param options
55
+ * @returns
56
+ */
13
57
  export declare function getElementSubmissionValue({ propertyName, submission, formElements, formatDate, formatTime, formatNumber, formatCurrency, }: {
14
58
  propertyName: string;
15
59
  formElements: FormTypes.FormElement[];
@@ -19,7 +63,58 @@ export declare function getElementSubmissionValue({ propertyName, submission, fo
19
63
  formatNumber: (value: number) => string;
20
64
  formatCurrency: (value: number) => string;
21
65
  }): unknown;
22
- export default function replaceCustomValues(text: string, { form, submission, externalId, submissionId, submissionTimestamp, formatDate, formatTime, formatNumber, formatCurrency, previousApprovalId, }: CustomValuesOptions & {
66
+ /**
67
+ * Function to replace a custom values in text
68
+ *
69
+ * #### Example
70
+ *
71
+ * ```js
72
+ * const result = submissionService.replaceCustomValues(
73
+ * 'https://example.com/path?submissionId={SUBMISSION_ID}&externalId={EXTERNAL_ID}&search{ELEMENT:search}',
74
+ * {
75
+ * submissionId: 'abc-123',
76
+ * submissionTimestamp: '2021-07-02T02:19:13.670Z',
77
+ * formatDate: (value) => new Date(value).toDateString(),
78
+ * formatTime: (value) => new Date(value).toTimeString(),
79
+ * submission: {
80
+ * search: 'Entered By User',
81
+ * },
82
+ * form: {
83
+ * id: 1,
84
+ * name: 'Form',
85
+ * organisationId: '',
86
+ * formsAppEnvironmentId: 1,
87
+ * formsAppIds: [],
88
+ * isAuthenticated: false,
89
+ * isMultiPage: false,
90
+ * isInfoPage: false,
91
+ * postSubmissionAction: 'FORMS_LIBRARY',
92
+ * cancelAction: 'FORMS_LIBRARY',
93
+ * submissionEvents: [],
94
+ * tags: [],
95
+ * elements: [
96
+ * {
97
+ * id: 'd4135b47-9004-4d75-aeb3-d2f6232da111',
98
+ * name: 'search',
99
+ * type: 'text',
100
+ * label: 'Search',
101
+ * readOnly: false,
102
+ * required: false,
103
+ * conditionallyShow: false,
104
+ * requiresAllConditionallyShowPredicates: false,
105
+ * isElementLookup: false,
106
+ * isDataLookup: false,
107
+ * },
108
+ * ],
109
+ * },
110
+ * },
111
+ * )
112
+ * ```
113
+ *
114
+ * @param text
115
+ * @param options
116
+ * @returns
117
+ */
118
+ export declare function replaceCustomValues(text: string, { form, submission, externalId, submissionId, submissionTimestamp, formatDate, formatTime, formatNumber, formatCurrency, previousApprovalId, }: CustomValuesOptions & {
23
119
  submission: SubmissionTypes.S3SubmissionData['submission'];
24
120
  }): string;
25
- export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getElementSubmissionValue = void 0;
3
+ exports.replaceCustomValues = exports.getElementSubmissionValue = void 0;
4
4
  const formElementsService_1 = require("./formElementsService");
5
5
  const abnService_1 = require("./abnService");
6
6
  const CUSTOM_VALUES = [
@@ -46,6 +46,50 @@ const CUSTOM_VALUES = [
46
46
  value: ({ previousApprovalId }) => previousApprovalId || '',
47
47
  },
48
48
  ];
49
+ /**
50
+ * Function to get the display value of a property in submission
51
+ *
52
+ * #### Example
53
+ *
54
+ * ```typescript
55
+ *
56
+ * const result = submissionService.getElementSubmissionValue({
57
+ * propertyName: 'search',
58
+ * submission: {
59
+ * search: 'Entered By User',
60
+ * },
61
+ * formElements: [
62
+ * {
63
+ * id: 'd4135b47-9004-4d75-aeb3-d2f6232da111',
64
+ * name: 'search',
65
+ * type: 'text',
66
+ * label: 'Search',
67
+ * readOnly: false,
68
+ * required: false,
69
+ * conditionallyShow: false,
70
+ * requiresAllConditionallyShowPredicates: false,
71
+ * isElementLookup: false,
72
+ * isDataLookup: false,
73
+ * },
74
+ * ],
75
+ * formatDate: (value) => new Date(value).toDateString(),
76
+ * formatTime: (value) => new Date(value).toTimeString(),
77
+ * formatNumber: (value) => Number(value).toString(),
78
+ * formatCurrency: (value) => Number(value).toFixed(2),
79
+ * }: {
80
+ * propertyName: string
81
+ * formElements: FormTypes.FormElement[]
82
+ * submission: SubmissionTypes.S3SubmissionData['submission']
83
+ * formatDate: (value: string) => string
84
+ * formatTime: (value: string) => string
85
+ * formatNumber: (value: number) => string
86
+ * formatCurrency: (value: number) => string
87
+ * })
88
+ * ```
89
+ *
90
+ * @param options
91
+ * @returns
92
+ */
49
93
  function getElementSubmissionValue({ propertyName, submission, formElements, formatDate, formatTime, formatNumber, formatCurrency, }) {
50
94
  var _a, _b, _c;
51
95
  const formElement = (0, formElementsService_1.findFormElement)(formElements, (element) => element.type !== 'page' &&
@@ -159,6 +203,58 @@ function replaceElementValues(text, { form, submission, formatDate, formatTime,
159
203
  return newString.replace(match, value === undefined ? '' : value);
160
204
  }, text);
161
205
  }
206
+ /**
207
+ * Function to replace a custom values in text
208
+ *
209
+ * #### Example
210
+ *
211
+ * ```js
212
+ * const result = submissionService.replaceCustomValues(
213
+ * 'https://example.com/path?submissionId={SUBMISSION_ID}&externalId={EXTERNAL_ID}&search{ELEMENT:search}',
214
+ * {
215
+ * submissionId: 'abc-123',
216
+ * submissionTimestamp: '2021-07-02T02:19:13.670Z',
217
+ * formatDate: (value) => new Date(value).toDateString(),
218
+ * formatTime: (value) => new Date(value).toTimeString(),
219
+ * submission: {
220
+ * search: 'Entered By User',
221
+ * },
222
+ * form: {
223
+ * id: 1,
224
+ * name: 'Form',
225
+ * organisationId: '',
226
+ * formsAppEnvironmentId: 1,
227
+ * formsAppIds: [],
228
+ * isAuthenticated: false,
229
+ * isMultiPage: false,
230
+ * isInfoPage: false,
231
+ * postSubmissionAction: 'FORMS_LIBRARY',
232
+ * cancelAction: 'FORMS_LIBRARY',
233
+ * submissionEvents: [],
234
+ * tags: [],
235
+ * elements: [
236
+ * {
237
+ * id: 'd4135b47-9004-4d75-aeb3-d2f6232da111',
238
+ * name: 'search',
239
+ * type: 'text',
240
+ * label: 'Search',
241
+ * readOnly: false,
242
+ * required: false,
243
+ * conditionallyShow: false,
244
+ * requiresAllConditionallyShowPredicates: false,
245
+ * isElementLookup: false,
246
+ * isDataLookup: false,
247
+ * },
248
+ * ],
249
+ * },
250
+ * },
251
+ * )
252
+ * ```
253
+ *
254
+ * @param text
255
+ * @param options
256
+ * @returns
257
+ */
162
258
  function replaceCustomValues(text, { form, submission, externalId, submissionId, submissionTimestamp, formatDate, formatTime, formatNumber, formatCurrency, previousApprovalId, }) {
163
259
  const string = replaceElementValues(text, {
164
260
  form,
@@ -182,5 +278,5 @@ function replaceCustomValues(text, { form, submission, externalId, submissionId,
182
278
  }));
183
279
  }, string);
184
280
  }
185
- exports.default = replaceCustomValues;
281
+ exports.replaceCustomValues = replaceCustomValues;
186
282
  //# sourceMappingURL=replaceCustomValues.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"replaceCustomValues.js","sourceRoot":"","sources":["../src/replaceCustomValues.ts"],"names":[],"mappings":";;;AACA,+DAAuD;AACvD,6CAAwD;AAcxD,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,KAAK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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'\nimport { getABNNumberFromABNRecord } from './abnService'\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 case 'abn': {\n return value ? getABNNumberFromABNRecord(value) : undefined\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"]}
1
+ {"version":3,"file":"replaceCustomValues.js","sourceRoot":"","sources":["../src/replaceCustomValues.ts"],"names":[],"mappings":";;;AACA,+DAAuD;AACvD,6CAAwD;AAcxD,MAAM,aAAa,GAAG;IACpB;QACE,MAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,SAAgB,mBAAmB,CACjC,IAAY,EACZ,EACE,IAAI,EACJ,UAAU,EACV,UAAU,EACV,YAAY,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,kDAyCC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { findFormElement } from './formElementsService'\nimport { getABNNumberFromABNRecord } from './abnService'\n\nexport type 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\n/**\n * Function to get the display value of a property in submission\n *\n * #### Example\n *\n * ```typescript\n *\n * const result = submissionService.getElementSubmissionValue({\n * propertyName: 'search',\n * submission: {\n * search: 'Entered By User',\n * },\n * formElements: [\n * {\n * id: 'd4135b47-9004-4d75-aeb3-d2f6232da111',\n * name: 'search',\n * type: 'text',\n * label: 'Search',\n * readOnly: false,\n * required: false,\n * conditionallyShow: false,\n * requiresAllConditionallyShowPredicates: false,\n * isElementLookup: false,\n * isDataLookup: false,\n * },\n * ],\n * formatDate: (value) => new Date(value).toDateString(),\n * formatTime: (value) => new Date(value).toTimeString(),\n * formatNumber: (value) => Number(value).toString(),\n * formatCurrency: (value) => Number(value).toFixed(2),\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 * })\n * ```\n *\n * @param options\n * @returns\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 case 'abn': {\n return value ? getABNNumberFromABNRecord(value) : undefined\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\n/**\n * Function to replace a custom values in text\n *\n * #### Example\n *\n * ```js\n * const result = submissionService.replaceCustomValues(\n * 'https://example.com/path?submissionId={SUBMISSION_ID}&externalId={EXTERNAL_ID}&search{ELEMENT:search}',\n * {\n * submissionId: 'abc-123',\n * submissionTimestamp: '2021-07-02T02:19:13.670Z',\n * formatDate: (value) => new Date(value).toDateString(),\n * formatTime: (value) => new Date(value).toTimeString(),\n * submission: {\n * search: 'Entered By User',\n * },\n * form: {\n * id: 1,\n * name: 'Form',\n * organisationId: '',\n * formsAppEnvironmentId: 1,\n * formsAppIds: [],\n * isAuthenticated: false,\n * isMultiPage: false,\n * isInfoPage: false,\n * postSubmissionAction: 'FORMS_LIBRARY',\n * cancelAction: 'FORMS_LIBRARY',\n * submissionEvents: [],\n * tags: [],\n * elements: [\n * {\n * id: 'd4135b47-9004-4d75-aeb3-d2f6232da111',\n * name: 'search',\n * type: 'text',\n * label: 'Search',\n * readOnly: false,\n * required: false,\n * conditionallyShow: false,\n * requiresAllConditionallyShowPredicates: false,\n * isElementLookup: false,\n * isDataLookup: false,\n * },\n * ],\n * },\n * },\n * )\n * ```\n *\n * @param text\n * @param options\n * @returns\n */\nexport 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"]}