@g9tm/lynxcontrols-pilot 0.0.0-stage → 2.4.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/README.md +159 -2
- package/catalog/cards/G9PilotHost.md +16 -0
- package/catalog/cards/G9PilotMask.md +10 -0
- package/catalog/cards/G9PilotPanel.md +10 -0
- package/catalog/catalog.json +420 -0
- package/catalog/index.md +7 -0
- package/check/cli.mjs +5 -0
- package/check/index.mjs +137 -0
- package/check/index.test.mjs +180 -0
- package/config/cli.mjs +31 -0
- package/config/index.d.ts +62 -0
- package/config/index.mjs +380 -0
- package/config/index.test.mjs +406 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/anchors.d.ts +39 -0
- package/dist/anchors.d.ts.map +1 -0
- package/dist/anchors.jsx +103 -0
- package/dist/bridge.d.ts +4 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.jsx +143 -0
- package/dist/busy.d.ts +4 -0
- package/dist/busy.d.ts.map +1 -0
- package/dist/busy.jsx +43 -0
- package/dist/commands.d.ts +24 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.jsx +286 -0
- package/dist/consent.d.ts +51 -0
- package/dist/consent.d.ts.map +1 -0
- package/dist/consent.jsx +131 -0
- package/dist/explore.d.ts +36 -0
- package/dist/explore.d.ts.map +1 -0
- package/dist/explore.jsx +133 -0
- package/dist/flags.d.ts +69 -0
- package/dist/flags.d.ts.map +1 -0
- package/dist/flags.jsx +81 -0
- package/dist/host-core.d.ts +36 -0
- package/dist/host-core.d.ts.map +1 -0
- package/dist/host-core.jsx +90 -0
- package/dist/host-sink.d.ts +43 -0
- package/dist/host-sink.d.ts.map +1 -0
- package/dist/host-sink.jsx +87 -0
- package/dist/index-marks.d.ts +33 -0
- package/dist/index-marks.d.ts.map +1 -0
- package/dist/index-marks.jsx +40 -0
- package/dist/index-observe.d.ts +17 -0
- package/dist/index-observe.d.ts.map +1 -0
- package/dist/index-observe.jsx +14 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.jsx +11 -0
- package/dist/info.d.ts +10 -0
- package/dist/info.d.ts.map +1 -0
- package/dist/info.jsx +9 -0
- package/dist/kit.d.ts +67 -0
- package/dist/kit.d.ts.map +1 -0
- package/dist/kit.jsx +1 -0
- package/dist/layer.d.ts +4 -0
- package/dist/layer.d.ts.map +1 -0
- package/dist/layer.jsx +10 -0
- package/dist/layers.d.ts +4 -0
- package/dist/layers.d.ts.map +1 -0
- package/dist/layers.jsx +146 -0
- package/dist/mask.d.ts +20 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/mask.jsx +35 -0
- package/dist/net.d.ts +17 -0
- package/dist/net.d.ts.map +1 -0
- package/dist/net.jsx +60 -0
- package/dist/observe.d.ts +99 -0
- package/dist/observe.d.ts.map +1 -0
- package/dist/observe.jsx +194 -0
- package/dist/off.d.ts +45 -0
- package/dist/off.d.ts.map +1 -0
- package/dist/off.jsx +81 -0
- package/dist/otlp.d.ts +61 -0
- package/dist/otlp.d.ts.map +1 -0
- package/dist/otlp.jsx +141 -0
- package/dist/panel.d.ts +13 -0
- package/dist/panel.d.ts.map +1 -0
- package/dist/panel.jsx +182 -0
- package/dist/session.d.ts +42 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.jsx +115 -0
- package/dist/types.d.ts +47 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.jsx +1 -0
- package/dist/watch.d.ts +17 -0
- package/dist/watch.d.ts.map +1 -0
- package/dist/watch.jsx +165 -0
- package/doctor/cli.mjs +5 -0
- package/doctor/index.mjs +214 -0
- package/doctor/index.test.mjs +174 -0
- package/gradle/g9pilot.app.gradle +55 -0
- package/gradle/g9pilot.settings.gradle +27 -0
- package/ios/g9pilot.rb +47 -0
- package/package.json +66 -4
- package/rspeedy/index.d.ts +40 -0
- package/rspeedy/index.mjs +100 -0
- package/rspeedy/index.test.mjs +192 -0
package/config/index.mjs
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
// @g9tm/lynxcontrols-pilot/config: one file, `g9pilot.config.json`, says per build environment how much of G9AppPilot a
|
|
2
|
+
// build carries. The rspeedy plugin, the Gradle and CocoaPods helpers and `g9pilot-check` all resolve it HERE, so the
|
|
3
|
+
// JavaScript bundle, the native project and the proof on the artifact can never disagree. Plain Node ESM, no
|
|
4
|
+
// dependencies (it also runs inside Gradle through `node config/cli.mjs`).
|
|
5
|
+
//
|
|
6
|
+
// off nothing (0 bytes): the default when no environment is named
|
|
7
|
+
// marks test ids and busy reasons on the page; no bridge, no native code
|
|
8
|
+
// observe marks + the always-awake watch (oracles, vitals, black box, traces, local report); no bridge
|
|
9
|
+
// support observe + the signed bridge, every command; defaults for helping a person remotely (badge always,
|
|
10
|
+
// consent per session); every part and every scope configurable
|
|
11
|
+
// full support with the QA defaults (no consent, DevTool, self-drive available)
|
|
12
|
+
//
|
|
13
|
+
// A build environment marked `"distribution": "store"` may never carry the bridge: resolving one is an error, not a
|
|
14
|
+
// warning, so a store build that would carry it does not build.
|
|
15
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
16
|
+
import { dirname, join, resolve } from 'node:path';
|
|
17
|
+
|
|
18
|
+
export const PROFILES = Object.freeze(['off', 'marks', 'observe', 'support', 'full']);
|
|
19
|
+
export const SCOPES = Object.freeze(['observe', 'drive', 'stage', 'design', 'write', 'admin']);
|
|
20
|
+
/** The page modules a profile switches on; each can be set on its own in `modules`. */
|
|
21
|
+
export const MODULES = Object.freeze([
|
|
22
|
+
'marks', // test ids, the kit's layers on them, busy reasons (production-safe)
|
|
23
|
+
'oracles', // the always-awake rules (errors, rejections, busy leaks, raw keys, Latin digits, off-screen, a11y)
|
|
24
|
+
'vitals', // stalls of the page and the main thread, memory growth
|
|
25
|
+
'blackbox', // log, requests, stores, failure traces
|
|
26
|
+
'screen', // ui.snapshot for the screen rules (and, with the bridge, every ui.* command)
|
|
27
|
+
'bridge', // the signed transport (startPilot) and the native package
|
|
28
|
+
'ui', // ui.* driving commands (real touch through the native package)
|
|
29
|
+
'lease', // one controller at a time
|
|
30
|
+
'recorder', // flow.record.*
|
|
31
|
+
'stage', // net.shape, clock, seed, flags, HAR
|
|
32
|
+
'design', // live design tokens over the G9 theme
|
|
33
|
+
'inspector', // pick a control on the phone
|
|
34
|
+
'annotate', // framed screenshots
|
|
35
|
+
'badge', // «under automation» pill
|
|
36
|
+
'devtool', // Lynx DevTool's in-app CDP (screen.model, app.eval) — brings lynx-devtool into the native build
|
|
37
|
+
'selfDrive', // the page drives itself through its own gate (demos, tours)
|
|
38
|
+
'perf', // g9.renders, g9.profileTheme, g9.profileVars, g9.profileMount and the host's perf.* commands
|
|
39
|
+
'explore', // g9.explore: walk every place and control with the oracles on
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
const OBSERVE = ['marks', 'oracles', 'vitals', 'blackbox', 'screen'];
|
|
43
|
+
const BRIDGED = [
|
|
44
|
+
...OBSERVE,
|
|
45
|
+
'bridge',
|
|
46
|
+
'ui',
|
|
47
|
+
'lease',
|
|
48
|
+
'recorder',
|
|
49
|
+
'stage',
|
|
50
|
+
'design',
|
|
51
|
+
'inspector',
|
|
52
|
+
'annotate',
|
|
53
|
+
'badge',
|
|
54
|
+
'perf',
|
|
55
|
+
'explore',
|
|
56
|
+
];
|
|
57
|
+
const PROFILE_MODULES = Object.freeze({
|
|
58
|
+
off: [],
|
|
59
|
+
marks: ['marks'],
|
|
60
|
+
observe: OBSERVE,
|
|
61
|
+
support: BRIDGED,
|
|
62
|
+
full: [...BRIDGED, 'devtool', 'selfDrive'],
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/** The defaults of each profile, before the environment's own settings. */
|
|
66
|
+
const PROFILE_DEFAULTS = Object.freeze({
|
|
67
|
+
support: { badge: 'always', consent: 'session', lan: true, mask: 'secret', session: { maxMinutes: 60 } },
|
|
68
|
+
full: { badge: 'realDeviceOrRemote', consent: 'none', lan: true, mask: 'off', session: { maxMinutes: 0 } },
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const OBSERVE_DEFAULTS = Object.freeze({
|
|
72
|
+
rules: {},
|
|
73
|
+
sampling: { errors: 1, vitals: 1, traces: 1 },
|
|
74
|
+
buffer: { maxFindings: 200, persist: true },
|
|
75
|
+
report: { via: 'local', consent: 'build', endpoint: null, service: null, auto: 0 },
|
|
76
|
+
});
|
|
77
|
+
const REPORT_KEYS = Object.freeze(['via', 'consent', 'endpoint', 'service', 'auto']);
|
|
78
|
+
|
|
79
|
+
/** What an environment may say; anything else is a mistake, never silently ignored. */
|
|
80
|
+
const ENV_KEYS = Object.freeze([
|
|
81
|
+
'$comment',
|
|
82
|
+
'profile',
|
|
83
|
+
'distribution',
|
|
84
|
+
'modules',
|
|
85
|
+
'keys',
|
|
86
|
+
'maxScopes',
|
|
87
|
+
'signatureRequired',
|
|
88
|
+
'port',
|
|
89
|
+
'lan',
|
|
90
|
+
'badge',
|
|
91
|
+
'consent',
|
|
92
|
+
'mask',
|
|
93
|
+
'session',
|
|
94
|
+
'selfDrive',
|
|
95
|
+
'observe',
|
|
96
|
+
]);
|
|
97
|
+
|
|
98
|
+
export class G9PilotConfigError extends Error {
|
|
99
|
+
constructor(message) {
|
|
100
|
+
super(`g9pilot.config: ${message}`);
|
|
101
|
+
this.name = 'G9PilotConfigError';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
106
|
+
const fail = (m) => {
|
|
107
|
+
throw new G9PilotConfigError(m);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/** `maxScopes`: "all" | "none" | a list of scope names. */
|
|
111
|
+
function scopeCap(value, where) {
|
|
112
|
+
if (value === undefined || value === 'all') return [...SCOPES];
|
|
113
|
+
if (value === 'none') return [];
|
|
114
|
+
if (!Array.isArray(value)) fail(`${where}.maxScopes must be "all", "none" or a list of ${SCOPES.join(', ')}`);
|
|
115
|
+
for (const s of value) if (!SCOPES.includes(s)) fail(`${where}.maxScopes: unknown scope "${s}"`);
|
|
116
|
+
return [...new Set(value)];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function keysOf(list, cap, where, baseDir) {
|
|
120
|
+
if (list === undefined) return [];
|
|
121
|
+
if (!Array.isArray(list)) fail(`${where}.keys must be a list of {kid, publicKey, scopes}`);
|
|
122
|
+
return list.map((k, i) => {
|
|
123
|
+
if (!isObject(k) || typeof k.kid !== 'string' || !k.kid) fail(`${where}.keys[${i}].kid is missing`);
|
|
124
|
+
let publicKey = k.publicKey;
|
|
125
|
+
if (publicKey === undefined && typeof k.publicKeyFile === 'string') {
|
|
126
|
+
// a key made per machine (`g9pilot keys new`) and kept out of the repository: the configuration names its file
|
|
127
|
+
const path = resolve(baseDir ?? process.cwd(), k.publicKeyFile);
|
|
128
|
+
if (!existsSync(path))
|
|
129
|
+
fail(`${where}.keys[${i}] (${k.kid}): ${k.publicKeyFile} does not exist (make the key pair first)`);
|
|
130
|
+
publicKey = readFileSync(path, 'utf8').trim();
|
|
131
|
+
}
|
|
132
|
+
if (typeof publicKey !== 'string' || !publicKey) fail(`${where}.keys[${i}] (${k.kid}): publicKey is missing`);
|
|
133
|
+
if (/PRIVATE KEY/.test(publicKey) || 'privateKey' in k)
|
|
134
|
+
fail(`${where}.keys[${i}] (${k.kid}): a private key never goes into a build configuration`);
|
|
135
|
+
const scopes = k.scopes ?? ['observe'];
|
|
136
|
+
if (!Array.isArray(scopes)) fail(`${where}.keys[${i}] (${k.kid}): scopes must be a list`);
|
|
137
|
+
for (const s of scopes)
|
|
138
|
+
if (s !== '*' && !SCOPES.includes(s)) fail(`${where}.keys[${i}] (${k.kid}): unknown scope "${s}"`);
|
|
139
|
+
const wanted = scopes.includes('*') ? [...SCOPES] : scopes;
|
|
140
|
+
// a short-lived key (a support engineer's, for a day): the gates refuse it after this moment (KEY_EXPIRED)
|
|
141
|
+
let notAfter = null;
|
|
142
|
+
if (k.notAfter !== undefined) {
|
|
143
|
+
notAfter = typeof k.notAfter === 'number' ? k.notAfter : Date.parse(String(k.notAfter));
|
|
144
|
+
if (!Number.isFinite(notAfter) || notAfter <= 0)
|
|
145
|
+
fail(`${where}.keys[${i}] (${k.kid}): notAfter must be a date (2026-12-31T18:00:00Z) or ms since the epoch`);
|
|
146
|
+
}
|
|
147
|
+
// the build's ceiling: a key may hold more, this build trusts it with no more than maxScopes
|
|
148
|
+
const key = { kid: k.kid, publicKey, scopes: wanted.filter((s) => cap.includes(s)) };
|
|
149
|
+
return notAfter === null ? key : { ...key, notAfter };
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Resolves one build environment of a parsed `g9pilot.config.json` (`environment` null or missing → `off`). Throws
|
|
155
|
+
* G9PilotConfigError on anything a build must not guess: an unknown profile, module or scope, a private key, a bridge
|
|
156
|
+
* without a key while signatures are required, a bridge in a store distribution.
|
|
157
|
+
*/
|
|
158
|
+
export function resolvePilotConfig(config, environment, { baseDir } = {}) {
|
|
159
|
+
const root = config ?? {};
|
|
160
|
+
if (!isObject(root)) fail('the file must hold an object');
|
|
161
|
+
for (const key of Object.keys(root))
|
|
162
|
+
if (!['$schema', '$comment', 'keys', 'environments'].includes(key))
|
|
163
|
+
fail(`${key} is not a setting of the file (known: keys, environments)`);
|
|
164
|
+
if (environment === undefined || environment === null || environment === '') return offConfig(null);
|
|
165
|
+
const envs = root.environments ?? {};
|
|
166
|
+
if (!isObject(envs)) fail('environments must be an object');
|
|
167
|
+
const env = envs[environment];
|
|
168
|
+
if (!isObject(env)) fail(`no environment "${environment}" (known: ${Object.keys(envs).join(', ') || 'none'})`);
|
|
169
|
+
const where = `environments.${environment}`;
|
|
170
|
+
const profile = env.profile ?? 'off';
|
|
171
|
+
if (!PROFILES.includes(profile)) fail(`${where}.profile "${profile}" is not one of ${PROFILES.join(', ')}`);
|
|
172
|
+
|
|
173
|
+
const modules = Object.fromEntries(MODULES.map((m) => [m, PROFILE_MODULES[profile].includes(m)]));
|
|
174
|
+
if (env.modules !== undefined) {
|
|
175
|
+
if (!isObject(env.modules)) fail(`${where}.modules must be an object of module: true|false`);
|
|
176
|
+
for (const [m, on] of Object.entries(env.modules)) {
|
|
177
|
+
if (!MODULES.includes(m)) fail(`${where}.modules: unknown module "${m}" (known: ${MODULES.join(', ')})`);
|
|
178
|
+
if (typeof on !== 'boolean') fail(`${where}.modules.${m} must be true or false`);
|
|
179
|
+
modules[m] = on;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// what a module needs to work at all
|
|
183
|
+
const bridgeOnly = [
|
|
184
|
+
'ui',
|
|
185
|
+
'lease',
|
|
186
|
+
'recorder',
|
|
187
|
+
'stage',
|
|
188
|
+
'design',
|
|
189
|
+
'inspector',
|
|
190
|
+
'annotate',
|
|
191
|
+
'badge',
|
|
192
|
+
'devtool',
|
|
193
|
+
'selfDrive',
|
|
194
|
+
'perf',
|
|
195
|
+
'explore',
|
|
196
|
+
];
|
|
197
|
+
for (const m of bridgeOnly)
|
|
198
|
+
if (modules[m] && !modules.bridge)
|
|
199
|
+
fail(`${where}.modules.${m} needs the bridge (profile support or full, or modules.bridge: true)`);
|
|
200
|
+
if (modules.bridge || modules.oracles || modules.screen) modules.marks = true;
|
|
201
|
+
if (modules.oracles && !modules.screen && modules.bridge) modules.screen = true;
|
|
202
|
+
|
|
203
|
+
const distribution = env.distribution ?? 'test';
|
|
204
|
+
if (!['store', 'test'].includes(distribution)) fail(`${where}.distribution must be "store" or "test"`);
|
|
205
|
+
if (distribution === 'store' && modules.bridge)
|
|
206
|
+
fail(`${where} is a store distribution: the bridge (profile "${profile}") can never be in it`);
|
|
207
|
+
|
|
208
|
+
const cap = scopeCap(env.maxScopes, where);
|
|
209
|
+
// keys matter only to a bridge: a store or observe build never reads (or needs) the key files
|
|
210
|
+
const keys = modules.bridge ? keysOf(env.keys ?? root.keys, cap, where, baseDir) : [];
|
|
211
|
+
const signatureRequired = env.signatureRequired ?? true;
|
|
212
|
+
if (modules.bridge && signatureRequired && keys.length === 0)
|
|
213
|
+
fail(`${where}: the bridge requires signatures and no public key is configured (keys)`);
|
|
214
|
+
if (modules.bridge && keys.every((k) => k.scopes.length === 0) && signatureRequired)
|
|
215
|
+
fail(`${where}: maxScopes leaves no key any scope`);
|
|
216
|
+
|
|
217
|
+
const defaults = PROFILE_DEFAULTS[profile] ?? PROFILE_DEFAULTS.full;
|
|
218
|
+
const badge = env.badge ?? defaults.badge;
|
|
219
|
+
if (!['off', 'remote', 'realDeviceOrRemote', 'always'].includes(badge)) fail(`${where}.badge "${badge}" is unknown`);
|
|
220
|
+
// secret: ui.screenshot blacks out password fields and <G9PilotMask> boxes (pilot.maskRects); off: the screen as it is
|
|
221
|
+
const mask = env.mask ?? defaults.mask;
|
|
222
|
+
if (!['off', 'secret'].includes(mask)) fail(`${where}.mask must be "off" or "secret"`);
|
|
223
|
+
const consent = env.consent ?? defaults.consent;
|
|
224
|
+
if (!['none', 'session', 'escalation'].includes(consent)) fail(`${where}.consent "${consent}" is unknown`);
|
|
225
|
+
// lan false: the listener binds loopback only (adb forward, a relay inside the app, self-drive)
|
|
226
|
+
const lan = env.lan ?? defaults.lan;
|
|
227
|
+
if (typeof lan !== 'boolean') fail(`${where}.lan must be true or false`);
|
|
228
|
+
const port = env.port ?? 8799;
|
|
229
|
+
if (!Number.isInteger(port) || port < 1024 || port > 65535) fail(`${where}: port ${port} is not 1024–65535`);
|
|
230
|
+
const session = { ...defaults.session, ...(env.session ?? {}) };
|
|
231
|
+
if (!Number.isInteger(session.maxMinutes) || session.maxMinutes < 0)
|
|
232
|
+
fail(`${where}.session.maxMinutes must be a whole number of minutes (0: no end)`);
|
|
233
|
+
const selfDrive = { maxSeconds: 120, ...(env.selfDrive ?? {}) };
|
|
234
|
+
for (const key of Object.keys(env))
|
|
235
|
+
if (!ENV_KEYS.includes(key)) fail(`${where}.${key} is not a setting (known: ${ENV_KEYS.join(', ')})`);
|
|
236
|
+
for (const key of Object.keys(env.observe ?? {}))
|
|
237
|
+
if (!['rules', 'sampling', 'buffer', 'report'].includes(key))
|
|
238
|
+
fail(`${where}.observe.${key} is not a setting (known: rules, sampling, buffer, report)`);
|
|
239
|
+
const observe = {
|
|
240
|
+
...OBSERVE_DEFAULTS,
|
|
241
|
+
...(env.observe ?? {}),
|
|
242
|
+
sampling: { ...OBSERVE_DEFAULTS.sampling, ...(env.observe?.sampling ?? {}) },
|
|
243
|
+
buffer: { ...OBSERVE_DEFAULTS.buffer, ...(env.observe?.buffer ?? {}) },
|
|
244
|
+
report: { ...OBSERVE_DEFAULTS.report, ...(env.observe?.report ?? {}) },
|
|
245
|
+
};
|
|
246
|
+
for (const [k, v] of Object.entries(observe.sampling))
|
|
247
|
+
if (typeof v !== 'number' || v < 0 || v > 1) fail(`${where}.observe.sampling.${k} must be between 0 and 1`);
|
|
248
|
+
for (const key of Object.keys(env.observe?.report ?? {}))
|
|
249
|
+
if (!REPORT_KEYS.includes(key))
|
|
250
|
+
fail(`${where}.observe.report.${key} is not a setting (known: ${REPORT_KEYS.join(', ')})`);
|
|
251
|
+
const report = observe.report;
|
|
252
|
+
if (!['local', 'diagnostic', 'hub', 'otlp'].includes(report.via))
|
|
253
|
+
fail(`${where}.observe.report.via must be local, diagnostic, hub or otlp`);
|
|
254
|
+
if (!['build', 'user', 'never'].includes(report.consent))
|
|
255
|
+
fail(`${where}.observe.report.consent must be build, user or never`);
|
|
256
|
+
// otlp: OTLP/HTTP JSON logs to a collector the team runs (the full URL, …/v1/logs); a store build only over https
|
|
257
|
+
if (report.via === 'otlp') {
|
|
258
|
+
if (typeof report.endpoint !== 'string' || !/^https?:\/\/[^\s]+$/.test(report.endpoint))
|
|
259
|
+
fail(`${where}.observe.report.endpoint must be the collector's URL (https://…/v1/logs) when via is otlp`);
|
|
260
|
+
if (distribution === 'store' && !report.endpoint.startsWith('https://'))
|
|
261
|
+
fail(`${where}.observe.report.endpoint: a store build sends only over https`);
|
|
262
|
+
} else if (report.endpoint !== null) fail(`${where}.observe.report.endpoint is read only when via is otlp`);
|
|
263
|
+
if (report.service !== null && (typeof report.service !== 'string' || report.service.length === 0))
|
|
264
|
+
fail(`${where}.observe.report.service must be a name (OTLP service.name)`);
|
|
265
|
+
// auto: a report on each new finding, at most one per `auto` seconds — only where the build's consent covers sending
|
|
266
|
+
if (!Number.isInteger(report.auto) || report.auto < 0)
|
|
267
|
+
fail(`${where}.observe.report.auto must be a whole number of seconds (0: only on request)`);
|
|
268
|
+
if (report.auto > 0 && (report.via === 'local' || report.consent !== 'build'))
|
|
269
|
+
fail(`${where}.observe.report.auto sends without asking: it needs a channel (via) and consent "build"`);
|
|
270
|
+
if (distribution === 'store' && observe.report.consent === 'build' && observe.report.via !== 'local')
|
|
271
|
+
fail(`${where}: a store build sends a report only with the user's consent (observe.report.consent: "user")`);
|
|
272
|
+
|
|
273
|
+
return Object.freeze({
|
|
274
|
+
environment,
|
|
275
|
+
profile,
|
|
276
|
+
distribution,
|
|
277
|
+
modules: Object.freeze(modules),
|
|
278
|
+
keys,
|
|
279
|
+
maxScopes: cap,
|
|
280
|
+
signatureRequired,
|
|
281
|
+
port,
|
|
282
|
+
lan,
|
|
283
|
+
badge,
|
|
284
|
+
consent,
|
|
285
|
+
mask,
|
|
286
|
+
session,
|
|
287
|
+
selfDrive,
|
|
288
|
+
observe,
|
|
289
|
+
native: { bridge: modules.bridge, devtool: modules.devtool },
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function offConfig(environment) {
|
|
294
|
+
return Object.freeze({
|
|
295
|
+
environment,
|
|
296
|
+
profile: 'off',
|
|
297
|
+
distribution: 'store',
|
|
298
|
+
modules: Object.freeze(Object.fromEntries(MODULES.map((m) => [m, false]))),
|
|
299
|
+
keys: [],
|
|
300
|
+
maxScopes: [],
|
|
301
|
+
signatureRequired: true,
|
|
302
|
+
port: 8799,
|
|
303
|
+
lan: false,
|
|
304
|
+
badge: 'off',
|
|
305
|
+
consent: 'none',
|
|
306
|
+
mask: 'off',
|
|
307
|
+
session: { maxMinutes: 0 },
|
|
308
|
+
selfDrive: { maxSeconds: 0 },
|
|
309
|
+
observe: OBSERVE_DEFAULTS,
|
|
310
|
+
native: { bridge: false, devtool: false },
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** `g9pilot.config.json` found from `from` upward (the app's folder), parsed, or null when there is none. */
|
|
315
|
+
export function findPilotConfig(from = process.cwd()) {
|
|
316
|
+
for (let dir = resolve(from); ; dir = dirname(dir)) {
|
|
317
|
+
const file = join(dir, 'g9pilot.config.json');
|
|
318
|
+
if (existsSync(file)) {
|
|
319
|
+
try {
|
|
320
|
+
return { file, config: JSON.parse(readFileSync(file, 'utf8')) };
|
|
321
|
+
} catch (e) {
|
|
322
|
+
throw new G9PilotConfigError(`${file} is not valid JSON: ${e.message}`);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (dirname(dir) === dir) return null;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** The environment a build names: the explicit argument, else G9_PILOT_ENV, else none (→ off). */
|
|
330
|
+
export const pilotEnvironment = (explicit, env = process.env) => explicit ?? env.G9_PILOT_ENV ?? null;
|
|
331
|
+
|
|
332
|
+
/** Find, then resolve, in one call (what the plugin and the helpers do). */
|
|
333
|
+
export function loadPilotConfig({ from, environment } = {}) {
|
|
334
|
+
const found = findPilotConfig(from);
|
|
335
|
+
const name = pilotEnvironment(environment);
|
|
336
|
+
if (!found) {
|
|
337
|
+
if (name) fail(`G9_PILOT_ENV is "${name}" but no g9pilot.config.json was found from ${from ?? process.cwd()}`);
|
|
338
|
+
return { file: null, resolved: offConfig(null) };
|
|
339
|
+
}
|
|
340
|
+
return { file: found.file, resolved: resolvePilotConfig(found.config, name, { baseDir: dirname(found.file) }) };
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* The page-side constants of a resolved configuration: what the plugin defines in the bundle. Flat booleans (one per
|
|
345
|
+
* module) so the minifier removes every switched-off branch, and the import it alone used, entirely.
|
|
346
|
+
*/
|
|
347
|
+
export function pilotDefines(resolved) {
|
|
348
|
+
const defines = { __G9_PILOT_PROFILE__: JSON.stringify(resolved.profile) };
|
|
349
|
+
for (const m of MODULES)
|
|
350
|
+
defines[`__G9_PILOT_${m.replace(/[A-Z]/g, (c) => `_${c}`).toUpperCase()}__`] = String(resolved.modules[m]);
|
|
351
|
+
defines.__G9_PILOT_SETTINGS__ = JSON.stringify({
|
|
352
|
+
environment: resolved.environment,
|
|
353
|
+
profile: resolved.profile,
|
|
354
|
+
distribution: resolved.distribution,
|
|
355
|
+
badge: resolved.badge,
|
|
356
|
+
consent: resolved.consent,
|
|
357
|
+
mask: resolved.mask,
|
|
358
|
+
session: resolved.session,
|
|
359
|
+
selfDrive: resolved.selfDrive,
|
|
360
|
+
observe: resolved.observe,
|
|
361
|
+
maxScopes: resolved.maxScopes,
|
|
362
|
+
});
|
|
363
|
+
return defines;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** What the native bridge needs (the host's PilotConfig), nothing the page alone uses. */
|
|
367
|
+
export function nativePilotConfig(r) {
|
|
368
|
+
return {
|
|
369
|
+
profile: r.profile,
|
|
370
|
+
environment: r.environment,
|
|
371
|
+
port: r.port,
|
|
372
|
+
keys: r.keys,
|
|
373
|
+
signatureRequired: r.signatureRequired,
|
|
374
|
+
lan: r.lan,
|
|
375
|
+
consent: r.consent,
|
|
376
|
+
selfDrive: r.modules.selfDrive ? r.selfDrive : null,
|
|
377
|
+
// the build links Lynx DevTool (module devtool): devtool.attach, dev.server and dev.status are the bridge's own
|
|
378
|
+
devtool: r.modules.devtool === true,
|
|
379
|
+
};
|
|
380
|
+
}
|