@orbit-work/oem-sdk 0.1.7 → 0.1.9
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-brand.js +231 -48
- package/dist/audit-brand.js.map +1 -1
- package/dist/audit.d.ts +40 -1
- package/dist/audit.js +231 -48
- package/dist/audit.js.map +1 -1
- package/dist/{chunk-YMKYAM23.js → chunk-C4G3TUO6.js} +2 -2
- package/dist/{chunk-YMKYAM23.js.map → chunk-C4G3TUO6.js.map} +1 -1
- package/dist/{chunk-ZOURSTKZ.js → chunk-I3RBZK2G.js} +161 -45
- package/dist/chunk-I3RBZK2G.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/manifest.d.ts +70 -3
- package/dist/manifest.js +1 -1
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.js +2 -2
- package/package.json +2 -2
- package/schema/orbit-brand.schema.json +124 -15
- package/dist/chunk-ZOURSTKZ.js.map +0 -1
package/dist/audit.js
CHANGED
|
@@ -1,14 +1,33 @@
|
|
|
1
1
|
import { realpath, readFile, stat } from 'fs/promises';
|
|
2
2
|
import { resolve, extname, sep, dirname } from 'path';
|
|
3
|
-
import { gzipSync } from 'zlib';
|
|
3
|
+
import { gzipSync, inflateSync } from 'zlib';
|
|
4
4
|
import { init, parse } from 'es-module-lexer';
|
|
5
5
|
import { transform } from 'esbuild';
|
|
6
6
|
import { validateDictionary } from '@orbit-work/ui/locale';
|
|
7
|
-
import { UNIFIED_NEUTRAL_TOKENS, BRAND_ACTION_TOKENS, isOrbitworkFontScale, ORBITWORK_FONT_SCALES
|
|
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
|
|
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,9 +37,11 @@ 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",
|
|
44
|
+
"appearance",
|
|
24
45
|
"assets",
|
|
25
46
|
"branding",
|
|
26
47
|
"locales",
|
|
@@ -28,13 +49,17 @@ var ROOT_KEYS = /* @__PURE__ */ new Set([
|
|
|
28
49
|
"contributes"
|
|
29
50
|
]);
|
|
30
51
|
var IDENTITY_KEYS = /* @__PURE__ */ new Set(["productName", "appId", "versionChannel", "protocolScheme", "userDataNamespace"]);
|
|
31
|
-
var ASSET_KEYS = /* @__PURE__ */ new Set(["appIcon", "tray", "logo", "loginKV"]);
|
|
52
|
+
var ASSET_KEYS = /* @__PURE__ */ new Set(["appIcon", "tray", "trayVariants", "logo", "loginKV"]);
|
|
32
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;
|
|
33
56
|
var CONTRIBUTES_KEYS = /* @__PURE__ */ new Set(["slots"]);
|
|
34
57
|
var NETWORK_KEYS = /* @__PURE__ */ new Set(["allowedOrigins"]);
|
|
35
58
|
var PERMISSIONS_KEYS = /* @__PURE__ */ new Set(["microphoneUsage"]);
|
|
36
59
|
var TYPOGRAPHY_KEYS = /* @__PURE__ */ new Set(["fontSans", "fontMono"]);
|
|
37
|
-
var
|
|
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"]);
|
|
38
63
|
var SLOT_COMMON_KEYS = /* @__PURE__ */ new Set(["name"]);
|
|
39
64
|
var BRAND_TOKEN_NAMES = /* @__PURE__ */ new Set([...UNIFIED_NEUTRAL_TOKENS, ...BRAND_ACTION_TOKENS]);
|
|
40
65
|
var SLOT_DECLARATIONS = WORKBENCH_SLOT_DECLARATIONS;
|
|
@@ -44,18 +69,15 @@ var APP_ID = /^[a-zA-Z][a-zA-Z0-9]*(?:\.[a-zA-Z0-9][a-zA-Z0-9-]*){2,}$/;
|
|
|
44
69
|
var PROTOCOL_SCHEME = /^[a-z][a-z0-9+.-]*$/;
|
|
45
70
|
var SOURCE_ENTRY = /^\.\/src\/.+\.(?:[cm]?js|[jt]sx?)$/;
|
|
46
71
|
var WINDOWS_DEVICE_NAME = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\..*)?$/i;
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"latest",
|
|
54
|
-
"desktop",
|
|
55
|
-
"macos",
|
|
56
|
-
"windows",
|
|
57
|
-
"linux"
|
|
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"
|
|
58
78
|
]);
|
|
79
|
+
var OFFICIAL_PRODUCT_NAMES = /* @__PURE__ */ new Set(["orbitwork"]);
|
|
80
|
+
var RESERVED_VERSION_CHANNELS = /* @__PURE__ */ new Set(["stable", "debug", "latest", "desktop", "macos", "windows", "linux"]);
|
|
59
81
|
var RESERVED_PROTOCOL_SCHEMES = /* @__PURE__ */ new Set([
|
|
60
82
|
"about",
|
|
61
83
|
"blob",
|
|
@@ -118,32 +140,30 @@ function relativePath(value, path) {
|
|
|
118
140
|
}
|
|
119
141
|
function parseIdentity(value, id, platform) {
|
|
120
142
|
if (!isRecord(value)) throw new Error("identity must be an object");
|
|
121
|
-
assertKnownKeys(value, IDENTITY_KEYS, "identity");
|
|
143
|
+
assertKnownKeys(value, platform ? /* @__PURE__ */ new Set([...IDENTITY_KEYS, "userDataNamespace"]) : IDENTITY_KEYS, "identity");
|
|
122
144
|
const productName = text(value.productName, "identity.productName", 64);
|
|
123
|
-
const appId = text(value.appId, "identity.appId", 160);
|
|
145
|
+
const appId = text(value.appId, "identity.appId", platform ? 200 : 160);
|
|
124
146
|
const versionChannel = text(value.versionChannel, "identity.versionChannel", 64);
|
|
125
147
|
const protocolScheme = text(value.protocolScheme, "identity.protocolScheme", 64);
|
|
126
|
-
if (
|
|
127
|
-
throw new Error("identity.
|
|
128
|
-
}
|
|
129
|
-
if (!APP_ID.test(appId)) throw new Error("identity.appId must be a reverse-DNS identifier");
|
|
148
|
+
if (!(platform ? /^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/ : APP_ID).test(appId))
|
|
149
|
+
throw new Error("identity.appId must be a reverse-DNS identifier");
|
|
130
150
|
if (!KEBAB_ID.test(versionChannel)) throw new Error("identity.versionChannel must be kebab-case");
|
|
131
151
|
if (!platform && RESERVED_VERSION_CHANNELS.has(versionChannel)) {
|
|
132
152
|
throw new Error(`identity.versionChannel is reserved: ${versionChannel}`);
|
|
133
153
|
}
|
|
134
|
-
if (!PROTOCOL_SCHEME.test(protocolScheme)) {
|
|
154
|
+
if (!(platform ? /^[a-z][a-z0-9+.-]{1,62}$/ : PROTOCOL_SCHEME).test(protocolScheme)) {
|
|
135
155
|
throw new Error("identity.protocolScheme must be a lowercase URI scheme beginning with a letter");
|
|
136
156
|
}
|
|
137
|
-
if (RESERVED_PROTOCOL_SCHEMES.has(protocolScheme)) {
|
|
157
|
+
if (RESERVED_PROTOCOL_SCHEMES.has(protocolScheme) && !(platform && protocolScheme === "orbit")) {
|
|
138
158
|
throw new Error(`identity.protocolScheme is reserved: ${protocolScheme}`);
|
|
139
159
|
}
|
|
140
160
|
if (hasUnsafeProductNameCharacter(productName) || /[. ]$/.test(productName) || productName === "." || productName === ".." || WINDOWS_DEVICE_NAME.test(productName)) {
|
|
141
161
|
throw new Error("identity.productName must be safe for macOS, Windows, Linux, and release artifact paths");
|
|
142
162
|
}
|
|
143
|
-
if (OFFICIAL_PRODUCT_NAMES.has(productName.toLowerCase())) {
|
|
163
|
+
if (!platform && OFFICIAL_PRODUCT_NAMES.has(productName.toLowerCase())) {
|
|
144
164
|
throw new Error(`identity.productName is reserved for the official application: ${productName}`);
|
|
145
165
|
}
|
|
146
|
-
if (
|
|
166
|
+
if (!platform && RESERVED_APP_IDS.has(appId)) {
|
|
147
167
|
throw new Error(`identity.appId is reserved for the official application: ${appId}`);
|
|
148
168
|
}
|
|
149
169
|
if (!platform && productNameNamespace(productName) !== id) {
|
|
@@ -155,29 +175,82 @@ function parseIdentity(value, id, platform) {
|
|
|
155
175
|
if (!platform && protocolScheme !== id) {
|
|
156
176
|
throw new Error("identity.protocolScheme must equal manifest id to keep OEM deep links namespaced");
|
|
157
177
|
}
|
|
158
|
-
if (!platform && !
|
|
159
|
-
throw new Error("identity.
|
|
178
|
+
if (!platform && value.userDataNamespace !== void 0 && !KEBAB_ID.test(text(value.userDataNamespace, "identity.userDataNamespace", 64))) {
|
|
179
|
+
throw new Error("identity.userDataNamespace must be lowercase kebab-case");
|
|
160
180
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
};
|
|
181
|
+
const userDataNamespace = value.userDataNamespace === void 0 ? void 0 : text(value.userDataNamespace, "identity.userDataNamespace", 200);
|
|
182
|
+
if (userDataNamespace && (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(userDataNamespace) || userDataNamespace.includes("..")))
|
|
183
|
+
throw new Error("identity.userDataNamespace must be a safe directory name");
|
|
184
|
+
if (platform && versionChannel !== id && !["stable", "debug", "oem-dev"].includes(versionChannel))
|
|
185
|
+
throw new Error("Platform environment must be stable, debug, or oem-dev");
|
|
186
|
+
return { productName, appId, versionChannel, protocolScheme, ...userDataNamespace ? { userDataNamespace } : {} };
|
|
168
187
|
}
|
|
169
188
|
function parseAssets(value) {
|
|
170
189
|
if (!isRecord(value)) throw new Error("assets must be an object");
|
|
171
190
|
assertKnownKeys(value, ASSET_KEYS, "assets");
|
|
172
191
|
const tray = value.tray === void 0 ? void 0 : relativePath(value.tray, "assets.tray");
|
|
192
|
+
const trayVariants = value.trayVariants === void 0 ? void 0 : parseTrayVariants(value.trayVariants);
|
|
193
|
+
if (trayVariants && tray !== TRAY_SOURCE_PATH) {
|
|
194
|
+
throw new Error(`assets.tray must equal ${TRAY_SOURCE_PATH} when assets.trayVariants is present`);
|
|
195
|
+
}
|
|
173
196
|
const loginKV = value.loginKV === void 0 ? void 0 : relativePath(value.loginKV, "assets.loginKV");
|
|
174
197
|
return {
|
|
175
198
|
appIcon: relativePath(value.appIcon, "assets.appIcon"),
|
|
176
199
|
...tray ? { tray } : {},
|
|
200
|
+
...trayVariants ? { trayVariants } : {},
|
|
177
201
|
logo: relativePath(value.logo, "assets.logo"),
|
|
178
202
|
...loginKV ? { loginKV } : {}
|
|
179
203
|
};
|
|
180
204
|
}
|
|
205
|
+
function parseTrayVariants(value) {
|
|
206
|
+
if (!isRecord(value)) throw new Error("assets.trayVariants must be an object");
|
|
207
|
+
assertKnownKeys(value, new Set(Object.keys(TRAY_VARIANT_PATHS)), "assets.trayVariants");
|
|
208
|
+
const result = {};
|
|
209
|
+
for (const [platform, expected] of Object.entries(TRAY_VARIANT_PATHS)) {
|
|
210
|
+
const variants = value[platform];
|
|
211
|
+
if (!isRecord(variants)) throw new Error(`assets.trayVariants.${platform} must be an object`);
|
|
212
|
+
assertKnownKeys(variants, new Set(Object.keys(expected)), `assets.trayVariants.${platform}`);
|
|
213
|
+
const parsed = {};
|
|
214
|
+
for (const [size, expectedPath] of Object.entries(expected)) {
|
|
215
|
+
const actual = relativePath(variants[size], `assets.trayVariants.${platform}.${size}`);
|
|
216
|
+
if (actual !== expectedPath) {
|
|
217
|
+
throw new Error(`assets.trayVariants.${platform}.${size} must equal ${expectedPath}`);
|
|
218
|
+
}
|
|
219
|
+
parsed[size] = actual;
|
|
220
|
+
}
|
|
221
|
+
result[platform] = parsed;
|
|
222
|
+
}
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
function parseAppearance(value) {
|
|
226
|
+
if (value === void 0) return void 0;
|
|
227
|
+
if (!isRecord(value)) throw new Error("appearance must be an object");
|
|
228
|
+
assertKnownKeys(value, APPEARANCE_KEYS, "appearance");
|
|
229
|
+
if (value.homeBackdrop !== void 0 && typeof value.homeBackdrop !== "boolean")
|
|
230
|
+
throw new Error("appearance.homeBackdrop must be a boolean");
|
|
231
|
+
let login;
|
|
232
|
+
if (value.login !== void 0) {
|
|
233
|
+
if (!isRecord(value.login)) throw new Error("appearance.login must be an object");
|
|
234
|
+
assertKnownKeys(value.login, LOGIN_APPEARANCE_KEYS, "appearance.login");
|
|
235
|
+
login = {};
|
|
236
|
+
for (const key of ["claimColor", "claimNoteColor", "accentColor"]) {
|
|
237
|
+
const color = value.login[key];
|
|
238
|
+
if (color !== void 0) {
|
|
239
|
+
if (typeof color !== "string" || color.length !== 7 || !HEX6.test(color))
|
|
240
|
+
throw new Error(`appearance.login.${key} must be an opaque #RRGGBB color`);
|
|
241
|
+
login[key] = color.toLowerCase();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (value.login.scrim !== void 0) {
|
|
245
|
+
if (typeof value.login.scrim !== "boolean") throw new Error("appearance.login.scrim must be a boolean");
|
|
246
|
+
login.scrim = value.login.scrim;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
...value.homeBackdrop !== void 0 ? { homeBackdrop: value.homeBackdrop } : {},
|
|
251
|
+
...login ? { login } : {}
|
|
252
|
+
};
|
|
253
|
+
}
|
|
181
254
|
function parseBrandCopy(value, path) {
|
|
182
255
|
if (!isRecord(value)) throw new Error(`${path} must be an object`);
|
|
183
256
|
assertKnownKeys(value, BRANDING_KEYS, path);
|
|
@@ -187,11 +260,14 @@ function parseBrandCopy(value, path) {
|
|
|
187
260
|
};
|
|
188
261
|
for (const [key, limit] of [
|
|
189
262
|
["claim", 40],
|
|
263
|
+
["claimHighlight", 40],
|
|
190
264
|
["claimNote", 48],
|
|
191
265
|
["slogan", 68]
|
|
192
266
|
]) {
|
|
193
267
|
if (value[key] !== void 0) result[key] = text(value[key], `${path}.${key}`, limit);
|
|
194
268
|
}
|
|
269
|
+
if (result.claimHighlight && !result.claim?.includes(result.claimHighlight))
|
|
270
|
+
throw new Error(`${path}.claimHighlight must be an exact substring of claim`);
|
|
195
271
|
return result;
|
|
196
272
|
}
|
|
197
273
|
function parseBranding(value) {
|
|
@@ -230,7 +306,7 @@ function isDevelopmentHostname(hostname) {
|
|
|
230
306
|
}
|
|
231
307
|
return lower.split(/[.-]/).some((label) => ["dev", "development", "test", "testing", "stage", "staging", "uat"].includes(label));
|
|
232
308
|
}
|
|
233
|
-
function parseNetwork(value) {
|
|
309
|
+
function parseNetwork(value, platform = false) {
|
|
234
310
|
if (value === void 0) return void 0;
|
|
235
311
|
if (!isRecord(value)) throw new Error("network must be an object");
|
|
236
312
|
assertKnownKeys(value, NETWORK_KEYS, "network");
|
|
@@ -249,7 +325,7 @@ function parseNetwork(value) {
|
|
|
249
325
|
if (parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.pathname !== "/" || parsed.search || parsed.hash || parsed.origin !== origin) {
|
|
250
326
|
throw new Error(`${path} must be a canonical exact HTTPS origin without credentials, path, query, or fragment`);
|
|
251
327
|
}
|
|
252
|
-
if (isDevelopmentHostname(parsed.hostname)) {
|
|
328
|
+
if (!platform && isDevelopmentHostname(parsed.hostname)) {
|
|
253
329
|
throw new Error(`${path} must be a production origin, not localhost, private network, dev, test, staging, or UAT`);
|
|
254
330
|
}
|
|
255
331
|
return origin;
|
|
@@ -315,6 +391,27 @@ function parseModeTokens(value, path) {
|
|
|
315
391
|
}
|
|
316
392
|
return result;
|
|
317
393
|
}
|
|
394
|
+
function parseTheme(value) {
|
|
395
|
+
if (value === void 0) return void 0;
|
|
396
|
+
if (!isRecord(value)) throw new Error("theme must be an object");
|
|
397
|
+
assertKnownKeys(value, THEME_KEYS, "theme");
|
|
398
|
+
if (typeof value.primary !== "string" || !HEX6.test(value.primary)) throw new Error("theme.primary must be #RRGGBB");
|
|
399
|
+
const primary = value.primary.toLowerCase();
|
|
400
|
+
let signal;
|
|
401
|
+
if (value.signal !== void 0) {
|
|
402
|
+
if (typeof value.signal !== "string" || !HEX6.test(value.signal)) throw new Error("theme.signal must be #RRGGBB");
|
|
403
|
+
signal = value.signal.toLowerCase();
|
|
404
|
+
const ratio = ds2ContrastRatio(signal, "#fafafb");
|
|
405
|
+
if (ratio < 3) throw new Error(`theme.signal contrast on #FAFAFB is ${ratio.toFixed(2)}:1; expected >= 3:1`);
|
|
406
|
+
}
|
|
407
|
+
if (value.allowDangerHue !== void 0 && typeof value.allowDangerHue !== "boolean") {
|
|
408
|
+
throw new Error("theme.allowDangerHue must be a boolean");
|
|
409
|
+
}
|
|
410
|
+
const allowDangerHue = value.allowDangerHue === true;
|
|
411
|
+
const check = checkOemPrimary(primary);
|
|
412
|
+
if (check.errors.length && !allowDangerHue) throw new Error(`theme.primary: ${check.errors.join("; ")}`);
|
|
413
|
+
return { primary, ...signal ? { signal } : {}, ...allowDangerHue ? { allowDangerHue } : {} };
|
|
414
|
+
}
|
|
318
415
|
function parseTokens(value) {
|
|
319
416
|
if (value === void 0) return void 0;
|
|
320
417
|
if (!isRecord(value)) throw new Error("tokens must be an object");
|
|
@@ -394,7 +491,8 @@ function parseBrandManifest(input, options) {
|
|
|
394
491
|
assertKnownKeys(input, ROOT_KEYS, "manifest");
|
|
395
492
|
if (input.$schema !== BRAND_MANIFEST_SCHEMA) throw new Error(`$schema must equal ${BRAND_MANIFEST_SCHEMA}`);
|
|
396
493
|
const id = text(input.id, "id", 64);
|
|
397
|
-
if (!KEBAB_ID.test(id))
|
|
494
|
+
if (!(platform ? /^[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/ : KEBAB_ID).test(id))
|
|
495
|
+
throw new Error("id must be lowercase kebab-case");
|
|
398
496
|
const entry = input.entry === void 0 ? void 0 : relativePath(input.entry, "entry");
|
|
399
497
|
if (entry && !SOURCE_ENTRY.test(entry)) {
|
|
400
498
|
throw new Error("entry must point to reviewed source under ./src using .js, .mjs, .jsx, .ts, or .tsx");
|
|
@@ -402,11 +500,13 @@ function parseBrandManifest(input, options) {
|
|
|
402
500
|
const contributes = parseContributes(input.contributes);
|
|
403
501
|
if ((contributes?.slots.length ?? 0) > 0 && !entry)
|
|
404
502
|
throw new Error("entry is required when contributes.slots is not empty");
|
|
503
|
+
const theme = parseTheme(input.theme);
|
|
405
504
|
const tokens = parseTokens(input.tokens);
|
|
406
505
|
const typography = parseTypography(input.typography);
|
|
407
506
|
const fontScale = parseFontScale(input.fontScale);
|
|
507
|
+
const appearance = parseAppearance(input.appearance);
|
|
408
508
|
const locales = parseLocales(input.locales);
|
|
409
|
-
const network = parseNetwork(input.network);
|
|
509
|
+
const network = parseNetwork(input.network, platform);
|
|
410
510
|
const identity = parseIdentity(input.identity, id, platform);
|
|
411
511
|
if (!platform && productNameNamespace(identity.productName) !== id) {
|
|
412
512
|
throw new Error("identity.productName must normalize to manifest id so installation names cannot collide");
|
|
@@ -417,9 +517,6 @@ function parseBrandManifest(input, options) {
|
|
|
417
517
|
if (!platform && identity.protocolScheme !== id) {
|
|
418
518
|
throw new Error("identity.protocolScheme must equal manifest id to keep OEM deep links namespaced");
|
|
419
519
|
}
|
|
420
|
-
if (!platform && !identity.appId.endsWith(`.oem.${id}`)) {
|
|
421
|
-
throw new Error("identity.appId must end with .oem.<manifest id> to isolate installation and user data");
|
|
422
|
-
}
|
|
423
520
|
return {
|
|
424
521
|
ok: true,
|
|
425
522
|
manifest: {
|
|
@@ -431,9 +528,11 @@ function parseBrandManifest(input, options) {
|
|
|
431
528
|
...input.permissions !== void 0 ? { permissions: parsePermissions(input.permissions) } : {},
|
|
432
529
|
...entry ? { entry } : {},
|
|
433
530
|
identity,
|
|
531
|
+
...theme ? { theme } : {},
|
|
434
532
|
...tokens ? { tokens } : {},
|
|
435
533
|
...typography ? { typography } : {},
|
|
436
534
|
...fontScale ? { fontScale } : {},
|
|
535
|
+
...appearance ? { appearance } : {},
|
|
437
536
|
assets: parseAssets(input.assets),
|
|
438
537
|
branding: parseBranding(input.branding),
|
|
439
538
|
...locales ? { locales } : {},
|
|
@@ -541,12 +640,86 @@ async function assertAsset(packageRoot, relative, kind) {
|
|
|
541
640
|
const { width, height } = dimensions;
|
|
542
641
|
if (kind === "appIcon") {
|
|
543
642
|
if (width !== height || width < 1024) throw new Error("assets.appIcon must be square and at least 1024x1024");
|
|
544
|
-
} else if (width !== height
|
|
545
|
-
throw new Error("assets.tray must be a square image
|
|
643
|
+
} else if (width !== height) {
|
|
644
|
+
throw new Error("assets.tray must be a square image");
|
|
546
645
|
}
|
|
547
646
|
}
|
|
548
647
|
return file;
|
|
549
648
|
}
|
|
649
|
+
var PNG_CRC_TABLE = (() => {
|
|
650
|
+
const table = new Uint32Array(256);
|
|
651
|
+
for (let index = 0; index < table.length; index += 1) {
|
|
652
|
+
let value = index;
|
|
653
|
+
for (let bit = 0; bit < 8; bit += 1) value = value & 1 ? 3988292384 ^ value >>> 1 : value >>> 1;
|
|
654
|
+
table[index] = value >>> 0;
|
|
655
|
+
}
|
|
656
|
+
return table;
|
|
657
|
+
})();
|
|
658
|
+
function pngCrc32(bytes) {
|
|
659
|
+
let crc = 4294967295;
|
|
660
|
+
for (const byte of bytes) crc = PNG_CRC_TABLE[(crc ^ byte) & 255] ^ crc >>> 8;
|
|
661
|
+
return (crc ^ 4294967295) >>> 0;
|
|
662
|
+
}
|
|
663
|
+
function strictPngDimensions(bytes) {
|
|
664
|
+
if (bytes.length < 45 || bytes.toString("hex", 0, 8) !== "89504e470d0a1a0a") return null;
|
|
665
|
+
let offset = 8;
|
|
666
|
+
let dimensions = null;
|
|
667
|
+
const idat = [];
|
|
668
|
+
while (offset + 12 <= bytes.length) {
|
|
669
|
+
const length = bytes.readUInt32BE(offset);
|
|
670
|
+
const end = offset + 12 + length;
|
|
671
|
+
if (end > bytes.length) return null;
|
|
672
|
+
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;
|
|
674
|
+
if (!dimensions) {
|
|
675
|
+
if (kind !== "IHDR" || length !== 13) return null;
|
|
676
|
+
const width = bytes.readUInt32BE(offset + 8);
|
|
677
|
+
const height = bytes.readUInt32BE(offset + 12);
|
|
678
|
+
if (!width || !height || bytes[offset + 18] !== 0 || bytes[offset + 19] !== 0 || bytes[offset + 20] > 1) return null;
|
|
679
|
+
dimensions = { width, height };
|
|
680
|
+
} else if (kind === "IDAT") {
|
|
681
|
+
idat.push(bytes.subarray(offset + 8, offset + 8 + length));
|
|
682
|
+
} else if (kind === "IEND") {
|
|
683
|
+
if (length !== 0 || idat.length === 0 || end !== bytes.length) return null;
|
|
684
|
+
try {
|
|
685
|
+
if (inflateSync(Buffer.concat(idat)).length === 0) return null;
|
|
686
|
+
} catch {
|
|
687
|
+
return null;
|
|
688
|
+
}
|
|
689
|
+
return dimensions;
|
|
690
|
+
}
|
|
691
|
+
offset = end;
|
|
692
|
+
}
|
|
693
|
+
return null;
|
|
694
|
+
}
|
|
695
|
+
async function assertTrayVariants(packageRoot, variants) {
|
|
696
|
+
const checked = [];
|
|
697
|
+
for (const [platform, expected] of Object.entries(TRAY_VARIANT_PATHS)) {
|
|
698
|
+
for (const [label, expectedPath] of Object.entries(expected)) {
|
|
699
|
+
const relative = variants[platform][label];
|
|
700
|
+
const field = `assets.trayVariants.${platform}.${label}`;
|
|
701
|
+
if (relative !== expectedPath) throw new Error(`${field} must equal ${expectedPath}`);
|
|
702
|
+
let file;
|
|
703
|
+
try {
|
|
704
|
+
file = await resolvePackageFile(packageRoot, relative, field);
|
|
705
|
+
} catch (error) {
|
|
706
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") throw new Error(`${field} file is missing: ${relative}`);
|
|
707
|
+
throw error;
|
|
708
|
+
}
|
|
709
|
+
const info = await stat(file);
|
|
710
|
+
if (!info.isFile()) throw new Error(`${field} must point to a file`);
|
|
711
|
+
if (info.size > ASSET_BUDGET) throw new Error(`${field} exceeds 5 MiB`);
|
|
712
|
+
const dimensions = strictPngDimensions(await readFile(file));
|
|
713
|
+
const size = platform === "macos" ? label === "1x" ? 16 : 32 : Number(label);
|
|
714
|
+
if (!dimensions) throw new Error(`${field} must be a valid PNG`);
|
|
715
|
+
if (dimensions.width !== size || dimensions.height !== size) {
|
|
716
|
+
throw new Error(`${field} must be ${size}x${size}, got ${dimensions.width}x${dimensions.height}`);
|
|
717
|
+
}
|
|
718
|
+
checked.push(relative);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
return checked;
|
|
722
|
+
}
|
|
550
723
|
function pngDimensions(bytes) {
|
|
551
724
|
if (bytes.length < 24 || bytes.toString("hex", 0, 8) !== "89504e470d0a1a0a") return null;
|
|
552
725
|
return { width: bytes.readUInt32BE(16), height: bytes.readUInt32BE(20) };
|
|
@@ -556,13 +729,19 @@ function jpegDimensions(bytes) {
|
|
|
556
729
|
let offset = 2;
|
|
557
730
|
while (offset + 9 < bytes.length) {
|
|
558
731
|
if (bytes[offset] !== 255) return null;
|
|
559
|
-
|
|
732
|
+
let markerOffset = offset;
|
|
733
|
+
while (bytes[markerOffset] === 255) markerOffset += 1;
|
|
734
|
+
const marker = bytes[markerOffset];
|
|
560
735
|
if (marker >= 192 && marker <= 207 && ![196, 200, 204].includes(marker)) {
|
|
561
|
-
return { height: bytes.readUInt16BE(
|
|
736
|
+
return { height: bytes.readUInt16BE(markerOffset + 4), width: bytes.readUInt16BE(markerOffset + 6) };
|
|
737
|
+
}
|
|
738
|
+
if (marker === 1 || marker >= 208 && marker <= 215) {
|
|
739
|
+
offset = markerOffset + 1;
|
|
740
|
+
continue;
|
|
562
741
|
}
|
|
563
|
-
const length = bytes.readUInt16BE(
|
|
742
|
+
const length = bytes.readUInt16BE(markerOffset + 1);
|
|
564
743
|
if (length < 2) return null;
|
|
565
|
-
offset
|
|
744
|
+
offset = markerOffset + 1 + length;
|
|
566
745
|
}
|
|
567
746
|
return null;
|
|
568
747
|
}
|
|
@@ -716,10 +895,14 @@ async function auditBrandPackage(manifestFile, options = {}) {
|
|
|
716
895
|
if (!parsed.ok) throw new Error(`manifest contract failed: ${parsed.error}`);
|
|
717
896
|
const manifest = parsed.manifest;
|
|
718
897
|
const checkedAssets = [];
|
|
719
|
-
|
|
898
|
+
const assetEntries = Object.entries(manifest.assets).filter(([kind]) => kind !== "trayVariants");
|
|
899
|
+
for (const [kind, relative] of assetEntries) {
|
|
720
900
|
await assertAsset(packageRoot, relative, kind);
|
|
721
901
|
checkedAssets.push(relative);
|
|
722
902
|
}
|
|
903
|
+
if (manifest.assets.trayVariants) {
|
|
904
|
+
checkedAssets.push(...await assertTrayVariants(packageRoot, manifest.assets.trayVariants));
|
|
905
|
+
}
|
|
723
906
|
let entryGzipBytes = 0;
|
|
724
907
|
let checkedModules = [];
|
|
725
908
|
const checkedLocales = manifest.locales ? await auditLocaleDictionaries(packageRoot, manifest.locales) : [];
|