@tillstack/secrets-node 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
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 Derivative
95
+ 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 do
117
+ not modify the License. You may add Your own attribution notices
118
+ within Derivative Works that You distribute, alongside or as an
119
+ addendum to the NOTICE text from the Work, provided that such
120
+ additional attribution notices cannot be construed as modifying
121
+ 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
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 TillStack
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { SecretsClientOptions, SecretsClient, PullResult } from '@tillstack/secrets-core';
1
+ import { SecretsClientOptions, BrokerClient, SecretsClient, PullResult } from '@tillstack/secrets-core';
2
2
  export * from '@tillstack/secrets-core';
3
3
 
4
4
  /** Create a client from options or the environment (`TILLSECRETS_TOKEN`,
@@ -11,5 +11,39 @@ interface LoadOptions extends Partial<SecretsClientOptions> {
11
11
  }
12
12
  /** Pull secrets and inject them into process.env. Returns the pulled map. */
13
13
  declare function load(opts?: LoadOptions): Promise<PullResult>;
14
+ interface CreateBrokerOptions {
15
+ /** Force a transport. Default `auto`: use the LOCAL bridge when the process runs
16
+ * under the TillForge bridge daemon (`TILLDEV_BROKER_URL` set) — the strongest
17
+ * posture, the value never leaves the machine — otherwise the cloud broker. */
18
+ mode?: 'auto' | 'bridge' | 'cloud';
19
+ /** Cloud API base (derives the spend endpoint). Ignored in bridge mode.
20
+ * Defaults to `TILLDEV_URL` / `TILLSECRETS_URL` / `https://tilldev.dev`. */
21
+ url?: string;
22
+ /** Bearer token — a session / `tp_` API key (cloud, `TILLDEV_TOKEN`) or the
23
+ * bridge run token (`TILLDEV_BROKER_TOKEN`, injected by the daemon). */
24
+ token?: string;
25
+ /** Stable agent identity. Required in cloud mode (or `TILLDEV_AGENT_KEY`). */
26
+ agentKey?: string;
27
+ /** Session id for session-scoped grants (or `TILLDEV_SESSION`). */
28
+ sessionId?: string;
29
+ timeoutMs?: number;
30
+ fetch?: typeof fetch;
31
+ }
32
+ /**
33
+ * Create a secretless-broker client. In `auto` mode it prefers the local bridge
34
+ * proxy (value spent on the user's machine) when the daemon has injected
35
+ * `TILLDEV_BROKER_URL` + `TILLDEV_BROKER_TOKEN`, and otherwise talks to the cloud
36
+ * broker with a session / `tp_` token + an agent identity.
37
+ *
38
+ * import { createBroker, secretref } from '@tillstack/secrets-node'
39
+ * const broker = createBroker({ agentKey: 'my-job' })
40
+ * const res = await broker.fetch('https://api.stripe.com/v1/charges', {
41
+ * method: 'POST',
42
+ * headers: { authorization: `Bearer ${secretref('prod', 'live', 'STRIPE_KEY')}` },
43
+ * body,
44
+ * })
45
+ * // res.body is the scrubbed reply — the STRIPE_KEY never entered this process.
46
+ */
47
+ declare function createBroker(opts?: CreateBrokerOptions): BrokerClient;
14
48
 
15
- export { type LoadOptions, createClient, load };
49
+ export { type CreateBrokerOptions, type LoadOptions, createBroker, createClient, load };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SecretsClientOptions, SecretsClient, PullResult } from '@tillstack/secrets-core';
1
+ import { SecretsClientOptions, BrokerClient, SecretsClient, PullResult } from '@tillstack/secrets-core';
2
2
  export * from '@tillstack/secrets-core';
3
3
 
4
4
  /** Create a client from options or the environment (`TILLSECRETS_TOKEN`,
@@ -11,5 +11,39 @@ interface LoadOptions extends Partial<SecretsClientOptions> {
11
11
  }
12
12
  /** Pull secrets and inject them into process.env. Returns the pulled map. */
13
13
  declare function load(opts?: LoadOptions): Promise<PullResult>;
14
+ interface CreateBrokerOptions {
15
+ /** Force a transport. Default `auto`: use the LOCAL bridge when the process runs
16
+ * under the TillForge bridge daemon (`TILLDEV_BROKER_URL` set) — the strongest
17
+ * posture, the value never leaves the machine — otherwise the cloud broker. */
18
+ mode?: 'auto' | 'bridge' | 'cloud';
19
+ /** Cloud API base (derives the spend endpoint). Ignored in bridge mode.
20
+ * Defaults to `TILLDEV_URL` / `TILLSECRETS_URL` / `https://tilldev.dev`. */
21
+ url?: string;
22
+ /** Bearer token — a session / `tp_` API key (cloud, `TILLDEV_TOKEN`) or the
23
+ * bridge run token (`TILLDEV_BROKER_TOKEN`, injected by the daemon). */
24
+ token?: string;
25
+ /** Stable agent identity. Required in cloud mode (or `TILLDEV_AGENT_KEY`). */
26
+ agentKey?: string;
27
+ /** Session id for session-scoped grants (or `TILLDEV_SESSION`). */
28
+ sessionId?: string;
29
+ timeoutMs?: number;
30
+ fetch?: typeof fetch;
31
+ }
32
+ /**
33
+ * Create a secretless-broker client. In `auto` mode it prefers the local bridge
34
+ * proxy (value spent on the user's machine) when the daemon has injected
35
+ * `TILLDEV_BROKER_URL` + `TILLDEV_BROKER_TOKEN`, and otherwise talks to the cloud
36
+ * broker with a session / `tp_` token + an agent identity.
37
+ *
38
+ * import { createBroker, secretref } from '@tillstack/secrets-node'
39
+ * const broker = createBroker({ agentKey: 'my-job' })
40
+ * const res = await broker.fetch('https://api.stripe.com/v1/charges', {
41
+ * method: 'POST',
42
+ * headers: { authorization: `Bearer ${secretref('prod', 'live', 'STRIPE_KEY')}` },
43
+ * body,
44
+ * })
45
+ * // res.body is the scrubbed reply — the STRIPE_KEY never entered this process.
46
+ */
47
+ declare function createBroker(opts?: CreateBrokerOptions): BrokerClient;
14
48
 
15
- export { type LoadOptions, createClient, load };
49
+ export { type CreateBrokerOptions, type LoadOptions, createBroker, createClient, load };
package/dist/index.js CHANGED
@@ -23,7 +23,35 @@ async function load(opts = {}) {
23
23
  }
24
24
  return result;
25
25
  }
26
+ function createBroker(opts = {}) {
27
+ const bridgeUrl = process.env.TILLDEV_BROKER_URL;
28
+ const bridgeToken = process.env.TILLDEV_BROKER_TOKEN;
29
+ const useBridge = opts.mode === "bridge" || opts.mode !== "cloud" && !!bridgeUrl && !!bridgeToken;
30
+ const built = { endpoint: "", token: "" };
31
+ if (opts.timeoutMs !== void 0) built.timeoutMs = opts.timeoutMs;
32
+ if (opts.fetch) built.fetch = opts.fetch;
33
+ const agentKey = opts.agentKey ?? process.env.TILLDEV_AGENT_KEY;
34
+ if (agentKey) built.agentKey = agentKey;
35
+ const sessionId = opts.sessionId ?? process.env.TILLDEV_SESSION;
36
+ if (sessionId) built.sessionId = sessionId;
37
+ if (useBridge) {
38
+ if (!bridgeUrl || !bridgeToken) {
39
+ throw new secretsCore.SecretsError("TillSecrets broker: bridge mode needs TILLDEV_BROKER_URL + TILLDEV_BROKER_TOKEN");
40
+ }
41
+ built.endpoint = `${bridgeUrl.replace(/\/$/, "")}/spend`;
42
+ built.token = opts.token ?? bridgeToken;
43
+ return new secretsCore.BrokerClient(built);
44
+ }
45
+ const base = (opts.url ?? process.env.TILLDEV_URL ?? process.env.TILLSECRETS_URL ?? "https://tilldev.dev").replace(/\/$/, "");
46
+ const token = opts.token ?? process.env.TILLDEV_TOKEN ?? process.env.TILLSECRETS_BROKER_TOKEN;
47
+ if (!token) throw new secretsCore.SecretsError("TillSecrets broker: no token \u2014 pass one or set TILLDEV_TOKEN");
48
+ if (!built.agentKey) throw new secretsCore.SecretsError("TillSecrets broker: cloud mode needs an agentKey (or TILLDEV_AGENT_KEY)");
49
+ built.endpoint = `${base}/api/secrets/broker/spend`;
50
+ built.token = token;
51
+ return new secretsCore.BrokerClient(built);
52
+ }
26
53
 
54
+ exports.createBroker = createBroker;
27
55
  exports.createClient = createClient;
28
56
  exports.load = load;
29
57
  Object.keys(secretsCore).forEach(function (k) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["SecretsClient"],"mappings":";;;;;AAgBO,SAAS,aAAa,IAAA,EAAqD;AAChF,EAAA,MAAM,KAAA,GAAQ,IAAA,EAAM,KAAA,IAAS,OAAA,CAAQ,GAAA,CAAI,iBAAA;AACzC,EAAA,IAAI,CAAC,KAAA,EAAO,MAAM,IAAI,MAAM,gEAA2D,CAAA;AACvF,EAAA,MAAM,KAAA,GAA8B,EAAE,KAAA,EAAM;AAC5C,EAAA,MAAM,GAAA,GAAM,IAAA,EAAM,GAAA,IAAO,OAAA,CAAQ,GAAA,CAAI,eAAA;AACrC,EAAA,IAAI,GAAA,QAAW,GAAA,GAAM,GAAA;AACrB,EAAA,MAAM,GAAA,GAAM,IAAA,EAAM,aAAA,IAAiB,OAAA,CAAQ,GAAA,CAAI,eAAA;AAC/C,EAAA,IAAI,GAAA,QAAW,aAAA,GAAgB,GAAA;AAC/B,EAAA,IAAI,IAAA,EAAM,SAAA,KAAc,MAAA,EAAW,KAAA,CAAM,YAAY,IAAA,CAAK,SAAA;AAC1D,EAAA,IAAI,IAAA,EAAM,KAAA,EAAO,KAAA,CAAM,KAAA,GAAQ,IAAA,CAAK,KAAA;AACpC,EAAA,OAAO,IAAIA,0BAAc,KAAK,CAAA;AAChC;AASA,eAAsB,IAAA,CAAK,IAAA,GAAoB,EAAC,EAAwB;AACtE,EAAA,MAAM,MAAA,GAAS,aAAa,IAAI,CAAA;AAChC,EAAA,MAAM,MAAA,GAAS,MAAM,MAAA,CAAO,IAAA,EAAK;AACjC,EAAA,KAAA,MAAW,CAAC,GAAG,CAAC,CAAA,IAAK,OAAO,OAAA,CAAQ,MAAA,CAAO,OAAO,CAAA,EAAG;AACnD,IAAA,IAAI,IAAA,CAAK,QAAA,IAAY,OAAA,CAAQ,GAAA,CAAI,CAAC,MAAM,MAAA,EAAW,OAAA,CAAQ,GAAA,CAAI,CAAC,CAAA,GAAI,CAAA;AAAA,EACtE;AACA,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["// @tillstack/secrets-node — TillSecrets client for Node.js.\n//\n// import { load } from '@tillstack/secrets-node'\n// await load() // reads TILLSECRETS_TOKEN, injects into process.env\n// // ... process.env.STRIPE_KEY is now populated\n//\n// or explicitly:\n// const client = createClient({ token })\n// const { secrets } = await client.pull()\n\nimport { SecretsClient, type SecretsClientOptions, type PullResult } from '@tillstack/secrets-core'\n\nexport * from '@tillstack/secrets-core'\n\n/** Create a client from options or the environment (`TILLSECRETS_TOKEN`,\n * optional `TILLSECRETS_URL`, optional `TILLSECRETS_ENV`). */\nexport function createClient(opts?: Partial<SecretsClientOptions>): SecretsClient {\n const token = opts?.token ?? process.env.TILLSECRETS_TOKEN\n if (!token) throw new Error('TillSecrets: no token — pass one or set TILLSECRETS_TOKEN')\n const built: SecretsClientOptions = { token }\n const url = opts?.url ?? process.env.TILLSECRETS_URL\n if (url) built.url = url\n const env = opts?.environmentId ?? process.env.TILLSECRETS_ENV\n if (env) built.environmentId = env\n if (opts?.timeoutMs !== undefined) built.timeoutMs = opts.timeoutMs\n if (opts?.fetch) built.fetch = opts.fetch\n return new SecretsClient(built)\n}\n\nexport interface LoadOptions extends Partial<SecretsClientOptions> {\n /** Overwrite keys already present in process.env (default false — existing\n * wins, matching dotenv). */\n override?: boolean\n}\n\n/** Pull secrets and inject them into process.env. Returns the pulled map. */\nexport async function load(opts: LoadOptions = {}): Promise<PullResult> {\n const client = createClient(opts)\n const result = await client.pull()\n for (const [k, v] of Object.entries(result.secrets)) {\n if (opts.override || process.env[k] === undefined) process.env[k] = v\n }\n return result\n}\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["SecretsClient","SecretsError","BrokerClient"],"mappings":";;;;;AAuBO,SAAS,aAAa,IAAA,EAAqD;AAChF,EAAA,MAAM,KAAA,GAAQ,IAAA,EAAM,KAAA,IAAS,OAAA,CAAQ,GAAA,CAAI,iBAAA;AACzC,EAAA,IAAI,CAAC,KAAA,EAAO,MAAM,IAAI,MAAM,gEAA2D,CAAA;AACvF,EAAA,MAAM,KAAA,GAA8B,EAAE,KAAA,EAAM;AAC5C,EAAA,MAAM,GAAA,GAAM,IAAA,EAAM,GAAA,IAAO,OAAA,CAAQ,GAAA,CAAI,eAAA;AACrC,EAAA,IAAI,GAAA,QAAW,GAAA,GAAM,GAAA;AACrB,EAAA,MAAM,GAAA,GAAM,IAAA,EAAM,aAAA,IAAiB,OAAA,CAAQ,GAAA,CAAI,eAAA;AAC/C,EAAA,IAAI,GAAA,QAAW,aAAA,GAAgB,GAAA;AAC/B,EAAA,IAAI,IAAA,EAAM,SAAA,KAAc,MAAA,EAAW,KAAA,CAAM,YAAY,IAAA,CAAK,SAAA;AAC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} from '@tillstack/secrets-node'\n// await load() // reads TILLSECRETS_TOKEN, injects into process.env\n// // ... process.env.STRIPE_KEY is now populated\n//\n// or explicitly:\n// const client = createClient({ token })\n// const { secrets } = await client.pull()\n\nimport {\n SecretsClient,\n SecretsError,\n BrokerClient,\n type SecretsClientOptions,\n type PullResult,\n type BrokerClientOptions,\n} from '@tillstack/secrets-core'\n\nexport * from '@tillstack/secrets-core'\n\n/** Create a client from options or the environment (`TILLSECRETS_TOKEN`,\n * optional `TILLSECRETS_URL`, optional `TILLSECRETS_ENV`). */\nexport function createClient(opts?: Partial<SecretsClientOptions>): SecretsClient {\n const token = opts?.token ?? process.env.TILLSECRETS_TOKEN\n if (!token) throw new Error('TillSecrets: no token — pass one or set TILLSECRETS_TOKEN')\n const built: SecretsClientOptions = { token }\n const url = opts?.url ?? process.env.TILLSECRETS_URL\n if (url) built.url = url\n const env = opts?.environmentId ?? process.env.TILLSECRETS_ENV\n if (env) built.environmentId = env\n if (opts?.timeoutMs !== undefined) built.timeoutMs = opts.timeoutMs\n if (opts?.fetch) built.fetch = opts.fetch\n return new SecretsClient(built)\n}\n\nexport interface LoadOptions extends Partial<SecretsClientOptions> {\n /** Overwrite keys already present in process.env (default false — existing\n * wins, matching dotenv). */\n override?: boolean\n}\n\n/** Pull secrets and inject them into process.env. Returns the pulled map. */\nexport async function load(opts: LoadOptions = {}): Promise<PullResult> {\n const client = createClient(opts)\n const result = await client.pull()\n for (const [k, v] of Object.entries(result.secrets)) {\n if (opts.override || process.env[k] === undefined) process.env[k] = v\n }\n return result\n}\n\nexport interface CreateBrokerOptions {\n /** Force a transport. Default `auto`: use the LOCAL bridge when the process runs\n * under the TillForge bridge daemon (`TILLDEV_BROKER_URL` set) — the strongest\n * posture, the value never leaves the machine — otherwise the cloud broker. */\n mode?: 'auto' | 'bridge' | 'cloud'\n /** Cloud API base (derives the spend endpoint). Ignored in bridge mode.\n * Defaults to `TILLDEV_URL` / `TILLSECRETS_URL` / `https://tilldev.dev`. */\n url?: string\n /** Bearer token — a session / `tp_` API key (cloud, `TILLDEV_TOKEN`) or the\n * bridge run token (`TILLDEV_BROKER_TOKEN`, injected by the daemon). */\n token?: string\n /** Stable agent identity. Required in cloud mode (or `TILLDEV_AGENT_KEY`). */\n agentKey?: string\n /** Session id for session-scoped grants (or `TILLDEV_SESSION`). */\n sessionId?: string\n timeoutMs?: number\n fetch?: typeof fetch\n}\n\n/**\n * Create a secretless-broker client. In `auto` mode it prefers the local bridge\n * proxy (value spent on the user's machine) when the daemon has injected\n * `TILLDEV_BROKER_URL` + `TILLDEV_BROKER_TOKEN`, and otherwise talks to the cloud\n * broker with a session / `tp_` token + an agent identity.\n *\n * import { createBroker, secretref } from '@tillstack/secrets-node'\n * const broker = createBroker({ agentKey: 'my-job' })\n * const res = await broker.fetch('https://api.stripe.com/v1/charges', {\n * method: 'POST',\n * headers: { authorization: `Bearer ${secretref('prod', 'live', 'STRIPE_KEY')}` },\n * body,\n * })\n * // res.body is the scrubbed reply — the STRIPE_KEY never entered this process.\n */\nexport function createBroker(opts: CreateBrokerOptions = {}): BrokerClient {\n const bridgeUrl = process.env.TILLDEV_BROKER_URL\n const bridgeToken = process.env.TILLDEV_BROKER_TOKEN\n const useBridge = opts.mode === 'bridge' || (opts.mode !== 'cloud' && !!bridgeUrl && !!bridgeToken)\n\n const built: BrokerClientOptions = { endpoint: '', token: '' }\n if (opts.timeoutMs !== undefined) built.timeoutMs = opts.timeoutMs\n if (opts.fetch) built.fetch = opts.fetch\n const agentKey = opts.agentKey ?? process.env.TILLDEV_AGENT_KEY\n if (agentKey) built.agentKey = agentKey\n const sessionId = opts.sessionId ?? process.env.TILLDEV_SESSION\n if (sessionId) built.sessionId = sessionId\n\n if (useBridge) {\n if (!bridgeUrl || !bridgeToken) {\n throw new SecretsError('TillSecrets broker: bridge mode needs TILLDEV_BROKER_URL + TILLDEV_BROKER_TOKEN')\n }\n built.endpoint = `${bridgeUrl.replace(/\\/$/, '')}/spend`\n built.token = opts.token ?? bridgeToken\n return new BrokerClient(built)\n }\n\n const base = (opts.url ?? process.env.TILLDEV_URL ?? process.env.TILLSECRETS_URL ?? 'https://tilldev.dev').replace(/\\/$/, '')\n const token = opts.token ?? process.env.TILLDEV_TOKEN ?? process.env.TILLSECRETS_BROKER_TOKEN\n if (!token) throw new SecretsError('TillSecrets broker: no token — pass one or set TILLDEV_TOKEN')\n if (!built.agentKey) throw new SecretsError('TillSecrets broker: cloud mode needs an agentKey (or TILLDEV_AGENT_KEY)')\n built.endpoint = `${base}/api/secrets/broker/spend`\n built.token = token\n return new BrokerClient(built)\n}\n"]}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { SecretsClient } from '@tillstack/secrets-core';
1
+ import { SecretsClient, SecretsError, BrokerClient } from '@tillstack/secrets-core';
2
2
  export * from '@tillstack/secrets-core';
3
3
 
4
4
  // src/index.ts
@@ -22,7 +22,34 @@ async function load(opts = {}) {
22
22
  }
23
23
  return result;
24
24
  }
25
+ function createBroker(opts = {}) {
26
+ const bridgeUrl = process.env.TILLDEV_BROKER_URL;
27
+ const bridgeToken = process.env.TILLDEV_BROKER_TOKEN;
28
+ const useBridge = opts.mode === "bridge" || opts.mode !== "cloud" && !!bridgeUrl && !!bridgeToken;
29
+ const built = { endpoint: "", token: "" };
30
+ if (opts.timeoutMs !== void 0) built.timeoutMs = opts.timeoutMs;
31
+ if (opts.fetch) built.fetch = opts.fetch;
32
+ const agentKey = opts.agentKey ?? process.env.TILLDEV_AGENT_KEY;
33
+ if (agentKey) built.agentKey = agentKey;
34
+ const sessionId = opts.sessionId ?? process.env.TILLDEV_SESSION;
35
+ if (sessionId) built.sessionId = sessionId;
36
+ if (useBridge) {
37
+ if (!bridgeUrl || !bridgeToken) {
38
+ throw new SecretsError("TillSecrets broker: bridge mode needs TILLDEV_BROKER_URL + TILLDEV_BROKER_TOKEN");
39
+ }
40
+ built.endpoint = `${bridgeUrl.replace(/\/$/, "")}/spend`;
41
+ built.token = opts.token ?? bridgeToken;
42
+ return new BrokerClient(built);
43
+ }
44
+ const base = (opts.url ?? process.env.TILLDEV_URL ?? process.env.TILLSECRETS_URL ?? "https://tilldev.dev").replace(/\/$/, "");
45
+ const token = opts.token ?? process.env.TILLDEV_TOKEN ?? process.env.TILLSECRETS_BROKER_TOKEN;
46
+ if (!token) throw new SecretsError("TillSecrets broker: no token \u2014 pass one or set TILLDEV_TOKEN");
47
+ if (!built.agentKey) throw new SecretsError("TillSecrets broker: cloud mode needs an agentKey (or TILLDEV_AGENT_KEY)");
48
+ built.endpoint = `${base}/api/secrets/broker/spend`;
49
+ built.token = token;
50
+ return new BrokerClient(built);
51
+ }
25
52
 
26
- export { createClient, load };
53
+ export { createBroker, createClient, load };
27
54
  //# sourceMappingURL=index.mjs.map
28
55
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;AAgBO,SAAS,aAAa,IAAA,EAAqD;AAChF,EAAA,MAAM,KAAA,GAAQ,IAAA,EAAM,KAAA,IAAS,OAAA,CAAQ,GAAA,CAAI,iBAAA;AACzC,EAAA,IAAI,CAAC,KAAA,EAAO,MAAM,IAAI,MAAM,gEAA2D,CAAA;AACvF,EAAA,MAAM,KAAA,GAA8B,EAAE,KAAA,EAAM;AAC5C,EAAA,MAAM,GAAA,GAAM,IAAA,EAAM,GAAA,IAAO,OAAA,CAAQ,GAAA,CAAI,eAAA;AACrC,EAAA,IAAI,GAAA,QAAW,GAAA,GAAM,GAAA;AACrB,EAAA,MAAM,GAAA,GAAM,IAAA,EAAM,aAAA,IAAiB,OAAA,CAAQ,GAAA,CAAI,eAAA;AAC/C,EAAA,IAAI,GAAA,QAAW,aAAA,GAAgB,GAAA;AAC/B,EAAA,IAAI,IAAA,EAAM,SAAA,KAAc,MAAA,EAAW,KAAA,CAAM,YAAY,IAAA,CAAK,SAAA;AAC1D,EAAA,IAAI,IAAA,EAAM,KAAA,EAAO,KAAA,CAAM,KAAA,GAAQ,IAAA,CAAK,KAAA;AACpC,EAAA,OAAO,IAAI,cAAc,KAAK,CAAA;AAChC;AASA,eAAsB,IAAA,CAAK,IAAA,GAAoB,EAAC,EAAwB;AACtE,EAAA,MAAM,MAAA,GAAS,aAAa,IAAI,CAAA;AAChC,EAAA,MAAM,MAAA,GAAS,MAAM,MAAA,CAAO,IAAA,EAAK;AACjC,EAAA,KAAA,MAAW,CAAC,GAAG,CAAC,CAAA,IAAK,OAAO,OAAA,CAAQ,MAAA,CAAO,OAAO,CAAA,EAAG;AACnD,IAAA,IAAI,IAAA,CAAK,QAAA,IAAY,OAAA,CAAQ,GAAA,CAAI,CAAC,MAAM,MAAA,EAAW,OAAA,CAAQ,GAAA,CAAI,CAAC,CAAA,GAAI,CAAA;AAAA,EACtE;AACA,EAAA,OAAO,MAAA;AACT","file":"index.mjs","sourcesContent":["// @tillstack/secrets-node — TillSecrets client for Node.js.\n//\n// import { load } from '@tillstack/secrets-node'\n// await load() // reads TILLSECRETS_TOKEN, injects into process.env\n// // ... process.env.STRIPE_KEY is now populated\n//\n// or explicitly:\n// const client = createClient({ token })\n// const { secrets } = await client.pull()\n\nimport { SecretsClient, type SecretsClientOptions, type PullResult } from '@tillstack/secrets-core'\n\nexport * from '@tillstack/secrets-core'\n\n/** Create a client from options or the environment (`TILLSECRETS_TOKEN`,\n * optional `TILLSECRETS_URL`, optional `TILLSECRETS_ENV`). */\nexport function createClient(opts?: Partial<SecretsClientOptions>): SecretsClient {\n const token = opts?.token ?? process.env.TILLSECRETS_TOKEN\n if (!token) throw new Error('TillSecrets: no token — pass one or set TILLSECRETS_TOKEN')\n const built: SecretsClientOptions = { token }\n const url = opts?.url ?? process.env.TILLSECRETS_URL\n if (url) built.url = url\n const env = opts?.environmentId ?? process.env.TILLSECRETS_ENV\n if (env) built.environmentId = env\n if (opts?.timeoutMs !== undefined) built.timeoutMs = opts.timeoutMs\n if (opts?.fetch) built.fetch = opts.fetch\n return new SecretsClient(built)\n}\n\nexport interface LoadOptions extends Partial<SecretsClientOptions> {\n /** Overwrite keys already present in process.env (default false — existing\n * wins, matching dotenv). */\n override?: boolean\n}\n\n/** Pull secrets and inject them into process.env. Returns the pulled map. */\nexport async function load(opts: LoadOptions = {}): Promise<PullResult> {\n const client = createClient(opts)\n const result = await client.pull()\n for (const [k, v] of Object.entries(result.secrets)) {\n if (opts.override || process.env[k] === undefined) process.env[k] = v\n }\n return result\n}\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;AAuBO,SAAS,aAAa,IAAA,EAAqD;AAChF,EAAA,MAAM,KAAA,GAAQ,IAAA,EAAM,KAAA,IAAS,OAAA,CAAQ,GAAA,CAAI,iBAAA;AACzC,EAAA,IAAI,CAAC,KAAA,EAAO,MAAM,IAAI,MAAM,gEAA2D,CAAA;AACvF,EAAA,MAAM,KAAA,GAA8B,EAAE,KAAA,EAAM;AAC5C,EAAA,MAAM,GAAA,GAAM,IAAA,EAAM,GAAA,IAAO,OAAA,CAAQ,GAAA,CAAI,eAAA;AACrC,EAAA,IAAI,GAAA,QAAW,GAAA,GAAM,GAAA;AACrB,EAAA,MAAM,GAAA,GAAM,IAAA,EAAM,aAAA,IAAiB,OAAA,CAAQ,GAAA,CAAI,eAAA;AAC/C,EAAA,IAAI,GAAA,QAAW,aAAA,GAAgB,GAAA;AAC/B,EAAA,IAAI,IAAA,EAAM,SAAA,KAAc,MAAA,EAAW,KAAA,CAAM,YAAY,IAAA,CAAK,SAAA;AAC1D,EAAA,IAAI,IAAA,EAAM,KAAA,EAAO,KAAA,CAAM,KAAA,GAAQ,IAAA,CAAK,KAAA;AACpC,EAAA,OAAO,IAAI,cAAc,KAAK,CAAA;AAChC;AASA,eAAsB,IAAA,CAAK,IAAA,GAAoB,EAAC,EAAwB;AACtE,EAAA,MAAM,MAAA,GAAS,aAAa,IAAI,CAAA;AAChC,EAAA,MAAM,MAAA,GAAS,MAAM,MAAA,CAAO,IAAA,EAAK;AACjC,EAAA,KAAA,MAA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;AAAA,IAC1G;AACA,IAAA,KAAA,CAAM,WAAW,CAAA,EAAG,SAAA,CAAU,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAC,CAAA,MAAA,CAAA;AAChD,IAAA,KAAA,CAAM,KAAA,GAAQ,KAAK,KAAA,IAAS,WAAA;AAC5B,IAAA,OAAO,IAAI,aAAa,KAAK,CAAA;AAAA,EAC/B;AAEA,EAAA,MAAM,IAAA,GAAA,CAAQ,IAAA,CAAK,GAAA,IAAO,OAAA,CAAQ,GAAA,CAAI,WAAA,IAAe,OAAA,CAAQ,GAAA,CAAI,eAAA,IAAmB,qBAAA,EAAuB,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AAC5H,EAAA,MAAM,QAAQ,IAAA,CAAK,KAAA,IAAS,QAAQ,GAAA,CAAI,aAAA,IAAiB,QAAQ,GAAA,CAAI,wBAAA;AACrE,EAAA,IAAI,CAAC,KAAA,EAAO,MAAM,IAAI,aAAa,mEAA8D,CAAA;AACjG,EAAA,IAAI,CAAC,KAAA,CAAM,QAAA,EAAU,MAAM,IAAI,aAAa,yEAAyE,CAAA;AACrH,EAAA,KAAA,CAAM,QAAA,GAAW,GAAG,IAAI,CAAA,yBAAA,CAAA;AACxB,EAAA,KAAA,CAAM,KAAA,GAAQ,KAAA;AACd,EAAA,OAAO,IAAI,aAAa,KAAK,CAAA;AAC/B","file":"index.mjs","sourcesContent":["// @tillstack/secrets-node — TillSecrets client for Node.js.\n//\n// import { load } from '@tillstack/secrets-node'\n// await load() // reads TILLSECRETS_TOKEN, injects into process.env\n// // ... process.env.STRIPE_KEY is now populated\n//\n// or explicitly:\n// const client = createClient({ token })\n// const { secrets } = await client.pull()\n\nimport {\n SecretsClient,\n SecretsError,\n BrokerClient,\n type SecretsClientOptions,\n type PullResult,\n type BrokerClientOptions,\n} from '@tillstack/secrets-core'\n\nexport * from '@tillstack/secrets-core'\n\n/** Create a client from options or the environment (`TILLSECRETS_TOKEN`,\n * optional `TILLSECRETS_URL`, optional `TILLSECRETS_ENV`). */\nexport function createClient(opts?: Partial<SecretsClientOptions>): SecretsClient {\n const token = opts?.token ?? process.env.TILLSECRETS_TOKEN\n if (!token) throw new Error('TillSecrets: no token — pass one or set TILLSECRETS_TOKEN')\n const built: SecretsClientOptions = { token }\n const url = opts?.url ?? process.env.TILLSECRETS_URL\n if (url) built.url = url\n const env = opts?.environmentId ?? process.env.TILLSECRETS_ENV\n if (env) built.environmentId = env\n if (opts?.timeoutMs !== undefined) built.timeoutMs = opts.timeoutMs\n if (opts?.fetch) built.fetch = opts.fetch\n return new SecretsClient(built)\n}\n\nexport interface LoadOptions extends Partial<SecretsClientOptions> {\n /** Overwrite keys already present in process.env (default false — existing\n * wins, matching dotenv). */\n override?: boolean\n}\n\n/** Pull secrets and inject them into process.env. Returns the pulled map. */\nexport async function load(opts: LoadOptions = {}): Promise<PullResult> {\n const client = createClient(opts)\n const result = await client.pull()\n for (const [k, v] of Object.entries(result.secrets)) {\n if (opts.override || process.env[k] === undefined) process.env[k] = v\n }\n return result\n}\n\nexport interface CreateBrokerOptions {\n /** Force a transport. Default `auto`: use the LOCAL bridge when the process runs\n * under the TillForge bridge daemon (`TILLDEV_BROKER_URL` set) — the strongest\n * posture, the value never leaves the machine — otherwise the cloud broker. */\n mode?: 'auto' | 'bridge' | 'cloud'\n /** Cloud API base (derives the spend endpoint). Ignored in bridge mode.\n * Defaults to `TILLDEV_URL` / `TILLSECRETS_URL` / `https://tilldev.dev`. */\n url?: string\n /** Bearer token — a session / `tp_` API key (cloud, `TILLDEV_TOKEN`) or the\n * bridge run token (`TILLDEV_BROKER_TOKEN`, injected by the daemon). */\n token?: string\n /** Stable agent identity. Required in cloud mode (or `TILLDEV_AGENT_KEY`). */\n agentKey?: string\n /** Session id for session-scoped grants (or `TILLDEV_SESSION`). */\n sessionId?: string\n timeoutMs?: number\n fetch?: typeof fetch\n}\n\n/**\n * Create a secretless-broker client. In `auto` mode it prefers the local bridge\n * proxy (value spent on the user's machine) when the daemon has injected\n * `TILLDEV_BROKER_URL` + `TILLDEV_BROKER_TOKEN`, and otherwise talks to the cloud\n * broker with a session / `tp_` token + an agent identity.\n *\n * import { createBroker, secretref } from '@tillstack/secrets-node'\n * const broker = createBroker({ agentKey: 'my-job' })\n * const res = await broker.fetch('https://api.stripe.com/v1/charges', {\n * method: 'POST',\n * headers: { authorization: `Bearer ${secretref('prod', 'live', 'STRIPE_KEY')}` },\n * body,\n * })\n * // res.body is the scrubbed reply — the STRIPE_KEY never entered this process.\n */\nexport function createBroker(opts: CreateBrokerOptions = {}): BrokerClient {\n const bridgeUrl = process.env.TILLDEV_BROKER_URL\n const bridgeToken = process.env.TILLDEV_BROKER_TOKEN\n const useBridge = opts.mode === 'bridge' || (opts.mode !== 'cloud' && !!bridgeUrl && !!bridgeToken)\n\n const built: BrokerClientOptions = { endpoint: '', token: '' }\n if (opts.timeoutMs !== undefined) built.timeoutMs = opts.timeoutMs\n if (opts.fetch) built.fetch = opts.fetch\n const agentKey = opts.agentKey ?? process.env.TILLDEV_AGENT_KEY\n if (agentKey) built.agentKey = agentKey\n const sessionId = opts.sessionId ?? process.env.TILLDEV_SESSION\n if (sessionId) built.sessionId = sessionId\n\n if (useBridge) {\n if (!bridgeUrl || !bridgeToken) {\n throw new SecretsError('TillSecrets broker: bridge mode needs TILLDEV_BROKER_URL + TILLDEV_BROKER_TOKEN')\n }\n built.endpoint = `${bridgeUrl.replace(/\\/$/, '')}/spend`\n built.token = opts.token ?? bridgeToken\n return new BrokerClient(built)\n }\n\n const base = (opts.url ?? process.env.TILLDEV_URL ?? process.env.TILLSECRETS_URL ?? 'https://tilldev.dev').replace(/\\/$/, '')\n const token = opts.token ?? process.env.TILLDEV_TOKEN ?? process.env.TILLSECRETS_BROKER_TOKEN\n if (!token) throw new SecretsError('TillSecrets broker: no token — pass one or set TILLDEV_TOKEN')\n if (!built.agentKey) throw new SecretsError('TillSecrets broker: cloud mode needs an agentKey (or TILLDEV_AGENT_KEY)')\n built.endpoint = `${base}/api/secrets/broker/spend`\n built.token = token\n return new BrokerClient(built)\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tillstack/secrets-node",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "TillSecrets client for Node.js — pull encrypted config at boot and inject it into process.env, with a drop-in dotenv-style API.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -24,14 +24,14 @@
24
24
  "dist"
25
25
  ],
26
26
  "dependencies": {
27
- "@tillstack/secrets-core": "^0.1.0"
27
+ "@tillstack/secrets-core": "^0.3.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/node": "^22.0.0",
31
31
  "tsup": "^8.5.1",
32
32
  "typescript": "^5.7.3"
33
33
  },
34
- "license": "UNLICENSED",
34
+ "license": "Apache-2.0",
35
35
  "repository": {
36
36
  "type": "git",
37
37
  "url": "git+https://github.com/tillafrica/tilldev.git",