@nocobase/acl 2.1.0-beta.2 → 2.1.0-beta.6

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
@@ -1,17 +1,24 @@
1
1
  # NocoBase
2
2
 
3
3
  <video width="100%" controls>
4
- <source src="https://static-docs.nocobase.com/NocoBase0510.mp4" type="video/mp4">
4
+ <source src="https://github.com/user-attachments/assets/4d11a87b-00e2-48f3-9bf7-389d21072d13" type="video/mp4">
5
5
  </video>
6
6
 
7
+ <p align="center">
8
+ <a href="https://trendshift.io/repositories/4112" target="_blank"><img src="https://trendshift.io/api/badge/repositories/4112" alt="nocobase%2Fnocobase | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
9
+ <a href="https://www.producthunt.com/posts/nocobase?embed=true&utm_source=badge-top-post-topic-badge&utm_medium=badge&utm_souce=badge-nocobase" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/top-post-topic-badge.svg?post_id=456520&theme=light&period=weekly&topic_id=267" alt="NocoBase - Scalability&#0045;first&#0044;&#0032;open&#0045;source&#0032;no&#0045;code&#0032;platform | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
10
+ </p>
7
11
 
8
12
  ## What is NocoBase
9
13
 
10
- NocoBase is a scalability-first, open-source no-code development platform.
11
- Instead of investing years of time and millions of dollars in research and development, deploy NocoBase in a few minutes and you'll have a private, controllable, and extremely scalable no-code development platform!
14
+ NocoBase is the most extensible AI-powered no-code platform.
15
+ Total control. Infinite extensibility. AI collaboration.
16
+ Enable your team to adapt quickly and cut costs dramatically.
17
+ No years of development. No millions wasted.
18
+ Deploy NocoBase in minutes — and take control of everything.
12
19
 
13
20
  Homepage:
14
- https://www.nocobase.com/
21
+ https://www.nocobase.com/
15
22
 
16
23
  Online Demo:
17
24
  https://demo.nocobase.com/new
@@ -19,12 +26,74 @@ https://demo.nocobase.com/new
19
26
  Documents:
20
27
  https://docs.nocobase.com/
21
28
 
22
- Commericial license & plugins:
23
- https://www.nocobase.com/en/commercial
29
+ Forum:
30
+ https://forum.nocobase.com/
24
31
 
25
- License agreement:
26
- https://www.nocobase.com/en/agreement
32
+ Use Cases:
33
+ https://www.nocobase.com/en/blog/tags/customer-stories
27
34
 
35
+ ## Release Notes
28
36
 
29
- ## Contact Us:
30
- hello@nocobase.com
37
+ Our [blog](https://www.nocobase.com/en/blog/timeline) is regularly updated with release notes and provides a weekly summary.
38
+
39
+ ## Distinctive features
40
+
41
+ ### 1. Data model-driven, not form/table–driven
42
+
43
+ Instead of being constrained by forms or tables, NocoBase adopts a data model–driven approach, separating data structure from user interface to unlock unlimited possibilities.
44
+
45
+ - UI and data structure are fully decoupled
46
+ - Multiple blocks and actions can be created for the same table or record in any quantity or form
47
+ - Supports the main database, external databases, and third-party APIs as data sources
48
+
49
+ ![model](https://static-docs.nocobase.com/model.png)
50
+
51
+ ### 2. AI employees, integrated into your business systems
52
+ Unlike standalone AI demos, NocoBase allows you to embed AI capabilities seamlessly into your interfaces, workflows, and data context, making AI truly useful in real business scenarios.
53
+
54
+ - Define AI employees for roles such as translator, analyst, researcher, or assistant
55
+ - Seamless AI–human collaboration in interfaces and workflows
56
+ - Ensure AI usage is secure, transparent, and customizable for your business needs
57
+
58
+ ![AI-employee](https://static-docs.nocobase.com/ai-employee-home.png)
59
+
60
+ ### 3. What you see is what you get, incredibly easy to use
61
+
62
+ While enabling the development of complex business systems, NocoBase keeps the experience simple and intuitive.
63
+
64
+ - One-click switch between usage mode and configuration mode
65
+ - Pages serve as a canvas to arrange blocks and actions, similar to Notion
66
+ - Configuration mode is designed for ordinary users, not just programmers
67
+
68
+ ![wysiwyg](https://static-docs.nocobase.com/wysiwyg.gif)
69
+
70
+ ### 4. Everything is a plugin, designed for extension
71
+ Adding more no-code features will never cover every business case. NocoBase is built for extension through its plugin-based microkernel architecture.
72
+
73
+ - All functionalities are plugins, similar to WordPress
74
+ - Plugins are ready to use upon installation
75
+ - Pages, blocks, actions, APIs, and data sources can all be extended through custom plugins
76
+
77
+ ![plugins](https://static-docs.nocobase.com/plugins.png)
78
+
79
+ ## Installation
80
+
81
+ NocoBase supports three installation methods:
82
+
83
+ - <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/docker-compose">Installing With Docker (👍Recommended)</a>
84
+
85
+ Suitable for no-code scenarios, no code to write. When upgrading, just download the latest image and reboot.
86
+
87
+ - <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/create-nocobase-app">Installing from create-nocobase-app CLI</a>
88
+
89
+ The business code of the project is completely independent and supports low-code development.
90
+
91
+ - <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/git-clone">Installing from Git source code</a>
92
+
93
+ If you want to experience the latest unreleased version, or want to participate in the contribution, you need to make changes and debug on the source code, it is recommended to choose this installation method, which requires a high level of development skills, and if the code has been updated, you can git pull the latest code.
94
+
95
+ ## How NocoBase works
96
+
97
+ <video width="100%" controls>
98
+ <source src="https://github.com/user-attachments/assets/8d183b44-9bb5-4792-b08f-bc08fe8dfaaf" type="video/mp4">
99
+ </video>
package/lib/acl.d.ts CHANGED
@@ -15,6 +15,7 @@ import { ACLRole, ResourceActionsOptions, RoleActionParams } from './acl-role';
15
15
  import { AllowManager, ConditionFunc } from './allow-manager';
16
16
  import FixedParamsManager, { Merger, GeneralMerger } from './fixed-params-manager';
17
17
  import SnippetManager, { SnippetOptions } from './snippet-manager';
18
+ import Database from '@nocobase/database';
18
19
  export interface CanResult {
19
20
  role: string;
20
21
  resource: string;
@@ -44,6 +45,14 @@ export interface ListenerContext {
44
45
  params: RoleActionParams;
45
46
  }
46
47
  type Listener = (ctx: ListenerContext) => void;
48
+ export type UserProvider = (args: {
49
+ fields: string[];
50
+ }) => Promise<any>;
51
+ export interface ParseJsonTemplateOptions {
52
+ timezone?: string;
53
+ state?: any;
54
+ userProvider?: UserProvider;
55
+ }
47
56
  interface CanArgs {
48
57
  role?: string;
49
58
  resource: string;
@@ -104,10 +113,6 @@ export declare class ACL extends EventEmitter {
104
113
  * @deprecated
105
114
  */
106
115
  skip(resourceName: string, actionNames: string[] | string, condition?: string | ConditionFunc): void;
107
- /**
108
- * @internal
109
- */
110
- parseJsonTemplate(json: any, ctx: any): Promise<any>;
111
116
  middleware(): (ctx: any, next: any) => Promise<void>;
112
117
  /**
113
118
  * @internal
@@ -116,11 +121,20 @@ export declare class ACL extends EventEmitter {
116
121
  addGeneralFixedParams(merger: GeneralMerger): void;
117
122
  addFixedParams(resource: string, action: string, merger: Merger): void;
118
123
  registerSnippet(snippet: SnippetOptions): void;
119
- /**
120
- * @internal
121
- */
122
- filterParams(ctx: any, resourceName: any, params: any): any;
123
124
  protected addCoreMiddleware(): void;
124
125
  protected isAvailableAction(actionName: string): boolean;
125
126
  }
127
+ export declare function createUserProvider(options: {
128
+ db?: Database;
129
+ dataSourceManager?: any;
130
+ currentUser?: any;
131
+ }): UserProvider;
132
+ /**
133
+ * @internal
134
+ */
135
+ export declare function parseJsonTemplate(filter: any, options: ParseJsonTemplateOptions): Promise<any>;
136
+ /**
137
+ * @internal
138
+ */
139
+ export declare function checkFilterParams(collection: any, filter: any): void;
126
140
  export {};
package/lib/acl.js CHANGED
@@ -37,7 +37,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
37
37
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
38
  var acl_exports = {};
39
39
  __export(acl_exports, {
40
- ACL: () => ACL
40
+ ACL: () => ACL,
41
+ checkFilterParams: () => checkFilterParams,
42
+ createUserProvider: () => createUserProvider,
43
+ parseJsonTemplate: () => parseJsonTemplate
41
44
  });
42
45
  module.exports = __toCommonJS(acl_exports);
43
46
  var import_utils = require("@nocobase/utils");
@@ -279,31 +282,6 @@ const _ACL = class _ACL extends import_events.default {
279
282
  this.allowManager.allow(resourceName, actionName, condition);
280
283
  }
281
284
  }
282
- /**
283
- * @internal
284
- */
285
- async parseJsonTemplate(json, ctx) {
286
- var _a, _b, _c, _d, _e;
287
- if (json.filter) {
288
- (_b = (_a = ctx.logger) == null ? void 0 : _a.info) == null ? void 0 : _b.call(_a, "parseJsonTemplate.raw", JSON.parse(JSON.stringify(json.filter)));
289
- const timezone = (_c = ctx == null ? void 0 : ctx.get) == null ? void 0 : _c.call(ctx, "x-timezone");
290
- const state = JSON.parse(JSON.stringify(ctx.state));
291
- const filter = await (0, import_utils.parseFilter)(json.filter, {
292
- timezone,
293
- now: (/* @__PURE__ */ new Date()).toISOString(),
294
- vars: {
295
- ctx: {
296
- state
297
- },
298
- $user: getUser(ctx),
299
- $nRole: /* @__PURE__ */ __name(() => state.currentRole, "$nRole")
300
- }
301
- });
302
- json.filter = filter;
303
- (_e = (_d = ctx.logger) == null ? void 0 : _d.info) == null ? void 0 : _e.call(_d, "parseJsonTemplate.parsed", filter);
304
- }
305
- return json;
306
- }
307
285
  middleware() {
308
286
  const acl = this;
309
287
  return /* @__PURE__ */ __name(async function ACLMiddleware(ctx, next) {
@@ -377,40 +355,11 @@ const _ACL = class _ACL extends import_events.default {
377
355
  registerSnippet(snippet) {
378
356
  this.snippetManager.register(snippet);
379
357
  }
380
- /**
381
- * @internal
382
- */
383
- filterParams(ctx, resourceName, params) {
384
- var _a, _b, _c;
385
- if ((_a = params == null ? void 0 : params.filter) == null ? void 0 : _a.createdById) {
386
- const collection = ctx.db.getCollection(resourceName);
387
- if (!collection || !collection.getField("createdById")) {
388
- throw new import_no_permission_error.NoPermissionError("createdById field not found");
389
- }
390
- }
391
- if ((_c = (_b = params == null ? void 0 : params.filter) == null ? void 0 : _b.$or) == null ? void 0 : _c.length) {
392
- const checkCreatedById = /* @__PURE__ */ __name((items) => {
393
- return items.some(
394
- (x) => {
395
- var _a2, _b2;
396
- return "createdById" in x || ((_a2 = x.$or) == null ? void 0 : _a2.some((y) => "createdById" in y)) || ((_b2 = x.$and) == null ? void 0 : _b2.some((y) => "createdById" in y));
397
- }
398
- );
399
- }, "checkCreatedById");
400
- if (checkCreatedById(params.filter.$or)) {
401
- const collection = ctx.db.getCollection(resourceName);
402
- if (!collection || !collection.getField("createdById")) {
403
- throw new import_no_permission_error.NoPermissionError("createdById field not found");
404
- }
405
- }
406
- }
407
- return params;
408
- }
409
358
  addCoreMiddleware() {
410
359
  const acl = this;
411
360
  this.middlewares.add(
412
361
  async (ctx, next) => {
413
- var _a, _b, _c, _d;
362
+ var _a, _b, _c, _d, _e, _f;
414
363
  const resourcerAction = ctx.action;
415
364
  const { resourceName, actionName } = ctx.permission;
416
365
  const permission = ctx.permission;
@@ -423,10 +372,20 @@ const _ACL = class _ACL extends import_events.default {
423
372
  ((_c = ctx.log) == null ? void 0 : _c.debug) && ctx.log.debug("acl params", params);
424
373
  try {
425
374
  if (params && resourcerAction.mergeParams) {
426
- const filteredParams = acl.filterParams(ctx, resourceName, params);
427
- const parsedParams = await acl.parseJsonTemplate(filteredParams, ctx);
375
+ const db = ctx.database ?? ctx.db;
376
+ const collection = (_d = db == null ? void 0 : db.getCollection) == null ? void 0 : _d.call(db, resourceName);
377
+ checkFilterParams(collection, params == null ? void 0 : params.filter);
378
+ const parsedFilter = await parseJsonTemplate(params.filter, {
379
+ state: ctx.state,
380
+ timezone: getTimezone(ctx),
381
+ userProvider: createUserProvider({
382
+ db: ctx.db,
383
+ currentUser: (_e = ctx.state) == null ? void 0 : _e.currentUser
384
+ })
385
+ });
386
+ const parsedParams = params.filter ? { ...params, filter: parsedFilter ?? params.filter } : params;
428
387
  ctx.permission.parsedParams = parsedParams;
429
- ((_d = ctx.log) == null ? void 0 : _d.debug) && ctx.log.debug("acl parsedParams", parsedParams);
388
+ ((_f = ctx.log) == null ? void 0 : _f.debug) && ctx.log.debug("acl parsedParams", parsedParams);
430
389
  ctx.permission.rawParams = import_lodash.default.cloneDeep(resourcerAction.params);
431
390
  if (parsedParams.appends && resourcerAction.params.fields) {
432
391
  for (const queryField of resourcerAction.params.fields) {
@@ -477,31 +436,99 @@ const _ACL = class _ACL extends import_events.default {
477
436
  };
478
437
  __name(_ACL, "ACL");
479
438
  let ACL = _ACL;
480
- function getUser(ctx) {
481
- const dataSource = ctx.app.dataSourceManager.dataSources.get("main");
482
- const db = dataSource.collectionManager.db;
439
+ function getTimezone(ctx) {
440
+ var _a, _b, _c, _d, _e, _f;
441
+ return ((_b = (_a = ctx == null ? void 0 : ctx.request) == null ? void 0 : _a.get) == null ? void 0 : _b.call(_a, "x-timezone")) ?? ((_d = (_c = ctx == null ? void 0 : ctx.request) == null ? void 0 : _c.header) == null ? void 0 : _d["x-timezone"]) ?? ((_f = (_e = ctx == null ? void 0 : ctx.req) == null ? void 0 : _e.headers) == null ? void 0 : _f["x-timezone"]);
442
+ }
443
+ __name(getTimezone, "getTimezone");
444
+ function createUserProvider(options) {
445
+ var _a, _b, _c, _d, _e;
446
+ const db = options.db ?? ((_e = (_d = (_c = (_b = (_a = options.dataSourceManager) == null ? void 0 : _a.dataSources) == null ? void 0 : _b.get) == null ? void 0 : _c.call(_b, "main")) == null ? void 0 : _d.collectionManager) == null ? void 0 : _e.db);
447
+ const currentUser = options.currentUser;
483
448
  return async ({ fields }) => {
484
- var _a, _b;
485
- const userFields = fields.filter((f) => f && db.getFieldByPath("users." + f));
486
- (_a = ctx.logger) == null ? void 0 : _a.info("filter-parse: ", { userFields });
487
- if (!ctx.state.currentUser) {
449
+ if (!db) {
488
450
  return;
489
451
  }
452
+ if (!currentUser) {
453
+ return;
454
+ }
455
+ const userFields = fields.filter((f) => f && db.getFieldByPath("users." + f));
490
456
  if (!userFields.length) {
491
457
  return;
492
458
  }
493
459
  const user = await db.getRepository("users").findOne({
494
- filterByTk: ctx.state.currentUser.id,
460
+ filterByTk: currentUser.id,
495
461
  fields: userFields
496
462
  });
497
- (_b = ctx.logger) == null ? void 0 : _b.info("filter-parse: ", {
498
- $user: user == null ? void 0 : user.toJSON()
499
- });
500
463
  return user;
501
464
  };
502
465
  }
503
- __name(getUser, "getUser");
466
+ __name(createUserProvider, "createUserProvider");
467
+ function containsCreatedByIdFilter(input, seen = /* @__PURE__ */ new Set()) {
468
+ if (!input) {
469
+ return false;
470
+ }
471
+ if (Array.isArray(input)) {
472
+ return input.some((item) => containsCreatedByIdFilter(item, seen));
473
+ }
474
+ if (!import_lodash.default.isPlainObject(input)) {
475
+ return false;
476
+ }
477
+ if (seen.has(input)) {
478
+ return false;
479
+ }
480
+ seen.add(input);
481
+ for (const [key, value] of Object.entries(input)) {
482
+ if (isCreatedByIdKey(key)) {
483
+ return true;
484
+ }
485
+ if (containsCreatedByIdFilter(value, seen)) {
486
+ return true;
487
+ }
488
+ }
489
+ return false;
490
+ }
491
+ __name(containsCreatedByIdFilter, "containsCreatedByIdFilter");
492
+ function isCreatedByIdKey(key) {
493
+ return key === "createdById" || key.startsWith("createdById.") || key.startsWith("createdById$");
494
+ }
495
+ __name(isCreatedByIdKey, "isCreatedByIdKey");
496
+ async function parseJsonTemplate(filter, options) {
497
+ if (!filter) {
498
+ return filter;
499
+ }
500
+ const timezone = options == null ? void 0 : options.timezone;
501
+ const state = JSON.parse(JSON.stringify((options == null ? void 0 : options.state) || {}));
502
+ const parsedFilter = await (0, import_utils.parseFilter)(filter, {
503
+ timezone,
504
+ now: (/* @__PURE__ */ new Date()).toISOString(),
505
+ vars: {
506
+ ctx: {
507
+ state
508
+ },
509
+ $user: (options == null ? void 0 : options.userProvider) || (async () => void 0),
510
+ $nRole: /* @__PURE__ */ __name(() => state.currentRole, "$nRole")
511
+ }
512
+ });
513
+ return parsedFilter;
514
+ }
515
+ __name(parseJsonTemplate, "parseJsonTemplate");
516
+ function checkFilterParams(collection, filter) {
517
+ if (!filter) {
518
+ return;
519
+ }
520
+ if (!containsCreatedByIdFilter(filter)) {
521
+ return;
522
+ }
523
+ if (!collection || !collection.getField("createdById")) {
524
+ throw new import_no_permission_error.NoPermissionError("createdById field not found");
525
+ }
526
+ }
527
+ __name(checkFilterParams, "checkFilterParams");
504
528
  // Annotate the CommonJS export names for ESM import in node:
505
529
  0 && (module.exports = {
506
- ACL
530
+ ACL,
531
+ checkFilterParams,
532
+ createUserProvider,
533
+ parseJsonTemplate
507
534
  });
package/package.json CHANGED
@@ -1,19 +1,22 @@
1
1
  {
2
2
  "name": "@nocobase/acl",
3
- "version": "2.1.0-beta.2",
3
+ "version": "2.1.0-beta.6",
4
4
  "description": "",
5
- "license": "AGPL-3.0",
5
+ "license": "Apache-2.0",
6
6
  "main": "./lib/index.js",
7
7
  "types": "./lib/index.d.ts",
8
8
  "dependencies": {
9
- "@nocobase/resourcer": "2.1.0-beta.2",
10
- "@nocobase/utils": "2.1.0-beta.2",
11
9
  "minimatch": "^5.1.1"
12
10
  },
11
+ "peerDependencies": {
12
+ "@nocobase/database": "2.1.0-beta.5",
13
+ "@nocobase/resourcer": "2.1.0-beta.5",
14
+ "@nocobase/utils": "2.1.0-beta.5"
15
+ },
13
16
  "repository": {
14
17
  "type": "git",
15
18
  "url": "git+https://github.com/nocobase/nocobase.git",
16
19
  "directory": "packages/acl"
17
20
  },
18
- "gitHead": "d80433799fb4a8d59ded4d7eea114d585a137ea0"
21
+ "gitHead": "439e45f32ee5f34d771e7f4751ef57eb7d4a82a8"
19
22
  }