vona-module-a-captcha 5.0.19 → 5.0.21
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/cli/captchaProvider/boilerplate/{{sceneName}}.{{beanName}}.ts_ +2 -1
- package/dist/.metadata/index.d.ts +25 -0
- package/dist/bean/bean.captcha.d.ts +1 -5
- package/dist/bean/hmr.captchaProvider.d.ts +6 -0
- package/dist/bean/hmr.captchaScene.d.ts +6 -0
- package/dist/index.js +55 -35
- package/dist/lib/const.d.ts +3 -0
- package/dist/lib/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -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
|
|
21
|
+
_options: ICaptchaProviderOptions<%=argv.beanNameCapitalize%>,
|
|
22
|
+
): Promise<boolean> {
|
|
22
23
|
return false;
|
|
23
24
|
}
|
|
24
25
|
}
|
|
@@ -123,6 +123,31 @@ 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';
|
|
@@ -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 |
|
|
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.js
CHANGED
|
@@ -3,17 +3,18 @@ import { zodCustomError, getRandomInt } from '@cabloy/utils';
|
|
|
3
3
|
import { Interceptor } from 'vona-module-a-aspect';
|
|
4
4
|
import { Bean, Scope } from 'vona-module-a-bean';
|
|
5
5
|
import { CacheRedis, BeanCacheRedisBase } from 'vona-module-a-cache';
|
|
6
|
-
import { Api, v } from 'vona-module-a-
|
|
6
|
+
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$
|
|
12
|
-
let InterceptorCaptchaVerify = (_dec$
|
|
12
|
+
var _dec$8, _dec2$8, _class$8;
|
|
13
|
+
let InterceptorCaptchaVerify = (_dec$8 = Interceptor({
|
|
13
14
|
bodyField: 'captcha'
|
|
14
|
-
}), _dec2$
|
|
15
|
+
}), _dec2$8 = BeanInfo({
|
|
15
16
|
module: "a-captcha"
|
|
16
|
-
}), _dec$
|
|
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$
|
|
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$
|
|
35
|
-
|
|
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$
|
|
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[
|
|
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[
|
|
221
|
+
this.app.meta[SymbolCacheSceneProviders][sceneName] = this._prepareProviders(onionOptions?.providers);
|
|
220
222
|
}
|
|
221
|
-
return this[
|
|
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$
|
|
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$
|
|
244
|
-
let CacheRedisCaptcha = (_dec$
|
|
245
|
+
var _dec$6, _dec2$6, _class$6;
|
|
246
|
+
let CacheRedisCaptcha = (_dec$6 = CacheRedis({
|
|
245
247
|
disableTransactionCompensate: true
|
|
246
|
-
}), _dec2$
|
|
248
|
+
}), _dec2$6 = BeanInfo({
|
|
247
249
|
module: "a-captcha"
|
|
248
|
-
}), _dec$
|
|
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$
|
|
268
|
-
let DtoCaptchaData = (_dec$
|
|
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$
|
|
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$
|
|
299
|
+
}), _class2$2)) || _class$5) || _class$5);
|
|
298
300
|
|
|
299
|
-
var _dec$
|
|
300
|
-
let DtoCaptchaVerify = (_dec$
|
|
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$
|
|
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$
|
|
319
|
+
}), _class2$1)) || _class$4) || _class$4);
|
|
318
320
|
|
|
319
|
-
var _dec$
|
|
320
|
-
let ControllerCaptcha = (_dec$
|
|
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$
|
|
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$
|
|
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;
|
|
@@ -385,4 +405,4 @@ function CaptchaScene(options) {
|
|
|
385
405
|
return createBeanDecorator('captchaScene', options);
|
|
386
406
|
}
|
|
387
407
|
|
|
388
|
-
export { $locale, BeanCaptcha, CacheRedisCaptcha, CaptchaProvider, CaptchaScene, ControllerCaptcha, DtoCaptchaData, DtoCaptchaVerify, InterceptorCaptchaVerify, ScopeModuleACaptcha, config, locales };
|
|
408
|
+
export { $locale, BeanCaptcha, CacheRedisCaptcha, CaptchaProvider, CaptchaScene, ControllerCaptcha, DtoCaptchaData, DtoCaptchaVerify, HmrCaptchaProvider, HmrCaptchaScene, InterceptorCaptchaVerify, ScopeModuleACaptcha, SymbolCacheSceneProviders, clearAllCacheSceneProviders, config, locales };
|
package/dist/lib/index.d.ts
CHANGED