@baasix/sdk 0.1.20 → 0.1.22

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
@@ -318,9 +318,21 @@ declare class PermissionsModule {
318
318
  * action: 'update',
319
319
  * fields: ['title', 'content', 'status'],
320
320
  * conditions: {
321
- * author_Id: { eq: '$CURRENT_USER' }
321
+ * author_Id: { eq: '$CURRENT_USER' } // USING: which rows may be updated
322
+ * },
323
+ * checkConditions: {
324
+ * author_Id: { eq: '$CURRENT_USER' } // WITH CHECK: what they may become
322
325
  * }
323
326
  * });
327
+ *
328
+ * // Create grants use checkConditions (conditions is rejected on create):
329
+ * await baasix.permissions.create({
330
+ * role_Id: 'user-role-uuid',
331
+ * collection: 'tasks',
332
+ * action: 'create',
333
+ * fields: ['*'],
334
+ * checkConditions: { owner_Id: { eq: '$CURRENT_USER' } }
335
+ * });
324
336
  * ```
325
337
  */
326
338
  create(data: CreatePermissionData): Promise<Permission>;
@@ -360,17 +372,18 @@ declare class PermissionsModule {
360
372
  * @example
361
373
  * ```typescript
362
374
  * await baasix.permissions.createCrudPermissions('role-uuid', 'products', {
363
- * create: { fields: ['name', 'price', 'description'] },
375
+ * create: { fields: ['name', 'price'], checkConditions: { owner_Id: { eq: '$CURRENT_USER' } } },
364
376
  * read: { fields: ['*'] },
365
- * update: { fields: ['name', 'price', 'description'] },
377
+ * update: { fields: ['name', 'price'], conditions: { owner_Id: { eq: '$CURRENT_USER' } } },
366
378
  * delete: false
367
379
  * });
368
380
  * ```
369
381
  */
370
382
  createCrudPermissions(roleId: string, collection: string, config: {
383
+ /** Create grants scope writes via checkConditions — `conditions` is rejected by the API on create. */
371
384
  create?: {
372
385
  fields?: string[];
373
- conditions?: Permission["conditions"];
386
+ checkConditions?: Permission["checkConditions"];
374
387
  } | false;
375
388
  read?: {
376
389
  fields?: string[];
@@ -379,6 +392,7 @@ declare class PermissionsModule {
379
392
  update?: {
380
393
  fields?: string[];
381
394
  conditions?: Permission["conditions"];
395
+ checkConditions?: Permission["checkConditions"];
382
396
  } | false;
383
397
  delete?: {
384
398
  conditions?: Permission["conditions"];
package/dist/index.d.ts CHANGED
@@ -318,9 +318,21 @@ declare class PermissionsModule {
318
318
  * action: 'update',
319
319
  * fields: ['title', 'content', 'status'],
320
320
  * conditions: {
321
- * author_Id: { eq: '$CURRENT_USER' }
321
+ * author_Id: { eq: '$CURRENT_USER' } // USING: which rows may be updated
322
+ * },
323
+ * checkConditions: {
324
+ * author_Id: { eq: '$CURRENT_USER' } // WITH CHECK: what they may become
322
325
  * }
323
326
  * });
327
+ *
328
+ * // Create grants use checkConditions (conditions is rejected on create):
329
+ * await baasix.permissions.create({
330
+ * role_Id: 'user-role-uuid',
331
+ * collection: 'tasks',
332
+ * action: 'create',
333
+ * fields: ['*'],
334
+ * checkConditions: { owner_Id: { eq: '$CURRENT_USER' } }
335
+ * });
324
336
  * ```
325
337
  */
326
338
  create(data: CreatePermissionData): Promise<Permission>;
@@ -360,17 +372,18 @@ declare class PermissionsModule {
360
372
  * @example
361
373
  * ```typescript
362
374
  * await baasix.permissions.createCrudPermissions('role-uuid', 'products', {
363
- * create: { fields: ['name', 'price', 'description'] },
375
+ * create: { fields: ['name', 'price'], checkConditions: { owner_Id: { eq: '$CURRENT_USER' } } },
364
376
  * read: { fields: ['*'] },
365
- * update: { fields: ['name', 'price', 'description'] },
377
+ * update: { fields: ['name', 'price'], conditions: { owner_Id: { eq: '$CURRENT_USER' } } },
366
378
  * delete: false
367
379
  * });
368
380
  * ```
369
381
  */
370
382
  createCrudPermissions(roleId: string, collection: string, config: {
383
+ /** Create grants scope writes via checkConditions — `conditions` is rejected by the API on create. */
371
384
  create?: {
372
385
  fields?: string[];
373
- conditions?: Permission["conditions"];
386
+ checkConditions?: Permission["checkConditions"];
374
387
  } | false;
375
388
  read?: {
376
389
  fields?: string[];
@@ -379,6 +392,7 @@ declare class PermissionsModule {
379
392
  update?: {
380
393
  fields?: string[];
381
394
  conditions?: Permission["conditions"];
395
+ checkConditions?: Permission["checkConditions"];
382
396
  } | false;
383
397
  delete?: {
384
398
  conditions?: Permission["conditions"];
package/dist/index.js CHANGED
@@ -913,10 +913,17 @@ var AuthModule = class {
913
913
  *
914
914
  * @example
915
915
  * ```typescript
916
+ * // Link mode (default): emails a clickable reset URL
916
917
  * await baasix.auth.forgotPassword({
917
918
  * email: 'user@example.com',
918
919
  * redirectUrl: 'https://myapp.com/reset-password'
919
920
  * });
921
+ *
922
+ * // Code mode: emails a short one-time code, no redirectUrl needed
923
+ * await baasix.auth.forgotPassword({
924
+ * email: 'user@example.com',
925
+ * mode: 'code'
926
+ * });
920
927
  * ```
921
928
  */
922
929
  async forgotPassword(options) {
@@ -924,17 +931,18 @@ var AuthModule = class {
924
931
  "/auth/password/reset",
925
932
  {
926
933
  email: options.email,
927
- link: options.redirectUrl
934
+ link: options.redirectUrl,
935
+ mode: options.mode || "link"
928
936
  },
929
937
  { skipAuth: true }
930
938
  );
931
939
  }
932
940
  /**
933
- * Reset password using a reset token
941
+ * Reset password using a reset token or emailed one-time code
934
942
  *
935
943
  * @example
936
944
  * ```typescript
937
- * await baasix.auth.resetPassword('reset-token', 'newpassword123');
945
+ * await baasix.auth.resetPassword('reset-token-or-code', 'newpassword123');
938
946
  * ```
939
947
  */
940
948
  async resetPassword(token, newPassword) {
@@ -2708,9 +2716,21 @@ var PermissionsModule = class {
2708
2716
  * action: 'update',
2709
2717
  * fields: ['title', 'content', 'status'],
2710
2718
  * conditions: {
2711
- * author_Id: { eq: '$CURRENT_USER' }
2719
+ * author_Id: { eq: '$CURRENT_USER' } // USING: which rows may be updated
2720
+ * },
2721
+ * checkConditions: {
2722
+ * author_Id: { eq: '$CURRENT_USER' } // WITH CHECK: what they may become
2712
2723
  * }
2713
2724
  * });
2725
+ *
2726
+ * // Create grants use checkConditions (conditions is rejected on create):
2727
+ * await baasix.permissions.create({
2728
+ * role_Id: 'user-role-uuid',
2729
+ * collection: 'tasks',
2730
+ * action: 'create',
2731
+ * fields: ['*'],
2732
+ * checkConditions: { owner_Id: { eq: '$CURRENT_USER' } }
2733
+ * });
2714
2734
  * ```
2715
2735
  */
2716
2736
  async create(data) {
@@ -2768,9 +2788,9 @@ var PermissionsModule = class {
2768
2788
  * @example
2769
2789
  * ```typescript
2770
2790
  * await baasix.permissions.createCrudPermissions('role-uuid', 'products', {
2771
- * create: { fields: ['name', 'price', 'description'] },
2791
+ * create: { fields: ['name', 'price'], checkConditions: { owner_Id: { eq: '$CURRENT_USER' } } },
2772
2792
  * read: { fields: ['*'] },
2773
- * update: { fields: ['name', 'price', 'description'] },
2793
+ * update: { fields: ['name', 'price'], conditions: { owner_Id: { eq: '$CURRENT_USER' } } },
2774
2794
  * delete: false
2775
2795
  * });
2776
2796
  * ```
@@ -2781,12 +2801,15 @@ var PermissionsModule = class {
2781
2801
  for (const action of actions) {
2782
2802
  const actionConfig = config[action];
2783
2803
  if (actionConfig === false) continue;
2804
+ const cfg = actionConfig;
2784
2805
  const permission = await this.create({
2785
2806
  role_Id: roleId,
2786
2807
  collection,
2787
2808
  action,
2788
- fields: actionConfig?.fields || ["*"],
2789
- conditions: actionConfig?.conditions
2809
+ fields: cfg?.fields || ["*"],
2810
+ // `conditions` filters existing rows (USING) — never sent for create
2811
+ conditions: action === "create" ? void 0 : cfg?.conditions,
2812
+ checkConditions: action === "create" || action === "update" ? cfg?.checkConditions : void 0
2790
2813
  });
2791
2814
  permissions.push(permission);
2792
2815
  }