@funcd-dev/shim 0.27.0 → 0.28.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/dist/secret.d.ts +5 -0
- package/dist/secret.js +15 -1
- package/package.json +1 -1
package/dist/secret.d.ts
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
export interface SecretClient {
|
|
3
3
|
get(key: string): Promise<string | undefined>;
|
|
4
4
|
list(): Promise<string[]>;
|
|
5
|
+
/** Writes key in Secret `binding`, which the function binds and may write: its owner, or a principal a writer role
|
|
6
|
+
* names. Every function that binds it reads the value at its next read. */
|
|
7
|
+
put(binding: string, key: string, value: string): Promise<void>;
|
|
8
|
+
/** Removes key from Secret `binding`, as put may write it; a key the Secret lacks is no error. */
|
|
9
|
+
del(binding: string, key: string): Promise<void>;
|
|
5
10
|
}
|
|
6
11
|
/** Build the context.secret client. In a pool, `member` names the calling function on every request (funcd checks it
|
|
7
12
|
* against the pool's members); the solo shim passes none. */
|
package/dist/secret.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// context.secret — the keys and values of a function's bound Secrets, read from funcd over the worker-node local API
|
|
2
2
|
// on every call (funcd ADR-0249): GET /secret and GET /secret/{key}, checked by funcd, with no cache. No secret sits in
|
|
3
|
-
// the worker's environment.
|
|
3
|
+
// the worker's environment. A function writes one key of a bound Secret it may write, its owner or a writer-role grant,
|
|
4
|
+
// with PUT and DELETE /secret/{binding}/{key} (funcd ADR-0327, ADR-0328).
|
|
4
5
|
import { send } from "./socket.js";
|
|
5
6
|
const fail = (verb, r) => new Error(`context.secret.${verb} failed: ${r.status} ${r.body.toString('utf8')}`);
|
|
6
7
|
const json = (verb, r) => {
|
|
@@ -13,6 +14,8 @@ const json = (verb, r) => {
|
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
16
|
};
|
|
17
|
+
const keyPath = (binding, key) => `/secret/${encodeURIComponent(binding)}/${encodeURIComponent(key)}`;
|
|
18
|
+
const written = (r) => r.status >= 200 && r.status < 300;
|
|
16
19
|
/** Build the context.secret client. In a pool, `member` names the calling function on every request (funcd checks it
|
|
17
20
|
* against the pool's members); the solo shim passes none. */
|
|
18
21
|
export function makeSecret(member) {
|
|
@@ -31,5 +34,16 @@ export function makeSecret(member) {
|
|
|
31
34
|
throw fail('list', r);
|
|
32
35
|
return json('list', r).keys;
|
|
33
36
|
},
|
|
37
|
+
async put(binding, key, value) {
|
|
38
|
+
const body = Buffer.from(JSON.stringify({ value }), 'utf8');
|
|
39
|
+
const r = await send('context.secret', 'PUT', keyPath(binding, key), body, member, 'application/json');
|
|
40
|
+
if (!written(r))
|
|
41
|
+
throw fail('put', r);
|
|
42
|
+
},
|
|
43
|
+
async del(binding, key) {
|
|
44
|
+
const r = await send('context.secret', 'DELETE', keyPath(binding, key), undefined, member);
|
|
45
|
+
if (!written(r))
|
|
46
|
+
throw fail('del', r);
|
|
47
|
+
},
|
|
34
48
|
};
|
|
35
49
|
}
|