@alore/auth-react-sdk 1.0.0-alpha → 1.0.1-alpha
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/helpers/crypto.d.ts +3 -0
- package/dist/helpers/crypto.js +33 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/types.d.ts +101 -0
- package/dist/types.js +1 -0
- package/dist/{AloreAuth.d.ts → utils/AloreAuth.d.ts} +52 -115
- package/dist/{AloreAuth.js → utils/AloreAuth.js} +135 -125
- package/dist/utils/AuthError.d.ts +29 -0
- package/dist/utils/AuthError.js +36 -0
- package/package.json +7 -6
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import argon2 from 'argon2-browser';
|
|
11
|
+
import crypto from 'crypto';
|
|
12
|
+
export function hashUserInfo(userInfo) {
|
|
13
|
+
const hash = crypto.createHash('sha256');
|
|
14
|
+
hash.update(userInfo);
|
|
15
|
+
return hash.digest('hex');
|
|
16
|
+
}
|
|
17
|
+
export function generateSecureHash(password_1, salt_1) {
|
|
18
|
+
return __awaiter(this, arguments, void 0, function* (password, salt, keyDerivationFunction = 'argon2d') {
|
|
19
|
+
if (keyDerivationFunction === 'argon2d') {
|
|
20
|
+
const result = yield argon2.hash({
|
|
21
|
+
pass: password,
|
|
22
|
+
salt,
|
|
23
|
+
type: argon2.ArgonType.Argon2d,
|
|
24
|
+
hashLen: 32,
|
|
25
|
+
mem: 32768,
|
|
26
|
+
time: 3,
|
|
27
|
+
parallelism: 2,
|
|
28
|
+
});
|
|
29
|
+
return result.encoded;
|
|
30
|
+
}
|
|
31
|
+
throw new Error('Unsupported key derivation function');
|
|
32
|
+
});
|
|
33
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './AloreAuth';
|
|
1
|
+
export * from './utils/AloreAuth';
|
|
2
|
+
export * from './helpers/crypto';
|
package/dist/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './AloreAuth';
|
|
1
|
+
export * from './utils/AloreAuth';
|
|
2
|
+
export * from './helpers/crypto';
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export type FetchWithProgressiveBackoffConfig = {
|
|
2
|
+
maxAttempts?: number;
|
|
3
|
+
initialDelay?: number;
|
|
4
|
+
};
|
|
5
|
+
export type KeyDerivationFunction = 'argon2d' | 'pbkdf2';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for Auth Provider.
|
|
8
|
+
*
|
|
9
|
+
* @property rpDomain - Optional relying party domain, used for passkey.
|
|
10
|
+
* @property locale - Optional locale for translation.
|
|
11
|
+
* @property emailTemplate - Optional email template for authentication-related emails.
|
|
12
|
+
* @property requireEmailVerification - Optional boolean to require email verification.
|
|
13
|
+
* @property requireUsername - Optional boolean to require username.
|
|
14
|
+
* @property passwordMinLength - Optional number for password minimum length.
|
|
15
|
+
* @property enablePasskeys - Optional boolean to enable passkeys.
|
|
16
|
+
* @property socialLoginEnabled - Optional boolean to enable social login.
|
|
17
|
+
* @property privacyPolicyUrl - Optional string for privacy policy URL.
|
|
18
|
+
* @property termsOfServiceUrl - Optional string for terms of service URL.
|
|
19
|
+
* @property logoUrl - Optional string for logo URL.
|
|
20
|
+
* @property socialProviders - Optional social login providers.
|
|
21
|
+
*/
|
|
22
|
+
export interface AuthProviderConfig {
|
|
23
|
+
rpDomain?: string;
|
|
24
|
+
locale?: 'pt' | 'en';
|
|
25
|
+
emailTemplate?: string;
|
|
26
|
+
requireEmailVerification?: boolean;
|
|
27
|
+
requireUsername?: boolean;
|
|
28
|
+
passwordMinLength?: number;
|
|
29
|
+
enablePasskeys?: boolean;
|
|
30
|
+
socialLoginEnabled?: boolean;
|
|
31
|
+
privacyPolicyUrl?: string;
|
|
32
|
+
termsOfServiceUrl?: string;
|
|
33
|
+
logoUrl?: string;
|
|
34
|
+
socialProviders?: SocialProvider[];
|
|
35
|
+
}
|
|
36
|
+
export interface AuthMachineContext {
|
|
37
|
+
authProviderConfigs?: AuthProviderConfig;
|
|
38
|
+
salt?: string;
|
|
39
|
+
error?: string;
|
|
40
|
+
active2fa?: TwoFactorAuth[];
|
|
41
|
+
sessionId?: string;
|
|
42
|
+
registerUser?: {
|
|
43
|
+
email: string;
|
|
44
|
+
nickname: string;
|
|
45
|
+
salt?: string;
|
|
46
|
+
};
|
|
47
|
+
forgeData?: ForgeData;
|
|
48
|
+
googleOtpCode?: string;
|
|
49
|
+
googleUser?: {
|
|
50
|
+
email: string;
|
|
51
|
+
nickname: string;
|
|
52
|
+
};
|
|
53
|
+
sessionUser?: SessionUser;
|
|
54
|
+
CCRPublicKey?: {
|
|
55
|
+
publicKey: PublicKeyCredentialCreationOptions;
|
|
56
|
+
};
|
|
57
|
+
RCRPublicKey?: {
|
|
58
|
+
publicKey: PublicKeyCredentialRequestOptions;
|
|
59
|
+
};
|
|
60
|
+
credentialEmail?: string;
|
|
61
|
+
}
|
|
62
|
+
type SessionUser = {
|
|
63
|
+
createdAt: string;
|
|
64
|
+
device: string;
|
|
65
|
+
deviceCreatedAt: string;
|
|
66
|
+
email: string;
|
|
67
|
+
id: string;
|
|
68
|
+
lastLogin: string | null;
|
|
69
|
+
lastTransaction: string | null;
|
|
70
|
+
nickname: string;
|
|
71
|
+
status: string;
|
|
72
|
+
accessToken: string;
|
|
73
|
+
refreshToken: string;
|
|
74
|
+
};
|
|
75
|
+
export type TwoFactorAuth = {
|
|
76
|
+
id: string;
|
|
77
|
+
name: string | null;
|
|
78
|
+
twoFaTypeId: number;
|
|
79
|
+
};
|
|
80
|
+
export interface ForgeData {
|
|
81
|
+
tokenAddress: string;
|
|
82
|
+
name: string;
|
|
83
|
+
symbol: string;
|
|
84
|
+
contractType: string;
|
|
85
|
+
id: string;
|
|
86
|
+
mintMethod: string;
|
|
87
|
+
maxSupply: number;
|
|
88
|
+
endTime: string;
|
|
89
|
+
contractAddress: string;
|
|
90
|
+
chainId: number;
|
|
91
|
+
}
|
|
92
|
+
export interface SocialProvider {
|
|
93
|
+
id: string;
|
|
94
|
+
authProviderConfigId: string;
|
|
95
|
+
providerName: string;
|
|
96
|
+
clientId: string;
|
|
97
|
+
enabled?: boolean;
|
|
98
|
+
createdAt: string;
|
|
99
|
+
updatedAt?: string;
|
|
100
|
+
}
|
|
101
|
+
export {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,75 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
type KeyDerivationFunction = 'argon2d' | 'pbkdf2';
|
|
3
|
-
export declare function generateSecureHash(password: string, salt: string, keyDerivationFunction?: KeyDerivationFunction): Promise<string>;
|
|
4
|
-
export interface AloreAuthConfiguration {
|
|
5
|
-
endpoint?: string;
|
|
6
|
-
emailTemplate?: string;
|
|
7
|
-
}
|
|
8
|
-
type FetchWithProgressiveBackoffConfig = {
|
|
9
|
-
maxAttempts?: number;
|
|
10
|
-
initialDelay?: number;
|
|
11
|
-
};
|
|
12
|
-
type SessionUser = {
|
|
13
|
-
createdAt: string;
|
|
14
|
-
device: string;
|
|
15
|
-
deviceCreatedAt: string;
|
|
16
|
-
email: string;
|
|
17
|
-
id: string;
|
|
18
|
-
lastLogin: string | null;
|
|
19
|
-
lastTransaction: string | null;
|
|
20
|
-
nickname: string;
|
|
21
|
-
status: string;
|
|
22
|
-
accessToken: string;
|
|
23
|
-
refreshToken: string;
|
|
24
|
-
};
|
|
25
|
-
export type TwoFactorAuth = {
|
|
26
|
-
id: string;
|
|
27
|
-
name: string | null;
|
|
28
|
-
twoFaTypeId: number;
|
|
29
|
-
};
|
|
30
|
-
interface ForgeData {
|
|
31
|
-
tokenAddress: string;
|
|
32
|
-
name: string;
|
|
33
|
-
symbol: string;
|
|
34
|
-
contractType: string;
|
|
35
|
-
id: string;
|
|
36
|
-
mintMethod: string;
|
|
37
|
-
maxSupply: number;
|
|
38
|
-
endTime: string;
|
|
39
|
-
contractAddress: string;
|
|
40
|
-
chainId: number;
|
|
41
|
-
}
|
|
42
|
-
interface AuthMachineContext {
|
|
43
|
-
salt?: string;
|
|
44
|
-
error?: string;
|
|
45
|
-
active2fa?: TwoFactorAuth[];
|
|
46
|
-
sessionId?: string;
|
|
47
|
-
registerUser?: {
|
|
48
|
-
email: string;
|
|
49
|
-
nickname: string;
|
|
50
|
-
salt?: string;
|
|
51
|
-
};
|
|
52
|
-
forgeData?: ForgeData;
|
|
53
|
-
googleOtpCode?: string;
|
|
54
|
-
googleUser?: {
|
|
55
|
-
email: string;
|
|
56
|
-
nickname: string;
|
|
57
|
-
};
|
|
58
|
-
sessionUser?: SessionUser;
|
|
59
|
-
CCRPublicKey?: {
|
|
60
|
-
publicKey: PublicKeyCredentialCreationOptions;
|
|
61
|
-
};
|
|
62
|
-
RCRPublicKey?: {
|
|
63
|
-
publicKey: PublicKeyCredentialRequestOptions;
|
|
64
|
-
};
|
|
65
|
-
credentialEmail?: string;
|
|
66
|
-
}
|
|
1
|
+
import { AuthMachineContext, AuthProviderConfig, FetchWithProgressiveBackoffConfig, ForgeData } from '../types';
|
|
67
2
|
export declare class AloreAuth {
|
|
68
|
-
readonly
|
|
69
|
-
protected readonly endpoint: string;
|
|
3
|
+
protected readonly aloreBaseUrl: string;
|
|
70
4
|
protected readonly emailTemplate: string;
|
|
71
|
-
|
|
5
|
+
protected readonly clientId: string;
|
|
6
|
+
constructor(clientId: string, aloreBaseUrl?: string, config?: AuthProviderConfig);
|
|
72
7
|
services: {
|
|
8
|
+
healthCheck: () => Promise<{
|
|
9
|
+
data: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
retrieveSalt: (context: AuthMachineContext, event: {
|
|
12
|
+
type: 'SELECT_PASSWORD';
|
|
13
|
+
payload: {
|
|
14
|
+
email: string;
|
|
15
|
+
};
|
|
16
|
+
}) => Promise<{
|
|
17
|
+
salt: string;
|
|
18
|
+
error?: undefined;
|
|
19
|
+
} | {
|
|
20
|
+
error: string;
|
|
21
|
+
salt?: undefined;
|
|
22
|
+
}>;
|
|
23
|
+
verifyEmail: (context: AuthMachineContext, event: {
|
|
24
|
+
type: 'VERIFY_EMAIL';
|
|
25
|
+
payload: {
|
|
26
|
+
secureCode: string;
|
|
27
|
+
};
|
|
28
|
+
}) => Promise<{}>;
|
|
73
29
|
completeRegistration: (context: AuthMachineContext, event: {
|
|
74
30
|
type: 'COMPLETE_REGISTRATION';
|
|
75
31
|
payload: {
|
|
@@ -117,18 +73,6 @@ export declare class AloreAuth {
|
|
|
117
73
|
salt?: undefined;
|
|
118
74
|
sessionId?: undefined;
|
|
119
75
|
}>;
|
|
120
|
-
retrieveSalt: (context: AuthMachineContext, _event: {
|
|
121
|
-
type: 'SELECT_PASSWORD';
|
|
122
|
-
payload: {
|
|
123
|
-
email: string;
|
|
124
|
-
};
|
|
125
|
-
}) => Promise<{
|
|
126
|
-
salt: string;
|
|
127
|
-
error?: undefined;
|
|
128
|
-
} | {
|
|
129
|
-
error: string;
|
|
130
|
-
salt?: undefined;
|
|
131
|
-
}>;
|
|
132
76
|
sendCode: (context: AuthMachineContext, event: {
|
|
133
77
|
type: 'SEND_CODE';
|
|
134
78
|
payload: {
|
|
@@ -139,7 +83,27 @@ export declare class AloreAuth {
|
|
|
139
83
|
} | {
|
|
140
84
|
error?: undefined;
|
|
141
85
|
}>;
|
|
142
|
-
|
|
86
|
+
verifyLogin: (_: AuthMachineContext, event: {
|
|
87
|
+
type: 'VERIFY_LOGIN';
|
|
88
|
+
payload: {
|
|
89
|
+
email: string;
|
|
90
|
+
device: string;
|
|
91
|
+
passwordHash: string;
|
|
92
|
+
isForgeClaim?: boolean | undefined;
|
|
93
|
+
locale?: string | undefined;
|
|
94
|
+
};
|
|
95
|
+
} | {
|
|
96
|
+
type: 'RESEND_CODE';
|
|
97
|
+
payload: {
|
|
98
|
+
email: string;
|
|
99
|
+
nickname?: string | undefined;
|
|
100
|
+
device?: string | undefined;
|
|
101
|
+
passwordHash?: string | undefined;
|
|
102
|
+
isForgeClaim?: boolean | undefined;
|
|
103
|
+
locale?: string | undefined;
|
|
104
|
+
};
|
|
105
|
+
}) => Promise<any>;
|
|
106
|
+
startRegisterPasskey: (context: AuthMachineContext, event: {
|
|
143
107
|
type: 'START_PASSKEY_REGISTER';
|
|
144
108
|
payload: {
|
|
145
109
|
device: string;
|
|
@@ -164,6 +128,12 @@ export declare class AloreAuth {
|
|
|
164
128
|
device: string;
|
|
165
129
|
};
|
|
166
130
|
}) => Promise<any>;
|
|
131
|
+
startPasskeyAuth: (context: AuthMachineContext, event: {
|
|
132
|
+
type: 'START_PASSKEY_LOGIN';
|
|
133
|
+
payload: {
|
|
134
|
+
email: string;
|
|
135
|
+
};
|
|
136
|
+
}) => Promise<any>;
|
|
167
137
|
finishPasskeyAuth: (context: AuthMachineContext, event: {
|
|
168
138
|
type: 'FINISH_PASSKEY_LOGIN';
|
|
169
139
|
payload: {
|
|
@@ -195,32 +165,6 @@ export declare class AloreAuth {
|
|
|
195
165
|
};
|
|
196
166
|
};
|
|
197
167
|
}) => Promise<any>;
|
|
198
|
-
startPasskeyAuth: (_: AuthMachineContext, event: {
|
|
199
|
-
type: 'START_PASSKEY_LOGIN';
|
|
200
|
-
payload: {
|
|
201
|
-
email: string;
|
|
202
|
-
};
|
|
203
|
-
}) => Promise<any>;
|
|
204
|
-
verifyLogin: (_: AuthMachineContext, event: {
|
|
205
|
-
type: 'VERIFY_LOGIN';
|
|
206
|
-
payload: {
|
|
207
|
-
email: string;
|
|
208
|
-
device: string;
|
|
209
|
-
passwordHash: string;
|
|
210
|
-
isForgeClaim?: boolean | undefined;
|
|
211
|
-
locale?: string | undefined;
|
|
212
|
-
};
|
|
213
|
-
} | {
|
|
214
|
-
type: 'RESEND_CODE';
|
|
215
|
-
payload: {
|
|
216
|
-
email: string;
|
|
217
|
-
nickname?: string | undefined;
|
|
218
|
-
device?: string | undefined;
|
|
219
|
-
passwordHash?: string | undefined;
|
|
220
|
-
isForgeClaim?: boolean | undefined;
|
|
221
|
-
locale?: string | undefined;
|
|
222
|
-
};
|
|
223
|
-
}) => Promise<any>;
|
|
224
168
|
verify2faCode: (_context: AuthMachineContext, event: {
|
|
225
169
|
type: 'CONFIRM_SW_CODE';
|
|
226
170
|
payload: {
|
|
@@ -248,12 +192,6 @@ export declare class AloreAuth {
|
|
|
248
192
|
secureCode: string;
|
|
249
193
|
};
|
|
250
194
|
}) => Promise<any>;
|
|
251
|
-
verifyEmail: (context: AuthMachineContext, event: {
|
|
252
|
-
type: 'VERIFY_EMAIL';
|
|
253
|
-
payload: {
|
|
254
|
-
secureCode: string;
|
|
255
|
-
};
|
|
256
|
-
}) => Promise<{}>;
|
|
257
195
|
verifyEmail2fa: (context: AuthMachineContext, event: {
|
|
258
196
|
type: 'VERIFY_EMAIL_2FA';
|
|
259
197
|
payload: {
|
|
@@ -325,4 +263,3 @@ export declare class AloreAuth {
|
|
|
325
263
|
fetchWithProgressiveBackoff(url: RequestInfo | URL, options?: RequestInit, config?: FetchWithProgressiveBackoffConfig): Promise<Response>;
|
|
326
264
|
private verifyBackendStatus;
|
|
327
265
|
}
|
|
328
|
-
export {};
|
|
@@ -8,38 +8,57 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { startAuthentication } from '@simplewebauthn/browser';
|
|
11
|
-
import
|
|
12
|
-
import crypto from 'crypto';
|
|
13
|
-
export function hashUserInfo(userInfo) {
|
|
14
|
-
const hash = crypto.createHash('sha256');
|
|
15
|
-
hash.update(userInfo);
|
|
16
|
-
return hash.digest('hex');
|
|
17
|
-
}
|
|
18
|
-
export function generateSecureHash(password_1, salt_1) {
|
|
19
|
-
return __awaiter(this, arguments, void 0, function* (password, salt, keyDerivationFunction = 'argon2d') {
|
|
20
|
-
if (keyDerivationFunction === 'argon2d') {
|
|
21
|
-
const result = yield argon2.hash({
|
|
22
|
-
pass: password,
|
|
23
|
-
salt,
|
|
24
|
-
type: argon2.ArgonType.Argon2d,
|
|
25
|
-
hashLen: 32,
|
|
26
|
-
mem: 32768,
|
|
27
|
-
time: 3,
|
|
28
|
-
parallelism: 2,
|
|
29
|
-
});
|
|
30
|
-
return result.encoded;
|
|
31
|
-
}
|
|
32
|
-
throw new Error('Unsupported key derivation function');
|
|
33
|
-
});
|
|
34
|
-
}
|
|
11
|
+
import { AloreAuthError, ErrorTypes } from './AuthError';
|
|
35
12
|
const DEFAULT_URL = 'https://alpha-api.bealore.com/v1';
|
|
36
13
|
export class AloreAuth {
|
|
37
|
-
constructor(
|
|
38
|
-
this.apiKey = apiKey;
|
|
14
|
+
constructor(clientId, aloreBaseUrl, config) {
|
|
39
15
|
this.services = {
|
|
16
|
+
healthCheck: () => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
try {
|
|
18
|
+
yield this.verifyBackendStatus();
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
throw new AloreAuthError(ErrorTypes.SERVER_DOWN, 'Server is down');
|
|
22
|
+
}
|
|
23
|
+
return { data: true };
|
|
24
|
+
}),
|
|
25
|
+
// Email and password flow
|
|
26
|
+
retrieveSalt: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const { email } = event.payload;
|
|
28
|
+
const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/salt/${email}`, {
|
|
29
|
+
headers: {
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
if (response.ok) {
|
|
34
|
+
const salt = yield response.json();
|
|
35
|
+
return { salt };
|
|
36
|
+
}
|
|
37
|
+
return { error: response === null || response === void 0 ? void 0 : response.statusText };
|
|
38
|
+
}),
|
|
39
|
+
verifyEmail: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const { secureCode } = event.payload;
|
|
41
|
+
const response = yield this.fetchWithProgressiveBackoff('/auth/v1/registration-code-verification', {
|
|
42
|
+
method: 'POST',
|
|
43
|
+
headers: {
|
|
44
|
+
'Content-Type': 'application/json',
|
|
45
|
+
},
|
|
46
|
+
body: JSON.stringify({
|
|
47
|
+
emailCode: secureCode,
|
|
48
|
+
sessionId: context.sessionId,
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
const data = yield response.json();
|
|
53
|
+
throw new Error((data === null || data === void 0 ? void 0 : data.message) || (data === null || data === void 0 ? void 0 : data.error) || data);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
}),
|
|
40
59
|
completeRegistration: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
41
60
|
const { email, nickname, passwordHash, device } = event.payload;
|
|
42
|
-
const response = yield this.fetchWithProgressiveBackoff('/auth/account-registration', {
|
|
61
|
+
const response = yield this.fetchWithProgressiveBackoff('/auth/v1/account-registration', {
|
|
43
62
|
method: 'POST',
|
|
44
63
|
headers: {
|
|
45
64
|
'Content-Type': 'application/json',
|
|
@@ -58,7 +77,7 @@ export class AloreAuth {
|
|
|
58
77
|
}),
|
|
59
78
|
confirmPassword: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
60
79
|
const { email, passwordHash } = event.payload;
|
|
61
|
-
const response = yield this.fetchWithProgressiveBackoff(`/auth/password-creation`, {
|
|
80
|
+
const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/password-creation`, {
|
|
62
81
|
method: 'POST',
|
|
63
82
|
headers: {
|
|
64
83
|
'Content-Type': 'application/json',
|
|
@@ -75,7 +94,7 @@ export class AloreAuth {
|
|
|
75
94
|
sendConfirmationEmail: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
76
95
|
const { email, nickname, locale } = event.payload;
|
|
77
96
|
const searchParams = new URLSearchParams();
|
|
78
|
-
const url = '/auth/confirmation-email';
|
|
97
|
+
const url = '/auth/v1/confirmation-email';
|
|
79
98
|
if (locale) {
|
|
80
99
|
searchParams.append('locale', locale);
|
|
81
100
|
}
|
|
@@ -103,19 +122,6 @@ export class AloreAuth {
|
|
|
103
122
|
}
|
|
104
123
|
return { error: response === null || response === void 0 ? void 0 : response.statusText };
|
|
105
124
|
}),
|
|
106
|
-
retrieveSalt: (context, _event) => __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
const { credentialEmail: email } = context;
|
|
108
|
-
const response = yield this.fetchWithProgressiveBackoff(`/auth/salt/${email}`, {
|
|
109
|
-
headers: {
|
|
110
|
-
'Content-Type': 'application/json',
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
if (response.ok) {
|
|
114
|
-
const salt = yield response.json();
|
|
115
|
-
return { salt };
|
|
116
|
-
}
|
|
117
|
-
return { error: response === null || response === void 0 ? void 0 : response.statusText };
|
|
118
|
-
}),
|
|
119
125
|
sendCode: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
120
126
|
const { email } = event.payload;
|
|
121
127
|
const response = yield this.fetchWithProgressiveBackoff(`/reset-password`, {
|
|
@@ -131,9 +137,47 @@ export class AloreAuth {
|
|
|
131
137
|
return { error: response === null || response === void 0 ? void 0 : response.statusText };
|
|
132
138
|
return {};
|
|
133
139
|
}),
|
|
134
|
-
|
|
140
|
+
verifyLogin: (_, event) => __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
var _a, _b;
|
|
142
|
+
const { email, passwordHash, device, locale } = event.payload;
|
|
143
|
+
const searchParams = new URLSearchParams();
|
|
144
|
+
const url = '/auth/v1/login-verification';
|
|
145
|
+
if (locale) {
|
|
146
|
+
searchParams.append('locale', locale);
|
|
147
|
+
}
|
|
148
|
+
if (this.emailTemplate !== '') {
|
|
149
|
+
searchParams.append('template', this.emailTemplate);
|
|
150
|
+
}
|
|
151
|
+
const response = yield this.fetchWithProgressiveBackoff(searchParams.size > 0 ? `${url}?${searchParams.toString()}` : url, {
|
|
152
|
+
method: 'POST',
|
|
153
|
+
headers: {
|
|
154
|
+
'Content-Type': 'application/json',
|
|
155
|
+
},
|
|
156
|
+
body: JSON.stringify({
|
|
157
|
+
email,
|
|
158
|
+
passwordHash,
|
|
159
|
+
device,
|
|
160
|
+
}),
|
|
161
|
+
});
|
|
162
|
+
const data = yield response.json();
|
|
163
|
+
if (!response.ok) {
|
|
164
|
+
if (response.status === 403) {
|
|
165
|
+
return { active2fa: data };
|
|
166
|
+
}
|
|
167
|
+
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'))) {
|
|
168
|
+
return { error: data === null || data === void 0 ? void 0 : data.error };
|
|
169
|
+
}
|
|
170
|
+
throw new Error((data === null || data === void 0 ? void 0 : data.message) || (data === null || data === void 0 ? void 0 : data.error) || data);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
return data;
|
|
174
|
+
}
|
|
175
|
+
}),
|
|
176
|
+
// Passkey registration flow
|
|
177
|
+
startRegisterPasskey: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
const { rpDomain } = context.authProviderConfigs || {};
|
|
135
179
|
const { email, nickname, device } = event.payload;
|
|
136
|
-
const startPasskeyRegistrationResponse = yield this.fetchWithProgressiveBackoff(
|
|
180
|
+
const startPasskeyRegistrationResponse = yield this.fetchWithProgressiveBackoff('/auth/v1/account-registration-passkey', {
|
|
137
181
|
method: 'POST',
|
|
138
182
|
headers: {
|
|
139
183
|
'Content-Type': 'application/json',
|
|
@@ -142,14 +186,16 @@ export class AloreAuth {
|
|
|
142
186
|
userEmail: email,
|
|
143
187
|
userNickname: nickname,
|
|
144
188
|
userDevice: device,
|
|
189
|
+
rpOrigin: rpDomain,
|
|
145
190
|
}),
|
|
146
191
|
});
|
|
147
192
|
const data = yield startPasskeyRegistrationResponse.json();
|
|
148
193
|
return data;
|
|
149
194
|
}),
|
|
150
195
|
finishRegisterPasskey: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
196
|
+
const { rpDomain } = context.authProviderConfigs || {};
|
|
151
197
|
const { email, nickname, device, passkeyRegistration } = event.payload;
|
|
152
|
-
const response = yield this.fetchWithProgressiveBackoff(
|
|
198
|
+
const response = yield this.fetchWithProgressiveBackoff('/auth/v1/account-registration-passkey-finish', {
|
|
153
199
|
method: 'POST',
|
|
154
200
|
headers: {
|
|
155
201
|
'Content-Type': 'application/json',
|
|
@@ -160,73 +206,55 @@ export class AloreAuth {
|
|
|
160
206
|
userDevice: device,
|
|
161
207
|
passkeyRegistration,
|
|
162
208
|
sessionId: context.sessionId,
|
|
209
|
+
rpOrigin: rpDomain,
|
|
163
210
|
}),
|
|
164
211
|
});
|
|
165
212
|
const data = yield response.json();
|
|
166
213
|
if (response.ok)
|
|
167
214
|
return data;
|
|
168
215
|
}),
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const email = event.type === 'START_PASSKEY_LOGIN' ? (_a = event.payload) === null || _a === void 0 ? void 0 : _a.email : undefined;
|
|
185
|
-
const url = `/auth/login-passkey${email ? `?email=${encodeURIComponent(email)}` : ''}`;
|
|
186
|
-
const startAuthResponse = yield this.fetchWithProgressiveBackoff(url);
|
|
216
|
+
// Passkey login flow
|
|
217
|
+
startPasskeyAuth: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
var _c;
|
|
219
|
+
const { rpDomain } = context.authProviderConfigs || {};
|
|
220
|
+
const email = event.type === 'START_PASSKEY_LOGIN' ? (_c = event.payload) === null || _c === void 0 ? void 0 : _c.email : undefined;
|
|
221
|
+
const searchParams = new URLSearchParams();
|
|
222
|
+
const url = '/auth/v1/login-passkey';
|
|
223
|
+
if (rpDomain) {
|
|
224
|
+
searchParams.append('rp_origin', rpDomain);
|
|
225
|
+
}
|
|
226
|
+
if (email) {
|
|
227
|
+
searchParams.append('email', encodeURIComponent(email));
|
|
228
|
+
}
|
|
229
|
+
const urlWithParams = `${url}?${searchParams.toString()}`;
|
|
230
|
+
const startAuthResponse = yield this.fetchWithProgressiveBackoff(urlWithParams);
|
|
187
231
|
const data = yield startAuthResponse.json();
|
|
188
232
|
if (startAuthResponse.ok)
|
|
189
233
|
return data;
|
|
190
234
|
}),
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const {
|
|
194
|
-
const
|
|
195
|
-
const url = '/auth/login-verification';
|
|
196
|
-
if (locale) {
|
|
197
|
-
searchParams.append('locale', locale);
|
|
198
|
-
}
|
|
199
|
-
if (this.emailTemplate !== '') {
|
|
200
|
-
searchParams.append('template', this.emailTemplate);
|
|
201
|
-
}
|
|
202
|
-
const response = yield this.fetchWithProgressiveBackoff(searchParams.size > 0 ? `${url}?${searchParams.toString()}` : url, {
|
|
235
|
+
finishPasskeyAuth: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
236
|
+
const { rpDomain } = context.authProviderConfigs || {};
|
|
237
|
+
const { passkeyAuth } = event.payload;
|
|
238
|
+
const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/login-passkey-finish`, {
|
|
203
239
|
method: 'POST',
|
|
204
240
|
headers: {
|
|
205
241
|
'Content-Type': 'application/json',
|
|
206
242
|
},
|
|
207
243
|
body: JSON.stringify({
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
244
|
+
passkeyAuth,
|
|
245
|
+
sessionId: context.sessionId,
|
|
246
|
+
rpOrigin: rpDomain,
|
|
211
247
|
}),
|
|
212
248
|
});
|
|
213
249
|
const data = yield response.json();
|
|
214
|
-
if (
|
|
215
|
-
if (response.status === 403) {
|
|
216
|
-
return { active2fa: data };
|
|
217
|
-
}
|
|
218
|
-
if (((_b = data === null || data === void 0 ? void 0 : data.error) === null || _b === void 0 ? void 0 : _b.includes('2FA')) || ((_c = data === null || data === void 0 ? void 0 : data.error) === null || _c === void 0 ? void 0 : _c.includes('device'))) {
|
|
219
|
-
return { error: data === null || data === void 0 ? void 0 : data.error };
|
|
220
|
-
}
|
|
221
|
-
throw new Error((data === null || data === void 0 ? void 0 : data.message) || (data === null || data === void 0 ? void 0 : data.error) || data);
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
250
|
+
if (response.ok)
|
|
224
251
|
return data;
|
|
225
|
-
|
|
252
|
+
throw new AloreAuthError(ErrorTypes.FAILED_TO_FETCH, data.message || data.error || data);
|
|
226
253
|
}),
|
|
254
|
+
// Hardware 2FA flow
|
|
227
255
|
verify2faCode: (_context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
228
256
|
const { email, passwordHash, device, otp } = event.payload;
|
|
229
|
-
const response = yield this.fetchWithProgressiveBackoff('/auth/sw-2fa-verification', {
|
|
257
|
+
const response = yield this.fetchWithProgressiveBackoff('/auth/v1/sw-2fa-verification', {
|
|
230
258
|
method: 'POST',
|
|
231
259
|
headers: {
|
|
232
260
|
'Content-Type': 'application/json',
|
|
@@ -245,7 +273,7 @@ export class AloreAuth {
|
|
|
245
273
|
}),
|
|
246
274
|
authenticateWebauthn: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
247
275
|
const { email, passwordHash, device, authId } = event.payload;
|
|
248
|
-
const optionsResponse = yield this.fetchWithProgressiveBackoff('/auth/hw-2fa-start-verification', {
|
|
276
|
+
const optionsResponse = yield this.fetchWithProgressiveBackoff('/auth/v1/hw-2fa-start-verification', {
|
|
249
277
|
method: 'POST',
|
|
250
278
|
headers: {
|
|
251
279
|
'Content-Type': 'application/json',
|
|
@@ -263,7 +291,7 @@ export class AloreAuth {
|
|
|
263
291
|
const credential = yield startAuthentication(optionsData.requestChallengeResponse.publicKey).catch((err) => {
|
|
264
292
|
throw new Error(err);
|
|
265
293
|
});
|
|
266
|
-
const response = yield this.fetchWithProgressiveBackoff('/auth/hw-2fa-finish-verification', {
|
|
294
|
+
const response = yield this.fetchWithProgressiveBackoff('/auth/v1/hw-2fa-finish-verification', {
|
|
267
295
|
method: 'POST',
|
|
268
296
|
headers: {
|
|
269
297
|
'Content-Type': 'application/json',
|
|
@@ -283,7 +311,7 @@ export class AloreAuth {
|
|
|
283
311
|
}),
|
|
284
312
|
verifyDeviceCode: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
285
313
|
const { email, passwordHash, device, secureCode } = event.payload;
|
|
286
|
-
const response = yield this.fetchWithProgressiveBackoff('/auth/device-ownership-verification', {
|
|
314
|
+
const response = yield this.fetchWithProgressiveBackoff('/auth/v1/device-ownership-verification', {
|
|
287
315
|
method: 'POST',
|
|
288
316
|
headers: {
|
|
289
317
|
'Content-Type': 'application/json',
|
|
@@ -301,29 +329,9 @@ export class AloreAuth {
|
|
|
301
329
|
return data;
|
|
302
330
|
throw new Error(data.message || data.error || 'Authentication failed');
|
|
303
331
|
}),
|
|
304
|
-
verifyEmail: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
305
|
-
const { secureCode } = event.payload;
|
|
306
|
-
const response = yield this.fetchWithProgressiveBackoff('/auth/registration-code-verification', {
|
|
307
|
-
method: 'POST',
|
|
308
|
-
headers: {
|
|
309
|
-
'Content-Type': 'application/json',
|
|
310
|
-
},
|
|
311
|
-
body: JSON.stringify({
|
|
312
|
-
emailCode: secureCode,
|
|
313
|
-
sessionId: context.sessionId,
|
|
314
|
-
}),
|
|
315
|
-
});
|
|
316
|
-
if (!response.ok) {
|
|
317
|
-
const data = yield response.json();
|
|
318
|
-
throw new Error((data === null || data === void 0 ? void 0 : data.message) || (data === null || data === void 0 ? void 0 : data.error) || data);
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
return {};
|
|
322
|
-
}
|
|
323
|
-
}),
|
|
324
332
|
verifyEmail2fa: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
325
333
|
const { email, passwordHash, secureCode } = event.payload;
|
|
326
|
-
const response = yield this.fetchWithProgressiveBackoff('/auth/email-2fa-verification', {
|
|
334
|
+
const response = yield this.fetchWithProgressiveBackoff('/auth/v1/email-2fa-verification', {
|
|
327
335
|
method: 'POST',
|
|
328
336
|
body: JSON.stringify({
|
|
329
337
|
email,
|
|
@@ -342,7 +350,7 @@ export class AloreAuth {
|
|
|
342
350
|
}),
|
|
343
351
|
verifyEmailEligibility: (_, event) => __awaiter(this, void 0, void 0, function* () {
|
|
344
352
|
const { email } = event;
|
|
345
|
-
const response = yield this.fetchWithProgressiveBackoff('/auth/email-eligibility-verification', {
|
|
353
|
+
const response = yield this.fetchWithProgressiveBackoff('/auth/v1/email-eligibility-verification', {
|
|
346
354
|
method: 'POST',
|
|
347
355
|
headers: {
|
|
348
356
|
'Content-Type': 'application/json',
|
|
@@ -358,7 +366,7 @@ export class AloreAuth {
|
|
|
358
366
|
}),
|
|
359
367
|
verifyClaimNftEmail2fa: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
360
368
|
const { email, emailCode } = event.payload;
|
|
361
|
-
const response = yield this.fetchWithProgressiveBackoff('/auth/eligible-email-code-verification', {
|
|
369
|
+
const response = yield this.fetchWithProgressiveBackoff('/auth/v1/eligible-email-code-verification', {
|
|
362
370
|
method: 'POST',
|
|
363
371
|
body: JSON.stringify({
|
|
364
372
|
email,
|
|
@@ -382,9 +390,10 @@ export class AloreAuth {
|
|
|
382
390
|
}
|
|
383
391
|
return data;
|
|
384
392
|
}),
|
|
393
|
+
// Google login flow
|
|
385
394
|
googleLogin: (_, event) => __awaiter(this, void 0, void 0, function* () {
|
|
386
395
|
const { googleToken } = event;
|
|
387
|
-
const response = yield this.fetchWithProgressiveBackoff('/auth/google-login', {
|
|
396
|
+
const response = yield this.fetchWithProgressiveBackoff('/auth/v1/google-login', {
|
|
388
397
|
method: 'POST',
|
|
389
398
|
headers: {
|
|
390
399
|
'Content-Type': 'application/json',
|
|
@@ -422,7 +431,7 @@ export class AloreAuth {
|
|
|
422
431
|
}),
|
|
423
432
|
verifyGoogleLogin: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
424
433
|
const { email, passwordHash, otp } = event.payload;
|
|
425
|
-
const response = yield this.fetchWithProgressiveBackoff('/auth/google-2fa-verification', {
|
|
434
|
+
const response = yield this.fetchWithProgressiveBackoff('/auth/v1/google-2fa-verification', {
|
|
426
435
|
method: 'POST',
|
|
427
436
|
body: JSON.stringify({
|
|
428
437
|
email,
|
|
@@ -440,10 +449,11 @@ export class AloreAuth {
|
|
|
440
449
|
throw new Error(data.message || data.error || 'Authentication failed');
|
|
441
450
|
}),
|
|
442
451
|
};
|
|
443
|
-
if (!
|
|
444
|
-
throw new
|
|
445
|
-
this.
|
|
446
|
-
this.
|
|
452
|
+
if (!clientId)
|
|
453
|
+
throw new AloreAuthError(ErrorTypes.CLIENT_ID_REQUIRED, 'Client ID is required');
|
|
454
|
+
this.clientId = clientId;
|
|
455
|
+
this.aloreBaseUrl = aloreBaseUrl || DEFAULT_URL;
|
|
456
|
+
this.emailTemplate = (config === null || config === void 0 ? void 0 : config.emailTemplate) || '';
|
|
447
457
|
}
|
|
448
458
|
// eslint-disable-next-line class-methods-use-this
|
|
449
459
|
delay(ms) {
|
|
@@ -462,7 +472,7 @@ export class AloreAuth {
|
|
|
462
472
|
let attempt = 0;
|
|
463
473
|
let delayValue = initialDelay;
|
|
464
474
|
// eslint-disable-next-line no-undef
|
|
465
|
-
const init = Object.assign(Object.assign({}, options), { credentials: 'include', headers: Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.headers), { 'X-
|
|
475
|
+
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' }) });
|
|
466
476
|
while (attempt < maxAttempts) {
|
|
467
477
|
if (attempt > 0) {
|
|
468
478
|
// eslint-disable-next-line no-await-in-loop, no-promise-executor-return, no-loop-func
|
|
@@ -472,7 +482,7 @@ export class AloreAuth {
|
|
|
472
482
|
attempt += 1;
|
|
473
483
|
try {
|
|
474
484
|
// eslint-disable-next-line no-await-in-loop
|
|
475
|
-
const response = yield fetch(new URL(`${this.
|
|
485
|
+
const response = yield fetch(new URL(`${this.aloreBaseUrl}${url}`), init);
|
|
476
486
|
if (response.ok || attempt === maxAttempts || response.status !== 500) {
|
|
477
487
|
return response;
|
|
478
488
|
}
|
|
@@ -496,7 +506,7 @@ export class AloreAuth {
|
|
|
496
506
|
verifyBackendStatus() {
|
|
497
507
|
return __awaiter(this, void 0, void 0, function* () {
|
|
498
508
|
try {
|
|
499
|
-
const res = yield fetch(`${this.
|
|
509
|
+
const res = yield fetch(`${this.aloreBaseUrl}/health-check`);
|
|
500
510
|
if (!res.ok) {
|
|
501
511
|
throw new Error('Failed to fetch');
|
|
502
512
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare enum ErrorCodes {
|
|
2
|
+
BAD_REQUEST = 400,
|
|
3
|
+
FORBIDDEN = 403,
|
|
4
|
+
TOO_MANY_REQUESTS = 429
|
|
5
|
+
}
|
|
6
|
+
export declare enum ErrorTypes {
|
|
7
|
+
CLIENT_ID_REQUIRED = "CLIENT_ID_REQUIRED",
|
|
8
|
+
PASSKEY_NOT_SUPPORTED = "PASSKEY_NOT_SUPPORTED",
|
|
9
|
+
USER_ALREADY_EXISTS = "USER_ALREADY_EXISTS",
|
|
10
|
+
FAILED_TO_FETCH = "FAILED_TO_FETCH",
|
|
11
|
+
SERVER_DOWN = "SERVER_DOWN",
|
|
12
|
+
BAD_RESPONSE = "BAD_RESPONSE",
|
|
13
|
+
UNKNOWN_ERROR = "UNKNOWN_ERROR",
|
|
14
|
+
INVALID_CREDENTIALS = "INVALID_CREDENTIALS",
|
|
15
|
+
WRONG_2FA_CODE = "WRONG_2FA_CODE",
|
|
16
|
+
INVALID_EMAIL_PASSWORD = "INVALID_EMAIL_PASSWORD",
|
|
17
|
+
PUBLIC_KEY_CREATION_OPTIONS_UNDEFINED = "PUBLIC_KEY_CREATION_OPTIONS_UNDEFINED",
|
|
18
|
+
CREATE_SECRET_FROM_CREDENTIAL_FAILED = "CREATE_SECRET_FROM_CREDENTIAL_FAILED",
|
|
19
|
+
PASSKEY_GET_ERROR = "PASSKEY_GET_ERROR",
|
|
20
|
+
PASSKEY_CREATE_ERROR = "PASSKEY_CREATE_ERROR",
|
|
21
|
+
PRF_EXTENSION_NOT_SUPPORTED = "PRF_EXTENSION_NOT_SUPPORTED",
|
|
22
|
+
LARGE_BLOB_EXTENSION_NOT_SUPPORTED = "LARGE_BLOB_EXTENSION_NOT_SUPPORTED",
|
|
23
|
+
TOO_MANY_REQUESTS = "TOO_MANY_REQUESTS"
|
|
24
|
+
}
|
|
25
|
+
export declare class AloreAuthError extends Error {
|
|
26
|
+
type: ErrorTypes;
|
|
27
|
+
code?: number;
|
|
28
|
+
constructor(type: ErrorTypes, message: string, code?: number);
|
|
29
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
|
2
|
+
export var ErrorCodes;
|
|
3
|
+
(function (ErrorCodes) {
|
|
4
|
+
ErrorCodes[ErrorCodes["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
5
|
+
ErrorCodes[ErrorCodes["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
6
|
+
ErrorCodes[ErrorCodes["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
7
|
+
})(ErrorCodes || (ErrorCodes = {}));
|
|
8
|
+
export var ErrorTypes;
|
|
9
|
+
(function (ErrorTypes) {
|
|
10
|
+
ErrorTypes["CLIENT_ID_REQUIRED"] = "CLIENT_ID_REQUIRED";
|
|
11
|
+
ErrorTypes["PASSKEY_NOT_SUPPORTED"] = "PASSKEY_NOT_SUPPORTED";
|
|
12
|
+
ErrorTypes["USER_ALREADY_EXISTS"] = "USER_ALREADY_EXISTS";
|
|
13
|
+
ErrorTypes["FAILED_TO_FETCH"] = "FAILED_TO_FETCH";
|
|
14
|
+
ErrorTypes["SERVER_DOWN"] = "SERVER_DOWN";
|
|
15
|
+
ErrorTypes["BAD_RESPONSE"] = "BAD_RESPONSE";
|
|
16
|
+
ErrorTypes["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
17
|
+
ErrorTypes["INVALID_CREDENTIALS"] = "INVALID_CREDENTIALS";
|
|
18
|
+
ErrorTypes["WRONG_2FA_CODE"] = "WRONG_2FA_CODE";
|
|
19
|
+
ErrorTypes["INVALID_EMAIL_PASSWORD"] = "INVALID_EMAIL_PASSWORD";
|
|
20
|
+
ErrorTypes["PUBLIC_KEY_CREATION_OPTIONS_UNDEFINED"] = "PUBLIC_KEY_CREATION_OPTIONS_UNDEFINED";
|
|
21
|
+
ErrorTypes["CREATE_SECRET_FROM_CREDENTIAL_FAILED"] = "CREATE_SECRET_FROM_CREDENTIAL_FAILED";
|
|
22
|
+
ErrorTypes["PASSKEY_GET_ERROR"] = "PASSKEY_GET_ERROR";
|
|
23
|
+
ErrorTypes["PASSKEY_CREATE_ERROR"] = "PASSKEY_CREATE_ERROR";
|
|
24
|
+
ErrorTypes["PRF_EXTENSION_NOT_SUPPORTED"] = "PRF_EXTENSION_NOT_SUPPORTED";
|
|
25
|
+
ErrorTypes["LARGE_BLOB_EXTENSION_NOT_SUPPORTED"] = "LARGE_BLOB_EXTENSION_NOT_SUPPORTED";
|
|
26
|
+
ErrorTypes["TOO_MANY_REQUESTS"] = "TOO_MANY_REQUESTS";
|
|
27
|
+
})(ErrorTypes || (ErrorTypes = {}));
|
|
28
|
+
export class AloreAuthError extends Error {
|
|
29
|
+
constructor(type, message, code) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = 'AloreAuthError';
|
|
32
|
+
this.type = type;
|
|
33
|
+
this.code = code;
|
|
34
|
+
Object.setPrototypeOf(this, AloreAuthError.prototype);
|
|
35
|
+
}
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alore/auth-react-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-alpha",
|
|
4
4
|
"repository": "https://github.com/0xCarbon/alore-js",
|
|
5
5
|
"description": "SDK for Alore Auth",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
"default": "./dist/index.js"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"prepare": "pnpm build",
|
|
19
|
+
"build": "rm -rf dist/* && tsc"
|
|
20
|
+
},
|
|
17
21
|
"author": "0xCarbon",
|
|
18
22
|
"license": "LGPL-2.1-only",
|
|
19
23
|
"engines": {
|
|
@@ -32,8 +36,5 @@
|
|
|
32
36
|
"@types/node": "20.4.8",
|
|
33
37
|
"typescript": "5.4.5"
|
|
34
38
|
},
|
|
35
|
-
"packageManager": "pnpm@8.15.7+sha512.c85cd21b6da10332156b1ca2aa79c0a61ee7ad2eb0453b88ab299289e9e8ca93e6091232b25c07cbf61f6df77128d9c849e5c9ac6e44854dbd211c49f3a67adc"
|
|
36
|
-
|
|
37
|
-
"build": "rm -rf dist/* && tsc"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
39
|
+
"packageManager": "pnpm@8.15.7+sha512.c85cd21b6da10332156b1ca2aa79c0a61ee7ad2eb0453b88ab299289e9e8ca93e6091232b25c07cbf61f6df77128d9c849e5c9ac6e44854dbd211c49f3a67adc"
|
|
40
|
+
}
|