@happyvertical/smrt-secrets 0.37.2 → 0.37.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.
@@ -1,378 +0,0 @@
1
- import { ObjectRegistry, foreignKey, crossPackageRef, smrt, SmrtObject } from "@happyvertical/smrt-core";
2
- ObjectRegistry.registerPackageManifest(
3
- new URL("./manifest.json", import.meta.url)
4
- );
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
7
- var __decorateClass$2 = (decorators, target, key, kind) => {
8
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
9
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
10
- if (decorator = decorators[i])
11
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
12
- if (kind && result) __defProp(target, key, result);
13
- return result;
14
- };
15
- let SecretAuditLog = class extends SmrtObject {
16
- /**
17
- * Tenant associated with the audited secret operation.
18
- */
19
- tenantId = null;
20
- secretId = null;
21
- /**
22
- * Name of the secret at the time of the operation
23
- */
24
- secretName = "";
25
- userId = null;
26
- /**
27
- * The action that was performed
28
- */
29
- action = "read";
30
- /**
31
- * Result of the operation
32
- */
33
- result = "success";
34
- /**
35
- * IP address of the client (if available)
36
- */
37
- ipAddress = "";
38
- /**
39
- * User agent string (if available)
40
- */
41
- userAgent = "";
42
- /**
43
- * Additional context about the operation
44
- */
45
- details = {};
46
- constructor(options = {}) {
47
- super(options);
48
- if (options.tenantId !== void 0) {
49
- this.tenantId = options.tenantId;
50
- }
51
- if (options.secretId !== void 0) this.secretId = options.secretId;
52
- if (options.secretName !== void 0) this.secretName = options.secretName;
53
- if (options.userId !== void 0) this.userId = options.userId;
54
- if (options.action !== void 0) this.action = options.action;
55
- if (options.result !== void 0) this.result = options.result;
56
- if (options.ipAddress !== void 0) this.ipAddress = options.ipAddress;
57
- if (options.userAgent !== void 0) this.userAgent = options.userAgent;
58
- if (options.details !== void 0) this.details = options.details;
59
- }
60
- /**
61
- * Check if this was a successful operation
62
- */
63
- isSuccess() {
64
- return this.result === "success";
65
- }
66
- /**
67
- * Check if this was a failed operation
68
- */
69
- isFailure() {
70
- return this.result === "failure";
71
- }
72
- /**
73
- * Check if this was a denied operation (permission denied)
74
- */
75
- isDenied() {
76
- return this.result === "denied";
77
- }
78
- /**
79
- * Check if this is a read operation
80
- */
81
- isReadAction() {
82
- return this.action === "read";
83
- }
84
- /**
85
- * Check if this is a write operation (create, update, delete)
86
- */
87
- isWriteAction() {
88
- return ["create", "update", "delete"].includes(this.action);
89
- }
90
- /**
91
- * Check if this is a key operation
92
- */
93
- isKeyOperation() {
94
- return this.action === "rotate_key";
95
- }
96
- };
97
- __decorateClass$2([
98
- foreignKey("Secret")
99
- ], SecretAuditLog.prototype, "secretId", 2);
100
- __decorateClass$2([
101
- crossPackageRef("@happyvertical/smrt-users:User")
102
- ], SecretAuditLog.prototype, "userId", 2);
103
- SecretAuditLog = __decorateClass$2([
104
- smrt({
105
- tenantScoped: true,
106
- api: { include: [] },
107
- // No API exposure
108
- mcp: { include: [] },
109
- // No MCP exposure
110
- // CLI runs in-process for compliance review; HTTP exposure is intentionally
111
- // excluded, so skipApiCheck acknowledges the cli.include / api.include divergence.
112
- cli: { include: ["list"], skipApiCheck: true }
113
- })
114
- ], SecretAuditLog);
115
- function createAuditEntry(params) {
116
- const tenantId = params.tenantId === void 0 || params.tenantId === "system" ? null : params.tenantId;
117
- const userId = params.userId == null || params.userId === "system" || params.userId === "" ? null : params.userId;
118
- const entry = {
119
- secretId: params.secretId ?? null,
120
- secretName: params.secretName,
121
- userId,
122
- action: params.action,
123
- result: params.result,
124
- ipAddress: params.ipAddress ?? "",
125
- userAgent: params.userAgent ?? "",
126
- details: params.details ?? {},
127
- tenantId
128
- };
129
- return entry;
130
- }
131
- var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
132
- var __decorateClass$1 = (decorators, target, key, kind) => {
133
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
134
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
135
- if (decorator = decorators[i])
136
- result = decorator(result) || result;
137
- return result;
138
- };
139
- let Secret = class extends SmrtObject {
140
- /**
141
- * Tenant that owns this secret. Also stored in context for per-tenant name uniqueness.
142
- */
143
- tenantId = "";
144
- /**
145
- * Unique name for the secret within the tenant
146
- */
147
- name = "";
148
- /**
149
- * Human-readable description
150
- */
151
- description = "";
152
- /**
153
- * Category for organization (e.g., 'database', 'api-key', 'oauth')
154
- */
155
- category = "";
156
- /**
157
- * JSON-encoded EncryptedEnvelope from @happyvertical/secrets
158
- */
159
- encryptedValue = "";
160
- /**
161
- * Version of the tenant key used to encrypt this secret
162
- */
163
- keyVersion = 1;
164
- /**
165
- * Current status of the secret
166
- */
167
- status = "active";
168
- /**
169
- * Optional expiration date
170
- */
171
- expiresAt = null;
172
- /**
173
- * Last time this secret was accessed (decrypted)
174
- */
175
- lastAccessedAt = null;
176
- /**
177
- * Number of times this secret has been accessed
178
- */
179
- accessCount = 0;
180
- /**
181
- * Additional metadata stored with the secret
182
- */
183
- metadata = {};
184
- constructor(options = {}) {
185
- super(options);
186
- if (options.tenantId !== void 0) this.tenantId = options.tenantId;
187
- if (options.name !== void 0) this.name = options.name;
188
- if (options.description !== void 0)
189
- this.description = options.description;
190
- if (options.category !== void 0) this.category = options.category;
191
- if (options.encryptedValue !== void 0)
192
- this.encryptedValue = options.encryptedValue;
193
- if (options.keyVersion !== void 0) this.keyVersion = options.keyVersion;
194
- if (options.status !== void 0) this.status = options.status;
195
- if (options.expiresAt !== void 0) {
196
- this.expiresAt = options.expiresAt instanceof Date ? options.expiresAt : options.expiresAt ? new Date(options.expiresAt) : null;
197
- }
198
- if (options.lastAccessedAt !== void 0) {
199
- this.lastAccessedAt = options.lastAccessedAt instanceof Date ? options.lastAccessedAt : options.lastAccessedAt ? new Date(options.lastAccessedAt) : null;
200
- }
201
- if (options.accessCount !== void 0)
202
- this.accessCount = options.accessCount;
203
- if (options.metadata !== void 0) this.metadata = options.metadata;
204
- }
205
- /**
206
- * Check if the secret is currently active
207
- */
208
- isActive() {
209
- return this.status === "active";
210
- }
211
- /**
212
- * Check if the secret has expired
213
- */
214
- isExpired() {
215
- if (!this.expiresAt) return false;
216
- return /* @__PURE__ */ new Date() >= this.expiresAt;
217
- }
218
- /**
219
- * Check if the secret can be used (active and not expired)
220
- */
221
- isUsable() {
222
- return this.isActive() && !this.isExpired();
223
- }
224
- /**
225
- * Record an access to this secret
226
- */
227
- recordAccess() {
228
- this.lastAccessedAt = /* @__PURE__ */ new Date();
229
- this.accessCount += 1;
230
- }
231
- /**
232
- * Disable the secret
233
- */
234
- disable() {
235
- this.status = "disabled";
236
- }
237
- /**
238
- * Enable the secret
239
- */
240
- enable() {
241
- this.status = "active";
242
- }
243
- };
244
- Secret = __decorateClass$1([
245
- smrt({
246
- tenantScoped: true,
247
- // NO API or MCP exposure for security
248
- api: { include: [] },
249
- mcp: { include: [] },
250
- // CLI runs in-process; secrets must never be reachable over HTTP, so
251
- // skipApiCheck acknowledges the cli.include / api.include divergence.
252
- cli: { include: ["list"], skipApiCheck: true }
253
- // Only list names, not values
254
- })
255
- ], Secret);
256
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
257
- var __decorateClass = (decorators, target, key, kind) => {
258
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
259
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
260
- if (decorator = decorators[i])
261
- result = decorator(result) || result;
262
- return result;
263
- };
264
- let TenantKey = class extends SmrtObject {
265
- /**
266
- * Tenant ID this key belongs to
267
- */
268
- tenantId = "";
269
- /**
270
- * Wrapped key data (format: wrappedKey:iv:authTag)
271
- */
272
- wrappedKey = "";
273
- /**
274
- * ID of the AMK used to wrap this key
275
- */
276
- amkKeyId = "";
277
- /**
278
- * Current status of the key
279
- */
280
- status = "active";
281
- /**
282
- * Version number (increments on rotation)
283
- */
284
- version = 1;
285
- /**
286
- * Recommended rotation date
287
- */
288
- rotateAfter = null;
289
- /**
290
- * When the key was retired (if applicable)
291
- */
292
- retiredAt = null;
293
- constructor(options = {}) {
294
- super(options);
295
- if (options.tenantId !== void 0) this.tenantId = options.tenantId;
296
- if (options.wrappedKey !== void 0) this.wrappedKey = options.wrappedKey;
297
- if (options.amkKeyId !== void 0) this.amkKeyId = options.amkKeyId;
298
- if (options.status !== void 0) this.status = options.status;
299
- if (options.version !== void 0) this.version = options.version;
300
- if (options.rotateAfter !== void 0) {
301
- this.rotateAfter = options.rotateAfter instanceof Date ? options.rotateAfter : options.rotateAfter ? new Date(options.rotateAfter) : null;
302
- }
303
- if (options.retiredAt !== void 0) {
304
- this.retiredAt = options.retiredAt instanceof Date ? options.retiredAt : options.retiredAt ? new Date(options.retiredAt) : null;
305
- }
306
- }
307
- /**
308
- * Check if this key is currently active
309
- */
310
- isActive() {
311
- return this.status === "active";
312
- }
313
- /**
314
- * Check if this key needs rotation
315
- */
316
- needsRotation() {
317
- if (!this.rotateAfter) return false;
318
- return /* @__PURE__ */ new Date() >= this.rotateAfter;
319
- }
320
- /**
321
- * Check if this key is retired
322
- */
323
- isRetired() {
324
- return this.status === "retired";
325
- }
326
- /**
327
- * Check if this key is compromised
328
- */
329
- isCompromised() {
330
- return this.status === "compromised";
331
- }
332
- /**
333
- * Check if this key can be used for decryption
334
- * (active or retired keys can decrypt)
335
- */
336
- canDecrypt() {
337
- return this.status === "active" || this.status === "retired";
338
- }
339
- /**
340
- * Check if this key can be used for encryption
341
- * (only active keys should encrypt)
342
- */
343
- canEncrypt() {
344
- return this.status === "active";
345
- }
346
- /**
347
- * Mark this key as retired
348
- */
349
- retire() {
350
- this.status = "retired";
351
- this.retiredAt = /* @__PURE__ */ new Date();
352
- }
353
- /**
354
- * Mark this key as compromised
355
- */
356
- markCompromised() {
357
- this.status = "compromised";
358
- }
359
- };
360
- TenantKey = __decorateClass([
361
- smrt({
362
- // NOT tenant-scoped - this model tracks keys FOR tenants
363
- api: { include: [] },
364
- // No API exposure
365
- mcp: { include: [] },
366
- // No MCP exposure
367
- // CLI runs in-process for key-rotation tooling and audit; HTTP exposure is
368
- // intentionally excluded, so skipApiCheck acknowledges the divergence.
369
- cli: { include: ["list", "get"], skipApiCheck: true }
370
- })
371
- ], TenantKey);
372
- export {
373
- Secret as S,
374
- TenantKey as T,
375
- SecretAuditLog as a,
376
- createAuditEntry as c
377
- };
378
- //# sourceMappingURL=TenantKey-Da_DXRSn.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TenantKey-Da_DXRSn.js","sources":["../../src/__smrt-register__.ts","../../src/models/SecretAuditLog.ts","../../src/models/Secret.ts","../../src/models/TenantKey.ts"],"sourcesContent":["/**\n * Self-registers this package's build-time manifest before any @smrt() decorator\n * in the package fires. Fixes issue #1132: in consumer runtimes (tsx, SvelteKit\n * SSR, plain `vite dev`) the decorator's synchronous manifest lookup previously\n * missed because no step populated the global manifest cache — classes got\n * registered with zero fields and `save()` / `toJSON()` silently dropped every\n * declared property.\n *\n * Import this module as the first statement in `src/index.ts` so its top-level\n * side effect runs ahead of any class module's @smrt() decorator.\n *\n * Silent no-op in dev/test, where the vitest plugin already populates manifests\n * via a different path. Only needs to succeed in the published dist output.\n *\n * @see https://github.com/happyvertical/smrt/issues/1132\n */\nimport { ObjectRegistry } from '@happyvertical/smrt-core';\n\n// `new URL('./manifest.json', import.meta.url)` resolves at runtime to the\n// manifest sitting next to this module's compiled output. Vite warns at build\n// time that it cannot pre-resolve the URL; that is the intended behavior —\n// the URL must resolve to dist/manifest.json at runtime, not be inlined.\nObjectRegistry.registerPackageManifest(\n new URL('./manifest.json', import.meta.url),\n);\n","/**\n * SecretAuditLog model - Audit trail for secret operations\n * @packageDocumentation\n */\n\nimport type {\n SmrtCreateInput,\n SmrtObjectOptions,\n} from '@happyvertical/smrt-core';\nimport {\n crossPackageRef,\n foreignKey,\n SmrtObject,\n smrt,\n} from '@happyvertical/smrt-core';\n\n/**\n * Secret audit action types\n */\nexport type SecretAuditAction =\n | 'create'\n | 'read'\n | 'update'\n | 'delete'\n | 'rotate_key'\n | 'disable'\n | 'enable'\n | 'expire';\n\n/**\n * Audit result types\n */\nexport type SecretAuditResult = 'success' | 'failure' | 'denied';\n\n/**\n * Constructor options for {@link SecretAuditLog}. Each field is optional and\n * mirrors a persisted column.\n */\nexport interface SecretAuditLogOptions extends SmrtObjectOptions {\n tenantId?: string | null;\n secretId?: string | null;\n secretName?: string;\n userId?: string | null;\n action?: SecretAuditAction;\n result?: SecretAuditResult;\n ipAddress?: string;\n userAgent?: string;\n details?: Record<string, unknown>;\n}\n\n/**\n * SecretAuditLog records all operations on secrets for compliance\n * and security monitoring.\n *\n * Every secret operation (create, read, update, delete, key rotation)\n * is logged with the user, action, result, and relevant details.\n *\n * **Retention**: Audit logs should be retained according to your\n * compliance requirements (typically 1-7 years).\n *\n * @example\n * ```typescript\n * // Query recent audit logs\n * const logs = await auditLogs.list({\n * where: { tenantId: 'tenant-123' },\n * orderBy: 'created_at DESC',\n * limit: 100\n * });\n *\n * // Filter by action\n * const reads = await auditLogs.list({\n * where: {\n * tenantId: 'tenant-123',\n * action: 'read'\n * }\n * });\n *\n * // Filter by secret name\n * const apiKeyLogs = await auditLogs.list({\n * where: {\n * tenantId: 'tenant-123',\n * secretName: 'stripe-api-key'\n * }\n * });\n * ```\n */\n// Intentional exception to standards.md §7 (`@TenantScoped({ mode: 'optional' })`):\n// `SecretAuditLog` uses the inline `tenantScoped: true` form on `@smrt()` rather than\n// the dedicated `@TenantScoped` decorator. Audit-trail queries are read-mostly and run\n// in mixed contexts — under a tenant for tenant-scoped reports, and (prospectively)\n// under super-admin bypass for compliance review. Cross-tenant audit queries should\n// be wrapped in `withSuperAdminBypass()` from `@happyvertical/smrt-tenancy` at the\n// call site; this package has no such call sites today, so the pattern is\n// prescriptive guidance for compliance tooling rather than current practice. See\n// `packages/secrets/CLAUDE.md` \"Known exceptions to monorepo standards\" for context.\n@smrt({\n tenantScoped: true,\n api: { include: [] }, // No API exposure\n mcp: { include: [] }, // No MCP exposure\n // CLI runs in-process for compliance review; HTTP exposure is intentionally\n // excluded, so skipApiCheck acknowledges the cli.include / api.include divergence.\n cli: { include: ['list'], skipApiCheck: true },\n})\nexport class SecretAuditLog extends SmrtObject {\n /**\n * Tenant associated with the audited secret operation.\n */\n tenantId: string | null = null;\n\n /**\n * ID of the secret (may be null for deleted secrets)\n */\n @foreignKey('Secret')\n secretId: string | null = null;\n\n /**\n * Name of the secret at the time of the operation\n */\n secretName: string = '';\n\n /**\n * ID of the user who performed the action, or `null` for system-initiated\n * operations with no authenticated user. Stored as a native `uuid` column on\n * Postgres, so a non-UUID actor sentinel must never reach it —\n * {@link createAuditEntry} normalizes the `'system'` sentinel to null (#1444).\n */\n @crossPackageRef('@happyvertical/smrt-users:User')\n userId: string | null = null;\n\n /**\n * The action that was performed\n */\n action: SecretAuditAction = 'read';\n\n /**\n * Result of the operation\n */\n result: SecretAuditResult = 'success';\n\n /**\n * IP address of the client (if available)\n */\n ipAddress: string = '';\n\n /**\n * User agent string (if available)\n */\n userAgent: string = '';\n\n /**\n * Additional context about the operation\n */\n details: Record<string, unknown> = {};\n\n constructor(options: SecretAuditLogOptions = {}) {\n super(options);\n if (options.tenantId !== undefined) {\n this.tenantId = options.tenantId;\n }\n if (options.secretId !== undefined) this.secretId = options.secretId;\n if (options.secretName !== undefined) this.secretName = options.secretName;\n if (options.userId !== undefined) this.userId = options.userId;\n if (options.action !== undefined) this.action = options.action;\n if (options.result !== undefined) this.result = options.result;\n if (options.ipAddress !== undefined) this.ipAddress = options.ipAddress;\n if (options.userAgent !== undefined) this.userAgent = options.userAgent;\n if (options.details !== undefined) this.details = options.details;\n }\n\n /**\n * Check if this was a successful operation\n */\n isSuccess(): boolean {\n return this.result === 'success';\n }\n\n /**\n * Check if this was a failed operation\n */\n isFailure(): boolean {\n return this.result === 'failure';\n }\n\n /**\n * Check if this was a denied operation (permission denied)\n */\n isDenied(): boolean {\n return this.result === 'denied';\n }\n\n /**\n * Check if this is a read operation\n */\n isReadAction(): boolean {\n return this.action === 'read';\n }\n\n /**\n * Check if this is a write operation (create, update, delete)\n */\n isWriteAction(): boolean {\n return ['create', 'update', 'delete'].includes(this.action);\n }\n\n /**\n * Check if this is a key operation\n */\n isKeyOperation(): boolean {\n return this.action === 'rotate_key';\n }\n}\n\n/**\n * Create an audit log entry for a secret operation\n */\nexport function createAuditEntry(params: {\n secretId?: string | null;\n secretName: string;\n tenantId?: string | null;\n userId?: string | null;\n action: SecretAuditAction;\n result: SecretAuditResult;\n ipAddress?: string;\n userAgent?: string;\n details?: Record<string, unknown>;\n}): SmrtCreateInput<SecretAuditLog> {\n const tenantId =\n params.tenantId === undefined || params.tenantId === 'system'\n ? null\n : params.tenantId;\n\n // The `userId` column is a native `uuid` on Postgres. A missing actor and the\n // `'system'`/empty sentinels are not valid UUIDs, so normalize them all to\n // null — a system-initiated operation has no authenticated user. Callers may\n // pass `null`/`undefined` directly to express that (#1444).\n const userId =\n params.userId == null ||\n params.userId === 'system' ||\n params.userId === ''\n ? null\n : params.userId;\n\n const entry: SmrtCreateInput<SecretAuditLog> = {\n secretId: params.secretId ?? null,\n secretName: params.secretName,\n userId,\n action: params.action,\n result: params.result,\n ipAddress: params.ipAddress ?? '',\n userAgent: params.userAgent ?? '',\n details: params.details ?? {},\n tenantId,\n };\n return entry;\n}\n","/**\n * Secret model - Tenant-scoped encrypted secrets storage\n * @packageDocumentation\n */\n\nimport type { SmrtObjectOptions } from '@happyvertical/smrt-core';\nimport { SmrtObject, smrt } from '@happyvertical/smrt-core';\n\n/**\n * Secret status values\n */\nexport type SecretStatus = 'active' | 'disabled' | 'expired';\n\n/**\n * Constructor options for {@link Secret}. Each field is optional and mirrors a\n * persisted column; date fields also accept the serialized forms accepted by\n * `new Date()` so hydrated rows coerce cleanly.\n */\nexport interface SecretOptions extends SmrtObjectOptions {\n tenantId?: string;\n name?: string;\n description?: string;\n category?: string;\n encryptedValue?: string;\n keyVersion?: number;\n status?: SecretStatus;\n expiresAt?: Date | string | number | null;\n lastAccessedAt?: Date | string | number | null;\n accessCount?: number;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Secret represents an encrypted value stored per-tenant.\n *\n * Secrets are tenant-scoped and use envelope encryption:\n * - Each tenant has their own Data Encryption Key (TDEK)\n * - The TDEK is wrapped by the Application Master Key (AMK)\n * - Secret values are encrypted by the unwrapped TDEK\n *\n * **Security**: This model deliberately excludes API and MCP exposure\n * to prevent accidental secret leakage. Secrets are only accessible\n * via CLI commands or direct service calls.\n *\n * @example\n * ```typescript\n * import { SecretService } from '@happyvertical/smrt-secrets';\n *\n * const service = await SecretService.create({ db });\n *\n * await withTenant({ tenantId: 'tenant-123' }, async () => {\n * // Store a secret\n * await service.store('api-key', 'sk_live_xxx', { category: 'stripe' });\n *\n * // Retrieve (auto-decrypts)\n * const apiKey = await service.retrieve('api-key');\n * });\n * ```\n */\n// Intentional exception to standards.md §7 (`@TenantScoped({ mode: 'optional' })`):\n// `Secret` uses the inline `tenantScoped: true` form on `@smrt()` rather than the\n// dedicated `@TenantScoped` decorator from `@happyvertical/smrt-tenancy`. The boolean\n// form gives us required-mode tenant scoping without depending on the tenancy package\n// at the model layer, while `SecretService` performs manual scoping by setting\n// `context = tenantId` on each row. The `(slug, context)` upsert key derived from the\n// base `SmrtObject` fields is what gives different tenants isolated namespaces for\n// secret names — switching to the decorator without changing the upsert key would\n// surface false-positive name collisions across tenants. See\n// `packages/secrets/CLAUDE.md` \"Known exceptions to monorepo standards\" for context.\n@smrt({\n tenantScoped: true,\n // NO API or MCP exposure for security\n api: { include: [] },\n mcp: { include: [] },\n // CLI runs in-process; secrets must never be reachable over HTTP, so\n // skipApiCheck acknowledges the cli.include / api.include divergence.\n cli: { include: ['list'], skipApiCheck: true }, // Only list names, not values\n})\nexport class Secret extends SmrtObject {\n /**\n * Tenant that owns this secret. Also stored in context for per-tenant name uniqueness.\n */\n tenantId: string = '';\n\n /**\n * Unique name for the secret within the tenant\n */\n name: string = '';\n\n /**\n * Human-readable description\n */\n description: string = '';\n\n /**\n * Category for organization (e.g., 'database', 'api-key', 'oauth')\n */\n category: string = '';\n\n /**\n * JSON-encoded EncryptedEnvelope from @happyvertical/secrets\n */\n encryptedValue: string = '';\n\n /**\n * Version of the tenant key used to encrypt this secret\n */\n keyVersion: number = 1;\n\n /**\n * Current status of the secret\n */\n status: SecretStatus = 'active';\n\n /**\n * Optional expiration date\n */\n expiresAt: Date | null = null;\n\n /**\n * Last time this secret was accessed (decrypted)\n */\n lastAccessedAt: Date | null = null;\n\n /**\n * Number of times this secret has been accessed\n */\n accessCount: number = 0;\n\n /**\n * Additional metadata stored with the secret\n */\n metadata: Record<string, unknown> = {};\n\n constructor(options: SecretOptions = {}) {\n super(options);\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n if (options.name !== undefined) this.name = options.name;\n if (options.description !== undefined)\n this.description = options.description;\n if (options.category !== undefined) this.category = options.category;\n if (options.encryptedValue !== undefined)\n this.encryptedValue = options.encryptedValue;\n if (options.keyVersion !== undefined) this.keyVersion = options.keyVersion;\n if (options.status !== undefined) this.status = options.status;\n if (options.expiresAt !== undefined) {\n this.expiresAt =\n options.expiresAt instanceof Date\n ? options.expiresAt\n : options.expiresAt\n ? new Date(options.expiresAt)\n : null;\n }\n if (options.lastAccessedAt !== undefined) {\n this.lastAccessedAt =\n options.lastAccessedAt instanceof Date\n ? options.lastAccessedAt\n : options.lastAccessedAt\n ? new Date(options.lastAccessedAt)\n : null;\n }\n if (options.accessCount !== undefined)\n this.accessCount = options.accessCount;\n if (options.metadata !== undefined) this.metadata = options.metadata;\n }\n\n /**\n * Check if the secret is currently active\n */\n isActive(): boolean {\n return this.status === 'active';\n }\n\n /**\n * Check if the secret has expired\n */\n isExpired(): boolean {\n if (!this.expiresAt) return false;\n return new Date() >= this.expiresAt;\n }\n\n /**\n * Check if the secret can be used (active and not expired)\n */\n isUsable(): boolean {\n return this.isActive() && !this.isExpired();\n }\n\n /**\n * Record an access to this secret\n */\n recordAccess(): void {\n this.lastAccessedAt = new Date();\n this.accessCount += 1;\n }\n\n /**\n * Disable the secret\n */\n disable(): void {\n this.status = 'disabled';\n }\n\n /**\n * Enable the secret\n */\n enable(): void {\n this.status = 'active';\n }\n}\n","/**\n * TenantKey model - Tracks per-tenant Data Encryption Keys (TDEKs)\n * @packageDocumentation\n */\n\nimport type { SmrtObjectOptions } from '@happyvertical/smrt-core';\nimport { SmrtObject, smrt } from '@happyvertical/smrt-core';\n\n/**\n * Key status values\n */\nexport type TenantKeyStatus = 'active' | 'rotating' | 'retired' | 'compromised';\n\n/**\n * Constructor options for {@link TenantKey}. Each field is optional and mirrors\n * a persisted column; date fields also accept the serialized forms accepted by\n * `new Date()` so hydrated rows coerce cleanly.\n */\nexport interface TenantKeyOptions extends SmrtObjectOptions {\n tenantId?: string;\n wrappedKey?: string;\n amkKeyId?: string;\n status?: TenantKeyStatus;\n version?: number;\n rotateAfter?: Date | string | number | null;\n retiredAt?: Date | string | number | null;\n}\n\n/**\n * TenantKey tracks the per-tenant Data Encryption Keys (TDEKs).\n *\n * Each tenant has one or more TDEKs stored in wrapped form. The wrapped key\n * can only be decrypted using the Application Master Key (AMK).\n *\n * **Key Lifecycle**:\n * 1. `active` - Current key used for encryption\n * 2. `rotating` - Transitional state during rotation\n * 3. `retired` - Old key kept for decryption of existing secrets\n * 4. `compromised` - Key marked as compromised, should not be used\n *\n * **Note**: This model is NOT tenant-scoped itself because it tracks\n * keys FOR tenants, not secrets owned BY tenants.\n *\n * @example\n * ```typescript\n * // Get active key for a tenant\n * const key = await tenantKeys.get({\n * tenantId: 'tenant-123',\n * status: 'active'\n * });\n *\n * // List all key versions for a tenant\n * const versions = await tenantKeys.list({\n * where: { tenantId: 'tenant-123' },\n * orderBy: 'version DESC'\n * });\n * ```\n */\n// Intentional exception to standards.md §7 (`@TenantScoped({ mode: 'optional' })`):\n// `TenantKey` is deliberately NOT tenant-scoped — neither via the decorator nor via\n// `tenantScoped: true` on `@smrt()`. The row carries a `tenantId` column because each\n// TDEK belongs to a tenant, but the model itself must remain queryable across tenants\n// (e.g. cross-tenant key-rotation tooling, AMK rewrap jobs, super-admin auditing).\n// Adding the tenancy interceptor here would silently filter out keys the rotation\n// service needs to inspect. See `packages/secrets/CLAUDE.md` \"Known exceptions to\n// monorepo standards\" for the full rationale.\n@smrt({\n // NOT tenant-scoped - this model tracks keys FOR tenants\n api: { include: [] }, // No API exposure\n mcp: { include: [] }, // No MCP exposure\n // CLI runs in-process for key-rotation tooling and audit; HTTP exposure is\n // intentionally excluded, so skipApiCheck acknowledges the divergence.\n cli: { include: ['list', 'get'], skipApiCheck: true },\n})\nexport class TenantKey extends SmrtObject {\n /**\n * Tenant ID this key belongs to\n */\n tenantId: string = '';\n\n /**\n * Wrapped key data (format: wrappedKey:iv:authTag)\n */\n wrappedKey: string = '';\n\n /**\n * ID of the AMK used to wrap this key\n */\n amkKeyId: string = '';\n\n /**\n * Current status of the key\n */\n status: TenantKeyStatus = 'active';\n\n /**\n * Version number (increments on rotation)\n */\n version: number = 1;\n\n /**\n * Recommended rotation date\n */\n rotateAfter: Date | null = null;\n\n /**\n * When the key was retired (if applicable)\n */\n retiredAt: Date | null = null;\n\n constructor(options: TenantKeyOptions = {}) {\n super(options);\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n if (options.wrappedKey !== undefined) this.wrappedKey = options.wrappedKey;\n if (options.amkKeyId !== undefined) this.amkKeyId = options.amkKeyId;\n if (options.status !== undefined) this.status = options.status;\n if (options.version !== undefined) this.version = options.version;\n if (options.rotateAfter !== undefined) {\n this.rotateAfter =\n options.rotateAfter instanceof Date\n ? options.rotateAfter\n : options.rotateAfter\n ? new Date(options.rotateAfter)\n : null;\n }\n if (options.retiredAt !== undefined) {\n this.retiredAt =\n options.retiredAt instanceof Date\n ? options.retiredAt\n : options.retiredAt\n ? new Date(options.retiredAt)\n : null;\n }\n }\n\n /**\n * Check if this key is currently active\n */\n isActive(): boolean {\n return this.status === 'active';\n }\n\n /**\n * Check if this key needs rotation\n */\n needsRotation(): boolean {\n if (!this.rotateAfter) return false;\n return new Date() >= this.rotateAfter;\n }\n\n /**\n * Check if this key is retired\n */\n isRetired(): boolean {\n return this.status === 'retired';\n }\n\n /**\n * Check if this key is compromised\n */\n isCompromised(): boolean {\n return this.status === 'compromised';\n }\n\n /**\n * Check if this key can be used for decryption\n * (active or retired keys can decrypt)\n */\n canDecrypt(): boolean {\n return this.status === 'active' || this.status === 'retired';\n }\n\n /**\n * Check if this key can be used for encryption\n * (only active keys should encrypt)\n */\n canEncrypt(): boolean {\n return this.status === 'active';\n }\n\n /**\n * Mark this key as retired\n */\n retire(): void {\n this.status = 'retired';\n this.retiredAt = new Date();\n }\n\n /**\n * Mark this key as compromised\n */\n markCompromised(): void {\n this.status = 'compromised';\n }\n}\n"],"names":["__decorateClass"],"mappings":";AAsBA,eAAe;AAAA,EACb,IAAA,IAAA,mBAAA,YAAA,GAAA;AACF;;;;;;;;;;;AC+EO,IAAM,iBAAN,cAA6B,WAAW;AAAA;AAAA;AAAA;AAAA,EAI7C,WAA0B;AAAA,EAM1B,WAA0B;AAAA;AAAA;AAAA;AAAA,EAK1B,aAAqB;AAAA,EASrB,SAAwB;AAAA;AAAA;AAAA;AAAA,EAKxB,SAA4B;AAAA;AAAA;AAAA;AAAA,EAK5B,SAA4B;AAAA;AAAA;AAAA;AAAA,EAK5B,YAAoB;AAAA;AAAA;AAAA;AAAA,EAKpB,YAAoB;AAAA;AAAA;AAAA;AAAA,EAKpB,UAAmC,CAAA;AAAA,EAEnC,YAAY,UAAiC,IAAI;AAC/C,UAAM,OAAO;AACb,QAAI,QAAQ,aAAa,QAAW;AAClC,WAAK,WAAW,QAAQ;AAAA,IAC1B;AACA,QAAI,QAAQ,aAAa,OAAW,MAAK,WAAW,QAAQ;AAC5D,QAAI,QAAQ,eAAe,OAAW,MAAK,aAAa,QAAQ;AAChE,QAAI,QAAQ,WAAW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AA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,aAAsB;AACpB,WAAO,KAAK,WAAW,YAAY,KAAK,WAAW;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,aAAsB;AACpB,WAAO,KAAK,WAAW;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKA,SAAe;AACb,SAAK,SAAS;AACd,SAAK,gCAAgB,KAAA;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,kBAAwB;AACtB,SAAK,SAAS;AAAA,EAChB;AACF;AAxHa,YAAN,gBAAA;AAAA,EARN,KAAK;AAAA;AAAA,IAEJ,KAAK,EAAE,SAAS,GAAC;AAAA;AAAA,IACjB,KAAK,EAAE,SAAS,GAAC;AAAA;AAAA;AAAA;AAAA,IAGjB,KAAK,EAAE,SAAS,CAAC,QAAQ,KAAK,GAAG,cAAc,KAAA;AAAA,EAAK,CACrD;AAAA,GACY,SAAA;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"SecretService.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}