@alore/auth-react-sdk 1.1.0-alpha.1 → 1.1.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './utils/AloreAuth';
2
2
  export * from './helpers/crypto';
3
+ export * from './types';
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './utils/AloreAuth';
2
2
  export * from './helpers/crypto';
3
+ export * from './types';
package/dist/types.d.ts CHANGED
@@ -20,7 +20,6 @@ export type KeyDerivationFunction = 'argon2d' | 'pbkdf2';
20
20
  * @property logoUrl - Optional string for logo URL.
21
21
  * @property socialProviders - Optional social login providers.
22
22
  * @property enableWalletCreation - Optional boolean to enable wallet creation.
23
- * @property allowedEmailDomains - Optional allowed email domain(s). If provided, authentication will only allow emails from these domains. Accepts a single string (e.g., 'bealore.com' or '@bealore.com') or an array of strings.
24
23
  */
25
24
  export interface AuthProviderConfig {
26
25
  rpDomain?: string;
@@ -38,7 +37,6 @@ export interface AuthProviderConfig {
38
37
  socialProviders?: SocialProvider[];
39
38
  enableWalletCreation?: boolean;
40
39
  firebaseCompatible?: boolean;
41
- allowedEmailDomains?: string | string[];
42
40
  }
43
41
  export interface AuthMachineContext {
44
42
  authProviderConfigs?: AuthProviderConfig;
@@ -1,11 +1,10 @@
1
- import { AuthMachineContext, AuthProviderConfig, FetchWithProgressiveBackoffConfig, ForgeData } from '../types';
1
+ import type { AuthMachineContext, AuthProviderConfig, FetchWithProgressiveBackoffConfig, ForgeData } from '../types';
2
2
  export declare class AloreAuth {
3
3
  protected readonly aloreBaseUrl: string;
4
4
  protected readonly emailTemplate: string;
5
5
  protected readonly clientId: string;
6
6
  constructor(clientId: string, aloreBaseUrl?: string, config?: AuthProviderConfig);
7
7
  services: {
8
- isEmailAllowed: (context: AuthMachineContext, email?: string | null) => boolean;
9
8
  healthCheck: () => Promise<{
10
9
  data: boolean;
11
10
  }>;
@@ -16,17 +15,13 @@ export declare class AloreAuth {
16
15
  };
17
16
  }) => Promise<{
18
17
  salt: string;
19
- error?: undefined;
20
- } | {
21
- error: string;
22
- salt?: undefined;
23
- }>;
18
+ } | undefined>;
24
19
  verifyEmail: (context: AuthMachineContext, event: {
25
20
  type: 'VERIFY_EMAIL';
26
21
  payload: {
27
22
  secureCode: string;
28
23
  };
29
- }) => Promise<{}>;
24
+ }) => Promise<{} | undefined>;
30
25
  completeRegistration: (context: AuthMachineContext, event: {
31
26
  type: 'COMPLETE_REGISTRATION';
32
27
  payload: {
@@ -42,11 +37,7 @@ export declare class AloreAuth {
42
37
  email: string;
43
38
  passwordHash: string;
44
39
  };
45
- }) => Promise<{
46
- error?: undefined;
47
- } | {
48
- error: string;
49
- }>;
40
+ }) => Promise<{}>;
50
41
  sendConfirmationEmail: (context: AuthMachineContext, event: {
51
42
  type: 'RESEND_CODE';
52
43
  payload: {
@@ -68,22 +59,13 @@ export declare class AloreAuth {
68
59
  }) => Promise<{
69
60
  salt: any;
70
61
  sessionId: any;
71
- error?: undefined;
72
- } | {
73
- error: string;
74
- salt?: undefined;
75
- sessionId?: undefined;
76
- }>;
62
+ } | undefined>;
77
63
  sendCode: (context: AuthMachineContext, event: {
78
64
  type: 'SEND_CODE';
79
65
  payload: {
80
66
  email: string;
81
67
  };
82
- }) => Promise<{
83
- error: string;
84
- } | {
85
- error?: undefined;
86
- }>;
68
+ }) => Promise<{}>;
87
69
  verifyLogin: (context: AuthMachineContext, event: {
88
70
  type: 'VERIFY_LOGIN';
89
71
  payload: {
@@ -264,6 +246,10 @@ export declare class AloreAuth {
264
246
  }) => Promise<any>;
265
247
  };
266
248
  private delay;
249
+ private isLocalUrl;
267
250
  fetchWithProgressiveBackoff(url: RequestInfo | URL, options?: RequestInit, config?: FetchWithProgressiveBackoffConfig): Promise<Response>;
251
+ private parseErrorResponse;
252
+ private throwParsedResponseError;
268
253
  private verifyBackendStatus;
254
+ private extractErrorInfo;
269
255
  }
@@ -13,28 +13,6 @@ const DEFAULT_URL = 'https://alpha-api.bealore.com/v1';
13
13
  export class AloreAuth {
14
14
  constructor(clientId, aloreBaseUrl, config) {
15
15
  this.services = {
16
- // Utility to check if an email is allowed based on allowedEmailDomains config
17
- isEmailAllowed: (context, email) => {
18
- var _a;
19
- const allowedConf = (_a = context.authProviderConfigs) === null || _a === void 0 ? void 0 : _a.allowedEmailDomains;
20
- const allowedList =
21
- // eslint-disable-next-line no-nested-ternary
22
- typeof allowedConf === 'string'
23
- ? [allowedConf]
24
- : Array.isArray(allowedConf)
25
- ? allowedConf
26
- : [];
27
- if (allowedList.length === 0)
28
- return true;
29
- if (!email)
30
- return false;
31
- const domain = (email.split('@')[1] || '').toLowerCase();
32
- // Allow items like '@bealore.com' or 'bealore.com'
33
- return allowedList.some((d) => {
34
- const normalized = d.startsWith('@') ? d.slice(1) : d;
35
- return domain === normalized.toLowerCase();
36
- });
37
- },
38
16
  healthCheck: () => __awaiter(this, void 0, void 0, function* () {
39
17
  try {
40
18
  yield this.verifyBackendStatus();
@@ -47,9 +25,6 @@ export class AloreAuth {
47
25
  // Email and password flow
48
26
  retrieveSalt: (context, event) => __awaiter(this, void 0, void 0, function* () {
49
27
  const { email } = event.payload;
50
- if (!this.services.isEmailAllowed(context, email)) {
51
- throw new Error('Email domain not allowed');
52
- }
53
28
  const { credentialEmail } = context;
54
29
  const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/salt/${email || credentialEmail}`, {
55
30
  headers: {
@@ -60,7 +35,8 @@ export class AloreAuth {
60
35
  const salt = yield response.json();
61
36
  return { salt };
62
37
  }
63
- return { error: response === null || response === void 0 ? void 0 : response.statusText };
38
+ // Propagate parsed error so machine receives full payload as event.data
39
+ yield this.throwParsedResponseError(response);
64
40
  }),
65
41
  verifyEmail: (context, event) => __awaiter(this, void 0, void 0, function* () {
66
42
  const { secureCode } = event.payload;
@@ -77,14 +53,10 @@ export class AloreAuth {
77
53
  if (response.ok) {
78
54
  return {};
79
55
  }
80
- const data = yield response.json();
81
- throw new Error((data === null || data === void 0 ? void 0 : data.message) || (data === null || data === void 0 ? void 0 : data.error) || data);
56
+ yield this.throwParsedResponseError(response);
82
57
  }),
83
58
  completeRegistration: (context, event) => __awaiter(this, void 0, void 0, function* () {
84
59
  const { email, nickname, passwordHash, device } = event.payload;
85
- if (!this.services.isEmailAllowed(context, email)) {
86
- throw new Error('Email domain not allowed');
87
- }
88
60
  const { firebaseCompatible } = context.authProviderConfigs || {};
89
61
  const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/account-registration${firebaseCompatible ? `?firebaseCompatibleToken=${firebaseCompatible}` : ''}`, {
90
62
  method: 'POST',
@@ -101,7 +73,7 @@ export class AloreAuth {
101
73
  const data = yield response.json();
102
74
  if (response.ok)
103
75
  return data;
104
- throw new Error(data.message || data.error || 'Authentication failed');
76
+ yield this.throwParsedResponseError(response);
105
77
  }),
106
78
  confirmPassword: (context, event) => __awaiter(this, void 0, void 0, function* () {
107
79
  const { email, passwordHash } = event.payload;
@@ -116,14 +88,11 @@ export class AloreAuth {
116
88
  }),
117
89
  });
118
90
  if (!response.ok)
119
- return {};
120
- return { error: response === null || response === void 0 ? void 0 : response.statusText };
91
+ yield this.throwParsedResponseError(response);
92
+ return {};
121
93
  }),
122
94
  sendConfirmationEmail: (context, event) => __awaiter(this, void 0, void 0, function* () {
123
95
  const { email, nickname, locale } = event.payload;
124
- if (!this.services.isEmailAllowed(context, email)) {
125
- throw new Error('Email domain not allowed');
126
- }
127
96
  const searchParams = new URLSearchParams();
128
97
  const url = '/auth/v1/confirmation-email';
129
98
  if (locale) {
@@ -147,17 +116,11 @@ export class AloreAuth {
147
116
  const { salt, sessionId } = resJson;
148
117
  return { salt, sessionId };
149
118
  }
150
- if (response.status === 403) {
151
- const resJson = yield response.json();
152
- throw new Error(resJson);
153
- }
154
- return { error: response === null || response === void 0 ? void 0 : response.statusText };
119
+ // Throw parsed error for machine to consume
120
+ yield this.throwParsedResponseError(response);
155
121
  }),
156
122
  sendCode: (context, event) => __awaiter(this, void 0, void 0, function* () {
157
123
  const { email } = event.payload;
158
- if (!this.services.isEmailAllowed(context, email)) {
159
- return { error: 'Email domain not allowed' };
160
- }
161
124
  const response = yield this.fetchWithProgressiveBackoff(`/reset-password`, {
162
125
  method: 'POST',
163
126
  headers: {
@@ -168,15 +131,12 @@ export class AloreAuth {
168
131
  }),
169
132
  });
170
133
  if (!response.ok)
171
- return { error: response === null || response === void 0 ? void 0 : response.statusText };
134
+ yield this.throwParsedResponseError(response);
172
135
  return {};
173
136
  }),
174
137
  verifyLogin: (context, event) => __awaiter(this, void 0, void 0, function* () {
175
138
  var _a, _b;
176
139
  const { email, passwordHash, device, locale } = event.payload;
177
- if (!this.services.isEmailAllowed(context, email || context.credentialEmail)) {
178
- throw new Error('Email domain not allowed');
179
- }
180
140
  const { credentialEmail } = context;
181
141
  const searchParams = new URLSearchParams();
182
142
  const url = '/auth/v1/login-verification';
@@ -205,7 +165,7 @@ export class AloreAuth {
205
165
  if (((_a = data === null || data === void 0 ? void 0 : data.error) === null || _a === void 0 ? void 0 : _a.includes('2FA')) || ((_b = data === null || data === void 0 ? void 0 : data.error) === null || _b === void 0 ? void 0 : _b.includes('device'))) {
206
166
  return { error: data === null || data === void 0 ? void 0 : data.error };
207
167
  }
208
- throw new Error((data === null || data === void 0 ? void 0 : data.message) || (data === null || data === void 0 ? void 0 : data.error) || data);
168
+ yield this.throwParsedResponseError(response);
209
169
  }
210
170
  else {
211
171
  return data;
@@ -215,9 +175,6 @@ export class AloreAuth {
215
175
  startRegisterPasskey: (context, event) => __awaiter(this, void 0, void 0, function* () {
216
176
  const { rpDomain } = context.authProviderConfigs || {};
217
177
  const { email, nickname, device } = event.payload || context.registerUser;
218
- if (email && !this.services.isEmailAllowed(context, email)) {
219
- throw new Error('Email domain not allowed');
220
- }
221
178
  const startPasskeyRegistrationResponse = yield this.fetchWithProgressiveBackoff('/auth/v1/account-registration-passkey', {
222
179
  method: 'POST',
223
180
  headers: {
@@ -231,14 +188,13 @@ export class AloreAuth {
231
188
  }),
232
189
  });
233
190
  const data = yield startPasskeyRegistrationResponse.json();
191
+ if (!startPasskeyRegistrationResponse.ok)
192
+ yield this.throwParsedResponseError(startPasskeyRegistrationResponse);
234
193
  return data;
235
194
  }),
236
195
  finishRegisterPasskey: (context, event) => __awaiter(this, void 0, void 0, function* () {
237
196
  const { rpDomain } = context.authProviderConfigs || {};
238
197
  const { email, nickname, device, passkeyRegistration } = event.payload || {};
239
- if (email && !this.services.isEmailAllowed(context, email)) {
240
- throw new Error('Email domain not allowed');
241
- }
242
198
  const response = yield this.fetchWithProgressiveBackoff('/auth/v1/account-registration-passkey-finish', {
243
199
  method: 'POST',
244
200
  headers: {
@@ -262,9 +218,6 @@ export class AloreAuth {
262
218
  var _c;
263
219
  const { rpDomain } = context.authProviderConfigs || {};
264
220
  const email = (_c = event.payload) === null || _c === void 0 ? void 0 : _c.email;
265
- if (email && !this.services.isEmailAllowed(context, email)) {
266
- throw new Error('Email domain not allowed');
267
- }
268
221
  const searchParams = new URLSearchParams();
269
222
  const url = '/auth/v1/login-passkey';
270
223
  if (rpDomain) {
@@ -297,7 +250,7 @@ export class AloreAuth {
297
250
  const data = yield response.json();
298
251
  if (response.ok)
299
252
  return data;
300
- throw new AloreAuthError(ErrorTypes.FAILED_TO_FETCH, data.message || data.error || data);
253
+ yield this.throwParsedResponseError(response);
301
254
  }),
302
255
  // Hardware 2FA flow
303
256
  verify2faCode: (_context, event) => __awaiter(this, void 0, void 0, function* () {
@@ -317,7 +270,7 @@ export class AloreAuth {
317
270
  const data = yield response.json();
318
271
  if (response.ok)
319
272
  return data;
320
- throw new Error(data.message || data.error || 'Authentication failed');
273
+ yield this.throwParsedResponseError(response);
321
274
  }),
322
275
  authenticateWebauthn: (context, event) => __awaiter(this, void 0, void 0, function* () {
323
276
  const { email, passwordHash, device, authId } = event.payload;
@@ -355,7 +308,7 @@ export class AloreAuth {
355
308
  const data = yield response.json();
356
309
  if (response.ok)
357
310
  return data;
358
- throw new Error(data.message || data.error || 'Authentication failed');
311
+ yield this.throwParsedResponseError(response);
359
312
  }),
360
313
  verifyDeviceCode: (context, event) => __awaiter(this, void 0, void 0, function* () {
361
314
  const { email, passwordHash, device, secureCode } = event.payload;
@@ -380,9 +333,6 @@ export class AloreAuth {
380
333
  verifyEmail2fa: (context, event) => __awaiter(this, void 0, void 0, function* () {
381
334
  const { email, passwordHash, secureCode } = event.payload;
382
335
  const { credentialEmail, authProviderConfigs } = context;
383
- if (!this.services.isEmailAllowed(context, email || credentialEmail)) {
384
- throw new Error('Email domain not allowed');
385
- }
386
336
  const { firebaseCompatible } = authProviderConfigs || {};
387
337
  const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/email-2fa-verification${firebaseCompatible ? `?firebaseCompatibleToken=${firebaseCompatible}` : ''}`, {
388
338
  method: 'POST',
@@ -414,7 +364,7 @@ export class AloreAuth {
414
364
  });
415
365
  const data = yield response.json();
416
366
  if (!response.ok)
417
- throw new Error((data === null || data === void 0 ? void 0 : data.message) || (data === null || data === void 0 ? void 0 : data.error) || data);
367
+ yield this.throwParsedResponseError(response);
418
368
  return data;
419
369
  }),
420
370
  verifyClaimNftEmail2fa: (context, event) => __awaiter(this, void 0, void 0, function* () {
@@ -433,14 +383,13 @@ export class AloreAuth {
433
383
  const data = yield response.json();
434
384
  if (response.ok)
435
385
  return data;
436
- throw new Error(data || 'Authentication failed');
386
+ yield this.throwParsedResponseError(response);
437
387
  }),
438
388
  fetchForgeData: (_, event) => __awaiter(this, void 0, void 0, function* () {
439
389
  const response = yield this.fetchWithProgressiveBackoff(`/forges/${event.forgeId}`);
440
390
  const data = (yield response.json());
441
- if (!response.ok) {
442
- throw new Error(`Failed to fetchWithProgressiveBackoff: ${data}`);
443
- }
391
+ if (!response.ok)
392
+ yield this.throwParsedResponseError(response);
444
393
  return data;
445
394
  }),
446
395
  // Google login flow
@@ -460,9 +409,6 @@ export class AloreAuth {
460
409
  });
461
410
  const data = yield response.json();
462
411
  if (response.ok) {
463
- if (!this.services.isEmailAllowed(context, data.email)) {
464
- throw new Error('Email domain not allowed');
465
- }
466
412
  return {
467
413
  googleOtpCode: data.otpCode,
468
414
  salt: data.salt,
@@ -475,9 +421,6 @@ export class AloreAuth {
475
421
  };
476
422
  }
477
423
  if (response.status === 404) {
478
- if (!this.services.isEmailAllowed(context, data.email)) {
479
- throw new Error('Email domain not allowed');
480
- }
481
424
  return {
482
425
  isNewUser: true,
483
426
  socialProviderRegisterUser: {
@@ -488,7 +431,7 @@ export class AloreAuth {
488
431
  };
489
432
  }
490
433
  if (!response.ok)
491
- throw new Error(data.error || data.message || data);
434
+ yield this.throwParsedResponseError(response);
492
435
  return {};
493
436
  }),
494
437
  verifyGoogleLogin: (context, event) => __awaiter(this, void 0, void 0, function* () {
@@ -524,6 +467,21 @@ export class AloreAuth {
524
467
  yield new Promise((resolve) => setTimeout(resolve, ms));
525
468
  });
526
469
  }
470
+ // eslint-disable-next-line class-methods-use-this
471
+ isLocalUrl(urlString) {
472
+ try {
473
+ const parsed = new URL(urlString);
474
+ const isHttp = parsed.protocol === 'http:';
475
+ const isLoopbackHost = parsed.hostname === 'localhost' ||
476
+ parsed.hostname === '127.0.0.1' ||
477
+ parsed.hostname === '::1';
478
+ const isPort8000 = parsed.port === '8000';
479
+ return isHttp || isLoopbackHost || isPort8000;
480
+ }
481
+ catch (_e) {
482
+ return false;
483
+ }
484
+ }
527
485
  fetchWithProgressiveBackoff(
528
486
  // eslint-disable-next-line no-undef
529
487
  url,
@@ -533,8 +491,9 @@ export class AloreAuth {
533
491
  const { maxAttempts = 3, initialDelay = 200 } = config || {};
534
492
  let attempt = 0;
535
493
  let delayValue = initialDelay;
494
+ const isLocal = this.isLocalUrl(this.aloreBaseUrl);
536
495
  // eslint-disable-next-line no-undef
537
- const init = Object.assign(Object.assign({}, options), { credentials: 'include', headers: Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.headers), { 'X-CLIENT-ID': this.clientId, 'CF-Connecting-IP': '127.0.0.1' }) });
496
+ const init = Object.assign(Object.assign({}, options), { credentials: 'include', headers: Object.assign(Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.headers), { 'X-CLIENT-ID': this.clientId }), (isLocal && { 'CF-Connecting-IP': '127.0.0.1' })) });
538
497
  while (attempt < maxAttempts) {
539
498
  if (attempt > 0) {
540
499
  // eslint-disable-next-line no-await-in-loop, no-promise-executor-return, no-loop-func
@@ -551,31 +510,110 @@ export class AloreAuth {
551
510
  }
552
511
  catch (error) {
553
512
  console.error(error);
554
- if (error instanceof TypeError &&
555
- error.message === 'Failed to fetch' &&
556
- attempt >= maxAttempts) {
557
- console.error('Connection refused, the backend is probably not running.');
558
- this.verifyBackendStatus();
513
+ // Treat any fetch TypeError as a network/CORS-style failure. Browsers localize the message.
514
+ const isFailedToFetch = error instanceof TypeError;
515
+ if (isFailedToFetch && attempt >= maxAttempts) {
516
+ // Determine whether backend is down or the request is likely blocked (e.g., CORS)
517
+ const origin = typeof window !== 'undefined' ? window.location.origin : undefined;
518
+ try {
519
+ // eslint-disable-next-line no-await-in-loop
520
+ const health = yield this.verifyBackendStatus();
521
+ const fullUrl = `${this.aloreBaseUrl}${url}`;
522
+ const message = origin
523
+ ? `Request blocked by CORS policy. Endpoint: ${fullUrl}. Please ensure origin ${origin} is allowed.`
524
+ : `Request blocked by CORS policy. Endpoint: ${fullUrl}.`;
525
+ const corsErr = new AloreAuthError(ErrorTypes.CORS_BLOCKED, message);
526
+ // Preserve original fetch error and health-check details for diagnostics
527
+ // @ts-ignore
528
+ corsErr.data = {
529
+ originalError: this.extractErrorInfo(error),
530
+ healthCheck: Object.assign({ reachable: true }, health),
531
+ };
532
+ throw corsErr;
533
+ }
534
+ catch (healthError) {
535
+ // Backend health-check failed → server likely down/unreachable
536
+ const downErr = new AloreAuthError(ErrorTypes.SERVER_DOWN, `Server is unreachable at ${this.aloreBaseUrl}. Please try again later.`);
537
+ // @ts-ignore
538
+ downErr.data = {
539
+ originalError: this.extractErrorInfo(error),
540
+ healthCheck: { reachable: false, error: this.extractErrorInfo(healthError) },
541
+ };
542
+ throw downErr;
543
+ }
559
544
  }
560
- else if (attempt < maxAttempts) {
545
+ if (attempt < maxAttempts) {
561
546
  console.error(`Attempt ${attempt} failed, retrying in ${delayValue}ms...`);
562
547
  }
563
548
  }
564
549
  }
565
- throw new Error(`Max attempts (${maxAttempts}) exceeded`);
550
+ // Final fallback (should rarely hit due to early throws above)
551
+ throw new AloreAuthError(ErrorTypes.FAILED_TO_FETCH, `Max attempts (${maxAttempts}) exceeded while contacting ${this.aloreBaseUrl}${url}`);
566
552
  });
567
553
  }
568
- verifyBackendStatus() {
554
+ // eslint-disable-next-line class-methods-use-this
555
+ parseErrorResponse(response) {
569
556
  return __awaiter(this, void 0, void 0, function* () {
570
557
  try {
571
- const res = yield fetch(`${this.aloreBaseUrl}/health-check`);
572
- if (!res.ok) {
573
- throw new Error('Failed to fetch');
558
+ const data = yield response.json();
559
+ // Standardize to server payload when present
560
+ if (data && typeof data === 'object' && (data.message || data.status)) {
561
+ return {
562
+ status: data.status || response.status,
563
+ message: data.message || data.error || response.statusText,
564
+ timestamp: data.timestamp,
565
+ };
574
566
  }
567
+ return { status: response.status, message: response.statusText };
568
+ }
569
+ catch (_a) {
570
+ return { status: response.status, message: response.statusText };
571
+ }
572
+ });
573
+ }
574
+ // eslint-disable-next-line class-methods-use-this
575
+ throwParsedResponseError(response) {
576
+ return __awaiter(this, void 0, void 0, function* () {
577
+ const parsed = yield this.parseErrorResponse(response);
578
+ // Normalize well-known auth errors for consistent UI handling
579
+ let normalizedMessage = parsed.message || 'Request failed';
580
+ if (parsed.status === 401) {
581
+ normalizedMessage = 'INVALID_CREDENTIALS';
582
+ }
583
+ else if (parsed.status === 403 && parsed.message === 'EMAIL_NOT_ALLOWED') {
584
+ normalizedMessage = 'EMAIL_NOT_ALLOWED';
585
+ }
586
+ const err = new AloreAuthError(ErrorTypes.FAILED_TO_FETCH, normalizedMessage);
587
+ // @ts-ignore attach server payload for consumers
588
+ err.data = Object.assign(Object.assign({}, parsed), { message: normalizedMessage });
589
+ throw err;
590
+ });
591
+ }
592
+ verifyBackendStatus() {
593
+ return __awaiter(this, void 0, void 0, function* () {
594
+ const endpoint = '/health/ready';
595
+ // eslint-disable-next-line no-undef
596
+ const init = { mode: 'no-cors', cache: 'no-store' };
597
+ try {
598
+ yield fetch(`${this.aloreBaseUrl}${endpoint}`, init);
599
+ return { checkedEndpoints: [endpoint] };
575
600
  }
576
601
  catch (_a) {
577
602
  throw new Error('Server down');
578
603
  }
579
604
  });
580
605
  }
606
+ // Capture a concise, serializable snapshot of an unknown error
607
+ // eslint-disable-next-line class-methods-use-this
608
+ extractErrorInfo(error) {
609
+ if (error instanceof Error) {
610
+ return { name: error.name, message: error.message, stack: error.stack };
611
+ }
612
+ try {
613
+ return JSON.parse(JSON.stringify(error));
614
+ }
615
+ catch (_a) {
616
+ return { error };
617
+ }
618
+ }
581
619
  }
@@ -5,10 +5,12 @@ export declare enum ErrorCodes {
5
5
  }
6
6
  export declare enum ErrorTypes {
7
7
  CLIENT_ID_REQUIRED = "CLIENT_ID_REQUIRED",
8
+ EMAIL_DOMAIN_NOT_ALLOWED = "EMAIL_DOMAIN_NOT_ALLOWED",
8
9
  PASSKEY_NOT_SUPPORTED = "PASSKEY_NOT_SUPPORTED",
9
10
  USER_ALREADY_EXISTS = "USER_ALREADY_EXISTS",
10
11
  FAILED_TO_FETCH = "FAILED_TO_FETCH",
11
12
  SERVER_DOWN = "SERVER_DOWN",
13
+ CORS_BLOCKED = "CORS_BLOCKED",
12
14
  BAD_RESPONSE = "BAD_RESPONSE",
13
15
  UNKNOWN_ERROR = "UNKNOWN_ERROR",
14
16
  INVALID_CREDENTIALS = "INVALID_CREDENTIALS",
@@ -8,10 +8,12 @@ export var ErrorCodes;
8
8
  export var ErrorTypes;
9
9
  (function (ErrorTypes) {
10
10
  ErrorTypes["CLIENT_ID_REQUIRED"] = "CLIENT_ID_REQUIRED";
11
+ ErrorTypes["EMAIL_DOMAIN_NOT_ALLOWED"] = "EMAIL_DOMAIN_NOT_ALLOWED";
11
12
  ErrorTypes["PASSKEY_NOT_SUPPORTED"] = "PASSKEY_NOT_SUPPORTED";
12
13
  ErrorTypes["USER_ALREADY_EXISTS"] = "USER_ALREADY_EXISTS";
13
14
  ErrorTypes["FAILED_TO_FETCH"] = "FAILED_TO_FETCH";
14
15
  ErrorTypes["SERVER_DOWN"] = "SERVER_DOWN";
16
+ ErrorTypes["CORS_BLOCKED"] = "CORS_BLOCKED";
15
17
  ErrorTypes["BAD_RESPONSE"] = "BAD_RESPONSE";
16
18
  ErrorTypes["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
17
19
  ErrorTypes["INVALID_CREDENTIALS"] = "INVALID_CREDENTIALS";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alore/auth-react-sdk",
3
- "version": "1.1.0-alpha.1",
3
+ "version": "1.1.0-alpha.10",
4
4
  "repository": "https://github.com/0xCarbon/alore-js",
5
5
  "description": "SDK for Alore Auth",
6
6
  "main": "dist/index.js",