@gvrs/nestjs-hcaptcha 0.3.0 → 0.4.0
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/dist/index.cjs +179 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.ts → index.d.cts} +1 -1
- package/package.json +7 -7
- package/dist/index.js +0 -235
- package/dist/index.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
let __nestjs_common = require("@nestjs/common");
|
|
25
|
+
__nestjs_common = __toESM(__nestjs_common);
|
|
26
|
+
let hcaptcha = require("hcaptcha");
|
|
27
|
+
hcaptcha = __toESM(hcaptcha);
|
|
28
|
+
|
|
29
|
+
//#region src/lib/hcaptcha.exception.ts
|
|
30
|
+
var HcaptchaException = class extends __nestjs_common.ForbiddenException {
|
|
31
|
+
constructor(cause, message = "Forbidden") {
|
|
32
|
+
super(message, { cause });
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/lib/get-captcha-data/get-captcha-data.ts
|
|
38
|
+
const defaultGetCaptchaData = (context) => {
|
|
39
|
+
const token = context.switchToHttp().getRequest().body["h-captcha-response"];
|
|
40
|
+
if (!token) throw new HcaptchaException(/* @__PURE__ */ new Error("No hCaptcha token present in request body"));
|
|
41
|
+
return { token };
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region \0@oxc-project+runtime@0.93.0/helpers/decorate.js
|
|
46
|
+
function __decorate(decorators, target, key, desc) {
|
|
47
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
48
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
49
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
50
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/lib/options/hcaptcha-options.module.ts
|
|
55
|
+
const PROVIDED_HCAPTCHA_OPTIONS = Symbol("PROVIDED_HCAPTCHA_OPTIONS");
|
|
56
|
+
const NORMALIZED_HCAPTCHA_OPTIONS = Symbol("NORMALIZED_HCAPTCHA_OPTIONS");
|
|
57
|
+
const normalizeOptions = (options) => ({
|
|
58
|
+
getCaptchaData: defaultGetCaptchaData,
|
|
59
|
+
...options
|
|
60
|
+
});
|
|
61
|
+
const host = new __nestjs_common.ConfigurableModuleBuilder({ optionsInjectionToken: PROVIDED_HCAPTCHA_OPTIONS }).setClassMethodName("forRoot").setExtras({}, (def) => ({
|
|
62
|
+
...def,
|
|
63
|
+
global: true,
|
|
64
|
+
providers: [...def.providers ?? [], {
|
|
65
|
+
provide: NORMALIZED_HCAPTCHA_OPTIONS,
|
|
66
|
+
useFactory: normalizeOptions,
|
|
67
|
+
inject: [PROVIDED_HCAPTCHA_OPTIONS]
|
|
68
|
+
}],
|
|
69
|
+
exports: [NORMALIZED_HCAPTCHA_OPTIONS]
|
|
70
|
+
})).build();
|
|
71
|
+
let HcaptchaOptionsModule = class HcaptchaOptionsModule$1 extends host.ConfigurableModuleClass {};
|
|
72
|
+
HcaptchaOptionsModule = __decorate([(0, __nestjs_common.Module)({})], HcaptchaOptionsModule);
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region \0@oxc-project+runtime@0.93.0/helpers/decorateMetadata.js
|
|
76
|
+
function __decorateMetadata(k, v) {
|
|
77
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region \0@oxc-project+runtime@0.93.0/helpers/decorateParam.js
|
|
82
|
+
function __decorateParam(paramIndex, decorator) {
|
|
83
|
+
return function(target, key) {
|
|
84
|
+
decorator(target, key, paramIndex);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/lib/hcaptcha.service.ts
|
|
90
|
+
let HcaptchaService = class HcaptchaService$1 {
|
|
91
|
+
constructor(options) {
|
|
92
|
+
this.options = options;
|
|
93
|
+
}
|
|
94
|
+
async verifyCaptcha(token, remoteip) {
|
|
95
|
+
let verifyResponse;
|
|
96
|
+
try {
|
|
97
|
+
verifyResponse = await (0, hcaptcha.verify)(this.options.secret, token, remoteip, this.options.sitekey);
|
|
98
|
+
} catch (e) {
|
|
99
|
+
throw new HcaptchaException(e);
|
|
100
|
+
}
|
|
101
|
+
const { success } = verifyResponse;
|
|
102
|
+
if (!success) throw new HcaptchaException(verifyResponse);
|
|
103
|
+
return verifyResponse;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
HcaptchaService = __decorate([
|
|
107
|
+
(0, __nestjs_common.Injectable)(),
|
|
108
|
+
__decorateParam(0, (0, __nestjs_common.Inject)(NORMALIZED_HCAPTCHA_OPTIONS)),
|
|
109
|
+
__decorateMetadata("design:paramtypes", [Object])
|
|
110
|
+
], HcaptchaService);
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/lib/hcaptcha.guard.ts
|
|
114
|
+
var _ref;
|
|
115
|
+
let HcaptchaGuard = class HcaptchaGuard$1 {
|
|
116
|
+
constructor(options, hcaptchaService) {
|
|
117
|
+
this.options = options;
|
|
118
|
+
this.hcaptchaService = hcaptchaService;
|
|
119
|
+
}
|
|
120
|
+
async canActivate(context) {
|
|
121
|
+
const { token, remoteip } = this.options.getCaptchaData(context);
|
|
122
|
+
await this.hcaptchaService.verifyCaptcha(token, remoteip);
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
HcaptchaGuard = __decorate([
|
|
127
|
+
(0, __nestjs_common.Injectable)(),
|
|
128
|
+
__decorateParam(0, (0, __nestjs_common.Inject)(NORMALIZED_HCAPTCHA_OPTIONS)),
|
|
129
|
+
__decorateMetadata("design:paramtypes", [Object, typeof (_ref = typeof HcaptchaService !== "undefined" && HcaptchaService) === "function" ? _ref : Object])
|
|
130
|
+
], HcaptchaGuard);
|
|
131
|
+
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/lib/hcaptcha.module.ts
|
|
134
|
+
let HcaptchaModule = class HcaptchaModule$1 {
|
|
135
|
+
static forRoot(options) {
|
|
136
|
+
return {
|
|
137
|
+
module: this,
|
|
138
|
+
imports: [HcaptchaOptionsModule.forRoot(options)]
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
static forRootAsync(options) {
|
|
142
|
+
return {
|
|
143
|
+
module: this,
|
|
144
|
+
imports: [HcaptchaOptionsModule.forRootAsync(options)]
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
HcaptchaModule = __decorate([(0, __nestjs_common.Module)({
|
|
149
|
+
providers: [HcaptchaService],
|
|
150
|
+
exports: [HcaptchaService]
|
|
151
|
+
})], HcaptchaModule);
|
|
152
|
+
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/lib/verify-captcha.decorator.ts
|
|
155
|
+
const VerifyCaptcha = () => (0, __nestjs_common.applyDecorators)((0, __nestjs_common.UseGuards)(HcaptchaGuard));
|
|
156
|
+
|
|
157
|
+
//#endregion
|
|
158
|
+
exports.HcaptchaException = HcaptchaException;
|
|
159
|
+
Object.defineProperty(exports, 'HcaptchaGuard', {
|
|
160
|
+
enumerable: true,
|
|
161
|
+
get: function () {
|
|
162
|
+
return HcaptchaGuard;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
Object.defineProperty(exports, 'HcaptchaModule', {
|
|
166
|
+
enumerable: true,
|
|
167
|
+
get: function () {
|
|
168
|
+
return HcaptchaModule;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
Object.defineProperty(exports, 'HcaptchaService', {
|
|
172
|
+
enumerable: true,
|
|
173
|
+
get: function () {
|
|
174
|
+
return HcaptchaService;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
exports.VerifyCaptcha = VerifyCaptcha;
|
|
178
|
+
exports.defaultGetCaptchaData = defaultGetCaptchaData;
|
|
179
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["ForbiddenException","defaultGetCaptchaData: GetCaptchaData","NORMALIZED_HCAPTCHA_OPTIONS: symbol","host: ConfigurableModuleHost<HcaptchaOptions, \"forRoot\", \"create\">","ConfigurableModuleBuilder","HcaptchaOptionsModule","HcaptchaService","options: NormalizedHcaptchaOptions","verifyResponse: VerifyResponse","HcaptchaGuard","options: NormalizedHcaptchaOptions","hcaptchaService: HcaptchaService","HcaptchaModule"],"sources":["../src/lib/hcaptcha.exception.ts","../src/lib/get-captcha-data/get-captcha-data.ts","../src/lib/options/hcaptcha-options.module.ts","../src/lib/hcaptcha.service.ts","../src/lib/hcaptcha.guard.ts","../src/lib/hcaptcha.module.ts","../src/lib/verify-captcha.decorator.ts"],"sourcesContent":["import { ForbiddenException } from '@nestjs/common';\n\nexport class HcaptchaException extends ForbiddenException {\n constructor(cause: unknown, message = 'Forbidden') {\n super(message, { cause });\n }\n}\n","import type { ExecutionContext } from \"@nestjs/common\";\nimport { HcaptchaException } from \"../hcaptcha.exception\";\n\nexport type CaptchaData = {\n token: string;\n remoteip?: string;\n};\n\nexport type GetCaptchaData = (\n executionContext: ExecutionContext,\n) => CaptchaData;\n\nexport const defaultGetCaptchaData: GetCaptchaData = (context) => {\n const request = context.switchToHttp().getRequest();\n\n const token = request.body[\"h-captcha-response\"];\n\n if (!token) {\n throw new HcaptchaException(\n new Error(\"No hCaptcha token present in request body\"),\n );\n }\n\n return {\n token,\n };\n};\n","import {\n ConfigurableModuleBuilder,\n Module,\n type ConfigurableModuleHost,\n} from \"@nestjs/common\";\n\nimport { defaultGetCaptchaData } from \"../get-captcha-data\";\nimport type {\n HcaptchaOptions,\n NormalizedHcaptchaOptions,\n} from \"./hcaptcha-options.types\";\n\nconst PROVIDED_HCAPTCHA_OPTIONS = Symbol(\"PROVIDED_HCAPTCHA_OPTIONS\");\n\nexport const NORMALIZED_HCAPTCHA_OPTIONS: symbol = Symbol(\n \"NORMALIZED_HCAPTCHA_OPTIONS\",\n);\n\nconst normalizeOptions = (\n options: HcaptchaOptions,\n): NormalizedHcaptchaOptions => ({\n getCaptchaData: defaultGetCaptchaData,\n ...options,\n});\n\nconst host: ConfigurableModuleHost<HcaptchaOptions, \"forRoot\", \"create\"> =\n new ConfigurableModuleBuilder<HcaptchaOptions>({\n optionsInjectionToken: PROVIDED_HCAPTCHA_OPTIONS,\n })\n .setClassMethodName(\"forRoot\")\n .setExtras({}, (def) => ({\n ...def,\n global: true,\n providers: [\n ...(def.providers ?? []),\n {\n provide: NORMALIZED_HCAPTCHA_OPTIONS,\n useFactory: normalizeOptions,\n inject: [PROVIDED_HCAPTCHA_OPTIONS],\n },\n ],\n exports: [NORMALIZED_HCAPTCHA_OPTIONS],\n }))\n .build();\n\n@Module({})\nexport class HcaptchaOptionsModule extends host.ConfigurableModuleClass {}\n\nexport type AsyncHcaptchaOptions = typeof host.ASYNC_OPTIONS_TYPE;\n","import { Injectable, Inject } from \"@nestjs/common\";\nimport { verify } from \"hcaptcha\";\n\nimport { NORMALIZED_HCAPTCHA_OPTIONS } from \"./options\";\nimport type { NormalizedHcaptchaOptions } from \"./options\";\nimport { HcaptchaException } from \"./hcaptcha.exception\";\nimport type { VerifyResponse } from \"./typings\";\n\n@Injectable()\nexport class HcaptchaService {\n constructor(\n @Inject(NORMALIZED_HCAPTCHA_OPTIONS)\n private readonly options: NormalizedHcaptchaOptions,\n ) {}\n\n async verifyCaptcha(\n token: string,\n remoteip?: string,\n ): Promise<VerifyResponse> {\n let verifyResponse: VerifyResponse;\n\n try {\n verifyResponse = await verify(\n this.options.secret,\n token,\n remoteip,\n this.options.sitekey,\n );\n } catch (e) {\n throw new HcaptchaException(e);\n }\n\n const { success } = verifyResponse;\n\n if (!success) {\n throw new HcaptchaException(verifyResponse);\n }\n\n return verifyResponse;\n }\n}\n","import {\n type CanActivate,\n type ExecutionContext,\n Inject,\n Injectable,\n} from \"@nestjs/common\";\n\nimport { NORMALIZED_HCAPTCHA_OPTIONS } from \"./options\";\nimport type { NormalizedHcaptchaOptions } from \"./options\";\nimport { HcaptchaService } from \"./hcaptcha.service\";\n\n@Injectable()\nexport class HcaptchaGuard implements CanActivate {\n constructor(\n @Inject(NORMALIZED_HCAPTCHA_OPTIONS)\n private readonly options: NormalizedHcaptchaOptions,\n private readonly hcaptchaService: HcaptchaService,\n ) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n const { token, remoteip } = this.options.getCaptchaData(context);\n\n await this.hcaptchaService.verifyCaptcha(token, remoteip);\n\n return true;\n }\n}\n","import { type DynamicModule, Module } from \"@nestjs/common\";\n\nimport {\n HcaptchaOptionsModule,\n type HcaptchaOptions,\n type AsyncHcaptchaOptions,\n} from \"./options\";\nimport { HcaptchaService } from \"./hcaptcha.service\";\n\n@Module({\n providers: [HcaptchaService],\n exports: [HcaptchaService],\n})\nexport class HcaptchaModule {\n static forRoot(options: HcaptchaOptions): DynamicModule {\n return {\n module: this,\n imports: [HcaptchaOptionsModule.forRoot(options)],\n };\n }\n\n static forRootAsync(options: AsyncHcaptchaOptions): DynamicModule {\n return {\n module: this,\n imports: [HcaptchaOptionsModule.forRootAsync(options)],\n };\n }\n}\n","import { UseGuards, applyDecorators } from \"@nestjs/common\";\n\nimport { HcaptchaGuard } from \"./hcaptcha.guard\";\n\nexport const VerifyCaptcha = (): ReturnType<typeof applyDecorators> =>\n applyDecorators(UseGuards(HcaptchaGuard));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAa,oBAAb,cAAuCA,mCAAmB;CACxD,YAAY,OAAgB,UAAU,aAAa;AACjD,QAAM,SAAS,EAAE,OAAO,CAAC;;;;;;ACQ7B,MAAaC,yBAAyC,YAAY;CAGhE,MAAM,QAFU,QAAQ,cAAc,CAAC,YAAY,CAE7B,KAAK;AAE3B,KAAI,CAAC,MACH,OAAM,IAAI,kCACR,IAAI,MAAM,4CAA4C,CACvD;AAGH,QAAO,EACL,OACD;;;;;;;;;;;;;;ACbH,MAAM,4BAA4B,OAAO,4BAA4B;AAErE,MAAaC,8BAAsC,OACjD,8BACD;AAED,MAAM,oBACJ,aAC+B;CAC/B,gBAAgB;CAChB,GAAG;CACJ;AAED,MAAMC,OACJ,IAAIC,0CAA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3B,CAAC;;;;ACRF,MAAa,0FACe,cAAc,CAAC"}
|
|
@@ -54,4 +54,4 @@ declare class HcaptchaModule {
|
|
|
54
54
|
declare const VerifyCaptcha: () => ReturnType<typeof applyDecorators>;
|
|
55
55
|
//#endregion
|
|
56
56
|
export { AsyncHcaptchaOptions, CaptchaData, GetCaptchaData, HcaptchaException, HcaptchaGuard, HcaptchaModule, HcaptchaOptions, HcaptchaService, VerifyCaptcha, VerifyResponse, defaultGetCaptchaData };
|
|
57
|
-
//# sourceMappingURL=index.d.
|
|
57
|
+
//# sourceMappingURL=index.d.cts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gvrs/nestjs-hcaptcha",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Alex Gavrusev <alex@gavrusev.dev>",
|
|
6
6
|
"repository": {
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/alexgavrusev/nestjs-hcaptcha/issues"
|
|
13
13
|
},
|
|
14
|
-
"type": "
|
|
14
|
+
"type": "module",
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
|
-
"main": "./dist/index.
|
|
19
|
-
"types": "./dist/index.d.
|
|
18
|
+
"main": "./dist/index.cjs",
|
|
19
|
+
"types": "./dist/index.d.cts",
|
|
20
20
|
"exports": {
|
|
21
|
-
".": "./dist/index.
|
|
21
|
+
".": "./dist/index.cjs",
|
|
22
22
|
"./package.json": "./package.json"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"hcaptcha": "^0.2.0",
|
|
39
39
|
"nock": "^14.0.7",
|
|
40
40
|
"oxlint": "^1.9.0",
|
|
41
|
-
"pkg-pr-new": "^0.0.
|
|
41
|
+
"pkg-pr-new": "^0.0.60",
|
|
42
42
|
"prettier": "^3.6.2",
|
|
43
43
|
"supertest": "^7.1.4",
|
|
44
|
-
"tsdown": "^0.
|
|
44
|
+
"tsdown": "^0.15.6",
|
|
45
45
|
"unplugin-swc": "^1.5.5",
|
|
46
46
|
"vitest": "^3.2.4",
|
|
47
47
|
"vitest-mock-extended": "^3.1.0"
|
package/dist/index.js
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __commonJS = (cb, mod) => function() {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
};
|
|
11
|
-
var __export = (target, all) => {
|
|
12
|
-
for (var name in all) __defProp(target, name, {
|
|
13
|
-
get: all[name],
|
|
14
|
-
enumerable: true
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
var __copyProps = (to, from, except, desc) => {
|
|
18
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
19
|
-
key = keys[i];
|
|
20
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
21
|
-
get: ((k) => from[k]).bind(null, key),
|
|
22
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return to;
|
|
26
|
-
};
|
|
27
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
28
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
29
|
-
value: mod,
|
|
30
|
-
enumerable: true
|
|
31
|
-
}) : target, mod));
|
|
32
|
-
|
|
33
|
-
//#endregion
|
|
34
|
-
const __nestjs_common = __toESM(require("@nestjs/common"));
|
|
35
|
-
const hcaptcha = __toESM(require("hcaptcha"));
|
|
36
|
-
|
|
37
|
-
//#region src/lib/hcaptcha.exception.ts
|
|
38
|
-
var HcaptchaException = class extends __nestjs_common.ForbiddenException {
|
|
39
|
-
constructor(cause, message = "Forbidden") {
|
|
40
|
-
super(message, { cause });
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/lib/get-captcha-data/get-captcha-data.ts
|
|
46
|
-
const defaultGetCaptchaData = (context) => {
|
|
47
|
-
const request = context.switchToHttp().getRequest();
|
|
48
|
-
const token = request.body["h-captcha-response"];
|
|
49
|
-
if (!token) throw new HcaptchaException(/* @__PURE__ */ new Error("No hCaptcha token present in request body"));
|
|
50
|
-
return { token };
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/decorate.js
|
|
55
|
-
var require_decorate = __commonJS({ "node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/decorate.js"(exports, module) {
|
|
56
|
-
function __decorate(decorators, target, key, desc) {
|
|
57
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
58
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
59
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
60
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
61
|
-
}
|
|
62
|
-
module.exports = __decorate, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
63
|
-
} });
|
|
64
|
-
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region src/lib/options/hcaptcha-options.module.ts
|
|
67
|
-
var import_decorate$3 = __toESM(require_decorate());
|
|
68
|
-
const PROVIDED_HCAPTCHA_OPTIONS = Symbol("PROVIDED_HCAPTCHA_OPTIONS");
|
|
69
|
-
const NORMALIZED_HCAPTCHA_OPTIONS = Symbol("NORMALIZED_HCAPTCHA_OPTIONS");
|
|
70
|
-
const normalizeOptions = (options) => ({
|
|
71
|
-
getCaptchaData: defaultGetCaptchaData,
|
|
72
|
-
...options
|
|
73
|
-
});
|
|
74
|
-
const host = new __nestjs_common.ConfigurableModuleBuilder({ optionsInjectionToken: PROVIDED_HCAPTCHA_OPTIONS }).setClassMethodName("forRoot").setExtras({}, (def) => ({
|
|
75
|
-
...def,
|
|
76
|
-
global: true,
|
|
77
|
-
providers: [...def.providers ?? [], {
|
|
78
|
-
provide: NORMALIZED_HCAPTCHA_OPTIONS,
|
|
79
|
-
useFactory: normalizeOptions,
|
|
80
|
-
inject: [PROVIDED_HCAPTCHA_OPTIONS]
|
|
81
|
-
}],
|
|
82
|
-
exports: [NORMALIZED_HCAPTCHA_OPTIONS]
|
|
83
|
-
})).build();
|
|
84
|
-
let HcaptchaOptionsModule = class HcaptchaOptionsModule$1 extends host.ConfigurableModuleClass {};
|
|
85
|
-
HcaptchaOptionsModule = (0, import_decorate$3.default)([(0, __nestjs_common.Module)({})], HcaptchaOptionsModule);
|
|
86
|
-
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/decorateMetadata.js
|
|
89
|
-
var require_decorateMetadata = __commonJS({ "node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/decorateMetadata.js"(exports, module) {
|
|
90
|
-
function __decorateMetadata(k, v) {
|
|
91
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
92
|
-
}
|
|
93
|
-
module.exports = __decorateMetadata, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
94
|
-
} });
|
|
95
|
-
|
|
96
|
-
//#endregion
|
|
97
|
-
//#region node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/decorateParam.js
|
|
98
|
-
var require_decorateParam = __commonJS({ "node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/decorateParam.js"(exports, module) {
|
|
99
|
-
function __decorateParam(paramIndex, decorator) {
|
|
100
|
-
return function(target, key) {
|
|
101
|
-
decorator(target, key, paramIndex);
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
module.exports = __decorateParam, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
105
|
-
} });
|
|
106
|
-
|
|
107
|
-
//#endregion
|
|
108
|
-
//#region src/lib/hcaptcha.service.ts
|
|
109
|
-
var import_decorateMetadata$1 = __toESM(require_decorateMetadata());
|
|
110
|
-
var import_decorateParam$1 = __toESM(require_decorateParam());
|
|
111
|
-
var import_decorate$2 = __toESM(require_decorate());
|
|
112
|
-
let HcaptchaService = class HcaptchaService$1 {
|
|
113
|
-
constructor(options) {
|
|
114
|
-
this.options = options;
|
|
115
|
-
}
|
|
116
|
-
async verifyCaptcha(token, remoteip) {
|
|
117
|
-
let verifyResponse;
|
|
118
|
-
try {
|
|
119
|
-
verifyResponse = await (0, hcaptcha.verify)(this.options.secret, token, remoteip, this.options.sitekey);
|
|
120
|
-
} catch (e) {
|
|
121
|
-
throw new HcaptchaException(e);
|
|
122
|
-
}
|
|
123
|
-
const { success } = verifyResponse;
|
|
124
|
-
if (!success) throw new HcaptchaException(verifyResponse);
|
|
125
|
-
return verifyResponse;
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
HcaptchaService = (0, import_decorate$2.default)([
|
|
129
|
-
(0, __nestjs_common.Injectable)(),
|
|
130
|
-
(0, import_decorateMetadata$1.default)("design:paramtypes", [Object]),
|
|
131
|
-
(0, import_decorateParam$1.default)(0, (0, __nestjs_common.Inject)(NORMALIZED_HCAPTCHA_OPTIONS))
|
|
132
|
-
], HcaptchaService);
|
|
133
|
-
|
|
134
|
-
//#endregion
|
|
135
|
-
//#region src/lib/hcaptcha.guard.ts
|
|
136
|
-
var import_decorateMetadata = __toESM(require_decorateMetadata());
|
|
137
|
-
var import_decorateParam = __toESM(require_decorateParam());
|
|
138
|
-
var import_decorate$1 = __toESM(require_decorate());
|
|
139
|
-
var _ref;
|
|
140
|
-
let HcaptchaGuard = class HcaptchaGuard$1 {
|
|
141
|
-
constructor(options, hcaptchaService) {
|
|
142
|
-
this.options = options;
|
|
143
|
-
this.hcaptchaService = hcaptchaService;
|
|
144
|
-
}
|
|
145
|
-
async canActivate(context) {
|
|
146
|
-
const { token, remoteip } = this.options.getCaptchaData(context);
|
|
147
|
-
await this.hcaptchaService.verifyCaptcha(token, remoteip);
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
HcaptchaGuard = (0, import_decorate$1.default)([
|
|
152
|
-
(0, __nestjs_common.Injectable)(),
|
|
153
|
-
(0, import_decorateMetadata.default)("design:paramtypes", [Object, typeof (_ref = typeof HcaptchaService !== "undefined" && HcaptchaService) === "function" ? _ref : Object]),
|
|
154
|
-
(0, import_decorateParam.default)(0, (0, __nestjs_common.Inject)(NORMALIZED_HCAPTCHA_OPTIONS))
|
|
155
|
-
], HcaptchaGuard);
|
|
156
|
-
|
|
157
|
-
//#endregion
|
|
158
|
-
//#region src/lib/hcaptcha.module.ts
|
|
159
|
-
var import_decorate = __toESM(require_decorate());
|
|
160
|
-
let HcaptchaModule = class HcaptchaModule$1 {
|
|
161
|
-
static forRoot(options) {
|
|
162
|
-
return {
|
|
163
|
-
module: this,
|
|
164
|
-
imports: [HcaptchaOptionsModule.forRoot(options)]
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
static forRootAsync(options) {
|
|
168
|
-
return {
|
|
169
|
-
module: this,
|
|
170
|
-
imports: [HcaptchaOptionsModule.forRootAsync(options)]
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
HcaptchaModule = (0, import_decorate.default)([(0, __nestjs_common.Module)({
|
|
175
|
-
providers: [HcaptchaService],
|
|
176
|
-
exports: [HcaptchaService]
|
|
177
|
-
})], HcaptchaModule);
|
|
178
|
-
|
|
179
|
-
//#endregion
|
|
180
|
-
//#region src/lib/verify-captcha.decorator.ts
|
|
181
|
-
const VerifyCaptcha = () => (0, __nestjs_common.applyDecorators)((0, __nestjs_common.UseGuards)(HcaptchaGuard));
|
|
182
|
-
|
|
183
|
-
//#endregion
|
|
184
|
-
//#region src/lib/typings.ts
|
|
185
|
-
var require_typings = __commonJS({ "src/lib/typings.ts"() {} });
|
|
186
|
-
|
|
187
|
-
//#endregion
|
|
188
|
-
//#region src/lib/index.ts
|
|
189
|
-
var lib_exports = {};
|
|
190
|
-
__export(lib_exports, {
|
|
191
|
-
HcaptchaException: () => HcaptchaException,
|
|
192
|
-
HcaptchaGuard: () => HcaptchaGuard,
|
|
193
|
-
HcaptchaModule: () => HcaptchaModule,
|
|
194
|
-
HcaptchaService: () => HcaptchaService,
|
|
195
|
-
VerifyCaptcha: () => VerifyCaptcha,
|
|
196
|
-
defaultGetCaptchaData: () => defaultGetCaptchaData
|
|
197
|
-
});
|
|
198
|
-
__reExport(lib_exports, __toESM(require_typings()));
|
|
199
|
-
|
|
200
|
-
//#endregion
|
|
201
|
-
//#region src/index.ts
|
|
202
|
-
var src_exports = {};
|
|
203
|
-
__export(src_exports, {
|
|
204
|
-
HcaptchaException: () => HcaptchaException,
|
|
205
|
-
HcaptchaGuard: () => HcaptchaGuard,
|
|
206
|
-
HcaptchaModule: () => HcaptchaModule,
|
|
207
|
-
HcaptchaService: () => HcaptchaService,
|
|
208
|
-
VerifyCaptcha: () => VerifyCaptcha,
|
|
209
|
-
defaultGetCaptchaData: () => defaultGetCaptchaData
|
|
210
|
-
});
|
|
211
|
-
__reExport(src_exports, lib_exports);
|
|
212
|
-
|
|
213
|
-
//#endregion
|
|
214
|
-
exports.HcaptchaException = HcaptchaException;
|
|
215
|
-
Object.defineProperty(exports, 'HcaptchaGuard', {
|
|
216
|
-
enumerable: true,
|
|
217
|
-
get: function () {
|
|
218
|
-
return HcaptchaGuard;
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
Object.defineProperty(exports, 'HcaptchaModule', {
|
|
222
|
-
enumerable: true,
|
|
223
|
-
get: function () {
|
|
224
|
-
return HcaptchaModule;
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
Object.defineProperty(exports, 'HcaptchaService', {
|
|
228
|
-
enumerable: true,
|
|
229
|
-
get: function () {
|
|
230
|
-
return HcaptchaService;
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
exports.VerifyCaptcha = VerifyCaptcha;
|
|
234
|
-
exports.defaultGetCaptchaData = defaultGetCaptchaData;
|
|
235
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["ForbiddenException","cause: unknown","defaultGetCaptchaData: GetCaptchaData","NORMALIZED_HCAPTCHA_OPTIONS: symbol","options: HcaptchaOptions","host: ConfigurableModuleHost<HcaptchaOptions, \"forRoot\", \"create\">","ConfigurableModuleBuilder","HcaptchaOptionsModule","HcaptchaService","options: NormalizedHcaptchaOptions","token: string","remoteip?: string","verifyResponse: VerifyResponse","HcaptchaGuard","options: NormalizedHcaptchaOptions","hcaptchaService: HcaptchaService","context: ExecutionContext","HcaptchaModule","options: HcaptchaOptions","options: AsyncHcaptchaOptions"],"sources":["../src/lib/hcaptcha.exception.ts","../src/lib/get-captcha-data/get-captcha-data.ts","../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/decorate.js","../src/lib/options/hcaptcha-options.module.ts","../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/decorateMetadata.js","../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/decorateParam.js","../src/lib/hcaptcha.service.ts","../src/lib/hcaptcha.guard.ts","../src/lib/hcaptcha.module.ts","../src/lib/verify-captcha.decorator.ts","../src/lib/typings.ts","../src/lib/index.ts","../src/index.ts"],"sourcesContent":["import { ForbiddenException } from '@nestjs/common';\n\nexport class HcaptchaException extends ForbiddenException {\n constructor(cause: unknown, message = 'Forbidden') {\n super(message, { cause });\n }\n}\n","import type { ExecutionContext } from \"@nestjs/common\";\nimport { HcaptchaException } from \"../hcaptcha.exception\";\n\nexport type CaptchaData = {\n token: string;\n remoteip?: string;\n};\n\nexport type GetCaptchaData = (\n executionContext: ExecutionContext,\n) => CaptchaData;\n\nexport const defaultGetCaptchaData: GetCaptchaData = (context) => {\n const request = context.switchToHttp().getRequest();\n\n const token = request.body[\"h-captcha-response\"];\n\n if (!token) {\n throw new HcaptchaException(\n new Error(\"No hCaptcha token present in request body\"),\n );\n }\n\n return {\n token,\n };\n};\n","// Copy from https://github.com/microsoft/TypeScript/blob/d85767abfd83880cea17cea70f9913e9c4496dcc/src/compiler/factory/emitHelpers.ts#L730-L742\n\nfunction __decorate(decorators, target, key, desc) {\n var c = arguments.length,\n r =\n c < 3\n ? target\n : desc === null\n ? (desc = Object.getOwnPropertyDescriptor(target, key))\n : desc,\n d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\")\n r = Reflect.decorate(decorators, target, key, desc);\n else\n for (var i = decorators.length - 1; i >= 0; i--)\n if ((d = decorators[i]))\n r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n}\n\n(module.exports = __decorate),\n (module.exports.__esModule = true),\n (module.exports[\"default\"] = module.exports);\n","import {\n ConfigurableModuleBuilder,\n Module,\n type ConfigurableModuleHost,\n} from \"@nestjs/common\";\n\nimport { defaultGetCaptchaData } from \"../get-captcha-data\";\nimport type {\n HcaptchaOptions,\n NormalizedHcaptchaOptions,\n} from \"./hcaptcha-options.types\";\n\nconst PROVIDED_HCAPTCHA_OPTIONS = Symbol(\"PROVIDED_HCAPTCHA_OPTIONS\");\n\nexport const NORMALIZED_HCAPTCHA_OPTIONS: symbol = Symbol(\n \"NORMALIZED_HCAPTCHA_OPTIONS\",\n);\n\nconst normalizeOptions = (\n options: HcaptchaOptions,\n): NormalizedHcaptchaOptions => ({\n getCaptchaData: defaultGetCaptchaData,\n ...options,\n});\n\nconst host: ConfigurableModuleHost<HcaptchaOptions, \"forRoot\", \"create\"> =\n new ConfigurableModuleBuilder<HcaptchaOptions>({\n optionsInjectionToken: PROVIDED_HCAPTCHA_OPTIONS,\n })\n .setClassMethodName(\"forRoot\")\n .setExtras({}, (def) => ({\n ...def,\n global: true,\n providers: [\n ...(def.providers ?? []),\n {\n provide: NORMALIZED_HCAPTCHA_OPTIONS,\n useFactory: normalizeOptions,\n inject: [PROVIDED_HCAPTCHA_OPTIONS],\n },\n ],\n exports: [NORMALIZED_HCAPTCHA_OPTIONS],\n }))\n .build();\n\n@Module({})\nexport class HcaptchaOptionsModule extends host.ConfigurableModuleClass {}\n\nexport type AsyncHcaptchaOptions = typeof host.ASYNC_OPTIONS_TYPE;\n","// Copy from https://github.com/microsoft/TypeScript/blob/d85767abfd83880cea17cea70f9913e9c4496dcc/src/compiler/factory/emitHelpers.ts#L744-L753\n\nfunction __decorateMetadata(k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};\n\n(module.exports = __decorateMetadata),\n (module.exports.__esModule = true),\n (module.exports[\"default\"] = module.exports);\n","// Copy from https://github.com/microsoft/TypeScript/blob/d85767abfd83880cea17cea70f9913e9c4496dcc/src/compiler/factory/emitHelpers.ts#L755-L764\n\nfunction __decorateParam(paramIndex, decorator) {\n return function (target, key) {\n decorator(target, key, paramIndex);\n };\n}\n\n(module.exports = __decorateParam),\n (module.exports.__esModule = true),\n (module.exports[\"default\"] = module.exports);\n","import { Injectable, Inject } from \"@nestjs/common\";\nimport { verify } from \"hcaptcha\";\n\nimport { NORMALIZED_HCAPTCHA_OPTIONS } from \"./options\";\nimport type { NormalizedHcaptchaOptions } from \"./options\";\nimport { HcaptchaException } from \"./hcaptcha.exception\";\nimport type { VerifyResponse } from \"./typings\";\n\n@Injectable()\nexport class HcaptchaService {\n constructor(\n @Inject(NORMALIZED_HCAPTCHA_OPTIONS)\n private readonly options: NormalizedHcaptchaOptions,\n ) {}\n\n async verifyCaptcha(\n token: string,\n remoteip?: string,\n ): Promise<VerifyResponse> {\n let verifyResponse: VerifyResponse;\n\n try {\n verifyResponse = await verify(\n this.options.secret,\n token,\n remoteip,\n this.options.sitekey,\n );\n } catch (e) {\n throw new HcaptchaException(e);\n }\n\n const { success } = verifyResponse;\n\n if (!success) {\n throw new HcaptchaException(verifyResponse);\n }\n\n return verifyResponse;\n }\n}\n","import {\n type CanActivate,\n type ExecutionContext,\n Inject,\n Injectable,\n} from \"@nestjs/common\";\n\nimport { NORMALIZED_HCAPTCHA_OPTIONS } from \"./options\";\nimport type { NormalizedHcaptchaOptions } from \"./options\";\nimport { HcaptchaService } from \"./hcaptcha.service\";\n\n@Injectable()\nexport class HcaptchaGuard implements CanActivate {\n constructor(\n @Inject(NORMALIZED_HCAPTCHA_OPTIONS)\n private readonly options: NormalizedHcaptchaOptions,\n private readonly hcaptchaService: HcaptchaService,\n ) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n const { token, remoteip } = this.options.getCaptchaData(context);\n\n await this.hcaptchaService.verifyCaptcha(token, remoteip);\n\n return true;\n }\n}\n","import { type DynamicModule, Module } from \"@nestjs/common\";\n\nimport {\n HcaptchaOptionsModule,\n type HcaptchaOptions,\n type AsyncHcaptchaOptions,\n} from \"./options\";\nimport { HcaptchaService } from \"./hcaptcha.service\";\n\n@Module({\n providers: [HcaptchaService],\n exports: [HcaptchaService],\n})\nexport class HcaptchaModule {\n static forRoot(options: HcaptchaOptions): DynamicModule {\n return {\n module: this,\n imports: [HcaptchaOptionsModule.forRoot(options)],\n };\n }\n\n static forRootAsync(options: AsyncHcaptchaOptions): DynamicModule {\n return {\n module: this,\n imports: [HcaptchaOptionsModule.forRootAsync(options)],\n };\n }\n}\n","import { UseGuards, applyDecorators } from \"@nestjs/common\";\n\nimport { HcaptchaGuard } from \"./hcaptcha.guard\";\n\nexport const VerifyCaptcha = (): ReturnType<typeof applyDecorators> =>\n applyDecorators(UseGuards(HcaptchaGuard));\n","import { verify } from 'hcaptcha';\n\nexport type VerifyResponse = Awaited<ReturnType<typeof verify>>;\n","export * from './get-captcha-data';\nexport type { HcaptchaOptions, AsyncHcaptchaOptions } from './options';\nexport * from './hcaptcha.exception';\nexport * from './hcaptcha.guard';\nexport * from './hcaptcha.module';\nexport * from './hcaptcha.service';\nexport * from './verify-captcha.decorator';\nexport * from './typings';\n","export * from './lib';\n"],"x_google_ignoreList":[2,4,5],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAa,oBAAb,cAAuCA,mCAAmB;CACxD,YAAYC,OAAgB,UAAU,aAAa;EACjD,MAAM,SAAS,EAAE,MAAO,EAAC;CAC1B;AACF;;;;ACMD,MAAaC,wBAAwC,CAAC,YAAY;CAChE,MAAM,UAAU,QAAQ,cAAc,CAAC,YAAY;CAEnD,MAAM,QAAQ,QAAQ,KAAK;AAE3B,KAAI,CAAC,MACH,OAAM,IAAI,kCACR,IAAI,MAAM;AAId,QAAO,EACL,MACD;AACF;;;;;CCxBD,SAAS,WAAW,YAAY,QAAQ,KAAK,MAAM;EACjD,IAAI,I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