openvibers/openvibe.sdk Commits

moneyReasons: plain words for a ledger row (billing.money-reason@1) (#187)

OP OpenVibers committed 3 days ago · 586b7566e9 · 15 files, +240 −12

* moneyReasons: the same plain words for a ledger row as billing.money-reason@1

* Merge main

* API surface: moneyReasons

* Merge main; moneyReasons at 0.137.0

* SDK 0.137.0: version, lockfile, README, bundle and ESM agree

Changes

ddiff --git a/CHANGELOG.md b/CHANGELOG.md
iindex c580a05..4bbbace 100644
---- a/CHANGELOG.md
++++ b/CHANGELOG.md
@@@ -1,9 +1,13 @@
++# Changelog
++
++## 0.137.0 (2026-11-10)
++
++- Add `moneyReasons` (`billing.money-reason@1`): the plain words for a movement of OpenCoins, Vibes or Balance, for a service that holds the raw `reason` row. It re-exports `openvibe-contracts`' list when the installed package has it, otherwise the same list copied at Contracts 0.392.0: `describe(key, { site, resolve, subject })` answers `{ key, text, subject: { name, url } | null, site, known }`, and `describeRow(row)` reads `{ reason, app_id }`. An undeclared key reads "for something on <site>" with `known: false`.
++
## 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)
- `ov.ai.files`: attach files through Media, list/read/remove them, and expose typed `ai.file@1` and conversational turn shapes.
ddiff --git a/README.md b/README.md
iindex e1aaa2c..f41fd0a 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.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.
++**Status:** alpha, v0.137.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.136.0
++npm install https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.137.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 45a30ae..38c5187 100644
---- a/STATUS.json
++++ b/STATUS.json
@@@ -3,7 +3,7 @@
"stage": "alpha",
"code": true,
"wave": "W2",
-- "version": "0.136.0",
++ "version": "0.137.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/openvibe-sdk.mjs b/browser/openvibe-sdk.mjs
iindex f9e78e4..91bdb52 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.136.0, MIT). Do not edit.
++// Generated by scripts/browser-bundle.js from browser.js (openvibe-sdk 0.137.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, 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 */
@@@ -57,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.136.0';
++const SDK_VERSION = '0.137.0';
module.exports = {
createClient,
ddiff --git a/docs/api-surface.json b/docs/api-surface.json
iindex f5decdb..fd2969d 100644
---- a/docs/api-surface.json
++++ b/docs/api-surface.json
@@@ -280,6 +280,17 @@
"createModulesClient"
]
},
++ "moneyReasons": {
++ "object": [
++ "KINDS",
++ "SITES",
++ "describe",
++ "describeRow",
++ "siteName",
++ "titleFromSlug",
++ "unknownText"
++ ]
++ },
"newEventId": "function",
"newIdempotencyKey": "function",
"news": {
ddiff --git a/esm/index.mjs b/esm/index.mjs
iindex fa5993f..17d101c 100644
---- a/esm/index.mjs
++++ b/esm/index.mjs
@@@ -15,6 +15,6 @@ export const {
deals, shoes, trade, space, host, news,
food, actor, run, video, pics, work,
zone, git, play, download, openre, geo,
-- usage, commerce, telemetry,
++ usage, commerce, moneyReasons, telemetry,
} = cjs;
export default cjs;
ddiff --git a/index.js b/index.js
iindex 7366429..fdc6cc4 100644
---- a/index.js
++++ b/index.js
@@@ -71,5 +71,6 @@ module.exports = {
geo: require('./src/geo'),
usage: require('./src/usage'),
commerce: require('./src/commerce'),
++ moneyReasons: require('./src/money-reasons'),
telemetry: require('./src/telemetry'),
};
ddiff --git a/package-lock.json b/package-lock.json
iindex f82d8e2..76f83db 100644
---- a/package-lock.json
++++ b/package-lock.json
@@@ -1,12 +1,12 @@
{
"name": "openvibe-sdk",
-- "version": "0.136.0",
++ "version": "0.137.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "openvibe-sdk",
-- "version": "0.136.0",
++ "version": "0.137.0",
"license": "MIT",
"bin": {
"openvibe-download": "bin/openvibe-download.js"
ddiff --git a/package.json b/package.json
iindex 90f892a..a7dc425 100644
---- a/package.json
++++ b/package.json
@@@ -1,6 +1,6 @@
{
"name": "openvibe-sdk",
-- "version": "0.136.0",
++ "version": "0.137.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",
ddiff --git a/src/core/index.js b/src/core/index.js
iindex b9b5145..aefa782 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.136.0';
++const SDK_VERSION = '0.137.0';
module.exports = {
createClient,
ddiff --git a/src/money-reasons-list.js b/src/money-reasons-list.js
nnew file mode 100644
iindex 0000000..6c099bd
---- /dev/null
++++ b/src/money-reasons-list.js
@@@ -0,0 +1,146 @@
++'use strict';
++/**
++ * The same list as openvibe-contracts/lib/money-reasons.js (0.392.0). SDK ships it for a service whose installed
++ * contract package predates the module; money-reasons.js uses the contract's copy whenever it is there.
++ *
++ * Money reasons: the plain words for a ledger row (2026-11-10).
++ *
++ * A ledger holds a key, never a sentence: OpenCoins rows carry `reason` ("quest:publish-a-video"),
++ * Vibes/Balance rows carry a type and metadata. This list is the one place each kind is declared:
++ * the key it matches, the site it belongs to, what its subject is (a quest, a stream, a tip, a
++ * creator, an app, a project, a purchase), the phrase that names it, and how the subject's own
++ * name and address are found.
++ *
++ * `describe(key, options)` makes `{ key, text, subject: { name, url } | null }`. `text` is the
++ * phrase without the amount ("for the quest Publish a video"); the page writes
++ * "+15 OpenCoins" before it and links the phrase to subject.url. A key nobody declared answers
++ * "for something on <site>" and is marked known: false, so a caller logs it once and never shows
++ * the key itself.
++ *
++ * `options.resolve` maps a subject type to a lookup: `{ quest: (id) => ({ name, url }) }`.
++ * `options.subject` is an already-found subject (a tip's creator, a project). `options.site`
++ * names the site for an undeclared key.
++ */
++
++/** The sites a key can belong to, in the words a person reads. */
++const SITES = Object.freeze({
++ quest: 'OpenVibe.Quest',
++ fun: 'OpenVibe.Fun',
++ live: 'OpenVibe.Live',
++ network: 'OpenVibe.Network',
++ billing: 'OpenVibe',
++ inventory: 'OpenVibe.Inventory',
++});
++
++/**
++ * One entry per reason kind.
++ * match RegExp whose first group is the subject's id or name (or an exact key string)
++ * site SITES key, for an undeclared key and for callers that show provenance
++ * subject the subject type `options.resolve` can look up; omitted when there is none
++ * text the phrase; `{name}` is where the subject's name goes
++ * fallback the name when the subject cannot be found ("a creator", "an item")
++ * path the subject's address; `{id}` is the matched group
++ * catalog where the subject's own names live (a declaration for the resolver)
++ */
++const KINDS = Object.freeze([
++ // ── OpenCoins: Network's coin_transactions.reason ───────────────────────────────────────────
++ Object.freeze({ id: 'quest', match: /^quest:([a-z0-9-]+)$/i, site: 'quest', subject: 'quest', text: 'for the quest {name}',
++ path: 'https://openvibe.quest/quests/{id}', catalog: 'https://openvibe.quest/api/v1/quests' }),
++ Object.freeze({ id: 'fun-quest', match: /^fun:([a-z0-9-]+)$/i, site: 'fun', subject: 'fun-quest', text: 'for the quest {name}',
++ path: 'https://openvibe.fun/q/{id}', catalog: 'https://openvibe.fun/api/v1/quests' }),
++ Object.freeze({ id: 'media-request', match: /^Media request: (.+)$/, site: 'live', subject: 'media', text: 'for the stream {name}' }),
++ Object.freeze({ id: 'media-refund', match: /^Refund: (.+)$/, site: 'live', subject: 'media', text: 'for a refund of {name}' }),
++ Object.freeze({ id: 'migration', match: 'migration:hobo-coins', site: 'network', text: 'for OpenCoins moved from the old Live wallet' }),
++ Object.freeze({ id: 'account-merge', match: 'account_merge', site: 'network', text: 'for merging your accounts' }),
++ Object.freeze({ id: 'account-deleted', match: 'account_deleted', site: 'network', text: 'for closing your account' }),
++ Object.freeze({ id: 'watch', match: 'watch', site: 'live', text: 'for watching a stream' }),
++ Object.freeze({ id: 'chat', match: 'chat', site: 'live', text: 'for chatting on a stream' }),
++ Object.freeze({ id: 'follow', match: 'follow', site: 'live', text: 'for following a channel' }),
++ Object.freeze({ id: 'bonus-game', match: 'bonus game', site: 'live', text: 'for winning the bonus game' }),
++ Object.freeze({ id: 'admin-grant', match: 'Admin grant', site: 'network', text: 'for OpenCoins from OpenVibe' }),
++
++ // ── Vibes / Balance: Billing's transaction type + metadata ──────────────────────────────────
++ Object.freeze({ id: 'ai-usage', match: 'credit:settle', site: 'billing', text: 'for AI usage' }),
++ Object.freeze({ id: 'topup', match: 'credit:topup', site: 'billing', text: 'for adding money to your Balance' }),
++ Object.freeze({ id: 'vibes-from-balance', match: 'purchase:vibes_from_balance', site: 'billing', text: 'for buying Vibes with your Balance' }),
++ Object.freeze({ id: 'vibes-bought', match: 'purchase:vibes', site: 'billing', text: 'for buying Vibes' }),
++ Object.freeze({ id: 'store-purchase', match: 'purchase:store', site: 'inventory', subject: 'item', text: 'for buying {name}', fallback: 'an item' }),
++ Object.freeze({ id: 'app-payment', match: 'vibes_charge', site: 'billing', subject: 'app', text: 'for paying {name}', fallback: 'an app' }),
++ Object.freeze({ id: 'app-purchase', match: 'purchase:app', site: 'billing', subject: 'app', text: 'for paying {name}', fallback: 'an app' }),
++ Object.freeze({ id: 'tip', match: 'donation', site: 'billing', subject: 'creator', text: 'for a tip to {name}', fallback: 'a creator' }),
++ Object.freeze({ id: 'tip-received', match: 'donation:received', site: 'billing', subject: 'creator', text: 'for a tip from {name}', fallback: 'someone' }),
++ Object.freeze({ id: 'subscription', match: 'subscription', site: 'billing', subject: 'creator', text: 'for a subscription to {name}', fallback: 'a creator' }),
++ Object.freeze({ id: 'subscription-share', match: 'subscription_share', site: 'billing', subject: 'creator', text: 'for a subscription to {name}', fallback: 'a creator' }),
++ Object.freeze({ id: 'refund', match: 'refund', site: 'billing', text: 'for a refund' }),
++ Object.freeze({ id: 'vibes-refund', match: 'vibes_refund', site: 'billing', text: 'for a refund of Vibes' }),
++ Object.freeze({ id: 'move-to-project', match: 'balance_transfer', site: 'billing', subject: 'project', text: 'for moving money to {name}', fallback: 'a project' }),
++ Object.freeze({ id: 'cashout-request', match: 'cashout_request', site: 'billing', text: 'for cashing out' }),
++ Object.freeze({ id: 'cashout-paid', match: 'cashout_paid', site: 'billing', text: 'for a payout' }),
++ Object.freeze({ id: 'cashout-denied', match: 'cashout_denied', site: 'billing', text: 'for a cashout that was denied' }),
++ Object.freeze({ id: 'recycle', match: 'recycle', site: 'billing', text: 'for moving your cashout balance back to Vibes' }),
++ Object.freeze({ id: 'adjustment', match: 'adjustment', site: 'billing', text: 'for an adjustment by OpenVibe' }),
++]);
++
++/** "live-setup-slot" → "Live setup slot": the name a slug gives when its catalog is not at hand. */
++function titleFromSlug(slug) {
++ const words = String(slug == null ? '' : slug).replace(/[-_]+/g, ' ').trim();
++ return words ? words.charAt(0).toUpperCase() + words.slice(1) : '';
++}
++
++function siteName(id) {
++ return SITES[String(id || '').toLowerCase()] || 'OpenVibe';
++}
++
++function subjectFrom(value, kind, options) {
++ if (options.subject && typeof options.subject === 'object' && options.subject.name) {
++ return { name: String(options.subject.name).slice(0, 160), url: options.subject.url ? String(options.subject.url).slice(0, 500) : null };
++ }
++ let found = null;
++ if (value != null && kind.subject && options.resolve && typeof options.resolve[kind.subject] === 'function') {
++ try { found = options.resolve[kind.subject](value); } catch { found = null; }
++ }
++ if (typeof found === 'string') found = { name: found };
++ const name = found && found.name ? String(found.name).slice(0, 160) : (kind.fallback || titleFromSlug(value));
++ const url = found && found.url ? String(found.url).slice(0, 500) : (kind.path && value != null ? kind.path.replace('{id}', encodeURIComponent(value)) : null);
++ if (!name) return null;
++ return { name, url: url || null };
++}
++
++/**
++ * The plain words for a ledger reason.
++ * @returns {{ key: string, text: string, subject: { name: string, url: string|null }|null, site: string, known: boolean }}
++ */
++function describe(key, options = {}) {
++ const raw = key == null ? '' : String(key).trim();
++ let kind = null;
++ let value = null;
++ for (const entry of KINDS) {
++ if (typeof entry.match === 'string') {
++ if (raw === entry.match) { kind = entry; break; }
++ continue;
++ }
++ const m = raw.match(entry.match);
++ if (m) { kind = entry; value = m[1] == null ? null : m[1].trim(); break; }
++ }
++ if (!kind) {
++ return { key: raw, text: `for something on ${siteName(options.site || raw.split(':')[0])}`, subject: null,
++ site: siteName(options.site || raw.split(':')[0]), known: false };
++ }
++ const subject = kind.subject ? subjectFrom(value, kind, options) : null;
++ const text = kind.text.indexOf('{name}') < 0 ? kind.text
++ : kind.text.replace('{name}', subject ? subject.name : (kind.fallback || 'something'));
++ return { key: raw, text, subject, site: siteName(kind.site), known: true };
++}
++
++/** A row from a service that keeps the raw key: `{ reason, app_id }` or `{ reason }`. */
++function describeRow(row, options = {}) {
++ const reason = row && (row.reason != null ? row.reason : row.reason_key);
++ return describe(reason, { ...options, site: options.site || (row && (row.app_id || row.site)) || undefined });
++}
++
++/** What an undeclared key reads, for a test and for a caller that wants only the words. */
++function unknownText(site) {
++ return `for something on ${siteName(site)}`;
++}
++
++module.exports = { KINDS, SITES, describe, describeRow, unknownText, siteName, titleFromSlug };
ddiff --git a/src/money-reasons.js b/src/money-reasons.js
nnew file mode 100644
iindex 0000000..164de63
---- /dev/null
++++ b/src/money-reasons.js
@@@ -0,0 +1,16 @@
++'use strict';
++
++/**
++ * The plain words for a ledger row, for a service that holds the raw key (`reason` from OpenCoins,
++ * or Billing's `type:metadata`). The list and the formatter live in openvibe-contracts
++ * (`billing.money-reason@1`, `lib/money-reasons.js`); this re-exports them when the installed
++ * package has them and otherwise answers from the same list copied at 0.392.0, so every service
++ * builds the sentence the same way.
++ *
++ * const { moneyReasons } = require('openvibe-sdk');
++ * moneyReasons.describe(row.reason, { site: row.app_id, resolve: { quest: (id) => ({ name, url }) } });
++ * // → { key, text: 'for the quest Publish a video', subject: { name, url }, site, known: true }
++ */
++let canonical = null;
++try { canonical = require('openvibe-contracts').moneyReasons || null; } catch { /* an older contract package: the copy below answers */ }
++module.exports = canonical || require('./money-reasons-list');
ddiff --git a/test/money-reasons.test.js b/test/money-reasons.test.js
nnew file mode 100644
iindex 0000000..aed3c96
---- /dev/null
++++ b/test/money-reasons.test.js
@@@ -0,0 +1,27 @@
++'use strict';
++// moneyReasons: the same formatter as openvibe-contracts (billing.money-reason@1), for a service holding a raw row.
++const assert = require('assert');
++const { moneyReasons } = require('..');
++
++let n = 0;
++const ok = (cond, msg) => { assert.ok(cond, msg); n++; };
++
++const quest = moneyReasons.describe('quest:publish-a-video', { site: 'quest' });
++ok(quest.text === 'for the quest Publish a video', 'a quest key reads as a sentence');
++ok(quest.subject && quest.subject.url === 'https://openvibe.quest/quests/publish-a-video', 'and links to the quest');
++ok(quest.site === 'OpenVibe.Quest', 'and names its site');
++
++const resolved = moneyReasons.describe('quest:go-live', { resolve: { quest: () => ({ name: 'Go live once', url: 'https://openvibe.quest/quests/go-live' }) } });
++ok(resolved.text === 'for the quest Go live once', 'a resolver names the subject');
++
++const row = moneyReasons.describeRow({ reason: 'Refund: A film', app_id: 'live' });
++ok(row.text === 'for a refund of A film' && row.site === 'OpenVibe.Live', 'a raw row is described by its reason and app');
++
++const tip = moneyReasons.describe('donation', { subject: { name: '@alice', url: 'https://openvibe.live/@alice' } });
++ok(tip.text === 'for a tip to @alice', 'a tip names its creator');
++
++const unknown = moneyReasons.describe('nobody:declared-this', { site: 'fun' });
++ok(!unknown.known && unknown.text === 'for something on OpenVibe.Fun', 'an undeclared key reads "for something on <site>"');
++ok(!/nobody:|declared-this/.test(unknown.text), 'and never shows the key');
++
++console.log(`openvibe-sdk money reasons: ${n} checks passed`);
ddiff --git a/types/index.d.ts b/types/index.d.ts
iindex 55698ff..81d43d5 100644
---- a/types/index.d.ts
++++ b/types/index.d.ts
@@@ -60,6 +60,7 @@ export * as openre from './openre';
export * as geo from './geo';
export * as usage from './usage';
export * as commerce from './commerce';
++export * as moneyReasons from './money-reasons';
export * as telemetry from './telemetry';
export const share: typeof import('./share').share;
export * as locker from './locker';
ddiff --git a/types/money-reasons.d.ts b/types/money-reasons.d.ts
nnew file mode 100644
iindex 0000000..1a47128
---- /dev/null
++++ b/types/money-reasons.d.ts
@@@ -0,0 +1,22 @@
++/** billing.money-reason@1: the plain words for a movement of OpenCoins, Vibes or Balance. */
++export interface MoneyReasonSubject { name: string; url: string | null }
++export interface MoneyReason {
++ /** The ledger's own reason, kept for support and logs; a page never prints it. */
++ key: string;
++ /** The phrase without the amount: "for the quest Publish a video". */
++ text: string;
++ /** What it was for, with its own name and address, or null. */
++ subject: MoneyReasonSubject | null;
++ /** The site in words: OpenVibe.Quest, OpenVibe.Live, OpenVibe. */
++ site: string;
++ /** False for a key no kind declares; its text is "for something on <site>". */
++ known: boolean;
++}
++export type MoneyReasonResolver = (value: string) => { name: string; url?: string | null } | string | null | undefined;
++export function describe(key: string | null | undefined, options?: { resolve?: Record<string, MoneyReasonResolver>; subject?: MoneyReasonSubject | null; site?: string }): MoneyReason;
++export function describeRow(row: { reason?: string | null; reason_key?: string | null; app_id?: string | null; site?: string | null }, options?: { resolve?: Record<string, MoneyReasonResolver>; subject?: MoneyReasonSubject | null; site?: string }): MoneyReason;
++export function unknownText(site?: string): string;
++export function siteName(site?: string): string;
++export function titleFromSlug(slug?: string): string;
++export const SITES: Readonly<Record<string, string>>;
++export const KINDS: ReadonlyArray<{ id: string; site: string; text?: string; path?: string; catalog?: string; subject?: string }>;