@orbit-work/oem-sdk 0.1.9 → 0.1.11

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/dist/audit.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { realpath, readFile, stat } from 'fs/promises';
2
2
  import { resolve, extname, sep, dirname } from 'path';
3
3
  import { gzipSync, inflateSync } from 'zlib';
4
+ 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';
4
5
  import { init, parse } from 'es-module-lexer';
5
6
  import { transform } from 'esbuild';
6
7
  import { validateDictionary } from '@orbit-work/ui/locale';
7
- import { UNIFIED_NEUTRAL_TOKENS, BRAND_ACTION_TOKENS, ds2ContrastRatio, checkOemPrimary, isOrbitworkFontScale, ORBITWORK_FONT_SCALES } from '@orbit-work/ui/appearance';
8
8
  import { WORKBENCH_SLOT_DECLARATIONS, WORKBENCH_KEYED_SLOT_KEYS } from '@orbit-work/ui/slot/core';
9
9
 
10
10
  // src/audit-brand.ts
@@ -49,7 +49,7 @@ var ROOT_KEYS = /* @__PURE__ */ new Set([
49
49
  "contributes"
50
50
  ]);
51
51
  var IDENTITY_KEYS = /* @__PURE__ */ new Set(["productName", "appId", "versionChannel", "protocolScheme", "userDataNamespace"]);
52
- var ASSET_KEYS = /* @__PURE__ */ new Set(["appIcon", "tray", "trayVariants", "logo", "loginKV"]);
52
+ var ASSET_KEYS = /* @__PURE__ */ new Set(["appIcon", "tray", "trayVariants", "logo", "loginLogo", "loginKV", ...CHAT_MARK_ASSET_KEYS]);
53
53
  var MODE_KEYS = /* @__PURE__ */ new Set(["light", "dark"]);
54
54
  var THEME_KEYS = /* @__PURE__ */ new Set(["primary", "signal", "allowDangerHue"]);
55
55
  var HEX6 = /^#[0-9a-f]{6}$/i;
@@ -57,11 +57,11 @@ var CONTRIBUTES_KEYS = /* @__PURE__ */ new Set(["slots"]);
57
57
  var NETWORK_KEYS = /* @__PURE__ */ new Set(["allowedOrigins"]);
58
58
  var PERMISSIONS_KEYS = /* @__PURE__ */ new Set(["microphoneUsage"]);
59
59
  var TYPOGRAPHY_KEYS = /* @__PURE__ */ new Set(["fontSans", "fontMono"]);
60
- var APPEARANCE_KEYS = /* @__PURE__ */ new Set(["homeBackdrop", "login"]);
61
- var LOGIN_APPEARANCE_KEYS = /* @__PURE__ */ new Set(["claimColor", "claimNoteColor", "accentColor", "scrim"]);
60
+ var APPEARANCE_KEYS = /* @__PURE__ */ new Set(["homeBackdrop", "homeLogo", "login"]);
61
+ var LOGIN_APPEARANCE_KEYS = /* @__PURE__ */ new Set(["brandName", "claimColor", "claimNoteColor", "accentColor", "scrim"]);
62
62
  var BRANDING_KEYS = /* @__PURE__ */ new Set(["productName", "companyName", "claim", "claimHighlight", "claimNote", "slogan"]);
63
63
  var SLOT_COMMON_KEYS = /* @__PURE__ */ new Set(["name"]);
64
- 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]);
65
65
  var SLOT_DECLARATIONS = WORKBENCH_SLOT_DECLARATIONS;
66
66
  var HEX = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
67
67
  var KEBAB_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
@@ -185,6 +185,23 @@ function parseIdentity(value, id, platform) {
185
185
  throw new Error("Platform environment must be stable, debug, or oem-dev");
186
186
  return { productName, appId, versionChannel, protocolScheme, ...userDataNamespace ? { userDataNamespace } : {} };
187
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
+ }
188
205
  function parseAssets(value) {
189
206
  if (!isRecord(value)) throw new Error("assets must be an object");
190
207
  assertKnownKeys(value, ASSET_KEYS, "assets");
@@ -195,10 +212,12 @@ function parseAssets(value) {
195
212
  }
196
213
  const loginKV = value.loginKV === void 0 ? void 0 : relativePath(value.loginKV, "assets.loginKV");
197
214
  return {
215
+ ...parseChatMarkAssets(value),
198
216
  appIcon: relativePath(value.appIcon, "assets.appIcon"),
199
217
  ...tray ? { tray } : {},
200
218
  ...trayVariants ? { trayVariants } : {},
201
219
  logo: relativePath(value.logo, "assets.logo"),
220
+ ...value.loginLogo !== void 0 ? { loginLogo: relativePath(value.loginLogo, "assets.loginLogo") } : {},
202
221
  ...loginKV ? { loginKV } : {}
203
222
  };
204
223
  }
@@ -228,11 +247,32 @@ function parseAppearance(value) {
228
247
  assertKnownKeys(value, APPEARANCE_KEYS, "appearance");
229
248
  if (value.homeBackdrop !== void 0 && typeof value.homeBackdrop !== "boolean")
230
249
  throw new Error("appearance.homeBackdrop must be a boolean");
250
+ let homeLogo;
251
+ if (value.homeLogo !== void 0) {
252
+ if (!isRecord(value.homeLogo)) throw new Error("appearance.homeLogo must be an object");
253
+ assertKnownKeys(value.homeLogo, /* @__PURE__ */ new Set(["placement", "size"]), "appearance.homeLogo");
254
+ const { placement, size } = value.homeLogo;
255
+ if (placement !== void 0) {
256
+ if (placement !== "inline" && placement !== "top")
257
+ throw new Error("appearance.homeLogo.placement must be inline or top");
258
+ }
259
+ if (size !== void 0) {
260
+ if (placement !== "top") throw new Error("appearance.homeLogo.size requires placement top");
261
+ if (typeof size !== "number" || !Number.isFinite(size) || size < 16 || size > 500)
262
+ throw new Error("appearance.homeLogo.size must be a number between 16 and 500");
263
+ }
264
+ homeLogo = placement === "top" ? { placement, ...size !== void 0 ? { size } : {} } : placement === "inline" ? { placement } : {};
265
+ }
231
266
  let login;
232
267
  if (value.login !== void 0) {
233
268
  if (!isRecord(value.login)) throw new Error("appearance.login must be an object");
234
269
  assertKnownKeys(value.login, LOGIN_APPEARANCE_KEYS, "appearance.login");
235
270
  login = {};
271
+ if (value.login.brandName !== void 0) {
272
+ if (typeof value.login.brandName !== "string" || value.login.brandName.trim().length > 64)
273
+ throw new Error("appearance.login.brandName must be a string of at most 64 characters");
274
+ login.brandName = value.login.brandName.trim();
275
+ }
236
276
  for (const key of ["claimColor", "claimNoteColor", "accentColor"]) {
237
277
  const color = value.login[key];
238
278
  if (color !== void 0) {
@@ -248,6 +288,7 @@ function parseAppearance(value) {
248
288
  }
249
289
  return {
250
290
  ...value.homeBackdrop !== void 0 ? { homeBackdrop: value.homeBackdrop } : {},
291
+ ...homeLogo ? { homeLogo } : {},
251
292
  ...login ? { login } : {}
252
293
  };
253
294
  }
@@ -631,7 +672,7 @@ async function assertAsset(packageRoot, relative, kind) {
631
672
  if (!info.isFile()) throw new Error(`assets.${kind} must point to a file`);
632
673
  if (info.size > ASSET_BUDGET) throw new Error(`assets.${kind} exceeds 5 MiB`);
633
674
  const extension = extname(file).toLowerCase();
634
- 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"]);
675
+ const allowed = kind === "loginKV" ? /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]) : kind === "logo" || kind === "loginLogo" || CHAT_MARK_ASSET_KEYS.includes(kind) ? /* @__PURE__ */ new Set([".svg", ".png", ".webp", ".jpg", ".jpeg"]) : /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg"]);
635
676
  if (!allowed.has(extension)) throw new Error(`assets.${kind} has unsupported extension: ${extension}`);
636
677
  if (kind === "appIcon" || kind === "tray") {
637
678
  const bytes = await readFile(file);
@@ -670,12 +711,14 @@ function strictPngDimensions(bytes) {
670
711
  const end = offset + 12 + length;
671
712
  if (end > bytes.length) return null;
672
713
  const kind = bytes.toString("ascii", offset + 4, offset + 8);
673
- if (pngCrc32(bytes.subarray(offset + 4, offset + 8 + length)) !== bytes.readUInt32BE(offset + 8 + length)) return null;
714
+ if (pngCrc32(bytes.subarray(offset + 4, offset + 8 + length)) !== bytes.readUInt32BE(offset + 8 + length))
715
+ return null;
674
716
  if (!dimensions) {
675
717
  if (kind !== "IHDR" || length !== 13) return null;
676
718
  const width = bytes.readUInt32BE(offset + 8);
677
719
  const height = bytes.readUInt32BE(offset + 12);
678
- if (!width || !height || bytes[offset + 18] !== 0 || bytes[offset + 19] !== 0 || bytes[offset + 20] > 1) return null;
720
+ if (!width || !height || bytes[offset + 18] !== 0 || bytes[offset + 19] !== 0 || bytes[offset + 20] > 1)
721
+ return null;
679
722
  dimensions = { width, height };
680
723
  } else if (kind === "IDAT") {
681
724
  idat.push(bytes.subarray(offset + 8, offset + 8 + length));
@@ -703,7 +746,8 @@ async function assertTrayVariants(packageRoot, variants) {
703
746
  try {
704
747
  file = await resolvePackageFile(packageRoot, relative, field);
705
748
  } catch (error) {
706
- if (error instanceof Error && "code" in error && error.code === "ENOENT") throw new Error(`${field} file is missing: ${relative}`);
749
+ if (error instanceof Error && "code" in error && error.code === "ENOENT")
750
+ throw new Error(`${field} file is missing: ${relative}`);
707
751
  throw error;
708
752
  }
709
753
  const info = await stat(file);