vona-module-a-captcha 5.0.20 → 5.0.22

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.
@@ -18,7 +18,8 @@ export class CaptchaProvider<%=argv.beanNameCapitalize%>
18
18
  async verify(
19
19
  _token: TypeCaptchaProvider<%=argv.beanNameCapitalize%>Token,
20
20
  _tokenInput: TypeCaptchaProvider<%=argv.beanNameCapitalize%>Token,
21
- _options: ICaptchaProviderOptions<%=argv.beanNameCapitalize%>): Promise<boolean> {
21
+ _options: ICaptchaProviderOptions<%=argv.beanNameCapitalize%>,
22
+ ): Promise<boolean> {
22
23
  return false;
23
24
  }
24
25
  }
@@ -123,17 +123,37 @@ declare module 'vona-module-a-web' {
123
123
  }
124
124
  }
125
125
  /** controller: end */
126
+ /** hmr: begin */
127
+ export * from '../bean/hmr.captchaProvider.ts';
128
+ export * from '../bean/hmr.captchaScene.ts';
129
+ import 'vona';
130
+ declare module 'vona' {
131
+ interface IHmrRecord {
132
+ 'a-captcha:captchaProvider': never;
133
+ 'a-captcha:captchaScene': never;
134
+ }
135
+ }
136
+ declare module 'vona-module-a-captcha' {
137
+ interface HmrCaptchaProvider {
138
+ }
139
+ interface HmrCaptchaProvider {
140
+ get $beanFullName(): 'a-captcha.hmr.captchaProvider';
141
+ get $onionName(): 'a-captcha:captchaProvider';
142
+ }
143
+ interface HmrCaptchaScene {
144
+ }
145
+ interface HmrCaptchaScene {
146
+ get $beanFullName(): 'a-captcha.hmr.captchaScene';
147
+ get $onionName(): 'a-captcha:captchaScene';
148
+ }
149
+ }
150
+ /** hmr: end */
126
151
  /** config: begin */
127
152
  export * from '../config/config.ts';
128
153
  import type { config } from '../config/config.ts';
129
- export declare const locales: {
130
- 'en-us': {
131
- CaptchaInvalid: string;
132
- };
133
- 'zh-cn': {
134
- CaptchaInvalid: string;
135
- };
136
- };
154
+ /** config: end */
155
+ /** locale: begin */
156
+ import { locales } from './locales.ts';
137
157
  /** locale: end */
138
158
  /** scope: begin */
139
159
  import { BeanScopeBase, type BeanScopeUtil, type TypeModuleConfig, type TypeModuleLocales, type TypeLocaleBase } from 'vona';
@@ -160,5 +180,4 @@ declare module 'vona' {
160
180
  'a-captcha': (typeof locales)[TypeLocaleBase];
161
181
  }
162
182
  }
163
- export declare function $locale<K extends keyof (typeof locales)[TypeLocaleBase]>(key: K): `a-captcha::${K}`;
164
183
  /** scope: end */
@@ -0,0 +1,10 @@
1
+ import type { TypeLocaleBase } from 'vona';
2
+ export declare const locales: {
3
+ 'en-us': {
4
+ CaptchaInvalid: string;
5
+ };
6
+ 'zh-cn': {
7
+ CaptchaInvalid: string;
8
+ };
9
+ };
10
+ export declare function $locale<K extends keyof (typeof locales)[TypeLocaleBase]>(key: K): `a-captcha::${K}`;
@@ -1,15 +1,12 @@
1
1
  import type { ICaptchaData, ICaptchaDataCache } from '../types/captcha.ts';
2
- import type { ICaptchaProviderRecord } from '../types/captchaProvider.ts';
3
2
  import type { ICaptchaSceneRecord } from '../types/captchaScene.ts';
4
3
  import { BeanBase } from 'vona';
5
- declare const SymbolProviders: unique symbol;
6
4
  export declare class BeanCaptcha extends BeanBase {
7
- protected [SymbolProviders]: Record<keyof ICaptchaSceneRecord, ICaptchaProviderRecord>;
8
5
  create(sceneName: keyof ICaptchaSceneRecord): Promise<ICaptchaData>;
9
6
  refresh(id: string, sceneName: keyof ICaptchaSceneRecord): Promise<ICaptchaData>;
10
7
  verify(id: string, token: unknown, sceneName: keyof ICaptchaSceneRecord): Promise<boolean>;
11
8
  verifyImmediate(id: string, token: unknown): Promise<false | string>;
12
- getCaptchaData(id: string): Promise<ICaptchaDataCache | null | undefined>;
9
+ getCaptchaData(id: string): Promise<ICaptchaDataCache | undefined>;
13
10
  updateCaptchaToken(id: string, token: unknown): Promise<undefined>;
14
11
  private _getProviderInstance;
15
12
  private _getProviderOptions;
@@ -17,4 +14,3 @@ export declare class BeanCaptcha extends BeanBase {
17
14
  private _getProviders;
18
15
  private _prepareProviders;
19
16
  }
20
- export {};
@@ -0,0 +1,6 @@
1
+ import type { IDecoratorBeanOptionsBase } from 'vona';
2
+ import type { IHmrReload } from 'vona-module-a-hmr';
3
+ import { BeanBase } from 'vona';
4
+ export declare class HmrCaptchaProvider extends BeanBase implements IHmrReload {
5
+ reload(_beanOptions: IDecoratorBeanOptionsBase): Promise<void>;
6
+ }
@@ -0,0 +1,6 @@
1
+ import type { IDecoratorBeanOptionsBase } from 'vona';
2
+ import type { IHmrReload } from 'vona-module-a-hmr';
3
+ import { BeanBase } from 'vona';
4
+ export declare class HmrCaptchaScene extends BeanBase implements IHmrReload {
5
+ reload(_beanOptions: IDecoratorBeanOptionsBase): Promise<void>;
6
+ }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './.metadata/index.ts';
2
+ export * from './.metadata/locales.ts';
2
3
  export * from './lib/index.ts';
3
4
  export * from './types/index.ts';
package/dist/index.js CHANGED
@@ -7,13 +7,14 @@ import { Api, v } from 'vona-module-a-openapiutils';
7
7
  import { Dto, Controller, Web, Arg } from 'vona-module-a-web';
8
8
  import z from 'zod';
9
9
  import { Passport } from 'vona-module-a-user';
10
+ import { Hmr } from 'vona-module-a-hmr';
10
11
 
11
- var _dec$6, _dec2$6, _class$6;
12
- let InterceptorCaptchaVerify = (_dec$6 = Interceptor({
12
+ var _dec$8, _dec2$8, _class$8;
13
+ let InterceptorCaptchaVerify = (_dec$8 = Interceptor({
13
14
  bodyField: 'captcha'
14
- }), _dec2$6 = BeanInfo({
15
+ }), _dec2$8 = BeanInfo({
15
16
  module: "a-captcha"
16
- }), _dec$6(_class$6 = _dec2$6(_class$6 = class InterceptorCaptchaVerify extends BeanBase {
17
+ }), _dec$8(_class$8 = _dec2$8(_class$8 = class InterceptorCaptchaVerify extends BeanBase {
17
18
  async execute(options, next) {
18
19
  // scene
19
20
  const sceneName = options.scene;
@@ -29,17 +30,17 @@ let InterceptorCaptchaVerify = (_dec$6 = Interceptor({
29
30
  // next
30
31
  return next();
31
32
  }
32
- }) || _class$6) || _class$6);
33
+ }) || _class$8) || _class$8);
34
+
35
+ const SymbolCacheSceneProviders = Symbol('SymbolCacheSceneProviders');
36
+ function clearAllCacheSceneProviders(app) {
37
+ delete app.meta[SymbolCacheSceneProviders];
38
+ }
33
39
 
34
- var _dec$5, _dec2$5, _class$5;
35
- const SymbolProviders = Symbol('SymbolProviders');
36
- let BeanCaptcha = (_dec$5 = Bean(), _dec2$5 = BeanInfo({
40
+ var _dec$7, _dec2$7, _class$7;
41
+ let BeanCaptcha = (_dec$7 = Bean(), _dec2$7 = BeanInfo({
37
42
  module: "a-captcha"
38
- }), _dec$5(_class$5 = _dec2$5(_class$5 = class BeanCaptcha extends BeanBase {
39
- constructor(...args) {
40
- super(...args);
41
- this[SymbolProviders] = {};
42
- }
43
+ }), _dec$7(_class$7 = _dec2$7(_class$7 = class BeanCaptcha extends BeanBase {
43
44
  async create(sceneName) {
44
45
  // resolve provider
45
46
  const provider = await this._resolveProvider(sceneName);
@@ -212,13 +213,14 @@ let BeanCaptcha = (_dec$5 = Bean(), _dec2$5 = BeanInfo({
212
213
  };
213
214
  }
214
215
  _getProviders(sceneName) {
215
- if (!this[SymbolProviders][sceneName]) {
216
+ if (!this.app.meta[SymbolCacheSceneProviders]) this.app.meta[SymbolCacheSceneProviders] = {};
217
+ if (!this.app.meta[SymbolCacheSceneProviders][sceneName]) {
216
218
  const onionSlice = this.bean.onion.captchaScene.getOnionSlice(sceneName);
217
219
  if (!onionSlice) throw new Error(`not found captcha scene: ${sceneName}`);
218
220
  const onionOptions = onionSlice.beanOptions.options;
219
- this[SymbolProviders][sceneName] = this._prepareProviders(onionOptions?.providers);
221
+ this.app.meta[SymbolCacheSceneProviders][sceneName] = this._prepareProviders(onionOptions?.providers);
220
222
  }
221
- return this[SymbolProviders][sceneName];
223
+ return this.app.meta[SymbolCacheSceneProviders][sceneName];
222
224
  }
223
225
  _prepareProviders(providers) {
224
226
  if (!providers) return {};
@@ -233,19 +235,19 @@ let BeanCaptcha = (_dec$5 = Bean(), _dec2$5 = BeanInfo({
233
235
  }
234
236
  return providersNew;
235
237
  }
236
- }) || _class$5) || _class$5);
238
+ }) || _class$7) || _class$7);
237
239
  async function resolverDefault(_ctx, providers) {
238
240
  const keys = Object.keys(providers);
239
241
  const index = getRandomInt(keys.length, 0);
240
242
  return keys[index];
241
243
  }
242
244
 
243
- var _dec$4, _dec2$4, _class$4;
244
- let CacheRedisCaptcha = (_dec$4 = CacheRedis({
245
+ var _dec$6, _dec2$6, _class$6;
246
+ let CacheRedisCaptcha = (_dec$6 = CacheRedis({
245
247
  disableTransactionCompensate: true
246
- }), _dec2$4 = BeanInfo({
248
+ }), _dec2$6 = BeanInfo({
247
249
  module: "a-captcha"
248
- }), _dec$4(_class$4 = _dec2$4(_class$4 = class CacheRedisCaptcha extends BeanCacheRedisBase {}) || _class$4) || _class$4);
250
+ }), _dec$6(_class$6 = _dec2$6(_class$6 = class CacheRedisCaptcha extends BeanCacheRedisBase {}) || _class$6) || _class$6);
249
251
 
250
252
  function _applyDecoratedDescriptor(i, e, r, n, l) {
251
253
  var a = {};
@@ -264,10 +266,10 @@ function _initializerDefineProperty(e, i, r, l) {
264
266
  });
265
267
  }
266
268
 
267
- var _dec$3, _dec2$3, _dec3$2, _dec4$2, _dec5$2, _dec6$2, _dec7$1, _dec8$1, _dec9$1, _dec0$1, _class$3, _class2$2, _descriptor$1, _descriptor2$1, _descriptor3, _descriptor4;
268
- let DtoCaptchaData = (_dec$3 = Dto(), _dec2$3 = BeanInfo({
269
+ var _dec$5, _dec2$5, _dec3$2, _dec4$2, _dec5$2, _dec6$2, _dec7$1, _dec8$1, _dec9$1, _dec0$1, _class$5, _class2$2, _descriptor$1, _descriptor2$1, _descriptor3, _descriptor4;
270
+ let DtoCaptchaData = (_dec$5 = Dto(), _dec2$5 = BeanInfo({
269
271
  module: "a-captcha"
270
- }), _dec3$2 = Api.field(), _dec4$2 = Reflect.metadata("design:type", String), _dec5$2 = Api.field(z.string()), _dec6$2 = Reflect.metadata("design:type", Object), _dec7$1 = Api.field(v.optional()), _dec8$1 = Reflect.metadata("design:type", Object), _dec9$1 = Api.field(), _dec0$1 = Reflect.metadata("design:type", Object), _dec$3(_class$3 = _dec2$3(_class$3 = (_class2$2 = class DtoCaptchaData {
272
+ }), _dec3$2 = Api.field(), _dec4$2 = Reflect.metadata("design:type", String), _dec5$2 = Api.field(z.string()), _dec6$2 = Reflect.metadata("design:type", Object), _dec7$1 = Api.field(v.optional()), _dec8$1 = Reflect.metadata("design:type", Object), _dec9$1 = Api.field(), _dec0$1 = Reflect.metadata("design:type", Object), _dec$5(_class$5 = _dec2$5(_class$5 = (_class2$2 = class DtoCaptchaData {
271
273
  constructor() {
272
274
  _initializerDefineProperty(this, "id", _descriptor$1, this);
273
275
  _initializerDefineProperty(this, "provider", _descriptor2$1, this);
@@ -294,12 +296,12 @@ let DtoCaptchaData = (_dec$3 = Dto(), _dec2$3 = BeanInfo({
294
296
  enumerable: true,
295
297
  writable: true,
296
298
  initializer: null
297
- }), _class2$2)) || _class$3) || _class$3);
299
+ }), _class2$2)) || _class$5) || _class$5);
298
300
 
299
- var _dec$2, _dec2$2, _dec3$1, _dec4$1, _dec5$1, _dec6$1, _class$2, _class2$1, _descriptor, _descriptor2;
300
- let DtoCaptchaVerify = (_dec$2 = Dto(), _dec2$2 = BeanInfo({
301
+ var _dec$4, _dec2$4, _dec3$1, _dec4$1, _dec5$1, _dec6$1, _class$4, _class2$1, _descriptor, _descriptor2;
302
+ let DtoCaptchaVerify = (_dec$4 = Dto(), _dec2$4 = BeanInfo({
301
303
  module: "a-captcha"
302
- }), _dec3$1 = Api.field(), _dec4$1 = Reflect.metadata("design:type", String), _dec5$1 = Api.field(), _dec6$1 = Reflect.metadata("design:type", Object), _dec$2(_class$2 = _dec2$2(_class$2 = (_class2$1 = class DtoCaptchaVerify {
304
+ }), _dec3$1 = Api.field(), _dec4$1 = Reflect.metadata("design:type", String), _dec5$1 = Api.field(), _dec6$1 = Reflect.metadata("design:type", Object), _dec$4(_class$4 = _dec2$4(_class$4 = (_class2$1 = class DtoCaptchaVerify {
303
305
  constructor() {
304
306
  _initializerDefineProperty(this, "id", _descriptor, this);
305
307
  _initializerDefineProperty(this, "token", _descriptor2, this);
@@ -314,10 +316,10 @@ let DtoCaptchaVerify = (_dec$2 = Dto(), _dec2$2 = BeanInfo({
314
316
  enumerable: true,
315
317
  writable: true,
316
318
  initializer: null
317
- }), _class2$1)) || _class$2) || _class$2);
319
+ }), _class2$1)) || _class$4) || _class$4);
318
320
 
319
- var _dec$1, _dec2$1, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec0, _dec1, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _dec16, _dec17, _dec18, _dec19, _dec20, _class$1, _class2;
320
- let ControllerCaptcha = (_dec$1 = Controller('captcha'), _dec2$1 = BeanInfo({
321
+ var _dec$3, _dec2$3, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec0, _dec1, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _dec16, _dec17, _dec18, _dec19, _dec20, _class$3, _class2;
322
+ let ControllerCaptcha = (_dec$3 = Controller('captcha'), _dec2$3 = BeanInfo({
321
323
  module: "a-captcha"
322
324
  }), _dec3 = Web.post('create'), _dec4 = Api.body(DtoCaptchaData), _dec5 = Passport.public(), _dec6 = function (target, key) {
323
325
  return Arg.body('scene')(target, key, 0);
@@ -329,7 +331,7 @@ let ControllerCaptcha = (_dec$1 = Controller('captcha'), _dec2$1 = BeanInfo({
329
331
  return Arg.body('id')(target, key, 0);
330
332
  }, _dec18 = function (target, key) {
331
333
  return Arg.body('token')(target, key, 1);
332
- }, _dec19 = Reflect.metadata("design:type", Function), _dec20 = Reflect.metadata("design:paramtypes", [String, Object]), _dec$1(_class$1 = _dec2$1(_class$1 = (_class2 = class ControllerCaptcha extends BeanBase {
334
+ }, _dec19 = Reflect.metadata("design:type", Function), _dec20 = Reflect.metadata("design:paramtypes", [String, Object]), _dec$3(_class$3 = _dec2$3(_class$3 = (_class2 = class ControllerCaptcha extends BeanBase {
333
335
  async create(scene) {
334
336
  return await this.bean.captcha.create(scene);
335
337
  }
@@ -341,7 +343,25 @@ let ControllerCaptcha = (_dec$1 = Controller('captcha'), _dec2$1 = BeanInfo({
341
343
  if (!verified) this.app.throw(403);
342
344
  return verified;
343
345
  }
344
- }, _applyDecoratedDescriptor(_class2.prototype, "create", [_dec3, _dec4, _dec5, _dec6, _dec7, _dec8], Object.getOwnPropertyDescriptor(_class2.prototype, "create"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "refresh", [_dec9, _dec0, _dec1, _dec10, _dec11, _dec12, _dec13], Object.getOwnPropertyDescriptor(_class2.prototype, "refresh"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "verifyImmediate", [_dec14, _dec15, _dec16, _dec17, _dec18, _dec19, _dec20], Object.getOwnPropertyDescriptor(_class2.prototype, "verifyImmediate"), _class2.prototype), _class2)) || _class$1) || _class$1);
346
+ }, _applyDecoratedDescriptor(_class2.prototype, "create", [_dec3, _dec4, _dec5, _dec6, _dec7, _dec8], Object.getOwnPropertyDescriptor(_class2.prototype, "create"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "refresh", [_dec9, _dec0, _dec1, _dec10, _dec11, _dec12, _dec13], Object.getOwnPropertyDescriptor(_class2.prototype, "refresh"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "verifyImmediate", [_dec14, _dec15, _dec16, _dec17, _dec18, _dec19, _dec20], Object.getOwnPropertyDescriptor(_class2.prototype, "verifyImmediate"), _class2.prototype), _class2)) || _class$3) || _class$3);
347
+
348
+ var _dec$2, _dec2$2, _class$2;
349
+ let HmrCaptchaProvider = (_dec$2 = Hmr(), _dec2$2 = BeanInfo({
350
+ module: "a-captcha"
351
+ }), _dec$2(_class$2 = _dec2$2(_class$2 = class HmrCaptchaProvider extends BeanBase {
352
+ async reload(_beanOptions) {
353
+ clearAllCacheSceneProviders(this.app);
354
+ }
355
+ }) || _class$2) || _class$2);
356
+
357
+ var _dec$1, _dec2$1, _class$1;
358
+ let HmrCaptchaScene = (_dec$1 = Hmr(), _dec2$1 = BeanInfo({
359
+ module: "a-captcha"
360
+ }), _dec$1(_class$1 = _dec2$1(_class$1 = class HmrCaptchaScene extends BeanBase {
361
+ async reload(_beanOptions) {
362
+ clearAllCacheSceneProviders(this.app);
363
+ }
364
+ }) || _class$1) || _class$1);
345
365
 
346
366
  function config(app) {
347
367
  const showToken = !app.meta.isProd;
@@ -356,6 +376,13 @@ function config(app) {
356
376
  };
357
377
  }
358
378
 
379
+ var _dec, _dec2, _class;
380
+ let ScopeModuleACaptcha = (_dec = Scope(), _dec2 = BeanInfo({
381
+ module: "a-captcha"
382
+ }), _dec(_class = _dec2(_class = class ScopeModuleACaptcha extends BeanScopeBase {}) || _class) || _class);
383
+
384
+ /** scope: end */
385
+
359
386
  var locale_en_us = {
360
387
  CaptchaInvalid: 'Captcha Invalid'
361
388
  };
@@ -364,18 +391,13 @@ var locale_zh_cn = {
364
391
  CaptchaInvalid: '验证码不正确'
365
392
  };
366
393
 
367
- var _dec, _dec2, _class;
368
394
  const locales = {
369
395
  'en-us': locale_en_us,
370
396
  'zh-cn': locale_zh_cn
371
397
  };
372
- let ScopeModuleACaptcha = (_dec = Scope(), _dec2 = BeanInfo({
373
- module: "a-captcha"
374
- }), _dec(_class = _dec2(_class = class ScopeModuleACaptcha extends BeanScopeBase {}) || _class) || _class);
375
398
  function $locale(key) {
376
399
  return `a-captcha::${key}`;
377
400
  }
378
- /** scope: end */
379
401
 
380
402
  function CaptchaProvider(options) {
381
403
  return createBeanDecorator('captchaProvider', options);
@@ -385,4 +407,4 @@ function CaptchaScene(options) {
385
407
  return createBeanDecorator('captchaScene', options);
386
408
  }
387
409
 
388
- export { $locale, BeanCaptcha, CacheRedisCaptcha, CaptchaProvider, CaptchaScene, ControllerCaptcha, DtoCaptchaData, DtoCaptchaVerify, InterceptorCaptchaVerify, ScopeModuleACaptcha, config, locales };
410
+ export { $locale, BeanCaptcha, CacheRedisCaptcha, CaptchaProvider, CaptchaScene, ControllerCaptcha, DtoCaptchaData, DtoCaptchaVerify, HmrCaptchaProvider, HmrCaptchaScene, InterceptorCaptchaVerify, ScopeModuleACaptcha, SymbolCacheSceneProviders, clearAllCacheSceneProviders, config, locales };
@@ -0,0 +1,3 @@
1
+ import type { VonaApplication } from 'vona';
2
+ export declare const SymbolCacheSceneProviders: unique symbol;
3
+ export declare function clearAllCacheSceneProviders(app: VonaApplication): void;
@@ -1,2 +1,3 @@
1
1
  export * from './captchaProvider.ts';
2
2
  export * from './captchaScene.ts';
3
+ export * from './const.ts';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-captcha",
3
3
  "type": "module",
4
- "version": "5.0.20",
4
+ "version": "5.0.22",
5
5
  "title": "a-captcha",
6
6
  "vonaModule": {
7
7
  "dependencies": {},