cabloy 5.1.240 → 5.1.242

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.
Files changed (55) hide show
  1. package/.cabloy-version +1 -1
  2. package/CHANGELOG.md +24 -0
  3. package/package.json +1 -1
  4. package/repo-docs/backend/i18n-guide.md +109 -11
  5. package/repo-docs/backend/openapi-guide.md +18 -0
  6. package/repo-docs/frontend/environment-config-guide.md +43 -0
  7. package/repo-docs/frontend/module-scope.md +88 -0
  8. package/repo-docs/frontend/system-startup-guide.md +31 -0
  9. package/repo-e2e/specs/home-user-account.spec.ts +53 -8
  10. package/vona/packages-vona/vona/package.json +1 -1
  11. package/vona/pnpm-lock.yaml +17 -142
  12. package/vona/src/suite/a-commerce/modules/commerce-siteadmin/src/dto/operatorContext.ts +4 -1
  13. package/vona/src/suite/a-commerce/modules/commerce-siteadmin/src/service/operator.ts +1 -0
  14. package/vona/src/suite/a-commerce/modules/commerce-siteadmin/test/operatorAccess.test.ts +1 -0
  15. package/vona/src/suite/a-home/modules/home-user/src/bean/meta.version.ts +1 -0
  16. package/vona/src/suite/a-home/modules/home-user/src/controller/passport.ts +1 -0
  17. package/vona/src/suite/a-home/modules/home-user/src/dto/accountCurrent.ts +3 -0
  18. package/vona/src/suite/a-home/modules/home-user/src/dto/accountProfileUpdate.ts +9 -2
  19. package/vona/src/suite/a-home/modules/home-user/src/dto/passportUser.ts +3 -0
  20. package/vona/src/suite/a-home/modules/home-user/src/entity/user.ts +3 -0
  21. package/vona/src/suite/a-home/modules/home-user/src/service/account.ts +7 -3
  22. package/vona/src/suite/a-home/modules/home-user/src/service/userAdapter.ts +1 -0
  23. package/vona/src/suite/a-home/modules/home-user/test/account.test.ts +133 -8
  24. package/vona/src/suite/a-home/modules/home-user/test/accountOpenapi.test.ts +32 -5
  25. package/vona/src/suite/a-home/modules/home-user/test/passport.test.ts +159 -1
  26. package/vona/src/suite-vendor/a-cabloy/modules/a-rbac/package.json +1 -1
  27. package/vona/src/suite-vendor/a-cabloy/package.json +2 -2
  28. package/vona/src/suite-vendor/a-captcha/modules/a-captcha/package.json +1 -1
  29. package/vona/src/suite-vendor/a-captcha/modules/a-captcha/src/bean/bean.captcha.ts +271 -137
  30. package/vona/src/suite-vendor/a-captcha/modules/a-captcha/src/bean/cacheRedis.captcha.ts +199 -2
  31. package/vona/src/suite-vendor/a-captcha/modules/a-captcha/src/lib/captchaLua.ts +90 -0
  32. package/vona/src/suite-vendor/a-captcha/modules/a-captcha/src/types/captcha.ts +15 -1
  33. package/vona/src/suite-vendor/a-captcha/modules/a-captcha/src/types/captchaProvider.ts +38 -1
  34. package/vona/src/suite-vendor/a-captcha/package.json +1 -1
  35. package/vona/src/suite-vendor/a-vona/modules/a-permission/package.json +1 -1
  36. package/vona/src/suite-vendor/a-vona/modules/a-permission/src/bean/bean.permission.ts +54 -8
  37. package/vona/src/suite-vendor/a-vona/modules/a-permission/test/permission.test.ts +12 -15
  38. package/vona/src/suite-vendor/a-vona/modules/a-ratelimit/package.json +1 -1
  39. package/vona/src/suite-vendor/a-vona/modules/a-user/package.json +1 -1
  40. package/vona/src/suite-vendor/a-vona/modules/a-user/src/types/user.ts +1 -0
  41. package/vona/src/suite-vendor/a-vona/package.json +1 -1
  42. package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/api/openapi/schemas.ts +68 -52
  43. package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/api/openapi/types.ts +530 -344
  44. package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/page/dashboard/controller.tsx +7 -1
  45. package/zova/src/suite/a-home/modules/home-api/src/api/openapi/types.ts +6 -1
  46. package/zova/src/suite/a-home/modules/home-base/src/config/locale/en-us.ts +1 -0
  47. package/zova/src/suite/a-home/modules/home-base/src/config/locale/zh-cn.ts +1 -0
  48. package/zova/src/suite/a-home/modules/home-layoutadmin/src/component/layoutAdmin/render.user.tsx +1 -1
  49. package/zova/src/suite/a-home/modules/home-layoutweb/src/component/layoutWeb/render.user.tsx +3 -1
  50. package/zova/src/suite/a-home/modules/home-passport/src/model/passport.ts +4 -0
  51. package/zova/src/suite/a-home/modules/home-user/src/config/locale/en-us.ts +1 -0
  52. package/zova/src/suite/a-home/modules/home-user/src/config/locale/zh-cn.ts +1 -0
  53. package/zova/src/suite/a-home/modules/home-user/src/model/account.ts +2 -1
  54. package/zova/src/suite/a-home/modules/home-user/src/page/account/controller.tsx +17 -3
  55. package/vona/src/suite-vendor/a-vona/modules/a-ratelimit/test/aggregate.test.ts +0 -247
@@ -110,25 +110,38 @@ describe('accountOpenapi.test.ts', () => {
110
110
  assert.equal(property?.rest?.form?.required, true);
111
111
  }
112
112
  }
113
+ if (expectation.action === 'current' || expectation.action === 'updateProfile') {
114
+ const response = operation.responses?.['200'];
115
+ assert.ok(response && 'content' in response);
116
+ const body = resolveSchema(doc, response.content?.['application/json']?.schema);
117
+ const current = resolveSchema(doc, body.properties?.data);
118
+ assert.deepEqual(inlineSchema(current.properties?.displayName).type, ['string', 'null']);
119
+ assert.equal(current.required?.includes('displayName') ?? false, false);
120
+ assert.equal(inlineSchema(current.properties?.name).type, 'string');
121
+ assert.ok(current.required?.includes('name'));
122
+ }
113
123
  if (expectation.action === 'updateProfile') {
114
124
  const schemaResolved = requestSchema(doc, operation);
115
125
  assert.deepEqual(Object.keys(schemaResolved?.properties ?? {}), [
116
- 'name',
126
+ 'displayName',
117
127
  'avatar',
118
128
  'locale',
119
129
  'tz',
120
130
  ]);
121
- assert.deepEqual(schemaResolved?.required, ['name']);
131
+ assert.deepEqual(schemaResolved.required ?? [], []);
132
+ assert.equal(schemaResolved.properties?.name, undefined);
122
133
  for (const [field, title] of [
123
- ['name', 'home-user::AccountDisplayName'],
134
+ ['displayName', 'home-user::AccountDisplayName'],
124
135
  ['avatar', 'home-user::AccountAvatar'],
125
136
  ['locale', 'home-user::AccountLocale'],
126
137
  ['tz', 'home-user::AccountTimezone'],
127
138
  ]) {
128
139
  assert.equal(inlineSchema(schemaResolved.properties?.[field]).title?.toString(), title);
129
140
  }
130
- assert.equal(inlineSchema(schemaResolved.properties?.name).minLength, 1);
131
- assert.equal(inlineSchema(schemaResolved.properties?.name).maxLength, 100);
141
+ const displayName = inlineSchema(schemaResolved.properties?.displayName);
142
+ assert.deepEqual(displayName.type, ['string', 'null']);
143
+ assert.equal(displayName.maxLength, 100);
144
+ assert.ok(!displayName.minLength);
132
145
  assert.deepEqual(inlineSchema(schemaResolved.properties?.avatar).type, [
133
146
  'string',
134
147
  'null',
@@ -154,6 +167,20 @@ function inlineSchema(
154
167
  return schema;
155
168
  }
156
169
 
170
+ function resolveSchema(
171
+ doc: OpenAPIObject,
172
+ schema: ReferenceObject | SchemaObject | undefined,
173
+ ): ISchemaObjectExtensionField {
174
+ assert.ok(schema);
175
+ if ('$ref' in schema && typeof schema.$ref === 'string') {
176
+ return resolveSchema(
177
+ doc,
178
+ doc.components?.schemas?.[schema.$ref.replace('#/components/schemas/', '')],
179
+ );
180
+ }
181
+ return inlineSchema(schema);
182
+ }
183
+
157
184
  function requestSchema(
158
185
  doc: OpenAPIObject,
159
186
  operation: OperationObject,
@@ -1,5 +1,5 @@
1
1
  import type { SchemaObject } from 'openapi3-ts/oas31';
2
- import type { IPassport } from 'vona-module-a-user';
2
+ import type { IAuthUserProfile, IPassport } from 'vona-module-a-user';
3
3
 
4
4
  import assert from 'node:assert';
5
5
  import { describe, it, mock } from 'node:test';
@@ -12,6 +12,7 @@ function createPassport(): IPassport {
12
12
  user: {
13
13
  id: 'passport-response-user',
14
14
  name: 'Passport response fixture',
15
+ displayName: 'Passport display name',
15
16
  activated: true,
16
17
  accountStatus: 'active',
17
18
  instanceId: 'untrusted-user-instance',
@@ -38,12 +39,26 @@ describe('passport.test.ts', { concurrency: false }, () => {
38
39
  assert.ok(result);
39
40
  assert.equal(result.instanceId, instanceId);
40
41
  assert.equal(result.user.id, passport.user!.id);
42
+ assert.equal(result.user.name, passport.user!.name);
43
+ assert.equal(result.user.displayName, passport.user!.displayName);
41
44
  assert.equal(result.auth, passport.auth);
42
45
  assert.equal(result.roles, passport.roles);
43
46
  assert.equal('instanceId' in result.user, false);
44
47
  });
45
48
  });
46
49
 
50
+ it('current leaves an absent displayName unset instead of falling back to the username', async () => {
51
+ await app.bean.executor.mockCtx(async () => {
52
+ const passport = createPassport();
53
+ delete passport.user!.displayName;
54
+ app.ctx.state.passport = passport;
55
+ const result = await app.bean._getBean(ControllerPassport).current();
56
+ assert.ok(result);
57
+ assert.equal(result.user.name, passport.user!.name);
58
+ assert.equal(result.user.displayName, undefined);
59
+ });
60
+ });
61
+
47
62
  it('current returns explicit null when the request has no instance', async () => {
48
63
  await app.bean.executor.mockCtx(
49
64
  async () => {
@@ -98,6 +113,8 @@ describe('passport.test.ts', { concurrency: false }, () => {
98
113
  assert.equal(response.passport.instanceId, app.ctx.instance?.id ?? null);
99
114
  assert.ok(Object.hasOwn(response.passport, 'instanceId'));
100
115
  assert.equal(response.passport.user.id, 'passport-response-user');
116
+ assert.equal(response.passport.user.displayName, 'Passport display name');
117
+ assert.equal(response.passport.user.name, 'Passport response fixture');
101
118
  assert.equal(response.jwt, jwt);
102
119
  }
103
120
  assert.equal(authenticate.mock.callCount(), 4);
@@ -112,6 +129,144 @@ describe('passport.test.ts', { concurrency: false }, () => {
112
129
  }
113
130
  });
114
131
 
132
+ it('userOfProfile maps only an actual trimmed provider displayName without name fallbacks', async () => {
133
+ const profile: IAuthUserProfile = {
134
+ id: 'display-name-profile',
135
+ username: 'provider-username',
136
+ name: { givenName: 'Given', familyName: 'Family' },
137
+ emails: [{ value: 'profile@example.test' }],
138
+ photos: [{ value: 'https://example.test/avatar.png' }],
139
+ };
140
+ for (const displayName of [undefined, '', ' \t ', ' Provider display name ']) {
141
+ await app.bean.executor.mockCtx(async () => {
142
+ const user = await app.scope('home-user').service.userAdapter.userOfProfile({
143
+ ...profile,
144
+ ...(displayName === undefined ? {} : { displayName }),
145
+ });
146
+ assert.equal(user.name, profile.username);
147
+ assert.equal(user.displayName, displayName?.trim() || undefined);
148
+ assert.equal(user.email, profile.emails![0].value);
149
+ assert.equal(user.avatar, profile.photos![0].value);
150
+ });
151
+ }
152
+ });
153
+
154
+ it('OAuth creation maps displayName but existing login and linking preserve account profile fields', async () => {
155
+ const suffix = crypto.randomUUID();
156
+ const oauthName = `display-oauth-${suffix}`;
157
+ const linkedName = `display-linked-${suffix}`;
158
+ const profileId = `display-profile-${suffix}`;
159
+ const linkedProfileId = `display-link-${suffix}`;
160
+ const profile: IAuthUserProfile = {
161
+ id: profileId,
162
+ username: oauthName,
163
+ displayName: ' Initial provider display ',
164
+ confirmed: true,
165
+ };
166
+ let oauthUserId: string | undefined;
167
+ let linkedUserId: string | undefined;
168
+ try {
169
+ await app.bean.executor.mockCtx(async () => {
170
+ const provider = await app.bean.authProvider.get({
171
+ providerName: 'auth-oauth:oauth',
172
+ clientName: 'github',
173
+ });
174
+ const passport = await app
175
+ .scope('a-auth')
176
+ .service.auth.issuePassport(profile, provider, {});
177
+ assert.ok(passport.user);
178
+ oauthUserId = passport.user.id.toString();
179
+ assert.equal(passport.user.name, oauthName);
180
+ assert.equal(passport.user.displayName, 'Initial provider display');
181
+ await app.bean.user.updateById(oauthUserId, { displayName: 'Account-owned display' });
182
+ });
183
+
184
+ await app.bean.executor.mockCtx(async () => {
185
+ const provider = await app.bean.authProvider.get({
186
+ providerName: 'auth-oauth:oauth',
187
+ clientName: 'github',
188
+ });
189
+ const passport = await app.scope('a-auth').service.auth.issuePassport(
190
+ { ...profile, username: `${oauthName}-changed`, displayName: 'Changed provider display' },
191
+ provider,
192
+ {},
193
+ {
194
+ intention: 'login',
195
+ authProviderId: provider.id,
196
+ instanceName: app.ctx.instanceName!,
197
+ locale: app.ctx.locale,
198
+ tz: app.ctx.tz,
199
+ },
200
+ );
201
+ assert.equal(passport.user?.id.toString(), oauthUserId);
202
+ assert.equal(passport.user?.name, oauthName);
203
+ assert.equal(passport.user?.displayName, 'Account-owned display');
204
+ const persisted = await app.bean.user.findOneById(oauthUserId!);
205
+ assert.equal(persisted?.displayName, 'Account-owned display');
206
+ });
207
+
208
+ await app.bean.executor.mockCtx(async () => {
209
+ const user = await app.bean.user.register({ name: linkedName }, true);
210
+ linkedUserId = user.id.toString();
211
+ });
212
+ await app.bean.executor.mockCtx(async () => {
213
+ const user = await app.bean.user.findOneById(linkedUserId!);
214
+ assert.ok(user);
215
+ await app.bean.passport.setCurrent({ user });
216
+ try {
217
+ const provider = await app.bean.authProvider.get({
218
+ providerName: 'auth-oauth:oauth',
219
+ clientName: 'github',
220
+ });
221
+ const passport = await app.scope('a-auth').service.auth.issuePassport(
222
+ { ...profile, id: linkedProfileId },
223
+ provider,
224
+ {},
225
+ {
226
+ intention: 'associate',
227
+ authProviderId: provider.id,
228
+ instanceName: app.ctx.instanceName!,
229
+ locale: app.ctx.locale,
230
+ tz: app.ctx.tz,
231
+ },
232
+ );
233
+ assert.equal(passport.user?.id.toString(), linkedUserId);
234
+ assert.equal(passport.user?.name, linkedName);
235
+ assert.equal(passport.user?.displayName, undefined);
236
+ const persisted = await app.bean.user.findOneById(linkedUserId!);
237
+ assert.equal(persisted?.name, linkedName);
238
+ assert.equal(persisted?.displayName, undefined);
239
+ const auth = await app.scope('a-auth').model.auth.get({
240
+ authProviderId: provider.id,
241
+ profileId: linkedProfileId,
242
+ });
243
+ assert.equal(auth?.userId.toString(), linkedUserId);
244
+ } finally {
245
+ await app.bean.passport.setCurrent(undefined);
246
+ }
247
+ });
248
+ } finally {
249
+ await app.bean.executor.mockCtx(async () => {
250
+ const provider = await app.bean.authProvider.get({
251
+ providerName: 'auth-oauth:oauth',
252
+ clientName: 'github',
253
+ });
254
+ for (const id of [linkedProfileId, profileId]) {
255
+ await app
256
+ .scope('a-auth')
257
+ .model.auth.delete({ authProviderId: provider.id, profileId: id });
258
+ }
259
+ for (const name of [linkedName, oauthName]) {
260
+ const user = await app.bean.user.findOneByName(name);
261
+ if (user) {
262
+ await app.scope('home-user').model.roleUser.delete({ userId: user.id });
263
+ await app.bean.user.removeById(user.id);
264
+ }
265
+ }
266
+ });
267
+ }
268
+ });
269
+
115
270
  it('OpenAPI exposes a required nullable table identity on current and every Passport/JWT response', async () => {
116
271
  await app.bean.executor.mockCtx(async () => {
117
272
  const actions = [
@@ -148,6 +303,9 @@ describe('passport.test.ts', { concurrency: false }, () => {
148
303
  const instanceId = resolve(passport.properties?.instanceId as SchemaObject);
149
304
  const user = resolve(passport.properties?.user as SchemaObject);
150
305
  const userId = resolve(user.properties?.id as SchemaObject);
306
+ const displayName = resolve(user.properties?.displayName as SchemaObject);
307
+ assert.deepEqual(displayName.type, ['string', 'null']);
308
+ assert.equal(user.required?.includes('displayName') ?? false, false);
151
309
  const types = (schema: SchemaObject): string[] => {
152
310
  if (schema.anyOf)
153
311
  return schema.anyOf.flatMap(item => types(resolve(item as SchemaObject)));
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vona-module-a-rbac",
3
- "version": "5.0.17",
3
+ "version": "5.0.18",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "Vona Module"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vona-suite-a-cabloy",
3
- "version": "5.1.69",
3
+ "version": "5.1.70",
4
4
  "gitHead": "a79189b882c17af5911573896a781bbb0046d37d",
5
5
  "description": "",
6
6
  "author": "",
@@ -10,7 +10,7 @@
10
10
  "vona-module-a-cabloy": "workspace:^",
11
11
  "vona-module-a-layoutprofile": "^5.0.2",
12
12
  "vona-module-a-markdown": "^5.0.3",
13
- "vona-module-a-rbac": "^5.0.17",
13
+ "vona-module-a-rbac": "^5.0.18",
14
14
  "vona-module-a-socket": "workspace:^",
15
15
  "vona-module-a-ssr": "workspace:^",
16
16
  "vona-module-a-ssrhmr": "workspace:^"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vona-module-a-captcha",
3
- "version": "5.1.15",
3
+ "version": "5.1.16",
4
4
  "gitHead": "a79189b882c17af5911573896a781bbb0046d37d",
5
5
  "description": "",
6
6
  "keywords": [