@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/index.mjs CHANGED
@@ -58,7 +58,9 @@ var createQueryParams = /* @__PURE__ */ __name((params) => {
58
58
  return Object.keys(params).filter((k) => typeof params[k] !== "undefined").map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(params[k])}`).join("&");
59
59
  }, "createQueryParams");
60
60
  var sha256 = /* @__PURE__ */ __name(async (s) => {
61
- const digestOp = getCryptoSubtle().digest({
61
+ const subtle = getCryptoSubtle();
62
+ if (!subtle) throw new Error("Web Crypto API is not available");
63
+ const digestOp = subtle.digest({
62
64
  name: "SHA-256"
63
65
  }, new TextEncoder().encode(s));
64
66
  if (window.msCrypto) {
@@ -88,8 +90,16 @@ var bufferToBase64UrlEncoded = /* @__PURE__ */ __name((input) => {
88
90
  const ie11SafeInput = new Uint8Array(input);
89
91
  return urlEncodeB64(window.btoa(String.fromCharCode(...Array.from(ie11SafeInput))));
90
92
  }, "bufferToBase64UrlEncoded");
93
+ var originFromAuthorizerUrl = /* @__PURE__ */ __name((authorizerUrl) => {
94
+ try {
95
+ return new URL(authorizerUrl).origin;
96
+ } catch {
97
+ return authorizerUrl;
98
+ }
99
+ }, "originFromAuthorizerUrl");
91
100
  var executeIframe = /* @__PURE__ */ __name((authorizeUrl, eventOrigin, timeoutInSeconds = DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS) => {
92
101
  return new Promise((resolve, reject) => {
102
+ const expectedOrigin = originFromAuthorizerUrl(eventOrigin);
93
103
  const iframe = window.document.createElement("iframe");
94
104
  iframe.setAttribute("id", "authorizer-iframe");
95
105
  iframe.setAttribute("width", "0");
@@ -106,11 +116,12 @@ var executeIframe = /* @__PURE__ */ __name((authorizeUrl, eventOrigin, timeoutIn
106
116
  removeIframe();
107
117
  }, timeoutInSeconds * 1e3);
108
118
  const iframeEventHandler = /* @__PURE__ */ __name(function(e) {
109
- if (e.origin !== eventOrigin) return;
119
+ if (e.origin !== expectedOrigin) return;
110
120
  if (!e.data || !e.data.response) return;
111
121
  const eventSource = e.source;
112
122
  if (eventSource) eventSource.close();
113
- e.data.response.error ? reject(e.data.response) : resolve(e.data.response);
123
+ if (e.data.response.error) reject(e.data.response);
124
+ else resolve(e.data.response);
114
125
  clearTimeout(timeoutSetTimeoutId);
115
126
  window.removeEventListener("message", iframeEventHandler, false);
116
127
  setTimeout(removeIframe, CLEANUP_IFRAME_TIMEOUT_IN_SECONDS * 1e3);
@@ -125,25 +136,60 @@ var executeIframe = /* @__PURE__ */ __name((authorizeUrl, eventOrigin, timeoutIn
125
136
  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";
126
137
  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} }`;
127
138
  var getFetcher = /* @__PURE__ */ __name(() => hasWindow() ? window.fetch : crossFetch, "getFetcher");
139
+ function toErrorList(errors) {
140
+ if (Array.isArray(errors)) {
141
+ return errors.map((item) => {
142
+ if (item instanceof Error) return item;
143
+ if (item && typeof item === "object" && "message" in item) return new Error(String(item.message));
144
+ return new Error(String(item));
145
+ });
146
+ }
147
+ if (errors instanceof Error) return [
148
+ errors
149
+ ];
150
+ if (errors !== null && typeof errors === "object") {
151
+ const o = errors;
152
+ if (typeof o.error_description === "string") return [
153
+ new Error(o.error_description)
154
+ ];
155
+ if (typeof o.error === "string") {
156
+ const desc = typeof o.error_description === "string" ? `: ${o.error_description}` : "";
157
+ return [
158
+ new Error(`${o.error}${desc}`)
159
+ ];
160
+ }
161
+ if (typeof o.message === "string") return [
162
+ new Error(o.message)
163
+ ];
164
+ }
165
+ if (errors === void 0 || errors === null) return [
166
+ new Error("Unknown error")
167
+ ];
168
+ return [
169
+ new Error(String(errors))
170
+ ];
171
+ }
172
+ __name(toErrorList, "toErrorList");
128
173
  var _Authorizer = class _Authorizer {
129
174
  // class variable
130
175
  config;
131
176
  codeVerifier;
132
177
  // constructor
133
178
  constructor(config) {
179
+ var _a, _b;
134
180
  if (!config) throw new Error("Configuration is required");
135
181
  this.config = config;
136
- if (!config.authorizerURL && !config.authorizerURL.trim()) throw new Error("Invalid authorizerURL");
137
- if (config.authorizerURL) this.config.authorizerURL = trimURL(config.authorizerURL);
138
- if (!config.redirectURL && !config.redirectURL.trim()) throw new Error("Invalid redirectURL");
139
- else this.config.redirectURL = trimURL(config.redirectURL);
182
+ if (!((_a = config.authorizerURL) == null ? void 0 : _a.trim())) throw new Error("Invalid authorizerURL");
183
+ this.config.authorizerURL = trimURL(config.authorizerURL);
184
+ if (!((_b = config.redirectURL) == null ? void 0 : _b.trim())) throw new Error("Invalid redirectURL");
185
+ this.config.redirectURL = trimURL(config.redirectURL);
186
+ this.config.clientID = ((config == null ? void 0 : config.clientID) || "").trim();
140
187
  this.config.extraHeaders = {
141
188
  ...config.extraHeaders || {},
142
- "x-authorizer-url": this.config.authorizerURL,
143
- "x-authorizer-client-id": this.config.clientID || "",
189
+ "x-authorizer-url": config.authorizerURL,
190
+ "x-authorizer-client-id": config.clientID || "",
144
191
  "Content-Type": "application/json"
145
192
  };
146
- this.config.clientID = ((config == null ? void 0 : config.clientID) || "").trim();
147
193
  }
148
194
  authorize = /* @__PURE__ */ __name(async (data) => {
149
195
  var _a;
@@ -170,6 +216,7 @@ var _Authorizer = class _Authorizer {
170
216
  const sha = await sha256(this.codeVerifier);
171
217
  const codeChallenge = bufferToBase64UrlEncoded(sha);
172
218
  requestData.code_challenge = codeChallenge;
219
+ requestData.code_challenge_method = "S256";
173
220
  }
174
221
  const authorizeURL = `${this.config.authorizerURL}/authorize?${createQueryParams(requestData)}`;
175
222
  if (requestData.response_mode !== "web_message") {
@@ -218,7 +265,7 @@ var _Authorizer = class _Authorizer {
218
265
  }
219
266
  }, "browserLogin");
220
267
  forgotPassword = /* @__PURE__ */ __name(async (data) => {
221
- var _a;
268
+ var _a, _b;
222
269
  if (!data.state) data.state = encode(createRandomString());
223
270
  if (!data.redirect_uri) data.redirect_uri = this.config.redirectURL;
224
271
  try {
@@ -226,9 +273,10 @@ var _Authorizer = class _Authorizer {
226
273
  query: "mutation forgotPassword($data: ForgotPasswordRequest!) { forgot_password(params: $data) { message should_show_mobile_otp_screen } }",
227
274
  variables: {
228
275
  data
229
- }
276
+ },
277
+ operationName: "forgotPassword"
230
278
  });
231
- 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);
279
+ 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);
232
280
  } catch (error) {
233
281
  return this.errorResponse([
234
282
  error
@@ -239,7 +287,8 @@ var _Authorizer = class _Authorizer {
239
287
  var _a;
240
288
  try {
241
289
  const res = await this.graphqlQuery({
242
- 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 } }"
290
+ 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 } }",
291
+ operationName: "meta"
243
292
  });
244
293
  return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse(res.data.meta);
245
294
  } catch (error) {
@@ -252,8 +301,9 @@ var _Authorizer = class _Authorizer {
252
301
  var _a;
253
302
  try {
254
303
  const profileRes = await this.graphqlQuery({
255
- query: `query { profile { ${userFragment} } }`,
256
- headers
304
+ query: `query profile { profile { ${userFragment} } }`,
305
+ headers,
306
+ operationName: "profile"
257
307
  });
258
308
  return ((_a = profileRes == null ? void 0 : profileRes.errors) == null ? void 0 : _a.length) ? this.errorResponse(profileRes.errors) : this.okResponse(profileRes.data.profile);
259
309
  } catch (error) {
@@ -271,7 +321,8 @@ var _Authorizer = class _Authorizer {
271
321
  headers,
272
322
  variables: {
273
323
  params
274
- }
324
+ },
325
+ operationName: "getSession"
275
326
  });
276
327
  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);
277
328
  } catch (err) {
@@ -279,8 +330,9 @@ var _Authorizer = class _Authorizer {
279
330
  }
280
331
  }, "getSession");
281
332
  getToken = /* @__PURE__ */ __name(async (data) => {
333
+ var _a;
282
334
  if (!data.grant_type) data.grant_type = "authorization_code";
283
- if (data.grant_type === "refresh_token" && !data.refresh_token) return this.errorResponse([
335
+ if (data.grant_type === "refresh_token" && !((_a = data.refresh_token) == null ? void 0 : _a.trim())) return this.errorResponse([
284
336
  new Error("Invalid refresh_token")
285
337
  ]);
286
338
  if (data.grant_type === "authorization_code" && !this.codeVerifier) return this.errorResponse([
@@ -303,10 +355,22 @@ var _Authorizer = class _Authorizer {
303
355
  },
304
356
  credentials: "include"
305
357
  });
306
- const json = await res.json();
307
- if (res.status >= 400) return this.errorResponse([
308
- new Error(json.error_description || json.error)
309
- ]);
358
+ const text = await res.text();
359
+ let json = {};
360
+ if (text) {
361
+ try {
362
+ json = JSON.parse(text);
363
+ } catch {
364
+ return this.errorResponse([
365
+ new Error(res.ok ? "Invalid JSON from token endpoint" : `HTTP ${res.status}`)
366
+ ]);
367
+ }
368
+ }
369
+ if (!res.ok) {
370
+ return this.errorResponse([
371
+ new Error(String(json.error_description || json.error || `HTTP ${res.status}`))
372
+ ]);
373
+ }
310
374
  return this.okResponse(json);
311
375
  } catch (err) {
312
376
  return this.errorResponse(err);
@@ -321,23 +385,23 @@ var _Authorizer = class _Authorizer {
321
385
  `,
322
386
  variables: {
323
387
  data
324
- }
388
+ },
389
+ operationName: "login"
325
390
  });
326
391
  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);
327
392
  } catch (err) {
328
- return this.errorResponse([
329
- new Error(err)
330
- ]);
393
+ return this.errorResponse(err);
331
394
  }
332
395
  }, "login");
333
396
  logout = /* @__PURE__ */ __name(async (headers) => {
334
397
  var _a, _b;
335
398
  try {
336
399
  const res = await this.graphqlQuery({
337
- query: " mutation { logout { message } } ",
338
- headers
400
+ query: "mutation logout { logout { message } }",
401
+ headers,
402
+ operationName: "logout"
339
403
  });
340
- 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.response);
404
+ 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);
341
405
  } catch (err) {
342
406
  return this.errorResponse([
343
407
  err
@@ -355,7 +419,8 @@ var _Authorizer = class _Authorizer {
355
419
  `,
356
420
  variables: {
357
421
  data
358
- }
422
+ },
423
+ operationName: "magicLinkLogin"
359
424
  });
360
425
  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);
361
426
  } catch (err) {
@@ -369,8 +434,9 @@ var _Authorizer = class _Authorizer {
369
434
  if (!urlState) {
370
435
  urlState = encode(createRandomString());
371
436
  }
372
- if (!Object.values(OAuthProviders).includes(oauthProvider)) {
373
- throw new Error(`only following oauth providers are supported: ${Object.values(oauthProvider).toString()}`);
437
+ const oauthProviderIds = Object.values(OAuthProviders);
438
+ if (!oauthProviderIds.includes(oauthProvider)) {
439
+ throw new Error(`only following oauth providers are supported: ${oauthProviderIds.join(", ")}`);
374
440
  }
375
441
  if (!hasWindow()) throw new Error("oauthLogin is only supported for browsers");
376
442
  if (roles && roles.length) urlState += `&roles=${roles.join(",")}`;
@@ -385,7 +451,8 @@ var _Authorizer = class _Authorizer {
385
451
  `,
386
452
  variables: {
387
453
  data
388
- }
454
+ },
455
+ operationName: "resendOtp"
389
456
  });
390
457
  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);
391
458
  } catch (err) {
@@ -401,7 +468,8 @@ var _Authorizer = class _Authorizer {
401
468
  query: "mutation resetPassword($data: ResetPasswordRequest!) { reset_password(params: $data) { message } }",
402
469
  variables: {
403
470
  data
404
- }
471
+ },
472
+ operationName: "resetPassword"
405
473
  });
406
474
  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);
407
475
  } catch (error) {
@@ -411,22 +479,43 @@ var _Authorizer = class _Authorizer {
411
479
  }
412
480
  }, "resetPassword");
413
481
  revokeToken = /* @__PURE__ */ __name(async (data) => {
414
- if (!data.refresh_token && !data.refresh_token.trim()) return this.errorResponse([
482
+ var _a;
483
+ if (!((_a = data.refresh_token) == null ? void 0 : _a.trim())) return this.errorResponse([
415
484
  new Error("Invalid refresh_token")
416
485
  ]);
417
- const fetcher = getFetcher();
418
- const res = await fetcher(`${this.config.authorizerURL}/oauth/revoke`, {
419
- method: "POST",
420
- headers: {
421
- ...this.config.extraHeaders
422
- },
423
- body: JSON.stringify({
424
- refresh_token: data.refresh_token,
425
- client_id: this.config.clientID
426
- })
427
- });
428
- const responseData = await res.json();
429
- return this.okResponse(responseData);
486
+ try {
487
+ const fetcher = getFetcher();
488
+ const res = await fetcher(`${this.config.authorizerURL}/oauth/revoke`, {
489
+ method: "POST",
490
+ headers: {
491
+ ...this.config.extraHeaders
492
+ },
493
+ body: JSON.stringify({
494
+ refresh_token: data.refresh_token,
495
+ client_id: this.config.clientID
496
+ })
497
+ });
498
+ const text = await res.text();
499
+ let responseData = {};
500
+ if (text) {
501
+ try {
502
+ responseData = JSON.parse(text);
503
+ } catch {
504
+ return this.errorResponse([
505
+ new Error(res.ok ? "Invalid JSON from revoke endpoint" : `HTTP ${res.status}`)
506
+ ]);
507
+ }
508
+ }
509
+ if (!res.ok) {
510
+ const errBody = responseData;
511
+ return this.errorResponse([
512
+ new Error(String(errBody.error_description || errBody.error || `HTTP ${res.status}`))
513
+ ]);
514
+ }
515
+ return this.okResponse(responseData);
516
+ } catch (err) {
517
+ return this.errorResponse(err);
518
+ }
430
519
  }, "revokeToken");
431
520
  signup = /* @__PURE__ */ __name(async (data) => {
432
521
  var _a, _b;
@@ -437,7 +526,8 @@ var _Authorizer = class _Authorizer {
437
526
  `,
438
527
  variables: {
439
528
  data
440
- }
529
+ },
530
+ operationName: "signup"
441
531
  });
442
532
  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);
443
533
  } catch (err) {
@@ -454,7 +544,8 @@ var _Authorizer = class _Authorizer {
454
544
  headers,
455
545
  variables: {
456
546
  data
457
- }
547
+ },
548
+ operationName: "updateProfile"
458
549
  });
459
550
  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);
460
551
  } catch (error) {
@@ -468,7 +559,8 @@ var _Authorizer = class _Authorizer {
468
559
  try {
469
560
  const res = await this.graphqlQuery({
470
561
  query: "mutation deactivateAccount { deactivate_account { message } }",
471
- headers
562
+ headers,
563
+ operationName: "deactivateAccount"
472
564
  });
473
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.deactivate_account);
474
566
  } catch (error) {
@@ -484,7 +576,8 @@ var _Authorizer = class _Authorizer {
484
576
  query: "query validateJWTToken($params: ValidateJWTTokenRequest!){validate_jwt_token(params: $params) { is_valid claims } }",
485
577
  variables: {
486
578
  params
487
- }
579
+ },
580
+ operationName: "validateJWTToken"
488
581
  });
489
582
  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);
490
583
  } catch (error) {
@@ -500,7 +593,8 @@ var _Authorizer = class _Authorizer {
500
593
  query: `query validateSession($params: ValidateSessionRequest){validate_session(params: $params) { is_valid user { ${userFragment} } } }`,
501
594
  variables: {
502
595
  params
503
- }
596
+ },
597
+ operationName: "validateSession"
504
598
  });
505
599
  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);
506
600
  } catch (error) {
@@ -518,7 +612,8 @@ var _Authorizer = class _Authorizer {
518
612
  `,
519
613
  variables: {
520
614
  data
521
- }
615
+ },
616
+ operationName: "verifyEmail"
522
617
  });
523
618
  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);
524
619
  } catch (err) {
@@ -536,7 +631,8 @@ var _Authorizer = class _Authorizer {
536
631
  `,
537
632
  variables: {
538
633
  data
539
- }
634
+ },
635
+ operationName: "resendVerifyEmail"
540
636
  });
541
637
  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);
542
638
  } catch (err) {
@@ -554,7 +650,8 @@ var _Authorizer = class _Authorizer {
554
650
  `,
555
651
  variables: {
556
652
  data
557
- }
653
+ },
654
+ operationName: "verifyOtp"
558
655
  });
559
656
  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);
560
657
  } catch (err) {
@@ -568,23 +665,55 @@ var _Authorizer = class _Authorizer {
568
665
  graphqlQuery = /* @__PURE__ */ __name(async (data) => {
569
666
  var _a;
570
667
  const fetcher = getFetcher();
668
+ const body = {
669
+ query: data.query,
670
+ variables: data.variables || {}
671
+ };
672
+ if (data.operationName) {
673
+ body.operationName = data.operationName;
674
+ }
571
675
  const res = await fetcher(`${this.config.authorizerURL}/graphql`, {
572
676
  method: "POST",
573
- body: JSON.stringify({
574
- query: data.query,
575
- variables: data.variables || {}
576
- }),
677
+ body: JSON.stringify(body),
577
678
  headers: {
578
679
  ...this.config.extraHeaders,
579
680
  ...data.headers || {}
580
681
  },
581
682
  credentials: "include"
582
683
  });
583
- const json = await res.json();
684
+ const text = await res.text();
685
+ let json = {};
686
+ if (text) {
687
+ try {
688
+ json = JSON.parse(text);
689
+ } catch {
690
+ return {
691
+ data: void 0,
692
+ errors: [
693
+ new Error(res.ok ? "Invalid JSON from GraphQL endpoint" : `HTTP ${res.status}`)
694
+ ]
695
+ };
696
+ }
697
+ } else if (!res.ok) {
698
+ return {
699
+ data: void 0,
700
+ errors: [
701
+ new Error(`HTTP ${res.status}`)
702
+ ]
703
+ };
704
+ }
584
705
  if ((_a = json == null ? void 0 : json.errors) == null ? void 0 : _a.length) {
585
706
  return {
586
707
  data: void 0,
587
- errors: json.errors
708
+ errors: toErrorList(json.errors)
709
+ };
710
+ }
711
+ if (!res.ok) {
712
+ return {
713
+ data: void 0,
714
+ errors: [
715
+ new Error(`HTTP ${res.status}`)
716
+ ]
588
717
  };
589
718
  }
590
719
  return {
@@ -595,7 +724,7 @@ var _Authorizer = class _Authorizer {
595
724
  errorResponse = /* @__PURE__ */ __name((errors) => {
596
725
  return {
597
726
  data: void 0,
598
- errors
727
+ errors: toErrorList(errors)
599
728
  };
600
729
  }, "errorResponse");
601
730
  okResponse = /* @__PURE__ */ __name((data) => {