botbye-nest-core 0.1.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/botbye.constants.d.ts +4 -0
- package/botbye.constants.js +9 -0
- package/botbye.decodator.d.ts +2 -0
- package/botbye.decodator.js +9 -0
- package/botbye.middleware.d.ts +11 -0
- package/botbye.middleware.js +43 -0
- package/botbye.service.d.ts +11 -0
- package/botbye.service.js +43 -0
- package/botbye.types.d.ts +12 -0
- package/botbye.types.js +2 -0
- package/botbye.utils.d.ts +24 -0
- package/botbye.utils.js +27 -0
- package/index.d.ts +6 -0
- package/index.js +16 -0
- package/package.json +16 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const BOTBYE_MODULE_OPTIONS_DI_TOKEN = "BOTBYE_MODULE_OPTIONS_DI_TOKEN";
|
|
2
|
+
declare const BOTBYE_SERVICE_DI_TOKEN = "BOTBYE_SERVICE_DI_TOKEN";
|
|
3
|
+
declare const BOTBYE_MODULE_VALIDATE_REQUEST_DI_TOKEN = "BOTBYE_MODULE_VALIDATE_REQUEST_DI_TOKEN";
|
|
4
|
+
export { BOTBYE_MODULE_OPTIONS_DI_TOKEN, BOTBYE_SERVICE_DI_TOKEN, BOTBYE_MODULE_VALIDATE_REQUEST_DI_TOKEN, };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BOTBYE_MODULE_VALIDATE_REQUEST_DI_TOKEN = exports.BOTBYE_SERVICE_DI_TOKEN = exports.BOTBYE_MODULE_OPTIONS_DI_TOKEN = void 0;
|
|
4
|
+
const BOTBYE_MODULE_OPTIONS_DI_TOKEN = "BOTBYE_MODULE_OPTIONS_DI_TOKEN";
|
|
5
|
+
exports.BOTBYE_MODULE_OPTIONS_DI_TOKEN = BOTBYE_MODULE_OPTIONS_DI_TOKEN;
|
|
6
|
+
const BOTBYE_SERVICE_DI_TOKEN = "BOTBYE_SERVICE_DI_TOKEN";
|
|
7
|
+
exports.BOTBYE_SERVICE_DI_TOKEN = BOTBYE_SERVICE_DI_TOKEN;
|
|
8
|
+
const BOTBYE_MODULE_VALIDATE_REQUEST_DI_TOKEN = "BOTBYE_MODULE_VALIDATE_REQUEST_DI_TOKEN";
|
|
9
|
+
exports.BOTBYE_MODULE_VALIDATE_REQUEST_DI_TOKEN = BOTBYE_MODULE_VALIDATE_REQUEST_DI_TOKEN;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BotByeResponse = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const BotByeResponse = (0, common_1.createParamDecorator)((data, ctx) => {
|
|
6
|
+
const request = ctx.switchToHttp().getRequest();
|
|
7
|
+
return request.__botbye_response || (request.raw || {}).__botbye_response;
|
|
8
|
+
});
|
|
9
|
+
exports.BotByeResponse = BotByeResponse;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NestMiddleware } from "@nestjs/common";
|
|
2
|
+
import { IBotByeService } from "./botbye.types";
|
|
3
|
+
import { TBotByeResponse } from "botbye-node-core";
|
|
4
|
+
declare class BotByeMiddleware<T> implements NestMiddleware {
|
|
5
|
+
private botbyeService;
|
|
6
|
+
constructor(botbyeService: IBotByeService<T>);
|
|
7
|
+
use(request: T & {
|
|
8
|
+
__botbye_response: TBotByeResponse;
|
|
9
|
+
}, _: any, next: () => void): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export { BotByeMiddleware, };
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.BotByeMiddleware = void 0;
|
|
25
|
+
const common_1 = require("@nestjs/common");
|
|
26
|
+
const botbye_constants_1 = require("./botbye.constants");
|
|
27
|
+
let BotByeMiddleware = class BotByeMiddleware {
|
|
28
|
+
constructor(botbyeService) {
|
|
29
|
+
this.botbyeService = botbyeService;
|
|
30
|
+
}
|
|
31
|
+
use(request, _, next) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
request.__botbye_response = yield this.botbyeService.validate(request);
|
|
34
|
+
next();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.BotByeMiddleware = BotByeMiddleware;
|
|
39
|
+
exports.BotByeMiddleware = BotByeMiddleware = __decorate([
|
|
40
|
+
(0, common_1.Injectable)(),
|
|
41
|
+
__param(0, (0, common_1.Inject)(botbye_constants_1.BOTBYE_SERVICE_DI_TOKEN)),
|
|
42
|
+
__metadata("design:paramtypes", [Object])
|
|
43
|
+
], BotByeMiddleware);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import * as core from "botbye-node-core";
|
|
3
|
+
import { IBotByeService, TBotByeServiceOptions, TValidationFunction } from "./botbye.types";
|
|
4
|
+
declare class BotByeService<T> implements OnModuleInit, IBotByeService<T> {
|
|
5
|
+
private options;
|
|
6
|
+
private validateRequest;
|
|
7
|
+
constructor(options: TBotByeServiceOptions<T>, validateRequest: TValidationFunction<T>);
|
|
8
|
+
onModuleInit(): void;
|
|
9
|
+
validate(request: T): Promise<core.TBotByeResponse>;
|
|
10
|
+
}
|
|
11
|
+
export { BotByeService, };
|
|
@@ -0,0 +1,43 @@
|
|
|
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.BotByeService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const botbye_constants_1 = require("./botbye.constants");
|
|
18
|
+
const core = require("botbye-node-core");
|
|
19
|
+
core.initPackageInfo({ name: 'NodeJS-Nest-Express', version: '0.1.0' });
|
|
20
|
+
let BotByeService = class BotByeService {
|
|
21
|
+
constructor(options, validateRequest) {
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.validateRequest = validateRequest;
|
|
24
|
+
}
|
|
25
|
+
onModuleInit() {
|
|
26
|
+
core.init(this.options);
|
|
27
|
+
}
|
|
28
|
+
validate(request) {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
return this.validateRequest({
|
|
31
|
+
request,
|
|
32
|
+
token: this.options.tokenExtractor(request),
|
|
33
|
+
customFields: (_b = (_a = this.options).customFieldsExtractor) === null || _b === void 0 ? void 0 : _b.call(_a, request),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.BotByeService = BotByeService;
|
|
38
|
+
exports.BotByeService = BotByeService = __decorate([
|
|
39
|
+
(0, common_1.Injectable)(),
|
|
40
|
+
__param(0, (0, common_1.Inject)(botbye_constants_1.BOTBYE_MODULE_OPTIONS_DI_TOKEN)),
|
|
41
|
+
__param(1, (0, common_1.Inject)(botbye_constants_1.BOTBYE_MODULE_VALIDATE_REQUEST_DI_TOKEN)),
|
|
42
|
+
__metadata("design:paramtypes", [Object, Function])
|
|
43
|
+
], BotByeService);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TBotByeInitOptions, TBotByeResponse, TValidateRequestOptions } from "botbye-node-core";
|
|
2
|
+
interface IBotByeService<T> {
|
|
3
|
+
validate: (request: T) => Promise<TBotByeResponse>;
|
|
4
|
+
}
|
|
5
|
+
type TValidationFunction<T> = (options: Omit<TValidateRequestOptions, "requestInfo" | "headers"> & {
|
|
6
|
+
request: T;
|
|
7
|
+
}) => Promise<TBotByeResponse>;
|
|
8
|
+
type TBotByeServiceOptions<T> = TBotByeInitOptions & {
|
|
9
|
+
tokenExtractor: (request: T) => string;
|
|
10
|
+
customFieldsExtractor?: (request: T) => Record<string, string>;
|
|
11
|
+
};
|
|
12
|
+
export { IBotByeService, TValidationFunction, TBotByeServiceOptions, };
|
package/botbye.types.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TBotByeServiceOptions, TValidationFunction } from "./botbye.types";
|
|
2
|
+
import { BotByeService } from "./botbye.service";
|
|
3
|
+
declare const getProvidersList: <T>(options: TBotByeServiceOptions<T>, validateRequest: TValidationFunction<T>) => ({
|
|
4
|
+
provide: string;
|
|
5
|
+
useClass: {
|
|
6
|
+
new (options: TBotByeServiceOptions<T>, validateRequest: TValidationFunction<T>): BotByeService<T>;
|
|
7
|
+
};
|
|
8
|
+
useValue?: undefined;
|
|
9
|
+
} | {
|
|
10
|
+
provide: string;
|
|
11
|
+
useValue: TValidationFunction<T>;
|
|
12
|
+
useClass?: undefined;
|
|
13
|
+
} | {
|
|
14
|
+
provide: string;
|
|
15
|
+
useValue: TBotByeServiceOptions<T>;
|
|
16
|
+
useClass?: undefined;
|
|
17
|
+
})[];
|
|
18
|
+
declare const getExports: <T>() => {
|
|
19
|
+
provide: string;
|
|
20
|
+
useClass: {
|
|
21
|
+
new (options: TBotByeServiceOptions<T>, validateRequest: TValidationFunction<T>): BotByeService<T>;
|
|
22
|
+
};
|
|
23
|
+
}[];
|
|
24
|
+
export { getProvidersList, getExports, };
|
package/botbye.utils.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getExports = exports.getProvidersList = void 0;
|
|
4
|
+
const botbye_constants_1 = require("./botbye.constants");
|
|
5
|
+
const botbye_service_1 = require("./botbye.service");
|
|
6
|
+
const getProvidersList = (options, validateRequest) => [
|
|
7
|
+
{
|
|
8
|
+
provide: botbye_constants_1.BOTBYE_SERVICE_DI_TOKEN,
|
|
9
|
+
useClass: (botbye_service_1.BotByeService),
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
provide: botbye_constants_1.BOTBYE_MODULE_VALIDATE_REQUEST_DI_TOKEN,
|
|
13
|
+
useValue: validateRequest,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
provide: botbye_constants_1.BOTBYE_MODULE_OPTIONS_DI_TOKEN,
|
|
17
|
+
useValue: options,
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
exports.getProvidersList = getProvidersList;
|
|
21
|
+
const getExports = () => [
|
|
22
|
+
{
|
|
23
|
+
provide: botbye_constants_1.BOTBYE_SERVICE_DI_TOKEN,
|
|
24
|
+
useClass: (botbye_service_1.BotByeService),
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
exports.getExports = getExports;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { BOTBYE_MODULE_OPTIONS_DI_TOKEN, BOTBYE_MODULE_VALIDATE_REQUEST_DI_TOKEN, BOTBYE_SERVICE_DI_TOKEN, } from "./botbye.constants";
|
|
2
|
+
export { BotByeResponse } from "./botbye.decodator";
|
|
3
|
+
export { IBotByeService, TValidationFunction, TBotByeServiceOptions } from "./botbye.types";
|
|
4
|
+
export { BotByeMiddleware } from "./botbye.middleware";
|
|
5
|
+
export { BotByeService } from "./botbye.service";
|
|
6
|
+
export { getProvidersList, getExports } from "./botbye.utils";
|
package/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getExports = exports.getProvidersList = exports.BotByeService = exports.BotByeMiddleware = exports.BotByeResponse = exports.BOTBYE_SERVICE_DI_TOKEN = exports.BOTBYE_MODULE_VALIDATE_REQUEST_DI_TOKEN = exports.BOTBYE_MODULE_OPTIONS_DI_TOKEN = void 0;
|
|
4
|
+
var botbye_constants_1 = require("./botbye.constants");
|
|
5
|
+
Object.defineProperty(exports, "BOTBYE_MODULE_OPTIONS_DI_TOKEN", { enumerable: true, get: function () { return botbye_constants_1.BOTBYE_MODULE_OPTIONS_DI_TOKEN; } });
|
|
6
|
+
Object.defineProperty(exports, "BOTBYE_MODULE_VALIDATE_REQUEST_DI_TOKEN", { enumerable: true, get: function () { return botbye_constants_1.BOTBYE_MODULE_VALIDATE_REQUEST_DI_TOKEN; } });
|
|
7
|
+
Object.defineProperty(exports, "BOTBYE_SERVICE_DI_TOKEN", { enumerable: true, get: function () { return botbye_constants_1.BOTBYE_SERVICE_DI_TOKEN; } });
|
|
8
|
+
var botbye_decodator_1 = require("./botbye.decodator");
|
|
9
|
+
Object.defineProperty(exports, "BotByeResponse", { enumerable: true, get: function () { return botbye_decodator_1.BotByeResponse; } });
|
|
10
|
+
var botbye_middleware_1 = require("./botbye.middleware");
|
|
11
|
+
Object.defineProperty(exports, "BotByeMiddleware", { enumerable: true, get: function () { return botbye_middleware_1.BotByeMiddleware; } });
|
|
12
|
+
var botbye_service_1 = require("./botbye.service");
|
|
13
|
+
Object.defineProperty(exports, "BotByeService", { enumerable: true, get: function () { return botbye_service_1.BotByeService; } });
|
|
14
|
+
var botbye_utils_1 = require("./botbye.utils");
|
|
15
|
+
Object.defineProperty(exports, "getProvidersList", { enumerable: true, get: function () { return botbye_utils_1.getProvidersList; } });
|
|
16
|
+
Object.defineProperty(exports, "getExports", { enumerable: true, get: function () { return botbye_utils_1.getExports; } });
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "botbye-nest-core",
|
|
3
|
+
"main": "index.js",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "BotBye! Core integration for NestJS",
|
|
6
|
+
"private": false,
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"@nestjs/common": "^11.0.0"
|
|
9
|
+
},
|
|
10
|
+
"peerDependencies": {
|
|
11
|
+
"@nestjs/common": "^11.0.0"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"botbye-node-core": "^1.0.5"
|
|
15
|
+
}
|
|
16
|
+
}
|