@camstack/addon-provider-hikvision 1.2.183 → 1.2.184
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 +6 -0
- package/dist/addon.js +1016 -769
- package/dist/addon.mjs +1016 -769
- package/package.json +2 -2
package/dist/addon.mjs
CHANGED
|
@@ -5989,7 +5989,7 @@ var ZodIssueCode = {
|
|
|
5989
5989
|
var ZodFirstPartyTypeKind;
|
|
5990
5990
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
5991
5991
|
//#endregion
|
|
5992
|
-
//#region ../types/dist/sleep-
|
|
5992
|
+
//#region ../types/dist/sleep-CmjWurK5.mjs
|
|
5993
5993
|
/**
|
|
5994
5994
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
5995
5995
|
* window to float samples (D455).
|
|
@@ -6673,137 +6673,179 @@ async function runAddonMigrations(host, migrations, logger, options = {}) {
|
|
|
6673
6673
|
blockOwner
|
|
6674
6674
|
};
|
|
6675
6675
|
}
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
|
|
6685
|
-
|
|
6686
|
-
|
|
6687
|
-
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
}
|
|
6692
|
-
return parsed.data;
|
|
6693
|
-
};
|
|
6694
|
-
const set = async (next) => {
|
|
6695
|
-
const validated = deps.schema.parse(next);
|
|
6696
|
-
await deps.write({ [deps.key]: validated });
|
|
6697
|
-
};
|
|
6698
|
-
const update = async (fn) => {
|
|
6699
|
-
await set(fn(await get()));
|
|
6676
|
+
function secretsOverMigrationApi(api) {
|
|
6677
|
+
return {
|
|
6678
|
+
resolve: async (refs) => {
|
|
6679
|
+
const { values } = await api.secrets.resolve({ refs: [...refs] });
|
|
6680
|
+
const out = {};
|
|
6681
|
+
for (const ref of refs) {
|
|
6682
|
+
const value = values[ref];
|
|
6683
|
+
out[ref] = value === null || value === void 0 ? { kind: "missing" } : {
|
|
6684
|
+
kind: "value",
|
|
6685
|
+
value,
|
|
6686
|
+
version: 0
|
|
6687
|
+
};
|
|
6688
|
+
}
|
|
6689
|
+
return out;
|
|
6690
|
+
},
|
|
6691
|
+
delete: async (refs) => (await api.secrets.delete({ refs: [...refs] })).deleted
|
|
6700
6692
|
};
|
|
6693
|
+
}
|
|
6694
|
+
/** The record calls the one-switch migration makes, over the migration API. */
|
|
6695
|
+
function switchRecordsOverMigrationApi(api) {
|
|
6696
|
+
return { kind: (definition) => {
|
|
6697
|
+
const handle = api.records.kind(definition);
|
|
6698
|
+
return {
|
|
6699
|
+
get: (id) => handle.get({ id }),
|
|
6700
|
+
put: (input, opts) => handle.put({
|
|
6701
|
+
...input,
|
|
6702
|
+
...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
|
|
6703
|
+
}),
|
|
6704
|
+
patch: (id, partial) => handle.patch({
|
|
6705
|
+
id,
|
|
6706
|
+
partial
|
|
6707
|
+
})
|
|
6708
|
+
};
|
|
6709
|
+
} };
|
|
6710
|
+
}
|
|
6711
|
+
/** `ctx.records` as the migration API offers it: bind a kind, read and write by id. */
|
|
6712
|
+
function recordsOverMigrationApi(api) {
|
|
6713
|
+
return { kind: (definition) => {
|
|
6714
|
+
const handle = api.records.kind(definition);
|
|
6715
|
+
return {
|
|
6716
|
+
get: (id) => handle.get({ id }),
|
|
6717
|
+
getResolved: (id) => handle.getResolved({ id }),
|
|
6718
|
+
put: (input, opts) => handle.put({
|
|
6719
|
+
...input,
|
|
6720
|
+
...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
|
|
6721
|
+
}),
|
|
6722
|
+
delete: (id) => handle.delete({ id })
|
|
6723
|
+
};
|
|
6724
|
+
} };
|
|
6725
|
+
}
|
|
6726
|
+
function integrationRowsApiOver(api) {
|
|
6701
6727
|
return {
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6728
|
+
list: async () => (await api.integrations.list({})).integrations,
|
|
6729
|
+
readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
|
|
6730
|
+
clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
|
|
6705
6731
|
};
|
|
6706
6732
|
}
|
|
6707
6733
|
/**
|
|
6708
|
-
*
|
|
6709
|
-
*
|
|
6710
|
-
*
|
|
6711
|
-
*
|
|
6712
|
-
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
6713
|
-
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
6714
|
-
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
6715
|
-
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
6716
|
-
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
6717
|
-
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
6718
|
-
*
|
|
6719
|
-
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
6720
|
-
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
6721
|
-
* schema and routes reads/writes through these helpers.
|
|
6722
|
-
*
|
|
6723
|
-
* ## No bare-key fallback — deliberate
|
|
6724
|
-
*
|
|
6725
|
-
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
6726
|
-
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
6727
|
-
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
6728
|
-
* the store is invisible to every node, hub included, so one node's
|
|
6729
|
-
* selection can never leak onto another. (This generalizes the
|
|
6730
|
-
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
6731
|
-
* arbitrary set of per-node field keys.)
|
|
6732
|
-
*
|
|
6733
|
-
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
6734
|
-
* LEAF module: import it via its deep path, never from the root barrel.
|
|
6735
|
-
*/
|
|
6736
|
-
/**
|
|
6737
|
-
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
6738
|
-
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
6739
|
-
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
6740
|
-
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
6734
|
+
* One serial lane per migration API: a log line is delivered after the line before it, so the
|
|
6735
|
+
* order the steps wrote them in is the order the hub reads them in. A delivery that fails
|
|
6736
|
+
* is reported once through the same door; if that fails too nothing is left to tell, and the
|
|
6737
|
+
* line is dropped rather than thrown into a migration step or left as an unhandled rejection.
|
|
6741
6738
|
*/
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
const
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6739
|
+
var lanes = /* @__PURE__ */ new WeakMap();
|
|
6740
|
+
function deliver(api, send) {
|
|
6741
|
+
const next = (lanes.get(api) ?? Promise.resolve()).then(send).then(() => void 0).catch(async (error) => {
|
|
6742
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
6743
|
+
await api.log.warn({ message: `a migration log line could not be delivered: ${reason}` }).catch(() => void 0);
|
|
6744
|
+
});
|
|
6745
|
+
lanes.set(api, next);
|
|
6746
|
+
return next;
|
|
6748
6747
|
}
|
|
6749
|
-
|
|
6750
|
-
|
|
6751
|
-
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
6748
|
+
function warnOver(api) {
|
|
6749
|
+
return (message) => deliver(api, () => api.log.warn({ message }));
|
|
6752
6750
|
}
|
|
6753
|
-
/**
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6751
|
+
/** What the rows-to-records move needs, over the migration API. */
|
|
6752
|
+
function rowsDepsOver(api) {
|
|
6753
|
+
return {
|
|
6754
|
+
api: integrationRowsApiOver(api),
|
|
6755
|
+
records: recordsOverMigrationApi(api),
|
|
6756
|
+
secrets: secretsOverMigrationApi(api),
|
|
6757
|
+
warn: warnOver(api)
|
|
6758
|
+
};
|
|
6761
6759
|
}
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6760
|
+
function defaultIntegrationApiOver(api) {
|
|
6761
|
+
return {
|
|
6762
|
+
...integrationRowsApiOver(api),
|
|
6763
|
+
listDevices: async (addonId) => (await api.devices.list({ addonId })).devices,
|
|
6764
|
+
readDeviceHasConfig: async (deviceId) => (await api.devices.get({ deviceId }))?.hasConfig ?? false,
|
|
6765
|
+
setDeviceIntegrationId: async (deviceId, integrationId) => {
|
|
6766
|
+
await api.devices.setIntegrationId({
|
|
6767
|
+
deviceId,
|
|
6768
|
+
integrationId
|
|
6769
|
+
});
|
|
6770
|
+
},
|
|
6771
|
+
readDeviceIntegrationId: async (deviceId) => (await api.devices.get({ deviceId }))?.integrationId ?? null
|
|
6772
|
+
};
|
|
6773
6773
|
}
|
|
6774
|
-
/**
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
*/
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
|
|
6774
|
+
/** What the rows-to-records move and the device claim need, over the migration API. */
|
|
6775
|
+
function defaultIntegrationDepsOver(api) {
|
|
6776
|
+
return {
|
|
6777
|
+
...rowsDepsOver(api),
|
|
6778
|
+
api: defaultIntegrationApiOver(api),
|
|
6779
|
+
info: (message) => deliver(api, () => api.log.info({ message })),
|
|
6780
|
+
warnDevice: (message, deviceId) => deliver(api, () => api.log.warn({
|
|
6781
|
+
message,
|
|
6782
|
+
tags: { deviceId }
|
|
6783
|
+
}))
|
|
6784
|
+
};
|
|
6785
|
+
}
|
|
6786
|
+
var PREFIX = "records/";
|
|
6787
|
+
/** The base of every records failure. `detail` is the human part of the message. */
|
|
6788
|
+
var RecordsError = class extends Error {
|
|
6789
|
+
code;
|
|
6790
|
+
detail;
|
|
6791
|
+
constructor(code, detail) {
|
|
6792
|
+
super(`${PREFIX}${code}: ${detail}`);
|
|
6793
|
+
this.name = "RecordsError";
|
|
6794
|
+
this.code = code;
|
|
6795
|
+
this.detail = detail;
|
|
6794
6796
|
}
|
|
6795
|
-
|
|
6796
|
-
|
|
6797
|
-
|
|
6797
|
+
};
|
|
6798
|
+
/** A write guarded by `ifRev` found another revision (or an existing row for `ifRev: 0`). */
|
|
6799
|
+
var RevConflictError = class extends RecordsError {
|
|
6800
|
+
constructor(detail) {
|
|
6801
|
+
super("rev-conflict", detail);
|
|
6802
|
+
this.name = "RevConflictError";
|
|
6798
6803
|
}
|
|
6799
|
-
|
|
6804
|
+
};
|
|
6805
|
+
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
6806
|
+
var RecordSecretUnavailableError = class extends RecordsError {
|
|
6807
|
+
constructor(detail) {
|
|
6808
|
+
super("secret-unavailable", detail);
|
|
6809
|
+
this.name = "RecordSecretUnavailableError";
|
|
6810
|
+
}
|
|
6811
|
+
};
|
|
6812
|
+
var InvalidRecordError = class extends RecordsError {
|
|
6813
|
+
constructor(detail) {
|
|
6814
|
+
super("invalid-record", detail);
|
|
6815
|
+
this.name = "InvalidRecordError";
|
|
6816
|
+
}
|
|
6817
|
+
};
|
|
6818
|
+
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
6819
|
+
var DeclarationRefusedError = class extends RecordsError {
|
|
6820
|
+
constructor(detail) {
|
|
6821
|
+
super("declaration-refused", detail);
|
|
6822
|
+
this.name = "DeclarationRefusedError";
|
|
6823
|
+
}
|
|
6824
|
+
};
|
|
6825
|
+
function linkTargetOf(meta) {
|
|
6826
|
+
if (typeof meta !== "object" || meta === null) return void 0;
|
|
6827
|
+
const link = Reflect.get(meta, "link");
|
|
6828
|
+
const parsed = LinkTargetSchema.safeParse(link);
|
|
6829
|
+
return parsed.success ? parsed.data : void 0;
|
|
6830
|
+
}
|
|
6831
|
+
var LinkTargetSchema = object({
|
|
6832
|
+
cap: string().min(1),
|
|
6833
|
+
kind: string().min(1).optional()
|
|
6834
|
+
});
|
|
6835
|
+
/** The links a kind declares, read from the meta of its body fields. */
|
|
6836
|
+
function linksOfKind(kind) {
|
|
6837
|
+
const schema = kind.schema;
|
|
6838
|
+
if (!(schema instanceof ZodObject)) return [];
|
|
6839
|
+
const links = [];
|
|
6840
|
+
for (const [field, fieldSchema] of Object.entries(schema.shape)) {
|
|
6841
|
+
const to = linkTargetOf(globalRegistry.get(fieldSchema));
|
|
6842
|
+
if (to !== void 0) links.push({
|
|
6843
|
+
field,
|
|
6844
|
+
to
|
|
6845
|
+
});
|
|
6846
|
+
}
|
|
6847
|
+
return links;
|
|
6800
6848
|
}
|
|
6801
|
-
/** Every scope, in the order the guard and the docs list them. */
|
|
6802
|
-
var SCOPED_SETTINGS_SCOPES = [
|
|
6803
|
-
"cluster",
|
|
6804
|
-
"device-defaults",
|
|
6805
|
-
"node"
|
|
6806
|
-
];
|
|
6807
6849
|
/**
|
|
6808
6850
|
* The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
|
|
6809
6851
|
*
|
|
@@ -6938,6 +6980,652 @@ function parseSecretRef(ref) {
|
|
|
6938
6980
|
fieldPath
|
|
6939
6981
|
};
|
|
6940
6982
|
}
|
|
6983
|
+
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
6984
|
+
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
6985
|
+
var RECORD_DATABASES = ["settings", "events"];
|
|
6986
|
+
/** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
|
|
6987
|
+
var RECORD_CLASSES = [
|
|
6988
|
+
"config",
|
|
6989
|
+
"ledger",
|
|
6990
|
+
"audit",
|
|
6991
|
+
"mirror",
|
|
6992
|
+
"ephemeral"
|
|
6993
|
+
];
|
|
6994
|
+
var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
6995
|
+
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
6996
|
+
var RECORD_BATCH_MAX = 1e3;
|
|
6997
|
+
var RECORD_QUERY_MAX = 1e3;
|
|
6998
|
+
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
6999
|
+
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
7000
|
+
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
7001
|
+
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
7002
|
+
/**
|
|
7003
|
+
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
7004
|
+
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
7005
|
+
* (`auth.accessToken`, `headers[].value`).
|
|
7006
|
+
*
|
|
7007
|
+
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
7008
|
+
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
7009
|
+
* key releases exactly that key's secret.
|
|
7010
|
+
*
|
|
7011
|
+
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
7012
|
+
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
7013
|
+
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
7014
|
+
* leaf names its element: `headers[X-Api].value`.
|
|
7015
|
+
*
|
|
7016
|
+
* Pure and browser-safe. Nothing here mutates: every transform returns a new value.
|
|
7017
|
+
*/
|
|
7018
|
+
/** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
|
|
7019
|
+
function parseSecretPath(path) {
|
|
7020
|
+
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
7021
|
+
return path.split(".").map((raw) => {
|
|
7022
|
+
const each = raw.endsWith("[]");
|
|
7023
|
+
const map = raw.endsWith("{}");
|
|
7024
|
+
const key = each || map ? raw.slice(0, -2) : raw;
|
|
7025
|
+
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
7026
|
+
return {
|
|
7027
|
+
key,
|
|
7028
|
+
each,
|
|
7029
|
+
map
|
|
7030
|
+
};
|
|
7031
|
+
});
|
|
7032
|
+
}
|
|
7033
|
+
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
7034
|
+
function secretArrayPrefixes(path) {
|
|
7035
|
+
const segments = parseSecretPath(path);
|
|
7036
|
+
const prefixes = [];
|
|
7037
|
+
const walked = [];
|
|
7038
|
+
for (const segment of segments) {
|
|
7039
|
+
walked.push(segment.key);
|
|
7040
|
+
if (segment.each) prefixes.push(walked.join("."));
|
|
7041
|
+
}
|
|
7042
|
+
return prefixes;
|
|
7043
|
+
}
|
|
7044
|
+
function isRecord$6(value) {
|
|
7045
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7046
|
+
}
|
|
7047
|
+
function elementId(element, idKey, declared, prefix) {
|
|
7048
|
+
const id = isRecord$6(element) ? element[idKey] : void 0;
|
|
7049
|
+
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`);
|
|
7050
|
+
return id;
|
|
7051
|
+
}
|
|
7052
|
+
/**
|
|
7053
|
+
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
7054
|
+
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
7055
|
+
* result is a new body, `data` is untouched.
|
|
7056
|
+
*/
|
|
7057
|
+
var REMOVE_LEAF = Symbol("remove-leaf");
|
|
7058
|
+
function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
|
|
7059
|
+
if (!isRecord$6(node)) return node;
|
|
7060
|
+
const segment = segments[index];
|
|
7061
|
+
if (segment === void 0) return node;
|
|
7062
|
+
if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
|
|
7063
|
+
const child = node[segment.key];
|
|
7064
|
+
const keys = [...walkedKeys, segment.key];
|
|
7065
|
+
const last = index === segments.length - 1;
|
|
7066
|
+
if (segment.each) {
|
|
7067
|
+
if (!Array.isArray(child)) return node;
|
|
7068
|
+
const prefix = keys.join(".");
|
|
7069
|
+
const idKey = arrayKeys[prefix];
|
|
7070
|
+
if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
|
|
7071
|
+
const mapped = child.map((element) => {
|
|
7072
|
+
const id = elementId(element, idKey, declared, prefix);
|
|
7073
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
|
|
7074
|
+
return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
|
|
7075
|
+
});
|
|
7076
|
+
return {
|
|
7077
|
+
...node,
|
|
7078
|
+
[segment.key]: mapped
|
|
7079
|
+
};
|
|
7080
|
+
}
|
|
7081
|
+
if (segment.map) {
|
|
7082
|
+
if (!isRecord$6(child)) return node;
|
|
7083
|
+
const kept = Object.entries(child).map(([mapKey, value]) => {
|
|
7084
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
|
|
7085
|
+
if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
|
|
7086
|
+
return [mapKey, visit({
|
|
7087
|
+
declared,
|
|
7088
|
+
concrete,
|
|
7089
|
+
value
|
|
7090
|
+
})];
|
|
7091
|
+
}).filter(([, value]) => value !== REMOVE_LEAF);
|
|
7092
|
+
return {
|
|
7093
|
+
...node,
|
|
7094
|
+
[segment.key]: Object.fromEntries(kept)
|
|
7095
|
+
};
|
|
7096
|
+
}
|
|
7097
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
7098
|
+
if (last) {
|
|
7099
|
+
const replacement = visit({
|
|
7100
|
+
declared,
|
|
7101
|
+
concrete,
|
|
7102
|
+
value: child
|
|
7103
|
+
});
|
|
7104
|
+
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
7105
|
+
return {
|
|
7106
|
+
...node,
|
|
7107
|
+
[segment.key]: replacement
|
|
7108
|
+
};
|
|
7109
|
+
}
|
|
7110
|
+
return {
|
|
7111
|
+
...node,
|
|
7112
|
+
[segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
|
|
7113
|
+
};
|
|
7114
|
+
}
|
|
7115
|
+
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
7116
|
+
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
7117
|
+
let current = data;
|
|
7118
|
+
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
7119
|
+
return current;
|
|
7120
|
+
}
|
|
7121
|
+
/** Every present secret leaf, read-only. */
|
|
7122
|
+
function collectSecretLeaves(data, paths, arrayKeys) {
|
|
7123
|
+
const found = [];
|
|
7124
|
+
mapSecretLeaves(data, paths, arrayKeys, (leaf) => {
|
|
7125
|
+
found.push(leaf);
|
|
7126
|
+
return leaf.value;
|
|
7127
|
+
});
|
|
7128
|
+
return found;
|
|
7129
|
+
}
|
|
7130
|
+
/**
|
|
7131
|
+
* The keychain collection name a kind's secrets live under. Prefixed so a
|
|
7132
|
+
* record's refs never collide with the refs a legacy collection of the same name
|
|
7133
|
+
* already holds during an adoption.
|
|
7134
|
+
*/
|
|
7135
|
+
function recordSecretCollection(kind) {
|
|
7136
|
+
return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
|
|
7137
|
+
}
|
|
7138
|
+
/** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
|
|
7139
|
+
function recordSecretRef(owner, kind, rowId, concretePath) {
|
|
7140
|
+
return buildSecretRef({
|
|
7141
|
+
owner,
|
|
7142
|
+
scope: {
|
|
7143
|
+
kind: "row",
|
|
7144
|
+
collection: recordSecretCollection(kind),
|
|
7145
|
+
rowId
|
|
7146
|
+
},
|
|
7147
|
+
fieldPath: concretePath
|
|
7148
|
+
});
|
|
7149
|
+
}
|
|
7150
|
+
/**
|
|
7151
|
+
* A stored secret, as an admin read shows it: a VIEW naming the row's own
|
|
7152
|
+
* keychain ref (`set: true`), never the value and no longer the bare redaction
|
|
7153
|
+
* token. The form hands it to the secret field, which reveals the value by ref
|
|
7154
|
+
* through the audited `keychain-admin.reveal`; sent back untouched it keeps the
|
|
7155
|
+
* stored secret (the records door reads a view as KEEP).
|
|
7156
|
+
*
|
|
7157
|
+
* ONE implementation for the entries service and for every addon that serves
|
|
7158
|
+
* its own instances (`RecordIntegrationInstances`).
|
|
7159
|
+
*/
|
|
7160
|
+
function isRecord$5(value) {
|
|
7161
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7162
|
+
}
|
|
7163
|
+
function secretViewsOf(owner, kind, id, decl, data) {
|
|
7164
|
+
if (decl.secretPaths.length === 0) return data;
|
|
7165
|
+
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
7166
|
+
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
7167
|
+
return {
|
|
7168
|
+
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
7169
|
+
v: 1,
|
|
7170
|
+
set: true
|
|
7171
|
+
};
|
|
7172
|
+
});
|
|
7173
|
+
return isRecord$5(shown) ? shown : data;
|
|
7174
|
+
}
|
|
7175
|
+
/** The most instances one addon lists (an integrations page, not a table). */
|
|
7176
|
+
var INSTANCES_LIST_MAX = 1e3;
|
|
7177
|
+
/**
|
|
7178
|
+
* The ONE reader of an instance's switch (D996): an absent field means on, so a row written
|
|
7179
|
+
* before the field existed needs no migration. Every consumer of an instance body asks this.
|
|
7180
|
+
*/
|
|
7181
|
+
function isInstanceEnabled(body) {
|
|
7182
|
+
return body.enabled !== false;
|
|
7183
|
+
}
|
|
7184
|
+
/** The body key of the switch; only {@link RecordIntegrationInstances.setInstanceEnabled} writes it. */
|
|
7185
|
+
var SWITCH_KEY = "enabled";
|
|
7186
|
+
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
7187
|
+
function topLevelSecretKeys(paths) {
|
|
7188
|
+
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
7189
|
+
}
|
|
7190
|
+
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
7191
|
+
function secretMapKeys(paths) {
|
|
7192
|
+
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
7193
|
+
}
|
|
7194
|
+
/**
|
|
7195
|
+
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
7196
|
+
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
7197
|
+
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
7198
|
+
*/
|
|
7199
|
+
function secretMapPatch(value) {
|
|
7200
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
7201
|
+
const out = {};
|
|
7202
|
+
for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
|
|
7203
|
+
else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
|
|
7204
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
7205
|
+
}
|
|
7206
|
+
var RecordIntegrationInstances = class {
|
|
7207
|
+
records;
|
|
7208
|
+
kind;
|
|
7209
|
+
hooks;
|
|
7210
|
+
handle;
|
|
7211
|
+
secretKeys;
|
|
7212
|
+
secretMaps;
|
|
7213
|
+
nameField;
|
|
7214
|
+
switchListeners = /* @__PURE__ */ new Set();
|
|
7215
|
+
constructor(records, kind, hooks) {
|
|
7216
|
+
this.records = records;
|
|
7217
|
+
this.kind = kind;
|
|
7218
|
+
this.hooks = hooks;
|
|
7219
|
+
this.handle = records.kind(kind);
|
|
7220
|
+
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
7221
|
+
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
7222
|
+
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
7223
|
+
}
|
|
7224
|
+
/**
|
|
7225
|
+
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
7226
|
+
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
7227
|
+
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
7228
|
+
*/
|
|
7229
|
+
async readResolved(id) {
|
|
7230
|
+
try {
|
|
7231
|
+
const record = await this.handle.getResolved(id);
|
|
7232
|
+
return record === null ? null : {
|
|
7233
|
+
id,
|
|
7234
|
+
body: record.data,
|
|
7235
|
+
enabled: isInstanceEnabled(record.data),
|
|
7236
|
+
secrets: "resolved"
|
|
7237
|
+
};
|
|
7238
|
+
} catch (err) {
|
|
7239
|
+
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
7240
|
+
const stored = await this.handle.get(id);
|
|
7241
|
+
if (stored === null) return null;
|
|
7242
|
+
return {
|
|
7243
|
+
id,
|
|
7244
|
+
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
7245
|
+
enabled: isInstanceEnabled(stored.data),
|
|
7246
|
+
secrets: "unavailable"
|
|
7247
|
+
};
|
|
7248
|
+
}
|
|
7249
|
+
}
|
|
7250
|
+
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
7251
|
+
async getResolved(id) {
|
|
7252
|
+
return (await this.readResolved(id))?.body ?? null;
|
|
7253
|
+
}
|
|
7254
|
+
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
7255
|
+
async listResolved() {
|
|
7256
|
+
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
7257
|
+
const out = [];
|
|
7258
|
+
for (const record of page.records) {
|
|
7259
|
+
const read = await this.readResolved(record.id);
|
|
7260
|
+
if (read !== null) out.push(read);
|
|
7261
|
+
}
|
|
7262
|
+
return out;
|
|
7263
|
+
}
|
|
7264
|
+
viewOf(record) {
|
|
7265
|
+
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
7266
|
+
const rawName = record.data[this.nameField];
|
|
7267
|
+
const kind = this.hooks.kindOf?.(record.data);
|
|
7268
|
+
const health = this.hooks.health?.(record.data, record.id);
|
|
7269
|
+
return {
|
|
7270
|
+
id: record.id,
|
|
7271
|
+
name: typeof rawName === "string" ? rawName : record.id,
|
|
7272
|
+
configured: this.hooks.configured(record.data),
|
|
7273
|
+
enabled: isInstanceEnabled(record.data),
|
|
7274
|
+
formValues: shown,
|
|
7275
|
+
...kind !== void 0 ? { kind } : {},
|
|
7276
|
+
...health?.status !== void 0 ? { status: health.status } : {},
|
|
7277
|
+
...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
|
|
7278
|
+
};
|
|
7279
|
+
}
|
|
7280
|
+
describe = async () => {
|
|
7281
|
+
const declared = linksOfKind(this.kind);
|
|
7282
|
+
const links = this.hooks.description.links !== void 0 || declared.length === 0 ? {} : { links: declared.map((link) => ({
|
|
7283
|
+
kind: this.kind.name,
|
|
7284
|
+
field: link.field,
|
|
7285
|
+
to: link.to
|
|
7286
|
+
})) };
|
|
7287
|
+
return {
|
|
7288
|
+
...this.hooks.description,
|
|
7289
|
+
...links,
|
|
7290
|
+
...this.hooks.mintId === void 0 ? {} : { mintsId: true }
|
|
7291
|
+
};
|
|
7292
|
+
};
|
|
7293
|
+
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
7294
|
+
listInstances = async () => {
|
|
7295
|
+
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
7296
|
+
};
|
|
7297
|
+
getInstance = async ({ id }) => {
|
|
7298
|
+
const record = await this.handle.get(id);
|
|
7299
|
+
return record === null ? null : this.viewOf(record);
|
|
7300
|
+
};
|
|
7301
|
+
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
7302
|
+
createInstance = async ({ id, name, kind, values }) => {
|
|
7303
|
+
const minted = id ?? this.hooks.mintId?.({
|
|
7304
|
+
name,
|
|
7305
|
+
...kind !== void 0 ? { kind } : {}
|
|
7306
|
+
});
|
|
7307
|
+
if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
|
|
7308
|
+
await this.handle.put({
|
|
7309
|
+
id: minted,
|
|
7310
|
+
data: this.hooks.initialBody(name, kind)
|
|
7311
|
+
}, { ifRev: 0 });
|
|
7312
|
+
const patch = this.patchOf(values ?? {});
|
|
7313
|
+
if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
|
|
7314
|
+
await this.hooks.onChanged?.(minted, "created");
|
|
7315
|
+
return { id: minted };
|
|
7316
|
+
};
|
|
7317
|
+
updateInstance = async ({ id, name, values }) => {
|
|
7318
|
+
const patch = this.patchOf(values);
|
|
7319
|
+
if (name !== void 0) patch[this.nameField] = name;
|
|
7320
|
+
await this.handle.patch(id, patch);
|
|
7321
|
+
await this.hooks.onChanged?.(id, "updated");
|
|
7322
|
+
return { ok: true };
|
|
7323
|
+
};
|
|
7324
|
+
/** The record patch a form `values` object means: secrets kept, cleared or replaced. */
|
|
7325
|
+
patchOf(values) {
|
|
7326
|
+
const patch = {};
|
|
7327
|
+
for (const [key, value] of Object.entries(values)) {
|
|
7328
|
+
if (value === void 0) continue;
|
|
7329
|
+
if (key === "enabled") continue;
|
|
7330
|
+
if (this.secretMaps.has(key)) {
|
|
7331
|
+
const entries = secretMapPatch(value);
|
|
7332
|
+
if (entries !== null) patch[key] = entries;
|
|
7333
|
+
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
7334
|
+
else if (isSecretClear(value)) patch[key] = null;
|
|
7335
|
+
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
7336
|
+
}
|
|
7337
|
+
return patch;
|
|
7338
|
+
}
|
|
7339
|
+
/**
|
|
7340
|
+
* Listen to the switch of ANY instance of this helper (in the process that serves it). The
|
|
7341
|
+
* durable replacement of the `integration.enabled` / `integration.disabled` events (D8): the
|
|
7342
|
+
* addon reconciles from the record, whichever way it flipped.
|
|
7343
|
+
*/
|
|
7344
|
+
onSwitched(listener) {
|
|
7345
|
+
this.switchListeners.add(listener);
|
|
7346
|
+
}
|
|
7347
|
+
/**
|
|
7348
|
+
* The ONE writer of the switch (D996, D1014): the record body's `enabled`, for every role. A
|
|
7349
|
+
* configured thing is an instance, so an id with no record yet (a default integration that was
|
|
7350
|
+
* never configured) gets its record from `initialBody` before the switch is written.
|
|
7351
|
+
*/
|
|
7352
|
+
setInstanceEnabled = async ({ id, enabled }) => {
|
|
7353
|
+
if (await this.handle.get(id) === null) await this.handle.put({
|
|
7354
|
+
id,
|
|
7355
|
+
data: this.hooks.initialBody(id)
|
|
7356
|
+
}, { ifRev: 0 });
|
|
7357
|
+
await this.handle.patch(id, { [SWITCH_KEY]: enabled });
|
|
7358
|
+
await this.hooks.onChanged?.(id, "enabled");
|
|
7359
|
+
for (const listener of this.switchListeners) await listener(id, enabled);
|
|
7360
|
+
return { ok: true };
|
|
7361
|
+
};
|
|
7362
|
+
/** The row and its keychain refs go together (the records door). */
|
|
7363
|
+
deleteInstance = async ({ id }) => {
|
|
7364
|
+
await this.handle.delete(id);
|
|
7365
|
+
await this.hooks.onChanged?.(id, "deleted");
|
|
7366
|
+
return { ok: true };
|
|
7367
|
+
};
|
|
7368
|
+
testInstance = async (input) => {
|
|
7369
|
+
if (this.hooks.test === void 0) return {
|
|
7370
|
+
success: false,
|
|
7371
|
+
status: "unsupported",
|
|
7372
|
+
error: "This integration declares no connection test"
|
|
7373
|
+
};
|
|
7374
|
+
return this.hooks.test(input);
|
|
7375
|
+
};
|
|
7376
|
+
/** The flat provider object to hand to `registerProvider`. */
|
|
7377
|
+
toProvider() {
|
|
7378
|
+
return {
|
|
7379
|
+
describe: this.describe,
|
|
7380
|
+
instanceFormSchema: this.instanceFormSchema,
|
|
7381
|
+
listInstances: this.listInstances,
|
|
7382
|
+
getInstance: this.getInstance,
|
|
7383
|
+
createInstance: this.createInstance,
|
|
7384
|
+
updateInstance: this.updateInstance,
|
|
7385
|
+
setInstanceEnabled: this.setInstanceEnabled,
|
|
7386
|
+
deleteInstance: this.deleteInstance,
|
|
7387
|
+
testInstance: this.testInstance
|
|
7388
|
+
};
|
|
7389
|
+
}
|
|
7390
|
+
};
|
|
7391
|
+
/**
|
|
7392
|
+
* The one-switch migration (epic #440, step 3). An integration's on/off state used to live in the
|
|
7393
|
+
* registry's `enabled` column for a device addon; it now lives only in the instance record's
|
|
7394
|
+
* body (`enabled`, D1007 superseded). This moves a registry `enabled = false` into the body, once.
|
|
7395
|
+
*
|
|
7396
|
+
* For every registry row of the addon that is OFF:
|
|
7397
|
+
* - no record under its id: the record is created from `initialBody(name)` with `enabled: false`
|
|
7398
|
+
* (a default integration that never had settings, Reolink's among them);
|
|
7399
|
+
* - a record whose body states no `enabled`: `enabled: false` is written into it;
|
|
7400
|
+
* - a record that already states `enabled` (either way) is the newer truth and is left alone.
|
|
7401
|
+
* A row that is ON writes nothing: an absent field reads as on. A rerun finds every off row with
|
|
7402
|
+
* a stated switch and does nothing, so nothing switched off comes back on and nothing switched on
|
|
7403
|
+
* goes off. The registry column itself is neither read afterwards nor written; its drop is step 5.
|
|
7404
|
+
*
|
|
7405
|
+
* It runs in the addon process, BEFORE the addon registers its `integration-instances` provider,
|
|
7406
|
+
* which is also why `integrations.list` still answers the stored column at that point.
|
|
7407
|
+
*/
|
|
7408
|
+
function registrySwitchToBodyId(addonId, date) {
|
|
7409
|
+
return `${addonId}/${date}-registry-switch-to-body`;
|
|
7410
|
+
}
|
|
7411
|
+
async function moveRegistrySwitchToBody(ports, spec) {
|
|
7412
|
+
const rows = await ports.listIntegrations(spec.addonId);
|
|
7413
|
+
let created = 0;
|
|
7414
|
+
let switched = 0;
|
|
7415
|
+
let kept = 0;
|
|
7416
|
+
for (const row of rows) {
|
|
7417
|
+
if (row.enabled) continue;
|
|
7418
|
+
const body = await ports.readBody(row.id);
|
|
7419
|
+
if (body === null) {
|
|
7420
|
+
if (await ports.createRecord(row.id, {
|
|
7421
|
+
...spec.initialBody(row.name),
|
|
7422
|
+
["enabled"]: false
|
|
7423
|
+
}) === "created") created += 1;
|
|
7424
|
+
else kept += 1;
|
|
7425
|
+
continue;
|
|
7426
|
+
}
|
|
7427
|
+
if ("enabled" in body) {
|
|
7428
|
+
kept += 1;
|
|
7429
|
+
continue;
|
|
7430
|
+
}
|
|
7431
|
+
await ports.switchOff(row.id);
|
|
7432
|
+
switched += 1;
|
|
7433
|
+
}
|
|
7434
|
+
const summary = {
|
|
7435
|
+
integrations: rows.length,
|
|
7436
|
+
off: rows.filter((r) => !r.enabled).length,
|
|
7437
|
+
created,
|
|
7438
|
+
switched,
|
|
7439
|
+
kept
|
|
7440
|
+
};
|
|
7441
|
+
return created === 0 && switched === 0 ? {
|
|
7442
|
+
outcome: "already-done",
|
|
7443
|
+
summary
|
|
7444
|
+
} : {
|
|
7445
|
+
outcome: "done",
|
|
7446
|
+
summary
|
|
7447
|
+
};
|
|
7448
|
+
}
|
|
7449
|
+
/** A migration entry: an addon states its kind and how a new body starts, nothing else. */
|
|
7450
|
+
function registrySwitchToBodyMigration(spec) {
|
|
7451
|
+
return {
|
|
7452
|
+
meta: {
|
|
7453
|
+
id: registrySwitchToBodyId(spec.addonId, spec.date),
|
|
7454
|
+
owner: spec.addonId,
|
|
7455
|
+
level: "addon-state",
|
|
7456
|
+
seq: spec.seq,
|
|
7457
|
+
dependsOn: [],
|
|
7458
|
+
store: "settings",
|
|
7459
|
+
scope: "cluster",
|
|
7460
|
+
onFailure: "block-owner",
|
|
7461
|
+
bodyKind: "procedure",
|
|
7462
|
+
description: "Move the registry enabled flag of every switched-off integration into its instance record body, creating the record when there is none",
|
|
7463
|
+
fixtureMark: "enabled"
|
|
7464
|
+
},
|
|
7465
|
+
procedure: (ports) => moveRegistrySwitchToBody(ports, {
|
|
7466
|
+
addonId: spec.addonId,
|
|
7467
|
+
initialBody: spec.initialBody
|
|
7468
|
+
})
|
|
7469
|
+
};
|
|
7470
|
+
}
|
|
7471
|
+
/** The hub and records sides of {@link registrySwitchToBodyMigration}. */
|
|
7472
|
+
function registrySwitchPortsOver(deps) {
|
|
7473
|
+
const handle = deps.records.kind({
|
|
7474
|
+
name: deps.kind.name,
|
|
7475
|
+
declaration: deps.kind.declaration,
|
|
7476
|
+
schema: record(string(), unknown())
|
|
7477
|
+
});
|
|
7478
|
+
return {
|
|
7479
|
+
listIntegrations: async (addonId) => (await deps.api.list()).filter((i) => i.addonId === addonId).map((i) => ({
|
|
7480
|
+
id: i.id,
|
|
7481
|
+
name: i.name,
|
|
7482
|
+
enabled: i.enabled !== false
|
|
7483
|
+
})),
|
|
7484
|
+
readBody: async (id) => (await handle.get(id))?.data ?? null,
|
|
7485
|
+
createRecord: async (id, body) => {
|
|
7486
|
+
if (await handle.get(id) !== null) return "exists";
|
|
7487
|
+
await handle.put({
|
|
7488
|
+
id,
|
|
7489
|
+
data: body
|
|
7490
|
+
}, { ifRev: 0 });
|
|
7491
|
+
return "created";
|
|
7492
|
+
},
|
|
7493
|
+
switchOff: async (id) => {
|
|
7494
|
+
await handle.patch(id, { [SWITCH_KEY]: false });
|
|
7495
|
+
}
|
|
7496
|
+
};
|
|
7497
|
+
}
|
|
7498
|
+
/**
|
|
7499
|
+
* Build a {@link DurableState} over a single store key. Transport-agnostic:
|
|
7500
|
+
* `read`/`write` are the addon-store or device-store accessors. The whole
|
|
7501
|
+
* validated value round-trips on every read/write — the schema is the
|
|
7502
|
+
* single source of truth for what is persisted, so no hand-listed field
|
|
7503
|
+
* set can drop a key on save.
|
|
7504
|
+
*/
|
|
7505
|
+
function createDurableState(deps) {
|
|
7506
|
+
const get = async () => {
|
|
7507
|
+
const raw = (await deps.read())[deps.key];
|
|
7508
|
+
if (raw === void 0) return deps.fallback;
|
|
7509
|
+
const parsed = deps.schema.safeParse(raw);
|
|
7510
|
+
if (!parsed.success) {
|
|
7511
|
+
deps.onParseError?.(deps.key, parsed.error);
|
|
7512
|
+
return deps.fallback;
|
|
7513
|
+
}
|
|
7514
|
+
return parsed.data;
|
|
7515
|
+
};
|
|
7516
|
+
const set = async (next) => {
|
|
7517
|
+
const validated = deps.schema.parse(next);
|
|
7518
|
+
await deps.write({ [deps.key]: validated });
|
|
7519
|
+
};
|
|
7520
|
+
const update = async (fn) => {
|
|
7521
|
+
await set(fn(await get()));
|
|
7522
|
+
};
|
|
7523
|
+
return {
|
|
7524
|
+
get,
|
|
7525
|
+
set,
|
|
7526
|
+
update
|
|
7527
|
+
};
|
|
7528
|
+
}
|
|
7529
|
+
/**
|
|
7530
|
+
* Per-node scoping for the shared addon-settings blob.
|
|
7531
|
+
*
|
|
7532
|
+
* An addon's settings store is hub-central (the `addon-settings` cap is
|
|
7533
|
+
* hub-routed — the hub instance answers for every node), so fields whose
|
|
7534
|
+
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
7535
|
+
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
7536
|
+
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
7537
|
+
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
7538
|
+
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
7539
|
+
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
7540
|
+
*
|
|
7541
|
+
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
7542
|
+
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
7543
|
+
* schema and routes reads/writes through these helpers.
|
|
7544
|
+
*
|
|
7545
|
+
* ## No bare-key fallback — deliberate
|
|
7546
|
+
*
|
|
7547
|
+
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
7548
|
+
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
7549
|
+
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
7550
|
+
* the store is invisible to every node, hub included, so one node's
|
|
7551
|
+
* selection can never leak onto another. (This generalizes the
|
|
7552
|
+
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
7553
|
+
* arbitrary set of per-node field keys.)
|
|
7554
|
+
*
|
|
7555
|
+
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
7556
|
+
* LEAF module: import it via its deep path, never from the root barrel.
|
|
7557
|
+
*/
|
|
7558
|
+
/**
|
|
7559
|
+
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
7560
|
+
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
7561
|
+
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
7562
|
+
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
7563
|
+
*/
|
|
7564
|
+
function normalizeNodeId(raw) {
|
|
7565
|
+
if (raw === void 0 || raw === null || raw === "") return "hub";
|
|
7566
|
+
const slashIdx = raw.indexOf("/");
|
|
7567
|
+
if (slashIdx < 0) return raw;
|
|
7568
|
+
const bare = raw.slice(0, slashIdx);
|
|
7569
|
+
return bare === "" ? "hub" : bare;
|
|
7570
|
+
}
|
|
7571
|
+
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
7572
|
+
function nodeScopedKey(base, nodeId) {
|
|
7573
|
+
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
7574
|
+
}
|
|
7575
|
+
/**
|
|
7576
|
+
* Read a node's value for a per-node field from the raw shared store:
|
|
7577
|
+
* the node-scoped key when present, otherwise `undefined`.
|
|
7578
|
+
* Deliberately NO bare-key fallback (see module doc) — the caller lets the
|
|
7579
|
+
* schema `default` win on `undefined`.
|
|
7580
|
+
*/
|
|
7581
|
+
function readNodeValue(store, base, nodeId) {
|
|
7582
|
+
return store[nodeScopedKey(base, nodeId)];
|
|
7583
|
+
}
|
|
7584
|
+
/**
|
|
7585
|
+
* Re-map a UI/settings patch so every bare perNode field persists under the
|
|
7586
|
+
* TARGET node's scoped key; all other keys pass through unchanged. Used on
|
|
7587
|
+
* the write path so a save for one node never clobbers another node's value
|
|
7588
|
+
* (and the bare key is never written). Returns a new object — the input
|
|
7589
|
+
* patch is not mutated.
|
|
7590
|
+
*/
|
|
7591
|
+
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
7592
|
+
const out = {};
|
|
7593
|
+
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
7594
|
+
return out;
|
|
7595
|
+
}
|
|
7596
|
+
/**
|
|
7597
|
+
* Project the raw shared store onto the bare schema keys for ONE node so a
|
|
7598
|
+
* UI schema (whose field keys are bare) hydrates from that node's own
|
|
7599
|
+
* values:
|
|
7600
|
+
*
|
|
7601
|
+
* - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
|
|
7602
|
+
* - Every bare perNode key is dropped from the pass-through (a stray bare
|
|
7603
|
+
* legacy key must never hydrate any node — no bare fallback).
|
|
7604
|
+
* - THIS node's effective value ({@link readNodeValue}) is then laid onto
|
|
7605
|
+
* each bare perNode key; when the node has no scoped key the bare key is
|
|
7606
|
+
* left ABSENT so the field's schema `default` wins.
|
|
7607
|
+
*
|
|
7608
|
+
* Returns a new object — the input store is not mutated.
|
|
7609
|
+
*/
|
|
7610
|
+
function projectStore(store, perNodeKeys, nodeId) {
|
|
7611
|
+
const out = {};
|
|
7612
|
+
for (const [key, value] of Object.entries(store)) {
|
|
7613
|
+
if (key.includes("@")) continue;
|
|
7614
|
+
if (perNodeKeys.has(key)) continue;
|
|
7615
|
+
out[key] = value;
|
|
7616
|
+
}
|
|
7617
|
+
for (const base of perNodeKeys) {
|
|
7618
|
+
const value = readNodeValue(store, base, nodeId);
|
|
7619
|
+
if (value !== void 0) out[base] = value;
|
|
7620
|
+
}
|
|
7621
|
+
return out;
|
|
7622
|
+
}
|
|
7623
|
+
/** Every scope, in the order the guard and the docs list them. */
|
|
7624
|
+
var SCOPED_SETTINGS_SCOPES = [
|
|
7625
|
+
"cluster",
|
|
7626
|
+
"device-defaults",
|
|
7627
|
+
"node"
|
|
7628
|
+
];
|
|
6941
7629
|
/** A write to a secret path could not be stored in the keychain, so it was refused. */
|
|
6942
7630
|
var KeychainWriteRefusedError = class extends Error {
|
|
6943
7631
|
fieldPath;
|
|
@@ -6948,7 +7636,7 @@ var KeychainWriteRefusedError = class extends Error {
|
|
|
6948
7636
|
}
|
|
6949
7637
|
};
|
|
6950
7638
|
var KEEP = { kind: "keep" };
|
|
6951
|
-
function isRecord$
|
|
7639
|
+
function isRecord$4(value) {
|
|
6952
7640
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6953
7641
|
}
|
|
6954
7642
|
function defaultMintId() {
|
|
@@ -6961,7 +7649,7 @@ function collectSecretMarkerRefs(value, out = []) {
|
|
|
6961
7649
|
return out;
|
|
6962
7650
|
}
|
|
6963
7651
|
if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
|
|
6964
|
-
else if (isRecord$
|
|
7652
|
+
else if (isRecord$4(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
|
|
6965
7653
|
return out;
|
|
6966
7654
|
}
|
|
6967
7655
|
async function storedValueEquals(secrets, marker, candidate) {
|
|
@@ -7016,7 +7704,7 @@ function rowId(row, idKey) {
|
|
|
7016
7704
|
return null;
|
|
7017
7705
|
}
|
|
7018
7706
|
async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
7019
|
-
const storedRows = Array.isArray(stored) ? stored.filter(isRecord$
|
|
7707
|
+
const storedRows = Array.isArray(stored) ? stored.filter(isRecord$4) : [];
|
|
7020
7708
|
if (!Array.isArray(incoming)) {
|
|
7021
7709
|
ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
|
|
7022
7710
|
return {
|
|
@@ -7032,7 +7720,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
7032
7720
|
const kept = /* @__PURE__ */ new Set();
|
|
7033
7721
|
const rows = [];
|
|
7034
7722
|
for (const row of incoming) {
|
|
7035
|
-
if (!isRecord$
|
|
7723
|
+
if (!isRecord$4(row)) {
|
|
7036
7724
|
rows.push(row);
|
|
7037
7725
|
continue;
|
|
7038
7726
|
}
|
|
@@ -7057,7 +7745,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
|
|
|
7057
7745
|
case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
|
|
7058
7746
|
case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
|
|
7059
7747
|
case "object": {
|
|
7060
|
-
if (!isRecord$
|
|
7748
|
+
if (!isRecord$4(incoming)) {
|
|
7061
7749
|
if (incoming === void 0) return KEEP;
|
|
7062
7750
|
ctx.deletes.push(...collectSecretMarkerRefs(stored));
|
|
7063
7751
|
return {
|
|
@@ -7065,7 +7753,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
|
|
|
7065
7753
|
value: incoming
|
|
7066
7754
|
};
|
|
7067
7755
|
}
|
|
7068
|
-
const storedObj = isRecord$
|
|
7756
|
+
const storedObj = isRecord$4(stored) ? stored : {};
|
|
7069
7757
|
return {
|
|
7070
7758
|
kind: "value",
|
|
7071
7759
|
value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
|
|
@@ -7188,7 +7876,7 @@ async function resolveSecretMarkers(value, secrets, options = {}) {
|
|
|
7188
7876
|
value: items
|
|
7189
7877
|
};
|
|
7190
7878
|
}
|
|
7191
|
-
if (isRecord$
|
|
7879
|
+
if (isRecord$4(v)) {
|
|
7192
7880
|
const out = {};
|
|
7193
7881
|
for (const [k, child] of Object.entries(v)) {
|
|
7194
7882
|
const s = substitute(child);
|
|
@@ -7220,7 +7908,7 @@ var SecretOverwriteRefusedError = class extends Error {
|
|
|
7220
7908
|
this.name = "SecretOverwriteRefusedError";
|
|
7221
7909
|
}
|
|
7222
7910
|
};
|
|
7223
|
-
function isRecord$
|
|
7911
|
+
function isRecord$3(value) {
|
|
7224
7912
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7225
7913
|
}
|
|
7226
7914
|
function resolvedValue(pass, marker) {
|
|
@@ -7249,7 +7937,7 @@ function inArray(pass, incoming, stored) {
|
|
|
7249
7937
|
return incoming.map((item, index) => {
|
|
7250
7938
|
const twin = stored[index];
|
|
7251
7939
|
if (isSecretMarker(twin)) return typeof item === "string" && item === resolvedValue(pass, twin) ? twin : item;
|
|
7252
|
-
if (isRecord$
|
|
7940
|
+
if (isRecord$3(item) && isRecord$3(twin)) return inArrayRow(pass, item, twin);
|
|
7253
7941
|
if (Array.isArray(item) && Array.isArray(twin)) return inArray(pass, item, twin);
|
|
7254
7942
|
return item;
|
|
7255
7943
|
});
|
|
@@ -7260,7 +7948,7 @@ function inArrayRow(pass, incoming, stored) {
|
|
|
7260
7948
|
const twin = stored[key];
|
|
7261
7949
|
if (isSecretMarker(twin)) {
|
|
7262
7950
|
if (typeof value === "string" && value === resolvedValue(pass, twin)) out[key] = twin;
|
|
7263
|
-
} else if (isRecord$
|
|
7951
|
+
} else if (isRecord$3(value) && isRecord$3(twin)) out[key] = inArrayRow(pass, value, twin);
|
|
7264
7952
|
else if (Array.isArray(value) && Array.isArray(twin)) out[key] = inArray(pass, value, twin);
|
|
7265
7953
|
}
|
|
7266
7954
|
return out;
|
|
@@ -7268,7 +7956,7 @@ function inArrayRow(pass, incoming, stored) {
|
|
|
7268
7956
|
async function walk(pass, incoming, stored) {
|
|
7269
7957
|
if (isSecretMarker(stored)) return atMarker(pass, incoming, stored);
|
|
7270
7958
|
if (Array.isArray(incoming) && Array.isArray(stored)) return inArray(pass, incoming, stored);
|
|
7271
|
-
if (!isRecord$
|
|
7959
|
+
if (!isRecord$3(incoming) || !isRecord$3(stored)) return incoming;
|
|
7272
7960
|
const out = { ...incoming };
|
|
7273
7961
|
for (const [key, value] of Object.entries(incoming)) out[key] = await walk(pass, value, stored[key]);
|
|
7274
7962
|
return out;
|
|
@@ -7299,7 +7987,7 @@ async function restoreUnchangedSecrets(input) {
|
|
|
7299
7987
|
function isJsonEqual(a, b) {
|
|
7300
7988
|
if (Object.is(a, b)) return true;
|
|
7301
7989
|
if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((v, i) => isJsonEqual(v, b[i]));
|
|
7302
|
-
if (isRecord$
|
|
7990
|
+
if (isRecord$3(a) && isRecord$3(b)) {
|
|
7303
7991
|
const keys = Object.keys(a);
|
|
7304
7992
|
if (keys.length !== Object.keys(b).length) return false;
|
|
7305
7993
|
return keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && isJsonEqual(a[k], b[k]));
|
|
@@ -7323,7 +8011,7 @@ function markerKeysOf(blob, owner) {
|
|
|
7323
8011
|
}
|
|
7324
8012
|
function nodeFromStored(value, owner) {
|
|
7325
8013
|
if (isSecretMarker(value)) return isSecretRefOwnedBy(value.$secret, owner) ? { kind: "leaf" } : null;
|
|
7326
|
-
if (!isRecord$
|
|
8014
|
+
if (!isRecord$3(value)) return null;
|
|
7327
8015
|
const children = /* @__PURE__ */ new Map();
|
|
7328
8016
|
for (const [key, child] of Object.entries(value)) {
|
|
7329
8017
|
const node = nodeFromStored(child, owner);
|
|
@@ -7820,13 +8508,48 @@ var BaseAddon = class {
|
|
|
7820
8508
|
if (api === void 0) throw new Error(`${this.ctx.id}: the migration API is not available on this context`);
|
|
7821
8509
|
return this.runBound(sets.flatMap((set) => set.bind(api)), options);
|
|
7822
8510
|
}
|
|
7823
|
-
|
|
8511
|
+
/**
|
|
8512
|
+
* A device addon states its instance kind once, before its migrations run, and the one-switch
|
|
8513
|
+
* migration (registry `enabled` to the instance body, epic #440 step 3) joins whatever
|
|
8514
|
+
* catalogue the addon runs, in the SAME declaration (the engine replaces an owner's catalogue
|
|
8515
|
+
* on every declare).
|
|
8516
|
+
*/
|
|
8517
|
+
declareRegistrySwitch(spec) {
|
|
8518
|
+
this.registrySwitchSpec = spec;
|
|
8519
|
+
}
|
|
8520
|
+
registrySwitchSpec = null;
|
|
8521
|
+
registrySwitchBound() {
|
|
8522
|
+
const spec = this.registrySwitchSpec;
|
|
8523
|
+
if (spec === null) return [];
|
|
8524
|
+
const api = this.ctx.migrationApi;
|
|
8525
|
+
if (api === void 0) {
|
|
8526
|
+
this.ctx.logger.warn("the registry switch migration is skipped: the migration API is not available on this context");
|
|
8527
|
+
return [];
|
|
8528
|
+
}
|
|
8529
|
+
return migrationSet([registrySwitchToBodyMigration({
|
|
8530
|
+
addonId: this.ctx.id,
|
|
8531
|
+
date: "2026-11-06",
|
|
8532
|
+
seq: 1e3,
|
|
8533
|
+
initialBody: spec.initialBody
|
|
8534
|
+
})], (a) => registrySwitchPortsOver({
|
|
8535
|
+
api: integrationRowsApiOver(a),
|
|
8536
|
+
records: switchRecordsOverMigrationApi(a),
|
|
8537
|
+
kind: spec.kind
|
|
8538
|
+
})).bind(api);
|
|
8539
|
+
}
|
|
8540
|
+
async runBound(declared, options) {
|
|
8541
|
+
const added = this.registrySwitchBound();
|
|
8542
|
+
const migrations = [...declared, ...added];
|
|
8543
|
+
const phased = options?.only === void 0 || added.length === 0 ? options : {
|
|
8544
|
+
...options,
|
|
8545
|
+
only: [...options.only, ...added.map((m) => m.meta.id)]
|
|
8546
|
+
};
|
|
7824
8547
|
const api = this.ctx.api.migrations;
|
|
7825
8548
|
const report = await runAddonMigrations({
|
|
7826
8549
|
declareOwner: (input) => api.declareOwner.mutate(input),
|
|
7827
8550
|
startMigration: (input) => api.startMigration.mutate(input),
|
|
7828
8551
|
finishMigration: (input) => api.finishMigration.mutate(input)
|
|
7829
|
-
}, migrations, this.ctx.logger,
|
|
8552
|
+
}, migrations, this.ctx.logger, phased);
|
|
7830
8553
|
if (report.blockOwner.length > 0) throw new AddonMigrationsBlockedError(report.blockOwner);
|
|
7831
8554
|
return report;
|
|
7832
8555
|
}
|
|
@@ -8899,237 +9622,6 @@ function normalizeAddonInitResult(result) {
|
|
|
8899
9622
|
if (Array.isArray(result)) return { providers: result };
|
|
8900
9623
|
return result;
|
|
8901
9624
|
}
|
|
8902
|
-
var PREFIX = "records/";
|
|
8903
|
-
/** The base of every records failure. `detail` is the human part of the message. */
|
|
8904
|
-
var RecordsError = class extends Error {
|
|
8905
|
-
code;
|
|
8906
|
-
detail;
|
|
8907
|
-
constructor(code, detail) {
|
|
8908
|
-
super(`${PREFIX}${code}: ${detail}`);
|
|
8909
|
-
this.name = "RecordsError";
|
|
8910
|
-
this.code = code;
|
|
8911
|
-
this.detail = detail;
|
|
8912
|
-
}
|
|
8913
|
-
};
|
|
8914
|
-
/** A write guarded by `ifRev` found another revision (or an existing row for `ifRev: 0`). */
|
|
8915
|
-
var RevConflictError = class extends RecordsError {
|
|
8916
|
-
constructor(detail) {
|
|
8917
|
-
super("rev-conflict", detail);
|
|
8918
|
-
this.name = "RevConflictError";
|
|
8919
|
-
}
|
|
8920
|
-
};
|
|
8921
|
-
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
8922
|
-
var RecordSecretUnavailableError = class extends RecordsError {
|
|
8923
|
-
constructor(detail) {
|
|
8924
|
-
super("secret-unavailable", detail);
|
|
8925
|
-
this.name = "RecordSecretUnavailableError";
|
|
8926
|
-
}
|
|
8927
|
-
};
|
|
8928
|
-
var InvalidRecordError = class extends RecordsError {
|
|
8929
|
-
constructor(detail) {
|
|
8930
|
-
super("invalid-record", detail);
|
|
8931
|
-
this.name = "InvalidRecordError";
|
|
8932
|
-
}
|
|
8933
|
-
};
|
|
8934
|
-
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
8935
|
-
var DeclarationRefusedError = class extends RecordsError {
|
|
8936
|
-
constructor(detail) {
|
|
8937
|
-
super("declaration-refused", detail);
|
|
8938
|
-
this.name = "DeclarationRefusedError";
|
|
8939
|
-
}
|
|
8940
|
-
};
|
|
8941
|
-
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
8942
|
-
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
8943
|
-
var RECORD_DATABASES = ["settings", "events"];
|
|
8944
|
-
/** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
|
|
8945
|
-
var RECORD_CLASSES = [
|
|
8946
|
-
"config",
|
|
8947
|
-
"ledger",
|
|
8948
|
-
"audit",
|
|
8949
|
-
"mirror",
|
|
8950
|
-
"ephemeral"
|
|
8951
|
-
];
|
|
8952
|
-
var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
8953
|
-
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
8954
|
-
var RECORD_BATCH_MAX = 1e3;
|
|
8955
|
-
var RECORD_QUERY_MAX = 1e3;
|
|
8956
|
-
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
8957
|
-
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
8958
|
-
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
8959
|
-
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
8960
|
-
/**
|
|
8961
|
-
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
8962
|
-
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
8963
|
-
* (`auth.accessToken`, `headers[].value`).
|
|
8964
|
-
*
|
|
8965
|
-
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
8966
|
-
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
8967
|
-
* key releases exactly that key's secret.
|
|
8968
|
-
*
|
|
8969
|
-
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
8970
|
-
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
8971
|
-
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
8972
|
-
* leaf names its element: `headers[X-Api].value`.
|
|
8973
|
-
*
|
|
8974
|
-
* Pure and browser-safe. Nothing here mutates: every transform returns a new value.
|
|
8975
|
-
*/
|
|
8976
|
-
/** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
|
|
8977
|
-
function parseSecretPath(path) {
|
|
8978
|
-
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
8979
|
-
return path.split(".").map((raw) => {
|
|
8980
|
-
const each = raw.endsWith("[]");
|
|
8981
|
-
const map = raw.endsWith("{}");
|
|
8982
|
-
const key = each || map ? raw.slice(0, -2) : raw;
|
|
8983
|
-
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
8984
|
-
return {
|
|
8985
|
-
key,
|
|
8986
|
-
each,
|
|
8987
|
-
map
|
|
8988
|
-
};
|
|
8989
|
-
});
|
|
8990
|
-
}
|
|
8991
|
-
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
8992
|
-
function secretArrayPrefixes(path) {
|
|
8993
|
-
const segments = parseSecretPath(path);
|
|
8994
|
-
const prefixes = [];
|
|
8995
|
-
const walked = [];
|
|
8996
|
-
for (const segment of segments) {
|
|
8997
|
-
walked.push(segment.key);
|
|
8998
|
-
if (segment.each) prefixes.push(walked.join("."));
|
|
8999
|
-
}
|
|
9000
|
-
return prefixes;
|
|
9001
|
-
}
|
|
9002
|
-
function isRecord$4(value) {
|
|
9003
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9004
|
-
}
|
|
9005
|
-
function elementId(element, idKey, declared, prefix) {
|
|
9006
|
-
const id = isRecord$4(element) ? element[idKey] : void 0;
|
|
9007
|
-
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`);
|
|
9008
|
-
return id;
|
|
9009
|
-
}
|
|
9010
|
-
/**
|
|
9011
|
-
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
9012
|
-
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
9013
|
-
* result is a new body, `data` is untouched.
|
|
9014
|
-
*/
|
|
9015
|
-
var REMOVE_LEAF = Symbol("remove-leaf");
|
|
9016
|
-
function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
|
|
9017
|
-
if (!isRecord$4(node)) return node;
|
|
9018
|
-
const segment = segments[index];
|
|
9019
|
-
if (segment === void 0) return node;
|
|
9020
|
-
if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
|
|
9021
|
-
const child = node[segment.key];
|
|
9022
|
-
const keys = [...walkedKeys, segment.key];
|
|
9023
|
-
const last = index === segments.length - 1;
|
|
9024
|
-
if (segment.each) {
|
|
9025
|
-
if (!Array.isArray(child)) return node;
|
|
9026
|
-
const prefix = keys.join(".");
|
|
9027
|
-
const idKey = arrayKeys[prefix];
|
|
9028
|
-
if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
|
|
9029
|
-
const mapped = child.map((element) => {
|
|
9030
|
-
const id = elementId(element, idKey, declared, prefix);
|
|
9031
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
|
|
9032
|
-
return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
|
|
9033
|
-
});
|
|
9034
|
-
return {
|
|
9035
|
-
...node,
|
|
9036
|
-
[segment.key]: mapped
|
|
9037
|
-
};
|
|
9038
|
-
}
|
|
9039
|
-
if (segment.map) {
|
|
9040
|
-
if (!isRecord$4(child)) return node;
|
|
9041
|
-
const kept = Object.entries(child).map(([mapKey, value]) => {
|
|
9042
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
|
|
9043
|
-
if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
|
|
9044
|
-
return [mapKey, visit({
|
|
9045
|
-
declared,
|
|
9046
|
-
concrete,
|
|
9047
|
-
value
|
|
9048
|
-
})];
|
|
9049
|
-
}).filter(([, value]) => value !== REMOVE_LEAF);
|
|
9050
|
-
return {
|
|
9051
|
-
...node,
|
|
9052
|
-
[segment.key]: Object.fromEntries(kept)
|
|
9053
|
-
};
|
|
9054
|
-
}
|
|
9055
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
9056
|
-
if (last) {
|
|
9057
|
-
const replacement = visit({
|
|
9058
|
-
declared,
|
|
9059
|
-
concrete,
|
|
9060
|
-
value: child
|
|
9061
|
-
});
|
|
9062
|
-
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
9063
|
-
return {
|
|
9064
|
-
...node,
|
|
9065
|
-
[segment.key]: replacement
|
|
9066
|
-
};
|
|
9067
|
-
}
|
|
9068
|
-
return {
|
|
9069
|
-
...node,
|
|
9070
|
-
[segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
|
|
9071
|
-
};
|
|
9072
|
-
}
|
|
9073
|
-
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
9074
|
-
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
9075
|
-
let current = data;
|
|
9076
|
-
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
9077
|
-
return current;
|
|
9078
|
-
}
|
|
9079
|
-
/** Every present secret leaf, read-only. */
|
|
9080
|
-
function collectSecretLeaves(data, paths, arrayKeys) {
|
|
9081
|
-
const found = [];
|
|
9082
|
-
mapSecretLeaves(data, paths, arrayKeys, (leaf) => {
|
|
9083
|
-
found.push(leaf);
|
|
9084
|
-
return leaf.value;
|
|
9085
|
-
});
|
|
9086
|
-
return found;
|
|
9087
|
-
}
|
|
9088
|
-
/**
|
|
9089
|
-
* The keychain collection name a kind's secrets live under. Prefixed so a
|
|
9090
|
-
* record's refs never collide with the refs a legacy collection of the same name
|
|
9091
|
-
* already holds during an adoption.
|
|
9092
|
-
*/
|
|
9093
|
-
function recordSecretCollection(kind) {
|
|
9094
|
-
return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
|
|
9095
|
-
}
|
|
9096
|
-
/** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
|
|
9097
|
-
function recordSecretRef(owner, kind, rowId, concretePath) {
|
|
9098
|
-
return buildSecretRef({
|
|
9099
|
-
owner,
|
|
9100
|
-
scope: {
|
|
9101
|
-
kind: "row",
|
|
9102
|
-
collection: recordSecretCollection(kind),
|
|
9103
|
-
rowId
|
|
9104
|
-
},
|
|
9105
|
-
fieldPath: concretePath
|
|
9106
|
-
});
|
|
9107
|
-
}
|
|
9108
|
-
/**
|
|
9109
|
-
* A stored secret, as an admin read shows it: a VIEW naming the row's own
|
|
9110
|
-
* keychain ref (`set: true`), never the value and no longer the bare redaction
|
|
9111
|
-
* token. The form hands it to the secret field, which reveals the value by ref
|
|
9112
|
-
* through the audited `keychain-admin.reveal`; sent back untouched it keeps the
|
|
9113
|
-
* stored secret (the records door reads a view as KEEP).
|
|
9114
|
-
*
|
|
9115
|
-
* ONE implementation for the entries service and for every addon that serves
|
|
9116
|
-
* its own instances (`RecordIntegrationInstances`).
|
|
9117
|
-
*/
|
|
9118
|
-
function isRecord$3(value) {
|
|
9119
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9120
|
-
}
|
|
9121
|
-
function secretViewsOf(owner, kind, id, decl, data) {
|
|
9122
|
-
if (decl.secretPaths.length === 0) return data;
|
|
9123
|
-
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
9124
|
-
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
9125
|
-
return {
|
|
9126
|
-
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
9127
|
-
v: 1,
|
|
9128
|
-
set: true
|
|
9129
|
-
};
|
|
9130
|
-
});
|
|
9131
|
-
return isRecord$3(shown) ? shown : data;
|
|
9132
|
-
}
|
|
9133
9625
|
/**
|
|
9134
9626
|
* The share-view scope kinds a share-link token can carry. The hub mints
|
|
9135
9627
|
* and validates them (`ShareViewGrantSchema` builds its
|
|
@@ -9383,6 +9875,7 @@ function defineRecordKinds(specs) {
|
|
|
9383
9875
|
function entryBody(shape) {
|
|
9384
9876
|
return object({
|
|
9385
9877
|
name: string().min(1),
|
|
9878
|
+
enabled: boolean().optional(),
|
|
9386
9879
|
...shape
|
|
9387
9880
|
});
|
|
9388
9881
|
}
|
|
@@ -11238,6 +11731,10 @@ Object.freeze({
|
|
|
11238
11731
|
"all",
|
|
11239
11732
|
"one"
|
|
11240
11733
|
]
|
|
11734
|
+
},
|
|
11735
|
+
{
|
|
11736
|
+
"path": "positionUpdatedAt",
|
|
11737
|
+
"valueType": "number"
|
|
11241
11738
|
}
|
|
11242
11739
|
],
|
|
11243
11740
|
"meter": [{
|
|
@@ -11492,22 +11989,6 @@ Object.freeze({
|
|
|
11492
11989
|
"path": "pumpRunning",
|
|
11493
11990
|
"valueType": "boolean"
|
|
11494
11991
|
},
|
|
11495
|
-
{
|
|
11496
|
-
"path": "lastDrink",
|
|
11497
|
-
"valueType": "number"
|
|
11498
|
-
},
|
|
11499
|
-
{
|
|
11500
|
-
"path": "currentHourDrink",
|
|
11501
|
-
"valueType": "number"
|
|
11502
|
-
},
|
|
11503
|
-
{
|
|
11504
|
-
"path": "last24hDrink",
|
|
11505
|
-
"valueType": "number"
|
|
11506
|
-
},
|
|
11507
|
-
{
|
|
11508
|
-
"path": "todayDrink",
|
|
11509
|
-
"valueType": "number"
|
|
11510
|
-
},
|
|
11511
11992
|
{
|
|
11512
11993
|
"path": "error",
|
|
11513
11994
|
"valueType": "string"
|
|
@@ -12073,6 +12554,60 @@ Object.freeze({
|
|
|
12073
12554
|
}
|
|
12074
12555
|
]
|
|
12075
12556
|
});
|
|
12557
|
+
Object.freeze({
|
|
12558
|
+
"actions": { "run": 363e4 },
|
|
12559
|
+
"audio-analyzer": { "classify": 3e4 },
|
|
12560
|
+
"custom-model-registry": { "importModelBundle": 18e5 },
|
|
12561
|
+
"database-snapshot": { "writeSnapshot": 18e5 },
|
|
12562
|
+
"device-manager": {
|
|
12563
|
+
"migrateDevice": 72e4,
|
|
12564
|
+
"runDiscoverySweep": 12e4
|
|
12565
|
+
},
|
|
12566
|
+
"device-provider": { "reloadDevice": 18e4 },
|
|
12567
|
+
"llm": {
|
|
12568
|
+
"generate": 6e5,
|
|
12569
|
+
"generateVision": 6e5,
|
|
12570
|
+
"testProfile": 6e5
|
|
12571
|
+
},
|
|
12572
|
+
"llm-runtime": {
|
|
12573
|
+
"complete": 6e5,
|
|
12574
|
+
"completeApple": 6e5,
|
|
12575
|
+
"ensureStarted": 6e5,
|
|
12576
|
+
"installModel": 36e5
|
|
12577
|
+
},
|
|
12578
|
+
"local-network": { "scanNetwork": 9e4 },
|
|
12579
|
+
"model-convert": { "convert": 6e5 },
|
|
12580
|
+
"pipeline-analytics": {
|
|
12581
|
+
"addRetrainFrameFromRecording": 6e4,
|
|
12582
|
+
"offerRetrainArchive": 12e4,
|
|
12583
|
+
"proposeRetrainAnnotationsWithLlm": 18e4,
|
|
12584
|
+
"resolveRetrainTrainingCorpus": 6e4,
|
|
12585
|
+
"writeRetrainArchive": 36e5
|
|
12586
|
+
},
|
|
12587
|
+
"server-management": { "applyServerUpdate": 96e4 },
|
|
12588
|
+
"terminal-session": { "pullOutput": 15e3 },
|
|
12589
|
+
"training": {
|
|
12590
|
+
"canaryResult": 12e4,
|
|
12591
|
+
"cancelJob": 12e4,
|
|
12592
|
+
"planJob": 6e4,
|
|
12593
|
+
"registerResult": 18e5,
|
|
12594
|
+
"rollbackCanary": 12e4,
|
|
12595
|
+
"startJob": 12e4,
|
|
12596
|
+
"startJobBatch": 12e4
|
|
12597
|
+
},
|
|
12598
|
+
"training-provider": {
|
|
12599
|
+
"cancelJob": 6e4,
|
|
12600
|
+
"cleanupJob": 3e5,
|
|
12601
|
+
"getJob": 6e4,
|
|
12602
|
+
"listJobEvents": 6e4,
|
|
12603
|
+
"listJobs": 12e4,
|
|
12604
|
+
"offerArtifact": 3e5,
|
|
12605
|
+
"readResult": 3e5,
|
|
12606
|
+
"submitJob": 18e5,
|
|
12607
|
+
"uploadDataset": 72e5,
|
|
12608
|
+
"validateCredentials": 3e4
|
|
12609
|
+
}
|
|
12610
|
+
});
|
|
12076
12611
|
object({
|
|
12077
12612
|
code: string().regex(/^[a-z][a-z0-9-]*(\.[a-z0-9-]+)+$/),
|
|
12078
12613
|
params: record(string(), union([string(), number()])).optional()
|
|
@@ -12092,7 +12627,7 @@ function userError(code, params, englishFallback) {
|
|
|
12092
12627
|
return new CamstackError(code, params, englishFallback);
|
|
12093
12628
|
}
|
|
12094
12629
|
//#endregion
|
|
12095
|
-
//#region ../types/dist/composition-
|
|
12630
|
+
//#region ../types/dist/composition-BmBHuDTQ.mjs
|
|
12096
12631
|
/**
|
|
12097
12632
|
* The ffmpeg build every CamStack node downloads, per platform and arch.
|
|
12098
12633
|
*
|
|
@@ -12396,7 +12931,7 @@ var table = {
|
|
|
12396
12931
|
},
|
|
12397
12932
|
dwell: {
|
|
12398
12933
|
minArgs: 3,
|
|
12399
|
-
maxArgs:
|
|
12934
|
+
maxArgs: 4,
|
|
12400
12935
|
apply: () => {
|
|
12401
12936
|
throw new ExpressionEvalError("dwell: stateful evaluation context is required");
|
|
12402
12937
|
}
|
|
@@ -13439,212 +13974,6 @@ var IntegrationInstanceRefSchema = object({
|
|
|
13439
13974
|
]),
|
|
13440
13975
|
candidateStableId: string().optional()
|
|
13441
13976
|
});
|
|
13442
|
-
/**
|
|
13443
|
-
* `RecordIntegrationInstances` - the `integration-instances` provider over ONE
|
|
13444
|
-
* entry kind, so an addon that holds a connection serves it in ~30 lines.
|
|
13445
|
-
*
|
|
13446
|
-
* Every instance is one record of the addon's own kind, keyed by the
|
|
13447
|
-
* `integrations` registry id. The records door does the secret work: a field the
|
|
13448
|
-
* kind marks `.meta({ secret: true })` is a keychain marker bound to the row, so
|
|
13449
|
-
* deleting the row deletes the secret, and one row's value is never another's.
|
|
13450
|
-
*
|
|
13451
|
-
* Patch rules for a secret (`updateInstance`): omitted, `''`, the redaction
|
|
13452
|
-
* token or the view the form was given KEEP the stored secret;
|
|
13453
|
-
* `{ $secretClear: true }` clears it; any other string replaces it.
|
|
13454
|
-
*/
|
|
13455
|
-
/** The most instances one addon lists (an integrations page, not a table). */
|
|
13456
|
-
var INSTANCES_LIST_MAX = 1e3;
|
|
13457
|
-
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
13458
|
-
function topLevelSecretKeys(paths) {
|
|
13459
|
-
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
13460
|
-
}
|
|
13461
|
-
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
13462
|
-
function secretMapKeys(paths) {
|
|
13463
|
-
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
13464
|
-
}
|
|
13465
|
-
/**
|
|
13466
|
-
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
13467
|
-
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
13468
|
-
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
13469
|
-
*/
|
|
13470
|
-
function secretMapPatch(value) {
|
|
13471
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
13472
|
-
const out = {};
|
|
13473
|
-
for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
|
|
13474
|
-
else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
|
|
13475
|
-
return Object.keys(out).length > 0 ? out : null;
|
|
13476
|
-
}
|
|
13477
|
-
/** Does the kind's body schema carry an `enabled` field? */
|
|
13478
|
-
function declaresEnabled(kind) {
|
|
13479
|
-
const json = toJSONSchema(kind.schema, {
|
|
13480
|
-
unrepresentable: "any",
|
|
13481
|
-
io: "input"
|
|
13482
|
-
});
|
|
13483
|
-
const properties = Reflect.get(json, "properties");
|
|
13484
|
-
return typeof properties === "object" && properties !== null && "enabled" in properties;
|
|
13485
|
-
}
|
|
13486
|
-
var RecordIntegrationInstances = class {
|
|
13487
|
-
records;
|
|
13488
|
-
kind;
|
|
13489
|
-
hooks;
|
|
13490
|
-
handle;
|
|
13491
|
-
secretKeys;
|
|
13492
|
-
secretMaps;
|
|
13493
|
-
nameField;
|
|
13494
|
-
/** The `integrations` registry owns the on/off switch (`role: devices`); the body has none. */
|
|
13495
|
-
registryOwnsEnabled;
|
|
13496
|
-
constructor(records, kind, hooks) {
|
|
13497
|
-
this.records = records;
|
|
13498
|
-
this.kind = kind;
|
|
13499
|
-
this.hooks = hooks;
|
|
13500
|
-
this.handle = records.kind(kind);
|
|
13501
|
-
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
13502
|
-
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
13503
|
-
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
13504
|
-
this.registryOwnsEnabled = hooks.description.role === "devices";
|
|
13505
|
-
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"`);
|
|
13506
|
-
}
|
|
13507
|
-
/**
|
|
13508
|
-
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
13509
|
-
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
13510
|
-
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
13511
|
-
*/
|
|
13512
|
-
async readResolved(id) {
|
|
13513
|
-
try {
|
|
13514
|
-
const record = await this.handle.getResolved(id);
|
|
13515
|
-
return record === null ? null : {
|
|
13516
|
-
id,
|
|
13517
|
-
body: record.data,
|
|
13518
|
-
enabled: record.data.enabled !== false,
|
|
13519
|
-
secrets: "resolved"
|
|
13520
|
-
};
|
|
13521
|
-
} catch (err) {
|
|
13522
|
-
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
13523
|
-
const stored = await this.handle.get(id);
|
|
13524
|
-
if (stored === null) return null;
|
|
13525
|
-
return {
|
|
13526
|
-
id,
|
|
13527
|
-
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
13528
|
-
enabled: stored.data.enabled !== false,
|
|
13529
|
-
secrets: "unavailable"
|
|
13530
|
-
};
|
|
13531
|
-
}
|
|
13532
|
-
}
|
|
13533
|
-
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
13534
|
-
async getResolved(id) {
|
|
13535
|
-
return (await this.readResolved(id))?.body ?? null;
|
|
13536
|
-
}
|
|
13537
|
-
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
13538
|
-
async listResolved() {
|
|
13539
|
-
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
13540
|
-
const out = [];
|
|
13541
|
-
for (const record of page.records) {
|
|
13542
|
-
const read = await this.readResolved(record.id);
|
|
13543
|
-
if (read !== null) out.push(read);
|
|
13544
|
-
}
|
|
13545
|
-
return out;
|
|
13546
|
-
}
|
|
13547
|
-
viewOf(record) {
|
|
13548
|
-
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
13549
|
-
const rawName = record.data[this.nameField];
|
|
13550
|
-
const kind = this.hooks.kindOf?.(record.data);
|
|
13551
|
-
const health = this.hooks.health?.(record.data, record.id);
|
|
13552
|
-
return {
|
|
13553
|
-
id: record.id,
|
|
13554
|
-
name: typeof rawName === "string" ? rawName : record.id,
|
|
13555
|
-
configured: this.hooks.configured(record.data),
|
|
13556
|
-
...this.registryOwnsEnabled ? {} : { enabled: record.data.enabled !== false },
|
|
13557
|
-
formValues: shown,
|
|
13558
|
-
...kind !== void 0 ? { kind } : {},
|
|
13559
|
-
...health?.status !== void 0 ? { status: health.status } : {},
|
|
13560
|
-
...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
|
|
13561
|
-
};
|
|
13562
|
-
}
|
|
13563
|
-
describe = async () => this.hooks.mintId === void 0 ? this.hooks.description : {
|
|
13564
|
-
...this.hooks.description,
|
|
13565
|
-
mintsId: true
|
|
13566
|
-
};
|
|
13567
|
-
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
13568
|
-
listInstances = async () => {
|
|
13569
|
-
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
13570
|
-
};
|
|
13571
|
-
getInstance = async ({ id }) => {
|
|
13572
|
-
const record = await this.handle.get(id);
|
|
13573
|
-
return record === null ? null : this.viewOf(record);
|
|
13574
|
-
};
|
|
13575
|
-
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
13576
|
-
createInstance = async ({ id, name, kind, values }) => {
|
|
13577
|
-
const minted = id ?? this.hooks.mintId?.({
|
|
13578
|
-
name,
|
|
13579
|
-
...kind !== void 0 ? { kind } : {}
|
|
13580
|
-
});
|
|
13581
|
-
if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
|
|
13582
|
-
await this.handle.put({
|
|
13583
|
-
id: minted,
|
|
13584
|
-
data: this.hooks.initialBody(name, kind)
|
|
13585
|
-
}, { ifRev: 0 });
|
|
13586
|
-
const patch = this.patchOf(values ?? {});
|
|
13587
|
-
if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
|
|
13588
|
-
await this.hooks.onChanged?.(minted, "created");
|
|
13589
|
-
return { id: minted };
|
|
13590
|
-
};
|
|
13591
|
-
updateInstance = async ({ id, name, values }) => {
|
|
13592
|
-
const patch = this.patchOf(values);
|
|
13593
|
-
if (name !== void 0) patch[this.nameField] = name;
|
|
13594
|
-
await this.handle.patch(id, patch);
|
|
13595
|
-
await this.hooks.onChanged?.(id, "updated");
|
|
13596
|
-
return { ok: true };
|
|
13597
|
-
};
|
|
13598
|
-
/** The record patch a form `values` object means: secrets kept, cleared or replaced. */
|
|
13599
|
-
patchOf(values) {
|
|
13600
|
-
const patch = {};
|
|
13601
|
-
for (const [key, value] of Object.entries(values)) {
|
|
13602
|
-
if (value === void 0) continue;
|
|
13603
|
-
if (this.secretMaps.has(key)) {
|
|
13604
|
-
const entries = secretMapPatch(value);
|
|
13605
|
-
if (entries !== null) patch[key] = entries;
|
|
13606
|
-
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
13607
|
-
else if (isSecretClear(value)) patch[key] = null;
|
|
13608
|
-
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
13609
|
-
}
|
|
13610
|
-
return patch;
|
|
13611
|
-
}
|
|
13612
|
-
/** The switch lives in the record body; the addon is told so it applies it (D996). */
|
|
13613
|
-
setInstanceEnabled = async ({ id, enabled }) => {
|
|
13614
|
-
if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
|
|
13615
|
-
await this.handle.patch(id, { enabled });
|
|
13616
|
-
await this.hooks.onChanged?.(id, "enabled");
|
|
13617
|
-
return { ok: true };
|
|
13618
|
-
};
|
|
13619
|
-
/** The row and its keychain refs go together (the records door). */
|
|
13620
|
-
deleteInstance = async ({ id }) => {
|
|
13621
|
-
await this.handle.delete(id);
|
|
13622
|
-
await this.hooks.onChanged?.(id, "deleted");
|
|
13623
|
-
return { ok: true };
|
|
13624
|
-
};
|
|
13625
|
-
testInstance = async (input) => {
|
|
13626
|
-
if (this.hooks.test === void 0) return {
|
|
13627
|
-
success: false,
|
|
13628
|
-
status: "unsupported",
|
|
13629
|
-
error: "This integration declares no connection test"
|
|
13630
|
-
};
|
|
13631
|
-
return this.hooks.test(input);
|
|
13632
|
-
};
|
|
13633
|
-
/** The flat provider object to hand to `registerProvider`. */
|
|
13634
|
-
toProvider() {
|
|
13635
|
-
return {
|
|
13636
|
-
describe: this.describe,
|
|
13637
|
-
instanceFormSchema: this.instanceFormSchema,
|
|
13638
|
-
listInstances: this.listInstances,
|
|
13639
|
-
getInstance: this.getInstance,
|
|
13640
|
-
createInstance: this.createInstance,
|
|
13641
|
-
updateInstance: this.updateInstance,
|
|
13642
|
-
setInstanceEnabled: this.setInstanceEnabled,
|
|
13643
|
-
deleteInstance: this.deleteInstance,
|
|
13644
|
-
testInstance: this.testInstance
|
|
13645
|
-
};
|
|
13646
|
-
}
|
|
13647
|
-
};
|
|
13648
13977
|
var EncodeProfileSchema = object({
|
|
13649
13978
|
video: object({
|
|
13650
13979
|
codec: _enum([
|
|
@@ -20462,31 +20791,21 @@ var APPLIANCE_CAP_VOCABULARY = {
|
|
|
20462
20791
|
"pet-fountain": {
|
|
20463
20792
|
scope: "device",
|
|
20464
20793
|
noun: t("Pet fountain", "Fontana per animali"),
|
|
20465
|
-
actions: [
|
|
20466
|
-
|
|
20467
|
-
|
|
20468
|
-
|
|
20469
|
-
|
|
20470
|
-
|
|
20471
|
-
|
|
20472
|
-
|
|
20473
|
-
|
|
20474
|
-
|
|
20475
|
-
|
|
20476
|
-
|
|
20477
|
-
|
|
20478
|
-
|
|
20479
|
-
|
|
20480
|
-
args: { on: false }
|
|
20481
|
-
},
|
|
20482
|
-
{
|
|
20483
|
-
id: "petFountain.resetDailyConsumption",
|
|
20484
|
-
method: "resetDailyConsumption",
|
|
20485
|
-
label: t("Clear daily consumption", "Azzera il consumo giornaliero"),
|
|
20486
|
-
phrase: t("Clear the daily water consumption of {device}", "Azzera il consumo giornaliero di acqua di {device}"),
|
|
20487
|
-
icon: "rotate-ccw"
|
|
20488
|
-
}
|
|
20489
|
-
],
|
|
20794
|
+
actions: [{
|
|
20795
|
+
id: "petFountain.pumpOn",
|
|
20796
|
+
method: "setPump",
|
|
20797
|
+
label: t("Pump on", "Pompa accesa"),
|
|
20798
|
+
phrase: t("Start the pump of {device}", "Avvia la pompa di {device}"),
|
|
20799
|
+
icon: "play",
|
|
20800
|
+
args: { on: true }
|
|
20801
|
+
}, {
|
|
20802
|
+
id: "petFountain.pumpOff",
|
|
20803
|
+
method: "setPump",
|
|
20804
|
+
label: t("Pump off", "Pompa spenta"),
|
|
20805
|
+
phrase: t("Stop the pump of {device}", "Ferma la pompa di {device}"),
|
|
20806
|
+
icon: "square",
|
|
20807
|
+
args: { on: false }
|
|
20808
|
+
}],
|
|
20490
20809
|
state: [{
|
|
20491
20810
|
kind: "boolean",
|
|
20492
20811
|
field: "empty",
|
|
@@ -44440,8 +44759,15 @@ var ActionInputSchema = object({
|
|
|
44440
44759
|
var ActionRunOriginSchema = object({
|
|
44441
44760
|
/** The automation block whose step started it. */
|
|
44442
44761
|
blockId: string().min(1).optional() });
|
|
44443
|
-
/**
|
|
44444
|
-
|
|
44762
|
+
/**
|
|
44763
|
+
* `started` = the caller did not ask to wait. `timed-out` = the run reached the
|
|
44764
|
+
* ceiling (`ACTION_RUN_MAX_MS`) and was stopped; it is never a `ran`.
|
|
44765
|
+
*/
|
|
44766
|
+
var ActionRunOutcomeSchema = union([
|
|
44767
|
+
AutomationRunOutcomeSchema,
|
|
44768
|
+
literal("started"),
|
|
44769
|
+
literal("timed-out")
|
|
44770
|
+
]);
|
|
44445
44771
|
var ActionRunResultSchema = object({
|
|
44446
44772
|
runId: string().min(1),
|
|
44447
44773
|
outcome: ActionRunOutcomeSchema,
|
|
@@ -44963,6 +45289,8 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
44963
45289
|
kind: "mutation",
|
|
44964
45290
|
auth: "admin"
|
|
44965
45291
|
});
|
|
45292
|
+
/** `timeoutMs` of `actions.run`: a waited call outlives any legal run. */
|
|
45293
|
+
var ACTION_RUN_TIMEOUT_MS = 363e4;
|
|
44966
45294
|
/**
|
|
44967
45295
|
* actions — the ONE surface for runnable actions, for the UI and for
|
|
44968
45296
|
* automations. Provided by the core-blocks builtin on the hub.
|
|
@@ -44981,6 +45309,12 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
44981
45309
|
* An admin, and an in-process caller (an automation block), may run any action.
|
|
44982
45310
|
* Every refusal is typed (`[not-linked] …`) and logged.
|
|
44983
45311
|
*
|
|
45312
|
+
* **A run lasts at most `ACTION_RUN_MAX_MS` (60 min).** The provider stops a
|
|
45313
|
+
* run that reaches it and answers `timed-out` (never `ran`); an action whose
|
|
45314
|
+
* `wait` steps alone add up to more is refused at create/update
|
|
45315
|
+
* (`[invalid-steps]`). `run` declares a `timeoutMs` above that ceiling, so a
|
|
45316
|
+
* waited call (an automation step) is never cut by the 60 s transport default.
|
|
45317
|
+
*
|
|
44984
45318
|
* A second `run` of an action that is already running is REFUSED — traced and
|
|
44985
45319
|
* logged — never queued.
|
|
44986
45320
|
*/
|
|
@@ -45007,7 +45341,8 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
45007
45341
|
role: "viewer",
|
|
45008
45342
|
auth: "protected",
|
|
45009
45343
|
kind: "mutation",
|
|
45010
|
-
caller: "required"
|
|
45344
|
+
caller: "required",
|
|
45345
|
+
timeoutMs: ACTION_RUN_TIMEOUT_MS
|
|
45011
45346
|
}), method(ActionIdInput, _void(), {
|
|
45012
45347
|
kind: "mutation",
|
|
45013
45348
|
auth: "admin"
|
|
@@ -50034,6 +50369,9 @@ var MediaPlayerStatusSchema = object({
|
|
|
50034
50369
|
/** Repeat mode. Null when no repeat surface.
|
|
50035
50370
|
* Pair with `DeviceFeature.MediaPlayerRepeat`. */
|
|
50036
50371
|
repeat: MediaPlayerRepeatSchema.nullable(),
|
|
50372
|
+
/** Ms epoch when `position` was read from the device. Null when the driver
|
|
50373
|
+
* does not say; a UI that advances the position while playing counts from it. */
|
|
50374
|
+
positionUpdatedAt: number().nullable().default(null),
|
|
50037
50375
|
/** Ms epoch when the slice was last updated. */
|
|
50038
50376
|
lastChangedAt: number()
|
|
50039
50377
|
});
|
|
@@ -50669,7 +51007,9 @@ var ThresholdTransformDraftSchema = object({
|
|
|
50669
51007
|
comparison: _enum(["gte", "lte"]),
|
|
50670
51008
|
threshold: number(),
|
|
50671
51009
|
startDwellMs: number().nonnegative(),
|
|
50672
|
-
stopDwellMs: number().nonnegative()
|
|
51010
|
+
stopDwellMs: number().nonnegative(),
|
|
51011
|
+
/** Samples a start needs; absent = the compiler's default for the source (2 for running power, else 1). */
|
|
51012
|
+
minSamples: number().int().min(1).optional()
|
|
50673
51013
|
});
|
|
50674
51014
|
var CustomizeTransformDraftSchema = discriminatedUnion("kind", [
|
|
50675
51015
|
IdentityTransformDraftSchema,
|
|
@@ -56569,6 +56909,7 @@ var IntegrationWithStateSchema = object({
|
|
|
56569
56909
|
id: string(),
|
|
56570
56910
|
addonId: string(),
|
|
56571
56911
|
name: string(),
|
|
56912
|
+
/** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
|
|
56572
56913
|
enabled: boolean(),
|
|
56573
56914
|
info: record(string(), unknown()).readonly(),
|
|
56574
56915
|
/** The discovery candidate this integration was set up from (D984). */
|
|
@@ -56581,6 +56922,7 @@ var IntegrationLiteSchema = object({
|
|
|
56581
56922
|
id: string(),
|
|
56582
56923
|
addonId: string(),
|
|
56583
56924
|
name: string(),
|
|
56925
|
+
/** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
|
|
56584
56926
|
enabled: boolean(),
|
|
56585
56927
|
info: record(string(), unknown()).readonly(),
|
|
56586
56928
|
/** The discovery candidate this integration was set up from (D984). */
|
|
@@ -56680,7 +57022,6 @@ var TestConnectionResultSchema = object({
|
|
|
56680
57022
|
var CreateIntegrationInputSchema = object({
|
|
56681
57023
|
addonId: string(),
|
|
56682
57024
|
name: string(),
|
|
56683
|
-
enabled: boolean().optional(),
|
|
56684
57025
|
info: record(string(), unknown()).optional(),
|
|
56685
57026
|
/** `stableId` of the discovery candidate the form was seeded from (D984). */
|
|
56686
57027
|
originStableId: string().optional(),
|
|
@@ -56689,6 +57030,11 @@ var CreateIntegrationInputSchema = object({
|
|
|
56689
57030
|
var UpdateIntegrationInputSchema = object({
|
|
56690
57031
|
id: string(),
|
|
56691
57032
|
name: string().optional(),
|
|
57033
|
+
/**
|
|
57034
|
+
* Accepted for a FIXED builtin only (`info.fixed`: alarm panel, camera grid, core blocks,
|
|
57035
|
+
* terminal), which keeps no instance record: the registry flag is its one store. Any other
|
|
57036
|
+
* integration is switched through `integration-instances.setInstanceEnabled`.
|
|
57037
|
+
*/
|
|
56692
57038
|
enabled: boolean().optional(),
|
|
56693
57039
|
info: record(string(), unknown()).optional()
|
|
56694
57040
|
});
|
|
@@ -56736,7 +57082,7 @@ var IntegrationInstanceIdSchema = string().min(1);
|
|
|
56736
57082
|
var IntegrationInstanceModeSchema = _enum(["single", "multiple"]);
|
|
56737
57083
|
/**
|
|
56738
57084
|
* What the addon's instances ARE for the Integrations page (planning#416). `devices`: each
|
|
56739
|
-
* instance is an integration that brings devices (
|
|
57085
|
+
* instance is an integration that brings devices (its record body owns the on/off switch);
|
|
56740
57086
|
* `services`: a connection configured from the addon's own function page, never listed on
|
|
56741
57087
|
* Integrations.
|
|
56742
57088
|
* It is the same vocabulary as the manifest's `integrationRole`, which stays as an override.
|
|
@@ -56779,18 +57125,38 @@ var IntegrationInstanceKindSchema = object({
|
|
|
56779
57125
|
/** Relative hub path to disconnect that account. */
|
|
56780
57126
|
disconnectPath: string().min(1).optional()
|
|
56781
57127
|
});
|
|
57128
|
+
/**
|
|
57129
|
+
* How devices of an instance are found. `none`: the operator adds them by hand; `lan`: the addon
|
|
57130
|
+
* scans the network before any instance exists (the wizard offers the candidates); `account`: the
|
|
57131
|
+
* devices appear after the instance signs in. `scopedToInstance`: a discovery run belongs to ONE
|
|
57132
|
+
* instance and its candidates are claimed by it.
|
|
57133
|
+
*/
|
|
57134
|
+
var IntegrationInstanceDiscoverySchema = object({
|
|
57135
|
+
mode: _enum([
|
|
57136
|
+
"none",
|
|
57137
|
+
"lan",
|
|
57138
|
+
"account"
|
|
57139
|
+
]),
|
|
57140
|
+
scopedToInstance: boolean()
|
|
57141
|
+
});
|
|
57142
|
+
/**
|
|
57143
|
+
* One link a kind of this provider declares (D1013 rule 5): the body `field` of an instance of
|
|
57144
|
+
* `kind` holds the id of an instance of the function cap `to.cap` (of kind `to.kind`, when set).
|
|
57145
|
+
* The hub indexes these so the target's delete is refused while a link names it.
|
|
57146
|
+
*/
|
|
57147
|
+
var IntegrationInstanceLinkSchema = object({
|
|
57148
|
+
kind: string().min(1),
|
|
57149
|
+
field: string().min(1),
|
|
57150
|
+
to: object({
|
|
57151
|
+
cap: string().min(1),
|
|
57152
|
+
kind: string().min(1).optional()
|
|
57153
|
+
})
|
|
57154
|
+
});
|
|
56782
57155
|
var IntegrationInstanceDescriptionSchema = object({
|
|
56783
57156
|
/** What the instances are for the Integrations page; see {@link IntegrationInstanceRoleSchema}. */
|
|
56784
57157
|
role: IntegrationInstanceRoleSchema,
|
|
56785
57158
|
/** How the devices of an instance are found; absent means `{ mode: 'none' }`. */
|
|
56786
|
-
discovery:
|
|
56787
|
-
mode: _enum([
|
|
56788
|
-
"none",
|
|
56789
|
-
"lan",
|
|
56790
|
-
"account"
|
|
56791
|
-
]),
|
|
56792
|
-
scopedToInstance: boolean()
|
|
56793
|
-
}).optional(),
|
|
57159
|
+
discovery: IntegrationInstanceDiscoverySchema.optional(),
|
|
56794
57160
|
/** `single`: at most one instance can exist (Loki). `multiple`: an account each. */
|
|
56795
57161
|
instanceMode: IntegrationInstanceModeSchema,
|
|
56796
57162
|
/** What the instance is, for the UI (`destination`, `relay`, `account`). */
|
|
@@ -56811,7 +57177,9 @@ var IntegrationInstanceDescriptionSchema = object({
|
|
|
56811
57177
|
* `createInstance` without an `id` works: the provider mints it. Absent means the caller must
|
|
56812
57178
|
* send an id (the UI then mints an opaque one).
|
|
56813
57179
|
*/
|
|
56814
|
-
mintsId: boolean().optional()
|
|
57180
|
+
mintsId: boolean().optional(),
|
|
57181
|
+
/** The links to other instances the provider's kinds declare; absent means none. */
|
|
57182
|
+
links: array(IntegrationInstanceLinkSchema).optional()
|
|
56815
57183
|
});
|
|
56816
57184
|
var IntegrationInstanceStatusSchema = object({
|
|
56817
57185
|
state: _enum([
|
|
@@ -56831,8 +57199,8 @@ var IntegrationInstanceSchema = object({
|
|
|
56831
57199
|
configured: boolean(),
|
|
56832
57200
|
/**
|
|
56833
57201
|
* The instance's own on/off switch (D996), derived from the record body (`enabled !== false`,
|
|
56834
|
-
* so a row written before the field existed is on).
|
|
56835
|
-
*
|
|
57202
|
+
* so a row written before the field existed is on). The same for every role, `devices` included:
|
|
57203
|
+
* the body is the one store, `setInstanceEnabled` the one writer (epic #440, step 3).
|
|
56836
57204
|
*/
|
|
56837
57205
|
enabled: boolean().optional(),
|
|
56838
57206
|
/** The kind of this instance (one of `describe().kinds[].id`), when the provider has kinds. */
|
|
@@ -56882,7 +57250,8 @@ var integrationInstancesCapability = {
|
|
|
56882
57250
|
auth: "admin"
|
|
56883
57251
|
}),
|
|
56884
57252
|
/**
|
|
56885
|
-
* Switch ONE instance on or off
|
|
57253
|
+
* Switch ONE instance on or off, for every role; a missing record is created from the addon's
|
|
57254
|
+
* initial body. A row control, not a form field: `updateInstance.values` is the
|
|
56886
57255
|
* form patch (D62, D996). An off instance keeps its record and secrets and does no work.
|
|
56887
57256
|
*/
|
|
56888
57257
|
setInstanceEnabled: method(object({
|
|
@@ -59945,6 +60314,8 @@ var MigrationIntegrationSchema = object({
|
|
|
59945
60314
|
addonId: string(),
|
|
59946
60315
|
name: string(),
|
|
59947
60316
|
info: Rows,
|
|
60317
|
+
/** The registry's stored switch: read by the one-switch migration, nothing else. */
|
|
60318
|
+
enabled: boolean().optional(),
|
|
59948
60319
|
originStableId: string().optional()
|
|
59949
60320
|
});
|
|
59950
60321
|
var MigrationDeviceSchema = object({
|
|
@@ -70120,14 +70491,6 @@ var PetFountainStatusSchema = object({
|
|
|
70120
70491
|
empty: boolean().nullable(),
|
|
70121
70492
|
/** True while the pump is running. Null while unknown. */
|
|
70122
70493
|
pumpRunning: boolean().nullable(),
|
|
70123
|
-
/** Water drunk in the last drink, in litres. */
|
|
70124
|
-
lastDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
70125
|
-
/** Water drunk in the current hour, in litres. */
|
|
70126
|
-
currentHourDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
70127
|
-
/** Water drunk over the last 24 hours (rolling), in litres. */
|
|
70128
|
-
last24hDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
70129
|
-
/** Water drunk since local midnight, in litres. Null when the fountain has no such sensor. */
|
|
70130
|
-
todayDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
70131
70494
|
/** Decoded fault message. Null means healthy; a non-null string is an active fault. */
|
|
70132
70495
|
error: string().nullable(),
|
|
70133
70496
|
/** Ms epoch when the slice was last refreshed. */
|
|
@@ -70140,21 +70503,15 @@ var petFountainCapability = {
|
|
|
70140
70503
|
deviceNative: true,
|
|
70141
70504
|
mode: "singleton",
|
|
70142
70505
|
deviceTypes: [DeviceType.PetFountain],
|
|
70143
|
-
methods: {
|
|
70144
|
-
|
|
70145
|
-
|
|
70146
|
-
|
|
70147
|
-
|
|
70148
|
-
|
|
70149
|
-
|
|
70150
|
-
|
|
70151
|
-
|
|
70152
|
-
/** Clear the rolling daily consumption counters on the device. */
|
|
70153
|
-
resetDailyConsumption: method(object({ deviceId: DeviceIdSchema$1 }), _void(), {
|
|
70154
|
-
kind: "mutation",
|
|
70155
|
-
auth: "protected"
|
|
70156
|
-
})
|
|
70157
|
-
},
|
|
70506
|
+
methods: {
|
|
70507
|
+
/** Start or stop the pump. */
|
|
70508
|
+
setPump: method(object({
|
|
70509
|
+
deviceId: DeviceIdSchema$1,
|
|
70510
|
+
on: boolean()
|
|
70511
|
+
}), _void(), {
|
|
70512
|
+
kind: "mutation",
|
|
70513
|
+
auth: "protected"
|
|
70514
|
+
}) },
|
|
70158
70515
|
status: {
|
|
70159
70516
|
schema: PetFountainStatusSchema,
|
|
70160
70517
|
kind: "push"
|
|
@@ -70178,14 +70535,6 @@ var petFountainCapability = {
|
|
|
70178
70535
|
waterVolume: {
|
|
70179
70536
|
kind: "gauge",
|
|
70180
70537
|
unit: "L"
|
|
70181
|
-
},
|
|
70182
|
-
todayDrink: {
|
|
70183
|
-
kind: "gauge",
|
|
70184
|
-
unit: "L"
|
|
70185
|
-
},
|
|
70186
|
-
last24hDrink: {
|
|
70187
|
-
kind: "gauge",
|
|
70188
|
-
unit: "L"
|
|
70189
70538
|
}
|
|
70190
70539
|
} }
|
|
70191
70540
|
};
|
|
@@ -89916,13 +90265,6 @@ Object.freeze({
|
|
|
89916
90265
|
access: "view",
|
|
89917
90266
|
role: "viewer"
|
|
89918
90267
|
},
|
|
89919
|
-
"petFountain.resetDailyConsumption": {
|
|
89920
|
-
capName: "pet-fountain",
|
|
89921
|
-
capScope: "device",
|
|
89922
|
-
addonId: null,
|
|
89923
|
-
access: "delete",
|
|
89924
|
-
role: "viewer"
|
|
89925
|
-
},
|
|
89926
90268
|
"petFountain.setPump": {
|
|
89927
90269
|
capName: "pet-fountain",
|
|
89928
90270
|
capScope: "device",
|
|
@@ -96537,11 +96879,6 @@ Object.freeze({
|
|
|
96537
96879
|
form: "single",
|
|
96538
96880
|
optional: false
|
|
96539
96881
|
}],
|
|
96540
|
-
"petFountain.resetDailyConsumption": [{
|
|
96541
|
-
name: "deviceId",
|
|
96542
|
-
form: "single",
|
|
96543
|
-
optional: false
|
|
96544
|
-
}],
|
|
96545
96882
|
"petFountain.setPump": [{
|
|
96546
96883
|
name: "deviceId",
|
|
96547
96884
|
form: "single",
|
|
@@ -99336,100 +99673,6 @@ object({
|
|
|
99336
99673
|
delay: number().nonnegative().optional(),
|
|
99337
99674
|
commands: record(string(), unknown())
|
|
99338
99675
|
});
|
|
99339
|
-
entryBody({ brokerId: string() });
|
|
99340
|
-
function secretsOverMigrationApi(api) {
|
|
99341
|
-
return {
|
|
99342
|
-
resolve: async (refs) => {
|
|
99343
|
-
const { values } = await api.secrets.resolve({ refs: [...refs] });
|
|
99344
|
-
const out = {};
|
|
99345
|
-
for (const ref of refs) {
|
|
99346
|
-
const value = values[ref];
|
|
99347
|
-
out[ref] = value === null || value === void 0 ? { kind: "missing" } : {
|
|
99348
|
-
kind: "value",
|
|
99349
|
-
value,
|
|
99350
|
-
version: 0
|
|
99351
|
-
};
|
|
99352
|
-
}
|
|
99353
|
-
return out;
|
|
99354
|
-
},
|
|
99355
|
-
delete: async (refs) => (await api.secrets.delete({ refs: [...refs] })).deleted
|
|
99356
|
-
};
|
|
99357
|
-
}
|
|
99358
|
-
/** `ctx.records` as the migration API offers it: bind a kind, read and write by id. */
|
|
99359
|
-
function recordsOverMigrationApi(api) {
|
|
99360
|
-
return { kind: (definition) => {
|
|
99361
|
-
const handle = api.records.kind(definition);
|
|
99362
|
-
return {
|
|
99363
|
-
get: (id) => handle.get({ id }),
|
|
99364
|
-
getResolved: (id) => handle.getResolved({ id }),
|
|
99365
|
-
put: (input, opts) => handle.put({
|
|
99366
|
-
...input,
|
|
99367
|
-
...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
|
|
99368
|
-
}),
|
|
99369
|
-
delete: (id) => handle.delete({ id })
|
|
99370
|
-
};
|
|
99371
|
-
} };
|
|
99372
|
-
}
|
|
99373
|
-
function integrationRowsApiOver(api) {
|
|
99374
|
-
return {
|
|
99375
|
-
list: async () => (await api.integrations.list({})).integrations,
|
|
99376
|
-
readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
|
|
99377
|
-
clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
|
|
99378
|
-
};
|
|
99379
|
-
}
|
|
99380
|
-
/**
|
|
99381
|
-
* One serial lane per migration API: a log line is delivered after the line before it, so the
|
|
99382
|
-
* order the steps wrote them in is the order the hub reads them in. A delivery that fails
|
|
99383
|
-
* is reported once through the same door; if that fails too nothing is left to tell, and the
|
|
99384
|
-
* line is dropped rather than thrown into a migration step or left as an unhandled rejection.
|
|
99385
|
-
*/
|
|
99386
|
-
var lanes = /* @__PURE__ */ new WeakMap();
|
|
99387
|
-
function deliver(api, send) {
|
|
99388
|
-
const next = (lanes.get(api) ?? Promise.resolve()).then(send).then(() => void 0).catch(async (error) => {
|
|
99389
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
99390
|
-
await api.log.warn({ message: `a migration log line could not be delivered: ${reason}` }).catch(() => void 0);
|
|
99391
|
-
});
|
|
99392
|
-
lanes.set(api, next);
|
|
99393
|
-
return next;
|
|
99394
|
-
}
|
|
99395
|
-
function warnOver(api) {
|
|
99396
|
-
return (message) => deliver(api, () => api.log.warn({ message }));
|
|
99397
|
-
}
|
|
99398
|
-
/** What the rows-to-records move needs, over the migration API. */
|
|
99399
|
-
function rowsDepsOver(api) {
|
|
99400
|
-
return {
|
|
99401
|
-
api: integrationRowsApiOver(api),
|
|
99402
|
-
records: recordsOverMigrationApi(api),
|
|
99403
|
-
secrets: secretsOverMigrationApi(api),
|
|
99404
|
-
warn: warnOver(api)
|
|
99405
|
-
};
|
|
99406
|
-
}
|
|
99407
|
-
function defaultIntegrationApiOver$1(api) {
|
|
99408
|
-
return {
|
|
99409
|
-
...integrationRowsApiOver(api),
|
|
99410
|
-
listDevices: async (addonId) => (await api.devices.list({ addonId })).devices,
|
|
99411
|
-
readDeviceHasConfig: async (deviceId) => (await api.devices.get({ deviceId }))?.hasConfig ?? false,
|
|
99412
|
-
setDeviceIntegrationId: async (deviceId, integrationId) => {
|
|
99413
|
-
await api.devices.setIntegrationId({
|
|
99414
|
-
deviceId,
|
|
99415
|
-
integrationId
|
|
99416
|
-
});
|
|
99417
|
-
},
|
|
99418
|
-
readDeviceIntegrationId: async (deviceId) => (await api.devices.get({ deviceId }))?.integrationId ?? null
|
|
99419
|
-
};
|
|
99420
|
-
}
|
|
99421
|
-
/** What the rows-to-records move and the device claim need, over the migration API. */
|
|
99422
|
-
function defaultIntegrationDepsOver(api) {
|
|
99423
|
-
return {
|
|
99424
|
-
...rowsDepsOver(api),
|
|
99425
|
-
api: defaultIntegrationApiOver$1(api),
|
|
99426
|
-
info: (message) => deliver(api, () => api.log.info({ message })),
|
|
99427
|
-
warnDevice: (message, deviceId) => deliver(api, () => api.log.warn({
|
|
99428
|
-
message,
|
|
99429
|
-
tags: { deviceId }
|
|
99430
|
-
}))
|
|
99431
|
-
};
|
|
99432
|
-
}
|
|
99433
99676
|
/**
|
|
99434
99677
|
* Per-device bounds for the STILLS, which are a different artifact entirely.
|
|
99435
99678
|
*
|
|
@@ -113156,6 +113399,10 @@ var HikvisionProviderAddon = class extends BaseDeviceProvider {
|
|
|
113156
113399
|
const records = this.ctx.records;
|
|
113157
113400
|
if (records === void 0) throw new Error("provider-hikvision: ctx.records is required (hub-only addon)");
|
|
113158
113401
|
await records.declare(hikvisionRecordKinds);
|
|
113402
|
+
this.declareRegistrySwitch({
|
|
113403
|
+
kind: hikvisionConnectionsEntryKind,
|
|
113404
|
+
initialBody: (name) => ({ name })
|
|
113405
|
+
});
|
|
113159
113406
|
await this.runMigrations(defaultIntegrationMigrations({
|
|
113160
113407
|
addonId: this.addonId,
|
|
113161
113408
|
date: HIKVISION_MIGRATIONS_DATE
|