@camstack/addon-provider-reolink 1.2.230 → 1.2.232
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/CHANGELOG.md +13 -0
- package/dist/addon.js +2223 -1990
- package/dist/addon.mjs +2223 -1990
- package/i18n/en.json +4 -12
- package/i18n/it.json +4 -12
- package/package.json +2 -2
package/dist/addon.mjs
CHANGED
|
@@ -106669,7 +106669,7 @@ var ZodIssueCode = {
|
|
|
106669
106669
|
var ZodFirstPartyTypeKind;
|
|
106670
106670
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
106671
106671
|
//#endregion
|
|
106672
|
-
//#region ../types/dist/sleep-
|
|
106672
|
+
//#region ../types/dist/sleep-D7ZKm4nb.mjs
|
|
106673
106673
|
/**
|
|
106674
106674
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
106675
106675
|
* window to float samples (D455).
|
|
@@ -107353,137 +107353,127 @@ async function runAddonMigrations(host, migrations, logger, options = {}) {
|
|
|
107353
107353
|
blockOwner
|
|
107354
107354
|
};
|
|
107355
107355
|
}
|
|
107356
|
-
/**
|
|
107357
|
-
|
|
107358
|
-
|
|
107359
|
-
|
|
107360
|
-
|
|
107361
|
-
|
|
107362
|
-
|
|
107363
|
-
|
|
107364
|
-
|
|
107365
|
-
|
|
107366
|
-
|
|
107367
|
-
|
|
107368
|
-
|
|
107369
|
-
|
|
107370
|
-
|
|
107371
|
-
|
|
107372
|
-
|
|
107373
|
-
|
|
107374
|
-
const set = async (next) => {
|
|
107375
|
-
const validated = deps.schema.parse(next);
|
|
107376
|
-
await deps.write({ [deps.key]: validated });
|
|
107377
|
-
};
|
|
107378
|
-
const update = async (fn) => {
|
|
107379
|
-
await set(fn(await get()));
|
|
107380
|
-
};
|
|
107356
|
+
/** The record calls the one-switch migration makes, over the migration API. */
|
|
107357
|
+
function switchRecordsOverMigrationApi(api) {
|
|
107358
|
+
return { kind: (definition) => {
|
|
107359
|
+
const handle = api.records.kind(definition);
|
|
107360
|
+
return {
|
|
107361
|
+
get: (id) => handle.get({ id }),
|
|
107362
|
+
put: (input, opts) => handle.put({
|
|
107363
|
+
...input,
|
|
107364
|
+
...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
|
|
107365
|
+
}),
|
|
107366
|
+
patch: (id, partial) => handle.patch({
|
|
107367
|
+
id,
|
|
107368
|
+
partial
|
|
107369
|
+
})
|
|
107370
|
+
};
|
|
107371
|
+
} };
|
|
107372
|
+
}
|
|
107373
|
+
function integrationRowsApiOver(api) {
|
|
107381
107374
|
return {
|
|
107382
|
-
|
|
107383
|
-
|
|
107384
|
-
|
|
107375
|
+
list: async () => (await api.integrations.list({})).integrations,
|
|
107376
|
+
readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
|
|
107377
|
+
clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
|
|
107385
107378
|
};
|
|
107386
107379
|
}
|
|
107380
|
+
var PREFIX = "records/";
|
|
107387
107381
|
/**
|
|
107388
|
-
*
|
|
107389
|
-
*
|
|
107390
|
-
*
|
|
107391
|
-
*
|
|
107392
|
-
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
107393
|
-
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
107394
|
-
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
107395
|
-
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
107396
|
-
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
107397
|
-
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
107398
|
-
*
|
|
107399
|
-
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
107400
|
-
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
107401
|
-
* schema and routes reads/writes through these helpers.
|
|
107402
|
-
*
|
|
107403
|
-
* ## No bare-key fallback — deliberate
|
|
107404
|
-
*
|
|
107405
|
-
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
107406
|
-
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
107407
|
-
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
107408
|
-
* the store is invisible to every node, hub included, so one node's
|
|
107409
|
-
* selection can never leak onto another. (This generalizes the
|
|
107410
|
-
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
107411
|
-
* arbitrary set of per-node field keys.)
|
|
107412
|
-
*
|
|
107413
|
-
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
107414
|
-
* LEAF module: import it via its deep path, never from the root barrel.
|
|
107415
|
-
*/
|
|
107416
|
-
/**
|
|
107417
|
-
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
107418
|
-
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
107419
|
-
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
107420
|
-
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
107382
|
+
* Cross-realm brand. An addon bundles its own copy of this module (D15) while
|
|
107383
|
+
* `ctx.records` is the HOST's door, so an error thrown by the host is an
|
|
107384
|
+
* instance of the host's classes, not of the addon's. The brand plus the code
|
|
107385
|
+
* make `instanceof` answer by identity of the failure, not of the copy.
|
|
107421
107386
|
*/
|
|
107422
|
-
|
|
107423
|
-
|
|
107424
|
-
|
|
107425
|
-
if (slashIdx < 0) return raw;
|
|
107426
|
-
const bare = raw.slice(0, slashIdx);
|
|
107427
|
-
return bare === "" ? "hub" : bare;
|
|
107428
|
-
}
|
|
107429
|
-
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
107430
|
-
function nodeScopedKey(base, nodeId) {
|
|
107431
|
-
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
107387
|
+
var RECORDS_ERROR_BRAND = Symbol.for("camstack.records-error");
|
|
107388
|
+
function carriesBrand(value) {
|
|
107389
|
+
return typeof value === "object" && value !== null && Reflect.get(value, RECORDS_ERROR_BRAND) === true;
|
|
107432
107390
|
}
|
|
107391
|
+
/** The base of every records failure. `detail` is the human part of the message. */
|
|
107392
|
+
var RecordsError = class extends Error {
|
|
107393
|
+
/** The code a subclass stands for; the base stands for every code. */
|
|
107394
|
+
static code = void 0;
|
|
107395
|
+
/**
|
|
107396
|
+
* `instanceof` across copies of this module: any branded error is a
|
|
107397
|
+
* `RecordsError`, and is an instance of a subclass only when its code is the
|
|
107398
|
+
* subclass's code. Same-copy answers are unchanged.
|
|
107399
|
+
*/
|
|
107400
|
+
static [Symbol.hasInstance](value) {
|
|
107401
|
+
if (Function.prototype[Symbol.hasInstance].call(this, value)) return true;
|
|
107402
|
+
if (!carriesBrand(value)) return false;
|
|
107403
|
+
return this.code === void 0 || value.code === this.code;
|
|
107404
|
+
}
|
|
107405
|
+
code;
|
|
107406
|
+
detail;
|
|
107407
|
+
[RECORDS_ERROR_BRAND] = true;
|
|
107408
|
+
constructor(code, detail) {
|
|
107409
|
+
super(`${PREFIX}${code}: ${detail}`);
|
|
107410
|
+
this.name = "RecordsError";
|
|
107411
|
+
this.code = code;
|
|
107412
|
+
this.detail = detail;
|
|
107413
|
+
}
|
|
107414
|
+
};
|
|
107415
|
+
/** A write guarded by `ifRev` found another revision (or an existing row for `ifRev: 0`). */
|
|
107416
|
+
var RevConflictError = class RevConflictError extends RecordsError {
|
|
107417
|
+
static code = "rev-conflict";
|
|
107418
|
+
constructor(detail) {
|
|
107419
|
+
super(RevConflictError.code, detail);
|
|
107420
|
+
this.name = "RevConflictError";
|
|
107421
|
+
}
|
|
107422
|
+
};
|
|
107423
|
+
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
107424
|
+
var RecordSecretUnavailableError = class RecordSecretUnavailableError extends RecordsError {
|
|
107425
|
+
static code = "secret-unavailable";
|
|
107426
|
+
constructor(detail) {
|
|
107427
|
+
super(RecordSecretUnavailableError.code, detail);
|
|
107428
|
+
this.name = "RecordSecretUnavailableError";
|
|
107429
|
+
}
|
|
107430
|
+
};
|
|
107431
|
+
var InvalidRecordError = class InvalidRecordError extends RecordsError {
|
|
107432
|
+
static code = "invalid-record";
|
|
107433
|
+
constructor(detail) {
|
|
107434
|
+
super(InvalidRecordError.code, detail);
|
|
107435
|
+
this.name = "InvalidRecordError";
|
|
107436
|
+
}
|
|
107437
|
+
};
|
|
107438
|
+
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
107439
|
+
var DeclarationRefusedError = class DeclarationRefusedError extends RecordsError {
|
|
107440
|
+
static code = "declaration-refused";
|
|
107441
|
+
constructor(detail) {
|
|
107442
|
+
super(DeclarationRefusedError.code, detail);
|
|
107443
|
+
this.name = "DeclarationRefusedError";
|
|
107444
|
+
}
|
|
107445
|
+
};
|
|
107433
107446
|
/**
|
|
107434
|
-
*
|
|
107435
|
-
*
|
|
107436
|
-
* Deliberately NO bare-key fallback (see module doc) — the caller lets the
|
|
107437
|
-
* schema `default` win on `undefined`.
|
|
107447
|
+
* A link that may stay empty (absent): for a link the addon fills itself, or one an instance does not
|
|
107448
|
+
* always need. The meta rides on the optional wrapper, where {@link linksOfKind} reads it.
|
|
107438
107449
|
*/
|
|
107439
|
-
function
|
|
107440
|
-
return
|
|
107450
|
+
function optionalLinkField(target) {
|
|
107451
|
+
return string().optional().meta({ link: target });
|
|
107441
107452
|
}
|
|
107442
|
-
|
|
107443
|
-
|
|
107444
|
-
|
|
107445
|
-
|
|
107446
|
-
|
|
107447
|
-
* patch is not mutated.
|
|
107448
|
-
*/
|
|
107449
|
-
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
107450
|
-
const out = {};
|
|
107451
|
-
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
107452
|
-
return out;
|
|
107453
|
+
function linkTargetOf(meta) {
|
|
107454
|
+
if (typeof meta !== "object" || meta === null) return void 0;
|
|
107455
|
+
const link = Reflect.get(meta, "link");
|
|
107456
|
+
const parsed = LinkTargetSchema.safeParse(link);
|
|
107457
|
+
return parsed.success ? parsed.data : void 0;
|
|
107453
107458
|
}
|
|
107454
|
-
|
|
107455
|
-
|
|
107456
|
-
|
|
107457
|
-
|
|
107458
|
-
|
|
107459
|
-
|
|
107460
|
-
|
|
107461
|
-
|
|
107462
|
-
|
|
107463
|
-
|
|
107464
|
-
|
|
107465
|
-
|
|
107466
|
-
|
|
107467
|
-
|
|
107468
|
-
|
|
107469
|
-
const out = {};
|
|
107470
|
-
for (const [key, value] of Object.entries(store)) {
|
|
107471
|
-
if (key.includes("@")) continue;
|
|
107472
|
-
if (perNodeKeys.has(key)) continue;
|
|
107473
|
-
out[key] = value;
|
|
107474
|
-
}
|
|
107475
|
-
for (const base of perNodeKeys) {
|
|
107476
|
-
const value = readNodeValue(store, base, nodeId);
|
|
107477
|
-
if (value !== void 0) out[base] = value;
|
|
107459
|
+
var LinkTargetSchema = object({
|
|
107460
|
+
cap: string().min(1),
|
|
107461
|
+
kind: string().min(1).optional()
|
|
107462
|
+
});
|
|
107463
|
+
/** The links a kind declares, read from the meta of its body fields. */
|
|
107464
|
+
function linksOfKind(kind) {
|
|
107465
|
+
const schema = kind.schema;
|
|
107466
|
+
if (!(schema instanceof ZodObject)) return [];
|
|
107467
|
+
const links = [];
|
|
107468
|
+
for (const [field, fieldSchema] of Object.entries(schema.shape)) {
|
|
107469
|
+
const to = linkTargetOf(globalRegistry.get(fieldSchema));
|
|
107470
|
+
if (to !== void 0) links.push({
|
|
107471
|
+
field,
|
|
107472
|
+
to
|
|
107473
|
+
});
|
|
107478
107474
|
}
|
|
107479
|
-
return
|
|
107475
|
+
return links;
|
|
107480
107476
|
}
|
|
107481
|
-
/** Every scope, in the order the guard and the docs list them. */
|
|
107482
|
-
var SCOPED_SETTINGS_SCOPES = [
|
|
107483
|
-
"cluster",
|
|
107484
|
-
"device-defaults",
|
|
107485
|
-
"node"
|
|
107486
|
-
];
|
|
107487
107477
|
/**
|
|
107488
107478
|
* The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
|
|
107489
107479
|
*
|
|
@@ -107618,6 +107608,652 @@ function parseSecretRef(ref) {
|
|
|
107618
107608
|
fieldPath
|
|
107619
107609
|
};
|
|
107620
107610
|
}
|
|
107611
|
+
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
107612
|
+
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
107613
|
+
var RECORD_DATABASES = ["settings", "events"];
|
|
107614
|
+
/** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
|
|
107615
|
+
var RECORD_CLASSES = [
|
|
107616
|
+
"config",
|
|
107617
|
+
"ledger",
|
|
107618
|
+
"audit",
|
|
107619
|
+
"mirror",
|
|
107620
|
+
"ephemeral"
|
|
107621
|
+
];
|
|
107622
|
+
var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
107623
|
+
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
107624
|
+
var RECORD_BATCH_MAX = 1e3;
|
|
107625
|
+
var RECORD_QUERY_MAX = 1e3;
|
|
107626
|
+
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
107627
|
+
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
107628
|
+
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
107629
|
+
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
107630
|
+
/**
|
|
107631
|
+
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
107632
|
+
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
107633
|
+
* (`auth.accessToken`, `headers[].value`).
|
|
107634
|
+
*
|
|
107635
|
+
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
107636
|
+
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
107637
|
+
* key releases exactly that key's secret.
|
|
107638
|
+
*
|
|
107639
|
+
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
107640
|
+
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
107641
|
+
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
107642
|
+
* leaf names its element: `headers[X-Api].value`.
|
|
107643
|
+
*
|
|
107644
|
+
* Pure and browser-safe. Nothing here mutates: every transform returns a new value.
|
|
107645
|
+
*/
|
|
107646
|
+
/** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
|
|
107647
|
+
function parseSecretPath(path) {
|
|
107648
|
+
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
107649
|
+
return path.split(".").map((raw) => {
|
|
107650
|
+
const each = raw.endsWith("[]");
|
|
107651
|
+
const map = raw.endsWith("{}");
|
|
107652
|
+
const key = each || map ? raw.slice(0, -2) : raw;
|
|
107653
|
+
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
107654
|
+
return {
|
|
107655
|
+
key,
|
|
107656
|
+
each,
|
|
107657
|
+
map
|
|
107658
|
+
};
|
|
107659
|
+
});
|
|
107660
|
+
}
|
|
107661
|
+
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
107662
|
+
function secretArrayPrefixes(path) {
|
|
107663
|
+
const segments = parseSecretPath(path);
|
|
107664
|
+
const prefixes = [];
|
|
107665
|
+
const walked = [];
|
|
107666
|
+
for (const segment of segments) {
|
|
107667
|
+
walked.push(segment.key);
|
|
107668
|
+
if (segment.each) prefixes.push(walked.join("."));
|
|
107669
|
+
}
|
|
107670
|
+
return prefixes;
|
|
107671
|
+
}
|
|
107672
|
+
function isRecord$6(value) {
|
|
107673
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
107674
|
+
}
|
|
107675
|
+
function elementId(element, idKey, declared, prefix) {
|
|
107676
|
+
const id = isRecord$6(element) ? element[idKey] : void 0;
|
|
107677
|
+
if (typeof id !== "string" || id.length === 0) throw new InvalidRecordError(`"${declared}": every element of "${prefix}" needs a non-empty string "${idKey}" to carry a secret`);
|
|
107678
|
+
return id;
|
|
107679
|
+
}
|
|
107680
|
+
/**
|
|
107681
|
+
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
107682
|
+
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
107683
|
+
* result is a new body, `data` is untouched.
|
|
107684
|
+
*/
|
|
107685
|
+
var REMOVE_LEAF = Symbol("remove-leaf");
|
|
107686
|
+
function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
|
|
107687
|
+
if (!isRecord$6(node)) return node;
|
|
107688
|
+
const segment = segments[index];
|
|
107689
|
+
if (segment === void 0) return node;
|
|
107690
|
+
if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
|
|
107691
|
+
const child = node[segment.key];
|
|
107692
|
+
const keys = [...walkedKeys, segment.key];
|
|
107693
|
+
const last = index === segments.length - 1;
|
|
107694
|
+
if (segment.each) {
|
|
107695
|
+
if (!Array.isArray(child)) return node;
|
|
107696
|
+
const prefix = keys.join(".");
|
|
107697
|
+
const idKey = arrayKeys[prefix];
|
|
107698
|
+
if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
|
|
107699
|
+
const mapped = child.map((element) => {
|
|
107700
|
+
const id = elementId(element, idKey, declared, prefix);
|
|
107701
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
|
|
107702
|
+
return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
|
|
107703
|
+
});
|
|
107704
|
+
return {
|
|
107705
|
+
...node,
|
|
107706
|
+
[segment.key]: mapped
|
|
107707
|
+
};
|
|
107708
|
+
}
|
|
107709
|
+
if (segment.map) {
|
|
107710
|
+
if (!isRecord$6(child)) return node;
|
|
107711
|
+
const kept = Object.entries(child).map(([mapKey, value]) => {
|
|
107712
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
|
|
107713
|
+
if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
|
|
107714
|
+
return [mapKey, visit({
|
|
107715
|
+
declared,
|
|
107716
|
+
concrete,
|
|
107717
|
+
value
|
|
107718
|
+
})];
|
|
107719
|
+
}).filter(([, value]) => value !== REMOVE_LEAF);
|
|
107720
|
+
return {
|
|
107721
|
+
...node,
|
|
107722
|
+
[segment.key]: Object.fromEntries(kept)
|
|
107723
|
+
};
|
|
107724
|
+
}
|
|
107725
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
107726
|
+
if (last) {
|
|
107727
|
+
const replacement = visit({
|
|
107728
|
+
declared,
|
|
107729
|
+
concrete,
|
|
107730
|
+
value: child
|
|
107731
|
+
});
|
|
107732
|
+
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
107733
|
+
return {
|
|
107734
|
+
...node,
|
|
107735
|
+
[segment.key]: replacement
|
|
107736
|
+
};
|
|
107737
|
+
}
|
|
107738
|
+
return {
|
|
107739
|
+
...node,
|
|
107740
|
+
[segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
|
|
107741
|
+
};
|
|
107742
|
+
}
|
|
107743
|
+
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
107744
|
+
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
107745
|
+
let current = data;
|
|
107746
|
+
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
107747
|
+
return current;
|
|
107748
|
+
}
|
|
107749
|
+
/** Every present secret leaf, read-only. */
|
|
107750
|
+
function collectSecretLeaves(data, paths, arrayKeys) {
|
|
107751
|
+
const found = [];
|
|
107752
|
+
mapSecretLeaves(data, paths, arrayKeys, (leaf) => {
|
|
107753
|
+
found.push(leaf);
|
|
107754
|
+
return leaf.value;
|
|
107755
|
+
});
|
|
107756
|
+
return found;
|
|
107757
|
+
}
|
|
107758
|
+
/**
|
|
107759
|
+
* The keychain collection name a kind's secrets live under. Prefixed so a
|
|
107760
|
+
* record's refs never collide with the refs a legacy collection of the same name
|
|
107761
|
+
* already holds during an adoption.
|
|
107762
|
+
*/
|
|
107763
|
+
function recordSecretCollection(kind) {
|
|
107764
|
+
return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
|
|
107765
|
+
}
|
|
107766
|
+
/** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
|
|
107767
|
+
function recordSecretRef(owner, kind, rowId, concretePath) {
|
|
107768
|
+
return buildSecretRef({
|
|
107769
|
+
owner,
|
|
107770
|
+
scope: {
|
|
107771
|
+
kind: "row",
|
|
107772
|
+
collection: recordSecretCollection(kind),
|
|
107773
|
+
rowId
|
|
107774
|
+
},
|
|
107775
|
+
fieldPath: concretePath
|
|
107776
|
+
});
|
|
107777
|
+
}
|
|
107778
|
+
/**
|
|
107779
|
+
* A stored secret, as an admin read shows it: a VIEW naming the row's own
|
|
107780
|
+
* keychain ref (`set: true`), never the value and no longer the bare redaction
|
|
107781
|
+
* token. The form hands it to the secret field, which reveals the value by ref
|
|
107782
|
+
* through the audited `keychain-admin.reveal`; sent back untouched it keeps the
|
|
107783
|
+
* stored secret (the records door reads a view as KEEP).
|
|
107784
|
+
*
|
|
107785
|
+
* ONE implementation for the entries service and for every addon that serves
|
|
107786
|
+
* its own instances (`RecordIntegrationInstances`).
|
|
107787
|
+
*/
|
|
107788
|
+
function isRecord$5(value) {
|
|
107789
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
107790
|
+
}
|
|
107791
|
+
function secretViewsOf(owner, kind, id, decl, data) {
|
|
107792
|
+
if (decl.secretPaths.length === 0) return data;
|
|
107793
|
+
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
107794
|
+
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
107795
|
+
return {
|
|
107796
|
+
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
107797
|
+
v: 1,
|
|
107798
|
+
set: true
|
|
107799
|
+
};
|
|
107800
|
+
});
|
|
107801
|
+
return isRecord$5(shown) ? shown : data;
|
|
107802
|
+
}
|
|
107803
|
+
/** The most instances one addon lists (an integrations page, not a table). */
|
|
107804
|
+
var INSTANCES_LIST_MAX = 1e3;
|
|
107805
|
+
/**
|
|
107806
|
+
* The ONE reader of an instance's switch (D996): an absent field means on, so a row written
|
|
107807
|
+
* before the field existed needs no migration. Every consumer of an instance body asks this.
|
|
107808
|
+
*/
|
|
107809
|
+
function isInstanceEnabled(body) {
|
|
107810
|
+
return body.enabled !== false;
|
|
107811
|
+
}
|
|
107812
|
+
/** The body key of the switch; only {@link RecordIntegrationInstances.setInstanceEnabled} writes it. */
|
|
107813
|
+
var SWITCH_KEY = "enabled";
|
|
107814
|
+
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
107815
|
+
function topLevelSecretKeys(paths) {
|
|
107816
|
+
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
107817
|
+
}
|
|
107818
|
+
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
107819
|
+
function secretMapKeys(paths) {
|
|
107820
|
+
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
107821
|
+
}
|
|
107822
|
+
/**
|
|
107823
|
+
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
107824
|
+
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
107825
|
+
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
107826
|
+
*/
|
|
107827
|
+
function secretMapPatch(value) {
|
|
107828
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
107829
|
+
const out = {};
|
|
107830
|
+
for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
|
|
107831
|
+
else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
|
|
107832
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
107833
|
+
}
|
|
107834
|
+
var RecordIntegrationInstances = class {
|
|
107835
|
+
records;
|
|
107836
|
+
kind;
|
|
107837
|
+
hooks;
|
|
107838
|
+
handle;
|
|
107839
|
+
secretKeys;
|
|
107840
|
+
secretMaps;
|
|
107841
|
+
nameField;
|
|
107842
|
+
switchListeners = /* @__PURE__ */ new Set();
|
|
107843
|
+
constructor(records, kind, hooks) {
|
|
107844
|
+
this.records = records;
|
|
107845
|
+
this.kind = kind;
|
|
107846
|
+
this.hooks = hooks;
|
|
107847
|
+
this.handle = records.kind(kind);
|
|
107848
|
+
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
107849
|
+
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
107850
|
+
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
107851
|
+
}
|
|
107852
|
+
/**
|
|
107853
|
+
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
107854
|
+
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
107855
|
+
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
107856
|
+
*/
|
|
107857
|
+
async readResolved(id) {
|
|
107858
|
+
try {
|
|
107859
|
+
const record = await this.handle.getResolved(id);
|
|
107860
|
+
return record === null ? null : {
|
|
107861
|
+
id,
|
|
107862
|
+
body: record.data,
|
|
107863
|
+
enabled: isInstanceEnabled(record.data),
|
|
107864
|
+
secrets: "resolved"
|
|
107865
|
+
};
|
|
107866
|
+
} catch (err) {
|
|
107867
|
+
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
107868
|
+
const stored = await this.handle.get(id);
|
|
107869
|
+
if (stored === null) return null;
|
|
107870
|
+
return {
|
|
107871
|
+
id,
|
|
107872
|
+
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
107873
|
+
enabled: isInstanceEnabled(stored.data),
|
|
107874
|
+
secrets: "unavailable"
|
|
107875
|
+
};
|
|
107876
|
+
}
|
|
107877
|
+
}
|
|
107878
|
+
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
107879
|
+
async getResolved(id) {
|
|
107880
|
+
return (await this.readResolved(id))?.body ?? null;
|
|
107881
|
+
}
|
|
107882
|
+
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
107883
|
+
async listResolved() {
|
|
107884
|
+
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
107885
|
+
const out = [];
|
|
107886
|
+
for (const record of page.records) {
|
|
107887
|
+
const read = await this.readResolved(record.id);
|
|
107888
|
+
if (read !== null) out.push(read);
|
|
107889
|
+
}
|
|
107890
|
+
return out;
|
|
107891
|
+
}
|
|
107892
|
+
viewOf(record) {
|
|
107893
|
+
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
107894
|
+
const rawName = record.data[this.nameField];
|
|
107895
|
+
const kind = this.hooks.kindOf?.(record.data);
|
|
107896
|
+
const health = this.hooks.health?.(record.data, record.id);
|
|
107897
|
+
return {
|
|
107898
|
+
id: record.id,
|
|
107899
|
+
name: typeof rawName === "string" ? rawName : record.id,
|
|
107900
|
+
configured: this.hooks.configured(record.data),
|
|
107901
|
+
enabled: isInstanceEnabled(record.data),
|
|
107902
|
+
formValues: shown,
|
|
107903
|
+
...kind !== void 0 ? { kind } : {},
|
|
107904
|
+
...health?.status !== void 0 ? { status: health.status } : {},
|
|
107905
|
+
...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
|
|
107906
|
+
};
|
|
107907
|
+
}
|
|
107908
|
+
describe = async () => {
|
|
107909
|
+
const declared = linksOfKind(this.kind);
|
|
107910
|
+
const links = this.hooks.description.links !== void 0 || declared.length === 0 ? {} : { links: declared.map((link) => ({
|
|
107911
|
+
kind: this.kind.name,
|
|
107912
|
+
field: link.field,
|
|
107913
|
+
to: link.to
|
|
107914
|
+
})) };
|
|
107915
|
+
return {
|
|
107916
|
+
...this.hooks.description,
|
|
107917
|
+
...links,
|
|
107918
|
+
...this.hooks.mintId === void 0 ? {} : { mintsId: true }
|
|
107919
|
+
};
|
|
107920
|
+
};
|
|
107921
|
+
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
107922
|
+
listInstances = async () => {
|
|
107923
|
+
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
107924
|
+
};
|
|
107925
|
+
getInstance = async ({ id }) => {
|
|
107926
|
+
const record = await this.handle.get(id);
|
|
107927
|
+
return record === null ? null : this.viewOf(record);
|
|
107928
|
+
};
|
|
107929
|
+
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
107930
|
+
createInstance = async ({ id, name, kind, values }) => {
|
|
107931
|
+
const minted = id ?? this.hooks.mintId?.({
|
|
107932
|
+
name,
|
|
107933
|
+
...kind !== void 0 ? { kind } : {}
|
|
107934
|
+
});
|
|
107935
|
+
if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
|
|
107936
|
+
await this.handle.put({
|
|
107937
|
+
id: minted,
|
|
107938
|
+
data: this.hooks.initialBody(name, kind)
|
|
107939
|
+
}, { ifRev: 0 });
|
|
107940
|
+
const patch = this.patchOf(values ?? {});
|
|
107941
|
+
if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
|
|
107942
|
+
await this.hooks.onChanged?.(minted, "created");
|
|
107943
|
+
return { id: minted };
|
|
107944
|
+
};
|
|
107945
|
+
updateInstance = async ({ id, name, values }) => {
|
|
107946
|
+
const patch = this.patchOf(values);
|
|
107947
|
+
if (name !== void 0) patch[this.nameField] = name;
|
|
107948
|
+
await this.handle.patch(id, patch);
|
|
107949
|
+
await this.hooks.onChanged?.(id, "updated");
|
|
107950
|
+
return { ok: true };
|
|
107951
|
+
};
|
|
107952
|
+
/** The record patch a form `values` object means: secrets kept, cleared or replaced. */
|
|
107953
|
+
patchOf(values) {
|
|
107954
|
+
const patch = {};
|
|
107955
|
+
for (const [key, value] of Object.entries(values)) {
|
|
107956
|
+
if (value === void 0) continue;
|
|
107957
|
+
if (key === "enabled") continue;
|
|
107958
|
+
if (this.secretMaps.has(key)) {
|
|
107959
|
+
const entries = secretMapPatch(value);
|
|
107960
|
+
if (entries !== null) patch[key] = entries;
|
|
107961
|
+
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
107962
|
+
else if (isSecretClear(value)) patch[key] = null;
|
|
107963
|
+
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
107964
|
+
}
|
|
107965
|
+
return patch;
|
|
107966
|
+
}
|
|
107967
|
+
/**
|
|
107968
|
+
* Listen to the switch of ANY instance of this helper (in the process that serves it). The
|
|
107969
|
+
* durable replacement of the `integration.enabled` / `integration.disabled` events (D8): the
|
|
107970
|
+
* addon reconciles from the record, whichever way it flipped.
|
|
107971
|
+
*/
|
|
107972
|
+
onSwitched(listener) {
|
|
107973
|
+
this.switchListeners.add(listener);
|
|
107974
|
+
}
|
|
107975
|
+
/**
|
|
107976
|
+
* The ONE writer of the switch (D996, D1014): the record body's `enabled`, for every role. A
|
|
107977
|
+
* configured thing is an instance, so an id with no record yet (a default integration that was
|
|
107978
|
+
* never configured) gets its record from `initialBody` before the switch is written.
|
|
107979
|
+
*/
|
|
107980
|
+
setInstanceEnabled = async ({ id, enabled }) => {
|
|
107981
|
+
if (await this.handle.get(id) === null) await this.handle.put({
|
|
107982
|
+
id,
|
|
107983
|
+
data: this.hooks.initialBody(id)
|
|
107984
|
+
}, { ifRev: 0 });
|
|
107985
|
+
await this.handle.patch(id, { [SWITCH_KEY]: enabled });
|
|
107986
|
+
await this.hooks.onChanged?.(id, "enabled");
|
|
107987
|
+
for (const listener of this.switchListeners) await listener(id, enabled);
|
|
107988
|
+
return { ok: true };
|
|
107989
|
+
};
|
|
107990
|
+
/** The row and its keychain refs go together (the records door). */
|
|
107991
|
+
deleteInstance = async ({ id }) => {
|
|
107992
|
+
await this.handle.delete(id);
|
|
107993
|
+
await this.hooks.onChanged?.(id, "deleted");
|
|
107994
|
+
return { ok: true };
|
|
107995
|
+
};
|
|
107996
|
+
testInstance = async (input) => {
|
|
107997
|
+
if (this.hooks.test === void 0) return {
|
|
107998
|
+
success: false,
|
|
107999
|
+
status: "unsupported",
|
|
108000
|
+
error: "This integration declares no connection test"
|
|
108001
|
+
};
|
|
108002
|
+
return this.hooks.test(input);
|
|
108003
|
+
};
|
|
108004
|
+
/** The flat provider object to hand to `registerProvider`. */
|
|
108005
|
+
toProvider() {
|
|
108006
|
+
return {
|
|
108007
|
+
describe: this.describe,
|
|
108008
|
+
instanceFormSchema: this.instanceFormSchema,
|
|
108009
|
+
listInstances: this.listInstances,
|
|
108010
|
+
getInstance: this.getInstance,
|
|
108011
|
+
createInstance: this.createInstance,
|
|
108012
|
+
updateInstance: this.updateInstance,
|
|
108013
|
+
setInstanceEnabled: this.setInstanceEnabled,
|
|
108014
|
+
deleteInstance: this.deleteInstance,
|
|
108015
|
+
testInstance: this.testInstance
|
|
108016
|
+
};
|
|
108017
|
+
}
|
|
108018
|
+
};
|
|
108019
|
+
/**
|
|
108020
|
+
* The one-switch migration (epic #440, step 3). An integration's on/off state used to live in the
|
|
108021
|
+
* registry's `enabled` column for a device addon; it now lives only in the instance record's
|
|
108022
|
+
* body (`enabled`, D1007 superseded). This moves a registry `enabled = false` into the body, once.
|
|
108023
|
+
*
|
|
108024
|
+
* For every registry row of the addon that is OFF:
|
|
108025
|
+
* - no record under its id: the record is created from `initialBody(name)` with `enabled: false`
|
|
108026
|
+
* (a default integration that never had settings, Reolink's among them);
|
|
108027
|
+
* - a record whose body states no `enabled`: `enabled: false` is written into it;
|
|
108028
|
+
* - a record that already states `enabled` (either way) is the newer truth and is left alone.
|
|
108029
|
+
* A row that is ON writes nothing: an absent field reads as on. A rerun finds every off row with
|
|
108030
|
+
* a stated switch and does nothing, so nothing switched off comes back on and nothing switched on
|
|
108031
|
+
* goes off. The registry column itself is neither read afterwards nor written; its drop is step 5.
|
|
108032
|
+
*
|
|
108033
|
+
* It runs in the addon process, BEFORE the addon registers its `integration-instances` provider,
|
|
108034
|
+
* which is also why `integrations.list` still answers the stored column at that point.
|
|
108035
|
+
*/
|
|
108036
|
+
function registrySwitchToBodyId(addonId, date) {
|
|
108037
|
+
return `${addonId}/${date}-registry-switch-to-body`;
|
|
108038
|
+
}
|
|
108039
|
+
async function moveRegistrySwitchToBody(ports, spec) {
|
|
108040
|
+
const rows = await ports.listIntegrations(spec.addonId);
|
|
108041
|
+
let created = 0;
|
|
108042
|
+
let switched = 0;
|
|
108043
|
+
let kept = 0;
|
|
108044
|
+
for (const row of rows) {
|
|
108045
|
+
if (row.enabled) continue;
|
|
108046
|
+
const body = await ports.readBody(row.id);
|
|
108047
|
+
if (body === null) {
|
|
108048
|
+
if (await ports.createRecord(row.id, {
|
|
108049
|
+
...spec.initialBody(row.name),
|
|
108050
|
+
["enabled"]: false
|
|
108051
|
+
}) === "created") created += 1;
|
|
108052
|
+
else kept += 1;
|
|
108053
|
+
continue;
|
|
108054
|
+
}
|
|
108055
|
+
if ("enabled" in body) {
|
|
108056
|
+
kept += 1;
|
|
108057
|
+
continue;
|
|
108058
|
+
}
|
|
108059
|
+
await ports.switchOff(row.id);
|
|
108060
|
+
switched += 1;
|
|
108061
|
+
}
|
|
108062
|
+
const summary = {
|
|
108063
|
+
integrations: rows.length,
|
|
108064
|
+
off: rows.filter((r) => !r.enabled).length,
|
|
108065
|
+
created,
|
|
108066
|
+
switched,
|
|
108067
|
+
kept
|
|
108068
|
+
};
|
|
108069
|
+
return created === 0 && switched === 0 ? {
|
|
108070
|
+
outcome: "already-done",
|
|
108071
|
+
summary
|
|
108072
|
+
} : {
|
|
108073
|
+
outcome: "done",
|
|
108074
|
+
summary
|
|
108075
|
+
};
|
|
108076
|
+
}
|
|
108077
|
+
/** A migration entry: an addon states its kind and how a new body starts, nothing else. */
|
|
108078
|
+
function registrySwitchToBodyMigration(spec) {
|
|
108079
|
+
return {
|
|
108080
|
+
meta: {
|
|
108081
|
+
id: registrySwitchToBodyId(spec.addonId, spec.date),
|
|
108082
|
+
owner: spec.addonId,
|
|
108083
|
+
level: "addon-state",
|
|
108084
|
+
seq: spec.seq,
|
|
108085
|
+
dependsOn: [],
|
|
108086
|
+
store: "settings",
|
|
108087
|
+
scope: "cluster",
|
|
108088
|
+
onFailure: "block-owner",
|
|
108089
|
+
bodyKind: "procedure",
|
|
108090
|
+
description: "Move the registry enabled flag of every switched-off integration into its instance record body, creating the record when there is none",
|
|
108091
|
+
fixtureMark: "enabled"
|
|
108092
|
+
},
|
|
108093
|
+
procedure: (ports) => moveRegistrySwitchToBody(ports, {
|
|
108094
|
+
addonId: spec.addonId,
|
|
108095
|
+
initialBody: spec.initialBody
|
|
108096
|
+
})
|
|
108097
|
+
};
|
|
108098
|
+
}
|
|
108099
|
+
/** The hub and records sides of {@link registrySwitchToBodyMigration}. */
|
|
108100
|
+
function registrySwitchPortsOver(deps) {
|
|
108101
|
+
const handle = deps.records.kind({
|
|
108102
|
+
name: deps.kind.name,
|
|
108103
|
+
declaration: deps.kind.declaration,
|
|
108104
|
+
schema: record(string(), unknown())
|
|
108105
|
+
});
|
|
108106
|
+
return {
|
|
108107
|
+
listIntegrations: async (addonId) => (await deps.api.list()).filter((i) => i.addonId === addonId).map((i) => ({
|
|
108108
|
+
id: i.id,
|
|
108109
|
+
name: i.name,
|
|
108110
|
+
enabled: i.enabled !== false
|
|
108111
|
+
})),
|
|
108112
|
+
readBody: async (id) => (await handle.get(id))?.data ?? null,
|
|
108113
|
+
createRecord: async (id, body) => {
|
|
108114
|
+
if (await handle.get(id) !== null) return "exists";
|
|
108115
|
+
await handle.put({
|
|
108116
|
+
id,
|
|
108117
|
+
data: body
|
|
108118
|
+
}, { ifRev: 0 });
|
|
108119
|
+
return "created";
|
|
108120
|
+
},
|
|
108121
|
+
switchOff: async (id) => {
|
|
108122
|
+
await handle.patch(id, { [SWITCH_KEY]: false });
|
|
108123
|
+
}
|
|
108124
|
+
};
|
|
108125
|
+
}
|
|
108126
|
+
/**
|
|
108127
|
+
* Build a {@link DurableState} over a single store key. Transport-agnostic:
|
|
108128
|
+
* `read`/`write` are the addon-store or device-store accessors. The whole
|
|
108129
|
+
* validated value round-trips on every read/write — the schema is the
|
|
108130
|
+
* single source of truth for what is persisted, so no hand-listed field
|
|
108131
|
+
* set can drop a key on save.
|
|
108132
|
+
*/
|
|
108133
|
+
function createDurableState(deps) {
|
|
108134
|
+
const get = async () => {
|
|
108135
|
+
const raw = (await deps.read())[deps.key];
|
|
108136
|
+
if (raw === void 0) return deps.fallback;
|
|
108137
|
+
const parsed = deps.schema.safeParse(raw);
|
|
108138
|
+
if (!parsed.success) {
|
|
108139
|
+
deps.onParseError?.(deps.key, parsed.error);
|
|
108140
|
+
return deps.fallback;
|
|
108141
|
+
}
|
|
108142
|
+
return parsed.data;
|
|
108143
|
+
};
|
|
108144
|
+
const set = async (next) => {
|
|
108145
|
+
const validated = deps.schema.parse(next);
|
|
108146
|
+
await deps.write({ [deps.key]: validated });
|
|
108147
|
+
};
|
|
108148
|
+
const update = async (fn) => {
|
|
108149
|
+
await set(fn(await get()));
|
|
108150
|
+
};
|
|
108151
|
+
return {
|
|
108152
|
+
get,
|
|
108153
|
+
set,
|
|
108154
|
+
update
|
|
108155
|
+
};
|
|
108156
|
+
}
|
|
108157
|
+
/**
|
|
108158
|
+
* Per-node scoping for the shared addon-settings blob.
|
|
108159
|
+
*
|
|
108160
|
+
* An addon's settings store is hub-central (the `addon-settings` cap is
|
|
108161
|
+
* hub-routed — the hub instance answers for every node), so fields whose
|
|
108162
|
+
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
108163
|
+
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
108164
|
+
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
108165
|
+
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
108166
|
+
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
108167
|
+
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
108168
|
+
*
|
|
108169
|
+
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
108170
|
+
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
108171
|
+
* schema and routes reads/writes through these helpers.
|
|
108172
|
+
*
|
|
108173
|
+
* ## No bare-key fallback — deliberate
|
|
108174
|
+
*
|
|
108175
|
+
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
108176
|
+
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
108177
|
+
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
108178
|
+
* the store is invisible to every node, hub included, so one node's
|
|
108179
|
+
* selection can never leak onto another. (This generalizes the
|
|
108180
|
+
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
108181
|
+
* arbitrary set of per-node field keys.)
|
|
108182
|
+
*
|
|
108183
|
+
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
108184
|
+
* LEAF module: import it via its deep path, never from the root barrel.
|
|
108185
|
+
*/
|
|
108186
|
+
/**
|
|
108187
|
+
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
108188
|
+
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
108189
|
+
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
108190
|
+
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
108191
|
+
*/
|
|
108192
|
+
function normalizeNodeId(raw) {
|
|
108193
|
+
if (raw === void 0 || raw === null || raw === "") return "hub";
|
|
108194
|
+
const slashIdx = raw.indexOf("/");
|
|
108195
|
+
if (slashIdx < 0) return raw;
|
|
108196
|
+
const bare = raw.slice(0, slashIdx);
|
|
108197
|
+
return bare === "" ? "hub" : bare;
|
|
108198
|
+
}
|
|
108199
|
+
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
108200
|
+
function nodeScopedKey(base, nodeId) {
|
|
108201
|
+
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
108202
|
+
}
|
|
108203
|
+
/**
|
|
108204
|
+
* Read a node's value for a per-node field from the raw shared store:
|
|
108205
|
+
* the node-scoped key when present, otherwise `undefined`.
|
|
108206
|
+
* Deliberately NO bare-key fallback (see module doc) — the caller lets the
|
|
108207
|
+
* schema `default` win on `undefined`.
|
|
108208
|
+
*/
|
|
108209
|
+
function readNodeValue(store, base, nodeId) {
|
|
108210
|
+
return store[nodeScopedKey(base, nodeId)];
|
|
108211
|
+
}
|
|
108212
|
+
/**
|
|
108213
|
+
* Re-map a UI/settings patch so every bare perNode field persists under the
|
|
108214
|
+
* TARGET node's scoped key; all other keys pass through unchanged. Used on
|
|
108215
|
+
* the write path so a save for one node never clobbers another node's value
|
|
108216
|
+
* (and the bare key is never written). Returns a new object — the input
|
|
108217
|
+
* patch is not mutated.
|
|
108218
|
+
*/
|
|
108219
|
+
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
108220
|
+
const out = {};
|
|
108221
|
+
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
108222
|
+
return out;
|
|
108223
|
+
}
|
|
108224
|
+
/**
|
|
108225
|
+
* Project the raw shared store onto the bare schema keys for ONE node so a
|
|
108226
|
+
* UI schema (whose field keys are bare) hydrates from that node's own
|
|
108227
|
+
* values:
|
|
108228
|
+
*
|
|
108229
|
+
* - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
|
|
108230
|
+
* - Every bare perNode key is dropped from the pass-through (a stray bare
|
|
108231
|
+
* legacy key must never hydrate any node — no bare fallback).
|
|
108232
|
+
* - THIS node's effective value ({@link readNodeValue}) is then laid onto
|
|
108233
|
+
* each bare perNode key; when the node has no scoped key the bare key is
|
|
108234
|
+
* left ABSENT so the field's schema `default` wins.
|
|
108235
|
+
*
|
|
108236
|
+
* Returns a new object — the input store is not mutated.
|
|
108237
|
+
*/
|
|
108238
|
+
function projectStore(store, perNodeKeys, nodeId) {
|
|
108239
|
+
const out = {};
|
|
108240
|
+
for (const [key, value] of Object.entries(store)) {
|
|
108241
|
+
if (key.includes("@")) continue;
|
|
108242
|
+
if (perNodeKeys.has(key)) continue;
|
|
108243
|
+
out[key] = value;
|
|
108244
|
+
}
|
|
108245
|
+
for (const base of perNodeKeys) {
|
|
108246
|
+
const value = readNodeValue(store, base, nodeId);
|
|
108247
|
+
if (value !== void 0) out[base] = value;
|
|
108248
|
+
}
|
|
108249
|
+
return out;
|
|
108250
|
+
}
|
|
108251
|
+
/** Every scope, in the order the guard and the docs list them. */
|
|
108252
|
+
var SCOPED_SETTINGS_SCOPES = [
|
|
108253
|
+
"cluster",
|
|
108254
|
+
"device-defaults",
|
|
108255
|
+
"node"
|
|
108256
|
+
];
|
|
107621
108257
|
/** A write to a secret path could not be stored in the keychain, so it was refused. */
|
|
107622
108258
|
var KeychainWriteRefusedError = class extends Error {
|
|
107623
108259
|
fieldPath;
|
|
@@ -107628,7 +108264,7 @@ var KeychainWriteRefusedError = class extends Error {
|
|
|
107628
108264
|
}
|
|
107629
108265
|
};
|
|
107630
108266
|
var KEEP = { kind: "keep" };
|
|
107631
|
-
function isRecord$
|
|
108267
|
+
function isRecord$4(value) {
|
|
107632
108268
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
107633
108269
|
}
|
|
107634
108270
|
function defaultMintId() {
|
|
@@ -107641,7 +108277,7 @@ function collectSecretMarkerRefs(value, out = []) {
|
|
|
107641
108277
|
return out;
|
|
107642
108278
|
}
|
|
107643
108279
|
if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
|
|
107644
|
-
else if (isRecord$
|
|
108280
|
+
else if (isRecord$4(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
|
|
107645
108281
|
return out;
|
|
107646
108282
|
}
|
|
107647
108283
|
async function storedValueEquals(secrets, marker, candidate) {
|
|
@@ -107696,7 +108332,7 @@ function rowId(row, idKey) {
|
|
|
107696
108332
|
return null;
|
|
107697
108333
|
}
|
|
107698
108334
|
async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
107699
|
-
const storedRows = Array.isArray(stored) ? stored.filter(isRecord$
|
|
108335
|
+
const storedRows = Array.isArray(stored) ? stored.filter(isRecord$4) : [];
|
|
107700
108336
|
if (!Array.isArray(incoming)) {
|
|
107701
108337
|
ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
|
|
107702
108338
|
return {
|
|
@@ -107712,7 +108348,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
107712
108348
|
const kept = /* @__PURE__ */ new Set();
|
|
107713
108349
|
const rows = [];
|
|
107714
108350
|
for (const row of incoming) {
|
|
107715
|
-
if (!isRecord$
|
|
108351
|
+
if (!isRecord$4(row)) {
|
|
107716
108352
|
rows.push(row);
|
|
107717
108353
|
continue;
|
|
107718
108354
|
}
|
|
@@ -107737,7 +108373,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
|
|
|
107737
108373
|
case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
|
|
107738
108374
|
case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
|
|
107739
108375
|
case "object": {
|
|
107740
|
-
if (!isRecord$
|
|
108376
|
+
if (!isRecord$4(incoming)) {
|
|
107741
108377
|
if (incoming === void 0) return KEEP;
|
|
107742
108378
|
ctx.deletes.push(...collectSecretMarkerRefs(stored));
|
|
107743
108379
|
return {
|
|
@@ -107745,7 +108381,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
|
|
|
107745
108381
|
value: incoming
|
|
107746
108382
|
};
|
|
107747
108383
|
}
|
|
107748
|
-
const storedObj = isRecord$
|
|
108384
|
+
const storedObj = isRecord$4(stored) ? stored : {};
|
|
107749
108385
|
return {
|
|
107750
108386
|
kind: "value",
|
|
107751
108387
|
value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
|
|
@@ -107868,7 +108504,7 @@ async function resolveSecretMarkers(value, secrets, options = {}) {
|
|
|
107868
108504
|
value: items
|
|
107869
108505
|
};
|
|
107870
108506
|
}
|
|
107871
|
-
if (isRecord$
|
|
108507
|
+
if (isRecord$4(v)) {
|
|
107872
108508
|
const out = {};
|
|
107873
108509
|
for (const [k, child] of Object.entries(v)) {
|
|
107874
108510
|
const s = substitute(child);
|
|
@@ -107900,7 +108536,7 @@ var SecretOverwriteRefusedError = class extends Error {
|
|
|
107900
108536
|
this.name = "SecretOverwriteRefusedError";
|
|
107901
108537
|
}
|
|
107902
108538
|
};
|
|
107903
|
-
function isRecord$
|
|
108539
|
+
function isRecord$3(value) {
|
|
107904
108540
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
107905
108541
|
}
|
|
107906
108542
|
function resolvedValue(pass, marker) {
|
|
@@ -107929,7 +108565,7 @@ function inArray(pass, incoming, stored) {
|
|
|
107929
108565
|
return incoming.map((item, index) => {
|
|
107930
108566
|
const twin = stored[index];
|
|
107931
108567
|
if (isSecretMarker(twin)) return typeof item === "string" && item === resolvedValue(pass, twin) ? twin : item;
|
|
107932
|
-
if (isRecord$
|
|
108568
|
+
if (isRecord$3(item) && isRecord$3(twin)) return inArrayRow(pass, item, twin);
|
|
107933
108569
|
if (Array.isArray(item) && Array.isArray(twin)) return inArray(pass, item, twin);
|
|
107934
108570
|
return item;
|
|
107935
108571
|
});
|
|
@@ -107940,7 +108576,7 @@ function inArrayRow(pass, incoming, stored) {
|
|
|
107940
108576
|
const twin = stored[key];
|
|
107941
108577
|
if (isSecretMarker(twin)) {
|
|
107942
108578
|
if (typeof value === "string" && value === resolvedValue(pass, twin)) out[key] = twin;
|
|
107943
|
-
} else if (isRecord$
|
|
108579
|
+
} else if (isRecord$3(value) && isRecord$3(twin)) out[key] = inArrayRow(pass, value, twin);
|
|
107944
108580
|
else if (Array.isArray(value) && Array.isArray(twin)) out[key] = inArray(pass, value, twin);
|
|
107945
108581
|
}
|
|
107946
108582
|
return out;
|
|
@@ -107948,7 +108584,7 @@ function inArrayRow(pass, incoming, stored) {
|
|
|
107948
108584
|
async function walk(pass, incoming, stored) {
|
|
107949
108585
|
if (isSecretMarker(stored)) return atMarker(pass, incoming, stored);
|
|
107950
108586
|
if (Array.isArray(incoming) && Array.isArray(stored)) return inArray(pass, incoming, stored);
|
|
107951
|
-
if (!isRecord$
|
|
108587
|
+
if (!isRecord$3(incoming) || !isRecord$3(stored)) return incoming;
|
|
107952
108588
|
const out = { ...incoming };
|
|
107953
108589
|
for (const [key, value] of Object.entries(incoming)) out[key] = await walk(pass, value, stored[key]);
|
|
107954
108590
|
return out;
|
|
@@ -107979,7 +108615,7 @@ async function restoreUnchangedSecrets(input) {
|
|
|
107979
108615
|
function isJsonEqual(a, b) {
|
|
107980
108616
|
if (Object.is(a, b)) return true;
|
|
107981
108617
|
if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((v, i) => isJsonEqual(v, b[i]));
|
|
107982
|
-
if (isRecord$
|
|
108618
|
+
if (isRecord$3(a) && isRecord$3(b)) {
|
|
107983
108619
|
const keys = Object.keys(a);
|
|
107984
108620
|
if (keys.length !== Object.keys(b).length) return false;
|
|
107985
108621
|
return keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && isJsonEqual(a[k], b[k]));
|
|
@@ -108003,7 +108639,7 @@ function markerKeysOf(blob, owner) {
|
|
|
108003
108639
|
}
|
|
108004
108640
|
function nodeFromStored(value, owner) {
|
|
108005
108641
|
if (isSecretMarker(value)) return isSecretRefOwnedBy(value.$secret, owner) ? { kind: "leaf" } : null;
|
|
108006
|
-
if (!isRecord$
|
|
108642
|
+
if (!isRecord$3(value)) return null;
|
|
108007
108643
|
const children = /* @__PURE__ */ new Map();
|
|
108008
108644
|
for (const [key, child] of Object.entries(value)) {
|
|
108009
108645
|
const node = nodeFromStored(child, owner);
|
|
@@ -108500,13 +109136,48 @@ var BaseAddon = class {
|
|
|
108500
109136
|
if (api === void 0) throw new Error(`${this.ctx.id}: the migration API is not available on this context`);
|
|
108501
109137
|
return this.runBound(sets.flatMap((set) => set.bind(api)), options);
|
|
108502
109138
|
}
|
|
108503
|
-
|
|
109139
|
+
/**
|
|
109140
|
+
* A device addon states its instance kind once, before its migrations run, and the one-switch
|
|
109141
|
+
* migration (registry `enabled` to the instance body, epic #440 step 3) joins whatever
|
|
109142
|
+
* catalogue the addon runs, in the SAME declaration (the engine replaces an owner's catalogue
|
|
109143
|
+
* on every declare).
|
|
109144
|
+
*/
|
|
109145
|
+
declareRegistrySwitch(spec) {
|
|
109146
|
+
this.registrySwitchSpec = spec;
|
|
109147
|
+
}
|
|
109148
|
+
registrySwitchSpec = null;
|
|
109149
|
+
registrySwitchBound() {
|
|
109150
|
+
const spec = this.registrySwitchSpec;
|
|
109151
|
+
if (spec === null) return [];
|
|
109152
|
+
const api = this.ctx.migrationApi;
|
|
109153
|
+
if (api === void 0) {
|
|
109154
|
+
this.ctx.logger.warn("the registry switch migration is skipped: the migration API is not available on this context");
|
|
109155
|
+
return [];
|
|
109156
|
+
}
|
|
109157
|
+
return migrationSet([registrySwitchToBodyMigration({
|
|
109158
|
+
addonId: this.ctx.id,
|
|
109159
|
+
date: "2026-11-06",
|
|
109160
|
+
seq: 1e3,
|
|
109161
|
+
initialBody: spec.initialBody
|
|
109162
|
+
})], (a) => registrySwitchPortsOver({
|
|
109163
|
+
api: integrationRowsApiOver(a),
|
|
109164
|
+
records: switchRecordsOverMigrationApi(a),
|
|
109165
|
+
kind: spec.kind
|
|
109166
|
+
})).bind(api);
|
|
109167
|
+
}
|
|
109168
|
+
async runBound(declared, options) {
|
|
109169
|
+
const added = this.registrySwitchBound();
|
|
109170
|
+
const migrations = [...declared, ...added];
|
|
109171
|
+
const phased = options?.only === void 0 || added.length === 0 ? options : {
|
|
109172
|
+
...options,
|
|
109173
|
+
only: [...options.only, ...added.map((m) => m.meta.id)]
|
|
109174
|
+
};
|
|
108504
109175
|
const api = this.ctx.api.migrations;
|
|
108505
109176
|
const report = await runAddonMigrations({
|
|
108506
109177
|
declareOwner: (input) => api.declareOwner.mutate(input),
|
|
108507
109178
|
startMigration: (input) => api.startMigration.mutate(input),
|
|
108508
109179
|
finishMigration: (input) => api.finishMigration.mutate(input)
|
|
108509
|
-
}, migrations, this.ctx.logger,
|
|
109180
|
+
}, migrations, this.ctx.logger, phased);
|
|
108510
109181
|
if (report.blockOwner.length > 0) throw new AddonMigrationsBlockedError(report.blockOwner);
|
|
108511
109182
|
return report;
|
|
108512
109183
|
}
|
|
@@ -109579,516 +110250,6 @@ function normalizeAddonInitResult(result) {
|
|
|
109579
110250
|
if (Array.isArray(result)) return { providers: result };
|
|
109580
110251
|
return result;
|
|
109581
110252
|
}
|
|
109582
|
-
var PREFIX = "records/";
|
|
109583
|
-
/** The base of every records failure. `detail` is the human part of the message. */
|
|
109584
|
-
var RecordsError = class extends Error {
|
|
109585
|
-
code;
|
|
109586
|
-
detail;
|
|
109587
|
-
constructor(code, detail) {
|
|
109588
|
-
super(`${PREFIX}${code}: ${detail}`);
|
|
109589
|
-
this.name = "RecordsError";
|
|
109590
|
-
this.code = code;
|
|
109591
|
-
this.detail = detail;
|
|
109592
|
-
}
|
|
109593
|
-
};
|
|
109594
|
-
/** A write guarded by `ifRev` found another revision (or an existing row for `ifRev: 0`). */
|
|
109595
|
-
var RevConflictError = class extends RecordsError {
|
|
109596
|
-
constructor(detail) {
|
|
109597
|
-
super("rev-conflict", detail);
|
|
109598
|
-
this.name = "RevConflictError";
|
|
109599
|
-
}
|
|
109600
|
-
};
|
|
109601
|
-
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
109602
|
-
var RecordSecretUnavailableError = class extends RecordsError {
|
|
109603
|
-
constructor(detail) {
|
|
109604
|
-
super("secret-unavailable", detail);
|
|
109605
|
-
this.name = "RecordSecretUnavailableError";
|
|
109606
|
-
}
|
|
109607
|
-
};
|
|
109608
|
-
var InvalidRecordError = class extends RecordsError {
|
|
109609
|
-
constructor(detail) {
|
|
109610
|
-
super("invalid-record", detail);
|
|
109611
|
-
this.name = "InvalidRecordError";
|
|
109612
|
-
}
|
|
109613
|
-
};
|
|
109614
|
-
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
109615
|
-
var DeclarationRefusedError = class extends RecordsError {
|
|
109616
|
-
constructor(detail) {
|
|
109617
|
-
super("declaration-refused", detail);
|
|
109618
|
-
this.name = "DeclarationRefusedError";
|
|
109619
|
-
}
|
|
109620
|
-
};
|
|
109621
|
-
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
109622
|
-
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
109623
|
-
var RECORD_DATABASES = ["settings", "events"];
|
|
109624
|
-
/** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
|
|
109625
|
-
var RECORD_CLASSES = [
|
|
109626
|
-
"config",
|
|
109627
|
-
"ledger",
|
|
109628
|
-
"audit",
|
|
109629
|
-
"mirror",
|
|
109630
|
-
"ephemeral"
|
|
109631
|
-
];
|
|
109632
|
-
var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
109633
|
-
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
109634
|
-
var RECORD_BATCH_MAX = 1e3;
|
|
109635
|
-
var RECORD_QUERY_MAX = 1e3;
|
|
109636
|
-
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
109637
|
-
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
109638
|
-
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
109639
|
-
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
109640
|
-
/**
|
|
109641
|
-
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
109642
|
-
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
109643
|
-
* (`auth.accessToken`, `headers[].value`).
|
|
109644
|
-
*
|
|
109645
|
-
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
109646
|
-
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
109647
|
-
* key releases exactly that key's secret.
|
|
109648
|
-
*
|
|
109649
|
-
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
109650
|
-
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
109651
|
-
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
109652
|
-
* leaf names its element: `headers[X-Api].value`.
|
|
109653
|
-
*
|
|
109654
|
-
* Pure and browser-safe. Nothing here mutates: every transform returns a new value.
|
|
109655
|
-
*/
|
|
109656
|
-
/** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
|
|
109657
|
-
function parseSecretPath(path) {
|
|
109658
|
-
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
109659
|
-
return path.split(".").map((raw) => {
|
|
109660
|
-
const each = raw.endsWith("[]");
|
|
109661
|
-
const map = raw.endsWith("{}");
|
|
109662
|
-
const key = each || map ? raw.slice(0, -2) : raw;
|
|
109663
|
-
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
109664
|
-
return {
|
|
109665
|
-
key,
|
|
109666
|
-
each,
|
|
109667
|
-
map
|
|
109668
|
-
};
|
|
109669
|
-
});
|
|
109670
|
-
}
|
|
109671
|
-
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
109672
|
-
function secretArrayPrefixes(path) {
|
|
109673
|
-
const segments = parseSecretPath(path);
|
|
109674
|
-
const prefixes = [];
|
|
109675
|
-
const walked = [];
|
|
109676
|
-
for (const segment of segments) {
|
|
109677
|
-
walked.push(segment.key);
|
|
109678
|
-
if (segment.each) prefixes.push(walked.join("."));
|
|
109679
|
-
}
|
|
109680
|
-
return prefixes;
|
|
109681
|
-
}
|
|
109682
|
-
function isRecord$4(value) {
|
|
109683
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
109684
|
-
}
|
|
109685
|
-
function elementId(element, idKey, declared, prefix) {
|
|
109686
|
-
const id = isRecord$4(element) ? element[idKey] : void 0;
|
|
109687
|
-
if (typeof id !== "string" || id.length === 0) throw new InvalidRecordError(`"${declared}": every element of "${prefix}" needs a non-empty string "${idKey}" to carry a secret`);
|
|
109688
|
-
return id;
|
|
109689
|
-
}
|
|
109690
|
-
/**
|
|
109691
|
-
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
109692
|
-
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
109693
|
-
* result is a new body, `data` is untouched.
|
|
109694
|
-
*/
|
|
109695
|
-
var REMOVE_LEAF = Symbol("remove-leaf");
|
|
109696
|
-
function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
|
|
109697
|
-
if (!isRecord$4(node)) return node;
|
|
109698
|
-
const segment = segments[index];
|
|
109699
|
-
if (segment === void 0) return node;
|
|
109700
|
-
if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
|
|
109701
|
-
const child = node[segment.key];
|
|
109702
|
-
const keys = [...walkedKeys, segment.key];
|
|
109703
|
-
const last = index === segments.length - 1;
|
|
109704
|
-
if (segment.each) {
|
|
109705
|
-
if (!Array.isArray(child)) return node;
|
|
109706
|
-
const prefix = keys.join(".");
|
|
109707
|
-
const idKey = arrayKeys[prefix];
|
|
109708
|
-
if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
|
|
109709
|
-
const mapped = child.map((element) => {
|
|
109710
|
-
const id = elementId(element, idKey, declared, prefix);
|
|
109711
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
|
|
109712
|
-
return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
|
|
109713
|
-
});
|
|
109714
|
-
return {
|
|
109715
|
-
...node,
|
|
109716
|
-
[segment.key]: mapped
|
|
109717
|
-
};
|
|
109718
|
-
}
|
|
109719
|
-
if (segment.map) {
|
|
109720
|
-
if (!isRecord$4(child)) return node;
|
|
109721
|
-
const kept = Object.entries(child).map(([mapKey, value]) => {
|
|
109722
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
|
|
109723
|
-
if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
|
|
109724
|
-
return [mapKey, visit({
|
|
109725
|
-
declared,
|
|
109726
|
-
concrete,
|
|
109727
|
-
value
|
|
109728
|
-
})];
|
|
109729
|
-
}).filter(([, value]) => value !== REMOVE_LEAF);
|
|
109730
|
-
return {
|
|
109731
|
-
...node,
|
|
109732
|
-
[segment.key]: Object.fromEntries(kept)
|
|
109733
|
-
};
|
|
109734
|
-
}
|
|
109735
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
109736
|
-
if (last) {
|
|
109737
|
-
const replacement = visit({
|
|
109738
|
-
declared,
|
|
109739
|
-
concrete,
|
|
109740
|
-
value: child
|
|
109741
|
-
});
|
|
109742
|
-
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
109743
|
-
return {
|
|
109744
|
-
...node,
|
|
109745
|
-
[segment.key]: replacement
|
|
109746
|
-
};
|
|
109747
|
-
}
|
|
109748
|
-
return {
|
|
109749
|
-
...node,
|
|
109750
|
-
[segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
|
|
109751
|
-
};
|
|
109752
|
-
}
|
|
109753
|
-
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
109754
|
-
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
109755
|
-
let current = data;
|
|
109756
|
-
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
109757
|
-
return current;
|
|
109758
|
-
}
|
|
109759
|
-
/** Every present secret leaf, read-only. */
|
|
109760
|
-
function collectSecretLeaves(data, paths, arrayKeys) {
|
|
109761
|
-
const found = [];
|
|
109762
|
-
mapSecretLeaves(data, paths, arrayKeys, (leaf) => {
|
|
109763
|
-
found.push(leaf);
|
|
109764
|
-
return leaf.value;
|
|
109765
|
-
});
|
|
109766
|
-
return found;
|
|
109767
|
-
}
|
|
109768
|
-
/**
|
|
109769
|
-
* The keychain collection name a kind's secrets live under. Prefixed so a
|
|
109770
|
-
* record's refs never collide with the refs a legacy collection of the same name
|
|
109771
|
-
* already holds during an adoption.
|
|
109772
|
-
*/
|
|
109773
|
-
function recordSecretCollection(kind) {
|
|
109774
|
-
return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
|
|
109775
|
-
}
|
|
109776
|
-
/** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
|
|
109777
|
-
function recordSecretRef(owner, kind, rowId, concretePath) {
|
|
109778
|
-
return buildSecretRef({
|
|
109779
|
-
owner,
|
|
109780
|
-
scope: {
|
|
109781
|
-
kind: "row",
|
|
109782
|
-
collection: recordSecretCollection(kind),
|
|
109783
|
-
rowId
|
|
109784
|
-
},
|
|
109785
|
-
fieldPath: concretePath
|
|
109786
|
-
});
|
|
109787
|
-
}
|
|
109788
|
-
/**
|
|
109789
|
-
* A stored secret, as an admin read shows it: a VIEW naming the row's own
|
|
109790
|
-
* keychain ref (`set: true`), never the value and no longer the bare redaction
|
|
109791
|
-
* token. The form hands it to the secret field, which reveals the value by ref
|
|
109792
|
-
* through the audited `keychain-admin.reveal`; sent back untouched it keeps the
|
|
109793
|
-
* stored secret (the records door reads a view as KEEP).
|
|
109794
|
-
*
|
|
109795
|
-
* ONE implementation for the entries service and for every addon that serves
|
|
109796
|
-
* its own instances (`RecordIntegrationInstances`).
|
|
109797
|
-
*/
|
|
109798
|
-
function isRecord$3(value) {
|
|
109799
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
109800
|
-
}
|
|
109801
|
-
function secretViewsOf(owner, kind, id, decl, data) {
|
|
109802
|
-
if (decl.secretPaths.length === 0) return data;
|
|
109803
|
-
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
109804
|
-
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
109805
|
-
return {
|
|
109806
|
-
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
109807
|
-
v: 1,
|
|
109808
|
-
set: true
|
|
109809
|
-
};
|
|
109810
|
-
});
|
|
109811
|
-
return isRecord$3(shown) ? shown : data;
|
|
109812
|
-
}
|
|
109813
|
-
/**
|
|
109814
|
-
* The share-view scope kinds a share-link token can carry. The hub mints
|
|
109815
|
-
* and validates them (`ShareViewGrantSchema` builds its
|
|
109816
|
-
* enum from this list); a data plane names the kinds it ACCEPTS in `share`.
|
|
109817
|
-
*/
|
|
109818
|
-
var SHARE_VIEW_KINDS = ["grid-view", "events-view"];
|
|
109819
|
-
/** The wire shape of {@link PeerBytesTicket} — see the type for what it is. */
|
|
109820
|
-
var PeerBytesTicketSchema = object({
|
|
109821
|
-
/** `http://127.0.0.1:<port>/<token>`. One `GET` takes it. */
|
|
109822
|
-
url: string().min(1),
|
|
109823
|
-
/**
|
|
109824
|
-
* The HOST node this URL means something on — the hub or a named agent,
|
|
109825
|
-
* never a runner. {@link AddonPeerBytes.open} compares it to its own and
|
|
109826
|
-
* refuses `cross-node` by name when they differ, without dialling.
|
|
109827
|
-
*/
|
|
109828
|
-
hostNodeId: string().min(1),
|
|
109829
|
-
expiresAtMs: number().int().nonnegative(),
|
|
109830
|
-
/**
|
|
109831
|
-
* What the producer DECLARED the body to be, when it knows — `null` when it
|
|
109832
|
-
* does not. Never `0` for unknown (D393): a consumer sizing a bound off this
|
|
109833
|
-
* must be able to tell "the producer did not say" from "the body is empty".
|
|
109834
|
-
*/
|
|
109835
|
-
declaredBytes: number().int().nonnegative().nullable()
|
|
109836
|
-
});
|
|
109837
|
-
function defOf(schema) {
|
|
109838
|
-
const zodBag = Reflect.get(schema, "_zod");
|
|
109839
|
-
if (typeof zodBag !== "object" || zodBag === null) return {};
|
|
109840
|
-
const def = Reflect.get(zodBag, "def");
|
|
109841
|
-
if (typeof def !== "object" || def === null) return {};
|
|
109842
|
-
return def;
|
|
109843
|
-
}
|
|
109844
|
-
function declaredHere(schema) {
|
|
109845
|
-
return globalRegistry.get(schema)?.secret === true;
|
|
109846
|
-
}
|
|
109847
|
-
/** Wrapper kinds whose `innerType` is the field itself. */
|
|
109848
|
-
var WRAPPERS = new Set([
|
|
109849
|
-
"optional",
|
|
109850
|
-
"nullable",
|
|
109851
|
-
"default",
|
|
109852
|
-
"prefault",
|
|
109853
|
-
"catch",
|
|
109854
|
-
"readonly",
|
|
109855
|
-
"nonoptional"
|
|
109856
|
-
]);
|
|
109857
|
-
/**
|
|
109858
|
-
* The schema layers that make up ONE field: the schema itself and every
|
|
109859
|
-
* wrapper below it (optional / default / nullable / readonly / catch), plus
|
|
109860
|
-
* both sides of a pipe (`z.preprocess` puts the real schema on `out`,
|
|
109861
|
-
* `.transform` on `in`).
|
|
109862
|
-
*/
|
|
109863
|
-
function layersOf(schema) {
|
|
109864
|
-
const out = [];
|
|
109865
|
-
const queue = [schema];
|
|
109866
|
-
while (queue.length > 0) {
|
|
109867
|
-
const s = queue.shift();
|
|
109868
|
-
if (!s || out.includes(s)) continue;
|
|
109869
|
-
out.push(s);
|
|
109870
|
-
const def = defOf(s);
|
|
109871
|
-
if (def.type !== void 0 && WRAPPERS.has(def.type) && def.innerType) queue.push(def.innerType);
|
|
109872
|
-
if (def.type === "pipe") {
|
|
109873
|
-
if (def.in) queue.push(def.in);
|
|
109874
|
-
if (def.out) queue.push(def.out);
|
|
109875
|
-
}
|
|
109876
|
-
}
|
|
109877
|
-
return out;
|
|
109878
|
-
}
|
|
109879
|
-
/** True when any layer of this field declares `.meta({ secret: true })`. */
|
|
109880
|
-
function isZodSecret(schema) {
|
|
109881
|
-
return layersOf(schema).some(declaredHere);
|
|
109882
|
-
}
|
|
109883
|
-
/**
|
|
109884
|
-
* Every declared secret path in a config schema: dotted keys, `[]` for "each
|
|
109885
|
-
* element of this array" (`connection.password`, `rows[].token`), `{}` for "each value of this
|
|
109886
|
-
* map" (`applianceSecrets{}`). A declared
|
|
109887
|
-
* object or array is reported as one path and not descended into — everything
|
|
109888
|
-
* under it is secret.
|
|
109889
|
-
*/
|
|
109890
|
-
function collectZodSecretPaths(schema, prefix = "") {
|
|
109891
|
-
if (isZodSecret(schema)) return prefix.length > 0 ? [prefix] : [];
|
|
109892
|
-
const paths = [];
|
|
109893
|
-
for (const layer of layersOf(schema)) {
|
|
109894
|
-
const def = defOf(layer);
|
|
109895
|
-
if (def.type === "object" && def.shape) for (const [key, child] of Object.entries(def.shape)) paths.push(...collectZodSecretPaths(child, prefix ? `${prefix}.${key}` : key));
|
|
109896
|
-
else if (def.type === "array" && def.element) paths.push(...collectZodSecretPaths(def.element, `${prefix}[]`));
|
|
109897
|
-
else if (def.type === "record" && def.valueType) paths.push(...collectZodSecretPaths(def.valueType, `${prefix}{}`));
|
|
109898
|
-
else if (def.type === "union" && def.options) for (const option of def.options) paths.push(...collectZodSecretPaths(option, prefix));
|
|
109899
|
-
else if (def.type === "intersection") {
|
|
109900
|
-
if (def.left) paths.push(...collectZodSecretPaths(def.left, prefix));
|
|
109901
|
-
if (def.right) paths.push(...collectZodSecretPaths(def.right, prefix));
|
|
109902
|
-
}
|
|
109903
|
-
}
|
|
109904
|
-
return [...new Set(paths)];
|
|
109905
|
-
}
|
|
109906
|
-
/**
|
|
109907
|
-
* Record kinds (D881): the declaration an addon makes of one kind of fact, the
|
|
109908
|
-
* Zod row schema that describes it, and the helper that turns the two into the
|
|
109909
|
-
* JSON the engine stores.
|
|
109910
|
-
*
|
|
109911
|
-
* A kind is declared ONCE, next to the code that owns it, and the engine's
|
|
109912
|
-
* reconciler creates its indexes - nothing creates DDL at runtime from a write.
|
|
109913
|
-
* Everything the generic machinery needs (secret fields, the entry descriptor)
|
|
109914
|
-
* is DERIVED from the Zod schema: `.meta({ secret: true })` marks a credential,
|
|
109915
|
-
* never a field name (D879).
|
|
109916
|
-
*/
|
|
109917
|
-
/** A JSON field path: `trackId`, `auth.accessToken`. Charset-restricted: it is rendered into DDL. */
|
|
109918
|
-
var RecordFieldPathSchema = string().regex(/^[A-Za-z_][A-Za-z0-9_]{0,63}(\.[A-Za-z_][A-Za-z0-9_]{0,63}){0,3}$/);
|
|
109919
|
-
var RecordIndexSchema = object({
|
|
109920
|
-
name: string().regex(/^[a-z][a-z0-9_]{0,31}$/),
|
|
109921
|
-
fields: array(RecordFieldPathSchema).min(1).max(4),
|
|
109922
|
-
unique: boolean().optional()
|
|
109923
|
-
}).strict();
|
|
109924
|
-
var RecordRetentionSchema = union([
|
|
109925
|
-
object({
|
|
109926
|
-
ttlMs: number().int().positive(),
|
|
109927
|
-
from: _enum(["at", "write"])
|
|
109928
|
-
}).strict(),
|
|
109929
|
-
object({
|
|
109930
|
-
maxRows: number().int().positive().optional(),
|
|
109931
|
-
maxRowsPerDevice: number().int().positive().optional()
|
|
109932
|
-
}).strict().refine((r) => r.maxRows !== void 0 || r.maxRowsPerDevice !== void 0, { message: "name maxRows, maxRowsPerDevice or both" }),
|
|
109933
|
-
object({
|
|
109934
|
-
owner: string().min(1),
|
|
109935
|
-
reason: string().min(1)
|
|
109936
|
-
}).strict(),
|
|
109937
|
-
object({ none: string().min(1) }).strict()
|
|
109938
|
-
]);
|
|
109939
|
-
/** The descriptor a generic entries UI reads (D881 "generic entries"). */
|
|
109940
|
-
var EntryDescriptorSchema = object({
|
|
109941
|
-
title: string().min(1),
|
|
109942
|
-
/** The record body field shown as the entry's name. */
|
|
109943
|
-
nameField: string().min(1),
|
|
109944
|
-
/** JSON Schema of the entry body; `secret: true` marks a password field. */
|
|
109945
|
-
fields: record(string(), unknown())
|
|
109946
|
-
}).strict();
|
|
109947
|
-
/** What crosses the wire from an addon: JSON only, no Zod. An unknown key is refused. */
|
|
109948
|
-
var RecordKindDeclarationSchema = object({
|
|
109949
|
-
database: _enum(RECORD_DATABASES).default("settings"),
|
|
109950
|
-
class: _enum(RECORD_CLASSES),
|
|
109951
|
-
writeTrigger: string().min(1),
|
|
109952
|
-
device: _enum([
|
|
109953
|
-
"required",
|
|
109954
|
-
"optional",
|
|
109955
|
-
"none"
|
|
109956
|
-
]).default("none"),
|
|
109957
|
-
at: _enum(["required", "none"]).default("none"),
|
|
109958
|
-
indexes: array(RecordIndexSchema).max(8).default([]),
|
|
109959
|
-
retention: RecordRetentionSchema,
|
|
109960
|
-
deviceRemoval: _enum(["delete", "none"]).default("none"),
|
|
109961
|
-
maxDataBytes: number().int().positive().max(RECORD_MAX_DATA_BYTES).default(RECORD_DEFAULT_MAX_DATA_BYTES),
|
|
109962
|
-
/** Derived from the Zod schema; never written by hand. */
|
|
109963
|
-
secretPaths: array(string().min(1)).default([]),
|
|
109964
|
-
/** The id key of each array that carries a secret (`{ headers: 'name' }`). */
|
|
109965
|
-
secretArrayKeys: record(string(), string()).default({}),
|
|
109966
|
-
/** Kinds that must agree through `transact` sit in one file under one family name. */
|
|
109967
|
-
transactFamily: string().min(1).optional(),
|
|
109968
|
-
entry: EntryDescriptorSchema.optional()
|
|
109969
|
-
}).strict();
|
|
109970
|
-
/** The kind names: lower-case, dash separated, short enough for an index name. */
|
|
109971
|
-
var RecordKindNameSchema = string().regex(/^[a-z][a-z0-9-]{0,47}$/);
|
|
109972
|
-
/** Cross-field rules a declaration must satisfy. Throws {@link DeclarationRefusedError}. */
|
|
109973
|
-
function assertValidDeclaration(name, decl) {
|
|
109974
|
-
const refuse = (why) => {
|
|
109975
|
-
throw new DeclarationRefusedError(`kind "${name}": ${why}`);
|
|
109976
|
-
};
|
|
109977
|
-
if (!RecordKindNameSchema.safeParse(name).success) refuse("the name must be lower-case-dashed");
|
|
109978
|
-
const seen = /* @__PURE__ */ new Set();
|
|
109979
|
-
for (const index of decl.indexes) {
|
|
109980
|
-
if (seen.has(index.name)) refuse(`index name "${index.name}" is declared twice`);
|
|
109981
|
-
seen.add(index.name);
|
|
109982
|
-
}
|
|
109983
|
-
const { retention } = decl;
|
|
109984
|
-
const hasSecrets = decl.secretPaths.length > 0;
|
|
109985
|
-
if ("ttlMs" in retention) {
|
|
109986
|
-
if (retention.from === "at" && decl.at !== "required") refuse("a ttl from \"at\" needs at: \"required\"");
|
|
109987
|
-
if (hasSecrets) refuse("a kind with secret fields cannot use engine TTL (its keychain values would be orphaned)");
|
|
109988
|
-
}
|
|
109989
|
-
if ("maxRows" in retention || "maxRowsPerDevice" in retention) {
|
|
109990
|
-
if (retention.maxRowsPerDevice !== void 0 && decl.device !== "required") refuse("maxRowsPerDevice needs device: \"required\"");
|
|
109991
|
-
if (decl.at !== "required") refuse("a row bound trims the oldest \"at\": it needs at: \"required\"");
|
|
109992
|
-
if (hasSecrets) refuse("a kind with secret fields cannot use an engine row bound");
|
|
109993
|
-
const bound = Math.max(retention.maxRows ?? 0, retention.maxRowsPerDevice ?? 0);
|
|
109994
|
-
if (decl.database === "settings" && bound > 5e4) refuse(`a row bound above ${RECORD_SETTINGS_MAX_ROWS} belongs in database: "events" (a big delete on the settings thread stalls every configuration read)`);
|
|
109995
|
-
}
|
|
109996
|
-
if (decl.deviceRemoval === "delete" && decl.device === "none") refuse("deviceRemoval: \"delete\" needs a device: \"required\" or \"optional\"");
|
|
109997
|
-
for (const path of decl.secretPaths) for (const prefix of secretArrayPrefixes(path)) if (decl.secretArrayKeys[prefix] === void 0) refuse(`secret path "${path}" crosses the array "${prefix}": declare its id key in secretArrayKeys`);
|
|
109998
|
-
}
|
|
109999
|
-
function bodyFieldsOf(schema) {
|
|
110000
|
-
return { ...toJSONSchema(schema, {
|
|
110001
|
-
unrepresentable: "any",
|
|
110002
|
-
io: "input"
|
|
110003
|
-
}) };
|
|
110004
|
-
}
|
|
110005
|
-
function isRecordLike(value) {
|
|
110006
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
110007
|
-
}
|
|
110008
|
-
/** Does every branch of the body schema carry `field`? (A discriminated union has several.) */
|
|
110009
|
-
function hasNameField(json, field) {
|
|
110010
|
-
const branches = json["oneOf"] ?? json["anyOf"];
|
|
110011
|
-
if (Array.isArray(branches)) return branches.length > 0 && branches.every((b) => isRecordLike(b) && hasNameField(b, field));
|
|
110012
|
-
const properties = json["properties"];
|
|
110013
|
-
return isRecordLike(properties) && Object.prototype.hasOwnProperty.call(properties, field);
|
|
110014
|
-
}
|
|
110015
|
-
/**
|
|
110016
|
-
* Declare the kinds of a package. The keys are the kind names. The result is
|
|
110017
|
-
* what `ctx.records.declare` sends to the engine and what `ctx.records.kind`
|
|
110018
|
-
* types its handle from.
|
|
110019
|
-
*/
|
|
110020
|
-
function defineRecordKinds(specs) {
|
|
110021
|
-
const out = {};
|
|
110022
|
-
for (const [name, spec] of Object.entries(specs)) {
|
|
110023
|
-
const secretPaths = collectZodSecretPaths(spec.schema);
|
|
110024
|
-
const nameField = spec.entry?.nameField ?? "name";
|
|
110025
|
-
const fields = bodyFieldsOf(spec.schema);
|
|
110026
|
-
if (spec.entry !== void 0 && !hasNameField(fields, nameField)) throw new DeclarationRefusedError(`kind "${name}": an entry kind's schema needs a "${nameField}" field`);
|
|
110027
|
-
const parsed = RecordKindDeclarationSchema.parse({
|
|
110028
|
-
database: spec.database,
|
|
110029
|
-
class: spec.class,
|
|
110030
|
-
writeTrigger: spec.writeTrigger,
|
|
110031
|
-
device: spec.device,
|
|
110032
|
-
at: spec.at,
|
|
110033
|
-
indexes: spec.indexes === void 0 ? void 0 : [...spec.indexes],
|
|
110034
|
-
retention: spec.retention,
|
|
110035
|
-
deviceRemoval: spec.deviceRemoval,
|
|
110036
|
-
maxDataBytes: spec.maxDataBytes,
|
|
110037
|
-
secretPaths: [...new Set([...secretPaths, ...spec.retiredSecretPaths ?? []])],
|
|
110038
|
-
secretArrayKeys: spec.secretArrayKeys === void 0 ? void 0 : { ...spec.secretArrayKeys },
|
|
110039
|
-
transactFamily: spec.transactFamily,
|
|
110040
|
-
entry: spec.entry === void 0 ? void 0 : {
|
|
110041
|
-
title: spec.entry.title,
|
|
110042
|
-
nameField,
|
|
110043
|
-
fields
|
|
110044
|
-
}
|
|
110045
|
-
});
|
|
110046
|
-
assertValidDeclaration(name, parsed);
|
|
110047
|
-
out[name] = {
|
|
110048
|
-
name,
|
|
110049
|
-
schema: spec.schema,
|
|
110050
|
-
declaration: parsed
|
|
110051
|
-
};
|
|
110052
|
-
}
|
|
110053
|
-
return out;
|
|
110054
|
-
}
|
|
110055
|
-
/**
|
|
110056
|
-
* Entry kinds (D881): every list of user-created entries (notification
|
|
110057
|
-
* targets, brokers, LLM profiles) is ONE record kind with an id, a name and a
|
|
110058
|
-
* kind-specific body, and the admin UI lists/adds/edits/deletes all of them
|
|
110059
|
-
* through the `record-entries` capability with password fields derived from
|
|
110060
|
-
* the schema (`.meta({ secret: true })`).
|
|
110061
|
-
*/
|
|
110062
|
-
/** The body of a plain entry: a name and the fields the kind adds. */
|
|
110063
|
-
function entryBody(shape) {
|
|
110064
|
-
return object({
|
|
110065
|
-
name: string().min(1),
|
|
110066
|
-
...shape
|
|
110067
|
-
});
|
|
110068
|
-
}
|
|
110069
|
-
/**
|
|
110070
|
-
* Declare one entry kind. An entry is configuration: never trimmed by the
|
|
110071
|
-
* engine, never aged, belonging to no device.
|
|
110072
|
-
*/
|
|
110073
|
-
function defineEntryKind(name, spec) {
|
|
110074
|
-
const defined = defineRecordKinds({ [name]: {
|
|
110075
|
-
schema: spec.schema,
|
|
110076
|
-
class: "config",
|
|
110077
|
-
writeTrigger: spec.writeTrigger ?? "an operator adds or edits an entry in the entries UI",
|
|
110078
|
-
retention: { none: "an entry goes only when the operator deletes it" },
|
|
110079
|
-
...spec.maxDataBytes === void 0 ? {} : { maxDataBytes: spec.maxDataBytes },
|
|
110080
|
-
...spec.database === void 0 ? {} : { database: spec.database },
|
|
110081
|
-
...spec.indexes === void 0 ? {} : { indexes: spec.indexes },
|
|
110082
|
-
...spec.secretArrayKeys === void 0 ? {} : { secretArrayKeys: spec.secretArrayKeys },
|
|
110083
|
-
...spec.retiredSecretPaths === void 0 ? {} : { retiredSecretPaths: spec.retiredSecretPaths },
|
|
110084
|
-
entry: {
|
|
110085
|
-
title: spec.title,
|
|
110086
|
-
...spec.nameField === void 0 ? {} : { nameField: spec.nameField }
|
|
110087
|
-
}
|
|
110088
|
-
} })[name];
|
|
110089
|
-
if (defined === void 0) throw new DeclarationRefusedError(`entry kind "${name}" was not built`);
|
|
110090
|
-
return defined;
|
|
110091
|
-
}
|
|
110092
110253
|
object({
|
|
110093
110254
|
field: string().min(1),
|
|
110094
110255
|
on: literal("advance")
|
|
@@ -110181,6 +110342,286 @@ function optionalMethod(input, output, options) {
|
|
|
110181
110342
|
function event(data) {
|
|
110182
110343
|
return { data };
|
|
110183
110344
|
}
|
|
110345
|
+
function defOf(schema) {
|
|
110346
|
+
const zodBag = Reflect.get(schema, "_zod");
|
|
110347
|
+
if (typeof zodBag !== "object" || zodBag === null) return {};
|
|
110348
|
+
const def = Reflect.get(zodBag, "def");
|
|
110349
|
+
if (typeof def !== "object" || def === null) return {};
|
|
110350
|
+
return def;
|
|
110351
|
+
}
|
|
110352
|
+
function declaredHere(schema) {
|
|
110353
|
+
return globalRegistry.get(schema)?.secret === true;
|
|
110354
|
+
}
|
|
110355
|
+
/** Wrapper kinds whose `innerType` is the field itself. */
|
|
110356
|
+
var WRAPPERS = new Set([
|
|
110357
|
+
"optional",
|
|
110358
|
+
"nullable",
|
|
110359
|
+
"default",
|
|
110360
|
+
"prefault",
|
|
110361
|
+
"catch",
|
|
110362
|
+
"readonly",
|
|
110363
|
+
"nonoptional"
|
|
110364
|
+
]);
|
|
110365
|
+
/**
|
|
110366
|
+
* The schema layers that make up ONE field: the schema itself and every
|
|
110367
|
+
* wrapper below it (optional / default / nullable / readonly / catch), plus
|
|
110368
|
+
* both sides of a pipe (`z.preprocess` puts the real schema on `out`,
|
|
110369
|
+
* `.transform` on `in`).
|
|
110370
|
+
*/
|
|
110371
|
+
function layersOf(schema) {
|
|
110372
|
+
const out = [];
|
|
110373
|
+
const queue = [schema];
|
|
110374
|
+
while (queue.length > 0) {
|
|
110375
|
+
const s = queue.shift();
|
|
110376
|
+
if (!s || out.includes(s)) continue;
|
|
110377
|
+
out.push(s);
|
|
110378
|
+
const def = defOf(s);
|
|
110379
|
+
if (def.type !== void 0 && WRAPPERS.has(def.type) && def.innerType) queue.push(def.innerType);
|
|
110380
|
+
if (def.type === "pipe") {
|
|
110381
|
+
if (def.in) queue.push(def.in);
|
|
110382
|
+
if (def.out) queue.push(def.out);
|
|
110383
|
+
}
|
|
110384
|
+
}
|
|
110385
|
+
return out;
|
|
110386
|
+
}
|
|
110387
|
+
/** True when any layer of this field declares `.meta({ secret: true })`. */
|
|
110388
|
+
function isZodSecret(schema) {
|
|
110389
|
+
return layersOf(schema).some(declaredHere);
|
|
110390
|
+
}
|
|
110391
|
+
/**
|
|
110392
|
+
* Every declared secret path in a config schema: dotted keys, `[]` for "each
|
|
110393
|
+
* element of this array" (`connection.password`, `rows[].token`), `{}` for "each value of this
|
|
110394
|
+
* map" (`applianceSecrets{}`). A declared
|
|
110395
|
+
* object or array is reported as one path and not descended into — everything
|
|
110396
|
+
* under it is secret.
|
|
110397
|
+
*/
|
|
110398
|
+
function collectZodSecretPaths(schema, prefix = "") {
|
|
110399
|
+
if (isZodSecret(schema)) return prefix.length > 0 ? [prefix] : [];
|
|
110400
|
+
const paths = [];
|
|
110401
|
+
for (const layer of layersOf(schema)) {
|
|
110402
|
+
const def = defOf(layer);
|
|
110403
|
+
if (def.type === "object" && def.shape) for (const [key, child] of Object.entries(def.shape)) paths.push(...collectZodSecretPaths(child, prefix ? `${prefix}.${key}` : key));
|
|
110404
|
+
else if (def.type === "array" && def.element) paths.push(...collectZodSecretPaths(def.element, `${prefix}[]`));
|
|
110405
|
+
else if (def.type === "record" && def.valueType) paths.push(...collectZodSecretPaths(def.valueType, `${prefix}{}`));
|
|
110406
|
+
else if (def.type === "union" && def.options) for (const option of def.options) paths.push(...collectZodSecretPaths(option, prefix));
|
|
110407
|
+
else if (def.type === "intersection") {
|
|
110408
|
+
if (def.left) paths.push(...collectZodSecretPaths(def.left, prefix));
|
|
110409
|
+
if (def.right) paths.push(...collectZodSecretPaths(def.right, prefix));
|
|
110410
|
+
}
|
|
110411
|
+
}
|
|
110412
|
+
return [...new Set(paths)];
|
|
110413
|
+
}
|
|
110414
|
+
/**
|
|
110415
|
+
* Record kinds (D881): the declaration an addon makes of one kind of fact, the
|
|
110416
|
+
* Zod row schema that describes it, and the helper that turns the two into the
|
|
110417
|
+
* JSON the engine stores.
|
|
110418
|
+
*
|
|
110419
|
+
* A kind is declared ONCE, next to the code that owns it, and the engine's
|
|
110420
|
+
* reconciler creates its indexes - nothing creates DDL at runtime from a write.
|
|
110421
|
+
* Everything the generic machinery needs (secret fields, the entry descriptor)
|
|
110422
|
+
* is DERIVED from the Zod schema: `.meta({ secret: true })` marks a credential,
|
|
110423
|
+
* never a field name (D879).
|
|
110424
|
+
*/
|
|
110425
|
+
/** A JSON field path: `trackId`, `auth.accessToken`. Charset-restricted: it is rendered into DDL. */
|
|
110426
|
+
var RecordFieldPathSchema = string().regex(/^[A-Za-z_][A-Za-z0-9_]{0,63}(\.[A-Za-z_][A-Za-z0-9_]{0,63}){0,3}$/);
|
|
110427
|
+
var RecordIndexSchema = object({
|
|
110428
|
+
name: string().regex(/^[a-z][a-z0-9_]{0,31}$/),
|
|
110429
|
+
fields: array(RecordFieldPathSchema).min(1).max(4),
|
|
110430
|
+
unique: boolean().optional()
|
|
110431
|
+
}).strict();
|
|
110432
|
+
var RecordRetentionSchema = union([
|
|
110433
|
+
object({
|
|
110434
|
+
ttlMs: number().int().positive(),
|
|
110435
|
+
from: _enum(["at", "write"])
|
|
110436
|
+
}).strict(),
|
|
110437
|
+
object({
|
|
110438
|
+
maxRows: number().int().positive().optional(),
|
|
110439
|
+
maxRowsPerDevice: number().int().positive().optional()
|
|
110440
|
+
}).strict().refine((r) => r.maxRows !== void 0 || r.maxRowsPerDevice !== void 0, { message: "name maxRows, maxRowsPerDevice or both" }),
|
|
110441
|
+
object({
|
|
110442
|
+
owner: string().min(1),
|
|
110443
|
+
reason: string().min(1)
|
|
110444
|
+
}).strict(),
|
|
110445
|
+
object({ none: string().min(1) }).strict()
|
|
110446
|
+
]);
|
|
110447
|
+
/** The descriptor a generic entries UI reads (D881 "generic entries"). */
|
|
110448
|
+
var EntryDescriptorSchema = object({
|
|
110449
|
+
title: string().min(1),
|
|
110450
|
+
/** The record body field shown as the entry's name. */
|
|
110451
|
+
nameField: string().min(1),
|
|
110452
|
+
/** JSON Schema of the entry body; `secret: true` marks a password field. */
|
|
110453
|
+
fields: record(string(), unknown())
|
|
110454
|
+
}).strict();
|
|
110455
|
+
/** What crosses the wire from an addon: JSON only, no Zod. An unknown key is refused. */
|
|
110456
|
+
var RecordKindDeclarationSchema = object({
|
|
110457
|
+
database: _enum(RECORD_DATABASES).default("settings"),
|
|
110458
|
+
class: _enum(RECORD_CLASSES),
|
|
110459
|
+
writeTrigger: string().min(1),
|
|
110460
|
+
device: _enum([
|
|
110461
|
+
"required",
|
|
110462
|
+
"optional",
|
|
110463
|
+
"none"
|
|
110464
|
+
]).default("none"),
|
|
110465
|
+
at: _enum(["required", "none"]).default("none"),
|
|
110466
|
+
indexes: array(RecordIndexSchema).max(8).default([]),
|
|
110467
|
+
retention: RecordRetentionSchema,
|
|
110468
|
+
deviceRemoval: _enum(["delete", "none"]).default("none"),
|
|
110469
|
+
maxDataBytes: number().int().positive().max(RECORD_MAX_DATA_BYTES).default(RECORD_DEFAULT_MAX_DATA_BYTES),
|
|
110470
|
+
/** Derived from the Zod schema; never written by hand. */
|
|
110471
|
+
secretPaths: array(string().min(1)).default([]),
|
|
110472
|
+
/** The id key of each array that carries a secret (`{ headers: 'name' }`). */
|
|
110473
|
+
secretArrayKeys: record(string(), string()).default({}),
|
|
110474
|
+
/** Kinds that must agree through `transact` sit in one file under one family name. */
|
|
110475
|
+
transactFamily: string().min(1).optional(),
|
|
110476
|
+
entry: EntryDescriptorSchema.optional()
|
|
110477
|
+
}).strict();
|
|
110478
|
+
/** The kind names: lower-case, dash separated, short enough for an index name. */
|
|
110479
|
+
var RecordKindNameSchema = string().regex(/^[a-z][a-z0-9-]{0,47}$/);
|
|
110480
|
+
/** Cross-field rules a declaration must satisfy. Throws {@link DeclarationRefusedError}. */
|
|
110481
|
+
function assertValidDeclaration(name, decl) {
|
|
110482
|
+
const refuse = (why) => {
|
|
110483
|
+
throw new DeclarationRefusedError(`kind "${name}": ${why}`);
|
|
110484
|
+
};
|
|
110485
|
+
if (!RecordKindNameSchema.safeParse(name).success) refuse("the name must be lower-case-dashed");
|
|
110486
|
+
const seen = /* @__PURE__ */ new Set();
|
|
110487
|
+
for (const index of decl.indexes) {
|
|
110488
|
+
if (seen.has(index.name)) refuse(`index name "${index.name}" is declared twice`);
|
|
110489
|
+
seen.add(index.name);
|
|
110490
|
+
}
|
|
110491
|
+
const { retention } = decl;
|
|
110492
|
+
const hasSecrets = decl.secretPaths.length > 0;
|
|
110493
|
+
if ("ttlMs" in retention) {
|
|
110494
|
+
if (retention.from === "at" && decl.at !== "required") refuse("a ttl from \"at\" needs at: \"required\"");
|
|
110495
|
+
if (hasSecrets) refuse("a kind with secret fields cannot use engine TTL (its keychain values would be orphaned)");
|
|
110496
|
+
}
|
|
110497
|
+
if ("maxRows" in retention || "maxRowsPerDevice" in retention) {
|
|
110498
|
+
if (retention.maxRowsPerDevice !== void 0 && decl.device !== "required") refuse("maxRowsPerDevice needs device: \"required\"");
|
|
110499
|
+
if (decl.at !== "required") refuse("a row bound trims the oldest \"at\": it needs at: \"required\"");
|
|
110500
|
+
if (hasSecrets) refuse("a kind with secret fields cannot use an engine row bound");
|
|
110501
|
+
const bound = Math.max(retention.maxRows ?? 0, retention.maxRowsPerDevice ?? 0);
|
|
110502
|
+
if (decl.database === "settings" && bound > 5e4) refuse(`a row bound above ${RECORD_SETTINGS_MAX_ROWS} belongs in database: "events" (a big delete on the settings thread stalls every configuration read)`);
|
|
110503
|
+
}
|
|
110504
|
+
if (decl.deviceRemoval === "delete" && decl.device === "none") refuse("deviceRemoval: \"delete\" needs a device: \"required\" or \"optional\"");
|
|
110505
|
+
for (const path of decl.secretPaths) for (const prefix of secretArrayPrefixes(path)) if (decl.secretArrayKeys[prefix] === void 0) refuse(`secret path "${path}" crosses the array "${prefix}": declare its id key in secretArrayKeys`);
|
|
110506
|
+
}
|
|
110507
|
+
function bodyFieldsOf(schema) {
|
|
110508
|
+
return { ...toJSONSchema(schema, {
|
|
110509
|
+
unrepresentable: "any",
|
|
110510
|
+
io: "input"
|
|
110511
|
+
}) };
|
|
110512
|
+
}
|
|
110513
|
+
function isRecordLike(value) {
|
|
110514
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
110515
|
+
}
|
|
110516
|
+
/** Does every branch of the body schema carry `field`? (A discriminated union has several.) */
|
|
110517
|
+
function hasNameField(json, field) {
|
|
110518
|
+
const branches = json["oneOf"] ?? json["anyOf"];
|
|
110519
|
+
if (Array.isArray(branches)) return branches.length > 0 && branches.every((b) => isRecordLike(b) && hasNameField(b, field));
|
|
110520
|
+
const properties = json["properties"];
|
|
110521
|
+
return isRecordLike(properties) && Object.prototype.hasOwnProperty.call(properties, field);
|
|
110522
|
+
}
|
|
110523
|
+
/**
|
|
110524
|
+
* Declare the kinds of a package. The keys are the kind names. The result is
|
|
110525
|
+
* what `ctx.records.declare` sends to the engine and what `ctx.records.kind`
|
|
110526
|
+
* types its handle from.
|
|
110527
|
+
*/
|
|
110528
|
+
function defineRecordKinds(specs) {
|
|
110529
|
+
const out = {};
|
|
110530
|
+
for (const [name, spec] of Object.entries(specs)) {
|
|
110531
|
+
const secretPaths = collectZodSecretPaths(spec.schema);
|
|
110532
|
+
const nameField = spec.entry?.nameField ?? "name";
|
|
110533
|
+
const fields = bodyFieldsOf(spec.schema);
|
|
110534
|
+
if (spec.entry !== void 0 && !hasNameField(fields, nameField)) throw new DeclarationRefusedError(`kind "${name}": an entry kind's schema needs a "${nameField}" field`);
|
|
110535
|
+
const parsed = RecordKindDeclarationSchema.parse({
|
|
110536
|
+
database: spec.database,
|
|
110537
|
+
class: spec.class,
|
|
110538
|
+
writeTrigger: spec.writeTrigger,
|
|
110539
|
+
device: spec.device,
|
|
110540
|
+
at: spec.at,
|
|
110541
|
+
indexes: spec.indexes === void 0 ? void 0 : [...spec.indexes],
|
|
110542
|
+
retention: spec.retention,
|
|
110543
|
+
deviceRemoval: spec.deviceRemoval,
|
|
110544
|
+
maxDataBytes: spec.maxDataBytes,
|
|
110545
|
+
secretPaths: [...new Set([...secretPaths, ...spec.retiredSecretPaths ?? []])],
|
|
110546
|
+
secretArrayKeys: spec.secretArrayKeys === void 0 ? void 0 : { ...spec.secretArrayKeys },
|
|
110547
|
+
transactFamily: spec.transactFamily,
|
|
110548
|
+
entry: spec.entry === void 0 ? void 0 : {
|
|
110549
|
+
title: spec.entry.title,
|
|
110550
|
+
nameField,
|
|
110551
|
+
fields
|
|
110552
|
+
}
|
|
110553
|
+
});
|
|
110554
|
+
assertValidDeclaration(name, parsed);
|
|
110555
|
+
out[name] = {
|
|
110556
|
+
name,
|
|
110557
|
+
schema: spec.schema,
|
|
110558
|
+
declaration: parsed
|
|
110559
|
+
};
|
|
110560
|
+
}
|
|
110561
|
+
return out;
|
|
110562
|
+
}
|
|
110563
|
+
/**
|
|
110564
|
+
* Entry kinds (D881): every list of user-created entries (notification
|
|
110565
|
+
* targets, brokers, LLM profiles) is ONE record kind with an id, a name and a
|
|
110566
|
+
* kind-specific body, and the admin UI lists/adds/edits/deletes all of them
|
|
110567
|
+
* through the `record-entries` capability with password fields derived from
|
|
110568
|
+
* the schema (`.meta({ secret: true })`).
|
|
110569
|
+
*/
|
|
110570
|
+
/** The body of a plain entry: a name and the fields the kind adds. */
|
|
110571
|
+
function entryBody(shape) {
|
|
110572
|
+
return object({
|
|
110573
|
+
name: string().min(1),
|
|
110574
|
+
enabled: boolean().optional(),
|
|
110575
|
+
...shape
|
|
110576
|
+
});
|
|
110577
|
+
}
|
|
110578
|
+
/**
|
|
110579
|
+
* Declare one entry kind. An entry is configuration: never trimmed by the
|
|
110580
|
+
* engine, never aged, belonging to no device.
|
|
110581
|
+
*/
|
|
110582
|
+
function defineEntryKind(name, spec) {
|
|
110583
|
+
const defined = defineRecordKinds({ [name]: {
|
|
110584
|
+
schema: spec.schema,
|
|
110585
|
+
class: "config",
|
|
110586
|
+
writeTrigger: spec.writeTrigger ?? "an operator adds or edits an entry in the entries UI",
|
|
110587
|
+
retention: { none: "an entry goes only when the operator deletes it" },
|
|
110588
|
+
...spec.maxDataBytes === void 0 ? {} : { maxDataBytes: spec.maxDataBytes },
|
|
110589
|
+
...spec.database === void 0 ? {} : { database: spec.database },
|
|
110590
|
+
...spec.indexes === void 0 ? {} : { indexes: spec.indexes },
|
|
110591
|
+
...spec.secretArrayKeys === void 0 ? {} : { secretArrayKeys: spec.secretArrayKeys },
|
|
110592
|
+
...spec.retiredSecretPaths === void 0 ? {} : { retiredSecretPaths: spec.retiredSecretPaths },
|
|
110593
|
+
entry: {
|
|
110594
|
+
title: spec.title,
|
|
110595
|
+
...spec.nameField === void 0 ? {} : { nameField: spec.nameField }
|
|
110596
|
+
}
|
|
110597
|
+
} })[name];
|
|
110598
|
+
if (defined === void 0) throw new DeclarationRefusedError(`entry kind "${name}" was not built`);
|
|
110599
|
+
return defined;
|
|
110600
|
+
}
|
|
110601
|
+
/**
|
|
110602
|
+
* The share-view scope kinds a share-link token can carry. The hub mints
|
|
110603
|
+
* and validates them (`ShareViewGrantSchema` builds its
|
|
110604
|
+
* enum from this list); a data plane names the kinds it ACCEPTS in `share`.
|
|
110605
|
+
*/
|
|
110606
|
+
var SHARE_VIEW_KINDS = ["grid-view", "events-view"];
|
|
110607
|
+
/** The wire shape of {@link PeerBytesTicket} — see the type for what it is. */
|
|
110608
|
+
var PeerBytesTicketSchema = object({
|
|
110609
|
+
/** `http://127.0.0.1:<port>/<token>`. One `GET` takes it. */
|
|
110610
|
+
url: string().min(1),
|
|
110611
|
+
/**
|
|
110612
|
+
* The HOST node this URL means something on — the hub or a named agent,
|
|
110613
|
+
* never a runner. {@link AddonPeerBytes.open} compares it to its own and
|
|
110614
|
+
* refuses `cross-node` by name when they differ, without dialling.
|
|
110615
|
+
*/
|
|
110616
|
+
hostNodeId: string().min(1),
|
|
110617
|
+
expiresAtMs: number().int().nonnegative(),
|
|
110618
|
+
/**
|
|
110619
|
+
* What the producer DECLARED the body to be, when it knows — `null` when it
|
|
110620
|
+
* does not. Never `0` for unknown (D393): a consumer sizing a bound off this
|
|
110621
|
+
* must be able to tell "the producer did not say" from "the body is empty".
|
|
110622
|
+
*/
|
|
110623
|
+
declaredBytes: number().int().nonnegative().nullable()
|
|
110624
|
+
});
|
|
110184
110625
|
var READING_QUANTITIES = [
|
|
110185
110626
|
"temperature",
|
|
110186
110627
|
"pressure",
|
|
@@ -110868,7 +111309,6 @@ var CAP_NAMES = Object.freeze([
|
|
|
110868
111309
|
"climate-control",
|
|
110869
111310
|
"color",
|
|
110870
111311
|
"composer",
|
|
110871
|
-
"connection-test",
|
|
110872
111312
|
"connectivity",
|
|
110873
111313
|
"consumables",
|
|
110874
111314
|
"contact",
|
|
@@ -112015,6 +112455,10 @@ Object.freeze({
|
|
|
112015
112455
|
"all",
|
|
112016
112456
|
"one"
|
|
112017
112457
|
]
|
|
112458
|
+
},
|
|
112459
|
+
{
|
|
112460
|
+
"path": "positionUpdatedAt",
|
|
112461
|
+
"valueType": "number"
|
|
112018
112462
|
}
|
|
112019
112463
|
],
|
|
112020
112464
|
"meter": [{
|
|
@@ -112269,22 +112713,6 @@ Object.freeze({
|
|
|
112269
112713
|
"path": "pumpRunning",
|
|
112270
112714
|
"valueType": "boolean"
|
|
112271
112715
|
},
|
|
112272
|
-
{
|
|
112273
|
-
"path": "lastDrink",
|
|
112274
|
-
"valueType": "number"
|
|
112275
|
-
},
|
|
112276
|
-
{
|
|
112277
|
-
"path": "currentHourDrink",
|
|
112278
|
-
"valueType": "number"
|
|
112279
|
-
},
|
|
112280
|
-
{
|
|
112281
|
-
"path": "last24hDrink",
|
|
112282
|
-
"valueType": "number"
|
|
112283
|
-
},
|
|
112284
|
-
{
|
|
112285
|
-
"path": "todayDrink",
|
|
112286
|
-
"valueType": "number"
|
|
112287
|
-
},
|
|
112288
112716
|
{
|
|
112289
112717
|
"path": "error",
|
|
112290
112718
|
"valueType": "string"
|
|
@@ -112850,6 +113278,59 @@ Object.freeze({
|
|
|
112850
113278
|
}
|
|
112851
113279
|
]
|
|
112852
113280
|
});
|
|
113281
|
+
Object.freeze({
|
|
113282
|
+
"actions": { "run": 363e4 },
|
|
113283
|
+
"audio-analyzer": { "classify": 3e4 },
|
|
113284
|
+
"custom-model-registry": { "importModelBundle": 18e5 },
|
|
113285
|
+
"database-snapshot": { "writeSnapshot": 18e5 },
|
|
113286
|
+
"device-manager": {
|
|
113287
|
+
"migrateDevice": 72e4,
|
|
113288
|
+
"runDiscoverySweep": 12e4
|
|
113289
|
+
},
|
|
113290
|
+
"device-provider": { "reloadDevice": 18e4 },
|
|
113291
|
+
"llm": {
|
|
113292
|
+
"generate": 6e5,
|
|
113293
|
+
"generateVision": 6e5,
|
|
113294
|
+
"testProfile": 6e5
|
|
113295
|
+
},
|
|
113296
|
+
"llm-runtime": {
|
|
113297
|
+
"complete": 6e5,
|
|
113298
|
+
"completeApple": 6e5,
|
|
113299
|
+
"ensureStarted": 6e5,
|
|
113300
|
+
"installModel": 36e5
|
|
113301
|
+
},
|
|
113302
|
+
"local-network": { "scanNetwork": 9e4 },
|
|
113303
|
+
"model-convert": { "convert": 6e5 },
|
|
113304
|
+
"pipeline-analytics": {
|
|
113305
|
+
"addRetrainFrameFromRecording": 6e4,
|
|
113306
|
+
"offerRetrainArchive": 12e4,
|
|
113307
|
+
"proposeRetrainAnnotationsWithLlm": 18e4,
|
|
113308
|
+
"resolveRetrainTrainingCorpus": 6e4,
|
|
113309
|
+
"writeRetrainArchive": 36e5
|
|
113310
|
+
},
|
|
113311
|
+
"server-management": { "applyServerUpdate": 96e4 },
|
|
113312
|
+
"terminal-session": { "pullOutput": 15e3 },
|
|
113313
|
+
"training": {
|
|
113314
|
+
"canaryResult": 12e4,
|
|
113315
|
+
"cancelJob": 12e4,
|
|
113316
|
+
"planJob": 6e4,
|
|
113317
|
+
"registerResult": 18e5,
|
|
113318
|
+
"rollbackCanary": 12e4,
|
|
113319
|
+
"startJob": 12e4,
|
|
113320
|
+
"startJobBatch": 12e4
|
|
113321
|
+
},
|
|
113322
|
+
"training-provider": {
|
|
113323
|
+
"cancelJob": 6e4,
|
|
113324
|
+
"cleanupJob": 3e5,
|
|
113325
|
+
"getJob": 6e4,
|
|
113326
|
+
"listJobEvents": 6e4,
|
|
113327
|
+
"listJobs": 12e4,
|
|
113328
|
+
"offerArtifact": 3e5,
|
|
113329
|
+
"readResult": 3e5,
|
|
113330
|
+
"submitJob": 18e5,
|
|
113331
|
+
"uploadDataset": 72e5
|
|
113332
|
+
}
|
|
113333
|
+
});
|
|
112853
113334
|
object({
|
|
112854
113335
|
code: string().regex(/^[a-z][a-z0-9-]*(\.[a-z0-9-]+)+$/),
|
|
112855
113336
|
params: record(string(), union([string(), number()])).optional()
|
|
@@ -112893,7 +113374,7 @@ function sleep(ms) {
|
|
|
112893
113374
|
return new Promise((resolve) => setTimeout(resolve, Math.max(0, ms)));
|
|
112894
113375
|
}
|
|
112895
113376
|
//#endregion
|
|
112896
|
-
//#region ../types/dist/composition-
|
|
113377
|
+
//#region ../types/dist/composition-BmBHuDTQ.mjs
|
|
112897
113378
|
/**
|
|
112898
113379
|
* The ffmpeg build every CamStack node downloads, per platform and arch.
|
|
112899
113380
|
*
|
|
@@ -113197,7 +113678,7 @@ var table = {
|
|
|
113197
113678
|
},
|
|
113198
113679
|
dwell: {
|
|
113199
113680
|
minArgs: 3,
|
|
113200
|
-
maxArgs:
|
|
113681
|
+
maxArgs: 4,
|
|
113201
113682
|
apply: () => {
|
|
113202
113683
|
throw new ExpressionEvalError("dwell: stateful evaluation context is required");
|
|
113203
113684
|
}
|
|
@@ -114054,6 +114535,17 @@ var NodeColorIdSchema = _enum([
|
|
|
114054
114535
|
"node-g",
|
|
114055
114536
|
"node-h"
|
|
114056
114537
|
]);
|
|
114538
|
+
//#endregion
|
|
114539
|
+
//#region ../types/dist/index.mjs
|
|
114540
|
+
/**
|
|
114541
|
+
* The `smtp-inbound` broker kind (D999): a mailbox a device can send mail to.
|
|
114542
|
+
*
|
|
114543
|
+
* The `broker` cap carries these as `Record<string, unknown>` on the wire; the
|
|
114544
|
+
* provider and its consumers parse them with the schemas below at BOTH ends, so
|
|
114545
|
+
* the shape is declared once.
|
|
114546
|
+
*/
|
|
114547
|
+
/** The broker kind tag. */
|
|
114548
|
+
var SMTP_INBOUND_KIND = "smtp-inbound";
|
|
114057
114549
|
/** The id the first mailbox is minted under (adopt-id), so a consumer can find it again. */
|
|
114058
114550
|
var SMTP_INBOUND_DEFAULT_ID = "smtp-inbound-default";
|
|
114059
114551
|
var SMTP_INBOUND_DEFAULT_PORT = 2525;
|
|
@@ -114075,387 +114567,607 @@ object({
|
|
|
114075
114567
|
maxMessageBytes: number().int().positive().default(SMTP_INBOUND_DEFAULT_MAX_MESSAGE_BYTES)
|
|
114076
114568
|
});
|
|
114077
114569
|
/**
|
|
114078
|
-
* What `getBrokerConfig` answers: what a device needs to send mail here.
|
|
114079
|
-
* `host` is null when the `internal` role of the network palette is not set;
|
|
114080
|
-
* `hostReason` then says where to set it.
|
|
114570
|
+
* What `getBrokerConfig` answers: what a device needs to send mail here.
|
|
114571
|
+
* `host` is null when the `internal` role of the network palette is not set;
|
|
114572
|
+
* `hostReason` then says where to set it.
|
|
114573
|
+
*/
|
|
114574
|
+
var SmtpInboundConfigSchema = object({
|
|
114575
|
+
host: string().min(1).nullable(),
|
|
114576
|
+
hostReason: string().nullable(),
|
|
114577
|
+
port: PortSchema,
|
|
114578
|
+
domain: string().min(1),
|
|
114579
|
+
requireAuth: boolean(),
|
|
114580
|
+
username: string(),
|
|
114581
|
+
password: string(),
|
|
114582
|
+
starttls: boolean()
|
|
114583
|
+
});
|
|
114584
|
+
object({
|
|
114585
|
+
recipients: array(SmtpRecipientSchema).min(1),
|
|
114586
|
+
/**
|
|
114587
|
+
* Who is subscribing. A second `subscribe` with the same id REPLACES that subscriber's
|
|
114588
|
+
* recipients (the way a consumer that restarted, or lost a device, declares its set again);
|
|
114589
|
+
* a recipient held by another subscriber is refused with `smtp-inbound/recipient-claimed`.
|
|
114590
|
+
* Absent, the subscriber is anonymous and unique.
|
|
114591
|
+
*/
|
|
114592
|
+
subscriberId: string().min(1).max(64).optional()
|
|
114593
|
+
});
|
|
114594
|
+
var SmtpInboundAttachmentSchema = object({
|
|
114595
|
+
filename: string(),
|
|
114596
|
+
contentType: string(),
|
|
114597
|
+
bytes: number().int().nonnegative()
|
|
114598
|
+
});
|
|
114599
|
+
/** The payload of one `broker.message` (the key is the recipient local-part). */
|
|
114600
|
+
var SmtpInboundMessageSchema = object({
|
|
114601
|
+
/** Monotonic per mailbox; a gap tells a consumer it missed an event. */
|
|
114602
|
+
seq: number().int().positive(),
|
|
114603
|
+
messageId: string(),
|
|
114604
|
+
receivedAt: number().int().nonnegative(),
|
|
114605
|
+
from: string(),
|
|
114606
|
+
to: string(),
|
|
114607
|
+
subject: string(),
|
|
114608
|
+
text: string().max(SMTP_INBOUND_TEXT_MAX_CHARS),
|
|
114609
|
+
attachments: array(SmtpInboundAttachmentSchema)
|
|
114610
|
+
});
|
|
114611
|
+
/** What `getState('since:<seq>')` answers: every retained message after `seq`. */
|
|
114612
|
+
var SmtpInboundSinceSchema = object({
|
|
114613
|
+
/** The newest seq issued so far (0 before any mail). */
|
|
114614
|
+
lastSeq: number().int().nonnegative(),
|
|
114615
|
+
/** The oldest seq still retained; messages below it are gone. */
|
|
114616
|
+
oldestSeq: number().int().nonnegative(),
|
|
114617
|
+
messages: array(object({
|
|
114618
|
+
key: string(),
|
|
114619
|
+
message: SmtpInboundMessageSchema
|
|
114620
|
+
}))
|
|
114621
|
+
});
|
|
114622
|
+
/** The key a consumer passes to `getState` to replay the ring, and its parser. */
|
|
114623
|
+
function smtpSinceKey(seq) {
|
|
114624
|
+
return `since:${seq}`;
|
|
114625
|
+
}
|
|
114626
|
+
new Set([
|
|
114627
|
+
"track",
|
|
114628
|
+
"face",
|
|
114629
|
+
"identity",
|
|
114630
|
+
"plate",
|
|
114631
|
+
"vehicle",
|
|
114632
|
+
"scene",
|
|
114633
|
+
"motion",
|
|
114634
|
+
"object",
|
|
114635
|
+
"audio",
|
|
114636
|
+
"mosaic"
|
|
114637
|
+
]);
|
|
114638
|
+
/**
|
|
114639
|
+
* The owner types that are event tables, in the order the event-media resolver
|
|
114640
|
+
* should consider them. Exported so a consumer asking "is this key an event?"
|
|
114641
|
+
* does not re-spell the list and drift from it.
|
|
114642
|
+
*/
|
|
114643
|
+
var EVENT_OWNER_TYPES = [
|
|
114644
|
+
"motion",
|
|
114645
|
+
"object",
|
|
114646
|
+
"audio"
|
|
114647
|
+
];
|
|
114648
|
+
/**
|
|
114649
|
+
* The same list as a Zod enum, for the cap inputs that must NAME the table
|
|
114650
|
+
* (D482: `getEventMedia` / `listEventMedia` take an owner, and an owner is
|
|
114651
|
+
* `(table, id)`).
|
|
114652
|
+
*
|
|
114653
|
+
* Built FROM {@link EVENT_OWNER_TYPES} rather than re-spelled: a fourth event
|
|
114654
|
+
* table would otherwise be accepted by the codec and refused at the door, with
|
|
114655
|
+
* nothing failing until a caller asked.
|
|
114656
|
+
*/
|
|
114657
|
+
var EventOwnerTypeSchema = _enum(EVENT_OWNER_TYPES);
|
|
114658
|
+
/** The same list as a Zod enum, for the cap input that carries it. */
|
|
114659
|
+
var MediaPresenceOwnerKindSchema = _enum([...EVENT_OWNER_TYPES, "track"]);
|
|
114660
|
+
new Set(EVENT_OWNER_TYPES);
|
|
114661
|
+
/**
|
|
114662
|
+
* What a published package needs from the rest of the install (D989).
|
|
114663
|
+
*
|
|
114664
|
+
* One published framework package (`@camstack/server`) carries the kernel, the
|
|
114665
|
+
* builtins and the capability contracts, so "which addon runs on which
|
|
114666
|
+
* framework" is a question of version, and the answer is DECLARED by the
|
|
114667
|
+
* package that knows it:
|
|
114668
|
+
*
|
|
114669
|
+
* - an addon says the oldest server it runs on (`requires.server: ">=X"`);
|
|
114670
|
+
* - the server says the oldest addon it works with
|
|
114671
|
+
* (`requires.addons: { "@camstack/addon-x": ">=Y" }`) and the oldest shell
|
|
114672
|
+
* around it (`requires.wrapper: { desktop, image }`);
|
|
114673
|
+
* - a wrapper (the desktop app, the container starter) says which server
|
|
114674
|
+
* range it can host, and reports its own kind and version.
|
|
114675
|
+
*
|
|
114676
|
+
* The publish workflow STAMPS these after the version bump
|
|
114677
|
+
* (`scripts/ci/stamp-requires.mjs`); nobody types a number by hand.
|
|
114678
|
+
*
|
|
114679
|
+
* A requirement that cannot be checked is NOT met: a shell that reports no
|
|
114680
|
+
* version counts as below the minimum, and an unreadable running version is
|
|
114681
|
+
* named in the result (a failed read is never a pass).
|
|
114682
|
+
*/
|
|
114683
|
+
/** `>=MAJOR.MINOR.PATCH[-prerelease]` — the only range shape a requirement uses. */
|
|
114684
|
+
var MinVersionSchema = string().regex(/^>=\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/, "a minimum is written \">=X.Y.Z\"");
|
|
114685
|
+
object({
|
|
114686
|
+
/** The oldest `@camstack/server` this package runs on. */
|
|
114687
|
+
server: MinVersionSchema.optional(),
|
|
114688
|
+
/** The oldest installed version of each named addon package. */
|
|
114689
|
+
addons: record(string(), MinVersionSchema).optional(),
|
|
114690
|
+
/** The oldest shell around the server, per shell kind. */
|
|
114691
|
+
wrapper: object({
|
|
114692
|
+
desktop: MinVersionSchema.optional(),
|
|
114693
|
+
image: MinVersionSchema.optional()
|
|
114694
|
+
}).optional()
|
|
114695
|
+
});
|
|
114696
|
+
/** One unmet requirement; each names the versions on both sides. */
|
|
114697
|
+
var UnmetRequirementSchema = discriminatedUnion("kind", [
|
|
114698
|
+
object({
|
|
114699
|
+
kind: literal("server-too-old"),
|
|
114700
|
+
required: string(),
|
|
114701
|
+
/** `null` — the running server version could not be read. */
|
|
114702
|
+
running: string().nullable()
|
|
114703
|
+
}),
|
|
114704
|
+
object({
|
|
114705
|
+
kind: literal("addon-too-old"),
|
|
114706
|
+
packageName: string(),
|
|
114707
|
+
required: string(),
|
|
114708
|
+
/** `null` — the addon is not installed (or its version is unreadable). */
|
|
114709
|
+
running: string().nullable()
|
|
114710
|
+
}),
|
|
114711
|
+
object({
|
|
114712
|
+
kind: literal("wrapper-too-old"),
|
|
114713
|
+
wrapper: _enum(["desktop", "image"]),
|
|
114714
|
+
required: string(),
|
|
114715
|
+
/** `null` — the wrapper reported no version. */
|
|
114716
|
+
running: string().nullable()
|
|
114717
|
+
})
|
|
114718
|
+
]);
|
|
114719
|
+
var RequiredAddonUpdateSchema = object({
|
|
114720
|
+
packageName: string(),
|
|
114721
|
+
/** The minimum the target server declares. */
|
|
114722
|
+
required: string(),
|
|
114723
|
+
/** What this node has; `null` when the addon is not installed. */
|
|
114724
|
+
installed: string().nullable()
|
|
114725
|
+
});
|
|
114726
|
+
/**
|
|
114727
|
+
* Which integration instance a settings form is for. An addon that serves several instances
|
|
114728
|
+
* (`instanceMode: multiple`) can show a different form per instance — an NVR integration
|
|
114729
|
+
* needs its connection, the default integration needs the addon's own sections.
|
|
114730
|
+
*
|
|
114731
|
+
* - `integrationId` is `null` in the create wizard: nothing exists yet, the operator is
|
|
114732
|
+
* setting up a NEW instance.
|
|
114733
|
+
* - `mode` is the wizard mode of the integration type (`getAvailableTypes`).
|
|
114734
|
+
* - `candidateStableId` is the discovery candidate a wizard was seeded from, if any.
|
|
114735
|
+
*/
|
|
114736
|
+
var IntegrationInstanceRefSchema = object({
|
|
114737
|
+
integrationId: string().nullable(),
|
|
114738
|
+
mode: _enum([
|
|
114739
|
+
"standalone",
|
|
114740
|
+
"account",
|
|
114741
|
+
"broker"
|
|
114742
|
+
]),
|
|
114743
|
+
candidateStableId: string().optional()
|
|
114744
|
+
});
|
|
114745
|
+
/**
|
|
114746
|
+
* notification-output — canonical, capability-gated notification delivery.
|
|
114747
|
+
*
|
|
114748
|
+
* Apprise-derived model (see
|
|
114749
|
+
* `docs/superpowers/specs/2026-07-03-notification-output-notifier-matrix.md`):
|
|
114750
|
+
* callers emit ONE canonical `Notification`; each provider declares a
|
|
114751
|
+
* per-kind capability descriptor (`TargetKind`), and the pure degrade
|
|
114752
|
+
* engine (`@camstack/types` `prepareNotification`) transcodes / degrades the
|
|
114753
|
+
* message to what the kind supports — callers never special-case a service.
|
|
114754
|
+
*
|
|
114755
|
+
* DESIGN DECISIONS (locked):
|
|
114756
|
+
* - Target CRUD lives on THIS cap (`upsertTarget` / `deleteTarget` /
|
|
114757
|
+
* `setTargetEnabled`), each provider persisting via the `settings-store`
|
|
114758
|
+
* cap. Rationale: the admin UI needs one uniform surface across the
|
|
114759
|
+
* notifiers addon AND the HA addon; the addon-`globalSettingsSchema`-array
|
|
114760
|
+
* alternative would fork the UI per addon and cannot host the
|
|
114761
|
+
* discovery→adopt flow.
|
|
114762
|
+
* - `listTargetKinds` / `listTargets` / `discoverTargets` return arrays →
|
|
114763
|
+
* the generated cap-mount auto-`concatCollection`-fans them across every
|
|
114764
|
+
* registered provider (notifiers addon + HA addon) so one catalog is
|
|
114765
|
+
* routable. `send` / `testTarget` / CRUD route to ONE provider by the
|
|
114766
|
+
* `addonId` the generated collection router extracts from the call input.
|
|
114767
|
+
* - `Attachment.bytes` is `Uint8Array`. Transport-safe: superjson (the tRPC
|
|
114768
|
+
* transformer) + UDS MsgPack both round-trip typed arrays — already used by
|
|
114769
|
+
* `storage` / `storage-provider` / `recording` caps over the same path. No
|
|
114770
|
+
* base64 fallback needed.
|
|
114771
|
+
*
|
|
114772
|
+
* TODO (deferred, closed-set change — separate decision): add
|
|
114773
|
+
* `providerKind: 'notify'` so notification providers surface on the unified
|
|
114774
|
+
* admin "Integrations" page.
|
|
114775
|
+
*/
|
|
114776
|
+
/**
|
|
114777
|
+
* Zentik-derived typed-media enum — the superset across every kind. Each
|
|
114778
|
+
* adapter picks what it supports and the degrade engine filters the rest.
|
|
114779
|
+
*/
|
|
114780
|
+
var AttachmentMediaTypeSchema = _enum([
|
|
114781
|
+
"image",
|
|
114782
|
+
"video",
|
|
114783
|
+
"gif",
|
|
114784
|
+
"audio",
|
|
114785
|
+
"icon"
|
|
114786
|
+
]);
|
|
114787
|
+
/**
|
|
114788
|
+
* A single attachment. Exactly one of `url` (remote source, most adapters
|
|
114789
|
+
* prefer this) or `bytes` (inline source; required for Pushover-style
|
|
114790
|
+
* bytes-only kinds) MUST be present — the degrade engine expresses a
|
|
114791
|
+
* url→bytes fetch as a `needsFetch` directive the adapter executes.
|
|
114792
|
+
*/
|
|
114793
|
+
var AttachmentSchema = object({
|
|
114794
|
+
mediaType: AttachmentMediaTypeSchema,
|
|
114795
|
+
url: string().optional(),
|
|
114796
|
+
bytes: _instanceof(Uint8Array).optional(),
|
|
114797
|
+
mime: string().optional(),
|
|
114798
|
+
name: string().optional()
|
|
114799
|
+
}).refine((a) => a.url !== void 0 || a.bytes !== void 0, { message: "Attachment requires either `url` or `bytes`" });
|
|
114800
|
+
var NotificationFormatSchema = _enum([
|
|
114801
|
+
"text",
|
|
114802
|
+
"markdown",
|
|
114803
|
+
"html"
|
|
114804
|
+
]);
|
|
114805
|
+
/**
|
|
114806
|
+
* The CLOSED icon vocabulary an action button may use.
|
|
114807
|
+
*
|
|
114808
|
+
* A closed set, not a free string, and that is the whole point: an arbitrary
|
|
114809
|
+
* icon name is one that ntfy renders, zentik silently drops, and nobody
|
|
114810
|
+
* notices — the same class of gap as a zone vocabulary nothing produced
|
|
114811
|
+
* ([D35](../../../docs/decisions/adr-0035.md)). Every adapter maps this set or
|
|
114812
|
+
* declares `actionIcons: false` and the degrade engine strips the field.
|
|
114813
|
+
*
|
|
114814
|
+
* Named by INTENT, never by glyph. "check" would tie the vocabulary to one
|
|
114815
|
+
* renderer's icon set; "acknowledge" survives an adapter that draws it
|
|
114816
|
+
* differently.
|
|
114817
|
+
*
|
|
114818
|
+
* ── A TOKEN IS NOT A WIRE VALUE ─────────────────────────────────────
|
|
114819
|
+
*
|
|
114820
|
+
* These names are for US. **No adapter may forward one verbatim.** Each maps
|
|
114821
|
+
* the whole set onto its own renderer's vocabulary through a
|
|
114822
|
+
* `Record<NotificationActionIcon, string>` — a Record, never a lookup with a
|
|
114823
|
+
* fallback, so adding a member here fails every adapter's build until someone
|
|
114824
|
+
* decides its glyph, which is the only place that decision can be made
|
|
114825
|
+
* honestly.
|
|
114826
|
+
*
|
|
114827
|
+
* This paragraph is the bug. Zentik declared `actionIcons: true` and passed
|
|
114828
|
+
* `disarm` straight through; iOS feeds that string to
|
|
114829
|
+
* `UNNotificationActionIcon(systemImageName:)`, `disarm` is not an SF Symbol,
|
|
114830
|
+
* and every snooze and alarm button arrived BLANK. A pass-through is not a
|
|
114831
|
+
* mapping, and "the field is documented" is not "the value renders".
|
|
114832
|
+
*
|
|
114833
|
+
* Adding a member is TRAIN-BOUND. The enum lives in the published
|
|
114834
|
+
* `@camstack/server` closure and the cap seam validates against the HUB's copy,
|
|
114835
|
+
* so an addon that emits a token the running hub does not know does not lose an
|
|
114836
|
+
* icon — its whole `send` fails Zod validation and the notification never
|
|
114837
|
+
* arrives. Never emit a new token from an addon before the train carrying it.
|
|
114838
|
+
*/
|
|
114839
|
+
var NotificationActionIconSchema = _enum([
|
|
114840
|
+
"acknowledge",
|
|
114841
|
+
"dismiss",
|
|
114842
|
+
"silence",
|
|
114843
|
+
"snooze",
|
|
114844
|
+
"view",
|
|
114845
|
+
"play",
|
|
114846
|
+
"open",
|
|
114847
|
+
"close",
|
|
114848
|
+
"lock",
|
|
114849
|
+
"unlock",
|
|
114850
|
+
"arm",
|
|
114851
|
+
"arm-home",
|
|
114852
|
+
"arm-away",
|
|
114853
|
+
"arm-night",
|
|
114854
|
+
"disarm",
|
|
114855
|
+
"light",
|
|
114856
|
+
"alert",
|
|
114857
|
+
"camera"
|
|
114858
|
+
]);
|
|
114859
|
+
/** A single tap-through action button. */
|
|
114860
|
+
var NotificationActionSchema = object({
|
|
114861
|
+
id: string(),
|
|
114862
|
+
label: string(),
|
|
114863
|
+
url: string().optional(),
|
|
114864
|
+
/** Dropped by the degrade engine for a kind with `caps.actionIcons: false`. */
|
|
114865
|
+
icon: NotificationActionIconSchema.optional(),
|
|
114866
|
+
/**
|
|
114867
|
+
* Renders in a warning style where the notifier supports it.
|
|
114868
|
+
*
|
|
114869
|
+
* A HINT, never a gate. The callback's authority is its token and nothing
|
|
114870
|
+
* else — see `notification-center/action-token.ts` for what that does and
|
|
114871
|
+
* does not buy.
|
|
114872
|
+
*/
|
|
114873
|
+
destructive: boolean().optional(),
|
|
114874
|
+
/**
|
|
114875
|
+
* How the tap should REACH the url.
|
|
114876
|
+
*
|
|
114877
|
+
* `navigate` (absent, and every button authored before this field) opens it:
|
|
114878
|
+
* the phone leaves the notification and shows whatever the callback returns.
|
|
114879
|
+
* That is right for a button whose answer the operator wants to read.
|
|
114880
|
+
*
|
|
114881
|
+
* `background` fires it as a POST and stays put. It exists for the buttons
|
|
114882
|
+
* whose whole point is not to interrupt — "silence this for 30 minutes" is
|
|
114883
|
+
* an answer to the notification, and being thrown into a browser tab to
|
|
114884
|
+
* confirm it costs more attention than the notification did. A backend that
|
|
114885
|
+
* cannot do a background call renders it as an ordinary link (the adapters
|
|
114886
|
+
* fall back rather than dropping the button), so this is a preference, never
|
|
114887
|
+
* a requirement.
|
|
114888
|
+
*/
|
|
114889
|
+
mode: _enum(["navigate", "background"]).optional()
|
|
114890
|
+
});
|
|
114891
|
+
/** A delivery parameter value: what a notifier declared it takes. */
|
|
114892
|
+
var DeliveryParamValueSchema = union([
|
|
114893
|
+
string(),
|
|
114894
|
+
number(),
|
|
114895
|
+
boolean()
|
|
114896
|
+
]);
|
|
114897
|
+
/**
|
|
114898
|
+
* One extra delivery parameter a notifier KIND declares (D938). A rule that
|
|
114899
|
+
* addresses a target of that kind may set it; a kind that declares nothing is
|
|
114900
|
+
* never handed one. The admin UI derives its control from this descriptor —
|
|
114901
|
+
* no editor knows a service by name.
|
|
114902
|
+
*
|
|
114903
|
+
* Optional fields are `.optional()`, never `.default()` (a Zod default does not
|
|
114904
|
+
* run on the addon cap path).
|
|
114905
|
+
*/
|
|
114906
|
+
var DeliveryParamSchema = object({
|
|
114907
|
+
key: string().min(1),
|
|
114908
|
+
label: string(),
|
|
114909
|
+
/** i18n key of the label, resolved by the declaring addon's namespace. */
|
|
114910
|
+
labelKey: string().optional(),
|
|
114911
|
+
type: _enum([
|
|
114912
|
+
"enum",
|
|
114913
|
+
"number",
|
|
114914
|
+
"boolean",
|
|
114915
|
+
"string"
|
|
114916
|
+
]),
|
|
114917
|
+
/** `enum` only: the closed set of accepted values. */
|
|
114918
|
+
options: array(object({
|
|
114919
|
+
value: string(),
|
|
114920
|
+
label: string()
|
|
114921
|
+
})).optional(),
|
|
114922
|
+
/** `number` only. */
|
|
114923
|
+
min: number().optional(),
|
|
114924
|
+
max: number().optional(),
|
|
114925
|
+
/** What the notifier does when the rule sets nothing; shown as the placeholder. */
|
|
114926
|
+
default: DeliveryParamValueSchema.optional()
|
|
114927
|
+
});
|
|
114928
|
+
/**
|
|
114929
|
+
* The canonical notification. `body` is the only hard field (Apprise model).
|
|
114930
|
+
* `priority` is a 5-level ORDINAL (1=lowest … 3=normal(default) … 5=urgent),
|
|
114931
|
+
* NOT a fixed severity enum — each kind declares its own `caps.levels` and
|
|
114932
|
+
* the adapter maps this ordinal onto its native level. `level?` is an
|
|
114933
|
+
* optional kind-native level id (`emergency`, `silent`, …) that overrides
|
|
114934
|
+
* `priority` for that one target.
|
|
114935
|
+
*/
|
|
114936
|
+
var NotificationSchema = object({
|
|
114937
|
+
body: string(),
|
|
114938
|
+
title: string().optional(),
|
|
114939
|
+
format: NotificationFormatSchema.default("text"),
|
|
114940
|
+
priority: number().int().min(1).max(5).default(3),
|
|
114941
|
+
level: string().optional(),
|
|
114942
|
+
attachments: array(AttachmentSchema).optional(),
|
|
114943
|
+
clickUrl: string().optional(),
|
|
114944
|
+
actions: array(NotificationActionSchema).optional(),
|
|
114945
|
+
sound: string().optional(),
|
|
114946
|
+
ttl: number().optional(),
|
|
114947
|
+
tag: string().optional(),
|
|
114948
|
+
deviceId: number().optional(),
|
|
114949
|
+
eventId: string().optional(),
|
|
114950
|
+
metadata: record(string(), unknown()).optional(),
|
|
114951
|
+
/**
|
|
114952
|
+
* Values for the parameters the target's kind DECLARES in
|
|
114953
|
+
* {@link TargetKindSchema} `deliveryParams`. Already validated against the
|
|
114954
|
+
* declaration by the sender; a notifier reads only the keys it declared.
|
|
114955
|
+
*/
|
|
114956
|
+
delivery: record(string(), DeliveryParamValueSchema).optional()
|
|
114957
|
+
});
|
|
114958
|
+
/** One declared native severity/priority level for a kind. */
|
|
114959
|
+
var TargetKindLevelSchema = object({
|
|
114960
|
+
id: string(),
|
|
114961
|
+
label: string(),
|
|
114962
|
+
/** Which canonical priority (1..5) this level maps to. `null` = qualitative-only. */
|
|
114963
|
+
ordinal: number().int().min(1).max(5).nullable(),
|
|
114964
|
+
flags: object({
|
|
114965
|
+
critical: boolean().optional(),
|
|
114966
|
+
silent: boolean().optional(),
|
|
114967
|
+
noPush: boolean().optional()
|
|
114968
|
+
}).optional(),
|
|
114969
|
+
/** e.g. Pushover `emergency` requires `retry` / `expire`. */
|
|
114970
|
+
requires: array(string()).optional(),
|
|
114971
|
+
description: string().optional()
|
|
114972
|
+
});
|
|
114973
|
+
/** The full capability block consulted before dispatch. */
|
|
114974
|
+
var TargetKindCapsSchema = object({
|
|
114975
|
+
attachments: object({
|
|
114976
|
+
mediaTypes: array(AttachmentMediaTypeSchema),
|
|
114977
|
+
mode: _enum([
|
|
114978
|
+
"url",
|
|
114979
|
+
"bytes",
|
|
114980
|
+
"both"
|
|
114981
|
+
]),
|
|
114982
|
+
max: number().int().nonnegative(),
|
|
114983
|
+
maxBytes: number().int().positive().optional()
|
|
114984
|
+
}),
|
|
114985
|
+
/** Max action buttons (0 = none). */
|
|
114986
|
+
actions: number().int().nonnegative(),
|
|
114987
|
+
/**
|
|
114988
|
+
* Whether this kind renders a per-action ICON.
|
|
114989
|
+
*
|
|
114990
|
+
* `.optional()`, deliberately NOT `.default(false)`: a Zod default does not
|
|
114991
|
+
* run on the addon cap path — three production failures in one day taught
|
|
114992
|
+
* this repo that once. Absent is read as false by the degrade engine, which
|
|
114993
|
+
* is the safe direction: an icon that is not rendered costs nothing, an icon
|
|
114994
|
+
* assumed and dropped costs the operator's trust in the field.
|
|
114995
|
+
*/
|
|
114996
|
+
actionIcons: boolean().optional(),
|
|
114997
|
+
levels: array(TargetKindLevelSchema),
|
|
114998
|
+
format: array(NotificationFormatSchema),
|
|
114999
|
+
clickUrl: boolean(),
|
|
115000
|
+
sound: boolean(),
|
|
115001
|
+
ttl: boolean(),
|
|
115002
|
+
bodyMaxLen: number().int().positive()
|
|
115003
|
+
});
|
|
115004
|
+
/**
|
|
115005
|
+
* `configSchema` is a `ConfigUISchema` tree passed through to the admin
|
|
115006
|
+
* FormBuilder. Stored as `z.unknown()` at the cap seam (mirrors
|
|
115007
|
+
* `device-provider.getChildCreationSchema` `CreationSchemaOutputSchema`) —
|
|
115008
|
+
* the union is large and not meant for runtime validation here; the exported
|
|
115009
|
+
* `TargetKind` type re-tightens `configSchema` to `ConfigUISchema`.
|
|
114081
115010
|
*/
|
|
114082
|
-
var
|
|
114083
|
-
|
|
114084
|
-
|
|
114085
|
-
|
|
114086
|
-
|
|
114087
|
-
|
|
114088
|
-
|
|
114089
|
-
password: string(),
|
|
114090
|
-
starttls: boolean()
|
|
114091
|
-
});
|
|
114092
|
-
object({
|
|
114093
|
-
recipients: array(SmtpRecipientSchema).min(1),
|
|
115011
|
+
var ConfigSchemaPassthrough$4 = unknown();
|
|
115012
|
+
var TargetKindSchema = object({
|
|
115013
|
+
kind: string(),
|
|
115014
|
+
label: string(),
|
|
115015
|
+
icon: string(),
|
|
115016
|
+
/** Stamped by each provider so the concat-fanned catalog stays routable. */
|
|
115017
|
+
addonId: string(),
|
|
114094
115018
|
/**
|
|
114095
|
-
*
|
|
114096
|
-
*
|
|
114097
|
-
*
|
|
114098
|
-
*
|
|
115019
|
+
* URL of the kind's bundled BRAND icon, served by the providing addon over
|
|
115020
|
+
* its own `addon-routes` surface (`/addon/<addonId>/icons/<kind>`). Absent
|
|
115021
|
+
* when the addon bundles no icon for that kind — the client then falls back
|
|
115022
|
+
* to a neutral glyph rather than rendering the raw `icon` NAME as text.
|
|
115023
|
+
*
|
|
115024
|
+
* Root-relative on purpose: it resolves against whatever origin serves a web
|
|
115025
|
+
* client, and a native client joins it onto its own hub base.
|
|
115026
|
+
*
|
|
115027
|
+
* DECLARED here deliberately. It used to travel as an undeclared passthrough
|
|
115028
|
+
* field that survived only because the runtime cap-router forwards provider
|
|
115029
|
+
* output verbatim — so every consumer had to re-declare it by hand to stop
|
|
115030
|
+
* its own Zod parse from stripping it, and the whole arrangement would have
|
|
115031
|
+
* broken silently the moment output validation was tightened anywhere.
|
|
114099
115032
|
*/
|
|
114100
|
-
|
|
114101
|
-
|
|
114102
|
-
|
|
114103
|
-
|
|
114104
|
-
|
|
114105
|
-
|
|
114106
|
-
|
|
114107
|
-
|
|
114108
|
-
|
|
114109
|
-
|
|
114110
|
-
|
|
114111
|
-
|
|
114112
|
-
|
|
114113
|
-
|
|
114114
|
-
|
|
114115
|
-
|
|
114116
|
-
|
|
114117
|
-
|
|
114118
|
-
|
|
114119
|
-
|
|
114120
|
-
|
|
114121
|
-
|
|
114122
|
-
|
|
114123
|
-
|
|
114124
|
-
|
|
114125
|
-
|
|
114126
|
-
|
|
114127
|
-
|
|
114128
|
-
|
|
115033
|
+
iconUrl: string().optional(),
|
|
115034
|
+
/**
|
|
115035
|
+
* Media type of {@link iconUrl} (`image/svg+xml`, `image/png`, …).
|
|
115036
|
+
*
|
|
115037
|
+
* The server knows this and therefore says it, because the client cannot
|
|
115038
|
+
* safely guess: a React-Native client renders SVG and raster through two
|
|
115039
|
+
* DIFFERENT components (`react-native-svg` vs `expo-image` — expo-image does
|
|
115040
|
+
* not decode SVG on iOS/Android), so without this it silently fell back to a
|
|
115041
|
+
* placeholder glyph for every vector icon while the web build looked fine.
|
|
115042
|
+
*
|
|
115043
|
+
* Absent when {@link iconUrl} is absent, or for a legacy provider that has
|
|
115044
|
+
* not been updated — a client that cannot determine the type should prefer
|
|
115045
|
+
* its raster path, which is the safe default for an unknown image.
|
|
115046
|
+
*/
|
|
115047
|
+
iconMediaType: string().optional(),
|
|
115048
|
+
configSchema: ConfigSchemaPassthrough$4,
|
|
115049
|
+
/**
|
|
115050
|
+
* The config keys that decide WHERE this kind's secrets are sent (server,
|
|
115051
|
+
* base URL, instance, chat, recipient). A save that changes any of them
|
|
115052
|
+
* while leaving a secret redacted is refused by the provider (D634), so an
|
|
115053
|
+
* editor uses this to ask for the secret on exactly those edits instead of
|
|
115054
|
+
* on every edit.
|
|
115055
|
+
*
|
|
115056
|
+
* Optional: absent from a provider that holds no secret (the Home Assistant
|
|
115057
|
+
* kinds) and from a provider older than this field — an editor that finds
|
|
115058
|
+
* it absent must assume ANY edit may need the secret.
|
|
115059
|
+
*/
|
|
115060
|
+
destinationKeys: array(string()).optional(),
|
|
115061
|
+
supportsDiscovery: boolean(),
|
|
115062
|
+
/**
|
|
115063
|
+
* Extra delivery parameters a rule may set for a target of this kind (D938).
|
|
115064
|
+
* Absent = none; the rule editor then offers nothing.
|
|
115065
|
+
*/
|
|
115066
|
+
deliveryParams: array(DeliveryParamSchema).optional(),
|
|
115067
|
+
caps: TargetKindCapsSchema
|
|
114129
115068
|
});
|
|
114130
|
-
/** The key a consumer passes to `getState` to replay the ring, and its parser. */
|
|
114131
|
-
function smtpSinceKey(seq) {
|
|
114132
|
-
return `since:${seq}`;
|
|
114133
|
-
}
|
|
114134
|
-
new Set([
|
|
114135
|
-
"track",
|
|
114136
|
-
"face",
|
|
114137
|
-
"identity",
|
|
114138
|
-
"plate",
|
|
114139
|
-
"vehicle",
|
|
114140
|
-
"scene",
|
|
114141
|
-
"motion",
|
|
114142
|
-
"object",
|
|
114143
|
-
"audio",
|
|
114144
|
-
"mosaic"
|
|
114145
|
-
]);
|
|
114146
|
-
/**
|
|
114147
|
-
* The owner types that are event tables, in the order the event-media resolver
|
|
114148
|
-
* should consider them. Exported so a consumer asking "is this key an event?"
|
|
114149
|
-
* does not re-spell the list and drift from it.
|
|
114150
|
-
*/
|
|
114151
|
-
var EVENT_OWNER_TYPES = [
|
|
114152
|
-
"motion",
|
|
114153
|
-
"object",
|
|
114154
|
-
"audio"
|
|
114155
|
-
];
|
|
114156
|
-
/**
|
|
114157
|
-
* The same list as a Zod enum, for the cap inputs that must NAME the table
|
|
114158
|
-
* (D482: `getEventMedia` / `listEventMedia` take an owner, and an owner is
|
|
114159
|
-
* `(table, id)`).
|
|
114160
|
-
*
|
|
114161
|
-
* Built FROM {@link EVENT_OWNER_TYPES} rather than re-spelled: a fourth event
|
|
114162
|
-
* table would otherwise be accepted by the codec and refused at the door, with
|
|
114163
|
-
* nothing failing until a caller asked.
|
|
114164
|
-
*/
|
|
114165
|
-
var EventOwnerTypeSchema = _enum(EVENT_OWNER_TYPES);
|
|
114166
|
-
/** The same list as a Zod enum, for the cap input that carries it. */
|
|
114167
|
-
var MediaPresenceOwnerKindSchema = _enum([...EVENT_OWNER_TYPES, "track"]);
|
|
114168
|
-
new Set(EVENT_OWNER_TYPES);
|
|
114169
115069
|
/**
|
|
114170
|
-
*
|
|
114171
|
-
*
|
|
114172
|
-
*
|
|
114173
|
-
* builtins and the capability contracts, so "which addon runs on which
|
|
114174
|
-
* framework" is a question of version, and the answer is DECLARED by the
|
|
114175
|
-
* package that knows it:
|
|
114176
|
-
*
|
|
114177
|
-
* - an addon says the oldest server it runs on (`requires.server: ">=X"`);
|
|
114178
|
-
* - the server says the oldest addon it works with
|
|
114179
|
-
* (`requires.addons: { "@camstack/addon-x": ">=Y" }`) and the oldest shell
|
|
114180
|
-
* around it (`requires.wrapper: { desktop, image }`);
|
|
114181
|
-
* - a wrapper (the desktop app, the container starter) says which server
|
|
114182
|
-
* range it can host, and reports its own kind and version.
|
|
114183
|
-
*
|
|
114184
|
-
* The publish workflow STAMPS these after the version bump
|
|
114185
|
-
* (`scripts/ci/stamp-requires.mjs`); nobody types a number by hand.
|
|
114186
|
-
*
|
|
114187
|
-
* A requirement that cannot be checked is NOT met: a shell that reports no
|
|
114188
|
-
* version counts as below the minimum, and an unreadable running version is
|
|
114189
|
-
* named in the result (a failed read is never a pass).
|
|
115070
|
+
* A persisted target. `config` holds secrets; providers REDACT secret fields
|
|
115071
|
+
* (return a presence marker only) when serving `listTargets` — never
|
|
115072
|
+
* round-trip a stored secret to the UI.
|
|
114190
115073
|
*/
|
|
114191
|
-
|
|
114192
|
-
|
|
114193
|
-
|
|
114194
|
-
|
|
114195
|
-
|
|
114196
|
-
|
|
114197
|
-
|
|
114198
|
-
/** The oldest shell around the server, per shell kind. */
|
|
114199
|
-
wrapper: object({
|
|
114200
|
-
desktop: MinVersionSchema.optional(),
|
|
114201
|
-
image: MinVersionSchema.optional()
|
|
114202
|
-
}).optional()
|
|
115074
|
+
var TargetSchema = object({
|
|
115075
|
+
id: string(),
|
|
115076
|
+
name: string(),
|
|
115077
|
+
kind: string(),
|
|
115078
|
+
addonId: string(),
|
|
115079
|
+
enabled: boolean(),
|
|
115080
|
+
config: record(string(), unknown())
|
|
114203
115081
|
});
|
|
114204
|
-
/**
|
|
114205
|
-
var
|
|
114206
|
-
|
|
114207
|
-
|
|
114208
|
-
|
|
114209
|
-
/** `null` — the running server version could not be read. */
|
|
114210
|
-
running: string().nullable()
|
|
114211
|
-
}),
|
|
114212
|
-
object({
|
|
114213
|
-
kind: literal("addon-too-old"),
|
|
114214
|
-
packageName: string(),
|
|
114215
|
-
required: string(),
|
|
114216
|
-
/** `null` — the addon is not installed (or its version is unreadable). */
|
|
114217
|
-
running: string().nullable()
|
|
114218
|
-
}),
|
|
114219
|
-
object({
|
|
114220
|
-
kind: literal("wrapper-too-old"),
|
|
114221
|
-
wrapper: _enum(["desktop", "image"]),
|
|
114222
|
-
required: string(),
|
|
114223
|
-
/** `null` — the wrapper reported no version. */
|
|
114224
|
-
running: string().nullable()
|
|
114225
|
-
})
|
|
114226
|
-
]);
|
|
114227
|
-
var RequiredAddonUpdateSchema = object({
|
|
114228
|
-
packageName: string(),
|
|
114229
|
-
/** The minimum the target server declares. */
|
|
114230
|
-
required: string(),
|
|
114231
|
-
/** What this node has; `null` when the addon is not installed. */
|
|
114232
|
-
installed: string().nullable()
|
|
115082
|
+
/** A discovery-surfaced candidate (config is partial + non-secret). */
|
|
115083
|
+
var DiscoveredTargetSchema = object({
|
|
115084
|
+
kind: string(),
|
|
115085
|
+
suggestedName: string(),
|
|
115086
|
+
config: record(string(), unknown())
|
|
114233
115087
|
});
|
|
114234
|
-
/**
|
|
114235
|
-
|
|
114236
|
-
|
|
114237
|
-
|
|
114238
|
-
|
|
114239
|
-
|
|
114240
|
-
|
|
114241
|
-
|
|
114242
|
-
* - `candidateStableId` is the discovery candidate a wizard was seeded from, if any.
|
|
114243
|
-
*/
|
|
114244
|
-
var IntegrationInstanceRefSchema = object({
|
|
114245
|
-
integrationId: string().nullable(),
|
|
114246
|
-
mode: _enum([
|
|
114247
|
-
"standalone",
|
|
114248
|
-
"account",
|
|
114249
|
-
"broker"
|
|
114250
|
-
]),
|
|
114251
|
-
candidateStableId: string().optional()
|
|
115088
|
+
/** The degrade engine's report — what was resolved / dropped / degraded. */
|
|
115089
|
+
var RenderedAsSchema = object({
|
|
115090
|
+
level: string(),
|
|
115091
|
+
format: NotificationFormatSchema,
|
|
115092
|
+
attachmentsSent: number().int().nonnegative(),
|
|
115093
|
+
actionsSent: number().int().nonnegative(),
|
|
115094
|
+
truncated: boolean(),
|
|
115095
|
+
dropped: array(string())
|
|
114252
115096
|
});
|
|
115097
|
+
var SendResultSchema = object({
|
|
115098
|
+
success: boolean(),
|
|
115099
|
+
error: string().optional(),
|
|
115100
|
+
renderedAs: RenderedAsSchema.optional()
|
|
115101
|
+
});
|
|
115102
|
+
/** Same shape as SendResult — kept as a distinct name for the test panel. */
|
|
115103
|
+
var TestResultSchema = SendResultSchema;
|
|
114253
115104
|
/**
|
|
114254
|
-
*
|
|
114255
|
-
*
|
|
114256
|
-
*
|
|
114257
|
-
* Every instance is one record of the addon's own kind, keyed by the
|
|
114258
|
-
* `integrations` registry id. The records door does the secret work: a field the
|
|
114259
|
-
* kind marks `.meta({ secret: true })` is a keychain marker bound to the row, so
|
|
114260
|
-
* deleting the row deletes the secret, and one row's value is never another's.
|
|
114261
|
-
*
|
|
114262
|
-
* Patch rules for a secret (`updateInstance`): omitted, `''`, the redaction
|
|
114263
|
-
* token or the view the form was given KEEP the stored secret;
|
|
114264
|
-
* `{ $secretClear: true }` clears it; any other string replaces it.
|
|
114265
|
-
*/
|
|
114266
|
-
/** The most instances one addon lists (an integrations page, not a table). */
|
|
114267
|
-
var INSTANCES_LIST_MAX = 1e3;
|
|
114268
|
-
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
114269
|
-
function topLevelSecretKeys(paths) {
|
|
114270
|
-
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
114271
|
-
}
|
|
114272
|
-
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
114273
|
-
function secretMapKeys(paths) {
|
|
114274
|
-
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
114275
|
-
}
|
|
114276
|
-
/**
|
|
114277
|
-
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
114278
|
-
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
114279
|
-
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
115105
|
+
* Pre-save credential probe against a partial (unsaved) target config.
|
|
115106
|
+
* `resolvedUrl` never includes secrets (token stripped from path).
|
|
114280
115107
|
*/
|
|
114281
|
-
|
|
114282
|
-
|
|
114283
|
-
|
|
114284
|
-
|
|
114285
|
-
|
|
114286
|
-
|
|
114287
|
-
}
|
|
114288
|
-
|
|
114289
|
-
|
|
114290
|
-
|
|
114291
|
-
unrepresentable: "any",
|
|
114292
|
-
io: "input"
|
|
114293
|
-
});
|
|
114294
|
-
const properties = Reflect.get(json, "properties");
|
|
114295
|
-
return typeof properties === "object" && properties !== null && "enabled" in properties;
|
|
114296
|
-
}
|
|
114297
|
-
var RecordIntegrationInstances = class {
|
|
114298
|
-
records;
|
|
114299
|
-
kind;
|
|
114300
|
-
hooks;
|
|
114301
|
-
handle;
|
|
114302
|
-
secretKeys;
|
|
114303
|
-
secretMaps;
|
|
114304
|
-
nameField;
|
|
114305
|
-
/** The `integrations` registry owns the on/off switch (`role: devices`); the body has none. */
|
|
114306
|
-
registryOwnsEnabled;
|
|
114307
|
-
constructor(records, kind, hooks) {
|
|
114308
|
-
this.records = records;
|
|
114309
|
-
this.kind = kind;
|
|
114310
|
-
this.hooks = hooks;
|
|
114311
|
-
this.handle = records.kind(kind);
|
|
114312
|
-
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
114313
|
-
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
114314
|
-
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
114315
|
-
this.registryOwnsEnabled = hooks.description.role === "devices";
|
|
114316
|
-
if (this.registryOwnsEnabled && declaresEnabled(kind)) throw new Error(`kind "${kind.name}": the integrations registry owns the on/off switch of a role "devices" addon, so the body must not declare "enabled"`);
|
|
114317
|
-
}
|
|
115108
|
+
var ProbeTargetConfigResultSchema = object({
|
|
115109
|
+
ok: boolean(),
|
|
115110
|
+
resolvedUrl: string(),
|
|
115111
|
+
httpStatus: number().int().optional(),
|
|
115112
|
+
stateInstance: string().optional(),
|
|
115113
|
+
error: string().optional()
|
|
115114
|
+
});
|
|
115115
|
+
method(object({}), array(TargetKindSchema)), method(object({}), array(TargetSchema), { auth: "admin" }), method(object({ targetId: string() }), TargetSchema, { auth: "admin" }), method(object({
|
|
115116
|
+
kind: string(),
|
|
115117
|
+
config: record(string(), unknown()).optional(),
|
|
114318
115118
|
/**
|
|
114319
|
-
*
|
|
114320
|
-
*
|
|
114321
|
-
*
|
|
115119
|
+
* When editing / duplicating, the blank password field never round-trips
|
|
115120
|
+
* the stored token. Pass the source target id so the provider can restore
|
|
115121
|
+
* secrets server-side before dialling (same merge as upsert).
|
|
114322
115122
|
*/
|
|
114323
|
-
|
|
114324
|
-
|
|
114325
|
-
|
|
114326
|
-
|
|
114327
|
-
|
|
114328
|
-
|
|
114329
|
-
|
|
114330
|
-
|
|
114331
|
-
|
|
114332
|
-
|
|
114333
|
-
|
|
114334
|
-
|
|
114335
|
-
|
|
114336
|
-
|
|
114337
|
-
|
|
114338
|
-
|
|
114339
|
-
|
|
114340
|
-
|
|
114341
|
-
|
|
114342
|
-
|
|
114343
|
-
|
|
114344
|
-
|
|
114345
|
-
|
|
114346
|
-
|
|
114347
|
-
|
|
114348
|
-
|
|
114349
|
-
|
|
114350
|
-
|
|
114351
|
-
|
|
114352
|
-
|
|
114353
|
-
|
|
114354
|
-
|
|
114355
|
-
|
|
114356
|
-
|
|
114357
|
-
|
|
114358
|
-
|
|
114359
|
-
|
|
114360
|
-
|
|
114361
|
-
|
|
114362
|
-
|
|
114363
|
-
|
|
114364
|
-
|
|
114365
|
-
|
|
114366
|
-
|
|
114367
|
-
|
|
114368
|
-
|
|
114369
|
-
|
|
114370
|
-
|
|
114371
|
-
...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
|
|
114372
|
-
};
|
|
114373
|
-
}
|
|
114374
|
-
describe = async () => this.hooks.mintId === void 0 ? this.hooks.description : {
|
|
114375
|
-
...this.hooks.description,
|
|
114376
|
-
mintsId: true
|
|
114377
|
-
};
|
|
114378
|
-
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
114379
|
-
listInstances = async () => {
|
|
114380
|
-
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
114381
|
-
};
|
|
114382
|
-
getInstance = async ({ id }) => {
|
|
114383
|
-
const record = await this.handle.get(id);
|
|
114384
|
-
return record === null ? null : this.viewOf(record);
|
|
114385
|
-
};
|
|
114386
|
-
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
114387
|
-
createInstance = async ({ id, name, kind, values }) => {
|
|
114388
|
-
const minted = id ?? this.hooks.mintId?.({
|
|
114389
|
-
name,
|
|
114390
|
-
...kind !== void 0 ? { kind } : {}
|
|
114391
|
-
});
|
|
114392
|
-
if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
|
|
114393
|
-
await this.handle.put({
|
|
114394
|
-
id: minted,
|
|
114395
|
-
data: this.hooks.initialBody(name, kind)
|
|
114396
|
-
}, { ifRev: 0 });
|
|
114397
|
-
const patch = this.patchOf(values ?? {});
|
|
114398
|
-
if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
|
|
114399
|
-
await this.hooks.onChanged?.(minted, "created");
|
|
114400
|
-
return { id: minted };
|
|
114401
|
-
};
|
|
114402
|
-
updateInstance = async ({ id, name, values }) => {
|
|
114403
|
-
const patch = this.patchOf(values);
|
|
114404
|
-
if (name !== void 0) patch[this.nameField] = name;
|
|
114405
|
-
await this.handle.patch(id, patch);
|
|
114406
|
-
await this.hooks.onChanged?.(id, "updated");
|
|
114407
|
-
return { ok: true };
|
|
114408
|
-
};
|
|
114409
|
-
/** The record patch a form `values` object means: secrets kept, cleared or replaced. */
|
|
114410
|
-
patchOf(values) {
|
|
114411
|
-
const patch = {};
|
|
114412
|
-
for (const [key, value] of Object.entries(values)) {
|
|
114413
|
-
if (value === void 0) continue;
|
|
114414
|
-
if (this.secretMaps.has(key)) {
|
|
114415
|
-
const entries = secretMapPatch(value);
|
|
114416
|
-
if (entries !== null) patch[key] = entries;
|
|
114417
|
-
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
114418
|
-
else if (isSecretClear(value)) patch[key] = null;
|
|
114419
|
-
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
114420
|
-
}
|
|
114421
|
-
return patch;
|
|
114422
|
-
}
|
|
114423
|
-
/** The switch lives in the record body; the addon is told so it applies it (D996). */
|
|
114424
|
-
setInstanceEnabled = async ({ id, enabled }) => {
|
|
114425
|
-
if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
|
|
114426
|
-
await this.handle.patch(id, { enabled });
|
|
114427
|
-
await this.hooks.onChanged?.(id, "enabled");
|
|
114428
|
-
return { ok: true };
|
|
114429
|
-
};
|
|
114430
|
-
/** The row and its keychain refs go together (the records door). */
|
|
114431
|
-
deleteInstance = async ({ id }) => {
|
|
114432
|
-
await this.handle.delete(id);
|
|
114433
|
-
await this.hooks.onChanged?.(id, "deleted");
|
|
114434
|
-
return { ok: true };
|
|
114435
|
-
};
|
|
114436
|
-
testInstance = async (input) => {
|
|
114437
|
-
if (this.hooks.test === void 0) return {
|
|
114438
|
-
success: false,
|
|
114439
|
-
status: "unsupported",
|
|
114440
|
-
error: "This integration declares no connection test"
|
|
114441
|
-
};
|
|
114442
|
-
return this.hooks.test(input);
|
|
114443
|
-
};
|
|
114444
|
-
/** The flat provider object to hand to `registerProvider`. */
|
|
114445
|
-
toProvider() {
|
|
114446
|
-
return {
|
|
114447
|
-
describe: this.describe,
|
|
114448
|
-
instanceFormSchema: this.instanceFormSchema,
|
|
114449
|
-
listInstances: this.listInstances,
|
|
114450
|
-
getInstance: this.getInstance,
|
|
114451
|
-
createInstance: this.createInstance,
|
|
114452
|
-
updateInstance: this.updateInstance,
|
|
114453
|
-
setInstanceEnabled: this.setInstanceEnabled,
|
|
114454
|
-
deleteInstance: this.deleteInstance,
|
|
114455
|
-
testInstance: this.testInstance
|
|
114456
|
-
};
|
|
114457
|
-
}
|
|
114458
|
-
};
|
|
115123
|
+
targetId: string().optional()
|
|
115124
|
+
}), array(DiscoveredTargetSchema), { auth: "admin" }), method(object({
|
|
115125
|
+
kind: string(),
|
|
115126
|
+
config: record(string(), unknown()),
|
|
115127
|
+
/** See `discoverTargets.targetId` — restore stored secrets for a blank password. */
|
|
115128
|
+
targetId: string().optional()
|
|
115129
|
+
}), ProbeTargetConfigResultSchema, {
|
|
115130
|
+
kind: "mutation",
|
|
115131
|
+
auth: "admin"
|
|
115132
|
+
}), method(object({
|
|
115133
|
+
targetId: string(),
|
|
115134
|
+
notification: NotificationSchema
|
|
115135
|
+
}), SendResultSchema, {
|
|
115136
|
+
kind: "mutation",
|
|
115137
|
+
auth: "admin"
|
|
115138
|
+
}), method(object({
|
|
115139
|
+
targetId: string(),
|
|
115140
|
+
sample: NotificationSchema.optional()
|
|
115141
|
+
}), TestResultSchema, {
|
|
115142
|
+
kind: "mutation",
|
|
115143
|
+
auth: "admin"
|
|
115144
|
+
}), method(object({
|
|
115145
|
+
target: TargetSchema,
|
|
115146
|
+
/**
|
|
115147
|
+
* Duplicate flow: create a NEW target id while copying secrets from an
|
|
115148
|
+
* existing row. The UI never holds the stored token; blank / redacted
|
|
115149
|
+
* password fields are restored from this source (D634 still applies if
|
|
115150
|
+
* destinations diverge without a re-typed secret).
|
|
115151
|
+
*/
|
|
115152
|
+
cloneSecretsFrom: string().optional()
|
|
115153
|
+
}), TargetSchema, {
|
|
115154
|
+
kind: "mutation",
|
|
115155
|
+
auth: "admin"
|
|
115156
|
+
}), method(object({ targetId: string() }), _void(), {
|
|
115157
|
+
kind: "mutation",
|
|
115158
|
+
auth: "admin"
|
|
115159
|
+
}), method(object({
|
|
115160
|
+
targetId: string(),
|
|
115161
|
+
enabled: boolean()
|
|
115162
|
+
}), _void(), {
|
|
115163
|
+
kind: "mutation",
|
|
115164
|
+
auth: "admin"
|
|
115165
|
+
});
|
|
115166
|
+
looseObject({
|
|
115167
|
+
name: string().min(1),
|
|
115168
|
+
enabled: boolean().optional()
|
|
115169
|
+
});
|
|
115170
|
+
TargetSchema.omit({ id: true });
|
|
114459
115171
|
var EncodeProfileSchema = object({
|
|
114460
115172
|
video: object({
|
|
114461
115173
|
codec: _enum([
|
|
@@ -121520,31 +122232,21 @@ var APPLIANCE_CAP_VOCABULARY = {
|
|
|
121520
122232
|
"pet-fountain": {
|
|
121521
122233
|
scope: "device",
|
|
121522
122234
|
noun: t("Pet fountain", "Fontana per animali"),
|
|
121523
|
-
actions: [
|
|
121524
|
-
|
|
121525
|
-
|
|
121526
|
-
|
|
121527
|
-
|
|
121528
|
-
|
|
121529
|
-
|
|
121530
|
-
|
|
121531
|
-
|
|
121532
|
-
|
|
121533
|
-
|
|
121534
|
-
|
|
121535
|
-
|
|
121536
|
-
|
|
121537
|
-
|
|
121538
|
-
args: { on: false }
|
|
121539
|
-
},
|
|
121540
|
-
{
|
|
121541
|
-
id: "petFountain.resetDailyConsumption",
|
|
121542
|
-
method: "resetDailyConsumption",
|
|
121543
|
-
label: t("Clear daily consumption", "Azzera il consumo giornaliero"),
|
|
121544
|
-
phrase: t("Clear the daily water consumption of {device}", "Azzera il consumo giornaliero di acqua di {device}"),
|
|
121545
|
-
icon: "rotate-ccw"
|
|
121546
|
-
}
|
|
121547
|
-
],
|
|
122235
|
+
actions: [{
|
|
122236
|
+
id: "petFountain.pumpOn",
|
|
122237
|
+
method: "setPump",
|
|
122238
|
+
label: t("Pump on", "Pompa accesa"),
|
|
122239
|
+
phrase: t("Start the pump of {device}", "Avvia la pompa di {device}"),
|
|
122240
|
+
icon: "play",
|
|
122241
|
+
args: { on: true }
|
|
122242
|
+
}, {
|
|
122243
|
+
id: "petFountain.pumpOff",
|
|
122244
|
+
method: "setPump",
|
|
122245
|
+
label: t("Pump off", "Pompa spenta"),
|
|
122246
|
+
phrase: t("Stop the pump of {device}", "Ferma la pompa di {device}"),
|
|
122247
|
+
icon: "square",
|
|
122248
|
+
args: { on: false }
|
|
122249
|
+
}],
|
|
121548
122250
|
state: [{
|
|
121549
122251
|
kind: "boolean",
|
|
121550
122252
|
field: "empty",
|
|
@@ -123563,7 +124265,6 @@ var SYSTEM_CAP_VOCABULARY = {
|
|
|
123563
124265
|
"calendar-source": system(INTERNAL),
|
|
123564
124266
|
calendars: system("calendars feed schedules and conditions, not device actions"),
|
|
123565
124267
|
composer: system("device composition — an authoring tool, not an action"),
|
|
123566
|
-
"connection-test": system(INTERNAL),
|
|
123567
124268
|
"core-blocks": system(INTERNAL),
|
|
123568
124269
|
"custom-model-registry": system(ML),
|
|
123569
124270
|
"data-store-provider": system(INTERNAL),
|
|
@@ -145322,637 +146023,223 @@ var AutomationStepTraceSchema = object({
|
|
|
145322
146023
|
kind: string().min(1),
|
|
145323
146024
|
cap: string().optional(),
|
|
145324
146025
|
method: string().optional(),
|
|
145325
|
-
/** The vocabulary action the step performs (`cover.open`), when it names one. */
|
|
145326
|
-
actionId: string().optional(),
|
|
145327
|
-
deviceId: number().int().optional(),
|
|
145328
|
-
/** What happened per device, when the step drove several (or a domain). */
|
|
145329
|
-
devices: array(StepDeviceTraceSchema).optional(),
|
|
145330
|
-
startedAt: number().optional(),
|
|
145331
|
-
endedAt: number().optional(),
|
|
145332
|
-
/**
|
|
145333
|
-
* The parameters the step SENT, after `{{vars.x}}` substitution — what the
|
|
145334
|
-
* device was actually asked. Bounded like trigger `vars`; a secret parameter
|
|
145335
|
-
* is shown as {@link REDACTED_ARG}. Absent on traces written before it existed.
|
|
145336
|
-
*/
|
|
145337
|
-
args: record(string(), TraceValueSchema).optional(),
|
|
145338
|
-
/** `empty`: the target resolved to no device, so nothing was done — never silently `ok`. */
|
|
145339
|
-
outcome: _enum([
|
|
145340
|
-
"ok",
|
|
145341
|
-
"error",
|
|
145342
|
-
"not-run",
|
|
145343
|
-
"empty"
|
|
145344
|
-
]),
|
|
145345
|
-
message: string().optional()
|
|
145346
|
-
});
|
|
145347
|
-
var AutomationRunTraceSchema = object({
|
|
145348
|
-
runId: string().min(1),
|
|
145349
|
-
startedAt: number(),
|
|
145350
|
-
endedAt: number(),
|
|
145351
|
-
trigger: AutomationTriggerTraceSchema,
|
|
145352
|
-
conditions: array(AutomationConditionTraceNodeSchema),
|
|
145353
|
-
verdict: AutomationRunVerdictSchema.optional(),
|
|
145354
|
-
steps: array(AutomationStepTraceSchema),
|
|
145355
|
-
outcome: AutomationRunOutcomeSchema,
|
|
145356
|
-
/** How many identical consecutive skips this trace stands for (>= 1). */
|
|
145357
|
-
repeat: number().int().min(1),
|
|
145358
|
-
/** When the latest of those repeats happened. */
|
|
145359
|
-
lastAt: number(),
|
|
145360
|
-
/**
|
|
145361
|
-
* A scheduler point's own outcome (D983). `outcome` carries the closest
|
|
145362
|
-
* automation outcome so a reader that does not know schedulers still reads
|
|
145363
|
-
* the trace; this field says exactly what happened.
|
|
145364
|
-
*/
|
|
145365
|
-
scheduler: SchedulerOutcomeSchema.optional()
|
|
145366
|
-
});
|
|
145367
|
-
/**
|
|
145368
|
-
* What the hub's `runs` ledger holds for one owner (`automation:<blockId>` or
|
|
145369
|
-
* `action:<actionId>`): the cooldown stamp and the trace ring.
|
|
145370
|
-
*/
|
|
145371
|
-
var AutomationStateDocSchema = object({
|
|
145372
|
-
version: literal(1),
|
|
145373
|
-
lastRunStartedAt: number().nullable(),
|
|
145374
|
-
traces: array(AutomationRunTraceSchema)
|
|
145375
|
-
});
|
|
145376
|
-
/**
|
|
145377
|
-
* Actions — named, runnable things an operator (or an automation) can start,
|
|
145378
|
-
* declared as LIST ENTRIES, never as devices.
|
|
145379
|
-
*
|
|
145380
|
-
* An entry is either **internal** (a short list of cap/wait steps kept in the
|
|
145381
|
-
* hub's `actions` record kind) or declared by an addon through the
|
|
145382
|
-
* `action-source` collection (a Home Assistant script, a scene …). The one
|
|
145383
|
-
* surface the UI and automations talk to is the `actions` cap; it keeps no
|
|
145384
|
-
* catalog of its own (D3) — every `list` asks the providers live.
|
|
145385
|
-
*
|
|
145386
|
-
* This file is the data half: the entry schema, the variables an entry may
|
|
145387
|
-
* declare, and the pure resolution of the values a run was given. It holds no
|
|
145388
|
-
* runtime.
|
|
145389
|
-
*/
|
|
145390
|
-
/** What a variable's value is. `select` takes one of `options`. */
|
|
145391
|
-
var ActionVariableTypeSchema = _enum([
|
|
145392
|
-
"string",
|
|
145393
|
-
"number",
|
|
145394
|
-
"boolean",
|
|
145395
|
-
"select"
|
|
145396
|
-
]);
|
|
145397
|
-
var ACTION_VARIABLE_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
145398
|
-
var ActionVariableValueSchema = union([
|
|
145399
|
-
string(),
|
|
145400
|
-
number(),
|
|
145401
|
-
boolean()
|
|
145402
|
-
]);
|
|
145403
|
-
/**
|
|
145404
|
-
* One declared variable. Steps reference it as `{ $var: 'name' }` (the whole
|
|
145405
|
-
* value) or `{{vars.name}}` (inside a string) in their args.
|
|
145406
|
-
*/
|
|
145407
|
-
var ActionVariableSchema = object({
|
|
145408
|
-
name: string().regex(ACTION_VARIABLE_NAME_RE),
|
|
145409
|
-
label: string().min(1).max(120).optional(),
|
|
145410
|
-
type: ActionVariableTypeSchema,
|
|
145411
|
-
required: boolean().optional(),
|
|
145412
|
-
default: ActionVariableValueSchema.optional(),
|
|
145413
|
-
/** The allowed values of a `select`. */
|
|
145414
|
-
options: array(string().min(1)).min(1).optional()
|
|
145415
|
-
}).superRefine((v, ctx) => {
|
|
145416
|
-
if (v.type === "select" && v.options === void 0) ctx.addIssue({
|
|
145417
|
-
code: "custom",
|
|
145418
|
-
message: "a select variable needs options",
|
|
145419
|
-
path: ["options"]
|
|
145420
|
-
});
|
|
145421
|
-
if (v.default !== void 0 && variableValueError(v, v.default) !== null) ctx.addIssue({
|
|
145422
|
-
code: "custom",
|
|
145423
|
-
message: variableValueError(v, v.default) ?? "invalid default",
|
|
145424
|
-
path: ["default"]
|
|
145425
|
-
});
|
|
145426
|
-
});
|
|
145427
|
-
/** Why `value` is not a legal value for the variable, or null when it is. */
|
|
145428
|
-
function variableValueError(variable, value) {
|
|
145429
|
-
switch (variable.type) {
|
|
145430
|
-
case "string": return typeof value === "string" ? null : `variable "${variable.name}" must be a string`;
|
|
145431
|
-
case "number": return typeof value === "number" && Number.isFinite(value) ? null : `variable "${variable.name}" must be a number`;
|
|
145432
|
-
case "boolean": return typeof value === "boolean" ? null : `variable "${variable.name}" must be true or false`;
|
|
145433
|
-
case "select": return typeof value === "string" && (variable.options ?? []).includes(value) ? null : `variable "${variable.name}" must be one of ${(variable.options ?? []).join(", ")}`;
|
|
145434
|
-
}
|
|
145435
|
-
}
|
|
145436
|
-
var ActionSourceKindSchema = _enum(["internal", "addon"]);
|
|
145437
|
-
function isInternalActionId(actionId) {
|
|
145438
|
-
return actionId.startsWith("internal:") && actionId.length > 9;
|
|
145439
|
-
}
|
|
145440
|
-
/** The addon behind a `<addonId>:<localId>` id, or null for anything else (internal included). */
|
|
145441
|
-
function addonIdOfActionId(actionId) {
|
|
145442
|
-
if (isInternalActionId(actionId)) return null;
|
|
145443
|
-
const at = actionId.indexOf(":");
|
|
145444
|
-
return at > 0 && at < actionId.length - 1 ? actionId.slice(0, at) : null;
|
|
145445
|
-
}
|
|
145446
|
-
var ActionStatusSchema = object({
|
|
145447
|
-
isRunning: boolean(),
|
|
145448
|
-
/** Ms epoch the latest run STARTED; null when it never ran. */
|
|
145449
|
-
lastRunAt: number().nullable(),
|
|
145450
|
-
/** The latest run's failure; null on success or when it never ran. */
|
|
145451
|
-
lastError: string().nullable()
|
|
145452
|
-
});
|
|
145453
|
-
var ActionEntrySchema = object({
|
|
145454
|
-
/** `internal:<uuid>` or `<addonId>:<localId>`. */
|
|
145455
|
-
id: string().min(3),
|
|
145456
|
-
name: string().min(1).max(120),
|
|
145457
|
-
/** The addon that declared it; `core-blocks` for an internal one. */
|
|
145458
|
-
addonId: string().min(1),
|
|
145459
|
-
source: ActionSourceKindSchema,
|
|
145460
|
-
/** An addon-declared entry is edited where it was declared. */
|
|
145461
|
-
readOnly: boolean(),
|
|
145462
|
-
/** Internal only: cap and wait steps. No action-in-action, so no cycles. */
|
|
145463
|
-
steps: array(ActionStepSchema).min(1).max(50).optional(),
|
|
145464
|
-
variables: array(ActionVariableSchema).max(20).optional(),
|
|
145465
|
-
status: ActionStatusSchema
|
|
145466
|
-
}).superRefine((entry, ctx) => {
|
|
145467
|
-
if (entry.source === "internal") {
|
|
145468
|
-
if (!isInternalActionId(entry.id)) ctx.addIssue({
|
|
145469
|
-
code: "custom",
|
|
145470
|
-
message: "an internal action id is internal:<uuid>",
|
|
145471
|
-
path: ["id"]
|
|
145472
|
-
});
|
|
145473
|
-
return;
|
|
145474
|
-
}
|
|
145475
|
-
if (entry.steps !== void 0) ctx.addIssue({
|
|
145476
|
-
code: "custom",
|
|
145477
|
-
message: "only an internal action carries steps",
|
|
145478
|
-
path: ["steps"]
|
|
145479
|
-
});
|
|
145480
|
-
if (!entry.readOnly) ctx.addIssue({
|
|
145481
|
-
code: "custom",
|
|
145482
|
-
message: "an addon action is read-only here",
|
|
145483
|
-
path: ["readOnly"]
|
|
145484
|
-
});
|
|
145485
|
-
if (addonIdOfActionId(entry.id) === null) ctx.addIssue({
|
|
145486
|
-
code: "custom",
|
|
145487
|
-
message: "an addon action id is <addonId>:<localId>",
|
|
145488
|
-
path: ["id"]
|
|
145489
|
-
});
|
|
145490
|
-
});
|
|
145491
|
-
/** What an operator writes for an internal action. */
|
|
145492
|
-
var ActionInputSchema = object({
|
|
145493
|
-
name: string().min(1).max(120),
|
|
145494
|
-
steps: array(ActionStepSchema).min(1).max(50),
|
|
145495
|
-
variables: array(ActionVariableSchema).max(20).optional()
|
|
145496
|
-
});
|
|
145497
|
-
/** Who started a run. Absent = the operator pressed it. */
|
|
145498
|
-
var ActionRunOriginSchema = object({
|
|
145499
|
-
/** The automation block whose step started it. */
|
|
145500
|
-
blockId: string().min(1).optional() });
|
|
145501
|
-
/** `started` = the caller did not ask to wait. */
|
|
145502
|
-
var ActionRunOutcomeSchema = union([AutomationRunOutcomeSchema, literal("started")]);
|
|
145503
|
-
var ActionRunResultSchema = object({
|
|
145504
|
-
runId: string().min(1),
|
|
145505
|
-
outcome: ActionRunOutcomeSchema,
|
|
145506
|
-
/** Why it did not run, or what failed. */
|
|
145507
|
-
message: string().optional()
|
|
145508
|
-
});
|
|
145509
|
-
_enum([
|
|
145510
|
-
"not-found",
|
|
145511
|
-
"read-only",
|
|
145512
|
-
"invalid-variables",
|
|
145513
|
-
"invalid-steps",
|
|
145514
|
-
"not-linked",
|
|
145515
|
-
"busy"
|
|
145516
|
-
]);
|
|
145517
|
-
object({
|
|
145518
|
-
actionId: string(),
|
|
145519
|
-
runId: string(),
|
|
145520
|
-
isRunning: boolean(),
|
|
145521
|
-
/** Set when the run ended. */
|
|
145522
|
-
outcome: AutomationRunOutcomeSchema.optional(),
|
|
145523
|
-
lastRunAt: number().nullable(),
|
|
145524
|
-
lastError: string().nullable()
|
|
145525
|
-
});
|
|
145526
|
-
/** A bare number accepted as a base unit — the save succeeded, say so. */
|
|
145527
|
-
var UnitWarningSchema = object({
|
|
145528
|
-
/** Where in the saved record, e.g. `conditions.children.0` or `steps.2.args.grams`. */
|
|
145529
|
-
path: string(),
|
|
145530
|
-
deviceId: number().int().optional(),
|
|
145531
|
-
field: string(),
|
|
145532
|
-
value: number(),
|
|
145533
|
-
assumedUnit: string(),
|
|
145534
|
-
message: string()
|
|
145535
|
-
});
|
|
145536
|
-
/**
|
|
145537
|
-
* notification-output — canonical, capability-gated notification delivery.
|
|
145538
|
-
*
|
|
145539
|
-
* Apprise-derived model (see
|
|
145540
|
-
* `docs/superpowers/specs/2026-07-03-notification-output-notifier-matrix.md`):
|
|
145541
|
-
* callers emit ONE canonical `Notification`; each provider declares a
|
|
145542
|
-
* per-kind capability descriptor (`TargetKind`), and the pure degrade
|
|
145543
|
-
* engine (`@camstack/types` `prepareNotification`) transcodes / degrades the
|
|
145544
|
-
* message to what the kind supports — callers never special-case a service.
|
|
145545
|
-
*
|
|
145546
|
-
* DESIGN DECISIONS (locked):
|
|
145547
|
-
* - Target CRUD lives on THIS cap (`upsertTarget` / `deleteTarget` /
|
|
145548
|
-
* `setTargetEnabled`), each provider persisting via the `settings-store`
|
|
145549
|
-
* cap. Rationale: the admin UI needs one uniform surface across the
|
|
145550
|
-
* notifiers addon AND the HA addon; the addon-`globalSettingsSchema`-array
|
|
145551
|
-
* alternative would fork the UI per addon and cannot host the
|
|
145552
|
-
* discovery→adopt flow.
|
|
145553
|
-
* - `listTargetKinds` / `listTargets` / `discoverTargets` return arrays →
|
|
145554
|
-
* the generated cap-mount auto-`concatCollection`-fans them across every
|
|
145555
|
-
* registered provider (notifiers addon + HA addon) so one catalog is
|
|
145556
|
-
* routable. `send` / `testTarget` / CRUD route to ONE provider by the
|
|
145557
|
-
* `addonId` the generated collection router extracts from the call input.
|
|
145558
|
-
* - `Attachment.bytes` is `Uint8Array`. Transport-safe: superjson (the tRPC
|
|
145559
|
-
* transformer) + UDS MsgPack both round-trip typed arrays — already used by
|
|
145560
|
-
* `storage` / `storage-provider` / `recording` caps over the same path. No
|
|
145561
|
-
* base64 fallback needed.
|
|
145562
|
-
*
|
|
145563
|
-
* TODO (deferred, closed-set change — separate decision): add
|
|
145564
|
-
* `providerKind: 'notify'` so notification providers surface on the unified
|
|
145565
|
-
* admin "Integrations" page.
|
|
145566
|
-
*/
|
|
145567
|
-
/**
|
|
145568
|
-
* Zentik-derived typed-media enum — the superset across every kind. Each
|
|
145569
|
-
* adapter picks what it supports and the degrade engine filters the rest.
|
|
145570
|
-
*/
|
|
145571
|
-
var AttachmentMediaTypeSchema = _enum([
|
|
145572
|
-
"image",
|
|
145573
|
-
"video",
|
|
145574
|
-
"gif",
|
|
145575
|
-
"audio",
|
|
145576
|
-
"icon"
|
|
145577
|
-
]);
|
|
145578
|
-
/**
|
|
145579
|
-
* A single attachment. Exactly one of `url` (remote source, most adapters
|
|
145580
|
-
* prefer this) or `bytes` (inline source; required for Pushover-style
|
|
145581
|
-
* bytes-only kinds) MUST be present — the degrade engine expresses a
|
|
145582
|
-
* url→bytes fetch as a `needsFetch` directive the adapter executes.
|
|
145583
|
-
*/
|
|
145584
|
-
var AttachmentSchema = object({
|
|
145585
|
-
mediaType: AttachmentMediaTypeSchema,
|
|
145586
|
-
url: string().optional(),
|
|
145587
|
-
bytes: _instanceof(Uint8Array).optional(),
|
|
145588
|
-
mime: string().optional(),
|
|
145589
|
-
name: string().optional()
|
|
145590
|
-
}).refine((a) => a.url !== void 0 || a.bytes !== void 0, { message: "Attachment requires either `url` or `bytes`" });
|
|
145591
|
-
var NotificationFormatSchema = _enum([
|
|
145592
|
-
"text",
|
|
145593
|
-
"markdown",
|
|
145594
|
-
"html"
|
|
145595
|
-
]);
|
|
145596
|
-
/**
|
|
145597
|
-
* The CLOSED icon vocabulary an action button may use.
|
|
145598
|
-
*
|
|
145599
|
-
* A closed set, not a free string, and that is the whole point: an arbitrary
|
|
145600
|
-
* icon name is one that ntfy renders, zentik silently drops, and nobody
|
|
145601
|
-
* notices — the same class of gap as a zone vocabulary nothing produced
|
|
145602
|
-
* ([D35](../../../docs/decisions/adr-0035.md)). Every adapter maps this set or
|
|
145603
|
-
* declares `actionIcons: false` and the degrade engine strips the field.
|
|
145604
|
-
*
|
|
145605
|
-
* Named by INTENT, never by glyph. "check" would tie the vocabulary to one
|
|
145606
|
-
* renderer's icon set; "acknowledge" survives an adapter that draws it
|
|
145607
|
-
* differently.
|
|
145608
|
-
*
|
|
145609
|
-
* ── A TOKEN IS NOT A WIRE VALUE ─────────────────────────────────────
|
|
145610
|
-
*
|
|
145611
|
-
* These names are for US. **No adapter may forward one verbatim.** Each maps
|
|
145612
|
-
* the whole set onto its own renderer's vocabulary through a
|
|
145613
|
-
* `Record<NotificationActionIcon, string>` — a Record, never a lookup with a
|
|
145614
|
-
* fallback, so adding a member here fails every adapter's build until someone
|
|
145615
|
-
* decides its glyph, which is the only place that decision can be made
|
|
145616
|
-
* honestly.
|
|
145617
|
-
*
|
|
145618
|
-
* This paragraph is the bug. Zentik declared `actionIcons: true` and passed
|
|
145619
|
-
* `disarm` straight through; iOS feeds that string to
|
|
145620
|
-
* `UNNotificationActionIcon(systemImageName:)`, `disarm` is not an SF Symbol,
|
|
145621
|
-
* and every snooze and alarm button arrived BLANK. A pass-through is not a
|
|
145622
|
-
* mapping, and "the field is documented" is not "the value renders".
|
|
145623
|
-
*
|
|
145624
|
-
* Adding a member is TRAIN-BOUND. The enum lives in the published
|
|
145625
|
-
* `@camstack/server` closure and the cap seam validates against the HUB's copy,
|
|
145626
|
-
* so an addon that emits a token the running hub does not know does not lose an
|
|
145627
|
-
* icon — its whole `send` fails Zod validation and the notification never
|
|
145628
|
-
* arrives. Never emit a new token from an addon before the train carrying it.
|
|
145629
|
-
*/
|
|
145630
|
-
var NotificationActionIconSchema = _enum([
|
|
145631
|
-
"acknowledge",
|
|
145632
|
-
"dismiss",
|
|
145633
|
-
"silence",
|
|
145634
|
-
"snooze",
|
|
145635
|
-
"view",
|
|
145636
|
-
"play",
|
|
145637
|
-
"open",
|
|
145638
|
-
"close",
|
|
145639
|
-
"lock",
|
|
145640
|
-
"unlock",
|
|
145641
|
-
"arm",
|
|
145642
|
-
"arm-home",
|
|
145643
|
-
"arm-away",
|
|
145644
|
-
"arm-night",
|
|
145645
|
-
"disarm",
|
|
145646
|
-
"light",
|
|
145647
|
-
"alert",
|
|
145648
|
-
"camera"
|
|
145649
|
-
]);
|
|
145650
|
-
/** A single tap-through action button. */
|
|
145651
|
-
var NotificationActionSchema = object({
|
|
145652
|
-
id: string(),
|
|
145653
|
-
label: string(),
|
|
145654
|
-
url: string().optional(),
|
|
145655
|
-
/** Dropped by the degrade engine for a kind with `caps.actionIcons: false`. */
|
|
145656
|
-
icon: NotificationActionIconSchema.optional(),
|
|
145657
|
-
/**
|
|
145658
|
-
* Renders in a warning style where the notifier supports it.
|
|
145659
|
-
*
|
|
145660
|
-
* A HINT, never a gate. The callback's authority is its token and nothing
|
|
145661
|
-
* else — see `notification-center/action-token.ts` for what that does and
|
|
145662
|
-
* does not buy.
|
|
145663
|
-
*/
|
|
145664
|
-
destructive: boolean().optional(),
|
|
145665
|
-
/**
|
|
145666
|
-
* How the tap should REACH the url.
|
|
145667
|
-
*
|
|
145668
|
-
* `navigate` (absent, and every button authored before this field) opens it:
|
|
145669
|
-
* the phone leaves the notification and shows whatever the callback returns.
|
|
145670
|
-
* That is right for a button whose answer the operator wants to read.
|
|
145671
|
-
*
|
|
145672
|
-
* `background` fires it as a POST and stays put. It exists for the buttons
|
|
145673
|
-
* whose whole point is not to interrupt — "silence this for 30 minutes" is
|
|
145674
|
-
* an answer to the notification, and being thrown into a browser tab to
|
|
145675
|
-
* confirm it costs more attention than the notification did. A backend that
|
|
145676
|
-
* cannot do a background call renders it as an ordinary link (the adapters
|
|
145677
|
-
* fall back rather than dropping the button), so this is a preference, never
|
|
145678
|
-
* a requirement.
|
|
145679
|
-
*/
|
|
145680
|
-
mode: _enum(["navigate", "background"]).optional()
|
|
145681
|
-
});
|
|
145682
|
-
/** A delivery parameter value: what a notifier declared it takes. */
|
|
145683
|
-
var DeliveryParamValueSchema = union([
|
|
145684
|
-
string(),
|
|
145685
|
-
number(),
|
|
145686
|
-
boolean()
|
|
145687
|
-
]);
|
|
145688
|
-
/**
|
|
145689
|
-
* One extra delivery parameter a notifier KIND declares (D938). A rule that
|
|
145690
|
-
* addresses a target of that kind may set it; a kind that declares nothing is
|
|
145691
|
-
* never handed one. The admin UI derives its control from this descriptor —
|
|
145692
|
-
* no editor knows a service by name.
|
|
145693
|
-
*
|
|
145694
|
-
* Optional fields are `.optional()`, never `.default()` (a Zod default does not
|
|
145695
|
-
* run on the addon cap path).
|
|
145696
|
-
*/
|
|
145697
|
-
var DeliveryParamSchema = object({
|
|
145698
|
-
key: string().min(1),
|
|
145699
|
-
label: string(),
|
|
145700
|
-
/** i18n key of the label, resolved by the declaring addon's namespace. */
|
|
145701
|
-
labelKey: string().optional(),
|
|
145702
|
-
type: _enum([
|
|
145703
|
-
"enum",
|
|
145704
|
-
"number",
|
|
145705
|
-
"boolean",
|
|
145706
|
-
"string"
|
|
145707
|
-
]),
|
|
145708
|
-
/** `enum` only: the closed set of accepted values. */
|
|
145709
|
-
options: array(object({
|
|
145710
|
-
value: string(),
|
|
145711
|
-
label: string()
|
|
145712
|
-
})).optional(),
|
|
145713
|
-
/** `number` only. */
|
|
145714
|
-
min: number().optional(),
|
|
145715
|
-
max: number().optional(),
|
|
145716
|
-
/** What the notifier does when the rule sets nothing; shown as the placeholder. */
|
|
145717
|
-
default: DeliveryParamValueSchema.optional()
|
|
145718
|
-
});
|
|
145719
|
-
/**
|
|
145720
|
-
* The canonical notification. `body` is the only hard field (Apprise model).
|
|
145721
|
-
* `priority` is a 5-level ORDINAL (1=lowest … 3=normal(default) … 5=urgent),
|
|
145722
|
-
* NOT a fixed severity enum — each kind declares its own `caps.levels` and
|
|
145723
|
-
* the adapter maps this ordinal onto its native level. `level?` is an
|
|
145724
|
-
* optional kind-native level id (`emergency`, `silent`, …) that overrides
|
|
145725
|
-
* `priority` for that one target.
|
|
145726
|
-
*/
|
|
145727
|
-
var NotificationSchema = object({
|
|
145728
|
-
body: string(),
|
|
145729
|
-
title: string().optional(),
|
|
145730
|
-
format: NotificationFormatSchema.default("text"),
|
|
145731
|
-
priority: number().int().min(1).max(5).default(3),
|
|
145732
|
-
level: string().optional(),
|
|
145733
|
-
attachments: array(AttachmentSchema).optional(),
|
|
145734
|
-
clickUrl: string().optional(),
|
|
145735
|
-
actions: array(NotificationActionSchema).optional(),
|
|
145736
|
-
sound: string().optional(),
|
|
145737
|
-
ttl: number().optional(),
|
|
145738
|
-
tag: string().optional(),
|
|
145739
|
-
deviceId: number().optional(),
|
|
145740
|
-
eventId: string().optional(),
|
|
145741
|
-
metadata: record(string(), unknown()).optional(),
|
|
146026
|
+
/** The vocabulary action the step performs (`cover.open`), when it names one. */
|
|
146027
|
+
actionId: string().optional(),
|
|
146028
|
+
deviceId: number().int().optional(),
|
|
146029
|
+
/** What happened per device, when the step drove several (or a domain). */
|
|
146030
|
+
devices: array(StepDeviceTraceSchema).optional(),
|
|
146031
|
+
startedAt: number().optional(),
|
|
146032
|
+
endedAt: number().optional(),
|
|
145742
146033
|
/**
|
|
145743
|
-
*
|
|
145744
|
-
*
|
|
145745
|
-
*
|
|
146034
|
+
* The parameters the step SENT, after `{{vars.x}}` substitution — what the
|
|
146035
|
+
* device was actually asked. Bounded like trigger `vars`; a secret parameter
|
|
146036
|
+
* is shown as {@link REDACTED_ARG}. Absent on traces written before it existed.
|
|
145746
146037
|
*/
|
|
145747
|
-
|
|
145748
|
-
|
|
145749
|
-
|
|
145750
|
-
|
|
145751
|
-
|
|
145752
|
-
|
|
145753
|
-
|
|
145754
|
-
|
|
145755
|
-
|
|
145756
|
-
critical: boolean().optional(),
|
|
145757
|
-
silent: boolean().optional(),
|
|
145758
|
-
noPush: boolean().optional()
|
|
145759
|
-
}).optional(),
|
|
145760
|
-
/** e.g. Pushover `emergency` requires `retry` / `expire`. */
|
|
145761
|
-
requires: array(string()).optional(),
|
|
145762
|
-
description: string().optional()
|
|
146038
|
+
args: record(string(), TraceValueSchema).optional(),
|
|
146039
|
+
/** `empty`: the target resolved to no device, so nothing was done — never silently `ok`. */
|
|
146040
|
+
outcome: _enum([
|
|
146041
|
+
"ok",
|
|
146042
|
+
"error",
|
|
146043
|
+
"not-run",
|
|
146044
|
+
"empty"
|
|
146045
|
+
]),
|
|
146046
|
+
message: string().optional()
|
|
145763
146047
|
});
|
|
145764
|
-
|
|
145765
|
-
|
|
145766
|
-
|
|
145767
|
-
|
|
145768
|
-
|
|
145769
|
-
|
|
145770
|
-
|
|
145771
|
-
|
|
145772
|
-
|
|
145773
|
-
|
|
145774
|
-
|
|
145775
|
-
|
|
145776
|
-
|
|
145777
|
-
actions: number().int().nonnegative(),
|
|
146048
|
+
var AutomationRunTraceSchema = object({
|
|
146049
|
+
runId: string().min(1),
|
|
146050
|
+
startedAt: number(),
|
|
146051
|
+
endedAt: number(),
|
|
146052
|
+
trigger: AutomationTriggerTraceSchema,
|
|
146053
|
+
conditions: array(AutomationConditionTraceNodeSchema),
|
|
146054
|
+
verdict: AutomationRunVerdictSchema.optional(),
|
|
146055
|
+
steps: array(AutomationStepTraceSchema),
|
|
146056
|
+
outcome: AutomationRunOutcomeSchema,
|
|
146057
|
+
/** How many identical consecutive skips this trace stands for (>= 1). */
|
|
146058
|
+
repeat: number().int().min(1),
|
|
146059
|
+
/** When the latest of those repeats happened. */
|
|
146060
|
+
lastAt: number(),
|
|
145778
146061
|
/**
|
|
145779
|
-
*
|
|
145780
|
-
*
|
|
145781
|
-
*
|
|
145782
|
-
* run on the addon cap path — three production failures in one day taught
|
|
145783
|
-
* this repo that once. Absent is read as false by the degrade engine, which
|
|
145784
|
-
* is the safe direction: an icon that is not rendered costs nothing, an icon
|
|
145785
|
-
* assumed and dropped costs the operator's trust in the field.
|
|
146062
|
+
* A scheduler point's own outcome (D983). `outcome` carries the closest
|
|
146063
|
+
* automation outcome so a reader that does not know schedulers still reads
|
|
146064
|
+
* the trace; this field says exactly what happened.
|
|
145786
146065
|
*/
|
|
145787
|
-
|
|
145788
|
-
levels: array(TargetKindLevelSchema),
|
|
145789
|
-
format: array(NotificationFormatSchema),
|
|
145790
|
-
clickUrl: boolean(),
|
|
145791
|
-
sound: boolean(),
|
|
145792
|
-
ttl: boolean(),
|
|
145793
|
-
bodyMaxLen: number().int().positive()
|
|
146066
|
+
scheduler: SchedulerOutcomeSchema.optional()
|
|
145794
146067
|
});
|
|
145795
146068
|
/**
|
|
145796
|
-
*
|
|
145797
|
-
*
|
|
145798
|
-
* `device-provider.getChildCreationSchema` `CreationSchemaOutputSchema`) —
|
|
145799
|
-
* the union is large and not meant for runtime validation here; the exported
|
|
145800
|
-
* `TargetKind` type re-tightens `configSchema` to `ConfigUISchema`.
|
|
146069
|
+
* What the hub's `runs` ledger holds for one owner (`automation:<blockId>` or
|
|
146070
|
+
* `action:<actionId>`): the cooldown stamp and the trace ring.
|
|
145801
146071
|
*/
|
|
145802
|
-
var
|
|
145803
|
-
|
|
145804
|
-
|
|
145805
|
-
|
|
145806
|
-
icon: string(),
|
|
145807
|
-
/** Stamped by each provider so the concat-fanned catalog stays routable. */
|
|
145808
|
-
addonId: string(),
|
|
145809
|
-
/**
|
|
145810
|
-
* URL of the kind's bundled BRAND icon, served by the providing addon over
|
|
145811
|
-
* its own `addon-routes` surface (`/addon/<addonId>/icons/<kind>`). Absent
|
|
145812
|
-
* when the addon bundles no icon for that kind — the client then falls back
|
|
145813
|
-
* to a neutral glyph rather than rendering the raw `icon` NAME as text.
|
|
145814
|
-
*
|
|
145815
|
-
* Root-relative on purpose: it resolves against whatever origin serves a web
|
|
145816
|
-
* client, and a native client joins it onto its own hub base.
|
|
145817
|
-
*
|
|
145818
|
-
* DECLARED here deliberately. It used to travel as an undeclared passthrough
|
|
145819
|
-
* field that survived only because the runtime cap-router forwards provider
|
|
145820
|
-
* output verbatim — so every consumer had to re-declare it by hand to stop
|
|
145821
|
-
* its own Zod parse from stripping it, and the whole arrangement would have
|
|
145822
|
-
* broken silently the moment output validation was tightened anywhere.
|
|
145823
|
-
*/
|
|
145824
|
-
iconUrl: string().optional(),
|
|
145825
|
-
/**
|
|
145826
|
-
* Media type of {@link iconUrl} (`image/svg+xml`, `image/png`, …).
|
|
145827
|
-
*
|
|
145828
|
-
* The server knows this and therefore says it, because the client cannot
|
|
145829
|
-
* safely guess: a React-Native client renders SVG and raster through two
|
|
145830
|
-
* DIFFERENT components (`react-native-svg` vs `expo-image` — expo-image does
|
|
145831
|
-
* not decode SVG on iOS/Android), so without this it silently fell back to a
|
|
145832
|
-
* placeholder glyph for every vector icon while the web build looked fine.
|
|
145833
|
-
*
|
|
145834
|
-
* Absent when {@link iconUrl} is absent, or for a legacy provider that has
|
|
145835
|
-
* not been updated — a client that cannot determine the type should prefer
|
|
145836
|
-
* its raster path, which is the safe default for an unknown image.
|
|
145837
|
-
*/
|
|
145838
|
-
iconMediaType: string().optional(),
|
|
145839
|
-
configSchema: ConfigSchemaPassthrough$4,
|
|
145840
|
-
/**
|
|
145841
|
-
* The config keys that decide WHERE this kind's secrets are sent (server,
|
|
145842
|
-
* base URL, instance, chat, recipient). A save that changes any of them
|
|
145843
|
-
* while leaving a secret redacted is refused by the provider (D634), so an
|
|
145844
|
-
* editor uses this to ask for the secret on exactly those edits instead of
|
|
145845
|
-
* on every edit.
|
|
145846
|
-
*
|
|
145847
|
-
* Optional: absent from a provider that holds no secret (the Home Assistant
|
|
145848
|
-
* kinds) and from a provider older than this field — an editor that finds
|
|
145849
|
-
* it absent must assume ANY edit may need the secret.
|
|
145850
|
-
*/
|
|
145851
|
-
destinationKeys: array(string()).optional(),
|
|
145852
|
-
supportsDiscovery: boolean(),
|
|
145853
|
-
/**
|
|
145854
|
-
* Extra delivery parameters a rule may set for a target of this kind (D938).
|
|
145855
|
-
* Absent = none; the rule editor then offers nothing.
|
|
145856
|
-
*/
|
|
145857
|
-
deliveryParams: array(DeliveryParamSchema).optional(),
|
|
145858
|
-
caps: TargetKindCapsSchema
|
|
146072
|
+
var AutomationStateDocSchema = object({
|
|
146073
|
+
version: literal(1),
|
|
146074
|
+
lastRunStartedAt: number().nullable(),
|
|
146075
|
+
traces: array(AutomationRunTraceSchema)
|
|
145859
146076
|
});
|
|
145860
146077
|
/**
|
|
145861
|
-
*
|
|
145862
|
-
*
|
|
145863
|
-
*
|
|
146078
|
+
* Actions — named, runnable things an operator (or an automation) can start,
|
|
146079
|
+
* declared as LIST ENTRIES, never as devices.
|
|
146080
|
+
*
|
|
146081
|
+
* An entry is either **internal** (a short list of cap/wait steps kept in the
|
|
146082
|
+
* hub's `actions` record kind) or declared by an addon through the
|
|
146083
|
+
* `action-source` collection (a Home Assistant script, a scene …). The one
|
|
146084
|
+
* surface the UI and automations talk to is the `actions` cap; it keeps no
|
|
146085
|
+
* catalog of its own (D3) — every `list` asks the providers live.
|
|
146086
|
+
*
|
|
146087
|
+
* This file is the data half: the entry schema, the variables an entry may
|
|
146088
|
+
* declare, and the pure resolution of the values a run was given. It holds no
|
|
146089
|
+
* runtime.
|
|
145864
146090
|
*/
|
|
145865
|
-
|
|
145866
|
-
|
|
145867
|
-
|
|
145868
|
-
|
|
145869
|
-
|
|
145870
|
-
|
|
145871
|
-
|
|
146091
|
+
/** What a variable's value is. `select` takes one of `options`. */
|
|
146092
|
+
var ActionVariableTypeSchema = _enum([
|
|
146093
|
+
"string",
|
|
146094
|
+
"number",
|
|
146095
|
+
"boolean",
|
|
146096
|
+
"select"
|
|
146097
|
+
]);
|
|
146098
|
+
var ACTION_VARIABLE_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
146099
|
+
var ActionVariableValueSchema = union([
|
|
146100
|
+
string(),
|
|
146101
|
+
number(),
|
|
146102
|
+
boolean()
|
|
146103
|
+
]);
|
|
146104
|
+
/**
|
|
146105
|
+
* One declared variable. Steps reference it as `{ $var: 'name' }` (the whole
|
|
146106
|
+
* value) or `{{vars.name}}` (inside a string) in their args.
|
|
146107
|
+
*/
|
|
146108
|
+
var ActionVariableSchema = object({
|
|
146109
|
+
name: string().regex(ACTION_VARIABLE_NAME_RE),
|
|
146110
|
+
label: string().min(1).max(120).optional(),
|
|
146111
|
+
type: ActionVariableTypeSchema,
|
|
146112
|
+
required: boolean().optional(),
|
|
146113
|
+
default: ActionVariableValueSchema.optional(),
|
|
146114
|
+
/** The allowed values of a `select`. */
|
|
146115
|
+
options: array(string().min(1)).min(1).optional()
|
|
146116
|
+
}).superRefine((v, ctx) => {
|
|
146117
|
+
if (v.type === "select" && v.options === void 0) ctx.addIssue({
|
|
146118
|
+
code: "custom",
|
|
146119
|
+
message: "a select variable needs options",
|
|
146120
|
+
path: ["options"]
|
|
146121
|
+
});
|
|
146122
|
+
if (v.default !== void 0 && variableValueError(v, v.default) !== null) ctx.addIssue({
|
|
146123
|
+
code: "custom",
|
|
146124
|
+
message: variableValueError(v, v.default) ?? "invalid default",
|
|
146125
|
+
path: ["default"]
|
|
146126
|
+
});
|
|
145872
146127
|
});
|
|
145873
|
-
/**
|
|
145874
|
-
|
|
145875
|
-
|
|
145876
|
-
|
|
145877
|
-
|
|
146128
|
+
/** Why `value` is not a legal value for the variable, or null when it is. */
|
|
146129
|
+
function variableValueError(variable, value) {
|
|
146130
|
+
switch (variable.type) {
|
|
146131
|
+
case "string": return typeof value === "string" ? null : `variable "${variable.name}" must be a string`;
|
|
146132
|
+
case "number": return typeof value === "number" && Number.isFinite(value) ? null : `variable "${variable.name}" must be a number`;
|
|
146133
|
+
case "boolean": return typeof value === "boolean" ? null : `variable "${variable.name}" must be true or false`;
|
|
146134
|
+
case "select": return typeof value === "string" && (variable.options ?? []).includes(value) ? null : `variable "${variable.name}" must be one of ${(variable.options ?? []).join(", ")}`;
|
|
146135
|
+
}
|
|
146136
|
+
}
|
|
146137
|
+
var ActionSourceKindSchema = _enum(["internal", "addon"]);
|
|
146138
|
+
function isInternalActionId(actionId) {
|
|
146139
|
+
return actionId.startsWith("internal:") && actionId.length > 9;
|
|
146140
|
+
}
|
|
146141
|
+
/** The addon behind a `<addonId>:<localId>` id, or null for anything else (internal included). */
|
|
146142
|
+
function addonIdOfActionId(actionId) {
|
|
146143
|
+
if (isInternalActionId(actionId)) return null;
|
|
146144
|
+
const at = actionId.indexOf(":");
|
|
146145
|
+
return at > 0 && at < actionId.length - 1 ? actionId.slice(0, at) : null;
|
|
146146
|
+
}
|
|
146147
|
+
var ActionStatusSchema = object({
|
|
146148
|
+
isRunning: boolean(),
|
|
146149
|
+
/** Ms epoch the latest run STARTED; null when it never ran. */
|
|
146150
|
+
lastRunAt: number().nullable(),
|
|
146151
|
+
/** The latest run's failure; null on success or when it never ran. */
|
|
146152
|
+
lastError: string().nullable()
|
|
145878
146153
|
});
|
|
145879
|
-
|
|
145880
|
-
|
|
145881
|
-
|
|
145882
|
-
|
|
145883
|
-
|
|
145884
|
-
|
|
145885
|
-
|
|
145886
|
-
|
|
146154
|
+
var ActionEntrySchema = object({
|
|
146155
|
+
/** `internal:<uuid>` or `<addonId>:<localId>`. */
|
|
146156
|
+
id: string().min(3),
|
|
146157
|
+
name: string().min(1).max(120),
|
|
146158
|
+
/** The addon that declared it; `core-blocks` for an internal one. */
|
|
146159
|
+
addonId: string().min(1),
|
|
146160
|
+
source: ActionSourceKindSchema,
|
|
146161
|
+
/** An addon-declared entry is edited where it was declared. */
|
|
146162
|
+
readOnly: boolean(),
|
|
146163
|
+
/** Internal only: cap and wait steps. No action-in-action, so no cycles. */
|
|
146164
|
+
steps: array(ActionStepSchema).min(1).max(50).optional(),
|
|
146165
|
+
variables: array(ActionVariableSchema).max(20).optional(),
|
|
146166
|
+
status: ActionStatusSchema
|
|
146167
|
+
}).superRefine((entry, ctx) => {
|
|
146168
|
+
if (entry.source === "internal") {
|
|
146169
|
+
if (!isInternalActionId(entry.id)) ctx.addIssue({
|
|
146170
|
+
code: "custom",
|
|
146171
|
+
message: "an internal action id is internal:<uuid>",
|
|
146172
|
+
path: ["id"]
|
|
146173
|
+
});
|
|
146174
|
+
return;
|
|
146175
|
+
}
|
|
146176
|
+
if (entry.steps !== void 0) ctx.addIssue({
|
|
146177
|
+
code: "custom",
|
|
146178
|
+
message: "only an internal action carries steps",
|
|
146179
|
+
path: ["steps"]
|
|
146180
|
+
});
|
|
146181
|
+
if (!entry.readOnly) ctx.addIssue({
|
|
146182
|
+
code: "custom",
|
|
146183
|
+
message: "an addon action is read-only here",
|
|
146184
|
+
path: ["readOnly"]
|
|
146185
|
+
});
|
|
146186
|
+
if (addonIdOfActionId(entry.id) === null) ctx.addIssue({
|
|
146187
|
+
code: "custom",
|
|
146188
|
+
message: "an addon action id is <addonId>:<localId>",
|
|
146189
|
+
path: ["id"]
|
|
146190
|
+
});
|
|
145887
146191
|
});
|
|
145888
|
-
|
|
145889
|
-
|
|
145890
|
-
|
|
145891
|
-
|
|
146192
|
+
/** What an operator writes for an internal action. */
|
|
146193
|
+
var ActionInputSchema = object({
|
|
146194
|
+
name: string().min(1).max(120),
|
|
146195
|
+
steps: array(ActionStepSchema).min(1).max(50),
|
|
146196
|
+
variables: array(ActionVariableSchema).max(20).optional()
|
|
145892
146197
|
});
|
|
145893
|
-
/**
|
|
145894
|
-
var
|
|
146198
|
+
/** Who started a run. Absent = the operator pressed it. */
|
|
146199
|
+
var ActionRunOriginSchema = object({
|
|
146200
|
+
/** The automation block whose step started it. */
|
|
146201
|
+
blockId: string().min(1).optional() });
|
|
145895
146202
|
/**
|
|
145896
|
-
*
|
|
145897
|
-
* `
|
|
146203
|
+
* `started` = the caller did not ask to wait. `timed-out` = the run reached the
|
|
146204
|
+
* ceiling (`ACTION_RUN_MAX_MS`) and was stopped; it is never a `ran`.
|
|
145898
146205
|
*/
|
|
145899
|
-
var
|
|
145900
|
-
|
|
145901
|
-
|
|
145902
|
-
|
|
145903
|
-
|
|
145904
|
-
|
|
146206
|
+
var ActionRunOutcomeSchema = union([
|
|
146207
|
+
AutomationRunOutcomeSchema,
|
|
146208
|
+
literal("started"),
|
|
146209
|
+
literal("timed-out")
|
|
146210
|
+
]);
|
|
146211
|
+
var ActionRunResultSchema = object({
|
|
146212
|
+
runId: string().min(1),
|
|
146213
|
+
outcome: ActionRunOutcomeSchema,
|
|
146214
|
+
/** Why it did not run, or what failed. */
|
|
146215
|
+
message: string().optional()
|
|
145905
146216
|
});
|
|
145906
|
-
|
|
145907
|
-
|
|
145908
|
-
|
|
145909
|
-
|
|
145910
|
-
|
|
145911
|
-
|
|
145912
|
-
|
|
145913
|
-
|
|
145914
|
-
|
|
145915
|
-
|
|
145916
|
-
|
|
145917
|
-
|
|
145918
|
-
/**
|
|
145919
|
-
|
|
145920
|
-
|
|
145921
|
-
|
|
145922
|
-
|
|
145923
|
-
|
|
145924
|
-
|
|
145925
|
-
|
|
145926
|
-
|
|
145927
|
-
|
|
145928
|
-
|
|
145929
|
-
|
|
145930
|
-
|
|
145931
|
-
|
|
145932
|
-
}), TestResultSchema, {
|
|
145933
|
-
kind: "mutation",
|
|
145934
|
-
auth: "admin"
|
|
145935
|
-
}), method(object({
|
|
145936
|
-
target: TargetSchema,
|
|
145937
|
-
/**
|
|
145938
|
-
* Duplicate flow: create a NEW target id while copying secrets from an
|
|
145939
|
-
* existing row. The UI never holds the stored token; blank / redacted
|
|
145940
|
-
* password fields are restored from this source (D634 still applies if
|
|
145941
|
-
* destinations diverge without a re-typed secret).
|
|
145942
|
-
*/
|
|
145943
|
-
cloneSecretsFrom: string().optional()
|
|
145944
|
-
}), TargetSchema, {
|
|
145945
|
-
kind: "mutation",
|
|
145946
|
-
auth: "admin"
|
|
145947
|
-
}), method(object({ targetId: string() }), _void(), {
|
|
145948
|
-
kind: "mutation",
|
|
145949
|
-
auth: "admin"
|
|
145950
|
-
}), method(object({
|
|
145951
|
-
targetId: string(),
|
|
145952
|
-
enabled: boolean()
|
|
145953
|
-
}), _void(), {
|
|
145954
|
-
kind: "mutation",
|
|
145955
|
-
auth: "admin"
|
|
146217
|
+
_enum([
|
|
146218
|
+
"not-found",
|
|
146219
|
+
"read-only",
|
|
146220
|
+
"invalid-variables",
|
|
146221
|
+
"invalid-steps",
|
|
146222
|
+
"not-linked",
|
|
146223
|
+
"busy"
|
|
146224
|
+
]);
|
|
146225
|
+
object({
|
|
146226
|
+
actionId: string(),
|
|
146227
|
+
runId: string(),
|
|
146228
|
+
isRunning: boolean(),
|
|
146229
|
+
/** Set when the run ended. */
|
|
146230
|
+
outcome: AutomationRunOutcomeSchema.optional(),
|
|
146231
|
+
lastRunAt: number().nullable(),
|
|
146232
|
+
lastError: string().nullable()
|
|
146233
|
+
});
|
|
146234
|
+
/** A bare number accepted as a base unit — the save succeeded, say so. */
|
|
146235
|
+
var UnitWarningSchema = object({
|
|
146236
|
+
/** Where in the saved record, e.g. `conditions.children.0` or `steps.2.args.grams`. */
|
|
146237
|
+
path: string(),
|
|
146238
|
+
deviceId: number().int().optional(),
|
|
146239
|
+
field: string(),
|
|
146240
|
+
value: number(),
|
|
146241
|
+
assumedUnit: string(),
|
|
146242
|
+
message: string()
|
|
145956
146243
|
});
|
|
145957
146244
|
_enum([
|
|
145958
146245
|
"automation",
|
|
@@ -146021,6 +146308,8 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
146021
146308
|
kind: "mutation",
|
|
146022
146309
|
auth: "admin"
|
|
146023
146310
|
});
|
|
146311
|
+
/** `timeoutMs` of `actions.run`: a waited call outlives any legal run. */
|
|
146312
|
+
var ACTION_RUN_TIMEOUT_MS = 363e4;
|
|
146024
146313
|
/**
|
|
146025
146314
|
* actions — the ONE surface for runnable actions, for the UI and for
|
|
146026
146315
|
* automations. Provided by the core-blocks builtin on the hub.
|
|
@@ -146039,6 +146328,12 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
146039
146328
|
* An admin, and an in-process caller (an automation block), may run any action.
|
|
146040
146329
|
* Every refusal is typed (`[not-linked] …`) and logged.
|
|
146041
146330
|
*
|
|
146331
|
+
* **A run lasts at most `ACTION_RUN_MAX_MS` (60 min).** The provider stops a
|
|
146332
|
+
* run that reaches it and answers `timed-out` (never `ran`); an action whose
|
|
146333
|
+
* `wait` steps alone add up to more is refused at create/update
|
|
146334
|
+
* (`[invalid-steps]`). `run` declares a `timeoutMs` above that ceiling, so a
|
|
146335
|
+
* waited call (an automation step) is never cut by the 60 s transport default.
|
|
146336
|
+
*
|
|
146042
146337
|
* A second `run` of an action that is already running is REFUSED — traced and
|
|
146043
146338
|
* logged — never queued.
|
|
146044
146339
|
*/
|
|
@@ -146065,7 +146360,8 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
146065
146360
|
role: "viewer",
|
|
146066
146361
|
auth: "protected",
|
|
146067
146362
|
kind: "mutation",
|
|
146068
|
-
caller: "required"
|
|
146363
|
+
caller: "required",
|
|
146364
|
+
timeoutMs: ACTION_RUN_TIMEOUT_MS
|
|
146069
146365
|
}), method(ActionIdInput, _void(), {
|
|
146070
146366
|
kind: "mutation",
|
|
146071
146367
|
auth: "admin"
|
|
@@ -150484,37 +150780,6 @@ method(object({
|
|
|
150484
150780
|
kind: "mutation",
|
|
150485
150781
|
auth: "admin"
|
|
150486
150782
|
}), method(object({ blockIds: array(string()) }), object({ states: array(CompositionBlockStateSchema) }), { auth: "admin" });
|
|
150487
|
-
var ConnectionTestOutcomeSchema = discriminatedUnion("outcome", [
|
|
150488
|
-
object({
|
|
150489
|
-
outcome: literal("validated"),
|
|
150490
|
-
/** Round-trip of the sign-in, when the provider measured it. */
|
|
150491
|
-
latencyMs: number().nonnegative().optional(),
|
|
150492
|
-
/** Optional human detail worth showing next to the tick
|
|
150493
|
-
* ("3 devices visible on this account"). */
|
|
150494
|
-
detail: string().optional()
|
|
150495
|
-
}).strict(),
|
|
150496
|
-
object({
|
|
150497
|
-
outcome: literal("rejected"),
|
|
150498
|
-
error: string()
|
|
150499
|
-
}).strict(),
|
|
150500
|
-
object({
|
|
150501
|
-
outcome: literal("inconclusive"),
|
|
150502
|
-
error: string()
|
|
150503
|
-
}).strict()
|
|
150504
|
-
]);
|
|
150505
|
-
var ConnectionTestInputSchema = object({
|
|
150506
|
-
/** Candidate integration settings, exactly as the create form collected them. */
|
|
150507
|
-
settings: record(string(), unknown()) });
|
|
150508
|
-
/**
|
|
150509
|
-
* What the provider's test actually DOES, so the UI can say it in words before
|
|
150510
|
-
* the operator presses the button ("Signs in to the Dreo cloud"). Purely
|
|
150511
|
-
* descriptive — it never changes routing.
|
|
150512
|
-
*/
|
|
150513
|
-
var ConnectionTestDescriptorSchema = object({ label: string() });
|
|
150514
|
-
method(ConnectionTestInputSchema, ConnectionTestOutcomeSchema, {
|
|
150515
|
-
kind: "mutation",
|
|
150516
|
-
auth: "admin"
|
|
150517
|
-
}), method(_void(), ConnectionTestDescriptorSchema, { auth: "admin" });
|
|
150518
150783
|
/**
|
|
150519
150784
|
* Upstream-system connectivity sensor — distinct from `device-status`,
|
|
150520
150785
|
* which is the kernel-managed online/offline flag for the device's
|
|
@@ -151092,6 +151357,9 @@ var MediaPlayerStatusSchema = object({
|
|
|
151092
151357
|
/** Repeat mode. Null when no repeat surface.
|
|
151093
151358
|
* Pair with `DeviceFeature.MediaPlayerRepeat`. */
|
|
151094
151359
|
repeat: MediaPlayerRepeatSchema.nullable(),
|
|
151360
|
+
/** Ms epoch when `position` was read from the device. Null when the driver
|
|
151361
|
+
* does not say; a UI that advances the position while playing counts from it. */
|
|
151362
|
+
positionUpdatedAt: number().nullable().default(null),
|
|
151095
151363
|
/** Ms epoch when the slice was last updated. */
|
|
151096
151364
|
lastChangedAt: number()
|
|
151097
151365
|
});
|
|
@@ -151727,7 +151995,9 @@ var ThresholdTransformDraftSchema = object({
|
|
|
151727
151995
|
comparison: _enum(["gte", "lte"]),
|
|
151728
151996
|
threshold: number(),
|
|
151729
151997
|
startDwellMs: number().nonnegative(),
|
|
151730
|
-
stopDwellMs: number().nonnegative()
|
|
151998
|
+
stopDwellMs: number().nonnegative(),
|
|
151999
|
+
/** Samples a start needs; absent = the compiler's default for the source (2 for running power, else 1). */
|
|
152000
|
+
minSamples: number().int().min(1).optional()
|
|
151731
152001
|
});
|
|
151732
152002
|
var CustomizeTransformDraftSchema = discriminatedUnion("kind", [
|
|
151733
152003
|
IdentityTransformDraftSchema,
|
|
@@ -157657,6 +157927,7 @@ var IntegrationWithStateSchema = object({
|
|
|
157657
157927
|
id: string(),
|
|
157658
157928
|
addonId: string(),
|
|
157659
157929
|
name: string(),
|
|
157930
|
+
/** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
|
|
157660
157931
|
enabled: boolean(),
|
|
157661
157932
|
info: record(string(), unknown()).readonly(),
|
|
157662
157933
|
/** The discovery candidate this integration was set up from (D984). */
|
|
@@ -157669,6 +157940,7 @@ var IntegrationLiteSchema = object({
|
|
|
157669
157940
|
id: string(),
|
|
157670
157941
|
addonId: string(),
|
|
157671
157942
|
name: string(),
|
|
157943
|
+
/** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
|
|
157672
157944
|
enabled: boolean(),
|
|
157673
157945
|
info: record(string(), unknown()).readonly(),
|
|
157674
157946
|
/** The discovery candidate this integration was set up from (D984). */
|
|
@@ -157714,10 +157986,9 @@ var AvailableIntegrationTypeSchema = object({
|
|
|
157714
157986
|
* locations" checkbox. Provider-declared in the addon manifest. */
|
|
157715
157987
|
supportsLocationImport: boolean(),
|
|
157716
157988
|
/**
|
|
157717
|
-
* True when this integration
|
|
157718
|
-
*
|
|
157719
|
-
*
|
|
157720
|
-
* rather than offering a button that always answers the same nonsense.
|
|
157989
|
+
* True when this integration's instances declare a Test (`integration-instances.describe().canTest`,
|
|
157990
|
+
* D1016). An integration that cannot be tested must say so up front rather than offering a
|
|
157991
|
+
* button that always answers the same nonsense.
|
|
157721
157992
|
*/
|
|
157722
157993
|
canTest: boolean(),
|
|
157723
157994
|
existingInstances: array(object({
|
|
@@ -157768,15 +158039,21 @@ var TestConnectionResultSchema = object({
|
|
|
157768
158039
|
var CreateIntegrationInputSchema = object({
|
|
157769
158040
|
addonId: string(),
|
|
157770
158041
|
name: string(),
|
|
157771
|
-
enabled: boolean().optional(),
|
|
157772
158042
|
info: record(string(), unknown()).optional(),
|
|
157773
158043
|
/** `stableId` of the discovery candidate the form was seeded from (D984). */
|
|
157774
158044
|
originStableId: string().optional(),
|
|
157775
|
-
settings: record(string(), unknown()).optional()
|
|
158045
|
+
settings: record(string(), unknown()).optional(),
|
|
158046
|
+
/** The instance kind being created, for a provider with several; omitted = its only testable kind. */
|
|
158047
|
+
kind: string().min(1).optional()
|
|
157776
158048
|
});
|
|
157777
158049
|
var UpdateIntegrationInputSchema = object({
|
|
157778
158050
|
id: string(),
|
|
157779
158051
|
name: string().optional(),
|
|
158052
|
+
/**
|
|
158053
|
+
* Accepted for a FIXED builtin only (`info.fixed`: alarm panel, camera grid, core blocks,
|
|
158054
|
+
* terminal), which keeps no instance record: the registry flag is its one store. Any other
|
|
158055
|
+
* integration is switched through `integration-instances.setInstanceEnabled`.
|
|
158056
|
+
*/
|
|
157780
158057
|
enabled: boolean().optional(),
|
|
157781
158058
|
info: record(string(), unknown()).optional()
|
|
157782
158059
|
});
|
|
@@ -157793,13 +158070,7 @@ method(_void(), array(IntegrationWithStateSchema)), method(object({ id: string()
|
|
|
157793
158070
|
}), method(object({ id: string() }), DeleteIntegrationResultSchema, {
|
|
157794
158071
|
kind: "mutation",
|
|
157795
158072
|
auth: "admin"
|
|
157796
|
-
}), method(_void(), array(AvailableIntegrationTypeSchema), { auth: "admin" })
|
|
157797
|
-
addonId: string(),
|
|
157798
|
-
settings: record(string(), unknown())
|
|
157799
|
-
}), TestConnectionResultSchema, {
|
|
157800
|
-
kind: "mutation",
|
|
157801
|
-
auth: "admin"
|
|
157802
|
-
});
|
|
158073
|
+
}), method(_void(), array(AvailableIntegrationTypeSchema), { auth: "admin" });
|
|
157803
158074
|
/**
|
|
157804
158075
|
* `integration-instances` - the connection of an addon that holds ONE or SEVERAL
|
|
157805
158076
|
* (an account, a relay, a destination) as typed records (D985, D986). The addon's
|
|
@@ -157824,7 +158095,7 @@ var IntegrationInstanceIdSchema = string().min(1);
|
|
|
157824
158095
|
var IntegrationInstanceModeSchema = _enum(["single", "multiple"]);
|
|
157825
158096
|
/**
|
|
157826
158097
|
* What the addon's instances ARE for the Integrations page (planning#416). `devices`: each
|
|
157827
|
-
* instance is an integration that brings devices (
|
|
158098
|
+
* instance is an integration that brings devices (its record body owns the on/off switch);
|
|
157828
158099
|
* `services`: a connection configured from the addon's own function page, never listed on
|
|
157829
158100
|
* Integrations.
|
|
157830
158101
|
* It is the same vocabulary as the manifest's `integrationRole`, which stays as an override.
|
|
@@ -157867,18 +158138,38 @@ var IntegrationInstanceKindSchema = object({
|
|
|
157867
158138
|
/** Relative hub path to disconnect that account. */
|
|
157868
158139
|
disconnectPath: string().min(1).optional()
|
|
157869
158140
|
});
|
|
158141
|
+
/**
|
|
158142
|
+
* How devices of an instance are found. `none`: the operator adds them by hand; `lan`: the addon
|
|
158143
|
+
* scans the network before any instance exists (the wizard offers the candidates); `account`: the
|
|
158144
|
+
* devices appear after the instance signs in. `scopedToInstance`: a discovery run belongs to ONE
|
|
158145
|
+
* instance and its candidates are claimed by it.
|
|
158146
|
+
*/
|
|
158147
|
+
var IntegrationInstanceDiscoverySchema = object({
|
|
158148
|
+
mode: _enum([
|
|
158149
|
+
"none",
|
|
158150
|
+
"lan",
|
|
158151
|
+
"account"
|
|
158152
|
+
]),
|
|
158153
|
+
scopedToInstance: boolean()
|
|
158154
|
+
});
|
|
158155
|
+
/**
|
|
158156
|
+
* One link a kind of this provider declares (D1013 rule 5): the body `field` of an instance of
|
|
158157
|
+
* `kind` holds the id of an instance of the function cap `to.cap` (of kind `to.kind`, when set).
|
|
158158
|
+
* The hub indexes these so the target's delete is refused while a link names it.
|
|
158159
|
+
*/
|
|
158160
|
+
var IntegrationInstanceLinkSchema = object({
|
|
158161
|
+
kind: string().min(1),
|
|
158162
|
+
field: string().min(1),
|
|
158163
|
+
to: object({
|
|
158164
|
+
cap: string().min(1),
|
|
158165
|
+
kind: string().min(1).optional()
|
|
158166
|
+
})
|
|
158167
|
+
});
|
|
157870
158168
|
var IntegrationInstanceDescriptionSchema = object({
|
|
157871
158169
|
/** What the instances are for the Integrations page; see {@link IntegrationInstanceRoleSchema}. */
|
|
157872
158170
|
role: IntegrationInstanceRoleSchema,
|
|
157873
158171
|
/** How the devices of an instance are found; absent means `{ mode: 'none' }`. */
|
|
157874
|
-
discovery:
|
|
157875
|
-
mode: _enum([
|
|
157876
|
-
"none",
|
|
157877
|
-
"lan",
|
|
157878
|
-
"account"
|
|
157879
|
-
]),
|
|
157880
|
-
scopedToInstance: boolean()
|
|
157881
|
-
}).optional(),
|
|
158172
|
+
discovery: IntegrationInstanceDiscoverySchema.optional(),
|
|
157882
158173
|
/** `single`: at most one instance can exist (Loki). `multiple`: an account each. */
|
|
157883
158174
|
instanceMode: IntegrationInstanceModeSchema,
|
|
157884
158175
|
/** What the instance is, for the UI (`destination`, `relay`, `account`). */
|
|
@@ -157899,7 +158190,9 @@ var IntegrationInstanceDescriptionSchema = object({
|
|
|
157899
158190
|
* `createInstance` without an `id` works: the provider mints it. Absent means the caller must
|
|
157900
158191
|
* send an id (the UI then mints an opaque one).
|
|
157901
158192
|
*/
|
|
157902
|
-
mintsId: boolean().optional()
|
|
158193
|
+
mintsId: boolean().optional(),
|
|
158194
|
+
/** The links to other instances the provider's kinds declare; absent means none. */
|
|
158195
|
+
links: array(IntegrationInstanceLinkSchema).optional()
|
|
157903
158196
|
});
|
|
157904
158197
|
var IntegrationInstanceStatusSchema = object({
|
|
157905
158198
|
state: _enum([
|
|
@@ -157919,8 +158212,8 @@ var IntegrationInstanceSchema = object({
|
|
|
157919
158212
|
configured: boolean(),
|
|
157920
158213
|
/**
|
|
157921
158214
|
* The instance's own on/off switch (D996), derived from the record body (`enabled !== false`,
|
|
157922
|
-
* so a row written before the field existed is on).
|
|
157923
|
-
*
|
|
158215
|
+
* so a row written before the field existed is on). The same for every role, `devices` included:
|
|
158216
|
+
* the body is the one store, `setInstanceEnabled` the one writer (epic #440, step 3).
|
|
157924
158217
|
*/
|
|
157925
158218
|
enabled: boolean().optional(),
|
|
157926
158219
|
/** The kind of this instance (one of `describe().kinds[].id`), when the provider has kinds. */
|
|
@@ -157970,7 +158263,8 @@ var integrationInstancesCapability = {
|
|
|
157970
158263
|
auth: "admin"
|
|
157971
158264
|
}),
|
|
157972
158265
|
/**
|
|
157973
|
-
* Switch ONE instance on or off
|
|
158266
|
+
* Switch ONE instance on or off, for every role; a missing record is created from the addon's
|
|
158267
|
+
* initial body. A row control, not a form field: `updateInstance.values` is the
|
|
157974
158268
|
* form patch (D62, D996). An off instance keeps its record and secrets and does no work.
|
|
157975
158269
|
*/
|
|
157976
158270
|
setInstanceEnabled: method(object({
|
|
@@ -161054,6 +161348,8 @@ var MigrationIntegrationSchema = object({
|
|
|
161054
161348
|
addonId: string(),
|
|
161055
161349
|
name: string(),
|
|
161056
161350
|
info: Rows,
|
|
161351
|
+
/** The registry's stored switch: read by the one-switch migration, nothing else. */
|
|
161352
|
+
enabled: boolean().optional(),
|
|
161057
161353
|
originStableId: string().optional()
|
|
161058
161354
|
});
|
|
161059
161355
|
var MigrationDeviceSchema = object({
|
|
@@ -166538,13 +166834,6 @@ var AddBrokerInputSchema = object({
|
|
|
166538
166834
|
});
|
|
166539
166835
|
var AddBrokerResultSchema = object({ id: string() });
|
|
166540
166836
|
var IdInputSchema = object({ id: string() });
|
|
166541
|
-
var TestResultSchema$1 = discriminatedUnion("ok", [object({
|
|
166542
|
-
ok: literal(true),
|
|
166543
|
-
latencyMs: number()
|
|
166544
|
-
}), object({
|
|
166545
|
-
ok: literal(false),
|
|
166546
|
-
error: string()
|
|
166547
|
-
})]);
|
|
166548
166837
|
var StartEmbeddedInputSchema = object({
|
|
166549
166838
|
port: number().int().min(1).max(65535).default(1883),
|
|
166550
166839
|
/** Allow anonymous connect (no username/password). Default: false. */
|
|
@@ -166567,9 +166856,6 @@ method(_void(), array(BrokerInfoSchema)), method(IdInputSchema, BrokerConnection
|
|
|
166567
166856
|
}), method(IdInputSchema, _void(), {
|
|
166568
166857
|
kind: "mutation",
|
|
166569
166858
|
auth: "admin"
|
|
166570
|
-
}), method(IdInputSchema, TestResultSchema$1, {
|
|
166571
|
-
kind: "mutation",
|
|
166572
|
-
auth: "admin"
|
|
166573
166859
|
}), method(StartEmbeddedInputSchema, StartEmbeddedResultSchema, {
|
|
166574
166860
|
kind: "mutation",
|
|
166575
166861
|
auth: "admin"
|
|
@@ -171249,14 +171535,6 @@ var PetFountainStatusSchema = object({
|
|
|
171249
171535
|
empty: boolean().nullable(),
|
|
171250
171536
|
/** True while the pump is running. Null while unknown. */
|
|
171251
171537
|
pumpRunning: boolean().nullable(),
|
|
171252
|
-
/** Water drunk in the last drink, in litres. */
|
|
171253
|
-
lastDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
171254
|
-
/** Water drunk in the current hour, in litres. */
|
|
171255
|
-
currentHourDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
171256
|
-
/** Water drunk over the last 24 hours (rolling), in litres. */
|
|
171257
|
-
last24hDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
171258
|
-
/** Water drunk since local midnight, in litres. Null when the fountain has no such sensor. */
|
|
171259
|
-
todayDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
171260
171538
|
/** Decoded fault message. Null means healthy; a non-null string is an active fault. */
|
|
171261
171539
|
error: string().nullable(),
|
|
171262
171540
|
/** Ms epoch when the slice was last refreshed. */
|
|
@@ -171269,21 +171547,15 @@ var petFountainCapability = {
|
|
|
171269
171547
|
deviceNative: true,
|
|
171270
171548
|
mode: "singleton",
|
|
171271
171549
|
deviceTypes: [DeviceType.PetFountain],
|
|
171272
|
-
methods: {
|
|
171273
|
-
|
|
171274
|
-
|
|
171275
|
-
|
|
171276
|
-
|
|
171277
|
-
|
|
171278
|
-
|
|
171279
|
-
|
|
171280
|
-
|
|
171281
|
-
/** Clear the rolling daily consumption counters on the device. */
|
|
171282
|
-
resetDailyConsumption: method(object({ deviceId: DeviceIdSchema$1 }), _void(), {
|
|
171283
|
-
kind: "mutation",
|
|
171284
|
-
auth: "protected"
|
|
171285
|
-
})
|
|
171286
|
-
},
|
|
171550
|
+
methods: {
|
|
171551
|
+
/** Start or stop the pump. */
|
|
171552
|
+
setPump: method(object({
|
|
171553
|
+
deviceId: DeviceIdSchema$1,
|
|
171554
|
+
on: boolean()
|
|
171555
|
+
}), _void(), {
|
|
171556
|
+
kind: "mutation",
|
|
171557
|
+
auth: "protected"
|
|
171558
|
+
}) },
|
|
171287
171559
|
status: {
|
|
171288
171560
|
schema: PetFountainStatusSchema,
|
|
171289
171561
|
kind: "push"
|
|
@@ -171307,14 +171579,6 @@ var petFountainCapability = {
|
|
|
171307
171579
|
waterVolume: {
|
|
171308
171580
|
kind: "gauge",
|
|
171309
171581
|
unit: "L"
|
|
171310
|
-
},
|
|
171311
|
-
todayDrink: {
|
|
171312
|
-
kind: "gauge",
|
|
171313
|
-
unit: "L"
|
|
171314
|
-
},
|
|
171315
|
-
last24hDrink: {
|
|
171316
|
-
kind: "gauge",
|
|
171317
|
-
unit: "L"
|
|
171318
171582
|
}
|
|
171319
171583
|
} }
|
|
171320
171584
|
};
|
|
@@ -180428,7 +180692,7 @@ var TrainingProviderTypeSchema = object({
|
|
|
180428
180692
|
label: string(),
|
|
180429
180693
|
/** Path under the addon package (e.g. `assets/training-modal/icon.svg`). */
|
|
180430
180694
|
iconAsset: string(),
|
|
180431
|
-
/** Owning `training-provider` addon
|
|
180695
|
+
/** Owning `training-provider` addon. */
|
|
180432
180696
|
addonId: string(),
|
|
180433
180697
|
/**
|
|
180434
180698
|
* Fields for one entry of this type (credentials + defaults). Absent on a
|
|
@@ -180473,36 +180737,6 @@ var TrainingProviderDescriptorSchema = object({
|
|
|
180473
180737
|
*/
|
|
180474
180738
|
formValues: record(string(), unknown()).optional()
|
|
180475
180739
|
});
|
|
180476
|
-
/**
|
|
180477
|
-
* Patch one entry's name, credentials and defaults. Pin with owning `{ addonId }`.
|
|
180478
|
-
* An omitted or empty `tokenSecret` means KEEP the stored secret (D787).
|
|
180479
|
-
* `{ $secretClear: true }` clears it.
|
|
180480
|
-
*/
|
|
180481
|
-
var TrainingProviderUpdateEntryInputSchema = object({
|
|
180482
|
-
entryId: string().min(1),
|
|
180483
|
-
name: string().min(1),
|
|
180484
|
-
tokenId: string().optional(),
|
|
180485
|
-
tokenSecret: union([string(), object({ $secretClear: literal(true) })]).optional(),
|
|
180486
|
-
environment: string().optional(),
|
|
180487
|
-
gpuType: string().optional(),
|
|
180488
|
-
region: string().optional(),
|
|
180489
|
-
costCapUsd: number().nonnegative().optional(),
|
|
180490
|
-
maxRuntimeSec: number().int().positive().optional(),
|
|
180491
|
-
failedDatasetGraceHours: number().nonnegative().optional()
|
|
180492
|
-
});
|
|
180493
|
-
var TrainingCredentialCheckSchema = object({
|
|
180494
|
-
ok: boolean(),
|
|
180495
|
-
/** Workspace / account name, when the provider says. */
|
|
180496
|
-
account: string().optional(),
|
|
180497
|
-
reason: _enum([
|
|
180498
|
-
"missing",
|
|
180499
|
-
"invalid",
|
|
180500
|
-
"forbidden",
|
|
180501
|
-
"network",
|
|
180502
|
-
"quota"
|
|
180503
|
-
]).optional(),
|
|
180504
|
-
detail: string().optional()
|
|
180505
|
-
});
|
|
180506
180740
|
var ProviderJobStateSchema = _enum([
|
|
180507
180741
|
"pending",
|
|
180508
180742
|
"starting",
|
|
@@ -180550,22 +180784,6 @@ var TrainingLogLineSchema = object({
|
|
|
180550
180784
|
text: string()
|
|
180551
180785
|
});
|
|
180552
180786
|
method(object({}), array(TrainingProviderDescriptorSchema).readonly(), { auth: "admin" }), method(object({}), array(TrainingProviderTypeSchema).readonly(), { auth: "admin" }), method(object({}), array(TrainingProviderEntrySchema).readonly(), { auth: "admin" }), method(object({
|
|
180553
|
-
typeId: string().min(1),
|
|
180554
|
-
name: string().min(1)
|
|
180555
|
-
}), object({ entryId: string() }), {
|
|
180556
|
-
kind: "mutation",
|
|
180557
|
-
auth: "admin"
|
|
180558
|
-
}), method(object({ entryId: string().min(1) }), object({ ok: literal(true) }), {
|
|
180559
|
-
kind: "mutation",
|
|
180560
|
-
auth: "admin"
|
|
180561
|
-
}), method(TrainingProviderUpdateEntryInputSchema, object({ ok: literal(true) }), {
|
|
180562
|
-
kind: "mutation",
|
|
180563
|
-
auth: "admin"
|
|
180564
|
-
}), method(object({ entryId: string().min(1) }), TrainingCredentialCheckSchema, {
|
|
180565
|
-
kind: "mutation",
|
|
180566
|
-
auth: "admin",
|
|
180567
|
-
timeoutMs: 3e4
|
|
180568
|
-
}), method(object({
|
|
180569
180787
|
entryId: string().min(1),
|
|
180570
180788
|
gpuType: string(),
|
|
180571
180789
|
region: string(),
|
|
@@ -186529,20 +186747,6 @@ Object.freeze({
|
|
|
186529
186747
|
access: "view",
|
|
186530
186748
|
role: "admin"
|
|
186531
186749
|
},
|
|
186532
|
-
"connectionTest.describeTest": {
|
|
186533
|
-
capName: "connection-test",
|
|
186534
|
-
capScope: "system",
|
|
186535
|
-
addonId: null,
|
|
186536
|
-
access: "view",
|
|
186537
|
-
role: "admin"
|
|
186538
|
-
},
|
|
186539
|
-
"connectionTest.testSettings": {
|
|
186540
|
-
capName: "connection-test",
|
|
186541
|
-
capScope: "system",
|
|
186542
|
-
addonId: null,
|
|
186543
|
-
access: "create",
|
|
186544
|
-
role: "admin"
|
|
186545
|
-
},
|
|
186546
186750
|
"connectivity.getStatus": {
|
|
186547
186751
|
capName: "connectivity",
|
|
186548
186752
|
capScope: "device",
|
|
@@ -188909,13 +189113,6 @@ Object.freeze({
|
|
|
188909
189113
|
access: "view",
|
|
188910
189114
|
role: "admin"
|
|
188911
189115
|
},
|
|
188912
|
-
"integrations.testConnection": {
|
|
188913
|
-
capName: "integrations",
|
|
188914
|
-
capScope: "system",
|
|
188915
|
-
addonId: null,
|
|
188916
|
-
access: "create",
|
|
188917
|
-
role: "admin"
|
|
188918
|
-
},
|
|
188919
189116
|
"integrations.update": {
|
|
188920
189117
|
capName: "integrations",
|
|
188921
189118
|
capScope: "system",
|
|
@@ -190148,13 +190345,6 @@ Object.freeze({
|
|
|
190148
190345
|
access: "create",
|
|
190149
190346
|
role: "admin"
|
|
190150
190347
|
},
|
|
190151
|
-
"mqttBroker.testConnection": {
|
|
190152
|
-
capName: "mqtt-broker",
|
|
190153
|
-
capScope: "system",
|
|
190154
|
-
addonId: null,
|
|
190155
|
-
access: "create",
|
|
190156
|
-
role: "admin"
|
|
190157
|
-
},
|
|
190158
190348
|
"nativeObjectDetection.getOptions": {
|
|
190159
190349
|
capName: "native-object-detection",
|
|
190160
190350
|
capScope: "device",
|
|
@@ -191030,13 +191220,6 @@ Object.freeze({
|
|
|
191030
191220
|
access: "view",
|
|
191031
191221
|
role: "viewer"
|
|
191032
191222
|
},
|
|
191033
|
-
"petFountain.resetDailyConsumption": {
|
|
191034
|
-
capName: "pet-fountain",
|
|
191035
|
-
capScope: "device",
|
|
191036
|
-
addonId: null,
|
|
191037
|
-
access: "delete",
|
|
191038
|
-
role: "viewer"
|
|
191039
|
-
},
|
|
191040
191223
|
"petFountain.setPump": {
|
|
191041
191224
|
capName: "pet-fountain",
|
|
191042
191225
|
capScope: "device",
|
|
@@ -194992,20 +195175,6 @@ Object.freeze({
|
|
|
194992
195175
|
access: "create",
|
|
194993
195176
|
role: "admin"
|
|
194994
195177
|
},
|
|
194995
|
-
"trainingProvider.createEntry": {
|
|
194996
|
-
capName: "training-provider",
|
|
194997
|
-
capScope: "system",
|
|
194998
|
-
addonId: null,
|
|
194999
|
-
access: "create",
|
|
195000
|
-
role: "admin"
|
|
195001
|
-
},
|
|
195002
|
-
"trainingProvider.deleteEntry": {
|
|
195003
|
-
capName: "training-provider",
|
|
195004
|
-
capScope: "system",
|
|
195005
|
-
addonId: null,
|
|
195006
|
-
access: "delete",
|
|
195007
|
-
role: "admin"
|
|
195008
|
-
},
|
|
195009
195178
|
"trainingProvider.describe": {
|
|
195010
195179
|
capName: "training-provider",
|
|
195011
195180
|
capScope: "system",
|
|
@@ -195076,13 +195245,6 @@ Object.freeze({
|
|
|
195076
195245
|
access: "create",
|
|
195077
195246
|
role: "admin"
|
|
195078
195247
|
},
|
|
195079
|
-
"trainingProvider.updateEntry": {
|
|
195080
|
-
capName: "training-provider",
|
|
195081
|
-
capScope: "system",
|
|
195082
|
-
addonId: null,
|
|
195083
|
-
access: "create",
|
|
195084
|
-
role: "admin"
|
|
195085
|
-
},
|
|
195086
195248
|
"trainingProvider.uploadDataset": {
|
|
195087
195249
|
capName: "training-provider",
|
|
195088
195250
|
capScope: "system",
|
|
@@ -195090,13 +195252,6 @@ Object.freeze({
|
|
|
195090
195252
|
access: "create",
|
|
195091
195253
|
role: "admin"
|
|
195092
195254
|
},
|
|
195093
|
-
"trainingProvider.validateCredentials": {
|
|
195094
|
-
capName: "training-provider",
|
|
195095
|
-
capScope: "system",
|
|
195096
|
-
addonId: null,
|
|
195097
|
-
access: "create",
|
|
195098
|
-
role: "admin"
|
|
195099
|
-
},
|
|
195100
195255
|
"turnProvider.getTurnServers": {
|
|
195101
195256
|
capName: "turn-provider",
|
|
195102
195257
|
capScope: "system",
|
|
@@ -197585,11 +197740,6 @@ Object.freeze({
|
|
|
197585
197740
|
form: "single",
|
|
197586
197741
|
optional: false
|
|
197587
197742
|
}],
|
|
197588
|
-
"petFountain.resetDailyConsumption": [{
|
|
197589
|
-
name: "deviceId",
|
|
197590
|
-
form: "single",
|
|
197591
|
-
optional: false
|
|
197592
|
-
}],
|
|
197593
197743
|
"petFountain.setPump": [{
|
|
197594
197744
|
name: "deviceId",
|
|
197595
197745
|
form: "single",
|
|
@@ -200384,7 +200534,6 @@ object({
|
|
|
200384
200534
|
delay: number().nonnegative().optional(),
|
|
200385
200535
|
commands: record(string(), unknown())
|
|
200386
200536
|
});
|
|
200387
|
-
entryBody({ brokerId: string() });
|
|
200388
200537
|
//#endregion
|
|
200389
200538
|
//#region src/clips/clip-prefetch.ts
|
|
200390
200539
|
/** The longest a device may stay quiet after refusals, whatever its interval. */
|
|
@@ -212887,6 +213036,10 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
|
|
|
212887
213036
|
const host = this.config.get("host");
|
|
212888
213037
|
return typeof host === "string" && host.length > 0 ? host : null;
|
|
212889
213038
|
}
|
|
213039
|
+
/** The integration this camera belongs to, or `null` when it names none. */
|
|
213040
|
+
get integrationId() {
|
|
213041
|
+
return this.hubIntegrationId();
|
|
213042
|
+
}
|
|
212890
213043
|
/** The integration (one NVR / Home Hub, D985) this camera was adopted from, or `null`. */
|
|
212891
213044
|
hubIntegrationId() {
|
|
212892
213045
|
const id = this.config.get("integrationId");
|
|
@@ -220861,6 +221014,20 @@ var SMTP_BROKER_ADDON_ID = "smtp-nodemailer";
|
|
|
220861
221014
|
/** Who this addon is, among the subscribers of a mailbox. */
|
|
220862
221015
|
var REOLINK_SUBSCRIBER_ID = "provider-reolink";
|
|
220863
221016
|
var MAILBOX_NAME = "Camera mailbox";
|
|
221017
|
+
/** What an integration's `mailboxId` points at: an `smtp-inbound` instance of the `broker` cap (D1013). */
|
|
221018
|
+
var SMTP_MAILBOX_LINK = {
|
|
221019
|
+
cap: "broker",
|
|
221020
|
+
kind: SMTP_INBOUND_KIND
|
|
221021
|
+
};
|
|
221022
|
+
/** The body field of an integration record that names its camera mailbox; empty or absent when none. */
|
|
221023
|
+
var MAILBOX_LINK_FIELD = "mailboxId";
|
|
221024
|
+
/**
|
|
221025
|
+
* The link field of the integration record. The bridge fills it (an integration whose standalone
|
|
221026
|
+
* cameras mail the mailbox links to it), so the hub refuses to delete a mailbox that is in use.
|
|
221027
|
+
*/
|
|
221028
|
+
function mailboxLinkField() {
|
|
221029
|
+
return optionalLinkField(SMTP_MAILBOX_LINK);
|
|
221030
|
+
}
|
|
220864
221031
|
var RECIPIENT_PREFIX = "cam-";
|
|
220865
221032
|
/**
|
|
220866
221033
|
* The real port: the mailboxes are `integration-instances` of the SMTP addon (the kind of its
|
|
@@ -221014,20 +221181,54 @@ var EmailPushBridge = class {
|
|
|
221014
221181
|
const recipients = this.recipients();
|
|
221015
221182
|
if (recipients.length === 0) {
|
|
221016
221183
|
if (this.brokerId !== null && this.subscriptionId !== null) await this.deps.port.unsubscribe(this.brokerId, this.subscriptionId);
|
|
221184
|
+
if (this.brokerId !== null) await this.syncLinks(this.brokerId, /* @__PURE__ */ new Set());
|
|
221017
221185
|
this.subscriptionId = null;
|
|
221018
221186
|
this.declared = null;
|
|
221019
221187
|
return;
|
|
221020
221188
|
}
|
|
221021
|
-
const
|
|
221189
|
+
const owners = this.linkOwners();
|
|
221190
|
+
const key = `${recipients.join(",")}|${[...owners].sort().join(",")}`;
|
|
221022
221191
|
if (!force && this.declared === key && this.subscriptionId !== null) return;
|
|
221023
221192
|
const brokerId = await this.ensureMailbox();
|
|
221024
221193
|
await this.seedBaseline(brokerId);
|
|
221025
221194
|
const { subscriptionId } = await this.deps.port.subscribe(brokerId, recipients);
|
|
221026
221195
|
this.brokerId = brokerId;
|
|
221027
221196
|
this.subscriptionId = subscriptionId;
|
|
221028
|
-
this.declared = key;
|
|
221197
|
+
this.declared = await this.syncLinks(brokerId, owners) ? key : null;
|
|
221029
221198
|
await this.reconcile();
|
|
221030
221199
|
}
|
|
221200
|
+
/** The integrations whose standalone cameras mail the mailbox: they link to it. */
|
|
221201
|
+
linkOwners() {
|
|
221202
|
+
const owners = /* @__PURE__ */ new Set();
|
|
221203
|
+
for (const cam of this.deps.listCameras()) if (cam.isEmailPushEligible && cam.integrationId !== null) owners.add(cam.integrationId);
|
|
221204
|
+
return owners;
|
|
221205
|
+
}
|
|
221206
|
+
/**
|
|
221207
|
+
* Make the `mailboxId` links say who uses the mailbox: `owners` link to it, no other
|
|
221208
|
+
* integration does. Idempotent, so an install whose mailbox already exists is filled from it
|
|
221209
|
+
* (the mailbox is re-adopted by `ensureMailbox`) with nothing stored beforehand. False when the
|
|
221210
|
+
* links could not be written: the caller retries at the next sync.
|
|
221211
|
+
*/
|
|
221212
|
+
async syncLinks(brokerId, owners) {
|
|
221213
|
+
try {
|
|
221214
|
+
const rows = await this.deps.links.list();
|
|
221215
|
+
for (const row of rows) {
|
|
221216
|
+
const wanted = owners.has(row.id) ? brokerId : "";
|
|
221217
|
+
if (row.mailboxId !== wanted) await this.deps.links.set(row.id, wanted);
|
|
221218
|
+
}
|
|
221219
|
+
for (const owner of owners) if (!rows.some((row) => row.id === owner)) this.deps.logger.warn("email-push: an integration with email-push cameras has no record to link the mailbox from", { meta: {
|
|
221220
|
+
integrationId: owner,
|
|
221221
|
+
brokerId
|
|
221222
|
+
} });
|
|
221223
|
+
return true;
|
|
221224
|
+
} catch (err) {
|
|
221225
|
+
this.deps.logger.warn("email-push: the camera mailbox links could not be written", { meta: {
|
|
221226
|
+
brokerId,
|
|
221227
|
+
error: errMsg(err)
|
|
221228
|
+
} });
|
|
221229
|
+
return false;
|
|
221230
|
+
}
|
|
221231
|
+
}
|
|
221031
221232
|
/**
|
|
221032
221233
|
* What the mailbox retains from BEFORE this subscription is old news (a restart of this addon
|
|
221033
221234
|
* must not re-fire a quarter hour of alarms). Nothing for our recipients is accepted before the
|
|
@@ -221176,6 +221377,126 @@ var EmailPushBridge = class {
|
|
|
221176
221377
|
function pickMailbox(list) {
|
|
221177
221378
|
return list.find((b) => b.id === "smtp-inbound-default")?.id ?? list[0]?.id ?? null;
|
|
221178
221379
|
}
|
|
221380
|
+
var reolinkConnectionsEntryKind = defineEntryKind("connections", {
|
|
221381
|
+
title: "Reolink integrations",
|
|
221382
|
+
schema: entryBody({
|
|
221383
|
+
host: string().nullish(),
|
|
221384
|
+
port: number().int().min(1).max(65535).nullish(),
|
|
221385
|
+
rtspPort: number().int().min(1).max(65535).nullish(),
|
|
221386
|
+
username: string().nullish(),
|
|
221387
|
+
password: string().optional().meta({ secret: true }),
|
|
221388
|
+
transport: _enum(["tcp", "udp"]).nullish(),
|
|
221389
|
+
uid: string().nullish(),
|
|
221390
|
+
debugGeneral: boolean().nullish(),
|
|
221391
|
+
debugSocketLogs: array(ReolinkSocketDebugFlagSchema).nullish(),
|
|
221392
|
+
mailboxId: mailboxLinkField()
|
|
221393
|
+
}),
|
|
221394
|
+
writeTrigger: "an operator adds, edits or removes a Reolink integration, or a Hub device is migrated into one"
|
|
221395
|
+
});
|
|
221396
|
+
/** Every kind this addon declares, keyed by its name. */
|
|
221397
|
+
var reolinkRecordKinds = { connections: reolinkConnectionsEntryKind };
|
|
221398
|
+
/** The record body as the connection form's flat values: no name, no unset keys. */
|
|
221399
|
+
function hubSettingsOf(body) {
|
|
221400
|
+
const out = {};
|
|
221401
|
+
for (const [key, value] of Object.entries(body)) {
|
|
221402
|
+
if (key === "name" || value === null || value === void 0) continue;
|
|
221403
|
+
out[key] = value;
|
|
221404
|
+
}
|
|
221405
|
+
return out;
|
|
221406
|
+
}
|
|
221407
|
+
/**
|
|
221408
|
+
* What a resolved record says about its hub. A keychain that is locked yields a record WITHOUT
|
|
221409
|
+
* its password: that is `password-locked`, never an empty password (D49).
|
|
221410
|
+
*/
|
|
221411
|
+
function hubConnectionOf(resolved) {
|
|
221412
|
+
const read = readHubConnection(hubSettingsOf(resolved.body));
|
|
221413
|
+
return read.kind === "no-password" && resolved.secrets === "unavailable" ? { kind: "password-locked" } : read;
|
|
221414
|
+
}
|
|
221415
|
+
/**
|
|
221416
|
+
* What each enabled integration's RECORD says about its hub: the one reader of the connection.
|
|
221417
|
+
* A record that is absent reads as `no-host` (no session), exactly as an empty settings blob did.
|
|
221418
|
+
*/
|
|
221419
|
+
async function readHubConnections(instances, integrations) {
|
|
221420
|
+
const out = [];
|
|
221421
|
+
for (const integration of integrations) {
|
|
221422
|
+
const resolved = await instances.readResolved(integration.id);
|
|
221423
|
+
out.push({
|
|
221424
|
+
id: integration.id,
|
|
221425
|
+
name: integration.name,
|
|
221426
|
+
read: resolved === null ? { kind: "no-host" } : hubConnectionOf(resolved)
|
|
221427
|
+
});
|
|
221428
|
+
}
|
|
221429
|
+
return out;
|
|
221430
|
+
}
|
|
221431
|
+
function buildReolinkInstances(records, deps) {
|
|
221432
|
+
return new RecordIntegrationInstances(records, reolinkConnectionsEntryKind, {
|
|
221433
|
+
description: {
|
|
221434
|
+
role: "devices",
|
|
221435
|
+
discovery: {
|
|
221436
|
+
mode: "lan",
|
|
221437
|
+
scopedToInstance: false
|
|
221438
|
+
},
|
|
221439
|
+
instanceMode: "multiple",
|
|
221440
|
+
kind: "connection",
|
|
221441
|
+
canTest: false
|
|
221442
|
+
},
|
|
221443
|
+
formSchema: () => buildHubInstanceSchema(),
|
|
221444
|
+
initialBody: (name) => ({ name }),
|
|
221445
|
+
configured: (body) => (body.host ?? "").length === 0 || (body.password ?? "").length > 0,
|
|
221446
|
+
onChanged: () => deps.onChanged()
|
|
221447
|
+
});
|
|
221448
|
+
}
|
|
221449
|
+
/**
|
|
221450
|
+
* The provider handed to the hub: the default integration (no connection) shows no hub form, an
|
|
221451
|
+
* NVR / Home Hub one does, and a create wizard (no id yet) sets up a hub.
|
|
221452
|
+
*/
|
|
221453
|
+
function reolinkInstancesProvider(instances, deps) {
|
|
221454
|
+
return {
|
|
221455
|
+
...instances.toProvider(),
|
|
221456
|
+
instanceFormSchema: async ({ id }) => {
|
|
221457
|
+
if (id === null) return buildHubInstanceSchema();
|
|
221458
|
+
const [evidence, body] = await Promise.all([deps.registryEvidenceOf(id), instances.getResolved(id)]);
|
|
221459
|
+
return evidence !== null && isHubIntegration({
|
|
221460
|
+
originStableId: evidence.originStableId,
|
|
221461
|
+
info: evidence.info,
|
|
221462
|
+
settings: body === null ? {} : hubSettingsOf(body)
|
|
221463
|
+
}) || body === null ? buildHubInstanceSchema() : { sections: [] };
|
|
221464
|
+
}
|
|
221465
|
+
};
|
|
221466
|
+
}
|
|
221467
|
+
/**
|
|
221468
|
+
* Whether an integration IS one NVR / Home Hub (its devices come from the hub, so there is no
|
|
221469
|
+
* manual add by IP). An integration the registry cannot name is not a hub for this question.
|
|
221470
|
+
*/
|
|
221471
|
+
async function integrationIsHub(instances, deps, id) {
|
|
221472
|
+
const [evidence, body] = await Promise.all([deps.registryEvidenceOf(id), instances.getResolved(id)]);
|
|
221473
|
+
if (evidence === null) return false;
|
|
221474
|
+
return isHubIntegration({
|
|
221475
|
+
originStableId: evidence.originStableId,
|
|
221476
|
+
info: evidence.info,
|
|
221477
|
+
settings: body === null ? {} : hubSettingsOf(body)
|
|
221478
|
+
});
|
|
221479
|
+
}
|
|
221480
|
+
//#endregion
|
|
221481
|
+
//#region src/mailbox-link-store.ts
|
|
221482
|
+
var INTEGRATIONS_MAX = 1e3;
|
|
221483
|
+
function mailboxLinkStoreOver(records) {
|
|
221484
|
+
const handle = records.kind(reolinkConnectionsEntryKind);
|
|
221485
|
+
return {
|
|
221486
|
+
list: async () => {
|
|
221487
|
+
return (await handle.query({ limit: INTEGRATIONS_MAX })).records.map((row) => {
|
|
221488
|
+
const linked = row.data[MAILBOX_LINK_FIELD];
|
|
221489
|
+
return {
|
|
221490
|
+
id: row.id,
|
|
221491
|
+
mailboxId: typeof linked === "string" ? linked : ""
|
|
221492
|
+
};
|
|
221493
|
+
});
|
|
221494
|
+
},
|
|
221495
|
+
set: async (integrationId, mailboxId) => {
|
|
221496
|
+
await handle.patch(integrationId, { [MAILBOX_LINK_FIELD]: mailboxId === "" ? null : mailboxId });
|
|
221497
|
+
}
|
|
221498
|
+
};
|
|
221499
|
+
}
|
|
221179
221500
|
//#endregion
|
|
221180
221501
|
//#region src/email-push-removal-hook.ts
|
|
221181
221502
|
/**
|
|
@@ -221602,105 +221923,6 @@ async function moveEmailPushToMailbox(ports) {
|
|
|
221602
221923
|
summary: { moved: true }
|
|
221603
221924
|
};
|
|
221604
221925
|
}
|
|
221605
|
-
var reolinkConnectionsEntryKind = defineEntryKind("connections", {
|
|
221606
|
-
title: "Reolink integrations",
|
|
221607
|
-
schema: entryBody({
|
|
221608
|
-
host: string().nullish(),
|
|
221609
|
-
port: number().int().min(1).max(65535).nullish(),
|
|
221610
|
-
rtspPort: number().int().min(1).max(65535).nullish(),
|
|
221611
|
-
username: string().nullish(),
|
|
221612
|
-
password: string().optional().meta({ secret: true }),
|
|
221613
|
-
transport: _enum(["tcp", "udp"]).nullish(),
|
|
221614
|
-
uid: string().nullish(),
|
|
221615
|
-
debugGeneral: boolean().nullish(),
|
|
221616
|
-
debugSocketLogs: array(ReolinkSocketDebugFlagSchema).nullish()
|
|
221617
|
-
}),
|
|
221618
|
-
writeTrigger: "an operator adds, edits or removes a Reolink integration, or a Hub device is migrated into one"
|
|
221619
|
-
});
|
|
221620
|
-
/** Every kind this addon declares, keyed by its name. */
|
|
221621
|
-
var reolinkRecordKinds = { connections: reolinkConnectionsEntryKind };
|
|
221622
|
-
/** The record body as the connection form's flat values: no name, no unset keys. */
|
|
221623
|
-
function hubSettingsOf(body) {
|
|
221624
|
-
const out = {};
|
|
221625
|
-
for (const [key, value] of Object.entries(body)) {
|
|
221626
|
-
if (key === "name" || value === null || value === void 0) continue;
|
|
221627
|
-
out[key] = value;
|
|
221628
|
-
}
|
|
221629
|
-
return out;
|
|
221630
|
-
}
|
|
221631
|
-
/**
|
|
221632
|
-
* What a resolved record says about its hub. A keychain that is locked yields a record WITHOUT
|
|
221633
|
-
* its password: that is `password-locked`, never an empty password (D49).
|
|
221634
|
-
*/
|
|
221635
|
-
function hubConnectionOf(resolved) {
|
|
221636
|
-
const read = readHubConnection(hubSettingsOf(resolved.body));
|
|
221637
|
-
return read.kind === "no-password" && resolved.secrets === "unavailable" ? { kind: "password-locked" } : read;
|
|
221638
|
-
}
|
|
221639
|
-
/**
|
|
221640
|
-
* What each enabled integration's RECORD says about its hub: the one reader of the connection.
|
|
221641
|
-
* A record that is absent reads as `no-host` (no session), exactly as an empty settings blob did.
|
|
221642
|
-
*/
|
|
221643
|
-
async function readHubConnections(instances, integrations) {
|
|
221644
|
-
const out = [];
|
|
221645
|
-
for (const integration of integrations) {
|
|
221646
|
-
const resolved = await instances.readResolved(integration.id);
|
|
221647
|
-
out.push({
|
|
221648
|
-
id: integration.id,
|
|
221649
|
-
name: integration.name,
|
|
221650
|
-
read: resolved === null ? { kind: "no-host" } : hubConnectionOf(resolved)
|
|
221651
|
-
});
|
|
221652
|
-
}
|
|
221653
|
-
return out;
|
|
221654
|
-
}
|
|
221655
|
-
function buildReolinkInstances(records, deps) {
|
|
221656
|
-
return new RecordIntegrationInstances(records, reolinkConnectionsEntryKind, {
|
|
221657
|
-
description: {
|
|
221658
|
-
role: "devices",
|
|
221659
|
-
discovery: {
|
|
221660
|
-
mode: "lan",
|
|
221661
|
-
scopedToInstance: false
|
|
221662
|
-
},
|
|
221663
|
-
instanceMode: "multiple",
|
|
221664
|
-
kind: "connection",
|
|
221665
|
-
canTest: false
|
|
221666
|
-
},
|
|
221667
|
-
formSchema: () => buildHubInstanceSchema(),
|
|
221668
|
-
initialBody: (name) => ({ name }),
|
|
221669
|
-
configured: (body) => (body.host ?? "").length === 0 || (body.password ?? "").length > 0,
|
|
221670
|
-
onChanged: () => deps.onChanged()
|
|
221671
|
-
});
|
|
221672
|
-
}
|
|
221673
|
-
/**
|
|
221674
|
-
* The provider handed to the hub: the default integration (no connection) shows no hub form, an
|
|
221675
|
-
* NVR / Home Hub one does, and a create wizard (no id yet) sets up a hub.
|
|
221676
|
-
*/
|
|
221677
|
-
function reolinkInstancesProvider(instances, deps) {
|
|
221678
|
-
return {
|
|
221679
|
-
...instances.toProvider(),
|
|
221680
|
-
instanceFormSchema: async ({ id }) => {
|
|
221681
|
-
if (id === null) return buildHubInstanceSchema();
|
|
221682
|
-
const [evidence, body] = await Promise.all([deps.registryEvidenceOf(id), instances.getResolved(id)]);
|
|
221683
|
-
return evidence !== null && isHubIntegration({
|
|
221684
|
-
originStableId: evidence.originStableId,
|
|
221685
|
-
info: evidence.info,
|
|
221686
|
-
settings: body === null ? {} : hubSettingsOf(body)
|
|
221687
|
-
}) || body === null ? buildHubInstanceSchema() : { sections: [] };
|
|
221688
|
-
}
|
|
221689
|
-
};
|
|
221690
|
-
}
|
|
221691
|
-
/**
|
|
221692
|
-
* Whether an integration IS one NVR / Home Hub (its devices come from the hub, so there is no
|
|
221693
|
-
* manual add by IP). An integration the registry cannot name is not a hub for this question.
|
|
221694
|
-
*/
|
|
221695
|
-
async function integrationIsHub(instances, deps, id) {
|
|
221696
|
-
const [evidence, body] = await Promise.all([deps.registryEvidenceOf(id), instances.getResolved(id)]);
|
|
221697
|
-
if (evidence === null) return false;
|
|
221698
|
-
return isHubIntegration({
|
|
221699
|
-
originStableId: evidence.originStableId,
|
|
221700
|
-
info: evidence.info,
|
|
221701
|
-
settings: body === null ? {} : hubSettingsOf(body)
|
|
221702
|
-
});
|
|
221703
|
-
}
|
|
221704
221926
|
//#endregion
|
|
221705
221927
|
//#region src/migrations/integration-rows-to-record.ts
|
|
221706
221928
|
/**
|
|
@@ -222577,10 +222799,16 @@ var ReolinkProviderAddon = class extends BaseDeviceProvider {
|
|
|
222577
222799
|
await this.mailboxPendingState.set(null);
|
|
222578
222800
|
await this.mailboxPendingPasswordState.set("");
|
|
222579
222801
|
}
|
|
222802
|
+
requireRecords() {
|
|
222803
|
+
const records = this.ctx.records;
|
|
222804
|
+
if (records === void 0) throw new Error("provider-reolink: ctx.records is required (hub-only addon)");
|
|
222805
|
+
return records;
|
|
222806
|
+
}
|
|
222580
222807
|
/** The camera mailbox bridge, built once. */
|
|
222581
222808
|
ensureEmailBridge() {
|
|
222582
222809
|
this.emailBridge ??= new EmailPushBridge({
|
|
222583
222810
|
port: createBrokerPort(this.ctx.api),
|
|
222811
|
+
links: mailboxLinkStoreOver(this.requireRecords()),
|
|
222584
222812
|
listCameras: () => this.listReolinkCameras(),
|
|
222585
222813
|
logger: this.ctx.logger.child("email-push"),
|
|
222586
222814
|
pending: {
|
|
@@ -222746,8 +222974,9 @@ var ReolinkProviderAddon = class extends BaseDeviceProvider {
|
|
|
222746
222974
|
if (typeof addonId === "string" && addonId !== this.ctx.id) return;
|
|
222747
222975
|
this.reconcileIntegrations();
|
|
222748
222976
|
};
|
|
222749
|
-
this.
|
|
222750
|
-
|
|
222977
|
+
this.instances?.onSwitched(() => {
|
|
222978
|
+
this.reconcileIntegrations();
|
|
222979
|
+
});
|
|
222751
222980
|
this.ctx.eventBus.subscribe({ category: EventCategory.IntegrationDeleted }, handler);
|
|
222752
222981
|
}
|
|
222753
222982
|
/** The hub box follows its integration's socket. */
|
|
@@ -222991,6 +223220,10 @@ var ReolinkProviderAddon = class extends BaseDeviceProvider {
|
|
|
222991
223220
|
});
|
|
222992
223221
|
this.instances = instances;
|
|
222993
223222
|
this.hubIntegrationProbe = (id) => integrationIsHub(instances, { registryEvidenceOf }, id);
|
|
223223
|
+
this.declareRegistrySwitch({
|
|
223224
|
+
kind: reolinkConnectionsEntryKind,
|
|
223225
|
+
initialBody: (name) => ({ name })
|
|
223226
|
+
});
|
|
222994
223227
|
await this.runMigrations([...defineAddonMigrations(REOLINK_MIGRATIONS, this.migrationPorts()), ...defineAddonMigrations(REOLINK_INTEGRATION_MIGRATIONS, integrationPorts)]);
|
|
222995
223228
|
this.wireEmailBridge();
|
|
222996
223229
|
const wireSleepPushResolvers = (event, via) => {
|