@saasquatch/component-boilerplate 1.6.1 → 1.6.2-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/useLoadEvent.d.ts +15 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +20 -16
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.modern.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{lazilyStartLocaleContext as e,LOCALE_CONTEXT_NAME as t,lazilyStartProgramContext as n,PROGRAM_CONTEXT_NAME as r,lazilyStartUserContext as a,USER_CONTEXT_NAME as o,userIdentityFromJwt as s,isDemo as i,setUserIdentity as d,getTenantAlias as c,getAppDomain as u,getEngagementMedium as l,getEnvironment as m,history as f}from"@saasquatch/component-environment";export{getEnvironmentSDK,isDemo,setProgramId,setUserIdentity}from"@saasquatch/component-environment";import{useDomContext as g}from"@saasquatch/dom-context-hooks";import{parse as p,print as h}from"graphql";import y from"jwt-decode";import{useReducer as v,useCallback as C,useState as w,useEffect as b,useMemo as I,useRef as
|
|
1
|
+
import{lazilyStartLocaleContext as e,LOCALE_CONTEXT_NAME as t,lazilyStartProgramContext as n,PROGRAM_CONTEXT_NAME as r,lazilyStartUserContext as a,USER_CONTEXT_NAME as o,userIdentityFromJwt as s,isDemo as i,setUserIdentity as d,getTenantAlias as c,getAppDomain as u,getEngagementMedium as l,getEnvironment as m,history as f}from"@saasquatch/component-environment";export{getEnvironmentSDK,isDemo,setProgramId,setUserIdentity}from"@saasquatch/component-environment";import{useDomContext as g}from"@saasquatch/dom-context-hooks";import{parse as p,print as h}from"graphql";import y from"jwt-decode";import{useReducer as v,useCallback as C,useState as w,useEffect as b,useMemo as I,useRef as E}from"@saasquatch/universal-hooks";import F from"fast-memoize";import{Subject as $}from"rxjs";import{bufferTime as P}from"rxjs/operators";import{nanoid as M}from"nanoid";import{ClientError as D}from"graphql-request/dist/types";import{GraphQLClient as S,gql as k}from"graphql-request";import A from"graphql-combine-query";import{equal as q}from"@wry/equality";import R from"debounce";import{ContextProvider as x}from"dom-context";import j from"jsonpointer";const V={current:void 0};function W(){if(void 0===V.current)throw new Error("no implementation of useHost provided");return V.current()}function N(e){if(!e)throw new Error("Must supply an implementation");if("function"!=typeof e)throw new Error("implementation must be a function");V.current=e}function O(){e();const n=W();return g(n,t)}function U(){n();const e=W();return g(e,r)}function L(){var e,t;return null==(e=H())||null==(t=e.managedIdentity)?void 0:t.sessionData}function _(){var e;return null==(e=H())?void 0:e.jwt}function H(){a();const e=W(),t=g(e,o),n=s(null==t?void 0:t.jwt);if(i()||!t||n)return t;d(void 0)}const T=c,J=u,Q=l;var z=function(){return(z=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)},G=new Map,B=new Map,K=!0,Z=!1;function X(e){return e.replace(/[\s,]+/g," ").trim()}function Y(e){var t,n,r,a=X(e);if(!G.has(a)){var o=p(e,{experimentalFragmentVariables:Z});if(!o||"Document"!==o.kind)throw new Error("Not a valid GraphQL document.");G.set(a,function(e){var t=new Set(e.definitions);t.forEach(function(e){e.loc&&delete e.loc,Object.keys(e).forEach(function(n){var r=e[n];r&&"object"==typeof r&&t.add(r)})});var n=e.loc;return n&&(delete n.startToken,delete n.endToken),e}((t=o,n=new Set,r=[],t.definitions.forEach(function(e){if("FragmentDefinition"===e.kind){var t=e.name.value,a=X((s=e.loc).source.body.substring(s.start,s.end)),o=B.get(t);o&&!o.has(a)?K&&console.warn("Warning: fragment with name "+t+" 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||B.set(t,o=new Set),o.add(a),n.has(a)||(n.add(a),r.push(e))}else r.push(e);var s}),z(z({},t),{definitions:r}))))}return G.get(a)}function ee(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];"string"==typeof e&&(e=[e]);var r=e[0];return t.forEach(function(t,n){r+=t&&"Document"===t.kind?t.loc.source.body:t,r+=e[n+1]}),Y(r)}var te,ne=ee;(te=ee||(ee={})).gql=ne,te.resetCaches=function(){G.clear(),B.clear()},te.disableFragmentWarnings=function(){K=!1},te.enableExperimentalFragmentVariables=function(){Z=!0},te.disableExperimentalFragmentVariables=function(){Z=!1},ee.default=ee;var re=ee;function ae(){return(ae=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}class oe extends S{constructor(e,t){var n;super(e,t),n=this,this.subject=new $;const r=new $;this.subject.pipe(P(200,void 0,10)).subscribe(async function(e){if(!e.length)return;const{mergedQuery:t,mergedVariables:a,mergedQueryAddedEvents:o,unmergedQueryAddedEvents:s}=ce(e);for(const e of s)r.next(e);if(o.length)try{const e=await n.superRequest(t,a);me(e,o)}catch(e){if(e instanceof D){const{data:t,errors:n}=e.response;if(!t)return ge(o,e);const r=Object.keys(t);let a=[...o];for(const t of n){let n;t.path.find((o,s,i)=>{if(r.includes(o)){const d=de(o),c=a.findIndex(e=>e.id===d);if(-1===c)return!1;r.splice(s,1),n=a.splice(c,1)[0];const u=ue(e.response.data,n);i[s]=ie(i[s],d);const{query:l,variables:m}=n,f=ae({},e.response,{errors:[t],data:u,path:i}),g=new D(f,{query:"string"!=typeof l?h(l):l,variables:m});return fe(n,g),!0}return!1})}me(t,a)}else ge(o,e)}}),r.subscribe(async function(e){try{const{query:t,variables:r}=e,a=await n.superRequest(t,r);le(a,e)}catch(t){fe(e,t)}})}superRequest(e,t){return super.request(e,t)}request(e,t){return new Promise((n,r)=>{const a={query:e,variables:t,id:se(),resolve:n,reject:r};this.subject.next(a)})}}const se=()=>M().replace(/[-_]/g,""),ie=(e,t)=>e.replace(`_${t}`,""),de=e=>{const t=e.split("_");return t[t.length-1]},ce=e=>{const t=[],n=[],{document:r,variables:a}=e.reduce((e,r)=>{const{query:a,variables:o,id:s}=r;try{const i="string"==typeof a?p(a):a,d=i.definitions.find(e=>"FragmentDefinition"===e.kind),c="string"==typeof a?a:h(a),u=/@/.test(c);if(d||u)return n.push(r),e;const l=e=>((e,t)=>`${e}_${t}`)(e,s);return e=e.addN(i,[o],l,l),t.push(r),e}catch(t){return n.push(r),e}},A("BatchedQuery"));return{mergedQuery:r&&h(r),mergedVariables:a,mergedQueryAddedEvents:t,unmergedQueryAddedEvents:n}},ue=(e,t)=>{if(!e)return e;const n=Object.keys(e),{id:r}=t;return n.reduce((t,n)=>(n.endsWith(r)&&(t=ae({},t,{[ie(n,r)]:e[n]})),t),{})},le=(e,t)=>{const{resolve:n}=t;n(e)},me=(e,t)=>{for(const n of t){const t=ue(e,n);n.resolve(t)}},fe=(e,t)=>{const{reject:n}=e;n(t)},ge=(e,t)=>{for(const n of e){const{reject:e}=n;e(t)}},pe="sq:graphql-client",he=F(function(e,t,n){return new oe(e+"/api/v1/"+t+"/graphql",{headers:{Authorization:`Bearer ${n||""}`}})});function ye(e,t){switch(t.type){case"loading":return{data:void 0,errors:void 0,loading:!0};case"data":return{data:t.payload,errors:void 0,loading:!1};case"errors":return{data:void 0,errors:t.payload,loading:!1}}}function ve(e,t){const n=function(){const e=_(),t=J(),n=T(),r=he(t,n,e),a=W(),o=g(a,"sq:graphql-client",{attempts:0});return null!=o?o:r}(),[r,a]=v(ye,t);return[r,C(async function(t,r=!1){if(!n){const e=new Error("No GraphQL client found");return a({type:"errors",payload:e}),e}try{r||a({type:"loading"});const o=await n.request(e,t);return a({type:"data",payload:o}),o}catch(e){return a({type:"errors",payload:e}),e}},[n,e,a])]}const Ce={loading:!1,data:void 0,errors:void 0};function we(e){const[t,n]=ve(e,Ce);return[n,t]}let be;const Ie=re(be||(be=(e=>e)`
|
|
2
2
|
mutation AuthenticateWithEmailAndPassword(
|
|
3
3
|
$email: String!
|
|
4
4
|
$password: String!
|
|
@@ -15,7 +15,7 @@ import{lazilyStartLocaleContext as e,LOCALE_CONTEXT_NAME as t,lazilyStartProgram
|
|
|
15
15
|
sessionData
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
`));function
|
|
18
|
+
`));function Ee(){const[e,{loading:t,data:n,errors:r}]=we(Ie);return[async t=>{const n=await e(t);if(!(n instanceof Error)&&n.authenticateManagedIdentityWithEmailAndPassword){const e=n.authenticateManagedIdentityWithEmailAndPassword.token,{user:t}=y(e);d({jwt:e,id:t.id,accountId:t.accountId,managedIdentity:{email:n.authenticateManagedIdentityWithEmailAndPassword.email,emailVerified:n.authenticateManagedIdentityWithEmailAndPassword.emailVerified,sessionData:n.authenticateManagedIdentityWithEmailAndPassword.sessionData}})}return n},{loading:t,data:n,errors:r}]}let Fe;const $e=re(Fe||(Fe=(e=>e)`
|
|
19
19
|
mutation RegisterWithEmailAndPassword(
|
|
20
20
|
$email: String!
|
|
21
21
|
$password: String!
|
|
@@ -36,7 +36,7 @@ import{lazilyStartLocaleContext as e,LOCALE_CONTEXT_NAME as t,lazilyStartProgram
|
|
|
36
36
|
sessionData
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
`));function Pe(){const[e,{loading:t,data:n,errors:r}]=
|
|
39
|
+
`));function Pe(){const[e,{loading:t,data:n,errors:r}]=we($e);return[async t=>{const n=await e(t);if(!(n instanceof Error)&&n.registerManagedIdentityWithEmailAndPassword){const e=n.registerManagedIdentityWithEmailAndPassword.token,{user:t}=y(e);d({jwt:e,id:t.id,accountId:t.accountId,managedIdentity:{email:n.registerManagedIdentityWithEmailAndPassword.email,emailVerified:n.registerManagedIdentityWithEmailAndPassword.emailVerified,sessionData:n.registerManagedIdentityWithEmailAndPassword.sessionData}})}return n},{loading:t,data:n,errors:r}]}let Me;const De=re(Me||(Me=(e=>e)`
|
|
40
40
|
mutation RegisterViaRegistrationForm($key: String!, $formData: RSJsonNode!) {
|
|
41
41
|
submitForm(formSubmissionInput: { key: $key, formData: $formData }) {
|
|
42
42
|
results {
|
|
@@ -58,7 +58,7 @@ import{lazilyStartLocaleContext as e,LOCALE_CONTEXT_NAME as t,lazilyStartProgram
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
`));function
|
|
61
|
+
`));function Se(){const[e,{loading:t,data:n,errors:r}]=we(De),[a,o]=w(null);return[async t=>{var n,r,a,s;o(null);const i=await e(t);if(i instanceof Error)return i;const c=null==(n=i.submitForm)||null==(r=n.results)?void 0:r.find(e=>{var t;return"identity"===(null==e||null==(t=e.formHandler)?void 0:t.namespace)});if(c&&null!=(a=c.result)&&null!=(s=a.results)&&s.length){const e=c.result.results[0];if(e.success){const t=e.data.token,{user:n}=y(t);d({jwt:t,id:n.id,accountId:n.accountId,managedIdentity:{email:e.data.email,emailVerified:e.data.emailVerified,sessionData:e.data.sessionData}})}else o(e.message)}return i},{loading:t,data:n,errors:r,formError:a}]}let ke;const Ae=re(ke||(ke=(e=>e)`
|
|
62
62
|
mutation ChangePassword($password: String!) {
|
|
63
63
|
changeManagedIdentityPassword(
|
|
64
64
|
changeManagedIdentityPasswordInput: { password: $password }
|
|
@@ -66,7 +66,7 @@ import{lazilyStartLocaleContext as e,LOCALE_CONTEXT_NAME as t,lazilyStartProgram
|
|
|
66
66
|
success
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
`));function
|
|
69
|
+
`));function qe(){const[e,{loading:t,data:n,errors:r}]=we(Ae);return[e,{loading:t,data:n,errors:r}]}let Re;const xe=re(Re||(Re=(e=>e)`
|
|
70
70
|
mutation ResetPassword($oobCode: String!, $password: String!) {
|
|
71
71
|
resetManagedIdentityPassword(
|
|
72
72
|
resetManagedIdentityPasswordInput: {
|
|
@@ -80,7 +80,7 @@ import{lazilyStartLocaleContext as e,LOCALE_CONTEXT_NAME as t,lazilyStartProgram
|
|
|
80
80
|
sessionData
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
`));function je(){const[e,{loading:t,data:n,errors:r}]=
|
|
83
|
+
`));function je(){const[e,{loading:t,data:n,errors:r}]=we(xe);return[async t=>{const n=await e(t);if(!(n instanceof Error)&&n.resetManagedIdentityPassword){const e=n.resetManagedIdentityPassword.token,{user:t}=y(e);d({jwt:e,id:t.id,accountId:t.accountId,managedIdentity:{email:n.resetManagedIdentityPassword.email,emailVerified:n.resetManagedIdentityPassword.emailVerified,sessionData:n.resetManagedIdentityPassword.sessionData}})}return n},{loading:t,data:n,errors:r}]}let Ve;const We=re(Ve||(Ve=(e=>e)`
|
|
84
84
|
mutation VerifyPasswordResetCode($oobCode: String!) {
|
|
85
85
|
verifyManagedIdentityPasswordResetCode(
|
|
86
86
|
verifyManagedIdentityPasswordResetCodeInput: { oobCode: $oobCode }
|
|
@@ -88,7 +88,7 @@ import{lazilyStartLocaleContext as e,LOCALE_CONTEXT_NAME as t,lazilyStartProgram
|
|
|
88
88
|
success
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
`));function We(){return
|
|
91
|
+
`));function Ne(){return we(We)}function Oe(e,t){return b(e,function(e){const t=E(e),n=E(0);return q(e,t.current)||(t.current=e,n.current+=1),I(()=>t.current,[n.current])}(t))}function Ue(){const e=W();return{refresh:C(()=>{e.dispatchEvent(new CustomEvent("sq:refresh",{bubbles:!0,composed:!0,cancelable:!0,detail:{}}))},[e])}}function Le({skip:e=!1,update:t,variables:n}){Oe(()=>{const r=r=>{!e&&t(n,!0)};return document.addEventListener("sq:refresh",r),()=>document.removeEventListener("sq:refresh",r)},[n,t,e])}const _e={loading:!1,data:void 0,errors:void 0},He=Symbol();function Te(e){const[t,n]=ve(e,_e),r=E(He);Le({skip:r.current===He,update:n,variables:r.current});const a=C(e=>(r.current=e,n(e)),[n]);return[n,ae({},t,{refetch:a})]}let Je;const Qe=re(Je||(Je=(e=>e)`
|
|
92
92
|
query ManagedIdentitySession {
|
|
93
93
|
managedIdentitySession {
|
|
94
94
|
email
|
|
@@ -96,7 +96,7 @@ import{lazilyStartLocaleContext as e,LOCALE_CONTEXT_NAME as t,lazilyStartProgram
|
|
|
96
96
|
sessionData
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
`));function
|
|
99
|
+
`));function ze(){const e=H(),[t,{loading:n,data:r,errors:a,refetch:o}]=Te(Qe),s=t=>{t instanceof Error||!t.managedIdentitySession||d(ae({},e,{managedIdentity:t.managedIdentitySession}))};return[async()=>{const e=await t({});return s(e),e},{loading:n,data:r,errors:a,refetch:async()=>{const e=await o();return s(e),e}}]}let Ge;const Be=re(Ge||(Ge=(e=>e)`
|
|
100
100
|
mutation VerifyEmail($oobCode: String!) {
|
|
101
101
|
verifyManagedIdentityEmail(
|
|
102
102
|
verifyManagedIdentityEmailInput: { oobCode: $oobCode }
|
|
@@ -104,7 +104,7 @@ import{lazilyStartLocaleContext as e,LOCALE_CONTEXT_NAME as t,lazilyStartProgram
|
|
|
104
104
|
success
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
`));function
|
|
107
|
+
`));function Ke(){const[e]=ze(),[t,{loading:n,data:r,errors:a}]=we(Be);return[async n=>{const r=await t(n);return r instanceof Error||!r.verifyManagedIdentityEmail.success||await e(),r},{loading:n,data:r,errors:a}]}let Ze;const Xe=re(Ze||(Ze=(e=>e)`
|
|
108
108
|
mutation RequestPasswordResetEmail(
|
|
109
109
|
$email: String!
|
|
110
110
|
$urlParams: RSJsonNode
|
|
@@ -120,7 +120,7 @@ import{lazilyStartLocaleContext as e,LOCALE_CONTEXT_NAME as t,lazilyStartProgram
|
|
|
120
120
|
success
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
`));function
|
|
123
|
+
`));function Ye(){return we(Xe)}let et;const tt=re(et||(et=(e=>e)`
|
|
124
124
|
mutation RequestVerificationEmail(
|
|
125
125
|
$email: String!
|
|
126
126
|
$urlParams: RSJsonNode
|
|
@@ -136,7 +136,7 @@ import{lazilyStartLocaleContext as e,LOCALE_CONTEXT_NAME as t,lazilyStartProgram
|
|
|
136
136
|
success
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
-
`));function
|
|
139
|
+
`));function nt(){return we(tt)}let rt;const at=re(rt||(rt=(e=>e)`
|
|
140
140
|
mutation authenticateManagedIdentityWithInstantAccess(
|
|
141
141
|
$email: String!
|
|
142
142
|
$firstName: String
|
|
@@ -161,11 +161,15 @@ import{lazilyStartLocaleContext as e,LOCALE_CONTEXT_NAME as t,lazilyStartProgram
|
|
|
161
161
|
token
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
`));function
|
|
164
|
+
`));function ot(){const e=U(),t=m(),[n,{loading:r,data:a,errors:o}]=we(at);return[async r=>{const a=await n(r);if(!(a instanceof Error)&&a.authenticateManagedIdentityWithInstantAccess){if("APPROVED"!==await async function(e,t){try{var n;const r=await fetch(`${u()}/api/v1/${c()}/graphql`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify({query:"\n query checkReferralFraudStatus($programId: ID) {\n viewer {\n ... on User {\n id\n instantAccessRewards(filter: { programId_eq: $programId }) {\n data {\n id\n pendingReasons\n cancelledReason\n }\n }\n }\n }\n }\n",variables:{programId:e}})});if(!r.ok)throw new Error("Failed to fetch locale");const a=await r.json();if(a.errors)throw new Error(JSON.stringify(a.errors,null,2));const o=(null==(n=a.data.viewer.instantAccessRewards)?void 0:n.data)||[];return o.some(e=>"SUSPECTED_FRAUD"===e.cancelledReason)?"DENIED":o.some(e=>{var t;return null==(t=e.pendingReasons)?void 0:t.includes("SUSPECTED_FRAUD")})?"PENDING_REVIEW":"APPROVED"}catch(e){return void console.error(e)}}(e,a.authenticateManagedIdentityWithInstantAccess.token))throw{name:"fraud_error",message:"Referral flagged as fraud."};{const e=a.authenticateManagedIdentityWithInstantAccess.email;if(d({jwt:a.authenticateManagedIdentityWithInstantAccess.token,id:e,accountId:e}),"SquatchJS2"===t){const t=new CustomEvent("sq:user-registration",{bubbles:!0,detail:{userId:e,accountId:e}});document.dispatchEvent(t)}}}return a},{loading:r,data:a,errors:o}]}function st(e,t){const n=E();return n.current&&q(t,n.current.key)||(n.current={key:t,value:e()}),n.current.value}function it(){return v(e=>e+1,0)}function dt(e){const t=Object.getOwnPropertyNames(e);for(const n of t){const t=e[n];t&&"object"==typeof t&&dt(t)}return Object.freeze(e)}const ct={loading:!0,data:void 0,errors:void 0};function ut(e,t,n){const[r,a]=ve(e,ct),[o,s]=it();return st(()=>{!n&&a(t)},[e,t,a,o,n]),Le({skip:n,update:a,variables:t}),dt(ae({},r,{refetch:s}))}function lt(){const[,e]=it();return b(()=>f.listen(()=>{e()}),[]),f.location}const mt=f;function ft(e){const[t,n]=w({limit:e.limit,offset:e.offset}),{offset:r,limit:a}=t,o=(e,t)=>e*t,s=(e,t)=>Math.ceil(e/t)||0;return{limit:a,setLimit:e=>{const a=s(r,e),i=o(e,a);n(ae({},t,{limit:e,offset:i}))},offset:r,setCurrentPage:e=>{let t=o(e,a);n(e=>ae({},e,{offset:t}))},calculatePagination:function(e,t){const n=s(r,a),o=((e,t)=>Math.ceil(e/t)||0)(t,a),i=0===e?"0":e>1?`${r+1}-${r+e}`:`${r+1}`;return{currentPage:n,pageCount:o,rangeOnPage:i,pageProgress:`${i} of ${t}`}}}}function gt(e,t,n,r={},a=!1){var o;const{limit:s,offset:i,setLimit:d,setCurrentPage:c,calculatePagination:u}=ft(n),l=ae({limit:s,offset:i},r),{loading:m,errors:f,data:g,refetch:p}=ut(e,l,a),h=t(g),{currentPage:y,pageCount:v,pageProgress:C}=u((null==h||null==(o=h.data)?void 0:o.length)||0,(null==h?void 0:h.totalCount)||0);return{envelope:h,states:{errors:f,loading:m,limit:s,currentPage:y,pageCount:v,pageProgress:C},callbacks:{refetch:p,setLimit:d,setCurrentPage:c}}}function pt(e,t){return e===t}function ht(e,t,n){const r=n&&n.equalityFn||pt,[a,o]=w(e),s=yt(C(e=>o(e),[]),t,n),i=E(e);return b(()=>{r(i.current,e)||(s.callback(e),i.current=e)},[e,s,r]),[a,{cancel:s.cancel,flush:s.flush}]}function yt(e,t=0,n={leading:!1}){const r=I(()=>R(e,t,n.leading),[e,t,n.leading]),{flush:a,clear:o}=r;return{flush:a,cancel:o,callback:r}}let vt;const Ct=k(vt||(vt=(e=>e)`
|
|
165
165
|
mutation ($eventMeta: UserAnalyticsEvent!) {
|
|
166
166
|
createUserAnalyticsEvent(eventMeta: $eventMeta)
|
|
167
167
|
}
|
|
168
|
-
`));function
|
|
168
|
+
`));function wt(){const e=Q(),t=H(),n=U(),[r]=we(Ct);return t?a=>{r({eventMeta:{id:t.id,accountId:t.accountId,programId:n,type:"USER_REFERRAL_PROGRAM_ENGAGEMENT_EVENT",meta:{engagementMedium:e,shareMedium:a}}})}:()=>{}}var bt=1e3,It=60*bt,Et=60*It,Ft=24*Et,$t=function(e,t){t=t||{};var n=typeof e;if("string"===n&&e.length>0)return function(e){if(!((e=String(e)).length>100)){var t=/^(-?(?:\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(t){var n=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*n;case"weeks":case"week":case"w":return 6048e5*n;case"days":case"day":case"d":return n*Ft;case"hours":case"hour":case"hrs":case"hr":case"h":return n*Et;case"minutes":case"minute":case"mins":case"min":case"m":return n*It;case"seconds":case"second":case"secs":case"sec":case"s":return n*bt;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}}}(e);if("number"===n&&isFinite(e))return t.long?function(e){var t=Math.abs(e);return t>=Ft?Pt(e,t,Ft,"day"):t>=Et?Pt(e,t,Et,"hour"):t>=It?Pt(e,t,It,"minute"):t>=bt?Pt(e,t,bt,"second"):e+" ms"}(e):function(e){var t=Math.abs(e);return t>=Ft?Math.round(e/Ft)+"d":t>=Et?Math.round(e/Et)+"h":t>=It?Math.round(e/It)+"m":t>=bt?Math.round(e/bt)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function Pt(e,t,n,r){var a=t>=1.5*n;return Math.round(e/n)+" "+r+(a?"s":"")}var Mt,Dt=(function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,a=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(a=r))}),t.splice(a,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},t.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+)/))},t.storage=function(){try{return localStorage}catch(e){}}(),t.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`."))}})(),t.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"],t.log=console.debug||console.log||(()=>{}),e.exports=function(e){function t(e){let r,a=null;function o(...e){if(!o.enabled)return;const n=o,a=Number(new Date);n.diff=a-(r||a),n.prev=r,n.curr=a,r=a,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let s=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(r,a)=>{if("%%"===r)return"%";s++;const o=t.formatters[a];return"function"==typeof o&&(r=o.call(n,e[s]),e.splice(s,1),s--),r}),t.formatArgs.call(n,e),(n.log||t.log).apply(n,e)}return o.namespace=e,o.useColors=t.useColors(),o.color=t.selectColor(e),o.extend=n,o.destroy=t.destroy,Object.defineProperty(o,"enabled",{enumerable:!0,configurable:!1,get:()=>null===a?t.enabled(e):a,set:e=>{a=e}}),"function"==typeof t.init&&t.init(o),o}function n(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function r(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names.map(r),...t.skips.map(r).map(e=>"-"+e)].join(",");return t.enable(""),e},t.enable=function(e){let n;t.save(e),t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),a=r.length;for(n=0;n<a;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.substr(1)+"$")):t.names.push(new RegExp("^"+e+"$")))},t.enabled=function(e){if("*"===e[e.length-1])return!0;let n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=$t,t.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(n=>{t[n]=e[n]}),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t}(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(Mt={exports:{}},Mt.exports),Mt.exports);let St;const kt=k(St||(St=(e=>e)`
|
|
169
|
+
mutation loadEvent($eventMeta: UserAnalyticsEvent!) {
|
|
170
|
+
createUserAnalyticsEvent(eventMeta: $eventMeta)
|
|
171
|
+
}
|
|
172
|
+
`));function At(){const e=Q(),t=H(),n=U(),[r]=we(kt),a=function(){let e=window.squatchLoadEvent;return e||(Dt("Creating load event provider"),e=new x({element:document.documentElement,initialState:{userIdentity:void 0,programId:void 0,loaded:!1},contextName:"sq:load-event"}).start(),window.squatchLoadEvent=e),e}();Oe(()=>{!t||!n||q(t,a.context.userIdentity)&&n===a.context.programId&&a.context.loaded||(r({eventMeta:{programId:n,id:t.id,accountId:t.accountId,type:"USER_REFERRAL_PROGRAM_LOADED_EVENT",meta:{engagementMedium:e}}}),console.log("updated context",{programChanged:n!==a.context.programId,userChanged:q(t,a.context.userIdentity)}),a.context={userIdentity:t,programId:n,loaded:!0})},[t,n])}let qt,Rt,xt,jt=e=>e;const Vt=Dt("sq:useForm"),Wt=k(qt||(qt=jt`
|
|
169
173
|
query ($key: String!) {
|
|
170
174
|
form(key: $key) {
|
|
171
175
|
schema
|
|
@@ -176,7 +180,7 @@ import{lazilyStartLocaleContext as e,LOCALE_CONTEXT_NAME as t,lazilyStartProgram
|
|
|
176
180
|
}
|
|
177
181
|
}
|
|
178
182
|
}
|
|
179
|
-
`)),
|
|
183
|
+
`)),Nt=k(Rt||(Rt=jt`
|
|
180
184
|
mutation ($formSubmissionInput: FormSubmissionInput!) {
|
|
181
185
|
submitForm(formSubmissionInput: $formSubmissionInput) {
|
|
182
186
|
success
|
|
@@ -206,7 +210,7 @@ import{lazilyStartLocaleContext as e,LOCALE_CONTEXT_NAME as t,lazilyStartProgram
|
|
|
206
210
|
}
|
|
207
211
|
}
|
|
208
212
|
}
|
|
209
|
-
`)),
|
|
213
|
+
`)),Ot=k(xt||(xt=jt`
|
|
210
214
|
query ($formValidationInput: FormValidationInput!) {
|
|
211
215
|
validateForm(formValidationInput: $formValidationInput) {
|
|
212
216
|
valid
|
|
@@ -236,5 +240,5 @@ import{lazilyStartLocaleContext as e,LOCALE_CONTEXT_NAME as t,lazilyStartProgram
|
|
|
236
240
|
}
|
|
237
241
|
}
|
|
238
242
|
}
|
|
239
|
-
`));function
|
|
243
|
+
`));function Ut(e){var t,n,r,a;const{formKey:o,formRef:s,autoSubmit:i=!1}=e,[d,{data:c,loading:u}]=Te(Wt),[l,m]=we(Nt),[f,g]=Te(Ot),p={enabled:!1,validating:!1,valid:!0,validationMessage:"",error:"",disabledMessage:"",formData:{},validationData:g,submitData:m},[h,y]=v((e,t)=>ae({},e,t),p),{enabled:C,disabledMessage:w,validating:I,valid:E,error:F,formData:$}=h;async function P(e){await f({formValidationInput:{key:o,formData:e}})}return st(()=>{Vt("submitData useEffect",m),y({submitData:m})},[m]),st(()=>{Vt("validationData useEffect",g),y({validationData:g})},[g]),b(()=>{!u&&c&&function(){var t,n,r,a,o;y({enabled:null==c||null==(t=c.form.initialData)?void 0:t.isEnabled,disabledMessage:null==c||null==(n=c.form)||null==(r=n.initialData)?void 0:r.isEnabledErrorMessage});const i=s;if(!i)return;const d=null==c||null==(a=c.form)||null==(o=a.initialData)?void 0:o.initialData;void 0!==e.setInitialData?e.setInitialData(i,d):async function(e,t){const n=e.elements,r=new FormData(e);Vt({htmlForm:e,formContent:r}),null==r||r.forEach((e,r)=>{Vt({value:e,key:r,inputs:n});const a=n.namedItem(r);try{"checkbox"==a.type?a.checked=j.get(t,r):a.value=j.get(t,r)||""}catch(e){Vt("no initialData found for key",r)}})}(i,d)}()},[u]),b(()=>{var e,t,n,r,a,s;h.validationData&&(y({validating:!1,valid:(null==(e=h.validationData)||null==(t=e.data)||null==(n=t.validateForm)?void 0:n.valid)||!1}),i&&null!=(r=h.validationData)&&null!=(a=r.data)&&null!=(s=a.validateForm)&&s.valid&&l({formSubmissionInput:{key:o,formData:$}}))},[null==(t=h.validationData)||null==(n=t.data)||null==(r=n.validateForm)?void 0:r.valid]),{states:{enabled:C,disabledMessage:w,loadingForm:u,validating:I,valid:E,error:F,validationData:h.validationData,submitData:h.submitData},data:{formKey:o,schema:null==c||null==(a=c.form)?void 0:a.schema},callbacks:{getForm:d,handleSubmit:async function(e){e.preventDefault(),y({validating:!0});const t=e.target;Vt("submit form",t);const n=new FormData(t);let r={};for(var a of n.entries())j.set(r,a[0],a[1]);y({formData:r}),await P(r)},validateForm:P,submitForm:async function(e){await l({formSubmissionInput:{key:o,formData:e}})},setFormState:y,getValidationErrors:function(){var e,t,n,r;const a=null==g||null==(e=g.data)||null==(t=e.validateForm)||null==(n=t.results[0])||null==(r=n.result)?void 0:r.errors;function o(e){return null==a?void 0:a.filter(t=>t.instanceLocation.substring(1).startsWith(`${e}`))}return{getErrorAtPath:function(e){return null==a?void 0:a.filter(t=>t.instanceLocation.substring(1)===e)},getSubErrorsAtPath:o,hasSubErrors:e=>{var t;return(null==(t=o(e))?void 0:t.length)>0}}},getSubmissionErrors:function(){var e;if(!h.submitData)return[];const t=null==(e=h.submitData.data)?void 0:e.submitForm.results;return(null==t?void 0:t.map(e=>{var t,n,r,a,o,s,i;const d=null==(t=e.result)||null==(n=t.results)?void 0:n.flatMap(e=>!e.success&&e.message).filter(e=>e),c=null==(r=e.result)||null==(a=r.results)?void 0:a.flatMap(e=>!e.success&&{error:e.error,errorType:e.errorType,errorCode:e.errorCode}).filter(({error:e})=>e);return{integration:null==(o=e.formHandler)||null==(s=o.integration)?void 0:s.name,formHandler:null==(i=e.formHandler)?void 0:i.name,messages:d,errors:c}}))||[]}}}}export{oe as BatchedGraphQLClient,pe as GRAPHQL_CONTEXT,he as memoizedGraphQLClient,mt as navigation,N as setUseHostImplementation,J as useAppDomain,ot as useAuthenticateManagedIdentityWithInstantAccess,Ee as useAuthenticateWithEmailAndPasswordMutation,qe as useChangePasswordMutation,lt as useCurrentPage,ht as useDebounce,yt as useDebouncedCallback,Q as useEngagementMedium,Ut as useForm,W as useHost,Te as useLazyQuery,At as useLoadEvent,O as useLocale,ze as useManagedIdentitySessionQuery,we as useMutation,gt as usePaginatedQuery,ft as usePagination,U as useProgramId,ut as useQuery,Ue as useRefreshDispatcher,Se as useRegisterViaRegistrationFormMutation,Pe as useRegisterWithEmailAndPasswordMutation,Ye as useRequestPasswordResetEmailMutation,nt as useRequestVerificationEmailMutation,je as useResetPasswordMutation,L as useSessionData,wt as useShareEvent,T as useTenantAlias,it as useTick,_ as useToken,H as useUserIdentity,Ke as useVerifyEmailMutation,Ne as useVerifyPasswordResetCodeMutation};
|
|
240
244
|
//# sourceMappingURL=index.modern.js.map
|