@descope/core-js-sdk 0.0.41-alpha.18 → 0.0.41-alpha.19
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/README.md +0 -1
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.d.ts +104 -49
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.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.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
declare type SdkFn = (...args: any[]) => Promise<SdkResponse
|
|
2
|
-
|
|
3
|
-
externalIds: string[];
|
|
4
|
-
verifiedEmail?: boolean;
|
|
5
|
-
verifiedPhone?: boolean;
|
|
6
|
-
}
|
|
1
|
+
declare type SdkFn = (...args: any[]) => Promise<SdkResponse<ResponseData>>;
|
|
2
|
+
/** User base details from Descope API */
|
|
7
3
|
declare type User = {
|
|
8
4
|
email?: string;
|
|
9
5
|
name?: string;
|
|
10
6
|
phone?: string;
|
|
11
7
|
};
|
|
12
|
-
|
|
8
|
+
/** User extended details from Descope API */
|
|
9
|
+
declare type UserResponse = User & {
|
|
10
|
+
externalIds: string[];
|
|
11
|
+
verifiedEmail?: boolean;
|
|
12
|
+
verifiedPhone?: boolean;
|
|
13
|
+
};
|
|
14
|
+
/** Authentication info result from the various JWT validations */
|
|
15
|
+
declare type JWTResponse = {
|
|
13
16
|
sessionJwt: string;
|
|
14
17
|
refreshJwt?: string;
|
|
15
18
|
cookieDomain?: string;
|
|
@@ -18,14 +21,38 @@ interface AuthInfo {
|
|
|
18
21
|
cookieExpiration?: number;
|
|
19
22
|
user?: UserResponse;
|
|
20
23
|
firstSeen?: boolean;
|
|
21
|
-
}
|
|
24
|
+
};
|
|
25
|
+
declare type ExchangeAccessKeyResponse = {
|
|
26
|
+
keyId: string;
|
|
27
|
+
sessionJwt: string;
|
|
28
|
+
expiration: number;
|
|
29
|
+
};
|
|
30
|
+
/** Pending reference URL to poll while waiting for user to click magic link */
|
|
31
|
+
declare type PendingRefResponse = {
|
|
32
|
+
pendingRef: string;
|
|
33
|
+
};
|
|
34
|
+
/** URL response to redirect user in case of OAuth or SSO */
|
|
35
|
+
declare type URLResponse = {
|
|
36
|
+
url: string;
|
|
37
|
+
};
|
|
38
|
+
/** TOTP response with the TOTP details */
|
|
39
|
+
declare type TOTPResponse = {
|
|
40
|
+
provisioningURL: string;
|
|
41
|
+
image: string;
|
|
42
|
+
key: string;
|
|
43
|
+
};
|
|
44
|
+
/** All delivery methods currently supported */
|
|
22
45
|
declare enum DeliveryMethods {
|
|
23
46
|
email = "email",
|
|
24
47
|
sms = "sms",
|
|
25
48
|
whatsapp = "whatsapp"
|
|
26
49
|
}
|
|
27
|
-
declare type
|
|
28
|
-
|
|
50
|
+
declare type ResponseData = Record<string, any>;
|
|
51
|
+
/**
|
|
52
|
+
* Response from our SDK calls which includes the result (ok, code, error).
|
|
53
|
+
* The relevant data is provided in the more specific interfaces extending SdkResponse.
|
|
54
|
+
*/
|
|
55
|
+
declare type SdkResponse<T extends ResponseData> = {
|
|
29
56
|
code?: number;
|
|
30
57
|
ok: boolean;
|
|
31
58
|
response?: Response;
|
|
@@ -33,10 +60,14 @@ declare type SdkResponse = {
|
|
|
33
60
|
message: string;
|
|
34
61
|
code: string;
|
|
35
62
|
};
|
|
36
|
-
data?:
|
|
63
|
+
data?: T;
|
|
37
64
|
};
|
|
65
|
+
/** Different delivery method */
|
|
66
|
+
declare type Deliveries<T extends SdkFn> = Record<DeliveryMethods, T>;
|
|
67
|
+
/** Logger type that supports the given levels (debug, log, error) */
|
|
38
68
|
declare type Logger = Pick<Console, 'debug' | 'log' | 'error'>;
|
|
39
69
|
|
|
70
|
+
/** Request configuration including headers, query params and token */
|
|
40
71
|
declare type HttpClientReqConfig = {
|
|
41
72
|
headers?: HeadersInit;
|
|
42
73
|
queryParams?: {
|
|
@@ -44,18 +75,21 @@ declare type HttpClientReqConfig = {
|
|
|
44
75
|
};
|
|
45
76
|
token?: string;
|
|
46
77
|
};
|
|
78
|
+
/** HTTP methods we use in the client */
|
|
47
79
|
declare enum HTTPMethods {
|
|
48
80
|
get = "GET",
|
|
49
81
|
delete = "DELETE",
|
|
50
82
|
post = "POST",
|
|
51
83
|
put = "PUT"
|
|
52
84
|
}
|
|
85
|
+
/** HTTP Client type that implements the HTTP method calls. Descopers can provide their own HTTP client although required only in rare cases. */
|
|
53
86
|
declare type HttpClient = {
|
|
54
87
|
get: (path: string, config?: HttpClientReqConfig) => Promise<Response>;
|
|
55
88
|
post: (path: string, body?: any, config?: HttpClientReqConfig) => Promise<Response>;
|
|
56
89
|
put: (path: string, body?: any, config?: HttpClientReqConfig) => Promise<Response>;
|
|
57
90
|
delete: (path: string, body?: any, config?: HttpClientReqConfig) => Promise<Response>;
|
|
58
91
|
};
|
|
92
|
+
/** For before-request hook allows overriding parts of the request */
|
|
59
93
|
declare type RequestConfig = {
|
|
60
94
|
path: string;
|
|
61
95
|
headers?: HeadersInit;
|
|
@@ -66,14 +100,16 @@ declare type RequestConfig = {
|
|
|
66
100
|
method: HTTPMethods;
|
|
67
101
|
token?: string;
|
|
68
102
|
};
|
|
103
|
+
/** Hooks before and after the request is made */
|
|
69
104
|
declare type Hooks = {
|
|
70
105
|
beforeRequest?: (config: RequestConfig) => RequestConfig;
|
|
71
106
|
afterRequest?: (req: RequestConfig, res: Response) => void;
|
|
72
107
|
};
|
|
73
108
|
|
|
74
|
-
declare type SignInFn = (identifier: string, uri: string) => Promise<SdkResponse
|
|
75
|
-
declare type SignUpFn = (identifier: string, uri: string, user?: User) => Promise<SdkResponse
|
|
76
|
-
declare type UpdatePhoneFn = (identifier: string, phone: string) => Promise<SdkResponse
|
|
109
|
+
declare type SignInFn = (identifier: string, uri: string) => Promise<SdkResponse<PendingRefResponse>>;
|
|
110
|
+
declare type SignUpFn = (identifier: string, uri: string, user?: User) => Promise<SdkResponse<PendingRefResponse>>;
|
|
111
|
+
declare type UpdatePhoneFn = (identifier: string, phone: string) => Promise<SdkResponse<never>>;
|
|
112
|
+
/** Polling configuration for session waiting */
|
|
77
113
|
declare type WaitForSessionConfig = {
|
|
78
114
|
pollingIntervalMs: number;
|
|
79
115
|
timeoutMs: number;
|
|
@@ -88,6 +124,22 @@ declare enum OAuthProviders {
|
|
|
88
124
|
apple = "apple"
|
|
89
125
|
}
|
|
90
126
|
|
|
127
|
+
/** Descope SDK client with delivery methods enum.
|
|
128
|
+
*
|
|
129
|
+
* Please see full documentation at {@link https://docs.descope.com/guides Descope Docs}
|
|
130
|
+
* @example Usage
|
|
131
|
+
*
|
|
132
|
+
* ```js
|
|
133
|
+
* import descopeSdk from '@descope/core-js-sdk';
|
|
134
|
+
*
|
|
135
|
+
* const myProjectId = 'xxx';
|
|
136
|
+
* const sdk = descopeSdk({ projectId: myProjectId });
|
|
137
|
+
*
|
|
138
|
+
* const userIdentifier = 'identifier';
|
|
139
|
+
* sdk.otp.signIn.email(userIdentifier);
|
|
140
|
+
* const jwtResponse = sdk.otp.verify.email(userIdentifier, codeFromEmail);
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
91
143
|
declare const sdkWithAttributes: ((args_0: {
|
|
92
144
|
projectId: string;
|
|
93
145
|
logger?: Logger;
|
|
@@ -96,114 +148,117 @@ declare const sdkWithAttributes: ((args_0: {
|
|
|
96
148
|
cookiePolicy?: RequestCredentials;
|
|
97
149
|
}) => {
|
|
98
150
|
accessKey: {
|
|
99
|
-
exchange: (accessKey: string) => Promise<SdkResponse
|
|
151
|
+
exchange: (accessKey: string) => Promise<SdkResponse<ExchangeAccessKeyResponse>>;
|
|
100
152
|
};
|
|
101
153
|
otp: {
|
|
102
|
-
verify: Deliveries<(identifier: string, code: string) => Promise<SdkResponse
|
|
103
|
-
signIn: Deliveries<(identifier: string) => Promise<SdkResponse
|
|
104
|
-
signUp: Deliveries<(identifier: string, user?: User) => Promise<SdkResponse
|
|
105
|
-
signUpOrIn: Deliveries<(identifier: string) => Promise<SdkResponse
|
|
154
|
+
verify: Deliveries<(identifier: string, code: string) => Promise<SdkResponse<JWTResponse>>>;
|
|
155
|
+
signIn: Deliveries<(identifier: string) => Promise<SdkResponse<never>>>;
|
|
156
|
+
signUp: Deliveries<(identifier: string, user?: User) => Promise<SdkResponse<never>>>;
|
|
157
|
+
signUpOrIn: Deliveries<(identifier: string) => Promise<SdkResponse<never>>>;
|
|
106
158
|
update: {
|
|
107
|
-
email: (identifier: string, email: string, token?: string) => Promise<SdkResponse
|
|
108
|
-
phone: Deliveries<(identifier: string, phone: string) => Promise<SdkResponse
|
|
159
|
+
email: (identifier: string, email: string, token?: string) => Promise<SdkResponse<never>>;
|
|
160
|
+
phone: Deliveries<(identifier: string, phone: string) => Promise<SdkResponse<never>>>;
|
|
109
161
|
};
|
|
110
162
|
};
|
|
111
163
|
magicLink: {
|
|
112
|
-
verify: (token: string) => Promise<SdkResponse
|
|
164
|
+
verify: (token: string) => Promise<SdkResponse<JWTResponse>>;
|
|
113
165
|
signIn: Deliveries<SignInFn>;
|
|
114
166
|
signUp: Deliveries<SignUpFn>;
|
|
115
167
|
signUpOrIn: Deliveries<SignInFn>;
|
|
116
168
|
update: {
|
|
117
|
-
email: (identifier: string, email: string, uri: string, token?: string) => Promise<SdkResponse
|
|
169
|
+
email: (identifier: string, email: string, uri: string, token?: string) => Promise<SdkResponse<never>>;
|
|
118
170
|
phone: Deliveries<UpdatePhoneFn>;
|
|
119
171
|
};
|
|
120
172
|
crossDevice: {
|
|
121
|
-
verify: (token: string) => Promise<SdkResponse
|
|
173
|
+
verify: (token: string) => Promise<SdkResponse<JWTResponse>>;
|
|
122
174
|
signIn: Deliveries<SignInFn>;
|
|
123
175
|
signUpOrIn: Deliveries<SignInFn>;
|
|
124
176
|
signUp: Deliveries<SignUpFn>;
|
|
125
|
-
waitForSession: (pendingRef: string, config?: WaitForSessionConfig) => Promise<SdkResponse
|
|
177
|
+
waitForSession: (pendingRef: string, config?: WaitForSessionConfig) => Promise<SdkResponse<JWTResponse>>;
|
|
126
178
|
update: {
|
|
127
|
-
email: (identifier: string, email: string, uri: string, token?: string) => Promise<SdkResponse
|
|
179
|
+
email: (identifier: string, email: string, uri: string, token?: string) => Promise<SdkResponse<never>>;
|
|
128
180
|
phone: Deliveries<UpdatePhoneFn>;
|
|
129
181
|
};
|
|
130
182
|
};
|
|
131
183
|
};
|
|
132
184
|
oauth: {
|
|
133
|
-
exchange: (code: string) => Promise<SdkResponse
|
|
185
|
+
exchange: (code: string) => Promise<SdkResponse<JWTResponse>>;
|
|
134
186
|
start: {
|
|
135
187
|
facebook: <B extends {
|
|
136
188
|
redirect: boolean;
|
|
137
189
|
}>(redirectURL?: string, config?: B) => Promise<B extends {
|
|
138
190
|
redirect: true;
|
|
139
|
-
} ? undefined : SdkResponse
|
|
191
|
+
} ? undefined : SdkResponse<URLResponse>>;
|
|
140
192
|
github: <B extends {
|
|
141
193
|
redirect: boolean;
|
|
142
194
|
}>(redirectURL?: string, config?: B) => Promise<B extends {
|
|
143
195
|
redirect: true;
|
|
144
|
-
} ? undefined : SdkResponse
|
|
196
|
+
} ? undefined : SdkResponse<URLResponse>>;
|
|
145
197
|
google: <B extends {
|
|
146
198
|
redirect: boolean;
|
|
147
199
|
}>(redirectURL?: string, config?: B) => Promise<B extends {
|
|
148
200
|
redirect: true;
|
|
149
|
-
} ? undefined : SdkResponse
|
|
201
|
+
} ? undefined : SdkResponse<URLResponse>>;
|
|
150
202
|
microsoft: <B extends {
|
|
151
203
|
redirect: boolean;
|
|
152
204
|
}>(redirectURL?: string, config?: B) => Promise<B extends {
|
|
153
205
|
redirect: true;
|
|
154
|
-
} ? undefined : SdkResponse
|
|
206
|
+
} ? undefined : SdkResponse<URLResponse>>;
|
|
155
207
|
gitlab: <B extends {
|
|
156
208
|
redirect: boolean;
|
|
157
209
|
}>(redirectURL?: string, config?: B) => Promise<B extends {
|
|
158
210
|
redirect: true;
|
|
159
|
-
} ? undefined : SdkResponse
|
|
211
|
+
} ? undefined : SdkResponse<URLResponse>>;
|
|
160
212
|
apple: <B extends {
|
|
161
213
|
redirect: boolean;
|
|
162
214
|
}>(redirectURL?: string, config?: B) => Promise<B extends {
|
|
163
215
|
redirect: true;
|
|
164
|
-
} ? undefined : SdkResponse
|
|
216
|
+
} ? undefined : SdkResponse<URLResponse>>;
|
|
165
217
|
};
|
|
166
218
|
};
|
|
167
219
|
saml: {
|
|
168
|
-
exchange: (code: string) => Promise<SdkResponse
|
|
220
|
+
exchange: (code: string) => Promise<SdkResponse<JWTResponse>>;
|
|
169
221
|
start: <B_1 extends {
|
|
170
222
|
redirect: boolean;
|
|
171
223
|
}>(tenantNameOrEmail: string, config?: B_1) => Promise<B_1 extends {
|
|
172
224
|
redirect: true;
|
|
173
|
-
} ? undefined : SdkResponse
|
|
225
|
+
} ? undefined : SdkResponse<URLResponse>>;
|
|
174
226
|
};
|
|
175
227
|
totp: {
|
|
176
|
-
signUp: (identifier: string, user?: User) => Promise<SdkResponse
|
|
177
|
-
verify: (identifier: string, code: string) => Promise<SdkResponse
|
|
178
|
-
update: (identifier: string, token?: string) => Promise<SdkResponse
|
|
228
|
+
signUp: (identifier: string, user?: User) => Promise<SdkResponse<TOTPResponse>>;
|
|
229
|
+
verify: (identifier: string, code: string) => Promise<SdkResponse<JWTResponse>>;
|
|
230
|
+
update: (identifier: string, token?: string) => Promise<SdkResponse<TOTPResponse>>;
|
|
179
231
|
};
|
|
180
232
|
webauthn: {
|
|
181
233
|
signUp: {
|
|
182
|
-
start: (identifier: string, origin: string, name: string) => Promise<SdkResponse
|
|
183
|
-
finish: (transactionId: string, response: string) => Promise<SdkResponse
|
|
234
|
+
start: (identifier: string, origin: string, name: string) => Promise<SdkResponse<ResponseData>>;
|
|
235
|
+
finish: (transactionId: string, response: string) => Promise<SdkResponse<ResponseData>>;
|
|
184
236
|
};
|
|
185
237
|
signIn: {
|
|
186
|
-
start: (identifier: string, origin: string) => Promise<SdkResponse
|
|
187
|
-
finish: (transactionId: string, response: string) => Promise<SdkResponse
|
|
238
|
+
start: (identifier: string, origin: string) => Promise<SdkResponse<ResponseData>>;
|
|
239
|
+
finish: (transactionId: string, response: string) => Promise<SdkResponse<ResponseData>>;
|
|
188
240
|
};
|
|
189
241
|
update: {
|
|
190
|
-
start: (identifier: string, origin: string, token: string) => Promise<SdkResponse
|
|
191
|
-
finish: (transactionId: string, response: string) => Promise<SdkResponse
|
|
242
|
+
start: (identifier: string, origin: string, token: string) => Promise<SdkResponse<ResponseData>>;
|
|
243
|
+
finish: (transactionId: string, response: string) => Promise<SdkResponse<ResponseData>>;
|
|
192
244
|
};
|
|
193
245
|
};
|
|
194
246
|
flow: {
|
|
195
|
-
start: (flowId: string) => Promise<SdkResponse
|
|
196
|
-
next: (executionId: string, stepId: string, interactionId: string, input?: Record<string, FormDataEntryValue>) => Promise<SdkResponse
|
|
247
|
+
start: (flowId: string) => Promise<SdkResponse<ResponseData>>; /** Descope SDK client */
|
|
248
|
+
next: (executionId: string, stepId: string, interactionId: string, input?: Record<string, FormDataEntryValue>) => Promise<SdkResponse<ResponseData>>;
|
|
197
249
|
};
|
|
198
|
-
refresh: (token?: string) => Promise<SdkResponse
|
|
199
|
-
logout: (token?: string) => Promise<SdkResponse
|
|
250
|
+
refresh: (token?: string) => Promise<SdkResponse<SdkResponse<JWTResponse>>>;
|
|
251
|
+
logout: (token?: string) => Promise<SdkResponse<SdkResponse<never>>>;
|
|
252
|
+
me: (token?: string) => Promise<SdkResponse<SdkResponse<UserResponse>>>;
|
|
200
253
|
isJwtExpired: (token: string) => boolean;
|
|
201
254
|
httpClient: HttpClient;
|
|
202
255
|
}) & {
|
|
203
256
|
DeliveryMethods: typeof DeliveryMethods;
|
|
204
257
|
};
|
|
205
258
|
|
|
259
|
+
/** Type to restrict to valid delivery methods */
|
|
206
260
|
declare type DeliveryMethod = keyof typeof DeliveryMethods;
|
|
261
|
+
/** Type to restrict to valid OAuth providers */
|
|
207
262
|
declare type OAuthProvider = keyof typeof OAuthProviders;
|
|
208
263
|
|
|
209
|
-
export {
|
|
264
|
+
export { DeliveryMethod, HTTPMethods, JWTResponse, OAuthProvider, PendingRefResponse, ResponseData, SdkResponse, TOTPResponse, URLResponse, UserResponse, sdkWithAttributes as default };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"jwt-decode";import t from"lodash.get";var s={exchange:"/v1/auth/accesskey/exchange"},n={verify:"/v1/auth/otp/verify",signIn:"/v1/auth/otp/signin",signUp:"/v1/auth/otp/signup",update:{email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},signUpOrIn:"/v1/auth/otp/signup-in"},a={verify:"/v1/auth/magiclink/verify",signIn:"/v1/auth/magiclink/signin",signUp:"/v1/auth/magiclink/signup",session:"/v1/auth/magiclink/pending-session",update:{email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/email"},signUpOrIn:"/v1/auth/magiclink/signup-in"},i={start:"/v1/auth/oauth/authorize"},r={start:"/v1/auth/saml/authorize"},o={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/user/totp/update"},c={signUp:{start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},signIn:{start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},update:{start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"}},u="/v1/auth/refresh",p="/v1/auth/logoutall",d={start:"/v1/flow/start",next:"/v1/flow/next"},g="/v1/auth/exchange";var l;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(l||(l={}));const h=()=>{const e={};return{headers(t){const s="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(s),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}},m=(e,t)=>{const s=t||fetch;if(!s)throw new Error("fetch is not defined");return e?async(...t)=>{e.log((e=>h().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const n=await s(...t);return e[n.ok?"log":"error"](await(async e=>{const t=await e.text();return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),h().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(n)),n}:s},v=(...e)=>new Headers(e.reduce(((e,t)=>{const s=(e=>Array.isArray(e)?e:e instanceof Headers?Array.from(e.entries()):e?Object.entries(e):[])(t);return s.reduce(((t,[s,n])=>(e[s]=n,e)),e),e}),{})),b=e=>void 0===e?void 0:JSON.stringify(e),f=(e,t="")=>{let s=e;return""!==t&&(s=s+":"+t),{Authorization:`Bearer ${s}`}},y=({baseUrl:e,projectId:t,baseConfig:s,logger:n,hooks:a,cookiePolicy:i})=>{const r=m(n),o=async n=>{const o=(null==a?void 0:a.beforeRequest)?a.beforeRequest(n):n,{path:c,body:u,headers:p,queryParams:d,method:g,token:l}=o,h=await r((({path:e,baseUrl:t,queryParams:s})=>{const n=new URL(e,t);return s&&(n.search=new URLSearchParams(s).toString()),n})({path:c,baseUrl:e,queryParams:d}),{headers:v(f(t,l),(null==s?void 0:s.baseHeaders)||{},p),method:g,body:b(u),credentials:i||"include"});return(null==a?void 0:a.afterRequest)&&a.afterRequest(n,null==h?void 0:h.clone()),h};return{get:(e,{headers:t,queryParams:s,token:n}={})=>o({path:e,headers:t,queryParams:s,body:void 0,method:l.get,token:n}),post:(e,t,{headers:s,queryParams:n,token:a}={})=>o({path:e,headers:s,queryParams:n,body:t,method:l.post,token:a}),put:(e,t,{headers:s,queryParams:n,token:a}={})=>o({path:e,headers:s,queryParams:n,body:t,method:l.put,token:a}),delete:(e,t,{headers:s,queryParams:n,token:a}={})=>o({path:e,headers:s,queryParams:n,body:t,method:l.delete,token:a})}},I=t=>{if("string"!=typeof t||!t)throw new Error("Invalid token provided");const{exp:s}=e(t);return(new Date).getTime()/1e3>s},k=(...e)=>e.join("/").replace(/\/{2,}/g,"/"),j=async e=>{const t=await e,s={code:t.status,ok:t.ok,response:t},n=await t.json();return t.ok?s.data=n:s.error=n,s},O=(e,t)=>(s=t)=>t=>!e(t)&&s.replace("{val}",t),U=(...e)=>({validate:t=>(e.forEach((e=>{const s=e(t);if(s)throw new Error(s)})),!0)}),w=e=>t=>e.test(t),x=w(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),P=w(/^\+[1-9]{1}[0-9]{3,14}$/),R=O(x,'"{val}" is not a valid email'),q=O(P,'"{val}" is not a valid phone number'),$=O((M=1,e=>e.length>=M),"Minimum length is 1");var M;const E=O((e=>"string"==typeof e),"Input is not a string"),S=(...e)=>t=>(...s)=>(e.forEach(((e,t)=>U(...e).validate(s[t]))),t(...s)),T=e=>[E(`"${e}" must be a string`),$(`"${e}" must not be empty`)],D=e=>[E(`"${e}" must be a string`),R()],A=e=>[E(`"${e}" must be a string`),q()],z=S(T("accessKey")),L=e=>({exchange:z((t=>j(e.get(s.exchange,{token:t}))))});var H,J,N,Z;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(H||(H={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(J||(J={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(N||(N={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(Z||(Z={}));const B=T("identifier"),C=S(B,T("code")),K=S(B),F=S(B,A("phone")),G=S(B,D("email")),_=e=>({verify:Object.keys(J).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:C(((t,a)=>j(e.post(k(n.verify,s),{code:a,externalId:t}))))})),{}),signIn:Object.keys(J).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:K((t=>j(e.post(k(n.signIn,s),{externalId:t}))))})),{}),signUp:Object.keys(J).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:K(((t,a)=>j(e.post(k(n.signUp,s),{externalId:t,user:a}))))})),{}),signUpOrIn:Object.keys(J).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:K((t=>j(e.post(k(n.signUpOrIn,s),{externalId:t}))))})),{}),update:{email:G(((t,s,a)=>j(e.post(n.update.email,{externalId:t,email:s},{token:a})))),phone:Object.keys(H).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:F(((t,a,i)=>j(e.post(k(n.update.phone,s),{externalId:t,phone:a},{token:i}))))})),{})}}),Q=T("identifier"),V=T("uri"),W=S(T("token")),X=S(Q,V),Y=S(T("pendingRef")),ee=S(Q,A("phone"),V),te=S(Q,D("email"),V),se=e=>({verify:W((t=>j(e.post(a.verify,{token:t})))),signIn:Object.keys(J).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:X(((t,n)=>j(e.post(k(a.signIn,s),{externalId:t,URI:n,crossDevice:!0}))))})),{}),signUpOrIn:Object.keys(J).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:X(((t,n)=>j(e.post(k(a.signUpOrIn,s),{externalId:t,URI:n,crossDevice:!0}))))})),{}),signUp:Object.keys(J).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:X(((t,n,i)=>j(e.post(k(a.signUp,s),{externalId:t,URI:n,user:i,crossDevice:!0}))))})),{}),waitForSession:Y(((t,s)=>new Promise((n=>{const{pollingIntervalMs:i,timeoutMs:r}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||6e5,6e5)}))(s);let o;const c=setInterval((async()=>{const s=await e.post(a.session,{pendingRef:t});s.ok&&(clearInterval(c),o&&clearTimeout(o),n(j(Promise.resolve(s))))}),i);o=setTimeout((()=>{n({error:{message:`Session polling timeout exceeded: ${r}ms`,code:"0"},ok:!1}),clearInterval(c)}),r)})))),update:{email:te(((t,s,n,i)=>j(e.post(a.update.email,{externalId:t,email:s,URI:n,crossDevice:!0},{token:i})))),phone:Object.keys(H).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:ee(((t,n,i,r)=>j(e.post(k(a.update.phone,s),{externalId:t,phone:n,URI:i,crossDevice:!0},{token:r}))))})),{})}}),ne=e=>({verify:W((t=>j(e.post(a.verify,{token:t})))),signIn:Object.keys(J).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:X(((t,n)=>j(e.post(k(a.signIn,s),{externalId:t,URI:n}))))})),{}),signUp:Object.keys(J).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:X(((t,n,i)=>j(e.post(k(a.signUp,s),{externalId:t,URI:n,user:i}))))})),{}),signUpOrIn:Object.keys(J).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:X(((t,n)=>j(e.post(k(a.signUpOrIn,s),{externalId:t,URI:n}))))})),{}),update:{email:te(((t,s,n,i)=>j(e.post(a.update.email,{externalId:t,email:s,URI:n},{token:i})))),phone:Object.keys(H).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:ee(((t,n,i,r)=>j(e.post(k(a.update.phone,s),{externalId:t,phone:n,URI:i},{token:r}))))})),{})},crossDevice:se(e)}),ae=S(T("code")),ie=e=>({exchange:ae((t=>j(e.get(g,{queryParams:{code:t}}))))});var re;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple"}(re||(re={}));const oe=e=>Object.assign({start:Object.keys(re).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:async(t,{redirect:n=!1}={})=>{const a=await e.get(i.start,{queryParams:Object.assign({provider:s},t&&{redirectURL:t})});if(!n||!a.ok)return j(Promise.resolve(a));const{url:r}=await a.json();window.location.href=r}})),{})},ie(e)),ce=S(T("flowId")),ue=S(T("executionId"),T("stepId"),T("interactionId")),pe=e=>({start:ce((t=>j(e.post(d.start,{flowId:t})))),next:ue(((t,s,n,a)=>j(e.post(d.next,{executionId:t,stepId:s,interactionId:n,input:a}))))}),de=S(T("tenant")),ge=e=>Object.assign({start:de((async(t,s,{redirect:n=!1}={})=>{const a=await e.get(r.start,{queryParams:{tenant:t,redirectURL:s}});if(!n||!a.ok)return j(Promise.resolve(a));const{url:i}=await a.json();window.location.href=i}))},ie(e)),le=T("identifier"),he=S(le,T("code")),me=S(le),ve=S(le),be=e=>({signUp:me(((t,s)=>j(e.post(o.signUp,{externalId:t,user:s})))),verify:he(((t,s)=>j(e.post(o.verify,{externalId:t,code:s})))),update:ve(((t,s)=>j(e.post(o.update,{externalId:t},{token:s}))))}),fe=T("identifier"),ye=T("origin"),Ie=S(fe,ye,T("name")),ke=S(fe,ye),je=S(fe,ye,T("token")),Oe=S(T("transactionId"),T("response")),Ue=e=>({signUp:{start:Ie(((t,s,n)=>j(e.post(c.signUp.start,{user:{externalId:t,name:n},origin:s})))),finish:Oe(((t,s)=>j(e.post(c.signUp.finish,{transactionId:t,response:s}))))},signIn:{start:ke(((t,s)=>j(e.post(c.signIn.start,{externalId:t,origin:s})))),finish:Oe(((t,s)=>j(e.post(c.signIn.finish,{transactionId:t,response:s}))))},update:{start:je(((t,s,n)=>j(e.post(c.update.start,{externalId:t,origin:s},{token:n})))),finish:Oe(((t,s)=>j(e.post(c.update.finish,{transactionId:t,response:s}))))}}),we=S(T("token"));var xe,Pe;const Re=S([(xe="projectId",Pe=T("projectId"),O(((e,s)=>n=>U(...s).validate(t(n,e)))(xe,Pe))())])((({projectId:e,logger:t,baseUrl:s,hooks:n,cookiePolicy:a})=>{return i=y({baseUrl:s||"https://api.descope.com",projectId:e,logger:t,hooks:n,cookiePolicy:a}),{accessKey:L(i),otp:_(i),magicLink:ne(i),oauth:oe(i),saml:ge(i),totp:be(i),webauthn:Ue(i),flow:pe(i),refresh:e=>j(i.get(u,{token:e})),logout:e=>j(i.get(p,{token:e})),isJwtExpired:we(I),httpClient:i};var i}));Re.DeliveryMethods=J;export{Re as default};
|
|
1
|
+
import e from"jwt-decode";import t from"lodash.get";var s={exchange:"/v1/auth/accesskey/exchange"},n={verify:"/v1/auth/otp/verify",signIn:"/v1/auth/otp/signin",signUp:"/v1/auth/otp/signup",update:{email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},signUpOrIn:"/v1/auth/otp/signup-in"},a={verify:"/v1/auth/magiclink/verify",signIn:"/v1/auth/magiclink/signin",signUp:"/v1/auth/magiclink/signup",session:"/v1/auth/magiclink/pending-session",update:{email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/email"},signUpOrIn:"/v1/auth/magiclink/signup-in"},i={start:"/v1/auth/oauth/authorize"},r={start:"/v1/auth/saml/authorize"},o={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/user/totp/update"},c={signUp:{start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},signIn:{start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},update:{start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"}},u="/v1/auth/refresh",p="/v1/auth/logoutall",d="/v1/auth/me",g={start:"/v1/flow/start",next:"/v1/flow/next"},l="/v1/auth/exchange";var h;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(h||(h={}));const m=()=>{const e={};return{headers(t){const s="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(s),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}},v=(e,t)=>{const s=t||fetch;if(!s)throw new Error("fetch is not defined");return e?async(...t)=>{e.log((e=>m().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const n=await s(...t);return e[n.ok?"log":"error"](await(async e=>{const t=await e.text();return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),m().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(n)),n}:s},b=(...e)=>new Headers(e.reduce(((e,t)=>{const s=(e=>Array.isArray(e)?e:e instanceof Headers?Array.from(e.entries()):e?Object.entries(e):[])(t);return s.reduce(((t,[s,n])=>(e[s]=n,e)),e),e}),{})),f=e=>void 0===e?void 0:JSON.stringify(e),y=(e,t="")=>{let s=e;return""!==t&&(s=s+":"+t),{Authorization:`Bearer ${s}`}},I=({baseUrl:e,projectId:t,baseConfig:s,logger:n,hooks:a,cookiePolicy:i})=>{const r=v(n),o=async n=>{const o=(null==a?void 0:a.beforeRequest)?a.beforeRequest(n):n,{path:c,body:u,headers:p,queryParams:d,method:g,token:l}=o,h=await r((({path:e,baseUrl:t,queryParams:s})=>{const n=new URL(e,t);return s&&(n.search=new URLSearchParams(s).toString()),n})({path:c,baseUrl:e,queryParams:d}),{headers:b(y(t,l),(null==s?void 0:s.baseHeaders)||{},p),method:g,body:f(u),credentials:i||"include"});return(null==a?void 0:a.afterRequest)&&a.afterRequest(n,null==h?void 0:h.clone()),h};return{get:(e,{headers:t,queryParams:s,token:n}={})=>o({path:e,headers:t,queryParams:s,body:void 0,method:h.get,token:n}),post:(e,t,{headers:s,queryParams:n,token:a}={})=>o({path:e,headers:s,queryParams:n,body:t,method:h.post,token:a}),put:(e,t,{headers:s,queryParams:n,token:a}={})=>o({path:e,headers:s,queryParams:n,body:t,method:h.put,token:a}),delete:(e,t,{headers:s,queryParams:n,token:a}={})=>o({path:e,headers:s,queryParams:n,body:t,method:h.delete,token:a})}},k=t=>{if("string"!=typeof t||!t)throw new Error("Invalid token provided");const{exp:s}=e(t);return(new Date).getTime()/1e3>s},j=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function O(e){const t=await e,s={code:t.status,ok:t.ok,response:t},n=await t.json();return t.ok?s.data=n:s.error=n,s}const U=(e,t)=>(s=t)=>t=>!e(t)&&s.replace("{val}",t),w=(...e)=>({validate:t=>(e.forEach((e=>{const s=e(t);if(s)throw new Error(s)})),!0)}),x=e=>t=>e.test(t),P=x(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),R=x(/^\+[1-9]{1}[0-9]{3,14}$/),q=U(P,'"{val}" is not a valid email'),$=U(R,'"{val}" is not a valid phone number'),M=U((E=1,e=>e.length>=E),"Minimum length is 1");var E;const S=U((e=>"string"==typeof e),"Input is not a string"),T=(...e)=>t=>(...s)=>(e.forEach(((e,t)=>w(...e).validate(s[t]))),t(...s)),D=e=>[S(`"${e}" must be a string`),M(`"${e}" must not be empty`)],A=e=>[S(`"${e}" must be a string`),q()],z=e=>[S(`"${e}" must be a string`),$()],L=T(D("accessKey")),H=e=>({exchange:L((t=>O(e.get(s.exchange,{token:t}))))});var J,N,Z,B;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(J||(J={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(N||(N={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(Z||(Z={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(B||(B={}));const C=D("identifier"),K=T(C,D("code")),F=T(C),G=T(C,z("phone")),_=T(C,A("email")),Q=e=>({verify:Object.keys(N).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:K(((t,a)=>O(e.post(j(n.verify,s),{code:a,externalId:t}))))})),{}),signIn:Object.keys(N).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:F((t=>O(e.post(j(n.signIn,s),{externalId:t}))))})),{}),signUp:Object.keys(N).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:F(((t,a)=>O(e.post(j(n.signUp,s),{externalId:t,user:a}))))})),{}),signUpOrIn:Object.keys(N).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:F((t=>O(e.post(j(n.signUpOrIn,s),{externalId:t}))))})),{}),update:{email:_(((t,s,a)=>O(e.post(n.update.email,{externalId:t,email:s},{token:a})))),phone:Object.keys(J).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:G(((t,a,i)=>O(e.post(j(n.update.phone,s),{externalId:t,phone:a},{token:i}))))})),{})}}),V=D("identifier"),W=D("uri"),X=T(D("token")),Y=T(V,W),ee=T(D("pendingRef")),te=T(V,z("phone"),W),se=T(V,A("email"),W),ne=e=>({verify:X((t=>O(e.post(a.verify,{token:t})))),signIn:Object.keys(N).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Y(((t,n)=>O(e.post(j(a.signIn,s),{externalId:t,URI:n,crossDevice:!0}))))})),{}),signUpOrIn:Object.keys(N).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Y(((t,n)=>O(e.post(j(a.signUpOrIn,s),{externalId:t,URI:n,crossDevice:!0}))))})),{}),signUp:Object.keys(N).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Y(((t,n,i)=>O(e.post(j(a.signUp,s),{externalId:t,URI:n,user:i,crossDevice:!0}))))})),{}),waitForSession:ee(((t,s)=>new Promise((n=>{const{pollingIntervalMs:i,timeoutMs:r}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||6e5,6e5)}))(s);let o;const c=setInterval((async()=>{const s=await e.post(a.session,{pendingRef:t});s.ok&&(clearInterval(c),o&&clearTimeout(o),n(O(Promise.resolve(s))))}),i);o=setTimeout((()=>{n({error:{message:`Session polling timeout exceeded: ${r}ms`,code:"0"},ok:!1}),clearInterval(c)}),r)})))),update:{email:se(((t,s,n,i)=>O(e.post(a.update.email,{externalId:t,email:s,URI:n,crossDevice:!0},{token:i})))),phone:Object.keys(J).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:te(((t,n,i,r)=>O(e.post(j(a.update.phone,s),{externalId:t,phone:n,URI:i,crossDevice:!0},{token:r}))))})),{})}}),ae=e=>({verify:X((t=>O(e.post(a.verify,{token:t})))),signIn:Object.keys(N).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Y(((t,n)=>O(e.post(j(a.signIn,s),{externalId:t,URI:n}))))})),{}),signUp:Object.keys(N).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Y(((t,n,i)=>O(e.post(j(a.signUp,s),{externalId:t,URI:n,user:i}))))})),{}),signUpOrIn:Object.keys(N).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Y(((t,n)=>O(e.post(j(a.signUpOrIn,s),{externalId:t,URI:n}))))})),{}),update:{email:se(((t,s,n,i)=>O(e.post(a.update.email,{externalId:t,email:s,URI:n},{token:i})))),phone:Object.keys(J).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:te(((t,n,i,r)=>O(e.post(j(a.update.phone,s),{externalId:t,phone:n,URI:i},{token:r}))))})),{})},crossDevice:ne(e)}),ie=T(D("code")),re=e=>({exchange:ie((t=>O(e.get(l,{queryParams:{code:t}}))))});var oe;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple"}(oe||(oe={}));const ce=e=>Object.assign({start:Object.keys(oe).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:async(t,{redirect:n=!1}={})=>{const a=await e.get(i.start,{queryParams:Object.assign({provider:s},t&&{redirectURL:t})});if(!n||!a.ok)return O(Promise.resolve(a));const{url:r}=await a.json();window.location.href=r}})),{})},re(e)),ue=T(D("flowId")),pe=T(D("executionId"),D("stepId"),D("interactionId")),de=e=>({start:ue((t=>O(e.post(g.start,{flowId:t})))),next:pe(((t,s,n,a)=>O(e.post(g.next,{executionId:t,stepId:s,interactionId:n,input:a}))))}),ge=T(D("tenant")),le=e=>Object.assign({start:ge((async(t,s,{redirect:n=!1}={})=>{const a=await e.get(r.start,{queryParams:{tenant:t,redirectURL:s}});if(!n||!a.ok)return O(Promise.resolve(a));const{url:i}=await a.json();window.location.href=i}))},re(e)),he=D("identifier"),me=T(he,D("code")),ve=T(he),be=T(he),fe=e=>({signUp:ve(((t,s)=>O(e.post(o.signUp,{externalId:t,user:s})))),verify:me(((t,s)=>O(e.post(o.verify,{externalId:t,code:s})))),update:be(((t,s)=>O(e.post(o.update,{externalId:t},{token:s}))))}),ye=D("identifier"),Ie=D("origin"),ke=T(ye,Ie,D("name")),je=T(ye,Ie),Oe=T(ye,Ie,D("token")),Ue=T(D("transactionId"),D("response")),we=e=>({signUp:{start:ke(((t,s,n)=>O(e.post(c.signUp.start,{user:{externalId:t,name:n},origin:s})))),finish:Ue(((t,s)=>O(e.post(c.signUp.finish,{transactionId:t,response:s}))))},signIn:{start:je(((t,s)=>O(e.post(c.signIn.start,{externalId:t,origin:s})))),finish:Ue(((t,s)=>O(e.post(c.signIn.finish,{transactionId:t,response:s}))))},update:{start:Oe(((t,s,n)=>O(e.post(c.update.start,{externalId:t,origin:s},{token:n})))),finish:Ue(((t,s)=>O(e.post(c.update.finish,{transactionId:t,response:s}))))}}),xe=T(D("token"));var Pe,Re;const qe=T([(Pe="projectId",Re=D("projectId"),U(((e,s)=>n=>w(...s).validate(t(n,e)))(Pe,Re))())])((({projectId:e,logger:t,baseUrl:s,hooks:n,cookiePolicy:a})=>{return i=I({baseUrl:s||"https://api.descope.com",projectId:e,logger:t,hooks:n,cookiePolicy:a}),{accessKey:H(i),otp:Q(i),magicLink:ae(i),oauth:ce(i),saml:le(i),totp:fe(i),webauthn:we(i),flow:de(i),refresh:e=>O(i.get(u,{token:e})),logout:e=>O(i.get(p,{token:e})),me:e=>O(i.get(d,{token:e})),isJwtExpired:xe(k),httpClient:i};var i}));qe.DeliveryMethods=N;export{qe as default};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|