@spendguard/sdk 0.5.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.
@@ -0,0 +1,6 @@
1
+ export { D as DEFAULT_CACHE_MAX_ENTRIES, d as DEFAULT_CACHE_TTL_MS, I as IdempotencyCache, m as InMemoryIdempotencyCache, n as InMemoryIdempotencyCacheOptions, N as NoopIdempotencyCache } from './cache-DOnw8QtJ.js';
2
+ import '@grpc/grpc-js';
3
+ import '@opentelemetry/api';
4
+ import './adapter-D9T3yEEw.js';
5
+ import '@protobuf-ts/runtime-rpc';
6
+ import '@protobuf-ts/runtime';
package/dist/cache.js ADDED
@@ -0,0 +1,74 @@
1
+ // src/cache.ts
2
+ var DEFAULT_CACHE_MAX_ENTRIES = 1024;
3
+ var DEFAULT_CACHE_TTL_MS = 5 * 60 * 1e3;
4
+ var InMemoryIdempotencyCache = class {
5
+ entries = /* @__PURE__ */ new Map();
6
+ maxEntries;
7
+ defaultTtlMs;
8
+ now;
9
+ constructor(opts = {}) {
10
+ this.maxEntries = clampPositive(opts.maxEntries ?? DEFAULT_CACHE_MAX_ENTRIES);
11
+ this.defaultTtlMs = clampPositive(opts.defaultTtlMs ?? DEFAULT_CACHE_TTL_MS);
12
+ this.now = opts.now ?? Date.now;
13
+ }
14
+ get(key, bodyHash) {
15
+ const entry = this.entries.get(key);
16
+ if (entry === void 0) return void 0;
17
+ if (entry.expiresAt <= this.now()) {
18
+ this.entries.delete(key);
19
+ return void 0;
20
+ }
21
+ if (bodyHash !== void 0 && entry.bodyHash !== void 0 && entry.bodyHash !== bodyHash) {
22
+ return void 0;
23
+ }
24
+ this.entries.delete(key);
25
+ this.entries.set(key, entry);
26
+ return entry.outcome;
27
+ }
28
+ set(key, outcome, ttlMs, bodyHash) {
29
+ const ttl = ttlMs !== void 0 ? clampTtl(ttlMs, this.defaultTtlMs) : this.defaultTtlMs;
30
+ this.entries.delete(key);
31
+ const entry = { outcome, expiresAt: this.now() + ttl };
32
+ if (bodyHash !== void 0) entry.bodyHash = bodyHash;
33
+ this.entries.set(key, entry);
34
+ while (this.entries.size > this.maxEntries) {
35
+ const oldestKey = this.entries.keys().next().value;
36
+ if (oldestKey === void 0) break;
37
+ this.entries.delete(oldestKey);
38
+ }
39
+ }
40
+ clear() {
41
+ this.entries.clear();
42
+ }
43
+ get size() {
44
+ return this.entries.size;
45
+ }
46
+ };
47
+ var NoopIdempotencyCache = class {
48
+ get(_key, _bodyHash) {
49
+ return void 0;
50
+ }
51
+ set(_key, _outcome, _ttlMs, _bodyHash) {
52
+ }
53
+ clear() {
54
+ }
55
+ get size() {
56
+ return 0;
57
+ }
58
+ };
59
+ function clampPositive(value) {
60
+ if (!Number.isFinite(value) || !Number.isInteger(value) || value <= 0) {
61
+ return DEFAULT_CACHE_MAX_ENTRIES;
62
+ }
63
+ return value;
64
+ }
65
+ function clampTtl(value, fallback) {
66
+ if (!Number.isFinite(value) || !Number.isInteger(value) || value <= 0) {
67
+ return fallback;
68
+ }
69
+ return value;
70
+ }
71
+
72
+ export { DEFAULT_CACHE_MAX_ENTRIES, DEFAULT_CACHE_TTL_MS, InMemoryIdempotencyCache, NoopIdempotencyCache };
73
+ //# sourceMappingURL=cache.js.map
74
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1,6 @@
1
+ export { status as GrpcStatus, ServiceError } from '@grpc/grpc-js';
2
+ export { A as ApplyFailedRequest, B as BudgetClaim, C as ClaimEstimate, a as CommitEstimatedRequest, e as DEFAULT_CAPABILITY_LEVEL, f as DEFAULT_DECISION_TIMEOUT_MS, g as DEFAULT_HANDSHAKE_TIMEOUT_MS, i as DEFAULT_PROTOCOL_VERSION, j as DEFAULT_PUBLISH_TIMEOUT_MS, k as DEFAULT_TRACE_TIMEOUT_MS, l as DecisionOutcome, E as EmitLlmCallPostRequest, H as HandshakeOutcome, a3 as MapGrpcStatusContext, o as PricingFreeze, p as PublishOutcomeRequest, Q as QueryBudgetRequest, q as QueryBudgetResult, a4 as REASON_CODE_PREFIXES, r as ReleaseOutcome, s as ReleaseRequest, v as ReserveRequest, y as ResolvedConfig, z as ResumeAfterApprovalRequest, R as RunProjectionPolicy, X as SpanRecord, Y as SpendGuardClient, Z as SpendGuardClientConfig, _ as SpendGuardClientOptions, $ as UnitRef, a5 as computeReserveBodyHash } from './cache-DOnw8QtJ.js';
3
+ import '@opentelemetry/api';
4
+ import './adapter-D9T3yEEw.js';
5
+ import '@protobuf-ts/runtime-rpc';
6
+ import '@protobuf-ts/runtime';