@atlas-cmdb/extension-sdk 0.0.0-stage → 0.5.1

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.
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Client for the Atlas API from inside an extension, authenticated with the invocation token
3
+ * of the current call. Paths are relative to the organisation:
4
+ * `ctx.api.get('assets', { category })` → `GET /api/v1/organizations/<org>/assets?category=…`.
5
+ */
6
+ export declare class AtlasApiError extends Error {
7
+ readonly status: number;
8
+ readonly code: string;
9
+ constructor(status: number, code: string, message: string);
10
+ }
11
+ type Query = Record<string, string | number | boolean | undefined | null>;
12
+ export type ExtensionRecord<T = Record<string, unknown>> = {
13
+ id: string;
14
+ key: string | null;
15
+ data: T;
16
+ created_at: string;
17
+ updated_at: string;
18
+ };
19
+ export type AgentJobStatus = 'queued' | 'running' | 'succeeded' | 'failed' | 'cancelled' | 'expired';
20
+ export type AgentJob = {
21
+ id: string;
22
+ action: string;
23
+ status: AgentJobStatus;
24
+ tags: string[];
25
+ agent: {
26
+ id: string;
27
+ name: string;
28
+ } | null;
29
+ summary: Record<string, unknown> | null;
30
+ error: string | null;
31
+ result_count: number;
32
+ created_at: string;
33
+ claimed_at: string | null;
34
+ finished_at: string | null;
35
+ };
36
+ export type AgentJobInput = {
37
+ /** only agents with all of these tags (e.g. a site) run the job */
38
+ tags?: string[];
39
+ /** a credential of the organisation (needs `agent:credentials`), or `local:<name>` */
40
+ credential?: string;
41
+ /** how long the agent may work on it (10–3600 s, default 300) */
42
+ timeoutSeconds?: number;
43
+ /**
44
+ * Polled readings nobody needs in the job history: Atlas deletes the job once its results
45
+ * are read (or 10 minutes after it finished).
46
+ */
47
+ ephemeral?: boolean;
48
+ };
49
+ export type Member = {
50
+ id: string;
51
+ given_name: string | null;
52
+ family_name: string | null;
53
+ email: string;
54
+ picture: string | null;
55
+ role: string;
56
+ };
57
+ export declare class AtlasClient {
58
+ #private;
59
+ constructor(options: {
60
+ apiUrl: string;
61
+ token: string;
62
+ organizationId: string;
63
+ signal?: AbortSignal;
64
+ });
65
+ request<T = unknown>(method: string, path: string, options?: {
66
+ query?: Query;
67
+ body?: unknown;
68
+ }): Promise<T>;
69
+ get<T = unknown>(path: string, query?: Query): Promise<T>;
70
+ post<T = unknown>(path: string, body?: unknown): Promise<T>;
71
+ put<T = unknown>(path: string, body?: unknown): Promise<T>;
72
+ patch<T = unknown>(path: string, body?: unknown): Promise<T>;
73
+ delete<T = unknown>(path: string): Promise<T>;
74
+ /**
75
+ * Jobs on the organisation's Atlas agents (manifest scopes `agent:<action>`). Each agent runs
76
+ * them inside its own network under its own policy; Atlas refuses a job up front (409) when
77
+ * no online agent with the tags supports the action and allows its targets.
78
+ */
79
+ get agents(): {
80
+ /** Queue a job and return it at once (or after up to `waitSeconds` ≤ 30). */
81
+ create: (action: string, params: unknown, input?: AgentJobInput & {
82
+ waitSeconds?: number;
83
+ }) => Promise<AgentJob>;
84
+ job: (id: string) => Promise<AgentJob>;
85
+ /** All results of a finished job, in the order the agent sent them. */
86
+ results: <T = unknown>(id: string) => Promise<T[]>;
87
+ cancel: (id: string) => Promise<AgentJob>;
88
+ /**
89
+ * Run a job and wait for it: resolves with the finished job and its results, or throws
90
+ * `AtlasApiError` (`agent_job_failed`) when it failed, expired or was cancelled.
91
+ */
92
+ run: <T = unknown>(action: string, params: unknown, input?: AgentJobInput & {
93
+ pollMs?: number;
94
+ maxWaitMs?: number;
95
+ }) => Promise<{
96
+ job: AgentJob;
97
+ results: T[];
98
+ }>;
99
+ };
100
+ /** Members of the organisation (scope `member:read`). */
101
+ members(): Promise<Member[]>;
102
+ /** The extension's own record store (collections declared in `storage.collections`). */
103
+ records<T = Record<string, unknown>>(collection: string): {
104
+ list: (query?: {
105
+ key?: string;
106
+ where?: Record<string, string>;
107
+ limit?: number;
108
+ cursor?: string;
109
+ }) => Promise<{
110
+ data: ExtensionRecord<T>[];
111
+ next_cursor: string | null;
112
+ }>;
113
+ get: (id: string) => Promise<ExtensionRecord<T>>;
114
+ create: (data: T, key?: string) => Promise<ExtensionRecord<T>>;
115
+ replace: (id: string, data: T) => Promise<ExtensionRecord<T>>;
116
+ put: (key: string, data: T) => Promise<ExtensionRecord<T>>;
117
+ delete: (id: string) => Promise<void>;
118
+ };
119
+ }
120
+ export {};
package/dist/client.js ADDED
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Client for the Atlas API from inside an extension, authenticated with the invocation token
3
+ * of the current call. Paths are relative to the organisation:
4
+ * `ctx.api.get('assets', { category })` → `GET /api/v1/organizations/<org>/assets?category=…`.
5
+ */
6
+ export class AtlasApiError extends Error {
7
+ status;
8
+ code;
9
+ constructor(status, code, message) {
10
+ super(message);
11
+ this.status = status;
12
+ this.code = code;
13
+ }
14
+ }
15
+ const FINISHED = ['succeeded', 'failed', 'cancelled', 'expired'];
16
+ const sleep = (ms, signal) => new Promise((resolve, reject) => {
17
+ const timer = setTimeout(resolve, ms);
18
+ signal?.addEventListener('abort', () => (clearTimeout(timer), reject(signal.reason)), { once: true });
19
+ });
20
+ export class AtlasClient {
21
+ #base;
22
+ #token;
23
+ #signal;
24
+ constructor(options) {
25
+ this.#base = `${options.apiUrl.replace(/\/$/, '')}/organizations/${encodeURIComponent(options.organizationId)}/`;
26
+ this.#token = options.token;
27
+ this.#signal = options.signal;
28
+ }
29
+ async request(method, path, options = {}) {
30
+ const url = new URL(path.replace(/^\/+/, ''), this.#base);
31
+ for (const [name, value] of Object.entries(options.query ?? {}))
32
+ if (value !== undefined && value !== null)
33
+ url.searchParams.set(name, String(value));
34
+ const response = await fetch(url, {
35
+ method,
36
+ headers: {
37
+ authorization: `Bearer ${this.#token}`,
38
+ accept: 'application/json',
39
+ ...(options.body !== undefined ? { 'content-type': 'application/json' } : {})
40
+ },
41
+ body: options.body !== undefined ? JSON.stringify(options.body) : undefined,
42
+ signal: this.#signal
43
+ });
44
+ if (response.status === 204)
45
+ return undefined;
46
+ const text = await response.text();
47
+ const json = text ? JSON.parse(text) : undefined;
48
+ if (!response.ok)
49
+ throw new AtlasApiError(response.status, json?.code ?? 'error', json?.detail ?? json?.title ?? response.statusText);
50
+ return json;
51
+ }
52
+ get(path, query) {
53
+ return this.request('GET', path, { query });
54
+ }
55
+ post(path, body) {
56
+ return this.request('POST', path, { body });
57
+ }
58
+ put(path, body) {
59
+ return this.request('PUT', path, { body });
60
+ }
61
+ patch(path, body) {
62
+ return this.request('PATCH', path, { body });
63
+ }
64
+ delete(path) {
65
+ return this.request('DELETE', path);
66
+ }
67
+ /**
68
+ * Jobs on the organisation's Atlas agents (manifest scopes `agent:<action>`). Each agent runs
69
+ * them inside its own network under its own policy; Atlas refuses a job up front (409) when
70
+ * no online agent with the tags supports the action and allows its targets.
71
+ */
72
+ get agents() {
73
+ const base = 'agent/jobs';
74
+ const create = (action, params, input = {}) => this.post(base, {
75
+ action,
76
+ params,
77
+ tags: input.tags,
78
+ credential: input.credential,
79
+ timeout_seconds: input.timeoutSeconds,
80
+ wait_seconds: input.waitSeconds,
81
+ ...(input.ephemeral ? { ephemeral: true } : {})
82
+ });
83
+ const job = (id) => this.get(`${base}/${encodeURIComponent(id)}`);
84
+ const results = async (id) => {
85
+ const all = [];
86
+ let cursor = '0';
87
+ while (cursor !== null) {
88
+ const page = await this.get(`${base}/${encodeURIComponent(id)}/results`, { cursor });
89
+ all.push(...page.data);
90
+ cursor = page.next_cursor;
91
+ }
92
+ return all;
93
+ };
94
+ return {
95
+ /** Queue a job and return it at once (or after up to `waitSeconds` ≤ 30). */
96
+ create,
97
+ job,
98
+ /** All results of a finished job, in the order the agent sent them. */
99
+ results,
100
+ cancel: (id) => this.post(`${base}/${encodeURIComponent(id)}/cancel`),
101
+ /**
102
+ * Run a job and wait for it: resolves with the finished job and its results, or throws
103
+ * `AtlasApiError` (`agent_job_failed`) when it failed, expired or was cancelled.
104
+ */
105
+ run: async (action, params, input = {}) => {
106
+ const deadline = Date.now() + (input.maxWaitMs ?? ((input.timeoutSeconds ?? 300) + 60) * 1000);
107
+ let current = await create(action, params, { ...input, waitSeconds: 25 });
108
+ while (!FINISHED.includes(current.status)) {
109
+ if (Date.now() > deadline) {
110
+ await this.post(`${base}/${encodeURIComponent(current.id)}/cancel`).catch(() => undefined);
111
+ throw new AtlasApiError(504, 'agent_job_timeout', `${action} did not finish in time`);
112
+ }
113
+ await sleep(input.pollMs ?? 1000, this.#signal);
114
+ current = await job(current.id);
115
+ }
116
+ if (current.status !== 'succeeded')
117
+ throw new AtlasApiError(502, 'agent_job_failed', current.error ?? `${action} ${current.status}`);
118
+ return { job: current, results: await results(current.id) };
119
+ }
120
+ };
121
+ }
122
+ /** Members of the organisation (scope `member:read`). */
123
+ async members() {
124
+ return (await this.get('members')).data;
125
+ }
126
+ /** The extension's own record store (collections declared in `storage.collections`). */
127
+ records(collection) {
128
+ const base = `extension/records/${encodeURIComponent(collection)}`;
129
+ return {
130
+ list: (query = {}) => this.get(base, {
131
+ key: query.key,
132
+ limit: query.limit,
133
+ cursor: query.cursor,
134
+ ...Object.fromEntries(Object.entries(query.where ?? {}).map(([k, v]) => [`where.${k}`, v]))
135
+ }),
136
+ get: (id) => this.get(`${base}/${encodeURIComponent(id)}`),
137
+ create: (data, key) => this.post(base, { data, key }),
138
+ replace: (id, data) => this.put(`${base}/${encodeURIComponent(id)}`, { data }),
139
+ put: (key, data) => this.put(`${base}/keys/${encodeURIComponent(key)}`, { data }),
140
+ delete: (id) => this.delete(`${base}/${encodeURIComponent(id)}`)
141
+ };
142
+ }
143
+ }
144
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAE7B;IACA;IAFV,YACU,MAAc,EACd,IAAY,EACrB,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,C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CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;aAC3F,CAAC;YACH,GAAG,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAqB,GAAG,IAAI,IAAI,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC;YACtF,MAAM,EAAE,CAAC,IAAO,EAAE,GAAY,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAqB,IAAI,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;YACrF,OAAO,EAAE,CAAC,EAAU,EAAE,IAAO,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAqB,GAAG,IAAI,IAAI,kBAAkB,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;YAC7G,GAAG,EAAE,CAAC,GAAW,EAAE,IAAO,EAAE,EAAE,CAC7B,IAAI,CAAC,GAAG,CAAqB,GAAG,IAAI,SAAS,kBAAkB,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;YAClF,MAAM,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAO,GAAG,IAAI,IAAI,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC;SAC9E,CAAC;IACH,CAAC;CACD"}
package/dist/dev.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `atlas-ext dev`: run the extension server locally with --watch, trusting a local Atlas.
3
+ * In Atlas set `SECRET_EXTENSION_RUNTIME=dev` and
4
+ * `SECRET_EXTENSION_DEV_ENDPOINTS={"<id>":"http://localhost:<port>"}`.
5
+ */
6
+ export declare function runDev(options: {
7
+ root: string;
8
+ port: number;
9
+ entry?: string;
10
+ atlas: string;
11
+ }): Promise<void>;
package/dist/dev.js ADDED
@@ -0,0 +1,23 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { existsSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ /**
5
+ * `atlas-ext dev`: run the extension server locally with --watch, trusting a local Atlas.
6
+ * In Atlas set `SECRET_EXTENSION_RUNTIME=dev` and
7
+ * `SECRET_EXTENSION_DEV_ENDPOINTS={"<id>":"http://localhost:<port>"}`.
8
+ */
9
+ export async function runDev(options) {
10
+ const entry = options.entry ??
11
+ ['server/index.ts', 'server/index.js', 'server/index.mjs'].find((path) => existsSync(join(options.root, path)));
12
+ if (!entry)
13
+ throw new Error('No server entry: add server/index.ts or pass --entry');
14
+ const keysUrl = `${options.atlas.replace(/\/$/, '')}/api/v1/extensions/keys`;
15
+ console.log(`atlas-ext dev: ${entry} on http://localhost:${options.port}, trusting ${keysUrl}`);
16
+ const child = spawn(process.execPath, ['--watch', entry], {
17
+ cwd: options.root,
18
+ stdio: 'inherit',
19
+ env: { ...process.env, PORT: String(options.port), ATLAS_CORE_KEYS_URL: keysUrl }
20
+ });
21
+ await new Promise((resolve) => child.on('exit', () => resolve()));
22
+ }
23
+ //# sourceMappingURL=dev.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.js","sourceRoot":"","sources":["../src/dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAAsE;IAClG,MAAM,KAAK,GACV,OAAO,CAAC,KAAK;QACb,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,kBAAkB,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACjH,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IACpF,MAAM,OAAO,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,yBAAyB,CAAC;IAC7E,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,wBAAwB,OAAO,CAAC,IAAI,cAAc,OAAO,EAAE,CAAC,CAAC;IAChG,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE;QACzD,GAAG,EAAE,OAAO,CAAC,IAAI;QACjB,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,mBAAmB,EAAE,OAAO,EAAE;KACjF,CAAC,CAAC;IACH,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;AACzE,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { z } from 'zod';
2
+ import { registryIndexSchema } from './registry.js';
3
+ /** Prints the JSON Schema of a registry index.json. */
4
+ const schema = z.toJSONSchema(registryIndexSchema, { io: 'input', unrepresentable: 'any' });
5
+ process.stdout.write(`${JSON.stringify({
6
+ $id: 'https://registry.atlas-cmdb.com/schema/atlas-index.schema.json',
7
+ title: 'Atlas extension registry index',
8
+ ...schema
9
+ }, null, '\t')}\n`);
10
+ //# sourceMappingURL=index-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-schema.js","sourceRoot":"","sources":["../src/index-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,uDAAuD;AACvD,MAAM,MAAM,GAAG,CAAC,CAAC,YAAY,CAAC,mBAAmB,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,CAAC;AAC5F,OAAO,CAAC,MAAM,CAAC,KAAK,CACnB,GAAG,IAAI,CAAC,SAAS,CAChB;IACC,GAAG,EAAE,gEAAgE;IACrE,KAAK,EAAE,gCAAgC;IACvC,GAAG,MAAM;CACT,EACD,IAAI,EACJ,IAAI,CACJ,IAAI,CACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './manifest.js';
2
+ export { MANIFEST_FILE, SIGNATURE_FILE, SIGNATURE_CONTEXT, packageDigest, keyIdOf, generatePublisherKey, signFiles, verifyFiles, packFiles, unpackFiles, type PackageSignature } from './package.js';
3
+ export { buildPackage, readManifest, type BuildOptions, type BuildResult } from './build.js';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './manifest.js';
2
+ export { MANIFEST_FILE, SIGNATURE_FILE, SIGNATURE_CONTEXT, packageDigest, keyIdOf, generatePublisherKey, signFiles, verifyFiles, packFiles, unpackFiles } from './package.js';
3
+ export { buildPackage, readManifest } from './build.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,OAAO,EACN,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,OAAO,EACP,oBAAoB,EACpB,SAAS,EACT,WAAW,EACX,SAAS,EACT,WAAW,EAEX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAuC,MAAM,YAAY,CAAC"}
@@ -0,0 +1,216 @@
1
+ import { z } from 'zod';
2
+ /** Widget sizes on the organisation home page. */
3
+ export declare const WIDGET_SIZES: readonly ["1x1", "2x1", "2x2"];
4
+ /** Organisation permissions a contribution or function can require. */
5
+ export declare const ORGANIZATION_PERMISSIONS: readonly ["organization:view", "content:edit", "content:delete-request", "content:delete-review", "organization:manage"];
6
+ /**
7
+ * Core API scopes an external extension may request in v1. Calendar and file scopes are left
8
+ * out until extension principals can own calendar events and files.
9
+ */
10
+ export declare const EXTENSION_CORE_SCOPES: readonly ["organization:read", "category:read", "asset:read", "asset:write", "relation:read", "relation:write", "note:read", "note:write", "history:read", "member:read"];
11
+ /** `net:host:<host>:<port>`: a host the extension's container may reach through the egress proxy. */
12
+ export declare const NET_HOST_SCOPE: RegExp;
13
+ /**
14
+ * `net:setting:<name>`: the host and port of the organisation's value of url setting `<name>`
15
+ * (a customer's own Zammad, say) may be reached through the egress proxy.
16
+ */
17
+ export declare const NET_SETTING_SCOPE: RegExp;
18
+ /** The setting name of a `net:setting:` scope, or null. */
19
+ export declare function netSettingOf(value: string): string | null;
20
+ export declare function isNetHostScope(value: string): boolean;
21
+ /**
22
+ * Agent actions an extension may request as `agent:<action>` (the Atlas agent's catalog v1,
23
+ * src/lib/server/agents/catalog.ts; a test keeps both lists equal). `agent:credentials` also
24
+ * lets its jobs use the organisation's agent credentials (SNMP communities, BMC logins).
25
+ */
26
+ export declare const AGENT_ACTION_NAMES: readonly ["net.ping", "net.tcp_probe", "net.arp_table", "dns.lookup", "snmp.get", "snmp.walk", "http.request", "redfish.get"];
27
+ export type AgentActionName = (typeof AGENT_ACTION_NAMES)[number];
28
+ export declare const AGENT_CREDENTIALS_SCOPE = "agent:credentials";
29
+ /** Carried by invocation tokens of extensions with any agent scope; guards the job routes. */
30
+ export declare const AGENT_JOBS_SCOPE = "agent:jobs";
31
+ export declare function isAgentScope(value: string): boolean;
32
+ /** Human-readable description of a scope, for consent screens. */
33
+ export declare function describeScope(scope: string): string;
34
+ /** Scopes of a manifest that are core API scopes (the rest are `net:host:` and agent grants). */
35
+ export declare const coreScopesOf: (scopes: readonly string[]) => string[];
36
+ export declare const agentScopesOf: (scopes: readonly string[]) => string[];
37
+ export declare const netHostsOf: (scopes: readonly string[]) => string[];
38
+ /**
39
+ * Manifest of an Atlas extension package (`atlas-extension.json` inside an `.atlasx`).
40
+ * Kept identical to the schema Atlas validates uploads with; Atlas is the authority.
41
+ */
42
+ /** Extension API version this Atlas build implements; manifests declare a range (`atlasApi`). */
43
+ export declare const ATLAS_EXTENSION_API = "1.1.0";
44
+ export declare const extensionManifestSchema: z.ZodObject<{
45
+ id: z.ZodString;
46
+ name: z.ZodString;
47
+ version: z.ZodString;
48
+ publisher: z.ZodString;
49
+ description: z.ZodOptional<z.ZodString>;
50
+ icon: z.ZodOptional<z.ZodString>;
51
+ homepage: z.ZodOptional<z.ZodURL>;
52
+ atlasApi: z.ZodString;
53
+ image: z.ZodOptional<z.ZodString>;
54
+ scopes: z.ZodDefault<z.ZodArray<z.ZodString>>;
55
+ settings: z.ZodDefault<z.ZodArray<z.ZodObject<{
56
+ name: z.ZodString;
57
+ label: z.ZodString;
58
+ type: z.ZodEnum<{
59
+ number: "number";
60
+ boolean: "boolean";
61
+ text: "text";
62
+ secret: "secret";
63
+ select: "select";
64
+ category: "category";
65
+ list: "list";
66
+ url: "url";
67
+ credential: "credential";
68
+ }>;
69
+ description: z.ZodOptional<z.ZodString>;
70
+ required: z.ZodOptional<z.ZodBoolean>;
71
+ options: z.ZodOptional<z.ZodArray<z.ZodObject<{
72
+ value: z.ZodString;
73
+ label: z.ZodString;
74
+ }, z.core.$strip>>>;
75
+ }, z.core.$strip>>>;
76
+ storage: z.ZodDefault<z.ZodObject<{
77
+ collections: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
78
+ indexes: z.ZodOptional<z.ZodArray<z.ZodString>>;
79
+ }, z.core.$strip>>>;
80
+ }, z.core.$strip>>;
81
+ functions: z.ZodDefault<z.ZodArray<z.ZodObject<{
82
+ name: z.ZodString;
83
+ permission: z.ZodOptional<z.ZodEnum<{
84
+ "organization:view": "organization:view";
85
+ "content:edit": "content:edit";
86
+ "content:delete-request": "content:delete-request";
87
+ "content:delete-review": "content:delete-review";
88
+ "organization:manage": "organization:manage";
89
+ }>>;
90
+ }, z.core.$strip>>>;
91
+ lifecycle: z.ZodDefault<z.ZodArray<z.ZodEnum<{
92
+ install: "install";
93
+ upgrade: "upgrade";
94
+ uninstall: "uninstall";
95
+ }>>>;
96
+ runtime: z.ZodDefault<z.ZodObject<{
97
+ isolation: z.ZodDefault<z.ZodEnum<{
98
+ shared: "shared";
99
+ "per-organization": "per-organization";
100
+ }>>;
101
+ }, z.core.$strip>>;
102
+ jobs: z.ZodDefault<z.ZodArray<z.ZodObject<{
103
+ name: z.ZodString;
104
+ title: z.ZodString;
105
+ schedule: z.ZodOptional<z.ZodString>;
106
+ timeoutSeconds: z.ZodDefault<z.ZodNumber>;
107
+ }, z.core.$strip>>>;
108
+ inbound: z.ZodDefault<z.ZodArray<z.ZodObject<{
109
+ name: z.ZodString;
110
+ function: z.ZodString;
111
+ methods: z.ZodArray<z.ZodEnum<{
112
+ GET: "GET";
113
+ POST: "POST";
114
+ PUT: "PUT";
115
+ PATCH: "PATCH";
116
+ DELETE: "DELETE";
117
+ }>>;
118
+ }, z.core.$strip>>>;
119
+ contributes: z.ZodDefault<z.ZodObject<{
120
+ navigation: z.ZodOptional<z.ZodArray<z.ZodObject<{
121
+ id: z.ZodString;
122
+ label: z.ZodString;
123
+ icon: z.ZodOptional<z.ZodString>;
124
+ page: z.ZodString;
125
+ order: z.ZodOptional<z.ZodNumber>;
126
+ permission: z.ZodOptional<z.ZodEnum<{
127
+ "organization:view": "organization:view";
128
+ "content:edit": "content:edit";
129
+ "content:delete-request": "content:delete-request";
130
+ "content:delete-review": "content:delete-review";
131
+ "organization:manage": "organization:manage";
132
+ }>>;
133
+ }, z.core.$strip>>>;
134
+ pages: z.ZodOptional<z.ZodArray<z.ZodObject<{
135
+ path: z.ZodString;
136
+ title: z.ZodString;
137
+ element: z.ZodString;
138
+ load: z.ZodOptional<z.ZodString>;
139
+ permission: z.ZodOptional<z.ZodEnum<{
140
+ "organization:view": "organization:view";
141
+ "content:edit": "content:edit";
142
+ "content:delete-request": "content:delete-request";
143
+ "content:delete-review": "content:delete-review";
144
+ "organization:manage": "organization:manage";
145
+ }>>;
146
+ }, z.core.$strip>>>;
147
+ assetTabs: z.ZodOptional<z.ZodArray<z.ZodObject<{
148
+ id: z.ZodString;
149
+ label: z.ZodString;
150
+ icon: z.ZodOptional<z.ZodString>;
151
+ element: z.ZodString;
152
+ permission: z.ZodOptional<z.ZodEnum<{
153
+ "organization:view": "organization:view";
154
+ "content:edit": "content:edit";
155
+ "content:delete-request": "content:delete-request";
156
+ "content:delete-review": "content:delete-review";
157
+ "organization:manage": "organization:manage";
158
+ }>>;
159
+ }, z.core.$strip>>>;
160
+ widgets: z.ZodOptional<z.ZodArray<z.ZodObject<{
161
+ id: z.ZodString;
162
+ title: z.ZodString;
163
+ element: z.ZodString;
164
+ sizes: z.ZodArray<z.ZodEnum<{
165
+ "1x1": "1x1";
166
+ "2x1": "2x1";
167
+ "2x2": "2x2";
168
+ }>>;
169
+ defaultSize: z.ZodOptional<z.ZodEnum<{
170
+ "1x1": "1x1";
171
+ "2x1": "2x1";
172
+ "2x2": "2x2";
173
+ }>>;
174
+ permission: z.ZodOptional<z.ZodEnum<{
175
+ "organization:view": "organization:view";
176
+ "content:edit": "content:edit";
177
+ "content:delete-request": "content:delete-request";
178
+ "content:delete-review": "content:delete-review";
179
+ "organization:manage": "organization:manage";
180
+ }>>;
181
+ }, z.core.$strip>>>;
182
+ settingsPanel: z.ZodOptional<z.ZodObject<{
183
+ element: z.ZodString;
184
+ }, z.core.$strip>>;
185
+ metrics: z.ZodOptional<z.ZodObject<{
186
+ function: z.ZodString;
187
+ }, z.core.$strip>>;
188
+ calendarSources: z.ZodOptional<z.ZodArray<z.ZodObject<{
189
+ id: z.ZodString;
190
+ label: z.ZodString;
191
+ function: z.ZodString;
192
+ }, z.core.$strip>>>;
193
+ mcpTools: z.ZodOptional<z.ZodArray<z.ZodObject<{
194
+ name: z.ZodString;
195
+ description: z.ZodString;
196
+ function: z.ZodString;
197
+ input: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
198
+ }, z.core.$strip>>>;
199
+ }, z.core.$strict>>;
200
+ }, z.core.$strict>;
201
+ export type ExtensionManifest = z.infer<typeof extensionManifestSchema>;
202
+ export type ManifestCheck = {
203
+ ok: true;
204
+ manifest: ExtensionManifest;
205
+ } | {
206
+ ok: false;
207
+ errors: string[];
208
+ };
209
+ /**
210
+ * Parse and validate a manifest, including the rules zod cannot express locally: element tags
211
+ * carry the package prefix, page `load` and functions exist, navigation targets a page, the
212
+ * server image is present when functions are declared, and the API range matches this build.
213
+ */
214
+ export declare function checkManifest(raw: unknown, options?: {
215
+ satisfiesApi?: (range: string) => boolean;
216
+ }): ManifestCheck;