@vibechain/os 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +80 -48
- package/README.md +143 -55
- package/SECURITY.md +47 -20
- package/dist/app-client.d.ts +4 -1
- package/dist/app-client.js +15 -4
- package/dist/app-host.d.ts +124 -9
- package/dist/app-host.js +395 -57
- package/dist/app-protocol.d.ts +17 -1
- package/dist/app-protocol.js +12 -0
- package/dist/app-runtime.d.ts +18 -2
- package/dist/app-runtime.js +75 -11
- package/dist/app-wire.d.ts +215 -0
- package/dist/app-wire.js +268 -0
- package/dist/browser.d.ts +3 -0
- package/dist/browser.js +3 -0
- package/dist/bundle.js +6 -6
- package/dist/canvas.d.ts +2 -2
- package/dist/canvas.js +3 -1
- package/dist/capture.d.ts +22 -0
- package/dist/capture.js +99 -0
- package/dist/check.d.ts +12 -0
- package/dist/check.js +167 -0
- package/dist/cli-publish.d.ts +24 -0
- package/dist/cli-publish.js +288 -0
- package/dist/cli-session.d.ts +108 -0
- package/dist/cli-session.js +245 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.js +46 -10
- package/dist/index.d.ts +8 -0
- package/dist/index.js +4 -0
- package/dist/links.d.ts +15 -0
- package/dist/links.js +41 -0
- package/dist/listing.d.ts +3 -3
- package/dist/listing.js +1 -1
- package/dist/loop.d.ts +18 -2
- package/dist/loop.js +13 -1
- package/dist/manifest.d.ts +90 -4
- package/dist/manifest.js +340 -5
- package/dist/os.d.ts +63 -0
- package/dist/os.js +383 -0
- package/dist/preview-parent.d.ts +42 -0
- package/dist/preview-parent.js +134 -11
- package/dist/preview-ui.js +1 -1
- package/dist/preview.js +25 -7
- package/dist/redact.d.ts +6 -0
- package/dist/redact.js +16 -0
- package/dist/runtime-policy.d.ts +20 -0
- package/dist/runtime-policy.js +45 -0
- package/dist/scaffold.d.ts +13 -2
- package/dist/scaffold.js +95 -31
- package/dist/submit-notice.d.ts +26 -0
- package/dist/submit-notice.js +34 -0
- package/dist/templates/plain/game.js +18 -0
- package/dist/testing.d.ts +68 -0
- package/dist/testing.js +181 -1
- package/dist/transport.d.ts +22 -0
- package/dist/transport.js +71 -19
- package/dist/vibemarket-os.js +1 -0
- package/dist/worker.d.ts +18 -0
- package/dist/worker.js +34 -0
- package/examples/paw-beat/README.md +20 -8
- package/examples/paw-beat/cat.ts +665 -89
- package/examples/paw-beat/game.ts +162 -28
- package/examples/paw-beat/index.html +114 -40
- package/examples/paw-beat/main.ts +264 -149
- package/examples/paw-beat/music.ts +314 -65
- package/examples/paw-beat/stage.ts +560 -0
- package/examples/paw-beat/store/icon.png +0 -0
- package/examples/paw-beat/store/screenshot-1.webp +0 -0
- package/examples/paw-beat/store/screenshot-2.webp +0 -0
- package/examples/paw-beat/vibemarket.json +2 -2
- package/examples/vibexp-app/README.md +7 -7
- package/examples/vibexp-app/index.html +3 -2
- package/examples/vibexp-app/plain/game.ts +20 -0
- package/examples/vibexp-app/plain/index.html +6 -0
- package/examples/vibexp-app/plain/vibemarket.json +17 -0
- package/examples/vibexp-app/src/main.ts +46 -31
- package/examples/vibexp-app/store/icon.png +0 -0
- package/examples/vibexp-app/three/README.md +21 -0
- package/examples/vibexp-app/three/index.html +4 -0
- package/examples/vibexp-app/three/src/main.ts +45 -0
- package/examples/vibexp-app/three/vibemarket.json +19 -0
- package/examples/vibexp-app/vibemarket.json +17 -11
- package/package.json +6 -2
package/dist/manifest.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export const GAME_PERMISSIONS = ["profile.get", "catalog.list", "inventory.get", "packs.buy", "packs.sell", "packs.open", "cards.reveal", "cards.sell", "cards.collect"];
|
|
2
|
-
/** VibeStore listing categories. */
|
|
3
|
-
export const APP_STORE_CATEGORIES = ["game", "
|
|
2
|
+
/** VibeStore listing categories: a game or an app (owner decision, 2026-11-23). */
|
|
3
|
+
export const APP_STORE_CATEGORIES = ["game", "app"];
|
|
4
|
+
/**
|
|
5
|
+
* Categories @vibechain/os 0.4 accepted. A schema version 2 manifest that names one still validates and is normalized to
|
|
6
|
+
* "app" (`manifestNotices` says so); schema version 3 refuses them.
|
|
7
|
+
*/
|
|
8
|
+
export const APP_LEGACY_STORE_CATEGORIES = ["tool", "toy"];
|
|
9
|
+
const legacyCategory = (value) => typeof value === "string" && APP_LEGACY_STORE_CATEGORIES.includes(value);
|
|
4
10
|
/** Content rating levels for `store.rating.violence` and `store.rating.language`. */
|
|
5
11
|
export const APP_CONTENT_RATINGS = ["none", "mild", "strong"];
|
|
6
12
|
/** Screenshot file extensions a listing may name (lowercase). */
|
|
@@ -15,7 +21,17 @@ export const APP_STORE_LIMITS = {
|
|
|
15
21
|
descriptionMin: 40, descriptionMax: 2000, supportMax: 200, screenshotsMin: 1, screenshotsMax: 4,
|
|
16
22
|
iconSize: 256, iconBytes: 256 * 1024, screenshotBytes: 1024 * 1024,
|
|
17
23
|
};
|
|
24
|
+
/** What a schema version 3 app may read of the player's vmOS cards: nothing, its linked packs, or every pack. */
|
|
25
|
+
export const APP_CARDS_ACCESS = ["none", "linked", "all"];
|
|
26
|
+
/** The legacy Market-game bounds. VibeStore bundles use `APP_BUNDLE_LIMITS`. */
|
|
18
27
|
export const GAME_LIMITS = { archive: 20 * 1024 * 1024, expanded: 64 * 1024 * 1024, file: 16 * 1024 * 1024, files: 256, versions: 100, games: 40 };
|
|
28
|
+
/** VibeStore bundle bounds: the submitted ZIP, its expanded bytes, the largest file and the entries (files and folders). */
|
|
29
|
+
export const APP_BUNDLE_LIMITS = { archive: 50 * 1024 * 1024, expanded: 128 * 1024 * 1024, file: 32 * 1024 * 1024, files: 2000 };
|
|
30
|
+
/** Schema version 3 bounds: linked packs, declared origins and a pack slug's length. */
|
|
31
|
+
export const APP_MANIFEST_LIMITS = { packs: 3, network: 8, packSlugMax: 56 };
|
|
32
|
+
/** A pack slug, as `vibemarket/steam/pack-slug.ts` defines it (at most `APP_MANIFEST_LIMITS.packSlugMax` characters). */
|
|
33
|
+
export const PACK_SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
34
|
+
export const packSlug = (value) => typeof value === "string" && value.length <= APP_MANIFEST_LIMITS.packSlugMax && PACK_SLUG.test(value);
|
|
19
35
|
export function assetPath(value) {
|
|
20
36
|
return value.length > 0 && value.length <= 200 && value.split("/").every(part => /^[A-Za-z0-9_][A-Za-z0-9_.-]*$/.test(part) && !part.endsWith("."));
|
|
21
37
|
}
|
|
@@ -103,7 +119,7 @@ function parseStore(input) {
|
|
|
103
119
|
const text = description.trim(), length = [...text].length;
|
|
104
120
|
if (length < limits.descriptionMin || length > limits.descriptionMax)
|
|
105
121
|
throw Error(`store.description must be ${limits.descriptionMin} to ${limits.descriptionMax} characters.`);
|
|
106
|
-
if (typeof category !== "string" || !APP_STORE_CATEGORIES.includes(category))
|
|
122
|
+
if (typeof category !== "string" || !(APP_STORE_CATEGORIES.includes(category) || legacyCategory(category)))
|
|
107
123
|
throw Error(`store.category must be one of ${APP_STORE_CATEGORIES.join(", ")}.`);
|
|
108
124
|
if (!record(rating) || !exactFields(rating, ["violence", "language", "mature"]))
|
|
109
125
|
throw Error("store.rating must be an object with exactly violence, language and mature.");
|
|
@@ -115,7 +131,7 @@ function parseStore(input) {
|
|
|
115
131
|
if (typeof support !== "string" || !supportContact(support))
|
|
116
132
|
throw Error(`store.support must be an https:// URL or an email address of at most ${limits.supportMax} characters.`);
|
|
117
133
|
return {
|
|
118
|
-
icon, screenshots: paths, description: text, category: category,
|
|
134
|
+
icon, screenshots: paths, description: text, category: legacyCategory(category) ? "app" : category,
|
|
119
135
|
rating: { violence: rating.violence, language: rating.language, mature: rating.mature }, support,
|
|
120
136
|
};
|
|
121
137
|
}
|
|
@@ -132,9 +148,328 @@ function parseV2(data) {
|
|
|
132
148
|
permissions: [], collectionId: null, window: parseWindow(data.window), store: parseStore(data.store),
|
|
133
149
|
};
|
|
134
150
|
}
|
|
135
|
-
/**
|
|
151
|
+
/** Names that resolve anywhere a resolver likes, or nowhere public (section 3.3, rule 5). */
|
|
152
|
+
export const NETWORK_RESERVED_SUFFIXES = ["localhost", "local", "internal", "lan", "home.arpa", "test", "example", "invalid", "onion", "arpa"];
|
|
153
|
+
/** Wildcard-DNS services that map a name to any address (rule 6). Extended by review. */
|
|
154
|
+
export const NETWORK_WILDCARD_DNS = ["nip.io", "sslip.io", "xip.io", "localtest.me", "lvh.me", "traefik.me"];
|
|
155
|
+
/** Vibechain's own domains (rule 7): an app never declares them. */
|
|
156
|
+
export const NETWORK_OWN_DOMAINS = ["vibechain.com", "vibe.market", "eattherich.gg"];
|
|
157
|
+
const under = (host, names) => names.some(name => host === name || host.endsWith(`.${name}`));
|
|
158
|
+
const LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
159
|
+
/**
|
|
160
|
+
* Why `value` is not a declared network origin, or `null` with its normalized form. The single implementation of
|
|
161
|
+
* section 3.3: `https://` or `wss://`, exactly `scheme://host[:port]`, a public DNS name, never an IP address, a
|
|
162
|
+
* local or reserved name, a wildcard-DNS service or a Vibechain domain.
|
|
163
|
+
*/
|
|
164
|
+
export function networkOriginCheck(value) {
|
|
165
|
+
const fail = (problem) => ({ origin: null, problem });
|
|
166
|
+
if (typeof value !== "string" || value.length > 300)
|
|
167
|
+
return fail("must be an https:// or wss:// origin, such as https://cdn.example.com.");
|
|
168
|
+
if (value.includes("*"))
|
|
169
|
+
return fail("must not contain a wildcard (*); list each origin.");
|
|
170
|
+
const lower = value.toLowerCase(), scheme = /^(https|wss):\/\//.exec(lower);
|
|
171
|
+
if (!scheme)
|
|
172
|
+
return fail("must start with https:// or wss://, such as https://cdn.example.com.");
|
|
173
|
+
const rest = lower.slice(scheme[0].length);
|
|
174
|
+
if (!rest || /[/?#@\\\s]/.test(rest))
|
|
175
|
+
return fail("must be only scheme://host or scheme://host:port, with no path (not even /), query, fragment or user name.");
|
|
176
|
+
if (rest.startsWith("["))
|
|
177
|
+
return fail("must use a DNS name, not an IP address.");
|
|
178
|
+
const parts = /^([^:]+)(?::([0-9]+))?$/.exec(rest);
|
|
179
|
+
if (!parts)
|
|
180
|
+
return fail("must be only scheme://host or scheme://host:port, with no path (not even /), query, fragment or user name.");
|
|
181
|
+
const host = parts[1], port = parts[2];
|
|
182
|
+
if (port !== undefined && (!/^[1-9][0-9]{0,4}$/.test(port) || Number(port) > 65535))
|
|
183
|
+
return fail("has a port that is not a number from 1 to 65535.");
|
|
184
|
+
if (port === "443")
|
|
185
|
+
return fail("names the default port 443; write the origin without a port.");
|
|
186
|
+
const labels = host.split("."), last = labels[labels.length - 1];
|
|
187
|
+
if (/^(?:[0-9]+|0x[0-9a-f]*)$/.test(last) || /[0-9]{1,3}[.-][0-9]{1,3}[.-][0-9]{1,3}[.-][0-9]{1,3}/.test(host))
|
|
188
|
+
return fail("must use a DNS name, not an IP address.");
|
|
189
|
+
if (under(host, NETWORK_RESERVED_SUFFIXES))
|
|
190
|
+
return fail("must be a public DNS name; local and reserved names such as localhost or .local are refused.");
|
|
191
|
+
if (under(host, NETWORK_WILDCARD_DNS))
|
|
192
|
+
return fail("names a wildcard-DNS service that can point at any address; use your own domain.");
|
|
193
|
+
if (under(host, NETWORK_OWN_DOMAINS))
|
|
194
|
+
return fail("must not be a vibechain.com, vibe.market or eattherich.gg address.");
|
|
195
|
+
if (labels.length < 2 || host.length > 253 || !labels.every(label => LABEL.test(label)) || !(/^[a-z]{2,63}$/.test(last) || /^xn--[a-z0-9-]+$/.test(last))) {
|
|
196
|
+
return fail("must be a valid DNS name of at least two labels, such as cdn.example.com; write internationalized names in punycode (xn--).");
|
|
197
|
+
}
|
|
198
|
+
return { origin: `${scheme[1]}://${host}${port === undefined ? "" : `:${port}`}`, problem: null };
|
|
199
|
+
}
|
|
200
|
+
/** The normalized (lowercase) origin, or `null` when `value` is not an origin an app may declare (section 3.3). */
|
|
201
|
+
export function networkOrigin(value) { return networkOriginCheck(value).origin; }
|
|
202
|
+
/** `path: message`, the line `os check` prints and the text `parseManifest` throws for schema version 3. */
|
|
203
|
+
export const manifestProblemText = (problem) => problem.path ? `${problem.path}: ${problem.message}` : problem.message;
|
|
204
|
+
const V3_REQUIRED = ["schemaVersion", "id", "version", "name", "tagline", "entry", "window", "store"];
|
|
205
|
+
const V3_OPTIONAL = ["packs", "cards", "network"];
|
|
206
|
+
const V3_REMOVED = ["sdkVersion", "category", "permissions", "collectionId"];
|
|
207
|
+
// origins are distinct by then, so two are never equal
|
|
208
|
+
const compareText = (a, b) => a < b ? -1 : 1;
|
|
209
|
+
/** Fields of an object: unknown ones and missing ones, in the input's order and then the expected order. */
|
|
210
|
+
function fieldProblems(data, prefix, required, optional = [], removed = []) {
|
|
211
|
+
const problems = [];
|
|
212
|
+
for (const key of Object.keys(data)) {
|
|
213
|
+
if (removed.includes(key))
|
|
214
|
+
problems.push({ path: prefix + key, message: "is no longer needed in schema version 3; remove it." });
|
|
215
|
+
else if (!required.includes(key) && !optional.includes(key))
|
|
216
|
+
problems.push({ path: prefix + key, message: "is not a field here; remove it." });
|
|
217
|
+
}
|
|
218
|
+
for (const key of required)
|
|
219
|
+
if (!(key in data))
|
|
220
|
+
problems.push({ path: prefix + key, message: "is required." });
|
|
221
|
+
return problems;
|
|
222
|
+
}
|
|
223
|
+
/** Schema version 3: every problem, in field order, and the normalized manifest when there are none. */
|
|
224
|
+
function inspectV3(data) {
|
|
225
|
+
const problems = fieldProblems(data, "", V3_REQUIRED, V3_OPTIONAL, V3_REMOVED);
|
|
226
|
+
const add = (path, message) => { problems.push({ path, message }); };
|
|
227
|
+
const text = (key, max) => {
|
|
228
|
+
const value = data[key];
|
|
229
|
+
if (!(key in data))
|
|
230
|
+
return null;
|
|
231
|
+
if (typeof value !== "string")
|
|
232
|
+
add(key, "must be a string.");
|
|
233
|
+
else if (!value.trim())
|
|
234
|
+
add(key, "must not be empty.");
|
|
235
|
+
else if (value !== value.trim())
|
|
236
|
+
add(key, "must not start or end with spaces.");
|
|
237
|
+
else if (value.length > max)
|
|
238
|
+
add(key, `must be at most ${max} characters.`);
|
|
239
|
+
else
|
|
240
|
+
return value;
|
|
241
|
+
return null;
|
|
242
|
+
};
|
|
243
|
+
let id = text("id", 60);
|
|
244
|
+
if (id !== null && id === "chonk-club") {
|
|
245
|
+
add("id", "chonk-club is reserved for the built-in game; choose another id.");
|
|
246
|
+
id = null;
|
|
247
|
+
}
|
|
248
|
+
else if (id !== null && !/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(id)) {
|
|
249
|
+
add("id", "must be lowercase letters, digits and single hyphens, starting with a letter, such as my-game.");
|
|
250
|
+
id = null;
|
|
251
|
+
}
|
|
252
|
+
let version = text("version", 50);
|
|
253
|
+
if (version !== null && !/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[a-z0-9]+(?:[.-][a-z0-9]+)*)?$/.test(version)) {
|
|
254
|
+
add("version", "must be a semantic version, such as 1.0.0 or 1.0.0-beta.1.");
|
|
255
|
+
version = null;
|
|
256
|
+
}
|
|
257
|
+
const name = text("name", 60), tagline = text("tagline", 160);
|
|
258
|
+
let entry = text("entry", 200);
|
|
259
|
+
if (entry !== null && (!assetPath(entry) || !entry.endsWith(".html"))) {
|
|
260
|
+
add("entry", "must be the relative path of an .html file in the bundle, such as index.html.");
|
|
261
|
+
entry = null;
|
|
262
|
+
}
|
|
263
|
+
const window = "window" in data ? inspectWindow(data.window, add) : null;
|
|
264
|
+
const store = "store" in data ? inspectStore(data.store, add) : null;
|
|
265
|
+
const packs = inspectPacks(data.packs, add);
|
|
266
|
+
let cards = "none";
|
|
267
|
+
if ("cards" in data) {
|
|
268
|
+
if (typeof data.cards !== "string" || !APP_CARDS_ACCESS.includes(data.cards)) {
|
|
269
|
+
add("cards", 'must be "none", "linked" or "all".');
|
|
270
|
+
cards = null;
|
|
271
|
+
}
|
|
272
|
+
else
|
|
273
|
+
cards = data.cards;
|
|
274
|
+
}
|
|
275
|
+
if (cards === "linked" && packs !== null && !packs.length) {
|
|
276
|
+
add("cards", '"linked" reads the packs listed in packs; add at least one pack, or use "none" or "all".');
|
|
277
|
+
cards = null;
|
|
278
|
+
}
|
|
279
|
+
const network = inspectNetwork(data.network, add);
|
|
280
|
+
if (problems.length || id === null || version === null || name === null || tagline === null || entry === null || !window || !store || !packs || !cards || !network)
|
|
281
|
+
return { manifest: null, problems };
|
|
282
|
+
return { manifest: { schemaVersion: 3, id, version, name, tagline, entry, window, store, packs, cards, network }, problems };
|
|
283
|
+
}
|
|
284
|
+
function inspectWindow(input, add) {
|
|
285
|
+
if (!record(input)) {
|
|
286
|
+
add("window", "must be an object with width, height and resizable.");
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
const before = fieldProblems(input, "window.", ["width", "height", "resizable"]);
|
|
290
|
+
for (const problem of before)
|
|
291
|
+
add(problem.path, problem.message);
|
|
292
|
+
const limits = APP_WINDOW_LIMITS, { width, height, resizable } = input;
|
|
293
|
+
let ok = !before.length;
|
|
294
|
+
if ("width" in input && (typeof width !== "number" || !Number.isInteger(width) || width < limits.minWidth || width > limits.maxWidth)) {
|
|
295
|
+
add("window.width", `must be a whole number of CSS pixels from ${limits.minWidth} to ${limits.maxWidth}.`);
|
|
296
|
+
ok = false;
|
|
297
|
+
}
|
|
298
|
+
if ("height" in input && (typeof height !== "number" || !Number.isInteger(height) || height < limits.minHeight || height > limits.maxHeight)) {
|
|
299
|
+
add("window.height", `must be a whole number of CSS pixels from ${limits.minHeight} to ${limits.maxHeight}.`);
|
|
300
|
+
ok = false;
|
|
301
|
+
}
|
|
302
|
+
if ("resizable" in input && typeof resizable !== "boolean") {
|
|
303
|
+
add("window.resizable", "must be true or false.");
|
|
304
|
+
ok = false;
|
|
305
|
+
}
|
|
306
|
+
return ok ? { width: width, height: height, resizable: resizable } : null;
|
|
307
|
+
}
|
|
308
|
+
function inspectStore(input, add) {
|
|
309
|
+
if (!record(input)) {
|
|
310
|
+
add("store", "must be an object with icon, screenshots, description, category, rating and support.");
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
const before = fieldProblems(input, "store.", ["icon", "screenshots", "description", "category", "rating", "support"]);
|
|
314
|
+
for (const problem of before)
|
|
315
|
+
add(problem.path, problem.message);
|
|
316
|
+
const limits = APP_STORE_LIMITS, { icon, screenshots, description, category, rating, support } = input;
|
|
317
|
+
let ok = !before.length;
|
|
318
|
+
const bad = (path, message) => { add(path, message); ok = false; };
|
|
319
|
+
if ("icon" in input && (typeof icon !== "string" || !assetPath(icon) || !icon.endsWith(".png")))
|
|
320
|
+
bad("store.icon", "must be the relative path of a .png file in the bundle, such as store/icon.png.");
|
|
321
|
+
const paths = [];
|
|
322
|
+
if ("screenshots" in input) {
|
|
323
|
+
if (!Array.isArray(screenshots) || screenshots.length < limits.screenshotsMin || screenshots.length > limits.screenshotsMax)
|
|
324
|
+
bad("store.screenshots", `must list ${limits.screenshotsMin} to ${limits.screenshotsMax} images.`);
|
|
325
|
+
if (Array.isArray(screenshots)) {
|
|
326
|
+
const seen = new Set(typeof icon === "string" ? [icon.toLowerCase()] : []);
|
|
327
|
+
screenshots.forEach((shot, index) => {
|
|
328
|
+
const path = `store.screenshots[${index}]`;
|
|
329
|
+
if (typeof shot !== "string" || !assetPath(shot) || !APP_SCREENSHOT_EXTENSIONS.includes(extension(shot)))
|
|
330
|
+
bad(path, "must be the relative path of a .png, .jpg, .jpeg or .webp file in the bundle.");
|
|
331
|
+
else if (seen.has(shot.toLowerCase()))
|
|
332
|
+
bad(path, "repeats another screenshot or the icon; each screenshot must be a different file.");
|
|
333
|
+
else {
|
|
334
|
+
seen.add(shot.toLowerCase());
|
|
335
|
+
paths.push(shot);
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
let text = "";
|
|
341
|
+
if ("description" in input) {
|
|
342
|
+
if (typeof description !== "string")
|
|
343
|
+
bad("store.description", "must be a string of plain text.");
|
|
344
|
+
else if (CONTROL.test(description))
|
|
345
|
+
bad("store.description", "must be plain text; line breaks are the only control characters allowed.");
|
|
346
|
+
else {
|
|
347
|
+
text = description.trim();
|
|
348
|
+
const length = [...text].length;
|
|
349
|
+
if (length < limits.descriptionMin || length > limits.descriptionMax)
|
|
350
|
+
bad("store.description", `must be ${limits.descriptionMin} to ${limits.descriptionMax} characters after trimming; it has ${length}.`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if ("category" in input && legacyCategory(category))
|
|
354
|
+
bad("store.category", `must be one of ${APP_STORE_CATEGORIES.join(", ")}; "tool" and "toy" are now "app".`);
|
|
355
|
+
else if ("category" in input && (typeof category !== "string" || !APP_STORE_CATEGORIES.includes(category)))
|
|
356
|
+
bad("store.category", `must be one of ${APP_STORE_CATEGORIES.join(", ")}.`);
|
|
357
|
+
if ("rating" in input) {
|
|
358
|
+
if (!record(rating))
|
|
359
|
+
bad("store.rating", "must be an object with violence, language and mature.");
|
|
360
|
+
else {
|
|
361
|
+
const fields = fieldProblems(rating, "store.rating.", ["violence", "language", "mature"]);
|
|
362
|
+
for (const problem of fields)
|
|
363
|
+
bad(problem.path, problem.message);
|
|
364
|
+
const levels = APP_CONTENT_RATINGS;
|
|
365
|
+
for (const key of ["violence", "language"])
|
|
366
|
+
if (key in rating && (typeof rating[key] !== "string" || !levels.includes(rating[key])))
|
|
367
|
+
bad(`store.rating.${key}`, `must be one of ${APP_CONTENT_RATINGS.join(", ")}.`);
|
|
368
|
+
if ("mature" in rating && typeof rating.mature !== "boolean")
|
|
369
|
+
bad("store.rating.mature", "must be true or false.");
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if ("support" in input && (typeof support !== "string" || !supportContact(support)))
|
|
373
|
+
bad("store.support", `must be an https:// address or an email address of at most ${limits.supportMax} characters.`);
|
|
374
|
+
if (!ok || !record(rating))
|
|
375
|
+
return null;
|
|
376
|
+
return {
|
|
377
|
+
icon: icon, screenshots: paths, description: text, category: category,
|
|
378
|
+
rating: { violence: rating.violence, language: rating.language, mature: rating.mature }, support: support,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
function inspectPacks(input, add) {
|
|
382
|
+
if (input === undefined)
|
|
383
|
+
return [];
|
|
384
|
+
if (!Array.isArray(input)) {
|
|
385
|
+
add("packs", 'must be a list of pack slugs, such as ["rooftop-rats"].');
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
let ok = true;
|
|
389
|
+
if (input.length > APP_MANIFEST_LIMITS.packs) {
|
|
390
|
+
add("packs", `may link at most ${APP_MANIFEST_LIMITS.packs} packs.`);
|
|
391
|
+
ok = false;
|
|
392
|
+
}
|
|
393
|
+
const packs = [];
|
|
394
|
+
input.forEach((slug, index) => {
|
|
395
|
+
if (!packSlug(slug)) {
|
|
396
|
+
add(`packs[${index}]`, `must be a pack slug: lowercase letters, digits and single hyphens, at most ${APP_MANIFEST_LIMITS.packSlugMax} characters, as in the pack's /os/pack/<slug> link.`);
|
|
397
|
+
ok = false;
|
|
398
|
+
}
|
|
399
|
+
else if (packs.includes(slug)) {
|
|
400
|
+
add(`packs[${index}]`, "repeats another pack; list each pack once.");
|
|
401
|
+
ok = false;
|
|
402
|
+
}
|
|
403
|
+
else
|
|
404
|
+
packs.push(slug);
|
|
405
|
+
});
|
|
406
|
+
return ok ? packs : null;
|
|
407
|
+
}
|
|
408
|
+
function inspectNetwork(input, add) {
|
|
409
|
+
if (input === undefined)
|
|
410
|
+
return [];
|
|
411
|
+
if (!Array.isArray(input)) {
|
|
412
|
+
add("network", 'must be a list of origins, such as ["https://cdn.example.com"].');
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
let ok = true;
|
|
416
|
+
if (input.length > APP_MANIFEST_LIMITS.network) {
|
|
417
|
+
add("network", `may declare at most ${APP_MANIFEST_LIMITS.network} origins.`);
|
|
418
|
+
ok = false;
|
|
419
|
+
}
|
|
420
|
+
const origins = [];
|
|
421
|
+
input.forEach((value, index) => {
|
|
422
|
+
const checked = networkOriginCheck(value);
|
|
423
|
+
if (checked.origin === null) {
|
|
424
|
+
add(`network[${index}]`, checked.problem);
|
|
425
|
+
ok = false;
|
|
426
|
+
}
|
|
427
|
+
else if (origins.includes(checked.origin)) {
|
|
428
|
+
add(`network[${index}]`, "repeats another origin; list each origin once.");
|
|
429
|
+
ok = false;
|
|
430
|
+
}
|
|
431
|
+
else
|
|
432
|
+
origins.push(checked.origin);
|
|
433
|
+
});
|
|
434
|
+
return ok ? origins.sort(compareText) : null;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Things `parseManifest` accepts but a developer should change, as `os check` prints them without failing: today only a
|
|
438
|
+
* schema version 2 `store.category` of "tool" or "toy", which is read as "app".
|
|
439
|
+
*/
|
|
440
|
+
export function manifestNotices(input) {
|
|
441
|
+
if (!record(input) || input.schemaVersion !== 2 || !record(input.store) || !legacyCategory(input.store.category))
|
|
442
|
+
return [];
|
|
443
|
+
return [{ path: "store.category", message: `"${input.store.category}" is read as "app"; write "app" (VibeStore lists apps as "game" or "app").` }];
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Every problem with a manifest, or `[]` when `parseManifest` accepts it. For schema version 3 this is every problem,
|
|
447
|
+
* one per field path, in field order. Schema versions 1 and 2 keep their single legacy message (`path` `""`).
|
|
448
|
+
*/
|
|
449
|
+
export function checkManifest(input) {
|
|
450
|
+
if (record(input) && input.schemaVersion === 3)
|
|
451
|
+
return inspectV3(input).problems;
|
|
452
|
+
try {
|
|
453
|
+
parseManifest(input);
|
|
454
|
+
return [];
|
|
455
|
+
}
|
|
456
|
+
catch (error) {
|
|
457
|
+
return [{ path: "", message: error.message }];
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Accepts schema version 1 exactly as before, schema version 2 with its window and store listing, and schema
|
|
462
|
+
* version 3 (no constant fields; optional `packs`, `cards` and `network`). Unknown fields are rejected at every
|
|
463
|
+
* level. Throws the first problem; `checkManifest` lists them all.
|
|
464
|
+
*/
|
|
136
465
|
export function parseManifest(input) {
|
|
137
466
|
if (!record(input))
|
|
138
467
|
throw Error("vibemarket.json must be an object.");
|
|
468
|
+
if (input.schemaVersion === 3) {
|
|
469
|
+
const { manifest, problems } = inspectV3(input);
|
|
470
|
+
if (!manifest)
|
|
471
|
+
throw Error(manifestProblemText(problems[0]));
|
|
472
|
+
return manifest;
|
|
473
|
+
}
|
|
139
474
|
return input.schemaVersion === 2 ? parseV2(input) : parseV1(input);
|
|
140
475
|
}
|
package/dist/os.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type Card, type Pack, type PackSummary, type Player } from "./app-wire.ts";
|
|
2
|
+
import { type CaptureResult } from "./capture.ts";
|
|
3
|
+
export type { Card, OsErrorCode, Pack, PackCard, PackSummary, Player, Rarity, SignedInPlayer } from "./app-wire.ts";
|
|
4
|
+
export { OS_ERROR_CODES } from "./app-wire.ts";
|
|
5
|
+
/** The SDK version a 0.5 client reports in `host.hello`. */
|
|
6
|
+
export declare const OS_SDK_VERSION = "0.5.1";
|
|
7
|
+
export { OsError } from "./app-wire.ts";
|
|
8
|
+
export type OsSize = Readonly<{
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}>;
|
|
12
|
+
export interface Os {
|
|
13
|
+
/** false while the window is minimized or behind another window */
|
|
14
|
+
readonly active: boolean;
|
|
15
|
+
readonly size: OsSize;
|
|
16
|
+
/** a guest's save lives only while the window is open */
|
|
17
|
+
readonly guest: boolean;
|
|
18
|
+
/** hide the host's loading screen */
|
|
19
|
+
ready(): Promise<void>;
|
|
20
|
+
/** 0 to 1 while loading; keeps a long load inside the host's readiness rule */
|
|
21
|
+
progress(fraction: number): void;
|
|
22
|
+
/** the app's save, or null */
|
|
23
|
+
load<T = unknown>(): Promise<T | null>;
|
|
24
|
+
/** any JSON value up to 1 MiB; calls made sooner than the host accepts are coalesced into one write */
|
|
25
|
+
save(value: unknown): Promise<void>;
|
|
26
|
+
/** the player's cards the manifest permits; `cards("rooftop-rats")` filters to one pack */
|
|
27
|
+
cards(pack?: string): Promise<Card[]>;
|
|
28
|
+
/** called with the whole current list whenever it changes; returns unsubscribe */
|
|
29
|
+
onCards(listener: (cards: Card[]) => void): () => void;
|
|
30
|
+
packs(): Promise<PackSummary[]>;
|
|
31
|
+
/** any public pack's face (name, cover, cards with art), in pack order; holdings only come from `cards()` */
|
|
32
|
+
pack(id: string): Promise<Pack>;
|
|
33
|
+
/** the host opens any public pack in VibeMarket; needs a click in the app */
|
|
34
|
+
showPack(id: string): Promise<void>;
|
|
35
|
+
/** the host opens that card in its pack's page; needs a click in the app (0.5.1 hosts) */
|
|
36
|
+
showCard(pack: string, cardId: string): Promise<void>;
|
|
37
|
+
/** open an app link (`vmos://pack/<slug>`, `vmos://card/<slug>/<cardId>`, `https://vibechain.com/os/pack/<slug>`); needs a click */
|
|
38
|
+
open(link: string): Promise<void>;
|
|
39
|
+
/** who is playing: handle, name and picture, or `{ guest: true }`; plus a 5-minute token for your own server with `network` */
|
|
40
|
+
player(): Promise<Player>;
|
|
41
|
+
finish(result: {
|
|
42
|
+
score: number;
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
maximize(on?: boolean): Promise<void>;
|
|
45
|
+
fullscreen(on?: boolean): Promise<void>;
|
|
46
|
+
onPause(listener: () => void): () => void;
|
|
47
|
+
onResume(listener: () => void): () => void;
|
|
48
|
+
onResize(listener: (size: OsSize) => void): () => void;
|
|
49
|
+
/**
|
|
50
|
+
* The desktop camera asks for a picture of the app. By default the SDK sends the largest visible canvas; register a handler
|
|
51
|
+
* to draw one yourself (DOM apps, a custom view). It may return a canvas, a PNG/JPEG/WebP data URL (at most 1,000,000
|
|
52
|
+
* characters) or null, now or as a promise. The latest handler wins; returns unsubscribe.
|
|
53
|
+
*/
|
|
54
|
+
onCapture?(handler: () => CaptureResult | Promise<CaptureResult>): () => void;
|
|
55
|
+
/** release the port */
|
|
56
|
+
close(): void;
|
|
57
|
+
}
|
|
58
|
+
/** Connect to the host: the handshake, then hello on a protocol 2 host. Call once, early. */
|
|
59
|
+
export declare function connect(options?: {
|
|
60
|
+
signal?: AbortSignal;
|
|
61
|
+
}): Promise<Os>;
|
|
62
|
+
/** The app API over an admitted port. `href` is the frame's own URL, against which art paths resolve. */
|
|
63
|
+
export declare function createOs(port: MessagePort, session: string, protocol: 1 | 2, href: string): Promise<Os>;
|