@open-conduit/sdk 0.0.0-stage → 7.1.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 +21 -0
- package/README.md +12 -2
- package/dist/actions.d.ts +145 -0
- package/dist/actions.js +281 -0
- package/dist/actiontest.d.ts +80 -0
- package/dist/actiontest.js +190 -0
- package/dist/artifactstore.d.ts +133 -0
- package/dist/artifactstore.js +364 -0
- package/dist/backup.d.ts +99 -0
- package/dist/backup.js +178 -0
- package/dist/containertest.d.ts +71 -0
- package/dist/containertest.js +294 -0
- package/dist/errors.d.ts +127 -0
- package/dist/errors.js +180 -0
- package/dist/executor.d.ts +374 -0
- package/dist/executor.js +556 -0
- package/dist/executortest.d.ts +183 -0
- package/dist/executortest.js +534 -0
- package/dist/extension.d.ts +855 -0
- package/dist/extension.js +1822 -0
- package/dist/feed.d.ts +20 -0
- package/dist/feed.js +88 -0
- package/dist/forward.d.ts +38 -0
- package/dist/forward.js +163 -0
- package/dist/forwardca.d.ts +21 -0
- package/dist/forwardca.js +144 -0
- package/dist/hooks.d.ts +108 -0
- package/dist/hooks.js +13 -0
- package/dist/host.d.ts +295 -0
- package/dist/host.js +486 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +31 -0
- package/dist/jsonrpc.d.ts +39 -0
- package/dist/jsonrpc.js +350 -0
- package/dist/probe.d.ts +61 -0
- package/dist/probe.js +92 -0
- package/dist/providertest.d.ts +59 -0
- package/dist/providertest.js +168 -0
- package/dist/resources.d.ts +208 -0
- package/dist/resources.js +303 -0
- package/dist/sandbox.d.ts +84 -0
- package/dist/sandbox.js +85 -0
- package/dist/schema.d.ts +71 -0
- package/dist/schema.js +252 -0
- package/dist/setup.d.ts +145 -0
- package/dist/setup.js +179 -0
- package/dist/setuptest.d.ts +90 -0
- package/dist/setuptest.js +319 -0
- package/dist/storetest.d.ts +64 -0
- package/dist/storetest.js +740 -0
- package/dist/telemetry.d.ts +86 -0
- package/dist/telemetry.js +46 -0
- package/dist/testing.d.ts +756 -0
- package/dist/testing.js +2165 -0
- package/dist/toolbelt.d.ts +91 -0
- package/dist/toolbelt.js +216 -0
- package/dist/tunnel.d.ts +62 -0
- package/dist/tunnel.js +93 -0
- package/dist/wire.d.ts +5359 -0
- package/dist/wire.js +2211 -0
- package/package.json +29 -4
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Context } from "./extension.js";
|
|
2
|
+
import type { Metric, ResourceOwner, TelemetryEvent, TelemetryRecord } from "./wire.js";
|
|
3
|
+
/**
|
|
4
|
+
* A telemetry exporter (observability.Exporter, manifest exporters): it
|
|
5
|
+
* receives the host's lifecycle records in batches. The host runs it on its
|
|
6
|
+
* telemetry pipeline and bounds each call; a batch it throws on, or that
|
|
7
|
+
* takes too long, is dropped and counted, never retried, so export must
|
|
8
|
+
* not block on a slow backend for long.
|
|
9
|
+
*/
|
|
10
|
+
export interface ExporterSpec {
|
|
11
|
+
export: (records: TelemetryRecord[], ctx: Context) => void | Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Flushes what export buffered when the host shuts the extension down.
|
|
14
|
+
* What it throws is ignored, as the Go SDK ignores it.
|
|
15
|
+
*/
|
|
16
|
+
shutdown?: (ctx: Context) => void | Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Receives each collection of the host's meter (observability.
|
|
20
|
+
* MetricExporter, permission telemetry.metrics). The host collects on an
|
|
21
|
+
* interval only while an exporter runs and bounds each call; a failed or
|
|
22
|
+
* slow one loses that collection, never the next, since sums and
|
|
23
|
+
* histograms are cumulative.
|
|
24
|
+
*/
|
|
25
|
+
export type MetricsFn = (metrics: Metric[], ctx: Context) => void | Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Receives every named telemetry event the host records, from every scope
|
|
28
|
+
* and from every extension that captures one (permission telemetry.sink).
|
|
29
|
+
* The host bounds each call to five seconds.
|
|
30
|
+
*/
|
|
31
|
+
export type SinkFn = (event: TelemetryEvent, ctx: Context) => void | Promise<void>;
|
|
32
|
+
/** One run the host asks for an environment layer for (extension.RunEnvironmentRequest). */
|
|
33
|
+
export interface RunEnvironmentRequest {
|
|
34
|
+
/** The run's scope, Work and Execution, as the host bound them. */
|
|
35
|
+
owner: ResourceOwner;
|
|
36
|
+
/** The connection the run's binding names, or "". */
|
|
37
|
+
connection: string;
|
|
38
|
+
/** The run's executor binding, as the host stored it. */
|
|
39
|
+
binding: string;
|
|
40
|
+
/**
|
|
41
|
+
* The directory the host writes the layer's files to, which the run
|
|
42
|
+
* reads at the same path on the host, in a process sandbox and in a
|
|
43
|
+
* container, so an environment variable can name a file in it. "" when
|
|
44
|
+
* the run has none (a binding with no toolbelt): files are then dropped.
|
|
45
|
+
*/
|
|
46
|
+
filesDir: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* An extension's contribution to a run (extension.RunLayer): environment
|
|
50
|
+
* variables, and files the host writes into the request's filesDir, each
|
|
51
|
+
* under its name, before the run starts. A file is the run's to read,
|
|
52
|
+
* never to change: the host writes it owner-only and removes it with the
|
|
53
|
+
* run's directory.
|
|
54
|
+
*
|
|
55
|
+
* The host skips a variable that isn't a variable name, one named OS_*
|
|
56
|
+
* (the toolbelt's own) and a value with a NUL. It fails the run when the
|
|
57
|
+
* files break checkRunFiles, or when the layer can't be had at all.
|
|
58
|
+
*/
|
|
59
|
+
export interface RunLayer {
|
|
60
|
+
env?: Record<string, string>;
|
|
61
|
+
files?: Record<string, string>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Contributes an environment layer to a run of a Work in a scope that uses
|
|
65
|
+
* the extension (manifest run_environment). Throwing fails the run, so a
|
|
66
|
+
* layer that can't be had stops it rather than running without it. The
|
|
67
|
+
* host bounds the call to a minute.
|
|
68
|
+
*/
|
|
69
|
+
export type RunEnvironmentFn = (r: RunEnvironmentRequest, ctx: Context) => RunLayer | Promise<RunLayer>;
|
|
70
|
+
/** The most files a run layer may carry (extension.MaxRunFiles). */
|
|
71
|
+
export declare const MaxRunFiles = 16;
|
|
72
|
+
/** The most bytes one run file may hold (extension.MaxRunFileBytes). */
|
|
73
|
+
export declare const MaxRunFileBytes: number;
|
|
74
|
+
/**
|
|
75
|
+
* Why the host would refuse to write files into a run, or undefined when
|
|
76
|
+
* it writes them (extension.CheckRunFiles): at most MaxRunFiles, each a
|
|
77
|
+
* plain file name (letters, digits, '.', '_' and '-', never a path) of at
|
|
78
|
+
* most MaxRunFileBytes with no NUL.
|
|
79
|
+
*/
|
|
80
|
+
export declare function checkRunFiles(files: Record<string, string> | undefined): string | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* The variables of env the host applies to a run (extension.ApplyEnv over
|
|
83
|
+
* an empty environment): it skips a name that isn't a variable name, an
|
|
84
|
+
* OS_* name and a value with a NUL.
|
|
85
|
+
*/
|
|
86
|
+
export declare function appliedEnv(env: Record<string, string> | undefined): Record<string, string>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Telemetry exporters, metric exporters and sinks (telemetry.export,
|
|
2
|
+
// telemetry.metrics, telemetry.sink) and run environments
|
|
3
|
+
// (run.environment), as protocol/sdk serves sdk.Extension's Exporter,
|
|
4
|
+
// Metrics, Sink and RunLayer (protocol/sdk/sdk.go and surfaces.go). The
|
|
5
|
+
// host owns the telemetry pipeline and each run's environment: it decides
|
|
6
|
+
// what to send an exporter or sink and when, and checks a run layer before
|
|
7
|
+
// it applies it.
|
|
8
|
+
/** The most files a run layer may carry (extension.MaxRunFiles). */
|
|
9
|
+
export const MaxRunFiles = 16;
|
|
10
|
+
/** The most bytes one run file may hold (extension.MaxRunFileBytes). */
|
|
11
|
+
export const MaxRunFileBytes = 64 << 10;
|
|
12
|
+
const runFileName = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
13
|
+
/**
|
|
14
|
+
* Why the host would refuse to write files into a run, or undefined when
|
|
15
|
+
* it writes them (extension.CheckRunFiles): at most MaxRunFiles, each a
|
|
16
|
+
* plain file name (letters, digits, '.', '_' and '-', never a path) of at
|
|
17
|
+
* most MaxRunFileBytes with no NUL.
|
|
18
|
+
*/
|
|
19
|
+
export function checkRunFiles(files) {
|
|
20
|
+
const entries = Object.entries(files ?? {});
|
|
21
|
+
if (entries.length > MaxRunFiles)
|
|
22
|
+
return `a run layer may carry at most ${MaxRunFiles} files`;
|
|
23
|
+
for (const [name, content] of entries) {
|
|
24
|
+
if (!runFileName.test(name) || name === "." || name === "..")
|
|
25
|
+
return `run file ${JSON.stringify(name)} is not a plain file name`;
|
|
26
|
+
if (Buffer.byteLength(content, "utf8") > MaxRunFileBytes ||
|
|
27
|
+
content.includes("\0"))
|
|
28
|
+
return `run file ${JSON.stringify(name)} is over ${MaxRunFileBytes} bytes or has a NUL`;
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const envName = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
33
|
+
/**
|
|
34
|
+
* The variables of env the host applies to a run (extension.ApplyEnv over
|
|
35
|
+
* an empty environment): it skips a name that isn't a variable name, an
|
|
36
|
+
* OS_* name and a value with a NUL.
|
|
37
|
+
*/
|
|
38
|
+
export function appliedEnv(env) {
|
|
39
|
+
const out = {};
|
|
40
|
+
for (const [name, value] of Object.entries(env ?? {}))
|
|
41
|
+
if (envName.test(name) &&
|
|
42
|
+
!name.toUpperCase().startsWith("OS_") &&
|
|
43
|
+
!value.includes("\0"))
|
|
44
|
+
out[name] = value;
|
|
45
|
+
return out;
|
|
46
|
+
}
|