nucleus-core-ts 0.9.710 → 0.9.712
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/dist/index.js +3 -3
- package/dist/src/Client/ApiCaller/system-tables.d.ts +3 -0
- package/dist/src/ElysiaPlugin/routes/authorization/index.d.ts +13 -0
- package/dist/src/Managers/Redis/index.d.ts +8 -0
- package/dist/src/Services/Authorization/Quota/index.d.ts +1 -1
- package/dist/src/Services/Authorization/Quota/windows.d.ts +11 -0
- package/package.json +1 -1
|
@@ -166,6 +166,9 @@ export declare const SYSTEM_TABLES: readonly [{
|
|
|
166
166
|
readonly type: "varchar";
|
|
167
167
|
readonly length: 10;
|
|
168
168
|
readonly notNull: true;
|
|
169
|
+
}, {
|
|
170
|
+
readonly name: "policy";
|
|
171
|
+
readonly type: "jsonb";
|
|
169
172
|
}];
|
|
170
173
|
readonly indexes: readonly [{
|
|
171
174
|
readonly columns: readonly ["action"];
|
|
@@ -16,6 +16,19 @@ export interface AuthorizationRoutesConfig {
|
|
|
16
16
|
* still returns effective LIMITS but omits live usage.
|
|
17
17
|
*/
|
|
18
18
|
readCounters?: (keys: string[]) => Promise<number[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Increments usage counters for the quota `/consume` (metering) endpoint. Wired to
|
|
21
|
+
* RedisManager.incrementCounter; when absent, `/consume` returns 503. Each item carries an
|
|
22
|
+
* optional TTL (rolling daily buckets self-expire; the `total` counter is permanent).
|
|
23
|
+
*/
|
|
24
|
+
incrementCounters?: (items: Array<{
|
|
25
|
+
key: string;
|
|
26
|
+
delta: number;
|
|
27
|
+
ttlSeconds?: number;
|
|
28
|
+
}>) => Promise<Array<{
|
|
29
|
+
key: string;
|
|
30
|
+
value: number;
|
|
31
|
+
}>>;
|
|
19
32
|
}
|
|
20
33
|
/**
|
|
21
34
|
* Endpoint-discovery admin + manifest routes.
|
|
@@ -33,6 +33,14 @@ export declare class RedisManager {
|
|
|
33
33
|
* gate usage; the counters themselves are maintained (INCR'd) by the spender.
|
|
34
34
|
*/
|
|
35
35
|
readCounters(keys: string[]): Promise<number[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Atomically add `delta` to a numeric counter and return the new value. Direct mode
|
|
38
|
+
* uses INCRBYFLOAT (atomic); Dapr mode falls back to read-modify-write (best-effort —
|
|
39
|
+
* fine for low-concurrency metering). An optional TTL (seconds) is (re)applied — pass it
|
|
40
|
+
* for rolling daily buckets so they self-expire; omit it for cumulative `total` counters.
|
|
41
|
+
* Used by the quota `/consume` endpoint (the spender reports usage here).
|
|
42
|
+
*/
|
|
43
|
+
incrementCounter(key: string, delta: number, ttlSeconds?: number): Promise<number>;
|
|
36
44
|
/**
|
|
37
45
|
* Returns the underlying ioredis client when running in direct mode.
|
|
38
46
|
* Returns null in Dapr mode — raw Redis commands (INFO, KEYS, …) are not
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { aggregateLimit, evaluateQuota, parseQuotaPolicy } from './evaluate';
|
|
2
2
|
export { type ResolvedQuota, resolveUserQuotas } from './resolve';
|
|
3
3
|
export type { CounterReader, QuotaAggregate, QuotaContext, QuotaEvaluation, QuotaOp, QuotaPolicy, QuotaWindow, } from './types';
|
|
4
|
-
export { bucketDatesForWindow, buildQuotaKeys } from './windows';
|
|
4
|
+
export { bucketDatesForWindow, buildIncrementKeys, buildQuotaKeys } from './windows';
|
|
@@ -9,3 +9,14 @@ export declare function bucketDatesForWindow(window: QuotaWindow, now: Date): st
|
|
|
9
9
|
* then `{date}` per bucket (or none for `total`). The spender maintains these; nucleus reads them.
|
|
10
10
|
*/
|
|
11
11
|
export declare function buildQuotaKeys(policy: QuotaPolicy, ctx: QuotaContext): string[];
|
|
12
|
+
/**
|
|
13
|
+
* The counter key(s) a SPEND should increment for one policy: TODAY's bucket for a
|
|
14
|
+
* `calendar_day`/`rolling` window (a rolling window reads several past buckets but a
|
|
15
|
+
* spend only lands in today's), or the single `total` key for a `total` window. Daily
|
|
16
|
+
* buckets get a TTL so they self-expire past the widest window; the total key never
|
|
17
|
+
* expires. Used by the quota `/consume` (metering) endpoint.
|
|
18
|
+
*/
|
|
19
|
+
export declare function buildIncrementKeys(policy: QuotaPolicy, ctx: QuotaContext): Array<{
|
|
20
|
+
key: string;
|
|
21
|
+
ttlSeconds?: number;
|
|
22
|
+
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nucleus-core-ts",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.712",
|
|
4
4
|
"description": "Production-ready, enterprise-grade TypeScript framework for building multi-tenant APIs",
|
|
5
5
|
"author": "Hidayet Can Özcan <hidayetcan@gmail.com>",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|