@saasquatch/component-boilerplate 1.2.3-6 → 1.2.3-7
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/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +10 -10
- 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{useDomContext as e}from"@saasquatch/dom-context-hooks";import{ContextProvider as t}from"dom-context";import n from"jwt-decode";import{equal as r}from"@wry/equality";import{parse as a,print as o}from"graphql";import{useReducer as i,useCallback as s,useEffect as
|
|
1
|
+
import{useDomContext as e}from"@saasquatch/dom-context-hooks";import{ContextProvider as t}from"dom-context";import n from"jwt-decode";import{equal as r}from"@wry/equality";import{parse as a,print as o}from"graphql";import{useReducer as i,useCallback as s,useEffect as d,useRef as u,useState as c,useMemo as l}from"@saasquatch/universal-hooks";import m from"fast-memoize";import{Subject as f}from"rxjs";import{bufferTime as g}from"rxjs/operators";import{nanoid as p}from"nanoid";import{ClientError as h}from"graphql-request/dist/types";import{GraphQLClient as y,gql as w}from"graphql-request";import v from"graphql-combine-query";import{createMemoryHistory as C,createBrowserHistory as b}from"history";import I from"debounce";import F from"jsonpointer";const q={current:void 0};function S(){if(void 0===q.current)throw new Error("no implementation of useHost provided");return q.current()}function E(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}function P(){var e;window.squatchProgramId||(window.squatchProgramId=new t({element:document.documentElement,initialState:(null==(e=window.widgetIdent)?void 0:e.programId)||void 0,contextName:"sq:program-id"}).start())}function M(){P();const t=S();return e(t,"sq:program-id")}function D(e){P(),window.squatchProgramId.context=e}function A(){var e,t;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==(t=window.frameElement)?void 0:t.squatchJsApi,widgetIdent:window.widgetIdent}:{type:"None"}}function $(){const e=A();return"None"===e.type||"SquatchAdmin"===e.type}function k(){const e=A();switch(e.type){case"SquatchAndroid":case"SquatchJS2":return e.widgetIdent.tenantAlias;case"SquatchAdmin":case"None":return"demo";case"SquatchPortal":return e.env.tenantAlias}}function j(){var e;const t=A();switch(t.type){case"SquatchAndroid":case"SquatchJS2":return t.widgetIdent.appDomain;case"SquatchPortal":return(null==(e=t.env)?void 0:e.appDomain)||"https://app.referralsaasquatch.com";case"SquatchAdmin":case"None":return"https://app.referralsaasquatch.com"}}function x(){const e=A();switch(e.type){case"SquatchJS2":return e.widgetIdent.engagementMedium||"EMBED";case"SquatchAndroid":case"SquatchPortal":case"SquatchAdmin":case"None":return"EMBED"}}function R(){return function(){const e=navigator.language,t=null==e?void 0:e.split("-");return t&&1!==t.length?`${t[0]}_${t[1].toUpperCase()}`:e}()}function V(){return(V=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)}function N(){window.squatchUserIdentity||(window.squatchUserIdentity=new t({element:document.documentElement,initialState:H(),contextName:"sq:user-identity"}).start())}function O(e){if(e)try{const t=n(e),r=t.exp;let a,o;if(function(e){return e.sub&&/.*:.*@.*:users/.test(e.sub)}(t)){const e=t.sub.match(/(.*):(.*)@(.*):users/);o=atob(e[1]),a=atob(e[2])}else(function(e){return e.user&&e.user.id&&e.user.accountId})(t)&&(o=t.user.accountId,a=t.user.id);if(!a||!o)return;if(r&&Date.now()>=1e3*r)return;return{id:a,accountId:o,jwt:e}}catch(e){return}}function H(){const e=A();switch(e.type){case"SquatchAndroid":case"SquatchJS2":return{id:e.widgetIdent.userId,accountId:e.widgetIdent.accountId,jwt:e.widgetIdent.token};case"SquatchPortal":const t=new URLSearchParams(document.location.search);if(t.has("jwt"))return O(t.get("jwt"));const n=localStorage.getItem("sq:user-identity");if(!n)return;try{const e=JSON.parse(n),t=O(e.jwt);return t?V({},e,t):void 0}catch(e){return}case"SquatchAdmin":case"None":return}}function W(e){N();const t=window.squatchUserIdentity;r(t.context,e)||(console.log("setting context:",e),t.context=e),e&&"SquatchPortal"===A().type?(console.log("Setting localStorage",{globalProvider:t,identity:e}),localStorage.setItem("sq:user-identity",JSON.stringify(e))):(console.log("removing!",{identity:e,envSdk:A().type}),localStorage.removeItem("sq:user-identity"))}function U(){var e;return null==(e=J())?void 0:e.jwt}function J(){N();const t=S(),n=e(t,"sq:user-identity"),r=O(null==n?void 0:n.jwt);return n&&!r?(console.log("signing out :(",{identity:n,validIdentity:r}),void W(void 0)):n}var L=function(){return(L=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)},_=new Map,Q=new Map,T=!0,z=!1;function G(e){return e.replace(/[\s,]+/g," ").trim()}function B(e){var t,n,r,o=G(e);if(!_.has(o)){var i=a(e,{experimentalFragmentVariables:z});if(!i||"Document"!==i.kind)throw new Error("Not a valid GraphQL document.");_.set(o,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=i,n=new Set,r=[],t.definitions.forEach(function(e){if("FragmentDefinition"===e.kind){var t=e.name.value,a=G((i=e.loc).source.body.substring(i.start,i.end)),o=Q.get(t);o&&!o.has(a)?T&&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||Q.set(t,o=new Set),o.add(a),n.has(a)||(n.add(a),r.push(e))}else r.push(e);var i}),L(L({},t),{definitions:r}))))}return _.get(o)}function K(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]}),B(r)}var Z,X=K;(Z=K||(K={})).gql=X,Z.resetCaches=function(){_.clear(),Q.clear()},Z.disableFragmentWarnings=function(){T=!1},Z.enableExperimentalFragmentVariables=function(){z=!0},Z.disableExperimentalFragmentVariables=function(){z=!1},K.default=K;var Y=K;class ee extends y{constructor(e,t){var n;super(e,t),n=this,this.subject=new f;const r=new f;this.subject.pipe(g(200,void 0,10)).subscribe(async function(e){if(!e.length)return;const{mergedQuery:t,mergedVariables:a,mergedQueryAddedEvents:i,unmergedQueryAddedEvents:s}=ae(e);for(const e of s)r.next(e);if(i.length)try{const e=await n.superRequest(t,a);se(e,i)}catch(e){if(e instanceof h){const{data:t,errors:n}=e.response;if(!t)return ue(i,e);const r=Object.keys(t);let a=[...i];for(const t of n){let n;t.path.find((i,s,d)=>{if(r.includes(i)){const u=re(i),c=a.findIndex(e=>e.id===u);if(-1===c)return!1;r.splice(s,1),n=a.splice(c,1)[0];const l=oe(e.response.data,n);d[s]=ne(d[s],u);const{query:m,variables:f}=n,g=V({},e.response,{errors:[t],data:l,path:d}),p=new h(g,{query:"string"!=typeof m?o(m):m,variables:f});return de(n,p),!0}return!1})}se(t,a)}else ue(i,e)}}),r.subscribe(async function(e){try{const{query:t,variables:r}=e,a=await n.superRequest(t,r);ie(a,e)}catch(t){de(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:te(),resolve:n,reject:r};this.subject.next(a)})}}const te=()=>p().replace(/[-_]/g,""),ne=(e,t)=>e.replace(`_${t}`,""),re=e=>{const t=e.split("_");return t[t.length-1]},ae=e=>{const t=[],n=[],{document:r,variables:i}=e.reduce((e,r)=>{const{query:i,variables:s,id:d}=r;try{const u="string"==typeof i?a(i):i,c=u.definitions.find(e=>"FragmentDefinition"===e.kind),l="string"==typeof i?i:o(i),m=/@/.test(l);if(c||m)return n.push(r),e;const f=e=>((e,t)=>`${e}_${t}`)(e,d);return e=e.addN(u,[s],f,f),t.push(r),e}catch(t){return n.push(r),e}},v("BatchedQuery"));return{mergedQuery:r&&o(r),mergedVariables:i,mergedQueryAddedEvents:t,unmergedQueryAddedEvents:n}},oe=(e,t)=>{if(!e)return e;const n=Object.keys(e),{id:r}=t;return n.reduce((t,n)=>(n.endsWith(r)&&(t=V({},t,{[ne(n,r)]:e[n]})),t),{})},ie=(e,t)=>{const{resolve:n}=t;n(e)},se=(e,t)=>{for(const n of t){const t=oe(e,n);n.resolve(t)}},de=(e,t)=>{const{reject:n}=e;n(t)},ue=(e,t)=>{for(const n of e){const{reject:e}=n;e(t)}},ce="sq:graphql-client",le=m(function(e,t,n){return new ee(e+"/api/v1/"+t+"/graphql",{headers:{Authorization:`Bearer ${n||""}`}})});function me(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 fe(t,n){const r=function(){const t=U(),n=j(),r=k(),a=le(n,r,t),o=S(),i=e(o,"sq:graphql-client",{attempts:0});return null!=i?i:a}(),[a,o]=i(me,n);return[a,s(async function(e){if(r)try{o({type:"loading"});const n=await r.request(t,e);o({type:"data",payload:n})}catch(e){o({type:"errors",payload:e})}else o({type:"errors",payload:new Error("No GraphQL client found")})},[r,t,o])]}const ge={loading:!1,data:void 0,errors:void 0};function pe(e){const[t,n]=fe(e,ge);return[n,t]}let he;const ye=Y(he||(he=(e=>e)`
|
|
2
2
|
mutation AuthenticateWithEmailAndPassword(
|
|
3
3
|
$email: String!
|
|
4
4
|
$password: String!
|
|
@@ -15,7 +15,7 @@ import{useDomContext as e}from"@saasquatch/dom-context-hooks";import{ContextProv
|
|
|
15
15
|
sessionData
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
`));function we(){const[e,{loading:t,data:r,errors:a}]=pe(ye);return
|
|
18
|
+
`));function we(){const[e,{loading:t,data:r,errors:a}]=pe(ye);return d(()=>{if(null!=r&&r.authenticateManagedIdentityWithEmailAndPassword){const{authenticateManagedIdentityWithEmailAndPassword:e}=r,t=e.token,{user:a}=n(t);W({jwt:t,id:a.id,accountId:a.accountId,managedIdentity:{email:e.email,emailVerified:e.emailVerified,sessionData:e.sessionData}})}},[null==r?void 0:r.authenticateManagedIdentityWithEmailAndPassword]),[e,{loading:t,data:r,errors:a}]}let ve;const Ce=Y(ve||(ve=(e=>e)`
|
|
19
19
|
mutation RegisterWithEmailAndPassword(
|
|
20
20
|
$email: String!
|
|
21
21
|
$password: String!
|
|
@@ -34,7 +34,7 @@ import{useDomContext as e}from"@saasquatch/dom-context-hooks";import{ContextProv
|
|
|
34
34
|
sessionData
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
`));function be(){const[e,{loading:t,data:r,errors:a}]=pe(Ce);return
|
|
37
|
+
`));function be(){const[e,{loading:t,data:r,errors:a}]=pe(Ce);return d(()=>{if(null!=r&&r.registerManagedIdentityWithEmailAndPassword){const{registerManagedIdentityWithEmailAndPassword:e}=r,t=e.token,{user:a}=n(t);W({jwt:t,id:a.id,accountId:a.accountId,managedIdentity:{email:e.email,emailVerified:e.emailVerified,sessionData:e.sessionData}})}},[null==r?void 0:r.registerManagedIdentityWithEmailAndPassword]),[e,{loading:t,data:r,errors:a}]}let Ie;const Fe=Y(Ie||(Ie=(e=>e)`
|
|
38
38
|
mutation ChangePassword($password: String!) {
|
|
39
39
|
changeManagedIdentityPassword(
|
|
40
40
|
changeManagedIdentityPasswordInput: { password: $password }
|
|
@@ -42,7 +42,7 @@ import{useDomContext as e}from"@saasquatch/dom-context-hooks";import{ContextProv
|
|
|
42
42
|
success
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
`));function qe(){const[e,{loading:t,data:n,errors:r}]=pe(Fe);return[e,{loading:t,data:n,errors:r}]}let
|
|
45
|
+
`));function qe(){const[e,{loading:t,data:n,errors:r}]=pe(Fe);return[e,{loading:t,data:n,errors:r}]}let Se;const Ee=Y(Se||(Se=(e=>e)`
|
|
46
46
|
mutation ResetPassword($oobCode: String!, $password: String!) {
|
|
47
47
|
resetManagedIdentityPassword(
|
|
48
48
|
resetManagedIdentityPasswordInput: {
|
|
@@ -56,7 +56,7 @@ import{useDomContext as e}from"@saasquatch/dom-context-hooks";import{ContextProv
|
|
|
56
56
|
sessionData
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
`));function Pe(){const[e,{loading:t,data:r,errors:a}]=pe(
|
|
59
|
+
`));function Pe(){const[e,{loading:t,data:r,errors:a}]=pe(Ee);return d(()=>{if(null!=r&&r.resetManagedIdentityPassword){const{resetManagedIdentityPassword:e}=r,t=e.token,{user:a}=n(t);W({jwt:t,id:a.id,accountId:a.accountId,managedIdentity:{email:e.email,emailVerified:e.emailVerified,sessionData:e.sessionData}})}},[null==r?void 0:r.resetManagedIdentityPassword]),[e,{loading:t,data:r,errors:a}]}let Me;const De=Y(Me||(Me=(e=>e)`
|
|
60
60
|
mutation VerifyPasswordResetCode($oobCode: String!) {
|
|
61
61
|
verifyManagedIdentityPasswordResetCode(
|
|
62
62
|
verifyManagedIdentityPasswordResetCodeInput: { oobCode: $oobCode }
|
|
@@ -72,7 +72,7 @@ import{useDomContext as e}from"@saasquatch/dom-context-hooks";import{ContextProv
|
|
|
72
72
|
sessionData
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
`));function Re(){const e=J(),[t,{loading:n,data:r,errors:a,refetch:o}]=ke(xe);return
|
|
75
|
+
`));function Re(){const e=J(),[t,{loading:n,data:r,errors:a,refetch:o}]=ke(xe);return d(()=>{if(null!=r&&r.managedIdentity){const{managedIdentity:t}=r;W(V({},e,{managedIdentity:t}))}},[null==r?void 0:r.managedIdentity]),[s(()=>t({}),[t]),{loading:n,data:r,errors:a,refetch:o}]}let Ve;const Ne=Y(Ve||(Ve=(e=>e)`
|
|
76
76
|
mutation VerifyEmail($oobCode: String!) {
|
|
77
77
|
verifyManagedIdentityEmail(
|
|
78
78
|
verifyManagedIdentityEmailInput: { oobCode: $oobCode }
|
|
@@ -80,7 +80,7 @@ import{useDomContext as e}from"@saasquatch/dom-context-hooks";import{ContextProv
|
|
|
80
80
|
success
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
`));function Oe(){var e;const[t]=Re(),[n,{loading:r,data:a,errors:o}]=pe(Ne);return
|
|
83
|
+
`));function Oe(){var e;const[t]=Re(),[n,{loading:r,data:a,errors:o}]=pe(Ne);return d(()=>{var e;null!=a&&null!=(e=a.verifyManagedIdentityEmail)&&e.success&&t()},[null==a||null==(e=a.verifyManagedIdentityEmail)?void 0:e.success]),[n,{loading:r,data:a,errors:o}]}let He;const We=Y(He||(He=(e=>e)`
|
|
84
84
|
mutation RequestPasswordResetEmail($email: String!, $urlParams: RSJsonNode) {
|
|
85
85
|
requestManagedIdentityPasswordResetEmail(
|
|
86
86
|
requestManagedIdentityPasswordResetEmailInput: {
|
|
@@ -102,11 +102,11 @@ import{useDomContext as e}from"@saasquatch/dom-context-hooks";import{ContextProv
|
|
|
102
102
|
success
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
`));function _e(){return pe(Le)}function Qe(e,t){const n=
|
|
105
|
+
`));function _e(){return pe(Le)}function Qe(e,t){const n=u();return n.current&&r(t,n.current.key)||(n.current={key:t,value:e()}),n.current.value}function Te(){return i(e=>e+1,0)}function ze(e){const t=Object.getOwnPropertyNames(e);for(const n of t){const t=e[n];t&&"object"==typeof t&&ze(t)}return Object.freeze(e)}const Ge={loading:!0,data:void 0,errors:void 0};function Be(e,t,n){const[r,a]=fe(e,Ge),[o,i]=Te();return Qe(()=>{!n&&a(t)},[e,t,a,o,n]),ze(V({},r,{refetch:i}))}function Ke(){return window.squatchHistory=window.squatchHistory||function(){switch(A().type){case"SquatchPortal":return b();default:return C()}}(),window.squatchHistory}const Ze={createHref:(...e)=>Ke().createHref(...e),push:(...e)=>Ke().push(...e),replace:(...e)=>Ke().replace(...e),go:(...e)=>Ke().go(...e),back:()=>Ke().back(),forward:(...e)=>Ke().forward(...e)};function Xe(){const[,e]=Te();return d(()=>Ke().listen(()=>{e()}),[]),Ke().location}function Ye(e){const[t,n]=c({limit:e.limit,offset:e.offset}),{offset:r,limit:a}=t,o=(e,t)=>e*t,i=(e,t)=>Math.ceil(e/t)||0;return{limit:a,setLimit:e=>{const a=i(r,e),s=o(e,a);n(V({},t,{limit:e,offset:s}))},offset:r,setCurrentPage:e=>{let t=o(e,a);n(e=>V({},e,{offset:t}))},calculatePagination:function(e,t){const n=i(r,a),o=((e,t)=>Math.ceil(e/t)||0)(t,a),s=0===e?"0":e>1?`${r+1}-${r+e}`:`${r+1}`;return{currentPage:n,pageCount:o,rangeOnPage:s,pageProgress:`${s} of ${t}`}}}}function et(e,t,n,r={},a=!1){var o;const{limit:i,offset:s,setLimit:d,setCurrentPage:u,calculatePagination:c}=Ye(n),l=V({limit:i,offset:s},r),{loading:m,errors:f,data:g,refetch:p}=Be(e,l,a),h=t(g),{currentPage:y,pageCount:w,pageProgress:v}=c((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:i,currentPage:y,pageCount:w,pageProgress:v},callbacks:{refetch:p,setLimit:d,setCurrentPage:u}}}function tt(e,t){return e===t}function nt(e,t,n){const r=n&&n.equalityFn||tt,[a,o]=c(e),i=rt(s(e=>o(e),[]),t,n),l=u(e);return d(()=>{r(l.current,e)||(i.callback(e),l.current=e)},[e,i,r]),[a,{cancel:i.cancel,flush:i.flush}]}function rt(e,t=0,n={leading:!1}){const r=l(()=>I(e,t,n.leading),[e,t,n.leading]),{flush:a,clear:o}=r;return{flush:a,cancel:o,callback:r}}let at;const ot=w(at||(at=(e=>e)`
|
|
106
106
|
mutation ($eventMeta: UserAnalyticsEvent!) {
|
|
107
107
|
createUserAnalyticsEvent(eventMeta: $eventMeta)
|
|
108
108
|
}
|
|
109
|
-
`));function it(){const e=x(),t=J(),n=M(),[r]=pe(ot);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 st,
|
|
109
|
+
`));function it(){const e=x(),t=J(),n=M(),[r]=pe(ot);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 st,dt=1e3,ut=60*dt,ct=60*ut,lt=24*ct,mt=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*lt;case"hours":case"hour":case"hrs":case"hr":case"h":return n*ct;case"minutes":case"minute":case"mins":case"min":case"m":return n*ut;case"seconds":case"second":case"secs":case"sec":case"s":return n*dt;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>=lt?ft(e,t,lt,"day"):t>=ct?ft(e,t,ct,"hour"):t>=ut?ft(e,t,ut,"minute"):t>=dt?ft(e,t,dt,"second"):e+" ms"}(e):function(e){var t=Math.abs(e);return t>=lt?Math.round(e/lt)+"d":t>=ct?Math.round(e/ct)+"h":t>=ut?Math.round(e/ut)+"m":t>=dt?Math.round(e/dt)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function ft(e,t,n,r){var a=t>=1.5*n;return Math.round(e/n)+" "+r+(a?"s":"")}let gt,pt,ht,yt=e=>e;const wt=(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 i=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(r,a)=>{if("%%"===r)return"%";i++;const o=t.formatters[a];return"function"==typeof o&&(r=o.call(n,e[i]),e.splice(i,1),i--),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=mt,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}}}(st={exports:{}},st.exports),st.exports)("sq:useForm"),vt=w(gt||(gt=yt`
|
|
110
110
|
query ($key: String!) {
|
|
111
111
|
form(key: $key) {
|
|
112
112
|
schema
|
|
@@ -177,5 +177,5 @@ import{useDomContext as e}from"@saasquatch/dom-context-hooks";import{ContextProv
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
-
`));function It(e){var t,n,r,a;const{formKey:o,formRef:s,autoSubmit:
|
|
180
|
+
`));function It(e){var t,n,r,a;const{formKey:o,formRef:s,autoSubmit:u=!1}=e,[c,{data:l,loading:m}]=ke(vt),[f,g]=pe(Ct),[p,h]=ke(bt),y={enabled:!1,validating:!1,valid:!0,validationMessage:"",error:"",disabledMessage:"",formData:{},validationData:h,submitData:g},[w,v]=i((e,t)=>V({},e,t),y),{enabled:C,disabledMessage:b,validating:I,valid:q,error:S,formData:E}=w;async function P(e){await p({formValidationInput:{key:o,formData:e}})}return Qe(()=>{wt("submitData useEffect",g),v({submitData:g})},[g]),Qe(()=>{wt("validationData useEffect",h),v({validationData:h})},[h]),d(()=>{!m&&l&&function(){var t,n,r,a,o;v({enabled:null==l||null==(t=l.form.initialData)?void 0:t.isEnabled,disabledMessage:null==l||null==(n=l.form)||null==(r=n.initialData)?void 0:r.isEnabledErrorMessage});const i=s;if(!i)return;const d=null==l||null==(a=l.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);wt({htmlForm:e,formContent:r}),null==r||r.forEach((e,r)=>{wt({value:e,key:r,inputs:n});const a=n.namedItem(r);try{"checkbox"==a.type?a.checked=F.get(t,r):a.value=F.get(t,r)||""}catch(e){wt("no initialData found for key",r)}})}(i,d)}()},[m]),d(()=>{var e,t,n,r,a,i;w.validationData&&(v({validating:!1,valid:(null==(e=w.validationData)||null==(t=e.data)||null==(n=t.validateForm)?void 0:n.valid)||!1}),u&&null!=(r=w.validationData)&&null!=(a=r.data)&&null!=(i=a.validateForm)&&i.valid&&f({formSubmissionInput:{key:o,formData:E}}))},[null==(t=w.validationData)||null==(n=t.data)||null==(r=n.validateForm)?void 0:r.valid]),{states:{enabled:C,disabledMessage:b,loadingForm:m,validating:I,valid:q,error:S,validationData:w.validationData,submitData:w.submitData},data:{formKey:o,schema:null==l||null==(a=l.form)?void 0:a.schema},callbacks:{getForm:c,handleSubmit:async function(e){e.preventDefault(),v({validating:!0});const t=e.target;wt("submit form",t);const n=new FormData(t);let r={};for(var a of n.entries())F.set(r,a[0],a[1]);v({formData:r}),await P(r)},validateForm:P,submitForm:async function(e){await f({formSubmissionInput:{key:o,formData:e}})},setFormState:v,getValidationErrors:function(){var e,t,n,r;const a=null==h||null==(e=h.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(!w.submitData)return[];const t=null==(e=w.submitData.data)?void 0:e.submitForm.results;return(null==t?void 0:t.map(e=>{var t,n,r,a,o,i,s;const d=null==(t=e.result)||null==(n=t.results)?void 0:n.flatMap(e=>!e.success&&e.message).filter(e=>e),u=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==(i=o.integration)?void 0:i.name,formHandler:null==(s=e.formHandler)?void 0:s.name,messages:d,errors:u}}))||[]}}}}export{ee as BatchedGraphQLClient,ce as GRAPHQL_CONTEXT,A as getEnvironmentSDK,$ as isDemo,le as memoizedGraphQLClient,Ze as navigation,D as setProgramId,E as setUseHostImplementation,W as setUserIdentity,j as useAppDomain,we as useAuthenticateWithEmailAndPasswordMutation,qe as useChangePasswordMutation,Xe as useCurrentPage,nt as useDebounce,rt as useDebouncedCallback,x as useEngagementMedium,It as useForm,S as useHost,ke as useLazyQuery,R as useLocale,Re as useManagedIdentityQuery,pe as useMutation,et as usePaginatedQuery,Ye as usePagination,M as useProgramId,Be as useQuery,be as useRegisterWithEmailAndPasswordMutation,Ue as useRequestPasswordResetEmailMutation,_e as useRequestVerificationEmailMutation,Pe as useResetPasswordMutation,it as useShareEvent,k as useTenantAlias,Te as useTick,U as useToken,J as useUserIdentity,Oe as useVerifyEmailMutation,Ae as useVerifyPasswordResetCodeMutation};
|
|
181
181
|
//# sourceMappingURL=index.modern.js.map
|