@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.js
CHANGED
|
@@ -6014,7 +6014,7 @@ var ZodIssueCode = {
|
|
|
6014
6014
|
var ZodFirstPartyTypeKind;
|
|
6015
6015
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
6016
6016
|
//#endregion
|
|
6017
|
-
//#region ../types/dist/sleep-
|
|
6017
|
+
//#region ../types/dist/sleep-CmjWurK5.mjs
|
|
6018
6018
|
/**
|
|
6019
6019
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
6020
6020
|
* window to float samples (D455).
|
|
@@ -6698,137 +6698,179 @@ async function runAddonMigrations(host, migrations, logger, options = {}) {
|
|
|
6698
6698
|
blockOwner
|
|
6699
6699
|
};
|
|
6700
6700
|
}
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
}
|
|
6717
|
-
return parsed.data;
|
|
6718
|
-
};
|
|
6719
|
-
const set = async (next) => {
|
|
6720
|
-
const validated = deps.schema.parse(next);
|
|
6721
|
-
await deps.write({ [deps.key]: validated });
|
|
6722
|
-
};
|
|
6723
|
-
const update = async (fn) => {
|
|
6724
|
-
await set(fn(await get()));
|
|
6701
|
+
function secretsOverMigrationApi(api) {
|
|
6702
|
+
return {
|
|
6703
|
+
resolve: async (refs) => {
|
|
6704
|
+
const { values } = await api.secrets.resolve({ refs: [...refs] });
|
|
6705
|
+
const out = {};
|
|
6706
|
+
for (const ref of refs) {
|
|
6707
|
+
const value = values[ref];
|
|
6708
|
+
out[ref] = value === null || value === void 0 ? { kind: "missing" } : {
|
|
6709
|
+
kind: "value",
|
|
6710
|
+
value,
|
|
6711
|
+
version: 0
|
|
6712
|
+
};
|
|
6713
|
+
}
|
|
6714
|
+
return out;
|
|
6715
|
+
},
|
|
6716
|
+
delete: async (refs) => (await api.secrets.delete({ refs: [...refs] })).deleted
|
|
6725
6717
|
};
|
|
6718
|
+
}
|
|
6719
|
+
/** The record calls the one-switch migration makes, over the migration API. */
|
|
6720
|
+
function switchRecordsOverMigrationApi(api) {
|
|
6721
|
+
return { kind: (definition) => {
|
|
6722
|
+
const handle = api.records.kind(definition);
|
|
6723
|
+
return {
|
|
6724
|
+
get: (id) => handle.get({ id }),
|
|
6725
|
+
put: (input, opts) => handle.put({
|
|
6726
|
+
...input,
|
|
6727
|
+
...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
|
|
6728
|
+
}),
|
|
6729
|
+
patch: (id, partial) => handle.patch({
|
|
6730
|
+
id,
|
|
6731
|
+
partial
|
|
6732
|
+
})
|
|
6733
|
+
};
|
|
6734
|
+
} };
|
|
6735
|
+
}
|
|
6736
|
+
/** `ctx.records` as the migration API offers it: bind a kind, read and write by id. */
|
|
6737
|
+
function recordsOverMigrationApi(api) {
|
|
6738
|
+
return { kind: (definition) => {
|
|
6739
|
+
const handle = api.records.kind(definition);
|
|
6740
|
+
return {
|
|
6741
|
+
get: (id) => handle.get({ id }),
|
|
6742
|
+
getResolved: (id) => handle.getResolved({ id }),
|
|
6743
|
+
put: (input, opts) => handle.put({
|
|
6744
|
+
...input,
|
|
6745
|
+
...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
|
|
6746
|
+
}),
|
|
6747
|
+
delete: (id) => handle.delete({ id })
|
|
6748
|
+
};
|
|
6749
|
+
} };
|
|
6750
|
+
}
|
|
6751
|
+
function integrationRowsApiOver(api) {
|
|
6726
6752
|
return {
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6753
|
+
list: async () => (await api.integrations.list({})).integrations,
|
|
6754
|
+
readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
|
|
6755
|
+
clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
|
|
6730
6756
|
};
|
|
6731
6757
|
}
|
|
6732
6758
|
/**
|
|
6733
|
-
*
|
|
6734
|
-
*
|
|
6735
|
-
*
|
|
6736
|
-
*
|
|
6737
|
-
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
6738
|
-
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
6739
|
-
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
6740
|
-
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
6741
|
-
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
6742
|
-
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
6743
|
-
*
|
|
6744
|
-
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
6745
|
-
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
6746
|
-
* schema and routes reads/writes through these helpers.
|
|
6747
|
-
*
|
|
6748
|
-
* ## No bare-key fallback — deliberate
|
|
6749
|
-
*
|
|
6750
|
-
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
6751
|
-
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
6752
|
-
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
6753
|
-
* the store is invisible to every node, hub included, so one node's
|
|
6754
|
-
* selection can never leak onto another. (This generalizes the
|
|
6755
|
-
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
6756
|
-
* arbitrary set of per-node field keys.)
|
|
6757
|
-
*
|
|
6758
|
-
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
6759
|
-
* LEAF module: import it via its deep path, never from the root barrel.
|
|
6760
|
-
*/
|
|
6761
|
-
/**
|
|
6762
|
-
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
6763
|
-
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
6764
|
-
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
6765
|
-
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
6759
|
+
* One serial lane per migration API: a log line is delivered after the line before it, so the
|
|
6760
|
+
* order the steps wrote them in is the order the hub reads them in. A delivery that fails
|
|
6761
|
+
* is reported once through the same door; if that fails too nothing is left to tell, and the
|
|
6762
|
+
* line is dropped rather than thrown into a migration step or left as an unhandled rejection.
|
|
6766
6763
|
*/
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
const
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6764
|
+
var lanes = /* @__PURE__ */ new WeakMap();
|
|
6765
|
+
function deliver(api, send) {
|
|
6766
|
+
const next = (lanes.get(api) ?? Promise.resolve()).then(send).then(() => void 0).catch(async (error) => {
|
|
6767
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
6768
|
+
await api.log.warn({ message: `a migration log line could not be delivered: ${reason}` }).catch(() => void 0);
|
|
6769
|
+
});
|
|
6770
|
+
lanes.set(api, next);
|
|
6771
|
+
return next;
|
|
6773
6772
|
}
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
6773
|
+
function warnOver(api) {
|
|
6774
|
+
return (message) => deliver(api, () => api.log.warn({ message }));
|
|
6777
6775
|
}
|
|
6778
|
-
/**
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6776
|
+
/** What the rows-to-records move needs, over the migration API. */
|
|
6777
|
+
function rowsDepsOver(api) {
|
|
6778
|
+
return {
|
|
6779
|
+
api: integrationRowsApiOver(api),
|
|
6780
|
+
records: recordsOverMigrationApi(api),
|
|
6781
|
+
secrets: secretsOverMigrationApi(api),
|
|
6782
|
+
warn: warnOver(api)
|
|
6783
|
+
};
|
|
6786
6784
|
}
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
|
|
6796
|
-
|
|
6797
|
-
|
|
6785
|
+
function defaultIntegrationApiOver(api) {
|
|
6786
|
+
return {
|
|
6787
|
+
...integrationRowsApiOver(api),
|
|
6788
|
+
listDevices: async (addonId) => (await api.devices.list({ addonId })).devices,
|
|
6789
|
+
readDeviceHasConfig: async (deviceId) => (await api.devices.get({ deviceId }))?.hasConfig ?? false,
|
|
6790
|
+
setDeviceIntegrationId: async (deviceId, integrationId) => {
|
|
6791
|
+
await api.devices.setIntegrationId({
|
|
6792
|
+
deviceId,
|
|
6793
|
+
integrationId
|
|
6794
|
+
});
|
|
6795
|
+
},
|
|
6796
|
+
readDeviceIntegrationId: async (deviceId) => (await api.devices.get({ deviceId }))?.integrationId ?? null
|
|
6797
|
+
};
|
|
6798
6798
|
}
|
|
6799
|
-
/**
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
|
|
6803
|
-
|
|
6804
|
-
|
|
6805
|
-
|
|
6806
|
-
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
*/
|
|
6813
|
-
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
|
|
6799
|
+
/** What the rows-to-records move and the device claim need, over the migration API. */
|
|
6800
|
+
function defaultIntegrationDepsOver(api) {
|
|
6801
|
+
return {
|
|
6802
|
+
...rowsDepsOver(api),
|
|
6803
|
+
api: defaultIntegrationApiOver(api),
|
|
6804
|
+
info: (message) => deliver(api, () => api.log.info({ message })),
|
|
6805
|
+
warnDevice: (message, deviceId) => deliver(api, () => api.log.warn({
|
|
6806
|
+
message,
|
|
6807
|
+
tags: { deviceId }
|
|
6808
|
+
}))
|
|
6809
|
+
};
|
|
6810
|
+
}
|
|
6811
|
+
var PREFIX = "records/";
|
|
6812
|
+
/** The base of every records failure. `detail` is the human part of the message. */
|
|
6813
|
+
var RecordsError = class extends Error {
|
|
6814
|
+
code;
|
|
6815
|
+
detail;
|
|
6816
|
+
constructor(code, detail) {
|
|
6817
|
+
super(`${PREFIX}${code}: ${detail}`);
|
|
6818
|
+
this.name = "RecordsError";
|
|
6819
|
+
this.code = code;
|
|
6820
|
+
this.detail = detail;
|
|
6819
6821
|
}
|
|
6820
|
-
|
|
6821
|
-
|
|
6822
|
-
|
|
6822
|
+
};
|
|
6823
|
+
/** A write guarded by `ifRev` found another revision (or an existing row for `ifRev: 0`). */
|
|
6824
|
+
var RevConflictError = class extends RecordsError {
|
|
6825
|
+
constructor(detail) {
|
|
6826
|
+
super("rev-conflict", detail);
|
|
6827
|
+
this.name = "RevConflictError";
|
|
6823
6828
|
}
|
|
6824
|
-
|
|
6829
|
+
};
|
|
6830
|
+
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
6831
|
+
var RecordSecretUnavailableError = class extends RecordsError {
|
|
6832
|
+
constructor(detail) {
|
|
6833
|
+
super("secret-unavailable", detail);
|
|
6834
|
+
this.name = "RecordSecretUnavailableError";
|
|
6835
|
+
}
|
|
6836
|
+
};
|
|
6837
|
+
var InvalidRecordError = class extends RecordsError {
|
|
6838
|
+
constructor(detail) {
|
|
6839
|
+
super("invalid-record", detail);
|
|
6840
|
+
this.name = "InvalidRecordError";
|
|
6841
|
+
}
|
|
6842
|
+
};
|
|
6843
|
+
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
6844
|
+
var DeclarationRefusedError = class extends RecordsError {
|
|
6845
|
+
constructor(detail) {
|
|
6846
|
+
super("declaration-refused", detail);
|
|
6847
|
+
this.name = "DeclarationRefusedError";
|
|
6848
|
+
}
|
|
6849
|
+
};
|
|
6850
|
+
function linkTargetOf(meta) {
|
|
6851
|
+
if (typeof meta !== "object" || meta === null) return void 0;
|
|
6852
|
+
const link = Reflect.get(meta, "link");
|
|
6853
|
+
const parsed = LinkTargetSchema.safeParse(link);
|
|
6854
|
+
return parsed.success ? parsed.data : void 0;
|
|
6855
|
+
}
|
|
6856
|
+
var LinkTargetSchema = object({
|
|
6857
|
+
cap: string().min(1),
|
|
6858
|
+
kind: string().min(1).optional()
|
|
6859
|
+
});
|
|
6860
|
+
/** The links a kind declares, read from the meta of its body fields. */
|
|
6861
|
+
function linksOfKind(kind) {
|
|
6862
|
+
const schema = kind.schema;
|
|
6863
|
+
if (!(schema instanceof ZodObject)) return [];
|
|
6864
|
+
const links = [];
|
|
6865
|
+
for (const [field, fieldSchema] of Object.entries(schema.shape)) {
|
|
6866
|
+
const to = linkTargetOf(globalRegistry.get(fieldSchema));
|
|
6867
|
+
if (to !== void 0) links.push({
|
|
6868
|
+
field,
|
|
6869
|
+
to
|
|
6870
|
+
});
|
|
6871
|
+
}
|
|
6872
|
+
return links;
|
|
6825
6873
|
}
|
|
6826
|
-
/** Every scope, in the order the guard and the docs list them. */
|
|
6827
|
-
var SCOPED_SETTINGS_SCOPES = [
|
|
6828
|
-
"cluster",
|
|
6829
|
-
"device-defaults",
|
|
6830
|
-
"node"
|
|
6831
|
-
];
|
|
6832
6874
|
/**
|
|
6833
6875
|
* The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
|
|
6834
6876
|
*
|
|
@@ -6963,6 +7005,652 @@ function parseSecretRef(ref) {
|
|
|
6963
7005
|
fieldPath
|
|
6964
7006
|
};
|
|
6965
7007
|
}
|
|
7008
|
+
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
7009
|
+
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
7010
|
+
var RECORD_DATABASES = ["settings", "events"];
|
|
7011
|
+
/** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
|
|
7012
|
+
var RECORD_CLASSES = [
|
|
7013
|
+
"config",
|
|
7014
|
+
"ledger",
|
|
7015
|
+
"audit",
|
|
7016
|
+
"mirror",
|
|
7017
|
+
"ephemeral"
|
|
7018
|
+
];
|
|
7019
|
+
var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
7020
|
+
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
7021
|
+
var RECORD_BATCH_MAX = 1e3;
|
|
7022
|
+
var RECORD_QUERY_MAX = 1e3;
|
|
7023
|
+
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
7024
|
+
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
7025
|
+
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
7026
|
+
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
7027
|
+
/**
|
|
7028
|
+
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
7029
|
+
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
7030
|
+
* (`auth.accessToken`, `headers[].value`).
|
|
7031
|
+
*
|
|
7032
|
+
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
7033
|
+
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
7034
|
+
* key releases exactly that key's secret.
|
|
7035
|
+
*
|
|
7036
|
+
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
7037
|
+
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
7038
|
+
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
7039
|
+
* leaf names its element: `headers[X-Api].value`.
|
|
7040
|
+
*
|
|
7041
|
+
* Pure and browser-safe. Nothing here mutates: every transform returns a new value.
|
|
7042
|
+
*/
|
|
7043
|
+
/** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
|
|
7044
|
+
function parseSecretPath(path) {
|
|
7045
|
+
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
7046
|
+
return path.split(".").map((raw) => {
|
|
7047
|
+
const each = raw.endsWith("[]");
|
|
7048
|
+
const map = raw.endsWith("{}");
|
|
7049
|
+
const key = each || map ? raw.slice(0, -2) : raw;
|
|
7050
|
+
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
7051
|
+
return {
|
|
7052
|
+
key,
|
|
7053
|
+
each,
|
|
7054
|
+
map
|
|
7055
|
+
};
|
|
7056
|
+
});
|
|
7057
|
+
}
|
|
7058
|
+
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
7059
|
+
function secretArrayPrefixes(path) {
|
|
7060
|
+
const segments = parseSecretPath(path);
|
|
7061
|
+
const prefixes = [];
|
|
7062
|
+
const walked = [];
|
|
7063
|
+
for (const segment of segments) {
|
|
7064
|
+
walked.push(segment.key);
|
|
7065
|
+
if (segment.each) prefixes.push(walked.join("."));
|
|
7066
|
+
}
|
|
7067
|
+
return prefixes;
|
|
7068
|
+
}
|
|
7069
|
+
function isRecord$6(value) {
|
|
7070
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7071
|
+
}
|
|
7072
|
+
function elementId(element, idKey, declared, prefix) {
|
|
7073
|
+
const id = isRecord$6(element) ? element[idKey] : void 0;
|
|
7074
|
+
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`);
|
|
7075
|
+
return id;
|
|
7076
|
+
}
|
|
7077
|
+
/**
|
|
7078
|
+
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
7079
|
+
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
7080
|
+
* result is a new body, `data` is untouched.
|
|
7081
|
+
*/
|
|
7082
|
+
var REMOVE_LEAF = Symbol("remove-leaf");
|
|
7083
|
+
function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
|
|
7084
|
+
if (!isRecord$6(node)) return node;
|
|
7085
|
+
const segment = segments[index];
|
|
7086
|
+
if (segment === void 0) return node;
|
|
7087
|
+
if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
|
|
7088
|
+
const child = node[segment.key];
|
|
7089
|
+
const keys = [...walkedKeys, segment.key];
|
|
7090
|
+
const last = index === segments.length - 1;
|
|
7091
|
+
if (segment.each) {
|
|
7092
|
+
if (!Array.isArray(child)) return node;
|
|
7093
|
+
const prefix = keys.join(".");
|
|
7094
|
+
const idKey = arrayKeys[prefix];
|
|
7095
|
+
if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
|
|
7096
|
+
const mapped = child.map((element) => {
|
|
7097
|
+
const id = elementId(element, idKey, declared, prefix);
|
|
7098
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
|
|
7099
|
+
return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
|
|
7100
|
+
});
|
|
7101
|
+
return {
|
|
7102
|
+
...node,
|
|
7103
|
+
[segment.key]: mapped
|
|
7104
|
+
};
|
|
7105
|
+
}
|
|
7106
|
+
if (segment.map) {
|
|
7107
|
+
if (!isRecord$6(child)) return node;
|
|
7108
|
+
const kept = Object.entries(child).map(([mapKey, value]) => {
|
|
7109
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
|
|
7110
|
+
if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
|
|
7111
|
+
return [mapKey, visit({
|
|
7112
|
+
declared,
|
|
7113
|
+
concrete,
|
|
7114
|
+
value
|
|
7115
|
+
})];
|
|
7116
|
+
}).filter(([, value]) => value !== REMOVE_LEAF);
|
|
7117
|
+
return {
|
|
7118
|
+
...node,
|
|
7119
|
+
[segment.key]: Object.fromEntries(kept)
|
|
7120
|
+
};
|
|
7121
|
+
}
|
|
7122
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
7123
|
+
if (last) {
|
|
7124
|
+
const replacement = visit({
|
|
7125
|
+
declared,
|
|
7126
|
+
concrete,
|
|
7127
|
+
value: child
|
|
7128
|
+
});
|
|
7129
|
+
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
7130
|
+
return {
|
|
7131
|
+
...node,
|
|
7132
|
+
[segment.key]: replacement
|
|
7133
|
+
};
|
|
7134
|
+
}
|
|
7135
|
+
return {
|
|
7136
|
+
...node,
|
|
7137
|
+
[segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
|
|
7138
|
+
};
|
|
7139
|
+
}
|
|
7140
|
+
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
7141
|
+
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
7142
|
+
let current = data;
|
|
7143
|
+
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
7144
|
+
return current;
|
|
7145
|
+
}
|
|
7146
|
+
/** Every present secret leaf, read-only. */
|
|
7147
|
+
function collectSecretLeaves(data, paths, arrayKeys) {
|
|
7148
|
+
const found = [];
|
|
7149
|
+
mapSecretLeaves(data, paths, arrayKeys, (leaf) => {
|
|
7150
|
+
found.push(leaf);
|
|
7151
|
+
return leaf.value;
|
|
7152
|
+
});
|
|
7153
|
+
return found;
|
|
7154
|
+
}
|
|
7155
|
+
/**
|
|
7156
|
+
* The keychain collection name a kind's secrets live under. Prefixed so a
|
|
7157
|
+
* record's refs never collide with the refs a legacy collection of the same name
|
|
7158
|
+
* already holds during an adoption.
|
|
7159
|
+
*/
|
|
7160
|
+
function recordSecretCollection(kind) {
|
|
7161
|
+
return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
|
|
7162
|
+
}
|
|
7163
|
+
/** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
|
|
7164
|
+
function recordSecretRef(owner, kind, rowId, concretePath) {
|
|
7165
|
+
return buildSecretRef({
|
|
7166
|
+
owner,
|
|
7167
|
+
scope: {
|
|
7168
|
+
kind: "row",
|
|
7169
|
+
collection: recordSecretCollection(kind),
|
|
7170
|
+
rowId
|
|
7171
|
+
},
|
|
7172
|
+
fieldPath: concretePath
|
|
7173
|
+
});
|
|
7174
|
+
}
|
|
7175
|
+
/**
|
|
7176
|
+
* A stored secret, as an admin read shows it: a VIEW naming the row's own
|
|
7177
|
+
* keychain ref (`set: true`), never the value and no longer the bare redaction
|
|
7178
|
+
* token. The form hands it to the secret field, which reveals the value by ref
|
|
7179
|
+
* through the audited `keychain-admin.reveal`; sent back untouched it keeps the
|
|
7180
|
+
* stored secret (the records door reads a view as KEEP).
|
|
7181
|
+
*
|
|
7182
|
+
* ONE implementation for the entries service and for every addon that serves
|
|
7183
|
+
* its own instances (`RecordIntegrationInstances`).
|
|
7184
|
+
*/
|
|
7185
|
+
function isRecord$5(value) {
|
|
7186
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7187
|
+
}
|
|
7188
|
+
function secretViewsOf(owner, kind, id, decl, data) {
|
|
7189
|
+
if (decl.secretPaths.length === 0) return data;
|
|
7190
|
+
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
7191
|
+
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
7192
|
+
return {
|
|
7193
|
+
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
7194
|
+
v: 1,
|
|
7195
|
+
set: true
|
|
7196
|
+
};
|
|
7197
|
+
});
|
|
7198
|
+
return isRecord$5(shown) ? shown : data;
|
|
7199
|
+
}
|
|
7200
|
+
/** The most instances one addon lists (an integrations page, not a table). */
|
|
7201
|
+
var INSTANCES_LIST_MAX = 1e3;
|
|
7202
|
+
/**
|
|
7203
|
+
* The ONE reader of an instance's switch (D996): an absent field means on, so a row written
|
|
7204
|
+
* before the field existed needs no migration. Every consumer of an instance body asks this.
|
|
7205
|
+
*/
|
|
7206
|
+
function isInstanceEnabled(body) {
|
|
7207
|
+
return body.enabled !== false;
|
|
7208
|
+
}
|
|
7209
|
+
/** The body key of the switch; only {@link RecordIntegrationInstances.setInstanceEnabled} writes it. */
|
|
7210
|
+
var SWITCH_KEY = "enabled";
|
|
7211
|
+
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
7212
|
+
function topLevelSecretKeys(paths) {
|
|
7213
|
+
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
7214
|
+
}
|
|
7215
|
+
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
7216
|
+
function secretMapKeys(paths) {
|
|
7217
|
+
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
7218
|
+
}
|
|
7219
|
+
/**
|
|
7220
|
+
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
7221
|
+
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
7222
|
+
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
7223
|
+
*/
|
|
7224
|
+
function secretMapPatch(value) {
|
|
7225
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
7226
|
+
const out = {};
|
|
7227
|
+
for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
|
|
7228
|
+
else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
|
|
7229
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
7230
|
+
}
|
|
7231
|
+
var RecordIntegrationInstances = class {
|
|
7232
|
+
records;
|
|
7233
|
+
kind;
|
|
7234
|
+
hooks;
|
|
7235
|
+
handle;
|
|
7236
|
+
secretKeys;
|
|
7237
|
+
secretMaps;
|
|
7238
|
+
nameField;
|
|
7239
|
+
switchListeners = /* @__PURE__ */ new Set();
|
|
7240
|
+
constructor(records, kind, hooks) {
|
|
7241
|
+
this.records = records;
|
|
7242
|
+
this.kind = kind;
|
|
7243
|
+
this.hooks = hooks;
|
|
7244
|
+
this.handle = records.kind(kind);
|
|
7245
|
+
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
7246
|
+
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
7247
|
+
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
7248
|
+
}
|
|
7249
|
+
/**
|
|
7250
|
+
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
7251
|
+
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
7252
|
+
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
7253
|
+
*/
|
|
7254
|
+
async readResolved(id) {
|
|
7255
|
+
try {
|
|
7256
|
+
const record = await this.handle.getResolved(id);
|
|
7257
|
+
return record === null ? null : {
|
|
7258
|
+
id,
|
|
7259
|
+
body: record.data,
|
|
7260
|
+
enabled: isInstanceEnabled(record.data),
|
|
7261
|
+
secrets: "resolved"
|
|
7262
|
+
};
|
|
7263
|
+
} catch (err) {
|
|
7264
|
+
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
7265
|
+
const stored = await this.handle.get(id);
|
|
7266
|
+
if (stored === null) return null;
|
|
7267
|
+
return {
|
|
7268
|
+
id,
|
|
7269
|
+
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
7270
|
+
enabled: isInstanceEnabled(stored.data),
|
|
7271
|
+
secrets: "unavailable"
|
|
7272
|
+
};
|
|
7273
|
+
}
|
|
7274
|
+
}
|
|
7275
|
+
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
7276
|
+
async getResolved(id) {
|
|
7277
|
+
return (await this.readResolved(id))?.body ?? null;
|
|
7278
|
+
}
|
|
7279
|
+
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
7280
|
+
async listResolved() {
|
|
7281
|
+
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
7282
|
+
const out = [];
|
|
7283
|
+
for (const record of page.records) {
|
|
7284
|
+
const read = await this.readResolved(record.id);
|
|
7285
|
+
if (read !== null) out.push(read);
|
|
7286
|
+
}
|
|
7287
|
+
return out;
|
|
7288
|
+
}
|
|
7289
|
+
viewOf(record) {
|
|
7290
|
+
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
7291
|
+
const rawName = record.data[this.nameField];
|
|
7292
|
+
const kind = this.hooks.kindOf?.(record.data);
|
|
7293
|
+
const health = this.hooks.health?.(record.data, record.id);
|
|
7294
|
+
return {
|
|
7295
|
+
id: record.id,
|
|
7296
|
+
name: typeof rawName === "string" ? rawName : record.id,
|
|
7297
|
+
configured: this.hooks.configured(record.data),
|
|
7298
|
+
enabled: isInstanceEnabled(record.data),
|
|
7299
|
+
formValues: shown,
|
|
7300
|
+
...kind !== void 0 ? { kind } : {},
|
|
7301
|
+
...health?.status !== void 0 ? { status: health.status } : {},
|
|
7302
|
+
...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
|
|
7303
|
+
};
|
|
7304
|
+
}
|
|
7305
|
+
describe = async () => {
|
|
7306
|
+
const declared = linksOfKind(this.kind);
|
|
7307
|
+
const links = this.hooks.description.links !== void 0 || declared.length === 0 ? {} : { links: declared.map((link) => ({
|
|
7308
|
+
kind: this.kind.name,
|
|
7309
|
+
field: link.field,
|
|
7310
|
+
to: link.to
|
|
7311
|
+
})) };
|
|
7312
|
+
return {
|
|
7313
|
+
...this.hooks.description,
|
|
7314
|
+
...links,
|
|
7315
|
+
...this.hooks.mintId === void 0 ? {} : { mintsId: true }
|
|
7316
|
+
};
|
|
7317
|
+
};
|
|
7318
|
+
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
7319
|
+
listInstances = async () => {
|
|
7320
|
+
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
7321
|
+
};
|
|
7322
|
+
getInstance = async ({ id }) => {
|
|
7323
|
+
const record = await this.handle.get(id);
|
|
7324
|
+
return record === null ? null : this.viewOf(record);
|
|
7325
|
+
};
|
|
7326
|
+
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
7327
|
+
createInstance = async ({ id, name, kind, values }) => {
|
|
7328
|
+
const minted = id ?? this.hooks.mintId?.({
|
|
7329
|
+
name,
|
|
7330
|
+
...kind !== void 0 ? { kind } : {}
|
|
7331
|
+
});
|
|
7332
|
+
if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
|
|
7333
|
+
await this.handle.put({
|
|
7334
|
+
id: minted,
|
|
7335
|
+
data: this.hooks.initialBody(name, kind)
|
|
7336
|
+
}, { ifRev: 0 });
|
|
7337
|
+
const patch = this.patchOf(values ?? {});
|
|
7338
|
+
if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
|
|
7339
|
+
await this.hooks.onChanged?.(minted, "created");
|
|
7340
|
+
return { id: minted };
|
|
7341
|
+
};
|
|
7342
|
+
updateInstance = async ({ id, name, values }) => {
|
|
7343
|
+
const patch = this.patchOf(values);
|
|
7344
|
+
if (name !== void 0) patch[this.nameField] = name;
|
|
7345
|
+
await this.handle.patch(id, patch);
|
|
7346
|
+
await this.hooks.onChanged?.(id, "updated");
|
|
7347
|
+
return { ok: true };
|
|
7348
|
+
};
|
|
7349
|
+
/** The record patch a form `values` object means: secrets kept, cleared or replaced. */
|
|
7350
|
+
patchOf(values) {
|
|
7351
|
+
const patch = {};
|
|
7352
|
+
for (const [key, value] of Object.entries(values)) {
|
|
7353
|
+
if (value === void 0) continue;
|
|
7354
|
+
if (key === "enabled") continue;
|
|
7355
|
+
if (this.secretMaps.has(key)) {
|
|
7356
|
+
const entries = secretMapPatch(value);
|
|
7357
|
+
if (entries !== null) patch[key] = entries;
|
|
7358
|
+
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
7359
|
+
else if (isSecretClear(value)) patch[key] = null;
|
|
7360
|
+
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
7361
|
+
}
|
|
7362
|
+
return patch;
|
|
7363
|
+
}
|
|
7364
|
+
/**
|
|
7365
|
+
* Listen to the switch of ANY instance of this helper (in the process that serves it). The
|
|
7366
|
+
* durable replacement of the `integration.enabled` / `integration.disabled` events (D8): the
|
|
7367
|
+
* addon reconciles from the record, whichever way it flipped.
|
|
7368
|
+
*/
|
|
7369
|
+
onSwitched(listener) {
|
|
7370
|
+
this.switchListeners.add(listener);
|
|
7371
|
+
}
|
|
7372
|
+
/**
|
|
7373
|
+
* The ONE writer of the switch (D996, D1014): the record body's `enabled`, for every role. A
|
|
7374
|
+
* configured thing is an instance, so an id with no record yet (a default integration that was
|
|
7375
|
+
* never configured) gets its record from `initialBody` before the switch is written.
|
|
7376
|
+
*/
|
|
7377
|
+
setInstanceEnabled = async ({ id, enabled }) => {
|
|
7378
|
+
if (await this.handle.get(id) === null) await this.handle.put({
|
|
7379
|
+
id,
|
|
7380
|
+
data: this.hooks.initialBody(id)
|
|
7381
|
+
}, { ifRev: 0 });
|
|
7382
|
+
await this.handle.patch(id, { [SWITCH_KEY]: enabled });
|
|
7383
|
+
await this.hooks.onChanged?.(id, "enabled");
|
|
7384
|
+
for (const listener of this.switchListeners) await listener(id, enabled);
|
|
7385
|
+
return { ok: true };
|
|
7386
|
+
};
|
|
7387
|
+
/** The row and its keychain refs go together (the records door). */
|
|
7388
|
+
deleteInstance = async ({ id }) => {
|
|
7389
|
+
await this.handle.delete(id);
|
|
7390
|
+
await this.hooks.onChanged?.(id, "deleted");
|
|
7391
|
+
return { ok: true };
|
|
7392
|
+
};
|
|
7393
|
+
testInstance = async (input) => {
|
|
7394
|
+
if (this.hooks.test === void 0) return {
|
|
7395
|
+
success: false,
|
|
7396
|
+
status: "unsupported",
|
|
7397
|
+
error: "This integration declares no connection test"
|
|
7398
|
+
};
|
|
7399
|
+
return this.hooks.test(input);
|
|
7400
|
+
};
|
|
7401
|
+
/** The flat provider object to hand to `registerProvider`. */
|
|
7402
|
+
toProvider() {
|
|
7403
|
+
return {
|
|
7404
|
+
describe: this.describe,
|
|
7405
|
+
instanceFormSchema: this.instanceFormSchema,
|
|
7406
|
+
listInstances: this.listInstances,
|
|
7407
|
+
getInstance: this.getInstance,
|
|
7408
|
+
createInstance: this.createInstance,
|
|
7409
|
+
updateInstance: this.updateInstance,
|
|
7410
|
+
setInstanceEnabled: this.setInstanceEnabled,
|
|
7411
|
+
deleteInstance: this.deleteInstance,
|
|
7412
|
+
testInstance: this.testInstance
|
|
7413
|
+
};
|
|
7414
|
+
}
|
|
7415
|
+
};
|
|
7416
|
+
/**
|
|
7417
|
+
* The one-switch migration (epic #440, step 3). An integration's on/off state used to live in the
|
|
7418
|
+
* registry's `enabled` column for a device addon; it now lives only in the instance record's
|
|
7419
|
+
* body (`enabled`, D1007 superseded). This moves a registry `enabled = false` into the body, once.
|
|
7420
|
+
*
|
|
7421
|
+
* For every registry row of the addon that is OFF:
|
|
7422
|
+
* - no record under its id: the record is created from `initialBody(name)` with `enabled: false`
|
|
7423
|
+
* (a default integration that never had settings, Reolink's among them);
|
|
7424
|
+
* - a record whose body states no `enabled`: `enabled: false` is written into it;
|
|
7425
|
+
* - a record that already states `enabled` (either way) is the newer truth and is left alone.
|
|
7426
|
+
* A row that is ON writes nothing: an absent field reads as on. A rerun finds every off row with
|
|
7427
|
+
* a stated switch and does nothing, so nothing switched off comes back on and nothing switched on
|
|
7428
|
+
* goes off. The registry column itself is neither read afterwards nor written; its drop is step 5.
|
|
7429
|
+
*
|
|
7430
|
+
* It runs in the addon process, BEFORE the addon registers its `integration-instances` provider,
|
|
7431
|
+
* which is also why `integrations.list` still answers the stored column at that point.
|
|
7432
|
+
*/
|
|
7433
|
+
function registrySwitchToBodyId(addonId, date) {
|
|
7434
|
+
return `${addonId}/${date}-registry-switch-to-body`;
|
|
7435
|
+
}
|
|
7436
|
+
async function moveRegistrySwitchToBody(ports, spec) {
|
|
7437
|
+
const rows = await ports.listIntegrations(spec.addonId);
|
|
7438
|
+
let created = 0;
|
|
7439
|
+
let switched = 0;
|
|
7440
|
+
let kept = 0;
|
|
7441
|
+
for (const row of rows) {
|
|
7442
|
+
if (row.enabled) continue;
|
|
7443
|
+
const body = await ports.readBody(row.id);
|
|
7444
|
+
if (body === null) {
|
|
7445
|
+
if (await ports.createRecord(row.id, {
|
|
7446
|
+
...spec.initialBody(row.name),
|
|
7447
|
+
["enabled"]: false
|
|
7448
|
+
}) === "created") created += 1;
|
|
7449
|
+
else kept += 1;
|
|
7450
|
+
continue;
|
|
7451
|
+
}
|
|
7452
|
+
if ("enabled" in body) {
|
|
7453
|
+
kept += 1;
|
|
7454
|
+
continue;
|
|
7455
|
+
}
|
|
7456
|
+
await ports.switchOff(row.id);
|
|
7457
|
+
switched += 1;
|
|
7458
|
+
}
|
|
7459
|
+
const summary = {
|
|
7460
|
+
integrations: rows.length,
|
|
7461
|
+
off: rows.filter((r) => !r.enabled).length,
|
|
7462
|
+
created,
|
|
7463
|
+
switched,
|
|
7464
|
+
kept
|
|
7465
|
+
};
|
|
7466
|
+
return created === 0 && switched === 0 ? {
|
|
7467
|
+
outcome: "already-done",
|
|
7468
|
+
summary
|
|
7469
|
+
} : {
|
|
7470
|
+
outcome: "done",
|
|
7471
|
+
summary
|
|
7472
|
+
};
|
|
7473
|
+
}
|
|
7474
|
+
/** A migration entry: an addon states its kind and how a new body starts, nothing else. */
|
|
7475
|
+
function registrySwitchToBodyMigration(spec) {
|
|
7476
|
+
return {
|
|
7477
|
+
meta: {
|
|
7478
|
+
id: registrySwitchToBodyId(spec.addonId, spec.date),
|
|
7479
|
+
owner: spec.addonId,
|
|
7480
|
+
level: "addon-state",
|
|
7481
|
+
seq: spec.seq,
|
|
7482
|
+
dependsOn: [],
|
|
7483
|
+
store: "settings",
|
|
7484
|
+
scope: "cluster",
|
|
7485
|
+
onFailure: "block-owner",
|
|
7486
|
+
bodyKind: "procedure",
|
|
7487
|
+
description: "Move the registry enabled flag of every switched-off integration into its instance record body, creating the record when there is none",
|
|
7488
|
+
fixtureMark: "enabled"
|
|
7489
|
+
},
|
|
7490
|
+
procedure: (ports) => moveRegistrySwitchToBody(ports, {
|
|
7491
|
+
addonId: spec.addonId,
|
|
7492
|
+
initialBody: spec.initialBody
|
|
7493
|
+
})
|
|
7494
|
+
};
|
|
7495
|
+
}
|
|
7496
|
+
/** The hub and records sides of {@link registrySwitchToBodyMigration}. */
|
|
7497
|
+
function registrySwitchPortsOver(deps) {
|
|
7498
|
+
const handle = deps.records.kind({
|
|
7499
|
+
name: deps.kind.name,
|
|
7500
|
+
declaration: deps.kind.declaration,
|
|
7501
|
+
schema: record(string(), unknown())
|
|
7502
|
+
});
|
|
7503
|
+
return {
|
|
7504
|
+
listIntegrations: async (addonId) => (await deps.api.list()).filter((i) => i.addonId === addonId).map((i) => ({
|
|
7505
|
+
id: i.id,
|
|
7506
|
+
name: i.name,
|
|
7507
|
+
enabled: i.enabled !== false
|
|
7508
|
+
})),
|
|
7509
|
+
readBody: async (id) => (await handle.get(id))?.data ?? null,
|
|
7510
|
+
createRecord: async (id, body) => {
|
|
7511
|
+
if (await handle.get(id) !== null) return "exists";
|
|
7512
|
+
await handle.put({
|
|
7513
|
+
id,
|
|
7514
|
+
data: body
|
|
7515
|
+
}, { ifRev: 0 });
|
|
7516
|
+
return "created";
|
|
7517
|
+
},
|
|
7518
|
+
switchOff: async (id) => {
|
|
7519
|
+
await handle.patch(id, { [SWITCH_KEY]: false });
|
|
7520
|
+
}
|
|
7521
|
+
};
|
|
7522
|
+
}
|
|
7523
|
+
/**
|
|
7524
|
+
* Build a {@link DurableState} over a single store key. Transport-agnostic:
|
|
7525
|
+
* `read`/`write` are the addon-store or device-store accessors. The whole
|
|
7526
|
+
* validated value round-trips on every read/write — the schema is the
|
|
7527
|
+
* single source of truth for what is persisted, so no hand-listed field
|
|
7528
|
+
* set can drop a key on save.
|
|
7529
|
+
*/
|
|
7530
|
+
function createDurableState(deps) {
|
|
7531
|
+
const get = async () => {
|
|
7532
|
+
const raw = (await deps.read())[deps.key];
|
|
7533
|
+
if (raw === void 0) return deps.fallback;
|
|
7534
|
+
const parsed = deps.schema.safeParse(raw);
|
|
7535
|
+
if (!parsed.success) {
|
|
7536
|
+
deps.onParseError?.(deps.key, parsed.error);
|
|
7537
|
+
return deps.fallback;
|
|
7538
|
+
}
|
|
7539
|
+
return parsed.data;
|
|
7540
|
+
};
|
|
7541
|
+
const set = async (next) => {
|
|
7542
|
+
const validated = deps.schema.parse(next);
|
|
7543
|
+
await deps.write({ [deps.key]: validated });
|
|
7544
|
+
};
|
|
7545
|
+
const update = async (fn) => {
|
|
7546
|
+
await set(fn(await get()));
|
|
7547
|
+
};
|
|
7548
|
+
return {
|
|
7549
|
+
get,
|
|
7550
|
+
set,
|
|
7551
|
+
update
|
|
7552
|
+
};
|
|
7553
|
+
}
|
|
7554
|
+
/**
|
|
7555
|
+
* Per-node scoping for the shared addon-settings blob.
|
|
7556
|
+
*
|
|
7557
|
+
* An addon's settings store is hub-central (the `addon-settings` cap is
|
|
7558
|
+
* hub-routed — the hub instance answers for every node), so fields whose
|
|
7559
|
+
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
7560
|
+
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
7561
|
+
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
7562
|
+
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
7563
|
+
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
7564
|
+
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
7565
|
+
*
|
|
7566
|
+
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
7567
|
+
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
7568
|
+
* schema and routes reads/writes through these helpers.
|
|
7569
|
+
*
|
|
7570
|
+
* ## No bare-key fallback — deliberate
|
|
7571
|
+
*
|
|
7572
|
+
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
7573
|
+
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
7574
|
+
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
7575
|
+
* the store is invisible to every node, hub included, so one node's
|
|
7576
|
+
* selection can never leak onto another. (This generalizes the
|
|
7577
|
+
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
7578
|
+
* arbitrary set of per-node field keys.)
|
|
7579
|
+
*
|
|
7580
|
+
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
7581
|
+
* LEAF module: import it via its deep path, never from the root barrel.
|
|
7582
|
+
*/
|
|
7583
|
+
/**
|
|
7584
|
+
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
7585
|
+
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
7586
|
+
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
7587
|
+
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
7588
|
+
*/
|
|
7589
|
+
function normalizeNodeId(raw) {
|
|
7590
|
+
if (raw === void 0 || raw === null || raw === "") return "hub";
|
|
7591
|
+
const slashIdx = raw.indexOf("/");
|
|
7592
|
+
if (slashIdx < 0) return raw;
|
|
7593
|
+
const bare = raw.slice(0, slashIdx);
|
|
7594
|
+
return bare === "" ? "hub" : bare;
|
|
7595
|
+
}
|
|
7596
|
+
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
7597
|
+
function nodeScopedKey(base, nodeId) {
|
|
7598
|
+
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
7599
|
+
}
|
|
7600
|
+
/**
|
|
7601
|
+
* Read a node's value for a per-node field from the raw shared store:
|
|
7602
|
+
* the node-scoped key when present, otherwise `undefined`.
|
|
7603
|
+
* Deliberately NO bare-key fallback (see module doc) — the caller lets the
|
|
7604
|
+
* schema `default` win on `undefined`.
|
|
7605
|
+
*/
|
|
7606
|
+
function readNodeValue(store, base, nodeId) {
|
|
7607
|
+
return store[nodeScopedKey(base, nodeId)];
|
|
7608
|
+
}
|
|
7609
|
+
/**
|
|
7610
|
+
* Re-map a UI/settings patch so every bare perNode field persists under the
|
|
7611
|
+
* TARGET node's scoped key; all other keys pass through unchanged. Used on
|
|
7612
|
+
* the write path so a save for one node never clobbers another node's value
|
|
7613
|
+
* (and the bare key is never written). Returns a new object — the input
|
|
7614
|
+
* patch is not mutated.
|
|
7615
|
+
*/
|
|
7616
|
+
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
7617
|
+
const out = {};
|
|
7618
|
+
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
7619
|
+
return out;
|
|
7620
|
+
}
|
|
7621
|
+
/**
|
|
7622
|
+
* Project the raw shared store onto the bare schema keys for ONE node so a
|
|
7623
|
+
* UI schema (whose field keys are bare) hydrates from that node's own
|
|
7624
|
+
* values:
|
|
7625
|
+
*
|
|
7626
|
+
* - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
|
|
7627
|
+
* - Every bare perNode key is dropped from the pass-through (a stray bare
|
|
7628
|
+
* legacy key must never hydrate any node — no bare fallback).
|
|
7629
|
+
* - THIS node's effective value ({@link readNodeValue}) is then laid onto
|
|
7630
|
+
* each bare perNode key; when the node has no scoped key the bare key is
|
|
7631
|
+
* left ABSENT so the field's schema `default` wins.
|
|
7632
|
+
*
|
|
7633
|
+
* Returns a new object — the input store is not mutated.
|
|
7634
|
+
*/
|
|
7635
|
+
function projectStore(store, perNodeKeys, nodeId) {
|
|
7636
|
+
const out = {};
|
|
7637
|
+
for (const [key, value] of Object.entries(store)) {
|
|
7638
|
+
if (key.includes("@")) continue;
|
|
7639
|
+
if (perNodeKeys.has(key)) continue;
|
|
7640
|
+
out[key] = value;
|
|
7641
|
+
}
|
|
7642
|
+
for (const base of perNodeKeys) {
|
|
7643
|
+
const value = readNodeValue(store, base, nodeId);
|
|
7644
|
+
if (value !== void 0) out[base] = value;
|
|
7645
|
+
}
|
|
7646
|
+
return out;
|
|
7647
|
+
}
|
|
7648
|
+
/** Every scope, in the order the guard and the docs list them. */
|
|
7649
|
+
var SCOPED_SETTINGS_SCOPES = [
|
|
7650
|
+
"cluster",
|
|
7651
|
+
"device-defaults",
|
|
7652
|
+
"node"
|
|
7653
|
+
];
|
|
6966
7654
|
/** A write to a secret path could not be stored in the keychain, so it was refused. */
|
|
6967
7655
|
var KeychainWriteRefusedError = class extends Error {
|
|
6968
7656
|
fieldPath;
|
|
@@ -6973,7 +7661,7 @@ var KeychainWriteRefusedError = class extends Error {
|
|
|
6973
7661
|
}
|
|
6974
7662
|
};
|
|
6975
7663
|
var KEEP = { kind: "keep" };
|
|
6976
|
-
function isRecord$
|
|
7664
|
+
function isRecord$4(value) {
|
|
6977
7665
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6978
7666
|
}
|
|
6979
7667
|
function defaultMintId() {
|
|
@@ -6986,7 +7674,7 @@ function collectSecretMarkerRefs(value, out = []) {
|
|
|
6986
7674
|
return out;
|
|
6987
7675
|
}
|
|
6988
7676
|
if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
|
|
6989
|
-
else if (isRecord$
|
|
7677
|
+
else if (isRecord$4(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
|
|
6990
7678
|
return out;
|
|
6991
7679
|
}
|
|
6992
7680
|
async function storedValueEquals(secrets, marker, candidate) {
|
|
@@ -7041,7 +7729,7 @@ function rowId(row, idKey) {
|
|
|
7041
7729
|
return null;
|
|
7042
7730
|
}
|
|
7043
7731
|
async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
7044
|
-
const storedRows = Array.isArray(stored) ? stored.filter(isRecord$
|
|
7732
|
+
const storedRows = Array.isArray(stored) ? stored.filter(isRecord$4) : [];
|
|
7045
7733
|
if (!Array.isArray(incoming)) {
|
|
7046
7734
|
ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
|
|
7047
7735
|
return {
|
|
@@ -7057,7 +7745,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
7057
7745
|
const kept = /* @__PURE__ */ new Set();
|
|
7058
7746
|
const rows = [];
|
|
7059
7747
|
for (const row of incoming) {
|
|
7060
|
-
if (!isRecord$
|
|
7748
|
+
if (!isRecord$4(row)) {
|
|
7061
7749
|
rows.push(row);
|
|
7062
7750
|
continue;
|
|
7063
7751
|
}
|
|
@@ -7082,7 +7770,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
|
|
|
7082
7770
|
case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
|
|
7083
7771
|
case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
|
|
7084
7772
|
case "object": {
|
|
7085
|
-
if (!isRecord$
|
|
7773
|
+
if (!isRecord$4(incoming)) {
|
|
7086
7774
|
if (incoming === void 0) return KEEP;
|
|
7087
7775
|
ctx.deletes.push(...collectSecretMarkerRefs(stored));
|
|
7088
7776
|
return {
|
|
@@ -7090,7 +7778,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
|
|
|
7090
7778
|
value: incoming
|
|
7091
7779
|
};
|
|
7092
7780
|
}
|
|
7093
|
-
const storedObj = isRecord$
|
|
7781
|
+
const storedObj = isRecord$4(stored) ? stored : {};
|
|
7094
7782
|
return {
|
|
7095
7783
|
kind: "value",
|
|
7096
7784
|
value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
|
|
@@ -7213,7 +7901,7 @@ async function resolveSecretMarkers(value, secrets, options = {}) {
|
|
|
7213
7901
|
value: items
|
|
7214
7902
|
};
|
|
7215
7903
|
}
|
|
7216
|
-
if (isRecord$
|
|
7904
|
+
if (isRecord$4(v)) {
|
|
7217
7905
|
const out = {};
|
|
7218
7906
|
for (const [k, child] of Object.entries(v)) {
|
|
7219
7907
|
const s = substitute(child);
|
|
@@ -7245,7 +7933,7 @@ var SecretOverwriteRefusedError = class extends Error {
|
|
|
7245
7933
|
this.name = "SecretOverwriteRefusedError";
|
|
7246
7934
|
}
|
|
7247
7935
|
};
|
|
7248
|
-
function isRecord$
|
|
7936
|
+
function isRecord$3(value) {
|
|
7249
7937
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7250
7938
|
}
|
|
7251
7939
|
function resolvedValue(pass, marker) {
|
|
@@ -7274,7 +7962,7 @@ function inArray(pass, incoming, stored) {
|
|
|
7274
7962
|
return incoming.map((item, index) => {
|
|
7275
7963
|
const twin = stored[index];
|
|
7276
7964
|
if (isSecretMarker(twin)) return typeof item === "string" && item === resolvedValue(pass, twin) ? twin : item;
|
|
7277
|
-
if (isRecord$
|
|
7965
|
+
if (isRecord$3(item) && isRecord$3(twin)) return inArrayRow(pass, item, twin);
|
|
7278
7966
|
if (Array.isArray(item) && Array.isArray(twin)) return inArray(pass, item, twin);
|
|
7279
7967
|
return item;
|
|
7280
7968
|
});
|
|
@@ -7285,7 +7973,7 @@ function inArrayRow(pass, incoming, stored) {
|
|
|
7285
7973
|
const twin = stored[key];
|
|
7286
7974
|
if (isSecretMarker(twin)) {
|
|
7287
7975
|
if (typeof value === "string" && value === resolvedValue(pass, twin)) out[key] = twin;
|
|
7288
|
-
} else if (isRecord$
|
|
7976
|
+
} else if (isRecord$3(value) && isRecord$3(twin)) out[key] = inArrayRow(pass, value, twin);
|
|
7289
7977
|
else if (Array.isArray(value) && Array.isArray(twin)) out[key] = inArray(pass, value, twin);
|
|
7290
7978
|
}
|
|
7291
7979
|
return out;
|
|
@@ -7293,7 +7981,7 @@ function inArrayRow(pass, incoming, stored) {
|
|
|
7293
7981
|
async function walk(pass, incoming, stored) {
|
|
7294
7982
|
if (isSecretMarker(stored)) return atMarker(pass, incoming, stored);
|
|
7295
7983
|
if (Array.isArray(incoming) && Array.isArray(stored)) return inArray(pass, incoming, stored);
|
|
7296
|
-
if (!isRecord$
|
|
7984
|
+
if (!isRecord$3(incoming) || !isRecord$3(stored)) return incoming;
|
|
7297
7985
|
const out = { ...incoming };
|
|
7298
7986
|
for (const [key, value] of Object.entries(incoming)) out[key] = await walk(pass, value, stored[key]);
|
|
7299
7987
|
return out;
|
|
@@ -7324,7 +8012,7 @@ async function restoreUnchangedSecrets(input) {
|
|
|
7324
8012
|
function isJsonEqual(a, b) {
|
|
7325
8013
|
if (Object.is(a, b)) return true;
|
|
7326
8014
|
if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((v, i) => isJsonEqual(v, b[i]));
|
|
7327
|
-
if (isRecord$
|
|
8015
|
+
if (isRecord$3(a) && isRecord$3(b)) {
|
|
7328
8016
|
const keys = Object.keys(a);
|
|
7329
8017
|
if (keys.length !== Object.keys(b).length) return false;
|
|
7330
8018
|
return keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && isJsonEqual(a[k], b[k]));
|
|
@@ -7348,7 +8036,7 @@ function markerKeysOf(blob, owner) {
|
|
|
7348
8036
|
}
|
|
7349
8037
|
function nodeFromStored(value, owner) {
|
|
7350
8038
|
if (isSecretMarker(value)) return isSecretRefOwnedBy(value.$secret, owner) ? { kind: "leaf" } : null;
|
|
7351
|
-
if (!isRecord$
|
|
8039
|
+
if (!isRecord$3(value)) return null;
|
|
7352
8040
|
const children = /* @__PURE__ */ new Map();
|
|
7353
8041
|
for (const [key, child] of Object.entries(value)) {
|
|
7354
8042
|
const node = nodeFromStored(child, owner);
|
|
@@ -7845,13 +8533,48 @@ var BaseAddon = class {
|
|
|
7845
8533
|
if (api === void 0) throw new Error(`${this.ctx.id}: the migration API is not available on this context`);
|
|
7846
8534
|
return this.runBound(sets.flatMap((set) => set.bind(api)), options);
|
|
7847
8535
|
}
|
|
7848
|
-
|
|
8536
|
+
/**
|
|
8537
|
+
* A device addon states its instance kind once, before its migrations run, and the one-switch
|
|
8538
|
+
* migration (registry `enabled` to the instance body, epic #440 step 3) joins whatever
|
|
8539
|
+
* catalogue the addon runs, in the SAME declaration (the engine replaces an owner's catalogue
|
|
8540
|
+
* on every declare).
|
|
8541
|
+
*/
|
|
8542
|
+
declareRegistrySwitch(spec) {
|
|
8543
|
+
this.registrySwitchSpec = spec;
|
|
8544
|
+
}
|
|
8545
|
+
registrySwitchSpec = null;
|
|
8546
|
+
registrySwitchBound() {
|
|
8547
|
+
const spec = this.registrySwitchSpec;
|
|
8548
|
+
if (spec === null) return [];
|
|
8549
|
+
const api = this.ctx.migrationApi;
|
|
8550
|
+
if (api === void 0) {
|
|
8551
|
+
this.ctx.logger.warn("the registry switch migration is skipped: the migration API is not available on this context");
|
|
8552
|
+
return [];
|
|
8553
|
+
}
|
|
8554
|
+
return migrationSet([registrySwitchToBodyMigration({
|
|
8555
|
+
addonId: this.ctx.id,
|
|
8556
|
+
date: "2026-11-06",
|
|
8557
|
+
seq: 1e3,
|
|
8558
|
+
initialBody: spec.initialBody
|
|
8559
|
+
})], (a) => registrySwitchPortsOver({
|
|
8560
|
+
api: integrationRowsApiOver(a),
|
|
8561
|
+
records: switchRecordsOverMigrationApi(a),
|
|
8562
|
+
kind: spec.kind
|
|
8563
|
+
})).bind(api);
|
|
8564
|
+
}
|
|
8565
|
+
async runBound(declared, options) {
|
|
8566
|
+
const added = this.registrySwitchBound();
|
|
8567
|
+
const migrations = [...declared, ...added];
|
|
8568
|
+
const phased = options?.only === void 0 || added.length === 0 ? options : {
|
|
8569
|
+
...options,
|
|
8570
|
+
only: [...options.only, ...added.map((m) => m.meta.id)]
|
|
8571
|
+
};
|
|
7849
8572
|
const api = this.ctx.api.migrations;
|
|
7850
8573
|
const report = await runAddonMigrations({
|
|
7851
8574
|
declareOwner: (input) => api.declareOwner.mutate(input),
|
|
7852
8575
|
startMigration: (input) => api.startMigration.mutate(input),
|
|
7853
8576
|
finishMigration: (input) => api.finishMigration.mutate(input)
|
|
7854
|
-
}, migrations, this.ctx.logger,
|
|
8577
|
+
}, migrations, this.ctx.logger, phased);
|
|
7855
8578
|
if (report.blockOwner.length > 0) throw new AddonMigrationsBlockedError(report.blockOwner);
|
|
7856
8579
|
return report;
|
|
7857
8580
|
}
|
|
@@ -8924,237 +9647,6 @@ function normalizeAddonInitResult(result) {
|
|
|
8924
9647
|
if (Array.isArray(result)) return { providers: result };
|
|
8925
9648
|
return result;
|
|
8926
9649
|
}
|
|
8927
|
-
var PREFIX = "records/";
|
|
8928
|
-
/** The base of every records failure. `detail` is the human part of the message. */
|
|
8929
|
-
var RecordsError = class extends Error {
|
|
8930
|
-
code;
|
|
8931
|
-
detail;
|
|
8932
|
-
constructor(code, detail) {
|
|
8933
|
-
super(`${PREFIX}${code}: ${detail}`);
|
|
8934
|
-
this.name = "RecordsError";
|
|
8935
|
-
this.code = code;
|
|
8936
|
-
this.detail = detail;
|
|
8937
|
-
}
|
|
8938
|
-
};
|
|
8939
|
-
/** A write guarded by `ifRev` found another revision (or an existing row for `ifRev: 0`). */
|
|
8940
|
-
var RevConflictError = class extends RecordsError {
|
|
8941
|
-
constructor(detail) {
|
|
8942
|
-
super("rev-conflict", detail);
|
|
8943
|
-
this.name = "RevConflictError";
|
|
8944
|
-
}
|
|
8945
|
-
};
|
|
8946
|
-
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
8947
|
-
var RecordSecretUnavailableError = class extends RecordsError {
|
|
8948
|
-
constructor(detail) {
|
|
8949
|
-
super("secret-unavailable", detail);
|
|
8950
|
-
this.name = "RecordSecretUnavailableError";
|
|
8951
|
-
}
|
|
8952
|
-
};
|
|
8953
|
-
var InvalidRecordError = class extends RecordsError {
|
|
8954
|
-
constructor(detail) {
|
|
8955
|
-
super("invalid-record", detail);
|
|
8956
|
-
this.name = "InvalidRecordError";
|
|
8957
|
-
}
|
|
8958
|
-
};
|
|
8959
|
-
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
8960
|
-
var DeclarationRefusedError = class extends RecordsError {
|
|
8961
|
-
constructor(detail) {
|
|
8962
|
-
super("declaration-refused", detail);
|
|
8963
|
-
this.name = "DeclarationRefusedError";
|
|
8964
|
-
}
|
|
8965
|
-
};
|
|
8966
|
-
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
8967
|
-
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
8968
|
-
var RECORD_DATABASES = ["settings", "events"];
|
|
8969
|
-
/** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
|
|
8970
|
-
var RECORD_CLASSES = [
|
|
8971
|
-
"config",
|
|
8972
|
-
"ledger",
|
|
8973
|
-
"audit",
|
|
8974
|
-
"mirror",
|
|
8975
|
-
"ephemeral"
|
|
8976
|
-
];
|
|
8977
|
-
var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
8978
|
-
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
8979
|
-
var RECORD_BATCH_MAX = 1e3;
|
|
8980
|
-
var RECORD_QUERY_MAX = 1e3;
|
|
8981
|
-
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
8982
|
-
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
8983
|
-
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
8984
|
-
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
8985
|
-
/**
|
|
8986
|
-
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
8987
|
-
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
8988
|
-
* (`auth.accessToken`, `headers[].value`).
|
|
8989
|
-
*
|
|
8990
|
-
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
8991
|
-
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
8992
|
-
* key releases exactly that key's secret.
|
|
8993
|
-
*
|
|
8994
|
-
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
8995
|
-
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
8996
|
-
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
8997
|
-
* leaf names its element: `headers[X-Api].value`.
|
|
8998
|
-
*
|
|
8999
|
-
* Pure and browser-safe. Nothing here mutates: every transform returns a new value.
|
|
9000
|
-
*/
|
|
9001
|
-
/** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
|
|
9002
|
-
function parseSecretPath(path) {
|
|
9003
|
-
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
9004
|
-
return path.split(".").map((raw) => {
|
|
9005
|
-
const each = raw.endsWith("[]");
|
|
9006
|
-
const map = raw.endsWith("{}");
|
|
9007
|
-
const key = each || map ? raw.slice(0, -2) : raw;
|
|
9008
|
-
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
9009
|
-
return {
|
|
9010
|
-
key,
|
|
9011
|
-
each,
|
|
9012
|
-
map
|
|
9013
|
-
};
|
|
9014
|
-
});
|
|
9015
|
-
}
|
|
9016
|
-
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
9017
|
-
function secretArrayPrefixes(path) {
|
|
9018
|
-
const segments = parseSecretPath(path);
|
|
9019
|
-
const prefixes = [];
|
|
9020
|
-
const walked = [];
|
|
9021
|
-
for (const segment of segments) {
|
|
9022
|
-
walked.push(segment.key);
|
|
9023
|
-
if (segment.each) prefixes.push(walked.join("."));
|
|
9024
|
-
}
|
|
9025
|
-
return prefixes;
|
|
9026
|
-
}
|
|
9027
|
-
function isRecord$4(value) {
|
|
9028
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9029
|
-
}
|
|
9030
|
-
function elementId(element, idKey, declared, prefix) {
|
|
9031
|
-
const id = isRecord$4(element) ? element[idKey] : void 0;
|
|
9032
|
-
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`);
|
|
9033
|
-
return id;
|
|
9034
|
-
}
|
|
9035
|
-
/**
|
|
9036
|
-
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
9037
|
-
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
9038
|
-
* result is a new body, `data` is untouched.
|
|
9039
|
-
*/
|
|
9040
|
-
var REMOVE_LEAF = Symbol("remove-leaf");
|
|
9041
|
-
function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
|
|
9042
|
-
if (!isRecord$4(node)) return node;
|
|
9043
|
-
const segment = segments[index];
|
|
9044
|
-
if (segment === void 0) return node;
|
|
9045
|
-
if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
|
|
9046
|
-
const child = node[segment.key];
|
|
9047
|
-
const keys = [...walkedKeys, segment.key];
|
|
9048
|
-
const last = index === segments.length - 1;
|
|
9049
|
-
if (segment.each) {
|
|
9050
|
-
if (!Array.isArray(child)) return node;
|
|
9051
|
-
const prefix = keys.join(".");
|
|
9052
|
-
const idKey = arrayKeys[prefix];
|
|
9053
|
-
if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
|
|
9054
|
-
const mapped = child.map((element) => {
|
|
9055
|
-
const id = elementId(element, idKey, declared, prefix);
|
|
9056
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
|
|
9057
|
-
return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
|
|
9058
|
-
});
|
|
9059
|
-
return {
|
|
9060
|
-
...node,
|
|
9061
|
-
[segment.key]: mapped
|
|
9062
|
-
};
|
|
9063
|
-
}
|
|
9064
|
-
if (segment.map) {
|
|
9065
|
-
if (!isRecord$4(child)) return node;
|
|
9066
|
-
const kept = Object.entries(child).map(([mapKey, value]) => {
|
|
9067
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
|
|
9068
|
-
if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
|
|
9069
|
-
return [mapKey, visit({
|
|
9070
|
-
declared,
|
|
9071
|
-
concrete,
|
|
9072
|
-
value
|
|
9073
|
-
})];
|
|
9074
|
-
}).filter(([, value]) => value !== REMOVE_LEAF);
|
|
9075
|
-
return {
|
|
9076
|
-
...node,
|
|
9077
|
-
[segment.key]: Object.fromEntries(kept)
|
|
9078
|
-
};
|
|
9079
|
-
}
|
|
9080
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
9081
|
-
if (last) {
|
|
9082
|
-
const replacement = visit({
|
|
9083
|
-
declared,
|
|
9084
|
-
concrete,
|
|
9085
|
-
value: child
|
|
9086
|
-
});
|
|
9087
|
-
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
9088
|
-
return {
|
|
9089
|
-
...node,
|
|
9090
|
-
[segment.key]: replacement
|
|
9091
|
-
};
|
|
9092
|
-
}
|
|
9093
|
-
return {
|
|
9094
|
-
...node,
|
|
9095
|
-
[segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
|
|
9096
|
-
};
|
|
9097
|
-
}
|
|
9098
|
-
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
9099
|
-
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
9100
|
-
let current = data;
|
|
9101
|
-
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
9102
|
-
return current;
|
|
9103
|
-
}
|
|
9104
|
-
/** Every present secret leaf, read-only. */
|
|
9105
|
-
function collectSecretLeaves(data, paths, arrayKeys) {
|
|
9106
|
-
const found = [];
|
|
9107
|
-
mapSecretLeaves(data, paths, arrayKeys, (leaf) => {
|
|
9108
|
-
found.push(leaf);
|
|
9109
|
-
return leaf.value;
|
|
9110
|
-
});
|
|
9111
|
-
return found;
|
|
9112
|
-
}
|
|
9113
|
-
/**
|
|
9114
|
-
* The keychain collection name a kind's secrets live under. Prefixed so a
|
|
9115
|
-
* record's refs never collide with the refs a legacy collection of the same name
|
|
9116
|
-
* already holds during an adoption.
|
|
9117
|
-
*/
|
|
9118
|
-
function recordSecretCollection(kind) {
|
|
9119
|
-
return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
|
|
9120
|
-
}
|
|
9121
|
-
/** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
|
|
9122
|
-
function recordSecretRef(owner, kind, rowId, concretePath) {
|
|
9123
|
-
return buildSecretRef({
|
|
9124
|
-
owner,
|
|
9125
|
-
scope: {
|
|
9126
|
-
kind: "row",
|
|
9127
|
-
collection: recordSecretCollection(kind),
|
|
9128
|
-
rowId
|
|
9129
|
-
},
|
|
9130
|
-
fieldPath: concretePath
|
|
9131
|
-
});
|
|
9132
|
-
}
|
|
9133
|
-
/**
|
|
9134
|
-
* A stored secret, as an admin read shows it: a VIEW naming the row's own
|
|
9135
|
-
* keychain ref (`set: true`), never the value and no longer the bare redaction
|
|
9136
|
-
* token. The form hands it to the secret field, which reveals the value by ref
|
|
9137
|
-
* through the audited `keychain-admin.reveal`; sent back untouched it keeps the
|
|
9138
|
-
* stored secret (the records door reads a view as KEEP).
|
|
9139
|
-
*
|
|
9140
|
-
* ONE implementation for the entries service and for every addon that serves
|
|
9141
|
-
* its own instances (`RecordIntegrationInstances`).
|
|
9142
|
-
*/
|
|
9143
|
-
function isRecord$3(value) {
|
|
9144
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9145
|
-
}
|
|
9146
|
-
function secretViewsOf(owner, kind, id, decl, data) {
|
|
9147
|
-
if (decl.secretPaths.length === 0) return data;
|
|
9148
|
-
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
9149
|
-
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
9150
|
-
return {
|
|
9151
|
-
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
9152
|
-
v: 1,
|
|
9153
|
-
set: true
|
|
9154
|
-
};
|
|
9155
|
-
});
|
|
9156
|
-
return isRecord$3(shown) ? shown : data;
|
|
9157
|
-
}
|
|
9158
9650
|
/**
|
|
9159
9651
|
* The share-view scope kinds a share-link token can carry. The hub mints
|
|
9160
9652
|
* and validates them (`ShareViewGrantSchema` builds its
|
|
@@ -9408,6 +9900,7 @@ function defineRecordKinds(specs) {
|
|
|
9408
9900
|
function entryBody(shape) {
|
|
9409
9901
|
return object({
|
|
9410
9902
|
name: string().min(1),
|
|
9903
|
+
enabled: boolean().optional(),
|
|
9411
9904
|
...shape
|
|
9412
9905
|
});
|
|
9413
9906
|
}
|
|
@@ -11263,6 +11756,10 @@ Object.freeze({
|
|
|
11263
11756
|
"all",
|
|
11264
11757
|
"one"
|
|
11265
11758
|
]
|
|
11759
|
+
},
|
|
11760
|
+
{
|
|
11761
|
+
"path": "positionUpdatedAt",
|
|
11762
|
+
"valueType": "number"
|
|
11266
11763
|
}
|
|
11267
11764
|
],
|
|
11268
11765
|
"meter": [{
|
|
@@ -11517,22 +12014,6 @@ Object.freeze({
|
|
|
11517
12014
|
"path": "pumpRunning",
|
|
11518
12015
|
"valueType": "boolean"
|
|
11519
12016
|
},
|
|
11520
|
-
{
|
|
11521
|
-
"path": "lastDrink",
|
|
11522
|
-
"valueType": "number"
|
|
11523
|
-
},
|
|
11524
|
-
{
|
|
11525
|
-
"path": "currentHourDrink",
|
|
11526
|
-
"valueType": "number"
|
|
11527
|
-
},
|
|
11528
|
-
{
|
|
11529
|
-
"path": "last24hDrink",
|
|
11530
|
-
"valueType": "number"
|
|
11531
|
-
},
|
|
11532
|
-
{
|
|
11533
|
-
"path": "todayDrink",
|
|
11534
|
-
"valueType": "number"
|
|
11535
|
-
},
|
|
11536
12017
|
{
|
|
11537
12018
|
"path": "error",
|
|
11538
12019
|
"valueType": "string"
|
|
@@ -12098,6 +12579,60 @@ Object.freeze({
|
|
|
12098
12579
|
}
|
|
12099
12580
|
]
|
|
12100
12581
|
});
|
|
12582
|
+
Object.freeze({
|
|
12583
|
+
"actions": { "run": 363e4 },
|
|
12584
|
+
"audio-analyzer": { "classify": 3e4 },
|
|
12585
|
+
"custom-model-registry": { "importModelBundle": 18e5 },
|
|
12586
|
+
"database-snapshot": { "writeSnapshot": 18e5 },
|
|
12587
|
+
"device-manager": {
|
|
12588
|
+
"migrateDevice": 72e4,
|
|
12589
|
+
"runDiscoverySweep": 12e4
|
|
12590
|
+
},
|
|
12591
|
+
"device-provider": { "reloadDevice": 18e4 },
|
|
12592
|
+
"llm": {
|
|
12593
|
+
"generate": 6e5,
|
|
12594
|
+
"generateVision": 6e5,
|
|
12595
|
+
"testProfile": 6e5
|
|
12596
|
+
},
|
|
12597
|
+
"llm-runtime": {
|
|
12598
|
+
"complete": 6e5,
|
|
12599
|
+
"completeApple": 6e5,
|
|
12600
|
+
"ensureStarted": 6e5,
|
|
12601
|
+
"installModel": 36e5
|
|
12602
|
+
},
|
|
12603
|
+
"local-network": { "scanNetwork": 9e4 },
|
|
12604
|
+
"model-convert": { "convert": 6e5 },
|
|
12605
|
+
"pipeline-analytics": {
|
|
12606
|
+
"addRetrainFrameFromRecording": 6e4,
|
|
12607
|
+
"offerRetrainArchive": 12e4,
|
|
12608
|
+
"proposeRetrainAnnotationsWithLlm": 18e4,
|
|
12609
|
+
"resolveRetrainTrainingCorpus": 6e4,
|
|
12610
|
+
"writeRetrainArchive": 36e5
|
|
12611
|
+
},
|
|
12612
|
+
"server-management": { "applyServerUpdate": 96e4 },
|
|
12613
|
+
"terminal-session": { "pullOutput": 15e3 },
|
|
12614
|
+
"training": {
|
|
12615
|
+
"canaryResult": 12e4,
|
|
12616
|
+
"cancelJob": 12e4,
|
|
12617
|
+
"planJob": 6e4,
|
|
12618
|
+
"registerResult": 18e5,
|
|
12619
|
+
"rollbackCanary": 12e4,
|
|
12620
|
+
"startJob": 12e4,
|
|
12621
|
+
"startJobBatch": 12e4
|
|
12622
|
+
},
|
|
12623
|
+
"training-provider": {
|
|
12624
|
+
"cancelJob": 6e4,
|
|
12625
|
+
"cleanupJob": 3e5,
|
|
12626
|
+
"getJob": 6e4,
|
|
12627
|
+
"listJobEvents": 6e4,
|
|
12628
|
+
"listJobs": 12e4,
|
|
12629
|
+
"offerArtifact": 3e5,
|
|
12630
|
+
"readResult": 3e5,
|
|
12631
|
+
"submitJob": 18e5,
|
|
12632
|
+
"uploadDataset": 72e5,
|
|
12633
|
+
"validateCredentials": 3e4
|
|
12634
|
+
}
|
|
12635
|
+
});
|
|
12101
12636
|
object({
|
|
12102
12637
|
code: string().regex(/^[a-z][a-z0-9-]*(\.[a-z0-9-]+)+$/),
|
|
12103
12638
|
params: record(string(), union([string(), number()])).optional()
|
|
@@ -12117,7 +12652,7 @@ function userError(code, params, englishFallback) {
|
|
|
12117
12652
|
return new CamstackError(code, params, englishFallback);
|
|
12118
12653
|
}
|
|
12119
12654
|
//#endregion
|
|
12120
|
-
//#region ../types/dist/composition-
|
|
12655
|
+
//#region ../types/dist/composition-BmBHuDTQ.mjs
|
|
12121
12656
|
/**
|
|
12122
12657
|
* The ffmpeg build every CamStack node downloads, per platform and arch.
|
|
12123
12658
|
*
|
|
@@ -12421,7 +12956,7 @@ var table = {
|
|
|
12421
12956
|
},
|
|
12422
12957
|
dwell: {
|
|
12423
12958
|
minArgs: 3,
|
|
12424
|
-
maxArgs:
|
|
12959
|
+
maxArgs: 4,
|
|
12425
12960
|
apply: () => {
|
|
12426
12961
|
throw new ExpressionEvalError("dwell: stateful evaluation context is required");
|
|
12427
12962
|
}
|
|
@@ -13464,212 +13999,6 @@ var IntegrationInstanceRefSchema = object({
|
|
|
13464
13999
|
]),
|
|
13465
14000
|
candidateStableId: string().optional()
|
|
13466
14001
|
});
|
|
13467
|
-
/**
|
|
13468
|
-
* `RecordIntegrationInstances` - the `integration-instances` provider over ONE
|
|
13469
|
-
* entry kind, so an addon that holds a connection serves it in ~30 lines.
|
|
13470
|
-
*
|
|
13471
|
-
* Every instance is one record of the addon's own kind, keyed by the
|
|
13472
|
-
* `integrations` registry id. The records door does the secret work: a field the
|
|
13473
|
-
* kind marks `.meta({ secret: true })` is a keychain marker bound to the row, so
|
|
13474
|
-
* deleting the row deletes the secret, and one row's value is never another's.
|
|
13475
|
-
*
|
|
13476
|
-
* Patch rules for a secret (`updateInstance`): omitted, `''`, the redaction
|
|
13477
|
-
* token or the view the form was given KEEP the stored secret;
|
|
13478
|
-
* `{ $secretClear: true }` clears it; any other string replaces it.
|
|
13479
|
-
*/
|
|
13480
|
-
/** The most instances one addon lists (an integrations page, not a table). */
|
|
13481
|
-
var INSTANCES_LIST_MAX = 1e3;
|
|
13482
|
-
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
13483
|
-
function topLevelSecretKeys(paths) {
|
|
13484
|
-
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
13485
|
-
}
|
|
13486
|
-
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
13487
|
-
function secretMapKeys(paths) {
|
|
13488
|
-
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
13489
|
-
}
|
|
13490
|
-
/**
|
|
13491
|
-
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
13492
|
-
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
13493
|
-
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
13494
|
-
*/
|
|
13495
|
-
function secretMapPatch(value) {
|
|
13496
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
13497
|
-
const out = {};
|
|
13498
|
-
for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
|
|
13499
|
-
else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
|
|
13500
|
-
return Object.keys(out).length > 0 ? out : null;
|
|
13501
|
-
}
|
|
13502
|
-
/** Does the kind's body schema carry an `enabled` field? */
|
|
13503
|
-
function declaresEnabled(kind) {
|
|
13504
|
-
const json = toJSONSchema(kind.schema, {
|
|
13505
|
-
unrepresentable: "any",
|
|
13506
|
-
io: "input"
|
|
13507
|
-
});
|
|
13508
|
-
const properties = Reflect.get(json, "properties");
|
|
13509
|
-
return typeof properties === "object" && properties !== null && "enabled" in properties;
|
|
13510
|
-
}
|
|
13511
|
-
var RecordIntegrationInstances = class {
|
|
13512
|
-
records;
|
|
13513
|
-
kind;
|
|
13514
|
-
hooks;
|
|
13515
|
-
handle;
|
|
13516
|
-
secretKeys;
|
|
13517
|
-
secretMaps;
|
|
13518
|
-
nameField;
|
|
13519
|
-
/** The `integrations` registry owns the on/off switch (`role: devices`); the body has none. */
|
|
13520
|
-
registryOwnsEnabled;
|
|
13521
|
-
constructor(records, kind, hooks) {
|
|
13522
|
-
this.records = records;
|
|
13523
|
-
this.kind = kind;
|
|
13524
|
-
this.hooks = hooks;
|
|
13525
|
-
this.handle = records.kind(kind);
|
|
13526
|
-
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
13527
|
-
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
13528
|
-
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
13529
|
-
this.registryOwnsEnabled = hooks.description.role === "devices";
|
|
13530
|
-
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"`);
|
|
13531
|
-
}
|
|
13532
|
-
/**
|
|
13533
|
-
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
13534
|
-
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
13535
|
-
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
13536
|
-
*/
|
|
13537
|
-
async readResolved(id) {
|
|
13538
|
-
try {
|
|
13539
|
-
const record = await this.handle.getResolved(id);
|
|
13540
|
-
return record === null ? null : {
|
|
13541
|
-
id,
|
|
13542
|
-
body: record.data,
|
|
13543
|
-
enabled: record.data.enabled !== false,
|
|
13544
|
-
secrets: "resolved"
|
|
13545
|
-
};
|
|
13546
|
-
} catch (err) {
|
|
13547
|
-
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
13548
|
-
const stored = await this.handle.get(id);
|
|
13549
|
-
if (stored === null) return null;
|
|
13550
|
-
return {
|
|
13551
|
-
id,
|
|
13552
|
-
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
13553
|
-
enabled: stored.data.enabled !== false,
|
|
13554
|
-
secrets: "unavailable"
|
|
13555
|
-
};
|
|
13556
|
-
}
|
|
13557
|
-
}
|
|
13558
|
-
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
13559
|
-
async getResolved(id) {
|
|
13560
|
-
return (await this.readResolved(id))?.body ?? null;
|
|
13561
|
-
}
|
|
13562
|
-
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
13563
|
-
async listResolved() {
|
|
13564
|
-
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
13565
|
-
const out = [];
|
|
13566
|
-
for (const record of page.records) {
|
|
13567
|
-
const read = await this.readResolved(record.id);
|
|
13568
|
-
if (read !== null) out.push(read);
|
|
13569
|
-
}
|
|
13570
|
-
return out;
|
|
13571
|
-
}
|
|
13572
|
-
viewOf(record) {
|
|
13573
|
-
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
13574
|
-
const rawName = record.data[this.nameField];
|
|
13575
|
-
const kind = this.hooks.kindOf?.(record.data);
|
|
13576
|
-
const health = this.hooks.health?.(record.data, record.id);
|
|
13577
|
-
return {
|
|
13578
|
-
id: record.id,
|
|
13579
|
-
name: typeof rawName === "string" ? rawName : record.id,
|
|
13580
|
-
configured: this.hooks.configured(record.data),
|
|
13581
|
-
...this.registryOwnsEnabled ? {} : { enabled: record.data.enabled !== false },
|
|
13582
|
-
formValues: shown,
|
|
13583
|
-
...kind !== void 0 ? { kind } : {},
|
|
13584
|
-
...health?.status !== void 0 ? { status: health.status } : {},
|
|
13585
|
-
...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
|
|
13586
|
-
};
|
|
13587
|
-
}
|
|
13588
|
-
describe = async () => this.hooks.mintId === void 0 ? this.hooks.description : {
|
|
13589
|
-
...this.hooks.description,
|
|
13590
|
-
mintsId: true
|
|
13591
|
-
};
|
|
13592
|
-
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
13593
|
-
listInstances = async () => {
|
|
13594
|
-
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
13595
|
-
};
|
|
13596
|
-
getInstance = async ({ id }) => {
|
|
13597
|
-
const record = await this.handle.get(id);
|
|
13598
|
-
return record === null ? null : this.viewOf(record);
|
|
13599
|
-
};
|
|
13600
|
-
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
13601
|
-
createInstance = async ({ id, name, kind, values }) => {
|
|
13602
|
-
const minted = id ?? this.hooks.mintId?.({
|
|
13603
|
-
name,
|
|
13604
|
-
...kind !== void 0 ? { kind } : {}
|
|
13605
|
-
});
|
|
13606
|
-
if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
|
|
13607
|
-
await this.handle.put({
|
|
13608
|
-
id: minted,
|
|
13609
|
-
data: this.hooks.initialBody(name, kind)
|
|
13610
|
-
}, { ifRev: 0 });
|
|
13611
|
-
const patch = this.patchOf(values ?? {});
|
|
13612
|
-
if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
|
|
13613
|
-
await this.hooks.onChanged?.(minted, "created");
|
|
13614
|
-
return { id: minted };
|
|
13615
|
-
};
|
|
13616
|
-
updateInstance = async ({ id, name, values }) => {
|
|
13617
|
-
const patch = this.patchOf(values);
|
|
13618
|
-
if (name !== void 0) patch[this.nameField] = name;
|
|
13619
|
-
await this.handle.patch(id, patch);
|
|
13620
|
-
await this.hooks.onChanged?.(id, "updated");
|
|
13621
|
-
return { ok: true };
|
|
13622
|
-
};
|
|
13623
|
-
/** The record patch a form `values` object means: secrets kept, cleared or replaced. */
|
|
13624
|
-
patchOf(values) {
|
|
13625
|
-
const patch = {};
|
|
13626
|
-
for (const [key, value] of Object.entries(values)) {
|
|
13627
|
-
if (value === void 0) continue;
|
|
13628
|
-
if (this.secretMaps.has(key)) {
|
|
13629
|
-
const entries = secretMapPatch(value);
|
|
13630
|
-
if (entries !== null) patch[key] = entries;
|
|
13631
|
-
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
13632
|
-
else if (isSecretClear(value)) patch[key] = null;
|
|
13633
|
-
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
13634
|
-
}
|
|
13635
|
-
return patch;
|
|
13636
|
-
}
|
|
13637
|
-
/** The switch lives in the record body; the addon is told so it applies it (D996). */
|
|
13638
|
-
setInstanceEnabled = async ({ id, enabled }) => {
|
|
13639
|
-
if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
|
|
13640
|
-
await this.handle.patch(id, { enabled });
|
|
13641
|
-
await this.hooks.onChanged?.(id, "enabled");
|
|
13642
|
-
return { ok: true };
|
|
13643
|
-
};
|
|
13644
|
-
/** The row and its keychain refs go together (the records door). */
|
|
13645
|
-
deleteInstance = async ({ id }) => {
|
|
13646
|
-
await this.handle.delete(id);
|
|
13647
|
-
await this.hooks.onChanged?.(id, "deleted");
|
|
13648
|
-
return { ok: true };
|
|
13649
|
-
};
|
|
13650
|
-
testInstance = async (input) => {
|
|
13651
|
-
if (this.hooks.test === void 0) return {
|
|
13652
|
-
success: false,
|
|
13653
|
-
status: "unsupported",
|
|
13654
|
-
error: "This integration declares no connection test"
|
|
13655
|
-
};
|
|
13656
|
-
return this.hooks.test(input);
|
|
13657
|
-
};
|
|
13658
|
-
/** The flat provider object to hand to `registerProvider`. */
|
|
13659
|
-
toProvider() {
|
|
13660
|
-
return {
|
|
13661
|
-
describe: this.describe,
|
|
13662
|
-
instanceFormSchema: this.instanceFormSchema,
|
|
13663
|
-
listInstances: this.listInstances,
|
|
13664
|
-
getInstance: this.getInstance,
|
|
13665
|
-
createInstance: this.createInstance,
|
|
13666
|
-
updateInstance: this.updateInstance,
|
|
13667
|
-
setInstanceEnabled: this.setInstanceEnabled,
|
|
13668
|
-
deleteInstance: this.deleteInstance,
|
|
13669
|
-
testInstance: this.testInstance
|
|
13670
|
-
};
|
|
13671
|
-
}
|
|
13672
|
-
};
|
|
13673
14002
|
var EncodeProfileSchema = object({
|
|
13674
14003
|
video: object({
|
|
13675
14004
|
codec: _enum([
|
|
@@ -20487,31 +20816,21 @@ var APPLIANCE_CAP_VOCABULARY = {
|
|
|
20487
20816
|
"pet-fountain": {
|
|
20488
20817
|
scope: "device",
|
|
20489
20818
|
noun: t("Pet fountain", "Fontana per animali"),
|
|
20490
|
-
actions: [
|
|
20491
|
-
|
|
20492
|
-
|
|
20493
|
-
|
|
20494
|
-
|
|
20495
|
-
|
|
20496
|
-
|
|
20497
|
-
|
|
20498
|
-
|
|
20499
|
-
|
|
20500
|
-
|
|
20501
|
-
|
|
20502
|
-
|
|
20503
|
-
|
|
20504
|
-
|
|
20505
|
-
args: { on: false }
|
|
20506
|
-
},
|
|
20507
|
-
{
|
|
20508
|
-
id: "petFountain.resetDailyConsumption",
|
|
20509
|
-
method: "resetDailyConsumption",
|
|
20510
|
-
label: t("Clear daily consumption", "Azzera il consumo giornaliero"),
|
|
20511
|
-
phrase: t("Clear the daily water consumption of {device}", "Azzera il consumo giornaliero di acqua di {device}"),
|
|
20512
|
-
icon: "rotate-ccw"
|
|
20513
|
-
}
|
|
20514
|
-
],
|
|
20819
|
+
actions: [{
|
|
20820
|
+
id: "petFountain.pumpOn",
|
|
20821
|
+
method: "setPump",
|
|
20822
|
+
label: t("Pump on", "Pompa accesa"),
|
|
20823
|
+
phrase: t("Start the pump of {device}", "Avvia la pompa di {device}"),
|
|
20824
|
+
icon: "play",
|
|
20825
|
+
args: { on: true }
|
|
20826
|
+
}, {
|
|
20827
|
+
id: "petFountain.pumpOff",
|
|
20828
|
+
method: "setPump",
|
|
20829
|
+
label: t("Pump off", "Pompa spenta"),
|
|
20830
|
+
phrase: t("Stop the pump of {device}", "Ferma la pompa di {device}"),
|
|
20831
|
+
icon: "square",
|
|
20832
|
+
args: { on: false }
|
|
20833
|
+
}],
|
|
20515
20834
|
state: [{
|
|
20516
20835
|
kind: "boolean",
|
|
20517
20836
|
field: "empty",
|
|
@@ -44465,8 +44784,15 @@ var ActionInputSchema = object({
|
|
|
44465
44784
|
var ActionRunOriginSchema = object({
|
|
44466
44785
|
/** The automation block whose step started it. */
|
|
44467
44786
|
blockId: string().min(1).optional() });
|
|
44468
|
-
/**
|
|
44469
|
-
|
|
44787
|
+
/**
|
|
44788
|
+
* `started` = the caller did not ask to wait. `timed-out` = the run reached the
|
|
44789
|
+
* ceiling (`ACTION_RUN_MAX_MS`) and was stopped; it is never a `ran`.
|
|
44790
|
+
*/
|
|
44791
|
+
var ActionRunOutcomeSchema = union([
|
|
44792
|
+
AutomationRunOutcomeSchema,
|
|
44793
|
+
literal("started"),
|
|
44794
|
+
literal("timed-out")
|
|
44795
|
+
]);
|
|
44470
44796
|
var ActionRunResultSchema = object({
|
|
44471
44797
|
runId: string().min(1),
|
|
44472
44798
|
outcome: ActionRunOutcomeSchema,
|
|
@@ -44988,6 +45314,8 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
44988
45314
|
kind: "mutation",
|
|
44989
45315
|
auth: "admin"
|
|
44990
45316
|
});
|
|
45317
|
+
/** `timeoutMs` of `actions.run`: a waited call outlives any legal run. */
|
|
45318
|
+
var ACTION_RUN_TIMEOUT_MS = 363e4;
|
|
44991
45319
|
/**
|
|
44992
45320
|
* actions — the ONE surface for runnable actions, for the UI and for
|
|
44993
45321
|
* automations. Provided by the core-blocks builtin on the hub.
|
|
@@ -45006,6 +45334,12 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
45006
45334
|
* An admin, and an in-process caller (an automation block), may run any action.
|
|
45007
45335
|
* Every refusal is typed (`[not-linked] …`) and logged.
|
|
45008
45336
|
*
|
|
45337
|
+
* **A run lasts at most `ACTION_RUN_MAX_MS` (60 min).** The provider stops a
|
|
45338
|
+
* run that reaches it and answers `timed-out` (never `ran`); an action whose
|
|
45339
|
+
* `wait` steps alone add up to more is refused at create/update
|
|
45340
|
+
* (`[invalid-steps]`). `run` declares a `timeoutMs` above that ceiling, so a
|
|
45341
|
+
* waited call (an automation step) is never cut by the 60 s transport default.
|
|
45342
|
+
*
|
|
45009
45343
|
* A second `run` of an action that is already running is REFUSED — traced and
|
|
45010
45344
|
* logged — never queued.
|
|
45011
45345
|
*/
|
|
@@ -45032,7 +45366,8 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
45032
45366
|
role: "viewer",
|
|
45033
45367
|
auth: "protected",
|
|
45034
45368
|
kind: "mutation",
|
|
45035
|
-
caller: "required"
|
|
45369
|
+
caller: "required",
|
|
45370
|
+
timeoutMs: ACTION_RUN_TIMEOUT_MS
|
|
45036
45371
|
}), method(ActionIdInput, _void(), {
|
|
45037
45372
|
kind: "mutation",
|
|
45038
45373
|
auth: "admin"
|
|
@@ -50059,6 +50394,9 @@ var MediaPlayerStatusSchema = object({
|
|
|
50059
50394
|
/** Repeat mode. Null when no repeat surface.
|
|
50060
50395
|
* Pair with `DeviceFeature.MediaPlayerRepeat`. */
|
|
50061
50396
|
repeat: MediaPlayerRepeatSchema.nullable(),
|
|
50397
|
+
/** Ms epoch when `position` was read from the device. Null when the driver
|
|
50398
|
+
* does not say; a UI that advances the position while playing counts from it. */
|
|
50399
|
+
positionUpdatedAt: number().nullable().default(null),
|
|
50062
50400
|
/** Ms epoch when the slice was last updated. */
|
|
50063
50401
|
lastChangedAt: number()
|
|
50064
50402
|
});
|
|
@@ -50694,7 +51032,9 @@ var ThresholdTransformDraftSchema = object({
|
|
|
50694
51032
|
comparison: _enum(["gte", "lte"]),
|
|
50695
51033
|
threshold: number(),
|
|
50696
51034
|
startDwellMs: number().nonnegative(),
|
|
50697
|
-
stopDwellMs: number().nonnegative()
|
|
51035
|
+
stopDwellMs: number().nonnegative(),
|
|
51036
|
+
/** Samples a start needs; absent = the compiler's default for the source (2 for running power, else 1). */
|
|
51037
|
+
minSamples: number().int().min(1).optional()
|
|
50698
51038
|
});
|
|
50699
51039
|
var CustomizeTransformDraftSchema = discriminatedUnion("kind", [
|
|
50700
51040
|
IdentityTransformDraftSchema,
|
|
@@ -56594,6 +56934,7 @@ var IntegrationWithStateSchema = object({
|
|
|
56594
56934
|
id: string(),
|
|
56595
56935
|
addonId: string(),
|
|
56596
56936
|
name: string(),
|
|
56937
|
+
/** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
|
|
56597
56938
|
enabled: boolean(),
|
|
56598
56939
|
info: record(string(), unknown()).readonly(),
|
|
56599
56940
|
/** The discovery candidate this integration was set up from (D984). */
|
|
@@ -56606,6 +56947,7 @@ var IntegrationLiteSchema = object({
|
|
|
56606
56947
|
id: string(),
|
|
56607
56948
|
addonId: string(),
|
|
56608
56949
|
name: string(),
|
|
56950
|
+
/** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
|
|
56609
56951
|
enabled: boolean(),
|
|
56610
56952
|
info: record(string(), unknown()).readonly(),
|
|
56611
56953
|
/** The discovery candidate this integration was set up from (D984). */
|
|
@@ -56705,7 +57047,6 @@ var TestConnectionResultSchema = object({
|
|
|
56705
57047
|
var CreateIntegrationInputSchema = object({
|
|
56706
57048
|
addonId: string(),
|
|
56707
57049
|
name: string(),
|
|
56708
|
-
enabled: boolean().optional(),
|
|
56709
57050
|
info: record(string(), unknown()).optional(),
|
|
56710
57051
|
/** `stableId` of the discovery candidate the form was seeded from (D984). */
|
|
56711
57052
|
originStableId: string().optional(),
|
|
@@ -56714,6 +57055,11 @@ var CreateIntegrationInputSchema = object({
|
|
|
56714
57055
|
var UpdateIntegrationInputSchema = object({
|
|
56715
57056
|
id: string(),
|
|
56716
57057
|
name: string().optional(),
|
|
57058
|
+
/**
|
|
57059
|
+
* Accepted for a FIXED builtin only (`info.fixed`: alarm panel, camera grid, core blocks,
|
|
57060
|
+
* terminal), which keeps no instance record: the registry flag is its one store. Any other
|
|
57061
|
+
* integration is switched through `integration-instances.setInstanceEnabled`.
|
|
57062
|
+
*/
|
|
56717
57063
|
enabled: boolean().optional(),
|
|
56718
57064
|
info: record(string(), unknown()).optional()
|
|
56719
57065
|
});
|
|
@@ -56761,7 +57107,7 @@ var IntegrationInstanceIdSchema = string().min(1);
|
|
|
56761
57107
|
var IntegrationInstanceModeSchema = _enum(["single", "multiple"]);
|
|
56762
57108
|
/**
|
|
56763
57109
|
* What the addon's instances ARE for the Integrations page (planning#416). `devices`: each
|
|
56764
|
-
* instance is an integration that brings devices (
|
|
57110
|
+
* instance is an integration that brings devices (its record body owns the on/off switch);
|
|
56765
57111
|
* `services`: a connection configured from the addon's own function page, never listed on
|
|
56766
57112
|
* Integrations.
|
|
56767
57113
|
* It is the same vocabulary as the manifest's `integrationRole`, which stays as an override.
|
|
@@ -56804,18 +57150,38 @@ var IntegrationInstanceKindSchema = object({
|
|
|
56804
57150
|
/** Relative hub path to disconnect that account. */
|
|
56805
57151
|
disconnectPath: string().min(1).optional()
|
|
56806
57152
|
});
|
|
57153
|
+
/**
|
|
57154
|
+
* How devices of an instance are found. `none`: the operator adds them by hand; `lan`: the addon
|
|
57155
|
+
* scans the network before any instance exists (the wizard offers the candidates); `account`: the
|
|
57156
|
+
* devices appear after the instance signs in. `scopedToInstance`: a discovery run belongs to ONE
|
|
57157
|
+
* instance and its candidates are claimed by it.
|
|
57158
|
+
*/
|
|
57159
|
+
var IntegrationInstanceDiscoverySchema = object({
|
|
57160
|
+
mode: _enum([
|
|
57161
|
+
"none",
|
|
57162
|
+
"lan",
|
|
57163
|
+
"account"
|
|
57164
|
+
]),
|
|
57165
|
+
scopedToInstance: boolean()
|
|
57166
|
+
});
|
|
57167
|
+
/**
|
|
57168
|
+
* One link a kind of this provider declares (D1013 rule 5): the body `field` of an instance of
|
|
57169
|
+
* `kind` holds the id of an instance of the function cap `to.cap` (of kind `to.kind`, when set).
|
|
57170
|
+
* The hub indexes these so the target's delete is refused while a link names it.
|
|
57171
|
+
*/
|
|
57172
|
+
var IntegrationInstanceLinkSchema = object({
|
|
57173
|
+
kind: string().min(1),
|
|
57174
|
+
field: string().min(1),
|
|
57175
|
+
to: object({
|
|
57176
|
+
cap: string().min(1),
|
|
57177
|
+
kind: string().min(1).optional()
|
|
57178
|
+
})
|
|
57179
|
+
});
|
|
56807
57180
|
var IntegrationInstanceDescriptionSchema = object({
|
|
56808
57181
|
/** What the instances are for the Integrations page; see {@link IntegrationInstanceRoleSchema}. */
|
|
56809
57182
|
role: IntegrationInstanceRoleSchema,
|
|
56810
57183
|
/** How the devices of an instance are found; absent means `{ mode: 'none' }`. */
|
|
56811
|
-
discovery:
|
|
56812
|
-
mode: _enum([
|
|
56813
|
-
"none",
|
|
56814
|
-
"lan",
|
|
56815
|
-
"account"
|
|
56816
|
-
]),
|
|
56817
|
-
scopedToInstance: boolean()
|
|
56818
|
-
}).optional(),
|
|
57184
|
+
discovery: IntegrationInstanceDiscoverySchema.optional(),
|
|
56819
57185
|
/** `single`: at most one instance can exist (Loki). `multiple`: an account each. */
|
|
56820
57186
|
instanceMode: IntegrationInstanceModeSchema,
|
|
56821
57187
|
/** What the instance is, for the UI (`destination`, `relay`, `account`). */
|
|
@@ -56836,7 +57202,9 @@ var IntegrationInstanceDescriptionSchema = object({
|
|
|
56836
57202
|
* `createInstance` without an `id` works: the provider mints it. Absent means the caller must
|
|
56837
57203
|
* send an id (the UI then mints an opaque one).
|
|
56838
57204
|
*/
|
|
56839
|
-
mintsId: boolean().optional()
|
|
57205
|
+
mintsId: boolean().optional(),
|
|
57206
|
+
/** The links to other instances the provider's kinds declare; absent means none. */
|
|
57207
|
+
links: array(IntegrationInstanceLinkSchema).optional()
|
|
56840
57208
|
});
|
|
56841
57209
|
var IntegrationInstanceStatusSchema = object({
|
|
56842
57210
|
state: _enum([
|
|
@@ -56856,8 +57224,8 @@ var IntegrationInstanceSchema = object({
|
|
|
56856
57224
|
configured: boolean(),
|
|
56857
57225
|
/**
|
|
56858
57226
|
* The instance's own on/off switch (D996), derived from the record body (`enabled !== false`,
|
|
56859
|
-
* so a row written before the field existed is on).
|
|
56860
|
-
*
|
|
57227
|
+
* so a row written before the field existed is on). The same for every role, `devices` included:
|
|
57228
|
+
* the body is the one store, `setInstanceEnabled` the one writer (epic #440, step 3).
|
|
56861
57229
|
*/
|
|
56862
57230
|
enabled: boolean().optional(),
|
|
56863
57231
|
/** The kind of this instance (one of `describe().kinds[].id`), when the provider has kinds. */
|
|
@@ -56907,7 +57275,8 @@ var integrationInstancesCapability = {
|
|
|
56907
57275
|
auth: "admin"
|
|
56908
57276
|
}),
|
|
56909
57277
|
/**
|
|
56910
|
-
* Switch ONE instance on or off
|
|
57278
|
+
* Switch ONE instance on or off, for every role; a missing record is created from the addon's
|
|
57279
|
+
* initial body. A row control, not a form field: `updateInstance.values` is the
|
|
56911
57280
|
* form patch (D62, D996). An off instance keeps its record and secrets and does no work.
|
|
56912
57281
|
*/
|
|
56913
57282
|
setInstanceEnabled: method(object({
|
|
@@ -59970,6 +60339,8 @@ var MigrationIntegrationSchema = object({
|
|
|
59970
60339
|
addonId: string(),
|
|
59971
60340
|
name: string(),
|
|
59972
60341
|
info: Rows,
|
|
60342
|
+
/** The registry's stored switch: read by the one-switch migration, nothing else. */
|
|
60343
|
+
enabled: boolean().optional(),
|
|
59973
60344
|
originStableId: string().optional()
|
|
59974
60345
|
});
|
|
59975
60346
|
var MigrationDeviceSchema = object({
|
|
@@ -70145,14 +70516,6 @@ var PetFountainStatusSchema = object({
|
|
|
70145
70516
|
empty: boolean().nullable(),
|
|
70146
70517
|
/** True while the pump is running. Null while unknown. */
|
|
70147
70518
|
pumpRunning: boolean().nullable(),
|
|
70148
|
-
/** Water drunk in the last drink, in litres. */
|
|
70149
|
-
lastDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
70150
|
-
/** Water drunk in the current hour, in litres. */
|
|
70151
|
-
currentHourDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
70152
|
-
/** Water drunk over the last 24 hours (rolling), in litres. */
|
|
70153
|
-
last24hDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
70154
|
-
/** Water drunk since local midnight, in litres. Null when the fountain has no such sensor. */
|
|
70155
|
-
todayDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
70156
70519
|
/** Decoded fault message. Null means healthy; a non-null string is an active fault. */
|
|
70157
70520
|
error: string().nullable(),
|
|
70158
70521
|
/** Ms epoch when the slice was last refreshed. */
|
|
@@ -70165,21 +70528,15 @@ var petFountainCapability = {
|
|
|
70165
70528
|
deviceNative: true,
|
|
70166
70529
|
mode: "singleton",
|
|
70167
70530
|
deviceTypes: [DeviceType.PetFountain],
|
|
70168
|
-
methods: {
|
|
70169
|
-
|
|
70170
|
-
|
|
70171
|
-
|
|
70172
|
-
|
|
70173
|
-
|
|
70174
|
-
|
|
70175
|
-
|
|
70176
|
-
|
|
70177
|
-
/** Clear the rolling daily consumption counters on the device. */
|
|
70178
|
-
resetDailyConsumption: method(object({ deviceId: DeviceIdSchema$1 }), _void(), {
|
|
70179
|
-
kind: "mutation",
|
|
70180
|
-
auth: "protected"
|
|
70181
|
-
})
|
|
70182
|
-
},
|
|
70531
|
+
methods: {
|
|
70532
|
+
/** Start or stop the pump. */
|
|
70533
|
+
setPump: method(object({
|
|
70534
|
+
deviceId: DeviceIdSchema$1,
|
|
70535
|
+
on: boolean()
|
|
70536
|
+
}), _void(), {
|
|
70537
|
+
kind: "mutation",
|
|
70538
|
+
auth: "protected"
|
|
70539
|
+
}) },
|
|
70183
70540
|
status: {
|
|
70184
70541
|
schema: PetFountainStatusSchema,
|
|
70185
70542
|
kind: "push"
|
|
@@ -70203,14 +70560,6 @@ var petFountainCapability = {
|
|
|
70203
70560
|
waterVolume: {
|
|
70204
70561
|
kind: "gauge",
|
|
70205
70562
|
unit: "L"
|
|
70206
|
-
},
|
|
70207
|
-
todayDrink: {
|
|
70208
|
-
kind: "gauge",
|
|
70209
|
-
unit: "L"
|
|
70210
|
-
},
|
|
70211
|
-
last24hDrink: {
|
|
70212
|
-
kind: "gauge",
|
|
70213
|
-
unit: "L"
|
|
70214
70563
|
}
|
|
70215
70564
|
} }
|
|
70216
70565
|
};
|
|
@@ -89941,13 +90290,6 @@ Object.freeze({
|
|
|
89941
90290
|
access: "view",
|
|
89942
90291
|
role: "viewer"
|
|
89943
90292
|
},
|
|
89944
|
-
"petFountain.resetDailyConsumption": {
|
|
89945
|
-
capName: "pet-fountain",
|
|
89946
|
-
capScope: "device",
|
|
89947
|
-
addonId: null,
|
|
89948
|
-
access: "delete",
|
|
89949
|
-
role: "viewer"
|
|
89950
|
-
},
|
|
89951
90293
|
"petFountain.setPump": {
|
|
89952
90294
|
capName: "pet-fountain",
|
|
89953
90295
|
capScope: "device",
|
|
@@ -96562,11 +96904,6 @@ Object.freeze({
|
|
|
96562
96904
|
form: "single",
|
|
96563
96905
|
optional: false
|
|
96564
96906
|
}],
|
|
96565
|
-
"petFountain.resetDailyConsumption": [{
|
|
96566
|
-
name: "deviceId",
|
|
96567
|
-
form: "single",
|
|
96568
|
-
optional: false
|
|
96569
|
-
}],
|
|
96570
96907
|
"petFountain.setPump": [{
|
|
96571
96908
|
name: "deviceId",
|
|
96572
96909
|
form: "single",
|
|
@@ -99361,100 +99698,6 @@ object({
|
|
|
99361
99698
|
delay: number().nonnegative().optional(),
|
|
99362
99699
|
commands: record(string(), unknown())
|
|
99363
99700
|
});
|
|
99364
|
-
entryBody({ brokerId: string() });
|
|
99365
|
-
function secretsOverMigrationApi(api) {
|
|
99366
|
-
return {
|
|
99367
|
-
resolve: async (refs) => {
|
|
99368
|
-
const { values } = await api.secrets.resolve({ refs: [...refs] });
|
|
99369
|
-
const out = {};
|
|
99370
|
-
for (const ref of refs) {
|
|
99371
|
-
const value = values[ref];
|
|
99372
|
-
out[ref] = value === null || value === void 0 ? { kind: "missing" } : {
|
|
99373
|
-
kind: "value",
|
|
99374
|
-
value,
|
|
99375
|
-
version: 0
|
|
99376
|
-
};
|
|
99377
|
-
}
|
|
99378
|
-
return out;
|
|
99379
|
-
},
|
|
99380
|
-
delete: async (refs) => (await api.secrets.delete({ refs: [...refs] })).deleted
|
|
99381
|
-
};
|
|
99382
|
-
}
|
|
99383
|
-
/** `ctx.records` as the migration API offers it: bind a kind, read and write by id. */
|
|
99384
|
-
function recordsOverMigrationApi(api) {
|
|
99385
|
-
return { kind: (definition) => {
|
|
99386
|
-
const handle = api.records.kind(definition);
|
|
99387
|
-
return {
|
|
99388
|
-
get: (id) => handle.get({ id }),
|
|
99389
|
-
getResolved: (id) => handle.getResolved({ id }),
|
|
99390
|
-
put: (input, opts) => handle.put({
|
|
99391
|
-
...input,
|
|
99392
|
-
...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
|
|
99393
|
-
}),
|
|
99394
|
-
delete: (id) => handle.delete({ id })
|
|
99395
|
-
};
|
|
99396
|
-
} };
|
|
99397
|
-
}
|
|
99398
|
-
function integrationRowsApiOver(api) {
|
|
99399
|
-
return {
|
|
99400
|
-
list: async () => (await api.integrations.list({})).integrations,
|
|
99401
|
-
readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
|
|
99402
|
-
clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
|
|
99403
|
-
};
|
|
99404
|
-
}
|
|
99405
|
-
/**
|
|
99406
|
-
* One serial lane per migration API: a log line is delivered after the line before it, so the
|
|
99407
|
-
* order the steps wrote them in is the order the hub reads them in. A delivery that fails
|
|
99408
|
-
* is reported once through the same door; if that fails too nothing is left to tell, and the
|
|
99409
|
-
* line is dropped rather than thrown into a migration step or left as an unhandled rejection.
|
|
99410
|
-
*/
|
|
99411
|
-
var lanes = /* @__PURE__ */ new WeakMap();
|
|
99412
|
-
function deliver(api, send) {
|
|
99413
|
-
const next = (lanes.get(api) ?? Promise.resolve()).then(send).then(() => void 0).catch(async (error) => {
|
|
99414
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
99415
|
-
await api.log.warn({ message: `a migration log line could not be delivered: ${reason}` }).catch(() => void 0);
|
|
99416
|
-
});
|
|
99417
|
-
lanes.set(api, next);
|
|
99418
|
-
return next;
|
|
99419
|
-
}
|
|
99420
|
-
function warnOver(api) {
|
|
99421
|
-
return (message) => deliver(api, () => api.log.warn({ message }));
|
|
99422
|
-
}
|
|
99423
|
-
/** What the rows-to-records move needs, over the migration API. */
|
|
99424
|
-
function rowsDepsOver(api) {
|
|
99425
|
-
return {
|
|
99426
|
-
api: integrationRowsApiOver(api),
|
|
99427
|
-
records: recordsOverMigrationApi(api),
|
|
99428
|
-
secrets: secretsOverMigrationApi(api),
|
|
99429
|
-
warn: warnOver(api)
|
|
99430
|
-
};
|
|
99431
|
-
}
|
|
99432
|
-
function defaultIntegrationApiOver$1(api) {
|
|
99433
|
-
return {
|
|
99434
|
-
...integrationRowsApiOver(api),
|
|
99435
|
-
listDevices: async (addonId) => (await api.devices.list({ addonId })).devices,
|
|
99436
|
-
readDeviceHasConfig: async (deviceId) => (await api.devices.get({ deviceId }))?.hasConfig ?? false,
|
|
99437
|
-
setDeviceIntegrationId: async (deviceId, integrationId) => {
|
|
99438
|
-
await api.devices.setIntegrationId({
|
|
99439
|
-
deviceId,
|
|
99440
|
-
integrationId
|
|
99441
|
-
});
|
|
99442
|
-
},
|
|
99443
|
-
readDeviceIntegrationId: async (deviceId) => (await api.devices.get({ deviceId }))?.integrationId ?? null
|
|
99444
|
-
};
|
|
99445
|
-
}
|
|
99446
|
-
/** What the rows-to-records move and the device claim need, over the migration API. */
|
|
99447
|
-
function defaultIntegrationDepsOver(api) {
|
|
99448
|
-
return {
|
|
99449
|
-
...rowsDepsOver(api),
|
|
99450
|
-
api: defaultIntegrationApiOver$1(api),
|
|
99451
|
-
info: (message) => deliver(api, () => api.log.info({ message })),
|
|
99452
|
-
warnDevice: (message, deviceId) => deliver(api, () => api.log.warn({
|
|
99453
|
-
message,
|
|
99454
|
-
tags: { deviceId }
|
|
99455
|
-
}))
|
|
99456
|
-
};
|
|
99457
|
-
}
|
|
99458
99701
|
/**
|
|
99459
99702
|
* Per-device bounds for the STILLS, which are a different artifact entirely.
|
|
99460
99703
|
*
|
|
@@ -113181,6 +113424,10 @@ var HikvisionProviderAddon = class extends BaseDeviceProvider {
|
|
|
113181
113424
|
const records = this.ctx.records;
|
|
113182
113425
|
if (records === void 0) throw new Error("provider-hikvision: ctx.records is required (hub-only addon)");
|
|
113183
113426
|
await records.declare(hikvisionRecordKinds);
|
|
113427
|
+
this.declareRegistrySwitch({
|
|
113428
|
+
kind: hikvisionConnectionsEntryKind,
|
|
113429
|
+
initialBody: (name) => ({ name })
|
|
113430
|
+
});
|
|
113184
113431
|
await this.runMigrations(defaultIntegrationMigrations({
|
|
113185
113432
|
addonId: this.addonId,
|
|
113186
113433
|
date: HIKVISION_MIGRATIONS_DATE
|