@opengeni/contracts 3.1.2 → 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1384 @@
1
+ import {
2
+ defineSchema
3
+ } from "./chunk-56SNIMDO.js";
4
+
5
+ // src/vault-provider-wire.ts
6
+ import { z as z3 } from "zod";
7
+
8
+ // src/vaults.ts
9
+ import { z as z2 } from "zod";
10
+
11
+ // src/secret-generator.ts
12
+ import { z } from "zod";
13
+ var SECRET_GENERATOR_DEFAULT_SYMBOLS = "!#%+-.:=?@_";
14
+ var SECRET_GENERATOR_AMBIGUOUS_CHARACTERS = "0O1lI|";
15
+ var LOWERCASE = "abcdefghijklmnopqrstuvwxyz";
16
+ var UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
17
+ var DIGITS = "0123456789";
18
+ function isPrintableAscii(value) {
19
+ for (let index = 0; index < value.length; index += 1) {
20
+ const code = value.charCodeAt(index);
21
+ if (code < 33 || code > 126) return false;
22
+ }
23
+ return true;
24
+ }
25
+ var GeneratePasswordSpec = /* @__PURE__ */ defineSchema(
26
+ () => z.object({
27
+ length: z.number().int().min(8).max(128).default(24),
28
+ lowercase: z.boolean().default(true),
29
+ uppercase: z.boolean().default(true),
30
+ digits: z.boolean().default(true),
31
+ symbols: z.boolean().default(true),
32
+ // No quotes, $, `, \, braces, /, &, ; or | by default: generated values
33
+ // stay safe to paste into shells, URLs and config files.
34
+ symbolSet: z.string().min(1).max(64).refine(isPrintableAscii, "symbolSet must be printable ASCII without spaces").default(SECRET_GENERATOR_DEFAULT_SYMBOLS),
35
+ excludeAmbiguous: z.boolean().default(true),
36
+ requireEachClass: z.boolean().default(true)
37
+ }).strict().refine(
38
+ (spec) => spec.lowercase || spec.uppercase || spec.digits || spec.symbols,
39
+ "at least one character class must be enabled"
40
+ )
41
+ );
42
+ var PasswordGeneratorError = class extends Error {
43
+ constructor(message) {
44
+ super(message);
45
+ this.name = "PasswordGeneratorError";
46
+ }
47
+ };
48
+ function defaultRandom(n) {
49
+ const bytes = new Uint8Array(n);
50
+ globalThis.crypto.getRandomValues(bytes);
51
+ return bytes;
52
+ }
53
+ function uniqueCharacters(value) {
54
+ return [...new Set(value)].join("");
55
+ }
56
+ function passwordCharacterClasses(spec) {
57
+ const ambiguous = spec.excludeAmbiguous ? new Set(SECRET_GENERATOR_AMBIGUOUS_CHARACTERS) : null;
58
+ const strip = (alphabet) => uniqueCharacters(alphabet).split("").filter((character) => !ambiguous?.has(character)).join("");
59
+ const classes = [];
60
+ if (spec.lowercase) classes.push(strip(LOWERCASE));
61
+ if (spec.uppercase) classes.push(strip(UPPERCASE));
62
+ if (spec.digits) classes.push(strip(DIGITS));
63
+ if (spec.symbols) classes.push(strip(spec.symbolSet));
64
+ return classes.filter((characters) => characters.length > 0);
65
+ }
66
+ function uniformIndexes(count, size, random) {
67
+ if (size < 1 || size > 256) throw new PasswordGeneratorError("alphabet size out of range");
68
+ const limit = 256 - 256 % size;
69
+ const out = [];
70
+ let guard = 0;
71
+ while (out.length < count) {
72
+ const bytes = random(Math.max(16, (count - out.length) * 2));
73
+ for (const byte of bytes) {
74
+ if (byte < limit) out.push(byte % size);
75
+ if (out.length === count) break;
76
+ }
77
+ guard += 1;
78
+ if (guard > 1e4) throw new PasswordGeneratorError("random source is not producing entropy");
79
+ }
80
+ return out;
81
+ }
82
+ function generatePassword(spec, random = defaultRandom) {
83
+ const parsed = GeneratePasswordSpec.parse(spec ?? {});
84
+ const classes = passwordCharacterClasses(parsed);
85
+ if (classes.length === 0) throw new PasswordGeneratorError("no characters available");
86
+ const alphabet = uniqueCharacters(classes.join(""));
87
+ const requireClasses = parsed.requireEachClass ? classes : [];
88
+ if (requireClasses.length > parsed.length) {
89
+ throw new PasswordGeneratorError("length is shorter than the number of required classes");
90
+ }
91
+ for (let attempt = 0; attempt < 1e3; attempt += 1) {
92
+ const password = uniformIndexes(parsed.length, alphabet.length, random).map((index) => alphabet[index]).join("");
93
+ if (requireClasses.every((characters) => [...password].some((c) => characters.includes(c)))) {
94
+ return password;
95
+ }
96
+ }
97
+ throw new PasswordGeneratorError("could not satisfy the character class requirements");
98
+ }
99
+ function passwordStrength(password) {
100
+ let pool = 0;
101
+ if (/[a-z]/.test(password)) pool += 26;
102
+ if (/[A-Z]/.test(password)) pool += 26;
103
+ if (/[0-9]/.test(password)) pool += 10;
104
+ if (/[^a-zA-Z0-9]/.test(password)) pool += 33;
105
+ const length = [...password].length;
106
+ const bits = pool === 0 ? 0 : Math.round(length * Math.log2(pool) * 10) / 10;
107
+ const label = bits < 40 ? "weak" : bits < 60 ? "fair" : bits < 100 ? "strong" : "very_strong";
108
+ return { bits, label };
109
+ }
110
+
111
+ // src/vaults.ts
112
+ var VaultOwnerKind = /* @__PURE__ */ defineSchema(
113
+ () => z2.enum(["user", "workspace", "organization", "task"])
114
+ );
115
+ var VaultSource = /* @__PURE__ */ defineSchema(
116
+ () => z2.enum(["opengeni", "onepassword", "host", "external", "protonpass", "keeper", "bitwarden"])
117
+ );
118
+ var VaultMode = /* @__PURE__ */ defineSchema(() => z2.enum(["read_write", "read_only"]));
119
+ var VaultSyncStatus = /* @__PURE__ */ defineSchema(
120
+ () => z2.enum(["ok", "syncing", "error", "auth_expired", "rate_limited"])
121
+ );
122
+ var VaultItemType = /* @__PURE__ */ defineSchema(
123
+ () => z2.enum(["login", "api_key", "note", "file", "passkey"])
124
+ );
125
+ var VaultFieldKind = /* @__PURE__ */ defineSchema(
126
+ () => z2.enum(["text", "concealed", "totp", "file"])
127
+ );
128
+ var VaultProviderOperations = /* @__PURE__ */ defineSchema(
129
+ () => z2.object({
130
+ createItemTypes: z2.array(VaultItemType).max(5),
131
+ updateItem: z2.boolean(),
132
+ removeField: z2.boolean(),
133
+ archiveItem: z2.boolean(),
134
+ archiveKind: z2.enum(["archive", "trash", "none"]),
135
+ /** Permanent provider deletion is deliberately not exposed. */
136
+ deleteItem: z2.literal(false),
137
+ restoreItem: z2.boolean(),
138
+ readFiles: z2.boolean(),
139
+ writeFiles: z2.boolean(),
140
+ createTotp: z2.boolean(),
141
+ updateTotp: z2.boolean(),
142
+ createVault: z2.boolean(),
143
+ restoreFieldHistory: z2.boolean()
144
+ }).strict()
145
+ );
146
+ var VaultProviderFreshness = /* @__PURE__ */ defineSchema(
147
+ () => z2.object({
148
+ state: z2.enum(["current", "stale", "refreshing", "unavailable"]),
149
+ lastCheckedAt: z2.string().datetime().nullable(),
150
+ sourceSyncedAt: z2.string().datetime().nullable(),
151
+ source: z2.enum(["live", "cache", "unknown"]),
152
+ errorCode: z2.string().max(100).nullable(),
153
+ retryAt: z2.string().datetime().nullable()
154
+ }).strict()
155
+ );
156
+ var VAULT_LOOKUP_TIERS = ["task", "user", "workspace", "organization"];
157
+ var VAULT_LIMITS = {
158
+ vaultsPerOwnerScope: 200,
159
+ itemsPerVault: 2e3,
160
+ fieldsPerItem: 50,
161
+ versionsPerField: 10,
162
+ nameMaxChars: 120,
163
+ descriptionMaxChars: 2e3,
164
+ websitesPerItem: 20,
165
+ websiteMaxChars: 2048,
166
+ textValueMaxBytes: 65536,
167
+ fileValueMaxBytes: 262144,
168
+ referenceMaxChars: 300,
169
+ execEnvMaxBytes: 262144,
170
+ execValueMaxBytes: 102400,
171
+ policyVaultIdsMax: 200,
172
+ searchResultsMax: 50,
173
+ /** Items one agent search call examines before it returns a cursor. */
174
+ searchScanMax: 1e3,
175
+ searchCursorMaxChars: 1024,
176
+ providerReadsPerAttempt: 50,
177
+ providerValueCacheMs: 6e4
178
+ };
179
+ var DEFAULT_VAULT_NAMES = {
180
+ user: "Private",
181
+ workspace: "Shared",
182
+ task: "Task"
183
+ };
184
+ var VAULT_DEFAULT_PRIMARY_FIELD = {
185
+ login: "password",
186
+ api_key: "value",
187
+ note: "note",
188
+ file: "file",
189
+ passkey: null
190
+ };
191
+ var PASSKEY_FIELD_NAMES = [
192
+ "rpId",
193
+ "credentialId",
194
+ "userHandle",
195
+ "userName",
196
+ "privateKey"
197
+ ];
198
+ var FORBIDDEN_NAME_CHARACTERS = /[/{}#\\\u0000-\u001f\u007f-\u009f]/;
199
+ function isValidSecretName(name) {
200
+ if (typeof name !== "string") return false;
201
+ const length = [...name].length;
202
+ if (length < 1 || length > VAULT_LIMITS.nameMaxChars) return false;
203
+ if (FORBIDDEN_NAME_CHARACTERS.test(name)) return false;
204
+ if (name.trim() !== name) return false;
205
+ if (name.toLowerCase().startsWith("id:")) return false;
206
+ return true;
207
+ }
208
+ function isReservedVaultFieldName(name) {
209
+ return name.normalize("NFC").trim().toLowerCase() === "otp";
210
+ }
211
+ var VaultName = /* @__PURE__ */ defineSchema(
212
+ () => z2.string().min(1).max(VAULT_LIMITS.nameMaxChars).refine(isValidSecretName, "invalid_secret_name")
213
+ );
214
+ var VaultFieldName = /* @__PURE__ */ defineSchema(
215
+ () => VaultName.refine((name) => !isReservedVaultFieldName(name), "invalid_secret_name")
216
+ );
217
+ var VaultPolicy = /* @__PURE__ */ defineSchema(
218
+ () => z2.discriminatedUnion("mode", [
219
+ z2.object({ mode: z2.literal("all") }).strict(),
220
+ z2.object({
221
+ mode: z2.literal("selected"),
222
+ vaultIds: z2.array(z2.string().uuid()).max(VAULT_LIMITS.policyVaultIdsMax)
223
+ }).strict()
224
+ ])
225
+ );
226
+ var VAULT_POLICY_ALL = Object.freeze({ mode: "all" });
227
+ function intersectVaultPolicies(a, b) {
228
+ if (a.mode === "all")
229
+ return b.mode === "all" ? VAULT_POLICY_ALL : { mode: "selected", vaultIds: [...b.vaultIds] };
230
+ if (b.mode === "all") return { mode: "selected", vaultIds: [...a.vaultIds] };
231
+ const allowed = new Set(b.vaultIds);
232
+ return { mode: "selected", vaultIds: a.vaultIds.filter((id) => allowed.has(id)) };
233
+ }
234
+ var VaultAvailability = /* @__PURE__ */ defineSchema(
235
+ () => z2.object({
236
+ allowedWorkspaceIds: z2.array(z2.string().uuid()).max(500).nullable(),
237
+ // null = every workspace
238
+ allowPersonalWorkspaces: z2.boolean()
239
+ }).strict()
240
+ );
241
+ var VaultSummary = /* @__PURE__ */ defineSchema(
242
+ () => z2.object({
243
+ id: z2.string().uuid(),
244
+ workspaceId: z2.string().uuid(),
245
+ ownerKind: VaultOwnerKind,
246
+ /** "Only me" | workspace name | organization name | "This task" */
247
+ ownerLabel: z2.string(),
248
+ rootSessionId: z2.string().uuid().nullable(),
249
+ name: z2.string(),
250
+ description: z2.string().nullable(),
251
+ source: VaultSource,
252
+ mode: VaultMode,
253
+ syncStatus: VaultSyncStatus,
254
+ syncErrorCode: z2.string().nullable(),
255
+ syncErrorMessage: z2.string().nullable(),
256
+ lastSyncedAt: z2.string().nullable(),
257
+ rateLimitedUntil: z2.string().nullable(),
258
+ providerConnectionId: z2.string().uuid().nullable(),
259
+ providerOperations: VaultProviderOperations.optional(),
260
+ freshness: VaultProviderFreshness.optional(),
261
+ /** Organization and Only-me vaults; null for workspace and task vaults. */
262
+ availability: VaultAvailability.nullable(),
263
+ isDefault: z2.boolean(),
264
+ itemCount: z2.number().int(),
265
+ canWrite: z2.boolean(),
266
+ canManage: z2.boolean(),
267
+ generation: z2.number().int(),
268
+ createdAt: z2.string(),
269
+ updatedAt: z2.string()
270
+ })
271
+ );
272
+ var VaultItemReferences = /* @__PURE__ */ defineSchema(
273
+ () => z2.object({
274
+ primary: z2.string().nullable(),
275
+ otp: z2.string().nullable(),
276
+ byField: z2.record(z2.string(), z2.string())
277
+ })
278
+ );
279
+ var VaultItemSummary = /* @__PURE__ */ defineSchema(
280
+ () => z2.object({
281
+ id: z2.string().uuid(),
282
+ vaultId: z2.string().uuid(),
283
+ type: VaultItemType,
284
+ name: z2.string(),
285
+ websites: z2.array(z2.string()),
286
+ /** Value of a text field named "username". */
287
+ username: z2.string().nullable(),
288
+ hasTotp: z2.boolean(),
289
+ hasPasskey: z2.boolean(),
290
+ expiresAt: z2.string().nullable(),
291
+ archivedAt: z2.string().nullable(),
292
+ lastUsedAt: z2.string().nullable(),
293
+ updatedAt: z2.string(),
294
+ references: VaultItemReferences
295
+ })
296
+ );
297
+ var VaultItemField = /* @__PURE__ */ defineSchema(
298
+ () => z2.object({
299
+ id: z2.string().uuid(),
300
+ name: z2.string(),
301
+ kind: VaultFieldKind,
302
+ position: z2.number().int(),
303
+ /** null for provider fields */
304
+ currentVersion: z2.number().int().nullable(),
305
+ /** Plaintext ONLY for kind "text"; null otherwise. */
306
+ value: z2.string().nullable(),
307
+ fileName: z2.string().nullable(),
308
+ fileSize: z2.number().int().nullable(),
309
+ reference: z2.string(),
310
+ updatedAt: z2.string()
311
+ })
312
+ );
313
+ var PasskeySummary = /* @__PURE__ */ defineSchema(
314
+ () => z2.object({
315
+ rpId: z2.string(),
316
+ userName: z2.string().nullable(),
317
+ /** Last 8 characters of the credential ID. */
318
+ credentialIdSuffix: z2.string(),
319
+ signCount: z2.number().int(),
320
+ leasedUntil: z2.string().nullable(),
321
+ lastUsedAt: z2.string().nullable()
322
+ })
323
+ );
324
+ var VaultItem = /* @__PURE__ */ defineSchema(
325
+ () => VaultItemSummary.extend({
326
+ fields: z2.array(VaultItemField),
327
+ passkey: PasskeySummary.nullable(),
328
+ aliases: z2.array(z2.string()),
329
+ primaryFieldId: z2.string().uuid().nullable(),
330
+ createdBySubjectId: z2.string().nullable(),
331
+ createdAt: z2.string(),
332
+ generation: z2.number().int()
333
+ })
334
+ );
335
+ var VaultVersionCreatedByKind = /* @__PURE__ */ defineSchema(
336
+ () => z2.enum(["human", "agent", "api_key", "migration", "provider", "system"])
337
+ );
338
+ var VaultFieldVersionMeta = /* @__PURE__ */ defineSchema(
339
+ () => z2.object({
340
+ version: z2.number().int(),
341
+ current: z2.boolean(),
342
+ createdAt: z2.string(),
343
+ createdByKind: VaultVersionCreatedByKind,
344
+ createdBySubjectId: z2.string().nullable()
345
+ })
346
+ );
347
+ var CreateVaultRequest = /* @__PURE__ */ defineSchema(
348
+ () => z2.object({
349
+ name: VaultName,
350
+ description: z2.string().max(VAULT_LIMITS.descriptionMaxChars).optional(),
351
+ ownerKind: z2.enum(["user", "workspace", "organization"]),
352
+ availability: VaultAvailability.optional()
353
+ }).strict()
354
+ );
355
+ var UpdateVaultRequest = /* @__PURE__ */ defineSchema(
356
+ () => z2.object({
357
+ expectedGeneration: z2.number().int(),
358
+ name: VaultName.optional(),
359
+ description: z2.string().max(VAULT_LIMITS.descriptionMaxChars).nullable().optional(),
360
+ availability: VaultAvailability.optional()
361
+ }).strict()
362
+ );
363
+ var DeleteVaultRequest = /* @__PURE__ */ defineSchema(
364
+ () => z2.object({ confirmName: z2.string().min(1) }).strict()
365
+ );
366
+ var VALUE_SOURCE_KEYS = [
367
+ "value",
368
+ "generate",
369
+ "fromReference",
370
+ "fileBase64",
371
+ "restoreVersion",
372
+ "remove"
373
+ ];
374
+ function exactlyOneValueSource(input) {
375
+ return VALUE_SOURCE_KEYS.filter((key) => input[key] !== void 0).length === 1;
376
+ }
377
+ var VaultFieldInput = /* @__PURE__ */ defineSchema(
378
+ () => z2.object({
379
+ fieldId: z2.string().uuid().optional(),
380
+ name: VaultFieldName,
381
+ /** Default concealed; a field named "username" defaults to text. */
382
+ kind: VaultFieldKind.optional(),
383
+ value: z2.string().optional(),
384
+ generate: GeneratePasswordSpec.optional(),
385
+ fromReference: z2.string().max(VAULT_LIMITS.referenceMaxChars).optional(),
386
+ fileBase64: z2.string().optional(),
387
+ fileName: z2.string().max(255).optional(),
388
+ restoreVersion: z2.number().int().optional(),
389
+ remove: z2.literal(true).optional()
390
+ }).strict().refine(
391
+ exactlyOneValueSource,
392
+ "exactly one of value|generate|fromReference|fileBase64|restoreVersion|remove"
393
+ )
394
+ );
395
+ var CreateVaultItemShape = /* @__PURE__ */ defineSchema(
396
+ () => z2.object({
397
+ type: VaultItemType,
398
+ name: VaultName,
399
+ websites: z2.array(z2.string().max(VAULT_LIMITS.websiteMaxChars)).max(VAULT_LIMITS.websitesPerItem).optional(),
400
+ expiresAt: z2.string().datetime({ offset: true }).nullable().optional(),
401
+ fields: z2.array(VaultFieldInput).max(VAULT_LIMITS.fieldsPerItem),
402
+ primaryFieldName: z2.string().optional()
403
+ }).strict()
404
+ );
405
+ var CreateVaultItemRequest = CreateVaultItemShape;
406
+ var UpdateVaultItemRequest = /* @__PURE__ */ defineSchema(
407
+ () => CreateVaultItemShape.partial().extend({ expectedGeneration: z2.number().int() }).strict()
408
+ );
409
+ var MoveVaultItemRequest = /* @__PURE__ */ defineSchema(
410
+ () => z2.object({
411
+ targetVaultId: z2.string().uuid(),
412
+ mode: z2.enum(["move", "copy"]),
413
+ newName: VaultName.optional()
414
+ }).strict()
415
+ );
416
+ var RevealVaultFieldRequest = /* @__PURE__ */ defineSchema(
417
+ () => z2.object({ version: z2.number().int().optional() }).strict()
418
+ );
419
+ var RevealVaultFieldResponse = /* @__PURE__ */ defineSchema(
420
+ () => z2.object({
421
+ value: z2.string(),
422
+ encoding: z2.enum(["utf8", "base64"]),
423
+ version: z2.number().int().nullable(),
424
+ totp: z2.object({ code: z2.string(), periodSeconds: z2.number().int(), expiresAt: z2.string() }).nullable()
425
+ })
426
+ );
427
+ var RestoreVaultFieldVersionRequest = /* @__PURE__ */ defineSchema(
428
+ () => z2.object({ version: z2.number().int().positive() }).strict()
429
+ );
430
+ var QueryBoolean = /* @__PURE__ */ defineSchema(
431
+ () => z2.preprocess(
432
+ (value) => value === "true" ? true : value === "false" ? false : value,
433
+ z2.boolean()
434
+ )
435
+ );
436
+ var QueryInt = /* @__PURE__ */ defineSchema(
437
+ () => z2.preprocess(
438
+ (value) => typeof value === "string" && /^\d+$/.test(value) ? Number(value) : value,
439
+ z2.number().int().min(1).max(200)
440
+ )
441
+ );
442
+ var ListVaultItemsQuery = /* @__PURE__ */ defineSchema(
443
+ () => z2.object({
444
+ q: z2.string().max(200).optional(),
445
+ type: VaultItemType.optional(),
446
+ includeArchived: QueryBoolean.optional(),
447
+ cursor: z2.string().optional(),
448
+ limit: QueryInt.optional()
449
+ })
450
+ );
451
+ var ListVaultsResponse = /* @__PURE__ */ defineSchema(
452
+ () => z2.object({ vaults: z2.array(VaultSummary) })
453
+ );
454
+ var ListVaultItemsResponse = /* @__PURE__ */ defineSchema(
455
+ () => z2.object({
456
+ items: z2.array(VaultItemSummary),
457
+ nextCursor: z2.string().nullable()
458
+ })
459
+ );
460
+ var ListVaultFieldVersionsResponse = /* @__PURE__ */ defineSchema(
461
+ () => z2.object({
462
+ versions: z2.array(VaultFieldVersionMeta)
463
+ })
464
+ );
465
+ var SetSessionVaultPolicyRequest = /* @__PURE__ */ defineSchema(
466
+ () => z2.object({ policy: VaultPolicy }).strict()
467
+ );
468
+ var SessionSecretsView = /* @__PURE__ */ defineSchema(
469
+ () => z2.object({
470
+ capabilityEnabled: z2.boolean(),
471
+ policy: VaultPolicy,
472
+ effectiveVaultIds: z2.array(z2.string().uuid()),
473
+ /** Nearest ancestor that narrowed, if any. */
474
+ narrowedBySessionId: z2.string().uuid().nullable(),
475
+ taskVault: VaultSummary.nullable(),
476
+ taskItems: z2.array(VaultItemSummary),
477
+ reachableVaults: z2.array(
478
+ VaultSummary.extend({ selected: z2.boolean(), selectable: z2.boolean() })
479
+ )
480
+ })
481
+ );
482
+ var InstallOnePasswordRequest = /* @__PURE__ */ defineSchema(
483
+ () => z2.object({
484
+ // Real service-account tokens are long; the dev fakes (ops_fake_healthy) are 16 chars.
485
+ token: z2.string().trim().min(16).max(4096),
486
+ ownership: z2.enum(["user", "workspace", "organization"]),
487
+ planTier: z2.enum(["family", "teams", "business"]).default("teams"),
488
+ label: z2.string().max(120).optional()
489
+ }).strict()
490
+ );
491
+ var ProviderVaultMeta = /* @__PURE__ */ defineSchema(
492
+ () => z2.object({
493
+ externalVaultId: z2.string(),
494
+ name: z2.string(),
495
+ itemCount: z2.number().int().nullable(),
496
+ linkedVaultId: z2.string().uuid().nullable(),
497
+ /** Unknown means the provider does not expose the grant; writes still check upstream. */
498
+ writeAccess: z2.enum(["read_only", "read_write", "unknown"]).optional(),
499
+ operations: VaultProviderOperations.optional()
500
+ })
501
+ );
502
+ var InstallOnePasswordResponse = /* @__PURE__ */ defineSchema(
503
+ () => z2.object({
504
+ connectionId: z2.string().uuid(),
505
+ accountName: z2.string().nullable(),
506
+ vaults: z2.array(ProviderVaultMeta)
507
+ })
508
+ );
509
+ var OnePasswordConnectionSummary = /* @__PURE__ */ defineSchema(
510
+ () => z2.object({
511
+ id: z2.string().uuid(),
512
+ /** Who can use the vaults linked through it. */
513
+ ownership: z2.enum(["user", "workspace", "organization"]),
514
+ /** Sign-in host from the token, for example "my.1password.com". */
515
+ accountName: z2.string().nullable(),
516
+ label: z2.string().nullable(),
517
+ planTier: z2.enum(["family", "teams", "business"]),
518
+ /** When the current token was last checked against 1Password. */
519
+ verifiedAt: z2.string(),
520
+ createdAt: z2.string(),
521
+ createdBySubjectId: z2.string().nullable(),
522
+ /** The caller can link vaults, replace the token and disconnect it. */
523
+ canManage: z2.boolean()
524
+ })
525
+ );
526
+ var ListOnePasswordConnectionsResponse = /* @__PURE__ */ defineSchema(
527
+ () => z2.object({
528
+ connections: z2.array(OnePasswordConnectionSummary)
529
+ })
530
+ );
531
+ var ReplaceOnePasswordTokenRequest = /* @__PURE__ */ defineSchema(
532
+ () => z2.object({
533
+ token: z2.string().trim().min(16).max(4096),
534
+ planTier: z2.enum(["family", "teams", "business"]).optional()
535
+ }).strict()
536
+ );
537
+ var DisconnectOnePasswordResponse = /* @__PURE__ */ defineSchema(
538
+ () => z2.object({
539
+ /** The Opengeni vaults that were unlinked. Nothing is deleted in 1Password. */
540
+ unlinkedVaultIds: z2.array(z2.string().uuid())
541
+ })
542
+ );
543
+ var ExternalVaultProviderKind = /* @__PURE__ */ defineSchema(
544
+ () => z2.enum(["external", "protonpass", "keeper", "bitwarden"])
545
+ );
546
+ var VaultProviderCredentials = /* @__PURE__ */ defineSchema(
547
+ () => z2.discriminatedUnion("provider", [
548
+ z2.object({
549
+ provider: z2.literal("external"),
550
+ endpoint: z2.string().url().max(2048),
551
+ signingSecret: z2.string().min(32).max(4096)
552
+ }).strict(),
553
+ z2.object({
554
+ provider: z2.literal("bitwarden"),
555
+ endpoint: z2.string().url().max(2048),
556
+ signingSecret: z2.string().min(32).max(4096)
557
+ }).strict(),
558
+ z2.object({
559
+ provider: z2.literal("protonpass"),
560
+ token: z2.string().min(16).max(4096)
561
+ }).strict(),
562
+ z2.object({
563
+ provider: z2.literal("keeper"),
564
+ oneTimeToken: z2.string().min(16).max(4096),
565
+ /** Optional region host for tokens that do not encode one. */
566
+ hostname: z2.string().max(253).optional()
567
+ }).strict()
568
+ ])
569
+ );
570
+ var InstallVaultProviderRequest = /* @__PURE__ */ defineSchema(
571
+ () => z2.object({
572
+ credentials: VaultProviderCredentials,
573
+ ownership: z2.enum(["user", "workspace", "organization"]),
574
+ label: z2.string().trim().min(1).max(120).optional()
575
+ }).strict()
576
+ );
577
+ var ReplaceVaultProviderCredentialsRequest = /* @__PURE__ */ defineSchema(
578
+ () => z2.object({ credentials: VaultProviderCredentials }).strict()
579
+ );
580
+ var VaultProviderConnectionSummary = /* @__PURE__ */ defineSchema(
581
+ () => z2.object({
582
+ id: z2.string().uuid(),
583
+ provider: z2.enum(["onepassword", "external", "protonpass", "keeper", "bitwarden"]),
584
+ ownership: z2.enum(["user", "workspace", "organization"]),
585
+ accountName: z2.string().nullable(),
586
+ label: z2.string().nullable(),
587
+ verifiedAt: z2.string(),
588
+ createdAt: z2.string(),
589
+ createdBySubjectId: z2.string().nullable(),
590
+ canManage: z2.boolean(),
591
+ operations: VaultProviderOperations,
592
+ /** Only 1Password uses a plan tier. */
593
+ planTier: z2.enum(["family", "teams", "business"]).optional(),
594
+ /** Unavailable means this deployment cannot run the adapter, not bad credentials. */
595
+ available: z2.boolean(),
596
+ /** Setup material is saved, but provider verification has not completed. */
597
+ verificationStatus: z2.enum(["ready", "pending"]).optional()
598
+ })
599
+ );
600
+ var VaultProviderAvailability = /* @__PURE__ */ defineSchema(
601
+ () => z2.object({
602
+ provider: VaultProviderConnectionSummary.shape.provider,
603
+ available: z2.boolean(),
604
+ reason: z2.enum(["not_enabled"]).nullable()
605
+ })
606
+ );
607
+ var ListVaultProviderConnectionsResponse = /* @__PURE__ */ defineSchema(
608
+ () => z2.object({
609
+ connections: z2.array(VaultProviderConnectionSummary),
610
+ /** Additive: older servers may omit this metadata-only deployment catalog. */
611
+ providers: z2.array(VaultProviderAvailability).optional()
612
+ })
613
+ );
614
+ var InstallVaultProviderResponse = /* @__PURE__ */ defineSchema(
615
+ () => z2.object({
616
+ connectionId: z2.string().uuid(),
617
+ accountName: z2.string().nullable(),
618
+ provider: ExternalVaultProviderKind,
619
+ operations: VaultProviderOperations,
620
+ vaults: z2.array(ProviderVaultMeta),
621
+ /** Retry verification on this connection; never replay a consumed bootstrap token. */
622
+ discoveryPending: z2.boolean().optional(),
623
+ errorCode: z2.string().max(100).optional()
624
+ })
625
+ );
626
+ var DisconnectVaultProviderResponse = /* @__PURE__ */ defineSchema(
627
+ () => z2.object({ unlinkedVaultIds: z2.array(z2.string().uuid()) })
628
+ );
629
+ var LinkProviderVaultRequest = /* @__PURE__ */ defineSchema(
630
+ () => z2.object({
631
+ provider: z2.enum(["onepassword", "host", "external", "protonpass", "keeper", "bitwarden"]),
632
+ /** Required except for an in-process host provider. */
633
+ connectionId: z2.string().uuid().optional(),
634
+ externalVaultId: z2.string(),
635
+ ownerKind: z2.enum(["user", "workspace", "organization"]),
636
+ mode: VaultMode,
637
+ name: VaultName.optional(),
638
+ availability: VaultAvailability.optional()
639
+ }).strict()
640
+ );
641
+ var CreateManagedProviderVaultRequest = /* @__PURE__ */ defineSchema(
642
+ () => z2.object({
643
+ name: VaultName,
644
+ ownerKind: z2.enum(["user", "workspace", "organization"]),
645
+ groupId: z2.string().optional()
646
+ }).strict()
647
+ );
648
+ var VaultErrorCode = /* @__PURE__ */ defineSchema(
649
+ () => z2.enum([
650
+ "vault_not_found",
651
+ "vault_item_not_found",
652
+ "vault_field_not_found",
653
+ "vault_name_conflict",
654
+ "vault_item_name_conflict",
655
+ "vault_limit_reached",
656
+ "vault_read_only",
657
+ "vault_generation_conflict",
658
+ "vault_permission_denied",
659
+ /** A session's vault policy reaches outside its parent's effective vaults (AX-2). */
660
+ "vault_policy_outside_parent",
661
+ "vault_reveal_requires_human",
662
+ "encryption_key_missing",
663
+ "provider_auth_invalid",
664
+ "provider_auth_expired",
665
+ "provider_rate_limited",
666
+ "provider_unavailable",
667
+ "provider_conflict",
668
+ "provider_locked",
669
+ "provider_inventory_incomplete",
670
+ "provider_outcome_unknown",
671
+ "variable_sets_removed",
672
+ "secret_save_forbidden",
673
+ "invalid_secret_name",
674
+ "secret_value_too_large",
675
+ "human_auth_required",
676
+ "secret_search_cursor_invalid"
677
+ ])
678
+ );
679
+ var VaultApiError = /* @__PURE__ */ defineSchema(
680
+ () => z2.object({
681
+ error: VaultErrorCode,
682
+ message: z2.string(),
683
+ details: z2.record(z2.string(), z2.unknown()).optional()
684
+ })
685
+ );
686
+ var VAULT_ERROR_HTTP_STATUS = {
687
+ vault_not_found: 404,
688
+ vault_item_not_found: 404,
689
+ vault_field_not_found: 404,
690
+ vault_name_conflict: 409,
691
+ vault_item_name_conflict: 409,
692
+ vault_generation_conflict: 409,
693
+ provider_conflict: 409,
694
+ vault_limit_reached: 422,
695
+ invalid_secret_name: 422,
696
+ secret_value_too_large: 422,
697
+ secret_save_forbidden: 422,
698
+ secret_search_cursor_invalid: 422,
699
+ vault_policy_outside_parent: 422,
700
+ vault_read_only: 403,
701
+ vault_permission_denied: 403,
702
+ vault_reveal_requires_human: 403,
703
+ human_auth_required: 403,
704
+ variable_sets_removed: 410,
705
+ encryption_key_missing: 503,
706
+ provider_unavailable: 503,
707
+ provider_rate_limited: 429,
708
+ provider_auth_invalid: 401,
709
+ provider_auth_expired: 401,
710
+ provider_locked: 423,
711
+ provider_inventory_incomplete: 503,
712
+ provider_outcome_unknown: 503
713
+ };
714
+ var SECRET_TOOL_NAMES = [
715
+ "secret_search",
716
+ "secret_save",
717
+ "secret_get",
718
+ "secret_move",
719
+ "secret_delete"
720
+ ];
721
+ var SECRET_SAVE_TO = /* @__PURE__ */ defineSchema(
722
+ () => z2.enum(["user", "task", "workspace"])
723
+ );
724
+ var SecretSearchInput = /* @__PURE__ */ defineSchema(
725
+ () => z2.object({
726
+ query: z2.string().max(200).optional(),
727
+ website: z2.string().max(VAULT_LIMITS.websiteMaxChars).optional(),
728
+ type: VaultItemType.optional(),
729
+ /** Vault name or ID. */
730
+ vault: z2.string().max(200).optional(),
731
+ limit: z2.number().int().min(1).max(VAULT_LIMITS.searchResultsMax).default(20),
732
+ /** `nextCursor` from the previous call with the same filters. */
733
+ cursor: z2.string().max(VAULT_LIMITS.searchCursorMaxChars).optional(),
734
+ /** Refresh provider metadata and subsequent value reads; never bypass rate limits. */
735
+ refresh: z2.boolean().optional()
736
+ }).strict()
737
+ );
738
+ var SecretSearchResult = /* @__PURE__ */ defineSchema(
739
+ () => z2.object({
740
+ vault: z2.object({
741
+ id: z2.string().uuid(),
742
+ name: z2.string(),
743
+ ownerKind: VaultOwnerKind,
744
+ source: VaultSource,
745
+ mode: VaultMode
746
+ }),
747
+ item: z2.object({
748
+ id: z2.string().uuid(),
749
+ name: z2.string(),
750
+ type: VaultItemType,
751
+ websites: z2.array(z2.string()),
752
+ username: z2.string().nullable(),
753
+ hasTotp: z2.boolean(),
754
+ hasPasskey: z2.boolean(),
755
+ expiresAt: z2.string().nullable()
756
+ }),
757
+ fields: z2.array(z2.object({ name: z2.string(), kind: VaultFieldKind })),
758
+ references: VaultItemReferences
759
+ })
760
+ );
761
+ var SecretSearchVault = /* @__PURE__ */ defineSchema(
762
+ () => z2.object({
763
+ id: z2.string().uuid(),
764
+ name: z2.string(),
765
+ ownerKind: VaultOwnerKind,
766
+ source: VaultSource,
767
+ mode: VaultMode,
768
+ itemCount: z2.number().int().nonnegative(),
769
+ freshness: VaultProviderFreshness.optional()
770
+ })
771
+ );
772
+ var SecretSearchOutput = /* @__PURE__ */ defineSchema(
773
+ () => z2.object({
774
+ items: z2.array(SecretSearchResult),
775
+ /** True when more matches remain; pass `nextCursor` to continue. */
776
+ truncated: z2.boolean(),
777
+ nextCursor: z2.string().nullable(),
778
+ /** Every vault the caller can reach, on the first page only. */
779
+ vaults: z2.array(SecretSearchVault).optional(),
780
+ /** False when a reachable provider could not be checked; empty items are not proof of absence. */
781
+ complete: z2.boolean().optional(),
782
+ /** Included on every page so failures are not lost after page one. */
783
+ sources: z2.array(
784
+ z2.object({
785
+ vaultId: z2.string().uuid(),
786
+ freshness: VaultProviderFreshness
787
+ })
788
+ ).optional()
789
+ })
790
+ );
791
+ var SecretSaveFieldInput = /* @__PURE__ */ defineSchema(
792
+ () => z2.object({
793
+ name: VaultFieldName,
794
+ kind: VaultFieldKind.optional(),
795
+ value: z2.string().optional(),
796
+ generate: GeneratePasswordSpec.optional(),
797
+ fromReference: z2.string().max(VAULT_LIMITS.referenceMaxChars).optional(),
798
+ restoreVersion: z2.number().int().optional()
799
+ }).strict().refine(exactlyOneValueSource, "exactly one of value|generate|fromReference|restoreVersion")
800
+ );
801
+ var SecretSaveInput = /* @__PURE__ */ defineSchema(
802
+ () => z2.object({
803
+ item: VaultName,
804
+ /** Vault name or ID; defaults to the saveTo scope's default vault. */
805
+ vault: z2.string().max(200).optional(),
806
+ saveTo: SECRET_SAVE_TO.optional(),
807
+ type: VaultItemType.default("login"),
808
+ websites: z2.array(z2.string().max(VAULT_LIMITS.websiteMaxChars)).max(VAULT_LIMITS.websitesPerItem).optional(),
809
+ username: z2.string().max(512).optional(),
810
+ fields: z2.array(SecretSaveFieldInput).max(VAULT_LIMITS.fieldsPerItem).optional(),
811
+ mode: z2.enum(["create", "update", "upsert"]).default("upsert")
812
+ }).strict()
813
+ );
814
+ var SecretSaveOutput = /* @__PURE__ */ defineSchema(
815
+ () => z2.object({
816
+ item: VaultItemSummary,
817
+ references: VaultItemReferences,
818
+ generatedFields: z2.array(z2.string())
819
+ })
820
+ );
821
+ var SecretGetInput = /* @__PURE__ */ defineSchema(
822
+ () => z2.object({
823
+ reference: z2.string().min(1).max(VAULT_LIMITS.referenceMaxChars),
824
+ version: z2.number().int().optional()
825
+ }).strict()
826
+ );
827
+ var SecretGetOutput = RevealVaultFieldResponse;
828
+ var SecretMoveInput = /* @__PURE__ */ defineSchema(
829
+ () => z2.object({
830
+ reference: z2.string().min(1).max(VAULT_LIMITS.referenceMaxChars),
831
+ /** Vault name or ID. */
832
+ toVault: z2.string().min(1).max(200),
833
+ mode: z2.enum(["move", "copy"]).default("move"),
834
+ newName: VaultName.optional()
835
+ }).strict()
836
+ );
837
+ var SecretMoveOutput = /* @__PURE__ */ defineSchema(
838
+ () => z2.object({
839
+ item: VaultItemSummary,
840
+ references: VaultItemReferences
841
+ })
842
+ );
843
+ var SecretDeleteInput = /* @__PURE__ */ defineSchema(
844
+ () => z2.object({ reference: z2.string().min(1).max(VAULT_LIMITS.referenceMaxChars) }).strict()
845
+ );
846
+ var SecretDeleteOutput = /* @__PURE__ */ defineSchema(
847
+ () => z2.object({ archived: z2.literal(true), restoreHint: z2.string() })
848
+ );
849
+ var VAULT_POLICY_UPDATED_EVENT_TYPE = "session.vaultPolicy.updated";
850
+ var VAULT_AUDIT_ACTIONS = [
851
+ "vault.created",
852
+ "vault.updated",
853
+ "vault.deleted",
854
+ "vault.item.created",
855
+ "vault.item.updated",
856
+ "vault.item.archived",
857
+ "vault.item.restored",
858
+ "vault.item.deleted",
859
+ "vault.item.moved",
860
+ "vault.item.copied",
861
+ "vault.field.set",
862
+ "vault.field.revealed",
863
+ "vault.secret.used",
864
+ "vault.secret.read",
865
+ "vault.secret.read.denied",
866
+ "vault.reference.failed",
867
+ "vault.provider.connected",
868
+ "vault.provider.linked",
869
+ "vault.provider.synced",
870
+ "vault.provider.error",
871
+ "vault.passkey.registered",
872
+ "vault.passkey.asserted",
873
+ "vault.policy.updated",
874
+ "vault.migrated"
875
+ ];
876
+ var VaultAuditAction = /* @__PURE__ */ defineSchema(() => z2.enum(VAULT_AUDIT_ACTIONS));
877
+ var VAULT_AUDIT_TARGET_TYPES = ["vault", "vault_item"];
878
+ var VAULT_METRIC_NAMES = {
879
+ resolutions: "opengeni_secret_resolutions_total",
880
+ resolutionDuration: "opengeni_secret_resolution_duration_seconds",
881
+ execEnvBytes: "opengeni_secret_exec_env_bytes",
882
+ providerCalls: "opengeni_vault_provider_calls_total",
883
+ providerRateLimited: "opengeni_vault_provider_rate_limited_total",
884
+ passkeyAssertions: "opengeni_passkey_assertions_total"
885
+ };
886
+
887
+ // src/vault-provider-wire.ts
888
+ var VAULT_PROVIDER_WIRE_VERSION = "opengeni.vault.v1";
889
+ var VAULT_PROVIDER_WIRE_RESPONSE_SIGNATURE_HEADER = "OpenGeni-Vault-Response-Signature";
890
+ function vaultProviderWireResponseKey(signingSecret) {
891
+ return `${signingSecret}\0${VAULT_PROVIDER_WIRE_VERSION}.response`;
892
+ }
893
+ var VAULT_PROVIDER_WIRE_LIMITS = {
894
+ maxRequestBytes: 4 * 1024 * 1024,
895
+ maxResponseBytes: 4 * 1024 * 1024,
896
+ /** Sum of returned secret value bytes in one read. */
897
+ maxReadValueBytes: 3 * 1024 * 1024,
898
+ pageSizeMax: 100,
899
+ cursorMaxChars: 1024,
900
+ snapshotMaxChars: 1024,
901
+ externalIdMaxChars: 300,
902
+ vaultNameMaxChars: 300,
903
+ nativeIdMaxChars: 200,
904
+ readFieldsMax: VAULT_LIMITS.fieldsPerItem,
905
+ idempotencyKeyMaxChars: 200,
906
+ accountIdMaxChars: 300,
907
+ accountNameMaxChars: 300,
908
+ versionMaxChars: 300,
909
+ cacheEpochMaxChars: 200,
910
+ /** Per request deadline enforced by Opengeni's transport. */
911
+ defaultTimeoutMs: 15e3,
912
+ maxTimeoutMs: 6e4,
913
+ /** Accepted request age; matches `OPENGENI_SIGNATURE_TOLERANCE_SECONDS`. */
914
+ signatureToleranceSeconds: 300
915
+ };
916
+ var VAULT_PROVIDER_WIRE_ERROR_CODES = [
917
+ "provider_auth_invalid",
918
+ "provider_auth_expired",
919
+ "provider_rate_limited",
920
+ "provider_unavailable",
921
+ "provider_conflict",
922
+ "provider_not_found",
923
+ "provider_permission_denied",
924
+ "provider_locked",
925
+ "provider_inventory_incomplete",
926
+ "provider_outcome_unknown"
927
+ ];
928
+ var VAULT_PROVIDER_WIRE_OPERATIONS = [
929
+ "describe",
930
+ "refresh",
931
+ "list_vaults",
932
+ "list_items",
933
+ "read_fields",
934
+ "write_item",
935
+ "archive_item"
936
+ ];
937
+ function isVaultProviderWireMutation(op) {
938
+ return op === "write_item" || op === "archive_item";
939
+ }
940
+ var VaultProviderWireProvider = /* @__PURE__ */ defineSchema(
941
+ () => z3.enum(["external", "bitwarden"])
942
+ );
943
+ var CONTROL_CHARACTERS = /[\u0000-\u001f\u007f-\u009f]/;
944
+ var encoder = /* @__PURE__ */ new TextEncoder();
945
+ function vaultProviderWireUtf8Bytes(value) {
946
+ return encoder.encode(value).byteLength;
947
+ }
948
+ function boundedText(max) {
949
+ return z3.string().min(1).max(max).refine((value) => !CONTROL_CHARACTERS.test(value), "control characters are not allowed");
950
+ }
951
+ var ExternalId = /* @__PURE__ */ defineSchema(
952
+ () => boundedText(VAULT_PROVIDER_WIRE_LIMITS.externalIdMaxChars)
953
+ );
954
+ var NativeId = /* @__PURE__ */ defineSchema(
955
+ () => boundedText(VAULT_PROVIDER_WIRE_LIMITS.nativeIdMaxChars)
956
+ );
957
+ var ItemName = /* @__PURE__ */ defineSchema(
958
+ () => z3.string().refine(isValidSecretName, "invalid_secret_name")
959
+ );
960
+ var FieldName = /* @__PURE__ */ defineSchema(
961
+ () => z3.string().refine(
962
+ (name) => isValidSecretName(name) && !isReservedVaultFieldName(name),
963
+ "invalid_secret_name"
964
+ )
965
+ );
966
+ var Website = /* @__PURE__ */ defineSchema(() => boundedText(VAULT_LIMITS.websiteMaxChars));
967
+ var Version = /* @__PURE__ */ defineSchema(
968
+ () => boundedText(VAULT_PROVIDER_WIRE_LIMITS.versionMaxChars)
969
+ );
970
+ var Cursor = /* @__PURE__ */ defineSchema(
971
+ () => boundedText(VAULT_PROVIDER_WIRE_LIMITS.cursorMaxChars)
972
+ );
973
+ var Snapshot = /* @__PURE__ */ defineSchema(
974
+ () => boundedText(VAULT_PROVIDER_WIRE_LIMITS.snapshotMaxChars)
975
+ );
976
+ var IdempotencyKey = /* @__PURE__ */ defineSchema(
977
+ () => boundedText(VAULT_PROVIDER_WIRE_LIMITS.idempotencyKeyMaxChars)
978
+ );
979
+ var CacheEpoch = /* @__PURE__ */ defineSchema(
980
+ () => boundedText(VAULT_PROVIDER_WIRE_LIMITS.cacheEpochMaxChars).nullable()
981
+ );
982
+ function uniqueBy(values, key) {
983
+ const seen = /* @__PURE__ */ new Set();
984
+ for (const value of values) {
985
+ const k = key(value);
986
+ if (seen.has(k)) return false;
987
+ seen.add(k);
988
+ }
989
+ return true;
990
+ }
991
+ function vaultProviderWireNameKey(name) {
992
+ return name.normalize("NFC").trim().toLowerCase();
993
+ }
994
+ var VaultProviderWireAuthority = /* @__PURE__ */ defineSchema(
995
+ () => z3.object({
996
+ accountId: NativeId,
997
+ workspaceId: NativeId,
998
+ /** Null for workspace-level background work with no acting human. */
999
+ subjectId: NativeId.nullable(),
1000
+ /** Workspace that owns the encrypted connection (may differ from the caller). */
1001
+ connectionWorkspaceId: NativeId,
1002
+ sessionId: NativeId.optional(),
1003
+ turnId: NativeId.optional(),
1004
+ attemptId: NativeId.optional(),
1005
+ siteId: NativeId.optional()
1006
+ }).strict()
1007
+ );
1008
+ var VaultProviderWirePage = /* @__PURE__ */ defineSchema(
1009
+ () => z3.object({
1010
+ limit: z3.number().int().min(1).max(VAULT_PROVIDER_WIRE_LIMITS.pageSizeMax),
1011
+ cursor: Cursor.optional(),
1012
+ snapshot: Snapshot.optional()
1013
+ }).strict()
1014
+ );
1015
+ var VaultProviderWireWriteField = /* @__PURE__ */ defineSchema(
1016
+ () => z3.object({
1017
+ externalFieldId: ExternalId.optional(),
1018
+ name: FieldName,
1019
+ kind: VaultFieldKind,
1020
+ /** Omitted on an update: keep the current value. */
1021
+ value: z3.string().refine(
1022
+ (value) => vaultProviderWireUtf8Bytes(value) <= VAULT_LIMITS.textValueMaxBytes,
1023
+ "secret_value_too_large"
1024
+ ).optional(),
1025
+ remove: z3.literal(true).optional()
1026
+ }).strict().refine((field) => !(field.remove && field.value !== void 0), "remove carries no value").refine((field) => !(field.remove && !field.externalFieldId), "remove needs a field id").refine(
1027
+ (field) => !(field.kind === "file" && field.value !== void 0),
1028
+ "file writes are not supported"
1029
+ )
1030
+ );
1031
+ var VaultProviderWireWriteItem = /* @__PURE__ */ defineSchema(
1032
+ () => z3.object({
1033
+ externalItemId: ExternalId.optional(),
1034
+ expectedVersion: Version.nullable().optional(),
1035
+ name: ItemName,
1036
+ type: VaultItemType.refine((type) => type !== "passkey", "passkeys are hosted only"),
1037
+ websites: z3.array(Website).max(VAULT_LIMITS.websitesPerItem),
1038
+ fields: z3.array(VaultProviderWireWriteField).max(VAULT_LIMITS.fieldsPerItem)
1039
+ }).strict().refine(
1040
+ (item) => uniqueBy(
1041
+ item.fields.filter((field) => !field.remove),
1042
+ (field) => vaultProviderWireNameKey(field.name)
1043
+ ) && uniqueBy(
1044
+ item.fields.filter((field) => field.externalFieldId !== void 0),
1045
+ (field) => field.externalFieldId
1046
+ ),
1047
+ "duplicate fields"
1048
+ )
1049
+ );
1050
+ var ReadContext = {
1051
+ /** Recheck upstream; never bypasses authorization or upstream rate limits. */
1052
+ forceRefresh: z3.boolean(),
1053
+ /** Opengeni's mirror freshness epoch, for receiver-side cache invalidation. */
1054
+ cacheEpoch: CacheEpoch
1055
+ };
1056
+ var VaultProviderWireOperation = /* @__PURE__ */ defineSchema(
1057
+ () => z3.discriminatedUnion("op", [
1058
+ z3.object({ op: z3.literal("describe") }).strict(),
1059
+ z3.object({ op: z3.literal("refresh") }).strict(),
1060
+ z3.object({ op: z3.literal("list_vaults"), page: VaultProviderWirePage, ...ReadContext }).strict(),
1061
+ z3.object({
1062
+ op: z3.literal("list_items"),
1063
+ externalVaultId: ExternalId,
1064
+ page: VaultProviderWirePage,
1065
+ ...ReadContext
1066
+ }).strict(),
1067
+ z3.object({
1068
+ op: z3.literal("read_fields"),
1069
+ externalVaultId: ExternalId,
1070
+ externalItemId: ExternalId,
1071
+ externalFieldIds: z3.array(ExternalId).min(1).max(VAULT_PROVIDER_WIRE_LIMITS.readFieldsMax).refine((ids) => new Set(ids).size === ids.length, "duplicate field ids"),
1072
+ ...ReadContext
1073
+ }).strict(),
1074
+ z3.object({
1075
+ op: z3.literal("write_item"),
1076
+ externalVaultId: ExternalId,
1077
+ item: VaultProviderWireWriteItem,
1078
+ idempotencyKey: IdempotencyKey
1079
+ }).strict(),
1080
+ z3.object({
1081
+ op: z3.literal("archive_item"),
1082
+ externalVaultId: ExternalId,
1083
+ externalItemId: ExternalId,
1084
+ idempotencyKey: IdempotencyKey
1085
+ }).strict()
1086
+ ])
1087
+ );
1088
+ var VaultProviderWireRequest = /* @__PURE__ */ defineSchema(
1089
+ () => z3.object({
1090
+ version: z3.literal(VAULT_PROVIDER_WIRE_VERSION),
1091
+ type: z3.literal("request"),
1092
+ requestId: z3.string().uuid(),
1093
+ sentAt: z3.string().datetime(),
1094
+ provider: VaultProviderWireProvider,
1095
+ connectionId: z3.string().uuid(),
1096
+ authority: VaultProviderWireAuthority,
1097
+ operation: VaultProviderWireOperation
1098
+ }).strict()
1099
+ );
1100
+ var VaultProviderWireErrorCode = /* @__PURE__ */ defineSchema(
1101
+ () => z3.enum(VAULT_PROVIDER_WIRE_ERROR_CODES)
1102
+ );
1103
+ var VaultProviderWireFreshness = /* @__PURE__ */ defineSchema(
1104
+ () => z3.object({
1105
+ state: z3.enum(["current", "stale", "refreshing", "unavailable"]),
1106
+ /** When the receiver last synchronized with its upstream store. */
1107
+ sourceSyncedAt: z3.string().datetime().nullable(),
1108
+ source: z3.enum(["live", "cache", "unknown"]),
1109
+ errorCode: VaultProviderWireErrorCode.nullable(),
1110
+ retryAt: z3.string().datetime().nullable()
1111
+ }).strict()
1112
+ );
1113
+ var VaultProviderWireVault = /* @__PURE__ */ defineSchema(
1114
+ () => z3.object({
1115
+ externalVaultId: ExternalId,
1116
+ name: boundedText(VAULT_PROVIDER_WIRE_LIMITS.vaultNameMaxChars),
1117
+ contentVersion: Version.nullable(),
1118
+ itemCount: z3.number().int().nonnegative().nullable(),
1119
+ writeAccess: z3.enum(["read_only", "read_write", "unknown"]),
1120
+ /** Narrows the connection operations for this vault; never widens them. */
1121
+ operations: VaultProviderOperations.optional()
1122
+ }).strict()
1123
+ );
1124
+ var VaultProviderWireFieldMeta = /* @__PURE__ */ defineSchema(
1125
+ () => z3.object({ externalFieldId: ExternalId, name: FieldName, kind: VaultFieldKind }).strict()
1126
+ );
1127
+ var VaultProviderWireItemMeta = /* @__PURE__ */ defineSchema(
1128
+ () => z3.object({
1129
+ externalItemId: ExternalId,
1130
+ name: ItemName,
1131
+ type: VaultItemType,
1132
+ websites: z3.array(Website).max(VAULT_LIMITS.websitesPerItem),
1133
+ fields: z3.array(VaultProviderWireFieldMeta).max(VAULT_LIMITS.fieldsPerItem).refine(
1134
+ (fields) => uniqueBy(fields, (field) => field.externalFieldId) && uniqueBy(fields, (field) => vaultProviderWireNameKey(field.name)),
1135
+ "duplicate fields"
1136
+ ),
1137
+ version: Version.nullable(),
1138
+ updatedAt: z3.string().datetime().nullable()
1139
+ }).strict()
1140
+ );
1141
+ var BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;
1142
+ var VaultProviderWireFieldValue = /* @__PURE__ */ defineSchema(
1143
+ () => z3.object({
1144
+ externalFieldId: ExternalId,
1145
+ value: z3.discriminatedUnion("type", [
1146
+ z3.object({
1147
+ type: z3.literal("text"),
1148
+ value: z3.string().refine(
1149
+ (value) => vaultProviderWireUtf8Bytes(value) <= VAULT_LIMITS.textValueMaxBytes
1150
+ )
1151
+ }).strict(),
1152
+ /** An `otpauth://` URI or Base32 seed; Opengeni computes codes at use. */
1153
+ z3.object({ type: z3.literal("totp"), value: boundedText(VAULT_LIMITS.websiteMaxChars) }).strict(),
1154
+ z3.object({
1155
+ type: z3.literal("bytes"),
1156
+ base64: z3.string().max(Math.ceil(VAULT_LIMITS.fileValueMaxBytes / 3) * 4).regex(BASE64)
1157
+ }).strict()
1158
+ ])
1159
+ }).strict()
1160
+ );
1161
+ function valueBytes(field) {
1162
+ if (field.value.type === "bytes") return Math.floor(field.value.base64.length * 3 / 4);
1163
+ return vaultProviderWireUtf8Bytes(field.value.value);
1164
+ }
1165
+ var VaultProviderWireDescribeResult = /* @__PURE__ */ defineSchema(
1166
+ () => z3.object({
1167
+ /** Stable upstream account or bridge identity; reconnect rejects a change. */
1168
+ accountId: boundedText(VAULT_PROVIDER_WIRE_LIMITS.accountIdMaxChars),
1169
+ accountName: boundedText(VAULT_PROVIDER_WIRE_LIMITS.accountNameMaxChars).nullable(),
1170
+ operations: VaultProviderOperations,
1171
+ capabilities: z3.object({ totp: z3.boolean(), files: z3.boolean() }).strict(),
1172
+ /** One fixed inventory per connection, independent of the acting subject. */
1173
+ inventoryScope: z3.literal("connection")
1174
+ }).strict()
1175
+ );
1176
+ function pageOf(item) {
1177
+ return z3.object({
1178
+ items: z3.array(item).max(VAULT_PROVIDER_WIRE_LIMITS.pageSizeMax),
1179
+ nextCursor: Cursor.nullable(),
1180
+ /** Null only when the receiver cannot supply snapshot consistency. */
1181
+ snapshot: Snapshot.nullable()
1182
+ }).strict();
1183
+ }
1184
+ var VaultProviderWireListVaultsResult = /* @__PURE__ */ defineSchema(
1185
+ () => pageOf(VaultProviderWireVault)
1186
+ );
1187
+ var VaultProviderWireListItemsResult = /* @__PURE__ */ defineSchema(
1188
+ () => pageOf(VaultProviderWireItemMeta)
1189
+ );
1190
+ var VaultProviderWireReadFieldsResult = /* @__PURE__ */ defineSchema(
1191
+ () => z3.object({
1192
+ fields: z3.array(VaultProviderWireFieldValue).max(VAULT_PROVIDER_WIRE_LIMITS.readFieldsMax).refine((fields) => uniqueBy(fields, (field) => field.externalFieldId), "duplicate fields").refine(
1193
+ (fields) => fields.reduce((total, field) => total + valueBytes(field), 0) <= VAULT_PROVIDER_WIRE_LIMITS.maxReadValueBytes,
1194
+ "secret values too large"
1195
+ )
1196
+ }).strict()
1197
+ );
1198
+ var VaultProviderWireRefreshResult = /* @__PURE__ */ defineSchema(
1199
+ () => z3.object({ refreshed: z3.literal(true) }).strict()
1200
+ );
1201
+ var VaultProviderWireWriteItemResult = /* @__PURE__ */ defineSchema(
1202
+ () => z3.object({ item: VaultProviderWireItemMeta }).strict()
1203
+ );
1204
+ var VaultProviderWireArchiveItemResult = /* @__PURE__ */ defineSchema(
1205
+ () => z3.object({ archived: z3.literal(true) }).strict()
1206
+ );
1207
+ var VaultProviderWireResults = {
1208
+ describe: VaultProviderWireDescribeResult,
1209
+ refresh: VaultProviderWireRefreshResult,
1210
+ list_vaults: VaultProviderWireListVaultsResult,
1211
+ list_items: VaultProviderWireListItemsResult,
1212
+ read_fields: VaultProviderWireReadFieldsResult,
1213
+ write_item: VaultProviderWireWriteItemResult,
1214
+ archive_item: VaultProviderWireArchiveItemResult
1215
+ };
1216
+ var VaultProviderWireError = /* @__PURE__ */ defineSchema(
1217
+ () => z3.object({
1218
+ code: VaultProviderWireErrorCode,
1219
+ retryAfterMs: z3.number().int().min(0).max(864e5).nullable()
1220
+ }).strict()
1221
+ );
1222
+ var VaultProviderWireResponseEnvelope = /* @__PURE__ */ defineSchema(
1223
+ () => z3.discriminatedUnion("ok", [
1224
+ z3.object({
1225
+ version: z3.literal(VAULT_PROVIDER_WIRE_VERSION),
1226
+ type: z3.literal("response"),
1227
+ requestId: z3.string().uuid(),
1228
+ ok: z3.literal(true),
1229
+ op: z3.enum(VAULT_PROVIDER_WIRE_OPERATIONS),
1230
+ result: z3.unknown(),
1231
+ freshness: VaultProviderWireFreshness.nullable()
1232
+ }).strict(),
1233
+ z3.object({
1234
+ version: z3.literal(VAULT_PROVIDER_WIRE_VERSION),
1235
+ type: z3.literal("response"),
1236
+ requestId: z3.string().uuid(),
1237
+ ok: z3.literal(false),
1238
+ op: z3.enum(VAULT_PROVIDER_WIRE_OPERATIONS),
1239
+ error: VaultProviderWireError,
1240
+ freshness: VaultProviderWireFreshness.nullable()
1241
+ }).strict()
1242
+ ])
1243
+ );
1244
+ function parseVaultProviderWireResponse(value, expected) {
1245
+ const envelope = VaultProviderWireResponseEnvelope.safeParse(value);
1246
+ if (!envelope.success) return null;
1247
+ const response = envelope.data;
1248
+ if (response.requestId !== expected.requestId || response.op !== expected.op) return null;
1249
+ if (!response.ok) return response;
1250
+ const result = VaultProviderWireResults[expected.op].safeParse(response.result);
1251
+ if (!result.success) return null;
1252
+ return { ...response, op: expected.op, result: result.data };
1253
+ }
1254
+
1255
+ export {
1256
+ SECRET_GENERATOR_DEFAULT_SYMBOLS,
1257
+ SECRET_GENERATOR_AMBIGUOUS_CHARACTERS,
1258
+ GeneratePasswordSpec,
1259
+ PasswordGeneratorError,
1260
+ passwordCharacterClasses,
1261
+ generatePassword,
1262
+ passwordStrength,
1263
+ VaultOwnerKind,
1264
+ VaultSource,
1265
+ VaultMode,
1266
+ VaultSyncStatus,
1267
+ VaultItemType,
1268
+ VaultFieldKind,
1269
+ VaultProviderOperations,
1270
+ VaultProviderFreshness,
1271
+ VAULT_LOOKUP_TIERS,
1272
+ VAULT_LIMITS,
1273
+ DEFAULT_VAULT_NAMES,
1274
+ VAULT_DEFAULT_PRIMARY_FIELD,
1275
+ PASSKEY_FIELD_NAMES,
1276
+ isValidSecretName,
1277
+ isReservedVaultFieldName,
1278
+ VaultName,
1279
+ VaultFieldName,
1280
+ VaultPolicy,
1281
+ VAULT_POLICY_ALL,
1282
+ intersectVaultPolicies,
1283
+ VaultAvailability,
1284
+ VaultSummary,
1285
+ VaultItemReferences,
1286
+ VaultItemSummary,
1287
+ VaultItemField,
1288
+ PasskeySummary,
1289
+ VaultItem,
1290
+ VaultVersionCreatedByKind,
1291
+ VaultFieldVersionMeta,
1292
+ CreateVaultRequest,
1293
+ UpdateVaultRequest,
1294
+ DeleteVaultRequest,
1295
+ exactlyOneValueSource,
1296
+ VaultFieldInput,
1297
+ CreateVaultItemRequest,
1298
+ UpdateVaultItemRequest,
1299
+ MoveVaultItemRequest,
1300
+ RevealVaultFieldRequest,
1301
+ RevealVaultFieldResponse,
1302
+ RestoreVaultFieldVersionRequest,
1303
+ ListVaultItemsQuery,
1304
+ ListVaultsResponse,
1305
+ ListVaultItemsResponse,
1306
+ ListVaultFieldVersionsResponse,
1307
+ SetSessionVaultPolicyRequest,
1308
+ SessionSecretsView,
1309
+ InstallOnePasswordRequest,
1310
+ ProviderVaultMeta,
1311
+ InstallOnePasswordResponse,
1312
+ OnePasswordConnectionSummary,
1313
+ ListOnePasswordConnectionsResponse,
1314
+ ReplaceOnePasswordTokenRequest,
1315
+ DisconnectOnePasswordResponse,
1316
+ ExternalVaultProviderKind,
1317
+ VaultProviderCredentials,
1318
+ InstallVaultProviderRequest,
1319
+ ReplaceVaultProviderCredentialsRequest,
1320
+ VaultProviderConnectionSummary,
1321
+ VaultProviderAvailability,
1322
+ ListVaultProviderConnectionsResponse,
1323
+ InstallVaultProviderResponse,
1324
+ DisconnectVaultProviderResponse,
1325
+ LinkProviderVaultRequest,
1326
+ CreateManagedProviderVaultRequest,
1327
+ VaultErrorCode,
1328
+ VaultApiError,
1329
+ VAULT_ERROR_HTTP_STATUS,
1330
+ SECRET_TOOL_NAMES,
1331
+ SECRET_SAVE_TO,
1332
+ SecretSearchInput,
1333
+ SecretSearchResult,
1334
+ SecretSearchVault,
1335
+ SecretSearchOutput,
1336
+ SecretSaveFieldInput,
1337
+ SecretSaveInput,
1338
+ SecretSaveOutput,
1339
+ SecretGetInput,
1340
+ SecretGetOutput,
1341
+ SecretMoveInput,
1342
+ SecretMoveOutput,
1343
+ SecretDeleteInput,
1344
+ SecretDeleteOutput,
1345
+ VAULT_POLICY_UPDATED_EVENT_TYPE,
1346
+ VAULT_AUDIT_ACTIONS,
1347
+ VaultAuditAction,
1348
+ VAULT_AUDIT_TARGET_TYPES,
1349
+ VAULT_METRIC_NAMES,
1350
+ VAULT_PROVIDER_WIRE_VERSION,
1351
+ VAULT_PROVIDER_WIRE_RESPONSE_SIGNATURE_HEADER,
1352
+ vaultProviderWireResponseKey,
1353
+ VAULT_PROVIDER_WIRE_LIMITS,
1354
+ VAULT_PROVIDER_WIRE_ERROR_CODES,
1355
+ VAULT_PROVIDER_WIRE_OPERATIONS,
1356
+ isVaultProviderWireMutation,
1357
+ VaultProviderWireProvider,
1358
+ vaultProviderWireUtf8Bytes,
1359
+ vaultProviderWireNameKey,
1360
+ VaultProviderWireAuthority,
1361
+ VaultProviderWirePage,
1362
+ VaultProviderWireWriteField,
1363
+ VaultProviderWireWriteItem,
1364
+ VaultProviderWireOperation,
1365
+ VaultProviderWireRequest,
1366
+ VaultProviderWireErrorCode,
1367
+ VaultProviderWireFreshness,
1368
+ VaultProviderWireVault,
1369
+ VaultProviderWireFieldMeta,
1370
+ VaultProviderWireItemMeta,
1371
+ VaultProviderWireFieldValue,
1372
+ VaultProviderWireDescribeResult,
1373
+ VaultProviderWireListVaultsResult,
1374
+ VaultProviderWireListItemsResult,
1375
+ VaultProviderWireReadFieldsResult,
1376
+ VaultProviderWireRefreshResult,
1377
+ VaultProviderWireWriteItemResult,
1378
+ VaultProviderWireArchiveItemResult,
1379
+ VaultProviderWireResults,
1380
+ VaultProviderWireError,
1381
+ VaultProviderWireResponseEnvelope,
1382
+ parseVaultProviderWireResponse
1383
+ };
1384
+ //# sourceMappingURL=chunk-C6HESWDB.js.map