@authorizerdev/authorizer-js 3.0.1 → 3.0.3
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/lib/authorizer.min.js +13 -13
- package/lib/index.d.mts +2 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +192 -63
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +192 -63
- package/lib/index.mjs.map +1 -1
- package/package.json +18 -17
package/lib/index.js
CHANGED
|
@@ -91,7 +91,9 @@ var createQueryParams = /* @__PURE__ */ __name((params) => {
|
|
|
91
91
|
return Object.keys(params).filter((k) => typeof params[k] !== "undefined").map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(params[k])}`).join("&");
|
|
92
92
|
}, "createQueryParams");
|
|
93
93
|
var sha256 = /* @__PURE__ */ __name(async (s) => {
|
|
94
|
-
const
|
|
94
|
+
const subtle = getCryptoSubtle();
|
|
95
|
+
if (!subtle) throw new Error("Web Crypto API is not available");
|
|
96
|
+
const digestOp = subtle.digest({
|
|
95
97
|
name: "SHA-256"
|
|
96
98
|
}, new TextEncoder().encode(s));
|
|
97
99
|
if (window.msCrypto) {
|
|
@@ -121,8 +123,16 @@ var bufferToBase64UrlEncoded = /* @__PURE__ */ __name((input) => {
|
|
|
121
123
|
const ie11SafeInput = new Uint8Array(input);
|
|
122
124
|
return urlEncodeB64(window.btoa(String.fromCharCode(...Array.from(ie11SafeInput))));
|
|
123
125
|
}, "bufferToBase64UrlEncoded");
|
|
126
|
+
var originFromAuthorizerUrl = /* @__PURE__ */ __name((authorizerUrl) => {
|
|
127
|
+
try {
|
|
128
|
+
return new URL(authorizerUrl).origin;
|
|
129
|
+
} catch {
|
|
130
|
+
return authorizerUrl;
|
|
131
|
+
}
|
|
132
|
+
}, "originFromAuthorizerUrl");
|
|
124
133
|
var executeIframe = /* @__PURE__ */ __name((authorizeUrl, eventOrigin, timeoutInSeconds = DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS) => {
|
|
125
134
|
return new Promise((resolve, reject) => {
|
|
135
|
+
const expectedOrigin = originFromAuthorizerUrl(eventOrigin);
|
|
126
136
|
const iframe = window.document.createElement("iframe");
|
|
127
137
|
iframe.setAttribute("id", "authorizer-iframe");
|
|
128
138
|
iframe.setAttribute("width", "0");
|
|
@@ -139,11 +149,12 @@ var executeIframe = /* @__PURE__ */ __name((authorizeUrl, eventOrigin, timeoutIn
|
|
|
139
149
|
removeIframe();
|
|
140
150
|
}, timeoutInSeconds * 1e3);
|
|
141
151
|
const iframeEventHandler = /* @__PURE__ */ __name(function(e) {
|
|
142
|
-
if (e.origin !==
|
|
152
|
+
if (e.origin !== expectedOrigin) return;
|
|
143
153
|
if (!e.data || !e.data.response) return;
|
|
144
154
|
const eventSource = e.source;
|
|
145
155
|
if (eventSource) eventSource.close();
|
|
146
|
-
e.data.response.error
|
|
156
|
+
if (e.data.response.error) reject(e.data.response);
|
|
157
|
+
else resolve(e.data.response);
|
|
147
158
|
clearTimeout(timeoutSetTimeoutId);
|
|
148
159
|
window.removeEventListener("message", iframeEventHandler, false);
|
|
149
160
|
setTimeout(removeIframe, CLEANUP_IFRAME_TIMEOUT_IN_SECONDS * 1e3);
|
|
@@ -158,25 +169,60 @@ var executeIframe = /* @__PURE__ */ __name((authorizeUrl, eventOrigin, timeoutIn
|
|
|
158
169
|
var userFragment = "id email email_verified given_name family_name middle_name nickname preferred_username picture signup_methods gender birthdate phone_number phone_number_verified roles created_at updated_at revoked_timestamp is_multi_factor_auth_enabled app_data";
|
|
159
170
|
var authTokenFragment = `message access_token expires_in refresh_token id_token should_show_email_otp_screen should_show_mobile_otp_screen should_show_totp_screen authenticator_scanner_image authenticator_secret authenticator_recovery_codes user { ${userFragment} }`;
|
|
160
171
|
var getFetcher = /* @__PURE__ */ __name(() => hasWindow() ? window.fetch : import_cross_fetch.default, "getFetcher");
|
|
172
|
+
function toErrorList(errors) {
|
|
173
|
+
if (Array.isArray(errors)) {
|
|
174
|
+
return errors.map((item) => {
|
|
175
|
+
if (item instanceof Error) return item;
|
|
176
|
+
if (item && typeof item === "object" && "message" in item) return new Error(String(item.message));
|
|
177
|
+
return new Error(String(item));
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (errors instanceof Error) return [
|
|
181
|
+
errors
|
|
182
|
+
];
|
|
183
|
+
if (errors !== null && typeof errors === "object") {
|
|
184
|
+
const o = errors;
|
|
185
|
+
if (typeof o.error_description === "string") return [
|
|
186
|
+
new Error(o.error_description)
|
|
187
|
+
];
|
|
188
|
+
if (typeof o.error === "string") {
|
|
189
|
+
const desc = typeof o.error_description === "string" ? `: ${o.error_description}` : "";
|
|
190
|
+
return [
|
|
191
|
+
new Error(`${o.error}${desc}`)
|
|
192
|
+
];
|
|
193
|
+
}
|
|
194
|
+
if (typeof o.message === "string") return [
|
|
195
|
+
new Error(o.message)
|
|
196
|
+
];
|
|
197
|
+
}
|
|
198
|
+
if (errors === void 0 || errors === null) return [
|
|
199
|
+
new Error("Unknown error")
|
|
200
|
+
];
|
|
201
|
+
return [
|
|
202
|
+
new Error(String(errors))
|
|
203
|
+
];
|
|
204
|
+
}
|
|
205
|
+
__name(toErrorList, "toErrorList");
|
|
161
206
|
var _Authorizer = class _Authorizer {
|
|
162
207
|
// class variable
|
|
163
208
|
config;
|
|
164
209
|
codeVerifier;
|
|
165
210
|
// constructor
|
|
166
211
|
constructor(config) {
|
|
212
|
+
var _a, _b;
|
|
167
213
|
if (!config) throw new Error("Configuration is required");
|
|
168
214
|
this.config = config;
|
|
169
|
-
if (!config.authorizerURL
|
|
170
|
-
|
|
171
|
-
if (!config.redirectURL
|
|
172
|
-
|
|
215
|
+
if (!((_a = config.authorizerURL) == null ? void 0 : _a.trim())) throw new Error("Invalid authorizerURL");
|
|
216
|
+
this.config.authorizerURL = trimURL(config.authorizerURL);
|
|
217
|
+
if (!((_b = config.redirectURL) == null ? void 0 : _b.trim())) throw new Error("Invalid redirectURL");
|
|
218
|
+
this.config.redirectURL = trimURL(config.redirectURL);
|
|
219
|
+
this.config.clientID = ((config == null ? void 0 : config.clientID) || "").trim();
|
|
173
220
|
this.config.extraHeaders = {
|
|
174
221
|
...config.extraHeaders || {},
|
|
175
|
-
"x-authorizer-url":
|
|
176
|
-
"x-authorizer-client-id":
|
|
222
|
+
"x-authorizer-url": config.authorizerURL,
|
|
223
|
+
"x-authorizer-client-id": config.clientID || "",
|
|
177
224
|
"Content-Type": "application/json"
|
|
178
225
|
};
|
|
179
|
-
this.config.clientID = ((config == null ? void 0 : config.clientID) || "").trim();
|
|
180
226
|
}
|
|
181
227
|
authorize = /* @__PURE__ */ __name(async (data) => {
|
|
182
228
|
var _a;
|
|
@@ -203,6 +249,7 @@ var _Authorizer = class _Authorizer {
|
|
|
203
249
|
const sha = await sha256(this.codeVerifier);
|
|
204
250
|
const codeChallenge = bufferToBase64UrlEncoded(sha);
|
|
205
251
|
requestData.code_challenge = codeChallenge;
|
|
252
|
+
requestData.code_challenge_method = "S256";
|
|
206
253
|
}
|
|
207
254
|
const authorizeURL = `${this.config.authorizerURL}/authorize?${createQueryParams(requestData)}`;
|
|
208
255
|
if (requestData.response_mode !== "web_message") {
|
|
@@ -251,7 +298,7 @@ var _Authorizer = class _Authorizer {
|
|
|
251
298
|
}
|
|
252
299
|
}, "browserLogin");
|
|
253
300
|
forgotPassword = /* @__PURE__ */ __name(async (data) => {
|
|
254
|
-
var _a;
|
|
301
|
+
var _a, _b;
|
|
255
302
|
if (!data.state) data.state = encode(createRandomString());
|
|
256
303
|
if (!data.redirect_uri) data.redirect_uri = this.config.redirectURL;
|
|
257
304
|
try {
|
|
@@ -259,9 +306,10 @@ var _Authorizer = class _Authorizer {
|
|
|
259
306
|
query: "mutation forgotPassword($data: ForgotPasswordRequest!) { forgot_password(params: $data) { message should_show_mobile_otp_screen } }",
|
|
260
307
|
variables: {
|
|
261
308
|
data
|
|
262
|
-
}
|
|
309
|
+
},
|
|
310
|
+
operationName: "forgotPassword"
|
|
263
311
|
});
|
|
264
|
-
return ((_a = forgotPasswordResp == null ? void 0 : forgotPasswordResp.errors) == null ? void 0 : _a.length) ? this.errorResponse(forgotPasswordResp.errors) : this.okResponse(forgotPasswordResp == null ? void 0 : forgotPasswordResp.data.forgot_password);
|
|
312
|
+
return ((_a = forgotPasswordResp == null ? void 0 : forgotPasswordResp.errors) == null ? void 0 : _a.length) ? this.errorResponse(forgotPasswordResp.errors) : this.okResponse((_b = forgotPasswordResp == null ? void 0 : forgotPasswordResp.data) == null ? void 0 : _b.forgot_password);
|
|
265
313
|
} catch (error) {
|
|
266
314
|
return this.errorResponse([
|
|
267
315
|
error
|
|
@@ -272,7 +320,8 @@ var _Authorizer = class _Authorizer {
|
|
|
272
320
|
var _a;
|
|
273
321
|
try {
|
|
274
322
|
const res = await this.graphqlQuery({
|
|
275
|
-
query: "query { meta { version client_id is_google_login_enabled is_facebook_login_enabled is_github_login_enabled is_linkedin_login_enabled is_apple_login_enabled is_twitter_login_enabled is_microsoft_login_enabled is_twitch_login_enabled is_roblox_login_enabled is_email_verification_enabled is_basic_authentication_enabled is_magic_link_login_enabled is_sign_up_enabled is_strong_password_enabled is_multi_factor_auth_enabled is_mobile_basic_authentication_enabled is_phone_verification_enabled } }"
|
|
323
|
+
query: "query meta { meta { version client_id is_google_login_enabled is_facebook_login_enabled is_github_login_enabled is_linkedin_login_enabled is_apple_login_enabled is_twitter_login_enabled is_microsoft_login_enabled is_twitch_login_enabled is_roblox_login_enabled is_email_verification_enabled is_basic_authentication_enabled is_magic_link_login_enabled is_sign_up_enabled is_strong_password_enabled is_multi_factor_auth_enabled is_mobile_basic_authentication_enabled is_phone_verification_enabled } }",
|
|
324
|
+
operationName: "meta"
|
|
276
325
|
});
|
|
277
326
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse(res.data.meta);
|
|
278
327
|
} catch (error) {
|
|
@@ -285,8 +334,9 @@ var _Authorizer = class _Authorizer {
|
|
|
285
334
|
var _a;
|
|
286
335
|
try {
|
|
287
336
|
const profileRes = await this.graphqlQuery({
|
|
288
|
-
query: `query { profile { ${userFragment} } }`,
|
|
289
|
-
headers
|
|
337
|
+
query: `query profile { profile { ${userFragment} } }`,
|
|
338
|
+
headers,
|
|
339
|
+
operationName: "profile"
|
|
290
340
|
});
|
|
291
341
|
return ((_a = profileRes == null ? void 0 : profileRes.errors) == null ? void 0 : _a.length) ? this.errorResponse(profileRes.errors) : this.okResponse(profileRes.data.profile);
|
|
292
342
|
} catch (error) {
|
|
@@ -304,7 +354,8 @@ var _Authorizer = class _Authorizer {
|
|
|
304
354
|
headers,
|
|
305
355
|
variables: {
|
|
306
356
|
params
|
|
307
|
-
}
|
|
357
|
+
},
|
|
358
|
+
operationName: "getSession"
|
|
308
359
|
});
|
|
309
360
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.session);
|
|
310
361
|
} catch (err) {
|
|
@@ -312,8 +363,9 @@ var _Authorizer = class _Authorizer {
|
|
|
312
363
|
}
|
|
313
364
|
}, "getSession");
|
|
314
365
|
getToken = /* @__PURE__ */ __name(async (data) => {
|
|
366
|
+
var _a;
|
|
315
367
|
if (!data.grant_type) data.grant_type = "authorization_code";
|
|
316
|
-
if (data.grant_type === "refresh_token" && !data.refresh_token) return this.errorResponse([
|
|
368
|
+
if (data.grant_type === "refresh_token" && !((_a = data.refresh_token) == null ? void 0 : _a.trim())) return this.errorResponse([
|
|
317
369
|
new Error("Invalid refresh_token")
|
|
318
370
|
]);
|
|
319
371
|
if (data.grant_type === "authorization_code" && !this.codeVerifier) return this.errorResponse([
|
|
@@ -336,10 +388,22 @@ var _Authorizer = class _Authorizer {
|
|
|
336
388
|
},
|
|
337
389
|
credentials: "include"
|
|
338
390
|
});
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
391
|
+
const text = await res.text();
|
|
392
|
+
let json = {};
|
|
393
|
+
if (text) {
|
|
394
|
+
try {
|
|
395
|
+
json = JSON.parse(text);
|
|
396
|
+
} catch {
|
|
397
|
+
return this.errorResponse([
|
|
398
|
+
new Error(res.ok ? "Invalid JSON from token endpoint" : `HTTP ${res.status}`)
|
|
399
|
+
]);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (!res.ok) {
|
|
403
|
+
return this.errorResponse([
|
|
404
|
+
new Error(String(json.error_description || json.error || `HTTP ${res.status}`))
|
|
405
|
+
]);
|
|
406
|
+
}
|
|
343
407
|
return this.okResponse(json);
|
|
344
408
|
} catch (err) {
|
|
345
409
|
return this.errorResponse(err);
|
|
@@ -354,23 +418,23 @@ var _Authorizer = class _Authorizer {
|
|
|
354
418
|
`,
|
|
355
419
|
variables: {
|
|
356
420
|
data
|
|
357
|
-
}
|
|
421
|
+
},
|
|
422
|
+
operationName: "login"
|
|
358
423
|
});
|
|
359
424
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.login);
|
|
360
425
|
} catch (err) {
|
|
361
|
-
return this.errorResponse(
|
|
362
|
-
new Error(err)
|
|
363
|
-
]);
|
|
426
|
+
return this.errorResponse(err);
|
|
364
427
|
}
|
|
365
428
|
}, "login");
|
|
366
429
|
logout = /* @__PURE__ */ __name(async (headers) => {
|
|
367
430
|
var _a, _b;
|
|
368
431
|
try {
|
|
369
432
|
const res = await this.graphqlQuery({
|
|
370
|
-
query: "
|
|
371
|
-
headers
|
|
433
|
+
query: "mutation logout { logout { message } }",
|
|
434
|
+
headers,
|
|
435
|
+
operationName: "logout"
|
|
372
436
|
});
|
|
373
|
-
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.
|
|
437
|
+
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.logout);
|
|
374
438
|
} catch (err) {
|
|
375
439
|
return this.errorResponse([
|
|
376
440
|
err
|
|
@@ -388,7 +452,8 @@ var _Authorizer = class _Authorizer {
|
|
|
388
452
|
`,
|
|
389
453
|
variables: {
|
|
390
454
|
data
|
|
391
|
-
}
|
|
455
|
+
},
|
|
456
|
+
operationName: "magicLinkLogin"
|
|
392
457
|
});
|
|
393
458
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.magic_link_login);
|
|
394
459
|
} catch (err) {
|
|
@@ -402,8 +467,9 @@ var _Authorizer = class _Authorizer {
|
|
|
402
467
|
if (!urlState) {
|
|
403
468
|
urlState = encode(createRandomString());
|
|
404
469
|
}
|
|
405
|
-
|
|
406
|
-
|
|
470
|
+
const oauthProviderIds = Object.values(OAuthProviders);
|
|
471
|
+
if (!oauthProviderIds.includes(oauthProvider)) {
|
|
472
|
+
throw new Error(`only following oauth providers are supported: ${oauthProviderIds.join(", ")}`);
|
|
407
473
|
}
|
|
408
474
|
if (!hasWindow()) throw new Error("oauthLogin is only supported for browsers");
|
|
409
475
|
if (roles && roles.length) urlState += `&roles=${roles.join(",")}`;
|
|
@@ -418,7 +484,8 @@ var _Authorizer = class _Authorizer {
|
|
|
418
484
|
`,
|
|
419
485
|
variables: {
|
|
420
486
|
data
|
|
421
|
-
}
|
|
487
|
+
},
|
|
488
|
+
operationName: "resendOtp"
|
|
422
489
|
});
|
|
423
490
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.resend_otp);
|
|
424
491
|
} catch (err) {
|
|
@@ -434,7 +501,8 @@ var _Authorizer = class _Authorizer {
|
|
|
434
501
|
query: "mutation resetPassword($data: ResetPasswordRequest!) { reset_password(params: $data) { message } }",
|
|
435
502
|
variables: {
|
|
436
503
|
data
|
|
437
|
-
}
|
|
504
|
+
},
|
|
505
|
+
operationName: "resetPassword"
|
|
438
506
|
});
|
|
439
507
|
return ((_a = resetPasswordRes == null ? void 0 : resetPasswordRes.errors) == null ? void 0 : _a.length) ? this.errorResponse(resetPasswordRes.errors) : this.okResponse((_b = resetPasswordRes.data) == null ? void 0 : _b.reset_password);
|
|
440
508
|
} catch (error) {
|
|
@@ -444,22 +512,43 @@ var _Authorizer = class _Authorizer {
|
|
|
444
512
|
}
|
|
445
513
|
}, "resetPassword");
|
|
446
514
|
revokeToken = /* @__PURE__ */ __name(async (data) => {
|
|
447
|
-
|
|
515
|
+
var _a;
|
|
516
|
+
if (!((_a = data.refresh_token) == null ? void 0 : _a.trim())) return this.errorResponse([
|
|
448
517
|
new Error("Invalid refresh_token")
|
|
449
518
|
]);
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
519
|
+
try {
|
|
520
|
+
const fetcher = getFetcher();
|
|
521
|
+
const res = await fetcher(`${this.config.authorizerURL}/oauth/revoke`, {
|
|
522
|
+
method: "POST",
|
|
523
|
+
headers: {
|
|
524
|
+
...this.config.extraHeaders
|
|
525
|
+
},
|
|
526
|
+
body: JSON.stringify({
|
|
527
|
+
refresh_token: data.refresh_token,
|
|
528
|
+
client_id: this.config.clientID
|
|
529
|
+
})
|
|
530
|
+
});
|
|
531
|
+
const text = await res.text();
|
|
532
|
+
let responseData = {};
|
|
533
|
+
if (text) {
|
|
534
|
+
try {
|
|
535
|
+
responseData = JSON.parse(text);
|
|
536
|
+
} catch {
|
|
537
|
+
return this.errorResponse([
|
|
538
|
+
new Error(res.ok ? "Invalid JSON from revoke endpoint" : `HTTP ${res.status}`)
|
|
539
|
+
]);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (!res.ok) {
|
|
543
|
+
const errBody = responseData;
|
|
544
|
+
return this.errorResponse([
|
|
545
|
+
new Error(String(errBody.error_description || errBody.error || `HTTP ${res.status}`))
|
|
546
|
+
]);
|
|
547
|
+
}
|
|
548
|
+
return this.okResponse(responseData);
|
|
549
|
+
} catch (err) {
|
|
550
|
+
return this.errorResponse(err);
|
|
551
|
+
}
|
|
463
552
|
}, "revokeToken");
|
|
464
553
|
signup = /* @__PURE__ */ __name(async (data) => {
|
|
465
554
|
var _a, _b;
|
|
@@ -470,7 +559,8 @@ var _Authorizer = class _Authorizer {
|
|
|
470
559
|
`,
|
|
471
560
|
variables: {
|
|
472
561
|
data
|
|
473
|
-
}
|
|
562
|
+
},
|
|
563
|
+
operationName: "signup"
|
|
474
564
|
});
|
|
475
565
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.signup);
|
|
476
566
|
} catch (err) {
|
|
@@ -487,7 +577,8 @@ var _Authorizer = class _Authorizer {
|
|
|
487
577
|
headers,
|
|
488
578
|
variables: {
|
|
489
579
|
data
|
|
490
|
-
}
|
|
580
|
+
},
|
|
581
|
+
operationName: "updateProfile"
|
|
491
582
|
});
|
|
492
583
|
return ((_a = updateProfileRes == null ? void 0 : updateProfileRes.errors) == null ? void 0 : _a.length) ? this.errorResponse(updateProfileRes.errors) : this.okResponse((_b = updateProfileRes.data) == null ? void 0 : _b.update_profile);
|
|
493
584
|
} catch (error) {
|
|
@@ -501,7 +592,8 @@ var _Authorizer = class _Authorizer {
|
|
|
501
592
|
try {
|
|
502
593
|
const res = await this.graphqlQuery({
|
|
503
594
|
query: "mutation deactivateAccount { deactivate_account { message } }",
|
|
504
|
-
headers
|
|
595
|
+
headers,
|
|
596
|
+
operationName: "deactivateAccount"
|
|
505
597
|
});
|
|
506
598
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.deactivate_account);
|
|
507
599
|
} catch (error) {
|
|
@@ -517,7 +609,8 @@ var _Authorizer = class _Authorizer {
|
|
|
517
609
|
query: "query validateJWTToken($params: ValidateJWTTokenRequest!){validate_jwt_token(params: $params) { is_valid claims } }",
|
|
518
610
|
variables: {
|
|
519
611
|
params
|
|
520
|
-
}
|
|
612
|
+
},
|
|
613
|
+
operationName: "validateJWTToken"
|
|
521
614
|
});
|
|
522
615
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.validate_jwt_token);
|
|
523
616
|
} catch (error) {
|
|
@@ -533,7 +626,8 @@ var _Authorizer = class _Authorizer {
|
|
|
533
626
|
query: `query validateSession($params: ValidateSessionRequest){validate_session(params: $params) { is_valid user { ${userFragment} } } }`,
|
|
534
627
|
variables: {
|
|
535
628
|
params
|
|
536
|
-
}
|
|
629
|
+
},
|
|
630
|
+
operationName: "validateSession"
|
|
537
631
|
});
|
|
538
632
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.validate_session);
|
|
539
633
|
} catch (error) {
|
|
@@ -551,7 +645,8 @@ var _Authorizer = class _Authorizer {
|
|
|
551
645
|
`,
|
|
552
646
|
variables: {
|
|
553
647
|
data
|
|
554
|
-
}
|
|
648
|
+
},
|
|
649
|
+
operationName: "verifyEmail"
|
|
555
650
|
});
|
|
556
651
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.verify_email);
|
|
557
652
|
} catch (err) {
|
|
@@ -569,7 +664,8 @@ var _Authorizer = class _Authorizer {
|
|
|
569
664
|
`,
|
|
570
665
|
variables: {
|
|
571
666
|
data
|
|
572
|
-
}
|
|
667
|
+
},
|
|
668
|
+
operationName: "resendVerifyEmail"
|
|
573
669
|
});
|
|
574
670
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.resend_verify_email);
|
|
575
671
|
} catch (err) {
|
|
@@ -587,7 +683,8 @@ var _Authorizer = class _Authorizer {
|
|
|
587
683
|
`,
|
|
588
684
|
variables: {
|
|
589
685
|
data
|
|
590
|
-
}
|
|
686
|
+
},
|
|
687
|
+
operationName: "verifyOtp"
|
|
591
688
|
});
|
|
592
689
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.verify_otp);
|
|
593
690
|
} catch (err) {
|
|
@@ -601,23 +698,55 @@ var _Authorizer = class _Authorizer {
|
|
|
601
698
|
graphqlQuery = /* @__PURE__ */ __name(async (data) => {
|
|
602
699
|
var _a;
|
|
603
700
|
const fetcher = getFetcher();
|
|
701
|
+
const body = {
|
|
702
|
+
query: data.query,
|
|
703
|
+
variables: data.variables || {}
|
|
704
|
+
};
|
|
705
|
+
if (data.operationName) {
|
|
706
|
+
body.operationName = data.operationName;
|
|
707
|
+
}
|
|
604
708
|
const res = await fetcher(`${this.config.authorizerURL}/graphql`, {
|
|
605
709
|
method: "POST",
|
|
606
|
-
body: JSON.stringify(
|
|
607
|
-
query: data.query,
|
|
608
|
-
variables: data.variables || {}
|
|
609
|
-
}),
|
|
710
|
+
body: JSON.stringify(body),
|
|
610
711
|
headers: {
|
|
611
712
|
...this.config.extraHeaders,
|
|
612
713
|
...data.headers || {}
|
|
613
714
|
},
|
|
614
715
|
credentials: "include"
|
|
615
716
|
});
|
|
616
|
-
const
|
|
717
|
+
const text = await res.text();
|
|
718
|
+
let json = {};
|
|
719
|
+
if (text) {
|
|
720
|
+
try {
|
|
721
|
+
json = JSON.parse(text);
|
|
722
|
+
} catch {
|
|
723
|
+
return {
|
|
724
|
+
data: void 0,
|
|
725
|
+
errors: [
|
|
726
|
+
new Error(res.ok ? "Invalid JSON from GraphQL endpoint" : `HTTP ${res.status}`)
|
|
727
|
+
]
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
} else if (!res.ok) {
|
|
731
|
+
return {
|
|
732
|
+
data: void 0,
|
|
733
|
+
errors: [
|
|
734
|
+
new Error(`HTTP ${res.status}`)
|
|
735
|
+
]
|
|
736
|
+
};
|
|
737
|
+
}
|
|
617
738
|
if ((_a = json == null ? void 0 : json.errors) == null ? void 0 : _a.length) {
|
|
618
739
|
return {
|
|
619
740
|
data: void 0,
|
|
620
|
-
errors: json.errors
|
|
741
|
+
errors: toErrorList(json.errors)
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
if (!res.ok) {
|
|
745
|
+
return {
|
|
746
|
+
data: void 0,
|
|
747
|
+
errors: [
|
|
748
|
+
new Error(`HTTP ${res.status}`)
|
|
749
|
+
]
|
|
621
750
|
};
|
|
622
751
|
}
|
|
623
752
|
return {
|
|
@@ -628,7 +757,7 @@ var _Authorizer = class _Authorizer {
|
|
|
628
757
|
errorResponse = /* @__PURE__ */ __name((errors) => {
|
|
629
758
|
return {
|
|
630
759
|
data: void 0,
|
|
631
|
-
errors
|
|
760
|
+
errors: toErrorList(errors)
|
|
632
761
|
};
|
|
633
762
|
}, "errorResponse");
|
|
634
763
|
okResponse = /* @__PURE__ */ __name((data) => {
|