@descope/react-sdk 2.1.0 → 2.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/dist/cjs/index.cjs.js +1 -1
- package/dist/dts/src/sdk.d.ts +144 -12
- package/dist/index.d.ts +48 -4
- package/dist/index.esm.js +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +10 -10
package/dist/index.d.ts
CHANGED
|
@@ -103,14 +103,19 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
103
103
|
locale?: string;
|
|
104
104
|
oidcPrompt?: string;
|
|
105
105
|
oidcErrorRedirectUri?: string;
|
|
106
|
-
|
|
106
|
+
nativeOptions?: {
|
|
107
|
+
platform: "ios" | "android";
|
|
108
|
+
oauthProvider?: string;
|
|
109
|
+
oauthRedirect?: string;
|
|
110
|
+
};
|
|
111
|
+
}, "tenant" | "redirectUrl" | "redirectAuth" | "oidcIdpStateId" | "samlIdpStateId" | "samlIdpUsername" | "ssoAppId" | "oidcLoginHint" | "preview" | "abTestingKey" | "client" | "locale" | "oidcPrompt" | "oidcErrorRedirectUri" | "nativeOptions"> & {
|
|
107
112
|
lastAuth?: Omit<{
|
|
108
113
|
authMethod?: "webauthn" | "otp" | "oauth" | "saml" | "totp" | "magiclink" | "enchantedlink";
|
|
109
114
|
oauthProvider?: string;
|
|
110
115
|
name?: string;
|
|
111
116
|
loginId?: string;
|
|
112
117
|
}, "loginId" | "name">;
|
|
113
|
-
}, conditionInteractionId?: string, interactionId?: string,
|
|
118
|
+
}, conditionInteractionId?: string, interactionId?: string, componentsVersion?: string, flowVersions?: Record<string, number>, input?: {
|
|
114
119
|
[x: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any[])[])[])[])[])[])[])[])[])[])[];
|
|
115
120
|
}) => Promise<_1.SdkResponse<_1.FlowResponse>>;
|
|
116
121
|
next: (executionId: string, stepId: string, interactionId: string, version?: number, componentsVersion?: string, input?: {
|
|
@@ -195,6 +200,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
195
200
|
phone?: string;
|
|
196
201
|
}, signUpOptions?: {
|
|
197
202
|
customClaims?: Record<string, any>;
|
|
203
|
+
templateId?: string;
|
|
198
204
|
templateOptions?: {
|
|
199
205
|
[x: string]: string;
|
|
200
206
|
};
|
|
@@ -210,6 +216,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
210
216
|
phone?: string;
|
|
211
217
|
}, signUpOptions?: {
|
|
212
218
|
customClaims?: Record<string, any>;
|
|
219
|
+
templateId?: string;
|
|
213
220
|
templateOptions?: {
|
|
214
221
|
[x: string]: string;
|
|
215
222
|
};
|
|
@@ -225,6 +232,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
225
232
|
phone?: string;
|
|
226
233
|
}, signUpOptions?: {
|
|
227
234
|
customClaims?: Record<string, any>;
|
|
235
|
+
templateId?: string;
|
|
228
236
|
templateOptions?: {
|
|
229
237
|
[x: string]: string;
|
|
230
238
|
};
|
|
@@ -240,6 +248,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
240
248
|
phone?: string;
|
|
241
249
|
}, signUpOptions?: {
|
|
242
250
|
customClaims?: Record<string, any>;
|
|
251
|
+
templateId?: string;
|
|
243
252
|
templateOptions?: {
|
|
244
253
|
[x: string]: string;
|
|
245
254
|
};
|
|
@@ -328,6 +337,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
328
337
|
phone?: string;
|
|
329
338
|
}, signUpOptions?: {
|
|
330
339
|
customClaims?: Record<string, any>;
|
|
340
|
+
templateId?: string;
|
|
331
341
|
templateOptions?: {
|
|
332
342
|
[x: string]: string;
|
|
333
343
|
};
|
|
@@ -343,6 +353,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
343
353
|
phone?: string;
|
|
344
354
|
}, signUpOptions?: {
|
|
345
355
|
customClaims?: Record<string, any>;
|
|
356
|
+
templateId?: string;
|
|
346
357
|
templateOptions?: {
|
|
347
358
|
[x: string]: string;
|
|
348
359
|
};
|
|
@@ -358,6 +369,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
358
369
|
phone?: string;
|
|
359
370
|
}, signUpOptions?: {
|
|
360
371
|
customClaims?: Record<string, any>;
|
|
372
|
+
templateId?: string;
|
|
361
373
|
templateOptions?: {
|
|
362
374
|
[x: string]: string;
|
|
363
375
|
};
|
|
@@ -373,6 +385,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
373
385
|
phone?: string;
|
|
374
386
|
}, signUpOptions?: {
|
|
375
387
|
customClaims?: Record<string, any>;
|
|
388
|
+
templateId?: string;
|
|
376
389
|
templateOptions?: {
|
|
377
390
|
[x: string]: string;
|
|
378
391
|
};
|
|
@@ -383,6 +396,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
383
396
|
signUpOrIn: {
|
|
384
397
|
sms: (loginId: string, URI?: string, signUpOptions?: {
|
|
385
398
|
customClaims?: Record<string, any>;
|
|
399
|
+
templateId?: string;
|
|
386
400
|
templateOptions?: {
|
|
387
401
|
[x: string]: string;
|
|
388
402
|
};
|
|
@@ -391,6 +405,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
391
405
|
}>>;
|
|
392
406
|
voice: (loginId: string, URI?: string, signUpOptions?: {
|
|
393
407
|
customClaims?: Record<string, any>;
|
|
408
|
+
templateId?: string;
|
|
394
409
|
templateOptions?: {
|
|
395
410
|
[x: string]: string;
|
|
396
411
|
};
|
|
@@ -399,6 +414,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
399
414
|
}>>;
|
|
400
415
|
whatsapp: (loginId: string, URI?: string, signUpOptions?: {
|
|
401
416
|
customClaims?: Record<string, any>;
|
|
417
|
+
templateId?: string;
|
|
402
418
|
templateOptions?: {
|
|
403
419
|
[x: string]: string;
|
|
404
420
|
};
|
|
@@ -407,6 +423,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
407
423
|
}>>;
|
|
408
424
|
email: (loginId: string, URI?: string, signUpOptions?: {
|
|
409
425
|
customClaims?: Record<string, any>;
|
|
426
|
+
templateId?: string;
|
|
410
427
|
templateOptions?: {
|
|
411
428
|
[x: string]: string;
|
|
412
429
|
};
|
|
@@ -460,6 +477,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
460
477
|
signIn: (loginId: string, URI?: string, loginOptions?: _1.LoginOptions, token?: string) => Promise<_1.SdkResponse<_1.EnchantedLinkResponse>>;
|
|
461
478
|
signUpOrIn: (loginId: string, URI?: string, signUpOptions?: {
|
|
462
479
|
customClaims?: Record<string, any>;
|
|
480
|
+
templateId?: string;
|
|
463
481
|
templateOptions?: {
|
|
464
482
|
[x: string]: string;
|
|
465
483
|
};
|
|
@@ -473,6 +491,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
473
491
|
phone?: string;
|
|
474
492
|
}, signUpOptions?: {
|
|
475
493
|
customClaims?: Record<string, any>;
|
|
494
|
+
templateId?: string;
|
|
476
495
|
templateOptions?: {
|
|
477
496
|
[x: string]: string;
|
|
478
497
|
};
|
|
@@ -526,6 +545,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
526
545
|
notp: {
|
|
527
546
|
signUpOrIn: (loginId?: string, signUpOptions?: {
|
|
528
547
|
customClaims?: Record<string, any>;
|
|
548
|
+
templateId?: string;
|
|
529
549
|
templateOptions?: {
|
|
530
550
|
[x: string]: string;
|
|
531
551
|
};
|
|
@@ -543,6 +563,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
543
563
|
phone?: string;
|
|
544
564
|
}, signUpOptions?: {
|
|
545
565
|
customClaims?: Record<string, any>;
|
|
566
|
+
templateId?: string;
|
|
546
567
|
templateOptions?: {
|
|
547
568
|
[x: string]: string;
|
|
548
569
|
};
|
|
@@ -571,6 +592,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
571
592
|
phone?: string;
|
|
572
593
|
}, signUpOptions?: {
|
|
573
594
|
customClaims?: Record<string, any>;
|
|
595
|
+
templateId?: string;
|
|
574
596
|
templateOptions?: {
|
|
575
597
|
[x: string]: string;
|
|
576
598
|
};
|
|
@@ -687,14 +709,19 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
687
709
|
locale?: string;
|
|
688
710
|
oidcPrompt?: string;
|
|
689
711
|
oidcErrorRedirectUri?: string;
|
|
690
|
-
|
|
712
|
+
nativeOptions?: {
|
|
713
|
+
platform: "ios" | "android";
|
|
714
|
+
oauthProvider?: string;
|
|
715
|
+
oauthRedirect?: string;
|
|
716
|
+
};
|
|
717
|
+
}, "tenant" | "redirectUrl" | "redirectAuth" | "oidcIdpStateId" | "samlIdpStateId" | "samlIdpUsername" | "ssoAppId" | "oidcLoginHint" | "preview" | "abTestingKey" | "client" | "locale" | "oidcPrompt" | "oidcErrorRedirectUri" | "nativeOptions"> & {
|
|
691
718
|
lastAuth?: Omit<{
|
|
692
719
|
authMethod?: "webauthn" | "otp" | "oauth" | "saml" | "totp" | "magiclink" | "enchantedlink";
|
|
693
720
|
oauthProvider?: string;
|
|
694
721
|
name?: string;
|
|
695
722
|
loginId?: string;
|
|
696
723
|
}, "loginId" | "name">;
|
|
697
|
-
}, conditionInteractionId?: string, interactionId?: string,
|
|
724
|
+
}, conditionInteractionId?: string, interactionId?: string, componentsVersion?: string, flowVersions?: Record<string, number>, input?: {
|
|
698
725
|
[x: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any[])[])[])[])[])[])[])[])[])[])[];
|
|
699
726
|
}) => Promise<_1.SdkResponse<_1.FlowResponse>>;
|
|
700
727
|
next: (executionId: string, stepId: string, interactionId: string, version?: number, componentsVersion?: string, input?: {
|
|
@@ -779,6 +806,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
779
806
|
phone?: string;
|
|
780
807
|
}, signUpOptions?: {
|
|
781
808
|
customClaims?: Record<string, any>;
|
|
809
|
+
templateId?: string;
|
|
782
810
|
templateOptions?: {
|
|
783
811
|
[x: string]: string;
|
|
784
812
|
};
|
|
@@ -794,6 +822,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
794
822
|
phone?: string;
|
|
795
823
|
}, signUpOptions?: {
|
|
796
824
|
customClaims?: Record<string, any>;
|
|
825
|
+
templateId?: string;
|
|
797
826
|
templateOptions?: {
|
|
798
827
|
[x: string]: string;
|
|
799
828
|
};
|
|
@@ -809,6 +838,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
809
838
|
phone?: string;
|
|
810
839
|
}, signUpOptions?: {
|
|
811
840
|
customClaims?: Record<string, any>;
|
|
841
|
+
templateId?: string;
|
|
812
842
|
templateOptions?: {
|
|
813
843
|
[x: string]: string;
|
|
814
844
|
};
|
|
@@ -824,6 +854,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
824
854
|
phone?: string;
|
|
825
855
|
}, signUpOptions?: {
|
|
826
856
|
customClaims?: Record<string, any>;
|
|
857
|
+
templateId?: string;
|
|
827
858
|
templateOptions?: {
|
|
828
859
|
[x: string]: string;
|
|
829
860
|
};
|
|
@@ -912,6 +943,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
912
943
|
phone?: string;
|
|
913
944
|
}, signUpOptions?: {
|
|
914
945
|
customClaims?: Record<string, any>;
|
|
946
|
+
templateId?: string;
|
|
915
947
|
templateOptions?: {
|
|
916
948
|
[x: string]: string;
|
|
917
949
|
};
|
|
@@ -927,6 +959,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
927
959
|
phone?: string;
|
|
928
960
|
}, signUpOptions?: {
|
|
929
961
|
customClaims?: Record<string, any>;
|
|
962
|
+
templateId?: string;
|
|
930
963
|
templateOptions?: {
|
|
931
964
|
[x: string]: string;
|
|
932
965
|
};
|
|
@@ -942,6 +975,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
942
975
|
phone?: string;
|
|
943
976
|
}, signUpOptions?: {
|
|
944
977
|
customClaims?: Record<string, any>;
|
|
978
|
+
templateId?: string;
|
|
945
979
|
templateOptions?: {
|
|
946
980
|
[x: string]: string;
|
|
947
981
|
};
|
|
@@ -957,6 +991,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
957
991
|
phone?: string;
|
|
958
992
|
}, signUpOptions?: {
|
|
959
993
|
customClaims?: Record<string, any>;
|
|
994
|
+
templateId?: string;
|
|
960
995
|
templateOptions?: {
|
|
961
996
|
[x: string]: string;
|
|
962
997
|
};
|
|
@@ -967,6 +1002,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
967
1002
|
signUpOrIn: {
|
|
968
1003
|
sms: (loginId: string, URI?: string, signUpOptions?: {
|
|
969
1004
|
customClaims?: Record<string, any>;
|
|
1005
|
+
templateId?: string;
|
|
970
1006
|
templateOptions?: {
|
|
971
1007
|
[x: string]: string;
|
|
972
1008
|
};
|
|
@@ -975,6 +1011,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
975
1011
|
}>>;
|
|
976
1012
|
voice: (loginId: string, URI?: string, signUpOptions?: {
|
|
977
1013
|
customClaims?: Record<string, any>;
|
|
1014
|
+
templateId?: string;
|
|
978
1015
|
templateOptions?: {
|
|
979
1016
|
[x: string]: string;
|
|
980
1017
|
};
|
|
@@ -983,6 +1020,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
983
1020
|
}>>;
|
|
984
1021
|
whatsapp: (loginId: string, URI?: string, signUpOptions?: {
|
|
985
1022
|
customClaims?: Record<string, any>;
|
|
1023
|
+
templateId?: string;
|
|
986
1024
|
templateOptions?: {
|
|
987
1025
|
[x: string]: string;
|
|
988
1026
|
};
|
|
@@ -991,6 +1029,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
991
1029
|
}>>;
|
|
992
1030
|
email: (loginId: string, URI?: string, signUpOptions?: {
|
|
993
1031
|
customClaims?: Record<string, any>;
|
|
1032
|
+
templateId?: string;
|
|
994
1033
|
templateOptions?: {
|
|
995
1034
|
[x: string]: string;
|
|
996
1035
|
};
|
|
@@ -1044,6 +1083,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
1044
1083
|
signIn: (loginId: string, URI?: string, loginOptions?: _1.LoginOptions, token?: string) => Promise<_1.SdkResponse<_1.EnchantedLinkResponse>>;
|
|
1045
1084
|
signUpOrIn: (loginId: string, URI?: string, signUpOptions?: {
|
|
1046
1085
|
customClaims?: Record<string, any>;
|
|
1086
|
+
templateId?: string;
|
|
1047
1087
|
templateOptions?: {
|
|
1048
1088
|
[x: string]: string;
|
|
1049
1089
|
};
|
|
@@ -1057,6 +1097,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
1057
1097
|
phone?: string;
|
|
1058
1098
|
}, signUpOptions?: {
|
|
1059
1099
|
customClaims?: Record<string, any>;
|
|
1100
|
+
templateId?: string;
|
|
1060
1101
|
templateOptions?: {
|
|
1061
1102
|
[x: string]: string;
|
|
1062
1103
|
};
|
|
@@ -1110,6 +1151,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
1110
1151
|
notp: {
|
|
1111
1152
|
signUpOrIn: (loginId?: string, signUpOptions?: {
|
|
1112
1153
|
customClaims?: Record<string, any>;
|
|
1154
|
+
templateId?: string;
|
|
1113
1155
|
templateOptions?: {
|
|
1114
1156
|
[x: string]: string;
|
|
1115
1157
|
};
|
|
@@ -1127,6 +1169,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
1127
1169
|
phone?: string;
|
|
1128
1170
|
}, signUpOptions?: {
|
|
1129
1171
|
customClaims?: Record<string, any>;
|
|
1172
|
+
templateId?: string;
|
|
1130
1173
|
templateOptions?: {
|
|
1131
1174
|
[x: string]: string;
|
|
1132
1175
|
};
|
|
@@ -1155,6 +1198,7 @@ declare const createSdkWrapper: <P extends Omit<{
|
|
|
1155
1198
|
phone?: string;
|
|
1156
1199
|
}, signUpOptions?: {
|
|
1157
1200
|
customClaims?: Record<string, any>;
|
|
1201
|
+
templateId?: string;
|
|
1158
1202
|
templateOptions?: {
|
|
1159
1203
|
[x: string]: string;
|
|
1160
1204
|
};
|
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e,{useMemo as t,useState as r,useEffect as n,useRef as s,useCallback as o,lazy as a,useImperativeHandle as i,Suspense as l,useContext as d}from"react";import c from"@descope/web-js-sdk";const u=e.createContext(void 0),g=e=>(...t)=>{if(!e)throw Error("You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component");return e(...t)},f=e=>(...t)=>{let r;try{r=e(...t)}catch(e){console.error(e)}return r},b={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.1.0"},p="undefined"!=typeof window;let m;const h=e=>{const t=c(Object.assign({persistTokens:p,autoRefresh:p},e));return m=t,t},U=()=>h({projectId:"temp pid",persistTokens:!1,autoRefresh:!1,storeLastAuthenticatedUser:!1});m=U();const w=()=>p?null==m?void 0:m.getSessionToken():(console.warn("Get session token is not supported in SSR"),""),I=()=>p?null==m?void 0:m.getRefreshToken():(console.warn("Get refresh token is not supported in SSR"),""),k=(e=w())=>null==m?void 0:m.isJwtExpired(e),E=(e=I())=>null==m?void 0:m.isJwtExpired(e),L=f(((e=w(),t)=>null==m?void 0:m.getJwtPermissions(e,t))),j=f(((e=w(),t)=>null==m?void 0:m.getJwtRoles(e,t))),v=(e=I())=>null==m?void 0:m.refresh(e);const S=({projectId:a,baseUrl:i="",baseStaticUrl:l="",sessionTokenViaCookie:d=!1,persistTokens:c=!0,storeLastAuthenticatedUser:f=!0,keepLastAuthenticatedUserAfterLogout:p=!1,children:m})=>{const[U,w]=r(),[I,k]=r(),[E,L]=r(!1),[j,v]=r(!1),S=(({projectId:e,baseUrl:r,persistTokens:n,sessionTokenViaCookie:s,storeLastAuthenticatedUser:o,keepLastAuthenticatedUserAfterLogout:a})=>t((()=>{if(e)return h({projectId:e,baseUrl:r,sessionTokenViaCookie:s,baseHeaders:b,persistTokens:n,storeLastAuthenticatedUser:o,keepLastAuthenticatedUserAfterLogout:a,autoRefresh:!0})}),[e,r,s]))({projectId:a,baseUrl:i,persistTokens:c,sessionTokenViaCookie:d,storeLastAuthenticatedUser:f,keepLastAuthenticatedUserAfterLogout:p});n((()=>{if(S){const e=S.onSessionTokenChange(k),t=S.onUserChange(w);return()=>{e(),t()}}}),[S]);const y=s(!1),R=s(!1),A=o((()=>{y.current||(y.current=!0,v(!0),g(null==S?void 0:S.refresh)().then((()=>{v(!1)})))}),[S]),C=o((()=>{R.current||(R.current=!0,L(!0),g(S.me)().then((()=>{L(!1)})))}),[S]),x=t((()=>({fetchUser:C,user:U,isUserLoading:E,isUserFetched:R.current,fetchSession:A,session:I,isSessionLoading:j,isSessionFetched:y.current,projectId:a,baseUrl:i,baseStaticUrl:l,storeLastAuthenticatedUser:f,keepLastAuthenticatedUserAfterLogout:p,setUser:w,setSession:k,sdk:S})),[C,U,E,R.current,A,I,j,y.current,a,i,l,w,k,S]);return e.createElement(u.Provider,{value:x},m)},y=a((async()=>((await import("@descope/web-component")).default.sdkConfigOverrides={baseHeaders:b,persistTokens:!1,hooks:{get beforeRequest(){return m.httpClient.hooks.beforeRequest},set beforeRequest(e){}}},{default:({projectId:t,flowId:r,baseUrl:n,baseStaticUrl:s,innerRef:o,tenant:a,theme:i,locale:l,debug:d,redirectUrl:c,client:u,form:g,styleId:f,autoFocus:b,validateOnBlur:p,storeLastAuthenticatedUser:m})=>e.createElement("descope-wc",{"project-id":t,"flow-id":r,"base-url":n,"base-static-url":s,ref:o,tenant:a,theme:i,locale:l,debug:d,client:u,form:g,"style-id":f,"redirect-url":c,"auto-focus":b,"validate-on-blur":p,"store-last-authenticated-user":m})}))),R=e.forwardRef((({flowId:s,onSuccess:a,onError:d,onReady:c,logger:g,tenant:f,theme:b,locale:p,debug:m,client:h,form:U,telemetryKey:w,redirectUrl:I,autoFocus:k,validateOnBlur:E,errorTransformer:L,styleId:j},v)=>{const[S,R]=r(null);i(v,(()=>S));const{projectId:A,baseUrl:C,baseStaticUrl:x,storeLastAuthenticatedUser:T,keepLastAuthenticatedUserAfterLogout:O,sdk:F}=e.useContext(u),J=o((async e=>{await F.httpClient.hooks.afterRequest({},new Response(JSON.stringify(e.detail))),a&&a(e)}),[a]);n((()=>{const e=S;return null==e||e.addEventListener("success",J),d&&(null==e||e.addEventListener("error",d)),c&&(null==e||e.addEventListener("ready",c)),()=>{d&&(null==e||e.removeEventListener("error",d)),c&&(null==e||e.removeEventListener("ready",c)),null==e||e.removeEventListener("success",J)}}),[S,d,J]),n((()=>{const e=S;return null==e||e.addEventListener("success",J),()=>{null==e||e.removeEventListener("success",J)}}),[S,J]),n((()=>{const e=S;return d&&(null==e||e.addEventListener("error",d)),()=>{d&&(null==e||e.removeEventListener("error",d))}}),[S,d]),n((()=>{const e=S;return c&&(null==e||e.addEventListener("ready",c)),()=>{c&&(null==e||e.removeEventListener("error",c))}}),[S,c]),n((()=>{S&&(S.errorTransformer=L)}),[S,L]),n((()=>{S&&g&&(S.logger=g)}),[S,g]);const{form:P,client:q}=t((()=>({form:JSON.stringify(U||{}),client:JSON.stringify(h||{})})),[U,h]);return e.createElement("form",null,e.createElement(l,{fallback:null},e.createElement(y,{projectId:A,flowId:s,baseUrl:C,baseStaticUrl:x,innerRef:R,tenant:f,theme:b,locale:p,debug:m,form:P,client:q,telemetryKey:w,redirectUrl:I,autoFocus:k,styleId:j,validateOnBlur:E,storeLastAuthenticatedUser:T,keepLastAuthenticatedUserAfterLogout:O})))})),A=t=>e.createElement(R,Object.assign({},t,{flowId:"sign-in"})),C=t=>e.createElement(R,Object.assign({},t,{flowId:"sign-up"})),x=t=>e.createElement(R,Object.assign({},t,{flowId:"sign-up-or-in"})),T=a((async()=>(await import("@descope/user-management-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,tenant:o,widgetId:a,theme:i,debug:l})=>e.createElement("descope-user-management-widget",{"project-id":t,"widget-id":a,"base-url":r,"base-static-url":n,theme:i,tenant:o,debug:l,ref:s})}))),O=e.forwardRef((({logger:t,tenant:s,theme:o,debug:a,widgetId:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),e.createElement(l,{fallback:null},e.createElement(T,{projectId:b,widgetId:d,baseUrl:p,baseStaticUrl:m,innerRef:f,tenant:s,theme:o,debug:a}))})),F=a((async()=>(await import("@descope/role-management-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,tenant:o,widgetId:a,theme:i,debug:l})=>e.createElement("descope-role-management-widget",{"project-id":t,"widget-id":a,"base-url":r,"base-static-url":n,theme:i,tenant:o,debug:l,ref:s})}))),J=e.forwardRef((({logger:t,tenant:s,theme:o,debug:a,widgetId:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),e.createElement(l,{fallback:null},e.createElement(F,{projectId:b,widgetId:d,baseUrl:p,baseStaticUrl:m,innerRef:f,tenant:s,theme:o,debug:a}))})),P=a((async()=>(await import("@descope/access-key-management-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,tenant:o,widgetId:a,theme:i,debug:l})=>e.createElement("descope-access-key-management-widget",{"project-id":t,"widget-id":a,"base-url":r,"base-static-url":n,theme:i,tenant:o,debug:l,ref:s})}))),q=e.forwardRef((({logger:t,tenant:s,theme:o,debug:a,widgetId:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),e.createElement(l,{fallback:null},e.createElement(P,{projectId:b,widgetId:d,baseUrl:p,baseStaticUrl:m,innerRef:f,tenant:s,theme:o,debug:a}))})),V=a((async()=>(await import("@descope/audit-management-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,tenant:o,widgetId:a,theme:i,debug:l})=>e.createElement("descope-audit-management-widget",{"project-id":t,"widget-id":a,"base-url":r,"base-static-url":n,theme:i,tenant:o,debug:l,ref:s})}))),B=e.forwardRef((({logger:t,tenant:s,theme:o,debug:a,widgetId:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),e.createElement(l,{fallback:null},e.createElement(V,{projectId:b,widgetId:d,baseUrl:p,baseStaticUrl:m,innerRef:f,tenant:s,theme:o,debug:a}))})),N=a((async()=>(await import("@descope/user-profile-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,widgetId:o,theme:a,debug:i})=>e.createElement("descope-user-profile-widget",{"project-id":t,"widget-id":o,"base-url":r,"base-static-url":n,theme:a,debug:i,ref:s})}))),Y=e.forwardRef((({logger:t,theme:s,debug:o,widgetId:a,onLogout:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),n((()=>{if(g&&d)return g.addEventListener("logout",d),()=>g.removeEventListener("logout",d)}),[g,d]),e.createElement(l,{fallback:null},e.createElement(N,{projectId:b,widgetId:a,baseUrl:p,baseStaticUrl:m,innerRef:f,theme:s,debug:o}))})),z=a((async()=>(await import("@descope/applications-portal-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,widgetId:o,theme:a,debug:i})=>e.createElement("descope-applications-portal-widget",{"project-id":t,"widget-id":o,"base-url":r,"base-static-url":n,theme:a,debug:i,ref:s})}))),G=e.forwardRef((({logger:t,theme:s,debug:o,widgetId:a},d)=>{const[c,g]=r(null);i(d,(()=>c));const{projectId:f,baseUrl:b,baseStaticUrl:p}=e.useContext(u);return n((()=>{c&&t&&(c.logger=t)}),[c,t]),e.createElement(l,{fallback:null},e.createElement(z,{projectId:f,widgetId:a,baseUrl:b,baseStaticUrl:p,innerRef:g,theme:s,debug:o}))}));var H=()=>{const e=d(u);if(!e)throw Error("You can only use this hook in the context of <AuthProvider />");return e};const K=e=>`You can only use this ${e} after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component`,M={get(e,t){if("object"==typeof e[t]&&null!==e[t])return new Proxy(e[t],M);if("function"==typeof e[t])return()=>{throw Error(K("function"))};throw Error(K("attribute"))}},$=()=>{const{sdk:e}=H();return t((()=>e||new Proxy(U(),M)),[e])},D=()=>{const{session:e,isSessionLoading:r,fetchSession:o,isSessionFetched:a}=H(),i=s(r);t((()=>{i.current=r}),[r]);const l=!e&&!r;return t((()=>{l&&!a&&(i.current=!0)}),[a]),n((()=>{l&&o()}),[o]),{isSessionLoading:i.current,sessionToken:e,isAuthenticated:!!e}},Q=()=>{const{user:e,fetchUser:o,isUserLoading:a,session:i,isUserFetched:l}=H(),[d,c]=r(!1),u=s(a),g=t((()=>!e&&!a&&i&&!d),[o,i,d]);return t((()=>{u.current=a}),[a]),t((()=>{g&&!l&&(u.current=!0)}),[g,l]),n((()=>{g&&(c(!0),o())}),[g]),{isUserLoading:u.current,user:e}};export{q as AccessKeyManagement,G as ApplicationsPortal,B as AuditManagement,S as AuthProvider,R as Descope,J as RoleManagement,A as SignInFlow,C as SignUpFlow,x as SignUpOrInFlow,O as UserManagement,Y as UserProfile,b as baseHeaders,L as getJwtPermissions,j as getJwtRoles,I as getRefreshToken,w as getSessionToken,E as isRefreshTokenExpired,k as isSessionTokenExpired,v as refresh,$ as useDescope,D as useSession,Q as useUser};
|
|
1
|
+
import e,{useMemo as t,useState as r,useEffect as n,useRef as s,useCallback as o,lazy as a,useImperativeHandle as i,Suspense as l,useContext as d}from"react";import c from"@descope/web-js-sdk";const u=e.createContext(void 0),g=e=>(...t)=>{if(!e)throw Error("You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component");return e(...t)},f=e=>(...t)=>{let r;try{r=e(...t)}catch(e){console.error(e)}return r},b={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.1.2"},p="undefined"!=typeof window;let m;const h=e=>{const t=c(Object.assign({persistTokens:p,autoRefresh:p},e));return m=t,t},U=()=>h({projectId:"temp pid",persistTokens:!1,autoRefresh:!1,storeLastAuthenticatedUser:!1});m=U();const w=()=>p?null==m?void 0:m.getSessionToken():(console.warn("Get session token is not supported in SSR"),""),I=()=>p?null==m?void 0:m.getRefreshToken():(console.warn("Get refresh token is not supported in SSR"),""),k=(e=w())=>null==m?void 0:m.isJwtExpired(e),E=(e=I())=>null==m?void 0:m.isJwtExpired(e),L=f(((e=w(),t)=>null==m?void 0:m.getJwtPermissions(e,t))),j=f(((e=w(),t)=>null==m?void 0:m.getJwtRoles(e,t))),v=(e=I())=>null==m?void 0:m.refresh(e);const S=({projectId:a,baseUrl:i="",baseStaticUrl:l="",sessionTokenViaCookie:d=!1,persistTokens:c=!0,storeLastAuthenticatedUser:f=!0,keepLastAuthenticatedUserAfterLogout:p=!1,children:m})=>{const[U,w]=r(),[I,k]=r(),[E,L]=r(!1),[j,v]=r(!1),S=(({projectId:e,baseUrl:r,persistTokens:n,sessionTokenViaCookie:s,storeLastAuthenticatedUser:o,keepLastAuthenticatedUserAfterLogout:a})=>t((()=>{if(e)return h({projectId:e,baseUrl:r,sessionTokenViaCookie:s,baseHeaders:b,persistTokens:n,storeLastAuthenticatedUser:o,keepLastAuthenticatedUserAfterLogout:a,autoRefresh:!0})}),[e,r,s]))({projectId:a,baseUrl:i,persistTokens:c,sessionTokenViaCookie:d,storeLastAuthenticatedUser:f,keepLastAuthenticatedUserAfterLogout:p});n((()=>{if(S){const e=S.onSessionTokenChange(k),t=S.onUserChange(w);return()=>{e(),t()}}}),[S]);const y=s(!1),R=s(!1),A=o((()=>{y.current||(y.current=!0,v(!0),g(null==S?void 0:S.refresh)().then((()=>{v(!1)})))}),[S]),C=o((()=>{R.current||(R.current=!0,L(!0),g(S.me)().then((()=>{L(!1)})))}),[S]),x=t((()=>({fetchUser:C,user:U,isUserLoading:E,isUserFetched:R.current,fetchSession:A,session:I,isSessionLoading:j,isSessionFetched:y.current,projectId:a,baseUrl:i,baseStaticUrl:l,storeLastAuthenticatedUser:f,keepLastAuthenticatedUserAfterLogout:p,setUser:w,setSession:k,sdk:S})),[C,U,E,R.current,A,I,j,y.current,a,i,l,w,k,S]);return e.createElement(u.Provider,{value:x},m)},y=a((async()=>((await import("@descope/web-component")).default.sdkConfigOverrides={baseHeaders:b,persistTokens:!1,hooks:{get beforeRequest(){return m.httpClient.hooks.beforeRequest},set beforeRequest(e){}}},{default:({projectId:t,flowId:r,baseUrl:n,baseStaticUrl:s,innerRef:o,tenant:a,theme:i,locale:l,debug:d,redirectUrl:c,client:u,form:g,styleId:f,autoFocus:b,validateOnBlur:p,storeLastAuthenticatedUser:m})=>e.createElement("descope-wc",{"project-id":t,"flow-id":r,"base-url":n,"base-static-url":s,ref:o,tenant:a,theme:i,locale:l,debug:d,client:u,form:g,"style-id":f,"redirect-url":c,"auto-focus":b,"validate-on-blur":p,"store-last-authenticated-user":m})}))),R=e.forwardRef((({flowId:s,onSuccess:a,onError:d,onReady:c,logger:g,tenant:f,theme:b,locale:p,debug:m,client:h,form:U,telemetryKey:w,redirectUrl:I,autoFocus:k,validateOnBlur:E,errorTransformer:L,styleId:j},v)=>{const[S,R]=r(null);i(v,(()=>S));const{projectId:A,baseUrl:C,baseStaticUrl:x,storeLastAuthenticatedUser:T,keepLastAuthenticatedUserAfterLogout:O,sdk:F}=e.useContext(u),J=o((async e=>{await F.httpClient.hooks.afterRequest({},new Response(JSON.stringify(e.detail))),a&&a(e)}),[a]);n((()=>{const e=S;return null==e||e.addEventListener("success",J),d&&(null==e||e.addEventListener("error",d)),c&&(null==e||e.addEventListener("ready",c)),()=>{d&&(null==e||e.removeEventListener("error",d)),c&&(null==e||e.removeEventListener("ready",c)),null==e||e.removeEventListener("success",J)}}),[S,d,J]),n((()=>{const e=S;return null==e||e.addEventListener("success",J),()=>{null==e||e.removeEventListener("success",J)}}),[S,J]),n((()=>{const e=S;return d&&(null==e||e.addEventListener("error",d)),()=>{d&&(null==e||e.removeEventListener("error",d))}}),[S,d]),n((()=>{const e=S;return c&&(null==e||e.addEventListener("ready",c)),()=>{c&&(null==e||e.removeEventListener("error",c))}}),[S,c]),n((()=>{S&&(S.errorTransformer=L)}),[S,L]),n((()=>{S&&g&&(S.logger=g)}),[S,g]);const{form:P,client:q}=t((()=>({form:JSON.stringify(U||{}),client:JSON.stringify(h||{})})),[U,h]);return e.createElement("form",null,e.createElement(l,{fallback:null},e.createElement(y,{projectId:A,flowId:s,baseUrl:C,baseStaticUrl:x,innerRef:R,tenant:f,theme:b,locale:p,debug:m,form:P,client:q,telemetryKey:w,redirectUrl:I,autoFocus:k,styleId:j,validateOnBlur:E,storeLastAuthenticatedUser:T,keepLastAuthenticatedUserAfterLogout:O})))})),A=t=>e.createElement(R,Object.assign({},t,{flowId:"sign-in"})),C=t=>e.createElement(R,Object.assign({},t,{flowId:"sign-up"})),x=t=>e.createElement(R,Object.assign({},t,{flowId:"sign-up-or-in"})),T=a((async()=>(await import("@descope/user-management-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,tenant:o,widgetId:a,theme:i,debug:l})=>e.createElement("descope-user-management-widget",{"project-id":t,"widget-id":a,"base-url":r,"base-static-url":n,theme:i,tenant:o,debug:l,ref:s})}))),O=e.forwardRef((({logger:t,tenant:s,theme:o,debug:a,widgetId:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),e.createElement(l,{fallback:null},e.createElement(T,{projectId:b,widgetId:d,baseUrl:p,baseStaticUrl:m,innerRef:f,tenant:s,theme:o,debug:a}))})),F=a((async()=>(await import("@descope/role-management-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,tenant:o,widgetId:a,theme:i,debug:l})=>e.createElement("descope-role-management-widget",{"project-id":t,"widget-id":a,"base-url":r,"base-static-url":n,theme:i,tenant:o,debug:l,ref:s})}))),J=e.forwardRef((({logger:t,tenant:s,theme:o,debug:a,widgetId:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),e.createElement(l,{fallback:null},e.createElement(F,{projectId:b,widgetId:d,baseUrl:p,baseStaticUrl:m,innerRef:f,tenant:s,theme:o,debug:a}))})),P=a((async()=>(await import("@descope/access-key-management-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,tenant:o,widgetId:a,theme:i,debug:l})=>e.createElement("descope-access-key-management-widget",{"project-id":t,"widget-id":a,"base-url":r,"base-static-url":n,theme:i,tenant:o,debug:l,ref:s})}))),q=e.forwardRef((({logger:t,tenant:s,theme:o,debug:a,widgetId:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),e.createElement(l,{fallback:null},e.createElement(P,{projectId:b,widgetId:d,baseUrl:p,baseStaticUrl:m,innerRef:f,tenant:s,theme:o,debug:a}))})),V=a((async()=>(await import("@descope/audit-management-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,tenant:o,widgetId:a,theme:i,debug:l})=>e.createElement("descope-audit-management-widget",{"project-id":t,"widget-id":a,"base-url":r,"base-static-url":n,theme:i,tenant:o,debug:l,ref:s})}))),B=e.forwardRef((({logger:t,tenant:s,theme:o,debug:a,widgetId:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),e.createElement(l,{fallback:null},e.createElement(V,{projectId:b,widgetId:d,baseUrl:p,baseStaticUrl:m,innerRef:f,tenant:s,theme:o,debug:a}))})),N=a((async()=>(await import("@descope/user-profile-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,widgetId:o,theme:a,debug:i})=>e.createElement("descope-user-profile-widget",{"project-id":t,"widget-id":o,"base-url":r,"base-static-url":n,theme:a,debug:i,ref:s})}))),Y=e.forwardRef((({logger:t,theme:s,debug:o,widgetId:a,onLogout:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),n((()=>{if(g&&d)return g.addEventListener("logout",d),()=>g.removeEventListener("logout",d)}),[g,d]),e.createElement(l,{fallback:null},e.createElement(N,{projectId:b,widgetId:a,baseUrl:p,baseStaticUrl:m,innerRef:f,theme:s,debug:o}))})),z=a((async()=>(await import("@descope/applications-portal-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,widgetId:o,theme:a,debug:i})=>e.createElement("descope-applications-portal-widget",{"project-id":t,"widget-id":o,"base-url":r,"base-static-url":n,theme:a,debug:i,ref:s})}))),G=e.forwardRef((({logger:t,theme:s,debug:o,widgetId:a},d)=>{const[c,g]=r(null);i(d,(()=>c));const{projectId:f,baseUrl:b,baseStaticUrl:p}=e.useContext(u);return n((()=>{c&&t&&(c.logger=t)}),[c,t]),e.createElement(l,{fallback:null},e.createElement(z,{projectId:f,widgetId:a,baseUrl:b,baseStaticUrl:p,innerRef:g,theme:s,debug:o}))}));var H=()=>{const e=d(u);if(!e)throw Error("You can only use this hook in the context of <AuthProvider />");return e};const K=e=>`You can only use this ${e} after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component`,M={get(e,t){if("object"==typeof e[t]&&null!==e[t])return new Proxy(e[t],M);if("function"==typeof e[t])return()=>{throw Error(K("function"))};throw Error(K("attribute"))}},$=()=>{const{sdk:e}=H();return t((()=>e||new Proxy(U(),M)),[e])},D=()=>{const{session:e,isSessionLoading:r,fetchSession:o,isSessionFetched:a}=H(),i=s(r);t((()=>{i.current=r}),[r]);const l=!e&&!r;return t((()=>{l&&!a&&(i.current=!0)}),[a]),n((()=>{l&&o()}),[o]),{isSessionLoading:i.current,sessionToken:e,isAuthenticated:!!e}},Q=()=>{const{user:e,fetchUser:o,isUserLoading:a,session:i,isUserFetched:l}=H(),[d,c]=r(!1),u=s(a),g=t((()=>!e&&!a&&i&&!d),[o,i,d]);return t((()=>{u.current=a}),[a]),t((()=>{g&&!l&&(u.current=!0)}),[g,l]),n((()=>{g&&(c(!0),o())}),[g]),{isUserLoading:u.current,user:e}};export{q as AccessKeyManagement,G as ApplicationsPortal,B as AuditManagement,S as AuthProvider,R as Descope,J as RoleManagement,A as SignInFlow,C as SignUpFlow,x as SignUpOrInFlow,O as UserManagement,Y as UserProfile,b as baseHeaders,L as getJwtPermissions,j as getJwtRoles,I as getRefreshToken,w as getSessionToken,E as isRefreshTokenExpired,k as isSessionTokenExpired,v as refresh,$ as useDescope,D as useSession,Q as useUser};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|