@gvrs/nestjs-hcaptcha 0.2.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.cts +57 -0
- package/package.json +44 -60
- package/CHANGELOG.md +0 -31
- package/index.cjs.d.ts +0 -1
- package/index.cjs.default.js +0 -1
- package/index.cjs.js +0 -28
- package/index.cjs.mjs +0 -2
- package/index.esm.js +0 -6
- package/lib/get-captcha-data/get-captcha-data.cjs.js +0 -18
- package/lib/get-captcha-data/get-captcha-data.esm.js +0 -14
- package/lib/hcaptcha.exception.cjs.js +0 -15
- package/lib/hcaptcha.exception.esm.js +0 -11
- package/lib/hcaptcha.guard.cjs.js +0 -33
- package/lib/hcaptcha.guard.esm.js +0 -29
- package/lib/hcaptcha.module.cjs.js +0 -39
- package/lib/hcaptcha.module.esm.js +0 -35
- package/lib/hcaptcha.service.cjs.js +0 -40
- package/lib/hcaptcha.service.esm.js +0 -36
- package/lib/options/hcaptcha-options.module.cjs.js +0 -40
- package/lib/options/hcaptcha-options.module.esm.js +0 -35
- package/lib/verify-captcha.decorator.cjs.js +0 -10
- package/lib/verify-captcha.decorator.esm.js +0 -6
- package/src/index.d.ts +0 -1
- package/src/lib/get-captcha-data/get-captcha-data.d.ts +0 -7
- package/src/lib/get-captcha-data/index.d.ts +0 -1
- package/src/lib/hcaptcha.exception.d.ts +0 -4
- package/src/lib/hcaptcha.guard.d.ts +0 -9
- package/src/lib/hcaptcha.module.d.ts +0 -6
- package/src/lib/hcaptcha.service.d.ts +0 -6
- package/src/lib/index.d.ts +0 -8
- package/src/lib/options/hcaptcha-options.module.d.ts +0 -7
- package/src/lib/options/hcaptcha-options.types.d.ts +0 -7
- package/src/lib/options/index.d.ts +0 -2
- package/src/lib/typings.d.ts +0 -2
- package/src/lib/verify-captcha.decorator.d.ts +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,0CAA2C,EAC7C,uBAAuB,2BACxB,CAAC,CACC,mBAAmB,UAAU,CAC7B,UAAU,EAAE,GAAG,SAAS;CACvB,GAAG;CACH,QAAQ;CACR,WAAW,CACT,GAAI,IAAI,aAAa,EAAE,EACvB;EACE,SAAS;EACT,YAAY;EACZ,QAAQ,CAAC,0BAA0B;EACpC,CACF;CACD,SAAS,CAAC,4BAA4B;CACvC,EAAE,CACF,OAAO;AAGL,kCAAMC,gCAA8B,KAAK,wBAAwB;gEADhE,EAAE,CAAC;;;;;;;;;;;;;;;;;;ACpCJ,4BAAMC,kBAAgB;CAC3B,YACE,AACiBC,SACjB;EADiB;;CAGnB,MAAM,cACJ,OACA,UACyB;EACzB,IAAIC;AAEJ,MAAI;AACF,oBAAiB,2BACf,KAAK,QAAQ,QACb,OACA,UACA,KAAK,QAAQ,QACd;WACM,GAAG;AACV,SAAM,IAAI,kBAAkB,EAAE;;EAGhC,MAAM,EAAE,YAAY;AAEpB,MAAI,CAAC,QACH,OAAM,IAAI,kBAAkB,eAAe;AAG7C,SAAO;;;;kCA9BE;gDAGD,4BAA4B;;;;;;;ACCjC,0BAAMC,gBAAqC;CAChD,YACE,AACiBC,SACjB,AAAiBC,iBACjB;EAFiB;EACA;;CAGnB,MAAM,YAAY,SAA6C;EAC7D,MAAM,EAAE,OAAO,aAAa,KAAK,QAAQ,eAAe,QAAQ;AAEhE,QAAM,KAAK,gBAAgB,cAAc,OAAO,SAAS;AAEzD,SAAO;;;;kCAbE;gDAGD,4BAA4B;;;;;;ACDjC,2BAAMC,iBAAe;CAC1B,OAAO,QAAQ,SAAyC;AACtD,SAAO;GACL,QAAQ;GACR,SAAS,CAAC,sBAAsB,QAAQ,QAAQ,CAAC;GAClD;;CAGH,OAAO,aAAa,SAA8C;AAChE,SAAO;GACL,QAAQ;GACR,SAAS,CAAC,sBAAsB,aAAa,QAAQ,CAAC;GACvD;;;yDAhBG;CACN,WAAW,CAAC,gBAAgB;CAC5B,SAAS,CAAC,gBAAgB;CAC3B,CAAC;;;;ACRF,MAAa,0FACe,cAAc,CAAC"}
|
package/dist/index.d.cts
ADDED
|
@@ -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.cts.map
|
package/package.json
CHANGED
|
@@ -1,76 +1,60 @@
|
|
|
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": {
|
|
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
|
-
"
|
|
15
|
-
|
|
14
|
+
"type": "module",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"main": "./dist/index.cjs",
|
|
19
|
+
"types": "./dist/index.d.cts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": "./dist/index.cjs",
|
|
22
|
+
"./package.json": "./package.json"
|
|
16
23
|
},
|
|
17
|
-
"
|
|
18
|
-
"@
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@nestjs/common": "^11.0.0",
|
|
26
|
+
"hcaptcha": "~0.2.0"
|
|
19
27
|
},
|
|
20
28
|
"devDependencies": {
|
|
21
|
-
"@
|
|
22
|
-
"@
|
|
23
|
-
"@
|
|
24
|
-
"@
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
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.60",
|
|
42
|
+
"prettier": "^3.6.2",
|
|
43
|
+
"supertest": "^7.1.4",
|
|
44
|
+
"tsdown": "^0.15.6",
|
|
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
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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";
|
package/index.cjs.default.js
DELETED
|
@@ -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
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,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;
|
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,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
|
-
}
|
package/src/lib/index.d.ts
DELETED
|
@@ -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;
|
package/src/lib/typings.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const VerifyCaptcha: () => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|