apitally 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/LICENSE +21 -0
- package/README.md +136 -0
- package/dist/common/client.d.ts +37 -0
- package/dist/common/client.d.ts.map +1 -0
- package/dist/common/client.js +243 -0
- package/dist/common/client.js.map +1 -0
- package/dist/common/index.d.ts +2 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +6 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/keyRegistry.d.ts +29 -0
- package/dist/common/keyRegistry.d.ts.map +1 -0
- package/dist/common/keyRegistry.js +90 -0
- package/dist/common/keyRegistry.js.map +1 -0
- package/dist/common/logging.d.ts +8 -0
- package/dist/common/logging.d.ts.map +1 -0
- package/dist/common/logging.js +13 -0
- package/dist/common/logging.js.map +1 -0
- package/dist/common/requestLogger.d.ts +10 -0
- package/dist/common/requestLogger.d.ts.map +1 -0
- package/dist/common/requestLogger.js +49 -0
- package/dist/common/requestLogger.js.map +1 -0
- package/dist/common/types.d.ts +56 -0
- package/dist/common/types.d.ts.map +1 -0
- package/dist/common/types.js +3 -0
- package/dist/common/types.js.map +1 -0
- package/dist/common/utils.d.ts +4 -0
- package/dist/common/utils.d.ts.map +1 -0
- package/dist/common/utils.js +23 -0
- package/dist/common/utils.js.map +1 -0
- package/dist/common/validationErrorLogger.d.ts +9 -0
- package/dist/common/validationErrorLogger.d.ts.map +1 -0
- package/dist/common/validationErrorLogger.js +40 -0
- package/dist/common/validationErrorLogger.js.map +1 -0
- package/dist/express/auth.d.ts +6 -0
- package/dist/express/auth.d.ts.map +1 -0
- package/dist/express/auth.js +66 -0
- package/dist/express/auth.js.map +1 -0
- package/dist/express/index.d.ts +3 -0
- package/dist/express/index.d.ts.map +1 -0
- package/dist/express/index.js +8 -0
- package/dist/express/index.js.map +1 -0
- package/dist/express/listEndpoints.d.ts +3 -0
- package/dist/express/listEndpoints.d.ts.map +1 -0
- package/dist/express/listEndpoints.js +166 -0
- package/dist/express/listEndpoints.js.map +1 -0
- package/dist/express/middleware.d.ts +4 -0
- package/dist/express/middleware.d.ts.map +1 -0
- package/dist/express/middleware.js +164 -0
- package/dist/express/middleware.js.map +1 -0
- package/dist/fastify/auth.d.ts +6 -0
- package/dist/fastify/auth.d.ts.map +1 -0
- package/dist/fastify/auth.js +66 -0
- package/dist/fastify/auth.js.map +1 -0
- package/dist/fastify/index.d.ts +3 -0
- package/dist/fastify/index.d.ts.map +1 -0
- package/dist/fastify/index.js +11 -0
- package/dist/fastify/index.js.map +1 -0
- package/dist/fastify/plugin.d.ts +16 -0
- package/dist/fastify/plugin.d.ts.map +1 -0
- package/dist/fastify/plugin.js +122 -0
- package/dist/fastify/plugin.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/koa/auth.d.ts +6 -0
- package/dist/koa/auth.d.ts.map +1 -0
- package/dist/koa/auth.js +67 -0
- package/dist/koa/auth.js.map +1 -0
- package/dist/koa/index.d.ts +3 -0
- package/dist/koa/index.d.ts.map +1 -0
- package/dist/koa/index.js +8 -0
- package/dist/koa/index.js.map +1 -0
- package/dist/koa/middleware.d.ts +4 -0
- package/dist/koa/middleware.d.ts.map +1 -0
- package/dist/koa/middleware.js +108 -0
- package/dist/koa/middleware.js.map +1 -0
- package/dist/nestjs/auth.d.ts +10 -0
- package/dist/nestjs/auth.d.ts.map +1 -0
- package/dist/nestjs/auth.js +84 -0
- package/dist/nestjs/auth.js.map +1 -0
- package/dist/nestjs/index.d.ts +3 -0
- package/dist/nestjs/index.d.ts.map +1 -0
- package/dist/nestjs/index.js +9 -0
- package/dist/nestjs/index.js.map +1 -0
- package/package.json +128 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.useApitally = void 0;
|
|
13
|
+
const client_1 = require("../common/client");
|
|
14
|
+
const keyRegistry_1 = require("../common/keyRegistry");
|
|
15
|
+
const utils_1 = require("../common/utils");
|
|
16
|
+
const useApitally = (app, config) => {
|
|
17
|
+
const client = new client_1.ApitallyClient(config);
|
|
18
|
+
const middleware = getMiddleware(client);
|
|
19
|
+
app.use(middleware);
|
|
20
|
+
setTimeout(() => {
|
|
21
|
+
client.setAppInfo(getAppInfo(app, config.appVersion));
|
|
22
|
+
}, 100);
|
|
23
|
+
};
|
|
24
|
+
exports.useApitally = useApitally;
|
|
25
|
+
const getMiddleware = (client) => {
|
|
26
|
+
return (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const startTime = performance.now();
|
|
28
|
+
let statusCode;
|
|
29
|
+
try {
|
|
30
|
+
yield next();
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
statusCode = error.statusCode || error.status || 500;
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
try {
|
|
38
|
+
// _matchedRoute is set by koa-router, routePath is set by koa-route
|
|
39
|
+
if (ctx._matchedRoute || ctx.routePath) {
|
|
40
|
+
client.requestLogger.logRequest({
|
|
41
|
+
consumer: getConsumer(ctx),
|
|
42
|
+
method: ctx.request.method,
|
|
43
|
+
path: ctx._matchedRoute || ctx.routePath,
|
|
44
|
+
statusCode: statusCode || ctx.response.status,
|
|
45
|
+
responseTime: performance.now() - startTime,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
client.logger.error("Error while logging request in Apitally middleware.", { context: ctx, error });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
const getConsumer = (ctx) => {
|
|
56
|
+
if (ctx.state.consumerIdentifier) {
|
|
57
|
+
return String(ctx.state.consumerIdentifier);
|
|
58
|
+
}
|
|
59
|
+
if (ctx.state.keyInfo && ctx.state.keyInfo instanceof keyRegistry_1.KeyInfo) {
|
|
60
|
+
return `key:${ctx.state.keyInfo.keyId}`;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
};
|
|
64
|
+
const getAppInfo = (app, appVersion) => {
|
|
65
|
+
const versions = [["nodejs", process.version]];
|
|
66
|
+
const koaVersion = (0, utils_1.getPackageVersion)("koa");
|
|
67
|
+
const apitallyVersion = (0, utils_1.getPackageVersion)("../..");
|
|
68
|
+
if (koaVersion) {
|
|
69
|
+
versions.push(["koa", koaVersion]);
|
|
70
|
+
}
|
|
71
|
+
if (apitallyVersion) {
|
|
72
|
+
versions.push(["apitally", apitallyVersion]);
|
|
73
|
+
}
|
|
74
|
+
if (appVersion) {
|
|
75
|
+
versions.push(["app", appVersion]);
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
paths: listEndpoints(app),
|
|
79
|
+
versions: new Map(versions),
|
|
80
|
+
client: "js:koa",
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
const isKoaRouterMiddleware = (middleware) => {
|
|
84
|
+
return (typeof middleware === "function" &&
|
|
85
|
+
middleware.router &&
|
|
86
|
+
Array.isArray(middleware.router.stack));
|
|
87
|
+
};
|
|
88
|
+
const listEndpoints = (app) => {
|
|
89
|
+
const endpoints = [];
|
|
90
|
+
app.middleware.forEach((middleware) => {
|
|
91
|
+
if (isKoaRouterMiddleware(middleware)) {
|
|
92
|
+
middleware.router.stack.forEach((layer) => {
|
|
93
|
+
if (layer.methods && layer.methods.length > 0) {
|
|
94
|
+
layer.methods.forEach((method) => {
|
|
95
|
+
if (method.toUpperCase() !== "HEAD") {
|
|
96
|
+
endpoints.push({
|
|
97
|
+
method: method.toUpperCase(),
|
|
98
|
+
path: layer.path,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
return endpoints;
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/koa/middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,6CAAkD;AAClD,uDAAgD;AAEhD,2CAAoD;AAE7C,MAAM,WAAW,GAAG,CAAC,GAAQ,EAAE,MAAsB,EAAE,EAAE;IAC9D,MAAM,MAAM,GAAG,IAAI,uBAAc,CAAC,MAAM,CAAC,CAAC;IAC1C,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACzC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACpB,UAAU,CAAC,GAAG,EAAE;QACd,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IACxD,CAAC,EAAE,GAAG,CAAC,CAAC;AACV,CAAC,CAAC;AAPW,QAAA,WAAW,eAOtB;AAEF,MAAM,aAAa,GAAG,CAAC,MAAsB,EAAE,EAAE;IAC/C,OAAO,CAAO,GAAgB,EAAE,IAAc,EAAE,EAAE;QAChD,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QACpC,IAAI,UAA8B,CAAC;QACnC,IAAI;YACF,MAAM,IAAI,EAAE,CAAC;SACd;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C,EAAE;oBAC7C,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAc,EAAE,EAAE;wBACvC,IAAI,MAAM,CAAC,WAAW,EAAE,KAAK,MAAM,EAAE;4BACnC,SAAS,CAAC,IAAI,CAAC;gCACb,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE;gCAC5B,IAAI,EAAE,KAAK,CAAC,IAAI;6BACjB,CAAC,CAAC;yBACJ;oBACH,CAAC,CAAC,CAAC;iBACJ;YACH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from "@nestjs/common";
|
|
2
|
+
import { Reflector } from "@nestjs/core";
|
|
3
|
+
export declare const Scopes: (...scopes: string[]) => import("@nestjs/common").CustomDecorator<string>;
|
|
4
|
+
export declare class ApitallyApiKeyGuard implements CanActivate {
|
|
5
|
+
private reflector;
|
|
6
|
+
static customHeader?: string;
|
|
7
|
+
constructor(reflector: Reflector);
|
|
8
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/nestjs/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAKjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAKzC,eAAO,MAAM,MAAM,cAAe,MAAM,EAAE,qDAAkC,CAAC;AAE7E,qBACa,mBAAoB,YAAW,WAAW;IAGzC,OAAO,CAAC,SAAS;IAF7B,OAAc,YAAY,CAAC,EAAE,MAAM,CAAC;gBAEhB,SAAS,EAAE,SAAS;IAElC,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CA+C/D"}
|
|
@@ -0,0 +1,84 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
var ApitallyApiKeyGuard_1;
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.ApitallyApiKeyGuard = exports.Scopes = void 0;
|
|
23
|
+
const common_1 = require("@nestjs/common");
|
|
24
|
+
const core_1 = require("@nestjs/core");
|
|
25
|
+
const client_1 = require("../common/client");
|
|
26
|
+
const Scopes = (...scopes) => (0, common_1.SetMetadata)("scopes", scopes);
|
|
27
|
+
exports.Scopes = Scopes;
|
|
28
|
+
let ApitallyApiKeyGuard = ApitallyApiKeyGuard_1 = class ApitallyApiKeyGuard {
|
|
29
|
+
constructor(reflector) {
|
|
30
|
+
this.reflector = reflector;
|
|
31
|
+
}
|
|
32
|
+
canActivate(context) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const customHeader = ApitallyApiKeyGuard_1.customHeader;
|
|
35
|
+
const req = context.switchToHttp().getRequest();
|
|
36
|
+
const res = context.switchToHttp().getResponse();
|
|
37
|
+
let apiKey;
|
|
38
|
+
if (!customHeader) {
|
|
39
|
+
if (!req.headers.authorization) {
|
|
40
|
+
res.set("WWW-Authenticate", "ApiKey");
|
|
41
|
+
throw new common_1.UnauthorizedException("Missing authorization header");
|
|
42
|
+
}
|
|
43
|
+
const authorizationParts = req.headers.authorization.split(" ");
|
|
44
|
+
if (authorizationParts.length === 2 &&
|
|
45
|
+
authorizationParts[0].toLowerCase() === "apikey") {
|
|
46
|
+
apiKey = authorizationParts[1];
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
res.set("WWW-Authenticate", "ApiKey");
|
|
50
|
+
throw new common_1.UnauthorizedException("Invalid authorization scheme");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (customHeader) {
|
|
54
|
+
const customHeaderValue = req.headers[customHeader.toLowerCase()];
|
|
55
|
+
if (typeof customHeaderValue === "string") {
|
|
56
|
+
apiKey = customHeaderValue;
|
|
57
|
+
}
|
|
58
|
+
else if (Array.isArray(customHeaderValue)) {
|
|
59
|
+
apiKey = customHeaderValue[0];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (!apiKey) {
|
|
63
|
+
throw new common_1.ForbiddenException("Missing API key");
|
|
64
|
+
}
|
|
65
|
+
const client = client_1.ApitallyClient.getInstance();
|
|
66
|
+
const keyInfo = yield client.keyRegistry.get(apiKey);
|
|
67
|
+
if (!keyInfo) {
|
|
68
|
+
throw new common_1.ForbiddenException("Invalid API key");
|
|
69
|
+
}
|
|
70
|
+
const scopes = this.reflector.get("scopes", context.getHandler());
|
|
71
|
+
if (scopes && !keyInfo.hasScopes(scopes)) {
|
|
72
|
+
throw new common_1.ForbiddenException("Permission denied");
|
|
73
|
+
}
|
|
74
|
+
res.locals.keyInfo = keyInfo;
|
|
75
|
+
return true;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
exports.ApitallyApiKeyGuard = ApitallyApiKeyGuard;
|
|
80
|
+
exports.ApitallyApiKeyGuard = ApitallyApiKeyGuard = ApitallyApiKeyGuard_1 = __decorate([
|
|
81
|
+
(0, common_1.Injectable)(),
|
|
82
|
+
__metadata("design:paramtypes", [core_1.Reflector])
|
|
83
|
+
], ApitallyApiKeyGuard);
|
|
84
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/nestjs/auth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,2CAOwB;AACxB,uCAAyC;AAGzC,6CAAkD;AAE3C,MAAM,MAAM,GAAG,CAAC,GAAG,MAAgB,EAAE,EAAE,CAAC,IAAA,oBAAW,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAAhE,QAAA,MAAM,UAA0D;AAGtE,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAG9B,YAAoB,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAEtC,WAAW,CAAC,OAAyB;;YACzC,MAAM,YAAY,GAAG,qBAAmB,CAAC,YAAY,CAAC;YACtD,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAW,CAAC;YACzD,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,WAAW,EAAY,CAAC;YAC3D,IAAI,MAA0B,CAAC;YAE/B,IAAI,CAA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,CAAC;aACjD;YACD,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAW,QAAQ,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;YAC5E,IAAI,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;gBACxC,MAAM,IAAI,2BAAkB,CAAC,mBAAmB,CAAC,CAAC;aACnD;YAED,GAAG,CAAC,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;YAC7B,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;CACF,CAAA;AApDY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;qCAIoB,gBAAS;GAH7B,mBAAmB,CAoD/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nestjs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Scopes = exports.ApitallyApiKeyGuard = exports.useApitally = void 0;
|
|
4
|
+
var express_1 = require("../express");
|
|
5
|
+
Object.defineProperty(exports, "useApitally", { enumerable: true, get: function () { return express_1.useApitally; } });
|
|
6
|
+
var auth_1 = require("./auth");
|
|
7
|
+
Object.defineProperty(exports, "ApitallyApiKeyGuard", { enumerable: true, get: function () { return auth_1.ApitallyApiKeyGuard; } });
|
|
8
|
+
Object.defineProperty(exports, "Scopes", { enumerable: true, get: function () { return auth_1.Scopes; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nestjs/index.ts"],"names":[],"mappings":";;;AAAA,sCAAyC;AAAhC,sGAAA,WAAW,OAAA;AACpB,+BAAqD;AAA5C,2GAAA,mBAAmB,OAAA;AAAE,8FAAA,MAAM,OAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "apitally",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Apitally client library for Node.js",
|
|
5
|
+
"author": "Apitally <hello@apitally.io>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+ssh://git@github.com/apitally/nodejs-client.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/apitally/nodejs-client/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://apitally.io",
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"format": "prettier --write .",
|
|
19
|
+
"check": "tsc --noEmit && eslint src && prettier --check .",
|
|
20
|
+
"test": "jest"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist/**/*",
|
|
24
|
+
"!dist/tests/",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"eslintConfig": {
|
|
29
|
+
"parser": "@typescript-eslint/parser",
|
|
30
|
+
"extends": [
|
|
31
|
+
"eslint:recommended",
|
|
32
|
+
"plugin:@typescript-eslint/recommended"
|
|
33
|
+
],
|
|
34
|
+
"plugins": [
|
|
35
|
+
"@typescript-eslint"
|
|
36
|
+
],
|
|
37
|
+
"rules": {
|
|
38
|
+
"@typescript-eslint/no-explicit-any": "off"
|
|
39
|
+
},
|
|
40
|
+
"env": {
|
|
41
|
+
"node": true
|
|
42
|
+
},
|
|
43
|
+
"root": true
|
|
44
|
+
},
|
|
45
|
+
"jest": {
|
|
46
|
+
"preset": "ts-jest",
|
|
47
|
+
"testEnvironment": "node",
|
|
48
|
+
"coverageReporters": [
|
|
49
|
+
"text",
|
|
50
|
+
"lcovonly"
|
|
51
|
+
],
|
|
52
|
+
"collectCoverageFrom": [
|
|
53
|
+
"src/**/*"
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"axios": "^1",
|
|
58
|
+
"axios-retry": "^3",
|
|
59
|
+
"winston": "^3"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@nestjs/common": "^8 || ^9 || ^10",
|
|
63
|
+
"@nestjs/core": "^8 || ^9 || ^10",
|
|
64
|
+
"@nestjs/platform-express": "^8 || ^9 || ^10",
|
|
65
|
+
"express": "^4",
|
|
66
|
+
"fastify": "^3 || ^4",
|
|
67
|
+
"fastify-plugin": "^3 || ^4",
|
|
68
|
+
"koa": "^2"
|
|
69
|
+
},
|
|
70
|
+
"peerDependenciesMeta": {
|
|
71
|
+
"@nestjs/common": {
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
"@nestjs/core": {
|
|
75
|
+
"optional": true
|
|
76
|
+
},
|
|
77
|
+
"@nestjs/platform-express": {
|
|
78
|
+
"optional": true
|
|
79
|
+
},
|
|
80
|
+
"express": {
|
|
81
|
+
"optional": true
|
|
82
|
+
},
|
|
83
|
+
"fastify": {
|
|
84
|
+
"optional": true
|
|
85
|
+
},
|
|
86
|
+
"fastify-plugin": {
|
|
87
|
+
"optional": true
|
|
88
|
+
},
|
|
89
|
+
"koa": {
|
|
90
|
+
"optional": true
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"devDependencies": {
|
|
94
|
+
"@koa/router": "^12.0.1",
|
|
95
|
+
"@nestjs/common": "^10.2.9",
|
|
96
|
+
"@nestjs/core": "^10.2.9",
|
|
97
|
+
"@nestjs/platform-express": "^10.2.9",
|
|
98
|
+
"@nestjs/testing": "^10.2.9",
|
|
99
|
+
"@types/express": "^4.17.21",
|
|
100
|
+
"@types/jest": "^29.5.8",
|
|
101
|
+
"@types/koa": "^2.13.11",
|
|
102
|
+
"@types/koa__router": "^12.0.4",
|
|
103
|
+
"@types/koa-route": "^3.2.8",
|
|
104
|
+
"@types/node": "^20.9.0",
|
|
105
|
+
"@types/supertest": "^2.0.16",
|
|
106
|
+
"@typescript-eslint/eslint-plugin": "^6.11.0",
|
|
107
|
+
"@typescript-eslint/parser": "^6.11.0",
|
|
108
|
+
"celebrate": "^15.0.3",
|
|
109
|
+
"class-transformer": "^0.5.1",
|
|
110
|
+
"class-validator": "^0.14.0",
|
|
111
|
+
"eslint": "^8.54.0",
|
|
112
|
+
"express": "^4.18.2",
|
|
113
|
+
"express-validator": "^7.0.1",
|
|
114
|
+
"fastify": "^4.24.3",
|
|
115
|
+
"fastify-plugin": "^4.5.1",
|
|
116
|
+
"install": "^0.13.0",
|
|
117
|
+
"jest": "^29.7.0",
|
|
118
|
+
"koa": "^2.14.2",
|
|
119
|
+
"koa-route": "^3.2.0",
|
|
120
|
+
"nock": "^13.3.8",
|
|
121
|
+
"npm": "^10.2.4",
|
|
122
|
+
"prettier": "^3.1.0",
|
|
123
|
+
"supertest": "^6.3.3",
|
|
124
|
+
"ts-jest": "^29.1.1",
|
|
125
|
+
"ts-node": "^10.9.1",
|
|
126
|
+
"typescript": "^5.2.2"
|
|
127
|
+
}
|
|
128
|
+
}
|