@opengeni/vaults 0.0.0-stage → 1.4.5-canary.38367122680001

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/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Cloudgeni-ai
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,22 @@
1
- # Temporary Holding Version
1
+ # `@opengeni/vaults`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Provider-side building blocks for Opengeni secrets (vaults). The shared types
4
+ (vaults, items, references, the resolver contract, the password generator and
5
+ TOTP) live in `@opengeni/contracts`; access decisions and the hosted resolver
6
+ live in `@opengeni/core` (`domain/vaults`).
7
+
8
+ This package owns:
9
+
10
+ - `VaultProvider`, the interface every external vault source implements
11
+ (1Password in `@opengeni/vaults-onepassword`, an embedder's host provider,
12
+ and the in-memory fake), plus `VaultProviderError` and its codes;
13
+ - `createVaultProviderRegistry`, which picks the provider for a vault;
14
+ - `createProviderCallBudget`, the per-attempt provider call budget;
15
+ - the shell splice contract (`spliceShellCommand`, `dialectFromShell`) used
16
+ by `exec_command` and `run_on` to turn references into per-command
17
+ environment variables;
18
+ - test doubles under `@opengeni/vaults/testing`: `createFakeVaultProvider`,
19
+ `createStaticSecretResolver` and `runVaultProviderContractSuite`.
20
+
21
+ Providers never see principals: access is decided before a provider is called.
22
+ Provider errors always map to a `VaultProviderErrorCode`; nothing is swallowed.
@@ -0,0 +1,229 @@
1
+ import {
2
+ VaultProviderError
3
+ } from "./chunk-NBSBMJIA.js";
4
+
5
+ // src/testing/fake-provider.ts
6
+ import { parseTotpInput } from "@opengeni/contracts";
7
+ var fakeIdCounter = 0;
8
+ function fakeId(prefix) {
9
+ fakeIdCounter += 1;
10
+ return `${prefix}${fakeIdCounter.toString(36).padStart(6, "0")}`;
11
+ }
12
+ function materialFor(field) {
13
+ if (field.kind === "totp") return { type: "totp", params: parseTotpInput(field.value) };
14
+ if (field.kind === "file") {
15
+ return { type: "bytes", value: Uint8Array.from(atob(field.value), (c) => c.charCodeAt(0)) };
16
+ }
17
+ return { type: "text", value: field.value };
18
+ }
19
+ function itemMeta(item) {
20
+ return {
21
+ externalItemId: item.externalItemId,
22
+ name: item.name,
23
+ type: item.type,
24
+ websites: [...item.websites],
25
+ fields: item.fields.map(({ externalFieldId, name, kind }) => ({ externalFieldId, name, kind })),
26
+ version: String(item.version),
27
+ updatedAt: item.updatedAt
28
+ };
29
+ }
30
+ function vaultMeta(vault) {
31
+ return {
32
+ externalVaultId: vault.externalVaultId,
33
+ name: vault.name,
34
+ contentVersion: String(vault.contentVersion),
35
+ itemCount: vault.items.filter((item) => !item.archived).length
36
+ };
37
+ }
38
+ function createFakeVaultProvider(seed = {}) {
39
+ const calls = [];
40
+ const now = () => (/* @__PURE__ */ new Date()).toISOString();
41
+ const vaults = (seed.vaults ?? []).map((vault) => ({
42
+ externalVaultId: vault.externalVaultId ?? fakeId("fv"),
43
+ name: vault.name,
44
+ contentVersion: 1,
45
+ readOnly: vault.readOnly ?? false,
46
+ items: (vault.items ?? []).map((item) => ({
47
+ externalItemId: item.externalItemId ?? fakeId("fi"),
48
+ name: item.name,
49
+ type: item.type ?? "login",
50
+ websites: item.websites ?? [],
51
+ version: 1,
52
+ archived: false,
53
+ updatedAt: now(),
54
+ fields: item.fields.map((field) => ({
55
+ externalFieldId: field.externalFieldId ?? fakeId("ff"),
56
+ name: field.name,
57
+ kind: field.kind ?? (field.name === "username" ? "text" : "concealed"),
58
+ value: field.value
59
+ }))
60
+ }))
61
+ }));
62
+ const capabilities = {
63
+ write: true,
64
+ createVault: true,
65
+ totp: true,
66
+ files: true,
67
+ groupGrants: false,
68
+ ...seed.capabilities,
69
+ passkeys: false
70
+ };
71
+ function charge(ctx, call, op) {
72
+ calls.push(call);
73
+ if (ctx.signal?.aborted) throw new VaultProviderError("provider_unavailable", "aborted");
74
+ ctx.budget.take(op);
75
+ if (seed.failWith)
76
+ throw new VaultProviderError(seed.failWith, `fake provider: ${seed.failWith}`);
77
+ }
78
+ function vaultById(id) {
79
+ const vault = vaults.find((candidate) => candidate.externalVaultId === id);
80
+ if (!vault) throw new VaultProviderError("provider_not_found", "vault not found");
81
+ return vault;
82
+ }
83
+ function writableVault(id) {
84
+ const vault = vaultById(id);
85
+ if (vault.readOnly)
86
+ throw new VaultProviderError(
87
+ "provider_permission_denied",
88
+ "vault is read-only for this credential"
89
+ );
90
+ return vault;
91
+ }
92
+ function itemById(vault, id) {
93
+ const item = vault.items.find(
94
+ (candidate) => candidate.externalItemId === id && !candidate.archived
95
+ );
96
+ if (!item) throw new VaultProviderError("provider_not_found", "item not found");
97
+ return item;
98
+ }
99
+ const provider = {
100
+ id: "fake",
101
+ calls,
102
+ capabilities: () => ({ ...capabilities }),
103
+ async validate(ctx) {
104
+ charge(ctx, { op: "validate", connectionId: ctx.connectionId }, "admin");
105
+ return { accountName: seed.accountName ?? "Fake account" };
106
+ },
107
+ async listVaults(ctx) {
108
+ charge(ctx, { op: "listVaults", connectionId: ctx.connectionId }, "list");
109
+ return vaults.map(vaultMeta);
110
+ },
111
+ async listItems(ctx, externalVaultId) {
112
+ charge(ctx, { op: "listItems", connectionId: ctx.connectionId, externalVaultId }, "list");
113
+ return vaultById(externalVaultId).items.filter((item) => !item.archived).map(itemMeta);
114
+ },
115
+ async readFields(ctx, externalVaultId, externalItemId, externalFieldIds) {
116
+ charge(
117
+ ctx,
118
+ {
119
+ op: "readFields",
120
+ connectionId: ctx.connectionId,
121
+ externalVaultId,
122
+ externalItemId,
123
+ externalFieldIds
124
+ },
125
+ "read"
126
+ );
127
+ const item = itemById(vaultById(externalVaultId), externalItemId);
128
+ return externalFieldIds.map((externalFieldId) => {
129
+ const field = item.fields.find(
130
+ (candidate) => candidate.externalFieldId === externalFieldId
131
+ );
132
+ if (!field) throw new VaultProviderError("provider_not_found", "field not found");
133
+ return { externalFieldId, material: materialFor(field) };
134
+ });
135
+ },
136
+ async writeItem(ctx, externalVaultId, input) {
137
+ charge(
138
+ ctx,
139
+ {
140
+ op: "writeItem",
141
+ connectionId: ctx.connectionId,
142
+ externalVaultId,
143
+ ...input.externalItemId ? { externalItemId: input.externalItemId } : {}
144
+ },
145
+ "write"
146
+ );
147
+ if (!capabilities.write)
148
+ throw new VaultProviderError("provider_conflict", "provider is read-only");
149
+ const vault = writableVault(externalVaultId);
150
+ let item;
151
+ if (input.externalItemId) {
152
+ item = itemById(vault, input.externalItemId);
153
+ if (input.expectedVersion != null && input.expectedVersion !== String(item.version)) {
154
+ throw new VaultProviderError("provider_conflict", "item changed since it was read");
155
+ }
156
+ } else {
157
+ item = {
158
+ externalItemId: fakeId("fi"),
159
+ name: input.name,
160
+ type: input.type,
161
+ websites: [],
162
+ fields: [],
163
+ version: 0,
164
+ archived: false,
165
+ updatedAt: now()
166
+ };
167
+ vault.items.push(item);
168
+ }
169
+ item.name = input.name;
170
+ item.type = input.type;
171
+ item.websites = [...input.websites];
172
+ for (const change of input.fields) {
173
+ const existing = item.fields.find(
174
+ (field) => change.externalFieldId !== void 0 && field.externalFieldId === change.externalFieldId || change.externalFieldId === void 0 && field.name === change.name
175
+ );
176
+ if (change.remove) {
177
+ if (existing) item.fields.splice(item.fields.indexOf(existing), 1);
178
+ continue;
179
+ }
180
+ if (existing) {
181
+ existing.name = change.name;
182
+ existing.kind = change.kind;
183
+ if (change.value !== void 0) existing.value = change.value;
184
+ } else {
185
+ item.fields.push({
186
+ externalFieldId: fakeId("ff"),
187
+ name: change.name,
188
+ kind: change.kind,
189
+ value: change.value ?? ""
190
+ });
191
+ }
192
+ }
193
+ item.version += 1;
194
+ item.updatedAt = now();
195
+ vault.contentVersion += 1;
196
+ return itemMeta(item);
197
+ },
198
+ async archiveItem(ctx, externalVaultId, externalItemId) {
199
+ charge(
200
+ ctx,
201
+ { op: "archiveItem", connectionId: ctx.connectionId, externalVaultId, externalItemId },
202
+ "write"
203
+ );
204
+ const vault = writableVault(externalVaultId);
205
+ itemById(vault, externalItemId).archived = true;
206
+ vault.contentVersion += 1;
207
+ },
208
+ async createVault(ctx, input) {
209
+ charge(ctx, { op: "createVault", connectionId: ctx.connectionId }, "admin");
210
+ if (!capabilities.createVault)
211
+ throw new VaultProviderError("provider_conflict", "cannot create vaults");
212
+ const vault = {
213
+ externalVaultId: fakeId("fv"),
214
+ name: input.name,
215
+ items: [],
216
+ contentVersion: 1,
217
+ readOnly: false
218
+ };
219
+ vaults.push(vault);
220
+ return vaultMeta(vault);
221
+ }
222
+ };
223
+ return provider;
224
+ }
225
+
226
+ export {
227
+ createFakeVaultProvider
228
+ };
229
+ //# sourceMappingURL=chunk-M7JOCNPD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/testing/fake-provider.ts"],"sourcesContent":["import type { SecretMaterial, VaultFieldKind, VaultItemType } from \"@opengeni/contracts\";\nimport { parseTotpInput } from \"@opengeni/contracts\";\nimport {\n VaultProviderError,\n type ProviderItemMeta,\n type ProviderVault,\n type VaultProvider,\n type VaultProviderCapabilities,\n type VaultProviderContext,\n type VaultProviderErrorCode,\n} from \"../provider\";\n\nexport interface FakeProviderSeedField {\n externalFieldId?: string;\n name: string;\n kind?: VaultFieldKind;\n value: string;\n}\nexport interface FakeProviderSeedItem {\n externalItemId?: string;\n name: string;\n type?: VaultItemType;\n websites?: string[];\n fields: FakeProviderSeedField[];\n}\nexport interface FakeProviderSeedVault {\n externalVaultId?: string;\n name: string;\n items?: FakeProviderSeedItem[];\n /** The credential can read but not write this vault (`provider_permission_denied`). */\n readOnly?: boolean;\n}\nexport interface FakeProviderSeed {\n accountName?: string | null;\n vaults?: FakeProviderSeedVault[];\n capabilities?: Partial<Omit<VaultProviderCapabilities, \"passkeys\">>;\n /** Every call fails with this code (auth, outage and rate-limit tests). */\n failWith?: VaultProviderErrorCode | null;\n}\nexport interface FakeProviderCall {\n op:\n | \"validate\"\n | \"listVaults\"\n | \"listItems\"\n | \"readFields\"\n | \"writeItem\"\n | \"archiveItem\"\n | \"createVault\";\n connectionId: string | null;\n externalVaultId?: string;\n externalItemId?: string;\n externalFieldIds?: readonly string[];\n}\n\ninterface FakeField {\n externalFieldId: string;\n name: string;\n kind: VaultFieldKind;\n value: string;\n}\ninterface FakeItem {\n externalItemId: string;\n name: string;\n type: VaultItemType;\n websites: string[];\n fields: FakeField[];\n version: number;\n archived: boolean;\n updatedAt: string;\n}\ninterface FakeVault {\n externalVaultId: string;\n name: string;\n items: FakeItem[];\n contentVersion: number;\n readOnly: boolean;\n}\n\nlet fakeIdCounter = 0;\nfunction fakeId(prefix: string): string {\n fakeIdCounter += 1;\n return `${prefix}${fakeIdCounter.toString(36).padStart(6, \"0\")}`;\n}\n\nfunction materialFor(field: FakeField): SecretMaterial {\n if (field.kind === \"totp\") return { type: \"totp\", params: parseTotpInput(field.value) };\n if (field.kind === \"file\") {\n return { type: \"bytes\", value: Uint8Array.from(atob(field.value), (c) => c.charCodeAt(0)) };\n }\n return { type: \"text\", value: field.value };\n}\n\nfunction itemMeta(item: FakeItem): ProviderItemMeta {\n return {\n externalItemId: item.externalItemId,\n name: item.name,\n type: item.type,\n websites: [...item.websites],\n fields: item.fields.map(({ externalFieldId, name, kind }) => ({ externalFieldId, name, kind })),\n version: String(item.version),\n updatedAt: item.updatedAt,\n };\n}\n\nfunction vaultMeta(vault: FakeVault): ProviderVault {\n return {\n externalVaultId: vault.externalVaultId,\n name: vault.name,\n contentVersion: String(vault.contentVersion),\n itemCount: vault.items.filter((item) => !item.archived).length,\n };\n}\n\n/**\n * In-memory `VaultProvider` for tests and local development. Values are\n * kept in memory only; every call is recorded in `calls` (without values) and\n * charged to the context budget like a real provider.\n */\nexport function createFakeVaultProvider(\n seed: FakeProviderSeed = {},\n): VaultProvider & { calls: FakeProviderCall[] } {\n const calls: FakeProviderCall[] = [];\n const now = () => new Date().toISOString();\n const vaults: FakeVault[] = (seed.vaults ?? []).map((vault) => ({\n externalVaultId: vault.externalVaultId ?? fakeId(\"fv\"),\n name: vault.name,\n contentVersion: 1,\n readOnly: vault.readOnly ?? false,\n items: (vault.items ?? []).map((item) => ({\n externalItemId: item.externalItemId ?? fakeId(\"fi\"),\n name: item.name,\n type: item.type ?? \"login\",\n websites: item.websites ?? [],\n version: 1,\n archived: false,\n updatedAt: now(),\n fields: item.fields.map((field) => ({\n externalFieldId: field.externalFieldId ?? fakeId(\"ff\"),\n name: field.name,\n kind: field.kind ?? (field.name === \"username\" ? \"text\" : \"concealed\"),\n value: field.value,\n })),\n })),\n }));\n const capabilities: VaultProviderCapabilities = {\n write: true,\n createVault: true,\n totp: true,\n files: true,\n groupGrants: false,\n ...seed.capabilities,\n passkeys: false,\n };\n\n function charge(\n ctx: VaultProviderContext,\n call: FakeProviderCall,\n op: \"list\" | \"read\" | \"write\" | \"admin\",\n ) {\n calls.push(call);\n if (ctx.signal?.aborted) throw new VaultProviderError(\"provider_unavailable\", \"aborted\");\n ctx.budget.take(op);\n if (seed.failWith)\n throw new VaultProviderError(seed.failWith, `fake provider: ${seed.failWith}`);\n }\n function vaultById(id: string): FakeVault {\n const vault = vaults.find((candidate) => candidate.externalVaultId === id);\n if (!vault) throw new VaultProviderError(\"provider_not_found\", \"vault not found\");\n return vault;\n }\n function writableVault(id: string): FakeVault {\n const vault = vaultById(id);\n if (vault.readOnly)\n throw new VaultProviderError(\n \"provider_permission_denied\",\n \"vault is read-only for this credential\",\n );\n return vault;\n }\n function itemById(vault: FakeVault, id: string): FakeItem {\n const item = vault.items.find(\n (candidate) => candidate.externalItemId === id && !candidate.archived,\n );\n if (!item) throw new VaultProviderError(\"provider_not_found\", \"item not found\");\n return item;\n }\n\n const provider: VaultProvider & { calls: FakeProviderCall[] } = {\n id: \"fake\",\n calls,\n capabilities: () => ({ ...capabilities }),\n async validate(ctx) {\n charge(ctx, { op: \"validate\", connectionId: ctx.connectionId }, \"admin\");\n return { accountName: seed.accountName ?? \"Fake account\" };\n },\n async listVaults(ctx) {\n charge(ctx, { op: \"listVaults\", connectionId: ctx.connectionId }, \"list\");\n return vaults.map(vaultMeta);\n },\n async listItems(ctx, externalVaultId) {\n charge(ctx, { op: \"listItems\", connectionId: ctx.connectionId, externalVaultId }, \"list\");\n return vaultById(externalVaultId)\n .items.filter((item) => !item.archived)\n .map(itemMeta);\n },\n async readFields(ctx, externalVaultId, externalItemId, externalFieldIds) {\n charge(\n ctx,\n {\n op: \"readFields\",\n connectionId: ctx.connectionId,\n externalVaultId,\n externalItemId,\n externalFieldIds,\n },\n \"read\",\n );\n const item = itemById(vaultById(externalVaultId), externalItemId);\n return externalFieldIds.map((externalFieldId) => {\n const field = item.fields.find(\n (candidate) => candidate.externalFieldId === externalFieldId,\n );\n if (!field) throw new VaultProviderError(\"provider_not_found\", \"field not found\");\n return { externalFieldId, material: materialFor(field) };\n });\n },\n async writeItem(ctx, externalVaultId, input) {\n charge(\n ctx,\n {\n op: \"writeItem\",\n connectionId: ctx.connectionId,\n externalVaultId,\n ...(input.externalItemId ? { externalItemId: input.externalItemId } : {}),\n },\n \"write\",\n );\n if (!capabilities.write)\n throw new VaultProviderError(\"provider_conflict\", \"provider is read-only\");\n const vault = writableVault(externalVaultId);\n let item: FakeItem;\n if (input.externalItemId) {\n item = itemById(vault, input.externalItemId);\n if (input.expectedVersion != null && input.expectedVersion !== String(item.version)) {\n throw new VaultProviderError(\"provider_conflict\", \"item changed since it was read\");\n }\n } else {\n item = {\n externalItemId: fakeId(\"fi\"),\n name: input.name,\n type: input.type,\n websites: [],\n fields: [],\n version: 0,\n archived: false,\n updatedAt: now(),\n };\n vault.items.push(item);\n }\n item.name = input.name;\n item.type = input.type;\n item.websites = [...input.websites];\n for (const change of input.fields) {\n const existing = item.fields.find(\n (field) =>\n (change.externalFieldId !== undefined &&\n field.externalFieldId === change.externalFieldId) ||\n (change.externalFieldId === undefined && field.name === change.name),\n );\n if (change.remove) {\n if (existing) item.fields.splice(item.fields.indexOf(existing), 1);\n continue;\n }\n if (existing) {\n existing.name = change.name;\n existing.kind = change.kind;\n if (change.value !== undefined) existing.value = change.value;\n } else {\n item.fields.push({\n externalFieldId: fakeId(\"ff\"),\n name: change.name,\n kind: change.kind,\n value: change.value ?? \"\",\n });\n }\n }\n item.version += 1;\n item.updatedAt = now();\n vault.contentVersion += 1;\n return itemMeta(item);\n },\n async archiveItem(ctx, externalVaultId, externalItemId) {\n charge(\n ctx,\n { op: \"archiveItem\", connectionId: ctx.connectionId, externalVaultId, externalItemId },\n \"write\",\n );\n const vault = writableVault(externalVaultId);\n itemById(vault, externalItemId).archived = true;\n vault.contentVersion += 1;\n },\n async createVault(ctx, input) {\n charge(ctx, { op: \"createVault\", connectionId: ctx.connectionId }, \"admin\");\n if (!capabilities.createVault)\n throw new VaultProviderError(\"provider_conflict\", \"cannot create vaults\");\n const vault: FakeVault = {\n externalVaultId: fakeId(\"fv\"),\n name: input.name,\n items: [],\n contentVersion: 1,\n readOnly: false,\n };\n vaults.push(vault);\n return vaultMeta(vault);\n },\n };\n return provider;\n}\n"],"mappings":";;;;;AACA,SAAS,sBAAsB;AA6E/B,IAAI,gBAAgB;AACpB,SAAS,OAAO,QAAwB;AACtC,mBAAiB;AACjB,SAAO,GAAG,MAAM,GAAG,cAAc,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC;AAChE;AAEA,SAAS,YAAY,OAAkC;AACrD,MAAI,MAAM,SAAS,OAAQ,QAAO,EAAE,MAAM,QAAQ,QAAQ,eAAe,MAAM,KAAK,EAAE;AACtF,MAAI,MAAM,SAAS,QAAQ;AACzB,WAAO,EAAE,MAAM,SAAS,OAAO,WAAW,KAAK,KAAK,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,EAAE;AAAA,EAC5F;AACA,SAAO,EAAE,MAAM,QAAQ,OAAO,MAAM,MAAM;AAC5C;AAEA,SAAS,SAAS,MAAkC;AAClD,SAAO;AAAA,IACL,gBAAgB,KAAK;AAAA,IACrB,MAAM,KAAK;AAAA,IACX,MAAM,KAAK;AAAA,IACX,UAAU,CAAC,GAAG,KAAK,QAAQ;AAAA,IAC3B,QAAQ,KAAK,OAAO,IAAI,CAAC,EAAE,iBAAiB,MAAM,KAAK,OAAO,EAAE,iBAAiB,MAAM,KAAK,EAAE;AAAA,IAC9F,SAAS,OAAO,KAAK,OAAO;AAAA,IAC5B,WAAW,KAAK;AAAA,EAClB;AACF;AAEA,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AAO;AAC5B,aAAO,KAAK,EAAE,IAAI,eAAe,cAAc,IAAI,aAAa,GAAG,OAAO;AAC1E,UAAI,CAAC,aAAa;AAChB,cAAM,IAAI,mBAAmB,qBAAqB,sBAAsB;AAC1E,YAAM,QAAmB;AAAA,QACvB,iBAAiB,OAAO,IAAI;AAAA,QAC5B,MAAM,MAAM;AAAA,QACZ,OAAO,CAAC;AAAA,QACR,gBAAgB;AAAA,QAChB,UAAU;AAAA,MACZ;AACA,aAAO,KAAK,KAAK;AACjB,aAAO,UAAU,KAAK;AAAA,IACxB;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
@@ -0,0 +1,68 @@
1
+ // src/provider.ts
2
+ var VAULT_PROVIDER_ERROR_CODES = [
3
+ "provider_auth_invalid",
4
+ "provider_auth_expired",
5
+ "provider_rate_limited",
6
+ "provider_unavailable",
7
+ "provider_conflict",
8
+ "provider_not_found",
9
+ /**
10
+ * The provider refused the operation for this credential (for example a
11
+ * write into a 1Password vault the service account can only read). The vault
12
+ * service reports `vault_read_only` for writes, `vault_permission_denied` otherwise.
13
+ */
14
+ "provider_permission_denied"
15
+ ];
16
+ var VaultProviderError = class extends Error {
17
+ code;
18
+ retryAfterMs;
19
+ constructor(code, message, retryAfterMs) {
20
+ super(message);
21
+ this.name = "VaultProviderError";
22
+ this.code = code;
23
+ this.retryAfterMs = retryAfterMs;
24
+ }
25
+ };
26
+ function isVaultProviderError(error) {
27
+ return error instanceof VaultProviderError;
28
+ }
29
+ function createVaultProviderRegistry(factories) {
30
+ return {
31
+ async forVault(vault) {
32
+ if (vault.source === "onepassword" && factories.onepassword) {
33
+ return factories.onepassword(vault.providerConnectionId);
34
+ }
35
+ if (vault.source === "host" && factories.host) return factories.host();
36
+ throw new VaultProviderError(
37
+ "provider_unavailable",
38
+ vault.source === "opengeni" ? "hosted vaults are read from the database, not a provider" : `no ${vault.source} vault provider is configured`
39
+ );
40
+ }
41
+ };
42
+ }
43
+ var EMPTY_VAULT_PROVIDER_REGISTRY = createVaultProviderRegistry({});
44
+ function createProviderCallBudget(limit) {
45
+ let used = 0;
46
+ return {
47
+ take(op) {
48
+ if (used >= limit) {
49
+ throw new VaultProviderError(
50
+ "provider_rate_limited",
51
+ `this attempt used its ${limit} vault provider calls (last: ${op})`
52
+ );
53
+ }
54
+ used += 1;
55
+ },
56
+ used: () => used
57
+ };
58
+ }
59
+
60
+ export {
61
+ VAULT_PROVIDER_ERROR_CODES,
62
+ VaultProviderError,
63
+ isVaultProviderError,
64
+ createVaultProviderRegistry,
65
+ EMPTY_VAULT_PROVIDER_REGISTRY,
66
+ createProviderCallBudget
67
+ };
68
+ //# sourceMappingURL=chunk-NBSBMJIA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/provider.ts"],"sourcesContent":["import type {\n ConnectionCredentialsPort,\n SecretMaterial,\n VaultFieldKind,\n VaultItemType,\n VaultSource,\n} from \"@opengeni/contracts\";\n\nexport interface VaultProviderCapabilities {\n write: boolean;\n createVault: boolean;\n totp: boolean;\n files: boolean;\n groupGrants: boolean;\n /** Passkeys live only in OpenGeni-hosted vaults (D20). */\n passkeys: false;\n}\nexport interface ProviderVault {\n externalVaultId: string;\n name: string;\n contentVersion: string | null;\n itemCount: number | null;\n}\nexport interface ProviderFieldMeta {\n externalFieldId: string;\n name: string;\n kind: VaultFieldKind;\n}\nexport interface ProviderItemMeta {\n externalItemId: string;\n name: string;\n type: VaultItemType;\n websites: string[];\n fields: ProviderFieldMeta[];\n version: string | null;\n updatedAt: string | null;\n}\nexport interface ProviderFieldValue {\n externalFieldId: string;\n material: SecretMaterial;\n}\nexport interface ProviderWriteField {\n externalFieldId?: string;\n name: string;\n kind: VaultFieldKind;\n value?: string;\n remove?: true;\n}\nexport interface ProviderWriteItem {\n externalItemId?: string;\n expectedVersion?: string | null;\n name: string;\n type: VaultItemType;\n websites: string[];\n fields: ProviderWriteField[];\n}\nexport type ProviderCallOperation = \"list\" | \"read\" | \"write\" | \"admin\";\nexport interface ProviderCallBudget {\n /** Throws VaultProviderError(\"provider_rate_limited\") when exhausted. */\n take(op: ProviderCallOperation): void;\n}\nexport interface VaultProviderContext {\n connectionId: string | null;\n budget: ProviderCallBudget;\n signal?: AbortSignal;\n}\nexport interface VaultProvider {\n readonly id: \"onepassword\" | \"host\" | \"fake\";\n capabilities(): VaultProviderCapabilities;\n validate(ctx: VaultProviderContext): Promise<{ accountName: string | null }>;\n listVaults(ctx: VaultProviderContext): Promise<ProviderVault[]>;\n listItems(ctx: VaultProviderContext, externalVaultId: string): Promise<ProviderItemMeta[]>;\n readFields(\n ctx: VaultProviderContext,\n externalVaultId: string,\n externalItemId: string,\n externalFieldIds: readonly string[],\n ): Promise<ProviderFieldValue[]>;\n writeItem(\n ctx: VaultProviderContext,\n externalVaultId: string,\n item: ProviderWriteItem,\n ): Promise<ProviderItemMeta>;\n archiveItem(\n ctx: VaultProviderContext,\n externalVaultId: string,\n externalItemId: string,\n ): Promise<void>;\n createVault?(\n ctx: VaultProviderContext,\n input: { name: string; description?: string; allowAdminsAccess: boolean; groupId?: string },\n ): Promise<ProviderVault>;\n}\n\nexport const VAULT_PROVIDER_ERROR_CODES = [\n \"provider_auth_invalid\",\n \"provider_auth_expired\",\n \"provider_rate_limited\",\n \"provider_unavailable\",\n \"provider_conflict\",\n \"provider_not_found\",\n /**\n * The provider refused the operation for this credential (for example a\n * write into a 1Password vault the service account can only read). The vault\n * service reports `vault_read_only` for writes, `vault_permission_denied` otherwise.\n */\n \"provider_permission_denied\",\n] as const;\nexport type VaultProviderErrorCode = (typeof VAULT_PROVIDER_ERROR_CODES)[number];\n\nexport class VaultProviderError extends Error {\n readonly code: VaultProviderErrorCode;\n readonly retryAfterMs: number | undefined;\n constructor(code: VaultProviderErrorCode, message: string, retryAfterMs?: number) {\n super(message);\n this.name = \"VaultProviderError\";\n this.code = code;\n this.retryAfterMs = retryAfterMs;\n }\n}\n\nexport function isVaultProviderError(error: unknown): error is VaultProviderError {\n return error instanceof VaultProviderError;\n}\n\n/**\n * The embedder's connection-credential port with its password-manager leg\n * (design §10.9, OP-6). `@opengeni/contracts` cannot name `VaultProvider`\n * (this package depends on it), so the leg is added here; core and worker\n * dependencies use this type. A host provider is linked as a vault with\n * `source: \"host\"` and resolved through `createVaultProviderRegistry({ host })`.\n */\nexport type VaultConnectionCredentialsPort = ConnectionCredentialsPort & {\n vaultProvider?: VaultProvider | null;\n};\n\nexport interface VaultProviderRegistry {\n /** onepassword: loads the connection credential and the SDK lazily; host: the embedder port; fake: tests/dev. */\n forVault(vault: {\n source: VaultSource;\n providerConnectionId: string | null;\n }): Promise<VaultProvider>;\n}\n\n/**\n * A registry over fixed provider factories. Missing providers raise\n * `provider_unavailable`; `opengeni` (hosted) vaults never reach a provider.\n */\nexport function createVaultProviderRegistry(factories: {\n onepassword?: (connectionId: string | null) => Promise<VaultProvider>;\n host?: () => Promise<VaultProvider>;\n}): VaultProviderRegistry {\n return {\n async forVault(vault) {\n if (vault.source === \"onepassword\" && factories.onepassword) {\n return factories.onepassword(vault.providerConnectionId);\n }\n if (vault.source === \"host\" && factories.host) return factories.host();\n throw new VaultProviderError(\n \"provider_unavailable\",\n vault.source === \"opengeni\"\n ? \"hosted vaults are read from the database, not a provider\"\n : `no ${vault.source} vault provider is configured`,\n );\n },\n };\n}\n\n/** A registry with no providers: every provider vault is unavailable. */\nexport const EMPTY_VAULT_PROVIDER_REGISTRY: VaultProviderRegistry = createVaultProviderRegistry({});\n\n/**\n * A simple counting budget: at most `limit` calls of any kind (Q-18 uses 50\n * reads per attempt). Exhaustion raises `provider_rate_limited`.\n */\nexport function createProviderCallBudget(limit: number): ProviderCallBudget & { used(): number } {\n let used = 0;\n return {\n take(op) {\n if (used >= limit) {\n throw new VaultProviderError(\n \"provider_rate_limited\",\n `this attempt used its ${limit} vault provider calls (last: ${op})`,\n );\n }\n used += 1;\n },\n used: () => used,\n };\n}\n"],"mappings":";AA8FO,IAAM,6BAA6B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AACF;AAGO,IAAM,qBAAN,cAAiC,MAAM;AAAA,EACnC;AAAA,EACA;AAAA,EACT,YAAY,MAA8B,SAAiB,cAAuB;AAChF,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,eAAe;AAAA,EACtB;AACF;AAEO,SAAS,qBAAqB,OAA6C;AAChF,SAAO,iBAAiB;AAC1B;AAyBO,SAAS,4BAA4B,WAGlB;AACxB,SAAO;AAAA,IACL,MAAM,SAAS,OAAO;AACpB,UAAI,MAAM,WAAW,iBAAiB,UAAU,aAAa;AAC3D,eAAO,UAAU,YAAY,MAAM,oBAAoB;AAAA,MACzD;AACA,UAAI,MAAM,WAAW,UAAU,UAAU,KAAM,QAAO,UAAU,KAAK;AACrE,YAAM,IAAI;AAAA,QACR;AAAA,QACA,MAAM,WAAW,aACb,6DACA,MAAM,MAAM,MAAM;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AACF;AAGO,IAAM,gCAAuD,4BAA4B,CAAC,CAAC;AAM3F,SAAS,yBAAyB,OAAwD;AAC/F,MAAI,OAAO;AACX,SAAO;AAAA,IACL,KAAK,IAAI;AACP,UAAI,QAAQ,OAAO;AACjB,cAAM,IAAI;AAAA,UACR;AAAA,UACA,yBAAyB,KAAK,gCAAgC,EAAE;AAAA,QAClE;AAAA,MACF;AACA,cAAQ;AAAA,IACV;AAAA,IACA,MAAM,MAAM;AAAA,EACd;AACF;","names":[]}
@@ -0,0 +1,2 @@
1
+ export * from "./provider.js";
2
+ export * from "./splice/index.js";