@qodalis/cli-server-plugin-public-api 0.0.0-stage → 1.0.0-beta.29
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 +130 -2
- package/dist/cli-public-api-builder.d.ts +136 -0
- package/dist/cli-public-api-builder.d.ts.map +1 -0
- package/dist/cli-public-api-builder.js +377 -0
- package/dist/cli-public-api-builder.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/openapi.d.ts +24 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +79 -0
- package/dist/openapi.js.map +1 -0
- package/dist/package-info.d.ts +8 -0
- package/dist/package-info.d.ts.map +1 -0
- package/dist/package-info.js +12 -0
- package/dist/package-info.js.map +1 -0
- package/dist/quota.d.ts +56 -0
- package/dist/quota.d.ts.map +1 -0
- package/dist/quota.js +65 -0
- package/dist/quota.js.map +1 -0
- package/dist/swagger.d.ts +10 -0
- package/dist/swagger.d.ts.map +1 -0
- package/dist/swagger.js +61 -0
- package/dist/swagger.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/usage-service.d.ts +73 -0
- package/dist/usage-service.d.ts.map +1 -0
- package/dist/usage-service.js +74 -0
- package/dist/usage-service.js.map +1 -0
- package/dist/usage-store.d.ts +31 -0
- package/dist/usage-store.d.ts.map +1 -0
- package/dist/usage-store.js +64 -0
- package/dist/usage-store.js.map +1 -0
- package/package.json +41 -5
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InMemoryPublicApiUsageStore = void 0;
|
|
4
|
+
/** A day window is `yyyy-MM-dd`; a minute window is longer (`yyyy-MM-ddTHH:mm`). */
|
|
5
|
+
const isDay = (window) => window.length === 10;
|
|
6
|
+
/** Counters in memory (the default): one process; lost on restart. */
|
|
7
|
+
class InMemoryPublicApiUsageStore {
|
|
8
|
+
/** `${tokenId}|${window}` → the token's user and count. */
|
|
9
|
+
tokens = new Map();
|
|
10
|
+
/** `${userId}|${window}` → the account's sum. */
|
|
11
|
+
accounts = new Map();
|
|
12
|
+
async increment(tokenId, userId, window) {
|
|
13
|
+
const key = `${tokenId}|${window}`;
|
|
14
|
+
const entry = this.tokens.get(key) ?? { tokenId, userId, window, count: 0 };
|
|
15
|
+
entry.count++;
|
|
16
|
+
this.tokens.set(key, entry);
|
|
17
|
+
const accountKey = `${entry.userId}|${window}`;
|
|
18
|
+
this.accounts.set(accountKey, (this.accounts.get(accountKey) ?? 0) + 1);
|
|
19
|
+
return entry.count;
|
|
20
|
+
}
|
|
21
|
+
async decrement(tokenId, window) {
|
|
22
|
+
const key = `${tokenId}|${window}`;
|
|
23
|
+
const entry = this.tokens.get(key);
|
|
24
|
+
if (!entry || entry.count <= 0)
|
|
25
|
+
return;
|
|
26
|
+
entry.count--;
|
|
27
|
+
const accountKey = `${entry.userId}|${window}`;
|
|
28
|
+
const sum = (this.accounts.get(accountKey) ?? 1) - 1;
|
|
29
|
+
if (sum > 0)
|
|
30
|
+
this.accounts.set(accountKey, sum);
|
|
31
|
+
else
|
|
32
|
+
this.accounts.delete(accountKey);
|
|
33
|
+
if (entry.count === 0)
|
|
34
|
+
this.tokens.delete(key);
|
|
35
|
+
}
|
|
36
|
+
async accountCount(userId, window) {
|
|
37
|
+
return this.accounts.get(`${userId}|${window}`) ?? 0;
|
|
38
|
+
}
|
|
39
|
+
async tokenDays(tokenIds, fromDay, toDay) {
|
|
40
|
+
const wanted = new Set(tokenIds);
|
|
41
|
+
const out = {};
|
|
42
|
+
for (const entry of this.tokens.values()) {
|
|
43
|
+
if (!wanted.has(entry.tokenId) || !isDay(entry.window) || entry.window < fromDay || entry.window > toDay)
|
|
44
|
+
continue;
|
|
45
|
+
(out[entry.tokenId] ??= {})[entry.window] = entry.count;
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
async prune(beforeDay, beforeMinute) {
|
|
50
|
+
for (const [key, entry] of this.tokens) {
|
|
51
|
+
if (entry.window < (isDay(entry.window) ? beforeDay : beforeMinute)) {
|
|
52
|
+
this.tokens.delete(key);
|
|
53
|
+
const accountKey = `${entry.userId}|${entry.window}`;
|
|
54
|
+
const sum = (this.accounts.get(accountKey) ?? 0) - entry.count;
|
|
55
|
+
if (sum > 0)
|
|
56
|
+
this.accounts.set(accountKey, sum);
|
|
57
|
+
else
|
|
58
|
+
this.accounts.delete(accountKey);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.InMemoryPublicApiUsageStore = InMemoryPublicApiUsageStore;
|
|
64
|
+
//# sourceMappingURL=usage-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-store.js","sourceRoot":"","sources":["../usage-store.ts"],"names":[],"mappings":";;;AAmBA,oFAAoF;AACpF,MAAM,KAAK,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,EAAE,CAAC;AAEvD,sEAAsE;AACtE,MAAa,2BAA2B;IACpC,2DAA2D;IAC1C,MAAM,GAAG,IAAI,GAAG,EAA8E,CAAC;IAChH,iDAAiD;IAChC,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEtD,KAAK,CAAC,SAAS,CAAC,OAAe,EAAE,MAAc,EAAE,MAAc;QAC3D,MAAM,GAAG,GAAG,GAAG,OAAO,IAAI,MAAM,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QAC5E,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,IAAI,CAAC,MAAM,CAAC,GAA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,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;;oBAC3C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAC1C,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AArDD,kEAqDC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@qodalis/cli-server-plugin-public-api",
|
|
3
|
+
"version": "1.0.0-beta.29",
|
|
4
|
+
"description": "Public API plugin for Qodalis CLI server — host-token guard with per-account quotas and usage, the host's public OpenAPI document and Swagger UI",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"LICENSE",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"cli",
|
|
17
|
+
"qodalis",
|
|
18
|
+
"public-api",
|
|
19
|
+
"openapi",
|
|
20
|
+
"rate-limit",
|
|
21
|
+
"cli-server",
|
|
22
|
+
"plugin"
|
|
23
|
+
],
|
|
24
|
+
"author": "Nicolae Lupei",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/qodalis-solutions/cli-server-node",
|
|
29
|
+
"directory": "plugins/public-api"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@qodalis/cli-server-abstractions": "^1.0.0-beta.29",
|
|
33
|
+
"swagger-ui-dist": "^5.17.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"express": "^4.18.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/express": "^4.17.21",
|
|
40
|
+
"typescript": "^5.6.0"
|
|
41
|
+
}
|
|
42
|
+
}
|