@frontmcp/auth 0.0.1 → 0.8.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.
Files changed (81) hide show
  1. package/README.md +11 -0
  2. package/authorization/authorization.types.d.ts +236 -0
  3. package/authorization/authorization.types.d.ts.map +1 -0
  4. package/authorization/index.d.ts +9 -0
  5. package/authorization/index.d.ts.map +1 -0
  6. package/cimd/cimd-redis.cache.d.ts +111 -0
  7. package/cimd/cimd-redis.cache.d.ts.map +1 -0
  8. package/cimd/cimd.cache.d.ts +200 -0
  9. package/cimd/cimd.cache.d.ts.map +1 -0
  10. package/cimd/cimd.errors.d.ts +124 -0
  11. package/cimd/cimd.errors.d.ts.map +1 -0
  12. package/cimd/cimd.logger.d.ts +39 -0
  13. package/cimd/cimd.logger.d.ts.map +1 -0
  14. package/cimd/cimd.service.d.ts +88 -0
  15. package/cimd/cimd.service.d.ts.map +1 -0
  16. package/cimd/cimd.types.d.ts +178 -0
  17. package/cimd/cimd.types.d.ts.map +1 -0
  18. package/cimd/cimd.validator.d.ts +49 -0
  19. package/cimd/cimd.validator.d.ts.map +1 -0
  20. package/cimd/index.d.ts +17 -0
  21. package/cimd/index.d.ts.map +1 -0
  22. package/esm/index.mjs +4001 -0
  23. package/esm/package.json +59 -0
  24. package/index.d.ts +44 -0
  25. package/index.d.ts.map +1 -0
  26. package/index.js +4131 -0
  27. package/jwks/dev-key-persistence.d.ts +70 -0
  28. package/jwks/dev-key-persistence.d.ts.map +1 -0
  29. package/jwks/index.d.ts +20 -0
  30. package/jwks/index.d.ts.map +1 -0
  31. package/jwks/jwks.service.d.ts +69 -0
  32. package/jwks/jwks.service.d.ts.map +1 -0
  33. package/jwks/jwks.types.d.ts +33 -0
  34. package/jwks/jwks.types.d.ts.map +1 -0
  35. package/jwks/jwks.utils.d.ts +5 -0
  36. package/jwks/jwks.utils.d.ts.map +1 -0
  37. package/package.json +2 -2
  38. package/session/authorization-vault.d.ts +667 -0
  39. package/session/authorization-vault.d.ts.map +1 -0
  40. package/session/authorization.store.d.ts +311 -0
  41. package/session/authorization.store.d.ts.map +1 -0
  42. package/session/index.d.ts +19 -0
  43. package/session/index.d.ts.map +1 -0
  44. package/session/storage/in-memory-authorization-vault.d.ts +53 -0
  45. package/session/storage/in-memory-authorization-vault.d.ts.map +1 -0
  46. package/session/storage/index.d.ts +17 -0
  47. package/session/storage/index.d.ts.map +1 -0
  48. package/session/storage/storage-authorization-vault.d.ts +107 -0
  49. package/session/storage/storage-authorization-vault.d.ts.map +1 -0
  50. package/session/storage/storage-token-store.d.ts +92 -0
  51. package/session/storage/storage-token-store.d.ts.map +1 -0
  52. package/session/token.store.d.ts +39 -0
  53. package/session/token.store.d.ts.map +1 -0
  54. package/session/token.vault.d.ts +33 -0
  55. package/session/token.vault.d.ts.map +1 -0
  56. package/session/utils/index.d.ts +5 -0
  57. package/session/utils/index.d.ts.map +1 -0
  58. package/session/utils/tiny-ttl-cache.d.ts +20 -0
  59. package/session/utils/tiny-ttl-cache.d.ts.map +1 -0
  60. package/session/vault-encryption.d.ts +190 -0
  61. package/session/vault-encryption.d.ts.map +1 -0
  62. package/ui/base-layout.d.ts +170 -0
  63. package/ui/base-layout.d.ts.map +1 -0
  64. package/ui/index.d.ts +10 -0
  65. package/ui/index.d.ts.map +1 -0
  66. package/ui/templates.d.ts +134 -0
  67. package/ui/templates.d.ts.map +1 -0
  68. package/utils/audience.validator.d.ts +130 -0
  69. package/utils/audience.validator.d.ts.map +1 -0
  70. package/utils/index.d.ts +8 -0
  71. package/utils/index.d.ts.map +1 -0
  72. package/utils/www-authenticate.utils.d.ts +98 -0
  73. package/utils/www-authenticate.utils.d.ts.map +1 -0
  74. package/vault/auth-providers.types.d.ts +262 -0
  75. package/vault/auth-providers.types.d.ts.map +1 -0
  76. package/vault/credential-cache.d.ts +98 -0
  77. package/vault/credential-cache.d.ts.map +1 -0
  78. package/vault/credential-helpers.d.ts +14 -0
  79. package/vault/credential-helpers.d.ts.map +1 -0
  80. package/vault/index.d.ts +10 -0
  81. package/vault/index.d.ts.map +1 -0
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # auth
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build auth` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test auth` to execute the unit tests via [Jest](https://jestjs.io).
@@ -0,0 +1,236 @@
1
+ /**
2
+ * Authorization Types
3
+ *
4
+ * Core types for authorization, user identity, and progressive auth.
5
+ * These types are portable and can be used across different implementations.
6
+ */
7
+ import { z } from 'zod';
8
+ /**
9
+ * Authentication mode determining how tokens are handled
10
+ */
11
+ export type AuthMode = 'public' | 'transparent' | 'orchestrated';
12
+ /**
13
+ * Zod schema for AuthMode
14
+ */
15
+ export declare const authModeSchema: z.ZodEnum<{
16
+ public: "public";
17
+ transparent: "transparent";
18
+ orchestrated: "orchestrated";
19
+ }>;
20
+ /**
21
+ * User identity from authentication
22
+ */
23
+ export interface AuthUser {
24
+ /** Subject identifier */
25
+ sub: string;
26
+ /** Display name */
27
+ name?: string;
28
+ /** Email address */
29
+ email?: string;
30
+ /** Profile picture URL */
31
+ picture?: string;
32
+ /** Whether this is an anonymous user */
33
+ anonymous?: boolean;
34
+ }
35
+ /**
36
+ * Zod schema for AuthUser
37
+ */
38
+ export declare const authUserSchema: z.ZodObject<{
39
+ sub: z.ZodString;
40
+ name: z.ZodOptional<z.ZodString>;
41
+ email: z.ZodOptional<z.ZodString>;
42
+ picture: z.ZodOptional<z.ZodString>;
43
+ anonymous: z.ZodOptional<z.ZodBoolean>;
44
+ }, z.core.$strip>;
45
+ /**
46
+ * Authorized tool entry
47
+ */
48
+ export interface AuthorizedTool {
49
+ /** Execution path: [appId, toolId] */
50
+ executionPath: [appId: string, toolId: string];
51
+ /** Required scopes for this tool */
52
+ scopes?: string[];
53
+ /** Additional tool metadata */
54
+ details?: Record<string, unknown>;
55
+ }
56
+ /**
57
+ * Zod schema for AuthorizedTool
58
+ */
59
+ export declare const authorizedToolSchema: z.ZodObject<{
60
+ executionPath: z.ZodTuple<[z.ZodString, z.ZodString], null>;
61
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
62
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
63
+ }, z.core.$strip>;
64
+ /**
65
+ * Authorized prompt entry
66
+ */
67
+ export interface AuthorizedPrompt {
68
+ /** Execution path: [appId, promptId] */
69
+ executionPath: [appId: string, promptId: string];
70
+ /** Required scopes for this prompt */
71
+ scopes?: string[];
72
+ /** Additional prompt metadata */
73
+ details?: Record<string, unknown>;
74
+ }
75
+ /**
76
+ * Zod schema for AuthorizedPrompt
77
+ */
78
+ export declare const authorizedPromptSchema: z.ZodObject<{
79
+ executionPath: z.ZodTuple<[z.ZodString, z.ZodString], null>;
80
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
81
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
82
+ }, z.core.$strip>;
83
+ /**
84
+ * LLM-safe session context (no tokens exposed)
85
+ */
86
+ export interface LLMSafeAuthContext {
87
+ /** Authorization ID */
88
+ authorizationId: string;
89
+ /** Session ID */
90
+ sessionId: string;
91
+ /** Auth mode */
92
+ mode: AuthMode;
93
+ /** Whether anonymous */
94
+ isAnonymous: boolean;
95
+ /** User (sub and name only) */
96
+ user: {
97
+ sub: string;
98
+ name?: string;
99
+ };
100
+ /** Granted scopes */
101
+ scopes: string[];
102
+ /** Authorized tool IDs */
103
+ authorizedToolIds: string[];
104
+ /** Authorized prompt IDs */
105
+ authorizedPromptIds: string[];
106
+ }
107
+ /**
108
+ * Zod schema for LLMSafeAuthContext
109
+ */
110
+ export declare const llmSafeAuthContextSchema: z.ZodObject<{
111
+ authorizationId: z.ZodString;
112
+ sessionId: z.ZodString;
113
+ mode: z.ZodEnum<{
114
+ public: "public";
115
+ transparent: "transparent";
116
+ orchestrated: "orchestrated";
117
+ }>;
118
+ isAnonymous: z.ZodBoolean;
119
+ user: z.ZodObject<{
120
+ sub: z.ZodString;
121
+ name: z.ZodOptional<z.ZodString>;
122
+ }, z.core.$strip>;
123
+ scopes: z.ZodArray<z.ZodString>;
124
+ authorizedToolIds: z.ZodArray<z.ZodString>;
125
+ authorizedPromptIds: z.ZodArray<z.ZodString>;
126
+ }, z.core.$strip>;
127
+ /**
128
+ * State of app authorization within a session.
129
+ * Used for progressive authorization flow.
130
+ */
131
+ export declare enum AppAuthState {
132
+ /** App has been fully authorized with tokens stored */
133
+ AUTHORIZED = "authorized",
134
+ /** User explicitly skipped this app during initial auth */
135
+ SKIPPED = "skipped",
136
+ /** App authorization is pending (not yet presented to user) */
137
+ PENDING = "pending"
138
+ }
139
+ /**
140
+ * Zod schema for AppAuthState enum
141
+ */
142
+ export declare const appAuthStateSchema: z.ZodEnum<typeof AppAuthState>;
143
+ /**
144
+ * App authorization record with state tracking.
145
+ * Stored server-side, NOT in JWT.
146
+ */
147
+ export interface AppAuthorizationRecord {
148
+ /** App ID */
149
+ appId: string;
150
+ /** Current authorization state */
151
+ state: AppAuthState;
152
+ /** When the state was last changed (epoch ms) */
153
+ stateChangedAt: number;
154
+ /** Scopes granted for this app */
155
+ grantedScopes?: string[];
156
+ /** Auth provider ID used for this app */
157
+ authProviderId?: string;
158
+ /** Tool IDs accessible through this app authorization */
159
+ toolIds: string[];
160
+ }
161
+ /**
162
+ * Zod schema for AppAuthorizationRecord
163
+ */
164
+ export declare const appAuthorizationRecordSchema: z.ZodObject<{
165
+ appId: z.ZodString;
166
+ state: z.ZodEnum<typeof AppAuthState>;
167
+ stateChangedAt: z.ZodNumber;
168
+ grantedScopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
169
+ authProviderId: z.ZodOptional<z.ZodString>;
170
+ toolIds: z.ZodArray<z.ZodString>;
171
+ }, z.core.$strip>;
172
+ /**
173
+ * Progressive auth session state.
174
+ * Tracks which apps are authorized, skipped, or pending.
175
+ * Stored server-side for security.
176
+ */
177
+ export interface ProgressiveAuthState {
178
+ /** App authorization records by app ID */
179
+ apps: Record<string, AppAuthorizationRecord>;
180
+ /** Apps authorized during initial auth */
181
+ initiallyAuthorized: string[];
182
+ /** Apps skipped during initial auth */
183
+ initiallySkipped: string[];
184
+ }
185
+ /**
186
+ * Zod schema for ProgressiveAuthState
187
+ */
188
+ export declare const progressiveAuthStateSchema: z.ZodObject<{
189
+ apps: z.ZodRecord<z.ZodString, z.ZodObject<{
190
+ appId: z.ZodString;
191
+ state: z.ZodEnum<typeof AppAuthState>;
192
+ stateChangedAt: z.ZodNumber;
193
+ grantedScopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
194
+ authProviderId: z.ZodOptional<z.ZodString>;
195
+ toolIds: z.ZodArray<z.ZodString>;
196
+ }, z.core.$strip>>;
197
+ initiallyAuthorized: z.ZodArray<z.ZodString>;
198
+ initiallySkipped: z.ZodArray<z.ZodString>;
199
+ }, z.core.$strip>;
200
+ /**
201
+ * Context for creating an authorization (portable version)
202
+ */
203
+ export interface AuthorizationCreateCtx {
204
+ /** Unique ID (typically token signature fingerprint) */
205
+ id: string;
206
+ /** Whether this is anonymous */
207
+ isAnonymous: boolean;
208
+ /** User identity */
209
+ user: AuthUser;
210
+ /** JWT claims */
211
+ claims?: Record<string, unknown>;
212
+ /** Token expiration (epoch ms) */
213
+ expiresAt?: number;
214
+ /** Granted scopes */
215
+ scopes?: string[];
216
+ /** The original token (for transparent mode) */
217
+ token?: string;
218
+ /** Authorized apps */
219
+ authorizedApps?: Record<string, {
220
+ id: string;
221
+ toolIds: string[];
222
+ }>;
223
+ /** Authorized app IDs */
224
+ authorizedAppIds?: string[];
225
+ /** Authorized tools */
226
+ authorizedTools?: Record<string, AuthorizedTool>;
227
+ /** Authorized tool IDs */
228
+ authorizedToolIds?: string[];
229
+ /** Authorized prompts */
230
+ authorizedPrompts?: Record<string, AuthorizedPrompt>;
231
+ /** Authorized prompt IDs */
232
+ authorizedPromptIds?: string[];
233
+ /** Authorized resources */
234
+ authorizedResources?: string[];
235
+ }
236
+ //# sourceMappingURL=authorization.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization.types.d.ts","sourceRoot":"","sources":["../../src/authorization/authorization.types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,aAAa,GAAG,cAAc,CAAC;AAEjE;;GAEG;AACH,eAAO,MAAM,cAAc;;;;EAAoD,CAAC;AAMhF;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,yBAAyB;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,mBAAmB;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0BAA0B;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wCAAwC;IACxC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;iBAMzB,CAAC;AAMH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,sCAAsC;IACtC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/C,oCAAoC;IACpC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;iBAI/B,CAAC;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,wCAAwC;IACxC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACjD,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC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AAC,EAAE,MAAM,EAAE,CAAC;IAC/B,2BAA2B;IAC3B,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;CAChC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Authorization Module
3
+ *
4
+ * Core types for authorization, user identity, and progressive auth.
5
+ */
6
+ export type { AuthMode, AuthUser, AuthorizedTool, AuthorizedPrompt, LLMSafeAuthContext, AppAuthorizationRecord, ProgressiveAuthState, AuthorizationCreateCtx, } from './authorization.types';
7
+ export { AppAuthState } from './authorization.types';
8
+ export { authModeSchema, authUserSchema, authorizedToolSchema, authorizedPromptSchema, llmSafeAuthContextSchema, appAuthStateSchema, appAuthorizationRecordSchema, progressiveAuthStateSchema, } from './authorization.types';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/authorization/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,YAAY,EACV,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGrD,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,EACxB,kBAAkB,EAClB,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,111 @@
1
+ import type { CimdCacheBackend, CimdCacheEntry, CimdCacheTtlConfig } from './cimd.cache';
2
+ import type { ClientMetadataDocument, CimdCacheConfig } from './cimd.types';
3
+ /**
4
+ * Redis-backed CIMD document cache.
5
+ *
6
+ * Stores cached CIMD documents in Redis with HTTP cache-aware TTLs.
7
+ * Suitable for production and distributed deployments.
8
+ *
9
+ * Key format: {keyPrefix}{sha256(clientId)}
10
+ * Value format: JSON-serialized CimdCacheEntry
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const cache = new RedisCimdCache({
15
+ * redis: { url: 'redis://localhost:6379' },
16
+ * defaultTtlMs: 3600_000,
17
+ * });
18
+ * await cache.connect();
19
+ *
20
+ * // Cache will be usable after connect()
21
+ * await cache.set(clientId, document, headers);
22
+ * const entry = await cache.get(clientId);
23
+ *
24
+ * // Close when done
25
+ * await cache.close();
26
+ * ```
27
+ */
28
+ export declare class RedisCimdCache implements CimdCacheBackend {
29
+ private readonly redis;
30
+ private readonly keyPrefix;
31
+ protected readonly config: CimdCacheTtlConfig;
32
+ constructor(config: CimdCacheConfig);
33
+ /**
34
+ * Connect to Redis.
35
+ * Must be called before using any cache operations.
36
+ */
37
+ connect(): Promise<void>;
38
+ /**
39
+ * Generate a Redis key for a client ID.
40
+ * Uses SHA-256 hash to handle URLs with special characters.
41
+ */
42
+ private cacheKey;
43
+ /**
44
+ * Get a cached entry by client_id.
45
+ *
46
+ * @param clientId - The client_id URL
47
+ * @returns The cached entry if valid, or undefined
48
+ */
49
+ get(clientId: string): Promise<CimdCacheEntry | undefined>;
50
+ /**
51
+ * Get a stale entry for conditional revalidation.
52
+ *
53
+ * @param clientId - The client_id URL
54
+ * @returns The stale entry (even if expired), or undefined if not cached
55
+ */
56
+ getStale(clientId: string): Promise<CimdCacheEntry | undefined>;
57
+ /**
58
+ * Store a document in the cache.
59
+ *
60
+ * @param clientId - The client_id URL
61
+ * @param document - The metadata document
62
+ * @param headers - HTTP response headers
63
+ */
64
+ set(clientId: string, document: ClientMetadataDocument, headers: Headers): Promise<void>;
65
+ /**
66
+ * Update an existing cache entry (after 304 Not Modified).
67
+ *
68
+ * @param clientId - The client_id URL
69
+ * @param headers - New HTTP headers with updated cache directives
70
+ */
71
+ revalidate(clientId: string, headers: Headers): Promise<boolean>;
72
+ /**
73
+ * Delete a cache entry.
74
+ *
75
+ * @param clientId - The client_id URL
76
+ * @returns true if an entry was deleted
77
+ */
78
+ delete(clientId: string): Promise<boolean>;
79
+ /**
80
+ * Get conditional request headers for a cached entry.
81
+ *
82
+ * @param clientId - The client_id URL
83
+ * @returns Headers for conditional request, or undefined if not cached
84
+ */
85
+ getConditionalHeaders(clientId: string): Promise<Record<string, string> | undefined>;
86
+ /**
87
+ * Clear all cached entries.
88
+ * Uses Redis SCAN to find and delete all keys with our prefix.
89
+ */
90
+ clear(): Promise<void>;
91
+ /**
92
+ * Get the number of cached entries.
93
+ * Uses Redis SCAN to count keys with our prefix.
94
+ */
95
+ size(): Promise<number>;
96
+ /**
97
+ * Remove expired entries.
98
+ *
99
+ * Note: Redis handles expiration automatically via TTL.
100
+ * This method is primarily for explicit cleanup of entries that are
101
+ * well past their HTTP cache expiration but still within Redis TTL.
102
+ *
103
+ * @returns Number of entries removed
104
+ */
105
+ cleanup(): Promise<number>;
106
+ /**
107
+ * Close the Redis connection.
108
+ */
109
+ close(): Promise<void>;
110
+ }
111
+ //# sourceMappingURL=cimd-redis.cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cimd-redis.cache.d.ts","sourceRoot":"","sources":["../../src/cimd/cimd-redis.cache.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEzF,OAAO,KAAK,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAa5E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,cAAe,YAAW,gBAAgB;IACrD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAsB;IAC5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC;gBAElC,MAAM,EAAE,eAAe;IA+BnC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B;;;OAGG;IACH,OAAO,CAAC,QAAQ;IAKhB;;;;;OAKG;IACG,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;IA0BhE;;;;;OAKG;IACG,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;IAerE;;;;;;OAMG;IACG,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAsB9F;;;;;OAKG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IA4BtE;;;;;OAKG;IACG,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKhD;;;;;OAKG;IACG,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IA0B1F;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAK7B;;;;;;;;OAQG;IACG,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IA2BhC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
@@ -0,0 +1,200 @@
1
+ /**
2
+ * CIMD HTTP Cache-Aware Caching
3
+ *
4
+ * Implements caching for CIMD documents that respects HTTP cache headers
5
+ * like Cache-Control, Expires, ETag, and Last-Modified.
6
+ *
7
+ * Supports both in-memory and Redis backends.
8
+ */
9
+ import type { ClientMetadataDocument, CimdCacheConfig } from './cimd.types';
10
+ /**
11
+ * Cache entry for a CIMD document.
12
+ */
13
+ export interface CimdCacheEntry {
14
+ /**
15
+ * The cached metadata document.
16
+ */
17
+ document: ClientMetadataDocument;
18
+ /**
19
+ * When the entry expires (Unix timestamp in ms).
20
+ */
21
+ expiresAt: number;
22
+ /**
23
+ * HTTP ETag for conditional requests.
24
+ */
25
+ etag?: string;
26
+ /**
27
+ * HTTP Last-Modified header value.
28
+ */
29
+ lastModified?: string;
30
+ /**
31
+ * When the entry was cached (Unix timestamp in ms).
32
+ */
33
+ cachedAt: number;
34
+ }
35
+ /**
36
+ * Headers relevant to caching.
37
+ */
38
+ export interface CacheableHeaders {
39
+ 'cache-control'?: string;
40
+ expires?: string;
41
+ etag?: string;
42
+ 'last-modified'?: string;
43
+ age?: string;
44
+ }
45
+ /**
46
+ * TTL configuration for cache operations.
47
+ * This is the minimal config needed for cache TTL calculations.
48
+ */
49
+ export interface CimdCacheTtlConfig {
50
+ defaultTtlMs: number;
51
+ maxTtlMs: number;
52
+ minTtlMs: number;
53
+ }
54
+ /**
55
+ * CIMD Cache Backend Interface.
56
+ *
57
+ * All cache operations are async to support both in-memory and Redis backends.
58
+ */
59
+ export interface CimdCacheBackend {
60
+ /**
61
+ * Get a cached entry by client_id.
62
+ * Returns undefined if not cached or expired.
63
+ */
64
+ get(clientId: string): Promise<CimdCacheEntry | undefined>;
65
+ /**
66
+ * Get a stale entry for conditional revalidation.
67
+ * Returns the entry even if expired.
68
+ */
69
+ getStale(clientId: string): Promise<CimdCacheEntry | undefined>;
70
+ /**
71
+ * Store a document in the cache with headers for TTL computation.
72
+ */
73
+ set(clientId: string, document: ClientMetadataDocument, headers: Headers): Promise<void>;
74
+ /**
75
+ * Update an existing cache entry after 304 Not Modified.
76
+ */
77
+ revalidate(clientId: string, headers: Headers): Promise<boolean>;
78
+ /**
79
+ * Delete a cache entry.
80
+ */
81
+ delete(clientId: string): Promise<boolean>;
82
+ /**
83
+ * Get conditional request headers for a cached entry.
84
+ */
85
+ getConditionalHeaders(clientId: string): Promise<Record<string, string> | undefined>;
86
+ /**
87
+ * Clear all cached entries.
88
+ */
89
+ clear(): Promise<void>;
90
+ /**
91
+ * Get the number of cached entries.
92
+ */
93
+ size(): Promise<number>;
94
+ /**
95
+ * Remove expired entries.
96
+ * Returns the number of entries removed.
97
+ */
98
+ cleanup(): Promise<number>;
99
+ /**
100
+ * Close the cache backend (for Redis connections).
101
+ */
102
+ close?(): Promise<void>;
103
+ }
104
+ /**
105
+ * Parse cache-relevant headers from a Response or Headers object.
106
+ */
107
+ export declare function extractCacheHeaders(headers: Headers): CacheableHeaders;
108
+ /**
109
+ * Parse cache headers and compute TTL.
110
+ *
111
+ * @param headers - Cache-relevant headers
112
+ * @param config - Cache configuration with min/max/default TTL
113
+ * @returns Object with computed TTL and conditional request headers
114
+ */
115
+ export declare function parseCacheHeaders(headers: CacheableHeaders, config: CimdCacheTtlConfig): {
116
+ ttlMs: number;
117
+ etag?: string;
118
+ lastModified?: string;
119
+ };
120
+ /**
121
+ * In-Memory CIMD document cache.
122
+ *
123
+ * Stores cached CIMD documents with HTTP cache-aware TTLs.
124
+ * Suitable for development and single-instance deployments.
125
+ */
126
+ export declare class InMemoryCimdCache implements CimdCacheBackend {
127
+ private cache;
128
+ protected readonly config: CimdCacheTtlConfig;
129
+ constructor(config?: Partial<CimdCacheConfig>);
130
+ /**
131
+ * Get a cached entry by client_id.
132
+ *
133
+ * @param clientId - The client_id URL
134
+ * @returns The cached entry if valid, or undefined
135
+ */
136
+ get(clientId: string): Promise<CimdCacheEntry | undefined>;
137
+ /**
138
+ * Get a stale entry for conditional revalidation.
139
+ *
140
+ * @param clientId - The client_id URL
141
+ * @returns The stale entry (even if expired), or undefined if not cached
142
+ */
143
+ getStale(clientId: string): Promise<CimdCacheEntry | undefined>;
144
+ /**
145
+ * Store a document in the cache.
146
+ *
147
+ * @param clientId - The client_id URL
148
+ * @param document - The metadata document
149
+ * @param headers - HTTP response headers
150
+ */
151
+ set(clientId: string, document: ClientMetadataDocument, headers: Headers): Promise<void>;
152
+ /**
153
+ * Update an existing cache entry (after 304 Not Modified).
154
+ *
155
+ * @param clientId - The client_id URL
156
+ * @param headers - New HTTP headers with updated cache directives
157
+ */
158
+ revalidate(clientId: string, headers: Headers): Promise<boolean>;
159
+ /**
160
+ * Delete a cache entry.
161
+ *
162
+ * @param clientId - The client_id URL
163
+ * @returns true if an entry was deleted
164
+ */
165
+ delete(clientId: string): Promise<boolean>;
166
+ /**
167
+ * Get conditional request headers for a cached entry.
168
+ *
169
+ * @param clientId - The client_id URL
170
+ * @returns Headers for conditional request, or undefined if not cached
171
+ */
172
+ getConditionalHeaders(clientId: string): Promise<Record<string, string> | undefined>;
173
+ /**
174
+ * Clear all cached entries.
175
+ */
176
+ clear(): Promise<void>;
177
+ /**
178
+ * Get the number of cached entries.
179
+ */
180
+ size(): Promise<number>;
181
+ /**
182
+ * Remove expired entries.
183
+ *
184
+ * @returns Number of entries removed
185
+ */
186
+ cleanup(): Promise<number>;
187
+ }
188
+ /**
189
+ * Backwards compatibility alias for CimdCache.
190
+ * @deprecated Use InMemoryCimdCache directly or createCimdCache factory.
191
+ */
192
+ export declare const CimdCache: typeof InMemoryCimdCache;
193
+ /**
194
+ * Factory function to create a CIMD cache backend.
195
+ *
196
+ * @param config - Cache configuration
197
+ * @returns A cache backend instance (InMemoryCimdCache or RedisCimdCache)
198
+ */
199
+ export declare function createCimdCache(config?: CimdCacheConfig): Promise<CimdCacheBackend>;
200
+ //# sourceMappingURL=cimd.cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cimd.cache.d.ts","sourceRoot":"","sources":["../../src/cimd/cimd.cache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,QAAQ,EAAE,sBAAsB,CAAC;IAEjC;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG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