apitally 0.1.1 → 0.1.3
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/lib/cjs/common/client.js +395 -0
- package/lib/cjs/common/client.js.map +1 -0
- package/lib/cjs/common/index.js +13 -0
- package/lib/cjs/common/index.js.map +1 -0
- package/lib/cjs/common/keyRegistry.js +162 -0
- package/lib/cjs/common/keyRegistry.js.map +1 -0
- package/lib/cjs/common/logging.js +17 -0
- package/lib/cjs/common/logging.js.map +1 -0
- package/lib/cjs/common/requestLogger.js +69 -0
- package/lib/cjs/common/requestLogger.js.map +1 -0
- package/lib/cjs/common/types.js +6 -0
- package/lib/cjs/common/types.js.map +1 -0
- package/lib/cjs/common/utils.js +24 -0
- package/lib/cjs/common/utils.js.map +1 -0
- package/lib/cjs/common/validationErrorLogger.js +58 -0
- package/lib/cjs/common/validationErrorLogger.js.map +1 -0
- package/lib/cjs/express/auth.js +105 -0
- package/lib/cjs/express/auth.js.map +1 -0
- package/lib/cjs/express/index.js +27 -0
- package/lib/cjs/express/index.js.map +1 -0
- package/lib/cjs/express/listEndpoints.js +175 -0
- package/lib/cjs/express/listEndpoints.js.map +1 -0
- package/lib/cjs/express/middleware.js +167 -0
- package/lib/cjs/express/middleware.js.map +1 -0
- package/lib/cjs/fastify/auth.js +105 -0
- package/lib/cjs/fastify/auth.js.map +1 -0
- package/lib/cjs/fastify/index.js +28 -0
- package/lib/cjs/fastify/index.js.map +1 -0
- package/lib/cjs/fastify/plugin.js +147 -0
- package/lib/cjs/fastify/plugin.js.map +1 -0
- package/lib/cjs/index.js +6 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/koa/auth.js +113 -0
- package/lib/cjs/koa/auth.js.map +1 -0
- package/lib/cjs/koa/index.js +27 -0
- package/lib/cjs/koa/index.js.map +1 -0
- package/lib/cjs/koa/middleware.js +122 -0
- package/lib/cjs/koa/middleware.js.map +1 -0
- package/lib/cjs/nestjs/auth.js +132 -0
- package/lib/cjs/nestjs/auth.js.map +1 -0
- package/lib/cjs/nestjs/index.js +39 -0
- package/lib/cjs/nestjs/index.js.map +1 -0
- package/lib/esm/common/client.js +385 -0
- package/lib/esm/common/client.js.map +1 -0
- package/lib/esm/common/index.js +1 -0
- package/lib/esm/common/index.js.map +1 -0
- package/lib/esm/common/keyRegistry.js +155 -0
- package/lib/esm/common/keyRegistry.js.map +1 -0
- package/lib/esm/common/logging.js +11 -0
- package/lib/esm/common/logging.js.map +1 -0
- package/lib/esm/common/requestLogger.js +63 -0
- package/lib/esm/common/requestLogger.js.map +1 -0
- package/lib/esm/common/types.js +1 -0
- package/lib/esm/common/types.js.map +1 -0
- package/lib/esm/common/utils.js +16 -0
- package/lib/esm/common/utils.js.map +1 -0
- package/lib/esm/common/validationErrorLogger.js +52 -0
- package/lib/esm/common/validationErrorLogger.js.map +1 -0
- package/lib/esm/express/auth.js +98 -0
- package/lib/esm/express/auth.js.map +1 -0
- package/lib/esm/express/index.js +4 -0
- package/lib/esm/express/index.js.map +1 -0
- package/lib/esm/express/listEndpoints.js +168 -0
- package/lib/esm/express/listEndpoints.js.map +1 -0
- package/lib/esm/express/middleware.js +160 -0
- package/lib/esm/express/middleware.js.map +1 -0
- package/lib/esm/fastify/auth.js +98 -0
- package/lib/esm/fastify/auth.js.map +1 -0
- package/lib/esm/fastify/index.js +4 -0
- package/lib/esm/fastify/index.js.map +1 -0
- package/lib/esm/fastify/plugin.js +140 -0
- package/lib/esm/fastify/plugin.js.map +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/koa/auth.js +106 -0
- package/lib/esm/koa/auth.js.map +1 -0
- package/lib/esm/koa/index.js +4 -0
- package/lib/esm/koa/index.js.map +1 -0
- package/lib/esm/koa/middleware.js +115 -0
- package/lib/esm/koa/middleware.js.map +1 -0
- package/lib/esm/nestjs/auth.js +126 -0
- package/lib/esm/nestjs/auth.js.map +1 -0
- package/lib/esm/nestjs/index.js +4 -0
- package/lib/esm/nestjs/index.js.map +1 -0
- package/{dist/src → lib/types}/common/client.d.ts +7 -6
- package/lib/types/common/client.d.ts.map +1 -0
- package/lib/types/common/index.d.ts +2 -0
- package/{dist/src → lib/types}/common/index.d.ts.map +1 -1
- package/{dist/src → lib/types}/common/requestLogger.d.ts +1 -1
- package/{dist/src → lib/types}/common/requestLogger.d.ts.map +1 -1
- package/{dist/src → lib/types}/common/types.d.ts +2 -2
- package/lib/types/common/types.d.ts.map +1 -0
- package/{dist/src → lib/types}/common/validationErrorLogger.d.ts +1 -1
- package/{dist/src → lib/types}/common/validationErrorLogger.d.ts.map +1 -1
- package/{dist/src → lib/types}/express/auth.d.ts +1 -1
- package/lib/types/express/auth.d.ts.map +1 -0
- package/lib/types/express/index.d.ts +4 -0
- package/{dist/src → lib/types}/express/index.d.ts.map +1 -1
- package/lib/types/express/listEndpoints.d.ts +3 -0
- package/{dist/src → lib/types}/express/middleware.d.ts +3 -3
- package/lib/types/express/middleware.d.ts.map +1 -0
- package/{dist/src → lib/types}/fastify/auth.d.ts +1 -1
- package/lib/types/fastify/auth.d.ts.map +1 -0
- package/lib/types/fastify/index.d.ts +4 -0
- package/{dist/src → lib/types}/fastify/index.d.ts.map +1 -1
- package/lib/types/fastify/plugin.d.ts +15 -0
- package/lib/types/fastify/plugin.d.ts.map +1 -0
- package/lib/types/koa/index.d.ts +4 -0
- package/{dist/src → lib/types}/koa/index.d.ts.map +1 -1
- package/{dist/src → lib/types}/koa/middleware.d.ts +1 -1
- package/{dist/src → lib/types}/koa/middleware.d.ts.map +1 -1
- package/{dist/src → lib/types}/nestjs/auth.d.ts +1 -1
- package/{dist/src → lib/types}/nestjs/auth.d.ts.map +1 -1
- package/lib/types/nestjs/index.d.ts +4 -0
- package/lib/types/nestjs/index.d.ts.map +1 -0
- package/package.json +117 -8
- package/dist/src/common/client.d.ts.map +0 -1
- package/dist/src/common/client.js +0 -244
- package/dist/src/common/client.js.map +0 -1
- package/dist/src/common/index.d.ts +0 -2
- package/dist/src/common/index.js +0 -6
- package/dist/src/common/index.js.map +0 -1
- package/dist/src/common/keyRegistry.js +0 -90
- package/dist/src/common/keyRegistry.js.map +0 -1
- package/dist/src/common/logging.js +0 -13
- package/dist/src/common/logging.js.map +0 -1
- package/dist/src/common/requestLogger.js +0 -49
- package/dist/src/common/requestLogger.js.map +0 -1
- package/dist/src/common/types.d.ts.map +0 -1
- package/dist/src/common/types.js +0 -3
- package/dist/src/common/types.js.map +0 -1
- package/dist/src/common/utils.js +0 -23
- package/dist/src/common/utils.js.map +0 -1
- package/dist/src/common/validationErrorLogger.js +0 -40
- package/dist/src/common/validationErrorLogger.js.map +0 -1
- package/dist/src/express/auth.d.ts.map +0 -1
- package/dist/src/express/auth.js +0 -66
- package/dist/src/express/auth.js.map +0 -1
- package/dist/src/express/index.d.ts +0 -4
- package/dist/src/express/index.js +0 -10
- package/dist/src/express/index.js.map +0 -1
- package/dist/src/express/listEndpoints.d.ts +0 -3
- package/dist/src/express/listEndpoints.js +0 -166
- package/dist/src/express/listEndpoints.js.map +0 -1
- package/dist/src/express/middleware.d.ts.map +0 -1
- package/dist/src/express/middleware.js +0 -164
- package/dist/src/express/middleware.js.map +0 -1
- package/dist/src/fastify/auth.d.ts.map +0 -1
- package/dist/src/fastify/auth.js +0 -66
- package/dist/src/fastify/auth.js.map +0 -1
- package/dist/src/fastify/index.d.ts +0 -4
- package/dist/src/fastify/index.js +0 -13
- package/dist/src/fastify/index.js.map +0 -1
- package/dist/src/fastify/plugin.d.ts +0 -16
- package/dist/src/fastify/plugin.d.ts.map +0 -1
- package/dist/src/fastify/plugin.js +0 -124
- package/dist/src/fastify/plugin.js.map +0 -1
- package/dist/src/index.js +0 -3
- package/dist/src/index.js.map +0 -1
- package/dist/src/koa/auth.js +0 -67
- package/dist/src/koa/auth.js.map +0 -1
- package/dist/src/koa/index.d.ts +0 -4
- package/dist/src/koa/index.js +0 -10
- package/dist/src/koa/index.js.map +0 -1
- package/dist/src/koa/middleware.js +0 -108
- package/dist/src/koa/middleware.js.map +0 -1
- package/dist/src/nestjs/auth.js +0 -88
- package/dist/src/nestjs/auth.js.map +0 -1
- package/dist/src/nestjs/index.d.ts +0 -4
- package/dist/src/nestjs/index.d.ts.map +0 -1
- package/dist/src/nestjs/index.js +0 -12
- package/dist/src/nestjs/index.js.map +0 -1
- /package/{dist/src → lib/types}/common/keyRegistry.d.ts +0 -0
- /package/{dist/src → lib/types}/common/keyRegistry.d.ts.map +0 -0
- /package/{dist/src → lib/types}/common/logging.d.ts +0 -0
- /package/{dist/src → lib/types}/common/logging.d.ts.map +0 -0
- /package/{dist/src → lib/types}/common/utils.d.ts +0 -0
- /package/{dist/src → lib/types}/common/utils.d.ts.map +0 -0
- /package/{dist/src → lib/types}/express/listEndpoints.d.ts.map +0 -0
- /package/{dist/src → lib/types}/index.d.ts +0 -0
- /package/{dist/src → lib/types}/index.d.ts.map +0 -0
- /package/{dist/src → lib/types}/koa/auth.d.ts +0 -0
- /package/{dist/src → lib/types}/koa/auth.d.ts.map +0 -0
package/dist/src/koa/auth.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
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.requireApiKey = void 0;
|
|
13
|
-
const client_1 = require("../common/client");
|
|
14
|
-
const requireApiKey = ({ scopes, customHeader, } = {}) => {
|
|
15
|
-
return (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
let apiKey;
|
|
17
|
-
if (!customHeader) {
|
|
18
|
-
if (!ctx.headers.authorization) {
|
|
19
|
-
ctx.status = 401;
|
|
20
|
-
ctx.set("WWW-Authenticate", "ApiKey");
|
|
21
|
-
ctx.body = { error: "Missing authorization header" };
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const authorizationParts = ctx.headers.authorization.split(" ");
|
|
25
|
-
if (authorizationParts.length === 2 &&
|
|
26
|
-
authorizationParts[0].toLowerCase() === "apikey") {
|
|
27
|
-
apiKey = authorizationParts[1];
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
ctx.status = 401;
|
|
31
|
-
ctx.set("WWW-Authenticate", "ApiKey");
|
|
32
|
-
ctx.body = { error: "Invalid authorization scheme" };
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else if (customHeader) {
|
|
37
|
-
const customHeaderValue = ctx.headers[customHeader.toLowerCase()];
|
|
38
|
-
if (typeof customHeaderValue === "string") {
|
|
39
|
-
apiKey = customHeaderValue;
|
|
40
|
-
}
|
|
41
|
-
else if (Array.isArray(customHeaderValue)) {
|
|
42
|
-
apiKey = customHeaderValue[0];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (!apiKey) {
|
|
46
|
-
ctx.status = 403;
|
|
47
|
-
ctx.body = { error: "Missing API key" };
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const client = client_1.ApitallyClient.getInstance();
|
|
51
|
-
const keyInfo = yield client.keyRegistry.get(apiKey);
|
|
52
|
-
if (!keyInfo) {
|
|
53
|
-
ctx.status = 403;
|
|
54
|
-
ctx.body = { error: "Invalid API key" };
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (scopes && !keyInfo.hasScopes(scopes)) {
|
|
58
|
-
ctx.status = 403;
|
|
59
|
-
ctx.body = { error: "Permission denied" };
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
ctx.state.keyInfo = keyInfo;
|
|
63
|
-
yield next();
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
exports.requireApiKey = requireApiKey;
|
|
67
|
-
//# sourceMappingURL=auth.js.map
|
package/dist/src/koa/auth.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/koa/auth.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,6CAAkD;AAE3C,MAAM,aAAa,GAAG,CAAC,EAC5B,MAAM,EACN,YAAY,MAIV,EAAE,EAAE,EAAE;IACR,OAAO,CAAO,GAAgB,EAAE,IAAc,EAAE,EAAE;QAChD,IAAI,MAA0B,CAAC;QAE/B,IAAI,CAAC,YAAY,EAAE;YACjB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE;gBAC9B,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;gBACjB,GAAG,CAAC,GAAG,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;gBACtC,GAAG,CAAC,IAAI,GAAG,EAAE,KAAK,EAAE,8BAA8B,EAAE,CAAC;gBACrD,OAAO;aACR;YACD,MAAM,kBAAkB,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAChE,IACE,kBAAkB,CAAC,MAAM,KAAK,CAAC;gBAC/B,kBAAkB,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,QAAQ,EAChD;gBACA,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;aAChC;iBAAM;gBACL,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;gBACjB,GAAG,CAAC,GAAG,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;gBACtC,GAAG,CAAC,IAAI,GAAG,EAAE,KAAK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
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useApitally = exports.requireApiKey = exports.KeyInfo = void 0;
|
|
4
|
-
var keyRegistry_1 = require("../common/keyRegistry");
|
|
5
|
-
Object.defineProperty(exports, "KeyInfo", { enumerable: true, get: function () { return keyRegistry_1.KeyInfo; } });
|
|
6
|
-
var auth_1 = require("./auth");
|
|
7
|
-
Object.defineProperty(exports, "requireApiKey", { enumerable: true, get: function () { return auth_1.requireApiKey; } });
|
|
8
|
-
var middleware_1 = require("./middleware");
|
|
9
|
-
Object.defineProperty(exports, "useApitally", { enumerable: true, get: function () { return middleware_1.useApitally; } });
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/koa/index.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAAvC,sGAAA,OAAO,OAAA;AAChB,+BAAuC;AAA9B,qGAAA,aAAa,OAAA;AACtB,2CAA2C;AAAlC,yGAAA,WAAW,OAAA"}
|
|
@@ -1,108 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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;QAAC,OAAO,KAAU,EAAE;YACnB,UAAU,GAAG,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC;YACrD,MAAM,KAAK,CAAC;SACb;gBAAS;YACR,IAAI;gBACF,oEAAoE;gBACpE,IAAI,GAAG,CAAC,aAAa,IAAI,GAAG,CAAC,SAAS,EAAE;oBACtC,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC;wBAC9B,QAAQ,EAAE,WAAW,CAAC,GAAG,CAAC;wBAC1B,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM;wBAC1B,IAAI,EAAE,GAA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CAAC"}
|
package/dist/src/nestjs/auth.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
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.GetKeyInfo = 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
|
-
req.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
|
-
exports.GetKeyInfo = (0, common_1.createParamDecorator)((data, context) => {
|
|
85
|
-
const req = context.switchToHttp().getRequest();
|
|
86
|
-
return req.keyInfo;
|
|
87
|
-
});
|
|
88
|
-
//# sourceMappingURL=auth.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/nestjs/auth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,2CAQwB;AACxB,uCAAyC;AAGzC,6CAAkD;AAG3C,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,YAA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AAO,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACrD,IAAI,CAAC,OAAO,EAAE;gBACZ,MAAM,IAAI,2BAAkB,CAAC,iBAAiB,CAAC,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,OAAO,GAAG,OAAO,CAAC;YACtB,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;CACF,CAAA;AApDY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;qCAIoB,gBAAS;GAH7B,mBAAmB,CAoD/B;AAEY,QAAA,UAAU,GAAG,IAAA,6BAAoB,EAC5C,CAAC,IAAa,EAAE,OAAyB,EAAE,EAAE;IAC3C,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAW,CAAC;IACzD,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC,CACF,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/nestjs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC"}
|
package/dist/src/nestjs/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Scopes = exports.GetKeyInfo = exports.ApitallyApiKeyGuard = exports.useApitally = exports.KeyInfo = void 0;
|
|
4
|
-
var keyRegistry_1 = require("../common/keyRegistry");
|
|
5
|
-
Object.defineProperty(exports, "KeyInfo", { enumerable: true, get: function () { return keyRegistry_1.KeyInfo; } });
|
|
6
|
-
var express_1 = require("../express");
|
|
7
|
-
Object.defineProperty(exports, "useApitally", { enumerable: true, get: function () { return express_1.useApitally; } });
|
|
8
|
-
var auth_1 = require("./auth");
|
|
9
|
-
Object.defineProperty(exports, "ApitallyApiKeyGuard", { enumerable: true, get: function () { return auth_1.ApitallyApiKeyGuard; } });
|
|
10
|
-
Object.defineProperty(exports, "GetKeyInfo", { enumerable: true, get: function () { return auth_1.GetKeyInfo; } });
|
|
11
|
-
Object.defineProperty(exports, "Scopes", { enumerable: true, get: function () { return auth_1.Scopes; } });
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/nestjs/index.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAAvC,sGAAA,OAAO,OAAA;AAChB,sCAAyC;AAAhC,sGAAA,WAAW,OAAA;AACpB,+BAAiE;AAAxD,2GAAA,mBAAmB,OAAA;AAAE,kGAAA,UAAU,OAAA;AAAE,8FAAA,MAAM,OAAA"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|