@atlas-cmdb/extension-sdk 0.0.0-stage → 0.5.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 +331 -2
- package/atlas-extension.schema.json +573 -0
- package/atlas-index.schema.json +173 -0
- package/dist/build.d.ts +27 -0
- package/dist/build.js +114 -0
- package/dist/build.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +215 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +120 -0
- package/dist/client.js +144 -0
- package/dist/client.js.map +1 -0
- package/dist/dev.d.ts +11 -0
- package/dist/dev.js +23 -0
- package/dist/dev.js.map +1 -0
- package/dist/index-schema.d.ts +1 -0
- package/dist/index-schema.js +10 -0
- package/dist/index-schema.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.d.ts +216 -0
- package/dist/manifest.js +380 -0
- package/dist/manifest.js.map +1 -0
- package/dist/package.d.ts +34 -0
- package/dist/package.js +107 -0
- package/dist/package.js.map +1 -0
- package/dist/registry.d.ts +124 -0
- package/dist/registry.js +158 -0
- package/dist/registry.js.map +1 -0
- package/dist/schema.d.ts +1 -0
- package/dist/schema.js +10 -0
- package/dist/schema.js.map +1 -0
- package/dist/server.d.ts +152 -0
- package/dist/server.js +254 -0
- package/dist/server.js.map +1 -0
- package/package.json +49 -5
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Registry index v1: a static `index.json` + `index.json.sig` that Atlas instances trust
|
|
4
|
+
* through a key pinned for the registry. The signature covers
|
|
5
|
+
* `atlas-index-v1\n<sha256 hex of the exact index.json bytes>`; Atlas verifies exactly this.
|
|
6
|
+
*
|
|
7
|
+
* A registry is a directory:
|
|
8
|
+
*
|
|
9
|
+
* registry.json { "name": "atlas-cmdb" }
|
|
10
|
+
* publishers.json { "<publisher>": { "name": "…", "keys": ["<base64>"] } }
|
|
11
|
+
* packages/<id>/package.json { "name", "description", "publisher", "homepage", "icon" }
|
|
12
|
+
* packages/<id>/<version>.json version entries (`atlas-ext registry entry`)
|
|
13
|
+
*/
|
|
14
|
+
export declare const INDEX_FORMAT = 1;
|
|
15
|
+
export declare const INDEX_SIGNATURE_CONTEXT = "atlas-index-v1\n";
|
|
16
|
+
export declare const indexVersionSchema: z.ZodObject<{
|
|
17
|
+
version: z.ZodString;
|
|
18
|
+
atlasApi: z.ZodString;
|
|
19
|
+
url: z.ZodURL;
|
|
20
|
+
sha256: z.ZodString;
|
|
21
|
+
size: z.ZodNumber;
|
|
22
|
+
digest: z.ZodString;
|
|
23
|
+
scopes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
24
|
+
image: z.ZodOptional<z.ZodString>;
|
|
25
|
+
lifecycle: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
26
|
+
isolation: z.ZodOptional<z.ZodEnum<{
|
|
27
|
+
shared: "shared";
|
|
28
|
+
"per-organization": "per-organization";
|
|
29
|
+
}>>;
|
|
30
|
+
published_at: z.ZodOptional<z.ZodString>;
|
|
31
|
+
yanked: z.ZodOptional<z.ZodBoolean>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
export declare const indexPackageSchema: z.ZodObject<{
|
|
34
|
+
name: z.ZodString;
|
|
35
|
+
description: z.ZodOptional<z.ZodString>;
|
|
36
|
+
publisher: z.ZodString;
|
|
37
|
+
homepage: z.ZodOptional<z.ZodURL>;
|
|
38
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
39
|
+
versions: z.ZodArray<z.ZodObject<{
|
|
40
|
+
version: z.ZodString;
|
|
41
|
+
atlasApi: z.ZodString;
|
|
42
|
+
url: z.ZodURL;
|
|
43
|
+
sha256: z.ZodString;
|
|
44
|
+
size: z.ZodNumber;
|
|
45
|
+
digest: z.ZodString;
|
|
46
|
+
scopes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
47
|
+
image: z.ZodOptional<z.ZodString>;
|
|
48
|
+
lifecycle: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
49
|
+
isolation: z.ZodOptional<z.ZodEnum<{
|
|
50
|
+
shared: "shared";
|
|
51
|
+
"per-organization": "per-organization";
|
|
52
|
+
}>>;
|
|
53
|
+
published_at: z.ZodOptional<z.ZodString>;
|
|
54
|
+
yanked: z.ZodOptional<z.ZodBoolean>;
|
|
55
|
+
}, z.core.$strip>>;
|
|
56
|
+
}, z.core.$strip>;
|
|
57
|
+
export declare const registryIndexSchema: z.ZodObject<{
|
|
58
|
+
format: z.ZodLiteral<1>;
|
|
59
|
+
name: z.ZodString;
|
|
60
|
+
serial: z.ZodNumber;
|
|
61
|
+
generated_at: z.ZodString;
|
|
62
|
+
expires_at: z.ZodString;
|
|
63
|
+
publishers: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
64
|
+
name: z.ZodOptional<z.ZodString>;
|
|
65
|
+
keys: z.ZodArray<z.ZodString>;
|
|
66
|
+
}, z.core.$strip>>;
|
|
67
|
+
packages: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
68
|
+
name: z.ZodString;
|
|
69
|
+
description: z.ZodOptional<z.ZodString>;
|
|
70
|
+
publisher: z.ZodString;
|
|
71
|
+
homepage: z.ZodOptional<z.ZodURL>;
|
|
72
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
73
|
+
versions: z.ZodArray<z.ZodObject<{
|
|
74
|
+
version: z.ZodString;
|
|
75
|
+
atlasApi: z.ZodString;
|
|
76
|
+
url: z.ZodURL;
|
|
77
|
+
sha256: z.ZodString;
|
|
78
|
+
size: z.ZodNumber;
|
|
79
|
+
digest: z.ZodString;
|
|
80
|
+
scopes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
81
|
+
image: z.ZodOptional<z.ZodString>;
|
|
82
|
+
lifecycle: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
83
|
+
isolation: z.ZodOptional<z.ZodEnum<{
|
|
84
|
+
shared: "shared";
|
|
85
|
+
"per-organization": "per-organization";
|
|
86
|
+
}>>;
|
|
87
|
+
published_at: z.ZodOptional<z.ZodString>;
|
|
88
|
+
yanked: z.ZodOptional<z.ZodBoolean>;
|
|
89
|
+
}, z.core.$strip>>;
|
|
90
|
+
}, z.core.$strip>>;
|
|
91
|
+
}, z.core.$strip>;
|
|
92
|
+
export type IndexVersion = z.infer<typeof indexVersionSchema>;
|
|
93
|
+
export type IndexPackage = z.infer<typeof indexPackageSchema>;
|
|
94
|
+
export type RegistryIndex = z.infer<typeof registryIndexSchema>;
|
|
95
|
+
export type IndexSignature = {
|
|
96
|
+
keyId: string;
|
|
97
|
+
alg: 'ed25519';
|
|
98
|
+
signature: string;
|
|
99
|
+
};
|
|
100
|
+
export declare const indexDigest: (bytes: Buffer) => string;
|
|
101
|
+
/** The exact bytes Atlas fetches and the signature covers. */
|
|
102
|
+
export declare const serializeIndex: (index: RegistryIndex) => Buffer<ArrayBuffer>;
|
|
103
|
+
export declare function signIndex(bytes: Buffer, privateKeyPem: string): IndexSignature;
|
|
104
|
+
export declare function verifyIndex(bytes: Buffer, signature: IndexSignature, publicKeyBase64: string): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* A version entry for a built package: verifies the manifest and, when publisher keys are
|
|
107
|
+
* given, the package signature (a registry must never list a package its publisher did not sign).
|
|
108
|
+
*/
|
|
109
|
+
export declare function versionEntry(archive: Buffer, options: {
|
|
110
|
+
url: string;
|
|
111
|
+
publisherKeys?: string[];
|
|
112
|
+
publishedAt?: string;
|
|
113
|
+
}): Promise<{
|
|
114
|
+
id: string;
|
|
115
|
+
publisher: string;
|
|
116
|
+
entry: IndexVersion;
|
|
117
|
+
manifest: Record<string, unknown>;
|
|
118
|
+
}>;
|
|
119
|
+
/** Assemble the index from a registry directory. Serial: seconds since the epoch. */
|
|
120
|
+
export declare function buildIndex(dir: string, options?: {
|
|
121
|
+
name?: string;
|
|
122
|
+
expiresInDays?: number;
|
|
123
|
+
now?: Date;
|
|
124
|
+
}): RegistryIndex;
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { createHash, createPrivateKey, createPublicKey, sign, verify } from 'node:crypto';
|
|
2
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import semver from 'semver';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { checkManifest } from './manifest.js';
|
|
7
|
+
import { keyIdOf, MANIFEST_FILE, packageDigest, publicKeyFromRaw, rawPublicKey, SIGNATURE_FILE, unpackFiles, verifyFiles } from './package.js';
|
|
8
|
+
/**
|
|
9
|
+
* Registry index v1: a static `index.json` + `index.json.sig` that Atlas instances trust
|
|
10
|
+
* through a key pinned for the registry. The signature covers
|
|
11
|
+
* `atlas-index-v1\n<sha256 hex of the exact index.json bytes>`; Atlas verifies exactly this.
|
|
12
|
+
*
|
|
13
|
+
* A registry is a directory:
|
|
14
|
+
*
|
|
15
|
+
* registry.json { "name": "atlas-cmdb" }
|
|
16
|
+
* publishers.json { "<publisher>": { "name": "…", "keys": ["<base64>"] } }
|
|
17
|
+
* packages/<id>/package.json { "name", "description", "publisher", "homepage", "icon" }
|
|
18
|
+
* packages/<id>/<version>.json version entries (`atlas-ext registry entry`)
|
|
19
|
+
*/
|
|
20
|
+
export const INDEX_FORMAT = 1;
|
|
21
|
+
export const INDEX_SIGNATURE_CONTEXT = 'atlas-index-v1\n';
|
|
22
|
+
const slug = z.string().regex(/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/);
|
|
23
|
+
const sha256Hex = z.string().regex(/^[a-f0-9]{64}$/);
|
|
24
|
+
export const indexVersionSchema = z.object({
|
|
25
|
+
version: z.string().refine((value) => semver.valid(value) === value, 'semantic version'),
|
|
26
|
+
atlasApi: z.string().min(1).max(40),
|
|
27
|
+
url: z.url(),
|
|
28
|
+
sha256: sha256Hex,
|
|
29
|
+
size: z.number().int().positive(),
|
|
30
|
+
digest: sha256Hex,
|
|
31
|
+
scopes: z.array(z.string()).max(50).default([]),
|
|
32
|
+
image: z.string().optional(),
|
|
33
|
+
lifecycle: z.array(z.string()).max(3).optional(),
|
|
34
|
+
isolation: z.enum(['shared', 'per-organization']).optional(),
|
|
35
|
+
published_at: z.string().optional(),
|
|
36
|
+
yanked: z.boolean().optional()
|
|
37
|
+
});
|
|
38
|
+
export const indexPackageSchema = z.object({
|
|
39
|
+
name: z.string().min(1).max(80),
|
|
40
|
+
description: z.string().max(500).optional(),
|
|
41
|
+
publisher: slug,
|
|
42
|
+
homepage: z.url().optional(),
|
|
43
|
+
icon: z.string().max(64).optional(),
|
|
44
|
+
versions: z.array(indexVersionSchema).min(1).max(200)
|
|
45
|
+
});
|
|
46
|
+
export const registryIndexSchema = z.object({
|
|
47
|
+
format: z.literal(INDEX_FORMAT),
|
|
48
|
+
name: slug,
|
|
49
|
+
serial: z.number().int().nonnegative(),
|
|
50
|
+
generated_at: z.string(),
|
|
51
|
+
expires_at: z.string(),
|
|
52
|
+
publishers: z.record(slug, z.object({ name: z.string().optional(), keys: z.array(z.string()).max(10) })),
|
|
53
|
+
packages: z.record(slug, indexPackageSchema)
|
|
54
|
+
});
|
|
55
|
+
export const indexDigest = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
56
|
+
/** The exact bytes Atlas fetches and the signature covers. */
|
|
57
|
+
export const serializeIndex = (index) => Buffer.from(`${JSON.stringify(index, null, '\t')}\n`);
|
|
58
|
+
export function signIndex(bytes, privateKeyPem) {
|
|
59
|
+
const privateKey = createPrivateKey(privateKeyPem);
|
|
60
|
+
return {
|
|
61
|
+
keyId: keyIdOf(rawPublicKey(createPublicKey(privateKey))),
|
|
62
|
+
alg: 'ed25519',
|
|
63
|
+
signature: sign(null, Buffer.from(INDEX_SIGNATURE_CONTEXT + indexDigest(bytes)), privateKey).toString('base64')
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export function verifyIndex(bytes, signature, publicKeyBase64) {
|
|
67
|
+
if (signature.alg !== 'ed25519' || signature.keyId !== keyIdOf(publicKeyBase64))
|
|
68
|
+
return false;
|
|
69
|
+
try {
|
|
70
|
+
return verify(null, Buffer.from(INDEX_SIGNATURE_CONTEXT + indexDigest(bytes)), publicKeyFromRaw(publicKeyBase64), Buffer.from(signature.signature, 'base64'));
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A version entry for a built package: verifies the manifest and, when publisher keys are
|
|
78
|
+
* given, the package signature (a registry must never list a package its publisher did not sign).
|
|
79
|
+
*/
|
|
80
|
+
export async function versionEntry(archive, options) {
|
|
81
|
+
const files = await unpackFiles(archive);
|
|
82
|
+
const rawSignature = files.get(SIGNATURE_FILE);
|
|
83
|
+
files.delete(SIGNATURE_FILE);
|
|
84
|
+
const manifestFile = files.get(MANIFEST_FILE);
|
|
85
|
+
if (!manifestFile)
|
|
86
|
+
throw new Error(`package has no ${MANIFEST_FILE}`);
|
|
87
|
+
const checked = checkManifest(JSON.parse(manifestFile.toString('utf8')));
|
|
88
|
+
if (!checked.ok)
|
|
89
|
+
throw new Error(`invalid manifest: ${checked.errors.join('; ')}`);
|
|
90
|
+
const manifest = checked.manifest;
|
|
91
|
+
if (options.publisherKeys) {
|
|
92
|
+
if (!rawSignature)
|
|
93
|
+
throw new Error('package is not signed');
|
|
94
|
+
const signature = JSON.parse(rawSignature.toString('utf8'));
|
|
95
|
+
if (signature.publisher !== manifest.publisher)
|
|
96
|
+
throw new Error(`signed by ${signature.publisher}, manifest says ${manifest.publisher}`);
|
|
97
|
+
if (!options.publisherKeys.some((key) => verifyFiles(files, signature, key)))
|
|
98
|
+
throw new Error(`signature does not match a key of publisher ${manifest.publisher}`);
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
id: manifest.id,
|
|
102
|
+
publisher: manifest.publisher,
|
|
103
|
+
manifest: manifest,
|
|
104
|
+
entry: {
|
|
105
|
+
version: manifest.version,
|
|
106
|
+
atlasApi: manifest.atlasApi,
|
|
107
|
+
url: options.url,
|
|
108
|
+
sha256: createHash('sha256').update(archive).digest('hex'),
|
|
109
|
+
size: archive.length,
|
|
110
|
+
digest: packageDigest(files),
|
|
111
|
+
scopes: manifest.scopes,
|
|
112
|
+
...(manifest.image ? { image: manifest.image } : {}),
|
|
113
|
+
...(manifest.lifecycle.length ? { lifecycle: manifest.lifecycle } : {}),
|
|
114
|
+
...(manifest.runtime.isolation !== 'shared' ? { isolation: manifest.runtime.isolation } : {}),
|
|
115
|
+
published_at: options.publishedAt ?? new Date().toISOString()
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const readJson = (path) => JSON.parse(readFileSync(path, 'utf8'));
|
|
120
|
+
/** Assemble the index from a registry directory. Serial: seconds since the epoch. */
|
|
121
|
+
export function buildIndex(dir, options = {}) {
|
|
122
|
+
const now = options.now ?? new Date();
|
|
123
|
+
const meta = existsSync(join(dir, 'registry.json'))
|
|
124
|
+
? readJson(join(dir, 'registry.json'))
|
|
125
|
+
: {};
|
|
126
|
+
const name = options.name ?? meta.name;
|
|
127
|
+
if (!name)
|
|
128
|
+
throw new Error('registry name missing: add registry.json { "name": … } or pass --name');
|
|
129
|
+
const publishers = existsSync(join(dir, 'publishers.json'))
|
|
130
|
+
? readJson(join(dir, 'publishers.json'))
|
|
131
|
+
: {};
|
|
132
|
+
const packages = {};
|
|
133
|
+
const root = join(dir, 'packages');
|
|
134
|
+
for (const id of existsSync(root) ? readdirSync(root).sort() : []) {
|
|
135
|
+
const folder = join(root, id);
|
|
136
|
+
if (!statSync(folder).isDirectory())
|
|
137
|
+
continue;
|
|
138
|
+
const info = readJson(join(folder, 'package.json'));
|
|
139
|
+
const versions = readdirSync(folder)
|
|
140
|
+
.filter((file) => file !== 'package.json' && file.endsWith('.json'))
|
|
141
|
+
.map((file) => indexVersionSchema.parse(readJson(join(folder, file))))
|
|
142
|
+
.sort((a, b) => semver.rcompare(a.version, b.version));
|
|
143
|
+
if (!publishers[info.publisher])
|
|
144
|
+
throw new Error(`${id}: publisher ${info.publisher} is not in publishers.json`);
|
|
145
|
+
packages[id] = { ...info, versions };
|
|
146
|
+
}
|
|
147
|
+
const expires = new Date(now.getTime() + (options.expiresInDays ?? 30) * 24 * 60 * 60 * 1000);
|
|
148
|
+
return registryIndexSchema.parse({
|
|
149
|
+
format: INDEX_FORMAT,
|
|
150
|
+
name,
|
|
151
|
+
serial: Math.floor(now.getTime() / 1000),
|
|
152
|
+
generated_at: now.toISOString(),
|
|
153
|
+
expires_at: expires.toISOString(),
|
|
154
|
+
publishers,
|
|
155
|
+
packages
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EACN,OAAO,EACP,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,WAAW,EACX,WAAW,EAEX,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;GAWG;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AAC9B,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBA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Schema } from './manifest.js';
|
|
3
|
+
/** Prints the JSON Schema of atlas-extension.json (editor completion and validation). */
|
|
4
|
+
const schema = z.toJSONSchema(extensionManifestSchema, { io: 'input', unrepresentable: 'any' });
|
|
5
|
+
process.stdout.write(`${JSON.stringify({
|
|
6
|
+
$id: 'https://registry.atlas-cmdb.com/schema/atlas-extension.schema.json',
|
|
7
|
+
title: 'Atlas extension manifest',
|
|
8
|
+
...schema
|
|
9
|
+
}, null, '\t')}\n`);
|
|
10
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAExD,yFAAyF;AACzF,MAAM,MAAM,GAAG,CAAC,CAAC,YAAY,CAAC,uBAAuB,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,CAAC;AAChG,OAAO,CAAC,MAAM,CAAC,KAAK,CACnB,GAAG,IAAI,CAAC,SAAS,CAChB;IACC,GAAG,EAAE,oEAAoE;IACzE,KAAK,EAAE,0BAA0B;IACjC,GAAG,MAAM;CACT,EACD,IAAI,EACJ,IAAI,CACJ,IAAI,CACL,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { type KeyObject } from 'node:crypto';
|
|
2
|
+
import { type IncomingMessage, type ServerResponse } from 'node:http';
|
|
3
|
+
import { AtlasClient } from './client.js';
|
|
4
|
+
export { AtlasApiError, AtlasClient, type AgentJob, type AgentJobInput, type AgentJobStatus, type ExtensionRecord, type Member } from './client.js';
|
|
5
|
+
/**
|
|
6
|
+
* Server part of an Atlas extension: the HTTP contract Atlas calls inside the container.
|
|
7
|
+
*
|
|
8
|
+
* GET /healthz liveness
|
|
9
|
+
* GET /manifest the packaged atlas-extension.json
|
|
10
|
+
* POST /invoke/:fn run a declared function (UI calls, page `load`)
|
|
11
|
+
* POST /hooks/:event lifecycle: install, upgrade, uninstall (per organisation)
|
|
12
|
+
* POST /jobs/:name a background job (manifest `jobs`), on its schedule or "Run now"
|
|
13
|
+
*
|
|
14
|
+
* Every request from Atlas is signed with Atlas' extension key; unsigned, stale or tampered
|
|
15
|
+
* requests are rejected. Each invocation brings a short-lived token for the Atlas API, scoped
|
|
16
|
+
* to the calling organisation, the approved scopes and the user's role.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { createExtension } from '@atlas-cmdb/extension-sdk/server';
|
|
20
|
+
*
|
|
21
|
+
* createExtension({
|
|
22
|
+
* functions: {
|
|
23
|
+
* async subnets(_input, ctx) {
|
|
24
|
+
* return ctx.api.get('assets', { category: String(ctx.settings['subnet-category']) });
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* }).listen();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export type SettingValue = string | number | boolean | string[] | null;
|
|
31
|
+
/** What a function returns to answer with a file instead of JSON (see `ctx.file`). */
|
|
32
|
+
export type FileAnswer = {
|
|
33
|
+
readonly [FILE]: true;
|
|
34
|
+
contentType: string;
|
|
35
|
+
filename: string;
|
|
36
|
+
body: Uint8Array | string;
|
|
37
|
+
};
|
|
38
|
+
declare const FILE: unique symbol;
|
|
39
|
+
export type FunctionContext = {
|
|
40
|
+
organization: {
|
|
41
|
+
id: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* the user the call is on behalf of; absent for instance admins who are not members and for
|
|
45
|
+
* calls without a user (providers, inbound endpoints, jobs, lifecycle hooks)
|
|
46
|
+
*/
|
|
47
|
+
user?: {
|
|
48
|
+
id: string;
|
|
49
|
+
permissions: string[];
|
|
50
|
+
};
|
|
51
|
+
/** the organisation's settings for this extension (`manifest.settings`), secrets included */
|
|
52
|
+
settings: Record<string, SettingValue>;
|
|
53
|
+
/** Atlas API, authenticated with this invocation's token */
|
|
54
|
+
api: AtlasClient;
|
|
55
|
+
/**
|
|
56
|
+
* HTTP(S) to hosts granted with `net:host:` or `net:setting:` scopes (through Atlas' egress
|
|
57
|
+
* gateway). An `authorization` header is passed to the target; nothing else of Atlas is.
|
|
58
|
+
*/
|
|
59
|
+
fetch: (url: string, init?: RequestInit) => Promise<Response>;
|
|
60
|
+
/** public URL of this Atlas, for links into its UI (e.g. `${atlasUrl}/dashboard/<org>/…`) */
|
|
61
|
+
atlasUrl: string;
|
|
62
|
+
/** answer with a file (served by Atlas as a download, or inline for images and PDFs) */
|
|
63
|
+
file: (file: {
|
|
64
|
+
contentType: string;
|
|
65
|
+
filename: string;
|
|
66
|
+
body: Uint8Array | string;
|
|
67
|
+
}) => FileAnswer;
|
|
68
|
+
/** aborted when Atlas stops waiting */
|
|
69
|
+
signal: AbortSignal;
|
|
70
|
+
};
|
|
71
|
+
/** Context of a background job: no user, and `log` lines kept with the run in Atlas. */
|
|
72
|
+
export type JobContext = Omit<FunctionContext, 'user' | 'file'> & {
|
|
73
|
+
/** add a line to the run's log (shown on the extension's Configure page) */
|
|
74
|
+
log: (message: string) => void;
|
|
75
|
+
run: {
|
|
76
|
+
id: string;
|
|
77
|
+
trigger: 'manual' | 'schedule';
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
export type ExtensionJob = (ctx: JobContext) => unknown | Promise<unknown>;
|
|
81
|
+
/** What an inbound endpoint function receives (manifest `inbound`). */
|
|
82
|
+
export type InboundRequest = {
|
|
83
|
+
endpoint: string;
|
|
84
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
85
|
+
/** the path after `/api/v1/organizations/<organization>/extensions/<id>/inbound/<endpoint>/` (may be empty) */
|
|
86
|
+
path: string;
|
|
87
|
+
query: Record<string, string | string[]>;
|
|
88
|
+
/** allow-listed request headers, lower case (never Authorization or cookies) */
|
|
89
|
+
headers: Record<string, string>;
|
|
90
|
+
/** the raw body (verify webhook signatures over this), or null */
|
|
91
|
+
body: string | null;
|
|
92
|
+
};
|
|
93
|
+
/** What an inbound endpoint function answers; a body that is not a string is sent as JSON. */
|
|
94
|
+
export type InboundResponse = {
|
|
95
|
+
status?: number;
|
|
96
|
+
headers?: Record<string, string>;
|
|
97
|
+
body?: unknown;
|
|
98
|
+
};
|
|
99
|
+
export type ExtensionFunction = (input: any, ctx: FunctionContext) => unknown | Promise<unknown>;
|
|
100
|
+
/** Context of a lifecycle hook: like a function call, but for the organisation, without a user. */
|
|
101
|
+
export type LifecycleContext = Omit<FunctionContext, 'user'>;
|
|
102
|
+
/**
|
|
103
|
+
* Lifecycle hooks, declared in the manifest's `lifecycle`. Atlas calls them per organisation:
|
|
104
|
+
* `install` when it first enables the extension, `upgrade` when its data is behind the
|
|
105
|
+
* installed version, `uninstall` before its data is removed. They may be retried, so keep them
|
|
106
|
+
* idempotent; throwing fails the step (a failed install leaves the extension disabled).
|
|
107
|
+
*/
|
|
108
|
+
export type LifecycleHooks = {
|
|
109
|
+
install?: (ctx: LifecycleContext) => unknown | Promise<unknown>;
|
|
110
|
+
upgrade?: (ctx: LifecycleContext, versions: {
|
|
111
|
+
from: string;
|
|
112
|
+
to: string;
|
|
113
|
+
}) => unknown | Promise<unknown>;
|
|
114
|
+
uninstall?: (ctx: LifecycleContext) => unknown | Promise<unknown>;
|
|
115
|
+
};
|
|
116
|
+
export type ExtensionDefinition = {
|
|
117
|
+
functions?: Record<string, ExtensionFunction>;
|
|
118
|
+
lifecycle?: LifecycleHooks;
|
|
119
|
+
/** background jobs, by the names in the manifest's `jobs` */
|
|
120
|
+
jobs?: Record<string, ExtensionJob>;
|
|
121
|
+
/** path of the manifest served at /manifest (default: ./atlas-extension.json) */
|
|
122
|
+
manifestPath?: string;
|
|
123
|
+
};
|
|
124
|
+
/** Throw to answer with a status and message the user may see. */
|
|
125
|
+
export declare class ExtensionError extends Error {
|
|
126
|
+
readonly status: number;
|
|
127
|
+
constructor(status: number, message: string);
|
|
128
|
+
}
|
|
129
|
+
export declare const SIGNATURE_HEADER = "x-atlas-signature";
|
|
130
|
+
/** Header the egress gateway turns back into `Authorization` towards the target. */
|
|
131
|
+
export declare const UPSTREAM_AUTHORIZATION_HEADER = "x-atlas-upstream-authorization";
|
|
132
|
+
export declare const RESULT_HEADER = "x-atlas-result";
|
|
133
|
+
export declare const FILENAME_HEADER = "x-atlas-filename";
|
|
134
|
+
/**
|
|
135
|
+
* Check a webhook's HMAC-SHA256 signature over the raw body, e.g.
|
|
136
|
+
* `verifyHmacSignature(request.body, secret, request.headers['x-zammad-signature'], 'sha256=')`.
|
|
137
|
+
* Compares in constant time; false for a missing or malformed signature.
|
|
138
|
+
*/
|
|
139
|
+
export declare function verifyHmacSignature(body: string | null, secret: string, signature: string | undefined, prefix?: string): boolean;
|
|
140
|
+
/** An inbound answer: `inboundJson(200, { ok: true })`. */
|
|
141
|
+
export declare function inboundJson(status: number, body: unknown, headers?: Record<string, string>): InboundResponse;
|
|
142
|
+
/** Verify `t=<unix>,sig=<base64>` over `<t>.<METHOD>.<path>.<sha256(body)>`. */
|
|
143
|
+
export declare function verifyRequestSignature(header: string | undefined, method: string, path: string, body: string, key: KeyObject, now?: number): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Atlas' public key: `ATLAS_CORE_KEY` (JWK, set by the runner) or fetched once from
|
|
146
|
+
* `ATLAS_CORE_KEYS_URL` (JWKS, e.g. `https://atlas.example/api/v1/extensions/keys` in dev).
|
|
147
|
+
*/
|
|
148
|
+
export declare function loadCoreKey(environment?: NodeJS.ProcessEnv): Promise<KeyObject>;
|
|
149
|
+
export declare function createExtension(definition: ExtensionDefinition): {
|
|
150
|
+
handler: (request: IncomingMessage, response: ServerResponse) => void;
|
|
151
|
+
listen(port?: number): import("http").Server<typeof IncomingMessage, typeof ServerResponse>;
|
|
152
|
+
};
|