@funcd-dev/shim 0.17.0 → 0.19.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/blob.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // context.blob — function-facing blob over the worker-node local API (HTTP-over-UDS, ADR-0127). Dials the
2
2
  // same per-sandbox socket as context.kv/context.invoke (FUNCD_INVOKE_SOCKET); the platform routes /blob/…
3
3
  // to the binding-gated, PDP-authorized Facade with the sandbox's function identity (bind-as-grant on
4
- // spec.blob). Reached only through the built-in shim — no @aws-sdk, no keypair. The blob twin of context.kv;
4
+ // spec.bindings.blob). Reached only through the built-in shim — no @aws-sdk, no keypair. The blob twin of context.kv;
5
5
  // v1 is bytes-in-memory (streaming is a v2 follow-up).
6
6
  import { send as sendOn } from "./socket.js";
7
7
  const send = (method, path, body, member) => sendOn('context.blob', method, path, body, member);
package/dist/config.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- export declare function listedKeys(env: NodeJS.ProcessEnv, list: string): string[];
2
- export declare function listedValue(env: NodeJS.ProcessEnv, list: string, key: string): string | undefined;
3
1
  /** A function's bound config (funcd ADR-0245): a key a secret overrides, or any unbound variable, reads as undefined. */
4
2
  export interface ConfigClient {
5
3
  get(key: string): string | undefined;
package/dist/config.js CHANGED
@@ -1,11 +1,11 @@
1
1
  // context.config — the keys of a function's bound ConfigMaps (funcd ADR-0245), read from the environment at call time.
2
- // funcd sets FUNCD_CONFIG_KEYS and FUNCD_SECRET_KEYS, comma-separated lists of the bound keys of each kind in the
3
- // environment; an absent or empty list is no keys. context.secret reads its list with the same helpers.
4
- export function listedKeys(env, list) {
2
+ // funcd sets FUNCD_CONFIG_KEYS, the comma-separated bound config keys in the environment; an absent or empty list is no
3
+ // keys. Secrets are read from funcd instead (context.secret, funcd ADR-0249).
4
+ function listedKeys(env, list) {
5
5
  const v = env[list];
6
6
  return v ? v.split(',') : [];
7
7
  }
8
- export function listedValue(env, list, key) {
8
+ function listedValue(env, list, key) {
9
9
  return listedKeys(env, list).includes(key) ? env[key] : undefined;
10
10
  }
11
11
  export function makeConfig(env = process.env) {
package/dist/secret.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- /** A function's bound secrets (funcd ADR-0245): an unbound key reads as undefined. */
1
+ /** A function's bound secrets (funcd ADR-0249): an unbound key reads as undefined. */
2
2
  export interface SecretClient {
3
3
  get(key: string): Promise<string | undefined>;
4
4
  list(): Promise<string[]>;
5
5
  }
6
- export declare function makeSecret(env?: NodeJS.ProcessEnv): SecretClient;
6
+ /** Build the context.secret client. In a pool, `member` names the calling function on every request (funcd checks it
7
+ * against the pool's members); the solo shim passes none. */
8
+ export declare function makeSecret(member?: string): SecretClient;
package/dist/secret.js CHANGED
@@ -1,9 +1,35 @@
1
- // context.secret — the keys of a function's bound Secrets (funcd ADR-0245), read from the environment at call time.
2
- // The methods return Promises, as every client that calls funcd does, so a later read from funcd keeps this API.
3
- import { listedKeys, listedValue } from "./config.js";
4
- export function makeSecret(env = process.env) {
1
+ // context.secret — the keys and values of a function's bound Secrets, read from funcd over the worker-node local API
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.
4
+ import { send } from "./socket.js";
5
+ const fail = (verb, r) => new Error(`context.secret.${verb} failed: ${r.status} ${r.body.toString('utf8')}`);
6
+ const json = (verb, r) => {
7
+ try {
8
+ return JSON.parse(r.body.toString('utf8'));
9
+ }
10
+ catch (err) {
11
+ throw new Error(`context.secret.${verb} failed: ${r.status} reply is not JSON: ${err.message}`, {
12
+ cause: err,
13
+ });
14
+ }
15
+ };
16
+ /** Build the context.secret client. In a pool, `member` names the calling function on every request (funcd checks it
17
+ * against the pool's members); the solo shim passes none. */
18
+ export function makeSecret(member) {
5
19
  return {
6
- get: async (key) => listedValue(env, 'FUNCD_SECRET_KEYS', key),
7
- list: async () => listedKeys(env, 'FUNCD_SECRET_KEYS'),
20
+ async get(key) {
21
+ const r = await send('context.secret', 'GET', `/secret/${encodeURIComponent(key)}`, undefined, member);
22
+ if (r.status === 404)
23
+ return undefined;
24
+ if (r.status !== 200)
25
+ throw fail('get', r);
26
+ return json('get', r).value;
27
+ },
28
+ async list() {
29
+ const r = await send('context.secret', 'GET', '/secret', undefined, member);
30
+ if (r.status !== 200)
31
+ throw fail('list', r);
32
+ return json('list', r).keys;
33
+ },
8
34
  };
9
35
  }
package/dist/sql.d.ts CHANGED
@@ -18,7 +18,7 @@ export interface SQLExecResult {
18
18
  columns?: string[];
19
19
  values?: unknown[][];
20
20
  }
21
- /** A function's view of the SQL databases it binds (spec.sql), by alias. */
21
+ /** A function's view of the SQL databases it binds (spec.bindings.sql), by alias. */
22
22
  export interface SQLClient {
23
23
  query(alias: string, sql: string, params?: SQLParams): Promise<SQLRow[]>;
24
24
  queryValues(alias: string, sql: string, params?: SQLParams): Promise<SQLValues>;
package/dist/types.d.ts CHANGED
@@ -27,7 +27,7 @@ export interface CloudEvent<T = unknown> {
27
27
  export interface FunctionContext {
28
28
  /** Structured log line → stdout (collected by the platform, ADR-0010). */
29
29
  log(...args: unknown[]): void;
30
- /** Synchronously invoke a linked function by its spec.links alias (ADR-0064). The input is
30
+ /** Synchronously invoke a linked function by its spec.bindings.links alias (ADR-0064). The input is
31
31
  * validated against the target's contract by the target's shim; its result is returned. Fails
32
32
  * closed (rejects) if the caller declares no such link.
33
33
  *
@@ -36,7 +36,7 @@ export interface FunctionContext {
36
36
  * `data`, and the other keys are dropped. To send an object that has its own `data` key, wrap it in an
37
37
  * envelope: `{ specversion: '1.0', data: { data: [1], page: 2 } }`. */
38
38
  invoke<I = unknown, O = unknown>(alias: string, input: I): Promise<O>;
39
- /** Send an HTTP request to a linked Function that serves HTTP (spec.protocol: http) by its spec.links alias
39
+ /** Send an HTTP request to a linked Function that serves HTTP (spec.protocol: http) by its spec.bindings.links alias
40
40
  * (funcd ADR-0243). `path` starts with "/" and may carry a query. The reply comes back whole, at most 1 MiB, with
41
41
  * its status and headers; funcd answers an error status, and calls nothing, for an undeclared link or a target
42
42
  * that does not serve HTTP (call it with invoke). */
@@ -51,9 +51,9 @@ export interface FunctionContext {
51
51
  sql: SQLClient;
52
52
  /** The keys of the ConfigMaps a function binds (funcd ADR-0245); a key a bound Secret overrides is a secret. */
53
53
  config: ConfigClient;
54
- /** The keys of the Secrets a function binds (funcd ADR-0245). */
54
+ /** The keys and values of the Secrets a function binds, read from funcd on every call (funcd ADR-0249). */
55
55
  secret: SecretClient;
56
- /** A bound catalog's proxy URL and this function's token, by spec.catalogs alias (funcd ADR-0245). */
56
+ /** A bound catalog's proxy URL and this function's token, by spec.bindings.catalog alias (funcd ADR-0245). */
57
57
  catalog: CatalogClient;
58
58
  /** Milliseconds left before the call's deadline (X-Funcd-Timeout-Ms), floored at 0; null without one (ADR-0226). */
59
59
  remainingMs(): number | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funcd-dev/shim",
3
- "version": "0.17.0",
3
+ "version": "0.19.0",
4
4
  "type": "module",
5
5
  "description": "Types and the contract build for writing funcd functions in TypeScript",
6
6
  "license": "Apache-2.0",