@oneblink/apps-react 13.5.1-beta.4 → 14.0.0-beta.1

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 (30) hide show
  1. package/dist/apps/approvals-service.d.ts +13 -1
  2. package/dist/apps/approvals-service.js +22 -1
  3. package/dist/apps/approvals-service.js.map +1 -1
  4. package/dist/apps/payment-service.d.ts +22 -0
  5. package/dist/apps/payment-service.js +43 -0
  6. package/dist/apps/payment-service.js.map +1 -1
  7. package/dist/apps/services/api/payment.d.ts +5 -1
  8. package/dist/apps/services/api/payment.js.map +1 -1
  9. package/dist/apps/services/fetch.d.ts +3 -1
  10. package/dist/apps/services/fetch.js +16 -4
  11. package/dist/apps/services/fetch.js.map +1 -1
  12. package/dist/apps/services/payment-handoff.d.ts +47 -0
  13. package/dist/apps/services/payment-handoff.js +79 -0
  14. package/dist/apps/services/payment-handoff.js.map +1 -0
  15. package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.d.ts +35 -19
  16. package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.js +41 -27
  17. package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.js.map +1 -1
  18. package/dist/apps/submission-service.js +2 -1
  19. package/dist/apps/submission-service.js.map +1 -1
  20. package/dist/components/payments/PaymentForm.d.ts +11 -6
  21. package/dist/components/payments/PaymentForm.js +10 -17
  22. package/dist/components/payments/PaymentForm.js.map +1 -1
  23. package/dist/components/payments/WestpacQuickStreamPaymentForm.d.ts +7 -11
  24. package/dist/components/payments/WestpacQuickStreamPaymentForm.js +25 -31
  25. package/dist/components/payments/WestpacQuickStreamPaymentForm.js.map +1 -1
  26. package/dist/services/form-validation/getApproverEditableFormElementIds.js +3 -0
  27. package/dist/services/form-validation/getApproverEditableFormElementIds.js.map +1 -1
  28. package/dist/services/getFlowInstanceNodesWithMeta.js +22 -3
  29. package/dist/services/getFlowInstanceNodesWithMeta.js.map +1 -1
  30. package/package.json +1 -1
@@ -1,16 +1,21 @@
1
1
  import { SubmissionTypes } from '@oneblink/types';
2
2
  import React from 'react';
3
3
  import { CaptchaType } from '../../types/form';
4
- declare function PaymentForm({ captchaSiteKey, captchaType, onCompleted, onCancelled, appImageUrl, title, }: {
5
- captchaSiteKey: string;
4
+ import type { PaymentFormSession } from '../../apps/services/payment-handoff';
5
+ /**
6
+ * Renders the payment form for a payment that is taken inside the application
7
+ * (for example Westpac QuickStream). The payment session is provided by the
8
+ * application, so the form does not depend on where the payment was started.
9
+ */
10
+ declare function PaymentForm({ session, captchaSiteKey, captchaType, onCompleted, onCancelled, appImageUrl, title, }: {
11
+ session: PaymentFormSession;
12
+ /** When provided, a CAPTCHA is shown and must be completed to make the payment */
13
+ captchaSiteKey?: string;
6
14
  captchaType?: CaptchaType;
7
15
  onCompleted: (result: {
8
16
  formSubmissionPayment: SubmissionTypes.FormSubmissionPayment;
9
- paymentReceiptUrl: string;
10
- }) => void;
11
- onCancelled: (result: {
12
- paymentReceiptUrl: string;
13
17
  }) => void;
18
+ onCancelled: () => void;
14
19
  appImageUrl?: string;
15
20
  title?: string;
16
21
  }): import("react/jsx-runtime").JSX.Element;
@@ -2,33 +2,26 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { paymentService } from '../../apps';
3
3
  import React from 'react';
4
4
  import WestpacQuickStreamPaymentForm from './WestpacQuickStreamPaymentForm';
5
- import useQuery from '../../hooks/useQuery';
6
5
  import useLoadDataState from '../../hooks/useLoadDataState';
7
6
  import OnLoading from '../renderer/OnLoading';
8
7
  import MaterialIcon from '../MaterialIcon';
9
- function PaymentForm({ captchaSiteKey, captchaType, onCompleted, onCancelled, appImageUrl, title, }) {
10
- const query = useQuery();
8
+ /**
9
+ * Renders the payment form for a payment that is taken inside the application
10
+ * (for example Westpac QuickStream). The payment session is provided by the
11
+ * application, so the form does not depend on where the payment was started.
12
+ */
13
+ function PaymentForm({ session, captchaSiteKey, captchaType, onCompleted, onCancelled, appImageUrl, title, }) {
11
14
  const loadPaymentFormConfiguration = React.useCallback(async (abortSignal) => {
12
- const formSubmissionPaymentId = query.formSubmissionPaymentId;
13
- if (typeof formSubmissionPaymentId !== 'string') {
14
- throw new Error('It looks like you are attempting to make an unknown payment.');
15
- }
16
- const { formSubmissionResult, paymentSubmissionEvent } = await paymentService.getFormSubmissionResultPayment();
17
- switch (paymentSubmissionEvent.type) {
15
+ switch (session.paymentType) {
18
16
  case 'WESTPAC_QUICK_STREAM': {
19
17
  const { supplierBusinessCode, publishableApiKey, isTestMode } = await paymentService.westpacQuickStream.getPaymentFormConfiguration({
20
- formSubmissionPaymentId,
21
- formSubmissionResult,
22
- paymentSubmissionEvent,
18
+ session,
23
19
  abortSignal,
24
20
  });
25
21
  return {
26
- renderPaymentForm: () => (_jsx(WestpacQuickStreamPaymentForm, { formSubmissionResult: formSubmissionResult, paymentSubmissionEvent: paymentSubmissionEvent, formSubmissionPaymentId: formSubmissionPaymentId, supplierBusinessCode: supplierBusinessCode, publishableApiKey: publishableApiKey, isTestMode: isTestMode, captchaSiteKey: captchaSiteKey, captchaType: captchaType, onCompleted: onCompleted, onCancelled: onCancelled, appImageUrl: appImageUrl, title: title })),
22
+ renderPaymentForm: () => (_jsx(WestpacQuickStreamPaymentForm, { session: session, supplierBusinessCode: supplierBusinessCode, publishableApiKey: publishableApiKey, isTestMode: isTestMode, captchaSiteKey: captchaSiteKey, captchaType: captchaType, onCompleted: onCompleted, onCancelled: onCancelled, appImageUrl: appImageUrl, title: title })),
27
23
  };
28
24
  }
29
- default: {
30
- throw new Error(`"${paymentSubmissionEvent.type}" payment events do not support a custom payment form.`);
31
- }
32
25
  }
33
26
  }, [
34
27
  appImageUrl,
@@ -36,7 +29,7 @@ function PaymentForm({ captchaSiteKey, captchaType, onCompleted, onCancelled, ap
36
29
  captchaType,
37
30
  onCancelled,
38
31
  onCompleted,
39
- query.formSubmissionPaymentId,
32
+ session,
40
33
  title,
41
34
  ]);
42
35
  const [state] = useLoadDataState(loadPaymentFormConfiguration);
@@ -1 +1 @@
1
- {"version":3,"file":"PaymentForm.js","sourceRoot":"","sources":["../../../src/components/payments/PaymentForm.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,6BAA6B,MAAM,iCAAiC,CAAA;AAC3E,OAAO,QAAQ,MAAM,sBAAsB,CAAA;AAC3C,OAAO,gBAAgB,MAAM,8BAA8B,CAAA;AAC3D,OAAO,SAAS,MAAM,uBAAuB,CAAA;AAC7C,OAAO,YAAY,MAAM,iBAAiB,CAAA;AAG1C,SAAS,WAAW,CAAC,EACnB,cAAc,EACd,WAAW,EACX,WAAW,EACX,WAAW,EACX,WAAW,EACX,KAAK,GAWN;IACC,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAA;IAExB,MAAM,4BAA4B,GAAG,KAAK,CAAC,WAAW,CACpD,KAAK,EAAE,WAAwB,EAAE,EAAE;QACjC,MAAM,uBAAuB,GAAG,KAAK,CAAC,uBAAuB,CAAA;QAC7D,IAAI,OAAO,uBAAuB,KAAK,QAAQ,EAAE,CAAC;YAChD,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAA;QACH,CAAC;QAED,MAAM,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,GACpD,MAAM,cAAc,CAAC,8BAA8B,EAAE,CAAA;QACvD,QAAQ,sBAAsB,CAAC,IAAI,EAAE,CAAC;YACpC,KAAK,sBAAsB,CAAC,CAAC,CAAC;gBAC5B,MAAM,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,UAAU,EAAE,GAC3D,MAAM,cAAc,CAAC,kBAAkB,CAAC,2BAA2B,CACjE;oBACE,uBAAuB;oBACvB,oBAAoB;oBACpB,sBAAsB;oBACtB,WAAW;iBACZ,CACF,CAAA;gBACH,OAAO;oBACL,iBAAiB,EAAE,GAAG,EAAE,CAAC,CACvB,KAAC,6B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;YACf,OAAO,KAAK,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAA;QACzC,CAAC;IACH,CAAC;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA","sourcesContent":["import { paymentService } from '../../apps'\nimport { SubmissionTypes } from '@oneblink/types'\nimport React from 'react'\nimport WestpacQuickStreamPaymentForm from './WestpacQuickStreamPaymentForm'\nimport useQuery from '../../hooks/useQuery'\nimport useLoadDataState from '../../hooks/useLoadDataState'\nimport OnLoading from '../renderer/OnLoading'\nimport MaterialIcon from '../MaterialIcon'\nimport { CaptchaType } from '../../types/form'\n\nfunction PaymentForm({\n captchaSiteKey,\n captchaType,\n onCompleted,\n onCancelled,\n appImageUrl,\n title,\n}: {\n captchaSiteKey: string\n captchaType?: CaptchaType\n onCompleted: (result: {\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment\n paymentReceiptUrl: string\n }) => void\n onCancelled: (result: { paymentReceiptUrl: string }) => void\n appImageUrl?: string\n title?: string\n}) {\n const query = useQuery()\n\n const loadPaymentFormConfiguration = React.useCallback(\n async (abortSignal: AbortSignal) => {\n const formSubmissionPaymentId = query.formSubmissionPaymentId\n if (typeof formSubmissionPaymentId !== 'string') {\n throw new Error(\n 'It looks like you are attempting to make an unknown payment.',\n )\n }\n\n const { formSubmissionResult, paymentSubmissionEvent } =\n await paymentService.getFormSubmissionResultPayment()\n switch (paymentSubmissionEvent.type) {\n case 'WESTPAC_QUICK_STREAM': {\n const { supplierBusinessCode, publishableApiKey, isTestMode } =\n await paymentService.westpacQuickStream.getPaymentFormConfiguration(\n {\n formSubmissionPaymentId,\n formSubmissionResult,\n paymentSubmissionEvent,\n abortSignal,\n },\n )\n return {\n renderPaymentForm: () => (\n <WestpacQuickStreamPaymentForm\n formSubmissionResult={formSubmissionResult}\n paymentSubmissionEvent={paymentSubmissionEvent}\n formSubmissionPaymentId={formSubmissionPaymentId}\n supplierBusinessCode={supplierBusinessCode}\n publishableApiKey={publishableApiKey}\n isTestMode={isTestMode}\n captchaSiteKey={captchaSiteKey}\n captchaType={captchaType}\n onCompleted={onCompleted}\n onCancelled={onCancelled}\n appImageUrl={appImageUrl}\n title={title}\n />\n ),\n }\n }\n default: {\n throw new Error(\n `\"${paymentSubmissionEvent.type}\" payment events do not support a custom payment form.`,\n )\n }\n }\n },\n [\n appImageUrl,\n captchaSiteKey,\n captchaType,\n onCancelled,\n onCompleted,\n query.formSubmissionPaymentId,\n title,\n ],\n )\n\n const [state] = useLoadDataState(loadPaymentFormConfiguration)\n\n switch (state.status) {\n case 'LOADING': {\n return (\n <section>\n <div className=\"cypress-loading has-text-centered\">\n <OnLoading className=\"has-text-centered\"></OnLoading>\n <span>Loading payment configuration...</span>\n </div>\n </section>\n )\n }\n case 'ERROR': {\n return (\n <section\n className=\"cypress-payment-form-loading-error-message\"\n role=\"alert\"\n >\n <div className=\"ob-payment-form__error-icon-container has-text-centered has-margin-bottom-8\">\n <MaterialIcon className=\"ob-payment-form__error-icon has-text-danger icon-x-large\">\n error\n </MaterialIcon>\n </div>\n <p className=\"ob-payment-form__error-message has-text-centered has-margin-bottom-4\">\n {state.error.message}\n </p>\n </section>\n )\n }\n case 'SUCCESS': {\n return state.result.renderPaymentForm()\n }\n }\n}\n\nexport default React.memo(PaymentForm)\n"]}
1
+ {"version":3,"file":"PaymentForm.js","sourceRoot":"","sources":["../../../src/components/payments/PaymentForm.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,6BAA6B,MAAM,iCAAiC,CAAA;AAC3E,OAAO,gBAAgB,MAAM,8BAA8B,CAAA;AAC3D,OAAO,SAAS,MAAM,uBAAuB,CAAA;AAC7C,OAAO,YAAY,MAAM,iBAAiB,CAAA;AAI1C;;;;GAIG;AACH,SAAS,WAAW,CAAC,EACnB,OAAO,EACP,cAAc,EACd,WAAW,EACX,WAAW,EAC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AEZ,cAAK,SAAS,EAAC,6EAA6E,YAC1F,KAAC,YAAY,IAAC,SAAS,EAAC,0DAA0D,sBAEnE,GACX,EACN,YAAG,SAAS,EAAC,sEAAsE,YAChF,KAAK,CAAC,KAAK,CAAC,OAAO,GAClB,IACI,CACX,CAAA;QACH,CAAC;QACD,KAAK,SAAS,CAAC,CAAC,CAAC;YACf,OAAO,KAAK,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAA;QACzC,CAAC;IACH,CAAC;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA","sourcesContent":["import { paymentService } from '../../apps'\nimport { SubmissionTypes } from '@oneblink/types'\nimport React from 'react'\nimport WestpacQuickStreamPaymentForm from './WestpacQuickStreamPaymentForm'\nimport useLoadDataState from '../../hooks/useLoadDataState'\nimport OnLoading from '../renderer/OnLoading'\nimport MaterialIcon from '../MaterialIcon'\nimport { CaptchaType } from '../../types/form'\nimport type { PaymentFormSession } from '../../apps/services/payment-handoff'\n\n/**\n * Renders the payment form for a payment that is taken inside the application\n * (for example Westpac QuickStream). The payment session is provided by the\n * application, so the form does not depend on where the payment was started.\n */\nfunction PaymentForm({\n session,\n captchaSiteKey,\n captchaType,\n onCompleted,\n onCancelled,\n appImageUrl,\n title,\n}: {\n session: PaymentFormSession\n /** When provided, a CAPTCHA is shown and must be completed to make the payment */\n captchaSiteKey?: string\n captchaType?: CaptchaType\n onCompleted: (result: {\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment\n }) => void\n onCancelled: () => void\n appImageUrl?: string\n title?: string\n}) {\n const loadPaymentFormConfiguration = React.useCallback(\n async (abortSignal: AbortSignal) => {\n switch (session.paymentType) {\n case 'WESTPAC_QUICK_STREAM': {\n const { supplierBusinessCode, publishableApiKey, isTestMode } =\n await paymentService.westpacQuickStream.getPaymentFormConfiguration(\n {\n session,\n abortSignal,\n },\n )\n return {\n renderPaymentForm: () => (\n <WestpacQuickStreamPaymentForm\n session={session}\n supplierBusinessCode={supplierBusinessCode}\n publishableApiKey={publishableApiKey}\n isTestMode={isTestMode}\n captchaSiteKey={captchaSiteKey}\n captchaType={captchaType}\n onCompleted={onCompleted}\n onCancelled={onCancelled}\n appImageUrl={appImageUrl}\n title={title}\n />\n ),\n }\n }\n }\n },\n [\n appImageUrl,\n captchaSiteKey,\n captchaType,\n onCancelled,\n onCompleted,\n session,\n title,\n ],\n )\n\n const [state] = useLoadDataState(loadPaymentFormConfiguration)\n\n switch (state.status) {\n case 'LOADING': {\n return (\n <section>\n <div className=\"cypress-loading has-text-centered\">\n <OnLoading className=\"has-text-centered\"></OnLoading>\n <span>Loading payment configuration...</span>\n </div>\n </section>\n )\n }\n case 'ERROR': {\n return (\n <section\n className=\"cypress-payment-form-loading-error-message\"\n role=\"alert\"\n >\n <div className=\"ob-payment-form__error-icon-container has-text-centered has-margin-bottom-8\">\n <MaterialIcon className=\"ob-payment-form__error-icon has-text-danger icon-x-large\">\n error\n </MaterialIcon>\n </div>\n <p className=\"ob-payment-form__error-message has-text-centered has-margin-bottom-4\">\n {state.error.message}\n </p>\n </section>\n )\n }\n case 'SUCCESS': {\n return state.result.renderPaymentForm()\n }\n }\n}\n\nexport default React.memo(PaymentForm)\n"]}
@@ -1,5 +1,5 @@
1
- import { submissionService } from '../../apps';
2
- import { SubmissionTypes, SubmissionEventTypes } from '@oneblink/types';
1
+ import { SubmissionTypes } from '@oneblink/types';
2
+ import type { PaymentFormSession } from '../../apps/services/payment-handoff';
3
3
  import React from 'react';
4
4
  import { CaptchaType } from '../../typedoc';
5
5
  interface TrustedFrame {
@@ -29,22 +29,18 @@ declare global {
29
29
  };
30
30
  }
31
31
  }
32
- declare function WestpacQuickStreamPaymentForm({ formSubmissionResult, paymentSubmissionEvent, formSubmissionPaymentId, supplierBusinessCode, publishableApiKey, isTestMode, captchaSiteKey, captchaType, onCompleted, onCancelled, appImageUrl, title, }: {
33
- formSubmissionResult: submissionService.FormSubmissionResult;
34
- paymentSubmissionEvent: SubmissionEventTypes.WestpacQuickStreamSubmissionEvent;
35
- formSubmissionPaymentId: string;
32
+ declare function WestpacQuickStreamPaymentForm({ session, supplierBusinessCode, publishableApiKey, isTestMode, captchaSiteKey, captchaType, onCompleted, onCancelled, appImageUrl, title, }: {
33
+ session: PaymentFormSession;
36
34
  supplierBusinessCode: string;
37
35
  publishableApiKey: string;
38
36
  isTestMode: boolean;
39
- captchaSiteKey: string;
37
+ /** When provided, a CAPTCHA is required before the payment is completed */
38
+ captchaSiteKey?: string;
40
39
  captchaType?: CaptchaType;
41
40
  onCompleted: (result: {
42
41
  formSubmissionPayment: SubmissionTypes.FormSubmissionPayment;
43
- paymentReceiptUrl: string;
44
- }) => void;
45
- onCancelled: (result: {
46
- paymentReceiptUrl: string;
47
42
  }) => void;
43
+ onCancelled: () => void;
48
44
  appImageUrl?: string;
49
45
  title?: string;
50
46
  }): import("react/jsx-runtime").JSX.Element;
@@ -10,8 +10,7 @@ import Modal from '../renderer/Modal';
10
10
  import MaterialIcon from '../MaterialIcon';
11
11
  import useReCAPTCHAProps from '../../hooks/useReCAPTCHAProps';
12
12
  import FormElementValidationMessage from '../renderer/FormElementValidationMessage';
13
- function WestpacQuickStreamPaymentForm({ formSubmissionResult, paymentSubmissionEvent, formSubmissionPaymentId, supplierBusinessCode, publishableApiKey, isTestMode, captchaSiteKey, captchaType, onCompleted, onCancelled, appImageUrl, title, }) {
14
- var _a, _b;
13
+ function WestpacQuickStreamPaymentForm({ session, supplierBusinessCode, publishableApiKey, isTestMode, captchaSiteKey, captchaType, onCompleted, onCancelled, appImageUrl, title, }) {
15
14
  const [{ isCompletingTransaction, completeTransactionError, captchaToken, displayCaptchaRequired, }, setCompleteTransactionState,] = React.useState({
16
15
  isCompletingTransaction: false,
17
16
  completeTransactionError: null,
@@ -170,24 +169,28 @@ function WestpacQuickStreamPaymentForm({ formSubmissionResult, paymentSubmission
170
169
  }));
171
170
  return;
172
171
  }
173
- const { recaptchaToken, displayCaptchaRequired } = await getRecaptchaToken();
174
- if (!recaptchaToken) {
175
- setCompleteTransactionState({
176
- captchaToken: null,
177
- displayCaptchaRequired,
178
- isCompletingTransaction: false,
179
- completeTransactionError: null,
180
- });
181
- return;
172
+ let recaptcha;
173
+ if (captchaSiteKey) {
174
+ const { recaptchaToken, displayCaptchaRequired } = await getRecaptchaToken();
175
+ if (!recaptchaToken) {
176
+ setCompleteTransactionState({
177
+ captchaToken: null,
178
+ displayCaptchaRequired,
179
+ isCompletingTransaction: false,
180
+ completeTransactionError: null,
181
+ });
182
+ return;
183
+ }
184
+ recaptcha = {
185
+ siteKey: captchaSiteKey,
186
+ token: recaptchaToken,
187
+ };
182
188
  }
183
189
  paymentService.westpacQuickStream
184
190
  .completeTransaction({
191
+ session,
185
192
  singleUseTokenId: data.singleUseToken.singleUseTokenId,
186
- formSubmissionResult,
187
- formSubmissionPaymentId,
188
- paymentSubmissionEvent,
189
- captchaSiteKey,
190
- captchaToken: recaptchaToken,
193
+ recaptcha,
191
194
  })
192
195
  .then(onCompleted)
193
196
  .catch((error) => {
@@ -198,15 +201,7 @@ function WestpacQuickStreamPaymentForm({ formSubmissionResult, paymentSubmission
198
201
  }));
199
202
  });
200
203
  });
201
- }, [
202
- trustedFrame,
203
- getRecaptchaToken,
204
- formSubmissionResult,
205
- formSubmissionPaymentId,
206
- paymentSubmissionEvent,
207
- captchaSiteKey,
208
- onCompleted,
209
- ]);
204
+ }, [trustedFrame, getRecaptchaToken, session, captchaSiteKey, onCompleted]);
210
205
  const [{ isCancellingTransaction, cancelError }, setCancelState] = React.useState({
211
206
  isCancellingTransaction: false,
212
207
  cancelError: null,
@@ -223,11 +218,10 @@ function WestpacQuickStreamPaymentForm({ formSubmissionResult, paymentSubmission
223
218
  cancelError: null,
224
219
  });
225
220
  try {
226
- const result = await paymentService.westpacQuickStream.cancelPayment({
227
- formSubmissionPaymentId,
228
- formSubmissionResult,
221
+ await paymentService.westpacQuickStream.cancelPayment({
222
+ session,
229
223
  });
230
- onCancelled(result);
224
+ onCancelled();
231
225
  }
232
226
  catch (error) {
233
227
  console.warn('Failed to cancel payment', error);
@@ -236,11 +230,11 @@ function WestpacQuickStreamPaymentForm({ formSubmissionResult, paymentSubmission
236
230
  cancelError: error,
237
231
  });
238
232
  }
239
- }, [formSubmissionPaymentId, formSubmissionResult, onCancelled]);
233
+ }, [session, onCancelled]);
240
234
  return (_jsxs(_Fragment, { children: [isLoading && (_jsx("section", { children: _jsxs("div", { className: "cypress-loading has-text-centered", children: [_jsx(OnLoading, { className: "has-text-centered" }), _jsx("span", { children: "Building payment form..." })] }) })), loadError && (_jsxs("section", { className: "cypress-payment-form-loading-error-message", children: [_jsx("div", { className: "ob-payment-form__error-icon-container has-text-centered has-margin-bottom-8", children: _jsx(MaterialIcon, { className: "ob-payment-form__error-icon has-text-danger icon-x-large", children: "error" }) }), _jsx("p", { className: "ob-payment-form__error-message has-text-centered has-margin-bottom-4", children: loadError.message })] })), _jsx("section", { children: _jsxs("form", { onSubmit: (event) => {
241
235
  event.preventDefault();
242
236
  handleSubmit();
243
- }, children: [_jsxs("div", { className: "ob-payment-form__westpac-quickstream-container", children: [!!appImageUrl && (_jsx("figure", { className: "image is-128x128 has-margin-bottom-6 ml-auto mr-auto", children: _jsx("img", { alt: "Application Icon", className: "is-rounded", src: appImageUrl }) })), !!title && (_jsx("h3", { className: "title is-3 is-size-3-mobile ob-header__heading has-text-centered", children: title })), _jsx("label", { className: "label ob-label has-text-centered", children: "Fill out the form below to complete your secure payment." }), _jsxs("div", { className: "ob-payment-form__westpac-quickstream-amount", children: [_jsx("div", { children: "Amount" }), _jsx("div", { className: "ob-payment-form__westpac-quickstream-amount-value", children: localisationService.formatCurrency((_b = (_a = formSubmissionResult.payment) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : 0) })] }), _jsx("div", { "data-quickstream-api": "creditCardContainer", className: "quickstream-credit-card-container" }), !isLoading && !loadError && (_jsxs(_Fragment, { children: [_jsx(ReCAPTCHA, { ...recaptchaProps, className: "ob-input cypress-captcha-control ob-payment-form__westpac-quickstream-captcha" }), displayCaptchaRequired && (_jsx(FormElementValidationMessage, { message: "Please complete the CAPTCHA successfully", className: "cypress-required" }))] }))] }), !isLoading && !loadError && (_jsxs("div", { className: "ob-payment-form__westpac-quickstream-form-actions", children: [_jsx("button", { type: "button", disabled: isCompletingTransaction || isCancellingTransaction, onClick: handleCancel, className: clsx('button ob-button is-outlined', {
237
+ }, children: [_jsxs("div", { className: "ob-payment-form__westpac-quickstream-container", children: [!!appImageUrl && (_jsx("figure", { className: "image is-128x128 has-margin-bottom-6 ml-auto mr-auto", children: _jsx("img", { alt: "Application Icon", className: "is-rounded", src: appImageUrl }) })), !!title && (_jsx("h3", { className: "title is-3 is-size-3-mobile ob-header__heading has-text-centered", children: title })), _jsx("label", { className: "label ob-label has-text-centered", children: "Fill out the form below to complete your secure payment." }), _jsxs("div", { className: "ob-payment-form__westpac-quickstream-amount", children: [_jsx("div", { children: "Amount" }), _jsx("div", { className: "ob-payment-form__westpac-quickstream-amount-value", children: localisationService.formatCurrency(session.amount) })] }), _jsx("div", { "data-quickstream-api": "creditCardContainer", className: "quickstream-credit-card-container" }), !isLoading && !loadError && captchaSiteKey && (_jsxs(_Fragment, { children: [_jsx(ReCAPTCHA, { ...recaptchaProps, className: "ob-input cypress-captcha-control ob-payment-form__westpac-quickstream-captcha" }), displayCaptchaRequired && (_jsx(FormElementValidationMessage, { message: "Please complete the CAPTCHA successfully", className: "cypress-required" }))] }))] }), !isLoading && !loadError && (_jsxs("div", { className: "ob-payment-form__westpac-quickstream-form-actions", children: [_jsx("button", { type: "button", disabled: isCompletingTransaction || isCancellingTransaction, onClick: handleCancel, className: clsx('button ob-button is-outlined', {
244
238
  'is-loading': isCancellingTransaction,
245
239
  }), children: "Cancel" }), _jsx("button", { type: "submit", disabled: isCompletingTransaction || isCancellingTransaction, className: clsx('button ob-button is-success', {
246
240
  'is-loading': isCompletingTransaction,
@@ -1 +1 @@
1
- {"version":3,"file":"WestpacQuickStreamPaymentForm.js","sourceRoot":"","sources":["../../../src/components/payments/WestpacQuickStreamPaymentForm.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EAEd,mBAAmB,GACpB,MAAM,YAAY,CAAA;AAEnB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,SAAS,MAAM,wBAAwB,CAAA;AAC9C,OAAO,KAAK,UAAU,MAAM,aAAa,CAAA;AACzC,OAAO,SAAS,MAAM,uBAAuB,CAAA;AAC7C,OAAO,gCAAgC,MAAM,8CAA8C,CAAA;AAC3F,OAAO,KAAK,MAAM,mBAAmB,CAAA;AACrC,OAAO,YAAY,MAAM,iBAAiB,CAAA;AAC1C,OAAO,iBAAiB,MAAM,+BAA+B,CAAA;AAE7D,OAAO,4BAA4B,MAAM,0CAA0C,CAAA;AA2CnF,SAAS,6BAA6B,CAAC,EACrC,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,WAAW,EACX,WAAW,EACX,WAAW,EACX,WAAW,EACX,KAAK,GAiBN;;IACC,MAAM,CACJ,EACE,uBAAuB,EACvB,wBAAwB,EACxB,YAAY,EACZ,sBAAsB,GACvB,EACD,2BAA2B,EAC5B,GAAG,KAAK,CAAC,QAAQ,CAKf;QACD,uBAAuB,EAAE,KAAK;QAC9B,wBAAwB,EAAE,IAAI;QAC9B,YAAY,EAAE,IAAI;QAClB,sBAAsB,EAAE,KAAK;KAC9B,CAAC,CAAA;IAEF,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAY,IAAI,CAAC,CAAA;IAEhD,MAAM,6BAA6B,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QAC3D,2BAA2B,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;YAC7C,GAAG,YAAY;YACf,uBAAuB,EA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,EAC9C,OAAO,EACL,4BACE,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,gEAAgE,EAC1E,OAAO,EAAE,6BAA6B,EACtC,SAAS,2BAGF,GACR,YAGL,8BACE,wBACG,wBAAwB,YAAY,KAAK;gCACxC,CAAC,CAAC,wBAAwB,CAAC,OAAO;gCAClC,CAAC,CAAC,wBAAwB,GACxB,EACL,wBAAwB,YAAY,iBAAiB,IAAI,CACxD,KAAC,gCAAgC,IAC/B,KAAK,EAAE,wBAAwB,CAAC,aAAa,GAC7C,CACH,IACA,GACG,EAER,KAAC,KAAK,IACJ,MAAM,EAAE,CAAC,CAAC,WAAW,EACrB,KAAK,EAAC,cAAc,EACpB,SAAS,EAAC,mCAAmC,EAC7C,OAAO,EACL,4BACE,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,+DAA+D,EACzE,OAAO,EAAE,gBAAgB,EACzB,SAAS,2BAGF,GACR,YAGL,8BACE,wBACG,WAAW,YAAY,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,GAC7D,EACL,WAAW,YAAY,iBAAiB,IAAI,CAC3C,KAAC,gCAAgC,IAC/B,KAAK,EAAE,WAAW,CAAC,aAAa,GAChC,CACH,IACA,GACG,IACP,CACJ,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAA","sourcesContent":["import {\n OneBlinkAppsError,\n paymentService,\n submissionService,\n localisationService,\n} from '../../apps'\nimport { SubmissionTypes, SubmissionEventTypes } from '@oneblink/types'\nimport clsx from 'clsx'\nimport React from 'react'\nimport ReCAPTCHA from 'react-google-recaptcha'\nimport * as bulmaToast from 'bulma-toast'\nimport OnLoading from '../renderer/OnLoading'\nimport OneBlinkAppsErrorOriginalMessage from '../renderer/OneBlinkAppsErrorOriginalMessage'\nimport Modal from '../renderer/Modal'\nimport MaterialIcon from '../MaterialIcon'\nimport useReCAPTCHAProps from '../../hooks/useReCAPTCHAProps'\nimport { CaptchaType } from '../../typedoc'\nimport FormElementValidationMessage from '../renderer/FormElementValidationMessage'\n\ninterface TrustedFrame {\n submitForm(\n callback: (\n errors:\n | Array<{\n fieldName: string\n messages: string[]\n }>\n | undefined,\n data: {\n singleUseToken: {\n singleUseTokenId: string\n }\n },\n ) => void,\n ): void\n}\n\ndeclare global {\n interface Window {\n QuickstreamAPI: {\n init(options: { publishableApiKey: string }): void\n creditCards: {\n createTrustedFrame(\n options: unknown,\n callback: (\n errors:\n | Array<{\n fieldName: string\n messages: string[]\n }>\n | undefined,\n data: {\n trustedFrame: TrustedFrame\n },\n ) => void,\n ): void\n }\n }\n }\n}\nfunction WestpacQuickStreamPaymentForm({\n formSubmissionResult,\n paymentSubmissionEvent,\n formSubmissionPaymentId,\n supplierBusinessCode,\n publishableApiKey,\n isTestMode,\n captchaSiteKey,\n captchaType,\n onCompleted,\n onCancelled,\n appImageUrl,\n title,\n}: {\n formSubmissionResult: submissionService.FormSubmissionResult\n paymentSubmissionEvent: SubmissionEventTypes.WestpacQuickStreamSubmissionEvent\n formSubmissionPaymentId: string\n supplierBusinessCode: string\n publishableApiKey: string\n isTestMode: boolean\n captchaSiteKey: string\n captchaType?: CaptchaType\n onCompleted: (result: {\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment\n paymentReceiptUrl: string\n }) => void\n onCancelled: (result: { paymentReceiptUrl: string }) => void\n appImageUrl?: string\n title?: string\n}) {\n const [\n {\n isCompletingTransaction,\n completeTransactionError,\n captchaToken,\n displayCaptchaRequired,\n },\n setCompleteTransactionState,\n ] = React.useState<{\n captchaToken: string | null\n displayCaptchaRequired: boolean\n isCompletingTransaction: boolean\n completeTransactionError: Error | null\n }>({\n isCompletingTransaction: false,\n completeTransactionError: null,\n captchaToken: null,\n displayCaptchaRequired: false,\n })\n\n const captchaRef = React.useRef<ReCAPTCHA>(null)\n\n const clearCompleteTransactionError = React.useCallback(() => {\n setCompleteTransactionState((currentState) => ({\n ...currentState,\n isCompletingTransaction: false,\n completeTransactionError: null,\n }))\n }, [])\n\n const [{ trustedFrame, isLoading, loadError }, setLoadState] =\n React.useState<{\n trustedFrame: TrustedFrame | null\n isLoading: boolean\n loadError: Error | null\n }>({\n trustedFrame: null,\n isLoading: true,\n loadError: null,\n })\n\n React.useEffect(() => {\n const abortController = new AbortController()\n const scriptEle = document.createElement('script')\n scriptEle.type = 'text/javascript'\n scriptEle.async = true\n\n const run = async () => {\n try {\n scriptEle.src = isTestMode\n ? 'https://api.quickstream.support.qvalent.com/rest/v1/quickstream-api-1.0.min.js'\n : 'https://api.quickstream.westpac.com.au/rest/v1/quickstream-api-1.0.min.js'\n\n await new Promise((resolve, reject) => {\n try {\n scriptEle.addEventListener(\n 'load',\n () => {\n resolve(undefined)\n },\n {\n signal: abortController.signal,\n },\n )\n\n scriptEle.addEventListener(\n 'error',\n () => {\n reject(new Error(`Failed to load the script ${scriptEle.src}`))\n },\n {\n signal: abortController.signal,\n },\n )\n\n document.body.appendChild(scriptEle)\n } catch (error) {\n console.warn('Failed to load script', error)\n reject(error)\n }\n })\n\n window.QuickstreamAPI.init({\n publishableApiKey,\n })\n const newTrustedFrame = await new Promise<TrustedFrame>(\n (resolve, reject) => {\n window.QuickstreamAPI.creditCards.createTrustedFrame(\n {\n config: {\n supplierBusinessCode,\n },\n iframe: {\n style: {\n width: '100%',\n },\n },\n showAcceptedCards: true,\n showRequiredIndicators: true,\n },\n (errors, data) => {\n if (errors) {\n reject(errors)\n return\n }\n resolve(data.trustedFrame)\n },\n )\n },\n )\n\n if (!abortController.signal.aborted) {\n setLoadState({\n trustedFrame: newTrustedFrame,\n isLoading: false,\n loadError: null,\n })\n }\n } catch (error) {\n if (!abortController.signal.aborted) {\n setLoadState({\n trustedFrame: null,\n isLoading: false,\n loadError: error as Error,\n })\n }\n }\n }\n\n run()\n\n return () => {\n abortController.abort()\n document.body.removeChild(scriptEle)\n }\n }, [isTestMode, publishableApiKey, supplierBusinessCode])\n\n const recaptchaType = React.useMemo(\n () => captchaType ?? 'CHECKBOX',\n [captchaType],\n )\n\n const hanedleCaptchaChange = React.useCallback((newValue: string | null) => {\n setCompleteTransactionState((currentState) => ({\n ...currentState,\n captchaToken: newValue,\n displayCaptchaRequired: newValue === null,\n }))\n }, [])\n\n const recaptchaProps = useReCAPTCHAProps({\n captchaSiteKey,\n captchaRef,\n onCaptchaChange: hanedleCaptchaChange,\n captchaType: recaptchaType,\n })\n\n const getRecaptchaToken = React.useCallback(async () => {\n captchaRef.current?.reset()\n switch (captchaType) {\n case 'INVISIBLE': {\n const token = await captchaRef.current\n ?.executeAsync()\n .catch((error) => {\n console.log('Invisible captcha executeAsync failure', error)\n return null\n })\n if (!token) {\n console.log('Captcha token failure')\n bulmaToast.toast({\n message: 'Failed to get a captcha token',\n type: 'is-danger',\n extraClasses: 'ob-toast cypress-failed-captcha-token-creation',\n duration: 4000,\n pauseOnHover: true,\n closeOnClick: true,\n })\n }\n return {\n recaptchaToken: token ?? null,\n displayCaptchaRequired: false,\n }\n }\n case 'CHECKBOX':\n default:\n return { recaptchaToken: captchaToken, displayCaptchaRequired: true }\n }\n }, [captchaToken, captchaType])\n\n const handleSubmit = React.useCallback(async () => {\n if (!trustedFrame) {\n return\n }\n\n setCompleteTransactionState((currentState) => ({\n ...currentState,\n isCompletingTransaction: true,\n completeTransactionError: null,\n }))\n\n trustedFrame.submitForm(async (errors, data) => {\n if (errors) {\n console.log('Invalid payment form submission', errors)\n setCompleteTransactionState((currentState) => ({\n ...currentState,\n isCompletingTransaction: false,\n completeTransactionError: null,\n }))\n return\n }\n\n const { recaptchaToken, displayCaptchaRequired } =\n await getRecaptchaToken()\n\n if (!recaptchaToken) {\n setCompleteTransactionState({\n captchaToken: null,\n displayCaptchaRequired,\n isCompletingTransaction: false,\n completeTransactionError: null,\n })\n return\n }\n\n paymentService.westpacQuickStream\n .completeTransaction({\n singleUseTokenId: data.singleUseToken.singleUseTokenId,\n formSubmissionResult,\n formSubmissionPaymentId,\n paymentSubmissionEvent,\n captchaSiteKey,\n captchaToken: recaptchaToken,\n })\n .then(onCompleted)\n .catch((error) => {\n setCompleteTransactionState((currentState) => ({\n ...currentState,\n isCompletingTransaction: false,\n completeTransactionError: error,\n }))\n })\n })\n }, [\n trustedFrame,\n getRecaptchaToken,\n formSubmissionResult,\n formSubmissionPaymentId,\n paymentSubmissionEvent,\n captchaSiteKey,\n onCompleted,\n ])\n\n const [{ isCancellingTransaction, cancelError }, setCancelState] =\n React.useState<{\n isCancellingTransaction: boolean\n cancelError: Error | null\n }>({\n isCancellingTransaction: false,\n cancelError: null,\n })\n\n const clearCancelError = React.useCallback(() => {\n setCancelState({\n isCancellingTransaction: false,\n cancelError: null,\n })\n }, [])\n\n const handleCancel = React.useCallback(async () => {\n setCancelState({\n isCancellingTransaction: true,\n cancelError: null,\n })\n try {\n const result = await paymentService.westpacQuickStream.cancelPayment({\n formSubmissionPaymentId,\n formSubmissionResult,\n })\n onCancelled(result)\n } catch (error) {\n console.warn('Failed to cancel payment', error)\n setCancelState({\n isCancellingTransaction: false,\n cancelError: error as Error,\n })\n }\n }, [formSubmissionPaymentId, formSubmissionResult, onCancelled])\n\n return (\n <>\n {isLoading && (\n <section>\n <div className=\"cypress-loading has-text-centered\">\n <OnLoading className=\"has-text-centered\"></OnLoading>\n <span>Building payment form...</span>\n </div>\n </section>\n )}\n\n {loadError && (\n <section className=\"cypress-payment-form-loading-error-message\">\n <div className=\"ob-payment-form__error-icon-container has-text-centered has-margin-bottom-8\">\n <MaterialIcon className=\"ob-payment-form__error-icon has-text-danger icon-x-large\">\n error\n </MaterialIcon>\n </div>\n <p className=\"ob-payment-form__error-message has-text-centered has-margin-bottom-4\">\n {loadError.message}\n </p>\n </section>\n )}\n\n <section>\n <form\n onSubmit={(event) => {\n event.preventDefault()\n handleSubmit()\n }}\n >\n <div className=\"ob-payment-form__westpac-quickstream-container\">\n {!!appImageUrl && (\n <figure className=\"image is-128x128 has-margin-bottom-6 ml-auto mr-auto\">\n <img\n alt=\"Application Icon\"\n className=\"is-rounded\"\n src={appImageUrl}\n />\n </figure>\n )}\n {!!title && (\n <h3 className=\"title is-3 is-size-3-mobile ob-header__heading has-text-centered\">\n {title}\n </h3>\n )}\n <label className=\"label ob-label has-text-centered\">\n Fill out the form below to complete your secure payment.\n </label>\n\n <div className=\"ob-payment-form__westpac-quickstream-amount\">\n <div>Amount</div>\n <div className=\"ob-payment-form__westpac-quickstream-amount-value\">\n {localisationService.formatCurrency(\n formSubmissionResult.payment?.amount ?? 0,\n )}\n </div>\n </div>\n <div\n data-quickstream-api=\"creditCardContainer\"\n className=\"quickstream-credit-card-container\"\n ></div>\n {!isLoading && !loadError && (\n <>\n <ReCAPTCHA\n {...recaptchaProps}\n className=\"ob-input cypress-captcha-control ob-payment-form__westpac-quickstream-captcha\"\n />\n {displayCaptchaRequired && (\n <FormElementValidationMessage\n message=\"Please complete the CAPTCHA successfully\"\n className=\"cypress-required\"\n />\n )}\n </>\n )}\n </div>\n {!isLoading && !loadError && (\n <div className=\"ob-payment-form__westpac-quickstream-form-actions\">\n <button\n type=\"button\"\n disabled={isCompletingTransaction || isCancellingTransaction}\n onClick={handleCancel}\n className={clsx('button ob-button is-outlined', {\n 'is-loading': isCancellingTransaction,\n })}\n >\n Cancel\n </button>\n <button\n type=\"submit\"\n disabled={isCompletingTransaction || isCancellingTransaction}\n className={clsx('button ob-button is-success', {\n 'is-loading': isCompletingTransaction,\n })}\n >\n Make Payment\n </button>\n </div>\n )}\n </form>\n </section>\n\n <Modal\n isOpen={!!completeTransactionError}\n title=\"Payment Issue\"\n className=\"cypress-payment-error-close-button\"\n actions={\n <>\n <button\n type=\"button\"\n className=\"button ob-button cypress-payment-error-close-button is-primary\"\n onClick={clearCompleteTransactionError}\n autoFocus\n >\n Okay\n </button>\n </>\n }\n >\n <>\n <div>\n {completeTransactionError instanceof Error\n ? completeTransactionError.message\n : completeTransactionError}\n </div>\n {completeTransactionError instanceof OneBlinkAppsError && (\n <OneBlinkAppsErrorOriginalMessage\n error={completeTransactionError.originalError}\n />\n )}\n </>\n </Modal>\n\n <Modal\n isOpen={!!cancelError}\n title=\"Cancel Issue\"\n className=\"cypress-cancel-error-close-button\"\n actions={\n <>\n <button\n type=\"button\"\n className=\"button ob-button cypress-cancel-error-close-button is-primary\"\n onClick={clearCancelError}\n autoFocus\n >\n Okay\n </button>\n </>\n }\n >\n <>\n <div>\n {cancelError instanceof Error ? cancelError.message : cancelError}\n </div>\n {cancelError instanceof OneBlinkAppsError && (\n <OneBlinkAppsErrorOriginalMessage\n error={cancelError.originalError}\n />\n )}\n </>\n </Modal>\n </>\n )\n}\n\nexport default React.memo(WestpacQuickStreamPaymentForm)\n"]}
1
+ {"version":3,"file":"WestpacQuickStreamPaymentForm.js","sourceRoot":"","sources":["../../../src/components/payments/WestpacQuickStreamPaymentForm.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,mBAAmB,GACpB,MAAM,YAAY,CAAA;AAGnB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,SAAS,MAAM,wBAAwB,CAAA;AAC9C,OAAO,KAAK,UAAU,MAAM,aAAa,CAAA;AACzC,OAAO,SAAS,MAAM,uBAAuB,CAAA;AAC7C,OAAO,gCAAgC,MAAM,8CAA8C,CAAA;AAC3F,OAAO,KAAK,MAAM,mBAAmB,CAAA;AACrC,OAAO,YAAY,MAAM,iBAAiB,CAAA;AAC1C,OAAO,iBAAiB,MAAM,+BAA+B,CAAA;AAE7D,OAAO,4BAA4B,MAAM,0CAA0C,CAAA;AA2CnF,SAAS,6BAA6B,CAAC,EACrC,OAAO,EACP,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,WAAW,EACX,WAAW,EACX,WAAW,EACX,WAAW,EACX,KAAK,GAeN;IACC,MAAM,CACJ,EACE,uBAAuB,EACvB,wBAAwB,EACxB,YAAY,EACZ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AI,CAAC,6BAA6B,CAAC,CAAA","sourcesContent":["import {\n OneBlinkAppsError,\n paymentService,\n localisationService,\n} from '../../apps'\nimport { SubmissionTypes } from '@oneblink/types'\nimport type { PaymentFormSession } from '../../apps/services/payment-handoff'\nimport clsx from 'clsx'\nimport React from 'react'\nimport ReCAPTCHA from 'react-google-recaptcha'\nimport * as bulmaToast from 'bulma-toast'\nimport OnLoading from '../renderer/OnLoading'\nimport OneBlinkAppsErrorOriginalMessage from '../renderer/OneBlinkAppsErrorOriginalMessage'\nimport Modal from '../renderer/Modal'\nimport MaterialIcon from '../MaterialIcon'\nimport useReCAPTCHAProps from '../../hooks/useReCAPTCHAProps'\nimport { CaptchaType } from '../../typedoc'\nimport FormElementValidationMessage from '../renderer/FormElementValidationMessage'\n\ninterface TrustedFrame {\n submitForm(\n callback: (\n errors:\n | Array<{\n fieldName: string\n messages: string[]\n }>\n | undefined,\n data: {\n singleUseToken: {\n singleUseTokenId: string\n }\n },\n ) => void,\n ): void\n}\n\ndeclare global {\n interface Window {\n QuickstreamAPI: {\n init(options: { publishableApiKey: string }): void\n creditCards: {\n createTrustedFrame(\n options: unknown,\n callback: (\n errors:\n | Array<{\n fieldName: string\n messages: string[]\n }>\n | undefined,\n data: {\n trustedFrame: TrustedFrame\n },\n ) => void,\n ): void\n }\n }\n }\n}\nfunction WestpacQuickStreamPaymentForm({\n session,\n supplierBusinessCode,\n publishableApiKey,\n isTestMode,\n captchaSiteKey,\n captchaType,\n onCompleted,\n onCancelled,\n appImageUrl,\n title,\n}: {\n session: PaymentFormSession\n supplierBusinessCode: string\n publishableApiKey: string\n isTestMode: boolean\n /** When provided, a CAPTCHA is required before the payment is completed */\n captchaSiteKey?: string\n captchaType?: CaptchaType\n onCompleted: (result: {\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment\n }) => void\n onCancelled: () => void\n appImageUrl?: string\n title?: string\n}) {\n const [\n {\n isCompletingTransaction,\n completeTransactionError,\n captchaToken,\n displayCaptchaRequired,\n },\n setCompleteTransactionState,\n ] = React.useState<{\n captchaToken: string | null\n displayCaptchaRequired: boolean\n isCompletingTransaction: boolean\n completeTransactionError: Error | null\n }>({\n isCompletingTransaction: false,\n completeTransactionError: null,\n captchaToken: null,\n displayCaptchaRequired: false,\n })\n\n const captchaRef = React.useRef<ReCAPTCHA>(null)\n\n const clearCompleteTransactionError = React.useCallback(() => {\n setCompleteTransactionState((currentState) => ({\n ...currentState,\n isCompletingTransaction: false,\n completeTransactionError: null,\n }))\n }, [])\n\n const [{ trustedFrame, isLoading, loadError }, setLoadState] =\n React.useState<{\n trustedFrame: TrustedFrame | null\n isLoading: boolean\n loadError: Error | null\n }>({\n trustedFrame: null,\n isLoading: true,\n loadError: null,\n })\n\n React.useEffect(() => {\n const abortController = new AbortController()\n const scriptEle = document.createElement('script')\n scriptEle.type = 'text/javascript'\n scriptEle.async = true\n\n const run = async () => {\n try {\n scriptEle.src = isTestMode\n ? 'https://api.quickstream.support.qvalent.com/rest/v1/quickstream-api-1.0.min.js'\n : 'https://api.quickstream.westpac.com.au/rest/v1/quickstream-api-1.0.min.js'\n\n await new Promise((resolve, reject) => {\n try {\n scriptEle.addEventListener(\n 'load',\n () => {\n resolve(undefined)\n },\n {\n signal: abortController.signal,\n },\n )\n\n scriptEle.addEventListener(\n 'error',\n () => {\n reject(new Error(`Failed to load the script ${scriptEle.src}`))\n },\n {\n signal: abortController.signal,\n },\n )\n\n document.body.appendChild(scriptEle)\n } catch (error) {\n console.warn('Failed to load script', error)\n reject(error)\n }\n })\n\n window.QuickstreamAPI.init({\n publishableApiKey,\n })\n const newTrustedFrame = await new Promise<TrustedFrame>(\n (resolve, reject) => {\n window.QuickstreamAPI.creditCards.createTrustedFrame(\n {\n config: {\n supplierBusinessCode,\n },\n iframe: {\n style: {\n width: '100%',\n },\n },\n showAcceptedCards: true,\n showRequiredIndicators: true,\n },\n (errors, data) => {\n if (errors) {\n reject(errors)\n return\n }\n resolve(data.trustedFrame)\n },\n )\n },\n )\n\n if (!abortController.signal.aborted) {\n setLoadState({\n trustedFrame: newTrustedFrame,\n isLoading: false,\n loadError: null,\n })\n }\n } catch (error) {\n if (!abortController.signal.aborted) {\n setLoadState({\n trustedFrame: null,\n isLoading: false,\n loadError: error as Error,\n })\n }\n }\n }\n\n run()\n\n return () => {\n abortController.abort()\n document.body.removeChild(scriptEle)\n }\n }, [isTestMode, publishableApiKey, supplierBusinessCode])\n\n const recaptchaType = React.useMemo(\n () => captchaType ?? 'CHECKBOX',\n [captchaType],\n )\n\n const hanedleCaptchaChange = React.useCallback((newValue: string | null) => {\n setCompleteTransactionState((currentState) => ({\n ...currentState,\n captchaToken: newValue,\n displayCaptchaRequired: newValue === null,\n }))\n }, [])\n\n const recaptchaProps = useReCAPTCHAProps({\n captchaSiteKey,\n captchaRef,\n onCaptchaChange: hanedleCaptchaChange,\n captchaType: recaptchaType,\n })\n\n const getRecaptchaToken = React.useCallback(async () => {\n captchaRef.current?.reset()\n switch (captchaType) {\n case 'INVISIBLE': {\n const token = await captchaRef.current\n ?.executeAsync()\n .catch((error) => {\n console.log('Invisible captcha executeAsync failure', error)\n return null\n })\n if (!token) {\n console.log('Captcha token failure')\n bulmaToast.toast({\n message: 'Failed to get a captcha token',\n type: 'is-danger',\n extraClasses: 'ob-toast cypress-failed-captcha-token-creation',\n duration: 4000,\n pauseOnHover: true,\n closeOnClick: true,\n })\n }\n return {\n recaptchaToken: token ?? null,\n displayCaptchaRequired: false,\n }\n }\n case 'CHECKBOX':\n default:\n return { recaptchaToken: captchaToken, displayCaptchaRequired: true }\n }\n }, [captchaToken, captchaType])\n\n const handleSubmit = React.useCallback(async () => {\n if (!trustedFrame) {\n return\n }\n\n setCompleteTransactionState((currentState) => ({\n ...currentState,\n isCompletingTransaction: true,\n completeTransactionError: null,\n }))\n\n trustedFrame.submitForm(async (errors, data) => {\n if (errors) {\n console.log('Invalid payment form submission', errors)\n setCompleteTransactionState((currentState) => ({\n ...currentState,\n isCompletingTransaction: false,\n completeTransactionError: null,\n }))\n return\n }\n\n let recaptcha: { siteKey: string; token: string } | undefined\n if (captchaSiteKey) {\n const { recaptchaToken, displayCaptchaRequired } =\n await getRecaptchaToken()\n\n if (!recaptchaToken) {\n setCompleteTransactionState({\n captchaToken: null,\n displayCaptchaRequired,\n isCompletingTransaction: false,\n completeTransactionError: null,\n })\n return\n }\n\n recaptcha = {\n siteKey: captchaSiteKey,\n token: recaptchaToken,\n }\n }\n\n paymentService.westpacQuickStream\n .completeTransaction({\n session,\n singleUseTokenId: data.singleUseToken.singleUseTokenId,\n recaptcha,\n })\n .then(onCompleted)\n .catch((error) => {\n setCompleteTransactionState((currentState) => ({\n ...currentState,\n isCompletingTransaction: false,\n completeTransactionError: error,\n }))\n })\n })\n }, [trustedFrame, getRecaptchaToken, session, captchaSiteKey, onCompleted])\n\n const [{ isCancellingTransaction, cancelError }, setCancelState] =\n React.useState<{\n isCancellingTransaction: boolean\n cancelError: Error | null\n }>({\n isCancellingTransaction: false,\n cancelError: null,\n })\n\n const clearCancelError = React.useCallback(() => {\n setCancelState({\n isCancellingTransaction: false,\n cancelError: null,\n })\n }, [])\n\n const handleCancel = React.useCallback(async () => {\n setCancelState({\n isCancellingTransaction: true,\n cancelError: null,\n })\n try {\n await paymentService.westpacQuickStream.cancelPayment({\n session,\n })\n onCancelled()\n } catch (error) {\n console.warn('Failed to cancel payment', error)\n setCancelState({\n isCancellingTransaction: false,\n cancelError: error as Error,\n })\n }\n }, [session, onCancelled])\n\n return (\n <>\n {isLoading && (\n <section>\n <div className=\"cypress-loading has-text-centered\">\n <OnLoading className=\"has-text-centered\"></OnLoading>\n <span>Building payment form...</span>\n </div>\n </section>\n )}\n\n {loadError && (\n <section className=\"cypress-payment-form-loading-error-message\">\n <div className=\"ob-payment-form__error-icon-container has-text-centered has-margin-bottom-8\">\n <MaterialIcon className=\"ob-payment-form__error-icon has-text-danger icon-x-large\">\n error\n </MaterialIcon>\n </div>\n <p className=\"ob-payment-form__error-message has-text-centered has-margin-bottom-4\">\n {loadError.message}\n </p>\n </section>\n )}\n\n <section>\n <form\n onSubmit={(event) => {\n event.preventDefault()\n handleSubmit()\n }}\n >\n <div className=\"ob-payment-form__westpac-quickstream-container\">\n {!!appImageUrl && (\n <figure className=\"image is-128x128 has-margin-bottom-6 ml-auto mr-auto\">\n <img\n alt=\"Application Icon\"\n className=\"is-rounded\"\n src={appImageUrl}\n />\n </figure>\n )}\n {!!title && (\n <h3 className=\"title is-3 is-size-3-mobile ob-header__heading has-text-centered\">\n {title}\n </h3>\n )}\n <label className=\"label ob-label has-text-centered\">\n Fill out the form below to complete your secure payment.\n </label>\n\n <div className=\"ob-payment-form__westpac-quickstream-amount\">\n <div>Amount</div>\n <div className=\"ob-payment-form__westpac-quickstream-amount-value\">\n {localisationService.formatCurrency(session.amount)}\n </div>\n </div>\n <div\n data-quickstream-api=\"creditCardContainer\"\n className=\"quickstream-credit-card-container\"\n ></div>\n {!isLoading && !loadError && captchaSiteKey && (\n <>\n <ReCAPTCHA\n {...recaptchaProps}\n className=\"ob-input cypress-captcha-control ob-payment-form__westpac-quickstream-captcha\"\n />\n {displayCaptchaRequired && (\n <FormElementValidationMessage\n message=\"Please complete the CAPTCHA successfully\"\n className=\"cypress-required\"\n />\n )}\n </>\n )}\n </div>\n {!isLoading && !loadError && (\n <div className=\"ob-payment-form__westpac-quickstream-form-actions\">\n <button\n type=\"button\"\n disabled={isCompletingTransaction || isCancellingTransaction}\n onClick={handleCancel}\n className={clsx('button ob-button is-outlined', {\n 'is-loading': isCancellingTransaction,\n })}\n >\n Cancel\n </button>\n <button\n type=\"submit\"\n disabled={isCompletingTransaction || isCancellingTransaction}\n className={clsx('button ob-button is-success', {\n 'is-loading': isCompletingTransaction,\n })}\n >\n Make Payment\n </button>\n </div>\n )}\n </form>\n </section>\n\n <Modal\n isOpen={!!completeTransactionError}\n title=\"Payment Issue\"\n className=\"cypress-payment-error-close-button\"\n actions={\n <>\n <button\n type=\"button\"\n className=\"button ob-button cypress-payment-error-close-button is-primary\"\n onClick={clearCompleteTransactionError}\n autoFocus\n >\n Okay\n </button>\n </>\n }\n >\n <>\n <div>\n {completeTransactionError instanceof Error\n ? completeTransactionError.message\n : completeTransactionError}\n </div>\n {completeTransactionError instanceof OneBlinkAppsError && (\n <OneBlinkAppsErrorOriginalMessage\n error={completeTransactionError.originalError}\n />\n )}\n </>\n </Modal>\n\n <Modal\n isOpen={!!cancelError}\n title=\"Cancel Issue\"\n className=\"cypress-cancel-error-close-button\"\n actions={\n <>\n <button\n type=\"button\"\n className=\"button ob-button cypress-cancel-error-close-button is-primary\"\n onClick={clearCancelError}\n autoFocus\n >\n Okay\n </button>\n </>\n }\n >\n <>\n <div>\n {cancelError instanceof Error ? cancelError.message : cancelError}\n </div>\n {cancelError instanceof OneBlinkAppsError && (\n <OneBlinkAppsErrorOriginalMessage\n error={cancelError.originalError}\n />\n )}\n </>\n </Modal>\n </>\n )\n}\n\nexport default React.memo(WestpacQuickStreamPaymentForm)\n"]}
@@ -2,6 +2,9 @@ export default function getApproverEditableFormElementIds(approvalSteps) {
2
2
  var _a;
3
3
  const editableFormElementIds = new Set();
4
4
  for (const step of approvalSteps !== null && approvalSteps !== void 0 ? approvalSteps : []) {
5
+ if (step.type === 'PAYMENT') {
6
+ continue;
7
+ }
5
8
  const nodes = step.type === 'CONCURRENT' ? step.nodes : [step];
6
9
  for (const node of nodes) {
7
10
  for (const formElementId of (_a = node.editableFormElementIds) !== null && _a !== void 0 ? _a : []) {
@@ -1 +1 @@
1
- {"version":3,"file":"getApproverEditableFormElementIds.js","sourceRoot":"","sources":["../../../src/services/form-validation/getApproverEditableFormElementIds.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,iCAAiC,CACvD,aAA+D;;IAE/D,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAU,CAAA;IAEhD,KAAK,MAAM,IAAI,IAAI,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,EAAE,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QAC9D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,KAAK,MAAM,aAAa,IAAI,MAAA,IAAI,CAAC,sBAAsB,mCAAI,EAAE,EAAE,CAAC;gBAC9D,sBAAsB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;YAC3C,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,sBAAsB,CAAC,CAAA;AACpC,CAAC","sourcesContent":["import { ApprovalTypes } from '@oneblink/types'\n\nexport default function getApproverEditableFormElementIds(\n approvalSteps: ApprovalTypes.FormApprovalFlowStep[] | undefined,\n): string[] {\n const editableFormElementIds = new Set<string>()\n\n for (const step of approvalSteps ?? []) {\n const nodes = step.type === 'CONCURRENT' ? step.nodes : [step]\n for (const node of nodes) {\n for (const formElementId of node.editableFormElementIds ?? []) {\n editableFormElementIds.add(formElementId)\n }\n }\n }\n\n return [...editableFormElementIds]\n}\n"]}
1
+ {"version":3,"file":"getApproverEditableFormElementIds.js","sourceRoot":"","sources":["../../../src/services/form-validation/getApproverEditableFormElementIds.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,iCAAiC,CACvD,aAA+D;;IAE/D,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAU,CAAA;IAEhD,KAAK,MAAM,IAAI,IAAI,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,EAAE,EAAE,CAAC;QACvC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC5B,SAAQ;QACV,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QAC9D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,KAAK,MAAM,aAAa,IAAI,MAAA,IAAI,CAAC,sBAAsB,mCAAI,EAAE,EAAE,CAAC;gBAC9D,sBAAsB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;YAC3C,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,sBAAsB,CAAC,CAAA;AACpC,CAAC","sourcesContent":["import { ApprovalTypes } from '@oneblink/types'\n\nexport default function getApproverEditableFormElementIds(\n approvalSteps: ApprovalTypes.FormApprovalFlowStep[] | undefined,\n): string[] {\n const editableFormElementIds = new Set<string>()\n\n for (const step of approvalSteps ?? []) {\n if (step.type === 'PAYMENT') {\n continue\n }\n const nodes = step.type === 'CONCURRENT' ? step.nodes : [step]\n for (const node of nodes) {\n for (const formElementId of node.editableFormElementIds ?? []) {\n editableFormElementIds.add(formElementId)\n }\n }\n }\n\n return [...editableFormElementIds]\n}\n"]}
@@ -104,6 +104,16 @@ function getFormApprovalFlowInstanceNodes(steps) {
104
104
  }
105
105
  break;
106
106
  }
107
+ case 'PAYMENT': {
108
+ memo.push({
109
+ ...step,
110
+ isPaymentStep: true,
111
+ isConcurrentWithPrevious: false,
112
+ isConcurrentWithNext: false,
113
+ parentStepLabelsId: step.label,
114
+ });
115
+ break;
116
+ }
107
117
  case 'STANDARD':
108
118
  default: {
109
119
  memo.push({
@@ -216,14 +226,23 @@ export function getFlowInstanceNodesWithMeta(formApprovalFlowInstance, formSubmi
216
226
  if ((status === null || status === void 0 ? void 0 : status.value) === 'CLARIFICATION_REQUIRED') {
217
227
  isClarificationRequired = true;
218
228
  }
229
+ const updatedByText = (associatedApproval === null || associatedApproval === void 0 ? void 0 : associatedApproval.updatedBy)
230
+ ? ` by ${associatedApproval.updatedBy}`
231
+ : '';
219
232
  let description = 'Awaiting previous approvals';
220
233
  if (step.isSkipped) {
221
234
  description = 'Skipped based on form submission';
222
235
  }
236
+ else if (step.isPaymentStep && (associatedApproval === null || associatedApproval === void 0 ? void 0 : associatedApproval.paymentSkipped)) {
237
+ description = `Payment skipped${updatedByText}`;
238
+ }
239
+ else if (step.isPaymentStep && (status === null || status === void 0 ? void 0 : status.value) === 'APPROVED') {
240
+ description = `Payment completed${updatedByText}`;
241
+ }
242
+ else if (step.isPaymentStep && (status === null || status === void 0 ? void 0 : status.value) === 'PENDING') {
243
+ description = 'Awaiting payment';
244
+ }
223
245
  else if (status) {
224
- const updatedByText = (associatedApproval === null || associatedApproval === void 0 ? void 0 : associatedApproval.updatedBy)
225
- ? ` by ${associatedApproval.updatedBy}`
226
- : '';
227
246
  description = `${status.label}${updatedByText}`;
228
247
  }
229
248
  else if (isAfterDeniedStep) {
@@ -1 +1 @@
1
- {"version":3,"file":"getFlowInstanceNodesWithMeta.js","sourceRoot":"","sources":["../../src/services/getFlowInstanceNodesWithMeta.ts"],"names":[],"mappings":"AAEA,MAAM,gBAAgB,GAAG;IACvB;QACE,KAAK,EAAE,mBAAmB;QAC1B,KAAK,EAAE,SAAS;KACjB;IACD;QACE,KAAK,EAAE,UAAU;QACjB,KAAK,EAAE,UAAU;KAClB;IACD;QACE,KAAK,EAAE,yBAAyB;QAChC,KAAK,EAAE,wBAAwB;KAChC;IACD;QACE,KAAK,EAAE,wBAAwB;QAC/B,KAAK,EAAE,wBAAwB;KAChC;IACD;QACE,KAAK,EAAE,QAAQ;QACf,KAAK,EAAE,QAAQ;KAChB;CACF,CAAA;AAED,MAAM,iBAAiB,GAEnB,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,QAAQ,EAAE,wBAAwB,CAAC,CAAC,CAAA;AAE7D,SAAS,gCAAgC,CACvC,gBAAmC,EACnC,uBAA+D;IAE/D,OAAO,uBAAuB,CAAC,MAAM,CAEnC,CAAC,iCAAiC,EAAE,sBAAsB,EAAE,EAAE;QAC9D,IACE,sBAAsB,CAAC,SAAS,KAAK,gBAAgB,CAAC,KAAK;YAC3D,CAAC,CAAC,iCAAiC;gBACjC,iCAAiC,CAAC,SAAS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;QAED,MAAM,iBAAiB,GAAG,QAAQ,CAAA;QAClC,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,MAAK,QAAQ,EAAE,CAAC;YAC/B,QAAQ,GAAG,IAAI,CAAA;QACjB,CAAC;QAED,MAAM,gCAAgC,GAAG,uBAAuB,CAAA;QAChE,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,MAAK,wBAAwB,EAAE,CAAC;YAC/C,uBAAuB,GAAG,IAAI,CAAA;QAChC,CAAC;QAED,IAAI,WAAW,GAAG,6BAA6B,CAAA;QAC/C,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,WAAW,GAAG,kCAAkC,CAAA;QAClD,CAAC;aAAM,IAAI,MAAM,EAAE,CAAC;YAClB,MAAM,aAAa,GAAG,CAAA,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,SAAS;gBACjD,CAAC,CAAC,OAAO,kBAAkB,CAAC,SAAS,EAAE;gBACvC,CAAC,CAAC,EAAE,CAAA;YACN,WAAW,GAAG,GAAG,MAAM,CAAC,KAAK,GAAG,aAAa,EAAE,CAAA;QACjD,CAAC;aAAM,IAAI,iBAAiB,EAAE,CAAC;YAC7B,WAAW,GAAG,2BAA2B,CAAA;QAC3C,CAAC;aAAM,IAAI,gCAAgC,EAAE,CAAC;YAC5C,WAAW,GAAG,2CAA2C,CAAA;QAC3D,CAAC;QAED,OAAO;YACL,GAAG,IAAI;YACP,MAAM;YACN,wBAAwB;YACxB,iBAAiB;YACjB,uCAAuC;YACvC,gCAAgC;YAChC,WAAW;SACZ,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,+BAA+B,CACpC,aAAa,EACb,uBAAuB,EACvB,wCAAwC,CACzC,CAAA;AACH,CAAC","sourcesContent":["import { ApprovalTypes } from '@oneblink/types'\n\nconst possibleStatuses = [\n {\n label: 'Awaiting Approval',\n value: 'PENDING',\n },\n {\n label: 'Approved',\n value: 'APPROVED',\n },\n {\n label: 'Clarification Requested',\n value: 'CLARIFICATION_REQUIRED',\n },\n {\n label: 'Clarification Received',\n value: 'CLARIFICATION_RECEIVED',\n },\n {\n label: 'Denied',\n value: 'CLOSED',\n },\n]\n\nconst ACTIONED_STATUSES: ReadonlySet<\n ApprovalTypes.FormSubmissionApproval['status']\n> = new Set(['APPROVED', 'CLOSED', 'CLARIFICATION_REQUIRED'])\n\nfunction findLatestFormSubmissionApproval(\n flowInstanceNode: { label: string },\n formSubmissionApprovals: ApprovalTypes.FormSubmissionApproval[],\n) {\n return formSubmissionApprovals.reduce<\n ApprovalTypes.FormSubmissionApproval | undefined\n >((lastUpdatedFormSubmissionApproval, formSubmissionApproval) => {\n if (\n formSubmissionApproval.stepLabel === flowInstanceNode.label &&\n (!lastUpdatedFormSubmissionApproval ||\n lastUpdatedFormSubmissionApproval.updatedAt <\n formSubmissionApproval.updatedAt)\n ) {\n return formSubmissionApproval\n }\n return lastUpdatedFormSubmissionApproval\n }, undefined)\n}\n\nfunction getConcurrentSortRank(\n node: ApprovalTypes.FlowInstanceNodeWithMeta,\n formSubmissionApprovals: ApprovalTypes.FormSubmissionApproval[],\n currentlyViewingFormSubmissionApprovalId: string | undefined,\n) {\n const approval = findLatestFormSubmissionApproval(\n node,\n formSubmissionApprovals,\n )\n if (approval && ACTIONED_STATUSES.has(approval.status)) {\n return 0\n }\n if (\n currentlyViewingFormSubmissionApprovalId &&\n approval?.id === currentlyViewingFormSubmissionApprovalId\n ) {\n return 1\n }\n return 2\n}\n\nfunction withUpdatedConcurrentFlags(\n nodes: ApprovalTypes.FlowInstanceNodeWithMeta[],\n) {\n return nodes.map((node, index) => ({\n ...node,\n isConcurrentWithPrevious: index !== 0,\n isConcurrentWithNext: index < nodes.length - 1,\n }))\n}\n\nfunction sortConcurrentGroup(\n nodes: ApprovalTypes.FlowInstanceNodeWithMeta[],\n formSubmissionApprovals: ApprovalTypes.FormSubmissionApproval[],\n currentlyViewingFormSubmissionApprovalId: string | undefined,\n) {\n const sorted = [...nodes].sort((left, right) => {\n const leftRank = getConcurrentSortRank(\n left,\n formSubmissionApprovals,\n currentlyViewingFormSubmissionApprovalId,\n )\n const rightRank = getConcurrentSortRank(\n right,\n formSubmissionApprovals,\n currentlyViewingFormSubmissionApprovalId,\n )\n if (leftRank !== rightRank) {\n return leftRank - rightRank\n }\n if (leftRank === 0) {\n const leftUpdatedAt =\n findLatestFormSubmissionApproval(left, formSubmissionApprovals)\n ?.updatedAt ?? ''\n const rightUpdatedAt =\n findLatestFormSubmissionApproval(right, formSubmissionApprovals)\n ?.updatedAt ?? ''\n return leftUpdatedAt.localeCompare(rightUpdatedAt)\n }\n return 0\n })\n return withUpdatedConcurrentFlags(sorted)\n}\n\nfunction sortConcurrentFlowInstanceNodes(\n nodes: ApprovalTypes.FlowInstanceNodeWithMeta[],\n formSubmissionApprovals: ApprovalTypes.FormSubmissionApproval[],\n currentlyViewingFormSubmissionApprovalId: string | undefined,\n) {\n const groups: ApprovalTypes.FlowInstanceNodeWithMeta[][] = []\n for (const node of nodes) {\n const currentGroup = groups[groups.length - 1]\n if (\n currentGroup &&\n currentGroup[0].parentStepLabelsId === node.parentStepLabelsId\n ) {\n currentGroup.push(node)\n } else {\n groups.push([node])\n }\n }\n\n return groups.flatMap((group) => {\n if (group.length < 2) {\n return group\n }\n return sortConcurrentGroup(\n group,\n formSubmissionApprovals,\n currentlyViewingFormSubmissionApprovalId,\n )\n })\n}\n\nfunction getFormApprovalFlowInstanceNodes(\n steps: ApprovalTypes.FormApprovalFlowInstanceStep[],\n) {\n return steps.reduce<\n Array<\n ApprovalTypes.FormApprovalFlowInstanceNode &\n Pick<\n ApprovalTypes.FlowInstanceNodeMeta,\n | 'parentStepLabelsId'\n | 'isConcurrentWithPrevious'\n | 'isConcurrentWithNext'\n >\n >\n >((memo, step) => {\n switch (step.type) {\n case 'CONCURRENT': {\n const parentStepLabelsId = step.nodes\n .map(({ label }) => label)\n .join('_')\n for (const node of step.nodes) {\n const index = step.nodes.indexOf(node)\n memo.push({\n ...node,\n parentStepLabelsId,\n isConcurrentWithPrevious: index !== 0,\n isConcurrentWithNext: index < step.nodes.length - 1,\n })\n }\n break\n }\n case 'STANDARD':\n default: {\n memo.push({\n ...step,\n isConcurrentWithPrevious: false,\n isConcurrentWithNext: false,\n parentStepLabelsId: step.label,\n })\n break\n }\n }\n return memo\n }, [])\n}\n\n/**\n * Inputs a form approval flow instance and set of form submission approvals and\n * returns a flattened array of nodes/steps with inlcuded metadata.\n *\n * #### Example\n *\n * ```js\n * const formApprovalFlowInstance = {\n * steps: [\n * {\n * type: 'STANDARD',\n * group: 'oneblink:administrator',\n * isSkipped: false,\n * label: 'Manager Approval',\n * approvalFormId: '1234',\n * },\n * {\n * type: 'CONCURRENT',\n * nodes: [\n * {\n * label: 'HR Review',\n * group: 'oneblink:administrator',\n * isSkipped: false,\n * approvalFormId: '1234',\n * },\n * {\n * label: 'Finance Review',\n * group: 'oneblink:administrator',\n * isSkipped: false,\n * approvalFormId: '1234',\n * },\n * ],\n * },\n * ],\n * }\n *\n * const formSubmissionApprovals = [\n * {\n * id: 'approval1',\n * stepLabel: 'Manager Approval',\n * status: 'APPROVED',\n * createdAt: '2024-03-20T10:00:00Z',\n * updatedAt: '2024-03-20T10:00:00Z',\n * updatedBy: 'fake@fake.com',\n * group: 'oneblink:administrator',\n * approvalFormId: '1234',\n * },\n * ]\n *\n * const nodesWithMeta = getFlowInstanceNodesWithMeta(\n * formApprovalFlowInstance,\n * formSubmissionApprovals,\n * )\n * ```\n *\n * Concurrent nodes are ordered as actioned (by the time they were actioned),\n * then the currently viewed pending approval if\n * `currentlyViewingFormSubmissionApprovalId` is provided, then remaining\n * unactioned nodes in definition order. Sequential steps around a concurrent\n * group are not reordered.\n *\n * @param formApprovalFlowInstance\n * @param formSubmissionApprovals\n * @param currentlyViewingFormSubmissionApprovalId The id of the approval\n * currently being viewed, used to keep that pending concurrent step next to\n * already actioned siblings.\n * @returns ApprovalTypes.FlowInstanceNodeWithMeta[]\n */\nexport function getFlowInstanceNodesWithMeta(\n formApprovalFlowInstance: ApprovalTypes.FormApprovalFlowInstance,\n formSubmissionApprovals: ApprovalTypes.FormSubmissionApproval[],\n currentlyViewingFormSubmissionApprovalId?: string,\n): ApprovalTypes.FlowInstanceNodeWithMeta[] {\n const formApprovalFlowInstanceNodes = getFormApprovalFlowInstanceNodes(\n formApprovalFlowInstance.steps,\n )\n let isDenied = false\n let isClarificationRequired = false\n const nodesWithMeta = formApprovalFlowInstanceNodes.map((step) => {\n const associatedApproval = findLatestFormSubmissionApproval(\n step,\n formSubmissionApprovals,\n )\n const status = possibleStatuses.find(\n ({ value }) => value === associatedApproval?.status,\n )\n\n let isDeniedInConcurrentStep = false\n let isClarificationRequiredInConcurrentStep = false\n if (status?.value === 'PENDING') {\n const siblingNodes = formApprovalFlowInstanceNodes.filter(\n ({ parentStepLabelsId, label }) =>\n parentStepLabelsId === step.parentStepLabelsId &&\n label !== step.label,\n )\n for (const siblingNode of siblingNodes) {\n const formSubmissionApproval = findLatestFormSubmissionApproval(\n siblingNode,\n formSubmissionApprovals,\n )\n if (formSubmissionApproval?.status === 'CLOSED') {\n isDeniedInConcurrentStep = true\n }\n if (formSubmissionApproval?.status === 'CLARIFICATION_REQUIRED') {\n isClarificationRequiredInConcurrentStep = true\n }\n }\n }\n\n const isAfterDeniedStep = isDenied\n if (status?.value === 'CLOSED') {\n isDenied = true\n }\n\n const isAfterClarificationRequiredStep = isClarificationRequired\n if (status?.value === 'CLARIFICATION_REQUIRED') {\n isClarificationRequired = true\n }\n\n let description = 'Awaiting previous approvals'\n if (step.isSkipped) {\n description = 'Skipped based on form submission'\n } else if (status) {\n const updatedByText = associatedApproval?.updatedBy\n ? ` by ${associatedApproval.updatedBy}`\n : ''\n description = `${status.label}${updatedByText}`\n } else if (isAfterDeniedStep) {\n description = 'Denied in a previous step'\n } else if (isAfterClarificationRequiredStep) {\n description = 'Sent for clarification in a previous step'\n }\n\n return {\n ...step,\n status,\n isDeniedInConcurrentStep,\n isAfterDeniedStep,\n isClarificationRequiredInConcurrentStep,\n isAfterClarificationRequiredStep,\n description,\n }\n })\n\n return sortConcurrentFlowInstanceNodes(\n nodesWithMeta,\n formSubmissionApprovals,\n currentlyViewingFormSubmissionApprovalId,\n )\n}\n"]}
1
+ {"version":3,"file":"getFlowInstanceNodesWithMeta.js","sourceRoot":"","sources":["../../src/services/getFlowInstanceNodesWithMeta.ts"],"names":[],"mappings":"AAEA,MAAM,gBAAgB,GAAG;IACvB;QACE,KAAK,EAAE,mBAAmB;QAC1B,KAAK,EAAE,SAAS;KACjB;IACD;QACE,KAAK,EAAE,UAAU;QACjB,KAAK,EAAE,UAAU;KAClB;IACD;QACE,KAAK,EAAE,yBAAyB;QAChC,KAAK,EAAE,wBAAwB;KAChC;IACD;QACE,KAAK,EAAE,wBAAwB;QAC/B,KAAK,EAAE,wBAAwB;KAChC;IACD;QACE,KAAK,EAAE,QAAQ;QACf,KAAK,EAAE,QAAQ;KAChB;CACF,CAAA;AAED,MAAM,iBAAiB,GAEnB,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,QAAQ,EAAE,wBAAwB,CAAC,CAAC,CAAA;AAE7D,SAAS,gCAAgC,CACvC,gBAAmC,EACnC,uBAA+D;IAE/D,OAAO,uBAAuB,CAAC,MAAM,CAEnC,CAAC,iCAAiC,EAAE,sBAAsB,EAAE,EAAE;QAC9D,IACE,sBAAsB,CAAC,SAAS,KAAK,gBAAgB,CAAC,KAAK;YAC3D,CAAC,CAAC,iCAAiC;gBACjC,iCAAiC,CAAC,SAAS;oBACzC,sBAAsB,CAAC,SAAS,CAAC,EACrC,CAAC;YACD,OAAO,sBAAsB,CAAA;QAC/B,CAAC;QACD,OAAO,iCAAiC,CAAA;IAC1C,CAAC,EAAE,SAAS,CAAC,CAAA;AACf,CAAC;AAED,SAAS,qBAAqB,CAC5B,IAA4C,EAC5C,uBAA+D,EAC/D,wCAA4D;IAE5D,MAAM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CAAC;aAAM,IAAI,iBAAiB,EAAE,CAAC;YAC7B,WAAW,GAAG,2BAA2B,CAAA;QAC3C,CAAC;aAAM,IAAI,gCAAgC,EAAE,CAAC;YAC5C,WAAW,GAAG,2CAA2C,CAAA;QAC3D,CAAC;QAED,OAAO;YACL,GAAG,IAAI;YACP,MAAM;YACN,wBAAwB;YACxB,iBAAiB;YACjB,uCAAuC;YACvC,gCAAgC;YAChC,WAAW;SACZ,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,+BAA+B,CACpC,aAAa,EACb,uBAAuB,EACvB,wCAAwC,CACzC,CAAA;AACH,CAAC","sourcesContent":["import { ApprovalTypes } from '@oneblink/types'\n\nconst possibleStatuses = [\n {\n label: 'Awaiting Approval',\n value: 'PENDING',\n },\n {\n label: 'Approved',\n value: 'APPROVED',\n },\n {\n label: 'Clarification Requested',\n value: 'CLARIFICATION_REQUIRED',\n },\n {\n label: 'Clarification Received',\n value: 'CLARIFICATION_RECEIVED',\n },\n {\n label: 'Denied',\n value: 'CLOSED',\n },\n]\n\nconst ACTIONED_STATUSES: ReadonlySet<\n ApprovalTypes.FormSubmissionApproval['status']\n> = new Set(['APPROVED', 'CLOSED', 'CLARIFICATION_REQUIRED'])\n\nfunction findLatestFormSubmissionApproval(\n flowInstanceNode: { label: string },\n formSubmissionApprovals: ApprovalTypes.FormSubmissionApproval[],\n) {\n return formSubmissionApprovals.reduce<\n ApprovalTypes.FormSubmissionApproval | undefined\n >((lastUpdatedFormSubmissionApproval, formSubmissionApproval) => {\n if (\n formSubmissionApproval.stepLabel === flowInstanceNode.label &&\n (!lastUpdatedFormSubmissionApproval ||\n lastUpdatedFormSubmissionApproval.updatedAt <\n formSubmissionApproval.updatedAt)\n ) {\n return formSubmissionApproval\n }\n return lastUpdatedFormSubmissionApproval\n }, undefined)\n}\n\nfunction getConcurrentSortRank(\n node: ApprovalTypes.FlowInstanceNodeWithMeta,\n formSubmissionApprovals: ApprovalTypes.FormSubmissionApproval[],\n currentlyViewingFormSubmissionApprovalId: string | undefined,\n) {\n const approval = findLatestFormSubmissionApproval(\n node,\n formSubmissionApprovals,\n )\n if (approval && ACTIONED_STATUSES.has(approval.status)) {\n return 0\n }\n if (\n currentlyViewingFormSubmissionApprovalId &&\n approval?.id === currentlyViewingFormSubmissionApprovalId\n ) {\n return 1\n }\n return 2\n}\n\nfunction withUpdatedConcurrentFlags(\n nodes: ApprovalTypes.FlowInstanceNodeWithMeta[],\n) {\n return nodes.map((node, index) => ({\n ...node,\n isConcurrentWithPrevious: index !== 0,\n isConcurrentWithNext: index < nodes.length - 1,\n }))\n}\n\nfunction sortConcurrentGroup(\n nodes: ApprovalTypes.FlowInstanceNodeWithMeta[],\n formSubmissionApprovals: ApprovalTypes.FormSubmissionApproval[],\n currentlyViewingFormSubmissionApprovalId: string | undefined,\n) {\n const sorted = [...nodes].sort((left, right) => {\n const leftRank = getConcurrentSortRank(\n left,\n formSubmissionApprovals,\n currentlyViewingFormSubmissionApprovalId,\n )\n const rightRank = getConcurrentSortRank(\n right,\n formSubmissionApprovals,\n currentlyViewingFormSubmissionApprovalId,\n )\n if (leftRank !== rightRank) {\n return leftRank - rightRank\n }\n if (leftRank === 0) {\n const leftUpdatedAt =\n findLatestFormSubmissionApproval(left, formSubmissionApprovals)\n ?.updatedAt ?? ''\n const rightUpdatedAt =\n findLatestFormSubmissionApproval(right, formSubmissionApprovals)\n ?.updatedAt ?? ''\n return leftUpdatedAt.localeCompare(rightUpdatedAt)\n }\n return 0\n })\n return withUpdatedConcurrentFlags(sorted)\n}\n\nfunction sortConcurrentFlowInstanceNodes(\n nodes: ApprovalTypes.FlowInstanceNodeWithMeta[],\n formSubmissionApprovals: ApprovalTypes.FormSubmissionApproval[],\n currentlyViewingFormSubmissionApprovalId: string | undefined,\n) {\n const groups: ApprovalTypes.FlowInstanceNodeWithMeta[][] = []\n for (const node of nodes) {\n const currentGroup = groups[groups.length - 1]\n if (\n currentGroup &&\n currentGroup[0].parentStepLabelsId === node.parentStepLabelsId\n ) {\n currentGroup.push(node)\n } else {\n groups.push([node])\n }\n }\n\n return groups.flatMap((group) => {\n if (group.length < 2) {\n return group\n }\n return sortConcurrentGroup(\n group,\n formSubmissionApprovals,\n currentlyViewingFormSubmissionApprovalId,\n )\n })\n}\n\nfunction getFormApprovalFlowInstanceNodes(\n steps: ApprovalTypes.FormApprovalFlowInstanceStep[],\n) {\n return steps.reduce<\n Array<\n ApprovalTypes.FormApprovalFlowInstanceNode &\n Pick<\n ApprovalTypes.FlowInstanceNodeMeta,\n | 'parentStepLabelsId'\n | 'isConcurrentWithPrevious'\n | 'isConcurrentWithNext'\n | 'isPaymentStep'\n >\n >\n >((memo, step) => {\n switch (step.type) {\n case 'CONCURRENT': {\n const parentStepLabelsId = step.nodes\n .map(({ label }) => label)\n .join('_')\n for (const node of step.nodes) {\n const index = step.nodes.indexOf(node)\n memo.push({\n ...node,\n parentStepLabelsId,\n isConcurrentWithPrevious: index !== 0,\n isConcurrentWithNext: index < step.nodes.length - 1,\n })\n }\n break\n }\n case 'PAYMENT': {\n memo.push({\n ...step,\n isPaymentStep: true,\n isConcurrentWithPrevious: false,\n isConcurrentWithNext: false,\n parentStepLabelsId: step.label,\n })\n break\n }\n case 'STANDARD':\n default: {\n memo.push({\n ...step,\n isConcurrentWithPrevious: false,\n isConcurrentWithNext: false,\n parentStepLabelsId: step.label,\n })\n break\n }\n }\n return memo\n }, [])\n}\n\n/**\n * Inputs a form approval flow instance and set of form submission approvals and\n * returns a flattened array of nodes/steps with inlcuded metadata.\n *\n * #### Example\n *\n * ```js\n * const formApprovalFlowInstance = {\n * steps: [\n * {\n * type: 'STANDARD',\n * group: 'oneblink:administrator',\n * isSkipped: false,\n * label: 'Manager Approval',\n * approvalFormId: '1234',\n * },\n * {\n * type: 'CONCURRENT',\n * nodes: [\n * {\n * label: 'HR Review',\n * group: 'oneblink:administrator',\n * isSkipped: false,\n * approvalFormId: '1234',\n * },\n * {\n * label: 'Finance Review',\n * group: 'oneblink:administrator',\n * isSkipped: false,\n * approvalFormId: '1234',\n * },\n * ],\n * },\n * ],\n * }\n *\n * const formSubmissionApprovals = [\n * {\n * id: 'approval1',\n * stepLabel: 'Manager Approval',\n * status: 'APPROVED',\n * createdAt: '2024-03-20T10:00:00Z',\n * updatedAt: '2024-03-20T10:00:00Z',\n * updatedBy: 'fake@fake.com',\n * group: 'oneblink:administrator',\n * approvalFormId: '1234',\n * },\n * ]\n *\n * const nodesWithMeta = getFlowInstanceNodesWithMeta(\n * formApprovalFlowInstance,\n * formSubmissionApprovals,\n * )\n * ```\n *\n * Concurrent nodes are ordered as actioned (by the time they were actioned),\n * then the currently viewed pending approval if\n * `currentlyViewingFormSubmissionApprovalId` is provided, then remaining\n * unactioned nodes in definition order. Sequential steps around a concurrent\n * group are not reordered.\n *\n * @param formApprovalFlowInstance\n * @param formSubmissionApprovals\n * @param currentlyViewingFormSubmissionApprovalId The id of the approval\n * currently being viewed, used to keep that pending concurrent step next to\n * already actioned siblings.\n * @returns ApprovalTypes.FlowInstanceNodeWithMeta[]\n */\nexport function getFlowInstanceNodesWithMeta(\n formApprovalFlowInstance: ApprovalTypes.FormApprovalFlowInstance,\n formSubmissionApprovals: ApprovalTypes.FormSubmissionApproval[],\n currentlyViewingFormSubmissionApprovalId?: string,\n): ApprovalTypes.FlowInstanceNodeWithMeta[] {\n const formApprovalFlowInstanceNodes = getFormApprovalFlowInstanceNodes(\n formApprovalFlowInstance.steps,\n )\n let isDenied = false\n let isClarificationRequired = false\n const nodesWithMeta = formApprovalFlowInstanceNodes.map((step) => {\n const associatedApproval = findLatestFormSubmissionApproval(\n step,\n formSubmissionApprovals,\n )\n const status = possibleStatuses.find(\n ({ value }) => value === associatedApproval?.status,\n )\n\n let isDeniedInConcurrentStep = false\n let isClarificationRequiredInConcurrentStep = false\n if (status?.value === 'PENDING') {\n const siblingNodes = formApprovalFlowInstanceNodes.filter(\n ({ parentStepLabelsId, label }) =>\n parentStepLabelsId === step.parentStepLabelsId &&\n label !== step.label,\n )\n for (const siblingNode of siblingNodes) {\n const formSubmissionApproval = findLatestFormSubmissionApproval(\n siblingNode,\n formSubmissionApprovals,\n )\n if (formSubmissionApproval?.status === 'CLOSED') {\n isDeniedInConcurrentStep = true\n }\n if (formSubmissionApproval?.status === 'CLARIFICATION_REQUIRED') {\n isClarificationRequiredInConcurrentStep = true\n }\n }\n }\n\n const isAfterDeniedStep = isDenied\n if (status?.value === 'CLOSED') {\n isDenied = true\n }\n\n const isAfterClarificationRequiredStep = isClarificationRequired\n if (status?.value === 'CLARIFICATION_REQUIRED') {\n isClarificationRequired = true\n }\n\n const updatedByText = associatedApproval?.updatedBy\n ? ` by ${associatedApproval.updatedBy}`\n : ''\n let description = 'Awaiting previous approvals'\n if (step.isSkipped) {\n description = 'Skipped based on form submission'\n } else if (step.isPaymentStep && associatedApproval?.paymentSkipped) {\n description = `Payment skipped${updatedByText}`\n } else if (step.isPaymentStep && status?.value === 'APPROVED') {\n description = `Payment completed${updatedByText}`\n } else if (step.isPaymentStep && status?.value === 'PENDING') {\n description = 'Awaiting payment'\n } else if (status) {\n description = `${status.label}${updatedByText}`\n } else if (isAfterDeniedStep) {\n description = 'Denied in a previous step'\n } else if (isAfterClarificationRequiredStep) {\n description = 'Sent for clarification in a previous step'\n }\n\n return {\n ...step,\n status,\n isDeniedInConcurrentStep,\n isAfterDeniedStep,\n isClarificationRequiredInConcurrentStep,\n isAfterClarificationRequiredStep,\n description,\n }\n })\n\n return sortConcurrentFlowInstanceNodes(\n nodesWithMeta,\n formSubmissionApprovals,\n currentlyViewingFormSubmissionApprovalId,\n )\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oneblink/apps-react",
3
3
  "description": "Helper functions for OneBlink apps in ReactJS.",
4
- "version": "13.5.1-beta.4",
4
+ "version": "14.0.0-beta.1",
5
5
  "author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/oneblink/apps-react/issues"