@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/README.md CHANGED
@@ -204,14 +204,20 @@ const { user, token } = await baasix.auth.verifyMagicLink('verification-token');
204
204
  ### Password Reset
205
205
 
206
206
  ```typescript
207
- // Request reset
207
+ // Request reset (link mode: emails a clickable reset URL)
208
208
  await baasix.auth.forgotPassword({
209
209
  email: 'user@example.com',
210
210
  redirectUrl: 'https://myapp.com/reset-password',
211
211
  });
212
212
 
213
- // Reset password
214
- await baasix.auth.resetPassword('reset-token', 'newpassword123');
213
+ // Request reset (code mode: emails a short one-time code, no redirectUrl needed)
214
+ await baasix.auth.forgotPassword({
215
+ email: 'user@example.com',
216
+ mode: 'code',
217
+ });
218
+
219
+ // Reset password with the token or emailed code
220
+ await baasix.auth.resetPassword('reset-token-or-code', 'newpassword123');
215
221
  ```
216
222
 
217
223
  ### Change Password
package/dist/index.cjs CHANGED
@@ -915,10 +915,17 @@ var AuthModule = class {
915
915
  *
916
916
  * @example
917
917
  * ```typescript
918
+ * // Link mode (default): emails a clickable reset URL
918
919
  * await baasix.auth.forgotPassword({
919
920
  * email: 'user@example.com',
920
921
  * redirectUrl: 'https://myapp.com/reset-password'
921
922
  * });
923
+ *
924
+ * // Code mode: emails a short one-time code, no redirectUrl needed
925
+ * await baasix.auth.forgotPassword({
926
+ * email: 'user@example.com',
927
+ * mode: 'code'
928
+ * });
922
929
  * ```
923
930
  */
924
931
  async forgotPassword(options) {
@@ -926,17 +933,18 @@ var AuthModule = class {
926
933
  "/auth/password/reset",
927
934
  {
928
935
  email: options.email,
929
- link: options.redirectUrl
936
+ link: options.redirectUrl,
937
+ mode: options.mode || "link"
930
938
  },
931
939
  { skipAuth: true }
932
940
  );
933
941
  }
934
942
  /**
935
- * Reset password using a reset token
943
+ * Reset password using a reset token or emailed one-time code
936
944
  *
937
945
  * @example
938
946
  * ```typescript
939
- * await baasix.auth.resetPassword('reset-token', 'newpassword123');
947
+ * await baasix.auth.resetPassword('reset-token-or-code', 'newpassword123');
940
948
  * ```
941
949
  */
942
950
  async resetPassword(token, newPassword) {
@@ -2710,9 +2718,21 @@ var PermissionsModule = class {
2710
2718
  * action: 'update',
2711
2719
  * fields: ['title', 'content', 'status'],
2712
2720
  * conditions: {
2713
- * author_Id: { eq: '$CURRENT_USER' }
2721
+ * author_Id: { eq: '$CURRENT_USER' } // USING: which rows may be updated
2722
+ * },
2723
+ * checkConditions: {
2724
+ * author_Id: { eq: '$CURRENT_USER' } // WITH CHECK: what they may become
2714
2725
  * }
2715
2726
  * });
2727
+ *
2728
+ * // Create grants use checkConditions (conditions is rejected on create):
2729
+ * await baasix.permissions.create({
2730
+ * role_Id: 'user-role-uuid',
2731
+ * collection: 'tasks',
2732
+ * action: 'create',
2733
+ * fields: ['*'],
2734
+ * checkConditions: { owner_Id: { eq: '$CURRENT_USER' } }
2735
+ * });
2716
2736
  * ```
2717
2737
  */
2718
2738
  async create(data) {
@@ -2770,9 +2790,9 @@ var PermissionsModule = class {
2770
2790
  * @example
2771
2791
  * ```typescript
2772
2792
  * await baasix.permissions.createCrudPermissions('role-uuid', 'products', {
2773
- * create: { fields: ['name', 'price', 'description'] },
2793
+ * create: { fields: ['name', 'price'], checkConditions: { owner_Id: { eq: '$CURRENT_USER' } } },
2774
2794
  * read: { fields: ['*'] },
2775
- * update: { fields: ['name', 'price', 'description'] },
2795
+ * update: { fields: ['name', 'price'], conditions: { owner_Id: { eq: '$CURRENT_USER' } } },
2776
2796
  * delete: false
2777
2797
  * });
2778
2798
  * ```
@@ -2783,12 +2803,15 @@ var PermissionsModule = class {
2783
2803
  for (const action of actions) {
2784
2804
  const actionConfig = config[action];
2785
2805
  if (actionConfig === false) continue;
2806
+ const cfg = actionConfig;
2786
2807
  const permission = await this.create({
2787
2808
  role_Id: roleId,
2788
2809
  collection,
2789
2810
  action,
2790
- fields: actionConfig?.fields || ["*"],
2791
- conditions: actionConfig?.conditions
2811
+ fields: cfg?.fields || ["*"],
2812
+ // `conditions` filters existing rows (USING) — never sent for create
2813
+ conditions: action === "create" ? void 0 : cfg?.conditions,
2814
+ checkConditions: action === "create" || action === "update" ? cfg?.checkConditions : void 0
2792
2815
  });
2793
2816
  permissions.push(permission);
2794
2817
  }