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