casbin 5.37.0 → 5.39.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [5.39.0](https://github.com/casbin/node-casbin/compare/v5.38.0...v5.39.0) (2025-09-22)
2
+
3
+
4
+ ### Features
5
+
6
+ * **adapter:** add lazyLoad parameter to initWithAdapter in newEnforcerWithClass ([#503](https://github.com/casbin/node-casbin/issues/503)) ([b9a3d45](https://github.com/casbin/node-casbin/commit/b9a3d451baabc60f2de0e64807b9930c888b3774))
7
+
8
+ # [5.38.0](https://github.com/casbin/node-casbin/compare/v5.37.0...v5.38.0) (2025-01-23)
9
+
10
+
11
+ ### Features
12
+
13
+ * implement `enableAcceptJsonRequest` API ([#497](https://github.com/casbin/node-casbin/issues/497)) ([650db88](https://github.com/casbin/node-casbin/commit/650db88d6703db9ef934a371ba782791376e0088))
14
+
1
15
  # [5.37.0](https://github.com/casbin/node-casbin/compare/v5.36.0...v5.37.0) (2025-01-10)
2
16
 
3
17
 
@@ -22,6 +22,7 @@ export declare class CoreEnforcer {
22
22
  protected autoSave: boolean;
23
23
  protected autoBuildRoleLinks: boolean;
24
24
  protected autoNotifyWatcher: boolean;
25
+ protected acceptJsonRequest: boolean;
25
26
  protected fs?: FileSystem;
26
27
  /**
27
28
  * setFileSystem sets a file system to read the model file or the policy file.
@@ -160,6 +161,12 @@ export declare class CoreEnforcer {
160
161
  * @param enable whether to enable the AutoNotifyWatcher feature.
161
162
  */
162
163
  enableAutoNotifyWatcher(enable: boolean): void;
164
+ /**
165
+ * enableAcceptJsonRequest determines whether to attempt parsing request args as JSON
166
+ *
167
+ * @param enable whether to attempt parsing request args as JSON
168
+ */
169
+ enableAcceptJsonRequest(enable: boolean): void;
163
170
  /**
164
171
  * enableAutoBuildRoleLinks controls whether to save a policy rule
165
172
  * automatically to the adapter when it is added or removed.
@@ -36,6 +36,7 @@ class CoreEnforcer {
36
36
  this.autoSave = true;
37
37
  this.autoBuildRoleLinks = true;
38
38
  this.autoNotifyWatcher = true;
39
+ this.acceptJsonRequest = false;
39
40
  }
40
41
  /**
41
42
  * setFileSystem sets a file system to read the model file or the policy file.
@@ -293,6 +294,14 @@ class CoreEnforcer {
293
294
  enableAutoNotifyWatcher(enable) {
294
295
  this.autoNotifyWatcher = enable;
295
296
  }
297
+ /**
298
+ * enableAcceptJsonRequest determines whether to attempt parsing request args as JSON
299
+ *
300
+ * @param enable whether to attempt parsing request args as JSON
301
+ */
302
+ enableAcceptJsonRequest(enable) {
303
+ this.acceptJsonRequest = enable;
304
+ }
296
305
  /**
297
306
  * enableAutoBuildRoleLinks controls whether to save a policy rule
298
307
  * automatically to the adapter when it is added or removed.
@@ -393,9 +402,22 @@ class CoreEnforcer {
393
402
  if ((rTokens === null || rTokens === void 0 ? void 0 : rTokens.length) !== rvals.length) {
394
403
  throw new Error(`invalid request size: expected ${rTokensLen}, got ${rvals.length}, rvals: ${rvals}"`);
395
404
  }
396
- rTokens.forEach((token, j) => {
397
- parameters[token] = rvals[j];
398
- });
405
+ if (this.acceptJsonRequest) {
406
+ // Attempt to parse each request parameter as JSON; continue with string if failed
407
+ rTokens.forEach((token, j) => {
408
+ try {
409
+ parameters[token] = JSON.parse(rvals[j]);
410
+ }
411
+ catch (_a) {
412
+ parameters[token] = rvals[j];
413
+ }
414
+ });
415
+ }
416
+ else {
417
+ rTokens.forEach((token, j) => {
418
+ parameters[token] = rvals[j];
419
+ });
420
+ }
399
421
  p === null || p === void 0 ? void 0 : p.tokens.forEach((token, j) => {
400
422
  parameters[token] = p === null || p === void 0 ? void 0 : p.policy[i][j];
401
423
  });
@@ -491,7 +491,7 @@ async function newEnforcerWithClass(enforcer, ...params) {
491
491
  await e.initWithFile(params[0].toString(), params[1].toString());
492
492
  }
493
493
  else {
494
- await e.initWithAdapter(params[0].toString(), params[1]);
494
+ await e.initWithAdapter(params[0].toString(), params[1], params[2] === true);
495
495
  }
496
496
  }
497
497
  else {
@@ -22,6 +22,7 @@ export declare class CoreEnforcer {
22
22
  protected autoSave: boolean;
23
23
  protected autoBuildRoleLinks: boolean;
24
24
  protected autoNotifyWatcher: boolean;
25
+ protected acceptJsonRequest: boolean;
25
26
  protected fs?: FileSystem;
26
27
  /**
27
28
  * setFileSystem sets a file system to read the model file or the policy file.
@@ -160,6 +161,12 @@ export declare class CoreEnforcer {
160
161
  * @param enable whether to enable the AutoNotifyWatcher feature.
161
162
  */
162
163
  enableAutoNotifyWatcher(enable: boolean): void;
164
+ /**
165
+ * enableAcceptJsonRequest determines whether to attempt parsing request args as JSON
166
+ *
167
+ * @param enable whether to attempt parsing request args as JSON
168
+ */
169
+ enableAcceptJsonRequest(enable: boolean): void;
163
170
  /**
164
171
  * enableAutoBuildRoleLinks controls whether to save a policy rule
165
172
  * automatically to the adapter when it is added or removed.
@@ -33,6 +33,7 @@ export class CoreEnforcer {
33
33
  this.autoSave = true;
34
34
  this.autoBuildRoleLinks = true;
35
35
  this.autoNotifyWatcher = true;
36
+ this.acceptJsonRequest = false;
36
37
  }
37
38
  /**
38
39
  * setFileSystem sets a file system to read the model file or the policy file.
@@ -290,6 +291,14 @@ export class CoreEnforcer {
290
291
  enableAutoNotifyWatcher(enable) {
291
292
  this.autoNotifyWatcher = enable;
292
293
  }
294
+ /**
295
+ * enableAcceptJsonRequest determines whether to attempt parsing request args as JSON
296
+ *
297
+ * @param enable whether to attempt parsing request args as JSON
298
+ */
299
+ enableAcceptJsonRequest(enable) {
300
+ this.acceptJsonRequest = enable;
301
+ }
293
302
  /**
294
303
  * enableAutoBuildRoleLinks controls whether to save a policy rule
295
304
  * automatically to the adapter when it is added or removed.
@@ -390,9 +399,22 @@ export class CoreEnforcer {
390
399
  if ((rTokens === null || rTokens === void 0 ? void 0 : rTokens.length) !== rvals.length) {
391
400
  throw new Error(`invalid request size: expected ${rTokensLen}, got ${rvals.length}, rvals: ${rvals}"`);
392
401
  }
393
- rTokens.forEach((token, j) => {
394
- parameters[token] = rvals[j];
395
- });
402
+ if (this.acceptJsonRequest) {
403
+ // Attempt to parse each request parameter as JSON; continue with string if failed
404
+ rTokens.forEach((token, j) => {
405
+ try {
406
+ parameters[token] = JSON.parse(rvals[j]);
407
+ }
408
+ catch (_a) {
409
+ parameters[token] = rvals[j];
410
+ }
411
+ });
412
+ }
413
+ else {
414
+ rTokens.forEach((token, j) => {
415
+ parameters[token] = rvals[j];
416
+ });
417
+ }
396
418
  p === null || p === void 0 ? void 0 : p.tokens.forEach((token, j) => {
397
419
  parameters[token] = p === null || p === void 0 ? void 0 : p.policy[i][j];
398
420
  });
@@ -468,7 +468,7 @@ export async function newEnforcerWithClass(enforcer, ...params) {
468
468
  await e.initWithFile(params[0].toString(), params[1].toString());
469
469
  }
470
470
  else {
471
- await e.initWithAdapter(params[0].toString(), params[1]);
471
+ await e.initWithAdapter(params[0].toString(), params[1], params[2] === true);
472
472
  }
473
473
  }
474
474
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "casbin",
3
- "version": "5.37.0",
3
+ "version": "5.39.0",
4
4
  "description": "An authorization library that supports access control models like ACL, RBAC, ABAC in Node.JS",
5
5
  "main": "lib/cjs/index.js",
6
6
  "typings": "lib/cjs/index.d.ts",