@baasix/sdk 0.1.18 → 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/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';
@@ -146,6 +146,7 @@ declare class NotificationsModule {
146
146
  limit?: number;
147
147
  page?: number;
148
148
  filter?: Record<string, unknown>;
149
+ sort?: string[] | Record<string, "asc" | "desc">;
149
150
  }): Promise<PaginatedResponse<Notification>>;
150
151
  /**
151
152
  * Get unread notification count
@@ -171,6 +172,33 @@ declare class NotificationsModule {
171
172
  markAsSeen(notificationIds?: string[]): Promise<{
172
173
  count: number;
173
174
  }>;
175
+ /**
176
+ * Mark notifications as unseen (unread)
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * // Mark specific notifications as unseen
181
+ * await baasix.notifications.markAsUnseen(['id1', 'id2']);
182
+ *
183
+ * // Mark all notifications as unseen
184
+ * await baasix.notifications.markAsUnseen();
185
+ * ```
186
+ */
187
+ markAsUnseen(notificationIds?: string[]): Promise<{
188
+ count: number;
189
+ }>;
190
+ /**
191
+ * Get the per-type notification link templates configured in settings
192
+ * (`metadata.notificationLinks`). Templates may contain `{{field}}`
193
+ * placeholders resolved from the notification (including `data.*` paths).
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * const links = await baasix.notifications.getLinks();
198
+ * // { task_assigned: '/pages/?slug=tasks&id={{data.taskId}}' }
199
+ * ```
200
+ */
201
+ getLinks(): Promise<Record<string, string>>;
174
202
  /**
175
203
  * Delete notifications for the current user
176
204
  *
@@ -459,7 +487,9 @@ declare class SettingsModule {
459
487
  * });
460
488
  * ```
461
489
  */
462
- update(settings: Partial<Settings>): Promise<Settings>;
490
+ update(settings: Partial<Settings>, options?: {
491
+ tenantId?: string | number;
492
+ }): Promise<Settings>;
463
493
  /**
464
494
  * Set a specific setting
465
495
  *
@@ -2066,14 +2096,19 @@ declare class ServerModule {
2066
2096
  /**
2067
2097
  * Get server information including project settings
2068
2098
  *
2099
+ * @param tenantId - Optional tenant ID to fetch tenant-merged project settings
2100
+ *
2069
2101
  * @example
2070
2102
  * ```typescript
2071
2103
  * const info = await baasix.server.info();
2072
2104
  * console.log('Project:', info.project?.name);
2073
2105
  * console.log('Version:', info.version);
2106
+ *
2107
+ * // Tenant-aware: settings merged for the given tenant
2108
+ * const tenantInfo = await baasix.server.info("tenant-uuid");
2074
2109
  * ```
2075
2110
  */
2076
- info(): Promise<ServerInfo>;
2111
+ info(tenantId?: string): Promise<ServerInfo>;
2077
2112
  /**
2078
2113
  * Check server health
2079
2114
  *
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';
@@ -146,6 +146,7 @@ declare class NotificationsModule {
146
146
  limit?: number;
147
147
  page?: number;
148
148
  filter?: Record<string, unknown>;
149
+ sort?: string[] | Record<string, "asc" | "desc">;
149
150
  }): Promise<PaginatedResponse<Notification>>;
150
151
  /**
151
152
  * Get unread notification count
@@ -171,6 +172,33 @@ declare class NotificationsModule {
171
172
  markAsSeen(notificationIds?: string[]): Promise<{
172
173
  count: number;
173
174
  }>;
175
+ /**
176
+ * Mark notifications as unseen (unread)
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * // Mark specific notifications as unseen
181
+ * await baasix.notifications.markAsUnseen(['id1', 'id2']);
182
+ *
183
+ * // Mark all notifications as unseen
184
+ * await baasix.notifications.markAsUnseen();
185
+ * ```
186
+ */
187
+ markAsUnseen(notificationIds?: string[]): Promise<{
188
+ count: number;
189
+ }>;
190
+ /**
191
+ * Get the per-type notification link templates configured in settings
192
+ * (`metadata.notificationLinks`). Templates may contain `{{field}}`
193
+ * placeholders resolved from the notification (including `data.*` paths).
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * const links = await baasix.notifications.getLinks();
198
+ * // { task_assigned: '/pages/?slug=tasks&id={{data.taskId}}' }
199
+ * ```
200
+ */
201
+ getLinks(): Promise<Record<string, string>>;
174
202
  /**
175
203
  * Delete notifications for the current user
176
204
  *
@@ -459,7 +487,9 @@ declare class SettingsModule {
459
487
  * });
460
488
  * ```
461
489
  */
462
- update(settings: Partial<Settings>): Promise<Settings>;
490
+ update(settings: Partial<Settings>, options?: {
491
+ tenantId?: string | number;
492
+ }): Promise<Settings>;
463
493
  /**
464
494
  * Set a specific setting
465
495
  *
@@ -2066,14 +2096,19 @@ declare class ServerModule {
2066
2096
  /**
2067
2097
  * Get server information including project settings
2068
2098
  *
2099
+ * @param tenantId - Optional tenant ID to fetch tenant-merged project settings
2100
+ *
2069
2101
  * @example
2070
2102
  * ```typescript
2071
2103
  * const info = await baasix.server.info();
2072
2104
  * console.log('Project:', info.project?.name);
2073
2105
  * console.log('Version:', info.version);
2106
+ *
2107
+ * // Tenant-aware: settings merged for the given tenant
2108
+ * const tenantInfo = await baasix.server.info("tenant-uuid");
2074
2109
  * ```
2075
2110
  */
2076
- info(): Promise<ServerInfo>;
2111
+ info(tenantId?: string): Promise<ServerInfo>;
2077
2112
  /**
2078
2113
  * Check server health
2079
2114
  *
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
- await this.storeTokens(response);
585
- this.emitAuthStateChange("SIGNED_IN", response.user);
586
- return response;
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
@@ -2404,6 +2540,42 @@ var NotificationsModule = class {
2404
2540
  );
2405
2541
  return { count: response.count };
2406
2542
  }
2543
+ /**
2544
+ * Mark notifications as unseen (unread)
2545
+ *
2546
+ * @example
2547
+ * ```typescript
2548
+ * // Mark specific notifications as unseen
2549
+ * await baasix.notifications.markAsUnseen(['id1', 'id2']);
2550
+ *
2551
+ * // Mark all notifications as unseen
2552
+ * await baasix.notifications.markAsUnseen();
2553
+ * ```
2554
+ */
2555
+ async markAsUnseen(notificationIds) {
2556
+ const response = await this.client.post(
2557
+ "/notifications/mark-unseen",
2558
+ { notificationIds }
2559
+ );
2560
+ return { count: response.count };
2561
+ }
2562
+ /**
2563
+ * Get the per-type notification link templates configured in settings
2564
+ * (`metadata.notificationLinks`). Templates may contain `{{field}}`
2565
+ * placeholders resolved from the notification (including `data.*` paths).
2566
+ *
2567
+ * @example
2568
+ * ```typescript
2569
+ * const links = await baasix.notifications.getLinks();
2570
+ * // { task_assigned: '/pages/?slug=tasks&id={{data.taskId}}' }
2571
+ * ```
2572
+ */
2573
+ async getLinks() {
2574
+ const response = await this.client.get(
2575
+ "/notifications/links"
2576
+ );
2577
+ return response.data ?? {};
2578
+ }
2407
2579
  /**
2408
2580
  * Delete notifications for the current user
2409
2581
  *
@@ -2710,10 +2882,11 @@ var SettingsModule = class {
2710
2882
  * });
2711
2883
  * ```
2712
2884
  */
2713
- async update(settings) {
2885
+ async update(settings, options) {
2714
2886
  const response = await this.client.patch(
2715
2887
  "/settings",
2716
- settings
2888
+ settings,
2889
+ options?.tenantId !== void 0 && options?.tenantId !== null ? { params: { tenant_id: options.tenantId } } : void 0
2717
2890
  );
2718
2891
  return response.data;
2719
2892
  }
@@ -4719,15 +4892,23 @@ var ServerModule = class {
4719
4892
  /**
4720
4893
  * Get server information including project settings
4721
4894
  *
4895
+ * @param tenantId - Optional tenant ID to fetch tenant-merged project settings
4896
+ *
4722
4897
  * @example
4723
4898
  * ```typescript
4724
4899
  * const info = await baasix.server.info();
4725
4900
  * console.log('Project:', info.project?.name);
4726
4901
  * console.log('Version:', info.version);
4902
+ *
4903
+ * // Tenant-aware: settings merged for the given tenant
4904
+ * const tenantInfo = await baasix.server.info("tenant-uuid");
4727
4905
  * ```
4728
4906
  */
4729
- async info() {
4730
- return this.client.get("/");
4907
+ async info(tenantId) {
4908
+ return this.client.get(
4909
+ "/",
4910
+ tenantId ? { params: { tenant_id: tenantId } } : void 0
4911
+ );
4731
4912
  }
4732
4913
  /**
4733
4914
  * Check server health
@@ -5041,6 +5222,6 @@ function createBaasix(config) {
5041
5222
  return new Baasix(config);
5042
5223
  }
5043
5224
 
5044
- 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 };
5045
5226
  //# sourceMappingURL=index.js.map
5046
5227
  //# sourceMappingURL=index.js.map