@gvrs/nestjs-hcaptcha 0.2.0 → 0.3.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.
Files changed (37) hide show
  1. package/dist/index.d.ts +57 -0
  2. package/dist/index.js +235 -0
  3. package/dist/index.js.map +1 -0
  4. package/package.json +44 -60
  5. package/CHANGELOG.md +0 -31
  6. package/index.cjs.d.ts +0 -1
  7. package/index.cjs.default.js +0 -1
  8. package/index.cjs.js +0 -28
  9. package/index.cjs.mjs +0 -2
  10. package/index.esm.js +0 -6
  11. package/lib/get-captcha-data/get-captcha-data.cjs.js +0 -18
  12. package/lib/get-captcha-data/get-captcha-data.esm.js +0 -14
  13. package/lib/hcaptcha.exception.cjs.js +0 -15
  14. package/lib/hcaptcha.exception.esm.js +0 -11
  15. package/lib/hcaptcha.guard.cjs.js +0 -33
  16. package/lib/hcaptcha.guard.esm.js +0 -29
  17. package/lib/hcaptcha.module.cjs.js +0 -39
  18. package/lib/hcaptcha.module.esm.js +0 -35
  19. package/lib/hcaptcha.service.cjs.js +0 -40
  20. package/lib/hcaptcha.service.esm.js +0 -36
  21. package/lib/options/hcaptcha-options.module.cjs.js +0 -40
  22. package/lib/options/hcaptcha-options.module.esm.js +0 -35
  23. package/lib/verify-captcha.decorator.cjs.js +0 -10
  24. package/lib/verify-captcha.decorator.esm.js +0 -6
  25. package/src/index.d.ts +0 -1
  26. package/src/lib/get-captcha-data/get-captcha-data.d.ts +0 -7
  27. package/src/lib/get-captcha-data/index.d.ts +0 -1
  28. package/src/lib/hcaptcha.exception.d.ts +0 -4
  29. package/src/lib/hcaptcha.guard.d.ts +0 -9
  30. package/src/lib/hcaptcha.module.d.ts +0 -6
  31. package/src/lib/hcaptcha.service.d.ts +0 -6
  32. package/src/lib/index.d.ts +0 -8
  33. package/src/lib/options/hcaptcha-options.module.d.ts +0 -7
  34. package/src/lib/options/hcaptcha-options.types.d.ts +0 -7
  35. package/src/lib/options/index.d.ts +0 -2
  36. package/src/lib/typings.d.ts +0 -2
  37. package/src/lib/verify-captcha.decorator.d.ts +0 -1
@@ -0,0 +1,57 @@
1
+ import { CanActivate, ConfigurableModuleHost, DynamicModule, ExecutionContext, ForbiddenException, applyDecorators } from "@nestjs/common";
2
+ import { verify } from "hcaptcha";
3
+
4
+ //#region src/lib/get-captcha-data/get-captcha-data.d.ts
5
+ type CaptchaData = {
6
+ token: string;
7
+ remoteip?: string;
8
+ };
9
+ type GetCaptchaData = (executionContext: ExecutionContext) => CaptchaData;
10
+ declare const defaultGetCaptchaData: GetCaptchaData;
11
+ //#endregion
12
+ //#region src/lib/options/hcaptcha-options.types.d.ts
13
+ type HcaptchaOptions = {
14
+ secret: string;
15
+ sitekey?: string;
16
+ getCaptchaData?: GetCaptchaData;
17
+ };
18
+ type NormalizedHcaptchaOptions = Required<Pick<HcaptchaOptions, "getCaptchaData">> & HcaptchaOptions;
19
+ //#endregion
20
+ //#region src/lib/options/hcaptcha-options.module.d.ts
21
+ declare const host: ConfigurableModuleHost<HcaptchaOptions, "forRoot", "create">;
22
+ type AsyncHcaptchaOptions = typeof host.ASYNC_OPTIONS_TYPE;
23
+ //#endregion
24
+ //#region src/lib/hcaptcha.exception.d.ts
25
+ declare class HcaptchaException extends ForbiddenException {
26
+ constructor(cause: unknown, message?: string);
27
+ }
28
+ //#endregion
29
+ //#region src/lib/typings.d.ts
30
+ type VerifyResponse = Awaited<ReturnType<typeof verify>>;
31
+ //#endregion
32
+ //#region src/lib/hcaptcha.service.d.ts
33
+ declare class HcaptchaService {
34
+ private readonly options;
35
+ constructor(options: NormalizedHcaptchaOptions);
36
+ verifyCaptcha(token: string, remoteip?: string): Promise<VerifyResponse>;
37
+ }
38
+ //#endregion
39
+ //#region src/lib/hcaptcha.guard.d.ts
40
+ declare class HcaptchaGuard implements CanActivate {
41
+ private readonly options;
42
+ private readonly hcaptchaService;
43
+ constructor(options: NormalizedHcaptchaOptions, hcaptchaService: HcaptchaService);
44
+ canActivate(context: ExecutionContext): Promise<boolean>;
45
+ }
46
+ //#endregion
47
+ //#region src/lib/hcaptcha.module.d.ts
48
+ declare class HcaptchaModule {
49
+ static forRoot(options: HcaptchaOptions): DynamicModule;
50
+ static forRootAsync(options: AsyncHcaptchaOptions): DynamicModule;
51
+ }
52
+ //#endregion
53
+ //#region src/lib/verify-captcha.decorator.d.ts
54
+ declare const VerifyCaptcha: () => ReturnType<typeof applyDecorators>;
55
+ //#endregion
56
+ export { AsyncHcaptchaOptions, CaptchaData, GetCaptchaData, HcaptchaException, HcaptchaGuard, HcaptchaModule, HcaptchaOptions, HcaptchaService, VerifyCaptcha, VerifyResponse, defaultGetCaptchaData };
57
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,235 @@
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
@@ -0,0 +1 @@
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":"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"}
package/package.json CHANGED
@@ -1,76 +1,60 @@
1
1
  {
2
2
  "name": "@gvrs/nestjs-hcaptcha",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "license": "MIT",
5
5
  "author": "Alex Gavrusev <alex@gavrusev.dev>",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/alexgavrusev/nestjs-hcaptcha.git"
8
+ "url": "git+https://github.com/alexgavrusev/nestjs-hcaptcha.git"
9
9
  },
10
10
  "homepage": "https://github.com/alexgavrusev/nestjs-hcaptcha#readme",
11
11
  "bugs": {
12
12
  "url": "https://github.com/alexgavrusev/nestjs-hcaptcha/issues"
13
13
  },
14
- "scripts": {
15
- "prepare": "node -e \"if(require('fs').existsSync('.git')){/* proceed only if .git is found */ process.exit(1)}\" || is-ci || husky install"
14
+ "type": "commonjs",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "main": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "exports": {
21
+ ".": "./dist/index.js",
22
+ "./package.json": "./package.json"
16
23
  },
17
- "dependencies": {
18
- "@swc/helpers": "~0.5.2"
24
+ "peerDependencies": {
25
+ "@nestjs/common": "^11.0.0",
26
+ "hcaptcha": "~0.2.0"
19
27
  },
20
28
  "devDependencies": {
21
- "@commitlint/cli": "^19.3.0",
22
- "@commitlint/config-conventional": "^19.2.2",
23
- "@gvrs-nx/ts-package": "0.3.0",
24
- "@jscutlery/semver": "^5.2.2",
25
- "@nestjs/common": "10.3.8",
26
- "@nestjs/platform-express": "10.3.8",
27
- "@nestjs/testing": "10.3.8",
28
- "@nx/eslint": "18.3.5",
29
- "@nx/eslint-plugin": "18.3.5",
30
- "@nx/js": "18.3.5",
31
- "@nx/rollup": "18.3.5",
32
- "@nx/vite": "18.3.5",
33
- "@nx/workspace": "18.3.5",
34
- "@swc-node/register": "~1.9.1",
35
- "@swc/cli": "~0.3.12",
36
- "@swc/core": "~1.5.7",
37
- "@types/express": "4.17.21",
38
- "@types/node": "20.12.12",
39
- "@types/supertest": "6.0.2",
40
- "@typescript-eslint/eslint-plugin": "^7.9.0",
41
- "@typescript-eslint/parser": "^7.9.0",
42
- "@vitest/coverage-v8": "~1.6.0",
43
- "@vitest/ui": "~1.6.0",
44
- "eslint": "~8.57.0",
45
- "eslint-config-prettier": "^9.0.0",
46
- "hcaptcha": "0.1.1",
47
- "husky": "^9.0.11",
48
- "is-ci": "^3.0.0",
49
- "nock": "13.5.4",
50
- "nx": "18.3.5",
51
- "prettier": "^3.2.5",
52
- "supertest": "7.0.0",
53
- "tslib": "^2.3.0",
54
- "typescript": "~5.4.5",
55
- "unplugin-swc": "1.4.5",
56
- "verdaccio": "^5.0.4",
57
- "vite": "^5.0.0",
58
- "vitest": "1.6.0",
59
- "vitest-mock-extended": "1.3.1"
60
- },
61
- "peerDependencies": {
62
- "@nestjs/common": "^10.0.0",
63
- "hcaptcha": "~0.1.1"
29
+ "@nestjs/common": "^11.1.5",
30
+ "@nestjs/platform-express": "^11.1.5",
31
+ "@nestjs/testing": "^11.1.5",
32
+ "@types/express": "^5.0.3",
33
+ "@types/node": "^24.1.0",
34
+ "@types/supertest": "^6.0.3",
35
+ "@vitest/coverage-v8": "3.2.4",
36
+ "bumpp": "^10.2.1",
37
+ "changelogithub": "^13.16.0",
38
+ "hcaptcha": "^0.2.0",
39
+ "nock": "^14.0.7",
40
+ "oxlint": "^1.9.0",
41
+ "pkg-pr-new": "^0.0.54",
42
+ "prettier": "^3.6.2",
43
+ "supertest": "^7.1.4",
44
+ "tsdown": "^0.13.0",
45
+ "unplugin-swc": "^1.5.5",
46
+ "vitest": "^3.2.4",
47
+ "vitest-mock-extended": "^3.1.0"
64
48
  },
65
49
  "sideEffects": false,
66
- "exports": {
67
- "./package.json": "./package.json",
68
- ".": {
69
- "module": "./index.esm.js",
70
- "import": "./index.cjs.mjs",
71
- "default": "./index.cjs.js"
72
- }
73
- },
74
- "module": "./index.esm.js",
75
- "main": "./index.cjs.js"
76
- }
50
+ "scripts": {
51
+ "build": "tsdown",
52
+ "dev": "tsdown --watch",
53
+ "test": "vitest",
54
+ "e2e": "vitest --config vitest.config.e2e.ts",
55
+ "lint": "oxlint --deny-warnings",
56
+ "lint:fix": "pnpm run lint --fix",
57
+ "format": "prettier --cache --write .",
58
+ "release": "bumpp && pnpm publish"
59
+ }
60
+ }
package/CHANGELOG.md DELETED
@@ -1,31 +0,0 @@
1
- # Changelog
2
-
3
- This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
-
5
- ## [0.2.0](https://github.com/alexgavrusev/nestjs-hcaptcha/compare/nestjs-hcaptcha-0.1.0...nestjs-hcaptcha-0.2.0) (2024-05-18)
6
-
7
-
8
- ### Features
9
-
10
- * add dependabot ([5c8bc61](https://github.com/alexgavrusev/nestjs-hcaptcha/commit/5c8bc618c0f295e6912c468d57b7998bd570a3ee))
11
-
12
-
13
- ### Bug Fixes
14
-
15
- * resolve missing dependency errors caused by test files ([0398cb2](https://github.com/alexgavrusev/nestjs-hcaptcha/commit/0398cb241302ae8a07ab813a0589152044c92c73))
16
-
17
-
18
- ### Miscellaneous Chores
19
-
20
- * bump the github-actions group with 4 updates ([064a598](https://github.com/alexgavrusev/nestjs-hcaptcha/commit/064a5981fa8bd9eddbd13ecb5a61bb36d624c10a))
21
- * **deps:** bump @swc/helpers in the production group ([9481c72](https://github.com/alexgavrusev/nestjs-hcaptcha/commit/9481c72f2dd67e4deda574e05adbc23f6c15044c))
22
- * **deps:** bump the development group with 31 updates ([0818d4f](https://github.com/alexgavrusev/nestjs-hcaptcha/commit/0818d4fef24cad86d1e8b91b5c7bb3143ac45283))
23
- * do not hide chore commits from changelog ([e60142f](https://github.com/alexgavrusev/nestjs-hcaptcha/commit/e60142f9844a2d278d738cf620d67f37247e9eef))
24
- * temporarily disable updates to nx 19 and eslint 9 ([ed3c0f6](https://github.com/alexgavrusev/nestjs-hcaptcha/commit/ed3c0f688387b3c0b097291001cc863b02993994))
25
-
26
- ## 0.1.0 (2024-01-28)
27
-
28
-
29
- ### Features
30
-
31
- * initial commit ([9008bc3](https://github.com/alexgavrusev/nestjs-hcaptcha/commit/9008bc3386fc8dad738af6c5a96ed28424812f63))
package/index.cjs.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";
@@ -1 +0,0 @@
1
- exports._default = require('./index.cjs.js').default;
package/index.cjs.js DELETED
@@ -1,28 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var getCaptchaData = require('./lib/get-captcha-data/get-captcha-data.cjs.js');
6
- var hcaptcha_exception = require('./lib/hcaptcha.exception.cjs.js');
7
- var hcaptcha_guard = require('./lib/hcaptcha.guard.cjs.js');
8
- var hcaptcha_module = require('./lib/hcaptcha.module.cjs.js');
9
- var hcaptcha_service = require('./lib/hcaptcha.service.cjs.js');
10
- var verifyCaptcha_decorator = require('./lib/verify-captcha.decorator.cjs.js');
11
-
12
-
13
-
14
- exports.defaultGetCaptchaData = getCaptchaData.defaultGetCaptchaData;
15
- exports.HcaptchaException = hcaptcha_exception.HcaptchaException;
16
- Object.defineProperty(exports, 'HcaptchaGuard', {
17
- enumerable: true,
18
- get: function () { return hcaptcha_guard.HcaptchaGuard; }
19
- });
20
- Object.defineProperty(exports, 'HcaptchaModule', {
21
- enumerable: true,
22
- get: function () { return hcaptcha_module.HcaptchaModule; }
23
- });
24
- Object.defineProperty(exports, 'HcaptchaService', {
25
- enumerable: true,
26
- get: function () { return hcaptcha_service.HcaptchaService; }
27
- });
28
- exports.VerifyCaptcha = verifyCaptcha_decorator.VerifyCaptcha;
package/index.cjs.mjs DELETED
@@ -1,2 +0,0 @@
1
- export * from './index.cjs.js';
2
- export { _default as default } from './index.cjs.default.js';
package/index.esm.js DELETED
@@ -1,6 +0,0 @@
1
- export { defaultGetCaptchaData } from './lib/get-captcha-data/get-captcha-data.esm.js';
2
- export { HcaptchaException } from './lib/hcaptcha.exception.esm.js';
3
- export { HcaptchaGuard } from './lib/hcaptcha.guard.esm.js';
4
- export { HcaptchaModule } from './lib/hcaptcha.module.esm.js';
5
- export { HcaptchaService } from './lib/hcaptcha.service.esm.js';
6
- export { VerifyCaptcha } from './lib/verify-captcha.decorator.esm.js';
@@ -1,18 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var hcaptcha_exception = require('../hcaptcha.exception.cjs.js');
6
-
7
- const defaultGetCaptchaData = (context)=>{
8
- const request = context.switchToHttp().getRequest();
9
- const token = request.body['h-captcha-response'];
10
- if (!token) {
11
- throw new hcaptcha_exception.HcaptchaException(new Error('No hCaptcha token present in request body'));
12
- }
13
- return {
14
- token
15
- };
16
- };
17
-
18
- exports.defaultGetCaptchaData = defaultGetCaptchaData;
@@ -1,14 +0,0 @@
1
- import { HcaptchaException } from '../hcaptcha.exception.esm.js';
2
-
3
- const defaultGetCaptchaData = (context)=>{
4
- const request = context.switchToHttp().getRequest();
5
- const token = request.body['h-captcha-response'];
6
- if (!token) {
7
- throw new HcaptchaException(new Error('No hCaptcha token present in request body'));
8
- }
9
- return {
10
- token
11
- };
12
- };
13
-
14
- export { defaultGetCaptchaData };
@@ -1,15 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var common = require('@nestjs/common');
6
-
7
- class HcaptchaException extends common.ForbiddenException {
8
- constructor(cause, message = 'Forbidden'){
9
- super(message, {
10
- cause
11
- });
12
- }
13
- }
14
-
15
- exports.HcaptchaException = HcaptchaException;
@@ -1,11 +0,0 @@
1
- import { ForbiddenException } from '@nestjs/common';
2
-
3
- class HcaptchaException extends ForbiddenException {
4
- constructor(cause, message = 'Forbidden'){
5
- super(message, {
6
- cause
7
- });
8
- }
9
- }
10
-
11
- export { HcaptchaException };
@@ -1,33 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _ts_decorate = require('@swc/helpers/_/_ts_decorate');
6
- var _ts_metadata = require('@swc/helpers/_/_ts_metadata');
7
- var _ts_param = require('@swc/helpers/_/_ts_param');
8
- var common = require('@nestjs/common');
9
- var hcaptchaOptions_module = require('./options/hcaptcha-options.module.cjs.js');
10
- var hcaptcha_service = require('./hcaptcha.service.cjs.js');
11
-
12
- class HcaptchaGuard {
13
- async canActivate(context) {
14
- const { token, remoteip } = this.options.getCaptchaData(context);
15
- await this.hcaptchaService.verifyCaptcha(token, remoteip);
16
- return true;
17
- }
18
- constructor(options, hcaptchaService){
19
- this.options = options;
20
- this.hcaptchaService = hcaptchaService;
21
- }
22
- }
23
- HcaptchaGuard = _ts_decorate._([
24
- common.Injectable(),
25
- _ts_param._(0, common.Inject(hcaptchaOptions_module.NORMALIZED_HCAPTCHA_OPTIONS)),
26
- _ts_metadata._("design:type", Function),
27
- _ts_metadata._("design:paramtypes", [
28
- typeof NormalizedHcaptchaOptions === "undefined" ? Object : NormalizedHcaptchaOptions,
29
- typeof hcaptcha_service.HcaptchaService === "undefined" ? Object : hcaptcha_service.HcaptchaService
30
- ])
31
- ], HcaptchaGuard);
32
-
33
- exports.HcaptchaGuard = HcaptchaGuard;
@@ -1,29 +0,0 @@
1
- import { _ } from '@swc/helpers/_/_ts_decorate';
2
- import { _ as _$2 } from '@swc/helpers/_/_ts_metadata';
3
- import { _ as _$1 } from '@swc/helpers/_/_ts_param';
4
- import { Injectable, Inject } from '@nestjs/common';
5
- import { HcaptchaService } from './hcaptcha.service.esm.js';
6
- import { NORMALIZED_HCAPTCHA_OPTIONS } from './options/hcaptcha-options.module.esm.js';
7
-
8
- class HcaptchaGuard {
9
- async canActivate(context) {
10
- const { token, remoteip } = this.options.getCaptchaData(context);
11
- await this.hcaptchaService.verifyCaptcha(token, remoteip);
12
- return true;
13
- }
14
- constructor(options, hcaptchaService){
15
- this.options = options;
16
- this.hcaptchaService = hcaptchaService;
17
- }
18
- }
19
- HcaptchaGuard = _([
20
- Injectable(),
21
- _$1(0, Inject(NORMALIZED_HCAPTCHA_OPTIONS)),
22
- _$2("design:type", Function),
23
- _$2("design:paramtypes", [
24
- typeof NormalizedHcaptchaOptions === "undefined" ? Object : NormalizedHcaptchaOptions,
25
- typeof HcaptchaService === "undefined" ? Object : HcaptchaService
26
- ])
27
- ], HcaptchaGuard);
28
-
29
- export { HcaptchaGuard };
@@ -1,39 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _ts_decorate = require('@swc/helpers/_/_ts_decorate');
6
- var common = require('@nestjs/common');
7
- var hcaptchaOptions_module = require('./options/hcaptcha-options.module.cjs.js');
8
- var hcaptcha_service = require('./hcaptcha.service.cjs.js');
9
-
10
- class HcaptchaModule {
11
- static forRoot(options) {
12
- return {
13
- module: this,
14
- imports: [
15
- hcaptchaOptions_module.HcaptchaOptionsModule.forRoot(options)
16
- ]
17
- };
18
- }
19
- static forRootAsync(options) {
20
- return {
21
- module: this,
22
- imports: [
23
- hcaptchaOptions_module.HcaptchaOptionsModule.forRootAsync(options)
24
- ]
25
- };
26
- }
27
- }
28
- HcaptchaModule = _ts_decorate._([
29
- common.Module({
30
- providers: [
31
- hcaptcha_service.HcaptchaService
32
- ],
33
- exports: [
34
- hcaptcha_service.HcaptchaService
35
- ]
36
- })
37
- ], HcaptchaModule);
38
-
39
- exports.HcaptchaModule = HcaptchaModule;
@@ -1,35 +0,0 @@
1
- import { _ } from '@swc/helpers/_/_ts_decorate';
2
- import { Module } from '@nestjs/common';
3
- import { HcaptchaService } from './hcaptcha.service.esm.js';
4
- import { HcaptchaOptionsModule } from './options/hcaptcha-options.module.esm.js';
5
-
6
- class HcaptchaModule {
7
- static forRoot(options) {
8
- return {
9
- module: this,
10
- imports: [
11
- HcaptchaOptionsModule.forRoot(options)
12
- ]
13
- };
14
- }
15
- static forRootAsync(options) {
16
- return {
17
- module: this,
18
- imports: [
19
- HcaptchaOptionsModule.forRootAsync(options)
20
- ]
21
- };
22
- }
23
- }
24
- HcaptchaModule = _([
25
- Module({
26
- providers: [
27
- HcaptchaService
28
- ],
29
- exports: [
30
- HcaptchaService
31
- ]
32
- })
33
- ], HcaptchaModule);
34
-
35
- export { HcaptchaModule };
@@ -1,40 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _ts_decorate = require('@swc/helpers/_/_ts_decorate');
6
- var _ts_metadata = require('@swc/helpers/_/_ts_metadata');
7
- var _ts_param = require('@swc/helpers/_/_ts_param');
8
- var common = require('@nestjs/common');
9
- var hcaptcha = require('hcaptcha');
10
- var hcaptchaOptions_module = require('./options/hcaptcha-options.module.cjs.js');
11
- var hcaptcha_exception = require('./hcaptcha.exception.cjs.js');
12
-
13
- class HcaptchaService {
14
- async verifyCaptcha(token, remoteip) {
15
- let verifyResponse;
16
- try {
17
- verifyResponse = await hcaptcha.verify(this.options.secret, token, remoteip, this.options.sitekey);
18
- } catch (e) {
19
- throw new hcaptcha_exception.HcaptchaException(e);
20
- }
21
- const { success } = verifyResponse;
22
- if (!success) {
23
- throw new hcaptcha_exception.HcaptchaException(verifyResponse);
24
- }
25
- return verifyResponse;
26
- }
27
- constructor(options){
28
- this.options = options;
29
- }
30
- }
31
- HcaptchaService = _ts_decorate._([
32
- common.Injectable(),
33
- _ts_param._(0, common.Inject(hcaptchaOptions_module.NORMALIZED_HCAPTCHA_OPTIONS)),
34
- _ts_metadata._("design:type", Function),
35
- _ts_metadata._("design:paramtypes", [
36
- typeof NormalizedHcaptchaOptions === "undefined" ? Object : NormalizedHcaptchaOptions
37
- ])
38
- ], HcaptchaService);
39
-
40
- exports.HcaptchaService = HcaptchaService;
@@ -1,36 +0,0 @@
1
- import { _ } from '@swc/helpers/_/_ts_decorate';
2
- import { _ as _$2 } from '@swc/helpers/_/_ts_metadata';
3
- import { _ as _$1 } from '@swc/helpers/_/_ts_param';
4
- import { Injectable, Inject } from '@nestjs/common';
5
- import { verify } from 'hcaptcha';
6
- import { HcaptchaException } from './hcaptcha.exception.esm.js';
7
- import { NORMALIZED_HCAPTCHA_OPTIONS } from './options/hcaptcha-options.module.esm.js';
8
-
9
- class HcaptchaService {
10
- async verifyCaptcha(token, remoteip) {
11
- let verifyResponse;
12
- try {
13
- verifyResponse = await verify(this.options.secret, token, remoteip, this.options.sitekey);
14
- } catch (e) {
15
- throw new HcaptchaException(e);
16
- }
17
- const { success } = verifyResponse;
18
- if (!success) {
19
- throw new HcaptchaException(verifyResponse);
20
- }
21
- return verifyResponse;
22
- }
23
- constructor(options){
24
- this.options = options;
25
- }
26
- }
27
- HcaptchaService = _([
28
- Injectable(),
29
- _$1(0, Inject(NORMALIZED_HCAPTCHA_OPTIONS)),
30
- _$2("design:type", Function),
31
- _$2("design:paramtypes", [
32
- typeof NormalizedHcaptchaOptions === "undefined" ? Object : NormalizedHcaptchaOptions
33
- ])
34
- ], HcaptchaService);
35
-
36
- export { HcaptchaService };
@@ -1,40 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _extends = require('@swc/helpers/_/_extends');
6
- var _ts_decorate = require('@swc/helpers/_/_ts_decorate');
7
- var common = require('@nestjs/common');
8
- var getCaptchaData = require('../get-captcha-data/get-captcha-data.cjs.js');
9
-
10
- const PROVIDED_HCAPTCHA_OPTIONS = Symbol('PROVIDED_HCAPTCHA_OPTIONS');
11
- const NORMALIZED_HCAPTCHA_OPTIONS = Symbol('NORMALIZED_HCAPTCHA_OPTIONS');
12
- const normalizeOptions = (options)=>_extends._({
13
- getCaptchaData: getCaptchaData.defaultGetCaptchaData
14
- }, options);
15
- const { ASYNC_OPTIONS_TYPE: ASYNC_HCAPTCHA_OPTIONS_TYPE, ConfigurableModuleClass } = new common.ConfigurableModuleBuilder({
16
- optionsInjectionToken: PROVIDED_HCAPTCHA_OPTIONS
17
- }).setClassMethodName('forRoot').setExtras({}, (def)=>_extends._({}, def, {
18
- global: true,
19
- providers: [
20
- ...def.providers,
21
- {
22
- provide: NORMALIZED_HCAPTCHA_OPTIONS,
23
- useFactory: normalizeOptions,
24
- inject: [
25
- PROVIDED_HCAPTCHA_OPTIONS
26
- ]
27
- }
28
- ],
29
- exports: [
30
- NORMALIZED_HCAPTCHA_OPTIONS
31
- ]
32
- })).build();
33
- class HcaptchaOptionsModule extends ConfigurableModuleClass {
34
- }
35
- HcaptchaOptionsModule = _ts_decorate._([
36
- common.Module({})
37
- ], HcaptchaOptionsModule);
38
-
39
- exports.HcaptchaOptionsModule = HcaptchaOptionsModule;
40
- exports.NORMALIZED_HCAPTCHA_OPTIONS = NORMALIZED_HCAPTCHA_OPTIONS;
@@ -1,35 +0,0 @@
1
- import { _ } from '@swc/helpers/_/_extends';
2
- import { _ as _$1 } from '@swc/helpers/_/_ts_decorate';
3
- import { ConfigurableModuleBuilder, Module } from '@nestjs/common';
4
- import { defaultGetCaptchaData } from '../get-captcha-data/get-captcha-data.esm.js';
5
-
6
- const PROVIDED_HCAPTCHA_OPTIONS = Symbol('PROVIDED_HCAPTCHA_OPTIONS');
7
- const NORMALIZED_HCAPTCHA_OPTIONS = Symbol('NORMALIZED_HCAPTCHA_OPTIONS');
8
- const normalizeOptions = (options)=>_({
9
- getCaptchaData: defaultGetCaptchaData
10
- }, options);
11
- const { ASYNC_OPTIONS_TYPE: ASYNC_HCAPTCHA_OPTIONS_TYPE, ConfigurableModuleClass } = new ConfigurableModuleBuilder({
12
- optionsInjectionToken: PROVIDED_HCAPTCHA_OPTIONS
13
- }).setClassMethodName('forRoot').setExtras({}, (def)=>_({}, def, {
14
- global: true,
15
- providers: [
16
- ...def.providers,
17
- {
18
- provide: NORMALIZED_HCAPTCHA_OPTIONS,
19
- useFactory: normalizeOptions,
20
- inject: [
21
- PROVIDED_HCAPTCHA_OPTIONS
22
- ]
23
- }
24
- ],
25
- exports: [
26
- NORMALIZED_HCAPTCHA_OPTIONS
27
- ]
28
- })).build();
29
- class HcaptchaOptionsModule extends ConfigurableModuleClass {
30
- }
31
- HcaptchaOptionsModule = _$1([
32
- Module({})
33
- ], HcaptchaOptionsModule);
34
-
35
- export { HcaptchaOptionsModule, NORMALIZED_HCAPTCHA_OPTIONS };
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var common = require('@nestjs/common');
6
- var hcaptcha_guard = require('./hcaptcha.guard.cjs.js');
7
-
8
- const VerifyCaptcha = ()=>common.applyDecorators(common.UseGuards(hcaptcha_guard.HcaptchaGuard));
9
-
10
- exports.VerifyCaptcha = VerifyCaptcha;
@@ -1,6 +0,0 @@
1
- import { applyDecorators, UseGuards } from '@nestjs/common';
2
- import { HcaptchaGuard } from './hcaptcha.guard.esm.js';
3
-
4
- const VerifyCaptcha = ()=>applyDecorators(UseGuards(HcaptchaGuard));
5
-
6
- export { VerifyCaptcha };
package/src/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './lib';
@@ -1,7 +0,0 @@
1
- import { ExecutionContext } from '@nestjs/common';
2
- export type CaptchaData = {
3
- token: string;
4
- remoteip?: string;
5
- };
6
- export type GetCaptchaData = (executionContext: ExecutionContext) => CaptchaData;
7
- export declare const defaultGetCaptchaData: GetCaptchaData;
@@ -1 +0,0 @@
1
- export * from './get-captcha-data';
@@ -1,4 +0,0 @@
1
- import { ForbiddenException } from '@nestjs/common';
2
- export declare class HcaptchaException extends ForbiddenException {
3
- constructor(cause: unknown, message?: string);
4
- }
@@ -1,9 +0,0 @@
1
- import { CanActivate, ExecutionContext } from '@nestjs/common';
2
- import type { NormalizedHcaptchaOptions } from './options';
3
- import { HcaptchaService } from './hcaptcha.service';
4
- export declare class HcaptchaGuard implements CanActivate {
5
- private readonly options;
6
- private readonly hcaptchaService;
7
- constructor(options: NormalizedHcaptchaOptions, hcaptchaService: HcaptchaService);
8
- canActivate(context: ExecutionContext): Promise<boolean>;
9
- }
@@ -1,6 +0,0 @@
1
- import { DynamicModule } from '@nestjs/common';
2
- import { HcaptchaOptions, AsyncHcaptchaOptions } from './options';
3
- export declare class HcaptchaModule {
4
- static forRoot(options: HcaptchaOptions): DynamicModule;
5
- static forRootAsync(options: AsyncHcaptchaOptions): DynamicModule;
6
- }
@@ -1,6 +0,0 @@
1
- import type { NormalizedHcaptchaOptions } from './options';
2
- export declare class HcaptchaService {
3
- private readonly options;
4
- constructor(options: NormalizedHcaptchaOptions);
5
- verifyCaptcha(token: string, remoteip?: string): Promise<globalThis.VerifyResponse>;
6
- }
@@ -1,8 +0,0 @@
1
- export * from './get-captcha-data';
2
- export type { HcaptchaOptions, AsyncHcaptchaOptions } from './options';
3
- export * from './hcaptcha.exception';
4
- export * from './hcaptcha.guard';
5
- export * from './hcaptcha.module';
6
- export * from './hcaptcha.service';
7
- export * from './verify-captcha.decorator';
8
- export * from './typings';
@@ -1,7 +0,0 @@
1
- import { HcaptchaOptions } from './hcaptcha-options.types';
2
- declare const NORMALIZED_HCAPTCHA_OPTIONS: unique symbol;
3
- declare const ASYNC_HCAPTCHA_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<HcaptchaOptions, "create"> & Partial<{}>, ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<HcaptchaOptions, "forRoot", "create", {}>;
4
- export declare class HcaptchaOptionsModule extends ConfigurableModuleClass {
5
- }
6
- export type AsyncHcaptchaOptions = typeof ASYNC_HCAPTCHA_OPTIONS_TYPE;
7
- export { NORMALIZED_HCAPTCHA_OPTIONS };
@@ -1,7 +0,0 @@
1
- import { GetCaptchaData } from '../get-captcha-data';
2
- export type HcaptchaOptions = {
3
- secret: string;
4
- sitekey?: string;
5
- getCaptchaData?: GetCaptchaData;
6
- };
7
- export type NormalizedHcaptchaOptions = Required<Pick<HcaptchaOptions, 'getCaptchaData'>> & HcaptchaOptions;
@@ -1,2 +0,0 @@
1
- export * from './hcaptcha-options.module';
2
- export * from './hcaptcha-options.types';
@@ -1,2 +0,0 @@
1
- import { verify } from 'hcaptcha';
2
- export type VerifyResponse = Awaited<ReturnType<typeof verify>>;
@@ -1 +0,0 @@
1
- export declare const VerifyCaptcha: () => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;