@orbit-work/oem-sdk 0.1.8 → 0.1.10

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.
@@ -1,14 +1,33 @@
1
1
  #!/usr/bin/env node
2
2
  import { realpath, readFile, stat } from 'fs/promises';
3
3
  import { resolve, extname, sep, dirname } from 'path';
4
- import { gzipSync } from 'zlib';
4
+ import { gzipSync, inflateSync } from 'zlib';
5
+ import { CHAT_MARK_ASSET_KEYS, UNIFIED_NEUTRAL_TOKENS, BRAND_ACTION_TOKENS, BRAND_LOGIN_TOKENS, ds2ContrastRatio, checkOemPrimary, isOrbitworkFontScale, ORBITWORK_FONT_SCALES } from '@orbit-work/ui/appearance';
5
6
  import { init, parse } from 'es-module-lexer';
6
7
  import { transform } from 'esbuild';
7
8
  import { validateDictionary } from '@orbit-work/ui/locale';
8
- import { UNIFIED_NEUTRAL_TOKENS, BRAND_ACTION_TOKENS, isOrbitworkFontScale, ORBITWORK_FONT_SCALES, ds2ContrastRatio } from '@orbit-work/ui/appearance';
9
9
  import { WORKBENCH_SLOT_DECLARATIONS, WORKBENCH_KEYED_SLOT_KEYS } from '@orbit-work/ui/slot/core';
10
10
 
11
11
  var BRAND_MANIFEST_SCHEMA = "@orbit-work/oem-sdk/manifest@1";
12
+ var TRAY_VARIANT_PATHS = {
13
+ macos: { "1x": "./macos/trayTemplate.png", "2x": "./macos/trayTemplate@2x.png" },
14
+ windows: {
15
+ "16": "./windows/tray-16.png",
16
+ "20": "./windows/tray-20.png",
17
+ "24": "./windows/tray-24.png",
18
+ "32": "./windows/tray-32.png"
19
+ },
20
+ linux: {
21
+ "16": "./linux/tray-16.png",
22
+ "22": "./linux/tray-22.png",
23
+ "24": "./linux/tray-24.png",
24
+ "32": "./linux/tray-32.png",
25
+ "48": "./linux/tray-48.png",
26
+ "64": "./linux/tray-64.png",
27
+ "128": "./linux/tray-128.png"
28
+ }
29
+ };
30
+ var TRAY_SOURCE_PATH = "./assets/tray-source.png";
12
31
  var ROOT_KEYS = /* @__PURE__ */ new Set([
13
32
  "$schema",
14
33
  "id",
@@ -18,6 +37,7 @@ var ROOT_KEYS = /* @__PURE__ */ new Set([
18
37
  "permissions",
19
38
  "entry",
20
39
  "identity",
40
+ "theme",
21
41
  "tokens",
22
42
  "typography",
23
43
  "fontScale",
@@ -29,16 +49,19 @@ var ROOT_KEYS = /* @__PURE__ */ new Set([
29
49
  "contributes"
30
50
  ]);
31
51
  var IDENTITY_KEYS = /* @__PURE__ */ new Set(["productName", "appId", "versionChannel", "protocolScheme", "userDataNamespace"]);
32
- var ASSET_KEYS = /* @__PURE__ */ new Set(["appIcon", "tray", "logo", "loginKV"]);
52
+ var ASSET_KEYS = /* @__PURE__ */ new Set(["appIcon", "tray", "trayVariants", "logo", "loginKV", ...CHAT_MARK_ASSET_KEYS]);
33
53
  var MODE_KEYS = /* @__PURE__ */ new Set(["light", "dark"]);
54
+ var THEME_KEYS = /* @__PURE__ */ new Set(["primary", "signal", "allowDangerHue"]);
55
+ var HEX6 = /^#[0-9a-f]{6}$/i;
34
56
  var CONTRIBUTES_KEYS = /* @__PURE__ */ new Set(["slots"]);
35
57
  var NETWORK_KEYS = /* @__PURE__ */ new Set(["allowedOrigins"]);
36
58
  var PERMISSIONS_KEYS = /* @__PURE__ */ new Set(["microphoneUsage"]);
37
59
  var TYPOGRAPHY_KEYS = /* @__PURE__ */ new Set(["fontSans", "fontMono"]);
38
- var APPEARANCE_KEYS = /* @__PURE__ */ new Set(["homeBackdrop"]);
39
- var BRANDING_KEYS = /* @__PURE__ */ new Set(["productName", "companyName", "claim", "claimNote", "slogan"]);
60
+ var APPEARANCE_KEYS = /* @__PURE__ */ new Set(["homeBackdrop", "login"]);
61
+ var LOGIN_APPEARANCE_KEYS = /* @__PURE__ */ new Set(["claimColor", "claimNoteColor", "accentColor", "scrim"]);
62
+ var BRANDING_KEYS = /* @__PURE__ */ new Set(["productName", "companyName", "claim", "claimHighlight", "claimNote", "slogan"]);
40
63
  var SLOT_COMMON_KEYS = /* @__PURE__ */ new Set(["name"]);
41
- var BRAND_TOKEN_NAMES = /* @__PURE__ */ new Set([...UNIFIED_NEUTRAL_TOKENS, ...BRAND_ACTION_TOKENS]);
64
+ var BRAND_TOKEN_NAMES = /* @__PURE__ */ new Set([...UNIFIED_NEUTRAL_TOKENS, ...BRAND_ACTION_TOKENS, ...BRAND_LOGIN_TOKENS]);
42
65
  var SLOT_DECLARATIONS = WORKBENCH_SLOT_DECLARATIONS;
43
66
  var HEX = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
44
67
  var KEBAB_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
@@ -46,7 +69,13 @@ var APP_ID = /^[a-zA-Z][a-zA-Z0-9]*(?:\.[a-zA-Z0-9][a-zA-Z0-9-]*){2,}$/;
46
69
  var PROTOCOL_SCHEME = /^[a-z][a-z0-9+.-]*$/;
47
70
  var SOURCE_ENTRY = /^\.\/src\/.+\.(?:[cm]?js|[jt]sx?)$/;
48
71
  var WINDOWS_DEVICE_NAME = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\..*)?$/i;
49
- var OFFICIAL_APP_ID = "ai.orbit.desktop";
72
+ var RESERVED_APP_IDS = /* @__PURE__ */ new Set([
73
+ "com.orbitwork.desktop",
74
+ "com.orbitwork.desktop-debug",
75
+ "com.orbitwork.desktop-oem-devhost",
76
+ "com.orbitwork.desktop-oem-devhost.sandbox",
77
+ "com.orbitwork.desktop-oem-devhost.workbench"
78
+ ]);
50
79
  var OFFICIAL_PRODUCT_NAMES = /* @__PURE__ */ new Set(["orbitwork"]);
51
80
  var RESERVED_VERSION_CHANNELS = /* @__PURE__ */ new Set(["stable", "debug", "latest", "desktop", "macos", "windows", "linux"]);
52
81
  var RESERVED_PROTOCOL_SCHEMES = /* @__PURE__ */ new Set([
@@ -134,7 +163,7 @@ function parseIdentity(value, id, platform) {
134
163
  if (!platform && OFFICIAL_PRODUCT_NAMES.has(productName.toLowerCase())) {
135
164
  throw new Error(`identity.productName is reserved for the official application: ${productName}`);
136
165
  }
137
- if (!platform && appId === OFFICIAL_APP_ID) {
166
+ if (!platform && RESERVED_APP_IDS.has(appId)) {
138
167
  throw new Error(`identity.appId is reserved for the official application: ${appId}`);
139
168
  }
140
169
  if (!platform && productNameNamespace(productName) !== id) {
@@ -146,9 +175,6 @@ function parseIdentity(value, id, platform) {
146
175
  if (!platform && protocolScheme !== id) {
147
176
  throw new Error("identity.protocolScheme must equal manifest id to keep OEM deep links namespaced");
148
177
  }
149
- if (!platform && !appId.endsWith(`.oem.${id}`)) {
150
- throw new Error("identity.appId must end with .oem.<manifest id> to isolate installation and user data");
151
- }
152
178
  if (!platform && value.userDataNamespace !== void 0 && !KEBAB_ID.test(text(value.userDataNamespace, "identity.userDataNamespace", 64))) {
153
179
  throw new Error("identity.userDataNamespace must be lowercase kebab-case");
154
180
  }
@@ -159,25 +185,89 @@ function parseIdentity(value, id, platform) {
159
185
  throw new Error("Platform environment must be stable, debug, or oem-dev");
160
186
  return { productName, appId, versionChannel, protocolScheme, ...userDataNamespace ? { userDataNamespace } : {} };
161
187
  }
188
+ function parseChatMarkAssets(value, partial = false) {
189
+ const result = {};
190
+ for (const key of CHAT_MARK_ASSET_KEYS) {
191
+ if (value[key] !== void 0) result[key] = relativePath(value[key], `assets.${key}`);
192
+ }
193
+ if (!partial) {
194
+ const light = CHAT_MARK_ASSET_KEYS.slice(0, 3);
195
+ const dark = CHAT_MARK_ASSET_KEYS.slice(3);
196
+ for (const group of [light, dark]) {
197
+ if (group.some((key) => result[key]) && group.some((key) => !result[key]))
198
+ throw new Error(`assets chat mark group is incomplete: ${group.join(", ")}`);
199
+ }
200
+ if (dark.some((key) => result[key]) && !result.chatThinkingOrbit)
201
+ throw new Error("assets dark chat marks require the light chat mark group");
202
+ }
203
+ return result;
204
+ }
162
205
  function parseAssets(value) {
163
206
  if (!isRecord(value)) throw new Error("assets must be an object");
164
207
  assertKnownKeys(value, ASSET_KEYS, "assets");
165
208
  const tray = value.tray === void 0 ? void 0 : relativePath(value.tray, "assets.tray");
209
+ const trayVariants = value.trayVariants === void 0 ? void 0 : parseTrayVariants(value.trayVariants);
210
+ if (trayVariants && tray !== TRAY_SOURCE_PATH) {
211
+ throw new Error(`assets.tray must equal ${TRAY_SOURCE_PATH} when assets.trayVariants is present`);
212
+ }
166
213
  const loginKV = value.loginKV === void 0 ? void 0 : relativePath(value.loginKV, "assets.loginKV");
167
214
  return {
215
+ ...parseChatMarkAssets(value),
168
216
  appIcon: relativePath(value.appIcon, "assets.appIcon"),
169
217
  ...tray ? { tray } : {},
218
+ ...trayVariants ? { trayVariants } : {},
170
219
  logo: relativePath(value.logo, "assets.logo"),
171
220
  ...loginKV ? { loginKV } : {}
172
221
  };
173
222
  }
223
+ function parseTrayVariants(value) {
224
+ if (!isRecord(value)) throw new Error("assets.trayVariants must be an object");
225
+ assertKnownKeys(value, new Set(Object.keys(TRAY_VARIANT_PATHS)), "assets.trayVariants");
226
+ const result = {};
227
+ for (const [platform, expected] of Object.entries(TRAY_VARIANT_PATHS)) {
228
+ const variants = value[platform];
229
+ if (!isRecord(variants)) throw new Error(`assets.trayVariants.${platform} must be an object`);
230
+ assertKnownKeys(variants, new Set(Object.keys(expected)), `assets.trayVariants.${platform}`);
231
+ const parsed = {};
232
+ for (const [size, expectedPath] of Object.entries(expected)) {
233
+ const actual = relativePath(variants[size], `assets.trayVariants.${platform}.${size}`);
234
+ if (actual !== expectedPath) {
235
+ throw new Error(`assets.trayVariants.${platform}.${size} must equal ${expectedPath}`);
236
+ }
237
+ parsed[size] = actual;
238
+ }
239
+ result[platform] = parsed;
240
+ }
241
+ return result;
242
+ }
174
243
  function parseAppearance(value) {
175
244
  if (value === void 0) return void 0;
176
245
  if (!isRecord(value)) throw new Error("appearance must be an object");
177
246
  assertKnownKeys(value, APPEARANCE_KEYS, "appearance");
178
247
  if (value.homeBackdrop !== void 0 && typeof value.homeBackdrop !== "boolean")
179
248
  throw new Error("appearance.homeBackdrop must be a boolean");
180
- return value.homeBackdrop === void 0 ? {} : { homeBackdrop: value.homeBackdrop };
249
+ let login;
250
+ if (value.login !== void 0) {
251
+ if (!isRecord(value.login)) throw new Error("appearance.login must be an object");
252
+ assertKnownKeys(value.login, LOGIN_APPEARANCE_KEYS, "appearance.login");
253
+ login = {};
254
+ for (const key of ["claimColor", "claimNoteColor", "accentColor"]) {
255
+ const color = value.login[key];
256
+ if (color !== void 0) {
257
+ if (typeof color !== "string" || color.length !== 7 || !HEX6.test(color))
258
+ throw new Error(`appearance.login.${key} must be an opaque #RRGGBB color`);
259
+ login[key] = color.toLowerCase();
260
+ }
261
+ }
262
+ if (value.login.scrim !== void 0) {
263
+ if (typeof value.login.scrim !== "boolean") throw new Error("appearance.login.scrim must be a boolean");
264
+ login.scrim = value.login.scrim;
265
+ }
266
+ }
267
+ return {
268
+ ...value.homeBackdrop !== void 0 ? { homeBackdrop: value.homeBackdrop } : {},
269
+ ...login ? { login } : {}
270
+ };
181
271
  }
182
272
  function parseBrandCopy(value, path) {
183
273
  if (!isRecord(value)) throw new Error(`${path} must be an object`);
@@ -188,11 +278,14 @@ function parseBrandCopy(value, path) {
188
278
  };
189
279
  for (const [key, limit] of [
190
280
  ["claim", 40],
281
+ ["claimHighlight", 40],
191
282
  ["claimNote", 48],
192
283
  ["slogan", 68]
193
284
  ]) {
194
285
  if (value[key] !== void 0) result[key] = text(value[key], `${path}.${key}`, limit);
195
286
  }
287
+ if (result.claimHighlight && !result.claim?.includes(result.claimHighlight))
288
+ throw new Error(`${path}.claimHighlight must be an exact substring of claim`);
196
289
  return result;
197
290
  }
198
291
  function parseBranding(value) {
@@ -316,6 +409,27 @@ function parseModeTokens(value, path) {
316
409
  }
317
410
  return result;
318
411
  }
412
+ function parseTheme(value) {
413
+ if (value === void 0) return void 0;
414
+ if (!isRecord(value)) throw new Error("theme must be an object");
415
+ assertKnownKeys(value, THEME_KEYS, "theme");
416
+ if (typeof value.primary !== "string" || !HEX6.test(value.primary)) throw new Error("theme.primary must be #RRGGBB");
417
+ const primary = value.primary.toLowerCase();
418
+ let signal;
419
+ if (value.signal !== void 0) {
420
+ if (typeof value.signal !== "string" || !HEX6.test(value.signal)) throw new Error("theme.signal must be #RRGGBB");
421
+ signal = value.signal.toLowerCase();
422
+ const ratio = ds2ContrastRatio(signal, "#fafafb");
423
+ if (ratio < 3) throw new Error(`theme.signal contrast on #FAFAFB is ${ratio.toFixed(2)}:1; expected >= 3:1`);
424
+ }
425
+ if (value.allowDangerHue !== void 0 && typeof value.allowDangerHue !== "boolean") {
426
+ throw new Error("theme.allowDangerHue must be a boolean");
427
+ }
428
+ const allowDangerHue = value.allowDangerHue === true;
429
+ const check = checkOemPrimary(primary);
430
+ if (check.errors.length && !allowDangerHue) throw new Error(`theme.primary: ${check.errors.join("; ")}`);
431
+ return { primary, ...signal ? { signal } : {}, ...allowDangerHue ? { allowDangerHue } : {} };
432
+ }
319
433
  function parseTokens(value) {
320
434
  if (value === void 0) return void 0;
321
435
  if (!isRecord(value)) throw new Error("tokens must be an object");
@@ -404,6 +518,7 @@ function parseBrandManifest(input, options) {
404
518
  const contributes = parseContributes(input.contributes);
405
519
  if ((contributes?.slots.length ?? 0) > 0 && !entry)
406
520
  throw new Error("entry is required when contributes.slots is not empty");
521
+ const theme = parseTheme(input.theme);
407
522
  const tokens = parseTokens(input.tokens);
408
523
  const typography = parseTypography(input.typography);
409
524
  const fontScale = parseFontScale(input.fontScale);
@@ -420,9 +535,6 @@ function parseBrandManifest(input, options) {
420
535
  if (!platform && identity.protocolScheme !== id) {
421
536
  throw new Error("identity.protocolScheme must equal manifest id to keep OEM deep links namespaced");
422
537
  }
423
- if (!platform && !identity.appId.endsWith(`.oem.${id}`)) {
424
- throw new Error("identity.appId must end with .oem.<manifest id> to isolate installation and user data");
425
- }
426
538
  return {
427
539
  ok: true,
428
540
  manifest: {
@@ -434,6 +546,7 @@ function parseBrandManifest(input, options) {
434
546
  ...input.permissions !== void 0 ? { permissions: parsePermissions(input.permissions) } : {},
435
547
  ...entry ? { entry } : {},
436
548
  identity,
549
+ ...theme ? { theme } : {},
437
550
  ...tokens ? { tokens } : {},
438
551
  ...typography ? { typography } : {},
439
552
  ...fontScale ? { fontScale } : {},
@@ -536,7 +649,7 @@ async function assertAsset(packageRoot, relative, kind) {
536
649
  if (!info.isFile()) throw new Error(`assets.${kind} must point to a file`);
537
650
  if (info.size > ASSET_BUDGET) throw new Error(`assets.${kind} exceeds 5 MiB`);
538
651
  const extension = extname(file).toLowerCase();
539
- const allowed = kind === "loginKV" ? /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]) : kind === "logo" ? /* @__PURE__ */ new Set([".svg", ".png", ".webp", ".jpg", ".jpeg"]) : /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg"]);
652
+ const allowed = kind === "loginKV" ? /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]) : kind === "logo" || CHAT_MARK_ASSET_KEYS.includes(kind) ? /* @__PURE__ */ new Set([".svg", ".png", ".webp", ".jpg", ".jpeg"]) : /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg"]);
540
653
  if (!allowed.has(extension)) throw new Error(`assets.${kind} has unsupported extension: ${extension}`);
541
654
  if (kind === "appIcon" || kind === "tray") {
542
655
  const bytes = await readFile(file);
@@ -551,6 +664,83 @@ async function assertAsset(packageRoot, relative, kind) {
551
664
  }
552
665
  return file;
553
666
  }
667
+ var PNG_CRC_TABLE = (() => {
668
+ const table = new Uint32Array(256);
669
+ for (let index = 0; index < table.length; index += 1) {
670
+ let value = index;
671
+ for (let bit = 0; bit < 8; bit += 1) value = value & 1 ? 3988292384 ^ value >>> 1 : value >>> 1;
672
+ table[index] = value >>> 0;
673
+ }
674
+ return table;
675
+ })();
676
+ function pngCrc32(bytes) {
677
+ let crc = 4294967295;
678
+ for (const byte of bytes) crc = PNG_CRC_TABLE[(crc ^ byte) & 255] ^ crc >>> 8;
679
+ return (crc ^ 4294967295) >>> 0;
680
+ }
681
+ function strictPngDimensions(bytes) {
682
+ if (bytes.length < 45 || bytes.toString("hex", 0, 8) !== "89504e470d0a1a0a") return null;
683
+ let offset = 8;
684
+ let dimensions = null;
685
+ const idat = [];
686
+ while (offset + 12 <= bytes.length) {
687
+ const length = bytes.readUInt32BE(offset);
688
+ const end = offset + 12 + length;
689
+ if (end > bytes.length) return null;
690
+ const kind = bytes.toString("ascii", offset + 4, offset + 8);
691
+ if (pngCrc32(bytes.subarray(offset + 4, offset + 8 + length)) !== bytes.readUInt32BE(offset + 8 + length))
692
+ return null;
693
+ if (!dimensions) {
694
+ if (kind !== "IHDR" || length !== 13) return null;
695
+ const width = bytes.readUInt32BE(offset + 8);
696
+ const height = bytes.readUInt32BE(offset + 12);
697
+ if (!width || !height || bytes[offset + 18] !== 0 || bytes[offset + 19] !== 0 || bytes[offset + 20] > 1)
698
+ return null;
699
+ dimensions = { width, height };
700
+ } else if (kind === "IDAT") {
701
+ idat.push(bytes.subarray(offset + 8, offset + 8 + length));
702
+ } else if (kind === "IEND") {
703
+ if (length !== 0 || idat.length === 0 || end !== bytes.length) return null;
704
+ try {
705
+ if (inflateSync(Buffer.concat(idat)).length === 0) return null;
706
+ } catch {
707
+ return null;
708
+ }
709
+ return dimensions;
710
+ }
711
+ offset = end;
712
+ }
713
+ return null;
714
+ }
715
+ async function assertTrayVariants(packageRoot, variants) {
716
+ const checked = [];
717
+ for (const [platform, expected] of Object.entries(TRAY_VARIANT_PATHS)) {
718
+ for (const [label, expectedPath] of Object.entries(expected)) {
719
+ const relative = variants[platform][label];
720
+ const field = `assets.trayVariants.${platform}.${label}`;
721
+ if (relative !== expectedPath) throw new Error(`${field} must equal ${expectedPath}`);
722
+ let file;
723
+ try {
724
+ file = await resolvePackageFile(packageRoot, relative, field);
725
+ } catch (error) {
726
+ if (error instanceof Error && "code" in error && error.code === "ENOENT")
727
+ throw new Error(`${field} file is missing: ${relative}`);
728
+ throw error;
729
+ }
730
+ const info = await stat(file);
731
+ if (!info.isFile()) throw new Error(`${field} must point to a file`);
732
+ if (info.size > ASSET_BUDGET) throw new Error(`${field} exceeds 5 MiB`);
733
+ const dimensions = strictPngDimensions(await readFile(file));
734
+ const size = platform === "macos" ? label === "1x" ? 16 : 32 : Number(label);
735
+ if (!dimensions) throw new Error(`${field} must be a valid PNG`);
736
+ if (dimensions.width !== size || dimensions.height !== size) {
737
+ throw new Error(`${field} must be ${size}x${size}, got ${dimensions.width}x${dimensions.height}`);
738
+ }
739
+ checked.push(relative);
740
+ }
741
+ }
742
+ return checked;
743
+ }
554
744
  function pngDimensions(bytes) {
555
745
  if (bytes.length < 24 || bytes.toString("hex", 0, 8) !== "89504e470d0a1a0a") return null;
556
746
  return { width: bytes.readUInt32BE(16), height: bytes.readUInt32BE(20) };
@@ -726,10 +916,14 @@ async function auditBrandPackage(manifestFile2, options = {}) {
726
916
  if (!parsed.ok) throw new Error(`manifest contract failed: ${parsed.error}`);
727
917
  const manifest = parsed.manifest;
728
918
  const checkedAssets = [];
729
- for (const [kind, relative] of Object.entries(manifest.assets)) {
919
+ const assetEntries = Object.entries(manifest.assets).filter(([kind]) => kind !== "trayVariants");
920
+ for (const [kind, relative] of assetEntries) {
730
921
  await assertAsset(packageRoot, relative, kind);
731
922
  checkedAssets.push(relative);
732
923
  }
924
+ if (manifest.assets.trayVariants) {
925
+ checkedAssets.push(...await assertTrayVariants(packageRoot, manifest.assets.trayVariants));
926
+ }
733
927
  let entryGzipBytes = 0;
734
928
  let checkedModules = [];
735
929
  const checkedLocales = manifest.locales ? await auditLocaleDictionaries(packageRoot, manifest.locales) : [];