@happyvertical/smrt-secrets 0.62.5 → 0.62.7
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/AGENTS.md +14 -0
- package/dist/chunks/ConnectState-DUeYDO6b.js +289 -0
- package/dist/chunks/ConnectState-DUeYDO6b.js.map +1 -0
- package/dist/chunks/{SecretService-CEvXX8bj.js → SecretService-DyzsJCio.js} +13 -116
- package/dist/chunks/SecretService-DyzsJCio.js.map +1 -0
- package/dist/chunks/TenantKey-p_gp_teA.js +356 -0
- package/dist/chunks/TenantKey-p_gp_teA.js.map +1 -0
- package/dist/chunks/dist-kZ2KUDiZ.js +129 -0
- package/dist/chunks/dist-kZ2KUDiZ.js.map +1 -0
- package/dist/collections/ConnectStateCollection.d.ts +20 -0
- package/dist/collections/ConnectStateCollection.d.ts.map +1 -0
- package/dist/collections/index.d.ts +1 -0
- package/dist/collections/index.d.ts.map +1 -1
- package/dist/connect/index.d.ts +7 -0
- package/dist/connect/index.d.ts.map +1 -0
- package/dist/connect/index.js +215 -0
- package/dist/connect/index.js.map +1 -0
- package/dist/connect/oauth.d.ts +46 -0
- package/dist/connect/oauth.d.ts.map +1 -0
- package/dist/connect/state.d.ts +57 -0
- package/dist/connect/state.d.ts.map +1 -0
- package/dist/connect/types.d.ts +65 -0
- package/dist/connect/types.d.ts.map +1 -0
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +447 -2
- package/dist/models/ConnectState.d.ts +42 -0
- package/dist/models/ConnectState.d.ts.map +1 -0
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +4 -2
- package/dist/services/SecretService.d.ts +8 -0
- package/dist/services/SecretService.d.ts.map +1 -1
- package/dist/services/SecretService.js +1 -1
- package/dist/smrt-knowledge.json +185 -8
- package/dist/smrt-knowledge.okf.md +5 -2
- package/package.json +12 -8
- package/dist/chunks/SecretService-CEvXX8bj.js.map +0 -1
- package/dist/chunks/TenantKey-rATrKLq9.js +0 -366
- package/dist/chunks/TenantKey-rATrKLq9.js.map +0 -1
package/AGENTS.md
CHANGED
|
@@ -29,10 +29,24 @@ no default key anywhere in this package.
|
|
|
29
29
|
| `retrieve(name)` | Decrypt + audit + increment accessCount |
|
|
30
30
|
| `diagnoseTenantSecretKeyDrift(tenantId)` | Report active secret/key drift without exposing values. Checks `secrets`, SDK `tenant_encryption_keys`, and SMRT `tenant_keys`. |
|
|
31
31
|
| `repairTenantSecretKeyDrift(tenantId, opts)` | Explicit repair path for unrecoverable drift. Use `dryRun` first; destructive cleanup requires `confirmDeleteUnrecoverableData: true`. |
|
|
32
|
+
| `storeForTenant` / `retrieveForTenant` / `deleteForTenant` | Explicit-tenant forms of `store` / `retrieve` / `delete` for integrations running outside the ambient tenant context. |
|
|
32
33
|
| `rotateKey()` | Create new TDEK, mark old as retired |
|
|
33
34
|
| `reencryptAll()` | Decrypt with old TDEK, re-encrypt with new — **must call separately after rotateKey()** |
|
|
34
35
|
| `disable(name)` / `enable(name)` | Toggle status |
|
|
35
36
|
|
|
37
|
+
## Credential connect (`@happyvertical/smrt-secrets/connect`)
|
|
38
|
+
|
|
39
|
+
Provider-neutral kernel shared by smrt-social and smrt-messages: `beginConnect` /
|
|
40
|
+
`consumeConnect` (single-use, tenant- and user-bound state; replay, wrong user,
|
|
41
|
+
wrong tenant, wrong redirect and expiry all fail with a neutral `ConnectError`),
|
|
42
|
+
PKCE helpers, `isSafeReturnPath`, and generic OAuth 2.0 / OIDC mechanics
|
|
43
|
+
(`buildOAuth2AuthorizeUrl`, `exchangeOAuth2Code`, `fetchOidcUserInfo`,
|
|
44
|
+
`discoverOidcEndpoints` which requires https and an exact issuer match).
|
|
45
|
+
`ConnectState` + `ConnectStateCollection.asStore()` are the shipped store
|
|
46
|
+
(generated REST/MCP/CLI off); a package may adapt its own table to
|
|
47
|
+
`ConnectStateStore` (smrt-social keeps `OAuthState` that way). No account
|
|
48
|
+
upsert or role checks here: the owning package does that.
|
|
49
|
+
|
|
36
50
|
## Gotchas
|
|
37
51
|
|
|
38
52
|
- **Key rotation doesn't auto-re-encrypt**: call `reencryptAll()` separately after `rotateKey()`
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { n as __decorate, t as createLogger } from "./dist-kZ2KUDiZ.js";
|
|
2
|
+
import { ObjectRegistry, SmrtObject, applyPendingDecoratorRegistrations, crossPackageRef, field, registerCompatibleFieldDecorator, smrt, toSnakeCase } from "@happyvertical/smrt-core";
|
|
3
|
+
//#region ../tenancy/dist/chunks/registry-DH0v5Efm.js
|
|
4
|
+
var logger = createLogger({ level: "info" });
|
|
5
|
+
var DEFAULT_CONFIG = {
|
|
6
|
+
mode: "required",
|
|
7
|
+
field: "tenantId",
|
|
8
|
+
autoFilter: true,
|
|
9
|
+
autoPopulate: true,
|
|
10
|
+
allowSuperAdminBypass: false
|
|
11
|
+
};
|
|
12
|
+
var tenantScopedClasses = /* @__PURE__ */ new Map();
|
|
13
|
+
var directSimpleRegistrations = /* @__PURE__ */ new Map();
|
|
14
|
+
var directQualifiedRegistrations = /* @__PURE__ */ new Map();
|
|
15
|
+
var directSimpleBindings = /* @__PURE__ */ new Map();
|
|
16
|
+
var unregisteredDecoratorRegistrations = /* @__PURE__ */ new Map();
|
|
17
|
+
var auditedSelectors = /* @__PURE__ */ new Set();
|
|
18
|
+
function isQualifiedClassName(className) {
|
|
19
|
+
return className.includes(":");
|
|
20
|
+
}
|
|
21
|
+
function isCurrentDirectSimpleBinding(binding) {
|
|
22
|
+
return ObjectRegistry.getClassByQualifiedName(binding.qualifiedName)?.constructor === binding.constructor;
|
|
23
|
+
}
|
|
24
|
+
function bindDirectSimpleRegistration(className) {
|
|
25
|
+
if (!directSimpleRegistrations.get(className) || directSimpleBindings.has(className)) return;
|
|
26
|
+
const matches = ObjectRegistry.findClassesByName(className);
|
|
27
|
+
if (matches.length !== 1 || !matches[0].qualifiedName) return;
|
|
28
|
+
directSimpleBindings.set(className, {
|
|
29
|
+
qualifiedName: matches[0].qualifiedName,
|
|
30
|
+
constructor: matches[0].constructor
|
|
31
|
+
});
|
|
32
|
+
warnOnRegistrationMismatch(className);
|
|
33
|
+
}
|
|
34
|
+
function getDirectSimpleRegistration(className) {
|
|
35
|
+
const config = directSimpleRegistrations.get(className);
|
|
36
|
+
if (!config) return void 0;
|
|
37
|
+
const binding = directSimpleBindings.get(className);
|
|
38
|
+
if (binding && !isCurrentDirectSimpleBinding(binding)) throw new Error(`Stale tenant-scoped class registration '${className}'; unregister and register it again for the current constructor.`);
|
|
39
|
+
if (ObjectRegistry.findClassesByName(className).length > 1) throw new Error(`Ambiguous tenant-scoped class registration '${className}'; register an explicit qualified class name instead.`);
|
|
40
|
+
return config;
|
|
41
|
+
}
|
|
42
|
+
function registerTenantScopedConstructor(target, config = {}) {
|
|
43
|
+
const resolved = {
|
|
44
|
+
...DEFAULT_CONFIG,
|
|
45
|
+
...config
|
|
46
|
+
};
|
|
47
|
+
unregisteredDecoratorRegistrations.set(target.name, resolved);
|
|
48
|
+
tenantScopedClasses.set(target.name, resolved);
|
|
49
|
+
}
|
|
50
|
+
function cloneConfig(config) {
|
|
51
|
+
return { ...config };
|
|
52
|
+
}
|
|
53
|
+
function getDirectTenantScopedConfig(className) {
|
|
54
|
+
const direct = getDeclaredTenantScopedConfig(className);
|
|
55
|
+
const qualifiedName = ObjectRegistry.getClass(className)?.qualifiedName;
|
|
56
|
+
if (direct && qualifiedName && ObjectRegistry.getRuntimeOverride(qualifiedName)?.tenancy) return {
|
|
57
|
+
...direct,
|
|
58
|
+
mode: "required"
|
|
59
|
+
};
|
|
60
|
+
return direct;
|
|
61
|
+
}
|
|
62
|
+
function getDeclaredTenantScopedConfig(className) {
|
|
63
|
+
ObjectRegistry.assertTenantScopedRegistrationValid(className);
|
|
64
|
+
const directQualified = directQualifiedRegistrations.get(className);
|
|
65
|
+
if (directQualified) {
|
|
66
|
+
if (!auditedSelectors.has(className)) warnOnRegistrationMismatch(className);
|
|
67
|
+
return cloneConfig(directQualified);
|
|
68
|
+
}
|
|
69
|
+
const registered = isQualifiedClassName(className) ? ObjectRegistry.getClassByQualifiedName(className) : ObjectRegistry.getClass(className);
|
|
70
|
+
if (registered) {
|
|
71
|
+
const simple = registered.name;
|
|
72
|
+
const bound = directSimpleBindings.get(simple);
|
|
73
|
+
if (bound) {
|
|
74
|
+
if (bound.qualifiedName === className && bound.constructor === registered.constructor) return cloneConfig(directSimpleRegistrations.get(simple));
|
|
75
|
+
if (!isCurrentDirectSimpleBinding(bound)) throw new Error(`Stale tenant-scoped class registration '${simple}'; unregister and register it again for the current constructor.`);
|
|
76
|
+
}
|
|
77
|
+
if (!bound && directSimpleRegistrations.has(simple)) {
|
|
78
|
+
if (ObjectRegistry.findClassesByName(simple).length > 1) throw new Error(`Ambiguous tenant-scoped class registration '${simple}'; register an explicit qualified class name instead.`);
|
|
79
|
+
bindDirectSimpleRegistration(simple);
|
|
80
|
+
const rebound = directSimpleBindings.get(simple);
|
|
81
|
+
if (rebound?.qualifiedName === className && rebound.constructor === registered.constructor) return cloneConfig(directSimpleRegistrations.get(simple));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (!isQualifiedClassName(className)) {
|
|
85
|
+
const directSimple = getDirectSimpleRegistration(className);
|
|
86
|
+
if (directSimple) return cloneConfig(directSimple);
|
|
87
|
+
}
|
|
88
|
+
const coreConfig = ObjectRegistry.getTenantScopedConfig(className);
|
|
89
|
+
if (coreConfig) return {
|
|
90
|
+
mode: coreConfig.mode,
|
|
91
|
+
field: coreConfig.field,
|
|
92
|
+
autoFilter: coreConfig.autoFilter,
|
|
93
|
+
autoPopulate: coreConfig.autoPopulate,
|
|
94
|
+
allowSuperAdminBypass: coreConfig.allowSuperAdminBypass
|
|
95
|
+
};
|
|
96
|
+
if (!registered && !isQualifiedClassName(className)) {
|
|
97
|
+
const decoratorConfig = unregisteredDecoratorRegistrations.get(className);
|
|
98
|
+
if (decoratorConfig) return cloneConfig(decoratorConfig);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function getInheritedTenantScopedConfig(className) {
|
|
102
|
+
const chain = ObjectRegistry.getInheritanceChain(className);
|
|
103
|
+
for (let i = chain.length - 2; i >= 0; i--) {
|
|
104
|
+
const ancestor = chain[i];
|
|
105
|
+
const direct = getDirectTenantScopedConfig(ancestor);
|
|
106
|
+
if (direct) return direct;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function getTenantScopedConfig(className) {
|
|
110
|
+
const direct = getDirectTenantScopedConfig(className);
|
|
111
|
+
if (direct) return direct;
|
|
112
|
+
return getInheritedTenantScopedConfig(className);
|
|
113
|
+
}
|
|
114
|
+
ObjectRegistry.registerOwnershipColumnSource((qualifiedName) => {
|
|
115
|
+
const config = getTenantScopedConfig(qualifiedName);
|
|
116
|
+
return config ? [toSnakeCase(config.field)] : void 0;
|
|
117
|
+
});
|
|
118
|
+
function resolveSelectorClass(selector) {
|
|
119
|
+
if (isQualifiedClassName(selector)) return ObjectRegistry.getClassByQualifiedName(selector);
|
|
120
|
+
const bound = directSimpleBindings.get(selector);
|
|
121
|
+
if (bound) return ObjectRegistry.getClassByQualifiedName(bound.qualifiedName);
|
|
122
|
+
const matches = ObjectRegistry.findClassesByName(selector);
|
|
123
|
+
return matches.length === 1 ? matches[0] : void 0;
|
|
124
|
+
}
|
|
125
|
+
function declaresFieldInChain(registered, fieldName) {
|
|
126
|
+
if (registered.fields.has(fieldName)) return true;
|
|
127
|
+
if (registered.inheritedFields?.has(fieldName)) return true;
|
|
128
|
+
const visited = /* @__PURE__ */ new Set([registered.constructor]);
|
|
129
|
+
let ctor = Object.getPrototypeOf(registered.constructor);
|
|
130
|
+
while (typeof ctor === "function" && !visited.has(ctor)) {
|
|
131
|
+
visited.add(ctor);
|
|
132
|
+
if (ObjectRegistry.getClassByConstructor(ctor)?.fields.has(fieldName)) return true;
|
|
133
|
+
ctor = Object.getPrototypeOf(ctor);
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
function auditSelector(selector, config) {
|
|
138
|
+
const registered = resolveSelectorClass(selector);
|
|
139
|
+
if (!registered) return [];
|
|
140
|
+
const className = registered.qualifiedName || registered.name;
|
|
141
|
+
const findings = [];
|
|
142
|
+
if (!declaresFieldInChain(registered, config.field)) {
|
|
143
|
+
findings.push({
|
|
144
|
+
selector,
|
|
145
|
+
className,
|
|
146
|
+
kind: "missing_tenant_field",
|
|
147
|
+
severity: "error",
|
|
148
|
+
message: `${className} is registered tenant-scoped on field '${config.field}', but the model declares no such field. Tenant filtering and population target a column its manifest and schema do not have. Add the field (or declare \`@smrt({ tenantScoped })\`) and regenerate the manifest.`
|
|
149
|
+
});
|
|
150
|
+
return findings;
|
|
151
|
+
}
|
|
152
|
+
if (!ObjectRegistry.getTenantScopedConfig(className)) findings.push({
|
|
153
|
+
selector,
|
|
154
|
+
className,
|
|
155
|
+
kind: "undeclared_tenant_scope",
|
|
156
|
+
severity: "info",
|
|
157
|
+
message: `${className} is tenant-scoped only by runtime registration; its manifest declares no tenancy. Declare \`@smrt({ tenantScoped })\` so schema, generated surfaces and knowledge agree with the read policy.`
|
|
158
|
+
});
|
|
159
|
+
const tenantColumn = toSnakeCase(config.field);
|
|
160
|
+
const conflictColumns = ObjectRegistry.getConflictColumns(className);
|
|
161
|
+
if (!(conflictColumns.length === 1 && conflictColumns[0] === "id") && !conflictColumns.includes(tenantColumn)) findings.push({
|
|
162
|
+
selector,
|
|
163
|
+
className,
|
|
164
|
+
kind: "natural_key_not_tenant_scoped",
|
|
165
|
+
severity: "warning",
|
|
166
|
+
message: `${className} is registered tenant-scoped, but its natural key (${conflictColumns.join(", ")}) omits '${tenantColumn}', so it is unique across tenants: a second tenant cannot store a key another tenant already uses. A new object saved on such a key is refused (TENANT_ISOLATION_VIOLATION) when the row it collides with has a different '${tenantColumn}'; one whose slug was derived from its name moves to a free slug instead. Include '${tenantColumn}' in the conflict columns (or drop the explicit conflictColumns) and run \`smrt db:migrate\`.`
|
|
167
|
+
});
|
|
168
|
+
return findings;
|
|
169
|
+
}
|
|
170
|
+
function warnOnRegistrationMismatch(selector) {
|
|
171
|
+
if (auditedSelectors.has(selector)) return;
|
|
172
|
+
const config = directQualifiedRegistrations.get(selector) ?? directSimpleRegistrations.get(selector);
|
|
173
|
+
if (!config) return;
|
|
174
|
+
let findings;
|
|
175
|
+
try {
|
|
176
|
+
findings = auditSelector(selector, config);
|
|
177
|
+
} catch {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (!resolveSelectorClass(selector)) return;
|
|
181
|
+
auditedSelectors.add(selector);
|
|
182
|
+
for (const finding of findings) {
|
|
183
|
+
if (finding.severity === "info") continue;
|
|
184
|
+
logger.warn(`[smrt-tenancy] ${finding.message}`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region ../tenancy/dist/decorators.js
|
|
189
|
+
function TenantScoped(options = {}) {
|
|
190
|
+
return (target, decoratorContext) => {
|
|
191
|
+
applyPendingDecoratorRegistrations(target, decoratorContext);
|
|
192
|
+
const config = {
|
|
193
|
+
mode: options.mode ?? "required",
|
|
194
|
+
field: options.field ?? "tenantId",
|
|
195
|
+
autoFilter: options.autoFilter ?? true,
|
|
196
|
+
autoPopulate: options.autoPopulate ?? true,
|
|
197
|
+
allowSuperAdminBypass: options.allowSuperAdminBypass ?? false
|
|
198
|
+
};
|
|
199
|
+
registerTenantScopedConstructor(target, config);
|
|
200
|
+
ObjectRegistry.reconcileTenantScopedConfig(target, {
|
|
201
|
+
mode: config.mode ?? "required",
|
|
202
|
+
field: config.field ?? "tenantId",
|
|
203
|
+
autoFilter: config.autoFilter ?? true,
|
|
204
|
+
autoPopulate: config.autoPopulate ?? true,
|
|
205
|
+
allowSuperAdminBypass: config.allowSuperAdminBypass ?? false
|
|
206
|
+
});
|
|
207
|
+
return target;
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function tenantId(options = {}) {
|
|
211
|
+
const opts = {
|
|
212
|
+
autoFilter: true,
|
|
213
|
+
required: true,
|
|
214
|
+
autoPopulate: true,
|
|
215
|
+
nullable: false,
|
|
216
|
+
...options
|
|
217
|
+
};
|
|
218
|
+
return ((targetOrValue, propertyKeyOrContext) => {
|
|
219
|
+
registerCompatibleFieldDecorator(targetOrValue, propertyKeyOrContext, (className, propertyKey, ctor) => {
|
|
220
|
+
const fieldOptions = {
|
|
221
|
+
type: "foreignKey",
|
|
222
|
+
related: "Tenant",
|
|
223
|
+
sqlType: "UUID",
|
|
224
|
+
required: opts.required,
|
|
225
|
+
nullable: opts.nullable,
|
|
226
|
+
...opts.required && !opts.nullable ? { requiredFor: "tenant-scope" } : {},
|
|
227
|
+
__tenancy: {
|
|
228
|
+
...opts,
|
|
229
|
+
isTenantIdField: true
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
ObjectRegistry.registerFieldDecorator(className, propertyKey, fieldOptions, ctor);
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/models/ConnectState.ts
|
|
238
|
+
var ConnectState = class ConnectState extends SmrtObject {
|
|
239
|
+
static __smrtPackage__ = "@happyvertical/smrt-secrets";
|
|
240
|
+
tenantId = null;
|
|
241
|
+
/** The provider or flow this state belongs to, for example `x` or `mail:stalwart`. */
|
|
242
|
+
kind = "";
|
|
243
|
+
/** The unguessable CSRF value round-tripped through the provider. */
|
|
244
|
+
state = "";
|
|
245
|
+
codeVerifier = null;
|
|
246
|
+
redirectUri = "";
|
|
247
|
+
scopes = [];
|
|
248
|
+
/** The user who started the connect; the callback must be made by the same user. */
|
|
249
|
+
initiatedByUserId = null;
|
|
250
|
+
/** A same-origin path to return to; the host validates before redirecting. */
|
|
251
|
+
returnTo = null;
|
|
252
|
+
expiresAt = new Date(Date.now() + 600 * 1e3);
|
|
253
|
+
constructor(options = {}) {
|
|
254
|
+
super(options);
|
|
255
|
+
if (options.tenantId !== void 0) this.tenantId = options.tenantId;
|
|
256
|
+
if (options.kind !== void 0) this.kind = options.kind;
|
|
257
|
+
if (options.state !== void 0) this.state = options.state;
|
|
258
|
+
if (options.codeVerifier !== void 0) this.codeVerifier = options.codeVerifier;
|
|
259
|
+
if (options.redirectUri !== void 0) this.redirectUri = options.redirectUri;
|
|
260
|
+
if (options.scopes !== void 0) this.scopes = options.scopes;
|
|
261
|
+
if (options.initiatedByUserId !== void 0) this.initiatedByUserId = options.initiatedByUserId;
|
|
262
|
+
if (options.returnTo !== void 0) this.returnTo = options.returnTo;
|
|
263
|
+
if (options.expiresAt !== void 0) this.expiresAt = options.expiresAt;
|
|
264
|
+
}
|
|
265
|
+
get isExpired() {
|
|
266
|
+
return Date.now() >= this.expiresAt.getTime();
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
__decorate([tenantId({ nullable: true })], ConnectState.prototype, "tenantId", void 0);
|
|
270
|
+
__decorate([field({ description: "The provider or flow this connect belongs to." })], ConnectState.prototype, "kind", void 0);
|
|
271
|
+
__decorate([field({ description: "The CSRF value sent to the provider." })], ConnectState.prototype, "state", void 0);
|
|
272
|
+
__decorate([field({
|
|
273
|
+
description: "The PKCE code verifier.",
|
|
274
|
+
sensitive: true
|
|
275
|
+
})], ConnectState.prototype, "codeVerifier", void 0);
|
|
276
|
+
__decorate([field({ description: "The callback URL the provider returns to." })], ConnectState.prototype, "redirectUri", void 0);
|
|
277
|
+
__decorate([field({ description: "The OAuth scopes requested." })], ConnectState.prototype, "scopes", void 0);
|
|
278
|
+
__decorate([crossPackageRef("@happyvertical/smrt-users:User")], ConnectState.prototype, "initiatedByUserId", void 0);
|
|
279
|
+
__decorate([field({ description: "The same-origin path to return to afterwards." })], ConnectState.prototype, "returnTo", void 0);
|
|
280
|
+
__decorate([field({ description: "When this connect link stops working." })], ConnectState.prototype, "expiresAt", void 0);
|
|
281
|
+
ConnectState = __decorate([TenantScoped({ mode: "optional" }), smrt({
|
|
282
|
+
api: false,
|
|
283
|
+
mcp: false,
|
|
284
|
+
cli: false
|
|
285
|
+
})], ConnectState);
|
|
286
|
+
//#endregion
|
|
287
|
+
export { ConnectState as t };
|
|
288
|
+
|
|
289
|
+
//# sourceMappingURL=ConnectState-DUeYDO6b.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectState-DUeYDO6b.js","names":[],"sources":["../../../tenancy/dist/chunks/registry-DH0v5Efm.js","../../../tenancy/dist/decorators.js","../../src/models/ConnectState.ts"],"sourcesContent":["import { ObjectRegistry, toSnakeCase } from \"@happyvertical/smrt-core\";\nimport { createLogger } from \"@happyvertical/logger\";\n//#region src/registry.ts\nvar logger = createLogger({ level: \"info\" });\nvar DEFAULT_CONFIG = {\n\tmode: \"required\",\n\tfield: \"tenantId\",\n\tautoFilter: true,\n\tautoPopulate: true,\n\tallowSuperAdminBypass: false\n};\nvar tenantScopedClasses = /* @__PURE__ */ new Map();\nvar directSimpleRegistrations = /* @__PURE__ */ new Map();\nvar directQualifiedRegistrations = /* @__PURE__ */ new Map();\nvar directSimpleBindings = /* @__PURE__ */ new Map();\nvar unregisteredDecoratorRegistrations = /* @__PURE__ */ new Map();\nvar auditedSelectors = /* @__PURE__ */ new Set();\nfunction isQualifiedClassName(className) {\n\treturn className.includes(\":\");\n}\nfunction isCurrentDirectSimpleBinding(binding) {\n\treturn ObjectRegistry.getClassByQualifiedName(binding.qualifiedName)?.constructor === binding.constructor;\n}\nfunction bindDirectSimpleRegistration(className) {\n\tif (!directSimpleRegistrations.get(className) || directSimpleBindings.has(className)) return;\n\tconst matches = ObjectRegistry.findClassesByName(className);\n\tif (matches.length !== 1 || !matches[0].qualifiedName) return;\n\tdirectSimpleBindings.set(className, {\n\t\tqualifiedName: matches[0].qualifiedName,\n\t\tconstructor: matches[0].constructor\n\t});\n\twarnOnRegistrationMismatch(className);\n}\nfunction getDirectSimpleRegistration(className) {\n\tconst config = directSimpleRegistrations.get(className);\n\tif (!config) return void 0;\n\tconst binding = directSimpleBindings.get(className);\n\tif (binding && !isCurrentDirectSimpleBinding(binding)) throw new Error(`Stale tenant-scoped class registration '${className}'; unregister and register it again for the current constructor.`);\n\tif (ObjectRegistry.findClassesByName(className).length > 1) throw new Error(`Ambiguous tenant-scoped class registration '${className}'; register an explicit qualified class name instead.`);\n\treturn config;\n}\nfunction registerTenantScopedConstructor(target, config = {}) {\n\tconst resolved = {\n\t\t...DEFAULT_CONFIG,\n\t\t...config\n\t};\n\tunregisteredDecoratorRegistrations.set(target.name, resolved);\n\ttenantScopedClasses.set(target.name, resolved);\n}\nfunction registerTenantScopedClass(className, config = {}) {\n\tconst resolved = {\n\t\t...DEFAULT_CONFIG,\n\t\t...config\n\t};\n\ttenantScopedClasses.set(className, resolved);\n\tauditedSelectors.delete(className);\n\tif (isQualifiedClassName(className)) {\n\t\tdirectQualifiedRegistrations.set(className, resolved);\n\t\twarnOnRegistrationMismatch(className);\n\t\treturn;\n\t}\n\tdirectSimpleRegistrations.set(className, resolved);\n\tconst existingBinding = directSimpleBindings.get(className);\n\tif (existingBinding && !isCurrentDirectSimpleBinding(existingBinding)) directSimpleBindings.delete(className);\n\tbindDirectSimpleRegistration(className);\n\twarnOnRegistrationMismatch(className);\n}\nfunction unregisterTenantScopedClass(className) {\n\tauditedSelectors.delete(className);\n\ttenantScopedClasses.delete(className);\n\tif (isQualifiedClassName(className)) {\n\t\tdirectQualifiedRegistrations.delete(className);\n\t\treturn;\n\t}\n\tdirectSimpleRegistrations.delete(className);\n\tdirectSimpleBindings.delete(className);\n\tunregisteredDecoratorRegistrations.delete(className);\n}\nfunction cloneConfig(config) {\n\treturn { ...config };\n}\nfunction getDirectTenantScopedConfig(className) {\n\tconst direct = getDeclaredTenantScopedConfig(className);\n\tconst qualifiedName = ObjectRegistry.getClass(className)?.qualifiedName;\n\tif (direct && qualifiedName && ObjectRegistry.getRuntimeOverride(qualifiedName)?.tenancy) return {\n\t\t...direct,\n\t\tmode: \"required\"\n\t};\n\treturn direct;\n}\nfunction getDeclaredTenantScopedConfig(className) {\n\tObjectRegistry.assertTenantScopedRegistrationValid(className);\n\tconst directQualified = directQualifiedRegistrations.get(className);\n\tif (directQualified) {\n\t\tif (!auditedSelectors.has(className)) warnOnRegistrationMismatch(className);\n\t\treturn cloneConfig(directQualified);\n\t}\n\tconst registered = isQualifiedClassName(className) ? ObjectRegistry.getClassByQualifiedName(className) : ObjectRegistry.getClass(className);\n\tif (registered) {\n\t\tconst simple = registered.name;\n\t\tconst bound = directSimpleBindings.get(simple);\n\t\tif (bound) {\n\t\t\tif (bound.qualifiedName === className && bound.constructor === registered.constructor) return cloneConfig(directSimpleRegistrations.get(simple));\n\t\t\tif (!isCurrentDirectSimpleBinding(bound)) throw new Error(`Stale tenant-scoped class registration '${simple}'; unregister and register it again for the current constructor.`);\n\t\t}\n\t\tif (!bound && directSimpleRegistrations.has(simple)) {\n\t\t\tif (ObjectRegistry.findClassesByName(simple).length > 1) throw new Error(`Ambiguous tenant-scoped class registration '${simple}'; register an explicit qualified class name instead.`);\n\t\t\tbindDirectSimpleRegistration(simple);\n\t\t\tconst rebound = directSimpleBindings.get(simple);\n\t\t\tif (rebound?.qualifiedName === className && rebound.constructor === registered.constructor) return cloneConfig(directSimpleRegistrations.get(simple));\n\t\t}\n\t}\n\tif (!isQualifiedClassName(className)) {\n\t\tconst directSimple = getDirectSimpleRegistration(className);\n\t\tif (directSimple) return cloneConfig(directSimple);\n\t}\n\tconst coreConfig = ObjectRegistry.getTenantScopedConfig(className);\n\tif (coreConfig) return {\n\t\tmode: coreConfig.mode,\n\t\tfield: coreConfig.field,\n\t\tautoFilter: coreConfig.autoFilter,\n\t\tautoPopulate: coreConfig.autoPopulate,\n\t\tallowSuperAdminBypass: coreConfig.allowSuperAdminBypass\n\t};\n\tif (!registered && !isQualifiedClassName(className)) {\n\t\tconst decoratorConfig = unregisteredDecoratorRegistrations.get(className);\n\t\tif (decoratorConfig) return cloneConfig(decoratorConfig);\n\t}\n}\nfunction getInheritedTenantScopedConfig(className) {\n\tconst chain = ObjectRegistry.getInheritanceChain(className);\n\tfor (let i = chain.length - 2; i >= 0; i--) {\n\t\tconst ancestor = chain[i];\n\t\tconst direct = getDirectTenantScopedConfig(ancestor);\n\t\tif (direct) return direct;\n\t}\n}\nfunction getTenantScopedConfig(className) {\n\tconst direct = getDirectTenantScopedConfig(className);\n\tif (direct) return direct;\n\treturn getInheritedTenantScopedConfig(className);\n}\nObjectRegistry.registerOwnershipColumnSource((qualifiedName) => {\n\tconst config = getTenantScopedConfig(qualifiedName);\n\treturn config ? [toSnakeCase(config.field)] : void 0;\n});\nfunction isTenantScopedClass(className) {\n\treturn getTenantScopedConfig(className) !== void 0;\n}\nfunction getAllTenantScopedClasses() {\n\treturn new Map(tenantScopedClasses);\n}\nfunction clearTenantScopedRegistry() {\n\tauditedSelectors.clear();\n\ttenantScopedClasses.clear();\n\tdirectSimpleRegistrations.clear();\n\tdirectQualifiedRegistrations.clear();\n\tdirectSimpleBindings.clear();\n\tunregisteredDecoratorRegistrations.clear();\n}\nfunction resolveSelectorClass(selector) {\n\tif (isQualifiedClassName(selector)) return ObjectRegistry.getClassByQualifiedName(selector);\n\tconst bound = directSimpleBindings.get(selector);\n\tif (bound) return ObjectRegistry.getClassByQualifiedName(bound.qualifiedName);\n\tconst matches = ObjectRegistry.findClassesByName(selector);\n\treturn matches.length === 1 ? matches[0] : void 0;\n}\nfunction declaresFieldInChain(registered, fieldName) {\n\tif (registered.fields.has(fieldName)) return true;\n\tif (registered.inheritedFields?.has(fieldName)) return true;\n\tconst visited = /* @__PURE__ */ new Set([registered.constructor]);\n\tlet ctor = Object.getPrototypeOf(registered.constructor);\n\twhile (typeof ctor === \"function\" && !visited.has(ctor)) {\n\t\tvisited.add(ctor);\n\t\tif (ObjectRegistry.getClassByConstructor(ctor)?.fields.has(fieldName)) return true;\n\t\tctor = Object.getPrototypeOf(ctor);\n\t}\n\treturn false;\n}\nfunction auditSelector(selector, config) {\n\tconst registered = resolveSelectorClass(selector);\n\tif (!registered) return [];\n\tconst className = registered.qualifiedName || registered.name;\n\tconst findings = [];\n\tif (!declaresFieldInChain(registered, config.field)) {\n\t\tfindings.push({\n\t\t\tselector,\n\t\t\tclassName,\n\t\t\tkind: \"missing_tenant_field\",\n\t\t\tseverity: \"error\",\n\t\t\tmessage: `${className} is registered tenant-scoped on field '${config.field}', but the model declares no such field. Tenant filtering and population target a column its manifest and schema do not have. Add the field (or declare \\`@smrt({ tenantScoped })\\`) and regenerate the manifest.`\n\t\t});\n\t\treturn findings;\n\t}\n\tif (!ObjectRegistry.getTenantScopedConfig(className)) findings.push({\n\t\tselector,\n\t\tclassName,\n\t\tkind: \"undeclared_tenant_scope\",\n\t\tseverity: \"info\",\n\t\tmessage: `${className} is tenant-scoped only by runtime registration; its manifest declares no tenancy. Declare \\`@smrt({ tenantScoped })\\` so schema, generated surfaces and knowledge agree with the read policy.`\n\t});\n\tconst tenantColumn = toSnakeCase(config.field);\n\tconst conflictColumns = ObjectRegistry.getConflictColumns(className);\n\tif (!(conflictColumns.length === 1 && conflictColumns[0] === \"id\") && !conflictColumns.includes(tenantColumn)) findings.push({\n\t\tselector,\n\t\tclassName,\n\t\tkind: \"natural_key_not_tenant_scoped\",\n\t\tseverity: \"warning\",\n\t\tmessage: `${className} is registered tenant-scoped, but its natural key (${conflictColumns.join(\", \")}) omits '${tenantColumn}', so it is unique across tenants: a second tenant cannot store a key another tenant already uses. A new object saved on such a key is refused (TENANT_ISOLATION_VIOLATION) when the row it collides with has a different '${tenantColumn}'; one whose slug was derived from its name moves to a free slug instead. Include '${tenantColumn}' in the conflict columns (or drop the explicit conflictColumns) and run \\`smrt db:migrate\\`.`\n\t});\n\treturn findings;\n}\nfunction auditTenantScopedRegistrations() {\n\tconst findings = [];\n\tfor (const [selector, config] of directQualifiedRegistrations) findings.push(...auditSelector(selector, config));\n\tfor (const [selector, config] of directSimpleRegistrations) findings.push(...auditSelector(selector, config));\n\treturn findings;\n}\nfunction warnOnRegistrationMismatch(selector) {\n\tif (auditedSelectors.has(selector)) return;\n\tconst config = directQualifiedRegistrations.get(selector) ?? directSimpleRegistrations.get(selector);\n\tif (!config) return;\n\tlet findings;\n\ttry {\n\t\tfindings = auditSelector(selector, config);\n\t} catch {\n\t\treturn;\n\t}\n\tif (!resolveSelectorClass(selector)) return;\n\tauditedSelectors.add(selector);\n\tfor (const finding of findings) {\n\t\tif (finding.severity === \"info\") continue;\n\t\tlogger.warn(`[smrt-tenancy] ${finding.message}`);\n\t}\n}\n//#endregion\nexport { isTenantScopedClass as a, unregisterTenantScopedClass as c, getTenantScopedConfig as i, clearTenantScopedRegistry as n, registerTenantScopedClass as o, getAllTenantScopedClasses as r, registerTenantScopedConstructor as s, auditTenantScopedRegistrations as t };\n\n//# sourceMappingURL=registry-DH0v5Efm.js.map","import { s as registerTenantScopedConstructor } from \"./chunks/registry-DH0v5Efm.js\";\nimport { ObjectRegistry, applyPendingDecoratorRegistrations, registerCompatibleFieldDecorator } from \"@happyvertical/smrt-core\";\n//#region src/decorators.ts\nfunction TenantScoped(options = {}) {\n\treturn (target, decoratorContext) => {\n\t\tapplyPendingDecoratorRegistrations(target, decoratorContext);\n\t\tconst config = {\n\t\t\tmode: options.mode ?? \"required\",\n\t\t\tfield: options.field ?? \"tenantId\",\n\t\t\tautoFilter: options.autoFilter ?? true,\n\t\t\tautoPopulate: options.autoPopulate ?? true,\n\t\t\tallowSuperAdminBypass: options.allowSuperAdminBypass ?? false\n\t\t};\n\t\tregisterTenantScopedConstructor(target, config);\n\t\tObjectRegistry.reconcileTenantScopedConfig(target, {\n\t\t\tmode: config.mode ?? \"required\",\n\t\t\tfield: config.field ?? \"tenantId\",\n\t\t\tautoFilter: config.autoFilter ?? true,\n\t\t\tautoPopulate: config.autoPopulate ?? true,\n\t\t\tallowSuperAdminBypass: config.allowSuperAdminBypass ?? false\n\t\t});\n\t\treturn target;\n\t};\n}\nfunction tenantId(options = {}) {\n\tconst opts = {\n\t\tautoFilter: true,\n\t\trequired: true,\n\t\tautoPopulate: true,\n\t\tnullable: false,\n\t\t...options\n\t};\n\treturn ((targetOrValue, propertyKeyOrContext) => {\n\t\tregisterCompatibleFieldDecorator(targetOrValue, propertyKeyOrContext, (className, propertyKey, ctor) => {\n\t\t\tconst fieldOptions = {\n\t\t\t\ttype: \"foreignKey\",\n\t\t\t\trelated: \"Tenant\",\n\t\t\t\tsqlType: \"UUID\",\n\t\t\t\trequired: opts.required,\n\t\t\t\tnullable: opts.nullable,\n\t\t\t\t...opts.required && !opts.nullable ? { requiredFor: \"tenant-scope\" } : {},\n\t\t\t\t__tenancy: {\n\t\t\t\t\t...opts,\n\t\t\t\t\tisTenantIdField: true\n\t\t\t\t}\n\t\t\t};\n\t\t\tObjectRegistry.registerFieldDecorator(className, propertyKey, fieldOptions, ctor);\n\t\t});\n\t});\n}\n//#endregion\nexport { TenantScoped, tenantId };\n\n//# sourceMappingURL=decorators.js.map","/**\n * ConnectState: one in-flight credential connect (OAuth 2.0 / OIDC redirect).\n * @packageDocumentation\n */\n\nimport type { SmrtObjectOptions } from '@happyvertical/smrt-core';\nimport {\n crossPackageRef,\n field,\n SmrtObject,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy/decorators';\n\nexport interface ConnectStateOptions extends SmrtObjectOptions {\n tenantId?: string | null;\n kind?: string;\n state?: string;\n codeVerifier?: string | null;\n redirectUri?: string;\n scopes?: string[];\n initiatedByUserId?: string | null;\n returnTo?: string | null;\n expiresAt?: Date;\n}\n\n/**\n * A single-use, tenant- and user-bound record that carries a connect across a\n * provider redirect: the CSRF state, the PKCE verifier, the redirect URI and\n * the signed-in user who started it. Created by `beginConnect`, burned by\n * `consumeConnect`. Never exposed through generated REST, MCP or CLI: the\n * verifier and state are credentials.\n */\n@TenantScoped({ mode: 'optional' })\n@smrt({\n api: false,\n mcp: false,\n cli: false,\n})\nexport class ConnectState extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-secrets\";\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n /** The provider or flow this state belongs to, for example `x` or `mail:stalwart`. */\n @field({ description: 'The provider or flow this connect belongs to.' })\n kind = '';\n\n /** The unguessable CSRF value round-tripped through the provider. */\n @field({ description: 'The CSRF value sent to the provider.' })\n state = '';\n\n @field({ description: 'The PKCE code verifier.', sensitive: true })\n codeVerifier: string | null = null;\n\n @field({ description: 'The callback URL the provider returns to.' })\n redirectUri = '';\n\n @field({ description: 'The OAuth scopes requested.' })\n scopes: string[] = [];\n\n /** The user who started the connect; the callback must be made by the same user. */\n @crossPackageRef('@happyvertical/smrt-users:User')\n initiatedByUserId: string | null = null;\n\n /** A same-origin path to return to; the host validates before redirecting. */\n @field({ description: 'The same-origin path to return to afterwards.' })\n returnTo: string | null = null;\n\n @field({ description: 'When this connect link stops working.' })\n expiresAt: Date = new Date(Date.now() + 10 * 60 * 1000);\n\n constructor(options: ConnectStateOptions = {}) {\n super(options);\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n if (options.kind !== undefined) this.kind = options.kind;\n if (options.state !== undefined) this.state = options.state;\n if (options.codeVerifier !== undefined)\n this.codeVerifier = options.codeVerifier;\n if (options.redirectUri !== undefined)\n this.redirectUri = options.redirectUri;\n if (options.scopes !== undefined) this.scopes = options.scopes;\n if (options.initiatedByUserId !== undefined)\n this.initiatedByUserId = options.initiatedByUserId;\n if (options.returnTo !== undefined) this.returnTo = options.returnTo;\n if (options.expiresAt !== undefined) this.expiresAt = options.expiresAt;\n }\n\n get isExpired(): boolean {\n return Date.now() >= this.expiresAt.getTime();\n }\n}\n"],"mappings":";;;AAGA,IAAI,SAAS,aAAa,EAAE,OAAO,OAAO,CAAC;AAC3C,IAAI,iBAAiB;CACpB,MAAM;CACN,OAAO;CACP,YAAY;CACZ,cAAc;CACd,uBAAuB;AACxB;AACA,IAAI,sCAAsC,IAAI,IAAI;AAClD,IAAI,4CAA4C,IAAI,IAAI;AACxD,IAAI,+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AE,aAAa,8BAA8B,CAAC,CAAA,GAAA,aAAA,WAAA,UAAA,KAAA,CAAA;YAIpD,gBAAgB,gCAAgC,CAAA,GAAA,aAAA,WAAA,qBAAA,KAAA,CAAA;YAIhD,MAAM,EAAE,aAAa,gDAAgD,CAAC,CAAA,GAAA,aAAA,WAAA,YAAA,KAAA,CAAA;YAGtE,MAAM,EAAE,aAAa,wCAAwC,CAAC,CAAA,GAAA,aAAA,WAAA,aAAA,KAAA,CAAA;2BAnChE,aAAa,EAAE,MAAM,WAAW,CAAC,GACjC,KAAK;CACJ,KAAK;CACL,KAAK;CACL,KAAK;AACP,CAAC,CAAA,GAAA,YAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as createLogger } from "./dist-kZ2KUDiZ.js";
|
|
2
|
+
import { i as createAuditEntry, n as Secret, r as SecretAuditLog, t as TenantKey } from "./TenantKey-p_gp_teA.js";
|
|
2
3
|
import { SmrtCollection } from "@happyvertical/smrt-core";
|
|
3
4
|
import { AMKUnavailableError, DecryptionError, EncryptionError, EnvelopeEncryption, TenantKeyMissingError, getSecretStore } from "@happyvertical/secrets";
|
|
4
|
-
import { loadEnvConfig } from "@happyvertical/utils";
|
|
5
5
|
import { getCurrentTenant, requireTenantId, withTenant } from "@happyvertical/smrt-tenancy";
|
|
6
6
|
//#region src/collections/SecretAuditLogCollection.ts
|
|
7
7
|
/**
|
|
@@ -367,119 +367,6 @@ var TenantKeyCollection = class extends SmrtCollection {
|
|
|
367
367
|
}
|
|
368
368
|
};
|
|
369
369
|
//#endregion
|
|
370
|
-
//#region ../../node_modules/.pnpm/@happyvertical+logger@0.113.0_@sentry+node@10.75.0_@opentelemetry+core@2.11.0_@opentele_b8affd7802c3f874a0bff86b77c43e92/node_modules/@happyvertical/logger/dist/index.js
|
|
371
|
-
/**
|
|
372
|
-
* Console-based logger with level filtering
|
|
373
|
-
*
|
|
374
|
-
* Logs are written to console with appropriate severity levels.
|
|
375
|
-
* Messages are only output if they meet the configured log level threshold.
|
|
376
|
-
*
|
|
377
|
-
* @example
|
|
378
|
-
* ```typescript
|
|
379
|
-
* const logger = new ConsoleLogger('info');
|
|
380
|
-
* logger.debug('Debug message'); // Not output (below 'info')
|
|
381
|
-
* logger.info('Info message'); // Output
|
|
382
|
-
* logger.error('Error message'); // Output
|
|
383
|
-
* ```
|
|
384
|
-
*/
|
|
385
|
-
var ConsoleLogger = class ConsoleLogger {
|
|
386
|
-
level;
|
|
387
|
-
static LEVELS = [
|
|
388
|
-
"debug",
|
|
389
|
-
"info",
|
|
390
|
-
"warn",
|
|
391
|
-
"error"
|
|
392
|
-
];
|
|
393
|
-
constructor(level = "info") {
|
|
394
|
-
this.level = level;
|
|
395
|
-
}
|
|
396
|
-
/**
|
|
397
|
-
* Check if a log level should be output
|
|
398
|
-
*
|
|
399
|
-
* @param level - Log level to check
|
|
400
|
-
* @returns True if level meets threshold
|
|
401
|
-
*/
|
|
402
|
-
shouldLog(level) {
|
|
403
|
-
const currentIndex = ConsoleLogger.LEVELS.indexOf(this.level);
|
|
404
|
-
return ConsoleLogger.LEVELS.indexOf(level) >= currentIndex;
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Format context for console output
|
|
408
|
-
*
|
|
409
|
-
* @param context - Structured metadata
|
|
410
|
-
* @returns Formatted context string
|
|
411
|
-
*/
|
|
412
|
-
formatContext(context) {
|
|
413
|
-
if (!context || Object.keys(context).length === 0) return "";
|
|
414
|
-
return ` ${JSON.stringify(context)}`;
|
|
415
|
-
}
|
|
416
|
-
debug(message, context) {
|
|
417
|
-
if (this.shouldLog("debug")) console.debug(`[DEBUG] ${message}${this.formatContext(context)}`);
|
|
418
|
-
}
|
|
419
|
-
info(message, context) {
|
|
420
|
-
if (this.shouldLog("info")) console.info(`[INFO] ${message}${this.formatContext(context)}`);
|
|
421
|
-
}
|
|
422
|
-
warn(message, context) {
|
|
423
|
-
if (this.shouldLog("warn")) console.warn(`[WARN] ${message}${this.formatContext(context)}`);
|
|
424
|
-
}
|
|
425
|
-
error(message, context) {
|
|
426
|
-
if (this.shouldLog("error")) console.error(`[ERROR] ${message}${this.formatContext(context)}`);
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
/**
|
|
430
|
-
* No-op logger that discards all log messages
|
|
431
|
-
*
|
|
432
|
-
* Used when logging is disabled (config: false)
|
|
433
|
-
*/
|
|
434
|
-
var NoopLogger = class {
|
|
435
|
-
debug(_message, _context) {}
|
|
436
|
-
info(_message, _context) {}
|
|
437
|
-
warn(_message, _context) {}
|
|
438
|
-
error(_message, _context) {}
|
|
439
|
-
};
|
|
440
|
-
/**
|
|
441
|
-
* Create a logger from configuration
|
|
442
|
-
*
|
|
443
|
-
* Supports environment variable configuration via HAVE_LOGGER_LEVEL.
|
|
444
|
-
* User-provided options take precedence over environment variables.
|
|
445
|
-
*
|
|
446
|
-
* @param config - Logger configuration (boolean or object)
|
|
447
|
-
* @returns Configured logger instance
|
|
448
|
-
*
|
|
449
|
-
* @example
|
|
450
|
-
* ```typescript
|
|
451
|
-
* // Console logger with 'info' level (default)
|
|
452
|
-
* const logger1 = createLogger(true);
|
|
453
|
-
*
|
|
454
|
-
* // Console logger with level from HAVE_LOGGER_LEVEL env var
|
|
455
|
-
* process.env.HAVE_LOGGER_LEVEL = 'debug';
|
|
456
|
-
* const logger2 = createLogger(true); // Uses 'debug' from env
|
|
457
|
-
*
|
|
458
|
-
* // No-op logger (all log calls are discarded)
|
|
459
|
-
* const logger3 = createLogger(false);
|
|
460
|
-
*
|
|
461
|
-
* // Console logger with 'debug' level (overrides env)
|
|
462
|
-
* const logger4 = createLogger({ level: 'debug' });
|
|
463
|
-
*
|
|
464
|
-
* // Custom log level (user options take precedence)
|
|
465
|
-
* process.env.HAVE_LOGGER_LEVEL = 'info';
|
|
466
|
-
* const logger5 = createLogger({ level: 'warn' }); // Uses 'warn' not 'info'
|
|
467
|
-
* ```
|
|
468
|
-
*/
|
|
469
|
-
function createLogger(config) {
|
|
470
|
-
if (typeof config === "boolean") {
|
|
471
|
-
if (!config) return new NoopLogger();
|
|
472
|
-
return new ConsoleLogger(loadEnvConfig({}, {
|
|
473
|
-
packageName: "logger",
|
|
474
|
-
schema: { level: "string" }
|
|
475
|
-
}).level || "info");
|
|
476
|
-
}
|
|
477
|
-
return new ConsoleLogger(loadEnvConfig(config, {
|
|
478
|
-
packageName: "logger",
|
|
479
|
-
schema: { level: "string" }
|
|
480
|
-
}).level || "info");
|
|
481
|
-
}
|
|
482
|
-
//#endregion
|
|
483
370
|
//#region src/services/SecretService.ts
|
|
484
371
|
var logger = createLogger({ level: "info" });
|
|
485
372
|
/**
|
|
@@ -967,6 +854,16 @@ var SecretService = class SecretService {
|
|
|
967
854
|
}
|
|
968
855
|
}
|
|
969
856
|
/**
|
|
857
|
+
* Delete a secret for a specific tenant.
|
|
858
|
+
*
|
|
859
|
+
* The explicit-tenant counterpart of {@link SecretService.delete}, for
|
|
860
|
+
* integrations that resolved tenant ownership but run outside the ambient
|
|
861
|
+
* tenant context. Returns `false` when the tenant has no such secret.
|
|
862
|
+
*/
|
|
863
|
+
async deleteForTenant(tenantId, name, options = {}) {
|
|
864
|
+
return withTenant({ tenantId }, () => this.delete(name, options));
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
970
867
|
* Disable a secret (soft delete)
|
|
971
868
|
*/
|
|
972
869
|
async disable(name) {
|
|
@@ -1243,4 +1140,4 @@ var SecretService = class SecretService {
|
|
|
1243
1140
|
//#endregion
|
|
1244
1141
|
export { SecretAuditLogCollection as a, SecretCollection as i, SecretService as n, TenantKeyCollection as r, SecretKeyDriftError as t };
|
|
1245
1142
|
|
|
1246
|
-
//# sourceMappingURL=SecretService-
|
|
1143
|
+
//# sourceMappingURL=SecretService-DyzsJCio.js.map
|