openvibers/openvibe.sdk Commits

0.59.0: openvibe-sdk/space (static-site deploys from apps and CI, projects, sites, settings, Git source and domains) (#70)

OP OpenVibers committed 24 days ago · 4c2874901c · 17 files, +258 −22

Changes

ddiff --git a/CHANGELOG.md b/CHANGELOG.md
iindex 8365c62..10d1072 100644
---- a/CHANGELOG.md
++++ b/CHANGELOG.md
@@@ -3,6 +3,14 @@
All notable changes to `openvibe-sdk`. The package follows semver; while it is `0.x`, a minor
release may change an API and says so here.
++## 0.59.0 (2026-10-20)
++
++- **`openvibe-sdk/space`** (`createSpaceClient`): OpenVibe.Space for apps and CI, public in openvibe-contracts 0.209.0.
++ Deploy a static site as a tar.gz archive or files with their paths (activate at once, or keep a preview), activate,
++ roll back, read a deploy's log; manage projects (members as deployer, maintainer or owner), sites, their serving
++ settings and Git source, and custom domains. An app is a principal of its own in Space and reaches only the
++ projects a person added it to. Uploads and creations are never retried on their own.
++
## 0.58.0 (2026-10-20)
- **`openvibe-sdk/coupons`**, **`openvibe-sdk/deals`** and **`openvibe-sdk/trade`**: what a person does for themselves
ddiff --git a/README.md b/README.md
iindex d506e86..a733b4a 100644
---- a/README.md
++++ b/README.md
@@@ -2,14 +2,14 @@
> Supported browser and server clients for the OpenVibe platform.
--**Status:** alpha, v0.58.0 (roadmap Wave 2; developer apps from Wave 20; Media objects v2 from Wave 4; the Tools platform API; Search, Chat and AI clients from WS-F task 4; per-actor limits from WS-R task 4). Every release is tagged (see [CHANGELOG.md](CHANGELOG.md)). Tested against local stub servers and the built-in mock platform only, never against the live platform. Services pin release tags; each repository's `STATUS.json` names the one it uses.
++**Status:** alpha, v0.59.0 (roadmap Wave 2; developer apps from Wave 20; Media objects v2 from Wave 4; the Tools platform API; Search, Chat and AI clients from WS-F task 4; per-actor limits from WS-R task 4). Every release is tagged (see [CHANGELOG.md](CHANGELOG.md)). Tested against local stub servers and the built-in mock platform only, never against the live platform. Services pin release tags; each repository's `STATUS.json` names the one it uses.
**Plan:** OpenVibe End-to-End Realignment & Implementation Plan, revision 3 (20 Sep 2026), §3.2; roadmap §30.
**License:** MIT ([LICENSE](LICENSE)). This package is a library that apps outside the network embed, so it uses MIT. The OpenVibe services themselves stay AGPL-3.0.
**If a capability is not in the SDK, it is not public.** Apps call services through `openvibe-sdk` and never build internal routes themselves. A route with no SDK wrapper is internal, even when you can reach it, and it can change without notice. To make a capability public, first define it in OpenVibe.Contracts, then wrap it here.
```bash
--npm install https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.58.0
++npm install https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.59.0
```
It has no runtime dependencies. It needs Node ≥ 20, or any browser with `fetch`, Web Crypto and `TextDecoder`. There is no build step. The package is CommonJS with ESM entry points (`import` works). Each subpath has its own `.d.ts`. For a page with no bundler, `browser/openvibe-sdk.mjs` is one self-contained ES module of the browser-safe subpaths (see [Browser without a bundler](#browser-without-a-bundler)). It does not depend on `openvibe-contracts` at runtime: it copies the contract types it uses (from Contracts v0.86.0, a devDependency the tests check them against).
@@@ -196,6 +196,7 @@ Until OpenVibe.Tools serves the gateway facade (Tools S6), point the jobs client
| `openvibe-sdk/coupons` | server | `createCouponsClient(client)`: OpenVibe.Coupons. `merchants.resolve(host)/get(id)/coupons(id)` and `get(cpn_…)` (public data), `submit({code, title, merchant_id \| host \| url, evidence_url, …})` (sensitive; never retried on its own) and `report(cpn_…, {outcome, reason})` for the person. Public capabilities since openvibe-contracts 0.208.0. Audience `openvibe.coupons` |
| `openvibe-sdk/deals` | server | `createDealsClient(client)`: OpenVibe.Deals. Public: `offers.list({sort, page})/get/hotness`, `products.get`, `stores.get`. For the person: `offers.submit` (sensitive), `update`, `observe` (a new price observation), `vote(id, 1 \| -1)` (sensitive), `unvote`, `flag(id, {kind, reason})`, `watches.list/create/remove`. Public capabilities since openvibe-contracts 0.208.0. Audience `openvibe.deals` |
| `openvibe-sdk/trade` | server | `createTradeClient(client)`: OpenVibe.Trade. `instruments.resolve(q)/list/get/observations(symbol, {metric, before, limit})/documents`, `sources()`; the person's `watchlists.list/get/create/rename/add/removeItem/remove` and `alerts.list/deliveries/create/remove`. Public capabilities since openvibe-contracts 0.208.0. Audience `openvibe.trade` |
++| `openvibe-sdk/space` | server | `createSpaceClient(client)`: OpenVibe.Space, static sites for apps and CI. `deploys.uploadArchive(site, tarGz, {activate, preview, root})`, `uploadFiles(site, [{path, data}], …)`, `uploadSourceBuild(site, archive, {ref, commit_sha})`, `list/get/log/activate/rollback(site, {deploy_id})/remove`; `projects.list/create/get/remove/quota/sites/members.set(p, principal, role)/remove`; `sites.create/get/remove`, `sites.config.get/set/reset` (`{ headers, redirects, spa }`), `sites.source.get/set/remove`; `domains.list/add/verify/remove`. An app reaches only the projects a person added it to (deployer, maintainer or owner). Public capabilities since openvibe-contracts 0.209.0. Audience `openvibe.space` |
| `openvibe-sdk/food` | server | `createFoodClient(client)`: OpenVibe.Food. Public: `places({kind, q, lat, lon, radius})` (food banks, pantries, free meals from OpenStreetMap), `foods.list/get` (the food list with store prices). The caller's own: `plans.create({people, days, budget, title})/list/get` (deterministic meal plans with a shopping list and costs), `pantry.get/set(items)` (with "what can I make" matches), `recipes.suggest({ask, people})/list` (AI recipe ideas, 10 a day). Plans and recipe ideas are never retried on their own. Audience `openvibe.food` |
| `openvibe-sdk/actor` | server | `createActorClient(client)`: OpenVibe.Actor. `agents.list()` and `route({task, mode})` (a dry run) are public. `tasks.create({task, mode, budget, agent, idempotency_key, webhooks})` (retried only with an idempotency_key; `webhook_secret` comes back once), `tasks.list/get/cancel`, `tasks.events(id, {lastEventId})` (SSE until the task ends). A person's own agents: `me.agents.list/create/get/update/remove/run/runs` and `me.agents.memory.list/add/update/remove/clear`. Audience `openvibe.actor` |
| `openvibe-sdk/run` | server | `createRunClient(client, {project?})`: OpenVibe.Run, jobs on worker nodes. `jobs.submit({class, artifact, args, limits, …})` (Idempotency-Key, so retried safely) → `{ created, job }`, `jobs.list({state, limit, cursor})`, `jobs.get/cancel`, `jobs.events(id, {lastEventId})` (SSE until `end`), `jobs.streamTicket(id)` (a one-use URL for a browser's EventSource); `forProject(prj_…)` sends X-OV-Project. Audience `openvibe.run` |
@@@ -482,7 +483,7 @@ Install the drivers the service uses: `pg` and `iovalkey` (production), `@electr
- **Media:** the v1 files API, the object API v2 (`createObjectsClient`) and the public URL helpers are wrapped. Retention holds on v2 objects are not (app keys only). VOD, clip, thumbnail and admin-storage routes are not wrapped because apps reach them only through Live and Media's own servers. Media's own paste API is not wrapped because pastes moved to Community (ADR-011). The mock platform (`openvibe-sdk/testing`) models Media's v1 files only, not v2 objects.
- **Media from the browser:** Media refuses user JWTs on `/api/v1/:app/files`, so a browser uploads through its own app server. That server holds the app key and names the user with `actingUserId`.
- **Network coins, notifications and legacy-map writes** are internal service-to-service routes with no public capability, so they are not wrapped. Staff-only paste routes are also internal: admin stats, bulk, censor and the AI pass.
--- **Billing and Games** from the original charter come when those services publish their capabilities in Contracts (Live has its module since v0.52.0). Products whose capabilities are all first-party (News, Space, Watch, Codes, Host and others) have no module yet: there is nothing an outside app may call. Blog opened its posts to apps (openvibe-contracts 0.206.0, `openvibe-sdk/blog`), then Reviews and the Wiki their reads (0.207.0), then Coupons, Deals and Trade what a person does for themselves (0.208.0). News' published stories need no capability, but its editorial reads stay first-party. Chat is wrapped over REST as the token's person (`openvibe-sdk/chat`, v0.11.0), but it has no app principal (`chat.message.send` is `first-party`) and the mock platform has no Chat.
++- **Billing and Games** from the original charter come when those services publish their capabilities in Contracts (Live has its module since v0.52.0). Products whose capabilities are all first-party (News, Watch, Codes, Host and others) have no module yet: there is nothing an outside app may call. Blog opened its posts to apps (openvibe-contracts 0.206.0, `openvibe-sdk/blog`), then Reviews and the Wiki their reads (0.207.0), then Coupons, Deals and Trade what a person does for themselves (0.208.0), then Space its sites (0.209.0). News' published stories need no capability, but its editorial reads stay first-party. Chat is wrapped over REST as the token's person (`openvibe-sdk/chat`, v0.11.0), but it has no app principal (`chat.message.send` is `first-party`) and the mock platform has no Chat.
- **Tools** are not wrapped one by one: `openvibe-sdk/tools` runs any tool with `api: true` by id, and its descriptor (`tools.get(id)`) gives the input schema, files and limits. `openvibe-sdk/jobs` still submits any job `type` directly. The YouTube downloader is page-only (`api: false`), so it is not in the SDK.
- **Realtime over WebSocket and presence** don't exist in Events yet (ADR-005). SSE is the only transport.
- **Bot:** the REST robots, public kits/profiles and pairing routes are wrapped (`openvibe-sdk/bot`). The operator WebSocket (`/control`, Realtime frames `bot.command@1`), device bootstrap (`POST /devices/bind`, a Network node token) and the internal Run→Bot job dispatch (`bot.job.dispatch`, service-to-service and never delegated to people or apps) are not.
ddiff --git a/STATUS.json b/STATUS.json
iindex b52fa90..f8431f4 100644
---- a/STATUS.json
++++ b/STATUS.json
@@@ -3,7 +3,7 @@
"stage": "alpha",
"code": true,
"wave": "W2",
-- "version": "0.58.0",
++ "version": "0.59.0",
"plan": "OpenVibe End-to-End Realignment & Implementation Plan, revision 3 (20 Sep 2026), §3.2; roadmap §30",
"deployed": false,
"deployment": "none: a package released as git tags; services and apps pin a tag",
ddiff --git a/browser/openvibe-sdk.mjs b/browser/openvibe-sdk.mjs
iindex d9a5766..a5e296f 100644
---- a/browser/openvibe-sdk.mjs
++++ b/browser/openvibe-sdk.mjs
@@@ -1,4 +1,4 @@
--// Generated by scripts/browser-bundle.js from browser.js (openvibe-sdk 0.58.0, MIT). Do not edit.
++// Generated by scripts/browser-bundle.js from browser.js (openvibe-sdk 0.59.0, MIT). Do not edit.
// One self-contained ES module: core at the top level plus the browser-safe subpaths as namespaces
// (auth, registry, modules, realtime, media, community, bot, search, chat, ai, jobs, tools, projects, geo). No server-only code: no service tokens, JWT verification, events, identity.
/* eslint-disable */
@@@ -42,7 +42,7 @@ const { paginate, offsetPager } = __load(7);
const semver = __load(6);
/** The package version (test/version.test.js keeps it equal to package.json). */
--const SDK_VERSION = '0.58.0';
++const SDK_VERSION = '0.59.0';
module.exports = {
createClient,
ddiff --git a/esm/index.mjs b/esm/index.mjs
iindex 518f200..c0a7726 100644
---- a/esm/index.mjs
++++ b/esm/index.mjs
@@@ -9,8 +9,8 @@ export const {
community, bot, search, chat, ai, jobs,
tools, projects, resources, vip, quest, live,
inventory, tips, blog, reviews, wiki, coupons,
-- deals, trade, food, actor, run, video,
-- work, zone, play, download, openre, geo,
-- usage, commerce, telemetry,
++ deals, trade, space, food, actor, run,
++ video, work, zone, play, download, openre,
++ geo, usage, commerce, telemetry,
} = cjs;
export default cjs;
ddiff --git a/esm/space.mjs b/esm/space.mjs
nnew file mode 100644
iindex 0000000..c9bd7b4
---- /dev/null
++++ b/esm/space.mjs
@@@ -0,0 +1,7 @@
++// Generated by scripts/esm.js from src/space.js. Do not edit.
++import cjs from '../src/space.js';
++
++export const {
++ createSpaceClient,
++} = cjs;
++export default cjs;
ddiff --git a/index.js b/index.js
iindex fcf64cb..39668e3 100644
---- a/index.js
++++ b/index.js
@@@ -35,6 +35,7 @@ module.exports = {
coupons: require('./src/coupons'),
deals: require('./src/deals'),
trade: require('./src/trade'),
++ space: require('./src/space'),
food: require('./src/food'),
actor: require('./src/actor'),
run: require('./src/run'),
ddiff --git a/package-lock.json b/package-lock.json
iindex 90246dc..c30f8fe 100644
---- a/package-lock.json
++++ b/package-lock.json
@@@ -1,12 +1,12 @@
{
"name": "openvibe-sdk",
-- "version": "0.58.0",
++ "version": "0.59.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "openvibe-sdk",
-- "version": "0.58.0",
++ "version": "0.59.0",
"license": "MIT",
"bin": {
"openvibe-download": "bin/openvibe-download.js"
ddiff --git a/package.json b/package.json
iindex 1343df7..f5d9e41 100644
---- a/package.json
++++ b/package.json
@@@ -1,6 +1,6 @@
{
"name": "openvibe-sdk",
-- "version": "0.58.0",
++ "version": "0.59.0",
"description": "Supported browser and server clients for the OpenVibe platform: auth (incl. developer apps), registry discovery, identity, user modules, events, realtime, media, community, Bot robots, search, chat, AI runs, Tools (registry, run API and jobs), VIP memberships and developer projects, the async PostgreSQL data layer (db) and the Valkey cache, limits store, queue and pub/sub, with deadlines, safe retries, problem errors and trace propagation.",
"main": "index.js",
"types": "types/index.d.ts",
@@@ -344,6 +344,12 @@
"import": "./esm/trade.mjs",
"default": "./src/trade.js"
},
++ "./space": {
++ "types": "./types/space.d.ts",
++ "browser": null,
++ "import": "./esm/space.mjs",
++ "default": "./src/space.js"
++ },
"./vip": {
"types": "./types/vip.d.ts",
"browser": null,
ddiff --git a/scripts/esm.js b/scripts/esm.js
iindex 73a9bdf..77a281f 100644
---- a/scripts/esm.js
++++ b/scripts/esm.js
@@@ -64,6 +64,7 @@ const ENTRIES = {
'coupons.mjs': '../src/coupons.js',
'deals.mjs': '../src/deals.js',
'trade.mjs': '../src/trade.js',
++ 'space.mjs': '../src/space.js',
'food.mjs': '../src/food.js',
'actor.mjs': '../src/actor.js',
'run.mjs': '../src/run.js',
ddiff --git a/src/core/index.js b/src/core/index.js
iindex 42ad7e0..4eec5fb 100644
---- a/src/core/index.js
++++ b/src/core/index.js
@@@ -8,7 +8,7 @@ const { paginate, offsetPager } = require('./paginate');
const semver = require('./semver');
/** The package version (test/version.test.js keeps it equal to package.json). */
--const SDK_VERSION = '0.58.0';
++const SDK_VERSION = '0.59.0';
module.exports = {
createClient,
ddiff --git a/src/space.js b/src/space.js
nnew file mode 100644
iindex 0000000..2db55a9
---- /dev/null
++++ b/src/space.js
@@@ -0,0 +1,119 @@
++'use strict';
++/**
++ * openvibe-sdk/space — OpenVibe.Space for apps and CI: deploy a static site (a tar/tar.gz archive or files with their
++ * paths), activate or roll back a deploy, and manage a project's sites, their serving settings, Git source and custom
++ * domains. Routes at https://openvibe.space/api/v1; tokens for audience openvibe.space.
++ *
++ * const space = createSpaceClient(createClient({ tokenProvider })); // e.g. an app's client-credentials token
++ * const { deploy } = await space.deploys.uploadArchive(siteId, fs.readFileSync('site.tar.gz'), { activate: true });
++ * await space.deploys.uploadFiles(siteId, [{ path: 'index.html', data: html }, { path: 'css/site.css', data: css }]);
++ * await space.sites.config.set(siteId, { spa: true, headers: { 'X-Frame-Options': 'DENY' } });
++ * await space.deploys.rollback(siteId, { deploy_id: previousDeployId });
++ *
++ * Capabilities (public since openvibe-contracts 0.209.0): space.deploy.create (sensitive), space.site.config,
++ * space.site.manage (sensitive) and space.domain.manage (sensitive). Space also judges each call by the acting
++ * principal's project role: an app is a principal of its own and reaches only the projects a person added it to
++ * (deployer: deploys; maintainer: + sites, settings, domains; owner: + members). Uploads and creations make a new
++ * deploy, site, project or domain each time and are never retried on their own; activating, rolling back, settings
++ * and deletes are.
++ * Errors are OpenVibeError: project.not_found (also for a project the principal is not in), site.not_found,
++ * deploy.not_found, environment.sandbox_token, quota.exceeded, …
++ */
++const enc = encodeURIComponent;
++
++function createSpaceClient(client, { baseUrl } = {}) {
++ if (!client || typeof client.json !== 'function') throw new TypeError('createSpaceClient: pass an openvibe-sdk/core client');
++ const at = { service: 'space', baseUrl, audience: 'openvibe.space' };
++ const call = (opts) => client.json({ ...at, ...opts });
++ const once = (opts) => call({ ...opts, idempotencyKey: false });
++ const id = (what, v) => {
++ if (!v || typeof v !== 'string') throw new TypeError(`space: a ${what} id`);
++ return enc(v);
++ };
++ const project = (p, rest = '') => `/api/v1/projects/${id('project', p)}${rest}`;
++ const site = (s, rest = '') => `/api/v1/sites/${id('site', s)}${rest}`;
++ const deploy = (d, rest = '') => `/api/v1/deploys/${id('deploy', d)}${rest}`;
++ const flag = (v) => (v ? '1' : undefined);
++
++ /** A tar or tar.gz archive as the request body. */
++ const archiveBody = (archive, gzip) => {
++ if (archive == null) throw new TypeError('space: the archive (Buffer, Uint8Array, Blob or stream)');
++ return { body: archive, headers: { 'Content-Type': gzip ? 'application/gzip' : 'application/x-tar' } };
++ };
++
++ return {
++ projects: {
++ list: ({ signal } = {}) => call({ path: '/api/v1/projects', signal }),
++ /** A project owned by the person (an app cannot own one). */
++ create: (fields, { signal } = {}) => once({ method: 'POST', path: '/api/v1/projects', json: fields || {}, signal }),
++ get: (p, { signal } = {}) => call({ path: project(p), signal }),
++ remove: (p, { signal } = {}) => call({ method: 'DELETE', path: project(p), signal }),
++ quota: (p, { signal } = {}) => call({ path: project(p, '/quota'), signal }),
++ sites: (p, { signal } = {}) => call({ path: project(p, '/sites'), signal }),
++ members: {
++ /** Add or change a member: a usr_ person or an app:app_… principal, as deployer, maintainer or owner. */
++ set: (p, principal, role, { signal } = {}) => {
++ if (!['deployer', 'maintainer', 'owner'].includes(role)) throw new TypeError('space.projects.members.set: role is deployer, maintainer or owner');
++ return call({ method: 'PUT', path: project(p, `/members/${enc(String(principal))}`), json: { role }, signal });
++ },
++ remove: (p, principal, { signal } = {}) => call({ method: 'DELETE', path: project(p, `/members/${enc(String(principal))}`), signal }),
++ },
++ },
++ sites: {
++ create: (p, fields, { signal } = {}) => once({ method: 'POST', path: project(p, '/sites'), json: fields || {}, signal }),
++ get: (s, { signal } = {}) => call({ path: site(s), signal }),
++ remove: (s, { signal } = {}) => call({ method: 'DELETE', path: site(s), signal }),
++ /** Serving settings { headers: { Name: value }, redirects: [...], spa: boolean }; reserved headers are refused. */
++ config: {
++ get: (s, { signal } = {}) => call({ path: site(s, '/config'), signal }),
++ set: (s, config, { signal } = {}) => call({ method: 'PUT', path: site(s, '/config'), json: config, signal }),
++ reset: (s, { signal } = {}) => call({ method: 'DELETE', path: site(s, '/config'), signal }),
++ },
++ /** The Git repository and branch CI deploys come from. */
++ source: {
++ get: (s, { signal } = {}) => call({ path: site(s, '/source'), signal }),
++ set: (s, source, { signal } = {}) => call({ method: 'PUT', path: site(s, '/source'), json: source, signal }),
++ remove: (s, { signal } = {}) => call({ method: 'DELETE', path: site(s, '/source'), signal }),
++ },
++ },
++ deploys: {
++ list: (s, { signal } = {}) => call({ path: site(s, '/deploys'), signal }),
++ get: (d, { signal } = {}) => call({ path: deploy(d), signal }),
++ log: (d, { signal } = {}) => call({ path: deploy(d, '/log'), signal }),
++ /** Upload a tar.gz (gzip: false for a plain tar) → { deploy, activated, preview, url }. */
++ uploadArchive: (s, archive, { activate, preview, root, gzip = true, signal } = {}) => once({
++ method: 'POST', path: site(s, '/deploys'), query: { activate: flag(activate), preview: flag(preview), root }, ...archiveBody(archive, gzip), signal,
++ }),
++ /** Upload files, each { path: 'css/site.css', data, type? } (the path in the site is the part's filename). */
++ uploadFiles: (s, files, { activate, preview, root, signal } = {}) => {
++ if (!Array.isArray(files) || !files.length) throw new TypeError('space.deploys.uploadFiles: at least one { path, data }');
++ const form = new FormData();
++ for (const f of files) {
++ if (!f || typeof f.path !== 'string' || !f.path || f.data == null) throw new TypeError('space.deploys.uploadFiles: each file is { path, data, type? }');
++ const blob = typeof Blob !== 'undefined' && f.data instanceof Blob ? f.data : new Blob([f.data], { type: f.type || 'application/octet-stream' });
++ form.append('files', blob, f.path);
++ }
++ return once({ method: 'POST', path: site(s, '/deploys'), query: { activate: flag(activate), preview: flag(preview), root }, form, signal });
++ },
++ /** A CI build for a site with a Git source (always a preview): ref and the full commit_sha. */
++ uploadSourceBuild: (s, archive, { ref, commit_sha: sha, gzip = true, signal } = {}) => once({
++ method: 'POST', path: site(s, '/source/deploys'), query: { ref, commit_sha: sha }, ...archiveBody(archive, gzip), signal,
++ }),
++ /** Make it the live deploy (one atomic switch); expected_active guards a race. */
++ activate: (d, { expected_active: expected, signal } = {}) => call({ method: 'POST', path: deploy(d, '/activate'), json: expected === undefined ? {} : { expected_active: expected }, idempotent: true, signal }),
++ /** Back to an earlier ready deploy (deploy_id, else the previous one). */
++ rollback: (s, { deploy_id: to, expected_active: expected, signal } = {}) => call({ method: 'POST', path: site(s, '/rollback'), json: { deploy_id: to, expected_active: expected }, idempotent: true, signal }),
++ /** Delete a deploy that is not active (maintainer). */
++ remove: (d, { signal } = {}) => call({ method: 'DELETE', path: deploy(d), signal }),
++ },
++ domains: {
++ list: (s, { signal } = {}) => call({ path: site(s, '/domains'), signal }),
++ /** Add a custom domain (never an OpenVibe one); it is served once its DNS TXT record verifies. */
++ add: (s, fields, { signal } = {}) => once({ method: 'POST', path: site(s, '/domains'), json: fields, signal }),
++ verify: (dom, { signal } = {}) => call({ method: 'POST', path: `/api/v1/domains/${id('domain', dom)}/verify`, json: {}, idempotent: true, signal }),
++ remove: (dom, { signal } = {}) => call({ method: 'DELETE', path: `/api/v1/domains/${id('domain', dom)}`, signal }),
++ },
++ };
++}
++
++module.exports = { createSpaceClient };
ddiff --git a/test/browser-entries.test.js b/test/browser-entries.test.js
iindex a49d250..c0ef078 100644
---- a/test/browser-entries.test.js
++++ b/test/browser-entries.test.js
@@@ -76,7 +76,7 @@ run([
for (const [re, why] of FORBIDDEN) if (re.test(src)) problems.push(`${path.relative(ROOT, file)}: ${why}`);
}
assert.deepEqual(problems, []);
-- assert.deepEqual(blocked.sort(), ['./account-data', './actor', './blog', './cache', './commerce', './cost', './coupons', './db', './deals', './delivery', './download', './events', './food', './govern', './identity', './inventory', './limits', './live', './node', './notifications', './openre', './placement', './play', './pubsub', './quest', './queue', './resources', './reviews', './run', './runtime', './service', './sso', './storage', './telemetry', './testing', './tips', './trade', './usage', './valkey', './video', './vip', './wiki', './work', './zone']);
++ assert.deepEqual(blocked.sort(), ['./account-data', './actor', './blog', './cache', './commerce', './cost', './coupons', './db', './deals', './delivery', './download', './events', './food', './govern', './identity', './inventory', './limits', './live', './node', './notifications', './openre', './placement', './play', './pubsub', './quest', './queue', './resources', './reviews', './run', './runtime', './service', './space', './sso', './storage', './telemetry', './testing', './tips', './trade', './usage', './valkey', './video', './vip', './wiki', './work', './zone']);
const rel = [...scanned].map((f) => path.relative(ROOT, f));
for (const must of ['browser.js', 'src/core/client.js', 'src/auth/browser.js', 'src/realtime.js', 'src/media.js', 'src/community.js', 'src/bot.js', 'src/modules.js', 'src/registry.js', 'src/jobs.js', 'src/tools.js', 'src/core/form.js', 'src/projects.js', 'browser/openvibe-sdk.mjs']) {
assert.ok(rel.includes(must), `${must} is scanned`);
ddiff --git a/test/pack.test.js b/test/pack.test.js
iindex 7d4abec..0f16d6d 100644
---- a/test/pack.test.js
++++ b/test/pack.test.js
@@@ -66,7 +66,7 @@ run([
})().catch((err) => { console.error(err); process.exit(1); });`;
const res = execFileSync(process.execPath, ['-e', script], { cwd: app, encoding: 'utf8' });
assert.match(res, new RegExp(`consumer ok: ${subpaths.length} subpaths \\+ the browser bundle`));
-- assert.equal(subpaths.length, 62);
++ assert.equal(subpaths.length, 63);
assert.ok(!fs.existsSync(path.join(app, 'node_modules/openvibe-contracts')), 'the optional peer is not installed');
} finally {
fs.rmSync(tmp, { recursive: true, force: true });
ddiff --git a/test/product-modules.test.js b/test/product-modules.test.js
iindex 90d9107..64db398 100644
---- a/test/product-modules.test.js
++++ b/test/product-modules.test.js
@@@ -1,5 +1,5 @@
'use strict';
--// openvibe-sdk/food, /actor, /run, /video, /work, /zone, /blog, /reviews, /wiki, /coupons, /deals and /trade through a real core client against one local stub: every
++// openvibe-sdk/food, /actor, /run, /video, /work, /zone, /blog, /reviews, /wiki, /coupons, /deals, /trade and /space through a real core client against one local stub: every
// route and method, the token audience, which writes are retried (keyed or idempotent) and which never are, the SSE
// followers (Actor's task events, Run's job stream), and the id checks done before any call.
const assert = require('assert');
@@@ -17,6 +17,7 @@ const { createWikiClient } = require('../src/wiki');
const { createCouponsClient } = require('../src/coupons');
const { createDealsClient } = require('../src/deals');
const { createTradeClient } = require('../src/trade');
++const { createSpaceClient } = require('../src/space');
const ULID = '01JAB2C3D4E5F6G7H8J9K0MNPQ';
const ids = { plan: `pln_${ULID}`, task: `tsk_${ULID}`, agent: `agt_${ULID}`, mem: `mem_${ULID}`, job: `job_${ULID}`, playlist: `vpl_${ULID}`, app: `wap_${ULID}`, project: `prj_${ULID}`, zone: `zon_${ULID}`, post: `pst_${ULID}`, page: `pg_${ULID}`, coupon: `cpn_${ULID}` };
@@@ -30,7 +31,8 @@ const ids = { plan: `pln_${ULID}`, task: `tsk_${ULID}`, agent: `agt_${ULID}`, me
req.on('end', () => {
const svc = req.url.split('/')[1];
const url = req.url.slice(svc.length + 1);
-- seen.push({ svc, method: req.method, url, idem: req.headers['idempotency-key'] || null, project: req.headers['x-ov-project'] || null, lastEvent: req.headers['last-event-id'] || null, auth: req.headers.authorization || null, body: body ? JSON.parse(body) : null });
++ const type = String(req.headers['content-type'] || '');
++ seen.push({ svc, method: req.method, url, type, raw: body, idem: req.headers['idempotency-key'] || null, project: req.headers['x-ov-project'] || null, lastEvent: req.headers['last-event-id'] || null, auth: req.headers.authorization || null, body: body && type.startsWith('application/json') ? JSON.parse(body) : null });
const json = (status, obj) => { res.writeHead(status, { 'Content-Type': 'application/json' }); res.end(JSON.stringify(obj)); };
const key = `${req.method} ${req.url} ${body}`; // one 503 per distinct request
attempts[key] = (attempts[key] || 0) + 1;
@@@ -50,7 +52,7 @@ const ids = { plan: `pln_${ULID}`, task: `tsk_${ULID}`, agent: `agt_${ULID}`, me
const base = `http://127.0.0.1:${server.address().port}`;
const audiences = [];
const client = createClient({
-- baseUrls: { food: `${base}/food`, actor: `${base}/actor`, run: `${base}/run`, 'media-hub': `${base}/video`, work: `${base}/work`, zone: `${base}/zone`, blog: `${base}/blog`, reviews: `${base}/reviews`, wiki: `${base}/wiki`, coupons: `${base}/coupons`, deals: `${base}/deals`, trade: `${base}/trade` },
++ baseUrls: { food: `${base}/food`, actor: `${base}/actor`, run: `${base}/run`, 'media-hub': `${base}/video`, work: `${base}/work`, zone: `${base}/zone`, blog: `${base}/blog`, reviews: `${base}/reviews`, wiki: `${base}/wiki`, coupons: `${base}/coupons`, deals: `${base}/deals`, trade: `${base}/trade`, space: `${base}/space` },
getToken: ({ audience }) => { audiences.push(audience); return `tok-${audience}`; },
retries: 2, retryDelayMs: 1, maxRetryDelayMs: 2,
});
@@@ -375,13 +377,56 @@ const ids = { plan: `pln_${ULID}`, task: `tsk_${ULID}`, agent: `agt_${ULID}`, me
assert.throws(() => trade.alerts.create({ symbol: 'AAPL', kind: 'rumour' }), /kind/);
assert.throws(() => trade.watchlists.create({}), /name/);
++ // ── Space ─────────────────────────────────────────────
++ const space = createSpaceClient(client);
++ mark = since();
++ await space.projects.list();
++ await busyOnce(() => space.projects.create({ name: 'my-site' }));
++ await space.projects.members.set('prj_1', 'app:app_9', 'deployer');
++ await space.projects.sites('prj_1');
++ await busyOnce(() => space.sites.create('prj_1', { name: 'docs' }));
++ await space.sites.config.set('site_1', { spa: true, headers: { 'X-Frame-Options': 'DENY' } });
++ await busyOnce(() => space.deploys.uploadArchive('site_1', Buffer.from('fake tar.gz bytes'), { activate: true }));
++ await busyOnce(() => space.deploys.uploadFiles('site_1', [{ path: 'index.html', data: '<h1>Hi</h1>', type: 'text/html' }, { path: 'css/site.css', data: 'h1{}' }], { preview: true }));
++ await busyOnce(() => space.deploys.uploadSourceBuild('site_1', Buffer.from('tar'), { ref: 'main', commit_sha: 'a'.repeat(40), gzip: false }));
++ await space.deploys.activate('dep_1', { expected_active: null });
++ await space.deploys.rollback('site_1', { deploy_id: 'dep_0' });
++ await space.deploys.log('dep_1');
++ await busyOnce(() => space.domains.add('site_1', { hostname: 'docs.example.com' }));
++ await space.domains.verify('dom_1');
++ await space.domains.remove('dom_1');
++ const sp = mark();
++ assert.deepStrictEqual(sp.map((x) => `${x.method} ${x.url}`), [
++ 'GET /api/v1/projects', 'POST /api/v1/projects', 'PUT /api/v1/projects/prj_1/members/app%3Aapp_9', 'PUT /api/v1/projects/prj_1/members/app%3Aapp_9',
++ 'GET /api/v1/projects/prj_1/sites', 'POST /api/v1/projects/prj_1/sites', 'PUT /api/v1/sites/site_1/config', 'PUT /api/v1/sites/site_1/config',
++ 'POST /api/v1/sites/site_1/deploys?activate=1', 'POST /api/v1/sites/site_1/deploys?preview=1',
++ `POST /api/v1/sites/site_1/source/deploys?ref=main&commit_sha=${'a'.repeat(40)}`, 'POST /api/v1/deploys/dep_1/activate',
++ 'POST /api/v1/deploys/dep_1/activate', 'POST /api/v1/sites/site_1/rollback', 'POST /api/v1/sites/site_1/rollback', 'GET /api/v1/deploys/dep_1/log',
++ 'POST /api/v1/sites/site_1/domains', 'POST /api/v1/domains/dom_1/verify', 'POST /api/v1/domains/dom_1/verify', 'DELETE /api/v1/domains/dom_1',
++ 'DELETE /api/v1/domains/dom_1',
++ ]);
++ // Uploads and creations surface the 503 (a second try would be a second deploy); settings, activate, rollback and verify are retried.
++ assert.deepStrictEqual(sp[3].body, { role: 'deployer' });
++ assert.deepStrictEqual(sp[7].body, { spa: true, headers: { 'X-Frame-Options': 'DENY' } });
++ assert.strictEqual(sp[8].type, 'application/gzip', 'an archive is the body, gzip by default');
++ assert.strictEqual(sp[8].raw, 'fake tar.gz bytes');
++ assert.match(sp[9].type, /^multipart\/form-data; boundary=/);
++ assert.match(sp[9].raw, /name="files"; filename="css\/site\.css"/, "each file's path is its part's filename");
++ assert.match(sp[9].raw, /<h1>Hi<\/h1>/);
++ assert.strictEqual(sp[10].type, 'application/x-tar');
++ assert.deepStrictEqual(sp[12].body, { expected_active: null });
++ assert.deepStrictEqual(sp[14].body, { deploy_id: 'dep_0' });
++ assert.throws(() => space.projects.members.set('prj_1', 'usr_1', 'admin'), /deployer, maintainer or owner/);
++ assert.throws(() => space.deploys.uploadFiles('site_1', []), /at least one/);
++ assert.throws(() => space.deploys.uploadArchive('site_1'), /archive/);
++
// Each product's token is for its own audience (Video's is the media hub's, openvibe.download).
-- assert.deepStrictEqual([...new Set(audiences)].sort(), ['openvibe.actor', 'openvibe.blog', 'openvibe.coupons', 'openvibe.deals', 'openvibe.download', 'openvibe.food', 'openvibe.reviews', 'openvibe.run', 'openvibe.trade', 'openvibe.wiki', 'openvibe.work', 'openvibe.zone']);
-- assert.ok(seen.every((x) => x.auth === `Bearer tok-${{ food: 'openvibe.food', actor: 'openvibe.actor', run: 'openvibe.run', video: 'openvibe.download', work: 'openvibe.work', zone: 'openvibe.zone', blog: 'openvibe.blog', reviews: 'openvibe.reviews', wiki: 'openvibe.wiki', coupons: 'openvibe.coupons', deals: 'openvibe.deals', trade: 'openvibe.trade' }[x.svc]}`));
++ assert.deepStrictEqual([...new Set(audiences)].sort(), ['openvibe.actor', 'openvibe.blog', 'openvibe.coupons', 'openvibe.deals', 'openvibe.download', 'openvibe.food', 'openvibe.reviews', 'openvibe.run', 'openvibe.space', 'openvibe.trade', 'openvibe.wiki', 'openvibe.work', 'openvibe.zone']);
++ assert.ok(seen.every((x) => x.auth === `Bearer tok-${{ food: 'openvibe.food', actor: 'openvibe.actor', run: 'openvibe.run', video: 'openvibe.download', work: 'openvibe.work', zone: 'openvibe.zone', blog: 'openvibe.blog', reviews: 'openvibe.reviews', wiki: 'openvibe.wiki', coupons: 'openvibe.coupons', deals: 'openvibe.deals', trade: 'openvibe.trade', space: 'openvibe.space' }[x.svc]}`));
// Each client needs a core client.
-- for (const make of [createFoodClient, createActorClient, createRunClient, createVideoClient, createWorkClient, createZoneClient, createBlogClient, createReviewsClient, createWikiClient, createCouponsClient, createDealsClient, createTradeClient]) assert.throws(() => make({}), /core client/);
-- console.log('product modules (food, actor, run, video, work, zone, blog, reviews, wiki, coupons, deals, trade): all checks passed');
++ for (const make of [createFoodClient, createActorClient, createRunClient, createVideoClient, createWorkClient, createZoneClient, createBlogClient, createReviewsClient, createWikiClient, createCouponsClient, createDealsClient, createTradeClient, createSpaceClient]) assert.throws(() => make({}), /core client/);
++ console.log('product modules (food, actor, run, video, work, zone, blog, reviews, wiki, coupons, deals, trade, space): all checks passed');
} finally {
server.close();
}
ddiff --git a/types/index.d.ts b/types/index.d.ts
iindex 752b391..f4c8e9e 100644
---- a/types/index.d.ts
++++ b/types/index.d.ts
@@@ -26,6 +26,7 @@ export * as wiki from './wiki';
export * as coupons from './coupons';
export * as deals from './deals';
export * as trade from './trade';
++export * as space from './space';
export * as food from './food';
export * as actor from './actor';
export * as run from './run';
ddiff --git a/types/space.d.ts b/types/space.d.ts
nnew file mode 100644
iindex 0000000..d13c51d
---- /dev/null
++++ b/types/space.d.ts
@@@ -0,0 +1,47 @@
++/** openvibe-sdk/space: OpenVibe.Space — static-site deploys, projects, sites, serving settings, Git source and domains. */
++type Opts = { signal?: AbortSignal };
++type SpaceJson = Record<string, any>;
++export type SpaceRole = 'deployer' | 'maintainer' | 'owner';
++export type ArchiveBody = Uint8Array | ArrayBuffer | Blob | ReadableStream | NodeJS.ReadableStream;
++export interface SiteFile { path: string; data: Blob | ArrayBuffer | Uint8Array | string; type?: string }
++export interface SiteConfig { headers?: Record<string, string>; redirects?: unknown[]; spa?: boolean }
++export interface UploadOpts extends Opts { activate?: boolean; preview?: boolean; root?: string }
++export interface SpaceClient {
++ projects: {
++ list(opts?: Opts): Promise<SpaceJson>;
++ create(fields: Record<string, unknown>, opts?: Opts): Promise<SpaceJson>;
++ get(project: string, opts?: Opts): Promise<SpaceJson>;
++ remove(project: string, opts?: Opts): Promise<SpaceJson>;
++ quota(project: string, opts?: Opts): Promise<SpaceJson>;
++ sites(project: string, opts?: Opts): Promise<SpaceJson>;
++ members: {
++ set(project: string, principal: string, role: SpaceRole, opts?: Opts): Promise<SpaceJson>;
++ remove(project: string, principal: string, opts?: Opts): Promise<SpaceJson>;
++ };
++ };
++ sites: {
++ create(project: string, fields: Record<string, unknown>, opts?: Opts): Promise<SpaceJson>;
++ get(site: string, opts?: Opts): Promise<SpaceJson>;
++ remove(site: string, opts?: Opts): Promise<SpaceJson>;
++ config: { get(site: string, opts?: Opts): Promise<SpaceJson>; set(site: string, config: SiteConfig, opts?: Opts): Promise<SpaceJson>; reset(site: string, opts?: Opts): Promise<SpaceJson> };
++ source: { get(site: string, opts?: Opts): Promise<SpaceJson>; set(site: string, source: Record<string, unknown>, opts?: Opts): Promise<SpaceJson>; remove(site: string, opts?: Opts): Promise<SpaceJson> };
++ };
++ deploys: {
++ list(site: string, opts?: Opts): Promise<SpaceJson>;
++ get(deploy: string, opts?: Opts): Promise<SpaceJson>;
++ log(deploy: string, opts?: Opts): Promise<SpaceJson>;
++ uploadArchive(site: string, archive: ArchiveBody, opts?: UploadOpts & { gzip?: boolean }): Promise<{ deploy: SpaceJson; activated: boolean; preview?: unknown; url?: string }>;
++ uploadFiles(site: string, files: SiteFile[], opts?: UploadOpts): Promise<{ deploy: SpaceJson; activated: boolean; preview?: unknown; url?: string }>;
++ uploadSourceBuild(site: string, archive: ArchiveBody, opts: Opts & { ref: string; commit_sha: string; gzip?: boolean }): Promise<SpaceJson>;
++ activate(deploy: string, opts?: Opts & { expected_active?: string | null }): Promise<SpaceJson>;
++ rollback(site: string, opts?: Opts & { deploy_id?: string; expected_active?: string | null }): Promise<SpaceJson>;
++ remove(deploy: string, opts?: Opts): Promise<SpaceJson>;
++ };
++ domains: {
++ list(site: string, opts?: Opts): Promise<SpaceJson>;
++ add(site: string, fields: Record<string, unknown>, opts?: Opts): Promise<SpaceJson>;
++ verify(domain: string, opts?: Opts): Promise<SpaceJson>;
++ remove(domain: string, opts?: Opts): Promise<SpaceJson>;
++ };
++}
++export function createSpaceClient(client: { json(opts: Record<string, unknown>): Promise<any> }, options?: { baseUrl?: string }): SpaceClient;