@baasix/sdk 0.1.19 → 0.1.20
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/README.md +147 -4
- package/dist/index.cjs +141 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +141 -5
- package/dist/index.js.map +1 -1
- package/dist/modules/auth.cjs +140 -3
- package/dist/modules/auth.cjs.map +1 -1
- package/dist/modules/auth.d.cts +104 -4
- package/dist/modules/auth.d.ts +104 -4
- package/dist/modules/auth.js +140 -4
- package/dist/modules/auth.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ export { a as HttpClientConfig, R as RequestOptions } from './client-BHbM3KOy.cj
|
|
|
3
3
|
import { S as StorageAdapter } from './types-BdjsGANq.cjs';
|
|
4
4
|
export { a as STORAGE_KEYS, b as StorageKey } from './types-BdjsGANq.cjs';
|
|
5
5
|
import { AuthModule } from './modules/auth.cjs';
|
|
6
|
-
export { InviteOptions, OAuthOptions, OAuthProvider, VerifyInviteResult } from './modules/auth.cjs';
|
|
6
|
+
export { AuthMethods, InviteOptions, LoginResult, OAuthOptions, OAuthProvider, SOCIAL_PROVIDERS, TwoFactorChallengeResponse, TwoFactorEnableResult, VerifyInviteResult } from './modules/auth.cjs';
|
|
7
7
|
import { ItemsModule } from './modules/items.cjs';
|
|
8
8
|
export { ImportResult, QueryBuilder } from './modules/items.cjs';
|
|
9
9
|
import { FilesModule } from './modules/files.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { a as HttpClientConfig, R as RequestOptions } from './client-D67LK80v.js
|
|
|
3
3
|
import { S as StorageAdapter } from './types-BdjsGANq.js';
|
|
4
4
|
export { a as STORAGE_KEYS, b as StorageKey } from './types-BdjsGANq.js';
|
|
5
5
|
import { AuthModule } from './modules/auth.js';
|
|
6
|
-
export { InviteOptions, OAuthOptions, OAuthProvider, VerifyInviteResult } from './modules/auth.js';
|
|
6
|
+
export { AuthMethods, InviteOptions, LoginResult, OAuthOptions, OAuthProvider, SOCIAL_PROVIDERS, TwoFactorChallengeResponse, TwoFactorEnableResult, VerifyInviteResult } from './modules/auth.js';
|
|
7
7
|
import { ItemsModule } from './modules/items.js';
|
|
8
8
|
export { ImportResult, QueryBuilder } from './modules/items.js';
|
|
9
9
|
import { FilesModule } from './modules/files.js';
|
package/dist/index.js
CHANGED
|
@@ -190,7 +190,7 @@ var HttpClient = class {
|
|
|
190
190
|
} catch {
|
|
191
191
|
}
|
|
192
192
|
const message = errorData.error?.message || errorData.message || response.statusText || "Request failed";
|
|
193
|
-
const code = errorData.error?.code;
|
|
193
|
+
const code = errorData.error?.code ?? errorData.code;
|
|
194
194
|
const details = errorData.details;
|
|
195
195
|
return new BaasixError(message, response.status, code, details);
|
|
196
196
|
}
|
|
@@ -474,17 +474,123 @@ var MemoryStorageAdapter = class {
|
|
|
474
474
|
};
|
|
475
475
|
|
|
476
476
|
// src/modules/auth.ts
|
|
477
|
+
var SOCIAL_PROVIDERS = ["apple", "atlassian", "cognito", "discord", "dropbox", "facebook", "figma", "github", "gitlab", "google", "huggingface", "kakao", "kick", "line", "linear", "linkedin", "microsoft", "naver", "notion", "paybin", "paypal", "polar", "railway", "reddit", "roblox", "salesforce", "slack", "spotify", "tiktok", "twitch", "twitter", "vercel", "vk", "wechat", "zoom"];
|
|
477
478
|
var AuthModule = class {
|
|
478
479
|
client;
|
|
479
480
|
storage;
|
|
480
481
|
authMode;
|
|
481
482
|
onAuthStateChange;
|
|
482
483
|
currentUser = null;
|
|
484
|
+
authMethodsCache = null;
|
|
485
|
+
/**
|
|
486
|
+
* Two-factor authentication (TOTP) helpers.
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```typescript
|
|
490
|
+
* const result = await baasix.auth.login({ email, password });
|
|
491
|
+
* if ("twoFactorRequired" in result && result.twoFactorRequired) {
|
|
492
|
+
* const { user, token } = await baasix.auth.twoFactor.verify(result.twoFactorToken, code);
|
|
493
|
+
* }
|
|
494
|
+
* ```
|
|
495
|
+
*/
|
|
496
|
+
twoFactor;
|
|
497
|
+
/**
|
|
498
|
+
* Passkey (WebAuthn) registration and authentication helpers.
|
|
499
|
+
* Browser-only: throws a `BaasixError` when called outside a browser
|
|
500
|
+
* environment (no `window`/`PublicKeyCredential`).
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```typescript
|
|
504
|
+
* // Register a passkey for the currently logged-in user
|
|
505
|
+
* await baasix.auth.passkey.register("My Laptop");
|
|
506
|
+
*
|
|
507
|
+
* // Authenticate with a passkey (no prior login required)
|
|
508
|
+
* const { user, token } = await baasix.auth.passkey.authenticate();
|
|
509
|
+
*
|
|
510
|
+
* // List and remove registered passkeys
|
|
511
|
+
* const passkeys = await baasix.auth.passkey.list();
|
|
512
|
+
* await baasix.auth.passkey.remove(passkeys[0].id);
|
|
513
|
+
* ```
|
|
514
|
+
*/
|
|
515
|
+
passkey = {
|
|
516
|
+
register: async (name) => {
|
|
517
|
+
this.assertBrowser();
|
|
518
|
+
const { startRegistration } = await import('@simplewebauthn/browser');
|
|
519
|
+
const options = await this.client.post("/auth/passkey/register/options", {});
|
|
520
|
+
const attestation = await startRegistration({ optionsJSON: options });
|
|
521
|
+
await this.client.post("/auth/passkey/register/verify", {
|
|
522
|
+
response: attestation,
|
|
523
|
+
name: name || null
|
|
524
|
+
});
|
|
525
|
+
return { verified: true };
|
|
526
|
+
},
|
|
527
|
+
authenticate: async (opts) => {
|
|
528
|
+
this.assertBrowser();
|
|
529
|
+
const { startAuthentication } = await import('@simplewebauthn/browser');
|
|
530
|
+
const { options, challengeId } = await this.client.post(
|
|
531
|
+
"/auth/passkey/authenticate/options",
|
|
532
|
+
{},
|
|
533
|
+
{ skipAuth: true }
|
|
534
|
+
);
|
|
535
|
+
const assertion = await startAuthentication({ optionsJSON: options });
|
|
536
|
+
const response = await this.client.post(
|
|
537
|
+
"/auth/passkey/authenticate/verify",
|
|
538
|
+
{ challengeId, response: assertion, authMode: opts?.authMode },
|
|
539
|
+
{ skipAuth: true }
|
|
540
|
+
);
|
|
541
|
+
await this.storeTokens(response);
|
|
542
|
+
this.emitAuthStateChange("SIGNED_IN", response.user);
|
|
543
|
+
return response;
|
|
544
|
+
},
|
|
545
|
+
list: async () => (await this.client.get("/auth/passkey")).passkeys,
|
|
546
|
+
remove: async (id) => {
|
|
547
|
+
await this.client.delete(`/auth/passkey/${encodeURIComponent(id)}`);
|
|
548
|
+
}
|
|
549
|
+
};
|
|
483
550
|
constructor(config) {
|
|
484
551
|
this.client = config.client;
|
|
485
552
|
this.storage = config.storage;
|
|
486
553
|
this.authMode = config.authMode;
|
|
487
554
|
this.onAuthStateChange = config.onAuthStateChange;
|
|
555
|
+
this.twoFactor = {
|
|
556
|
+
verify: async (twoFactorToken, code, opts) => {
|
|
557
|
+
const response = await this.client.post(
|
|
558
|
+
"/auth/2fa/verify",
|
|
559
|
+
{
|
|
560
|
+
twoFactorToken,
|
|
561
|
+
code,
|
|
562
|
+
authMode: opts?.authMode,
|
|
563
|
+
authType: opts?.authType
|
|
564
|
+
},
|
|
565
|
+
{ skipAuth: true }
|
|
566
|
+
);
|
|
567
|
+
await this.storeTokens(response);
|
|
568
|
+
this.emitAuthStateChange("SIGNED_IN", response.user);
|
|
569
|
+
return response;
|
|
570
|
+
},
|
|
571
|
+
enable: () => {
|
|
572
|
+
return this.client.post("/auth/2fa/enable");
|
|
573
|
+
},
|
|
574
|
+
verifySetup: (code) => {
|
|
575
|
+
return this.client.post("/auth/2fa/verify-setup", {
|
|
576
|
+
code
|
|
577
|
+
});
|
|
578
|
+
},
|
|
579
|
+
disable: (password) => {
|
|
580
|
+
return this.client.post("/auth/2fa/disable", {
|
|
581
|
+
password
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Assert that we're running in a browser environment with WebAuthn support.
|
|
588
|
+
* Throws a `BaasixError` otherwise.
|
|
589
|
+
*/
|
|
590
|
+
assertBrowser() {
|
|
591
|
+
if (typeof window === "undefined" || !window.PublicKeyCredential) {
|
|
592
|
+
throw new BaasixError("Passkeys are only available in a browser", 400);
|
|
593
|
+
}
|
|
488
594
|
}
|
|
489
595
|
/**
|
|
490
596
|
* Emit an authentication state change event
|
|
@@ -581,9 +687,39 @@ var AuthModule = class {
|
|
|
581
687
|
},
|
|
582
688
|
{ skipAuth: true }
|
|
583
689
|
);
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
690
|
+
if ("twoFactorRequired" in response && response.twoFactorRequired) {
|
|
691
|
+
return response;
|
|
692
|
+
}
|
|
693
|
+
const authResponse = response;
|
|
694
|
+
await this.storeTokens(authResponse);
|
|
695
|
+
this.emitAuthStateChange("SIGNED_IN", authResponse.user);
|
|
696
|
+
return authResponse;
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Discover which authentication methods are enabled for this project
|
|
700
|
+
* (registration, email/password, magic link, passkey, 2FA, and the list
|
|
701
|
+
* of configured social/OAuth providers). Result is cached per instance;
|
|
702
|
+
* pass `force: true` to bypass the cache and refetch.
|
|
703
|
+
*
|
|
704
|
+
* @example
|
|
705
|
+
* ```typescript
|
|
706
|
+
* const methods = await baasix.auth.getAuthMethods();
|
|
707
|
+
* if (methods.socialProviders.includes("google")) {
|
|
708
|
+
* // show "Sign in with Google"
|
|
709
|
+
* }
|
|
710
|
+
* ```
|
|
711
|
+
*/
|
|
712
|
+
async getAuthMethods(force = false) {
|
|
713
|
+
if (this.authMethodsCache && !force) {
|
|
714
|
+
return this.authMethodsCache;
|
|
715
|
+
}
|
|
716
|
+
const response = await this.client.get(
|
|
717
|
+
"/",
|
|
718
|
+
{ skipAuth: true }
|
|
719
|
+
);
|
|
720
|
+
const authMethods = response?.project?.auth;
|
|
721
|
+
this.authMethodsCache = authMethods;
|
|
722
|
+
return authMethods;
|
|
587
723
|
}
|
|
588
724
|
/**
|
|
589
725
|
* Logout the current user
|
|
@@ -5086,6 +5222,6 @@ function createBaasix(config) {
|
|
|
5086
5222
|
return new Baasix(config);
|
|
5087
5223
|
}
|
|
5088
5224
|
|
|
5089
|
-
export { AsyncStorageAdapter, AuthModule, Baasix, BaasixError, FilesModule, HttpClient, ItemsModule, LocalStorageAdapter, MemoryStorageAdapter, MigrationsModule, NotificationsModule, PermissionsModule, QueryBuilder, RealtimeChannel, RealtimeModule, ReportsModule, RolesModule, STORAGE_KEYS, SchemasModule, SettingsModule, UsersModule, WorkflowsModule, createBaasix };
|
|
5225
|
+
export { AsyncStorageAdapter, AuthModule, Baasix, BaasixError, FilesModule, HttpClient, ItemsModule, LocalStorageAdapter, MemoryStorageAdapter, MigrationsModule, NotificationsModule, PermissionsModule, QueryBuilder, RealtimeChannel, RealtimeModule, ReportsModule, RolesModule, SOCIAL_PROVIDERS, STORAGE_KEYS, SchemasModule, SettingsModule, UsersModule, WorkflowsModule, createBaasix };
|
|
5090
5226
|
//# sourceMappingURL=index.js.map
|
|
5091
5227
|
//# sourceMappingURL=index.js.map
|