@oneblink/apps-react 11.1.1-beta.1 → 11.1.1-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -183,14 +183,22 @@ export declare function generateDate({ daysOffset, value, }: {
183
183
  value: string;
184
184
  }): Date | undefined;
185
185
  /**
186
- * Parse a date/datetime string for conditional logic evaluation. Date-only
187
- * values (`YYYY-MM-DD`) are interpreted in the user's local timezone.
186
+ * Parse a day-only (`YYYY-MM-DD`) string for conditional logic evaluation in
187
+ * the user's local timezone. sdk-core only calls this for day-only values.
188
188
  */
189
- export declare function parseDate(value: string): Date;
189
+ export declare function parseDayOnlyDate(value: string): Date;
190
190
  /**
191
191
  * Add calendar days to a date for conditional logic evaluation.
192
192
  */
193
193
  export declare function addDaysToDate(date: Date, days: number): Date;
194
+ /**
195
+ * Start of calendar day in the user's local timezone for conditional logic.
196
+ */
197
+ export declare function startOfDay(date: Date): Date;
198
+ /**
199
+ * End of calendar day in the user's local timezone for conditional logic.
200
+ */
201
+ export declare function endOfDay(date: Date): Date;
194
202
  export declare const replaceSubmissionFormatters: submissionService.ReplaceInjectablesFormatters;
195
203
  /**
196
204
  * Replace the `{ELEMENT:<elementName>}` values in text after a successful form
@@ -1,7 +1,7 @@
1
1
  import { submissionService } from '@oneblink/sdk-core';
2
2
  import tenants from './tenants';
3
3
  import parser from 'ua-parser-js';
4
- import { add, parse } from 'date-fns';
4
+ import { add, endOfDay as dateFnsEndOfDay, parse, startOfDay as dateFnsStartOfDay, } from 'date-fns';
5
5
  let iosVersion;
6
6
  const parsedUserAgent = parser(window.navigator.userAgent);
7
7
  if (parsedUserAgent.os.name === 'iOS' &&
@@ -271,10 +271,10 @@ function generateDateOffset({ date, daysOffset, }) {
271
271
  return date;
272
272
  }
273
273
  /**
274
- * Parse a date/datetime string for conditional logic evaluation. Date-only
275
- * values (`YYYY-MM-DD`) are interpreted in the user's local timezone.
274
+ * Parse a day-only (`YYYY-MM-DD`) string for conditional logic evaluation in
275
+ * the user's local timezone. sdk-core only calls this for day-only values.
276
276
  */
277
- export function parseDate(value) {
277
+ export function parseDayOnlyDate(value) {
278
278
  var _a;
279
279
  // Always return a Date so callers can use Number.isNaN(date.getTime()) to
280
280
  // detect unparseable values. generateDate returns undefined in that case.
@@ -289,6 +289,18 @@ export function parseDate(value) {
289
289
  export function addDaysToDate(date, days) {
290
290
  return add(date, { days });
291
291
  }
292
+ /**
293
+ * Start of calendar day in the user's local timezone for conditional logic.
294
+ */
295
+ export function startOfDay(date) {
296
+ return dateFnsStartOfDay(date);
297
+ }
298
+ /**
299
+ * End of calendar day in the user's local timezone for conditional logic.
300
+ */
301
+ export function endOfDay(date) {
302
+ return dateFnsEndOfDay(date);
303
+ }
292
304
  export const replaceSubmissionFormatters = {
293
305
  formatDate: (v) => {
294
306
  const date = generateDate({
@@ -1 +1 @@
1
- {"version":3,"file":"localisation-service.js","sourceRoot":"","sources":["../../src/apps/localisation-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,MAAM,MAAM,cAAc,CAAA;AACjC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAErC,IAAI,UAA8B,CAAA;AAClC,MAAM,eAAe,GAAmB,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;AAC1E,IACE,eAAe,CAAC,EAAE,CAAC,IAAI,KAAK,KAAK;IACjC,OAAO,eAAe,CAAC,EAAE,CAAC,OAAO,KAAK,QAAQ,EAC9C,CAAC;IACD,UAAU,GAAG,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC,OAAO,CAAC,CAAA;IACnD,IAAI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7B,UAAU,GAAG,SAAS,CAAA;IACxB,CAAC;AACH,CAAC;AAED;;;;;;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AO;QACV,GAAG,2BAA2B;KAC/B,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,mCAAmC,CACjD,IAAY,EACZ,OAGC;IAED,OAAO,iBAAiB,CAAC,mCAAmC,CAAC,IAAI,EAAE;QACjE,GAAG,OAAO;QACV,GAAG,2BAA2B;KAC/B,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { submissionService } from '@oneblink/sdk-core'\nimport tenants from './tenants'\nimport parser from 'ua-parser-js'\nimport { add, parse } from 'date-fns'\n\nlet iosVersion: number | undefined\nconst parsedUserAgent: parser.IResult = parser(window.navigator.userAgent)\nif (\n parsedUserAgent.os.name === 'iOS' &&\n typeof parsedUserAgent.os.version === 'string'\n) {\n iosVersion = parseFloat(parsedUserAgent.os.version)\n if (Number.isNaN(iosVersion)) {\n iosVersion = undefined\n }\n}\n\n/**\n * Get the locale (e.g. `en-AU`) for the current tenant.\n *\n * #### Example\n *\n * ```js\n * const locale = localisationService.getLocale()\n * ```\n *\n * @returns\n */\nexport function getLocale() {\n return tenants.locale\n}\n\n/**\n * Get the distance units (e.g. `feet` & 'ft) for the current tenant.\n *\n * #### Example\n *\n * ```js\n * const { distanceUnit, distanceUnitShortName } =\n * localisationService.getDistanceUnits()\n * ```\n *\n * @returns\n */\nexport function getDistanceUnits() {\n return {\n distanceUnit: tenants.current.distanceUnit,\n distanceUnitShortName: tenants.current.distanceUnitShortName,\n }\n}\n\nfunction generateFormats({\n time,\n shortDate,\n shortYearlessDate,\n longDate,\n longYearlessDate,\n}: {\n time: string\n shortDate: string\n shortYearlessDate: string\n longDate: string\n longYearlessDate: string\n}) {\n return {\n time,\n shortDate,\n shortYearlessDate,\n longDate,\n longYearlessDate,\n shortDateTime: `${shortDate} ${time}`,\n longDateTime: `${longDate} ${time}`,\n }\n}\n\nexport function getDateFnsFormats() {\n const time = 'h:mm a'\n switch (tenants.locale) {\n case 'en-US': {\n return generateFormats({\n time,\n shortDate: 'MM/dd/yyyy',\n shortYearlessDate: 'MM/dd',\n longDate: 'MMM do, yyyy',\n longYearlessDate: 'MMM do',\n })\n }\n case 'en-AU':\n default: {\n return generateFormats({\n time,\n shortDate: 'dd/MM/yyyy',\n shortYearlessDate: 'dd/MM',\n longDate: 'do MMM, yyyy',\n longYearlessDate: 'do MMM',\n })\n }\n }\n}\n\n/**\n * Format a `Date` as a `string` that just contains the date portion e.g.\n * _31/01/2020_\n *\n * #### Example\n *\n * ```js\n * const date = new Date()\n * const text = localisationService.formatDate(date)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatDate(value: Date): string {\n return tenants.current.intlFormats.date.format(value)\n}\n\n/**\n * Format a `Date` as a `string` that just contains the date portion in a long\n * format e.g. _Thursday, 2 January 2020_\n *\n * #### Example\n *\n * ```js\n * const date = new Date()\n * const text = localisationService.formatDateLong(date)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatDateLong(value: Date): string {\n return tenants.current.intlFormats.dateLong.format(value)\n}\n\n/**\n * Format a `Date` as a `string` that just contains the time portion e.g. _5:31\n * pm_\n *\n * #### Example\n *\n * ```js\n * const date = new Date()\n * const text = localisationService.formatTime(date)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatTime(value: Date): string {\n /*\n * Time formatting for older iOS devices. Prevents date from repeating.\n * Example: Last sync time: 24/11/2022 24/11/2022\n */\n if (typeof iosVersion === 'number' && iosVersion < 13.0) {\n const time = tenants.current.intlFormats.olderIOSTime.formatToParts(value)\n const newTime = time.map((t) => t.value).join('')\n return `${newTime}`\n }\n return tenants.current.intlFormats.time.format(value)\n}\n\n/**\n * Format a `Date` as a `string` that contains the date and time portions e.g.\n * _31/01/2020 5:31 pm_\n *\n * #### Example\n *\n * ```js\n * const date = new Date()\n * const text = localisationService.formatDatetime(date)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatDatetime(value: Date) {\n return `${formatDate(value)} ${formatTime(value)}`\n}\n\n/**\n * Format a `Date` as a `string` that contains the date and time portions in a\n * long format e.g. _Thursday, 2 January 2020 5:31 pm_\n *\n * #### Example\n *\n * ```js\n * const date = new Date()\n * const text = localisationService.formatDatetime(date)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatDatetimeLong(value: Date) {\n return `${formatDateLong(value)} ${formatTime(value)}`\n}\n\n/**\n * Format a `number` as a `string` represented as a readable number e.g.\n * _123,321.123_\n *\n * #### Example\n *\n * ```js\n * const amount = 1234.4321\n * const text = localisationService.formatCurrency(amount)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatNumber(value: number): string {\n return tenants.current.intlFormats.number.format(value)\n}\n\n/**\n * Format a `number` as a `string` represented as a currency e.g. _$123.31_\n *\n * #### Example\n *\n * ```js\n * const amount = 123.321\n * const text = localisationService.formatCurrency(amount)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatCurrency(value: number): string {\n return tenants.current.intlFormats.currency.format(value)\n}\n\n/**\n * Generate a `Date` based a `string` while adding/subtracting a number of days.\n * Use this function to generate a date with the correct time if only the date\n * part is required to be formatted for display purposes. Also supports passing\n * `'NOW'` as the value to get the current date with an offset.\n *\n * #### Example\n *\n * ```js\n * const dateOnly = localisationService.generateDate({\n * value: '2023-05-04',\n * dateOnly: true,\n * daysOffset: undefined,\n * })\n *\n * const date = localisationService.generateDate({\n * value: '2023-05-04T02:49:23.616Z',\n * dateOnly: false,\n * daysOffset: undefined,\n * })\n *\n * const now = localisationService.generateDate({\n * value: 'NOW',\n * dateOnly: false,\n * daysOffset: undefined,\n * })\n * ```\n *\n * @param options\n * @returns\n */\nexport function generateDate({\n daysOffset,\n value,\n}: {\n daysOffset: number | undefined\n value: string\n}): Date | undefined {\n if (value === 'NOW') {\n const date = new Date()\n if (daysOffset !== undefined) {\n date.setDate(date.getDate() + daysOffset)\n }\n return date\n } else {\n let date = parse(value, 'yyyy-MM-dd', new Date())\n if (Number.isNaN(date.getTime())) {\n date = parse(value, \"yyyy-MM-dd'T'HH:mm:ss.SSSX\", new Date())\n if (!Number.isNaN(date.getTime())) {\n return generateDateOffset({ date, daysOffset })\n }\n } else {\n return generateDateOffset({ date, daysOffset })\n }\n }\n}\n\nfunction generateDateOffset({\n date,\n daysOffset,\n}: {\n daysOffset: number | undefined\n date: Date\n}) {\n if (daysOffset !== undefined) {\n return add(date, { days: daysOffset })\n }\n return date\n}\n\n/**\n * Parse a date/datetime string for conditional logic evaluation. Date-only\n * values (`YYYY-MM-DD`) are interpreted in the user's local timezone.\n */\nexport function parseDate(value: string): Date {\n // Always return a Date so callers can use Number.isNaN(date.getTime()) to\n // detect unparseable values. generateDate returns undefined in that case.\n return (\n generateDate({\n value,\n daysOffset: undefined,\n }) ?? new Date(NaN)\n )\n}\n\n/**\n * Add calendar days to a date for conditional logic evaluation.\n */\nexport function addDaysToDate(date: Date, days: number): Date {\n return add(date, { days })\n}\n\nexport const replaceSubmissionFormatters: submissionService.ReplaceInjectablesFormatters =\n {\n formatDate: (v) => {\n const date = generateDate({\n value: v,\n daysOffset: undefined,\n })\n if (date) {\n return formatDate(date)\n }\n return ''\n },\n formatDateTime: (value) => formatDatetime(new Date(value)),\n formatTime: (value) => formatTime(new Date(value)),\n formatCurrency: (value) => formatCurrency(value),\n formatNumber: (value) => value.toString(),\n }\n\n/**\n * Replace the `{ELEMENT:<elementName>}` values in text after a successful form\n * submission as well as other replaceable parameters e.g. `submissionId`. The\n * replacements are suppose to be user friendly and for display purposes, e.g.\n * dates should be displayed in the user's desired format and timezone.\n *\n * @param text\n * @param options\n * @returns\n */\nexport function replaceInjectablesWithSubmissionValues(\n text: string,\n options: Omit<\n Parameters<\n typeof submissionService.replaceInjectablesWithSubmissionValues\n >[1],\n keyof submissionService.ReplaceInjectablesFormatters\n >,\n): ReturnType<typeof submissionService.replaceInjectablesWithSubmissionValues> {\n return submissionService.replaceInjectablesWithSubmissionValues(text, {\n ...options,\n ...replaceSubmissionFormatters,\n })\n}\n\n/**\n * Replace the `{ELEMENT:<elementName>}` values in text while a form is being\n * filled out. The replacements are suppose to be user friendly and for display\n * purposes, e.g. dates should be displayed in the user's desired format and\n * timezone.\n *\n * @param text\n * @param options\n * @returns\n */\nexport function replaceInjectablesWithElementValues(\n text: string,\n options: Omit<\n Parameters<typeof submissionService.replaceInjectablesWithElementValues>[1],\n keyof submissionService.ReplaceInjectablesFormatters\n >,\n): ReturnType<typeof submissionService.replaceInjectablesWithElementValues> {\n return submissionService.replaceInjectablesWithElementValues(text, {\n ...options,\n ...replaceSubmissionFormatters,\n })\n}\n"]}
1
+ {"version":3,"file":"localisation-service.js","sourceRoot":"","sources":["../../src/apps/localisation-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,MAAM,MAAM,cAAc,CAAA;AACjC,OAAO,EACL,GAAG,EACH,QAAQ,IAAI,eAAe,EAC3B,KAAK,EACL,UAAU,IAAI,iBAAiB,GAChC,MAAM,UAAU,CAAA;AAEjB,IAAI,UAA8B,CAAA;AAClC,MAAM,eAAe,GAAmB,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;AAC1E,IACE,eAAe,CAAC,EAAE,CAAC,IAAI,KAAK,KAAK;IACjC,OAAO,eAAe,CAAC,EAAE,CAAC,OAAO,KAAK,QAAQ,EAC9C,CAAC;IACD,UAAU,GAAG,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC,OAAO,CAAC,CAAA;IACnD,IAAI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7B,UAAU,GAAG,SAAS,CAAA;IACxB,CAAC;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,OAAO,CAAC,MAAM,CAAA;AACvB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO;QACL,Y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OAAO,iBAAiB,CAAC,sCAAsC,CAAC,IAAI,EAAE;QACpE,GAAG,OAAO;QACV,GAAG,2BAA2B;KAC/B,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,mCAAmC,CACjD,IAAY,EACZ,OAGC;IAED,OAAO,iBAAiB,CAAC,mCAAmC,CAAC,IAAI,EAAE;QACjE,GAAG,OAAO;QACV,GAAG,2BAA2B;KAC/B,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { submissionService } from '@oneblink/sdk-core'\nimport tenants from './tenants'\nimport parser from 'ua-parser-js'\nimport {\n add,\n endOfDay as dateFnsEndOfDay,\n parse,\n startOfDay as dateFnsStartOfDay,\n} from 'date-fns'\n\nlet iosVersion: number | undefined\nconst parsedUserAgent: parser.IResult = parser(window.navigator.userAgent)\nif (\n parsedUserAgent.os.name === 'iOS' &&\n typeof parsedUserAgent.os.version === 'string'\n) {\n iosVersion = parseFloat(parsedUserAgent.os.version)\n if (Number.isNaN(iosVersion)) {\n iosVersion = undefined\n }\n}\n\n/**\n * Get the locale (e.g. `en-AU`) for the current tenant.\n *\n * #### Example\n *\n * ```js\n * const locale = localisationService.getLocale()\n * ```\n *\n * @returns\n */\nexport function getLocale() {\n return tenants.locale\n}\n\n/**\n * Get the distance units (e.g. `feet` & 'ft) for the current tenant.\n *\n * #### Example\n *\n * ```js\n * const { distanceUnit, distanceUnitShortName } =\n * localisationService.getDistanceUnits()\n * ```\n *\n * @returns\n */\nexport function getDistanceUnits() {\n return {\n distanceUnit: tenants.current.distanceUnit,\n distanceUnitShortName: tenants.current.distanceUnitShortName,\n }\n}\n\nfunction generateFormats({\n time,\n shortDate,\n shortYearlessDate,\n longDate,\n longYearlessDate,\n}: {\n time: string\n shortDate: string\n shortYearlessDate: string\n longDate: string\n longYearlessDate: string\n}) {\n return {\n time,\n shortDate,\n shortYearlessDate,\n longDate,\n longYearlessDate,\n shortDateTime: `${shortDate} ${time}`,\n longDateTime: `${longDate} ${time}`,\n }\n}\n\nexport function getDateFnsFormats() {\n const time = 'h:mm a'\n switch (tenants.locale) {\n case 'en-US': {\n return generateFormats({\n time,\n shortDate: 'MM/dd/yyyy',\n shortYearlessDate: 'MM/dd',\n longDate: 'MMM do, yyyy',\n longYearlessDate: 'MMM do',\n })\n }\n case 'en-AU':\n default: {\n return generateFormats({\n time,\n shortDate: 'dd/MM/yyyy',\n shortYearlessDate: 'dd/MM',\n longDate: 'do MMM, yyyy',\n longYearlessDate: 'do MMM',\n })\n }\n }\n}\n\n/**\n * Format a `Date` as a `string` that just contains the date portion e.g.\n * _31/01/2020_\n *\n * #### Example\n *\n * ```js\n * const date = new Date()\n * const text = localisationService.formatDate(date)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatDate(value: Date): string {\n return tenants.current.intlFormats.date.format(value)\n}\n\n/**\n * Format a `Date` as a `string` that just contains the date portion in a long\n * format e.g. _Thursday, 2 January 2020_\n *\n * #### Example\n *\n * ```js\n * const date = new Date()\n * const text = localisationService.formatDateLong(date)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatDateLong(value: Date): string {\n return tenants.current.intlFormats.dateLong.format(value)\n}\n\n/**\n * Format a `Date` as a `string` that just contains the time portion e.g. _5:31\n * pm_\n *\n * #### Example\n *\n * ```js\n * const date = new Date()\n * const text = localisationService.formatTime(date)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatTime(value: Date): string {\n /*\n * Time formatting for older iOS devices. Prevents date from repeating.\n * Example: Last sync time: 24/11/2022 24/11/2022\n */\n if (typeof iosVersion === 'number' && iosVersion < 13.0) {\n const time = tenants.current.intlFormats.olderIOSTime.formatToParts(value)\n const newTime = time.map((t) => t.value).join('')\n return `${newTime}`\n }\n return tenants.current.intlFormats.time.format(value)\n}\n\n/**\n * Format a `Date` as a `string` that contains the date and time portions e.g.\n * _31/01/2020 5:31 pm_\n *\n * #### Example\n *\n * ```js\n * const date = new Date()\n * const text = localisationService.formatDatetime(date)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatDatetime(value: Date) {\n return `${formatDate(value)} ${formatTime(value)}`\n}\n\n/**\n * Format a `Date` as a `string` that contains the date and time portions in a\n * long format e.g. _Thursday, 2 January 2020 5:31 pm_\n *\n * #### Example\n *\n * ```js\n * const date = new Date()\n * const text = localisationService.formatDatetime(date)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatDatetimeLong(value: Date) {\n return `${formatDateLong(value)} ${formatTime(value)}`\n}\n\n/**\n * Format a `number` as a `string` represented as a readable number e.g.\n * _123,321.123_\n *\n * #### Example\n *\n * ```js\n * const amount = 1234.4321\n * const text = localisationService.formatCurrency(amount)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatNumber(value: number): string {\n return tenants.current.intlFormats.number.format(value)\n}\n\n/**\n * Format a `number` as a `string` represented as a currency e.g. _$123.31_\n *\n * #### Example\n *\n * ```js\n * const amount = 123.321\n * const text = localisationService.formatCurrency(amount)\n * // Display text\n * ```\n *\n * @param value\n * @returns\n */\nexport function formatCurrency(value: number): string {\n return tenants.current.intlFormats.currency.format(value)\n}\n\n/**\n * Generate a `Date` based a `string` while adding/subtracting a number of days.\n * Use this function to generate a date with the correct time if only the date\n * part is required to be formatted for display purposes. Also supports passing\n * `'NOW'` as the value to get the current date with an offset.\n *\n * #### Example\n *\n * ```js\n * const dateOnly = localisationService.generateDate({\n * value: '2023-05-04',\n * dateOnly: true,\n * daysOffset: undefined,\n * })\n *\n * const date = localisationService.generateDate({\n * value: '2023-05-04T02:49:23.616Z',\n * dateOnly: false,\n * daysOffset: undefined,\n * })\n *\n * const now = localisationService.generateDate({\n * value: 'NOW',\n * dateOnly: false,\n * daysOffset: undefined,\n * })\n * ```\n *\n * @param options\n * @returns\n */\nexport function generateDate({\n daysOffset,\n value,\n}: {\n daysOffset: number | undefined\n value: string\n}): Date | undefined {\n if (value === 'NOW') {\n const date = new Date()\n if (daysOffset !== undefined) {\n date.setDate(date.getDate() + daysOffset)\n }\n return date\n } else {\n let date = parse(value, 'yyyy-MM-dd', new Date())\n if (Number.isNaN(date.getTime())) {\n date = parse(value, \"yyyy-MM-dd'T'HH:mm:ss.SSSX\", new Date())\n if (!Number.isNaN(date.getTime())) {\n return generateDateOffset({ date, daysOffset })\n }\n } else {\n return generateDateOffset({ date, daysOffset })\n }\n }\n}\n\nfunction generateDateOffset({\n date,\n daysOffset,\n}: {\n daysOffset: number | undefined\n date: Date\n}) {\n if (daysOffset !== undefined) {\n return add(date, { days: daysOffset })\n }\n return date\n}\n\n/**\n * Parse a day-only (`YYYY-MM-DD`) string for conditional logic evaluation in\n * the user's local timezone. sdk-core only calls this for day-only values.\n */\nexport function parseDayOnlyDate(value: string): Date {\n // Always return a Date so callers can use Number.isNaN(date.getTime()) to\n // detect unparseable values. generateDate returns undefined in that case.\n return (\n generateDate({\n value,\n daysOffset: undefined,\n }) ?? new Date(NaN)\n )\n}\n\n/**\n * Add calendar days to a date for conditional logic evaluation.\n */\nexport function addDaysToDate(date: Date, days: number): Date {\n return add(date, { days })\n}\n\n/**\n * Start of calendar day in the user's local timezone for conditional logic.\n */\nexport function startOfDay(date: Date): Date {\n return dateFnsStartOfDay(date)\n}\n\n/**\n * End of calendar day in the user's local timezone for conditional logic.\n */\nexport function endOfDay(date: Date): Date {\n return dateFnsEndOfDay(date)\n}\n\nexport const replaceSubmissionFormatters: submissionService.ReplaceInjectablesFormatters =\n {\n formatDate: (v) => {\n const date = generateDate({\n value: v,\n daysOffset: undefined,\n })\n if (date) {\n return formatDate(date)\n }\n return ''\n },\n formatDateTime: (value) => formatDatetime(new Date(value)),\n formatTime: (value) => formatTime(new Date(value)),\n formatCurrency: (value) => formatCurrency(value),\n formatNumber: (value) => value.toString(),\n }\n\n/**\n * Replace the `{ELEMENT:<elementName>}` values in text after a successful form\n * submission as well as other replaceable parameters e.g. `submissionId`. The\n * replacements are suppose to be user friendly and for display purposes, e.g.\n * dates should be displayed in the user's desired format and timezone.\n *\n * @param text\n * @param options\n * @returns\n */\nexport function replaceInjectablesWithSubmissionValues(\n text: string,\n options: Omit<\n Parameters<\n typeof submissionService.replaceInjectablesWithSubmissionValues\n >[1],\n keyof submissionService.ReplaceInjectablesFormatters\n >,\n): ReturnType<typeof submissionService.replaceInjectablesWithSubmissionValues> {\n return submissionService.replaceInjectablesWithSubmissionValues(text, {\n ...options,\n ...replaceSubmissionFormatters,\n })\n}\n\n/**\n * Replace the `{ELEMENT:<elementName>}` values in text while a form is being\n * filled out. The replacements are suppose to be user friendly and for display\n * purposes, e.g. dates should be displayed in the user's desired format and\n * timezone.\n *\n * @param text\n * @param options\n * @returns\n */\nexport function replaceInjectablesWithElementValues(\n text: string,\n options: Omit<\n Parameters<typeof submissionService.replaceInjectablesWithElementValues>[1],\n keyof submissionService.ReplaceInjectablesFormatters\n >,\n): ReturnType<typeof submissionService.replaceInjectablesWithElementValues> {\n return submissionService.replaceInjectablesWithElementValues(text, {\n ...options,\n ...replaceSubmissionFormatters,\n })\n}\n"]}
@@ -6,7 +6,7 @@ import BPOINTPaymentProvider from './services/payment-providers/BPOINTPaymentPro
6
6
  import CPPayPaymentProvider from './services/payment-providers/CPPayPaymentProvider';
7
7
  import NSWGovPayPaymentProvider from './services/payment-providers/NSWGovPayPaymentProvider';
8
8
  import WestpacQuickStreamPaymentProvider, * as westpacQuickStream from './services/payment-providers/WestpacQuickStreamPaymentProvider';
9
- import { addDaysToDate, parseDate, replaceSubmissionFormatters, } from './localisation-service';
9
+ import { addDaysToDate, endOfDay, parseDayOnlyDate, startOfDay, replaceSubmissionFormatters, } from './localisation-service';
10
10
  import { getSchedulingBooking, removeSchedulingBooking, } from './services/schedulingHandlers';
11
11
  const KEY = 'PAYMENT_SUBMISSION_RESULT';
12
12
  export { westpacQuickStream };
@@ -76,8 +76,10 @@ export function checkForPaymentSubmissionEvent(formSubmission, submissionTimesta
76
76
  definition: formSubmission.definition,
77
77
  submission: formSubmission.submission,
78
78
  submissionTimestamp,
79
- parseDate,
79
+ parseDayOnlyDate,
80
80
  addDaysToDate,
81
+ startOfDay,
82
+ endOfDay,
81
83
  });
82
84
  if (result) {
83
85
  console.log('Form has a payment submission event with amount', result);
@@ -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,4BAA4B,EAAE,MAAM,wBAAwB,CAAA;AACrE,OAAO,YAAY,MAAM,kBAAkB,CAAA;AAQ3C,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,SAAS,EACT,2BAA2B,GAC5B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,+BAA+B,CAAA;AAEtC,MAAM,GAAG,GAAG,2BAA2B,CAAA;AAEvC,OAAO,EAA2C,kBAAkB,EAAE,CAAA;AAEtE,SAAS,kBAAkB,CACzB,oBAA0C,EAC1C,sBAA6D;IAE7D,QAAQ,sBAAsB,CAAC,IAAI,EAAE,CAAC;QACpC,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,OAAO,IAAI,qBAAqB,CAC9B,sBAAsB,EACtB,oBAAoB,CACrB,CAAA;QACH,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,OAAO,IAAI,oBAAoB,CAC7B,sBAAsB,EACtB,oBAAoB,CACrB,CAAA;QACH,CAAC;QACD,KAAK,aAAa,CAAC,CAAC,CAAC;YACnB,OAAO,IAAI,wBAAwB,CACjC,sBAAsB,EACtB,oBAAoB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CAAC,KAAK,UAAU,8BAA8B;;IAIlD,MAAM,oBAAoB,GACxB,MAAM,YAAY,CAAC,kBAAkB,CAA8B,GAAG,CAAC,CAAA;IAEzE,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC1B,MAAM,IAAI,iBAAiB,CACzB,oFAAoF,CACrF,CAAA;IACH,CAAC;IACD,IAAI,CAAC,CAAA,MAAA,oBAAoB,CAAC,OAAO,0CAAE,eAAe,CAAA,EAAE,CAAC;QACnD,MAAM,IAAI,iBAAiB,CACzB,yFAAyF,CAC1F,CAAA;IACH,CAAC;IAED,OAAO;QACL,oBAAoB;QACpB,sBAAsB,EAAE,MAAA,oBAAoB,CAAC,OAAO,0CAAE,eAAe;KACtE,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,0CAA0C,CACxD,qBAA4D;IAE5D,OAAO,cAAc,CAAC,0CAA0C,CAC9D,qBAAqB,EACrB,2BAA2B,CAC5B,CAAA;AACH,CAAC","sourcesContent":["import { paymentService } from '@oneblink/sdk-core'\nimport OneBlinkAppsError from './services/errors/oneBlinkAppsError'\nimport { generatePaymentConfiguration } from './services/api/payment'\nimport utilsService from './services/utils'\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 parseDate,\n replaceSubmissionFormatters,\n} from './localisation-service'\nimport {\n getSchedulingBooking,\n removeSchedulingBooking,\n} from './services/schedulingHandlers'\n\nconst KEY = 'PAYMENT_SUBMISSION_RESULT'\n\nexport { HandlePaymentResult, PaymentReceiptItem, westpacQuickStream }\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 =\n await utilsService.getLocalForageItem<FormSubmissionResult | null>(KEY)\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):\n | {\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n amount: number\n }\n | undefined {\n const result = paymentService.checkForPaymentEvent({\n definition: formSubmission.definition,\n submission: formSubmission.submission,\n submissionTimestamp,\n parseDate,\n addDaysToDate,\n })\n if (result) {\n console.log('Form has a payment submission event with amount', result)\n }\n return result\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 amount,\n formSubmissionResult,\n paymentSubmissionEvent,\n paymentReceiptUrl,\n paymentFormUrl,\n}: {\n amount: number\n formSubmissionResult: FormSubmissionResult\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n paymentReceiptUrl: string\n paymentFormUrl: string | undefined\n}): Promise<FormSubmissionResult['payment']> {\n const paymentProvider = getPaymentProvider(\n formSubmissionResult,\n paymentSubmissionEvent,\n )\n if (!paymentProvider) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to make a payment using an unsupported payment method.',\n )\n }\n\n const paymentConfiguration = await generatePaymentConfiguration(\n paymentProvider,\n {\n amount,\n redirectUrl: paymentReceiptUrl,\n submissionId: formSubmissionResult.submissionId,\n paymentFormUrl,\n },\n )\n\n const payment = {\n submissionEvent: paymentSubmissionEvent,\n paymentReceiptUrl,\n hostedFormUrl: paymentConfiguration.hostedFormUrl,\n paymentFormUrl,\n amount,\n }\n console.log('Created Payment configuration to start transaction', payment)\n\n await utilsService.setLocalForageItem(KEY, {\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 =\n await utilsService.getLocalForageItem<FormSubmissionResult | null>(KEY)\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"]}
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,4BAA4B,EAAE,MAAM,wBAAwB,CAAA;AACrE,OAAO,YAAY,MAAM,kBAAkB,CAAA;AAQ3C,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,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,+BAA+B,CAAA;AAEtC,MAAM,GAAG,GAAG,2BAA2B,CAAA;AAEvC,OAAO,EAA2C,kBAAkB,EAAE,CAAA;AAEtE,SAAS,kBAAkB,CACzB,oBAA0C,EAC1C,sBAA6D;IAE7D,QAAQ,sBAAsB,CAAC,IAAI,EAAE,CAAC;QACpC,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,OAAO,IAAI,qBAAqB,CAC9B,sBAAsB,EACtB,oBAAoB,CACrB,CAAA;QACH,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,OAAO,IAAI,oBAAoB,CAC7B,sBAA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AY,CAAC,kBAAkB,CAAC,GAAG,EAAE;QACzC,GAAG,oBAAoB;QACvB,UAAU,EAAE,IAAI;QAChB,OAAO;KACR,CAAC,CAAA;IAEF,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,8BAA8B;;IAIlD,MAAM,oBAAoB,GACxB,MAAM,YAAY,CAAC,kBAAkB,CAA8B,GAAG,CAAC,CAAA;IAEzE,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC1B,MAAM,IAAI,iBAAiB,CACzB,oFAAoF,CACrF,CAAA;IACH,CAAC;IACD,IAAI,CAAC,CAAA,MAAA,oBAAoB,CAAC,OAAO,0CAAE,eAAe,CAAA,EAAE,CAAC;QACnD,MAAM,IAAI,iBAAiB,CACzB,yFAAyF,CAC1F,CAAA;IACH,CAAC;IAED,OAAO;QACL,oBAAoB;QACpB,sBAAsB,EAAE,MAAA,oBAAoB,CAAC,OAAO,0CAAE,eAAe;KACtE,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,0CAA0C,CACxD,qBAA4D;IAE5D,OAAO,cAAc,CAAC,0CAA0C,CAC9D,qBAAqB,EACrB,2BAA2B,CAC5B,CAAA;AACH,CAAC","sourcesContent":["import { paymentService } from '@oneblink/sdk-core'\nimport OneBlinkAppsError from './services/errors/oneBlinkAppsError'\nimport { generatePaymentConfiguration } from './services/api/payment'\nimport utilsService from './services/utils'\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 getSchedulingBooking,\n removeSchedulingBooking,\n} from './services/schedulingHandlers'\n\nconst KEY = 'PAYMENT_SUBMISSION_RESULT'\n\nexport { HandlePaymentResult, PaymentReceiptItem, westpacQuickStream }\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 =\n await utilsService.getLocalForageItem<FormSubmissionResult | null>(KEY)\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):\n | {\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n amount: number\n }\n | 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 }\n return result\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 amount,\n formSubmissionResult,\n paymentSubmissionEvent,\n paymentReceiptUrl,\n paymentFormUrl,\n}: {\n amount: number\n formSubmissionResult: FormSubmissionResult\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n paymentReceiptUrl: string\n paymentFormUrl: string | undefined\n}): Promise<FormSubmissionResult['payment']> {\n const paymentProvider = getPaymentProvider(\n formSubmissionResult,\n paymentSubmissionEvent,\n )\n if (!paymentProvider) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to make a payment using an unsupported payment method.',\n )\n }\n\n const paymentConfiguration = await generatePaymentConfiguration(\n paymentProvider,\n {\n amount,\n redirectUrl: paymentReceiptUrl,\n submissionId: formSubmissionResult.submissionId,\n paymentFormUrl,\n },\n )\n\n const payment = {\n submissionEvent: paymentSubmissionEvent,\n paymentReceiptUrl,\n hostedFormUrl: paymentConfiguration.hostedFormUrl,\n paymentFormUrl,\n amount,\n }\n console.log('Created Payment configuration to start transaction', payment)\n\n await utilsService.setLocalForageItem(KEY, {\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 =\n await utilsService.getLocalForageItem<FormSubmissionResult | null>(KEY)\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"]}
@@ -1,7 +1,7 @@
1
1
  import { generateSchedulingConfiguration } from './api/scheduling';
2
2
  import utilsService from './utils';
3
3
  import { schedulingService } from '@oneblink/sdk-core';
4
- import { addDaysToDate, parseDate } from '../localisation-service';
4
+ import { addDaysToDate, endOfDay, parseDayOnlyDate, startOfDay, } from '../localisation-service';
5
5
  const SCHEDULING_SUBMISSION_RESULT_KEY = 'SCHEDULING_SUBMISSION_RESULT';
6
6
  export async function getSchedulingSubmissionResult() {
7
7
  return await utilsService.getLocalForageItem(SCHEDULING_SUBMISSION_RESULT_KEY);
@@ -43,8 +43,10 @@ function checkForSchedulingSubmissionEvent(baseFormSubmission, submissionTimesta
43
43
  definition: baseFormSubmission.definition,
44
44
  submission: baseFormSubmission.submission,
45
45
  submissionTimestamp,
46
- parseDate,
46
+ parseDayOnlyDate,
47
47
  addDaysToDate,
48
+ startOfDay,
49
+ endOfDay,
48
50
  });
49
51
  if (schedulingSubmissionEvent) {
50
52
  console.log('Form has a scheduling submission event', schedulingSubmissionEvent);
@@ -1 +1 @@
1
- {"version":3,"file":"schedulingHandlers.js","sourceRoot":"","sources":["../../../src/apps/services/schedulingHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,k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3E,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,EAAE,oBAAoB,CAAC,YAAY,CAAC,CAAA;IAE9E,MAAM,UAAU,GAAG;QACjB,eAAe,EAAE,yBAAyB;QAC1C,UAAU,EAAE,UAAU,CAAC,QAAQ,EAAE;KAClC,CAAA;IACD,OAAO,CAAC,GAAG,CAAC,mDAAmD,EAAE,UAAU,CAAC,CAAA;IAC5E,MAAM,6BAA6B,CAAC;QAClC,oBAAoB,EAAE;YACpB,GAAG,oBAAoB;YACvB,UAAU;SACX;QACD,iBAAiB;QACjB,cAAc;QACd,cAAc;KACf,CAAC,CAAA;IAEF,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,OAAO,EAEL,iCAAiC,EACjC,+BAA+B,GAChC,CAAA","sourcesContent":["import { generateSchedulingConfiguration } from './api/scheduling'\nimport utilsService from './utils'\nimport { SubmissionEventTypes } from '@oneblink/types'\nimport { schedulingService } from '@oneblink/sdk-core'\nimport {\n FormSubmissionResult,\n BaseNewFormSubmission,\n} from '../types/submissions'\nimport { SchedulingUrlConfiguration } from '../types/scheduling'\nimport { addDaysToDate, parseDate } from '../localisation-service'\n\nconst SCHEDULING_SUBMISSION_RESULT_KEY = 'SCHEDULING_SUBMISSION_RESULT'\ntype SchedulingSubmissionResult = {\n formSubmissionResult: FormSubmissionResult\n paymentReceiptUrl: string | undefined\n paymentFormUrl: string | undefined\n preventPayment: boolean\n}\nexport async function getSchedulingSubmissionResult(): Promise<SchedulingSubmissionResult | null> {\n return await utilsService.getLocalForageItem(SCHEDULING_SUBMISSION_RESULT_KEY)\n}\nexport async function removeSchedulingSubmissionResult() {\n await utilsService.removeLocalForageItem(SCHEDULING_SUBMISSION_RESULT_KEY)\n}\nasync function setSchedulingSubmissionResult(\n schedulingSubmissionResult: SchedulingSubmissionResult,\n) {\n await utilsService.setLocalForageItem(\n SCHEDULING_SUBMISSION_RESULT_KEY,\n schedulingSubmissionResult,\n )\n}\n\nconst SCHEDULING_BOOKING_KEY = 'SCHEDULING_BOOKING'\ntype SchedulingBooking = {\n /** The unique identifier for the submission associated with the booking */\n submissionId: string\n /** Date and time the booking starts */\n startTime: Date\n /** Date and time the booking ends */\n endTime: Date\n /** Location of booking */\n location: string | undefined\n /** `true` if the booking has been rescheduled, otherwise `false` */\n isReschedule: boolean\n}\n\nasync function getSchedulingBookingMap() {\n return await utilsService.getLocalForageItem<\n Record<string, SchedulingBooking>\n >(SCHEDULING_BOOKING_KEY)\n}\n\nasync function setSchedulingBookingMap(\n schedulingBookingMap: Record<string, SchedulingBooking>,\n) {\n await utilsService.setLocalForageItem(\n SCHEDULING_BOOKING_KEY,\n schedulingBookingMap,\n )\n}\n\nexport async function getSchedulingBooking(\n submissionId: string | null,\n): Promise<SchedulingBooking | undefined> {\n if (!submissionId) {\n return\n }\n const schedulingBookingMap = await getSchedulingBookingMap()\n return schedulingBookingMap?.[submissionId]\n}\n\nexport async function removeSchedulingBooking(submissionId: string) {\n const schedulingBookingMap = await getSchedulingBookingMap()\n if (schedulingBookingMap?.[submissionId]) {\n delete schedulingBookingMap[submissionId]\n await setSchedulingBookingMap(schedulingBookingMap)\n }\n}\n\nexport async function setSchedulingBooking(\n schedulingBooking: SchedulingBooking,\n) {\n const schedulingBookingMap = (await getSchedulingBookingMap()) || {}\n schedulingBookingMap[schedulingBooking.submissionId] = schedulingBooking\n await setSchedulingBookingMap(schedulingBookingMap)\n}\n\nfunction checkForSchedulingSubmissionEvent(\n baseFormSubmission: BaseNewFormSubmission,\n submissionTimestamp: string,\n): SubmissionEventTypes.FormSchedulingEvent | undefined {\n const schedulingSubmissionEvent = schedulingService.checkForSchedulingEvent({\n definition: baseFormSubmission.definition,\n submission: baseFormSubmission.submission,\n submissionTimestamp,\n parseDate,\n addDaysToDate,\n })\n if (schedulingSubmissionEvent) {\n console.log(\n 'Form has a scheduling submission event',\n schedulingSubmissionEvent,\n )\n }\n return schedulingSubmissionEvent\n}\n\nasync function handleSchedulingSubmissionEvent({\n formSubmissionResult,\n schedulingSubmissionEvent,\n schedulingUrlConfiguration,\n paymentReceiptUrl,\n paymentFormUrl,\n preventPayment,\n}: {\n formSubmissionResult: FormSubmissionResult\n schedulingSubmissionEvent: SubmissionEventTypes.FormSchedulingEvent\n schedulingUrlConfiguration: SchedulingUrlConfiguration\n paymentReceiptUrl: string | undefined\n paymentFormUrl: string | undefined\n preventPayment: boolean\n}): Promise<NonNullable<FormSubmissionResult['scheduling']>> {\n console.log(\n 'Attempting to handle submission with scheduling submission event',\n )\n if (!formSubmissionResult.submissionId) {\n throw Error(\n 'Cannot generate calendar booking configuration. Form Submission is missing \"submissionId\"',\n )\n }\n\n await generateSchedulingConfiguration({\n formSubmissionResult,\n schedulingSubmissionEvent,\n schedulingUrlConfiguration,\n })\n\n const bookingUrl = new URL(schedulingUrlConfiguration.schedulingBookingUrl)\n bookingUrl.searchParams.set('submissionId', formSubmissionResult.submissionId)\n\n const scheduling = {\n submissionEvent: schedulingSubmissionEvent,\n bookingUrl: bookingUrl.toString(),\n }\n console.log('Created scheduling configuration to start booking', scheduling)\n await setSchedulingSubmissionResult({\n formSubmissionResult: {\n ...formSubmissionResult,\n scheduling,\n },\n paymentReceiptUrl,\n paymentFormUrl,\n preventPayment,\n })\n\n return scheduling\n}\n\nexport {\n SchedulingBooking,\n checkForSchedulingSubmissionEvent,\n handleSchedulingSubmissionEvent,\n}\n"]}
1
+ {"version":3,"file":"schedulingHandlers.js","sourceRoot":"","sources":["../../../src/apps/services/schedulingHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,kBAAkB,CAAA;AAClE,OAAO,YAAY,MAAM,SAAS,CAAA;AAElC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAMtD,OAAO,EACL,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,UAAU,GACX,MAAM,yBAAyB,CAAA;AAEhC,MAAM,gCAAgC,GAAG,8BAA8B,CAAA;AAOvE,MAAM,CAAC,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AO,CAAC,GAAG,CAAC,mDAAmD,EAAE,UAAU,CAAC,CAAA;IAC5E,MAAM,6BAA6B,CAAC;QAClC,oBAAoB,EAAE;YACpB,GAAG,oBAAoB;YACvB,UAAU;SACX;QACD,iBAAiB;QACjB,cAAc;QACd,cAAc;KACf,CAAC,CAAA;IAEF,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,OAAO,EAEL,iCAAiC,EACjC,+BAA+B,GAChC,CAAA","sourcesContent":["import { generateSchedulingConfiguration } from './api/scheduling'\nimport utilsService from './utils'\nimport { SubmissionEventTypes } from '@oneblink/types'\nimport { schedulingService } from '@oneblink/sdk-core'\nimport {\n FormSubmissionResult,\n BaseNewFormSubmission,\n} from '../types/submissions'\nimport { SchedulingUrlConfiguration } from '../types/scheduling'\nimport {\n addDaysToDate,\n endOfDay,\n parseDayOnlyDate,\n startOfDay,\n} from '../localisation-service'\n\nconst SCHEDULING_SUBMISSION_RESULT_KEY = 'SCHEDULING_SUBMISSION_RESULT'\ntype SchedulingSubmissionResult = {\n formSubmissionResult: FormSubmissionResult\n paymentReceiptUrl: string | undefined\n paymentFormUrl: string | undefined\n preventPayment: boolean\n}\nexport async function getSchedulingSubmissionResult(): Promise<SchedulingSubmissionResult | null> {\n return await utilsService.getLocalForageItem(SCHEDULING_SUBMISSION_RESULT_KEY)\n}\nexport async function removeSchedulingSubmissionResult() {\n await utilsService.removeLocalForageItem(SCHEDULING_SUBMISSION_RESULT_KEY)\n}\nasync function setSchedulingSubmissionResult(\n schedulingSubmissionResult: SchedulingSubmissionResult,\n) {\n await utilsService.setLocalForageItem(\n SCHEDULING_SUBMISSION_RESULT_KEY,\n schedulingSubmissionResult,\n )\n}\n\nconst SCHEDULING_BOOKING_KEY = 'SCHEDULING_BOOKING'\ntype SchedulingBooking = {\n /** The unique identifier for the submission associated with the booking */\n submissionId: string\n /** Date and time the booking starts */\n startTime: Date\n /** Date and time the booking ends */\n endTime: Date\n /** Location of booking */\n location: string | undefined\n /** `true` if the booking has been rescheduled, otherwise `false` */\n isReschedule: boolean\n}\n\nasync function getSchedulingBookingMap() {\n return await utilsService.getLocalForageItem<\n Record<string, SchedulingBooking>\n >(SCHEDULING_BOOKING_KEY)\n}\n\nasync function setSchedulingBookingMap(\n schedulingBookingMap: Record<string, SchedulingBooking>,\n) {\n await utilsService.setLocalForageItem(\n SCHEDULING_BOOKING_KEY,\n schedulingBookingMap,\n )\n}\n\nexport async function getSchedulingBooking(\n submissionId: string | null,\n): Promise<SchedulingBooking | undefined> {\n if (!submissionId) {\n return\n }\n const schedulingBookingMap = await getSchedulingBookingMap()\n return schedulingBookingMap?.[submissionId]\n}\n\nexport async function removeSchedulingBooking(submissionId: string) {\n const schedulingBookingMap = await getSchedulingBookingMap()\n if (schedulingBookingMap?.[submissionId]) {\n delete schedulingBookingMap[submissionId]\n await setSchedulingBookingMap(schedulingBookingMap)\n }\n}\n\nexport async function setSchedulingBooking(\n schedulingBooking: SchedulingBooking,\n) {\n const schedulingBookingMap = (await getSchedulingBookingMap()) || {}\n schedulingBookingMap[schedulingBooking.submissionId] = schedulingBooking\n await setSchedulingBookingMap(schedulingBookingMap)\n}\n\nfunction checkForSchedulingSubmissionEvent(\n baseFormSubmission: BaseNewFormSubmission,\n submissionTimestamp: string,\n): SubmissionEventTypes.FormSchedulingEvent | undefined {\n const schedulingSubmissionEvent = schedulingService.checkForSchedulingEvent({\n definition: baseFormSubmission.definition,\n submission: baseFormSubmission.submission,\n submissionTimestamp,\n parseDayOnlyDate,\n addDaysToDate,\n startOfDay,\n endOfDay,\n })\n if (schedulingSubmissionEvent) {\n console.log(\n 'Form has a scheduling submission event',\n schedulingSubmissionEvent,\n )\n }\n return schedulingSubmissionEvent\n}\n\nasync function handleSchedulingSubmissionEvent({\n formSubmissionResult,\n schedulingSubmissionEvent,\n schedulingUrlConfiguration,\n paymentReceiptUrl,\n paymentFormUrl,\n preventPayment,\n}: {\n formSubmissionResult: FormSubmissionResult\n schedulingSubmissionEvent: SubmissionEventTypes.FormSchedulingEvent\n schedulingUrlConfiguration: SchedulingUrlConfiguration\n paymentReceiptUrl: string | undefined\n paymentFormUrl: string | undefined\n preventPayment: boolean\n}): Promise<NonNullable<FormSubmissionResult['scheduling']>> {\n console.log(\n 'Attempting to handle submission with scheduling submission event',\n )\n if (!formSubmissionResult.submissionId) {\n throw Error(\n 'Cannot generate calendar booking configuration. Form Submission is missing \"submissionId\"',\n )\n }\n\n await generateSchedulingConfiguration({\n formSubmissionResult,\n schedulingSubmissionEvent,\n schedulingUrlConfiguration,\n })\n\n const bookingUrl = new URL(schedulingUrlConfiguration.schedulingBookingUrl)\n bookingUrl.searchParams.set('submissionId', formSubmissionResult.submissionId)\n\n const scheduling = {\n submissionEvent: schedulingSubmissionEvent,\n bookingUrl: bookingUrl.toString(),\n }\n console.log('Created scheduling configuration to start booking', scheduling)\n await setSchedulingSubmissionResult({\n formSubmissionResult: {\n ...formSubmissionResult,\n scheduling,\n },\n paymentReceiptUrl,\n paymentFormUrl,\n preventPayment,\n })\n\n return scheduling\n}\n\nexport {\n SchedulingBooking,\n checkForSchedulingSubmissionEvent,\n handleSchedulingSubmissionEvent,\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": "11.1.1-beta.1",
4
+ "version": "11.1.1-beta.2",
5
5
  "author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/oneblink/apps-react/issues"
@@ -12,7 +12,7 @@
12
12
  "@emotion/react": "^11.14.0",
13
13
  "@emotion/styled": "^11.14.1",
14
14
  "@nylas/react": "^3.1.2",
15
- "@oneblink/sdk-core": "^10.0.0-beta.2",
15
+ "@oneblink/sdk-core": "^10.0.0-beta.3",
16
16
  "@oneblink/storage": "^7.1.2-beta.2",
17
17
  "@react-google-maps/api": "^2.20.8",
18
18
  "@react-input/mask": "^2.0.4",