@fourt/sdk 1.2.2 → 1.3.0
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.cjs +227 -90
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +120 -14
- package/dist/index.d.ts +120 -14
- package/dist/index.js +234 -90
- package/dist/index.js.map +1 -1
- package/package.json +3 -9
package/dist/index.d.ts
CHANGED
|
@@ -120,6 +120,38 @@ type AuthenticationServiceEndpoints = [
|
|
|
120
120
|
subOrgId: string;
|
|
121
121
|
};
|
|
122
122
|
},
|
|
123
|
+
{
|
|
124
|
+
Route: '/v1/email-auth';
|
|
125
|
+
Body: {};
|
|
126
|
+
Response: {
|
|
127
|
+
method: string;
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
Route: '/v1/otp-auth';
|
|
132
|
+
Body: AtLeastOne<{
|
|
133
|
+
init: {
|
|
134
|
+
email: string;
|
|
135
|
+
};
|
|
136
|
+
auth: {
|
|
137
|
+
email: string;
|
|
138
|
+
otpCode: string;
|
|
139
|
+
otpId: string;
|
|
140
|
+
targetPublicKey: string;
|
|
141
|
+
};
|
|
142
|
+
}>;
|
|
143
|
+
Response: AtLeastOne<{
|
|
144
|
+
init: {
|
|
145
|
+
otpId: string;
|
|
146
|
+
};
|
|
147
|
+
auth: {
|
|
148
|
+
userId: string;
|
|
149
|
+
apiKeyId: string;
|
|
150
|
+
credentialBundle: string;
|
|
151
|
+
subOrgId: string;
|
|
152
|
+
};
|
|
153
|
+
}>;
|
|
154
|
+
},
|
|
123
155
|
{
|
|
124
156
|
Route: '/v1/signup';
|
|
125
157
|
Body: AtLeastOne<{
|
|
@@ -205,6 +237,10 @@ type AuthenticationServiceEndpoints = [
|
|
|
205
237
|
Response: User;
|
|
206
238
|
}
|
|
207
239
|
];
|
|
240
|
+
declare const ROUTE_METHOD_LIST: readonly [readonly ["/v1/signup", "POST"], readonly ["/v1/email-auth", "POST"], readonly ["/v1/email-auth", "GET"], readonly ["/v1/otp-auth", "POST"], readonly ["/v1/lookup", "POST"], readonly ["/v1/signin", "POST"], readonly ["/v1/sign", "POST"], readonly ["/v1/oauth/init", "POST"], readonly ["/v1/refresh", "POST"], readonly ["/v1/csrf-token", "GET"], readonly ["/v1/logout", "POST"], readonly ["/v1/me", "GET"]];
|
|
241
|
+
type RouteMethod = (typeof ROUTE_METHOD_LIST)[number];
|
|
242
|
+
type Route = RouteMethod[0];
|
|
243
|
+
type Method = RouteMethod[1];
|
|
208
244
|
|
|
209
245
|
type SignerClientConfiguration = {
|
|
210
246
|
apiKey: string;
|
|
@@ -234,7 +270,14 @@ declare abstract class SignerClient {
|
|
|
234
270
|
protected get stamper(): TurnkeyClient['stamper'];
|
|
235
271
|
protected lookUpUser(email: string): Promise<string | null>;
|
|
236
272
|
protected whoAmI(subOrgId?: string): Promise<void>;
|
|
237
|
-
protected request<Route extends
|
|
273
|
+
protected request<R extends Route, M extends Method>(route: R, method: M, body?: AuthenticationServiceBody<R>): Promise<AuthenticationServiceResponse<R>>;
|
|
274
|
+
/**
|
|
275
|
+
* Compute milliseconds until refresh time.
|
|
276
|
+
* - expSeconds is the JWT exp claim (seconds).
|
|
277
|
+
* - earlyMinutes is how many minutes before exp to refresh (default 2).
|
|
278
|
+
* Returns 0 if refresh time is already past.
|
|
279
|
+
*/
|
|
280
|
+
private _computeRefreshDelayMs;
|
|
238
281
|
protected _scheduleRefresh(token: string): void;
|
|
239
282
|
private _refreshToken;
|
|
240
283
|
}
|
|
@@ -242,11 +285,20 @@ declare abstract class SignerClient {
|
|
|
242
285
|
type WebauthnSignInParams = {
|
|
243
286
|
email: string;
|
|
244
287
|
};
|
|
288
|
+
type EmailAuthReturn = {
|
|
289
|
+
method: string;
|
|
290
|
+
otpId?: string;
|
|
291
|
+
};
|
|
245
292
|
type EmailInitializeAuthParams = {
|
|
246
293
|
email: string;
|
|
247
294
|
redirectUrl: string;
|
|
248
295
|
expirationSeconds?: number;
|
|
249
296
|
};
|
|
297
|
+
type OtpAuthParams = {
|
|
298
|
+
email: string;
|
|
299
|
+
otpCode: string;
|
|
300
|
+
otpId: string;
|
|
301
|
+
};
|
|
250
302
|
type CompleteAuthWithBundleParams = {
|
|
251
303
|
bundle: string;
|
|
252
304
|
subOrgId: string;
|
|
@@ -300,12 +352,42 @@ declare class WebSignerClient extends SignerClient {
|
|
|
300
352
|
*/
|
|
301
353
|
webauthnSignIn({ email }: WebauthnSignInParams): Promise<void>;
|
|
302
354
|
/**
|
|
303
|
-
*
|
|
355
|
+
* Handles auth user process with email according to the method of the used app.
|
|
304
356
|
*
|
|
305
|
-
* @param {EmailInitializeAuthParams} params
|
|
306
|
-
*/
|
|
307
|
-
emailAuth(params: EmailInitializeAuthParams): Promise<
|
|
357
|
+
* @param {EmailInitializeAuthParams} params params needed for the initialization of the auth process
|
|
358
|
+
*/
|
|
359
|
+
emailAuth(params: EmailInitializeAuthParams): Promise<{
|
|
360
|
+
method: string;
|
|
361
|
+
otpId?: undefined;
|
|
362
|
+
} | {
|
|
363
|
+
method: string;
|
|
364
|
+
otpId: string;
|
|
365
|
+
}>;
|
|
308
366
|
getIframePublicKey(): Promise<string>;
|
|
367
|
+
/**
|
|
368
|
+
* Verifies the provided otp code.
|
|
369
|
+
*
|
|
370
|
+
* @param {OtpAuthParams} params params needed for otp code verification
|
|
371
|
+
*/
|
|
372
|
+
otpAuth(params: OtpAuthParams): Promise<AtLeastOne<{
|
|
373
|
+
init: {
|
|
374
|
+
otpId: string;
|
|
375
|
+
};
|
|
376
|
+
auth: {
|
|
377
|
+
userId: string;
|
|
378
|
+
apiKeyId: string;
|
|
379
|
+
credentialBundle: string;
|
|
380
|
+
subOrgId: string;
|
|
381
|
+
};
|
|
382
|
+
}>>;
|
|
383
|
+
/**
|
|
384
|
+
* Gets the email authentication method of the app.
|
|
385
|
+
*/
|
|
386
|
+
private _getEmailAuthMethod;
|
|
387
|
+
/**
|
|
388
|
+
* Starts email authentication process via otp.
|
|
389
|
+
*/
|
|
390
|
+
private _initOtpAuth;
|
|
309
391
|
/**
|
|
310
392
|
* Completes the authentication process with a credential bundle.
|
|
311
393
|
*
|
|
@@ -344,12 +426,38 @@ declare class WebSignerClient extends SignerClient {
|
|
|
344
426
|
private _initIframeStamper;
|
|
345
427
|
}
|
|
346
428
|
|
|
429
|
+
declare class MagicLinkModule {
|
|
430
|
+
private readonly _webSignerClient;
|
|
431
|
+
constructor(_webSignerClient: WebSignerClient);
|
|
432
|
+
/**
|
|
433
|
+
* Completes authentication with magic link that contains a bundle.
|
|
434
|
+
*
|
|
435
|
+
* @param params {CompleteAuthWithBundleParams} params received as URL params necessary to complete authentication process.
|
|
436
|
+
* @returns {Promise<void>} promise that completes the authentication process.
|
|
437
|
+
*/
|
|
438
|
+
complete(params: Pick<CompleteAuthWithBundleParams, 'subOrgId' | 'bundle'>): Promise<void>;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
declare class OtpModule {
|
|
442
|
+
private readonly _webSignerClient;
|
|
443
|
+
constructor(_webSignerClient: WebSignerClient);
|
|
444
|
+
/**
|
|
445
|
+
* Completes authentication with OTP code after user receives the bundle and subOrgId.
|
|
446
|
+
*
|
|
447
|
+
* @param params {OtpAuthParams} params to complete the authentication process.
|
|
448
|
+
* @returns {Promise<void>} promise that completes the authentication process.
|
|
449
|
+
*/
|
|
450
|
+
complete(params: OtpAuthParams): Promise<void>;
|
|
451
|
+
}
|
|
452
|
+
|
|
347
453
|
/**
|
|
348
454
|
* A module for interacting with the Email authentication methods.
|
|
349
455
|
* Available through the `auth.email` property on a `FourtWebSigner` instance.
|
|
350
456
|
*/
|
|
351
457
|
declare class EmailModule {
|
|
352
458
|
private readonly _webSignerClient;
|
|
459
|
+
private readonly _magicLinkModule;
|
|
460
|
+
private readonly _otpModule;
|
|
353
461
|
constructor(_webSignerClient: WebSignerClient);
|
|
354
462
|
/**
|
|
355
463
|
* Initialize user authentication process using email.
|
|
@@ -357,14 +465,9 @@ declare class EmailModule {
|
|
|
357
465
|
* @param params {EmailInitializeAuthParams} params to initialize the user authentication process.
|
|
358
466
|
* @returns {Promise<void>} promise that resolves to the result of the authentication process.
|
|
359
467
|
*/
|
|
360
|
-
initialize(params: EmailInitializeAuthParams): Promise<
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
*
|
|
364
|
-
* @param params {CompleteAuthWithBundleParams} params received as URL params necessary to complete authentication process.
|
|
365
|
-
* @returns {Promise<void>} promise that completes the authentication process.
|
|
366
|
-
*/
|
|
367
|
-
complete(params: Pick<CompleteAuthWithBundleParams, 'subOrgId' | 'bundle'>): Promise<void>;
|
|
468
|
+
initialize(params: EmailInitializeAuthParams): Promise<EmailAuthReturn>;
|
|
469
|
+
get magicLink(): MagicLinkModule;
|
|
470
|
+
get otp(): OtpModule;
|
|
368
471
|
}
|
|
369
472
|
|
|
370
473
|
/**
|
|
@@ -378,7 +481,6 @@ declare class PasskeysModule {
|
|
|
378
481
|
* Signs in a user using Passkeys.
|
|
379
482
|
*
|
|
380
483
|
* @param params {WebauthnSignInParams} params for the sign-in process.
|
|
381
|
-
* @returns {Promise<void>} promise that resolves to the result of the sign-in process.
|
|
382
484
|
*/
|
|
383
485
|
signIn(params: WebauthnSignInParams): Promise<void>;
|
|
384
486
|
}
|
|
@@ -413,6 +515,10 @@ type CompleteParams = {
|
|
|
413
515
|
bundle: string;
|
|
414
516
|
subOrgId: string;
|
|
415
517
|
};
|
|
518
|
+
/**
|
|
519
|
+
* A module for interacting with the OAuth authentication methods.
|
|
520
|
+
* Available through the `auth.oauth` property on a `FourtWebSigner` instance.
|
|
521
|
+
*/
|
|
416
522
|
declare class OAuthModule {
|
|
417
523
|
private readonly _webSignerClient;
|
|
418
524
|
private readonly _googleModule;
|