vendure-plugin-capjs 0.0.1

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/README.md ADDED
@@ -0,0 +1 @@
1
+ # Capjs plugin
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './src/plugin';
2
+ export * from './src/decorators/capjs-validate.decorator';
package/lib/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./src/plugin"), exports);
18
+ __exportStar(require("./src/decorators/capjs-validate.decorator"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,4EAA0D"}
@@ -0,0 +1,21 @@
1
+ import { OnApplicationBootstrap } from '@nestjs/common';
2
+ import { Response } from 'express';
3
+ import { CapjsService } from '../services/capjs.service';
4
+ export declare class CapjsController implements OnApplicationBootstrap {
5
+ private readonly capjsService;
6
+ constructor(capjsService: CapjsService);
7
+ onApplicationBootstrap(): void;
8
+ createChallenge(): Promise<{
9
+ challenge: {
10
+ c: number;
11
+ s: number;
12
+ d: number;
13
+ };
14
+ token?: string;
15
+ expires: number;
16
+ }>;
17
+ redeemChallenge(res: Response, body: {
18
+ token: string;
19
+ solutions: number[];
20
+ }): Promise<Response<any, Record<string, any>>>;
21
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.CapjsController = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const core_1 = require("@vendure/core");
18
+ const capjs_service_1 = require("../services/capjs.service");
19
+ let CapjsController = class CapjsController {
20
+ constructor(capjsService) {
21
+ this.capjsService = capjsService;
22
+ }
23
+ onApplicationBootstrap() {
24
+ (0, core_1.registerPluginStartupMessage)('Cap Challenge Endpoint', 'cap/challenge');
25
+ (0, core_1.registerPluginStartupMessage)('Cap Redeem Endpoint', 'cap/redeem');
26
+ }
27
+ createChallenge() {
28
+ return this.capjsService.createChallenge();
29
+ }
30
+ async redeemChallenge(res, body) {
31
+ const { token, solutions } = body;
32
+ if (!token || !solutions) {
33
+ return res.status(400).json({ success: false });
34
+ }
35
+ const result = await this.capjsService.redeemChallenge(token, solutions);
36
+ return res.json(result);
37
+ }
38
+ };
39
+ exports.CapjsController = CapjsController;
40
+ __decorate([
41
+ (0, common_1.Post)('challenge'),
42
+ __metadata("design:type", Function),
43
+ __metadata("design:paramtypes", []),
44
+ __metadata("design:returntype", void 0)
45
+ ], CapjsController.prototype, "createChallenge", null);
46
+ __decorate([
47
+ (0, common_1.Post)('redeem'),
48
+ __param(0, (0, common_1.Res)()),
49
+ __param(1, (0, common_1.Body)()),
50
+ __metadata("design:type", Function),
51
+ __metadata("design:paramtypes", [Object, Object]),
52
+ __metadata("design:returntype", Promise)
53
+ ], CapjsController.prototype, "redeemChallenge", null);
54
+ exports.CapjsController = CapjsController = __decorate([
55
+ (0, common_1.Controller)('cap'),
56
+ __metadata("design:paramtypes", [capjs_service_1.CapjsService])
57
+ ], CapjsController);
58
+ //# sourceMappingURL=capjs.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capjs.controller.js","sourceRoot":"","sources":["../../../src/api/capjs.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAMwB;AACxB,wCAA6D;AAG7D,6DAAyD;AAGlD,IAAM,eAAe,GAArB,MAAM,eAAe;IAC1B,YAA6B,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAE3D,sBAAsB;QACpB,IAAA,mCAA4B,EAAC,wBAAwB,EAAE,eAAe,CAAC,CAAC;QACxE,IAAA,mCAA4B,EAAC,qBAAqB,EAAE,YAAY,CAAC,CAAC;IACpE,CAAC;IAGD,eAAe;QACb,OAAO,IAAI,CAAC,YAAY,CAAC,eAAe,EAAE,CAAC;IAC7C,CAAC;IAGK,AAAN,KAAK,CAAC,eAAe,CACZ,GAAa,EACZ,IAA4C;QAEpD,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAElC,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC;YACzB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;QAClD,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACzE,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;CACF,CAAA;AA3BY,0CAAe;AAS1B;IADC,IAAA,aAAI,EAAC,WAAW,CAAC;;;;sDAGjB;AAGK;IADL,IAAA,aAAI,EAAC,QAAQ,CAAC;IAEZ,WAAA,IAAA,YAAG,GAAE,CAAA;IACL,WAAA,IAAA,aAAI,GAAE,CAAA;;;;sDAUR;0BA1BU,eAAe;IAD3B,IAAA,mBAAU,EAAC,KAAK,CAAC;qCAE2B,4BAAY;GAD5C,eAAe,CA2B3B"}
@@ -0,0 +1,2 @@
1
+ export declare const CAPJS_PLUGIN_OPTIONS: unique symbol;
2
+ export declare const loggerCtx = "CapjsPlugin";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loggerCtx = exports.CAPJS_PLUGIN_OPTIONS = void 0;
4
+ exports.CAPJS_PLUGIN_OPTIONS = Symbol('CAPJS_PLUGIN_OPTIONS');
5
+ exports.loggerCtx = 'CapjsPlugin';
6
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AACtD,QAAA,SAAS,GAAG,aAAa,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function CapjsValidate(): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CapjsValidate = CapjsValidate;
4
+ const common_1 = require("@nestjs/common");
5
+ const capjs_guard_1 = require("../guards/capjs.guard");
6
+ function CapjsValidate() {
7
+ return (0, common_1.applyDecorators)((0, common_1.UseGuards)(capjs_guard_1.CapjsGuard));
8
+ }
9
+ //# sourceMappingURL=capjs-validate.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capjs-validate.decorator.js","sourceRoot":"","sources":["../../../src/decorators/capjs-validate.decorator.ts"],"names":[],"mappings":";;AAIA,sCAEC;AAND,2CAA4D;AAE5D,uDAAmD;AAEnD,SAAgB,aAAa;IAC3B,OAAO,IAAA,wBAAe,EAAC,IAAA,kBAAS,EAAC,wBAAU,CAAC,CAAC,CAAC;AAChD,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { VendureEntity } from '@vendure/core';
2
+ import { DeepPartial } from 'typeorm';
3
+ export declare class CapjsChallenge extends VendureEntity {
4
+ constructor(input?: DeepPartial<CapjsChallenge>);
5
+ token: string;
6
+ data: string;
7
+ expires: number;
8
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CapjsChallenge = void 0;
13
+ const core_1 = require("@vendure/core");
14
+ const typeorm_1 = require("typeorm");
15
+ let CapjsChallenge = class CapjsChallenge extends core_1.VendureEntity {
16
+ constructor(input) {
17
+ super(input);
18
+ }
19
+ };
20
+ exports.CapjsChallenge = CapjsChallenge;
21
+ __decorate([
22
+ (0, typeorm_1.Index)({ unique: true }),
23
+ (0, typeorm_1.Column)('text'),
24
+ __metadata("design:type", String)
25
+ ], CapjsChallenge.prototype, "token", void 0);
26
+ __decorate([
27
+ (0, typeorm_1.Column)('text'),
28
+ __metadata("design:type", String)
29
+ ], CapjsChallenge.prototype, "data", void 0);
30
+ __decorate([
31
+ (0, typeorm_1.Column)('bigint'),
32
+ __metadata("design:type", Number)
33
+ ], CapjsChallenge.prototype, "expires", void 0);
34
+ exports.CapjsChallenge = CapjsChallenge = __decorate([
35
+ (0, typeorm_1.Entity)(),
36
+ __metadata("design:paramtypes", [Object])
37
+ ], CapjsChallenge);
38
+ //# sourceMappingURL=capjs-challenges.entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capjs-challenges.entity.js","sourceRoot":"","sources":["../../../src/entities/capjs-challenges.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA8C;AAC9C,qCAA6D;AAGtD,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,oBAAa;IAC7C,YAAY,KAAmC;QAC3C,KAAK,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;CAWJ,CAAA;AAdY,wCAAc;AAOvB;IAFC,IAAA,eAAK,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACvB,IAAA,gBAAM,EAAC,MAAM,CAAC;;6CACD;AAGd;IADC,IAAA,gBAAM,EAAC,MAAM,CAAC;;4CACF;AAGb;IADC,IAAA,gBAAM,EAAC,QAAQ,CAAC;;+CACD;yBAbP,cAAc;IAD1B,IAAA,gBAAM,GAAE;;GACI,cAAc,CAc1B"}
@@ -0,0 +1,7 @@
1
+ import { VendureEntity } from '@vendure/core';
2
+ import { DeepPartial } from 'typeorm';
3
+ export declare class CapjsToken extends VendureEntity {
4
+ constructor(input?: DeepPartial<CapjsToken>);
5
+ key: string;
6
+ expires: number;
7
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CapjsToken = void 0;
13
+ const core_1 = require("@vendure/core");
14
+ const typeorm_1 = require("typeorm");
15
+ let CapjsToken = class CapjsToken extends core_1.VendureEntity {
16
+ constructor(input) {
17
+ super(input);
18
+ }
19
+ };
20
+ exports.CapjsToken = CapjsToken;
21
+ __decorate([
22
+ (0, typeorm_1.Index)({ unique: true }),
23
+ (0, typeorm_1.Column)('text'),
24
+ __metadata("design:type", String)
25
+ ], CapjsToken.prototype, "key", void 0);
26
+ __decorate([
27
+ (0, typeorm_1.Column)('bigint'),
28
+ __metadata("design:type", Number)
29
+ ], CapjsToken.prototype, "expires", void 0);
30
+ exports.CapjsToken = CapjsToken = __decorate([
31
+ (0, typeorm_1.Entity)(),
32
+ __metadata("design:paramtypes", [Object])
33
+ ], CapjsToken);
34
+ //# sourceMappingURL=capjs-token.entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capjs-token.entity.js","sourceRoot":"","sources":["../../../src/entities/capjs-token.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA8C;AAC9C,qCAA6D;AAGtD,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,oBAAa;IACzC,YAAY,KAA+B;QACvC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;CAQJ,CAAA;AAXY,gCAAU;AAOnB;IAFC,IAAA,eAAK,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACvB,IAAA,gBAAM,EAAC,MAAM,CAAC;;uCACH;AAGZ;IADC,IAAA,gBAAM,EAAC,QAAQ,CAAC;;2CACD;qBAVP,UAAU;IADtB,IAAA,gBAAM,GAAE;;GACI,UAAU,CAWtB"}
@@ -0,0 +1,7 @@
1
+ import { CanActivate, ExecutionContext } from '@nestjs/common';
2
+ import { CapjsService } from '../services/capjs.service';
3
+ export declare class CapjsGuard implements CanActivate {
4
+ private capjsService;
5
+ constructor(capjsService: CapjsService);
6
+ canActivate(context: ExecutionContext): Promise<boolean>;
7
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CapjsGuard = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const graphql_1 = require("@nestjs/graphql");
15
+ const core_1 = require("@vendure/core");
16
+ const capjs_service_1 = require("../services/capjs.service");
17
+ let CapjsGuard = class CapjsGuard {
18
+ constructor(capjsService) {
19
+ this.capjsService = capjsService;
20
+ }
21
+ async canActivate(context) {
22
+ const gqlCtx = graphql_1.GqlExecutionContext.create(context);
23
+ const req = gqlCtx.getContext().req;
24
+ const token = req.headers['x-captcha-token'];
25
+ if (!token) {
26
+ throw new core_1.UserInputError('MISSING_CAPTCHA', {
27
+ message: 'Captcha token is required',
28
+ });
29
+ }
30
+ const { success } = await this.capjsService.validateToken(token);
31
+ if (!success) {
32
+ throw new core_1.UserInputError('INVALID_CAPTCHA', {
33
+ message: 'Captcha validation failed',
34
+ });
35
+ }
36
+ return true;
37
+ }
38
+ };
39
+ exports.CapjsGuard = CapjsGuard;
40
+ exports.CapjsGuard = CapjsGuard = __decorate([
41
+ (0, common_1.Injectable)(),
42
+ __metadata("design:paramtypes", [capjs_service_1.CapjsService])
43
+ ], CapjsGuard);
44
+ //# sourceMappingURL=capjs.guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capjs.guard.js","sourceRoot":"","sources":["../../../src/guards/capjs.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA2E;AAC3E,6CAAsD;AACtD,wCAA+C;AAE/C,6DAAyD;AAGlD,IAAM,UAAU,GAAhB,MAAM,UAAU;IACnB,YAAoB,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAElD,KAAK,CAAC,WAAW,CAAC,OAAyB;QACvC,MAAM,MAAM,GAAG,6BAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACnD,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC;QACpC,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAC7C,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,MAAM,IAAI,qBAAc,CAAC,iBAAiB,EAAE;gBACxC,OAAO,EAAE,2BAA2B;aACvC,CAAC,CAAC;QACP,CAAC;QAED,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACjE,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,IAAI,qBAAc,CAAC,iBAAiB,EAAE;gBACxC,OAAO,EAAE,2BAA2B;aACvC,CAAC,CAAC;QACP,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ,CAAA;AArBY,gCAAU;qBAAV,UAAU;IADtB,IAAA,mBAAU,GAAE;qCAEyB,4BAAY;GADrC,UAAU,CAqBtB"}
@@ -0,0 +1,6 @@
1
+ import { Type } from '@vendure/core';
2
+ import { PluginInitOptions } from './types';
3
+ export declare class CapjsPlugin {
4
+ static options: PluginInitOptions;
5
+ static init(options: PluginInitOptions): Type<CapjsPlugin>;
6
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var CapjsPlugin_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.CapjsPlugin = void 0;
11
+ const core_1 = require("@vendure/core");
12
+ const capjs_controller_1 = require("./api/capjs.controller");
13
+ const constants_1 = require("./constants");
14
+ const capjs_challenges_entity_1 = require("./entities/capjs-challenges.entity");
15
+ const capjs_token_entity_1 = require("./entities/capjs-token.entity");
16
+ const capjs_service_1 = require("./services/capjs.service");
17
+ let CapjsPlugin = CapjsPlugin_1 = class CapjsPlugin {
18
+ static init(options) {
19
+ this.options = options;
20
+ return CapjsPlugin_1;
21
+ }
22
+ };
23
+ exports.CapjsPlugin = CapjsPlugin;
24
+ exports.CapjsPlugin = CapjsPlugin = CapjsPlugin_1 = __decorate([
25
+ (0, core_1.VendurePlugin)({
26
+ imports: [core_1.PluginCommonModule],
27
+ providers: [
28
+ { provide: constants_1.CAPJS_PLUGIN_OPTIONS, useFactory: () => CapjsPlugin.options },
29
+ capjs_service_1.CapjsService,
30
+ ],
31
+ entities: [capjs_token_entity_1.CapjsToken, capjs_challenges_entity_1.CapjsChallenge],
32
+ controllers: [capjs_controller_1.CapjsController],
33
+ exports: [capjs_service_1.CapjsService],
34
+ compatibility: '^3.0.0',
35
+ })
36
+ ], CapjsPlugin);
37
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,wCAAwE;AAExE,6DAAyD;AACzD,2CAAmD;AACnD,gFAAoE;AACpE,sEAA2D;AAC3D,4DAAwD;AAcjD,IAAM,WAAW,mBAAjB,MAAM,WAAW;IAGtB,MAAM,CAAC,IAAI,CAAC,OAA0B;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO,aAAW,CAAC;IACrB,CAAC;CACF,CAAA;AAPY,kCAAW;sBAAX,WAAW;IAXvB,IAAA,oBAAa,EAAC;QACb,OAAO,EAAE,CAAC,yBAAkB,CAAC;QAC7B,SAAS,EAAE;YACT,EAAE,OAAO,EAAE,gCAAoB,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE;YACxE,4BAAY;SACb;QACD,QAAQ,EAAE,CAAC,+BAAU,EAAE,wCAAc,CAAC;QACtC,WAAW,EAAE,CAAC,kCAAe,CAAC;QAC9B,OAAO,EAAE,CAAC,4BAAY,CAAC;QACvB,aAAa,EAAE,QAAQ;KACxB,CAAC;GACW,WAAW,CAOvB"}
@@ -0,0 +1,25 @@
1
+ import { TransactionalConnection } from '@vendure/core';
2
+ export declare class CapjsService {
3
+ private connection;
4
+ private cap;
5
+ constructor(connection: TransactionalConnection);
6
+ createChallenge(): Promise<{
7
+ challenge: {
8
+ c: number;
9
+ s: number;
10
+ d: number;
11
+ };
12
+ token?: string;
13
+ expires: number;
14
+ }>;
15
+ redeemChallenge(token: string, solutions: number[]): Promise<{
16
+ success: boolean;
17
+ message?: string;
18
+ token?: string;
19
+ expires?: number;
20
+ }>;
21
+ validateToken(token: string): Promise<{
22
+ success: boolean;
23
+ }>;
24
+ cleanup(): Promise<void>;
25
+ }
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.CapjsService = void 0;
16
+ const server_1 = __importDefault(require("@cap.js/server"));
17
+ const common_1 = require("@nestjs/common");
18
+ const core_1 = require("@vendure/core");
19
+ const capjs_challenges_entity_1 = require("../entities/capjs-challenges.entity");
20
+ const capjs_token_entity_1 = require("../entities/capjs-token.entity");
21
+ let CapjsService = class CapjsService {
22
+ constructor(connection) {
23
+ this.connection = connection;
24
+ this.cap = new server_1.default({
25
+ storage: {
26
+ challenges: {
27
+ store: async (token, challengeData) => {
28
+ await this.connection.rawConnection.getRepository(capjs_challenges_entity_1.CapjsChallenge).save({
29
+ token,
30
+ data: JSON.stringify(challengeData),
31
+ expires: challengeData.expires,
32
+ });
33
+ },
34
+ read: async (token) => {
35
+ const challenge = await this.connection.rawConnection
36
+ .getRepository(capjs_challenges_entity_1.CapjsChallenge)
37
+ .createQueryBuilder('challenge')
38
+ .where('challenge.token = :token', { token })
39
+ .andWhere('challenge.expires > :now', { now: Date.now() })
40
+ .getOne();
41
+ if (!challenge) {
42
+ return null;
43
+ }
44
+ return {
45
+ challenge: JSON.parse(challenge.data),
46
+ expires: challenge.expires,
47
+ };
48
+ },
49
+ delete: async (token) => {
50
+ await this.connection.rawConnection.getRepository(capjs_challenges_entity_1.CapjsChallenge).delete({ token });
51
+ },
52
+ deleteExpired: async () => {
53
+ await this.connection.rawConnection
54
+ .getRepository(capjs_challenges_entity_1.CapjsChallenge)
55
+ .createQueryBuilder()
56
+ .delete()
57
+ .where('expires <= :now', { now: Date.now() })
58
+ .execute();
59
+ },
60
+ },
61
+ tokens: {
62
+ store: async (tokenKey, expires) => {
63
+ await this.connection.rawConnection.getRepository(capjs_token_entity_1.CapjsToken).save({
64
+ key: tokenKey,
65
+ expires,
66
+ });
67
+ },
68
+ get: async (tokenKey) => {
69
+ const token = await this.connection.rawConnection
70
+ .getRepository(capjs_token_entity_1.CapjsToken)
71
+ .createQueryBuilder('token')
72
+ .where('token.key = :key', { key: tokenKey })
73
+ .andWhere('token.expires > :now', { now: Date.now() })
74
+ .getOne();
75
+ if (!token) {
76
+ return null;
77
+ }
78
+ return token.expires;
79
+ },
80
+ delete: async (tokenKey) => {
81
+ await this.connection.rawConnection
82
+ .getRepository(capjs_token_entity_1.CapjsToken)
83
+ .delete({ key: tokenKey });
84
+ },
85
+ deleteExpired: async () => {
86
+ await this.connection.rawConnection
87
+ .getRepository(capjs_token_entity_1.CapjsToken)
88
+ .createQueryBuilder()
89
+ .delete()
90
+ .where('expires <= :now', { now: Date.now() })
91
+ .execute();
92
+ },
93
+ },
94
+ },
95
+ });
96
+ }
97
+ createChallenge() {
98
+ return this.cap.createChallenge();
99
+ }
100
+ redeemChallenge(token, solutions) {
101
+ return this.cap.redeemChallenge({ token, solutions });
102
+ }
103
+ validateToken(token) {
104
+ return this.cap.validateToken(token);
105
+ }
106
+ cleanup() {
107
+ return this.cap.cleanup();
108
+ }
109
+ };
110
+ exports.CapjsService = CapjsService;
111
+ exports.CapjsService = CapjsService = __decorate([
112
+ (0, common_1.Injectable)(),
113
+ __metadata("design:paramtypes", [core_1.TransactionalConnection])
114
+ ], CapjsService);
115
+ //# sourceMappingURL=capjs.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capjs.service.js","sourceRoot":"","sources":["../../../src/services/capjs.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4DAAiC;AACjC,2CAA4C;AAC5C,wCAAwD;AAExD,iFAAqE;AACrE,uEAA4D;AAGrD,IAAM,YAAY,GAAlB,MAAM,YAAY;IAGrB,YAAoB,UAAmC;QAAnC,eAAU,GAAV,UAAU,CAAyB;QACnD,IAAI,CAAC,GAAG,GAAG,IAAI,gBAAG,CAAC;YACf,OAAO,EAAE;gBACL,UAAU,EAAE;oBACR,KAAK,EAAE,KAAK,EAAE,KAAa,EAAE,aAAkB,EAAE,EAAE;wBAC/C,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,aAAa,CAAC,wCAAc,CAAC,CAAC,IAAI,CAAC;4BACnE,KAAK;4BACL,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC;4BACnC,OAAO,EAAE,aAAa,CAAC,OAAO;yBACjC,CAAC,CAAC;oBACP,CAAC;oBACD,IAAI,EAAE,KAAK,EAAE,KAAa,EAAE,EAAE;wBAC1B,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa;6BAChD,aAAa,CAAC,wCAAc,CAAC;6BAC7B,kBAAkB,CAAC,WAAW,CAAC;6BAC/B,KAAK,CAAC,0BAA0B,EAAE,EAAE,KAAK,EAAE,CAAC;6BAC5C,QAAQ,CAAC,0BAA0B,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,YAAY;IADxB,IAAA,mBAAU,GAAE;qCAIuB,8BAAuB;GAH9C,YAAY,CAiGxB"}
@@ -0,0 +1,2 @@
1
+ export interface PluginInitOptions {
2
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "vendure-plugin-capjs",
3
+ "version": "0.0.1",
4
+ "license": "GPL-3.0-or-later",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib/**/*"
9
+ ],
10
+ "scripts": {
11
+ "watch": "tsc -p ./tsconfig.build.json --watch",
12
+ "build": "rimraf lib && tsc -p ./tsconfig.build.json",
13
+ "e2e": "cross-env PACKAGE=payments-plugin vitest --config ../../e2e-common/vitest.config.mts --run",
14
+ "e2e:watch": "cross-env PACKAGE=payments-plugin vitest --config ../../e2e-common/vitest.config.mts",
15
+ "ci": "npm run build",
16
+ "lint": "eslint .",
17
+ "test": "vitest --run"
18
+ },
19
+ "private": false,
20
+ "peerDependencies": {
21
+ "@cap.js/server": "^4.0.5",
22
+ "@google-cloud/pubsub": ">=4.0.0",
23
+ "@vendure/common": ">=3.0.0",
24
+ "@vendure/core": ">=3.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "@google-cloud/pubsub": "^4.11.0",
28
+ "@nestjs/testing": "^11.1.13",
29
+ "@types/supertest": "^6.0.3",
30
+ "@vendure/common": "^3.5.3",
31
+ "@vendure/core": "^3.5.3",
32
+ "@vendure/testing": "^3.5.3",
33
+ "rimraf": "^5.0.5",
34
+ "supertest": "^7.2.2",
35
+ "typescript": "5.8.2"
36
+ }
37
+ }