openvibers/openvibe.sdk Commits

Network levels client and SDK 0.136.0 (#185)

OP OpenVibers committed 3 days ago · 0372943569 · 19 files, +188 −82

* Add Network levels reads and service awards to the SDK

* Record levels in the generated SDK API surface

Changes

ddiff --git a/CHANGELOG.md b/CHANGELOG.md
iindex cf619e9..c580a05 100644
---- a/CHANGELOG.md
++++ b/CHANGELOG.md
@@@ -1,3 +1,7 @@
++## 0.136.0 — 2026-11-09
++
++- Network levels client: public person, batch and board reads, and service awards.
++
# Changelog
## 0.135.0 (2026-11-10)
ddiff --git a/README.md b/README.md
iindex c4e76c5..e1aaa2c 100644
---- a/README.md
++++ b/README.md
@@@ -13,7 +13,7 @@ npm install https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags
> Supported browser and server clients for the OpenVibe platform.
--**Status:** alpha, v0.135.0 (the five 1.0 core entries — `core`, `auth`, `events`, `db` and `media` — are frozen: their exported names change only with a major release; roadmap Wave 2; developer apps from Wave 20; Media objects v2 from Wave 4; the Tools platform API; Search, Chat, AI, Vision and consent clients; sign-in with recovery and a client health check). 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.136.0 (the five 1.0 core entries — `core`, `auth`, `events`, `db` and `media` — are frozen: their exported names change only with a major release; roadmap Wave 2; developer apps from Wave 20; Media objects v2 from Wave 4; the Tools platform API; Search, Chat, AI, Vision and consent clients; sign-in with recovery and a client health check). 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.
@@@ -22,7 +22,7 @@ npm install https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags
After v0.97.1 is tagged:
```bash
--npm install https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.135.0
++npm install https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.136.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 the temporary Contracts sharing branch, a devDependency the tests check them against).
ddiff --git a/STATUS.json b/STATUS.json
iindex b3a791a..45a30ae 100644
---- a/STATUS.json
++++ b/STATUS.json
@@@ -3,7 +3,7 @@
"stage": "alpha",
"code": true,
"wave": "W2",
-- "version": "0.135.0",
++ "version": "0.136.0",
"plan": "OpenVibe End-to-End Realignment & Implementation Plan, revision 3 (20 Sep 2026), \u00a73.2; roadmap \u00a730",
"deployed": false,
"deployment": "none: a package released as git tags; services and apps pin a tag",
ddiff --git a/browser.js b/browser.js
iindex 2fed999..897c919 100644
---- a/browser.js
++++ b/browser.js
@@@ -12,6 +12,7 @@ module.exports = {
locker: require('./src/locker'),
registry: require('./src/registry'),
trust: require('./src/trust'),
++ levels: require('./src/levels'),
modules: require('./src/modules'),
realtime: require('./src/realtime'),
media: require('./src/media'),
ddiff --git a/browser/openvibe-sdk.mjs b/browser/openvibe-sdk.mjs
iindex 6d7ffa5..f9e78e4 100644
---- a/browser/openvibe-sdk.mjs
++++ b/browser/openvibe-sdk.mjs
@@@ -1,6 +1,6 @@
--// Generated by scripts/browser-bundle.js from browser.js (openvibe-sdk 0.135.0, MIT). Do not edit.
++// Generated by scripts/browser-bundle.js from browser.js (openvibe-sdk 0.136.0, MIT). Do not edit.
// One self-contained ES module: core at the top level plus the browser-safe subpaths as namespaces
--// (auth, locker, registry, trust, modules, realtime, media, cam, mediaUpload, ui, community, homeFeed, bot, search, bench, meme, vision, themes, design, redact, chat, ai, credentials, jobs, tools, projects, geo). No server-only code: no service tokens, JWT verification, events, identity.
++// (auth, locker, registry, trust, levels, modules, realtime, media, cam, mediaUpload, ui, community, homeFeed, bot, search, bench, meme, vision, themes, design, redact, chat, ai, credentials, jobs, tools, projects, geo). No server-only code: no service tokens, JWT verification, events, identity.
/* eslint-disable */
const __defs = [
// ── 0: browser.js ──────────────────────────────────────────────────
@@@ -19,29 +19,30 @@ module.exports = {
locker: __load(10),
registry: __load(21),
trust: __load(22),
-- modules: __load(23),
-- realtime: __load(24),
-- media: __load(25),
-- cam: __load(27),
-- mediaUpload: __load(28),
-- ui: __load(29),
-- community: __load(30),
-- homeFeed: __load(31),
-- bot: __load(32),
-- search: __load(33),
-- bench: __load(34),
-- meme: __load(35),
-- vision: __load(36),
-- themes: __load(37),
-- design: __load(38),
-- redact: __load(39),
-- chat: __load(40),
-- ai: __load(41),
-- credentials: __load(42),
-- jobs: __load(43),
-- tools: __load(45),
-- projects: __load(46),
-- geo: __load(47),
++ levels: __load(23),
++ modules: __load(24),
++ realtime: __load(25),
++ media: __load(26),
++ cam: __load(28),
++ mediaUpload: __load(29),
++ ui: __load(30),
++ community: __load(31),
++ homeFeed: __load(32),
++ bot: __load(33),
++ search: __load(34),
++ bench: __load(35),
++ meme: __load(36),
++ vision: __load(37),
++ themes: __load(38),
++ design: __load(39),
++ redact: __load(40),
++ chat: __load(41),
++ ai: __load(42),
++ credentials: __load(43),
++ jobs: __load(44),
++ tools: __load(46),
++ projects: __load(47),
++ geo: __load(48),
};
},
// ── 1: src/core/index.js ───────────────────────────────────────────
@@@ -56,7 +57,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.135.0';
++const SDK_VERSION = '0.136.0';
module.exports = {
createClient,
@@@ -2512,7 +2513,31 @@ function atLeast(signals, band) {
module.exports = { createTrustClient, isNew, atLeast, AGE_BANDS };
},
--// ── 23: src/modules.js ──────────────────────────────────────────────
++// ── 23: src/levels.js ───────────────────────────────────────────────
++function (module, exports) {
++'use strict';
++/** Network owns experience. Reads are public; awards require network.levels.award. */
++function createLevelsClient(client, { baseUrl } = {}) {
++ if (!client || typeof client.json !== 'function') throw new TypeError('createLevelsClient: pass an SDK core client');
++ const call = (options) => client.json({ service: 'network', audience: 'openvibe.network', baseUrl, ...options });
++ return {
++ get(username, { signal } = {}) {
++ if (!/^[A-Za-z0-9_]{1,40}$/.test(username)) throw new TypeError('invalid username');
++ return call({ path: `/api/v1/levels/people/${encodeURIComponent(username)}`, signal });
++ },
++ batch(subjects, { signal } = {}) {
++ if (!Array.isArray(subjects) || subjects.length > 100 || subjects.some(s => !/^usr_[0-9A-HJKMNP-TV-Z]{26}$/.test(s))) throw new TypeError('batch requires up to 100 user subjects');
++ return call({ path: `/api/v1/levels/batch?subjects=${encodeURIComponent(subjects.join(','))}`, signal });
++ },
++ board({ signal } = {}) { return call({ path: '/api/v1/levels/board', signal }); },
++ award(body, { signal } = {}) {
++ return call({ method: 'POST', path: '/internal/levels/award', json: body, signal, idempotencyKey: false });
++ },
++ };
++}
++module.exports = { createLevelsClient };
++},
++// ── 24: src/modules.js ──────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -2591,7 +2616,7 @@ function createModulesClient(client, { baseUrl, maxAttempts = 5 } = {}) {
module.exports = { createModulesClient };
},
--// ── 24: src/realtime.js ─────────────────────────────────────────────
++// ── 25: src/realtime.js ─────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -2844,7 +2869,7 @@ function createRealtimeClient(client, defaults = {}) {
module.exports = { subscribe, createRealtimeClient, parseSSE, DEFAULT_ORIGIN };
},
--// ── 25: src/media.js ────────────────────────────────────────────────
++// ── 26: src/media.js ────────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -2867,7 +2892,7 @@ function (module, exports) {
*/
const { isOpenVibeError } = __load(3);
const { paginate, offsetPager } = __load(7);
--const { createObjectsClient } = __load(26);
++const { createObjectsClient } = __load(27);
const DEFAULT_PUBLIC_ORIGIN = 'https://openvibe.media';
const enc = encodeURIComponent;
@@@ -2959,7 +2984,7 @@ function createMediaClient(client, { app, apiKey, actingUserId, baseUrl, publicO
module.exports = { createMediaClient, createObjectsClient, mediaUrls, DEFAULT_PUBLIC_ORIGIN };
},
--// ── 26: src/objects.js ──────────────────────────────────────────────
++// ── 27: src/objects.js ──────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -3279,7 +3304,7 @@ function createObjectsClient({
module.exports = { createObjectsClient };
},
--// ── 27: src/cam/index.js ────────────────────────────────────────────
++// ── 28: src/cam/index.js ────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -3389,10 +3414,10 @@ function defineOvCamera(options = {}) {
module.exports = { defineOvCamera, OV_CAMERA_SRC, CAM_KIT_SRC, CAM_KIT_SRI, loadCamKit, open, settings };
},
--// ── 28: src/media-upload.js ─────────────────────────────────────────
++// ── 29: src/media-upload.js ─────────────────────────────────────────
function (module, exports) {
'use strict';
--const { createObjectsClient } = __load(25);
++const { createObjectsClient } = __load(26);
const MIB = 1024 * 1024;
/** Media's resumable multipart transport, configured for 8 MiB parts and three in flight. */
@@@ -3409,7 +3434,7 @@ function createUploadClient(config) {
module.exports = { createUploadClient };
},
--// ── 29: src/ui.js ───────────────────────────────────────────────────
++// ── 30: src/ui.js ───────────────────────────────────────────────────
function (module, exports) {
'use strict';
@@@ -3422,7 +3447,7 @@ function progress(el, options) {
module.exports = { progress };
},
--// ── 30: src/community.js ────────────────────────────────────────────
++// ── 31: src/community.js ────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -3562,7 +3587,7 @@ function createCommunityClient(client, defaults = {}) {
module.exports = { createCommunityClient, actingHeaders };
},
--// ── 31: src/home-feed.js ────────────────────────────────────────────
++// ── 32: src/home-feed.js ────────────────────────────────────────────
function (module, exports) {
'use strict';
/** The menu's portable Home layout, network day counts and personal wall. Pass a user-token core client;
@@@ -3589,7 +3614,7 @@ function createHomeFeedClient(client, { networkBaseUrl, communityBaseUrl } = {})
module.exports = { createHomeFeedClient };
},
--// ── 32: src/bot.js ──────────────────────────────────────────────────
++// ── 33: src/bot.js ──────────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -3811,7 +3836,7 @@ function createBotClient(client, defaults = {}) {
module.exports = { createBotClient, actingHeaders };
},
--// ── 33: src/search.js ───────────────────────────────────────────────
++// ── 34: src/search.js ───────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -3924,7 +3949,7 @@ function createSearchClient(client, defaults = {}) {
module.exports = { createSearchClient, queryOf, fabricOf };
},
--// ── 34: src/bench.js ────────────────────────────────────────────────
++// ── 35: src/bench.js ────────────────────────────────────────────────
function (module, exports) {
'use strict';
/** openvibe-sdk/bench: OpenVibe.Bench's JSON API and streamed open dataset. Browser-safe. */
@@@ -4025,7 +4050,7 @@ function createBenchClient(client, defaults = {}) {
module.exports = { createBenchClient };
},
--// ── 35: src/meme.js ─────────────────────────────────────────────────
++// ── 36: src/meme.js ─────────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -4108,7 +4133,7 @@ function createMemeClient(client, defaults = {}) {
module.exports = { createMemeClient };
},
--// ── 36: src/vision.js ───────────────────────────────────────────────
++// ── 37: src/vision.js ───────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -4266,7 +4291,7 @@ function pick(o, keys) {
module.exports = { createVisionClient, DEFAULT_AUDIENCE };
},
--// ── 37: src/themes.js ───────────────────────────────────────────────
++// ── 38: src/themes.js ───────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -4416,7 +4441,7 @@ function followTheme(fn, opts = {}) {
module.exports = { createThemesClient, followTheme, readTheme, applyTheme, seasonOn, onColor, DISPLAY_OPTIONS, TOKENS };
},
--// ── 38: src/design.js ───────────────────────────────────────────────
++// ── 39: src/design.js ───────────────────────────────────────────────
function (module, exports) {
'use strict';
@@@ -4483,7 +4508,7 @@ function createDesignClient({ accessToken = null, baseUrl = DEFAULT_DESIGN_URL,
module.exports = { createDesignClient, DEFAULT_DESIGN_URL };
},
--// ── 39: src/redact.js ───────────────────────────────────────────────
++// ── 40: src/redact.js ───────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -4730,7 +4755,7 @@ function onlySecret(text) {
module.exports = { redact, onlySecret };
},
--// ── 40: src/chat.js ─────────────────────────────────────────────────
++// ── 41: src/chat.js ─────────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -4981,7 +5006,7 @@ function createFeedPublisher(client, { feed, key, baseUrl } = {}) {
module.exports = { createChatClient, createInboxVisitor, createFeedPublisher };
},
--// ── 41: src/ai.js ───────────────────────────────────────────────────
++// ── 42: src/ai.js ───────────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -5117,7 +5142,7 @@ function createAiClient(client, defaults = {}) {
};
// Files live in Media; turns carry only their Media object references.
-- const fileObjects = defaults.objectsClient || (defaults.media ? __load(26).createObjectsClient(defaults.media) : null);
++ const fileObjects = defaults.objectsClient || (defaults.media ? __load(27).createObjectsClient(defaults.media) : null);
const requireFiles = (method) => { if (!fileObjects) throw new TypeError(`ai.files.${method}: configure defaults.media or defaults.objectsClient`); };
const files = {
async attach(data, { filename, mediaType, subject, signal, ...options } = {}) {
@@@ -5171,7 +5196,7 @@ function createAiClient(client, defaults = {}) {
module.exports = { createAiClient, TERMINAL, OPS, CLASSES };
},
--// ── 42: src/credentials.js ──────────────────────────────────────────
++// ── 43: src/credentials.js ──────────────────────────────────────────
function (module, exports) {
'use strict';
@@@ -5189,7 +5214,7 @@ function createCredentialsClient(client, defaults = {}) {
module.exports = { createCredentialsClient };
},
--// ── 43: src/jobs.js ─────────────────────────────────────────────────
++// ── 44: src/jobs.js ─────────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -5227,8 +5252,8 @@ function (module, exports) {
*/
const { OpenVibeError, isOpenVibeError } = __load(3);
const { newIdempotencyKey } = __load(5);
--const { appendFiles } = __load(44);
--const { parseSSE } = __load(24);
++const { appendFiles } = __load(45);
++const { parseSSE } = __load(25);
const TERMINAL = new Set(['succeeded', 'failed', 'cancelled']);
const TERMINAL_EVENTS = new Set(['job.succeeded', 'job.failed', 'job.cancelled']);
@@@ -5391,7 +5416,7 @@ function createJobsClient(client, { baseUrl, service = 'tools', audience = 'open
module.exports = { createJobsClient, isTerminal, TERMINAL_STATES: [...TERMINAL] };
},
--// ── 44: src/core/form.js ────────────────────────────────────────────
++// ── 45: src/core/form.js ────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -5425,7 +5450,7 @@ function appendFiles(form, list, where) {
module.exports = { isBlob, isUpload, appendFiles };
},
--// ── 45: src/tools.js ────────────────────────────────────────────────
++// ── 46: src/tools.js ────────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -5459,8 +5484,8 @@ function (module, exports) {
*/
const { OpenVibeError, isOpenVibeError } = __load(3);
const { newIdempotencyKey } = __load(5);
--const { isUpload, appendFiles } = __load(44);
--const { createJobsClient } = __load(43);
++const { isUpload, appendFiles } = __load(45);
++const { createJobsClient } = __load(44);
const enc = encodeURIComponent;
const ID_RE = /^[a-z][a-z0-9-]{0,39}$/;
@@@ -5720,7 +5745,7 @@ function createToolsClient(client, { baseUrl, service = 'tools', audience = 'ope
module.exports = { createToolsClient, ToolRunError, isToolRunError };
},
--// ── 46: src/projects.js ─────────────────────────────────────────────
++// ── 47: src/projects.js ─────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -5836,7 +5861,7 @@ function createProjectsClient(client, { baseUrl } = {}) {
module.exports = { createProjectsClient };
},
--// ── 47: src/geo.js ──────────────────────────────────────────────────
++// ── 48: src/geo.js ──────────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -5915,10 +5940,10 @@ export const {
createWalletClient, createClient, OpenVibeError, isOpenVibeError, paginate, offsetPager,
parseTraceparent, startSpan, contextFromHeaders, ulid, newEventId, newIdempotencyKey,
isActingSubjectId, satisfiesRange, compareVersions, CONTRACTS_RANGE, DEFAULT_NETWORK, SDK_VERSION,
-- auth, locker, registry, trust, modules, realtime,
-- media, cam, mediaUpload, ui, community, homeFeed,
-- bot, search, bench, meme, vision, themes,
-- design, redact, chat, ai, credentials, jobs,
-- tools, projects, geo,
++ auth, locker, registry, trust, levels, modules,
++ realtime, media, cam, mediaUpload, ui, community,
++ homeFeed, bot, search, bench, meme, vision,
++ themes, design, redact, chat, ai, credentials,
++ jobs, tools, projects, geo,
} = sdk;
export default sdk;
ddiff --git a/docs/api-surface.json b/docs/api-surface.json
iindex 7c60017..f5decdb 100644
---- a/docs/api-surface.json
++++ b/docs/api-surface.json
@@@ -211,6 +211,11 @@
"isTerminal"
]
},
++ "levels": {
++ "object": [
++ "createLevelsClient"
++ ]
++ },
"live": {
"object": [
"createLiveClient"
@@@ -814,6 +819,9 @@
"createJobsClient": "function",
"isTerminal": "function"
},
++ "openvibe-sdk/levels": {
++ "createLevelsClient": "function"
++ },
"openvibe-sdk/limits": {
"WINDOWS": {
"object": [
ddiff --git a/esm/index.mjs b/esm/index.mjs
iindex 2bcf21a..fa5993f 100644
---- a/esm/index.mjs
++++ b/esm/index.mjs
@@@ -6,15 +6,15 @@ export const {
parseTraceparent, startSpan, contextFromHeaders, ulid, newEventId, newIdempotencyKey,
isActingSubjectId, satisfiesRange, compareVersions, CONTRACTS_RANGE, DEFAULT_NETWORK, SDK_VERSION,
report, share, locker, auth, registry, identity,
-- trust, modules, events, realtime, media, cam,
-- mediaUpload, ui, community, homeFeed, bot, search,
-- bench, meme, vision, themes, design, redact,
-- chat, chatApps, ai, credentials, jobs, tools,
-- projects, resources, vip, quest, live, inventory,
-- tips, blog, reviews, wiki, coupons, deals,
-- shoes, trade, space, host, news, food,
-- actor, run, video, pics, work, zone,
-- git, play, download, openre, geo, usage,
-- commerce, telemetry,
++ trust, levels, modules, events, realtime, media,
++ cam, mediaUpload, ui, community, homeFeed, bot,
++ search, bench, meme, vision, themes, design,
++ redact, chat, chatApps, ai, credentials, jobs,
++ tools, projects, resources, vip, quest, live,
++ inventory, tips, blog, reviews, wiki, coupons,
++ deals, shoes, trade, space, host, news,
++ food, actor, run, video, pics, work,
++ zone, git, play, download, openre, geo,
++ usage, commerce, telemetry,
} = cjs;
export default cjs;
ddiff --git a/esm/levels.mjs b/esm/levels.mjs
nnew file mode 100644
iindex 0000000..e3b5ee4
---- /dev/null
++++ b/esm/levels.mjs
@@@ -0,0 +1,7 @@
++// Generated by scripts/esm.js from src/levels.js. Do not edit.
++import cjs from '../src/levels.js';
++
++export const {
++ createLevelsClient,
++} = cjs;
++export default cjs;
ddiff --git a/index.js b/index.js
iindex 000f2be..7366429 100644
---- a/index.js
++++ b/index.js
@@@ -16,6 +16,7 @@ module.exports = {
registry: require('./src/registry'),
identity: require('./src/identity'),
trust: require('./src/trust'),
++ levels: require('./src/levels'),
modules: require('./src/modules'),
events: require('./src/events'),
realtime: require('./src/realtime'),
ddiff --git a/package-lock.json b/package-lock.json
iindex ec34643..f82d8e2 100644
---- a/package-lock.json
++++ b/package-lock.json
@@@ -1,12 +1,12 @@
{
"name": "openvibe-sdk",
-- "version": "0.135.0",
++ "version": "0.136.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "openvibe-sdk",
-- "version": "0.135.0",
++ "version": "0.136.0",
"license": "MIT",
"bin": {
"openvibe-download": "bin/openvibe-download.js"
ddiff --git a/package.json b/package.json
iindex 1faa6d7..90f892a 100644
---- a/package.json
++++ b/package.json
@@@ -1,6 +1,6 @@
{
"name": "openvibe-sdk",
-- "version": "0.135.0",
++ "version": "0.136.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",
@@@ -579,6 +579,11 @@
"browser": "./src/wallet.js",
"import": "./esm/wallet.mjs",
"default": "./src/wallet.js"
++ },
++ "./levels": {
++ "types": "./types/levels.d.ts",
++ "import": "./esm/levels.mjs",
++ "default": "./src/levels.js"
}
},
"bin": {
ddiff --git a/scripts/esm.js b/scripts/esm.js
iindex 6675d84..4dc10c5 100644
---- a/scripts/esm.js
++++ b/scripts/esm.js
@@@ -26,6 +26,7 @@ const ENTRIES = {
'registry.mjs': '../src/registry.js',
'identity.mjs': '../src/identity.js',
'trust.mjs': '../src/trust.js',
++ 'levels.mjs': '../src/levels.js',
'notifications.mjs': '../src/notifications.js',
'modules.mjs': '../src/modules.js',
'events.mjs': '../src/events.js',
ddiff --git a/src/core/index.js b/src/core/index.js
iindex a029f03..b9b5145 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.135.0';
++const SDK_VERSION = '0.136.0';
module.exports = {
createClient,
ddiff --git a/src/levels.js b/src/levels.js
nnew file mode 100644
iindex 0000000..817601b
---- /dev/null
++++ b/src/levels.js
@@@ -0,0 +1,21 @@
++'use strict';
++/** Network owns experience. Reads are public; awards require network.levels.award. */
++function createLevelsClient(client, { baseUrl } = {}) {
++ if (!client || typeof client.json !== 'function') throw new TypeError('createLevelsClient: pass an SDK core client');
++ const call = (options) => client.json({ service: 'network', audience: 'openvibe.network', baseUrl, ...options });
++ return {
++ get(username, { signal } = {}) {
++ if (!/^[A-Za-z0-9_]{1,40}$/.test(username)) throw new TypeError('invalid username');
++ return call({ path: `/api/v1/levels/people/${encodeURIComponent(username)}`, signal });
++ },
++ batch(subjects, { signal } = {}) {
++ if (!Array.isArray(subjects) || subjects.length > 100 || subjects.some(s => !/^usr_[0-9A-HJKMNP-TV-Z]{26}$/.test(s))) throw new TypeError('batch requires up to 100 user subjects');
++ return call({ path: `/api/v1/levels/batch?subjects=${encodeURIComponent(subjects.join(','))}`, signal });
++ },
++ board({ signal } = {}) { return call({ path: '/api/v1/levels/board', signal }); },
++ award(body, { signal } = {}) {
++ return call({ method: 'POST', path: '/internal/levels/award', json: body, signal, idempotencyKey: false });
++ },
++ };
++}
++module.exports = { createLevelsClient };
ddiff --git a/test/levels.test.js b/test/levels.test.js
nnew file mode 100644
iindex 0000000..84f2032
---- /dev/null
++++ b/test/levels.test.js
@@@ -0,0 +1,18 @@
++'use strict';
++const assert = require('assert');
++const { createLevelsClient } = require('../src/levels');
++(async () => {
++ const calls = []; const levels = createLevelsClient({ json: async o => { calls.push(o); return { level: 1 }; } });
++ const subject = 'usr_01JAB2C3D4E5F6G7H8J9K0MNP1';
++ await levels.get('alice'); await levels.batch([subject]); await levels.board();
++ await levels.award({ subject, reason: 'quest.completed', amount: 25, idempotency_key: 'completion:1' });
++ assert.equal(calls[0].path, '/api/v1/levels/people/alice');
++ assert(calls[1].path.includes(subject)); assert.equal(calls[2].path, '/api/v1/levels/board');
++ assert.equal(calls[3].method, 'POST'); assert.equal(calls[3].idempotencyKey, false);
++ assert(calls.every(c => c.audience === 'openvibe.network'));
++ assert.throws(() => levels.batch(Array(101).fill(subject))); assert.throws(() => levels.batch(['bad']));
++ assert.throws(() => levels.get('../board'));
++ const refused = createLevelsClient({ json: async () => { const e = new Error('duplicate'); e.status = 409; throw e; } });
++ await assert.rejects(refused.award({}), e => e.status === 409);
++ console.log('levels: public reads, bounded batches and service awards passed');
++})().catch(e => { console.error(e); process.exitCode = 1; });
ddiff --git a/test/pack.test.js b/test/pack.test.js
iindex f5d3d9c..d15dce4 100644
---- a/test/pack.test.js
++++ b/test/pack.test.js
@@@ -72,7 +72,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, 100); // openvibe-sdk/git adds the 100th subpath (0.127.0).
++ assert.equal(subpaths.length, 101); // levels adds the 101st subpath.
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/types/bundle.d.ts b/types/bundle.d.ts
iindex ab2bc33..120e5a0 100644
---- a/types/bundle.d.ts
++++ b/types/bundle.d.ts
@@@ -26,6 +26,7 @@ import * as projects from './projects';
import * as geo from './geo';
import * as locker from './locker';
import * as trust from './trust';
++import * as levels from './levels';
import * as core from './core';
export const createWalletClient: typeof import('./wallet').createWalletClient;
@@@ -57,10 +58,11 @@ export * as projects from './projects';
export * as geo from './geo';
export * as locker from './locker';
export * as trust from './trust';
++export * as levels from './levels';
declare const sdk: typeof core & {
createWalletClient: typeof createWalletClient;
auth: typeof auth; registry: typeof registry; modules: typeof modules; realtime: typeof realtime;
-- media: typeof media; cam: typeof cam; mediaUpload: typeof mediaUpload; ui: typeof ui; community: typeof community; homeFeed: typeof homeFeed; bot: typeof bot; search: typeof search; bench: typeof bench; meme: typeof meme; vision: typeof vision; themes: typeof themes; design: typeof design; redact: typeof redact; chat: typeof chat; ai: typeof ai; credentials: typeof credentials; jobs: typeof jobs; tools: typeof tools; projects: typeof projects; geo: typeof geo; locker: typeof locker; trust: typeof trust;
++ media: typeof media; cam: typeof cam; mediaUpload: typeof mediaUpload; ui: typeof ui; community: typeof community; homeFeed: typeof homeFeed; bot: typeof bot; search: typeof search; bench: typeof bench; meme: typeof meme; vision: typeof vision; themes: typeof themes; design: typeof design; redact: typeof redact; chat: typeof chat; ai: typeof ai; credentials: typeof credentials; jobs: typeof jobs; tools: typeof tools; projects: typeof projects; geo: typeof geo; locker: typeof locker; trust: typeof trust; levels: typeof levels;
};
export default sdk;
ddiff --git a/types/index.d.ts b/types/index.d.ts
iindex e9bb6fa..55698ff 100644
---- a/types/index.d.ts
++++ b/types/index.d.ts
@@@ -65,3 +65,5 @@ export const share: typeof import('./share').share;
export * as locker from './locker';
export const createWalletClient: typeof import('./wallet').createWalletClient;
++
++export * as levels from './levels';
ddiff --git a/types/levels.d.ts b/types/levels.d.ts
nnew file mode 100644
iindex 0000000..66565e6
---- /dev/null
++++ b/types/levels.d.ts
@@@ -0,0 +1,11 @@
++import type { OpenVibeClient } from './core';
++export interface Level { level: number; xp: number; into: number; span: number; next_at: number; rank: number | null; recent: Array<{ name: string; at: string; amount: number }>; }
++export interface Entry { subject: string; username: string; level: number; xp: number; rank: number; }
++export interface Period { top: Entry[]; me: Entry | null; around: Entry[]; }
++export interface Award { subject: string; reason: 'quest.completed' | 'coins.earned' | 'video.published' | 'stream.watched'; amount: number; idempotency_key: string; }
++export function createLevelsClient(client: OpenVibeClient, options?: { baseUrl?: string }): {
++ get(username: string, options?: { signal?: AbortSignal }): Promise<Level>;
++ batch(subjects: string[], options?: { signal?: AbortSignal }): Promise<{ levels: Record<string, number> }>;
++ board(options?: { signal?: AbortSignal }): Promise<{ all_time: Period; week: Period }>;
++ award(body: Award, options?: { signal?: AbortSignal }): Promise<Level>;
++};