@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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ProjectSource V.o.F.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,332 @@
1
- # Temporary Holding Version
1
+ # Atlas extension SDK
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Build, sign and run extensions for [Atlas CMDB](https://atlas-cmdb.com), a solution by
4
+ [ProjectSource V.o.F.](https://projectsource.nl)
5
+
6
+ | Package | What it is |
7
+ | --- | --- |
8
+ | [`@atlas-cmdb/extension-sdk`](https://www.npmjs.com/package/@atlas-cmdb/extension-sdk) | manifest schema, the `atlas-ext` CLI (build, sign, verify, dev) and the server runtime (`/server`) |
9
+ | [`@atlas-cmdb/ui`](https://www.npmjs.com/package/@atlas-cmdb/ui) | the Atlas theme for extension UIs and the types of the `atlas` context |
10
+
11
+ Official extensions live in [atlas-cmdb/extensions](https://github.com/atlas-cmdb/extensions).
12
+
13
+ ## How an extension works
14
+
15
+ An extension is one signed package, `<id>-<version>.atlasx`:
16
+
17
+ ```
18
+ atlas-extension.json manifest: id, version, publisher, scopes, settings, functions, UI contributions
19
+ ui/index.mjs custom elements, bundled with their own Svelte runtime
20
+ assets/… icons, images
21
+ signature.json ed25519 signature of the publisher over everything above
22
+ ```
23
+
24
+ - **UI**: Atlas mounts your custom elements into slots — navigation entries, full pages,
25
+ asset tabs, home-page widgets and the settings page — and gives each one an `atlas`
26
+ context (organisation, user, `atlas.api.call(fn, input)`, navigation, toasts). Your
27
+ elements get the Atlas theme in their shadow root, so plain HTML looks like Atlas.
28
+ - **Server** (optional): an OCI image, pinned by digest in the manifest. Atlas runs it in
29
+ a locked-down container and calls your `functions`. The container has no database and
30
+ no network: it reads and writes Atlas data through the Atlas API with a short-lived
31
+ token scoped to the organisation and the `scopes` an admin approved.
32
+
33
+ ## Quick start
34
+
35
+ Node.js 20 or later.
36
+
37
+ ```sh
38
+ npm i -D @atlas-cmdb/extension-sdk @atlas-cmdb/ui vite svelte @sveltejs/vite-plugin-svelte
39
+ npx atlas-ext keygen acme --out ~/.atlas-keys # once per publisher; keep acme.key secret
40
+ ```
41
+
42
+ `atlas-extension.json`:
43
+
44
+ ```json
45
+ {
46
+ "$schema": "./node_modules/@atlas-cmdb/extension-sdk/atlas-extension.schema.json",
47
+ "id": "hello",
48
+ "name": "Hello",
49
+ "version": "1.0.0",
50
+ "publisher": "acme",
51
+ "atlasApi": "^1.0",
52
+ "contributes": {
53
+ "widgets": [{ "id": "card", "title": "Hello", "element": "hello-card", "sizes": ["1x1"] }]
54
+ }
55
+ }
56
+ ```
57
+
58
+ `ui/index.ts` imports your elements; every `.svelte` file compiles to a custom element:
59
+
60
+ ```svelte
61
+ <!-- ui/Card.svelte -->
62
+ <svelte:options customElement="hello-card" />
63
+ <script lang="ts">
64
+ import type { AtlasContext } from '@atlas-cmdb/ui';
65
+ let { atlas }: { atlas: AtlasContext } = $props();
66
+ </script>
67
+
68
+ <div class="atlas-card">Hello {atlas.user.name}</div>
69
+ ```
70
+
71
+ ```sh
72
+ npx atlas-ext validate
73
+ npx atlas-ext build --key ~/.atlas-keys/acme.key # → dist/hello-1.0.0.atlasx
74
+ npx atlas-ext verify dist/hello-1.0.0.atlasx --pub ~/.atlas-keys/acme.pub
75
+ ```
76
+
77
+ ## Server part
78
+
79
+ Declare `functions` (and `scopes`, `settings`, `storage.collections`) in the manifest and
80
+ implement them with `createExtension`:
81
+
82
+ ```ts
83
+ // server/index.ts
84
+ import { createExtension } from '@atlas-cmdb/extension-sdk/server';
85
+
86
+ createExtension({
87
+ functions: {
88
+ async summary(_input, ctx) {
89
+ const category = ctx.settings['subnet-category'];
90
+ const assets = await ctx.api.get<{ data: unknown[] }>('assets', { category: String(category) });
91
+ await ctx.api.records('runs').put('last', { at: new Date().toISOString() });
92
+ return { count: assets.data.length };
93
+ }
94
+ }
95
+ }).listen();
96
+ ```
97
+
98
+ Each call gets `ctx.organization`, `ctx.user` (the person using the UI), `ctx.settings`,
99
+ `ctx.api` (Atlas API with a token scoped to this organisation, the approved scopes and the
100
+ user's role), `ctx.api.records(collection)` (your own record store), `ctx.api.members()`
101
+ (with `member:read`), `ctx.atlasUrl` (for links into Atlas) and `ctx.fetch` (HTTP(S) to hosts
102
+ granted with `net:host:` scopes). The UI calls it with `atlas.api.call('summary')`; a page's
103
+ `load` function feeds the element's `data`.
104
+
105
+ Settings are `string`, `secret`, `number`, `boolean`, `select`, `category`, `list` (a
106
+ `string[]`), `url` and `credential` (the name of one of the organisation's agent credentials).
107
+ To reach an address the customer enters, such as their own Zammad, declare a `url` setting and
108
+ the scope `net:setting:<name>`: the host and port of that setting's value are allowed through
109
+ the egress gateway for that organisation. An `authorization` header you pass to `ctx.fetch`
110
+ goes to the target; the invocation token never does.
111
+
112
+ A function can answer with a file instead of JSON; Atlas serves it at
113
+ `/api/v1/organizations/<org>/extensions/<id>/functions/<fn>` (`atlas.api.fileUrl(fn, input)` in the UI), inline for
114
+ images, PDFs and plain text, as a download otherwise (25 MB at most):
115
+
116
+ ```ts
117
+ attachment: async ({ id }, ctx) =>
118
+ ctx.file({ contentType: 'application/pdf', filename: 'invoice.pdf', body: await download(id) })
119
+ ```
120
+
121
+ To reach devices inside a customer network, use the organisation's
122
+ [Atlas agents](https://github.com/atlas-cmdb/agent) instead of `ctx.fetch`: request
123
+ `agent:<action>` scopes and run jobs with `ctx.api.agents`. Each agent runs inside that network,
124
+ under a policy the customer controls:
125
+
126
+ ```ts
127
+ const { results } = await ctx.api.agents.run<{ ip: string; online: boolean }>(
128
+ 'net.ping',
129
+ { targets: ['10.20.0.0/24'], count: 2 },
130
+ { tags: ['dc1'] }
131
+ );
132
+ ```
133
+
134
+ `create`, `job`, `results` and `cancel` are there for jobs you follow up yourself. If no online
135
+ agent with those tags supports the action and allows its targets, Atlas refuses the job at
136
+ once (`AtlasApiError`, status 409) and says why. To pass `credential` (the name of an
137
+ organisation credential, or `local:<name>` for one in the agent's config), the extension also
138
+ needs `agent:credentials`.
139
+
140
+ ### Lifecycle hooks
141
+
142
+ Declare `"lifecycle": ["install", "upgrade", "uninstall"]` in the manifest and handle them in
143
+ `createExtension`. Atlas calls them per organisation, with a token for the organisation's
144
+ approved scopes and no user:
145
+
146
+ - `install` when the organisation first enables the extension;
147
+ - `upgrade` when its data is behind the installed version (after an update, or once new
148
+ scopes are approved);
149
+ - `uninstall` before its data is removed.
150
+
151
+ ```ts
152
+ createExtension({
153
+ functions: { … },
154
+ lifecycle: {
155
+ async install(ctx) {
156
+ await ctx.api.records('subnets').put('defaults', { prefix: 24 });
157
+ },
158
+ async upgrade(ctx, { from, to }) {
159
+ if (from < '1.1.0') { /* migrate records */ }
160
+ }
161
+ }
162
+ }).listen();
163
+ ```
164
+
165
+ Hooks get 60 seconds and may be retried, so make them idempotent. A failing `install` leaves the
166
+ extension disabled for that organisation with your error message; a failing `upgrade` is
167
+ retried later.
168
+
169
+ Ship the server as an OCI image (any base, runs as non-root with a read-only filesystem,
170
+ listens on `PORT`, default 8080) and pin it: `atlas-ext build --image ghcr.io/acme/hello@sha256:…`.
171
+
172
+ For local development run `npx atlas-ext dev --atlas http://localhost:5173` and set in Atlas:
173
+ `SECRET_EXTENSION_RUNTIME=dev` and `SECRET_EXTENSION_DEV_ENDPOINTS={"hello":"http://localhost:4100"}`.
174
+
175
+ ### Background jobs
176
+
177
+ Declare jobs in the manifest and implement them under `jobs`. Atlas runs each on its schedule
178
+ (cron, `@hourly`, `@daily` or `@every 30m`; the organisation can change or clear it on the
179
+ extension's Configure page) and on "Run now", one run at a time per organisation, without a
180
+ user. `ctx.log` lines are kept with the run (500 at most) and shown with it:
181
+
182
+ ```json
183
+ "jobs": [{ "name": "scan", "title": "Scan subnets", "schedule": "@every 1h", "timeoutSeconds": 900 }]
184
+ ```
185
+
186
+ ```ts
187
+ createExtension({
188
+ jobs: {
189
+ async scan(ctx) {
190
+ for (const subnet of ctx.settings.subnets as string[]) {
191
+ const { results } = await ctx.api.agents.run('net.ping', { targets: [subnet] });
192
+ ctx.log(`${subnet}: ${results.length} addresses`);
193
+ }
194
+ }
195
+ }
196
+ }).listen();
197
+ ```
198
+
199
+ Throwing fails the run with your message. `timeoutSeconds` is 10–3600 (default 600).
200
+
201
+ ### Data for Atlas pages
202
+
203
+ Core pages can ask an extension for data, without a user (with the organisation's approved
204
+ scopes), so viewers see it too:
205
+
206
+ - `contributes.metrics: { "function": "readings" }`: live readings on an asset page and in
207
+ DCIM. The function gets `{ asset: { id } }` and returns
208
+ `[{ item_id, name, value, unit?, status? }]` (`status`: ok, warning, critical, unknown).
209
+ Atlas polls every 5 seconds and caches answers for 5 seconds.
210
+ - `contributes.calendarSources: [{ "id": "tickets", "label": "Tickets", "function": "events" }]`:
211
+ events in the Calendar. The function gets `{ from, to }` (ISO dates) and returns
212
+ `[{ id, title, start, end?, url?, kind?, details? }]`.
213
+
214
+ Only functions named there can run without a user.
215
+
216
+ ### MCP tools
217
+
218
+ `contributes.mcpTools: [{ "name": "list_tickets", "description": "…", "function": "tickets",
219
+ "input": { "type": "object", "properties": { … } } }]` offers tools to the organisation's MCP
220
+ clients as `<id>_<name>` (dashes become underscores). They run on behalf of the MCP user, like
221
+ UI calls; `input` is the JSON Schema of the arguments (8 KB at most).
222
+
223
+ ### Inbound endpoints
224
+
225
+ External systems can call an extension through Atlas (its container stays unreachable from
226
+ outside). Declare endpoints:
227
+
228
+ ```json
229
+ "inbound": [{ "name": "webhooks", "function": "webhook", "methods": ["POST"] }]
230
+ ```
231
+
232
+ Atlas serves them at `/api/v1/organizations/<organization>/extensions/<id>/inbound/<name>/<path…>`. Callers send an inbound
233
+ token the organisation creates on the extension's Configure page (`Authorization: Bearer
234
+ atlasi_…`). The function runs without a user and gets the method, the rest of the path, the
235
+ query, allow-listed headers and the raw body (1 MB at most); it answers
236
+ `{ status, headers?, body }` (no redirects or cookies):
237
+
238
+ ```ts
239
+ import { createExtension, inboundJson, verifyHmacSignature, type InboundRequest } from '@atlas-cmdb/extension-sdk/server';
240
+
241
+ createExtension({
242
+ functions: {
243
+ webhook(request: InboundRequest, ctx) {
244
+ const secret = String(ctx.settings['webhook-secret'] ?? '');
245
+ if (!verifyHmacSignature(request.body, secret, request.headers['x-hub-signature-256'], 'sha256='))
246
+ return inboundJson(401, { error: 'bad signature' });
247
+ return inboundJson(204, null);
248
+ }
249
+ }
250
+ }).listen();
251
+ ```
252
+
253
+ ### Per-organisation containers
254
+
255
+ By default Atlas runs one container per extension version, shared by every organisation; the
256
+ invocation token tells each call which organisation it is for. A server part that keeps tenant
257
+ data in memory (caches, connections, per-tenant secrets) declares
258
+
259
+ ```json
260
+ "runtime": { "isolation": "per-organization" }
261
+ ```
262
+
263
+ and gets a container of its own for every organisation that enables it. The runner forwards a
264
+ call only when its token is for that organisation, and removes containers that have been idle
265
+ for a while (the next call starts them again), so do not rely on memory surviving. The code is
266
+ the same in both modes.
267
+
268
+ ## Installing
269
+
270
+ Atlas instance admins install packages from a registry (**Settings → Extensions → Store**) or
271
+ upload an `.atlasx`. Uploads must be signed by a publisher key the instance pins
272
+ (`SECRET_EXTENSION_TRUSTED_PUBLISHERS`); registry packages by a key of their publisher listed in
273
+ the registry's signed index (or pinned).
274
+
275
+ ## Registries
276
+
277
+ A registry is a static, signed `index.json` (format in `atlas-index.schema.json`). The official
278
+ one is [registry.atlas-cmdb.com](https://registry.atlas-cmdb.com/index.json); private ones are
279
+ added to an instance with `SECRET_EXTENSION_REGISTRIES` and their own key. A registry is a
280
+ directory you build in CI:
281
+
282
+ ```
283
+ registry.json { "name": "acme" }
284
+ publishers.json { "acme": { "name": "Acme", "keys": ["<base64 ed25519>"] } }
285
+ packages/<id>/package.json { "name", "description", "publisher", "homepage" }
286
+ packages/<id>/<version>.json one entry per published version (never edited)
287
+ ```
288
+
289
+ ```sh
290
+ # add a released version (verifies the publisher signature)
291
+ npx atlas-ext registry entry dist/hello-1.0.0.atlasx --url https://…/hello-1.0.0.atlasx --pub keys/acme.pub --out registry
292
+ # sign and write public/index.json + index.json.sig (expires after 30 days: re-sign on a schedule)
293
+ npx atlas-ext registry build registry --key "$REGISTRY_KEY_FILE" --out public
294
+ npx atlas-ext registry verify public/index.json --pub keys/registry.pub
295
+ ```
296
+
297
+ The signature covers `atlas-index-v1\n<sha256 of index.json>`. Atlas refuses an index with an
298
+ older `serial` than it has seen, and installs nothing from an expired one. Each version entry
299
+ pins the archive's size, sha256 and package digest; Atlas checks them and that the manifest's
300
+ id, version, scopes and image match.
301
+
302
+ ## Rules Atlas enforces
303
+
304
+ - Element tags start with `<id>-`.
305
+ - `image` is pinned by `@sha256:` digest; it is required when the package declares `functions`,
306
+ `jobs` or `lifecycle` hooks.
307
+ - Functions named in `contributes`, `jobs` and `inbound` are declared in `functions`.
308
+ - `scopes` are limited to read scopes (including `member:read`) plus `asset:write`,
309
+ `relation:write`, `note:write`, `net:host:<host>:<port>` for hosts the server part may reach
310
+ through the egress proxy, `net:setting:<name>` for the address in a `url` setting, and
311
+ `agent:<action>` (`net.ping`, `net.tcp_probe`, `net.arp_table`, `dns.lookup`, `snmp.get`,
312
+ `snmp.walk`, `http.request`, `redfish.get`) plus `agent:credentials` for Atlas agent jobs.
313
+ Agent jobs are never available on behalf of a viewer.
314
+ - Packages using jobs, providers, MCP tools, inbound endpoints or the new setting types declare
315
+ `"atlasApi": "^1.1"`.
316
+ - Archive entries live under `ui/` or `assets/`; no links, at most 500 files, 5 MB per file, 20 MB in total.
317
+
318
+ ## Development
319
+
320
+ ```sh
321
+ npm install
322
+ npm run build
323
+ npm test
324
+ ```
325
+
326
+ To release, raise the version in the package's `package.json` and push a tag
327
+ `extension-sdk-v<version>` or `ui-v<version>`. The **publish** workflow builds, tests and
328
+ publishes that package to npm with provenance.
329
+
330
+ ## Licence
331
+
332
+ MIT © [ProjectSource V.o.F.](https://projectsource.nl)