@oneblink/apps-react 13.7.0 → 13.8.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.
@@ -8,6 +8,8 @@ export type FormSubmissionApprovalsResponse = {
8
8
  latestSuccessfulFormSubmissionPayment: SubmissionTypes.FormSubmissionPayment | undefined;
9
9
  /** True while this approval has a checkout that has not finished. */
10
10
  paymentInProgress?: boolean;
11
+ /** True when a payment request has been sent for this step. */
12
+ paymentRequested?: boolean;
11
13
  }>;
12
14
  };
13
15
  export type FormApprovalFlowInstanceHistory = {
@@ -17,6 +19,7 @@ export type FormApprovalFlowInstanceHistory = {
17
19
  formSubmissionApprovals: ApprovalTypes.FormSubmissionApproval[];
18
20
  successfulFormSubmissionPayment?: SubmissionTypes.FormSubmissionPayment;
19
21
  approvalStepPayments?: SubmissionTypes.FormSubmissionPayment[];
22
+ paymentRequests?: SubmissionTypes.FormSubmissionPaymentRequest[];
20
23
  };
21
24
  export type FormSubmissionApprovalResponse = {
22
25
  formSubmissionMeta: SubmissionTypes.FormSubmissionMeta;
@@ -161,6 +164,36 @@ export declare function createApprovalStepPayment(formSubmissionApprovalId: stri
161
164
  paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent;
162
165
  customerReferenceNumber?: string;
163
166
  }>;
167
+ /**
168
+ * Email a recipient a link to review the submission and pay this approval step.
169
+ *
170
+ * #### Example
171
+ *
172
+ * ```js
173
+ * const { paymentRequests } =
174
+ * await approvalsService.requestApprovalStepPayment(
175
+ * 'd27966cc-128d-48a2-b681-6ad52012e113',
176
+ * {
177
+ * delivery: {
178
+ * method: 'EMAIL',
179
+ * email: 'payer@example.com',
180
+ * name: 'Alex',
181
+ * },
182
+ * },
183
+ * )
184
+ * ```
185
+ *
186
+ * @param formSubmissionApprovalId
187
+ * @param options
188
+ * @param options.delivery How to send the request. Only email is supported.
189
+ * @param abortSignal
190
+ * @returns The payment requests sent for this step. Tokens are not included.
191
+ */
192
+ export declare function requestApprovalStepPayment(formSubmissionApprovalId: string, options: {
193
+ delivery: SubmissionTypes.FormSubmissionPaymentRequestDelivery;
194
+ }, abortSignal?: AbortSignal): Promise<{
195
+ paymentRequests: SubmissionTypes.FormSubmissionPaymentRequest[];
196
+ }>;
164
197
  /**
165
198
  * Skip the payment for an approval step and continue the approval flow.
166
199
  *
@@ -254,6 +254,34 @@ export async function createApprovalStepPayment(formSubmissionApprovalId, option
254
254
  });
255
255
  return result;
256
256
  }
257
+ /**
258
+ * Email a recipient a link to review the submission and pay this approval step.
259
+ *
260
+ * #### Example
261
+ *
262
+ * ```js
263
+ * const { paymentRequests } =
264
+ * await approvalsService.requestApprovalStepPayment(
265
+ * 'd27966cc-128d-48a2-b681-6ad52012e113',
266
+ * {
267
+ * delivery: {
268
+ * method: 'EMAIL',
269
+ * email: 'payer@example.com',
270
+ * name: 'Alex',
271
+ * },
272
+ * },
273
+ * )
274
+ * ```
275
+ *
276
+ * @param formSubmissionApprovalId
277
+ * @param options
278
+ * @param options.delivery How to send the request. Only email is supported.
279
+ * @param abortSignal
280
+ * @returns The payment requests sent for this step. Tokens are not included.
281
+ */
282
+ export async function requestApprovalStepPayment(formSubmissionApprovalId, options, abortSignal) {
283
+ return await postRequest(`${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/payment-requests`, options, abortSignal);
284
+ }
257
285
  /**
258
286
  * Skip the payment for an approval step and continue the approval flow.
259
287
  *
@@ -1 +1 @@
1
- {"version":3,"file":"approvals-service.js","sourceRoot":"","sources":["../../src/apps/approvals-service.ts"],"names":[],"mappings":"AAMA,OAAO,iBAAiB,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,EACL,aAAa,EACb,UAAU,EACV,UAAU,EACV,aAAa,EACb,WAAW,EACX,SAAS,GACV,MAAM,kBAAkB,CAAA;AACzB,OAAO,OAAO,MAAM,WAAW,CAAA;AAC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AAK,GAAG,CAAC;YACT,KAAK,GAAG,CAAC,CAAC,CAAC;gBACT,MAAM,IAAI,iBAAiB,CAAC,KAAK,CAAC,OAAO,EAAE;oBACzC,KAAK,EAAE,iBAAiB;oBACxB,cAAc,EAAE,KAAK,CAAC,MAAM;iBAC7B,CAAC,CAAA;YACJ,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,IAAI,iBAAiB,CACzB,gFAAgF,EAChF;oBACE,aAAa,EAAE,KAAK;oBACpB,cAAc,EAAE,KAAK,CAAC,MAAM;iBAC7B,CACF,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import {\n SubmissionTypes,\n ApprovalTypes,\n FormTypes,\n SubmissionEventTypes,\n} from '@oneblink/types'\nimport OneBlinkAppsError from './services/errors/oneBlinkAppsError'\nimport { isOffline, OFFLINE_ERROR_MESSAGE } from './offline-service'\nimport {\n deleteRequest,\n getRequest,\n putRequest,\n searchRequest,\n postRequest,\n HTTPError,\n} from './services/fetch'\nimport tenants from './tenants'\nimport Sentry from './Sentry'\nimport { rememberPaymentSubmissionResult } from './services/payment-submission-result'\nexport { getFlowInstanceNodesWithMeta } from '../services/getFlowInstanceNodesWithMeta'\n\nexport type FormSubmissionApprovalsResponse = {\n approvals: Array<{\n formSubmissionApproval: ApprovalTypes.FormSubmissionApproval\n formApprovalFlowInstance: ApprovalTypes.FormApprovalFlowInstance\n formSubmissionMeta: SubmissionTypes.FormSubmissionMeta\n latestSuccessfulFormSubmissionPayment:\n | SubmissionTypes.FormSubmissionPayment\n | undefined\n /** True while this approval has a checkout that has not finished. */\n paymentInProgress?: boolean\n }>\n}\n\nexport type FormApprovalFlowInstanceHistory = {\n formApprovalFlowInstance: ApprovalTypes.FormApprovalFlowInstance\n formSubmissionMeta: SubmissionTypes.FormSubmissionMeta\n formSubmissionMetaEdits: SubmissionTypes.FormSubmissionMetaEdit[]\n formSubmissionApprovals: ApprovalTypes.FormSubmissionApproval[]\n successfulFormSubmissionPayment?: SubmissionTypes.FormSubmissionPayment\n approvalStepPayments?: SubmissionTypes.FormSubmissionPayment[]\n}\n\nexport type FormSubmissionApprovalResponse = {\n formSubmissionMeta: SubmissionTypes.FormSubmissionMeta\n formApprovalFlowInstance: ApprovalTypes.FormApprovalFlowInstance\n formSubmissionApproval: ApprovalTypes.FormSubmissionApproval\n form: FormTypes.Form\n successfulFormSubmissionPayment?: SubmissionTypes.FormSubmissionPayment\n history: FormApprovalFlowInstanceHistory[]\n}\n\nexport type FormSubmissionsAdministrationApprovalsResponse = {\n approvals: Array<\n FormApprovalFlowInstanceHistory & {\n history: Array<FormApprovalFlowInstanceHistory>\n }\n >\n meta: {\n limit: number\n offset: number\n nextOffset?: number\n }\n}\n\n/**\n * Get an Object containing FormSubmissionApprovals assigned to the current user\n * and the Form definitions in those approvals.\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const {\n * formSubmissionApprovals,\n * formApprovalFlowInstances,\n * forms,\n * formSubmissionMeta,\n * } = await approvalsService.getFormSubmissionApprovals(formAppId)\n * ```\n *\n * @param formsAppId\n * @param abortSignal\n * @returns\n */\nexport async function getFormSubmissionApprovals(\n formsAppId: number,\n abortSignal?: AbortSignal,\n): Promise<FormSubmissionApprovalsResponse> {\n try {\n return await getRequest<FormSubmissionApprovalsResponse>(\n `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/my-approvals`,\n abortSignal,\n )\n } catch (err) {\n Sentry.captureException(err)\n console.error('Error retrieving form submission approvals', err)\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline and do not have a local copy of this app available, please connect to the internet and try again',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot view your pending approvals without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Get a single FormSubmissionApproval belonging to the given id.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionApprovalId = 'd27966cc-128d-48a2-b681-6ad52012e113'\n * const {\n * formSubmissionApproval,\n * formApprovalFlowInstance,\n * formSubmissionMeta,\n * form,\n * history,\n * } = await approvalsService.getFormSubmissionApproval(\n * formSubmissionApprovalId,\n * )\n * ```\n *\n * @param formSubmissionApprovalId\n * @param abortSignal\n * @returns\n */\nexport async function getFormSubmissionApproval(\n formSubmissionApprovalId: string,\n abortSignal?: AbortSignal,\n): Promise<FormSubmissionApprovalResponse> {\n try {\n const result = await getRequest<FormSubmissionApprovalResponse>(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}`,\n abortSignal,\n )\n return result\n } catch (err) {\n Sentry.captureException(err)\n console.error('Error retrieving form submission approval', err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline and do not have a local copy of this app available, please connect to the internet and try again',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot action this pending submission without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Conflict code on the error thrown when an approval step already has a\n * checkout in progress.\n *\n * #### Example\n *\n * ```js\n * import {\n * approvalsService,\n * OneBlinkAppsError,\n * } from '@oneblink/apps-react'\n *\n * try {\n * await approvalsService.createApprovalStepPayment(\n * formSubmissionApprovalId,\n * {\n * redirectUrl,\n * paymentFormUrl,\n * form,\n * submissionId,\n * },\n * )\n * } catch (error) {\n * if (\n * error instanceof OneBlinkAppsError &&\n * error.conflict === approvalsService.PAYMENT_IN_PROGRESS_CONFLICT\n * ) {\n * console.log('A payment is already in progress')\n * }\n * }\n * ```\n */\nexport const PAYMENT_IN_PROGRESS_CONFLICT = 'PAYMENT_IN_PROGRESS'\n\n/**\n * Create a payment for an approval step. Returns the details needed to send the\n * user to the payment provider. When the provider redirects to `redirectUrl`,\n * the receipt for this payment can be displayed. Throws an `OneBlinkAppsError`\n * with `conflict` set to `PAYMENT_IN_PROGRESS_CONFLICT` when a checkout for\n * this step is already in progress.\n *\n * #### Example\n *\n * ```js\n * const payment = await approvalsService.createApprovalStepPayment(\n * 'd27966cc-128d-48a2-b681-6ad52012e113',\n * {\n * redirectUrl:\n * 'https://approvals.example/approvals/d27966cc-128d-48a2-b681-6ad52012e113/payment-receipt',\n * paymentFormUrl:\n * 'https://approvals.example/approvals/d27966cc-128d-48a2-b681-6ad52012e113/payment',\n * form,\n * submissionId: '89c6e98e-f56f-45fc-84fe-c4fc62331d34',\n * },\n * )\n * ```\n *\n * @param formSubmissionApprovalId\n * @param options\n * @param options.redirectUrl The URL the payment provider redirects to when the\n * payment finishes.\n * @param options.paymentFormUrl The in-app payment page. Required for providers\n * that render their payment form in the app.\n * @param options.form The form definition for this approval.\n * @param options.submissionId The submission this approval belongs to.\n * @param options.replacePendingPayment Cancel a checkout that is already in\n * progress so this payment can start. Leave unset to reject that checkout.\n * @param abortSignal\n * @returns\n */\nexport async function createApprovalStepPayment(\n formSubmissionApprovalId: string,\n options: {\n redirectUrl: string\n paymentFormUrl?: string\n form: FormTypes.Form\n submissionId: string\n replacePendingPayment?: boolean\n },\n abortSignal?: AbortSignal,\n): Promise<{\n hostedFormUrl: string\n amount: number\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n customerReferenceNumber?: string\n}> {\n const {\n redirectUrl,\n paymentFormUrl,\n form,\n submissionId,\n replacePendingPayment,\n } = options\n let result: {\n hostedFormUrl: string\n amount: number\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n customerReferenceNumber?: string\n }\n try {\n result = await postRequest(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/payment`,\n {\n redirectUrl,\n paymentFormUrl,\n replacePendingPayment,\n },\n abortSignal,\n )\n } catch (error) {\n if (\n error instanceof HTTPError &&\n error.status === 409 &&\n error.conflict === PAYMENT_IN_PROGRESS_CONFLICT\n ) {\n throw new OneBlinkAppsError(\n 'A payment is already in progress for this step. Finish or cancel that payment before starting another.',\n {\n httpStatusCode: error.status,\n conflict: PAYMENT_IN_PROGRESS_CONFLICT,\n originalError: error,\n },\n )\n }\n throw error\n }\n\n await rememberPaymentSubmissionResult({\n submission: {},\n // The post-submission receipt is written for the original submitter.\n // This result has no submission to fill its injectables.\n definition: {\n ...form,\n postSubmissionReceipt: undefined,\n },\n preFillFormDataId: null,\n submissionId,\n submissionTimestamp: new Date().toISOString(),\n payment: {\n amount: result.amount,\n paymentReceiptUrl: redirectUrl,\n paymentFormUrl,\n hostedFormUrl: result.hostedFormUrl,\n submissionEvent: result.paymentSubmissionEvent,\n },\n scheduling: null,\n isInPendingQueue: false,\n isOffline: false,\n isUploadingAttachments: false,\n })\n\n return result\n}\n\n/**\n * Skip the payment for an approval step and continue the approval flow.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionApproval =\n * await approvalsService.skipApprovalStepPayment(\n * 'd27966cc-128d-48a2-b681-6ad52012e113',\n * )\n * ```\n *\n * @param formSubmissionApprovalId\n * @param abortSignal\n * @returns\n */\nexport async function skipApprovalStepPayment(\n formSubmissionApprovalId: string,\n abortSignal?: AbortSignal,\n): Promise<ApprovalTypes.FormSubmissionApproval> {\n return await postRequest(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/skip-payment`,\n {},\n abortSignal,\n )\n}\n\n/**\n * Update a single FormSubmissionApproval assigned to the current user.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionApproval = {\n * id: 'd27966cc-128d-48a2-b681-6ad52012e113',\n * status: 'APPROVED',\n * username: 'email@example.com',\n * formApprovalFlowInstanceId: 1,\n * notificationEmailAddress: 'email@example.com',\n * notes: 'Great work!!!',\n * internalNotes: 'It was not really that great...',\n * cannedResponseKey: 'my_canned_response_key',\n * createdAt: '2021-02-21T22:57:56.257Z',\n * updatedAt: '2021-02-21T22:57:56.257Z',\n * }\n * const updatedFormSubmissionApproval =\n * await approvalsService.updateFormSubmissionApproval(\n * formSubmissionApproval,\n * )\n * ```\n *\n * @param formSubmissionApproval\n * @param abortSignal\n * @returns\n */\nexport async function updateFormSubmissionApproval(\n formSubmissionApproval: ApprovalTypes.FormSubmissionApproval,\n abortSignal?: AbortSignal,\n): Promise<ApprovalTypes.FormSubmissionApproval> {\n try {\n return await putRequest<ApprovalTypes.FormSubmissionApproval>(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApproval.id}`,\n formSubmissionApproval,\n abortSignal,\n )\n } catch (err) {\n Sentry.captureException(err)\n console.error('Error updating form submission approval', err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(OFFLINE_ERROR_MESSAGE, {\n originalError: error,\n isOffline: true,\n })\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot action this pending submission without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404:\n case 409: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * @deprecated Use \"reopenFormApprovalFlowInstance()\" instead\n * @internal\n */\nexport const reopenFormSubmissionApproval = reopenFormApprovalFlowInstance\n\n/**\n * As an administrator, reopen a submission that has been approved or denied.\n *\n * #### Example\n *\n * ```js\n * await approvalsService.reopenFormApprovalFlowInstance({\n * formApprovalFlowInstanceId: 1,\n * notificationEmailAddress: 'email@example.com',\n * notes: 'Great work!!!',\n * internalNotes: 'It was not really that great...',\n * cannedResponseKey: 'my_canned_response_key',\n * })\n * ```\n *\n * @param options\n * @param abortSignal\n * @returns\n */\nexport async function reopenFormApprovalFlowInstance(\n {\n formApprovalFlowInstanceId,\n ...payload\n }: {\n formApprovalFlowInstanceId: number\n notificationEmailAddress: string\n notes: string\n internalNotes?: string\n cannedResponseKey?: string\n },\n abortSignal?: AbortSignal,\n): Promise<ApprovalTypes.FormSubmissionApproval> {\n console.log('Reopening form approval flow instance', {\n formApprovalFlowInstanceId,\n ...payload,\n })\n try {\n return await postRequest<ApprovalTypes.FormSubmissionApproval>(\n `${tenants.current.apiOrigin}/form-approval-flow-instances/${formApprovalFlowInstanceId}/reopen`,\n payload,\n abortSignal,\n )\n } catch (err) {\n console.error('Error reopening form approval flow instance', err)\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(OFFLINE_ERROR_MESSAGE, {\n originalError: error,\n isOffline: true,\n })\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot reopen this approval without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this approval. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404:\n case 409: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * As an administrator, close a submission that has been approved.\n *\n * #### Example\n *\n * ```js\n * await approvalsService.closeFormApprovalFlowInstance({\n * formApprovalFlowInstanceId: 1,\n * notificationEmailAddress: ['email@example.com'],\n * notes: 'Great work!!!',\n * internalNotes: 'It was not really that great...',\n * cannedResponseKey: 'my_canned_response_key',\n * })\n * ```\n *\n * @param options\n * @param abortSignal\n * @returns\n */\nexport async function closeFormApprovalFlowInstance(\n {\n formApprovalFlowInstanceId,\n ...payload\n }: {\n formApprovalFlowInstanceId: number\n notificationEmailAddress?: string[]\n notes?: string\n internalNotes?: string\n cannedResponseKey?: string\n },\n abortSignal?: AbortSignal,\n): Promise<ApprovalTypes.FormSubmissionApproval> {\n console.log('Closing form approval flow instance', {\n formApprovalFlowInstanceId,\n ...payload,\n })\n try {\n return await postRequest<ApprovalTypes.FormSubmissionApproval>(\n `${tenants.current.apiOrigin}/form-approval-flow-instances/${formApprovalFlowInstanceId}/close`,\n payload,\n abortSignal,\n )\n } catch (err) {\n console.log('Error closing form approval flow instance', err)\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(OFFLINE_ERROR_MESSAGE, {\n originalError: error,\n isOffline: true,\n })\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot close this approval without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this approval. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404:\n case 409: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\nexport type FormApprovalFlowResponse = {\n forms: FormTypes.Form[]\n}\n\nexport async function getFormApprovalFlows(\n formsAppId: number,\n abortSignal?: AbortSignal,\n): Promise<FormApprovalFlowResponse> {\n try {\n return await getRequest<FormApprovalFlowResponse>(\n `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/form-approval-flows`,\n abortSignal,\n )\n } catch (err) {\n Sentry.captureException(err)\n console.error('Error retrieving form approval flows', err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(OFFLINE_ERROR_MESSAGE, {\n originalError: error,\n isOffline: true,\n })\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot access form approval flows without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Get an Object containing approvals for the app regardless of approval groups\n * and meta for paging. Must be an Approvals Administrator.\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const limit = 50\n * const offset = 0\n * const { approvals, meta } =\n * await approvalsService.getFormSubmissionAdministrationApprovals({\n * formAppId,\n * limit,\n * offset,\n * })\n * ```\n *\n * @param options\n * @param abortSignal\n * @returns\n */\nexport async function getFormSubmissionAdministrationApprovals(\n {\n formsAppId,\n ...rest\n }: {\n formsAppId: number\n formId?: number\n externalId?: string\n submissionId?: string\n formApprovalFlowInstanceId?: number\n submittedAfterDateTime?: string\n submittedBeforeDateTime?: string\n limit: number\n offset: number\n statuses?: string[]\n updatedAfterDateTime?: string\n updatedBeforeDateTime?: string\n lastUpdatedBy?: string[]\n submissionTitle?: string\n },\n abortSignal?: AbortSignal,\n): Promise<FormSubmissionsAdministrationApprovalsResponse> {\n try {\n return await searchRequest<FormSubmissionsAdministrationApprovalsResponse>(\n `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/approvals`,\n {\n ...rest,\n },\n abortSignal,\n )\n } catch (err) {\n Sentry.captureException(err)\n console.error(\n 'Error retrieving administrator form submission approvals',\n err,\n )\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline and do not have a local copy of this app available, please connect to the internet and try again',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot view approvals without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\nexport type FormApprovalUsernamesResponse = {\n usernames: Array<{ username: string }>\n}\n/**\n * Get an array containing usernames that have updated approvals in the within\n * the formsAppId associated with the passed `formsAppId`. Must be an Approvals\n * Administrator.\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const { usernames } =\n * await approvalsService.getFormApprovalUsernames(formsAppId)\n * ```\n *\n * @param formsAppId\n * @param abortSignal\n * @returns\n */\nexport async function getFormApprovalUsernames(\n formsAppId: number,\n abortSignal?: AbortSignal,\n): Promise<FormApprovalUsernamesResponse> {\n try {\n return await getRequest<FormApprovalUsernamesResponse>(\n `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/approvals/usernames`,\n abortSignal,\n )\n } catch (err) {\n Sentry.captureException(err)\n console.error('Error retrieving form approval usernames', err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(OFFLINE_ERROR_MESSAGE, {\n originalError: error,\n isOffline: true,\n })\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot access form approval usernames without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Create an additional note for a form submission approval.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionApprovalId = 'd96ff812-f263-4a66-868d-e259a1fe4157'\n * const newFormSubmissionApprovalNote = {\n * note: 'this is my note',\n * }\n * const createdFormSubmissionApprovalNote =\n * await approvalsService.createApprovalAdditionalNote({\n * formSubmissionApprovalId,\n * newFormSubmissionApprovalNote,\n * })\n * ```\n *\n * @param options\n * @returns\n */\nexport async function createApprovalAdditionalNote({\n formSubmissionApprovalId,\n newFormSubmissionApprovalNote,\n abortSignal,\n}: {\n formSubmissionApprovalId: string\n newFormSubmissionApprovalNote: ApprovalTypes.NewFormSubmissionApprovalNote\n abortSignal?: AbortSignal\n}): Promise<ApprovalTypes.FormSubmissionApprovalNote> {\n try {\n return await postRequest<ApprovalTypes.FormSubmissionApprovalNote>(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/additional-notes`,\n newFormSubmissionApprovalNote,\n abortSignal,\n )\n } catch (err) {\n console.error('Error creating form submission approval note', err)\n if (abortSignal?.aborted) {\n throw err\n }\n\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(OFFLINE_ERROR_MESSAGE, {\n originalError: error,\n isOffline: true,\n })\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot create additional notes without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Update an additional note for a form submission approval.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionApprovalId = 'd96ff812-f263-4a66-868d-e259a1fe4157'\n * const formSubmissionApprovalNote = {\n * id: '1e84dee3-0dc0-4abe-b2cf-d15d62fd9d0b',\n * note: 'this is my note',\n * createdAt: '2022-06-24T03:16:34.696Z',\n * createdBy: {\n * username: 'user@domain.com',\n * },\n * updatedAt: '2022-06-24T03:16:34.696Z',\n * lastUpdatedBy: {\n * username: 'user@domain.com',\n * },\n * }\n * const updatedFormSubmissionApprovalNote =\n * await approvalsService.updateApprovalAdditionalNote({\n * formSubmissionApprovalId,\n * formSubmissionApprovalNote,\n * })\n * ```\n *\n * @param options\n * @returns\n */\nexport async function updateApprovalAdditionalNote({\n formSubmissionApprovalId,\n formSubmissionApprovalNote,\n abortSignal,\n}: {\n formSubmissionApprovalId: string\n formSubmissionApprovalNote: ApprovalTypes.FormSubmissionApprovalNote\n abortSignal?: AbortSignal\n}): Promise<ApprovalTypes.FormSubmissionApprovalNote> {\n try {\n return await putRequest<ApprovalTypes.FormSubmissionApprovalNote>(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/additional-notes/${formSubmissionApprovalNote.id}`,\n formSubmissionApprovalNote,\n abortSignal,\n )\n } catch (err) {\n console.error('Error updating form submission approval note', err)\n if (abortSignal?.aborted) {\n throw err\n }\n\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(OFFLINE_ERROR_MESSAGE, {\n originalError: error,\n isOffline: true,\n })\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot update additional notes without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Delete an additional note for a form submission approval.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionApprovalId = 'd96ff812-f263-4a66-868d-e259a1fe4157'\n * const formSubmissionApprovalNoteId = '1e84dee3-0dc0-4abe-b2cf-d15d62fd9d0b',\n * const updatedFormSubmissionApprovalNote =\n * await approvalsService.deleteApprovalAdditionalNote({\n * formSubmissionApprovalId,\n * formSubmissionApprovalNoteId,\n * })\n * ```\n *\n * @param options\n * @returns\n */\nexport async function deleteApprovalAdditionalNote({\n formSubmissionApprovalId,\n formSubmissionApprovalNoteId,\n abortSignal,\n}: {\n formSubmissionApprovalId: string\n formSubmissionApprovalNoteId: string\n abortSignal?: AbortSignal\n}): Promise<void> {\n try {\n return await deleteRequest(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/additional-notes/${formSubmissionApprovalNoteId}`,\n abortSignal,\n )\n } catch (err) {\n console.error('Error updating form submission approval note', err)\n if (abortSignal?.aborted) {\n throw err\n }\n\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(OFFLINE_ERROR_MESSAGE, {\n originalError: error,\n isOffline: true,\n })\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot delete additional notes without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Get the status of a single FormSubmissionApproval for the given id.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionApprovalId = 'd27966cc-128d-48a2-b681-6ad52012e113'\n * const { status } =\n * await approvalsService.getFormSubmissionApprovalStatus(\n * formSubmissionApprovalId,\n * )\n * ```\n *\n * @param formSubmissionApprovalId\n * @param abortSignal\n * @returns\n */\nexport async function getFormSubmissionApprovalStatus(\n formSubmissionApprovalId: string,\n abortSignal?: AbortSignal,\n): Promise<{ status: ApprovalTypes.NewFormSubmissionApproval['status'] }> {\n try {\n const result = await getRequest<{\n status: ApprovalTypes.NewFormSubmissionApproval['status']\n }>(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/status`,\n abortSignal,\n )\n return result\n } catch (err) {\n Sentry.captureException(err)\n console.error('Error retrieving form submission approval status', err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline and do not have a local copy of this app available, please connect to the internet and try again',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot action this pending submission without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"approvals-service.js","sourceRoot":"","sources":["../../src/apps/approvals-service.ts"],"names":[],"mappings":"AAMA,OAAO,iBAAiB,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAA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CAAC;YACrB,KAAK,GAAG,CAAC,CAAC,CAAC;gBACT,MAAM,IAAI,iBAAiB,CACzB,iGAAiG,EACjG;oBACE,aAAa,EAAE,KAAK;oBACpB,aAAa,EAAE,IAAI;oBACnB,cAAc,EAAE,KAAK,CAAC,MAAM;iBAC7B,CACF,CAAA;YACH,CAAC;YACD,KAAK,GAAG,CAAC,CAAC,CAAC;gBACT,MAAM,IAAI,iBAAiB,CACzB,oHAAoH,EACpH;oBACE,aAAa,EAAE,KAAK;oBACpB,qBAAqB,EAAE,IAAI;oBAC3B,cAAc,EAAE,KAAK,CAAC,MAAM;iBAC7B,CACF,CAAA;YACH,CAAC;YACD,KAAK,GAAG,CAAC;YACT,KAAK,GAAG,CAAC,CAAC,CAAC;gBACT,MAAM,IAAI,iBAAiB,CAAC,KAAK,CAAC,OAAO,EAAE;oBACzC,KAAK,EAAE,iBAAiB;oBACxB,cAAc,EAAE,KAAK,CAAC,MAAM;iBAC7B,CAAC,CAAA;YACJ,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,IAAI,iBAAiB,CACzB,gFAAgF,EAChF;oBACE,aAAa,EAAE,KAAK;oBACpB,cAAc,EAAE,KAAK,CAAC,MAAM;iBAC7B,CACF,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import {\n SubmissionTypes,\n ApprovalTypes,\n FormTypes,\n SubmissionEventTypes,\n} from '@oneblink/types'\nimport OneBlinkAppsError from './services/errors/oneBlinkAppsError'\nimport { isOffline, OFFLINE_ERROR_MESSAGE } from './offline-service'\nimport {\n deleteRequest,\n getRequest,\n putRequest,\n searchRequest,\n postRequest,\n HTTPError,\n} from './services/fetch'\nimport tenants from './tenants'\nimport Sentry from './Sentry'\nimport { rememberPaymentSubmissionResult } from './services/payment-submission-result'\nexport { getFlowInstanceNodesWithMeta } from '../services/getFlowInstanceNodesWithMeta'\n\nexport type FormSubmissionApprovalsResponse = {\n approvals: Array<{\n formSubmissionApproval: ApprovalTypes.FormSubmissionApproval\n formApprovalFlowInstance: ApprovalTypes.FormApprovalFlowInstance\n formSubmissionMeta: SubmissionTypes.FormSubmissionMeta\n latestSuccessfulFormSubmissionPayment:\n | SubmissionTypes.FormSubmissionPayment\n | undefined\n /** True while this approval has a checkout that has not finished. */\n paymentInProgress?: boolean\n /** True when a payment request has been sent for this step. */\n paymentRequested?: boolean\n }>\n}\n\nexport type FormApprovalFlowInstanceHistory = {\n formApprovalFlowInstance: ApprovalTypes.FormApprovalFlowInstance\n formSubmissionMeta: SubmissionTypes.FormSubmissionMeta\n formSubmissionMetaEdits: SubmissionTypes.FormSubmissionMetaEdit[]\n formSubmissionApprovals: ApprovalTypes.FormSubmissionApproval[]\n successfulFormSubmissionPayment?: SubmissionTypes.FormSubmissionPayment\n approvalStepPayments?: SubmissionTypes.FormSubmissionPayment[]\n paymentRequests?: SubmissionTypes.FormSubmissionPaymentRequest[]\n}\n\nexport type FormSubmissionApprovalResponse = {\n formSubmissionMeta: SubmissionTypes.FormSubmissionMeta\n formApprovalFlowInstance: ApprovalTypes.FormApprovalFlowInstance\n formSubmissionApproval: ApprovalTypes.FormSubmissionApproval\n form: FormTypes.Form\n successfulFormSubmissionPayment?: SubmissionTypes.FormSubmissionPayment\n history: FormApprovalFlowInstanceHistory[]\n}\n\nexport type FormSubmissionsAdministrationApprovalsResponse = {\n approvals: Array<\n FormApprovalFlowInstanceHistory & {\n history: Array<FormApprovalFlowInstanceHistory>\n }\n >\n meta: {\n limit: number\n offset: number\n nextOffset?: number\n }\n}\n\n/**\n * Get an Object containing FormSubmissionApprovals assigned to the current user\n * and the Form definitions in those approvals.\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const {\n * formSubmissionApprovals,\n * formApprovalFlowInstances,\n * forms,\n * formSubmissionMeta,\n * } = await approvalsService.getFormSubmissionApprovals(formAppId)\n * ```\n *\n * @param formsAppId\n * @param abortSignal\n * @returns\n */\nexport async function getFormSubmissionApprovals(\n formsAppId: number,\n abortSignal?: AbortSignal,\n): Promise<FormSubmissionApprovalsResponse> {\n try {\n return await getRequest<FormSubmissionApprovalsResponse>(\n `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/my-approvals`,\n abortSignal,\n )\n } catch (err) {\n Sentry.captureException(err)\n console.error('Error retrieving form submission approvals', err)\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline and do not have a local copy of this app available, please connect to the internet and try again',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot view your pending approvals without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Get a single FormSubmissionApproval belonging to the given id.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionApprovalId = 'd27966cc-128d-48a2-b681-6ad52012e113'\n * const {\n * formSubmissionApproval,\n * formApprovalFlowInstance,\n * formSubmissionMeta,\n * form,\n * history,\n * } = await approvalsService.getFormSubmissionApproval(\n * formSubmissionApprovalId,\n * )\n * ```\n *\n * @param formSubmissionApprovalId\n * @param abortSignal\n * @returns\n */\nexport async function getFormSubmissionApproval(\n formSubmissionApprovalId: string,\n abortSignal?: AbortSignal,\n): Promise<FormSubmissionApprovalResponse> {\n try {\n const result = await getRequest<FormSubmissionApprovalResponse>(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}`,\n abortSignal,\n )\n return result\n } catch (err) {\n Sentry.captureException(err)\n console.error('Error retrieving form submission approval', err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline and do not have a local copy of this app available, please connect to the internet and try again',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot action this pending submission without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Conflict code on the error thrown when an approval step already has a\n * checkout in progress.\n *\n * #### Example\n *\n * ```js\n * import {\n * approvalsService,\n * OneBlinkAppsError,\n * } from '@oneblink/apps-react'\n *\n * try {\n * await approvalsService.createApprovalStepPayment(\n * formSubmissionApprovalId,\n * {\n * redirectUrl,\n * paymentFormUrl,\n * form,\n * submissionId,\n * },\n * )\n * } catch (error) {\n * if (\n * error instanceof OneBlinkAppsError &&\n * error.conflict === approvalsService.PAYMENT_IN_PROGRESS_CONFLICT\n * ) {\n * console.log('A payment is already in progress')\n * }\n * }\n * ```\n */\nexport const PAYMENT_IN_PROGRESS_CONFLICT = 'PAYMENT_IN_PROGRESS'\n\n/**\n * Create a payment for an approval step. Returns the details needed to send the\n * user to the payment provider. When the provider redirects to `redirectUrl`,\n * the receipt for this payment can be displayed. Throws an `OneBlinkAppsError`\n * with `conflict` set to `PAYMENT_IN_PROGRESS_CONFLICT` when a checkout for\n * this step is already in progress.\n *\n * #### Example\n *\n * ```js\n * const payment = await approvalsService.createApprovalStepPayment(\n * 'd27966cc-128d-48a2-b681-6ad52012e113',\n * {\n * redirectUrl:\n * 'https://approvals.example/approvals/d27966cc-128d-48a2-b681-6ad52012e113/payment-receipt',\n * paymentFormUrl:\n * 'https://approvals.example/approvals/d27966cc-128d-48a2-b681-6ad52012e113/payment',\n * form,\n * submissionId: '89c6e98e-f56f-45fc-84fe-c4fc62331d34',\n * },\n * )\n * ```\n *\n * @param formSubmissionApprovalId\n * @param options\n * @param options.redirectUrl The URL the payment provider redirects to when the\n * payment finishes.\n * @param options.paymentFormUrl The in-app payment page. Required for providers\n * that render their payment form in the app.\n * @param options.form The form definition for this approval.\n * @param options.submissionId The submission this approval belongs to.\n * @param options.replacePendingPayment Cancel a checkout that is already in\n * progress so this payment can start. Leave unset to reject that checkout.\n * @param abortSignal\n * @returns\n */\nexport async function createApprovalStepPayment(\n formSubmissionApprovalId: string,\n options: {\n redirectUrl: string\n paymentFormUrl?: string\n form: FormTypes.Form\n submissionId: string\n replacePendingPayment?: boolean\n },\n abortSignal?: AbortSignal,\n): Promise<{\n hostedFormUrl: string\n amount: number\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n customerReferenceNumber?: string\n}> {\n const {\n redirectUrl,\n paymentFormUrl,\n form,\n submissionId,\n replacePendingPayment,\n } = options\n let result: {\n hostedFormUrl: string\n amount: number\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n customerReferenceNumber?: string\n }\n try {\n result = await postRequest(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/payment`,\n {\n redirectUrl,\n paymentFormUrl,\n replacePendingPayment,\n },\n abortSignal,\n )\n } catch (error) {\n if (\n error instanceof HTTPError &&\n error.status === 409 &&\n error.conflict === PAYMENT_IN_PROGRESS_CONFLICT\n ) {\n throw new OneBlinkAppsError(\n 'A payment is already in progress for this step. Finish or cancel that payment before starting another.',\n {\n httpStatusCode: error.status,\n conflict: PAYMENT_IN_PROGRESS_CONFLICT,\n originalError: error,\n },\n )\n }\n throw error\n }\n\n await rememberPaymentSubmissionResult({\n submission: {},\n // The post-submission receipt is written for the original submitter.\n // This result has no submission to fill its injectables.\n definition: {\n ...form,\n postSubmissionReceipt: undefined,\n },\n preFillFormDataId: null,\n submissionId,\n submissionTimestamp: new Date().toISOString(),\n payment: {\n amount: result.amount,\n paymentReceiptUrl: redirectUrl,\n paymentFormUrl,\n hostedFormUrl: result.hostedFormUrl,\n submissionEvent: result.paymentSubmissionEvent,\n },\n scheduling: null,\n isInPendingQueue: false,\n isOffline: false,\n isUploadingAttachments: false,\n })\n\n return result\n}\n\n/**\n * Email a recipient a link to review the submission and pay this approval step.\n *\n * #### Example\n *\n * ```js\n * const { paymentRequests } =\n * await approvalsService.requestApprovalStepPayment(\n * 'd27966cc-128d-48a2-b681-6ad52012e113',\n * {\n * delivery: {\n * method: 'EMAIL',\n * email: 'payer@example.com',\n * name: 'Alex',\n * },\n * },\n * )\n * ```\n *\n * @param formSubmissionApprovalId\n * @param options\n * @param options.delivery How to send the request. Only email is supported.\n * @param abortSignal\n * @returns The payment requests sent for this step. Tokens are not included.\n */\nexport async function requestApprovalStepPayment(\n formSubmissionApprovalId: string,\n options: {\n delivery: SubmissionTypes.FormSubmissionPaymentRequestDelivery\n },\n abortSignal?: AbortSignal,\n): Promise<{\n paymentRequests: SubmissionTypes.FormSubmissionPaymentRequest[]\n}> {\n return await postRequest(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/payment-requests`,\n options,\n abortSignal,\n )\n}\n\n/**\n * Skip the payment for an approval step and continue the approval flow.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionApproval =\n * await approvalsService.skipApprovalStepPayment(\n * 'd27966cc-128d-48a2-b681-6ad52012e113',\n * )\n * ```\n *\n * @param formSubmissionApprovalId\n * @param abortSignal\n * @returns\n */\nexport async function skipApprovalStepPayment(\n formSubmissionApprovalId: string,\n abortSignal?: AbortSignal,\n): Promise<ApprovalTypes.FormSubmissionApproval> {\n return await postRequest(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/skip-payment`,\n {},\n abortSignal,\n )\n}\n\n/**\n * Update a single FormSubmissionApproval assigned to the current user.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionApproval = {\n * id: 'd27966cc-128d-48a2-b681-6ad52012e113',\n * status: 'APPROVED',\n * username: 'email@example.com',\n * formApprovalFlowInstanceId: 1,\n * notificationEmailAddress: 'email@example.com',\n * notes: 'Great work!!!',\n * internalNotes: 'It was not really that great...',\n * cannedResponseKey: 'my_canned_response_key',\n * createdAt: '2021-02-21T22:57:56.257Z',\n * updatedAt: '2021-02-21T22:57:56.257Z',\n * }\n * const updatedFormSubmissionApproval =\n * await approvalsService.updateFormSubmissionApproval(\n * formSubmissionApproval,\n * )\n * ```\n *\n * @param formSubmissionApproval\n * @param abortSignal\n * @returns\n */\nexport async function updateFormSubmissionApproval(\n formSubmissionApproval: ApprovalTypes.FormSubmissionApproval,\n abortSignal?: AbortSignal,\n): Promise<ApprovalTypes.FormSubmissionApproval> {\n try {\n return await putRequest<ApprovalTypes.FormSubmissionApproval>(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApproval.id}`,\n formSubmissionApproval,\n abortSignal,\n )\n } catch (err) {\n Sentry.captureException(err)\n console.error('Error updating form submission approval', err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(OFFLINE_ERROR_MESSAGE, {\n originalError: error,\n isOffline: true,\n })\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot action this pending submission without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404:\n case 409: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * @deprecated Use \"reopenFormApprovalFlowInstance()\" instead\n * @internal\n */\nexport const reopenFormSubmissionApproval = reopenFormApprovalFlowInstance\n\n/**\n * As an administrator, reopen a submission that has been approved or denied.\n *\n * #### Example\n *\n * ```js\n * await approvalsService.reopenFormApprovalFlowInstance({\n * formApprovalFlowInstanceId: 1,\n * notificationEmailAddress: 'email@example.com',\n * notes: 'Great work!!!',\n * internalNotes: 'It was not really that great...',\n * cannedResponseKey: 'my_canned_response_key',\n * })\n * ```\n *\n * @param options\n * @param abortSignal\n * @returns\n */\nexport async function reopenFormApprovalFlowInstance(\n {\n formApprovalFlowInstanceId,\n ...payload\n }: {\n formApprovalFlowInstanceId: number\n notificationEmailAddress: string\n notes: string\n internalNotes?: string\n cannedResponseKey?: string\n },\n abortSignal?: AbortSignal,\n): Promise<ApprovalTypes.FormSubmissionApproval> {\n console.log('Reopening form approval flow instance', {\n formApprovalFlowInstanceId,\n ...payload,\n })\n try {\n return await postRequest<ApprovalTypes.FormSubmissionApproval>(\n `${tenants.current.apiOrigin}/form-approval-flow-instances/${formApprovalFlowInstanceId}/reopen`,\n payload,\n abortSignal,\n )\n } catch (err) {\n console.error('Error reopening form approval flow instance', err)\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(OFFLINE_ERROR_MESSAGE, {\n originalError: error,\n isOffline: true,\n })\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot reopen this approval without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this approval. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404:\n case 409: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * As an administrator, close a submission that has been approved.\n *\n * #### Example\n *\n * ```js\n * await approvalsService.closeFormApprovalFlowInstance({\n * formApprovalFlowInstanceId: 1,\n * notificationEmailAddress: ['email@example.com'],\n * notes: 'Great work!!!',\n * internalNotes: 'It was not really that great...',\n * cannedResponseKey: 'my_canned_response_key',\n * })\n * ```\n *\n * @param options\n * @param abortSignal\n * @returns\n */\nexport async function closeFormApprovalFlowInstance(\n {\n formApprovalFlowInstanceId,\n ...payload\n }: {\n formApprovalFlowInstanceId: number\n notificationEmailAddress?: string[]\n notes?: string\n internalNotes?: string\n cannedResponseKey?: string\n },\n abortSignal?: AbortSignal,\n): Promise<ApprovalTypes.FormSubmissionApproval> {\n console.log('Closing form approval flow instance', {\n formApprovalFlowInstanceId,\n ...payload,\n })\n try {\n return await postRequest<ApprovalTypes.FormSubmissionApproval>(\n `${tenants.current.apiOrigin}/form-approval-flow-instances/${formApprovalFlowInstanceId}/close`,\n payload,\n abortSignal,\n )\n } catch (err) {\n console.log('Error closing form approval flow instance', err)\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(OFFLINE_ERROR_MESSAGE, {\n originalError: error,\n isOffline: true,\n })\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot close this approval without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this approval. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404:\n case 409: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\nexport type FormApprovalFlowResponse = {\n forms: FormTypes.Form[]\n}\n\nexport async function getFormApprovalFlows(\n formsAppId: number,\n abortSignal?: AbortSignal,\n): Promise<FormApprovalFlowResponse> {\n try {\n return await getRequest<FormApprovalFlowResponse>(\n `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/form-approval-flows`,\n abortSignal,\n )\n } catch (err) {\n Sentry.captureException(err)\n console.error('Error retrieving form approval flows', err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(OFFLINE_ERROR_MESSAGE, {\n originalError: error,\n isOffline: true,\n })\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot access form approval flows without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Get an Object containing approvals for the app regardless of approval groups\n * and meta for paging. Must be an Approvals Administrator.\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const limit = 50\n * const offset = 0\n * const { approvals, meta } =\n * await approvalsService.getFormSubmissionAdministrationApprovals({\n * formAppId,\n * limit,\n * offset,\n * })\n * ```\n *\n * @param options\n * @param abortSignal\n * @returns\n */\nexport async function getFormSubmissionAdministrationApprovals(\n {\n formsAppId,\n ...rest\n }: {\n formsAppId: number\n formId?: number\n externalId?: string\n submissionId?: string\n formApprovalFlowInstanceId?: number\n submittedAfterDateTime?: string\n submittedBeforeDateTime?: string\n limit: number\n offset: number\n statuses?: string[]\n updatedAfterDateTime?: string\n updatedBeforeDateTime?: string\n lastUpdatedBy?: string[]\n submissionTitle?: string\n },\n abortSignal?: AbortSignal,\n): Promise<FormSubmissionsAdministrationApprovalsResponse> {\n try {\n return await searchRequest<FormSubmissionsAdministrationApprovalsResponse>(\n `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/approvals`,\n {\n ...rest,\n },\n abortSignal,\n )\n } catch (err) {\n Sentry.captureException(err)\n console.error(\n 'Error retrieving administrator form submission approvals',\n err,\n )\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline and do not have a local copy of this app available, please connect to the internet and try again',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot view approvals without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\nexport type FormApprovalUsernamesResponse = {\n usernames: Array<{ username: string }>\n}\n/**\n * Get an array containing usernames that have updated approvals in the within\n * the formsAppId associated with the passed `formsAppId`. Must be an Approvals\n * Administrator.\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const { usernames } =\n * await approvalsService.getFormApprovalUsernames(formsAppId)\n * ```\n *\n * @param formsAppId\n * @param abortSignal\n * @returns\n */\nexport async function getFormApprovalUsernames(\n formsAppId: number,\n abortSignal?: AbortSignal,\n): Promise<FormApprovalUsernamesResponse> {\n try {\n return await getRequest<FormApprovalUsernamesResponse>(\n `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/approvals/usernames`,\n abortSignal,\n )\n } catch (err) {\n Sentry.captureException(err)\n console.error('Error retrieving form approval usernames', err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(OFFLINE_ERROR_MESSAGE, {\n originalError: error,\n isOffline: true,\n })\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot access form approval usernames without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Create an additional note for a form submission approval.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionApprovalId = 'd96ff812-f263-4a66-868d-e259a1fe4157'\n * const newFormSubmissionApprovalNote = {\n * note: 'this is my note',\n * }\n * const createdFormSubmissionApprovalNote =\n * await approvalsService.createApprovalAdditionalNote({\n * formSubmissionApprovalId,\n * newFormSubmissionApprovalNote,\n * })\n * ```\n *\n * @param options\n * @returns\n */\nexport async function createApprovalAdditionalNote({\n formSubmissionApprovalId,\n newFormSubmissionApprovalNote,\n abortSignal,\n}: {\n formSubmissionApprovalId: string\n newFormSubmissionApprovalNote: ApprovalTypes.NewFormSubmissionApprovalNote\n abortSignal?: AbortSignal\n}): Promise<ApprovalTypes.FormSubmissionApprovalNote> {\n try {\n return await postRequest<ApprovalTypes.FormSubmissionApprovalNote>(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/additional-notes`,\n newFormSubmissionApprovalNote,\n abortSignal,\n )\n } catch (err) {\n console.error('Error creating form submission approval note', err)\n if (abortSignal?.aborted) {\n throw err\n }\n\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(OFFLINE_ERROR_MESSAGE, {\n originalError: error,\n isOffline: true,\n })\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot create additional notes without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Update an additional note for a form submission approval.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionApprovalId = 'd96ff812-f263-4a66-868d-e259a1fe4157'\n * const formSubmissionApprovalNote = {\n * id: '1e84dee3-0dc0-4abe-b2cf-d15d62fd9d0b',\n * note: 'this is my note',\n * createdAt: '2022-06-24T03:16:34.696Z',\n * createdBy: {\n * username: 'user@domain.com',\n * },\n * updatedAt: '2022-06-24T03:16:34.696Z',\n * lastUpdatedBy: {\n * username: 'user@domain.com',\n * },\n * }\n * const updatedFormSubmissionApprovalNote =\n * await approvalsService.updateApprovalAdditionalNote({\n * formSubmissionApprovalId,\n * formSubmissionApprovalNote,\n * })\n * ```\n *\n * @param options\n * @returns\n */\nexport async function updateApprovalAdditionalNote({\n formSubmissionApprovalId,\n formSubmissionApprovalNote,\n abortSignal,\n}: {\n formSubmissionApprovalId: string\n formSubmissionApprovalNote: ApprovalTypes.FormSubmissionApprovalNote\n abortSignal?: AbortSignal\n}): Promise<ApprovalTypes.FormSubmissionApprovalNote> {\n try {\n return await putRequest<ApprovalTypes.FormSubmissionApprovalNote>(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/additional-notes/${formSubmissionApprovalNote.id}`,\n formSubmissionApprovalNote,\n abortSignal,\n )\n } catch (err) {\n console.error('Error updating form submission approval note', err)\n if (abortSignal?.aborted) {\n throw err\n }\n\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(OFFLINE_ERROR_MESSAGE, {\n originalError: error,\n isOffline: true,\n })\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot update additional notes without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Delete an additional note for a form submission approval.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionApprovalId = 'd96ff812-f263-4a66-868d-e259a1fe4157'\n * const formSubmissionApprovalNoteId = '1e84dee3-0dc0-4abe-b2cf-d15d62fd9d0b',\n * const updatedFormSubmissionApprovalNote =\n * await approvalsService.deleteApprovalAdditionalNote({\n * formSubmissionApprovalId,\n * formSubmissionApprovalNoteId,\n * })\n * ```\n *\n * @param options\n * @returns\n */\nexport async function deleteApprovalAdditionalNote({\n formSubmissionApprovalId,\n formSubmissionApprovalNoteId,\n abortSignal,\n}: {\n formSubmissionApprovalId: string\n formSubmissionApprovalNoteId: string\n abortSignal?: AbortSignal\n}): Promise<void> {\n try {\n return await deleteRequest(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/additional-notes/${formSubmissionApprovalNoteId}`,\n abortSignal,\n )\n } catch (err) {\n console.error('Error updating form submission approval note', err)\n if (abortSignal?.aborted) {\n throw err\n }\n\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(OFFLINE_ERROR_MESSAGE, {\n originalError: error,\n isOffline: true,\n })\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot delete additional notes without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Get the status of a single FormSubmissionApproval for the given id.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionApprovalId = 'd27966cc-128d-48a2-b681-6ad52012e113'\n * const { status } =\n * await approvalsService.getFormSubmissionApprovalStatus(\n * formSubmissionApprovalId,\n * )\n * ```\n *\n * @param formSubmissionApprovalId\n * @param abortSignal\n * @returns\n */\nexport async function getFormSubmissionApprovalStatus(\n formSubmissionApprovalId: string,\n abortSignal?: AbortSignal,\n): Promise<{ status: ApprovalTypes.NewFormSubmissionApproval['status'] }> {\n try {\n const result = await getRequest<{\n status: ApprovalTypes.NewFormSubmissionApproval['status']\n }>(\n `${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/status`,\n abortSignal,\n )\n return result\n } catch (err) {\n Sentry.captureException(err)\n console.error('Error retrieving form submission approval status', err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline and do not have a local copy of this app available, please connect to the internet and try again',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot action this pending submission without first logging in. Please login and try again.',\n {\n originalError: error,\n requiresLogin: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to this application. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n"]}
@@ -1,11 +1,13 @@
1
1
  import { paymentService } from '@oneblink/sdk-core';
2
- import { SubmissionEventTypes, SubmissionTypes } from '@oneblink/types';
2
+ import { FormTypes, SubmissionEventTypes, SubmissionTypes } from '@oneblink/types';
3
3
  import { FormSubmission, FormSubmissionResult } from './types/submissions';
4
4
  import { HandlePaymentResult, PaymentReceiptItem } from './types/payments';
5
5
  import * as westpacQuickStream from './services/payment-providers/WestpacQuickStreamPaymentProvider';
6
6
  import { getPaymentFormSession, getPaymentHandoff, paymentProviderRendersInApp, type InAppPaymentType, type PaymentFormSession } from './services/payment-handoff';
7
+ import { rememberPaymentSubmissionResult } from './services/payment-submission-result';
7
8
  export { HandlePaymentResult, PaymentReceiptItem, westpacQuickStream };
8
9
  export { paymentProviderRendersInApp, getPaymentHandoff, getPaymentFormSession };
10
+ export { rememberPaymentSubmissionResult };
9
11
  export type { InAppPaymentType, PaymentFormSession };
10
12
  /**
11
13
  * Get the receipt URL for a completed in-app payment. The receipt page verifies
@@ -116,6 +118,60 @@ export declare function getFormSubmissionResultPayment(): Promise<{
116
118
  * @returns
117
119
  */
118
120
  export declare function getDisplayDetailsFromFormSubmissionPayment(formSubmissionPayment: SubmissionTypes.FormSubmissionPayment): paymentService.PaymentDisplayDetailsResult | undefined;
121
+ /**
122
+ * Load the latest submission for a payment request. The token is the secret
123
+ * from the review link and is not stored by the client beyond this call. Throws
124
+ * an `OneBlinkAppsError` when the link can no longer be used.
125
+ */
126
+ export declare function reviewFormSubmissionPaymentRequest(paymentRequestToken: string, abortSignal?: AbortSignal): Promise<{
127
+ form: FormTypes.Form;
128
+ submission: SubmissionTypes.S3SubmissionData['submission'];
129
+ submissionId: string;
130
+ }>;
131
+ /**
132
+ * Start checkout for a payment request and store the result for the receipt
133
+ * page. The hosted payment URL is built by the server from the submission's
134
+ * forms app.
135
+ *
136
+ * #### Example
137
+ *
138
+ * ```js
139
+ * const payment = await paymentService.startFormSubmissionPaymentRequest(
140
+ * paymentRequestToken,
141
+ * {
142
+ * form,
143
+ * submission,
144
+ * submissionId: '89c6e98e-f56f-45fc-84fe-c4fc62331d34',
145
+ * paymentReceiptUrl: `${window.location.origin}/payment-receipt`,
146
+ * paymentFormUrl: `${window.location.origin}/payment-form`,
147
+ * },
148
+ * )
149
+ * ```
150
+ *
151
+ * @param paymentRequestToken The secret from the review link.
152
+ * @param options
153
+ * @param options.form The form definition returned by the review.
154
+ * @param options.submission The submission returned by the review.
155
+ * @param options.submissionId The submission this payment belongs to.
156
+ * @param options.paymentReceiptUrl The URL the payment provider redirects to
157
+ * when the payment finishes.
158
+ * @param options.paymentFormUrl The in-app payment page. Required for providers
159
+ * that render their payment form in the app.
160
+ * @returns
161
+ * @throws {OneBlinkAppsError} When the payment request can no longer be paid.
162
+ */
163
+ export declare function startFormSubmissionPaymentRequest(paymentRequestToken: string, options: {
164
+ form: FormTypes.Form;
165
+ submission: SubmissionTypes.S3SubmissionData['submission'];
166
+ submissionId: string;
167
+ paymentReceiptUrl: string;
168
+ paymentFormUrl?: string;
169
+ }): Promise<{
170
+ hostedFormUrl: string;
171
+ amount: number;
172
+ paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent;
173
+ customerReferenceNumber?: string;
174
+ }>;
119
175
  /**
120
176
  * Retrieve the failure message and provider response fields for a form
121
177
  * submission payment. Returns an empty array unless the payment failed.
@@ -9,8 +9,11 @@ import { addDaysToDate, endOfDay, parseDayOnlyDate, startOfDay, replaceSubmissio
9
9
  import { getPaymentFormSession, getPaymentHandoff, paymentProviderRendersInApp, } from './services/payment-handoff';
10
10
  import { getSchedulingBooking, removeSchedulingBooking, } from './services/schedulingHandlers';
11
11
  import { retrieveFormSubmissionResult, rememberPaymentSubmissionResult, } from './services/payment-submission-result';
12
+ import { HTTPError, postRequest } from './services/fetch';
13
+ import tenants from './tenants';
12
14
  export { westpacQuickStream };
13
15
  export { paymentProviderRendersInApp, getPaymentHandoff, getPaymentFormSession };
16
+ export { rememberPaymentSubmissionResult };
14
17
  /**
15
18
  * Receipt URLs for providers whose payment form is rendered by the app. Add a
16
19
  * new in-app provider here so hosts of that form can redirect to a receipt
@@ -232,6 +235,145 @@ export async function getFormSubmissionResultPayment() {
232
235
  export function getDisplayDetailsFromFormSubmissionPayment(formSubmissionPayment) {
233
236
  return paymentService.getDisplayDetailsFromFormSubmissionPayment(formSubmissionPayment, replaceSubmissionFormatters);
234
237
  }
238
+ const paymentRequestConflictMessages = {
239
+ PAYMENT_REQUEST_NOT_FOUND: 'This payment link is not valid.',
240
+ PAYMENT_REQUEST_ALREADY_PAID: 'This payment has already been completed.',
241
+ PAYMENT_REQUEST_SKIPPED: 'This payment was skipped, so there is nothing to pay.',
242
+ PAYMENT_REQUEST_DENIED: 'This payment was denied and can no longer be paid.',
243
+ PAYMENT_REQUEST_CLARIFICATION_REQUIRED: 'This submission was sent back for clarification, so this payment link can no longer be used.',
244
+ PAYMENT_REQUEST_SUBMISSION_REMOVED: 'The submission for this payment has been removed, so it can no longer be paid.',
245
+ PAYMENT_REQUEST_UNAVAILABLE: 'This payment request is no longer available.',
246
+ PAYMENT_IN_PROGRESS: 'A payment is already in progress for this step. Finish that payment before starting another.',
247
+ };
248
+ function paymentRequestConflictMessage(conflict) {
249
+ switch (conflict) {
250
+ case 'PAYMENT_REQUEST_NOT_FOUND': {
251
+ return paymentRequestConflictMessages.PAYMENT_REQUEST_NOT_FOUND;
252
+ }
253
+ case 'PAYMENT_REQUEST_ALREADY_PAID': {
254
+ return paymentRequestConflictMessages.PAYMENT_REQUEST_ALREADY_PAID;
255
+ }
256
+ case 'PAYMENT_REQUEST_SKIPPED': {
257
+ return paymentRequestConflictMessages.PAYMENT_REQUEST_SKIPPED;
258
+ }
259
+ case 'PAYMENT_REQUEST_DENIED': {
260
+ return paymentRequestConflictMessages.PAYMENT_REQUEST_DENIED;
261
+ }
262
+ case 'PAYMENT_REQUEST_CLARIFICATION_REQUIRED': {
263
+ return paymentRequestConflictMessages.PAYMENT_REQUEST_CLARIFICATION_REQUIRED;
264
+ }
265
+ case 'PAYMENT_REQUEST_SUBMISSION_REMOVED': {
266
+ return paymentRequestConflictMessages.PAYMENT_REQUEST_SUBMISSION_REMOVED;
267
+ }
268
+ case 'PAYMENT_REQUEST_UNAVAILABLE': {
269
+ return paymentRequestConflictMessages.PAYMENT_REQUEST_UNAVAILABLE;
270
+ }
271
+ case 'PAYMENT_IN_PROGRESS': {
272
+ return paymentRequestConflictMessages.PAYMENT_IN_PROGRESS;
273
+ }
274
+ default: {
275
+ return undefined;
276
+ }
277
+ }
278
+ }
279
+ function throwPaymentRequestError(error) {
280
+ var _a;
281
+ if (error instanceof OneBlinkAppsError) {
282
+ throw error;
283
+ }
284
+ if (error instanceof HTTPError) {
285
+ throw new OneBlinkAppsError((_a = paymentRequestConflictMessage(error.conflict)) !== null && _a !== void 0 ? _a : (error.status === 409
286
+ ? paymentRequestConflictMessages.PAYMENT_REQUEST_UNAVAILABLE
287
+ : error.message ||
288
+ paymentRequestConflictMessages.PAYMENT_REQUEST_UNAVAILABLE), {
289
+ httpStatusCode: error.status,
290
+ conflict: error.conflict,
291
+ });
292
+ }
293
+ throw new OneBlinkAppsError(error instanceof Error && error.message
294
+ ? error.message
295
+ : paymentRequestConflictMessages.PAYMENT_REQUEST_UNAVAILABLE);
296
+ }
297
+ /**
298
+ * Load the latest submission for a payment request. The token is the secret
299
+ * from the review link and is not stored by the client beyond this call. Throws
300
+ * an `OneBlinkAppsError` when the link can no longer be used.
301
+ */
302
+ export async function reviewFormSubmissionPaymentRequest(paymentRequestToken, abortSignal) {
303
+ if (!paymentRequestToken) {
304
+ throw new OneBlinkAppsError(paymentRequestConflictMessages.PAYMENT_REQUEST_NOT_FOUND);
305
+ }
306
+ try {
307
+ return await postRequest(`${tenants.current.apiOrigin}/form-submission-payment-requests/review`, { paymentRequestToken }, abortSignal);
308
+ }
309
+ catch (error) {
310
+ throwPaymentRequestError(error);
311
+ }
312
+ }
313
+ /**
314
+ * Start checkout for a payment request and store the result for the receipt
315
+ * page. The hosted payment URL is built by the server from the submission's
316
+ * forms app.
317
+ *
318
+ * #### Example
319
+ *
320
+ * ```js
321
+ * const payment = await paymentService.startFormSubmissionPaymentRequest(
322
+ * paymentRequestToken,
323
+ * {
324
+ * form,
325
+ * submission,
326
+ * submissionId: '89c6e98e-f56f-45fc-84fe-c4fc62331d34',
327
+ * paymentReceiptUrl: `${window.location.origin}/payment-receipt`,
328
+ * paymentFormUrl: `${window.location.origin}/payment-form`,
329
+ * },
330
+ * )
331
+ * ```
332
+ *
333
+ * @param paymentRequestToken The secret from the review link.
334
+ * @param options
335
+ * @param options.form The form definition returned by the review.
336
+ * @param options.submission The submission returned by the review.
337
+ * @param options.submissionId The submission this payment belongs to.
338
+ * @param options.paymentReceiptUrl The URL the payment provider redirects to
339
+ * when the payment finishes.
340
+ * @param options.paymentFormUrl The in-app payment page. Required for providers
341
+ * that render their payment form in the app.
342
+ * @returns
343
+ * @throws {OneBlinkAppsError} When the payment request can no longer be paid.
344
+ */
345
+ export async function startFormSubmissionPaymentRequest(paymentRequestToken, options) {
346
+ let result;
347
+ try {
348
+ result = await postRequest(`${tenants.current.apiOrigin}/form-submission-payment-requests/start`, { paymentRequestToken });
349
+ }
350
+ catch (error) {
351
+ throwPaymentRequestError(error);
352
+ }
353
+ await rememberPaymentSubmissionResult({
354
+ submission: options.submission,
355
+ // The post-submission receipt is written for the original submitter.
356
+ definition: {
357
+ ...options.form,
358
+ postSubmissionReceipt: undefined,
359
+ },
360
+ preFillFormDataId: null,
361
+ submissionId: options.submissionId,
362
+ submissionTimestamp: new Date().toISOString(),
363
+ payment: {
364
+ amount: result.amount,
365
+ paymentReceiptUrl: options.paymentReceiptUrl,
366
+ paymentFormUrl: options.paymentFormUrl,
367
+ hostedFormUrl: result.hostedFormUrl,
368
+ submissionEvent: result.paymentSubmissionEvent,
369
+ },
370
+ scheduling: null,
371
+ isInPendingQueue: false,
372
+ isOffline: false,
373
+ isUploadingAttachments: false,
374
+ });
375
+ return result;
376
+ }
235
377
  /**
236
378
  * Retrieve the failure message and provider response fields for a form
237
379
  * submission payment. Returns an empty array unless the payment failed.
@@ -1 +1 @@
1
- {"version":3,"file":"payment-service.js","sourceRoot":"","sources":["../../src/apps/payment-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,iBAAiB,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAA;AAQnE,OAAO,qBAAqB,MAA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;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,0CAA0C,CACxD,qBAA4D;IAE5D,OAAO,cAAc,CAAC,0CAA0C,CAC9D,qBAAqB,EACrB,2BAA2B,CAC5B,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,0CAA0C,CACxD,qBAA4D;IAE5D,OAAO,cAAc,CAAC,0CAA0C,CAC9D,qBAAqB,CACtB,CAAA;AACH,CAAC","sourcesContent":["import { paymentService } from '@oneblink/sdk-core'\nimport OneBlinkAppsError from './services/errors/oneBlinkAppsError'\nimport { createPaymentConfiguration } from './services/api/payment'\nimport { SubmissionEventTypes, SubmissionTypes } from '@oneblink/types'\nimport { FormSubmission, FormSubmissionResult } from './types/submissions'\nimport {\n HandlePaymentResult,\n PaymentProvider,\n PaymentReceiptItem,\n} from './types/payments'\nimport BPOINTPaymentProvider from './services/payment-providers/BPOINTPaymentProvider'\nimport CPPayPaymentProvider from './services/payment-providers/CPPayPaymentProvider'\nimport NSWGovPayPaymentProvider from './services/payment-providers/NSWGovPayPaymentProvider'\nimport WestpacQuickStreamPaymentProvider, * as westpacQuickStream from './services/payment-providers/WestpacQuickStreamPaymentProvider'\nimport {\n addDaysToDate,\n endOfDay,\n parseDayOnlyDate,\n startOfDay,\n replaceSubmissionFormatters,\n} from './localisation-service'\nimport {\n getPaymentFormSession,\n getPaymentHandoff,\n paymentProviderRendersInApp,\n type InAppPaymentType,\n type PaymentFormSession,\n} from './services/payment-handoff'\nimport {\n getSchedulingBooking,\n removeSchedulingBooking,\n} from './services/schedulingHandlers'\nimport {\n retrieveFormSubmissionResult,\n rememberPaymentSubmissionResult,\n} from './services/payment-submission-result'\n\nexport { HandlePaymentResult, PaymentReceiptItem, westpacQuickStream }\nexport { paymentProviderRendersInApp, getPaymentHandoff, getPaymentFormSession }\nexport type { InAppPaymentType, PaymentFormSession }\n\n/**\n * Receipt URLs for providers whose payment form is rendered by the app. Add a\n * new in-app provider here so hosts of that form can redirect to a receipt\n * without knowing which provider took the payment.\n */\nfunction getInAppPaymentReceipts(formSubmissionResult: FormSubmissionResult) {\n const paymentType = formSubmissionResult.payment?.submissionEvent.type\n if (!paymentType || !paymentProviderRendersInApp(paymentType)) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for an unsupported payment.',\n )\n }\n\n switch (paymentType) {\n case 'WESTPAC_QUICK_STREAM': {\n return westpacQuickStream\n }\n default: {\n const unsupportedPaymentType: never = paymentType\n throw new OneBlinkAppsError(\n `It looks like you are attempting to view a receipt for an unsupported payment (${unsupportedPaymentType}).`,\n )\n }\n }\n}\n\n/**\n * Get the receipt URL for a completed in-app payment. The receipt page verifies\n * the transaction from the query parameters on this URL.\n *\n * @param options\n * @returns\n */\nexport function getCompletedPaymentReceiptUrl(options: {\n formSubmissionResult: FormSubmissionResult\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment\n}): string {\n return getInAppPaymentReceipts(\n options.formSubmissionResult,\n ).getCompletedPaymentReceiptUrl(options)\n}\n\n/**\n * Get the receipt URL for a cancelled in-app payment.\n *\n * @param formSubmissionResult\n * @param formSubmissionPaymentId\n * @returns\n */\nexport function getCancelledPaymentReceiptUrl(\n formSubmissionResult: FormSubmissionResult,\n formSubmissionPaymentId: string,\n): string {\n return getInAppPaymentReceipts(\n formSubmissionResult,\n ).getCancelledPaymentReceiptUrl(formSubmissionResult, formSubmissionPaymentId)\n}\n\nfunction getPaymentProvider(\n formSubmissionResult: FormSubmissionResult,\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent,\n): PaymentProvider<SubmissionEventTypes.FormPaymentEvent> {\n switch (paymentSubmissionEvent.type) {\n case 'BPOINT': {\n return new BPOINTPaymentProvider(\n paymentSubmissionEvent,\n formSubmissionResult,\n )\n }\n case 'CP_PAY': {\n return new CPPayPaymentProvider(\n paymentSubmissionEvent,\n formSubmissionResult,\n )\n }\n case 'NSW_GOV_PAY': {\n return new NSWGovPayPaymentProvider(\n paymentSubmissionEvent,\n formSubmissionResult,\n )\n }\n case 'WESTPAC_QUICK_STREAM': {\n return new WestpacQuickStreamPaymentProvider(\n paymentSubmissionEvent,\n formSubmissionResult,\n )\n }\n }\n}\n\n/**\n * Pass in query string parameters after a redirect back to your app after a\n * payment is processed. This function will handle all payment submission events\n * supported by OneBlink. Will return a Transaction and the submission result\n * that was returned from `handlePaymentSubmissionEvent()` before redirecting to\n * `payment.hostedFormUrl`.\n *\n * #### Example\n *\n * ```js\n * import queryString from 'query-string'\n *\n * const query = queryString.parse(window.location.search)\n * const { transaction, submissionResult } =\n * await paymentService.handlePaymentQuerystring(query)\n * ```\n *\n * @param query\n * @returns\n */\nexport async function handlePaymentQuerystring(\n query: Record<string, unknown>,\n): Promise<HandlePaymentResult> {\n const submissionResult = await retrieveFormSubmissionResult()\n // If the current transaction does not match the submission\n // we will display message to user indicating\n // they are looking for the wrong transaction receipt.\n if (!submissionResult) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for an unknown payment.',\n )\n }\n if (!submissionResult.payment || !submissionResult.payment.submissionEvent) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for a misconfigured payment.',\n )\n }\n const paymentProvider = getPaymentProvider(\n submissionResult,\n submissionResult.payment.submissionEvent,\n )\n if (!paymentProvider) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for an unsupported payment.',\n )\n }\n\n const verifiedPaymentTransaction =\n await paymentProvider.verifyPaymentTransaction(query)\n\n const schedulingBooking = await getSchedulingBooking(\n verifiedPaymentTransaction.submissionResult.submissionId,\n )\n if (schedulingBooking && verifiedPaymentTransaction.transaction.isSuccess) {\n await removeSchedulingBooking(schedulingBooking.submissionId)\n }\n\n return {\n ...verifiedPaymentTransaction,\n schedulingBooking,\n }\n}\n\nexport function checkForPaymentSubmissionEvent(\n formSubmission: FormSubmission,\n submissionTimestamp: string,\n): SubmissionEventTypes.FormPaymentEvent | undefined {\n const result = paymentService.checkForPaymentEvent({\n definition: formSubmission.definition,\n submission: formSubmission.submission,\n submissionTimestamp,\n parseDayOnlyDate,\n addDaysToDate,\n startOfDay,\n endOfDay,\n })\n if (result) {\n console.log('Form has a payment submission event with amount', result)\n return result.paymentSubmissionEvent\n }\n return undefined\n}\n\n/**\n * Handle a submission result with a payment submission event. Will throw an\n * error if a transaction has already been made using this submission result.\n * Will return `undefined` if the submission does not have an amount. Will\n * return the submission result passed in with a `payment` property if the\n * submission requires processing.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionResult = {\n * submissionId: '89c6e98e-f56f-45fc-84fe-c4fc62331d34',\n * submissionTimestamp: '2020-07-29T01:03:26.573Z'\n * formsAppId: 1,\n * submission: {\n * form: 'data',\n * goes: 'here',\n * amount: 1.50,\n * }\n * definition: OneBlinkForm,\n * payment: null,\n * }\n * const paymentSubmissionEvent = {\n * type: 'CP_PAY',\n * configuration: {\n * elementId: '12663efc-4c6a-4e72-8505-559edfe3e92e',\n * gatewayId: '6658c5c4-e0db-483b-8af7-6a6464fe772c',\n * },\n * }\n * const paymentReceiptUrl = `${window.location.origin}/payment-receipt`\n * const paymentSubmissionResult = await paymentService.handlePaymentSubmissionEvent({\n * formSubmissionResult,\n * paymentSubmissionEvent,\n * paymentReceiptUrl,\n * })\n * if (paymentSubmissionResult) {\n * window.location.href = paymentSubmissionResult.payment.hostedFormUrl\n * }\n * ```\n *\n * @param options\n * @returns\n */\nexport async function handlePaymentSubmissionEvent({\n formSubmissionResult,\n paymentReceiptUrl,\n paymentFormUrl,\n}: {\n formSubmissionResult: FormSubmissionResult\n paymentReceiptUrl: string\n paymentFormUrl: string | undefined\n}): Promise<FormSubmissionResult['payment']> {\n if (!formSubmissionResult.submissionId) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to make a payment for an unknown submission.',\n )\n }\n const paymentConfiguration = await createPaymentConfiguration(\n formSubmissionResult.submissionId,\n { redirectUrl: paymentReceiptUrl, paymentFormUrl },\n )\n\n if (!paymentConfiguration) {\n await rememberPaymentSubmissionResult({\n ...formSubmissionResult,\n scheduling: null,\n payment: null,\n })\n return null\n }\n\n const payment = {\n submissionEvent: paymentConfiguration.paymentSubmissionEvent,\n paymentReceiptUrl,\n hostedFormUrl: paymentConfiguration.hostedFormUrl,\n paymentFormUrl,\n amount: paymentConfiguration.amount,\n }\n console.log('Created Payment configuration to start transaction', payment)\n\n await rememberPaymentSubmissionResult({\n ...formSubmissionResult,\n scheduling: null,\n payment,\n })\n\n return payment\n}\n\nexport async function getFormSubmissionResultPayment(): Promise<{\n formSubmissionResult: FormSubmissionResult\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n}> {\n const formSubmissionResult = await retrieveFormSubmissionResult()\n\n if (!formSubmissionResult) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to complete a transaction for an unknown payment.',\n )\n }\n if (!formSubmissionResult.payment?.submissionEvent) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to complete a transaction for a misconfigured payment.',\n )\n }\n\n return {\n formSubmissionResult,\n paymentSubmissionEvent: formSubmissionResult.payment?.submissionEvent,\n }\n}\n\n/**\n * Retrieve an array of detail items from a form submission payment.\n *\n * #### Example\n *\n * ```js\n * const detailItems =\n * paymentService.getDisplayDetailsFromFormSubmissionPayment(\n * formSubmissionPayment,\n * )\n * ```\n *\n * @param formSubmissionPayment\n * @returns\n */\nexport function getDisplayDetailsFromFormSubmissionPayment(\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment,\n) {\n return paymentService.getDisplayDetailsFromFormSubmissionPayment(\n formSubmissionPayment,\n replaceSubmissionFormatters,\n )\n}\n\n/**\n * Retrieve the failure message and provider response fields for a form\n * submission payment. Returns an empty array unless the payment failed.\n *\n * #### Example\n *\n * ```js\n * const failureDetails =\n * paymentService.getFailureDetailsFromFormSubmissionPayment(\n * formSubmissionPayment,\n * )\n * ```\n *\n * @param formSubmissionPayment\n * @returns\n */\nexport function getFailureDetailsFromFormSubmissionPayment(\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment,\n) {\n return paymentService.getFailureDetailsFromFormSubmissionPayment(\n formSubmissionPayment,\n )\n}\n"]}
1
+ {"version":3,"file":"payment-service.js","sourceRoot":"","sources":["../../src/apps/payment-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,iBAAiB,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAA;AAYnE,OAAO,qBAAqB,MAAM,oDAAoD,CAAA;AACtF,OAAO,oBAAoB,MAAM,mDAAmD,CAAA;AACpF,OAAO,wBAAwB,MAAM,uDAAuD,CAAA;AAC5F,OAAO,iCAAiC,EAAE,KAAK,kBAAkB,MAAM,gEAAgE,CAAA;AACvI,OAAO,EACL,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,UAAU,EACV,2BAA2B,GAC5B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,2BAA2B,GAG5B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EACL,4BAA4B,EAC5B,+BAA+B,GAChC,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,OAAO,EAA2C,kBAAkB,EAAE,CAAA;AACtE,OAAO,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,CAAA;AAChF,OAAO,EAAE,+BAA+B,EAAE,CAAA;AAG1C;;;;GAIG;AACH,SAAS,uBAAuB,CAAC,oBAA0C;;IACzE,MAAM,WAAW,GAAG,MAAA,oBAAoB,CAAC,OAAO,0CAAE,eAAe,CAAC,IAAI,CAAA;IACtE,IAAI,CAAC,WAAW,IAAI,CAAC,2BAA2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AAa;YACnC,eAAe,EAAE,MAAM,CAAC,sBAAsB;SAC/C;QACD,UAAU,EAAE,IAAI;QAChB,gBAAgB,EAAE,KAAK;QACvB,SAAS,EAAE,KAAK;QAChB,sBAAsB,EAAE,KAAK;KAC9B,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,0CAA0C,CACxD,qBAA4D;IAE5D,OAAO,cAAc,CAAC,0CAA0C,CAC9D,qBAAqB,CACtB,CAAA;AACH,CAAC","sourcesContent":["import { paymentService } from '@oneblink/sdk-core'\nimport OneBlinkAppsError from './services/errors/oneBlinkAppsError'\nimport { createPaymentConfiguration } from './services/api/payment'\nimport {\n FormTypes,\n SubmissionEventTypes,\n SubmissionTypes,\n} from '@oneblink/types'\nimport { FormSubmission, FormSubmissionResult } from './types/submissions'\nimport {\n HandlePaymentResult,\n PaymentProvider,\n PaymentReceiptItem,\n} from './types/payments'\nimport BPOINTPaymentProvider from './services/payment-providers/BPOINTPaymentProvider'\nimport CPPayPaymentProvider from './services/payment-providers/CPPayPaymentProvider'\nimport NSWGovPayPaymentProvider from './services/payment-providers/NSWGovPayPaymentProvider'\nimport WestpacQuickStreamPaymentProvider, * as westpacQuickStream from './services/payment-providers/WestpacQuickStreamPaymentProvider'\nimport {\n addDaysToDate,\n endOfDay,\n parseDayOnlyDate,\n startOfDay,\n replaceSubmissionFormatters,\n} from './localisation-service'\nimport {\n getPaymentFormSession,\n getPaymentHandoff,\n paymentProviderRendersInApp,\n type InAppPaymentType,\n type PaymentFormSession,\n} from './services/payment-handoff'\nimport {\n getSchedulingBooking,\n removeSchedulingBooking,\n} from './services/schedulingHandlers'\nimport {\n retrieveFormSubmissionResult,\n rememberPaymentSubmissionResult,\n} from './services/payment-submission-result'\nimport { HTTPError, postRequest } from './services/fetch'\nimport tenants from './tenants'\n\nexport { HandlePaymentResult, PaymentReceiptItem, westpacQuickStream }\nexport { paymentProviderRendersInApp, getPaymentHandoff, getPaymentFormSession }\nexport { rememberPaymentSubmissionResult }\nexport type { InAppPaymentType, PaymentFormSession }\n\n/**\n * Receipt URLs for providers whose payment form is rendered by the app. Add a\n * new in-app provider here so hosts of that form can redirect to a receipt\n * without knowing which provider took the payment.\n */\nfunction getInAppPaymentReceipts(formSubmissionResult: FormSubmissionResult) {\n const paymentType = formSubmissionResult.payment?.submissionEvent.type\n if (!paymentType || !paymentProviderRendersInApp(paymentType)) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for an unsupported payment.',\n )\n }\n\n switch (paymentType) {\n case 'WESTPAC_QUICK_STREAM': {\n return westpacQuickStream\n }\n default: {\n const unsupportedPaymentType: never = paymentType\n throw new OneBlinkAppsError(\n `It looks like you are attempting to view a receipt for an unsupported payment (${unsupportedPaymentType}).`,\n )\n }\n }\n}\n\n/**\n * Get the receipt URL for a completed in-app payment. The receipt page verifies\n * the transaction from the query parameters on this URL.\n *\n * @param options\n * @returns\n */\nexport function getCompletedPaymentReceiptUrl(options: {\n formSubmissionResult: FormSubmissionResult\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment\n}): string {\n return getInAppPaymentReceipts(\n options.formSubmissionResult,\n ).getCompletedPaymentReceiptUrl(options)\n}\n\n/**\n * Get the receipt URL for a cancelled in-app payment.\n *\n * @param formSubmissionResult\n * @param formSubmissionPaymentId\n * @returns\n */\nexport function getCancelledPaymentReceiptUrl(\n formSubmissionResult: FormSubmissionResult,\n formSubmissionPaymentId: string,\n): string {\n return getInAppPaymentReceipts(\n formSubmissionResult,\n ).getCancelledPaymentReceiptUrl(formSubmissionResult, formSubmissionPaymentId)\n}\n\nfunction getPaymentProvider(\n formSubmissionResult: FormSubmissionResult,\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent,\n): PaymentProvider<SubmissionEventTypes.FormPaymentEvent> {\n switch (paymentSubmissionEvent.type) {\n case 'BPOINT': {\n return new BPOINTPaymentProvider(\n paymentSubmissionEvent,\n formSubmissionResult,\n )\n }\n case 'CP_PAY': {\n return new CPPayPaymentProvider(\n paymentSubmissionEvent,\n formSubmissionResult,\n )\n }\n case 'NSW_GOV_PAY': {\n return new NSWGovPayPaymentProvider(\n paymentSubmissionEvent,\n formSubmissionResult,\n )\n }\n case 'WESTPAC_QUICK_STREAM': {\n return new WestpacQuickStreamPaymentProvider(\n paymentSubmissionEvent,\n formSubmissionResult,\n )\n }\n }\n}\n\n/**\n * Pass in query string parameters after a redirect back to your app after a\n * payment is processed. This function will handle all payment submission events\n * supported by OneBlink. Will return a Transaction and the submission result\n * that was returned from `handlePaymentSubmissionEvent()` before redirecting to\n * `payment.hostedFormUrl`.\n *\n * #### Example\n *\n * ```js\n * import queryString from 'query-string'\n *\n * const query = queryString.parse(window.location.search)\n * const { transaction, submissionResult } =\n * await paymentService.handlePaymentQuerystring(query)\n * ```\n *\n * @param query\n * @returns\n */\nexport async function handlePaymentQuerystring(\n query: Record<string, unknown>,\n): Promise<HandlePaymentResult> {\n const submissionResult = await retrieveFormSubmissionResult()\n // If the current transaction does not match the submission\n // we will display message to user indicating\n // they are looking for the wrong transaction receipt.\n if (!submissionResult) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for an unknown payment.',\n )\n }\n if (!submissionResult.payment || !submissionResult.payment.submissionEvent) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for a misconfigured payment.',\n )\n }\n const paymentProvider = getPaymentProvider(\n submissionResult,\n submissionResult.payment.submissionEvent,\n )\n if (!paymentProvider) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for an unsupported payment.',\n )\n }\n\n const verifiedPaymentTransaction =\n await paymentProvider.verifyPaymentTransaction(query)\n\n const schedulingBooking = await getSchedulingBooking(\n verifiedPaymentTransaction.submissionResult.submissionId,\n )\n if (schedulingBooking && verifiedPaymentTransaction.transaction.isSuccess) {\n await removeSchedulingBooking(schedulingBooking.submissionId)\n }\n\n return {\n ...verifiedPaymentTransaction,\n schedulingBooking,\n }\n}\n\nexport function checkForPaymentSubmissionEvent(\n formSubmission: FormSubmission,\n submissionTimestamp: string,\n): SubmissionEventTypes.FormPaymentEvent | undefined {\n const result = paymentService.checkForPaymentEvent({\n definition: formSubmission.definition,\n submission: formSubmission.submission,\n submissionTimestamp,\n parseDayOnlyDate,\n addDaysToDate,\n startOfDay,\n endOfDay,\n })\n if (result) {\n console.log('Form has a payment submission event with amount', result)\n return result.paymentSubmissionEvent\n }\n return undefined\n}\n\n/**\n * Handle a submission result with a payment submission event. Will throw an\n * error if a transaction has already been made using this submission result.\n * Will return `undefined` if the submission does not have an amount. Will\n * return the submission result passed in with a `payment` property if the\n * submission requires processing.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionResult = {\n * submissionId: '89c6e98e-f56f-45fc-84fe-c4fc62331d34',\n * submissionTimestamp: '2020-07-29T01:03:26.573Z'\n * formsAppId: 1,\n * submission: {\n * form: 'data',\n * goes: 'here',\n * amount: 1.50,\n * }\n * definition: OneBlinkForm,\n * payment: null,\n * }\n * const paymentSubmissionEvent = {\n * type: 'CP_PAY',\n * configuration: {\n * elementId: '12663efc-4c6a-4e72-8505-559edfe3e92e',\n * gatewayId: '6658c5c4-e0db-483b-8af7-6a6464fe772c',\n * },\n * }\n * const paymentReceiptUrl = `${window.location.origin}/payment-receipt`\n * const paymentSubmissionResult = await paymentService.handlePaymentSubmissionEvent({\n * formSubmissionResult,\n * paymentSubmissionEvent,\n * paymentReceiptUrl,\n * })\n * if (paymentSubmissionResult) {\n * window.location.href = paymentSubmissionResult.payment.hostedFormUrl\n * }\n * ```\n *\n * @param options\n * @returns\n */\nexport async function handlePaymentSubmissionEvent({\n formSubmissionResult,\n paymentReceiptUrl,\n paymentFormUrl,\n}: {\n formSubmissionResult: FormSubmissionResult\n paymentReceiptUrl: string\n paymentFormUrl: string | undefined\n}): Promise<FormSubmissionResult['payment']> {\n if (!formSubmissionResult.submissionId) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to make a payment for an unknown submission.',\n )\n }\n const paymentConfiguration = await createPaymentConfiguration(\n formSubmissionResult.submissionId,\n { redirectUrl: paymentReceiptUrl, paymentFormUrl },\n )\n\n if (!paymentConfiguration) {\n await rememberPaymentSubmissionResult({\n ...formSubmissionResult,\n scheduling: null,\n payment: null,\n })\n return null\n }\n\n const payment = {\n submissionEvent: paymentConfiguration.paymentSubmissionEvent,\n paymentReceiptUrl,\n hostedFormUrl: paymentConfiguration.hostedFormUrl,\n paymentFormUrl,\n amount: paymentConfiguration.amount,\n }\n console.log('Created Payment configuration to start transaction', payment)\n\n await rememberPaymentSubmissionResult({\n ...formSubmissionResult,\n scheduling: null,\n payment,\n })\n\n return payment\n}\n\nexport async function getFormSubmissionResultPayment(): Promise<{\n formSubmissionResult: FormSubmissionResult\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n}> {\n const formSubmissionResult = await retrieveFormSubmissionResult()\n\n if (!formSubmissionResult) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to complete a transaction for an unknown payment.',\n )\n }\n if (!formSubmissionResult.payment?.submissionEvent) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to complete a transaction for a misconfigured payment.',\n )\n }\n\n return {\n formSubmissionResult,\n paymentSubmissionEvent: formSubmissionResult.payment?.submissionEvent,\n }\n}\n\n/**\n * Retrieve an array of detail items from a form submission payment.\n *\n * #### Example\n *\n * ```js\n * const detailItems =\n * paymentService.getDisplayDetailsFromFormSubmissionPayment(\n * formSubmissionPayment,\n * )\n * ```\n *\n * @param formSubmissionPayment\n * @returns\n */\nexport function getDisplayDetailsFromFormSubmissionPayment(\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment,\n) {\n return paymentService.getDisplayDetailsFromFormSubmissionPayment(\n formSubmissionPayment,\n replaceSubmissionFormatters,\n )\n}\n\nconst paymentRequestConflictMessages = {\n PAYMENT_REQUEST_NOT_FOUND: 'This payment link is not valid.',\n PAYMENT_REQUEST_ALREADY_PAID: 'This payment has already been completed.',\n PAYMENT_REQUEST_SKIPPED:\n 'This payment was skipped, so there is nothing to pay.',\n PAYMENT_REQUEST_DENIED: 'This payment was denied and can no longer be paid.',\n PAYMENT_REQUEST_CLARIFICATION_REQUIRED:\n 'This submission was sent back for clarification, so this payment link can no longer be used.',\n PAYMENT_REQUEST_SUBMISSION_REMOVED:\n 'The submission for this payment has been removed, so it can no longer be paid.',\n PAYMENT_REQUEST_UNAVAILABLE: 'This payment request is no longer available.',\n PAYMENT_IN_PROGRESS:\n 'A payment is already in progress for this step. Finish that payment before starting another.',\n} as const\n\nfunction paymentRequestConflictMessage(\n conflict: string | undefined,\n): string | undefined {\n switch (conflict) {\n case 'PAYMENT_REQUEST_NOT_FOUND': {\n return paymentRequestConflictMessages.PAYMENT_REQUEST_NOT_FOUND\n }\n case 'PAYMENT_REQUEST_ALREADY_PAID': {\n return paymentRequestConflictMessages.PAYMENT_REQUEST_ALREADY_PAID\n }\n case 'PAYMENT_REQUEST_SKIPPED': {\n return paymentRequestConflictMessages.PAYMENT_REQUEST_SKIPPED\n }\n case 'PAYMENT_REQUEST_DENIED': {\n return paymentRequestConflictMessages.PAYMENT_REQUEST_DENIED\n }\n case 'PAYMENT_REQUEST_CLARIFICATION_REQUIRED': {\n return paymentRequestConflictMessages.PAYMENT_REQUEST_CLARIFICATION_REQUIRED\n }\n case 'PAYMENT_REQUEST_SUBMISSION_REMOVED': {\n return paymentRequestConflictMessages.PAYMENT_REQUEST_SUBMISSION_REMOVED\n }\n case 'PAYMENT_REQUEST_UNAVAILABLE': {\n return paymentRequestConflictMessages.PAYMENT_REQUEST_UNAVAILABLE\n }\n case 'PAYMENT_IN_PROGRESS': {\n return paymentRequestConflictMessages.PAYMENT_IN_PROGRESS\n }\n default: {\n return undefined\n }\n }\n}\n\nfunction throwPaymentRequestError(error: unknown): never {\n if (error instanceof OneBlinkAppsError) {\n throw error\n }\n if (error instanceof HTTPError) {\n throw new OneBlinkAppsError(\n paymentRequestConflictMessage(error.conflict) ??\n (error.status === 409\n ? paymentRequestConflictMessages.PAYMENT_REQUEST_UNAVAILABLE\n : error.message ||\n paymentRequestConflictMessages.PAYMENT_REQUEST_UNAVAILABLE),\n {\n httpStatusCode: error.status,\n conflict: error.conflict,\n },\n )\n }\n throw new OneBlinkAppsError(\n error instanceof Error && error.message\n ? error.message\n : paymentRequestConflictMessages.PAYMENT_REQUEST_UNAVAILABLE,\n )\n}\n\n/**\n * Load the latest submission for a payment request. The token is the secret\n * from the review link and is not stored by the client beyond this call. Throws\n * an `OneBlinkAppsError` when the link can no longer be used.\n */\nexport async function reviewFormSubmissionPaymentRequest(\n paymentRequestToken: string,\n abortSignal?: AbortSignal,\n): Promise<{\n form: FormTypes.Form\n submission: SubmissionTypes.S3SubmissionData['submission']\n submissionId: string\n}> {\n if (!paymentRequestToken) {\n throw new OneBlinkAppsError(\n paymentRequestConflictMessages.PAYMENT_REQUEST_NOT_FOUND,\n )\n }\n try {\n return await postRequest(\n `${tenants.current.apiOrigin}/form-submission-payment-requests/review`,\n { paymentRequestToken },\n abortSignal,\n )\n } catch (error) {\n throwPaymentRequestError(error)\n }\n}\n\n/**\n * Start checkout for a payment request and store the result for the receipt\n * page. The hosted payment URL is built by the server from the submission's\n * forms app.\n *\n * #### Example\n *\n * ```js\n * const payment = await paymentService.startFormSubmissionPaymentRequest(\n * paymentRequestToken,\n * {\n * form,\n * submission,\n * submissionId: '89c6e98e-f56f-45fc-84fe-c4fc62331d34',\n * paymentReceiptUrl: `${window.location.origin}/payment-receipt`,\n * paymentFormUrl: `${window.location.origin}/payment-form`,\n * },\n * )\n * ```\n *\n * @param paymentRequestToken The secret from the review link.\n * @param options\n * @param options.form The form definition returned by the review.\n * @param options.submission The submission returned by the review.\n * @param options.submissionId The submission this payment belongs to.\n * @param options.paymentReceiptUrl The URL the payment provider redirects to\n * when the payment finishes.\n * @param options.paymentFormUrl The in-app payment page. Required for providers\n * that render their payment form in the app.\n * @returns\n * @throws {OneBlinkAppsError} When the payment request can no longer be paid.\n */\nexport async function startFormSubmissionPaymentRequest(\n paymentRequestToken: string,\n options: {\n form: FormTypes.Form\n submission: SubmissionTypes.S3SubmissionData['submission']\n submissionId: string\n paymentReceiptUrl: string\n paymentFormUrl?: string\n },\n): Promise<{\n hostedFormUrl: string\n amount: number\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n customerReferenceNumber?: string\n}> {\n let result: {\n hostedFormUrl: string\n amount: number\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n customerReferenceNumber?: string\n }\n try {\n result = await postRequest(\n `${tenants.current.apiOrigin}/form-submission-payment-requests/start`,\n { paymentRequestToken },\n )\n } catch (error) {\n throwPaymentRequestError(error)\n }\n\n await rememberPaymentSubmissionResult({\n submission: options.submission,\n // The post-submission receipt is written for the original submitter.\n definition: {\n ...options.form,\n postSubmissionReceipt: undefined,\n },\n preFillFormDataId: null,\n submissionId: options.submissionId,\n submissionTimestamp: new Date().toISOString(),\n payment: {\n amount: result.amount,\n paymentReceiptUrl: options.paymentReceiptUrl,\n paymentFormUrl: options.paymentFormUrl,\n hostedFormUrl: result.hostedFormUrl,\n submissionEvent: result.paymentSubmissionEvent,\n },\n scheduling: null,\n isInPendingQueue: false,\n isOffline: false,\n isUploadingAttachments: false,\n })\n\n return result\n}\n\n/**\n * Retrieve the failure message and provider response fields for a form\n * submission payment. Returns an empty array unless the payment failed.\n *\n * #### Example\n *\n * ```js\n * const failureDetails =\n * paymentService.getFailureDetailsFromFormSubmissionPayment(\n * formSubmissionPayment,\n * )\n * ```\n *\n * @param formSubmissionPayment\n * @returns\n */\nexport function getFailureDetailsFromFormSubmissionPayment(\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment,\n) {\n return paymentService.getFailureDetailsFromFormSubmissionPayment(\n formSubmissionPayment,\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.7.0",
4
+ "version": "13.8.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"