@tealbrick/provider-transport 0.1.3 → 0.2.5
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/dist/avmm.d.ts +6 -0
- package/dist/avmm.js +18 -0
- package/package.json +5 -1
package/dist/avmm.d.ts
ADDED
package/dist/avmm.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
/** Runtime-only AVMM broker transport. Reread rotating VM leases per request. */
|
|
3
|
+
export function createAvmmBrokerFetch(options) {
|
|
4
|
+
const base = new URL(options.baseURL);
|
|
5
|
+
return async (input, init) => {
|
|
6
|
+
const url = new URL(typeof input === 'string' ? input : input instanceof URL ? input : input.url);
|
|
7
|
+
if (url.origin !== base.origin || !url.pathname.startsWith(base.pathname.replace(/\/$/, '') + '/'))
|
|
8
|
+
throw Error('avmm_broker_target_mismatch');
|
|
9
|
+
const content = await readFile(options.leaseFile, 'utf8');
|
|
10
|
+
const entry = content.split('\n').find(line => line.startsWith('AGENTVM_CODEX_LEASE_TOKEN='));
|
|
11
|
+
const token = entry?.slice('AGENTVM_CODEX_LEASE_TOKEN='.length).trim().replace(/^['"]|['"]$/g, '');
|
|
12
|
+
if (!token || !/^[-A-Za-z0-9._]+$/.test(token))
|
|
13
|
+
throw Error('avmm_broker_lease_unavailable');
|
|
14
|
+
const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));
|
|
15
|
+
headers.set('authorization', `Bearer ${token}`);
|
|
16
|
+
return (options.fetch ?? fetch)(input, { ...init, headers });
|
|
17
|
+
};
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tealbrick/provider-transport",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Shared bounded provider transport and endpoint credential policy for Teal Brick adapters",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
".": {
|
|
18
18
|
"types": "./dist/index.d.ts",
|
|
19
19
|
"import": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./avmm": {
|
|
22
|
+
"types": "./dist/avmm.d.ts",
|
|
23
|
+
"import": "./dist/avmm.js"
|
|
20
24
|
}
|
|
21
25
|
},
|
|
22
26
|
"scripts": {
|