@sequenceholdings/managed-functions 0.4.0 → 0.4.2
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/README.md +444 -2
- package/dist/abrigo-contract.d.ts +92 -0
- package/dist/abrigo-contract.js +55 -0
- package/dist/abrigo-response.d.ts +6 -0
- package/dist/abrigo-response.js +27 -0
- package/dist/abrigo.d.ts +14 -0
- package/dist/abrigo.js +150 -0
- package/dist/agent-evidence.d.ts +9 -0
- package/dist/agent-evidence.js +84 -0
- package/dist/agent-source-evidence-contract.d.ts +1197 -0
- package/dist/agent-source-evidence-contract.js +96 -0
- package/dist/agents-contract.d.ts +99 -0
- package/dist/agents-contract.js +69 -0
- package/dist/agents.d.ts +15 -0
- package/dist/agents.js +121 -0
- package/dist/capabilities.d.ts +165 -0
- package/dist/capabilities.js +61 -1
- package/dist/config.d.ts +18 -2
- package/dist/config.js +62 -1
- package/dist/deployed-policy.js +102 -0
- package/dist/directory-config.d.ts +23 -0
- package/dist/directory-config.js +22 -0
- package/dist/directory-contract.d.ts +68 -0
- package/dist/directory-contract.js +57 -0
- package/dist/directory-manifest.d.ts +5 -0
- package/dist/directory-manifest.js +10 -0
- package/dist/directory.d.ts +15 -0
- package/dist/directory.js +65 -0
- package/dist/http-tracing.js +3 -0
- package/dist/immutable-release-contract.d.ts +3 -0
- package/dist/immutable-release-contract.js +12 -0
- package/dist/index.d.ts +40 -1
- package/dist/index.js +75 -1
- package/dist/invocation-client.d.ts +45 -0
- package/dist/invocation-client.js +90 -0
- package/dist/invocation-contract.d.ts +36 -0
- package/dist/invocation-contract.js +48 -0
- package/dist/invocation.d.ts +8 -0
- package/dist/invocation.js +134 -0
- package/dist/lattice-capability.d.ts +5 -0
- package/dist/lattice-capability.js +16 -0
- package/dist/lattice-provenance-contract.d.ts +519 -0
- package/dist/lattice-provenance-contract.js +148 -0
- package/dist/lattice-provenance.d.ts +16 -0
- package/dist/lattice-provenance.js +167 -0
- package/dist/monitoring-annotations.d.ts +53 -0
- package/dist/monitoring-annotations.js +54 -0
- package/dist/monitoring-contract.d.ts +463 -0
- package/dist/monitoring-contract.js +89 -0
- package/dist/monitoring-events.d.ts +257 -0
- package/dist/monitoring-events.js +136 -0
- package/dist/monitoring.d.ts +14 -0
- package/dist/monitoring.js +78 -0
- package/dist/orm-contract.d.ts +1 -0
- package/dist/orm-contract.js +4 -0
- package/dist/orm.d.ts +19 -3
- package/dist/orm.js +93 -13
- package/dist/preflight-abrigo.d.ts +10 -0
- package/dist/preflight-abrigo.js +26 -0
- package/dist/preflight-agents.d.ts +10 -0
- package/dist/preflight-agents.js +51 -0
- package/dist/preflight-directory.d.ts +10 -0
- package/dist/preflight-directory.js +36 -0
- package/dist/preflight-immutable-release.d.ts +10 -0
- package/dist/preflight-immutable-release.js +34 -0
- package/dist/preflight-invocation.d.ts +10 -0
- package/dist/preflight-invocation.js +40 -0
- package/dist/preflight-lattice.d.ts +10 -0
- package/dist/preflight-lattice.js +40 -0
- package/dist/preflight-monitoring.d.ts +10 -0
- package/dist/preflight-monitoring.js +46 -0
- package/dist/preflight-service-directory.d.ts +10 -0
- package/dist/preflight-service-directory.js +26 -0
- package/dist/preflight-workflows.d.ts +10 -0
- package/dist/preflight-workflows.js +38 -0
- package/dist/preflight.js +50 -2
- package/dist/processes-contract.d.ts +20 -0
- package/dist/processes-contract.js +8 -1
- package/dist/processes.d.ts +4 -8
- package/dist/processes.js +52 -83
- package/dist/runtime.cjs +3387 -259
- package/dist/sdk-range.d.ts +1 -0
- package/dist/sdk-range.js +25 -0
- package/dist/service-directory.d.ts +12 -0
- package/dist/service-directory.js +72 -0
- package/dist/workflow-scopes-contract.d.ts +8 -0
- package/dist/workflow-scopes-contract.js +29 -0
- package/dist/workflow-source-contract.d.ts +524 -0
- package/dist/workflow-source-contract.js +59 -0
- package/dist/workflow-source.d.ts +12 -0
- package/dist/workflow-source.js +93 -0
- package/package.json +2 -2
package/dist/sdk-range.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare function concreteOrStaleSdkSpec(spec: string | undefined, minimum: string): string | null;
|
|
2
2
|
export declare function sdkConstraintIsOlder(declared: string, minimum: string): boolean;
|
|
3
|
+
export declare function sdkSpecAllowsOnlyAtOrAbove(declared: string, minimum: string): boolean;
|
package/dist/sdk-range.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.concreteOrStaleSdkSpec = concreteOrStaleSdkSpec;
|
|
4
4
|
exports.sdkConstraintIsOlder = sdkConstraintIsOlder;
|
|
5
|
+
exports.sdkSpecAllowsOnlyAtOrAbove = sdkSpecAllowsOnlyAtOrAbove;
|
|
5
6
|
function parseSemver(raw) {
|
|
6
7
|
const match = /^v?(\d+)\.(\d+)\.(\d+)$/.exec(raw.trim());
|
|
7
8
|
if (!match)
|
|
@@ -144,3 +145,27 @@ function sdkConstraintIsOlder(declared, minimum) {
|
|
|
144
145
|
}
|
|
145
146
|
return concreteOrStaleSdkSpec(declared, minimum) === declared;
|
|
146
147
|
}
|
|
148
|
+
function sdkSpecAllowsOnlyAtOrAbove(declared, minimum) {
|
|
149
|
+
const target = parseSemver(minimum);
|
|
150
|
+
if (!target || !target.every(Number.isSafeInteger))
|
|
151
|
+
return false;
|
|
152
|
+
const alternatives = declared.trim().split('||');
|
|
153
|
+
if (alternatives.some((alternative) => alternative.trim() === ''))
|
|
154
|
+
return false;
|
|
155
|
+
return alternatives.every((alternative) => {
|
|
156
|
+
const versions = alternative.match(/\d+\.\d+\.\d+/g) ?? [];
|
|
157
|
+
if (!versions.every((version) => /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(version)))
|
|
158
|
+
return false;
|
|
159
|
+
const bounds = clauseBounds(alternative);
|
|
160
|
+
if (!bounds || !bounds.min.every(Number.isSafeInteger) ||
|
|
161
|
+
(bounds.max && !bounds.max.every(Number.isSafeInteger)))
|
|
162
|
+
return false;
|
|
163
|
+
const first = bounds.minInclusive ? bounds.min : [bounds.min[0], bounds.min[1], bounds.min[2] + 1];
|
|
164
|
+
if (!first.every(Number.isSafeInteger) || compare(first, target) < 0)
|
|
165
|
+
return false;
|
|
166
|
+
if (!bounds.max)
|
|
167
|
+
return true;
|
|
168
|
+
const relation = compare(first, bounds.max);
|
|
169
|
+
return relation < 0 || (relation === 0 && bounds.maxInclusive);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type DirectoryPrincipalResolveRequest, type DirectoryPrincipalResolution } from './directory-contract';
|
|
2
|
+
export interface FunctionServiceDirectoryOptions {
|
|
3
|
+
request: {
|
|
4
|
+
headers: Pick<Headers, 'get'> | Readonly<Record<string, string | readonly string[] | undefined>>;
|
|
5
|
+
};
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
fetchImpl?: typeof globalThis.fetch;
|
|
8
|
+
}
|
|
9
|
+
export interface FunctionServiceDirectoryClient {
|
|
10
|
+
resolve(input: DirectoryPrincipalResolveRequest): Promise<DirectoryPrincipalResolution>;
|
|
11
|
+
}
|
|
12
|
+
export declare function createFunctionServiceDirectoryClient({ request, baseUrl, fetchImpl }: FunctionServiceDirectoryOptions): FunctionServiceDirectoryClient;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFunctionServiceDirectoryClient = createFunctionServiceDirectoryClient;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const directory_contract_1 = require("./directory-contract");
|
|
6
|
+
function credential({ request }) {
|
|
7
|
+
const headers = request.headers;
|
|
8
|
+
const matches = typeof headers.get === 'function' ? [headers.get(directory_contract_1.FUNCTION_DIRECTORY_TOKEN_HEADER)]
|
|
9
|
+
: Object.entries(headers).filter(([key]) => key.toLowerCase() === directory_contract_1.FUNCTION_DIRECTORY_TOKEN_HEADER).map(([, value]) => value);
|
|
10
|
+
const token = matches[0];
|
|
11
|
+
const refused = () => new directory_contract_1.DirectoryPrincipalResolveError(401, 'invalid_context', 'This invocation has no valid directory credential');
|
|
12
|
+
if (matches.length !== 1 || typeof token !== 'string' || token.length > 16_384)
|
|
13
|
+
throw refused();
|
|
14
|
+
const envelope = /^([A-Za-z0-9_-]+)\.([A-Za-z0-9_-]{43})$/.exec(token);
|
|
15
|
+
if (!envelope?.[1])
|
|
16
|
+
throw refused();
|
|
17
|
+
let value;
|
|
18
|
+
try {
|
|
19
|
+
value = JSON.parse(Buffer.from(envelope[1], 'base64url').toString('utf8'));
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
throw refused();
|
|
23
|
+
}
|
|
24
|
+
const parsed = zod_1.z.object({ audience: zod_1.z.literal('atlas-managed-function-directory-resolve'), sub: zod_1.z.string().startsWith('service-account|'), functionId: zod_1.z.string().min(1), invocationId: zod_1.z.string().min(1), exp: zod_1.z.number() }).safeParse(value);
|
|
25
|
+
if (!parsed.success)
|
|
26
|
+
throw refused();
|
|
27
|
+
return { token, expiresAt: parsed.data.exp };
|
|
28
|
+
}
|
|
29
|
+
function origin(baseUrl) {
|
|
30
|
+
const refused = () => new directory_contract_1.DirectoryPrincipalResolveError(400, 'invalid_configuration', 'Configure a trusted HTTPS Atlas origin without credentials, path, query or fragment');
|
|
31
|
+
let url;
|
|
32
|
+
try {
|
|
33
|
+
url = new URL(baseUrl);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
throw refused();
|
|
37
|
+
}
|
|
38
|
+
const loopback = url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
|
|
39
|
+
if ((!loopback && url.protocol !== 'https:') || url.username || url.password || url.pathname !== '/' || url.search || url.hash)
|
|
40
|
+
throw refused();
|
|
41
|
+
return url.origin;
|
|
42
|
+
}
|
|
43
|
+
function completeResolution({ result, query }) {
|
|
44
|
+
const expected = new Set(query.lookups.map((lookup) => `${lookup.type}:${lookup.value}`));
|
|
45
|
+
const received = [...result.resolved.map((value) => value.lookup), ...result.unresolved];
|
|
46
|
+
const actual = new Set(received.map((lookup) => `${lookup.type}:${lookup.value}`));
|
|
47
|
+
return received.length === expected.size && actual.size === expected.size && [...actual].every((key) => expected.has(key))
|
|
48
|
+
&& result.resolved.every((value) => value.lookup.type !== 'email' || value.email === value.lookup.value);
|
|
49
|
+
}
|
|
50
|
+
function createFunctionServiceDirectoryClient({ request, baseUrl, fetchImpl = globalThis.fetch }) {
|
|
51
|
+
const url = `${origin(baseUrl)}${directory_contract_1.FUNCTION_DIRECTORY_RESOLVE_PATH}`;
|
|
52
|
+
const { token, expiresAt } = credential({ request });
|
|
53
|
+
return {
|
|
54
|
+
async resolve(input) {
|
|
55
|
+
if (expiresAt <= Date.now() / 1000)
|
|
56
|
+
throw new directory_contract_1.DirectoryPrincipalResolveError(401, 'expired_context', 'The directory credential expired; start a new invocation');
|
|
57
|
+
const query = directory_contract_1.directoryPrincipalResolveRequestSchema.safeParse(input);
|
|
58
|
+
if (!query.success)
|
|
59
|
+
throw new directory_contract_1.DirectoryPrincipalResolveError(400, 'invalid_request', 'Invalid exact directory resolution request');
|
|
60
|
+
const response = await fetchImpl(url, { method: 'POST', headers: { 'content-type': 'application/json', [directory_contract_1.FUNCTION_DIRECTORY_TOKEN_HEADER]: token }, body: JSON.stringify(query.data), redirect: 'error', signal: AbortSignal.timeout(30_000) });
|
|
61
|
+
const body = await response.json().catch(() => null);
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
const error = zod_1.z.object({ code: zod_1.z.string().max(128).optional(), detail: zod_1.z.string().max(2000).optional() }).safeParse(body);
|
|
64
|
+
throw new directory_contract_1.DirectoryPrincipalResolveError(response.status, error.success ? error.data.code ?? 'directory_resolve_failed' : 'directory_resolve_failed', error.success ? error.data.detail ?? 'Directory resolution failed' : 'Directory resolution failed');
|
|
65
|
+
}
|
|
66
|
+
const result = directory_contract_1.directoryPrincipalResolutionSchema.safeParse(body);
|
|
67
|
+
if (!result.success || !completeResolution({ result: result.data, query: query.data }))
|
|
68
|
+
throw new directory_contract_1.DirectoryPrincipalResolveError(502, 'malformed_response', 'Atlas returned an invalid directory resolution');
|
|
69
|
+
return result.data;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const functionWorkflowScopesSchema: z.ZodObject<{
|
|
3
|
+
read: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
4
|
+
evidence: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
5
|
+
}, z.core.$strict>;
|
|
6
|
+
export type FunctionWorkflowScopes = z.infer<typeof functionWorkflowScopesSchema>;
|
|
7
|
+
export declare function readFunctionWorkflowScopes(manifest: unknown): string[];
|
|
8
|
+
export declare function readFunctionWorkflowEvidenceScopes(manifest: unknown): string[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.functionWorkflowScopesSchema = void 0;
|
|
4
|
+
exports.readFunctionWorkflowScopes = readFunctionWorkflowScopes;
|
|
5
|
+
exports.readFunctionWorkflowEvidenceScopes = readFunctionWorkflowEvidenceScopes;
|
|
6
|
+
const zod_1 = require("zod");
|
|
7
|
+
const workflowId = zod_1.z.string().min(1).max(255).regex(/^[A-Za-z0-9._-]+$/);
|
|
8
|
+
const exactWorkflowIds = zod_1.z.array(workflowId).min(1).max(64)
|
|
9
|
+
.refine((ids) => new Set(ids).size === ids.length, 'Workflow ids must be distinct')
|
|
10
|
+
.refine((ids) => ids.reduce((bytes, id) => bytes + id.length, 0) <= 8192, 'Workflow ids must fit within 8192 bytes');
|
|
11
|
+
exports.functionWorkflowScopesSchema = zod_1.z.strictObject({
|
|
12
|
+
read: exactWorkflowIds.optional(),
|
|
13
|
+
evidence: exactWorkflowIds.optional(),
|
|
14
|
+
}).refine((scopes) => scopes.read !== undefined || scopes.evidence !== undefined, 'Declare workflow reads or evidence verification');
|
|
15
|
+
function readWorkflowCapabilities({ manifest }) {
|
|
16
|
+
if (typeof manifest !== 'object' || manifest === null)
|
|
17
|
+
return null;
|
|
18
|
+
const capabilities = Reflect.get(manifest, 'capabilities');
|
|
19
|
+
if (typeof capabilities !== 'object' || capabilities === null)
|
|
20
|
+
return null;
|
|
21
|
+
const workflows = Reflect.get(capabilities, 'workflows');
|
|
22
|
+
return workflows === undefined ? null : exports.functionWorkflowScopesSchema.parse(workflows);
|
|
23
|
+
}
|
|
24
|
+
function readFunctionWorkflowScopes(manifest) {
|
|
25
|
+
return readWorkflowCapabilities({ manifest })?.read ?? [];
|
|
26
|
+
}
|
|
27
|
+
function readFunctionWorkflowEvidenceScopes(manifest) {
|
|
28
|
+
return readWorkflowCapabilities({ manifest })?.evidence ?? [];
|
|
29
|
+
}
|