@nhost/nhost-js 3.2.8 → 5.0.0-beta.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/README.md +73 -37
- package/dist/nhost-js/auth.cjs.js +2 -0
- package/dist/nhost-js/auth.cjs.js.map +1 -0
- package/dist/nhost-js/auth.es.js +589 -0
- package/dist/nhost-js/auth.es.js.map +1 -0
- package/dist/nhost-js/fetch.cjs.js +2 -0
- package/dist/nhost-js/fetch.cjs.js.map +1 -0
- package/dist/nhost-js/fetch.es.js +10 -0
- package/dist/nhost-js/fetch.es.js.map +1 -0
- package/dist/nhost-js/functions.cjs.js +2 -0
- package/dist/nhost-js/functions.cjs.js.map +1 -0
- package/dist/nhost-js/functions.es.js +31 -0
- package/dist/nhost-js/functions.es.js.map +1 -0
- package/dist/nhost-js/graphql.cjs.js +2 -0
- package/dist/nhost-js/graphql.cjs.js.map +1 -0
- package/dist/nhost-js/graphql.es.js +35 -0
- package/dist/nhost-js/graphql.es.js.map +1 -0
- package/dist/nhost-js/storage.cjs.js +2 -0
- package/dist/nhost-js/storage.cjs.js.map +1 -0
- package/dist/nhost-js/storage.es.js +205 -0
- package/dist/nhost-js/storage.es.js.map +1 -0
- package/dist/nhost-js.cjs.js +2 -0
- package/dist/nhost-js.cjs.js.map +1 -0
- package/dist/nhost-js.es.js +497 -0
- package/dist/nhost-js.es.js.map +1 -0
- package/dist/nhost-js.umd.js +2 -0
- package/dist/nhost-js.umd.js.map +1 -0
- package/dist/src/auth/client.d.ts +430 -0
- package/dist/src/auth/client.d.ts.map +1 -0
- package/dist/src/auth/client.js +727 -0
- package/dist/src/auth/client.js.map +1 -0
- package/dist/src/auth/index.d.ts +11 -0
- package/dist/src/auth/index.d.ts.map +1 -0
- package/dist/src/auth/index.js +11 -0
- package/dist/src/auth/index.js.map +1 -0
- package/dist/src/auth/interface.d.ts +142 -0
- package/dist/src/auth/interface.d.ts.map +1 -0
- package/dist/src/auth/interface.js +2 -0
- package/dist/src/auth/interface.js.map +1 -0
- package/dist/src/fetch/index.d.ts +53 -0
- package/dist/src/fetch/index.d.ts.map +1 -0
- package/dist/src/fetch/index.js +40 -0
- package/dist/src/fetch/index.js.map +1 -0
- package/dist/src/functions/client.d.ts +47 -0
- package/dist/src/functions/client.d.ts.map +1 -0
- package/dist/src/functions/client.js +62 -0
- package/dist/src/functions/client.js.map +1 -0
- package/dist/src/functions/index.d.ts +10 -0
- package/dist/src/functions/index.d.ts.map +1 -0
- package/dist/src/functions/index.js +10 -0
- package/dist/src/functions/index.js.map +1 -0
- package/dist/src/graphql/client.d.ts +89 -0
- package/dist/src/graphql/client.d.ts.map +1 -0
- package/dist/src/graphql/client.js +49 -0
- package/dist/src/graphql/client.js.map +1 -0
- package/dist/src/graphql/index.d.ts +10 -0
- package/dist/src/graphql/index.d.ts.map +1 -0
- package/dist/src/graphql/index.js +10 -0
- package/dist/src/graphql/index.js.map +1 -0
- package/dist/src/index.d.ts +184 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +251 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/middlewareAttachToken.d.ts +24 -0
- package/dist/src/middlewareAttachToken.d.ts.map +1 -0
- package/dist/src/middlewareAttachToken.js +60 -0
- package/dist/src/middlewareAttachToken.js.map +1 -0
- package/dist/src/middlewareRefreshSession.d.ts +43 -0
- package/dist/src/middlewareRefreshSession.d.ts.map +1 -0
- package/dist/src/middlewareRefreshSession.js +190 -0
- package/dist/src/middlewareRefreshSession.js.map +1 -0
- package/dist/src/middlewareResponseSession.d.ts +26 -0
- package/dist/src/middlewareResponseSession.d.ts.map +1 -0
- package/dist/src/middlewareResponseSession.js +83 -0
- package/dist/src/middlewareResponseSession.js.map +1 -0
- package/dist/src/sessionStorage.d.ts +123 -0
- package/dist/src/sessionStorage.d.ts.map +1 -0
- package/dist/src/sessionStorage.js +165 -0
- package/dist/src/sessionStorage.js.map +1 -0
- package/dist/src/storage/client.d.ts +184 -0
- package/dist/src/storage/client.d.ts.map +1 -0
- package/dist/src/storage/client.js +249 -0
- package/dist/src/storage/client.js.map +1 -0
- package/dist/src/storage/index.d.ts +11 -0
- package/dist/src/storage/index.d.ts.map +1 -0
- package/dist/src/storage/index.js +11 -0
- package/dist/src/storage/index.js.map +1 -0
- package/dist/src/storage/interface.d.ts +52 -0
- package/dist/src/storage/interface.d.ts.map +1 -0
- package/dist/src/storage/interface.js +2 -0
- package/dist/src/storage/interface.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +109 -63
- package/LICENSE +0 -21
- package/dist/clients/auth.d.ts +0 -8
- package/dist/clients/auth.d.ts.map +0 -1
- package/dist/clients/functions/index.d.ts +0 -107
- package/dist/clients/functions/index.d.ts.map +0 -1
- package/dist/clients/functions/types.d.ts +0 -28
- package/dist/clients/functions/types.d.ts.map +0 -1
- package/dist/clients/graphql.d.ts +0 -8
- package/dist/clients/graphql.d.ts.map +0 -1
- package/dist/clients/index.d.ts +0 -6
- package/dist/clients/index.d.ts.map +0 -1
- package/dist/clients/nhost.d.ts +0 -83
- package/dist/clients/nhost.d.ts.map +0 -1
- package/dist/clients/storage.d.ts +0 -8
- package/dist/clients/storage.d.ts.map +0 -1
- package/dist/index.cjs.js +0 -2
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/index.esm.js +0 -344
- package/dist/index.esm.js.map +0 -1
- package/dist/utils/helpers.d.ts +0 -20
- package/dist/utils/helpers.d.ts.map +0 -1
- package/dist/utils/types.d.ts +0 -57
- package/dist/utils/types.d.ts.map +0 -1
- package/umd/nhost-js.umd.js +0 -22
- package/umd/nhost-js.umd.js.map +0 -1
|
@@ -0,0 +1,727 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v7.9.0 🍺
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Nhost Authentication API
|
|
5
|
+
* Comprehensive authentication service for managing user identities, sessions, and authentication methods
|
|
6
|
+
* OpenAPI spec version: 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
import { createEnhancedFetch } from "../fetch";
|
|
9
|
+
export const createAPIClient = (baseURL, chainFunctions = []) => {
|
|
10
|
+
let fetch = createEnhancedFetch(chainFunctions);
|
|
11
|
+
const pushChainFunction = (chainFunction) => {
|
|
12
|
+
chainFunctions.push(chainFunction);
|
|
13
|
+
fetch = createEnhancedFetch(chainFunctions);
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Verify if the authentication service is operational using HEAD method
|
|
17
|
+
* @summary Health check (HEAD)
|
|
18
|
+
*/
|
|
19
|
+
const healthCheckHead = async (options) => {
|
|
20
|
+
const res = await fetch(getHealthCheckHeadUrl(), {
|
|
21
|
+
...options,
|
|
22
|
+
method: "HEAD",
|
|
23
|
+
});
|
|
24
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
25
|
+
? null
|
|
26
|
+
: await res.text();
|
|
27
|
+
const payload = body ? JSON.parse(body) : {};
|
|
28
|
+
const response = {
|
|
29
|
+
body: payload,
|
|
30
|
+
status: res.status,
|
|
31
|
+
headers: res.headers,
|
|
32
|
+
};
|
|
33
|
+
if (!res.ok) {
|
|
34
|
+
throw response;
|
|
35
|
+
}
|
|
36
|
+
return response;
|
|
37
|
+
};
|
|
38
|
+
const getHealthCheckHeadUrl = () => {
|
|
39
|
+
return baseURL + `/healthz`;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Verify if the authentication service is operational using GET method
|
|
43
|
+
* @summary Health check (GET)
|
|
44
|
+
*/
|
|
45
|
+
const healthCheckGet = async (options) => {
|
|
46
|
+
const res = await fetch(getHealthCheckGetUrl(), {
|
|
47
|
+
...options,
|
|
48
|
+
method: "GET",
|
|
49
|
+
});
|
|
50
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
51
|
+
? null
|
|
52
|
+
: await res.text();
|
|
53
|
+
const payload = body ? JSON.parse(body) : {};
|
|
54
|
+
const response = {
|
|
55
|
+
body: payload,
|
|
56
|
+
status: res.status,
|
|
57
|
+
headers: res.headers,
|
|
58
|
+
};
|
|
59
|
+
if (!res.ok) {
|
|
60
|
+
throw response;
|
|
61
|
+
}
|
|
62
|
+
return response;
|
|
63
|
+
};
|
|
64
|
+
const getHealthCheckGetUrl = () => {
|
|
65
|
+
return baseURL + `/healthz`;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Retrieve version information about the authentication service
|
|
69
|
+
* @summary Get service version
|
|
70
|
+
*/
|
|
71
|
+
const getVersion = async (options) => {
|
|
72
|
+
const res = await fetch(getGetVersionUrl(), {
|
|
73
|
+
...options,
|
|
74
|
+
method: "GET",
|
|
75
|
+
});
|
|
76
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
77
|
+
? null
|
|
78
|
+
: await res.text();
|
|
79
|
+
const payload = body ? JSON.parse(body) : {};
|
|
80
|
+
const response = {
|
|
81
|
+
body: payload,
|
|
82
|
+
status: res.status,
|
|
83
|
+
headers: res.headers,
|
|
84
|
+
};
|
|
85
|
+
if (!res.ok) {
|
|
86
|
+
throw response;
|
|
87
|
+
}
|
|
88
|
+
return response;
|
|
89
|
+
};
|
|
90
|
+
const getGetVersionUrl = () => {
|
|
91
|
+
return baseURL + `/version`;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Generate a new JWT access token using a valid refresh token. The refresh token used will be revoked and a new one will be issued.
|
|
95
|
+
* @summary Refresh access token
|
|
96
|
+
*/
|
|
97
|
+
const refreshToken = async (refreshTokenRequest, options) => {
|
|
98
|
+
const res = await fetch(getRefreshTokenUrl(), {
|
|
99
|
+
...options,
|
|
100
|
+
method: "POST",
|
|
101
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
102
|
+
body: JSON.stringify(refreshTokenRequest),
|
|
103
|
+
});
|
|
104
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
105
|
+
? null
|
|
106
|
+
: await res.text();
|
|
107
|
+
const payload = body ? JSON.parse(body) : {};
|
|
108
|
+
const response = {
|
|
109
|
+
body: payload,
|
|
110
|
+
status: res.status,
|
|
111
|
+
headers: res.headers,
|
|
112
|
+
};
|
|
113
|
+
if (!res.ok) {
|
|
114
|
+
throw response;
|
|
115
|
+
}
|
|
116
|
+
return response;
|
|
117
|
+
};
|
|
118
|
+
const getRefreshTokenUrl = () => {
|
|
119
|
+
return baseURL + `/token`;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* @summary Sign out
|
|
123
|
+
*/
|
|
124
|
+
const signOut = async (signOutSchema, options) => {
|
|
125
|
+
const res = await fetch(getSignOutUrl(), {
|
|
126
|
+
...options,
|
|
127
|
+
method: "POST",
|
|
128
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
129
|
+
body: JSON.stringify(signOutSchema),
|
|
130
|
+
});
|
|
131
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
132
|
+
? null
|
|
133
|
+
: await res.text();
|
|
134
|
+
const payload = body ? JSON.parse(body) : {};
|
|
135
|
+
const response = {
|
|
136
|
+
body: payload,
|
|
137
|
+
status: res.status,
|
|
138
|
+
headers: res.headers,
|
|
139
|
+
};
|
|
140
|
+
if (!res.ok) {
|
|
141
|
+
throw response;
|
|
142
|
+
}
|
|
143
|
+
return response;
|
|
144
|
+
};
|
|
145
|
+
const getSignOutUrl = () => {
|
|
146
|
+
return baseURL + `/signout`;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Authenticate a user with their email and password. Returns a session object or MFA challenge if two-factor authentication is enabled.
|
|
150
|
+
* @summary Sign in with email and password
|
|
151
|
+
*/
|
|
152
|
+
const signInEmailPassword = async (signInEmailPasswordRequest, options) => {
|
|
153
|
+
const res = await fetch(getSignInEmailPasswordUrl(), {
|
|
154
|
+
...options,
|
|
155
|
+
method: "POST",
|
|
156
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
157
|
+
body: JSON.stringify(signInEmailPasswordRequest),
|
|
158
|
+
});
|
|
159
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
160
|
+
? null
|
|
161
|
+
: await res.text();
|
|
162
|
+
const payload = body ? JSON.parse(body) : {};
|
|
163
|
+
const response = {
|
|
164
|
+
body: payload,
|
|
165
|
+
status: res.status,
|
|
166
|
+
headers: res.headers,
|
|
167
|
+
};
|
|
168
|
+
if (!res.ok) {
|
|
169
|
+
throw response;
|
|
170
|
+
}
|
|
171
|
+
return response;
|
|
172
|
+
};
|
|
173
|
+
const getSignInEmailPasswordUrl = () => {
|
|
174
|
+
return baseURL + `/signin/email-password`;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Complete the multi-factor authentication by verifying a Time-based One-Time Password (TOTP). Returns a session if validation is successful.
|
|
178
|
+
* @summary Verify TOTP for MFA
|
|
179
|
+
*/
|
|
180
|
+
const signInVerifyMfaTotp = async (signInMfaTotpRequest, options) => {
|
|
181
|
+
const res = await fetch(getSignInVerifyMfaTotpUrl(), {
|
|
182
|
+
...options,
|
|
183
|
+
method: "POST",
|
|
184
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
185
|
+
body: JSON.stringify(signInMfaTotpRequest),
|
|
186
|
+
});
|
|
187
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
188
|
+
? null
|
|
189
|
+
: await res.text();
|
|
190
|
+
const payload = body ? JSON.parse(body) : {};
|
|
191
|
+
const response = {
|
|
192
|
+
body: payload,
|
|
193
|
+
status: res.status,
|
|
194
|
+
headers: res.headers,
|
|
195
|
+
};
|
|
196
|
+
if (!res.ok) {
|
|
197
|
+
throw response;
|
|
198
|
+
}
|
|
199
|
+
return response;
|
|
200
|
+
};
|
|
201
|
+
const getSignInVerifyMfaTotpUrl = () => {
|
|
202
|
+
return baseURL + `/signin/mfa/totp`;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Initiate passwordless authentication by sending a magic link to the user's email. If the user doesn't exist, a new account will be created with the provided options.
|
|
206
|
+
* @summary Sign in with magic link email
|
|
207
|
+
*/
|
|
208
|
+
const signInPasswordlessEmail = async (signInPasswordlessEmailRequest, options) => {
|
|
209
|
+
const res = await fetch(getSignInPasswordlessEmailUrl(), {
|
|
210
|
+
...options,
|
|
211
|
+
method: "POST",
|
|
212
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
213
|
+
body: JSON.stringify(signInPasswordlessEmailRequest),
|
|
214
|
+
});
|
|
215
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
216
|
+
? null
|
|
217
|
+
: await res.text();
|
|
218
|
+
const payload = body ? JSON.parse(body) : {};
|
|
219
|
+
const response = {
|
|
220
|
+
body: payload,
|
|
221
|
+
status: res.status,
|
|
222
|
+
headers: res.headers,
|
|
223
|
+
};
|
|
224
|
+
if (!res.ok) {
|
|
225
|
+
throw response;
|
|
226
|
+
}
|
|
227
|
+
return response;
|
|
228
|
+
};
|
|
229
|
+
const getSignInPasswordlessEmailUrl = () => {
|
|
230
|
+
return baseURL + `/signin/passwordless/email`;
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Register a new user account with email and password. Returns a session if email verification is not required, otherwise returns null session.
|
|
234
|
+
* @summary Sign up with email and password
|
|
235
|
+
*/
|
|
236
|
+
const signUpEmailPassword = async (signUpEmailPasswordRequest, options) => {
|
|
237
|
+
const res = await fetch(getSignUpEmailPasswordUrl(), {
|
|
238
|
+
...options,
|
|
239
|
+
method: "POST",
|
|
240
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
241
|
+
body: JSON.stringify(signUpEmailPasswordRequest),
|
|
242
|
+
});
|
|
243
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
244
|
+
? null
|
|
245
|
+
: await res.text();
|
|
246
|
+
const payload = body ? JSON.parse(body) : {};
|
|
247
|
+
const response = {
|
|
248
|
+
body: payload,
|
|
249
|
+
status: res.status,
|
|
250
|
+
headers: res.headers,
|
|
251
|
+
};
|
|
252
|
+
if (!res.ok) {
|
|
253
|
+
throw response;
|
|
254
|
+
}
|
|
255
|
+
return response;
|
|
256
|
+
};
|
|
257
|
+
const getSignUpEmailPasswordUrl = () => {
|
|
258
|
+
return baseURL + `/signup/email-password`;
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Activate or deactivate multi-factor authentication for the authenticated user
|
|
262
|
+
* @summary Manage multi-factor authentication
|
|
263
|
+
*/
|
|
264
|
+
const changeUserMfaVerify = async (userMfaRequest, options) => {
|
|
265
|
+
const res = await fetch(getChangeUserMfaVerifyUrl(), {
|
|
266
|
+
...options,
|
|
267
|
+
method: "POST",
|
|
268
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
269
|
+
body: JSON.stringify(userMfaRequest),
|
|
270
|
+
});
|
|
271
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
272
|
+
? null
|
|
273
|
+
: await res.text();
|
|
274
|
+
const payload = body ? JSON.parse(body) : {};
|
|
275
|
+
const response = {
|
|
276
|
+
body: payload,
|
|
277
|
+
status: res.status,
|
|
278
|
+
headers: res.headers,
|
|
279
|
+
};
|
|
280
|
+
if (!res.ok) {
|
|
281
|
+
throw response;
|
|
282
|
+
}
|
|
283
|
+
return response;
|
|
284
|
+
};
|
|
285
|
+
const getChangeUserMfaVerifyUrl = () => {
|
|
286
|
+
return baseURL + `/user/mfa`;
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Generate a Time-based One-Time Password (TOTP) secret for setting up multi-factor authentication
|
|
290
|
+
* @summary Generate TOTP secret
|
|
291
|
+
*/
|
|
292
|
+
const changeUserMfa = async (options) => {
|
|
293
|
+
const res = await fetch(getChangeUserMfaUrl(), {
|
|
294
|
+
...options,
|
|
295
|
+
method: "GET",
|
|
296
|
+
});
|
|
297
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
298
|
+
? null
|
|
299
|
+
: await res.text();
|
|
300
|
+
const payload = body ? JSON.parse(body) : {};
|
|
301
|
+
const response = {
|
|
302
|
+
body: payload,
|
|
303
|
+
status: res.status,
|
|
304
|
+
headers: res.headers,
|
|
305
|
+
};
|
|
306
|
+
if (!res.ok) {
|
|
307
|
+
throw response;
|
|
308
|
+
}
|
|
309
|
+
return response;
|
|
310
|
+
};
|
|
311
|
+
const getChangeUserMfaUrl = () => {
|
|
312
|
+
return baseURL + `/mfa/totp/generate`;
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* @summary Get public keys for JWT verification in JWK Set format
|
|
316
|
+
*/
|
|
317
|
+
const getJWKs = async (options) => {
|
|
318
|
+
const res = await fetch(getGetJWKsUrl(), {
|
|
319
|
+
...options,
|
|
320
|
+
method: "GET",
|
|
321
|
+
});
|
|
322
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
323
|
+
? null
|
|
324
|
+
: await res.text();
|
|
325
|
+
const payload = body ? JSON.parse(body) : {};
|
|
326
|
+
const response = {
|
|
327
|
+
body: payload,
|
|
328
|
+
status: res.status,
|
|
329
|
+
headers: res.headers,
|
|
330
|
+
};
|
|
331
|
+
if (!res.ok) {
|
|
332
|
+
throw response;
|
|
333
|
+
}
|
|
334
|
+
return response;
|
|
335
|
+
};
|
|
336
|
+
const getGetJWKsUrl = () => {
|
|
337
|
+
return baseURL + `/.well-known/jwks.json`;
|
|
338
|
+
};
|
|
339
|
+
/**
|
|
340
|
+
* @summary Create a Personal Access Token (PAT)
|
|
341
|
+
*/
|
|
342
|
+
const createPAT = async (createPATRequest, options) => {
|
|
343
|
+
const res = await fetch(getCreatePATUrl(), {
|
|
344
|
+
...options,
|
|
345
|
+
method: "POST",
|
|
346
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
347
|
+
body: JSON.stringify(createPATRequest),
|
|
348
|
+
});
|
|
349
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
350
|
+
? null
|
|
351
|
+
: await res.text();
|
|
352
|
+
const payload = body ? JSON.parse(body) : {};
|
|
353
|
+
const response = {
|
|
354
|
+
body: payload,
|
|
355
|
+
status: res.status,
|
|
356
|
+
headers: res.headers,
|
|
357
|
+
};
|
|
358
|
+
if (!res.ok) {
|
|
359
|
+
throw response;
|
|
360
|
+
}
|
|
361
|
+
return response;
|
|
362
|
+
};
|
|
363
|
+
const getCreatePATUrl = () => {
|
|
364
|
+
return baseURL + `/pat`;
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* @summary Sign in anonymously
|
|
368
|
+
*/
|
|
369
|
+
const signInAnonymous = async (signinAnonymousRequest, options) => {
|
|
370
|
+
const res = await fetch(getSignInAnonymousUrl(), {
|
|
371
|
+
...options,
|
|
372
|
+
method: "POST",
|
|
373
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
374
|
+
body: JSON.stringify(signinAnonymousRequest),
|
|
375
|
+
});
|
|
376
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
377
|
+
? null
|
|
378
|
+
: await res.text();
|
|
379
|
+
const payload = body ? JSON.parse(body) : {};
|
|
380
|
+
const response = {
|
|
381
|
+
body: payload,
|
|
382
|
+
status: res.status,
|
|
383
|
+
headers: res.headers,
|
|
384
|
+
};
|
|
385
|
+
if (!res.ok) {
|
|
386
|
+
throw response;
|
|
387
|
+
}
|
|
388
|
+
return response;
|
|
389
|
+
};
|
|
390
|
+
const getSignInAnonymousUrl = () => {
|
|
391
|
+
return baseURL + `/signin/anonymous`;
|
|
392
|
+
};
|
|
393
|
+
/**
|
|
394
|
+
* @summary Sign in with a one time password sent to user's email. If the user doesn't exist, it will be created. The options object is optional and can be used to configure the user's when signing up a new user. It is ignored if the user already exists.
|
|
395
|
+
*/
|
|
396
|
+
const signInOTPEmail = async (signInOTPEmailRequest, options) => {
|
|
397
|
+
const res = await fetch(getSignInOTPEmailUrl(), {
|
|
398
|
+
...options,
|
|
399
|
+
method: "POST",
|
|
400
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
401
|
+
body: JSON.stringify(signInOTPEmailRequest),
|
|
402
|
+
});
|
|
403
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
404
|
+
? null
|
|
405
|
+
: await res.text();
|
|
406
|
+
const payload = body ? JSON.parse(body) : {};
|
|
407
|
+
const response = {
|
|
408
|
+
body: payload,
|
|
409
|
+
status: res.status,
|
|
410
|
+
headers: res.headers,
|
|
411
|
+
};
|
|
412
|
+
if (!res.ok) {
|
|
413
|
+
throw response;
|
|
414
|
+
}
|
|
415
|
+
return response;
|
|
416
|
+
};
|
|
417
|
+
const getSignInOTPEmailUrl = () => {
|
|
418
|
+
return baseURL + `/signin/otp/email`;
|
|
419
|
+
};
|
|
420
|
+
/**
|
|
421
|
+
* @summary Verify OTP and return a session if validation is successful
|
|
422
|
+
*/
|
|
423
|
+
const verifySignInOTPEmail = async (signInOTPEmailVerifyRequest, options) => {
|
|
424
|
+
const res = await fetch(getVerifySignInOTPEmailUrl(), {
|
|
425
|
+
...options,
|
|
426
|
+
method: "POST",
|
|
427
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
428
|
+
body: JSON.stringify(signInOTPEmailVerifyRequest),
|
|
429
|
+
});
|
|
430
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
431
|
+
? null
|
|
432
|
+
: await res.text();
|
|
433
|
+
const payload = body ? JSON.parse(body) : {};
|
|
434
|
+
const response = {
|
|
435
|
+
body: payload,
|
|
436
|
+
status: res.status,
|
|
437
|
+
headers: res.headers,
|
|
438
|
+
};
|
|
439
|
+
if (!res.ok) {
|
|
440
|
+
throw response;
|
|
441
|
+
}
|
|
442
|
+
return response;
|
|
443
|
+
};
|
|
444
|
+
const getVerifySignInOTPEmailUrl = () => {
|
|
445
|
+
return baseURL + `/signin/otp/email/verify`;
|
|
446
|
+
};
|
|
447
|
+
/**
|
|
448
|
+
* @summary Sign in with Personal Access Token (PAT)
|
|
449
|
+
*/
|
|
450
|
+
const signInPAT = async (signInPATRequest, options) => {
|
|
451
|
+
const res = await fetch(getSignInPATUrl(), {
|
|
452
|
+
...options,
|
|
453
|
+
method: "POST",
|
|
454
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
455
|
+
body: JSON.stringify(signInPATRequest),
|
|
456
|
+
});
|
|
457
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
458
|
+
? null
|
|
459
|
+
: await res.text();
|
|
460
|
+
const payload = body ? JSON.parse(body) : {};
|
|
461
|
+
const response = {
|
|
462
|
+
body: payload,
|
|
463
|
+
status: res.status,
|
|
464
|
+
headers: res.headers,
|
|
465
|
+
};
|
|
466
|
+
if (!res.ok) {
|
|
467
|
+
throw response;
|
|
468
|
+
}
|
|
469
|
+
return response;
|
|
470
|
+
};
|
|
471
|
+
const getSignInPATUrl = () => {
|
|
472
|
+
return baseURL + `/signin/pat`;
|
|
473
|
+
};
|
|
474
|
+
/**
|
|
475
|
+
* @summary Sign in with in an id token
|
|
476
|
+
*/
|
|
477
|
+
const signInIdToken = async (signInIdTokenRequest, options) => {
|
|
478
|
+
const res = await fetch(getSignInIdTokenUrl(), {
|
|
479
|
+
...options,
|
|
480
|
+
method: "POST",
|
|
481
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
482
|
+
body: JSON.stringify(signInIdTokenRequest),
|
|
483
|
+
});
|
|
484
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
485
|
+
? null
|
|
486
|
+
: await res.text();
|
|
487
|
+
const payload = body ? JSON.parse(body) : {};
|
|
488
|
+
const response = {
|
|
489
|
+
body: payload,
|
|
490
|
+
status: res.status,
|
|
491
|
+
headers: res.headers,
|
|
492
|
+
};
|
|
493
|
+
if (!res.ok) {
|
|
494
|
+
throw response;
|
|
495
|
+
}
|
|
496
|
+
return response;
|
|
497
|
+
};
|
|
498
|
+
const getSignInIdTokenUrl = () => {
|
|
499
|
+
return baseURL + `/signin/idtoken`;
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* @summary Link a user account with the provider's account using an id token
|
|
503
|
+
*/
|
|
504
|
+
const linkIdToken = async (linkIdTokenRequest, options) => {
|
|
505
|
+
const res = await fetch(getLinkIdTokenUrl(), {
|
|
506
|
+
...options,
|
|
507
|
+
method: "POST",
|
|
508
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
509
|
+
body: JSON.stringify(linkIdTokenRequest),
|
|
510
|
+
});
|
|
511
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
512
|
+
? null
|
|
513
|
+
: await res.text();
|
|
514
|
+
const payload = body ? JSON.parse(body) : {};
|
|
515
|
+
const response = {
|
|
516
|
+
body: payload,
|
|
517
|
+
status: res.status,
|
|
518
|
+
headers: res.headers,
|
|
519
|
+
};
|
|
520
|
+
if (!res.ok) {
|
|
521
|
+
throw response;
|
|
522
|
+
}
|
|
523
|
+
return response;
|
|
524
|
+
};
|
|
525
|
+
const getLinkIdTokenUrl = () => {
|
|
526
|
+
return baseURL + `/link/idtoken`;
|
|
527
|
+
};
|
|
528
|
+
/**
|
|
529
|
+
* @summary Deanonymize an anonymous user in adding missing email or email+password, depending on the chosen authentication method. Will send a confirmation email if the server is configured to do so
|
|
530
|
+
*/
|
|
531
|
+
const deanonymizeUser = async (userDeanonymizeRequest, options) => {
|
|
532
|
+
const res = await fetch(getDeanonymizeUserUrl(), {
|
|
533
|
+
...options,
|
|
534
|
+
method: "POST",
|
|
535
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
536
|
+
body: JSON.stringify(userDeanonymizeRequest),
|
|
537
|
+
});
|
|
538
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
539
|
+
? null
|
|
540
|
+
: await res.text();
|
|
541
|
+
const payload = body ? JSON.parse(body) : {};
|
|
542
|
+
const response = {
|
|
543
|
+
body: payload,
|
|
544
|
+
status: res.status,
|
|
545
|
+
headers: res.headers,
|
|
546
|
+
};
|
|
547
|
+
if (!res.ok) {
|
|
548
|
+
throw response;
|
|
549
|
+
}
|
|
550
|
+
return response;
|
|
551
|
+
};
|
|
552
|
+
const getDeanonymizeUserUrl = () => {
|
|
553
|
+
return baseURL + `/user/deanonymize`;
|
|
554
|
+
};
|
|
555
|
+
/**
|
|
556
|
+
* @summary Change user email
|
|
557
|
+
*/
|
|
558
|
+
const changeUserEmail = async (userEmailChangeRequest, options) => {
|
|
559
|
+
const res = await fetch(getChangeUserEmailUrl(), {
|
|
560
|
+
...options,
|
|
561
|
+
method: "POST",
|
|
562
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
563
|
+
body: JSON.stringify(userEmailChangeRequest),
|
|
564
|
+
});
|
|
565
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
566
|
+
? null
|
|
567
|
+
: await res.text();
|
|
568
|
+
const payload = body ? JSON.parse(body) : {};
|
|
569
|
+
const response = {
|
|
570
|
+
body: payload,
|
|
571
|
+
status: res.status,
|
|
572
|
+
headers: res.headers,
|
|
573
|
+
};
|
|
574
|
+
if (!res.ok) {
|
|
575
|
+
throw response;
|
|
576
|
+
}
|
|
577
|
+
return response;
|
|
578
|
+
};
|
|
579
|
+
const getChangeUserEmailUrl = () => {
|
|
580
|
+
return baseURL + `/user/email/change`;
|
|
581
|
+
};
|
|
582
|
+
/**
|
|
583
|
+
* @summary Send verification email
|
|
584
|
+
*/
|
|
585
|
+
const sendVerificationEmail = async (userEmailSendVerificationEmailRequest, options) => {
|
|
586
|
+
const res = await fetch(getSendVerificationEmailUrl(), {
|
|
587
|
+
...options,
|
|
588
|
+
method: "POST",
|
|
589
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
590
|
+
body: JSON.stringify(userEmailSendVerificationEmailRequest),
|
|
591
|
+
});
|
|
592
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
593
|
+
? null
|
|
594
|
+
: await res.text();
|
|
595
|
+
const payload = body ? JSON.parse(body) : {};
|
|
596
|
+
const response = {
|
|
597
|
+
body: payload,
|
|
598
|
+
status: res.status,
|
|
599
|
+
headers: res.headers,
|
|
600
|
+
};
|
|
601
|
+
if (!res.ok) {
|
|
602
|
+
throw response;
|
|
603
|
+
}
|
|
604
|
+
return response;
|
|
605
|
+
};
|
|
606
|
+
const getSendVerificationEmailUrl = () => {
|
|
607
|
+
return baseURL + `/user/email/send-verification-email`;
|
|
608
|
+
};
|
|
609
|
+
/**
|
|
610
|
+
* @summary Change user password. The user must be authenticated or provide a ticket
|
|
611
|
+
*/
|
|
612
|
+
const changeUserPassword = async (userPasswordRequest, options) => {
|
|
613
|
+
const res = await fetch(getChangeUserPasswordUrl(), {
|
|
614
|
+
...options,
|
|
615
|
+
method: "POST",
|
|
616
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
617
|
+
body: JSON.stringify(userPasswordRequest),
|
|
618
|
+
});
|
|
619
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
620
|
+
? null
|
|
621
|
+
: await res.text();
|
|
622
|
+
const payload = body ? JSON.parse(body) : {};
|
|
623
|
+
const response = {
|
|
624
|
+
body: payload,
|
|
625
|
+
status: res.status,
|
|
626
|
+
headers: res.headers,
|
|
627
|
+
};
|
|
628
|
+
if (!res.ok) {
|
|
629
|
+
throw response;
|
|
630
|
+
}
|
|
631
|
+
return response;
|
|
632
|
+
};
|
|
633
|
+
const getChangeUserPasswordUrl = () => {
|
|
634
|
+
return baseURL + `/user/password`;
|
|
635
|
+
};
|
|
636
|
+
/**
|
|
637
|
+
* @summary Request a password reset. An email with a verification link will be sent to the user's address
|
|
638
|
+
*/
|
|
639
|
+
const sendPasswordResetEmail = async (userPasswordResetRequest, options) => {
|
|
640
|
+
const res = await fetch(getSendPasswordResetEmailUrl(), {
|
|
641
|
+
...options,
|
|
642
|
+
method: "POST",
|
|
643
|
+
headers: { "Content-Type": "application/json", ...options?.headers },
|
|
644
|
+
body: JSON.stringify(userPasswordResetRequest),
|
|
645
|
+
});
|
|
646
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
647
|
+
? null
|
|
648
|
+
: await res.text();
|
|
649
|
+
const payload = body ? JSON.parse(body) : {};
|
|
650
|
+
const response = {
|
|
651
|
+
body: payload,
|
|
652
|
+
status: res.status,
|
|
653
|
+
headers: res.headers,
|
|
654
|
+
};
|
|
655
|
+
if (!res.ok) {
|
|
656
|
+
throw response;
|
|
657
|
+
}
|
|
658
|
+
return response;
|
|
659
|
+
};
|
|
660
|
+
const getSendPasswordResetEmailUrl = () => {
|
|
661
|
+
return baseURL + `/user/password/reset`;
|
|
662
|
+
};
|
|
663
|
+
/**
|
|
664
|
+
* @summary Verify tickets created by email verification, email passwordless authentication (magic link), or password reset
|
|
665
|
+
*/
|
|
666
|
+
const verifyTicket = async (params, options) => {
|
|
667
|
+
const res = await fetch(getVerifyTicketUrl(params), {
|
|
668
|
+
...options,
|
|
669
|
+
method: "GET",
|
|
670
|
+
});
|
|
671
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
672
|
+
? null
|
|
673
|
+
: await res.text();
|
|
674
|
+
const payload = body ? JSON.parse(body) : {};
|
|
675
|
+
const response = {
|
|
676
|
+
body: payload,
|
|
677
|
+
status: res.status,
|
|
678
|
+
headers: res.headers,
|
|
679
|
+
};
|
|
680
|
+
if (!res.ok) {
|
|
681
|
+
throw response;
|
|
682
|
+
}
|
|
683
|
+
return response;
|
|
684
|
+
};
|
|
685
|
+
const getVerifyTicketUrl = (params) => {
|
|
686
|
+
const normalizedParams = new URLSearchParams();
|
|
687
|
+
Object.entries(params || {}).forEach(([key, value]) => {
|
|
688
|
+
if (value !== undefined) {
|
|
689
|
+
normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
const stringifiedParams = normalizedParams.toString();
|
|
693
|
+
return stringifiedParams.length > 0
|
|
694
|
+
? baseURL + `/verify?${stringifiedParams}`
|
|
695
|
+
: baseURL + `/verify`;
|
|
696
|
+
};
|
|
697
|
+
return {
|
|
698
|
+
healthCheckHead,
|
|
699
|
+
healthCheckGet,
|
|
700
|
+
getVersion,
|
|
701
|
+
refreshToken,
|
|
702
|
+
signOut,
|
|
703
|
+
signInEmailPassword,
|
|
704
|
+
signInVerifyMfaTotp,
|
|
705
|
+
signInPasswordlessEmail,
|
|
706
|
+
signUpEmailPassword,
|
|
707
|
+
changeUserMfaVerify,
|
|
708
|
+
changeUserMfa,
|
|
709
|
+
getJWKs,
|
|
710
|
+
createPAT,
|
|
711
|
+
signInAnonymous,
|
|
712
|
+
signInOTPEmail,
|
|
713
|
+
verifySignInOTPEmail,
|
|
714
|
+
signInPAT,
|
|
715
|
+
signInIdToken,
|
|
716
|
+
linkIdToken,
|
|
717
|
+
deanonymizeUser,
|
|
718
|
+
changeUserEmail,
|
|
719
|
+
sendVerificationEmail,
|
|
720
|
+
changeUserPassword,
|
|
721
|
+
sendPasswordResetEmail,
|
|
722
|
+
verifyTicket,
|
|
723
|
+
pushChainFunction,
|
|
724
|
+
baseURL,
|
|
725
|
+
};
|
|
726
|
+
};
|
|
727
|
+
//# sourceMappingURL=client.js.map
|