@nocobase/flow-engine 2.2.0-beta.8 → 2.2.0-beta.9

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.
@@ -2626,12 +2626,16 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
2626
2626
  }, "get")
2627
2627
  });
2628
2628
  this.defineProperty("auth", {
2629
- get: /* @__PURE__ */ __name(() => ({
2630
- roleName: this.api.auth.role,
2631
- locale: this.api.auth.locale,
2632
- token: this.api.auth.token,
2633
- user: this.user
2634
- }), "get")
2629
+ get: /* @__PURE__ */ __name(() => {
2630
+ var _a, _b, _c, _d, _e, _f;
2631
+ return {
2632
+ roleName: (_b = (_a = this.api) == null ? void 0 : _a.auth) == null ? void 0 : _b.role,
2633
+ locale: (_d = (_c = this.api) == null ? void 0 : _c.auth) == null ? void 0 : _d.locale,
2634
+ token: (_f = (_e = this.api) == null ? void 0 : _e.auth) == null ? void 0 : _f.token,
2635
+ user: this.user
2636
+ };
2637
+ }, "get"),
2638
+ cache: false
2635
2639
  });
2636
2640
  this.defineProperty("date", {
2637
2641
  get: /* @__PURE__ */ __name(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/flow-engine",
3
- "version": "2.2.0-beta.8",
3
+ "version": "2.2.0-beta.9",
4
4
  "private": false,
5
5
  "description": "A standalone flow engine for NocoBase, managing workflows, models, and actions.",
6
6
  "main": "lib/index.js",
@@ -8,8 +8,8 @@
8
8
  "dependencies": {
9
9
  "@formily/antd-v5": "1.x",
10
10
  "@formily/reactive": "2.x",
11
- "@nocobase/sdk": "2.2.0-beta.8",
12
- "@nocobase/shared": "2.2.0-beta.8",
11
+ "@nocobase/sdk": "2.2.0-beta.9",
12
+ "@nocobase/shared": "2.2.0-beta.9",
13
13
  "ahooks": "^3.7.2",
14
14
  "axios": "^1.7.0",
15
15
  "dayjs": "^1.11.9",
@@ -37,5 +37,5 @@
37
37
  ],
38
38
  "author": "NocoBase Team",
39
39
  "license": "Apache-2.0",
40
- "gitHead": "fa2502c1e9faf6d74b3f51b42dbc6546638d46af"
40
+ "gitHead": "60e3d7abbaa0c7cead76f71a4f3d5eedb6b8acdb"
41
41
  }
@@ -1607,6 +1607,29 @@ describe('FlowEngine context', () => {
1607
1607
  await expect((engine.context as any).getVar('foo.bar')).rejects.toThrow();
1608
1608
  });
1609
1609
 
1610
+ it('model.context.getVar should resolve the latest ctx.auth.user after user changes', async () => {
1611
+ const engine = new FlowEngine();
1612
+ engine.context.defineProperty('api', {
1613
+ value: { auth: { role: 'admin', locale: 'en-US', token: 'token-1' } },
1614
+ });
1615
+ engine.context.defineProperty('user', { value: { id: 1, nickname: 'Alice' } });
1616
+
1617
+ class AuthUserModel extends FlowModel {}
1618
+ engine.registerModels({ AuthUserModel });
1619
+ const model = engine.createModel({ use: 'AuthUserModel' });
1620
+
1621
+ expect(await model.context.getVar('ctx.auth.user.id')).toBe(1);
1622
+ expect(await model.context.getVar('ctx.auth.token')).toBe('token-1');
1623
+
1624
+ engine.context.api.auth.role = 'member';
1625
+ engine.context.api.auth.token = 'token-2';
1626
+ engine.context.defineProperty('user', { value: { id: 2, nickname: 'Bob' } });
1627
+
1628
+ expect(await model.context.getVar('ctx.auth.user.id')).toBe(2);
1629
+ expect(await model.context.getVar('ctx.auth.roleName')).toBe('member');
1630
+ expect(await model.context.getVar('ctx.auth.token')).toBe('token-2');
1631
+ });
1632
+
1610
1633
  it('engine.context.runAction should resolve action from engine.getAction', async () => {
1611
1634
  const engine = new FlowEngine();
1612
1635
 
@@ -3504,11 +3504,12 @@ export class FlowEngineContext extends BaseFlowEngineContext {
3504
3504
  });
3505
3505
  this.defineProperty('auth', {
3506
3506
  get: () => ({
3507
- roleName: this.api.auth.role,
3508
- locale: this.api.auth.locale,
3509
- token: this.api.auth.token,
3507
+ roleName: this.api?.auth?.role,
3508
+ locale: this.api?.auth?.locale,
3509
+ token: this.api?.auth?.token,
3510
3510
  user: this.user,
3511
3511
  }),
3512
+ cache: false,
3512
3513
  });
3513
3514
  this.defineProperty('date', {
3514
3515
  get: () => {