@baasix/sdk 0.1.20 → 0.1.21

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 CHANGED
@@ -2710,9 +2710,21 @@ var PermissionsModule = class {
2710
2710
  * action: 'update',
2711
2711
  * fields: ['title', 'content', 'status'],
2712
2712
  * conditions: {
2713
- * author_Id: { eq: '$CURRENT_USER' }
2713
+ * author_Id: { eq: '$CURRENT_USER' } // USING: which rows may be updated
2714
+ * },
2715
+ * checkConditions: {
2716
+ * author_Id: { eq: '$CURRENT_USER' } // WITH CHECK: what they may become
2714
2717
  * }
2715
2718
  * });
2719
+ *
2720
+ * // Create grants use checkConditions (conditions is rejected on create):
2721
+ * await baasix.permissions.create({
2722
+ * role_Id: 'user-role-uuid',
2723
+ * collection: 'tasks',
2724
+ * action: 'create',
2725
+ * fields: ['*'],
2726
+ * checkConditions: { owner_Id: { eq: '$CURRENT_USER' } }
2727
+ * });
2716
2728
  * ```
2717
2729
  */
2718
2730
  async create(data) {
@@ -2770,9 +2782,9 @@ var PermissionsModule = class {
2770
2782
  * @example
2771
2783
  * ```typescript
2772
2784
  * await baasix.permissions.createCrudPermissions('role-uuid', 'products', {
2773
- * create: { fields: ['name', 'price', 'description'] },
2785
+ * create: { fields: ['name', 'price'], checkConditions: { owner_Id: { eq: '$CURRENT_USER' } } },
2774
2786
  * read: { fields: ['*'] },
2775
- * update: { fields: ['name', 'price', 'description'] },
2787
+ * update: { fields: ['name', 'price'], conditions: { owner_Id: { eq: '$CURRENT_USER' } } },
2776
2788
  * delete: false
2777
2789
  * });
2778
2790
  * ```
@@ -2783,12 +2795,15 @@ var PermissionsModule = class {
2783
2795
  for (const action of actions) {
2784
2796
  const actionConfig = config[action];
2785
2797
  if (actionConfig === false) continue;
2798
+ const cfg = actionConfig;
2786
2799
  const permission = await this.create({
2787
2800
  role_Id: roleId,
2788
2801
  collection,
2789
2802
  action,
2790
- fields: actionConfig?.fields || ["*"],
2791
- conditions: actionConfig?.conditions
2803
+ fields: cfg?.fields || ["*"],
2804
+ // `conditions` filters existing rows (USING) — never sent for create
2805
+ conditions: action === "create" ? void 0 : cfg?.conditions,
2806
+ checkConditions: action === "create" || action === "update" ? cfg?.checkConditions : void 0
2792
2807
  });
2793
2808
  permissions.push(permission);
2794
2809
  }