@saasquatch/component-boilerplate 1.3.1-1 → 1.3.1-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,112 +1,112 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [1.3.0] - 2021-12-09
9
-
10
- ### Fixed
11
-
12
- - Rare race condition causing queries to not return their data fixed
13
- - User identity no longer being cleared if identity is not immediately available in context
14
-
15
- ### Added
16
-
17
- - redirectPath is now included with registration, password reset, and verify email requests
18
-
19
- ## [1.2.2] - 2021-08-23
20
-
21
- ### Added
22
-
23
- - Support for theme engine JWTs for determining user identity, enabling support for hybrid themes
24
-
25
- ## [1.2.1] - 2021-08-20
26
-
27
- ### Changed
28
-
29
- - Fixed infinite loop caused by calling useToken while logged out
30
- - Changed environment detection to support `widgetIdent.env = "demo"` in vanilla components
31
-
32
- ## [1.2.0] - 2021-08-04
33
-
34
- ### Added
35
-
36
- - Portal environment now supports storing and retrieving user identity from localStorage
37
- and validating JWT expiry
38
- - New hooks:
39
- - useAuthenticatedWithEmailAndPasswordMutation: Login a user with email and password
40
- - useChangePasswordMutation: Change a user's password
41
- - useManagedIdentityQuery: Query a user's managed identity
42
- - useRegisterWithEmailAndPasswordMutation: Register a user with email and password
43
- - useRequestPasswordResetEmailMutation: Request a password reset for an email address
44
- - useRequestVerificationEmailMutation: Request an email verification for a user
45
- - useResetPasswordMutation: Reset a user's password from an oobCode
46
- - useVerifyEmailMutation: Verify a user's email from an oobCode
47
- - useVerifyPasswordResetCodeMutation: Verify a password reset oobCode
48
-
49
- ### Changed
50
-
51
- ## [1.1.0] - 2021-05-20
52
-
53
- ### Added
54
-
55
- - BatchedGraphQLClient - Updated client to allow queries to be batched if run in the same 200ms interval
56
- - useLocale Added back due to usage in mint-components
57
-
58
- ### Changed
59
-
60
- - useGraphQLClient - Use BatchedGraphQLClient instead of client from graphql-request
61
- - useBaseQuery - Handle component unmounts with a cleanup function
62
- - useForm - No longer automatically queries for the form, getForm function must be called manually from the component using the hook
63
- - useQuery - New "skip" parameter based on https://www.apollographql.com/docs/react/data/queries/#skip. Also added to usePaginatedQuery
64
- - Jest tests rewritten to use BatchedGraphQLClient
65
-
66
- ## [1.0.0] - 2021-04-21
67
-
68
- ### Added
69
-
70
- - Initial release
71
- - exported hooks available:
72
- - identity hooks:
73
- - useUserIdentity
74
- setUserIdentity
75
- useToken
76
- - environment hooks:
77
- - getEnvironmentSDK
78
- useTenantAlias
79
- useProgramId
80
- setProgramId
81
- useAppDomain
82
- isDemo
83
- useEngagementMedium
84
- - graphql hooks:
85
- - useQuery
86
- useMutation
87
- useLazyQuery
88
- - navigation hooks
89
- - navigation
90
- useCurrentPage
91
- - pagination hooks
92
- - usePagination
93
- usePaginatedQuery
94
- - Generic low-level helpers
95
- - useDebounce
96
- useDebouncedCallback
97
- useTick
98
- useHost
99
- setUseHostImplementation
100
- - Common higher-level functionality
101
- - useShareEvent
102
- useForm
103
-
104
- [unreleased]: https://github.com/saasquatch/program-tools/compare/component-boilerplate@1.3.0...HEAD
105
-
106
- [1.3.0]: https://github.com/saasquatch/program-tools/releases/tag/%40saasquatch%2Fcomponent-boilerplate%401.3.0
107
- [1.2.2]: https://github.com/saasquatch/program-tools/releases/tag/%40saasquatch%2Fcomponent-boilerplate%401.2.2
108
- [1.2.1]: https://github.com/saasquatch/program-tools/releases/tag/%40saasquatch%2Fcomponent-boilerplate%401.2.1
109
- [1.2.0]: https://github.com/saasquatch/program-tools/releases/tag/%40saasquatch%2Fcomponent-boilerplate%401.2.0
110
- [1.1.0]: https://github.com/saasquatch/program-tools/releases/tag/%40saasquatch%2Fcomponent-boilerplate%401.1.0
111
- [1.0.1]: https://github.com/saasquatch/program-tools/releases/tag/%40saasquatch%2Fcomponent-boilerplate%401.0.1
112
- [1.0.0]: https://github.com/saasquatch/program-tools/releases/tag/%40saasquatch%2Fcomponent-boilerplate%401.0.0
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.3.0] - 2021-12-09
9
+
10
+ ### Fixed
11
+
12
+ - Rare race condition causing queries to not return their data fixed
13
+ - User identity no longer being cleared if identity is not immediately available in context
14
+
15
+ ### Added
16
+
17
+ - redirectPath is now included with registration, password reset, and verify email requests
18
+
19
+ ## [1.2.2] - 2021-08-23
20
+
21
+ ### Added
22
+
23
+ - Support for theme engine JWTs for determining user identity, enabling support for hybrid themes
24
+
25
+ ## [1.2.1] - 2021-08-20
26
+
27
+ ### Changed
28
+
29
+ - Fixed infinite loop caused by calling useToken while logged out
30
+ - Changed environment detection to support `widgetIdent.env = "demo"` in vanilla components
31
+
32
+ ## [1.2.0] - 2021-08-04
33
+
34
+ ### Added
35
+
36
+ - Portal environment now supports storing and retrieving user identity from localStorage
37
+ and validating JWT expiry
38
+ - New hooks:
39
+ - useAuthenticatedWithEmailAndPasswordMutation: Login a user with email and password
40
+ - useChangePasswordMutation: Change a user's password
41
+ - useManagedIdentityQuery: Query a user's managed identity
42
+ - useRegisterWithEmailAndPasswordMutation: Register a user with email and password
43
+ - useRequestPasswordResetEmailMutation: Request a password reset for an email address
44
+ - useRequestVerificationEmailMutation: Request an email verification for a user
45
+ - useResetPasswordMutation: Reset a user's password from an oobCode
46
+ - useVerifyEmailMutation: Verify a user's email from an oobCode
47
+ - useVerifyPasswordResetCodeMutation: Verify a password reset oobCode
48
+
49
+ ### Changed
50
+
51
+ ## [1.1.0] - 2021-05-20
52
+
53
+ ### Added
54
+
55
+ - BatchedGraphQLClient - Updated client to allow queries to be batched if run in the same 200ms interval
56
+ - useLocale Added back due to usage in mint-components
57
+
58
+ ### Changed
59
+
60
+ - useGraphQLClient - Use BatchedGraphQLClient instead of client from graphql-request
61
+ - useBaseQuery - Handle component unmounts with a cleanup function
62
+ - useForm - No longer automatically queries for the form, getForm function must be called manually from the component using the hook
63
+ - useQuery - New "skip" parameter based on https://www.apollographql.com/docs/react/data/queries/#skip. Also added to usePaginatedQuery
64
+ - Jest tests rewritten to use BatchedGraphQLClient
65
+
66
+ ## [1.0.0] - 2021-04-21
67
+
68
+ ### Added
69
+
70
+ - Initial release
71
+ - exported hooks available:
72
+ - identity hooks:
73
+ - useUserIdentity
74
+ setUserIdentity
75
+ useToken
76
+ - environment hooks:
77
+ - getEnvironmentSDK
78
+ useTenantAlias
79
+ useProgramId
80
+ setProgramId
81
+ useAppDomain
82
+ isDemo
83
+ useEngagementMedium
84
+ - graphql hooks:
85
+ - useQuery
86
+ useMutation
87
+ useLazyQuery
88
+ - navigation hooks
89
+ - navigation
90
+ useCurrentPage
91
+ - pagination hooks
92
+ - usePagination
93
+ usePaginatedQuery
94
+ - Generic low-level helpers
95
+ - useDebounce
96
+ useDebouncedCallback
97
+ useTick
98
+ useHost
99
+ setUseHostImplementation
100
+ - Common higher-level functionality
101
+ - useShareEvent
102
+ useForm
103
+
104
+ [unreleased]: https://github.com/saasquatch/program-tools/compare/component-boilerplate@1.3.0...HEAD
105
+
106
+ [1.3.0]: https://github.com/saasquatch/program-tools/releases/tag/%40saasquatch%2Fcomponent-boilerplate%401.3.0
107
+ [1.2.2]: https://github.com/saasquatch/program-tools/releases/tag/%40saasquatch%2Fcomponent-boilerplate%401.2.2
108
+ [1.2.1]: https://github.com/saasquatch/program-tools/releases/tag/%40saasquatch%2Fcomponent-boilerplate%401.2.1
109
+ [1.2.0]: https://github.com/saasquatch/program-tools/releases/tag/%40saasquatch%2Fcomponent-boilerplate%401.2.0
110
+ [1.1.0]: https://github.com/saasquatch/program-tools/releases/tag/%40saasquatch%2Fcomponent-boilerplate%401.1.0
111
+ [1.0.1]: https://github.com/saasquatch/program-tools/releases/tag/%40saasquatch%2Fcomponent-boilerplate%401.0.1
112
+ [1.0.0]: https://github.com/saasquatch/program-tools/releases/tag/%40saasquatch%2Fcomponent-boilerplate%401.0.0
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # SaaSquatch Component Boilerplate
2
-
3
- This is a collection of essential universal hooks for use in building web components for the SaaSquatch platform.
4
-
5
- ## Documentation
6
-
7
- See [index.ts](src/index.ts) for API documentation directly in Typescript.
1
+ # SaaSquatch Component Boilerplate
2
+
3
+ This is a collection of essential universal hooks for use in building web components for the SaaSquatch platform.
4
+
5
+ ## Documentation
6
+
7
+ See [index.ts](src/index.ts) for API documentation directly in Typescript.
@@ -0,0 +1 @@
1
+ export declare function addQuery(queryObj: any): void;
@@ -0,0 +1,15 @@
1
+ import { ContextProvider } from "dom-context";
2
+ import { WidgetIdent } from "./environment";
3
+ declare global {
4
+ interface Window {
5
+ widgetIdent: WidgetIdent;
6
+ squatchLocale: ContextProvider<string>;
7
+ }
8
+ }
9
+ export declare function useLocale(): string | undefined;
10
+ /**
11
+ * Overide the globally defined Locale context
12
+ *
13
+ * @param locale the new locale used by the user
14
+ */
15
+ export declare function setLocale(locale: string): void;
@@ -0,0 +1,26 @@
1
+ import { WidgetIdent } from "./environment";
2
+ /**
3
+ * Environment provided by components hosted in a web component (`sqh-widget`)
4
+ */
5
+ export declare type SquatchPortal = typeof SquatchPortalInstance;
6
+ declare global {
7
+ interface Window {
8
+ SquatchPortal?: PortalEnv;
9
+ }
10
+ }
11
+ /**
12
+ * Portal env doesn't include User Id
13
+ */
14
+ export declare type PortalEnv = Pick<WidgetIdent, "tenantAlias" | "appDomain" | "programId">;
15
+ export declare const SquatchPortalInstance: {
16
+ readonly localeContext: {
17
+ useContext: (host: HTMLElement, options?: Pick<import("dom-context").ListenerOptions<unknown>, "onStatus" | "pollingMs" | "attempts">) => string;
18
+ useContextState: (host: HTMLElement, initialState?: string) => readonly [string, (value: string | ((previousState?: string) => string)) => void, import("dom-context").ContextProvider<string>];
19
+ Listener: new (o: Pick<import("dom-context").ListenerOptions<string>, "element" | "onChange" | "onStatus" | "pollingMs" | "attempts">) => import("dom-context").ContextListener<string>;
20
+ listen(o: Pick<import("dom-context").ListenerOptions<string>, "element" | "onChange" | "onStatus" | "pollingMs" | "attempts">): import("dom-context").ContextListener<string>;
21
+ Provider: new (o: Pick<import("dom-context").ProviderOptions<string>, "element" | "initialState">) => import("dom-context").ContextProvider<string>;
22
+ provide(o: Pick<import("dom-context").ProviderOptions<string>, "element" | "initialState">): import("dom-context").ContextProvider<string>;
23
+ provideGlobally(next: string): void;
24
+ name: string;
25
+ };
26
+ };
@@ -14,6 +14,10 @@ export declare type PortalEnv = Pick<WidgetIdent, "tenantAlias" | "appDomain" |
14
14
  * Program ID context helpers
15
15
  */
16
16
  export { useProgramId, setProgramId } from "./ProgramContext";
17
+ /**
18
+ * Locale context helpers
19
+ */
20
+ export { useLocale, setLocale } from "./LocaleContext";
17
21
  /**
18
22
  * Provided by the SaaSquatch GraphQL backend when a widget is rendered.
19
23
  *
@@ -26,6 +30,7 @@ export interface WidgetIdent {
26
30
  token: string;
27
31
  userId: string;
28
32
  accountId: string;
33
+ locale?: string;
29
34
  engagementMedium?: "POPUP" | "EMBED";
30
35
  programId?: string;
31
36
  env?: string;
@@ -127,4 +132,3 @@ export declare type UserId = {
127
132
  };
128
133
  declare type EngagementMedium = "EMBED" | "POPUP";
129
134
  export declare function useEngagementMedium(): EngagementMedium;
130
- export declare function useLocale(): string;
@@ -1,11 +1,9 @@
1
- import { GqlType } from "./useBaseQuery";
2
1
  export declare const REFRESH_EVENT_NAME = "sq:refresh";
3
2
  export declare function useRefreshDispatcher(): {
4
3
  refresh: () => void;
5
4
  };
6
- export declare function useRefreshListener({ skip, update, variables, query, }: {
5
+ export declare function useRefreshListener({ skip, update, variables, }: {
7
6
  skip?: boolean;
8
7
  update: (variables: unknown, skipLoading?: boolean) => unknown;
9
8
  variables: unknown;
10
- query: GqlType;
11
9
  }): void;
@@ -43,4 +43,7 @@ export declare type GraphQlRequestError<T> = {
43
43
  };
44
44
  message?: string;
45
45
  };
46
- export declare function useBaseQuery<T = any>(query: GqlType, initialState: BaseQueryData<T>): [BaseQueryData<T>, (variables: unknown, skipLoading?: boolean) => unknown];
46
+ export declare function useBaseQuery<T = any>(query: GqlType, initialState: BaseQueryData<T>): [
47
+ BaseQueryData<T>,
48
+ (variables: unknown, skipLoading?: boolean) => Promise<void>
49
+ ];
@@ -0,0 +1,45 @@
1
+ import { RequestDocument } from "graphql-request/dist/types";
2
+ export declare type GqlType = RequestDocument;
3
+ export interface BaseQueryData<T = unknown> {
4
+ loading: boolean;
5
+ data?: T;
6
+ errors?: GraphQlRequestError<T>;
7
+ }
8
+ export declare type QueryData<T> = BaseQueryData<T> & {
9
+ refetch: (variables?: unknown) => unknown;
10
+ };
11
+ /**
12
+ * Note: reverse-engineered from a returned error. May not capture all error types.
13
+ */
14
+ export declare type GraphQlRequestError<T> = {
15
+ response: {
16
+ errors: [
17
+ {
18
+ message: string;
19
+ locations: [{
20
+ line: number;
21
+ column: number;
22
+ }];
23
+ path: string[];
24
+ extensions: {
25
+ apiError: {
26
+ message: string;
27
+ statusCode: number;
28
+ apiErrorCode: string;
29
+ rsCode: string;
30
+ };
31
+ classification: string;
32
+ };
33
+ }
34
+ ];
35
+ data: Partial<T>;
36
+ status: number;
37
+ };
38
+ request: {
39
+ query: string;
40
+ variables: {
41
+ [key: string]: unknown;
42
+ };
43
+ };
44
+ };
45
+ export declare function useBatchedQuery<T = any>(query: GqlType, initialState: BaseQueryData<T>): [BaseQueryData<T>, (variables: unknown) => unknown];
@@ -41,7 +41,7 @@ export interface DebouncedState<T extends (...args: any[]) => ReturnType<T>> ext
41
41
  * `wait` timeout. The `func` is invoked with the last arguments provided to the
42
42
  * debounced function. Subsequent calls to the debounced function return the
43
43
  * result of the last `func` invocation.
44
-
44
+
45
45
  *
46
46
  * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
47
47
  * for details over the differences between `debounce` and `throttle`.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Identity and environment
3
3
  */
4
- export { useUserIdentity, setUserIdentity, useToken, getEnvironmentSDK, useTenantAlias, useProgramId, setProgramId, useAppDomain, isDemo, useEngagementMedium, useLocale, } from "./environment";
4
+ export { useUserIdentity, setUserIdentity, useToken, getEnvironmentSDK, useTenantAlias, useProgramId, setProgramId, useAppDomain, isDemo, useEngagementMedium, useLocale, setLocale, } from "./environment";
5
5
  export { useAuthenticateWithEmailAndPasswordMutation } from "./hooks/managedIdentity/useAuthenticateWithEmailAndPasswordMutation";
6
6
  export { useRegisterWithEmailAndPasswordMutation } from "./hooks/managedIdentity/useRegisterWithEmailAndPasswordMutation";
7
7
  export { useChangePasswordMutation } from "./hooks/managedIdentity/useChangePasswordMutation";
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var e=require("@saasquatch/dom-context-hooks"),n=require("dom-context"),t=require("jwt-decode"),r=require("@wry/equality"),a=require("graphql"),o=require("@saasquatch/universal-hooks"),i=require("fast-memoize"),s=require("rxjs"),u=require("rxjs/operators"),c=require("nanoid"),d=require("graphql-request/dist/types"),l=require("graphql-request"),f=require("graphql-combine-query"),m=require("history"),v=require("debounce"),p=require("jsonpointer");function g(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var h=g(t),y=g(i),w=g(f),C=g(v),b=g(p),q={current:void 0};function I(){if(void 0===q.current)throw new Error("no implementation of useHost provided");return q.current()}function P(){var e;window.squatchProgramId||(window.squatchProgramId=new n.ContextProvider({element:document.documentElement,initialState:(null==(e=window.widgetIdent)?void 0:e.programId)||void 0,contextName:"sq:program-id"}).start())}function E(){P();var n=I();return e.useDomContext(n,"sq:program-id")}function F(){var e,n;return window.SquatchAndroid?{type:"SquatchAndroid",android:window.SquatchAndroid,widgetIdent:window.widgetIdent}:window.SquatchPortal?{type:"SquatchPortal",env:window.SquatchPortal}:window.SquatchAdmin?{type:"SquatchAdmin",adminSDK:window.SquatchAdmin}:window.widgetIdent&&"demo"!==(null==(e=window.widgetIdent)?void 0:e.env)?{type:"SquatchJS2",api:null==(n=window.frameElement)?void 0:n.squatchJsApi,widgetIdent:window.widgetIdent}:{type:"None"}}function S(){var e=F();switch(e.type){case"SquatchAndroid":case"SquatchJS2":return e.widgetIdent.tenantAlias;case"SquatchAdmin":case"None":return"demo";case"SquatchPortal":return e.env.tenantAlias}}function x(){var e,n=F();switch(n.type){case"SquatchAndroid":case"SquatchJS2":return n.widgetIdent.appDomain;case"SquatchPortal":return(null==(e=n.env)?void 0:e.appDomain)||"https://app.referralsaasquatch.com";case"SquatchAdmin":case"None":return"https://app.referralsaasquatch.com"}}function M(){var e=F();switch(e.type){case"SquatchJS2":return e.widgetIdent.engagementMedium||"EMBED";case"SquatchAndroid":case"SquatchPortal":case"SquatchAdmin":case"None":return"EMBED"}}function D(){return(D=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function A(e,n){return(A=Object.setPrototypeOf||function(e,n){return e.__proto__=n,e})(e,n)}function k(e,n){return n||(n=e.slice(0)),e.raw=n,e}function j(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function $(e,n){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return j(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?j(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){t&&(e=t);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}var R=1e3,V=60*R,O=60*V,N=24*O,H=function(e,n){n=n||{};var t=typeof e;if("string"===t&&e.length>0)return function(e){if(!((e=String(e)).length>100)){var n=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(n){var t=parseFloat(n[1]);switch((n[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*t;case"weeks":case"week":case"w":return 6048e5*t;case"days":case"day":case"d":return t*N;case"hours":case"hour":case"hrs":case"hr":case"h":return t*O;case"minutes":case"minute":case"mins":case"min":case"m":return t*V;case"seconds":case"second":case"secs":case"sec":case"s":return t*R;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}(e);if("number"===t&&isFinite(e))return n.long?function(e){var n=Math.abs(e);return n>=N?L(e,n,N,"day"):n>=O?L(e,n,O,"hour"):n>=V?L(e,n,V,"minute"):n>=R?L(e,n,R,"second"):e+" ms"}(e):function(e){var n=Math.abs(e);return n>=N?Math.round(e/N)+"d":n>=O?Math.round(e/O)+"h":n>=V?Math.round(e/V)+"m":n>=R?Math.round(e/R)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function L(e,n,t,r){var a=n>=1.5*t;return Math.round(e/t)+" "+r+(a?"s":"")}var W,U=(function(e,n){n.formatArgs=function(n){if(n[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+n[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const t="color: "+this.color;n.splice(1,0,t,"color: inherit");let r=0,a=0;n[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(a=r))}),n.splice(a,0,t)},n.save=function(e){try{e?n.storage.setItem("debug",e):n.storage.removeItem("debug")}catch(e){}},n.load=function(){let e;try{e=n.storage.getItem("debug")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},n.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},n.storage=function(){try{return localStorage}catch(e){}}(),n.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),n.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],n.log=console.debug||console.log||(()=>{}),e.exports=function(e){function n(e){let r,a=null;function o(...e){if(!o.enabled)return;const t=o,a=Number(new Date);t.diff=a-(r||a),t.prev=r,t.curr=a,r=a,e[0]=n.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let i=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(r,a)=>{if("%%"===r)return"%";i++;const o=n.formatters[a];return"function"==typeof o&&(r=o.call(t,e[i]),e.splice(i,1),i--),r}),n.formatArgs.call(t,e),(t.log||n.log).apply(t,e)}return o.namespace=e,o.useColors=n.useColors(),o.color=n.selectColor(e),o.extend=t,o.destroy=n.destroy,Object.defineProperty(o,"enabled",{enumerable:!0,configurable:!1,get:()=>null===a?n.enabled(e):a,set:e=>{a=e}}),"function"==typeof n.init&&n.init(o),o}function t(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function r(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(r),...n.skips.map(r).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),a=r.length;for(t=0;t<a;t++)r[t]&&("-"===(e=r[t].replace(/\*/g,".*?"))[0]?n.skips.push(new RegExp("^"+e.substr(1)+"$")):n.names.push(new RegExp("^"+e+"$")))},n.enabled=function(e){if("*"===e[e.length-1])return!0;let t,r;for(t=0,r=n.skips.length;t<r;t++)if(n.skips[t].test(e))return!1;for(t=0,r=n.names.length;t<r;t++)if(n.names[t].test(e))return!0;return!1},n.humanize=H,n.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach(t=>{n[t]=e[t]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return n.colors[Math.abs(t)%n.colors.length]},n.enable(n.load()),n}(n);const{formatters:t}=e.exports;t.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(W={exports:{}},W.exports),W.exports),Q=U("sq:user-identity");function _(){window.squatchUserIdentity||(window.squatchUserIdentity=new n.ContextProvider({element:document.documentElement,initialState:J(),contextName:"sq:user-identity"}).start())}function T(e){if(e)try{var n,t,r=h.default(e),a=r.exp;if(function(e){return e.sub&&/.*:.*@.*:users/.test(e.sub)}(r)){var o=r.sub.match(/(.*):(.*)@(.*):users/);t=atob(o[1]),n=atob(o[2])}else(function(e){return e.user&&e.user.id&&e.user.accountId})(r)&&(t=r.user.accountId,n=r.user.id);if(!n||!t)return;if(a&&Date.now()>=1e3*a)return;return{id:n,accountId:t,jwt:e}}catch(e){return}}function J(){var e=F();switch(e.type){case"SquatchAndroid":case"SquatchJS2":return{id:e.widgetIdent.userId,accountId:e.widgetIdent.accountId,jwt:e.widgetIdent.token};case"SquatchPortal":var n=new URLSearchParams(document.location.search);if(n.has("jwt"))return T(n.get("jwt"));var t=localStorage.getItem("sq:user-identity");if(!t)return;try{var r=JSON.parse(t),a=T(r.jwt);return a?D({},r,a):void 0}catch(e){return}case"SquatchAdmin":case"None":return}}function G(e){_();var n=window.squatchUserIdentity;r.equal(n.context,e)||(n.context=e),e&&"SquatchPortal"===F().type?localStorage.setItem("sq:user-identity",JSON.stringify(e)):e||(Q("Deleting user from localStorage"),localStorage.removeItem("sq:user-identity"))}function z(){var e;return null==(e=B())?void 0:e.jwt}function B(){_();var n=I(),t=e.useDomContext(n,"sq:user-identity"),r=T(null==t?void 0:t.jwt);if(!t||r)return t;G(void 0)}var K=function(){return(K=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var a in n=arguments[t])Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a]);return e}).apply(this,arguments)},Z=new Map,X=new Map,Y=!0,ee=!1;function ne(e){return e.replace(/[\s,]+/g," ").trim()}function te(e){var n,t,r,o=ne(e);if(!Z.has(o)){var i=a.parse(e,{experimentalFragmentVariables:ee});if(!i||"Document"!==i.kind)throw new Error("Not a valid GraphQL document.");Z.set(o,function(e){var n=new Set(e.definitions);n.forEach(function(e){e.loc&&delete e.loc,Object.keys(e).forEach(function(t){var r=e[t];r&&"object"==typeof r&&n.add(r)})});var t=e.loc;return t&&(delete t.startToken,delete t.endToken),e}((n=i,t=new Set,r=[],n.definitions.forEach(function(e){if("FragmentDefinition"===e.kind){var n=e.name.value,a=ne((i=e.loc).source.body.substring(i.start,i.end)),o=X.get(n);o&&!o.has(a)?Y&&console.warn("Warning: fragment with name "+n+" already exists.\ngraphql-tag enforces all fragment names across your application to be unique; read more about\nthis in the docs: http://dev.apollodata.com/core/fragments.html#unique-names"):o||X.set(n,o=new Set),o.add(a),t.has(a)||(t.add(a),r.push(e))}else r.push(e);var i}),K(K({},n),{definitions:r}))))}return Z.get(o)}function re(e){for(var n=[],t=1;t<arguments.length;t++)n[t-1]=arguments[t];"string"==typeof e&&(e=[e]);var r=e[0];return n.forEach(function(n,t){r+=n&&"Document"===n.kind?n.loc.source.body:n,r+=e[t+1]}),te(r)}var ae,oe=re;(ae=re||(re={})).gql=oe,ae.resetCaches=function(){Z.clear(),X.clear()},ae.disableFragmentWarnings=function(){Y=!1},ae.enableExperimentalFragmentVariables=function(){ee=!0},ae.disableExperimentalFragmentVariables=function(){ee=!1},re.default=re;var ie=re;function se(e,n){try{var t=e()}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}var ue=function(e){var n,t;function r(n,t){var r;(r=e.call(this,n,t)||this).subject=new s.Subject;var o=new s.Subject;return r.subject.pipe(u.bufferTime(200,void 0,10)).subscribe(function(e){try{if(!e.length)return Promise.resolve();for(var n,t=fe(e),i=t.mergedQuery,s=t.mergedVariables,u=t.mergedQueryAddedEvents,c=$(t.unmergedQueryAddedEvents);!(n=c()).done;)o.next(n.value);return u.length?Promise.resolve(se(function(){return Promise.resolve(r.superRequest(i,s)).then(function(e){pe(e,u)})},function(e){if(e instanceof d.ClientError){var n=function(){var n=e.response,t=n.data,r=n.errors;if(!t)return{v:he(u,e)};for(var o,i=Object.keys(t),s=[].concat(u),c=function(){var n=o.value,t=void 0;n.path.find(function(r,o,u){if(i.includes(r)){var c=le(r),l=s.findIndex(function(e){return e.id===c});if(-1===l)return!1;i.splice(o,1),t=s.splice(l,1)[0];var f=me(e.response.data,t);u[o]=de(u[o],c);var m=t.query,v=t.variables,p=D({},e.response,{errors:[n],data:f,path:u}),g=new d.ClientError(p,{query:"string"!=typeof m?a.print(m):m,variables:v});return ge(t,g),!0}return!1})},l=$(r);!(o=l()).done;)c();pe(t,s)}();if("object"==typeof n)return n.v}else he(u,e)})):Promise.resolve()}catch(e){return Promise.reject(e)}}),o.subscribe(function(e){try{var n=se(function(){return Promise.resolve(r.superRequest(e.query,e.variables)).then(function(n){ve(n,e)})},function(n){ge(e,n)});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}),r}t=e,(n=r).prototype=Object.create(t.prototype),n.prototype.constructor=n,A(n,t);var o=r.prototype;return o.superRequest=function(n,t){return e.prototype.request.call(this,n,t)},o.request=function(e,n){var t=this;return new Promise(function(r,a){var o={query:e,variables:n,id:ce(),resolve:r,reject:a};t.subject.next(o)})},r}(l.GraphQLClient),ce=function(){return c.nanoid().replace(/[-_]/g,"")},de=function(e,n){return e.replace("_"+n,"")},le=function(e){var n=e.split("_");return n[n.length-1]},fe=function(e){var n=[],t=[],r=e.reduce(function(e,r){var o=r.query,i=r.variables,s=r.id;try{var u="string"==typeof o?a.parse(o):o,c=u.definitions.find(function(e){return"FragmentDefinition"===e.kind}),d="string"==typeof o?o:a.print(o),l=/@/.test(d);if(c||l)return t.push(r),e;var f=function(e){return function(e,n){return e+"_"+n}(e,s)};return e=e.addN(u,[i],f,f),n.push(r),e}catch(n){return t.push(r),e}},w.default("BatchedQuery")),o=r.document,i=r.variables;return{mergedQuery:o&&a.print(o),mergedVariables:i,mergedQueryAddedEvents:n,unmergedQueryAddedEvents:t}},me=function(e,n){if(!e)return e;var t=Object.keys(e),r=n.id;return t.reduce(function(n,t){var a;return t.endsWith(r)&&(n=D({},n,((a={})[de(t,r)]=e[t],a))),n},{})},ve=function(e,n){(0,n.resolve)(e)},pe=function(e,n){for(var t,r=$(n);!(t=r()).done;){var a=t.value,o=me(e,a);a.resolve(o)}},ge=function(e,n){(0,e.reject)(n)},he=function(e,n){for(var t,r=$(e);!(t=r()).done;)(0,t.value.reject)(n)},ye=y.default(function(e,n,t){return new ue(e+"/api/v1/"+n+"/graphql",{headers:{Authorization:"Bearer "+(t||"")}})});function we(e,n){switch(n.type){case"loading":return{data:void 0,errors:void 0,loading:!0};case"data":return{data:n.payload,errors:void 0,loading:!1};case"errors":return{data:void 0,errors:n.payload,loading:!1}}}function Ce(n,t){var r,a,i,s,u,c,d=(r=z(),a=x(),i=S(),s=ye(a,i,r),u=I(),null!=(c=e.useDomContext(u,"sq:graphql-client",{attempts:0}))?c:s),l=o.useReducer(we,t),f=l[1];return[l[0],o.useCallback(function(e,t){void 0===t&&(t=!1);try{if(!d)return f({type:"errors",payload:new Error("No GraphQL client found")}),Promise.resolve();var r=function(r,a){try{var o=(t||f({type:"loading"}),Promise.resolve(d.request(n,e)).then(function(e){f({type:"data",payload:e})}))}catch(e){return a(e)}return o&&o.then?o.then(void 0,a):o}(0,function(e){f({type:"errors",payload:e})});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},[d,n,f])]}var be,qe={loading:!1,data:void 0,errors:void 0};function Ie(e){var n=Ce(e,qe);return[n[1],n[0]]}var Pe,Ee,Fe,Se,xe=ie(be||(be=k(["\n mutation AuthenticateWithEmailAndPassword(\n $email: String!\n $password: String!\n ) {\n authenticateManagedIdentityWithEmailAndPassword(\n authenticateManagedIdentityWithEmailAndPasswordInput: {\n email: $email\n password: $password\n }\n ) {\n token\n email\n emailVerified\n sessionData\n }\n }\n"]))),Me=ie(Pe||(Pe=k(["\n mutation RegisterWithEmailAndPassword(\n $email: String!\n $password: String!\n $formData: RSJsonNode\n $redirectPath: String\n ) {\n registerManagedIdentityWithEmailAndPassword(\n registerManagedIdentityWithEmailAndPasswordInput: {\n email: $email\n password: $password\n formData: $formData\n redirectPath: $redirectPath\n }\n ) {\n token\n email\n emailVerified\n sessionData\n }\n }\n"]))),De=ie(Ee||(Ee=k(["\n mutation ChangePassword($password: String!) {\n changeManagedIdentityPassword(\n changeManagedIdentityPasswordInput: { password: $password }\n ) {\n success\n }\n }\n"]))),Ae=ie(Fe||(Fe=k(["\n mutation ResetPassword($oobCode: String!, $password: String!) {\n resetManagedIdentityPassword(\n resetManagedIdentityPasswordInput: {\n password: $password\n oobCode: $oobCode\n }\n ) {\n token\n email\n emailVerified\n sessionData\n }\n }\n"]))),ke=ie(Se||(Se=k(["\n mutation VerifyPasswordResetCode($oobCode: String!) {\n verifyManagedIdentityPasswordResetCode(\n verifyManagedIdentityPasswordResetCodeInput: { oobCode: $oobCode }\n ) {\n success\n }\n }\n"])));function je(e){var n=e.skip,t=void 0!==n&&n,a=e.update,i=e.variables;o.useEffect(function(){var e=function(e){!t&&a(i,!0)};return document.addEventListener("sq:refresh",e),function(){return document.removeEventListener("sq:refresh",e)}},function(e){var n=o.useRef(e),t=o.useRef(0);return r.equal(e,n.current)||(n.current=e,t.current+=1),o.useMemo(function(){return n.current},[t.current])}([e.query,i,a,t]))}var $e,Re={loading:!1,data:void 0,errors:void 0},Ve=Symbol();function Oe(e){var n=Ce(e,Re),t=n[0],r=n[1],a=o.useRef(Ve);return je({skip:a.current===Ve,update:r,variables:a.current,query:e}),[r,D({},t,{refetch:function(e){a.current=e,r(e)}})]}var Ne,He=ie($e||($e=k(["\n query ManagedIdentity {\n managedIdentity {\n email\n emailVerified\n sessionData\n }\n }\n"])));function Le(){var e=B(),n=Oe(He),t=n[0],r=n[1],a=r.loading,i=r.data,s=r.errors,u=r.refetch;return o.useEffect(function(){null!=i&&i.managedIdentity&&G(D({},e,{managedIdentity:i.managedIdentity}))},[null==i?void 0:i.managedIdentity]),[o.useCallback(function(){return t({})},[t]),{loading:a,data:i,errors:s,refetch:u}]}var We,Ue,Qe=ie(Ne||(Ne=k(["\n mutation VerifyEmail($oobCode: String!) {\n verifyManagedIdentityEmail(\n verifyManagedIdentityEmailInput: { oobCode: $oobCode }\n ) {\n success\n }\n }\n"]))),_e=ie(We||(We=k(["\n mutation RequestPasswordResetEmail(\n $email: String!\n $urlParams: RSJsonNode\n $redirectPath: String\n ) {\n requestManagedIdentityPasswordResetEmail(\n requestManagedIdentityPasswordResetEmailInput: {\n email: $email\n urlParams: $urlParams\n redirectPath: $redirectPath\n }\n ) {\n success\n }\n }\n"]))),Te=ie(Ue||(Ue=k(["\n mutation RequestVerificationEmail(\n $email: String!\n $urlParams: RSJsonNode\n $redirectPath: String\n ) {\n requestManagedIdentityVerificationEmail(\n requestManagedIdentityVerificationEmailInput: {\n email: $email\n urlParams: $urlParams\n redirectPath: $redirectPath\n }\n ) {\n success\n }\n }\n"])));function Je(e,n){var t=o.useRef();return t.current&&r.equal(n,t.current.key)||(t.current={key:n,value:e()}),t.current.value}function Ge(){return o.useReducer(function(e){return e+1},0)}function ze(e){for(var n,t=$(Object.getOwnPropertyNames(e));!(n=t()).done;){var r=e[n.value];r&&"object"==typeof r&&ze(r)}return Object.freeze(e)}var Be={loading:!0,data:void 0,errors:void 0};function Ke(e,n,t){var r=Ce(e,Be),a=r[0],o=r[1],i=Ge(),s=i[1];return Je(function(){!t&&o(n)},[e,n,o,i[0],t]),je({skip:t,update:o,variables:n,query:e}),ze(D({},a,{refetch:s}))}function Ze(){return window.squatchHistory=window.squatchHistory||function(){switch(F().type){case"SquatchPortal":return m.createBrowserHistory();default:return m.createMemoryHistory()}}(),window.squatchHistory}var Xe,Ye={createHref:function(){var e;return(e=Ze()).createHref.apply(e,[].slice.call(arguments))},push:function(){var e;return(e=Ze()).push.apply(e,[].slice.call(arguments))},replace:function(){var e;return(e=Ze()).replace.apply(e,[].slice.call(arguments))},go:function(){var e;return(e=Ze()).go.apply(e,[].slice.call(arguments))},back:function(){return Ze().back()},forward:function(){var e;return(e=Ze()).forward.apply(e,[].slice.call(arguments))}};function en(e){var n=o.useState({limit:e.limit,offset:e.offset}),t=n[0],r=n[1],a=t.offset,i=t.limit,s=function(e,n){return e*n},u=function(e,n){return Math.ceil(e/n)||0};return{limit:i,setLimit:function(e){var n=u(a,e),o=s(e,n);r(D({},t,{limit:e,offset:o}))},offset:a,setCurrentPage:function(e){var n=s(e,i);r(function(e){return D({},e,{offset:n})})},calculatePagination:function(e,n){var t=u(a,i),r=function(e,n){return Math.ceil(e/n)||0}(n,i),o=0===e?"0":e>1?a+1+"-"+(a+e):""+(a+1);return{currentPage:t,pageCount:r,rangeOnPage:o,pageProgress:o+" of "+n}}}}function nn(e,n){return e===n}function tn(e,n,t){void 0===n&&(n=0),void 0===t&&(t={leading:!1});var r=o.useMemo(function(){return C.default(e,n,t.leading)},[e,n,t.leading]);return{flush:r.flush,cancel:r.clear,callback:r}}var rn,an,on,sn=l.gql(Xe||(Xe=k(["\n mutation ($eventMeta: UserAnalyticsEvent!) {\n createUserAnalyticsEvent(eventMeta: $eventMeta)\n }\n"]))),un=U("sq:useForm"),cn=l.gql(rn||(rn=k(["\n query ($key: String!) {\n form(key: $key) {\n schema\n initialData {\n initialData\n isEnabled\n isEnabledErrorMessage\n }\n }\n }\n"]))),dn=l.gql(an||(an=k(["\n mutation ($formSubmissionInput: FormSubmissionInput!) {\n submitForm(formSubmissionInput: $formSubmissionInput) {\n success\n results {\n ... on FormHandlerSubmissionResult {\n formHandler {\n name\n endpointUrl\n integration {\n name\n }\n }\n result\n }\n ... on FormHandlerError {\n formHandler {\n name\n endpointUrl\n integration {\n name\n }\n }\n errorType\n error\n errorCode\n }\n }\n }\n }\n"]))),ln=l.gql(on||(on=k(["\n query ($formValidationInput: FormValidationInput!) {\n validateForm(formValidationInput: $formValidationInput) {\n valid\n results {\n ... on FormHandlerValidationResult {\n formHandler {\n name\n endpointUrl\n integration {\n name\n }\n }\n result\n }\n ... on FormHandlerError {\n formHandler {\n name\n endpointUrl\n integration {\n name\n }\n }\n errorType\n error\n errorCode\n }\n }\n }\n }\n"])));exports.BatchedGraphQLClient=ue,exports.GRAPHQL_CONTEXT="sq:graphql-client",exports.getEnvironmentSDK=F,exports.isDemo=function(){var e=F();return"None"===e.type||"SquatchAdmin"===e.type},exports.memoizedGraphQLClient=ye,exports.navigation=Ye,exports.setProgramId=function(e){P(),window.squatchProgramId.context=e},exports.setUseHostImplementation=function(e){if(!e)throw new Error("Must supply an implementation");if("function"!=typeof e)throw new Error("implementation must be a function");q.current=e},exports.setUserIdentity=G,exports.useAppDomain=x,exports.useAuthenticateWithEmailAndPasswordMutation=function(){var e=Ie(xe),n=e[0],t=e[1],r=t.loading,a=t.data,i=t.errors;return o.useEffect(function(){if(null!=a&&a.authenticateManagedIdentityWithEmailAndPassword){var e=a.authenticateManagedIdentityWithEmailAndPassword,n=e.token,t=h.default(n).user;G({jwt:n,id:t.id,accountId:t.accountId,managedIdentity:{email:e.email,emailVerified:e.emailVerified,sessionData:e.sessionData}})}},[null==a?void 0:a.authenticateManagedIdentityWithEmailAndPassword]),[n,{loading:r,data:a,errors:i}]},exports.useChangePasswordMutation=function(){var e=Ie(De),n=e[1];return[e[0],{loading:n.loading,data:n.data,errors:n.errors}]},exports.useCurrentPage=function(){var e=Ge()[1];return o.useEffect(function(){return Ze().listen(function(){e()})},[]),Ze().location},exports.useDebounce=function(e,n,t){var r=t&&t.equalityFn||nn,a=o.useState(e),i=a[0],s=a[1],u=tn(o.useCallback(function(e){return s(e)},[]),n,t),c=o.useRef(e);return o.useEffect(function(){r(c.current,e)||(u.callback(e),c.current=e)},[e,u,r]),[i,{cancel:u.cancel,flush:u.flush}]},exports.useDebouncedCallback=tn,exports.useEngagementMedium=M,exports.useForm=function(e){var n,t,r,a,i=function(e){try{return Promise.resolve(C({formValidationInput:{key:s,formData:e}})).then(function(){})}catch(e){return Promise.reject(e)}},s=e.formKey,u=e.formRef,c=e.autoSubmit,d=void 0!==c&&c,l=Oe(cn),f=l[0],m=l[1],v=m.data,p=m.loading,g=Ie(dn),h=g[0],y=g[1],w=Oe(ln),C=w[0],q=w[1],I=o.useReducer(function(e,n){return D({},e,n)},{enabled:!1,validating:!1,valid:!0,validationMessage:"",error:"",disabledMessage:"",formData:{},validationData:q,submitData:y}),P=I[0],E=I[1],F=P.enabled,S=P.disabledMessage,x=P.validating,M=P.valid,A=P.error,k=P.formData;return Je(function(){un("submitData useEffect",y),E({submitData:y})},[y]),Je(function(){un("validationData useEffect",q),E({validationData:q})},[q]),o.useEffect(function(){!p&&v&&function(){var n,t,r,a,o;E({enabled:null==v||null==(n=v.form.initialData)?void 0:n.isEnabled,disabledMessage:null==v||null==(t=v.form)||null==(r=t.initialData)?void 0:r.isEnabledErrorMessage});var i=u;if(i){var s=null==v||null==(a=v.form)||null==(o=a.initialData)?void 0:o.initialData;void 0!==e.setInitialData?e.setInitialData(i,s):function(e,n){try{var t=e.elements,r=new FormData(e);un({htmlForm:e,formContent:r}),null==r||r.forEach(function(e,r){un({value:e,key:r,inputs:t});var a=t.namedItem(r);try{"checkbox"==a.type?a.checked=b.default.get(n,r):a.value=b.default.get(n,r)||""}catch(e){un("no initialData found for key",r)}}),Promise.resolve()}catch(e){return Promise.reject(e)}}(i,s)}}()},[p]),o.useEffect(function(){var e,n,t,r,a,o;P.validationData&&(E({validating:!1,valid:(null==(e=P.validationData)||null==(n=e.data)||null==(t=n.validateForm)?void 0:t.valid)||!1}),d&&null!=(r=P.validationData)&&null!=(a=r.data)&&null!=(o=a.validateForm)&&o.valid&&h({formSubmissionInput:{key:s,formData:k}}))},[null==(n=P.validationData)||null==(t=n.data)||null==(r=t.validateForm)?void 0:r.valid]),{states:{enabled:F,disabledMessage:S,loadingForm:p,validating:x,valid:M,error:A,validationData:P.validationData,submitData:P.submitData},data:{formKey:s,schema:null==v||null==(a=v.form)?void 0:a.schema},callbacks:{getForm:f,handleSubmit:function(e){try{e.preventDefault(),E({validating:!0});var n=e.target;un("submit form",n);for(var t,r=new FormData(n),a={},o=$(r.entries());!(t=o()).done;){var s=t.value;b.default.set(a,s[0],s[1])}return E({formData:a}),Promise.resolve(i(a)).then(function(){})}catch(e){return Promise.reject(e)}},validateForm:i,submitForm:function(e){try{return Promise.resolve(h({formSubmissionInput:{key:s,formData:e}})).then(function(){})}catch(e){return Promise.reject(e)}},setFormState:E,getValidationErrors:function(){var e,n,t,r,a=null==q||null==(e=q.data)||null==(n=e.validateForm)||null==(t=n.results[0])||null==(r=t.result)?void 0:r.errors;function o(e){return null==a?void 0:a.filter(function(n){return n.instanceLocation.substring(1).startsWith(""+e)})}return{getErrorAtPath:function(e){return null==a?void 0:a.filter(function(n){return n.instanceLocation.substring(1)===e})},getSubErrorsAtPath:o,hasSubErrors:function(e){var n;return(null==(n=o(e))?void 0:n.length)>0}}},getSubmissionErrors:function(){var e;if(!P.submitData)return[];var n=null==(e=P.submitData.data)?void 0:e.submitForm.results;return(null==n?void 0:n.map(function(e){var n,t,r,a,o,i,s,u=null==(n=e.result)||null==(t=n.results)?void 0:t.flatMap(function(e){return!e.success&&e.message}).filter(function(e){return e}),c=null==(r=e.result)||null==(a=r.results)?void 0:a.flatMap(function(e){return!e.success&&{error:e.error,errorType:e.errorType,errorCode:e.errorCode}}).filter(function(e){return e.error});return{integration:null==(o=e.formHandler)||null==(i=o.integration)?void 0:i.name,formHandler:null==(s=e.formHandler)?void 0:s.name,messages:u,errors:c}}))||[]}}}},exports.useHost=I,exports.useLazyQuery=Oe,exports.useLocale=function(){return(n=null==(e=navigator.language)?void 0:e.split("-"))&&1!==n.length?n[0]+"_"+n[1].toUpperCase():e;var e,n},exports.useManagedIdentityQuery=Le,exports.useMutation=Ie,exports.usePaginatedQuery=function(e,n,t,r,a){var o;void 0===r&&(r={}),void 0===a&&(a=!1);var i=en(t),s=i.limit,u=i.setLimit,c=i.setCurrentPage,d=i.calculatePagination,l=Ke(e,D({limit:s,offset:i.offset},r),a),f=l.loading,m=l.errors,v=l.refetch,p=n(l.data),g=d((null==p||null==(o=p.data)?void 0:o.length)||0,(null==p?void 0:p.totalCount)||0);return{envelope:p,states:{errors:m,loading:f,limit:s,currentPage:g.currentPage,pageCount:g.pageCount,pageProgress:g.pageProgress},callbacks:{refetch:v,setLimit:u,setCurrentPage:c}}},exports.usePagination=en,exports.useProgramId=E,exports.useQuery=Ke,exports.useRefreshDispatcher=function(){var e=I();return{refresh:o.useCallback(function(){e.dispatchEvent(new CustomEvent("sq:refresh",{bubbles:!0,composed:!0,cancelable:!0,detail:{}}))},[e])}},exports.useRegisterWithEmailAndPasswordMutation=function(){var e=Ie(Me),n=e[0],t=e[1],r=t.loading,a=t.data,i=t.errors;return o.useEffect(function(){if(null!=a&&a.registerManagedIdentityWithEmailAndPassword){var e=a.registerManagedIdentityWithEmailAndPassword,n=e.token,t=h.default(n).user;G({jwt:n,id:t.id,accountId:t.accountId,managedIdentity:{email:e.email,emailVerified:e.emailVerified,sessionData:e.sessionData}})}},[null==a?void 0:a.registerManagedIdentityWithEmailAndPassword]),[n,{loading:r,data:a,errors:i}]},exports.useRequestPasswordResetEmailMutation=function(){return Ie(_e)},exports.useRequestVerificationEmailMutation=function(){return Ie(Te)},exports.useResetPasswordMutation=function(){var e=Ie(Ae),n=e[0],t=e[1],r=t.loading,a=t.data,i=t.errors;return o.useEffect(function(){if(null!=a&&a.resetManagedIdentityPassword){var e=a.resetManagedIdentityPassword,n=e.token,t=h.default(n).user;G({jwt:n,id:t.id,accountId:t.accountId,managedIdentity:{email:e.email,emailVerified:e.emailVerified,sessionData:e.sessionData}})}},[null==a?void 0:a.resetManagedIdentityPassword]),[n,{loading:r,data:a,errors:i}]},exports.useShareEvent=function(){var e=M(),n=B(),t=E(),r=Ie(sn)[0];return n?function(a){r({eventMeta:{id:n.id,accountId:n.accountId,programId:t,type:"USER_REFERRAL_PROGRAM_ENGAGEMENT_EVENT",meta:{engagementMedium:e,shareMedium:a}}})}:function(){}},exports.useTenantAlias=S,exports.useTick=Ge,exports.useToken=z,exports.useUserIdentity=B,exports.useVerifyEmailMutation=function(){var e,n=Le()[0],t=Ie(Qe),r=t[0],a=t[1],i=a.loading,s=a.data,u=a.errors;return o.useEffect(function(){var e;null!=s&&null!=(e=s.verifyManagedIdentityEmail)&&e.success&&n()},[null==s||null==(e=s.verifyManagedIdentityEmail)?void 0:e.success]),[r,{loading:i,data:s,errors:u}]},exports.useVerifyPasswordResetCodeMutation=function(){return Ie(ke)};
1
+ var e=require("@saasquatch/dom-context-hooks"),n=require("dom-context"),t=require("graphql-request"),r=require("jwt-decode"),a=require("@wry/equality"),o=require("graphql"),i=require("@saasquatch/universal-hooks"),s=require("fast-memoize"),u=require("rxjs"),c=require("rxjs/operators"),d=require("nanoid"),l=require("graphql-request/dist/types"),f=require("graphql-combine-query"),m=require("history"),v=require("debounce"),p=require("jsonpointer");function g(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var h=g(r),y=g(s),w=g(f),C=g(v),b=g(p),q={current:void 0};function I(){if(void 0===q.current)throw new Error("no implementation of useHost provided");return q.current()}function P(){var e;window.squatchProgramId||(window.squatchProgramId=new n.ContextProvider({element:document.documentElement,initialState:(null==(e=window.widgetIdent)?void 0:e.programId)||void 0,contextName:"sq:program-id"}).start())}function E(){P();var n=I();return e.useDomContext(n,"sq:program-id")}function F(){return(F=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function S(e,n){return(S=Object.setPrototypeOf||function(e,n){return e.__proto__=n,e})(e,n)}function x(e,n){return n||(n=e.slice(0)),e.raw=n,e}function M(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function D(e,n){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return M(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?M(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){t&&(e=t);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}var A=function(){return(A=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var a in n=arguments[t])Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a]);return e}).apply(this,arguments)},k=new Map,j=new Map,$=!0,R=!1;function V(e){return e.replace(/[\s,]+/g," ").trim()}function O(e){var n,t,r,a=V(e);if(!k.has(a)){var i=o.parse(e,{experimentalFragmentVariables:R});if(!i||"Document"!==i.kind)throw new Error("Not a valid GraphQL document.");k.set(a,function(e){var n=new Set(e.definitions);n.forEach(function(e){e.loc&&delete e.loc,Object.keys(e).forEach(function(t){var r=e[t];r&&"object"==typeof r&&n.add(r)})});var t=e.loc;return t&&(delete t.startToken,delete t.endToken),e}((n=i,t=new Set,r=[],n.definitions.forEach(function(e){if("FragmentDefinition"===e.kind){var n=e.name.value,a=V((i=e.loc).source.body.substring(i.start,i.end)),o=j.get(n);o&&!o.has(a)?$&&console.warn("Warning: fragment with name "+n+" already exists.\ngraphql-tag enforces all fragment names across your application to be unique; read more about\nthis in the docs: http://dev.apollodata.com/core/fragments.html#unique-names"):o||j.set(n,o=new Set),o.add(a),t.has(a)||(t.add(a),r.push(e))}else r.push(e);var i}),A(A({},n),{definitions:r}))))}return k.get(a)}function N(e){for(var n=[],t=1;t<arguments.length;t++)n[t-1]=arguments[t];"string"==typeof e&&(e=[e]);var r=e[0];return n.forEach(function(n,t){r+=n&&"Document"===n.kind?n.loc.source.body:n,r+=e[t+1]}),O(r)}var L,H=N;(L=N||(N={})).gql=H,L.resetCaches=function(){k.clear(),j.clear()},L.disableFragmentWarnings=function(){$=!1},L.enableExperimentalFragmentVariables=function(){R=!0},L.disableExperimentalFragmentVariables=function(){R=!1},N.default=N;var W=N,U=1e3,Q=60*U,T=60*Q,_=24*T,J=function(e,n){n=n||{};var t=typeof e;if("string"===t&&e.length>0)return function(e){if(!((e=String(e)).length>100)){var n=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(n){var t=parseFloat(n[1]);switch((n[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*t;case"weeks":case"week":case"w":return 6048e5*t;case"days":case"day":case"d":return t*_;case"hours":case"hour":case"hrs":case"hr":case"h":return t*T;case"minutes":case"minute":case"mins":case"min":case"m":return t*Q;case"seconds":case"second":case"secs":case"sec":case"s":return t*U;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}(e);if("number"===t&&isFinite(e))return n.long?function(e){var n=Math.abs(e);return n>=_?G(e,n,_,"day"):n>=T?G(e,n,T,"hour"):n>=Q?G(e,n,Q,"minute"):n>=U?G(e,n,U,"second"):e+" ms"}(e):function(e){var n=Math.abs(e);return n>=_?Math.round(e/_)+"d":n>=T?Math.round(e/T)+"h":n>=Q?Math.round(e/Q)+"m":n>=U?Math.round(e/U)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function G(e,n,t,r){var a=n>=1.5*t;return Math.round(e/t)+" "+r+(a?"s":"")}var z,B=(function(e,n){n.formatArgs=function(n){if(n[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+n[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const t="color: "+this.color;n.splice(1,0,t,"color: inherit");let r=0,a=0;n[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(a=r))}),n.splice(a,0,t)},n.save=function(e){try{e?n.storage.setItem("debug",e):n.storage.removeItem("debug")}catch(e){}},n.load=function(){let e;try{e=n.storage.getItem("debug")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},n.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},n.storage=function(){try{return localStorage}catch(e){}}(),n.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),n.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],n.log=console.debug||console.log||(()=>{}),e.exports=function(e){function n(e){let r,a=null;function o(...e){if(!o.enabled)return;const t=o,a=Number(new Date);t.diff=a-(r||a),t.prev=r,t.curr=a,r=a,e[0]=n.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let i=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(r,a)=>{if("%%"===r)return"%";i++;const o=n.formatters[a];return"function"==typeof o&&(r=o.call(t,e[i]),e.splice(i,1),i--),r}),n.formatArgs.call(t,e),(t.log||n.log).apply(t,e)}return o.namespace=e,o.useColors=n.useColors(),o.color=n.selectColor(e),o.extend=t,o.destroy=n.destroy,Object.defineProperty(o,"enabled",{enumerable:!0,configurable:!1,get:()=>null===a?n.enabled(e):a,set:e=>{a=e}}),"function"==typeof n.init&&n.init(o),o}function t(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function r(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(r),...n.skips.map(r).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),a=r.length;for(t=0;t<a;t++)r[t]&&("-"===(e=r[t].replace(/\*/g,".*?"))[0]?n.skips.push(new RegExp("^"+e.substr(1)+"$")):n.names.push(new RegExp("^"+e+"$")))},n.enabled=function(e){if("*"===e[e.length-1])return!0;let t,r;for(t=0,r=n.skips.length;t<r;t++)if(n.skips[t].test(e))return!1;for(t=0,r=n.names.length;t<r;t++)if(n.names[t].test(e))return!0;return!1},n.humanize=J,n.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach(t=>{n[t]=e[t]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return n.colors[Math.abs(t)%n.colors.length]},n.enable(n.load()),n}(n);const{formatters:t}=e.exports;t.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(z={exports:{}},z.exports),z.exports),K=B("sq:user-identity");function Z(){window.squatchUserIdentity||(window.squatchUserIdentity=new n.ContextProvider({element:document.documentElement,initialState:Y(),contextName:"sq:user-identity"}).start())}function X(e){if(e)try{var n,t,r=h.default(e),a=r.exp;if(function(e){return e.sub&&/.*:.*@.*:users/.test(e.sub)}(r)){var o=r.sub.match(/(.*):(.*)@(.*):users/);t=atob(o[1]),n=atob(o[2])}else(function(e){return e.user&&e.user.id&&e.user.accountId})(r)&&(t=r.user.accountId,n=r.user.id);if(!n||!t)return;if(a&&Date.now()>=1e3*a)return;return{id:n,accountId:t,jwt:e}}catch(e){return}}function Y(){var e=dn();switch(e.type){case"SquatchAndroid":case"SquatchJS2":return{id:e.widgetIdent.userId,accountId:e.widgetIdent.accountId,jwt:e.widgetIdent.token};case"SquatchPortal":var n=new URLSearchParams(document.location.search);if(n.has("jwt"))return X(n.get("jwt"));var t=localStorage.getItem("sq:user-identity");if(!t)return;try{var r=JSON.parse(t),a=X(r.jwt);return a?F({},r,a):void 0}catch(e){return}case"SquatchAdmin":case"None":return}}function ee(e){Z();var n=window.squatchUserIdentity;a.equal(n.context,e)||(n.context=e),e&&"SquatchPortal"===dn().type?localStorage.setItem("sq:user-identity",JSON.stringify(e)):e||(K("Deleting user from localStorage"),localStorage.removeItem("sq:user-identity"))}function ne(){var e;return null==(e=te())?void 0:e.jwt}function te(){Z();var n=I(),t=e.useDomContext(n,"sq:user-identity"),r=X(null==t?void 0:t.jwt);if(!t||r)return t;ee(void 0)}function re(e,n){try{var t=e()}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}var ae=function(e){var n,t;function r(n,t){var r;(r=e.call(this,n,t)||this).subject=new u.Subject;var a=new u.Subject;return r.subject.pipe(c.bufferTime(200,void 0,10)).subscribe(function(e){try{if(!e.length)return Promise.resolve();for(var n,t=ue(e),i=t.mergedQuery,s=t.mergedVariables,u=t.mergedQueryAddedEvents,c=D(t.unmergedQueryAddedEvents);!(n=c()).done;)a.next(n.value);return u.length?Promise.resolve(re(function(){return Promise.resolve(r.superRequest(i,s)).then(function(e){le(e,u)})},function(e){if(e instanceof l.ClientError){var n=function(){var n=e.response,t=n.data,r=n.errors;if(!t)return{v:me(u,e)};for(var a,i=Object.keys(t),s=[].concat(u),c=function(){var n=a.value,t=void 0;n.path.find(function(r,a,u){if(i.includes(r)){var c=se(r),d=s.findIndex(function(e){return e.id===c});if(-1===d)return!1;i.splice(a,1),t=s.splice(d,1)[0];var f=ce(e.response.data,t);u[a]=ie(u[a],c);var m=t.query,v=t.variables,p=F({},e.response,{errors:[n],data:f,path:u}),g=new l.ClientError(p,{query:"string"!=typeof m?o.print(m):m,variables:v});return fe(t,g),!0}return!1})},d=D(r);!(a=d()).done;)c();le(t,s)}();if("object"==typeof n)return n.v}else me(u,e)})):Promise.resolve()}catch(e){return Promise.reject(e)}}),a.subscribe(function(e){try{var n=re(function(){return Promise.resolve(r.superRequest(e.query,e.variables)).then(function(n){de(n,e)})},function(n){fe(e,n)});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}),r}t=e,(n=r).prototype=Object.create(t.prototype),n.prototype.constructor=n,S(n,t);var a=r.prototype;return a.superRequest=function(n,t){return e.prototype.request.call(this,n,t)},a.request=function(e,n){var t=this;return new Promise(function(r,a){var o={query:e,variables:n,id:oe(),resolve:r,reject:a};t.subject.next(o)})},r}(t.GraphQLClient),oe=function(){return d.nanoid().replace(/[-_]/g,"")},ie=function(e,n){return e.replace("_"+n,"")},se=function(e){var n=e.split("_");return n[n.length-1]},ue=function(e){var n=[],t=[],r=e.reduce(function(e,r){var a=r.query,i=r.variables,s=r.id;try{var u="string"==typeof a?o.parse(a):a,c=u.definitions.find(function(e){return"FragmentDefinition"===e.kind}),d="string"==typeof a?a:o.print(a),l=/@/.test(d);if(c||l)return t.push(r),e;var f=function(e){return function(e,n){return e+"_"+n}(e,s)};return e=e.addN(u,[i],f,f),n.push(r),e}catch(n){return t.push(r),e}},w.default("BatchedQuery")),a=r.document,i=r.variables;return{mergedQuery:a&&o.print(a),mergedVariables:i,mergedQueryAddedEvents:n,unmergedQueryAddedEvents:t}},ce=function(e,n){if(!e)return e;var t=Object.keys(e),r=n.id;return t.reduce(function(n,t){var a;return t.endsWith(r)&&(n=F({},n,((a={})[ie(t,r)]=e[t],a))),n},{})},de=function(e,n){(0,n.resolve)(e)},le=function(e,n){for(var t,r=D(n);!(t=r()).done;){var a=t.value,o=ce(e,a);a.resolve(o)}},fe=function(e,n){(0,e.reject)(n)},me=function(e,n){for(var t,r=D(e);!(t=r()).done;)(0,t.value.reject)(n)},ve=y.default(function(e,n,t){return new ae(e+"/api/v1/"+n+"/graphql",{headers:{Authorization:"Bearer "+(t||"")}})});function pe(e,n){switch(n.type){case"loading":return{data:void 0,errors:void 0,loading:!0};case"data":return{data:n.payload,errors:void 0,loading:!1};case"errors":return{data:void 0,errors:n.payload,loading:!1}}}function ge(n,t){var r,a,o,s,u,c,d=(r=ne(),a=fn(),o=ln(),s=ve(a,o,r),u=I(),null!=(c=e.useDomContext(u,"sq:graphql-client",{attempts:0}))?c:s),l=i.useReducer(pe,t),f=l[1];return[l[0],i.useCallback(function(e,t){void 0===t&&(t=!1);try{if(!d)return f({type:"errors",payload:new Error("No GraphQL client found")}),Promise.resolve();var r=function(r,a){try{var o=(t||f({type:"loading"}),Promise.resolve(d.request(n,e)).then(function(e){f({type:"data",payload:e})}))}catch(e){return a(e)}return o&&o.then?o.then(void 0,a):o}(0,function(e){f({type:"errors",payload:e})});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},[d,n,f])]}var he,ye={loading:!1,data:void 0,errors:void 0};function we(e){var n=ge(e,ye);return[n[1],n[0]]}var Ce,be,qe,Ie,Pe=W(he||(he=x(["\n mutation AuthenticateWithEmailAndPassword(\n $email: String!\n $password: String!\n ) {\n authenticateManagedIdentityWithEmailAndPassword(\n authenticateManagedIdentityWithEmailAndPasswordInput: {\n email: $email\n password: $password\n }\n ) {\n token\n email\n emailVerified\n sessionData\n }\n }\n"]))),Ee=W(Ce||(Ce=x(["\n mutation RegisterWithEmailAndPassword(\n $email: String!\n $password: String!\n $formData: RSJsonNode\n $redirectPath: String\n ) {\n registerManagedIdentityWithEmailAndPassword(\n registerManagedIdentityWithEmailAndPasswordInput: {\n email: $email\n password: $password\n formData: $formData\n redirectPath: $redirectPath\n }\n ) {\n token\n email\n emailVerified\n sessionData\n }\n }\n"]))),Fe=W(be||(be=x(["\n mutation ChangePassword($password: String!) {\n changeManagedIdentityPassword(\n changeManagedIdentityPasswordInput: { password: $password }\n ) {\n success\n }\n }\n"]))),Se=W(qe||(qe=x(["\n mutation ResetPassword($oobCode: String!, $password: String!) {\n resetManagedIdentityPassword(\n resetManagedIdentityPasswordInput: {\n password: $password\n oobCode: $oobCode\n }\n ) {\n token\n email\n emailVerified\n sessionData\n }\n }\n"]))),xe=W(Ie||(Ie=x(["\n mutation VerifyPasswordResetCode($oobCode: String!) {\n verifyManagedIdentityPasswordResetCode(\n verifyManagedIdentityPasswordResetCodeInput: { oobCode: $oobCode }\n ) {\n success\n }\n }\n"])));function Me(e){var n=e.skip,t=void 0!==n&&n,r=e.update,o=e.variables;i.useEffect(function(){var e=function(e){!t&&r(o,!0)};return document.addEventListener("sq:refresh",e),function(){return document.removeEventListener("sq:refresh",e)}},function(e){var n=i.useRef(e),t=i.useRef(0);return a.equal(e,n.current)||(n.current=e,t.current+=1),i.useMemo(function(){return n.current},[t.current])}([o,r,t]))}var De,Ae={loading:!1,data:void 0,errors:void 0},ke=Symbol();function je(e){var n=ge(e,Ae),t=n[0],r=n[1],a=i.useRef(ke);return Me({skip:a.current===ke,update:r,variables:a.current}),[r,F({},t,{refetch:function(e){a.current=e,r(e)}})]}var $e,Re=W(De||(De=x(["\n query ManagedIdentity {\n managedIdentity {\n email\n emailVerified\n sessionData\n }\n }\n"])));function Ve(){var e=te(),n=je(Re),t=n[0],r=n[1],a=r.loading,o=r.data,s=r.errors,u=r.refetch;return i.useEffect(function(){null!=o&&o.managedIdentity&&ee(F({},e,{managedIdentity:o.managedIdentity}))},[null==o?void 0:o.managedIdentity]),[i.useCallback(function(){return t({})},[t]),{loading:a,data:o,errors:s,refetch:u}]}var Oe,Ne,Le=W($e||($e=x(["\n mutation VerifyEmail($oobCode: String!) {\n verifyManagedIdentityEmail(\n verifyManagedIdentityEmailInput: { oobCode: $oobCode }\n ) {\n success\n }\n }\n"]))),He=W(Oe||(Oe=x(["\n mutation RequestPasswordResetEmail(\n $email: String!\n $urlParams: RSJsonNode\n $redirectPath: String\n ) {\n requestManagedIdentityPasswordResetEmail(\n requestManagedIdentityPasswordResetEmailInput: {\n email: $email\n urlParams: $urlParams\n redirectPath: $redirectPath\n }\n ) {\n success\n }\n }\n"]))),We=W(Ne||(Ne=x(["\n mutation RequestVerificationEmail(\n $email: String!\n $urlParams: RSJsonNode\n $redirectPath: String\n ) {\n requestManagedIdentityVerificationEmail(\n requestManagedIdentityVerificationEmailInput: {\n email: $email\n urlParams: $urlParams\n redirectPath: $redirectPath\n }\n ) {\n success\n }\n }\n"])));function Ue(e,n){var t=i.useRef();return t.current&&a.equal(n,t.current.key)||(t.current={key:n,value:e()}),t.current.value}function Qe(){return i.useReducer(function(e){return e+1},0)}function Te(e){for(var n,t=D(Object.getOwnPropertyNames(e));!(n=t()).done;){var r=e[n.value];r&&"object"==typeof r&&Te(r)}return Object.freeze(e)}var _e={loading:!0,data:void 0,errors:void 0};function Je(e,n,t){var r=ge(e,_e),a=r[0],o=r[1],i=Qe(),s=i[1];return Ue(function(){!t&&o(n)},[e,n,o,i[0],t]),Me({skip:t,update:o,variables:n}),Te(F({},a,{refetch:s}))}function Ge(){return window.squatchHistory=window.squatchHistory||function(){switch(dn().type){case"SquatchPortal":return m.createBrowserHistory();default:return m.createMemoryHistory()}}(),window.squatchHistory}var ze,Be={createHref:function(){var e;return(e=Ge()).createHref.apply(e,[].slice.call(arguments))},push:function(){var e;return(e=Ge()).push.apply(e,[].slice.call(arguments))},replace:function(){var e;return(e=Ge()).replace.apply(e,[].slice.call(arguments))},go:function(){var e;return(e=Ge()).go.apply(e,[].slice.call(arguments))},back:function(){return Ge().back()},forward:function(){var e;return(e=Ge()).forward.apply(e,[].slice.call(arguments))}};function Ke(e){var n=i.useState({limit:e.limit,offset:e.offset}),t=n[0],r=n[1],a=t.offset,o=t.limit,s=function(e,n){return e*n},u=function(e,n){return Math.ceil(e/n)||0};return{limit:o,setLimit:function(e){var n=u(a,e),o=s(e,n);r(F({},t,{limit:e,offset:o}))},offset:a,setCurrentPage:function(e){var n=s(e,o);r(function(e){return F({},e,{offset:n})})},calculatePagination:function(e,n){var t=u(a,o),r=function(e,n){return Math.ceil(e/n)||0}(n,o),i=0===e?"0":e>1?a+1+"-"+(a+e):""+(a+1);return{currentPage:t,pageCount:r,rangeOnPage:i,pageProgress:i+" of "+n}}}}function Ze(e,n){return e===n}function Xe(e,n,t){void 0===n&&(n=0),void 0===t&&(t={leading:!1});var r=i.useMemo(function(){return C.default(e,n,t.leading)},[e,n,t.leading]);return{flush:r.flush,cancel:r.clear,callback:r}}var Ye,en,nn,tn,rn=t.gql(ze||(ze=x(["\n mutation ($eventMeta: UserAnalyticsEvent!) {\n createUserAnalyticsEvent(eventMeta: $eventMeta)\n }\n"]))),an=B("sq:useForm"),on=t.gql(Ye||(Ye=x(["\n query ($key: String!) {\n form(key: $key) {\n schema\n initialData {\n initialData\n isEnabled\n isEnabledErrorMessage\n }\n }\n }\n"]))),sn=t.gql(en||(en=x(["\n mutation ($formSubmissionInput: FormSubmissionInput!) {\n submitForm(formSubmissionInput: $formSubmissionInput) {\n success\n results {\n ... on FormHandlerSubmissionResult {\n formHandler {\n name\n endpointUrl\n integration {\n name\n }\n }\n result\n }\n ... on FormHandlerError {\n formHandler {\n name\n endpointUrl\n integration {\n name\n }\n }\n errorType\n error\n errorCode\n }\n }\n }\n }\n"]))),un=t.gql(nn||(nn=x(["\n query ($formValidationInput: FormValidationInput!) {\n validateForm(formValidationInput: $formValidationInput) {\n valid\n results {\n ... on FormHandlerValidationResult {\n formHandler {\n name\n endpointUrl\n integration {\n name\n }\n }\n result\n }\n ... on FormHandlerError {\n formHandler {\n name\n endpointUrl\n integration {\n name\n }\n }\n errorType\n error\n errorCode\n }\n }\n }\n }\n"]))),cn=t.gql(tn||(tn=x(["\n query {\n viewer {\n ... on User {\n locale\n }\n }\n }\n"])));function dn(){var e,n;return window.SquatchAndroid?{type:"SquatchAndroid",android:window.SquatchAndroid,widgetIdent:window.widgetIdent}:window.SquatchPortal?{type:"SquatchPortal",env:window.SquatchPortal}:window.SquatchAdmin?{type:"SquatchAdmin",adminSDK:window.SquatchAdmin}:window.widgetIdent&&"demo"!==(null==(e=window.widgetIdent)?void 0:e.env)?{type:"SquatchJS2",api:null==(n=window.frameElement)?void 0:n.squatchJsApi,widgetIdent:window.widgetIdent}:{type:"None"}}function ln(){var e=dn();switch(e.type){case"SquatchAndroid":case"SquatchJS2":return e.widgetIdent.tenantAlias;case"SquatchAdmin":case"None":return"demo";case"SquatchPortal":return e.env.tenantAlias}}function fn(){var e,n=dn();switch(n.type){case"SquatchAndroid":case"SquatchJS2":return n.widgetIdent.appDomain;case"SquatchPortal":return(null==(e=n.env)?void 0:e.appDomain)||"https://app.referralsaasquatch.com";case"SquatchAdmin":case"None":return"https://app.referralsaasquatch.com"}}function mn(){var e=dn();switch(e.type){case"SquatchJS2":return e.widgetIdent.engagementMedium||"EMBED";case"SquatchAndroid":case"SquatchPortal":case"SquatchAdmin":case"None":return"EMBED"}}exports.BatchedGraphQLClient=ae,exports.GRAPHQL_CONTEXT="sq:graphql-client",exports.getEnvironmentSDK=dn,exports.isDemo=function(){var e=dn();return"None"===e.type||"SquatchAdmin"===e.type},exports.memoizedGraphQLClient=ve,exports.navigation=Be,exports.setLocale=function(e){window.squatchLocale.context=e},exports.setProgramId=function(e){P(),window.squatchProgramId.context=e},exports.setUseHostImplementation=function(e){if(!e)throw new Error("Must supply an implementation");if("function"!=typeof e)throw new Error("implementation must be a function");q.current=e},exports.setUserIdentity=ee,exports.useAppDomain=fn,exports.useAuthenticateWithEmailAndPasswordMutation=function(){var e=we(Pe),n=e[0],t=e[1],r=t.loading,a=t.data,o=t.errors;return i.useEffect(function(){if(null!=a&&a.authenticateManagedIdentityWithEmailAndPassword){var e=a.authenticateManagedIdentityWithEmailAndPassword,n=e.token,t=h.default(n).user;ee({jwt:n,id:t.id,accountId:t.accountId,managedIdentity:{email:e.email,emailVerified:e.emailVerified,sessionData:e.sessionData}})}},[null==a?void 0:a.authenticateManagedIdentityWithEmailAndPassword]),[n,{loading:r,data:a,errors:o}]},exports.useChangePasswordMutation=function(){var e=we(Fe),n=e[1];return[e[0],{loading:n.loading,data:n.data,errors:n.errors}]},exports.useCurrentPage=function(){var e=Qe()[1];return i.useEffect(function(){return Ge().listen(function(){e()})},[]),Ge().location},exports.useDebounce=function(e,n,t){var r=t&&t.equalityFn||Ze,a=i.useState(e),o=a[0],s=a[1],u=Xe(i.useCallback(function(e){return s(e)},[]),n,t),c=i.useRef(e);return i.useEffect(function(){r(c.current,e)||(u.callback(e),c.current=e)},[e,u,r]),[o,{cancel:u.cancel,flush:u.flush}]},exports.useDebouncedCallback=Xe,exports.useEngagementMedium=mn,exports.useForm=function(e){var n,t,r,a,o=function(e){try{return Promise.resolve(C({formValidationInput:{key:s,formData:e}})).then(function(){})}catch(e){return Promise.reject(e)}},s=e.formKey,u=e.formRef,c=e.autoSubmit,d=void 0!==c&&c,l=je(on),f=l[0],m=l[1],v=m.data,p=m.loading,g=we(sn),h=g[0],y=g[1],w=je(un),C=w[0],q=w[1],I=i.useReducer(function(e,n){return F({},e,n)},{enabled:!1,validating:!1,valid:!0,validationMessage:"",error:"",disabledMessage:"",formData:{},validationData:q,submitData:y}),P=I[0],E=I[1],S=P.enabled,x=P.disabledMessage,M=P.validating,A=P.valid,k=P.error,j=P.formData;return Ue(function(){an("submitData useEffect",y),E({submitData:y})},[y]),Ue(function(){an("validationData useEffect",q),E({validationData:q})},[q]),i.useEffect(function(){!p&&v&&function(){var n,t,r,a,o;E({enabled:null==v||null==(n=v.form.initialData)?void 0:n.isEnabled,disabledMessage:null==v||null==(t=v.form)||null==(r=t.initialData)?void 0:r.isEnabledErrorMessage});var i=u;if(i){var s=null==v||null==(a=v.form)||null==(o=a.initialData)?void 0:o.initialData;void 0!==e.setInitialData?e.setInitialData(i,s):function(e,n){try{var t=e.elements,r=new FormData(e);an({htmlForm:e,formContent:r}),null==r||r.forEach(function(e,r){an({value:e,key:r,inputs:t});var a=t.namedItem(r);try{"checkbox"==a.type?a.checked=b.default.get(n,r):a.value=b.default.get(n,r)||""}catch(e){an("no initialData found for key",r)}}),Promise.resolve()}catch(e){return Promise.reject(e)}}(i,s)}}()},[p]),i.useEffect(function(){var e,n,t,r,a,o;P.validationData&&(E({validating:!1,valid:(null==(e=P.validationData)||null==(n=e.data)||null==(t=n.validateForm)?void 0:t.valid)||!1}),d&&null!=(r=P.validationData)&&null!=(a=r.data)&&null!=(o=a.validateForm)&&o.valid&&h({formSubmissionInput:{key:s,formData:j}}))},[null==(n=P.validationData)||null==(t=n.data)||null==(r=t.validateForm)?void 0:r.valid]),{states:{enabled:S,disabledMessage:x,loadingForm:p,validating:M,valid:A,error:k,validationData:P.validationData,submitData:P.submitData},data:{formKey:s,schema:null==v||null==(a=v.form)?void 0:a.schema},callbacks:{getForm:f,handleSubmit:function(e){try{e.preventDefault(),E({validating:!0});var n=e.target;an("submit form",n);for(var t,r=new FormData(n),a={},i=D(r.entries());!(t=i()).done;){var s=t.value;b.default.set(a,s[0],s[1])}return E({formData:a}),Promise.resolve(o(a)).then(function(){})}catch(e){return Promise.reject(e)}},validateForm:o,submitForm:function(e){try{return Promise.resolve(h({formSubmissionInput:{key:s,formData:e}})).then(function(){})}catch(e){return Promise.reject(e)}},setFormState:E,getValidationErrors:function(){var e,n,t,r,a=null==q||null==(e=q.data)||null==(n=e.validateForm)||null==(t=n.results[0])||null==(r=t.result)?void 0:r.errors;function o(e){return null==a?void 0:a.filter(function(n){return n.instanceLocation.substring(1).startsWith(""+e)})}return{getErrorAtPath:function(e){return null==a?void 0:a.filter(function(n){return n.instanceLocation.substring(1)===e})},getSubErrorsAtPath:o,hasSubErrors:function(e){var n;return(null==(n=o(e))?void 0:n.length)>0}}},getSubmissionErrors:function(){var e;if(!P.submitData)return[];var n=null==(e=P.submitData.data)?void 0:e.submitForm.results;return(null==n?void 0:n.map(function(e){var n,t,r,a,o,i,s,u=null==(n=e.result)||null==(t=n.results)?void 0:t.flatMap(function(e){return!e.success&&e.message}).filter(function(e){return e}),c=null==(r=e.result)||null==(a=r.results)?void 0:a.flatMap(function(e){return!e.success&&{error:e.error,errorType:e.errorType,errorCode:e.errorCode}}).filter(function(e){return e.error});return{integration:null==(o=e.formHandler)||null==(i=o.integration)?void 0:i.name,formHandler:null==(s=e.formHandler)?void 0:s.name,messages:u,errors:c}}))||[]}}}},exports.useHost=I,exports.useLazyQuery=je,exports.useLocale=function(){var t,r,a,o,i,s;a=window.squatchLocale,o=te(),s=null==(i=Je(cn,{},!o).data)||null==(t=i.viewer)?void 0:t.locale,a?s&&s!==a.context&&(a.context=s):window.squatchLocale=new n.ContextProvider({element:document.documentElement,initialState:s||(null==(r=window.widgetIdent)?void 0:r.locale)||void 0,contextName:"sq:locale"}).start();var u=I();return e.useDomContext(u,"sq:locale")},exports.useManagedIdentityQuery=Ve,exports.useMutation=we,exports.usePaginatedQuery=function(e,n,t,r,a){var o;void 0===r&&(r={}),void 0===a&&(a=!1);var i=Ke(t),s=i.limit,u=i.setLimit,c=i.setCurrentPage,d=i.calculatePagination,l=Je(e,F({limit:s,offset:i.offset},r),a),f=l.loading,m=l.errors,v=l.refetch,p=n(l.data),g=d((null==p||null==(o=p.data)?void 0:o.length)||0,(null==p?void 0:p.totalCount)||0);return{envelope:p,states:{errors:m,loading:f,limit:s,currentPage:g.currentPage,pageCount:g.pageCount,pageProgress:g.pageProgress},callbacks:{refetch:v,setLimit:u,setCurrentPage:c}}},exports.usePagination=Ke,exports.useProgramId=E,exports.useQuery=Je,exports.useRefreshDispatcher=function(){var e=I();return{refresh:i.useCallback(function(){e.dispatchEvent(new CustomEvent("sq:refresh",{bubbles:!0,composed:!0,cancelable:!0,detail:{}}))},[e])}},exports.useRegisterWithEmailAndPasswordMutation=function(){var e=we(Ee),n=e[0],t=e[1],r=t.loading,a=t.data,o=t.errors;return i.useEffect(function(){if(null!=a&&a.registerManagedIdentityWithEmailAndPassword){var e=a.registerManagedIdentityWithEmailAndPassword,n=e.token,t=h.default(n).user;ee({jwt:n,id:t.id,accountId:t.accountId,managedIdentity:{email:e.email,emailVerified:e.emailVerified,sessionData:e.sessionData}})}},[null==a?void 0:a.registerManagedIdentityWithEmailAndPassword]),[n,{loading:r,data:a,errors:o}]},exports.useRequestPasswordResetEmailMutation=function(){return we(He)},exports.useRequestVerificationEmailMutation=function(){return we(We)},exports.useResetPasswordMutation=function(){var e=we(Se),n=e[0],t=e[1],r=t.loading,a=t.data,o=t.errors;return i.useEffect(function(){if(null!=a&&a.resetManagedIdentityPassword){var e=a.resetManagedIdentityPassword,n=e.token,t=h.default(n).user;ee({jwt:n,id:t.id,accountId:t.accountId,managedIdentity:{email:e.email,emailVerified:e.emailVerified,sessionData:e.sessionData}})}},[null==a?void 0:a.resetManagedIdentityPassword]),[n,{loading:r,data:a,errors:o}]},exports.useShareEvent=function(){var e=mn(),n=te(),t=E(),r=we(rn)[0];return n?function(a){r({eventMeta:{id:n.id,accountId:n.accountId,programId:t,type:"USER_REFERRAL_PROGRAM_ENGAGEMENT_EVENT",meta:{engagementMedium:e,shareMedium:a}}})}:function(){}},exports.useTenantAlias=ln,exports.useTick=Qe,exports.useToken=ne,exports.useUserIdentity=te,exports.useVerifyEmailMutation=function(){var e,n=Ve()[0],t=we(Le),r=t[0],a=t[1],o=a.loading,s=a.data,u=a.errors;return i.useEffect(function(){var e;null!=s&&null!=(e=s.verifyManagedIdentityEmail)&&e.success&&n()},[null==s||null==(e=s.verifyManagedIdentityEmail)?void 0:e.success]),[r,{loading:o,data:s,errors:u}]},exports.useVerifyPasswordResetCodeMutation=function(){return we(xe)};
2
2
  //# sourceMappingURL=index.js.map