@camstack/addon-provider-bosch 0.1.39 → 0.1.40
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/{account-integration-offline-etjkhGaj.mjs → account-integration-offline-DTnyqayb.mjs} +1 -1
- package/dist/{account-integration-offline-CG1-xGSm.js → account-integration-offline-DwgBg38i.js} +1 -1
- package/dist/{bosch-instances-WlrW2PAy.js → bosch-instances-DEH7DYwo.js} +1002 -759
- package/dist/{bosch-instances-GrNuqDFv.mjs → bosch-instances-Yqi-WAZN.mjs} +1003 -760
- package/dist/home-connect/addon.js +9 -4
- package/dist/home-connect/addon.mjs +9 -4
- package/dist/homecom/addon.js +9 -4
- package/dist/homecom/addon.mjs +9 -4
- package/dist/shc/addon.js +8 -3
- package/dist/shc/addon.mjs +8 -3
- package/package.json +2 -2
|
@@ -5981,7 +5981,7 @@ var ZodIssueCode = {
|
|
|
5981
5981
|
var ZodFirstPartyTypeKind;
|
|
5982
5982
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
5983
5983
|
//#endregion
|
|
5984
|
-
//#region ../types/dist/sleep-
|
|
5984
|
+
//#region ../types/dist/sleep-CmjWurK5.mjs
|
|
5985
5985
|
/**
|
|
5986
5986
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
5987
5987
|
* window to float samples (D455).
|
|
@@ -6665,6 +6665,802 @@ async function runAddonMigrations(host, migrations, logger, options = {}) {
|
|
|
6665
6665
|
blockOwner
|
|
6666
6666
|
};
|
|
6667
6667
|
}
|
|
6668
|
+
function secretsOverMigrationApi(api) {
|
|
6669
|
+
return {
|
|
6670
|
+
resolve: async (refs) => {
|
|
6671
|
+
const { values } = await api.secrets.resolve({ refs: [...refs] });
|
|
6672
|
+
const out = {};
|
|
6673
|
+
for (const ref of refs) {
|
|
6674
|
+
const value = values[ref];
|
|
6675
|
+
out[ref] = value === null || value === void 0 ? { kind: "missing" } : {
|
|
6676
|
+
kind: "value",
|
|
6677
|
+
value,
|
|
6678
|
+
version: 0
|
|
6679
|
+
};
|
|
6680
|
+
}
|
|
6681
|
+
return out;
|
|
6682
|
+
},
|
|
6683
|
+
delete: async (refs) => (await api.secrets.delete({ refs: [...refs] })).deleted
|
|
6684
|
+
};
|
|
6685
|
+
}
|
|
6686
|
+
/** The record calls the one-switch migration makes, over the migration API. */
|
|
6687
|
+
function switchRecordsOverMigrationApi(api) {
|
|
6688
|
+
return { kind: (definition) => {
|
|
6689
|
+
const handle = api.records.kind(definition);
|
|
6690
|
+
return {
|
|
6691
|
+
get: (id) => handle.get({ id }),
|
|
6692
|
+
put: (input, opts) => handle.put({
|
|
6693
|
+
...input,
|
|
6694
|
+
...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
|
|
6695
|
+
}),
|
|
6696
|
+
patch: (id, partial) => handle.patch({
|
|
6697
|
+
id,
|
|
6698
|
+
partial
|
|
6699
|
+
})
|
|
6700
|
+
};
|
|
6701
|
+
} };
|
|
6702
|
+
}
|
|
6703
|
+
/** `ctx.records` as the migration API offers it: bind a kind, read and write by id. */
|
|
6704
|
+
function recordsOverMigrationApi(api) {
|
|
6705
|
+
return { kind: (definition) => {
|
|
6706
|
+
const handle = api.records.kind(definition);
|
|
6707
|
+
return {
|
|
6708
|
+
get: (id) => handle.get({ id }),
|
|
6709
|
+
getResolved: (id) => handle.getResolved({ id }),
|
|
6710
|
+
put: (input, opts) => handle.put({
|
|
6711
|
+
...input,
|
|
6712
|
+
...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
|
|
6713
|
+
}),
|
|
6714
|
+
delete: (id) => handle.delete({ id })
|
|
6715
|
+
};
|
|
6716
|
+
} };
|
|
6717
|
+
}
|
|
6718
|
+
function integrationRowsApiOver(api) {
|
|
6719
|
+
return {
|
|
6720
|
+
list: async () => (await api.integrations.list({})).integrations,
|
|
6721
|
+
readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
|
|
6722
|
+
clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
|
|
6723
|
+
};
|
|
6724
|
+
}
|
|
6725
|
+
/**
|
|
6726
|
+
* One serial lane per migration API: a log line is delivered after the line before it, so the
|
|
6727
|
+
* order the steps wrote them in is the order the hub reads them in. A delivery that fails
|
|
6728
|
+
* is reported once through the same door; if that fails too nothing is left to tell, and the
|
|
6729
|
+
* line is dropped rather than thrown into a migration step or left as an unhandled rejection.
|
|
6730
|
+
*/
|
|
6731
|
+
var lanes = /* @__PURE__ */ new WeakMap();
|
|
6732
|
+
function deliver(api, send) {
|
|
6733
|
+
const next = (lanes.get(api) ?? Promise.resolve()).then(send).then(() => void 0).catch(async (error) => {
|
|
6734
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
6735
|
+
await api.log.warn({ message: `a migration log line could not be delivered: ${reason}` }).catch(() => void 0);
|
|
6736
|
+
});
|
|
6737
|
+
lanes.set(api, next);
|
|
6738
|
+
return next;
|
|
6739
|
+
}
|
|
6740
|
+
function warnOver(api) {
|
|
6741
|
+
return (message) => deliver(api, () => api.log.warn({ message }));
|
|
6742
|
+
}
|
|
6743
|
+
/** What the rows-to-records move needs, over the migration API. */
|
|
6744
|
+
function rowsDepsOver(api) {
|
|
6745
|
+
return {
|
|
6746
|
+
api: integrationRowsApiOver(api),
|
|
6747
|
+
records: recordsOverMigrationApi(api),
|
|
6748
|
+
secrets: secretsOverMigrationApi(api),
|
|
6749
|
+
warn: warnOver(api)
|
|
6750
|
+
};
|
|
6751
|
+
}
|
|
6752
|
+
var PREFIX = "records/";
|
|
6753
|
+
/** The base of every records failure. `detail` is the human part of the message. */
|
|
6754
|
+
var RecordsError = class extends Error {
|
|
6755
|
+
code;
|
|
6756
|
+
detail;
|
|
6757
|
+
constructor(code, detail) {
|
|
6758
|
+
super(`${PREFIX}${code}: ${detail}`);
|
|
6759
|
+
this.name = "RecordsError";
|
|
6760
|
+
this.code = code;
|
|
6761
|
+
this.detail = detail;
|
|
6762
|
+
}
|
|
6763
|
+
};
|
|
6764
|
+
/** A write guarded by `ifRev` found another revision (or an existing row for `ifRev: 0`). */
|
|
6765
|
+
var RevConflictError = class extends RecordsError {
|
|
6766
|
+
constructor(detail) {
|
|
6767
|
+
super("rev-conflict", detail);
|
|
6768
|
+
this.name = "RevConflictError";
|
|
6769
|
+
}
|
|
6770
|
+
};
|
|
6771
|
+
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
6772
|
+
var RecordSecretUnavailableError = class extends RecordsError {
|
|
6773
|
+
constructor(detail) {
|
|
6774
|
+
super("secret-unavailable", detail);
|
|
6775
|
+
this.name = "RecordSecretUnavailableError";
|
|
6776
|
+
}
|
|
6777
|
+
};
|
|
6778
|
+
var InvalidRecordError = class extends RecordsError {
|
|
6779
|
+
constructor(detail) {
|
|
6780
|
+
super("invalid-record", detail);
|
|
6781
|
+
this.name = "InvalidRecordError";
|
|
6782
|
+
}
|
|
6783
|
+
};
|
|
6784
|
+
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
6785
|
+
var DeclarationRefusedError = class extends RecordsError {
|
|
6786
|
+
constructor(detail) {
|
|
6787
|
+
super("declaration-refused", detail);
|
|
6788
|
+
this.name = "DeclarationRefusedError";
|
|
6789
|
+
}
|
|
6790
|
+
};
|
|
6791
|
+
function linkTargetOf(meta) {
|
|
6792
|
+
if (typeof meta !== "object" || meta === null) return void 0;
|
|
6793
|
+
const link = Reflect.get(meta, "link");
|
|
6794
|
+
const parsed = LinkTargetSchema.safeParse(link);
|
|
6795
|
+
return parsed.success ? parsed.data : void 0;
|
|
6796
|
+
}
|
|
6797
|
+
var LinkTargetSchema = object({
|
|
6798
|
+
cap: string().min(1),
|
|
6799
|
+
kind: string().min(1).optional()
|
|
6800
|
+
});
|
|
6801
|
+
/** The links a kind declares, read from the meta of its body fields. */
|
|
6802
|
+
function linksOfKind(kind) {
|
|
6803
|
+
const schema = kind.schema;
|
|
6804
|
+
if (!(schema instanceof ZodObject)) return [];
|
|
6805
|
+
const links = [];
|
|
6806
|
+
for (const [field, fieldSchema] of Object.entries(schema.shape)) {
|
|
6807
|
+
const to = linkTargetOf(globalRegistry.get(fieldSchema));
|
|
6808
|
+
if (to !== void 0) links.push({
|
|
6809
|
+
field,
|
|
6810
|
+
to
|
|
6811
|
+
});
|
|
6812
|
+
}
|
|
6813
|
+
return links;
|
|
6814
|
+
}
|
|
6815
|
+
/**
|
|
6816
|
+
* The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
|
|
6817
|
+
*
|
|
6818
|
+
* A ref is DETERMINISTIC from where the value lives — the owner addon, the
|
|
6819
|
+
* scope (global, one node, one device, one integration, one row of a business
|
|
6820
|
+
* collection) and the field path inside that scope — so saving the same field
|
|
6821
|
+
* twice updates the same ref, and the ref itself says which settings blob
|
|
6822
|
+
* points at it. It is also the AAD of the value's ciphertext: a ciphertext
|
|
6823
|
+
* copied onto another ref does not decrypt.
|
|
6824
|
+
*
|
|
6825
|
+
* Array items are addressed by ITEM ID, never by index
|
|
6826
|
+
* (`providers[authentik].clientSecret`), so reordering a list keeps every ref.
|
|
6827
|
+
*
|
|
6828
|
+
* Pure and browser-safe: no node builtins, no I/O.
|
|
6829
|
+
*/
|
|
6830
|
+
/** The URI scheme of every keychain ref. */
|
|
6831
|
+
var SECRET_REF_SCHEME = "secret://";
|
|
6832
|
+
var GLOBAL_SCOPE = { kind: "global" };
|
|
6833
|
+
/** The scope every addon-wide (not per-node, not per-device) setting lives in. */
|
|
6834
|
+
function globalSecretScope() {
|
|
6835
|
+
return GLOBAL_SCOPE;
|
|
6836
|
+
}
|
|
6837
|
+
/**
|
|
6838
|
+
* An addon id as a ref owner. A hub in-process builtin's context id is
|
|
6839
|
+
* `addon:<id>`; the owner of its secrets is `<id>`, exactly as for the same
|
|
6840
|
+
* addon running forked.
|
|
6841
|
+
*/
|
|
6842
|
+
function normalizeSecretOwner(addonId) {
|
|
6843
|
+
return addonId.startsWith("addon:") ? addonId.slice(6) : addonId;
|
|
6844
|
+
}
|
|
6845
|
+
function encodeSegment(value) {
|
|
6846
|
+
return encodeURIComponent(value);
|
|
6847
|
+
}
|
|
6848
|
+
function decodeSegment(value) {
|
|
6849
|
+
try {
|
|
6850
|
+
return decodeURIComponent(value);
|
|
6851
|
+
} catch {
|
|
6852
|
+
return null;
|
|
6853
|
+
}
|
|
6854
|
+
}
|
|
6855
|
+
/** The scope as it appears inside a ref (`global`, `node/<id>`, …). */
|
|
6856
|
+
function formatSecretScope(scope) {
|
|
6857
|
+
switch (scope.kind) {
|
|
6858
|
+
case "global": return "global";
|
|
6859
|
+
case "node": return `node/${encodeSegment(scope.nodeId)}`;
|
|
6860
|
+
case "device": return `device/${scope.deviceId}`;
|
|
6861
|
+
case "integration": return `integration/${encodeSegment(scope.integrationId)}`;
|
|
6862
|
+
case "row": return `row/${encodeSegment(scope.collection)}/${encodeSegment(scope.rowId)}`;
|
|
6863
|
+
}
|
|
6864
|
+
}
|
|
6865
|
+
/**
|
|
6866
|
+
* The field path of a value inside an array item, addressed by the item's id:
|
|
6867
|
+
* `arrayItemFieldPath('providers', 'authentik', 'clientSecret')` →
|
|
6868
|
+
* `providers[authentik].clientSecret`.
|
|
6869
|
+
*/
|
|
6870
|
+
function arrayItemFieldPath(arrayKey, itemId, fieldKey) {
|
|
6871
|
+
return `${arrayKey}[${encodeSegment(itemId)}].${fieldKey}`;
|
|
6872
|
+
}
|
|
6873
|
+
/** Build a ref. Throws on an empty owner or field path — both are bugs. */
|
|
6874
|
+
function buildSecretRef(parts) {
|
|
6875
|
+
const owner = normalizeSecretOwner(parts.owner);
|
|
6876
|
+
if (owner.length === 0) throw new Error("buildSecretRef: owner is empty");
|
|
6877
|
+
if (parts.fieldPath.length === 0) throw new Error("buildSecretRef: fieldPath is empty");
|
|
6878
|
+
return `${SECRET_REF_SCHEME}${encodeSegment(owner)}/${formatSecretScope(parts.scope)}/${parts.fieldPath}`;
|
|
6879
|
+
}
|
|
6880
|
+
function parseScope(segments) {
|
|
6881
|
+
switch (segments[0]) {
|
|
6882
|
+
case "global": return {
|
|
6883
|
+
scope: GLOBAL_SCOPE,
|
|
6884
|
+
used: 1
|
|
6885
|
+
};
|
|
6886
|
+
case "node": {
|
|
6887
|
+
const nodeId = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
|
|
6888
|
+
return nodeId === null || nodeId.length === 0 ? null : {
|
|
6889
|
+
scope: {
|
|
6890
|
+
kind: "node",
|
|
6891
|
+
nodeId
|
|
6892
|
+
},
|
|
6893
|
+
used: 2
|
|
6894
|
+
};
|
|
6895
|
+
}
|
|
6896
|
+
case "device": {
|
|
6897
|
+
const raw = segments[1];
|
|
6898
|
+
if (raw === void 0 || !/^\d+$/.test(raw)) return null;
|
|
6899
|
+
return {
|
|
6900
|
+
scope: {
|
|
6901
|
+
kind: "device",
|
|
6902
|
+
deviceId: Number(raw)
|
|
6903
|
+
},
|
|
6904
|
+
used: 2
|
|
6905
|
+
};
|
|
6906
|
+
}
|
|
6907
|
+
case "integration": {
|
|
6908
|
+
const id = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
|
|
6909
|
+
return id === null || id.length === 0 ? null : {
|
|
6910
|
+
scope: {
|
|
6911
|
+
kind: "integration",
|
|
6912
|
+
integrationId: id
|
|
6913
|
+
},
|
|
6914
|
+
used: 2
|
|
6915
|
+
};
|
|
6916
|
+
}
|
|
6917
|
+
case "row": {
|
|
6918
|
+
const collection = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
|
|
6919
|
+
const rowId = segments[2] !== void 0 ? decodeSegment(segments[2]) : null;
|
|
6920
|
+
if (collection === null || rowId === null || collection.length === 0 || rowId.length === 0) return null;
|
|
6921
|
+
return {
|
|
6922
|
+
scope: {
|
|
6923
|
+
kind: "row",
|
|
6924
|
+
collection,
|
|
6925
|
+
rowId
|
|
6926
|
+
},
|
|
6927
|
+
used: 3
|
|
6928
|
+
};
|
|
6929
|
+
}
|
|
6930
|
+
default: return null;
|
|
6931
|
+
}
|
|
6932
|
+
}
|
|
6933
|
+
/** Take a ref apart; `null` when it is not a well-formed ref. */
|
|
6934
|
+
function parseSecretRef(ref) {
|
|
6935
|
+
if (!ref.startsWith("secret://")) return null;
|
|
6936
|
+
const segments = ref.slice(9).split("/");
|
|
6937
|
+
const owner = segments[0] !== void 0 ? decodeSegment(segments[0]) : null;
|
|
6938
|
+
if (owner === null || owner.length === 0) return null;
|
|
6939
|
+
const parsed = parseScope(segments.slice(1));
|
|
6940
|
+
if (parsed === null) return null;
|
|
6941
|
+
const fieldPath = segments.slice(1 + parsed.used).join("/");
|
|
6942
|
+
if (fieldPath.length === 0) return null;
|
|
6943
|
+
return {
|
|
6944
|
+
owner,
|
|
6945
|
+
scope: parsed.scope,
|
|
6946
|
+
fieldPath
|
|
6947
|
+
};
|
|
6948
|
+
}
|
|
6949
|
+
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
6950
|
+
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
6951
|
+
var RECORD_DATABASES = ["settings", "events"];
|
|
6952
|
+
/** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
|
|
6953
|
+
var RECORD_CLASSES = [
|
|
6954
|
+
"config",
|
|
6955
|
+
"ledger",
|
|
6956
|
+
"audit",
|
|
6957
|
+
"mirror",
|
|
6958
|
+
"ephemeral"
|
|
6959
|
+
];
|
|
6960
|
+
var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
6961
|
+
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
6962
|
+
var RECORD_BATCH_MAX = 1e3;
|
|
6963
|
+
var RECORD_QUERY_MAX = 1e3;
|
|
6964
|
+
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
6965
|
+
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
6966
|
+
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
6967
|
+
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
6968
|
+
/**
|
|
6969
|
+
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
6970
|
+
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
6971
|
+
* (`auth.accessToken`, `headers[].value`).
|
|
6972
|
+
*
|
|
6973
|
+
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
6974
|
+
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
6975
|
+
* key releases exactly that key's secret.
|
|
6976
|
+
*
|
|
6977
|
+
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
6978
|
+
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
6979
|
+
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
6980
|
+
* leaf names its element: `headers[X-Api].value`.
|
|
6981
|
+
*
|
|
6982
|
+
* Pure and browser-safe. Nothing here mutates: every transform returns a new value.
|
|
6983
|
+
*/
|
|
6984
|
+
/** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
|
|
6985
|
+
function parseSecretPath(path) {
|
|
6986
|
+
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
6987
|
+
return path.split(".").map((raw) => {
|
|
6988
|
+
const each = raw.endsWith("[]");
|
|
6989
|
+
const map = raw.endsWith("{}");
|
|
6990
|
+
const key = each || map ? raw.slice(0, -2) : raw;
|
|
6991
|
+
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
6992
|
+
return {
|
|
6993
|
+
key,
|
|
6994
|
+
each,
|
|
6995
|
+
map
|
|
6996
|
+
};
|
|
6997
|
+
});
|
|
6998
|
+
}
|
|
6999
|
+
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
7000
|
+
function secretArrayPrefixes(path) {
|
|
7001
|
+
const segments = parseSecretPath(path);
|
|
7002
|
+
const prefixes = [];
|
|
7003
|
+
const walked = [];
|
|
7004
|
+
for (const segment of segments) {
|
|
7005
|
+
walked.push(segment.key);
|
|
7006
|
+
if (segment.each) prefixes.push(walked.join("."));
|
|
7007
|
+
}
|
|
7008
|
+
return prefixes;
|
|
7009
|
+
}
|
|
7010
|
+
function isRecord$6(value) {
|
|
7011
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7012
|
+
}
|
|
7013
|
+
function elementId(element, idKey, declared, prefix) {
|
|
7014
|
+
const id = isRecord$6(element) ? element[idKey] : void 0;
|
|
7015
|
+
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`);
|
|
7016
|
+
return id;
|
|
7017
|
+
}
|
|
7018
|
+
/**
|
|
7019
|
+
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
7020
|
+
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
7021
|
+
* result is a new body, `data` is untouched.
|
|
7022
|
+
*/
|
|
7023
|
+
var REMOVE_LEAF = Symbol("remove-leaf");
|
|
7024
|
+
function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
|
|
7025
|
+
if (!isRecord$6(node)) return node;
|
|
7026
|
+
const segment = segments[index];
|
|
7027
|
+
if (segment === void 0) return node;
|
|
7028
|
+
if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
|
|
7029
|
+
const child = node[segment.key];
|
|
7030
|
+
const keys = [...walkedKeys, segment.key];
|
|
7031
|
+
const last = index === segments.length - 1;
|
|
7032
|
+
if (segment.each) {
|
|
7033
|
+
if (!Array.isArray(child)) return node;
|
|
7034
|
+
const prefix = keys.join(".");
|
|
7035
|
+
const idKey = arrayKeys[prefix];
|
|
7036
|
+
if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
|
|
7037
|
+
const mapped = child.map((element) => {
|
|
7038
|
+
const id = elementId(element, idKey, declared, prefix);
|
|
7039
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
|
|
7040
|
+
return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
|
|
7041
|
+
});
|
|
7042
|
+
return {
|
|
7043
|
+
...node,
|
|
7044
|
+
[segment.key]: mapped
|
|
7045
|
+
};
|
|
7046
|
+
}
|
|
7047
|
+
if (segment.map) {
|
|
7048
|
+
if (!isRecord$6(child)) return node;
|
|
7049
|
+
const kept = Object.entries(child).map(([mapKey, value]) => {
|
|
7050
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
|
|
7051
|
+
if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
|
|
7052
|
+
return [mapKey, visit({
|
|
7053
|
+
declared,
|
|
7054
|
+
concrete,
|
|
7055
|
+
value
|
|
7056
|
+
})];
|
|
7057
|
+
}).filter(([, value]) => value !== REMOVE_LEAF);
|
|
7058
|
+
return {
|
|
7059
|
+
...node,
|
|
7060
|
+
[segment.key]: Object.fromEntries(kept)
|
|
7061
|
+
};
|
|
7062
|
+
}
|
|
7063
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
7064
|
+
if (last) {
|
|
7065
|
+
const replacement = visit({
|
|
7066
|
+
declared,
|
|
7067
|
+
concrete,
|
|
7068
|
+
value: child
|
|
7069
|
+
});
|
|
7070
|
+
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
7071
|
+
return {
|
|
7072
|
+
...node,
|
|
7073
|
+
[segment.key]: replacement
|
|
7074
|
+
};
|
|
7075
|
+
}
|
|
7076
|
+
return {
|
|
7077
|
+
...node,
|
|
7078
|
+
[segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
|
|
7079
|
+
};
|
|
7080
|
+
}
|
|
7081
|
+
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
7082
|
+
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
7083
|
+
let current = data;
|
|
7084
|
+
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
7085
|
+
return current;
|
|
7086
|
+
}
|
|
7087
|
+
/** Every present secret leaf, read-only. */
|
|
7088
|
+
function collectSecretLeaves(data, paths, arrayKeys) {
|
|
7089
|
+
const found = [];
|
|
7090
|
+
mapSecretLeaves(data, paths, arrayKeys, (leaf) => {
|
|
7091
|
+
found.push(leaf);
|
|
7092
|
+
return leaf.value;
|
|
7093
|
+
});
|
|
7094
|
+
return found;
|
|
7095
|
+
}
|
|
7096
|
+
/**
|
|
7097
|
+
* The keychain collection name a kind's secrets live under. Prefixed so a
|
|
7098
|
+
* record's refs never collide with the refs a legacy collection of the same name
|
|
7099
|
+
* already holds during an adoption.
|
|
7100
|
+
*/
|
|
7101
|
+
function recordSecretCollection(kind) {
|
|
7102
|
+
return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
|
|
7103
|
+
}
|
|
7104
|
+
/** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
|
|
7105
|
+
function recordSecretRef(owner, kind, rowId, concretePath) {
|
|
7106
|
+
return buildSecretRef({
|
|
7107
|
+
owner,
|
|
7108
|
+
scope: {
|
|
7109
|
+
kind: "row",
|
|
7110
|
+
collection: recordSecretCollection(kind),
|
|
7111
|
+
rowId
|
|
7112
|
+
},
|
|
7113
|
+
fieldPath: concretePath
|
|
7114
|
+
});
|
|
7115
|
+
}
|
|
7116
|
+
/**
|
|
7117
|
+
* A stored secret, as an admin read shows it: a VIEW naming the row's own
|
|
7118
|
+
* keychain ref (`set: true`), never the value and no longer the bare redaction
|
|
7119
|
+
* token. The form hands it to the secret field, which reveals the value by ref
|
|
7120
|
+
* through the audited `keychain-admin.reveal`; sent back untouched it keeps the
|
|
7121
|
+
* stored secret (the records door reads a view as KEEP).
|
|
7122
|
+
*
|
|
7123
|
+
* ONE implementation for the entries service and for every addon that serves
|
|
7124
|
+
* its own instances (`RecordIntegrationInstances`).
|
|
7125
|
+
*/
|
|
7126
|
+
function isRecord$5(value) {
|
|
7127
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7128
|
+
}
|
|
7129
|
+
function secretViewsOf(owner, kind, id, decl, data) {
|
|
7130
|
+
if (decl.secretPaths.length === 0) return data;
|
|
7131
|
+
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
7132
|
+
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
7133
|
+
return {
|
|
7134
|
+
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
7135
|
+
v: 1,
|
|
7136
|
+
set: true
|
|
7137
|
+
};
|
|
7138
|
+
});
|
|
7139
|
+
return isRecord$5(shown) ? shown : data;
|
|
7140
|
+
}
|
|
7141
|
+
/** The most instances one addon lists (an integrations page, not a table). */
|
|
7142
|
+
var INSTANCES_LIST_MAX = 1e3;
|
|
7143
|
+
/**
|
|
7144
|
+
* The ONE reader of an instance's switch (D996): an absent field means on, so a row written
|
|
7145
|
+
* before the field existed needs no migration. Every consumer of an instance body asks this.
|
|
7146
|
+
*/
|
|
7147
|
+
function isInstanceEnabled(body) {
|
|
7148
|
+
return body.enabled !== false;
|
|
7149
|
+
}
|
|
7150
|
+
/** The body key of the switch; only {@link RecordIntegrationInstances.setInstanceEnabled} writes it. */
|
|
7151
|
+
var SWITCH_KEY = "enabled";
|
|
7152
|
+
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
7153
|
+
function topLevelSecretKeys(paths) {
|
|
7154
|
+
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
7155
|
+
}
|
|
7156
|
+
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
7157
|
+
function secretMapKeys(paths) {
|
|
7158
|
+
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
7159
|
+
}
|
|
7160
|
+
/**
|
|
7161
|
+
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
7162
|
+
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
7163
|
+
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
7164
|
+
*/
|
|
7165
|
+
function secretMapPatch(value) {
|
|
7166
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
7167
|
+
const out = {};
|
|
7168
|
+
for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
|
|
7169
|
+
else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
|
|
7170
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
7171
|
+
}
|
|
7172
|
+
var RecordIntegrationInstances = class {
|
|
7173
|
+
records;
|
|
7174
|
+
kind;
|
|
7175
|
+
hooks;
|
|
7176
|
+
handle;
|
|
7177
|
+
secretKeys;
|
|
7178
|
+
secretMaps;
|
|
7179
|
+
nameField;
|
|
7180
|
+
switchListeners = /* @__PURE__ */ new Set();
|
|
7181
|
+
constructor(records, kind, hooks) {
|
|
7182
|
+
this.records = records;
|
|
7183
|
+
this.kind = kind;
|
|
7184
|
+
this.hooks = hooks;
|
|
7185
|
+
this.handle = records.kind(kind);
|
|
7186
|
+
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
7187
|
+
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
7188
|
+
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
7189
|
+
}
|
|
7190
|
+
/**
|
|
7191
|
+
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
7192
|
+
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
7193
|
+
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
7194
|
+
*/
|
|
7195
|
+
async readResolved(id) {
|
|
7196
|
+
try {
|
|
7197
|
+
const record = await this.handle.getResolved(id);
|
|
7198
|
+
return record === null ? null : {
|
|
7199
|
+
id,
|
|
7200
|
+
body: record.data,
|
|
7201
|
+
enabled: isInstanceEnabled(record.data),
|
|
7202
|
+
secrets: "resolved"
|
|
7203
|
+
};
|
|
7204
|
+
} catch (err) {
|
|
7205
|
+
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
7206
|
+
const stored = await this.handle.get(id);
|
|
7207
|
+
if (stored === null) return null;
|
|
7208
|
+
return {
|
|
7209
|
+
id,
|
|
7210
|
+
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
7211
|
+
enabled: isInstanceEnabled(stored.data),
|
|
7212
|
+
secrets: "unavailable"
|
|
7213
|
+
};
|
|
7214
|
+
}
|
|
7215
|
+
}
|
|
7216
|
+
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
7217
|
+
async getResolved(id) {
|
|
7218
|
+
return (await this.readResolved(id))?.body ?? null;
|
|
7219
|
+
}
|
|
7220
|
+
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
7221
|
+
async listResolved() {
|
|
7222
|
+
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
7223
|
+
const out = [];
|
|
7224
|
+
for (const record of page.records) {
|
|
7225
|
+
const read = await this.readResolved(record.id);
|
|
7226
|
+
if (read !== null) out.push(read);
|
|
7227
|
+
}
|
|
7228
|
+
return out;
|
|
7229
|
+
}
|
|
7230
|
+
viewOf(record) {
|
|
7231
|
+
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
7232
|
+
const rawName = record.data[this.nameField];
|
|
7233
|
+
const kind = this.hooks.kindOf?.(record.data);
|
|
7234
|
+
const health = this.hooks.health?.(record.data, record.id);
|
|
7235
|
+
return {
|
|
7236
|
+
id: record.id,
|
|
7237
|
+
name: typeof rawName === "string" ? rawName : record.id,
|
|
7238
|
+
configured: this.hooks.configured(record.data),
|
|
7239
|
+
enabled: isInstanceEnabled(record.data),
|
|
7240
|
+
formValues: shown,
|
|
7241
|
+
...kind !== void 0 ? { kind } : {},
|
|
7242
|
+
...health?.status !== void 0 ? { status: health.status } : {},
|
|
7243
|
+
...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
|
|
7244
|
+
};
|
|
7245
|
+
}
|
|
7246
|
+
describe = async () => {
|
|
7247
|
+
const declared = linksOfKind(this.kind);
|
|
7248
|
+
const links = this.hooks.description.links !== void 0 || declared.length === 0 ? {} : { links: declared.map((link) => ({
|
|
7249
|
+
kind: this.kind.name,
|
|
7250
|
+
field: link.field,
|
|
7251
|
+
to: link.to
|
|
7252
|
+
})) };
|
|
7253
|
+
return {
|
|
7254
|
+
...this.hooks.description,
|
|
7255
|
+
...links,
|
|
7256
|
+
...this.hooks.mintId === void 0 ? {} : { mintsId: true }
|
|
7257
|
+
};
|
|
7258
|
+
};
|
|
7259
|
+
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
7260
|
+
listInstances = async () => {
|
|
7261
|
+
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
7262
|
+
};
|
|
7263
|
+
getInstance = async ({ id }) => {
|
|
7264
|
+
const record = await this.handle.get(id);
|
|
7265
|
+
return record === null ? null : this.viewOf(record);
|
|
7266
|
+
};
|
|
7267
|
+
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
7268
|
+
createInstance = async ({ id, name, kind, values }) => {
|
|
7269
|
+
const minted = id ?? this.hooks.mintId?.({
|
|
7270
|
+
name,
|
|
7271
|
+
...kind !== void 0 ? { kind } : {}
|
|
7272
|
+
});
|
|
7273
|
+
if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
|
|
7274
|
+
await this.handle.put({
|
|
7275
|
+
id: minted,
|
|
7276
|
+
data: this.hooks.initialBody(name, kind)
|
|
7277
|
+
}, { ifRev: 0 });
|
|
7278
|
+
const patch = this.patchOf(values ?? {});
|
|
7279
|
+
if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
|
|
7280
|
+
await this.hooks.onChanged?.(minted, "created");
|
|
7281
|
+
return { id: minted };
|
|
7282
|
+
};
|
|
7283
|
+
updateInstance = async ({ id, name, values }) => {
|
|
7284
|
+
const patch = this.patchOf(values);
|
|
7285
|
+
if (name !== void 0) patch[this.nameField] = name;
|
|
7286
|
+
await this.handle.patch(id, patch);
|
|
7287
|
+
await this.hooks.onChanged?.(id, "updated");
|
|
7288
|
+
return { ok: true };
|
|
7289
|
+
};
|
|
7290
|
+
/** The record patch a form `values` object means: secrets kept, cleared or replaced. */
|
|
7291
|
+
patchOf(values) {
|
|
7292
|
+
const patch = {};
|
|
7293
|
+
for (const [key, value] of Object.entries(values)) {
|
|
7294
|
+
if (value === void 0) continue;
|
|
7295
|
+
if (key === "enabled") continue;
|
|
7296
|
+
if (this.secretMaps.has(key)) {
|
|
7297
|
+
const entries = secretMapPatch(value);
|
|
7298
|
+
if (entries !== null) patch[key] = entries;
|
|
7299
|
+
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
7300
|
+
else if (isSecretClear(value)) patch[key] = null;
|
|
7301
|
+
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
7302
|
+
}
|
|
7303
|
+
return patch;
|
|
7304
|
+
}
|
|
7305
|
+
/**
|
|
7306
|
+
* Listen to the switch of ANY instance of this helper (in the process that serves it). The
|
|
7307
|
+
* durable replacement of the `integration.enabled` / `integration.disabled` events (D8): the
|
|
7308
|
+
* addon reconciles from the record, whichever way it flipped.
|
|
7309
|
+
*/
|
|
7310
|
+
onSwitched(listener) {
|
|
7311
|
+
this.switchListeners.add(listener);
|
|
7312
|
+
}
|
|
7313
|
+
/**
|
|
7314
|
+
* The ONE writer of the switch (D996, D1014): the record body's `enabled`, for every role. A
|
|
7315
|
+
* configured thing is an instance, so an id with no record yet (a default integration that was
|
|
7316
|
+
* never configured) gets its record from `initialBody` before the switch is written.
|
|
7317
|
+
*/
|
|
7318
|
+
setInstanceEnabled = async ({ id, enabled }) => {
|
|
7319
|
+
if (await this.handle.get(id) === null) await this.handle.put({
|
|
7320
|
+
id,
|
|
7321
|
+
data: this.hooks.initialBody(id)
|
|
7322
|
+
}, { ifRev: 0 });
|
|
7323
|
+
await this.handle.patch(id, { [SWITCH_KEY]: enabled });
|
|
7324
|
+
await this.hooks.onChanged?.(id, "enabled");
|
|
7325
|
+
for (const listener of this.switchListeners) await listener(id, enabled);
|
|
7326
|
+
return { ok: true };
|
|
7327
|
+
};
|
|
7328
|
+
/** The row and its keychain refs go together (the records door). */
|
|
7329
|
+
deleteInstance = async ({ id }) => {
|
|
7330
|
+
await this.handle.delete(id);
|
|
7331
|
+
await this.hooks.onChanged?.(id, "deleted");
|
|
7332
|
+
return { ok: true };
|
|
7333
|
+
};
|
|
7334
|
+
testInstance = async (input) => {
|
|
7335
|
+
if (this.hooks.test === void 0) return {
|
|
7336
|
+
success: false,
|
|
7337
|
+
status: "unsupported",
|
|
7338
|
+
error: "This integration declares no connection test"
|
|
7339
|
+
};
|
|
7340
|
+
return this.hooks.test(input);
|
|
7341
|
+
};
|
|
7342
|
+
/** The flat provider object to hand to `registerProvider`. */
|
|
7343
|
+
toProvider() {
|
|
7344
|
+
return {
|
|
7345
|
+
describe: this.describe,
|
|
7346
|
+
instanceFormSchema: this.instanceFormSchema,
|
|
7347
|
+
listInstances: this.listInstances,
|
|
7348
|
+
getInstance: this.getInstance,
|
|
7349
|
+
createInstance: this.createInstance,
|
|
7350
|
+
updateInstance: this.updateInstance,
|
|
7351
|
+
setInstanceEnabled: this.setInstanceEnabled,
|
|
7352
|
+
deleteInstance: this.deleteInstance,
|
|
7353
|
+
testInstance: this.testInstance
|
|
7354
|
+
};
|
|
7355
|
+
}
|
|
7356
|
+
};
|
|
7357
|
+
/**
|
|
7358
|
+
* The one-switch migration (epic #440, step 3). An integration's on/off state used to live in the
|
|
7359
|
+
* registry's `enabled` column for a device addon; it now lives only in the instance record's
|
|
7360
|
+
* body (`enabled`, D1007 superseded). This moves a registry `enabled = false` into the body, once.
|
|
7361
|
+
*
|
|
7362
|
+
* For every registry row of the addon that is OFF:
|
|
7363
|
+
* - no record under its id: the record is created from `initialBody(name)` with `enabled: false`
|
|
7364
|
+
* (a default integration that never had settings, Reolink's among them);
|
|
7365
|
+
* - a record whose body states no `enabled`: `enabled: false` is written into it;
|
|
7366
|
+
* - a record that already states `enabled` (either way) is the newer truth and is left alone.
|
|
7367
|
+
* A row that is ON writes nothing: an absent field reads as on. A rerun finds every off row with
|
|
7368
|
+
* a stated switch and does nothing, so nothing switched off comes back on and nothing switched on
|
|
7369
|
+
* goes off. The registry column itself is neither read afterwards nor written; its drop is step 5.
|
|
7370
|
+
*
|
|
7371
|
+
* It runs in the addon process, BEFORE the addon registers its `integration-instances` provider,
|
|
7372
|
+
* which is also why `integrations.list` still answers the stored column at that point.
|
|
7373
|
+
*/
|
|
7374
|
+
function registrySwitchToBodyId(addonId, date) {
|
|
7375
|
+
return `${addonId}/${date}-registry-switch-to-body`;
|
|
7376
|
+
}
|
|
7377
|
+
async function moveRegistrySwitchToBody(ports, spec) {
|
|
7378
|
+
const rows = await ports.listIntegrations(spec.addonId);
|
|
7379
|
+
let created = 0;
|
|
7380
|
+
let switched = 0;
|
|
7381
|
+
let kept = 0;
|
|
7382
|
+
for (const row of rows) {
|
|
7383
|
+
if (row.enabled) continue;
|
|
7384
|
+
const body = await ports.readBody(row.id);
|
|
7385
|
+
if (body === null) {
|
|
7386
|
+
if (await ports.createRecord(row.id, {
|
|
7387
|
+
...spec.initialBody(row.name),
|
|
7388
|
+
["enabled"]: false
|
|
7389
|
+
}) === "created") created += 1;
|
|
7390
|
+
else kept += 1;
|
|
7391
|
+
continue;
|
|
7392
|
+
}
|
|
7393
|
+
if ("enabled" in body) {
|
|
7394
|
+
kept += 1;
|
|
7395
|
+
continue;
|
|
7396
|
+
}
|
|
7397
|
+
await ports.switchOff(row.id);
|
|
7398
|
+
switched += 1;
|
|
7399
|
+
}
|
|
7400
|
+
const summary = {
|
|
7401
|
+
integrations: rows.length,
|
|
7402
|
+
off: rows.filter((r) => !r.enabled).length,
|
|
7403
|
+
created,
|
|
7404
|
+
switched,
|
|
7405
|
+
kept
|
|
7406
|
+
};
|
|
7407
|
+
return created === 0 && switched === 0 ? {
|
|
7408
|
+
outcome: "already-done",
|
|
7409
|
+
summary
|
|
7410
|
+
} : {
|
|
7411
|
+
outcome: "done",
|
|
7412
|
+
summary
|
|
7413
|
+
};
|
|
7414
|
+
}
|
|
7415
|
+
/** A migration entry: an addon states its kind and how a new body starts, nothing else. */
|
|
7416
|
+
function registrySwitchToBodyMigration(spec) {
|
|
7417
|
+
return {
|
|
7418
|
+
meta: {
|
|
7419
|
+
id: registrySwitchToBodyId(spec.addonId, spec.date),
|
|
7420
|
+
owner: spec.addonId,
|
|
7421
|
+
level: "addon-state",
|
|
7422
|
+
seq: spec.seq,
|
|
7423
|
+
dependsOn: [],
|
|
7424
|
+
store: "settings",
|
|
7425
|
+
scope: "cluster",
|
|
7426
|
+
onFailure: "block-owner",
|
|
7427
|
+
bodyKind: "procedure",
|
|
7428
|
+
description: "Move the registry enabled flag of every switched-off integration into its instance record body, creating the record when there is none",
|
|
7429
|
+
fixtureMark: "enabled"
|
|
7430
|
+
},
|
|
7431
|
+
procedure: (ports) => moveRegistrySwitchToBody(ports, {
|
|
7432
|
+
addonId: spec.addonId,
|
|
7433
|
+
initialBody: spec.initialBody
|
|
7434
|
+
})
|
|
7435
|
+
};
|
|
7436
|
+
}
|
|
7437
|
+
/** The hub and records sides of {@link registrySwitchToBodyMigration}. */
|
|
7438
|
+
function registrySwitchPortsOver(deps) {
|
|
7439
|
+
const handle = deps.records.kind({
|
|
7440
|
+
name: deps.kind.name,
|
|
7441
|
+
declaration: deps.kind.declaration,
|
|
7442
|
+
schema: record(string(), unknown())
|
|
7443
|
+
});
|
|
7444
|
+
return {
|
|
7445
|
+
listIntegrations: async (addonId) => (await deps.api.list()).filter((i) => i.addonId === addonId).map((i) => ({
|
|
7446
|
+
id: i.id,
|
|
7447
|
+
name: i.name,
|
|
7448
|
+
enabled: i.enabled !== false
|
|
7449
|
+
})),
|
|
7450
|
+
readBody: async (id) => (await handle.get(id))?.data ?? null,
|
|
7451
|
+
createRecord: async (id, body) => {
|
|
7452
|
+
if (await handle.get(id) !== null) return "exists";
|
|
7453
|
+
await handle.put({
|
|
7454
|
+
id,
|
|
7455
|
+
data: body
|
|
7456
|
+
}, { ifRev: 0 });
|
|
7457
|
+
return "created";
|
|
7458
|
+
},
|
|
7459
|
+
switchOff: async (id) => {
|
|
7460
|
+
await handle.patch(id, { [SWITCH_KEY]: false });
|
|
7461
|
+
}
|
|
7462
|
+
};
|
|
7463
|
+
}
|
|
6668
7464
|
/**
|
|
6669
7465
|
* Build a {@link DurableState} over a single store key. Transport-agnostic:
|
|
6670
7466
|
* `read`/`write` are the addon-store or device-store accessors. The whole
|
|
@@ -6796,140 +7592,6 @@ var SCOPED_SETTINGS_SCOPES = [
|
|
|
6796
7592
|
"device-defaults",
|
|
6797
7593
|
"node"
|
|
6798
7594
|
];
|
|
6799
|
-
/**
|
|
6800
|
-
* The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
|
|
6801
|
-
*
|
|
6802
|
-
* A ref is DETERMINISTIC from where the value lives — the owner addon, the
|
|
6803
|
-
* scope (global, one node, one device, one integration, one row of a business
|
|
6804
|
-
* collection) and the field path inside that scope — so saving the same field
|
|
6805
|
-
* twice updates the same ref, and the ref itself says which settings blob
|
|
6806
|
-
* points at it. It is also the AAD of the value's ciphertext: a ciphertext
|
|
6807
|
-
* copied onto another ref does not decrypt.
|
|
6808
|
-
*
|
|
6809
|
-
* Array items are addressed by ITEM ID, never by index
|
|
6810
|
-
* (`providers[authentik].clientSecret`), so reordering a list keeps every ref.
|
|
6811
|
-
*
|
|
6812
|
-
* Pure and browser-safe: no node builtins, no I/O.
|
|
6813
|
-
*/
|
|
6814
|
-
/** The URI scheme of every keychain ref. */
|
|
6815
|
-
var SECRET_REF_SCHEME = "secret://";
|
|
6816
|
-
var GLOBAL_SCOPE = { kind: "global" };
|
|
6817
|
-
/** The scope every addon-wide (not per-node, not per-device) setting lives in. */
|
|
6818
|
-
function globalSecretScope() {
|
|
6819
|
-
return GLOBAL_SCOPE;
|
|
6820
|
-
}
|
|
6821
|
-
/**
|
|
6822
|
-
* An addon id as a ref owner. A hub in-process builtin's context id is
|
|
6823
|
-
* `addon:<id>`; the owner of its secrets is `<id>`, exactly as for the same
|
|
6824
|
-
* addon running forked.
|
|
6825
|
-
*/
|
|
6826
|
-
function normalizeSecretOwner(addonId) {
|
|
6827
|
-
return addonId.startsWith("addon:") ? addonId.slice(6) : addonId;
|
|
6828
|
-
}
|
|
6829
|
-
function encodeSegment(value) {
|
|
6830
|
-
return encodeURIComponent(value);
|
|
6831
|
-
}
|
|
6832
|
-
function decodeSegment(value) {
|
|
6833
|
-
try {
|
|
6834
|
-
return decodeURIComponent(value);
|
|
6835
|
-
} catch {
|
|
6836
|
-
return null;
|
|
6837
|
-
}
|
|
6838
|
-
}
|
|
6839
|
-
/** The scope as it appears inside a ref (`global`, `node/<id>`, …). */
|
|
6840
|
-
function formatSecretScope(scope) {
|
|
6841
|
-
switch (scope.kind) {
|
|
6842
|
-
case "global": return "global";
|
|
6843
|
-
case "node": return `node/${encodeSegment(scope.nodeId)}`;
|
|
6844
|
-
case "device": return `device/${scope.deviceId}`;
|
|
6845
|
-
case "integration": return `integration/${encodeSegment(scope.integrationId)}`;
|
|
6846
|
-
case "row": return `row/${encodeSegment(scope.collection)}/${encodeSegment(scope.rowId)}`;
|
|
6847
|
-
}
|
|
6848
|
-
}
|
|
6849
|
-
/**
|
|
6850
|
-
* The field path of a value inside an array item, addressed by the item's id:
|
|
6851
|
-
* `arrayItemFieldPath('providers', 'authentik', 'clientSecret')` →
|
|
6852
|
-
* `providers[authentik].clientSecret`.
|
|
6853
|
-
*/
|
|
6854
|
-
function arrayItemFieldPath(arrayKey, itemId, fieldKey) {
|
|
6855
|
-
return `${arrayKey}[${encodeSegment(itemId)}].${fieldKey}`;
|
|
6856
|
-
}
|
|
6857
|
-
/** Build a ref. Throws on an empty owner or field path — both are bugs. */
|
|
6858
|
-
function buildSecretRef(parts) {
|
|
6859
|
-
const owner = normalizeSecretOwner(parts.owner);
|
|
6860
|
-
if (owner.length === 0) throw new Error("buildSecretRef: owner is empty");
|
|
6861
|
-
if (parts.fieldPath.length === 0) throw new Error("buildSecretRef: fieldPath is empty");
|
|
6862
|
-
return `${SECRET_REF_SCHEME}${encodeSegment(owner)}/${formatSecretScope(parts.scope)}/${parts.fieldPath}`;
|
|
6863
|
-
}
|
|
6864
|
-
function parseScope(segments) {
|
|
6865
|
-
switch (segments[0]) {
|
|
6866
|
-
case "global": return {
|
|
6867
|
-
scope: GLOBAL_SCOPE,
|
|
6868
|
-
used: 1
|
|
6869
|
-
};
|
|
6870
|
-
case "node": {
|
|
6871
|
-
const nodeId = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
|
|
6872
|
-
return nodeId === null || nodeId.length === 0 ? null : {
|
|
6873
|
-
scope: {
|
|
6874
|
-
kind: "node",
|
|
6875
|
-
nodeId
|
|
6876
|
-
},
|
|
6877
|
-
used: 2
|
|
6878
|
-
};
|
|
6879
|
-
}
|
|
6880
|
-
case "device": {
|
|
6881
|
-
const raw = segments[1];
|
|
6882
|
-
if (raw === void 0 || !/^\d+$/.test(raw)) return null;
|
|
6883
|
-
return {
|
|
6884
|
-
scope: {
|
|
6885
|
-
kind: "device",
|
|
6886
|
-
deviceId: Number(raw)
|
|
6887
|
-
},
|
|
6888
|
-
used: 2
|
|
6889
|
-
};
|
|
6890
|
-
}
|
|
6891
|
-
case "integration": {
|
|
6892
|
-
const id = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
|
|
6893
|
-
return id === null || id.length === 0 ? null : {
|
|
6894
|
-
scope: {
|
|
6895
|
-
kind: "integration",
|
|
6896
|
-
integrationId: id
|
|
6897
|
-
},
|
|
6898
|
-
used: 2
|
|
6899
|
-
};
|
|
6900
|
-
}
|
|
6901
|
-
case "row": {
|
|
6902
|
-
const collection = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
|
|
6903
|
-
const rowId = segments[2] !== void 0 ? decodeSegment(segments[2]) : null;
|
|
6904
|
-
if (collection === null || rowId === null || collection.length === 0 || rowId.length === 0) return null;
|
|
6905
|
-
return {
|
|
6906
|
-
scope: {
|
|
6907
|
-
kind: "row",
|
|
6908
|
-
collection,
|
|
6909
|
-
rowId
|
|
6910
|
-
},
|
|
6911
|
-
used: 3
|
|
6912
|
-
};
|
|
6913
|
-
}
|
|
6914
|
-
default: return null;
|
|
6915
|
-
}
|
|
6916
|
-
}
|
|
6917
|
-
/** Take a ref apart; `null` when it is not a well-formed ref. */
|
|
6918
|
-
function parseSecretRef(ref) {
|
|
6919
|
-
if (!ref.startsWith("secret://")) return null;
|
|
6920
|
-
const segments = ref.slice(9).split("/");
|
|
6921
|
-
const owner = segments[0] !== void 0 ? decodeSegment(segments[0]) : null;
|
|
6922
|
-
if (owner === null || owner.length === 0) return null;
|
|
6923
|
-
const parsed = parseScope(segments.slice(1));
|
|
6924
|
-
if (parsed === null) return null;
|
|
6925
|
-
const fieldPath = segments.slice(1 + parsed.used).join("/");
|
|
6926
|
-
if (fieldPath.length === 0) return null;
|
|
6927
|
-
return {
|
|
6928
|
-
owner,
|
|
6929
|
-
scope: parsed.scope,
|
|
6930
|
-
fieldPath
|
|
6931
|
-
};
|
|
6932
|
-
}
|
|
6933
7595
|
/** A write to a secret path could not be stored in the keychain, so it was refused. */
|
|
6934
7596
|
var KeychainWriteRefusedError = class extends Error {
|
|
6935
7597
|
fieldPath;
|
|
@@ -6940,7 +7602,7 @@ var KeychainWriteRefusedError = class extends Error {
|
|
|
6940
7602
|
}
|
|
6941
7603
|
};
|
|
6942
7604
|
var KEEP = { kind: "keep" };
|
|
6943
|
-
function isRecord$
|
|
7605
|
+
function isRecord$4(value) {
|
|
6944
7606
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6945
7607
|
}
|
|
6946
7608
|
function defaultMintId() {
|
|
@@ -6953,7 +7615,7 @@ function collectSecretMarkerRefs(value, out = []) {
|
|
|
6953
7615
|
return out;
|
|
6954
7616
|
}
|
|
6955
7617
|
if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
|
|
6956
|
-
else if (isRecord$
|
|
7618
|
+
else if (isRecord$4(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
|
|
6957
7619
|
return out;
|
|
6958
7620
|
}
|
|
6959
7621
|
async function storedValueEquals(secrets, marker, candidate) {
|
|
@@ -7008,7 +7670,7 @@ function rowId(row, idKey) {
|
|
|
7008
7670
|
return null;
|
|
7009
7671
|
}
|
|
7010
7672
|
async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
7011
|
-
const storedRows = Array.isArray(stored) ? stored.filter(isRecord$
|
|
7673
|
+
const storedRows = Array.isArray(stored) ? stored.filter(isRecord$4) : [];
|
|
7012
7674
|
if (!Array.isArray(incoming)) {
|
|
7013
7675
|
ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
|
|
7014
7676
|
return {
|
|
@@ -7024,7 +7686,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
7024
7686
|
const kept = /* @__PURE__ */ new Set();
|
|
7025
7687
|
const rows = [];
|
|
7026
7688
|
for (const row of incoming) {
|
|
7027
|
-
if (!isRecord$
|
|
7689
|
+
if (!isRecord$4(row)) {
|
|
7028
7690
|
rows.push(row);
|
|
7029
7691
|
continue;
|
|
7030
7692
|
}
|
|
@@ -7049,7 +7711,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
|
|
|
7049
7711
|
case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
|
|
7050
7712
|
case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
|
|
7051
7713
|
case "object": {
|
|
7052
|
-
if (!isRecord$
|
|
7714
|
+
if (!isRecord$4(incoming)) {
|
|
7053
7715
|
if (incoming === void 0) return KEEP;
|
|
7054
7716
|
ctx.deletes.push(...collectSecretMarkerRefs(stored));
|
|
7055
7717
|
return {
|
|
@@ -7057,7 +7719,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
|
|
|
7057
7719
|
value: incoming
|
|
7058
7720
|
};
|
|
7059
7721
|
}
|
|
7060
|
-
const storedObj = isRecord$
|
|
7722
|
+
const storedObj = isRecord$4(stored) ? stored : {};
|
|
7061
7723
|
return {
|
|
7062
7724
|
kind: "value",
|
|
7063
7725
|
value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
|
|
@@ -7180,7 +7842,7 @@ async function resolveSecretMarkers(value, secrets, options = {}) {
|
|
|
7180
7842
|
value: items
|
|
7181
7843
|
};
|
|
7182
7844
|
}
|
|
7183
|
-
if (isRecord$
|
|
7845
|
+
if (isRecord$4(v)) {
|
|
7184
7846
|
const out = {};
|
|
7185
7847
|
for (const [k, child] of Object.entries(v)) {
|
|
7186
7848
|
const s = substitute(child);
|
|
@@ -7212,7 +7874,7 @@ var SecretOverwriteRefusedError = class extends Error {
|
|
|
7212
7874
|
this.name = "SecretOverwriteRefusedError";
|
|
7213
7875
|
}
|
|
7214
7876
|
};
|
|
7215
|
-
function isRecord$
|
|
7877
|
+
function isRecord$3(value) {
|
|
7216
7878
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7217
7879
|
}
|
|
7218
7880
|
function resolvedValue(pass, marker) {
|
|
@@ -7241,7 +7903,7 @@ function inArray(pass, incoming, stored) {
|
|
|
7241
7903
|
return incoming.map((item, index) => {
|
|
7242
7904
|
const twin = stored[index];
|
|
7243
7905
|
if (isSecretMarker(twin)) return typeof item === "string" && item === resolvedValue(pass, twin) ? twin : item;
|
|
7244
|
-
if (isRecord$
|
|
7906
|
+
if (isRecord$3(item) && isRecord$3(twin)) return inArrayRow(pass, item, twin);
|
|
7245
7907
|
if (Array.isArray(item) && Array.isArray(twin)) return inArray(pass, item, twin);
|
|
7246
7908
|
return item;
|
|
7247
7909
|
});
|
|
@@ -7252,7 +7914,7 @@ function inArrayRow(pass, incoming, stored) {
|
|
|
7252
7914
|
const twin = stored[key];
|
|
7253
7915
|
if (isSecretMarker(twin)) {
|
|
7254
7916
|
if (typeof value === "string" && value === resolvedValue(pass, twin)) out[key] = twin;
|
|
7255
|
-
} else if (isRecord$
|
|
7917
|
+
} else if (isRecord$3(value) && isRecord$3(twin)) out[key] = inArrayRow(pass, value, twin);
|
|
7256
7918
|
else if (Array.isArray(value) && Array.isArray(twin)) out[key] = inArray(pass, value, twin);
|
|
7257
7919
|
}
|
|
7258
7920
|
return out;
|
|
@@ -7260,7 +7922,7 @@ function inArrayRow(pass, incoming, stored) {
|
|
|
7260
7922
|
async function walk(pass, incoming, stored) {
|
|
7261
7923
|
if (isSecretMarker(stored)) return atMarker(pass, incoming, stored);
|
|
7262
7924
|
if (Array.isArray(incoming) && Array.isArray(stored)) return inArray(pass, incoming, stored);
|
|
7263
|
-
if (!isRecord$
|
|
7925
|
+
if (!isRecord$3(incoming) || !isRecord$3(stored)) return incoming;
|
|
7264
7926
|
const out = { ...incoming };
|
|
7265
7927
|
for (const [key, value] of Object.entries(incoming)) out[key] = await walk(pass, value, stored[key]);
|
|
7266
7928
|
return out;
|
|
@@ -7291,7 +7953,7 @@ async function restoreUnchangedSecrets(input) {
|
|
|
7291
7953
|
function isJsonEqual(a, b) {
|
|
7292
7954
|
if (Object.is(a, b)) return true;
|
|
7293
7955
|
if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((v, i) => isJsonEqual(v, b[i]));
|
|
7294
|
-
if (isRecord$
|
|
7956
|
+
if (isRecord$3(a) && isRecord$3(b)) {
|
|
7295
7957
|
const keys = Object.keys(a);
|
|
7296
7958
|
if (keys.length !== Object.keys(b).length) return false;
|
|
7297
7959
|
return keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && isJsonEqual(a[k], b[k]));
|
|
@@ -7315,7 +7977,7 @@ function markerKeysOf(blob, owner) {
|
|
|
7315
7977
|
}
|
|
7316
7978
|
function nodeFromStored(value, owner) {
|
|
7317
7979
|
if (isSecretMarker(value)) return isSecretRefOwnedBy(value.$secret, owner) ? { kind: "leaf" } : null;
|
|
7318
|
-
if (!isRecord$
|
|
7980
|
+
if (!isRecord$3(value)) return null;
|
|
7319
7981
|
const children = /* @__PURE__ */ new Map();
|
|
7320
7982
|
for (const [key, child] of Object.entries(value)) {
|
|
7321
7983
|
const node = nodeFromStored(child, owner);
|
|
@@ -7812,13 +8474,48 @@ var BaseAddon = class {
|
|
|
7812
8474
|
if (api === void 0) throw new Error(`${this.ctx.id}: the migration API is not available on this context`);
|
|
7813
8475
|
return this.runBound(sets.flatMap((set) => set.bind(api)), options);
|
|
7814
8476
|
}
|
|
7815
|
-
|
|
8477
|
+
/**
|
|
8478
|
+
* A device addon states its instance kind once, before its migrations run, and the one-switch
|
|
8479
|
+
* migration (registry `enabled` to the instance body, epic #440 step 3) joins whatever
|
|
8480
|
+
* catalogue the addon runs, in the SAME declaration (the engine replaces an owner's catalogue
|
|
8481
|
+
* on every declare).
|
|
8482
|
+
*/
|
|
8483
|
+
declareRegistrySwitch(spec) {
|
|
8484
|
+
this.registrySwitchSpec = spec;
|
|
8485
|
+
}
|
|
8486
|
+
registrySwitchSpec = null;
|
|
8487
|
+
registrySwitchBound() {
|
|
8488
|
+
const spec = this.registrySwitchSpec;
|
|
8489
|
+
if (spec === null) return [];
|
|
8490
|
+
const api = this.ctx.migrationApi;
|
|
8491
|
+
if (api === void 0) {
|
|
8492
|
+
this.ctx.logger.warn("the registry switch migration is skipped: the migration API is not available on this context");
|
|
8493
|
+
return [];
|
|
8494
|
+
}
|
|
8495
|
+
return migrationSet([registrySwitchToBodyMigration({
|
|
8496
|
+
addonId: this.ctx.id,
|
|
8497
|
+
date: "2026-11-06",
|
|
8498
|
+
seq: 1e3,
|
|
8499
|
+
initialBody: spec.initialBody
|
|
8500
|
+
})], (a) => registrySwitchPortsOver({
|
|
8501
|
+
api: integrationRowsApiOver(a),
|
|
8502
|
+
records: switchRecordsOverMigrationApi(a),
|
|
8503
|
+
kind: spec.kind
|
|
8504
|
+
})).bind(api);
|
|
8505
|
+
}
|
|
8506
|
+
async runBound(declared, options) {
|
|
8507
|
+
const added = this.registrySwitchBound();
|
|
8508
|
+
const migrations = [...declared, ...added];
|
|
8509
|
+
const phased = options?.only === void 0 || added.length === 0 ? options : {
|
|
8510
|
+
...options,
|
|
8511
|
+
only: [...options.only, ...added.map((m) => m.meta.id)]
|
|
8512
|
+
};
|
|
7816
8513
|
const api = this.ctx.api.migrations;
|
|
7817
8514
|
const report = await runAddonMigrations({
|
|
7818
8515
|
declareOwner: (input) => api.declareOwner.mutate(input),
|
|
7819
8516
|
startMigration: (input) => api.startMigration.mutate(input),
|
|
7820
8517
|
finishMigration: (input) => api.finishMigration.mutate(input)
|
|
7821
|
-
}, migrations, this.ctx.logger,
|
|
8518
|
+
}, migrations, this.ctx.logger, phased);
|
|
7822
8519
|
if (report.blockOwner.length > 0) throw new AddonMigrationsBlockedError(report.blockOwner);
|
|
7823
8520
|
return report;
|
|
7824
8521
|
}
|
|
@@ -8891,237 +9588,6 @@ function normalizeAddonInitResult(result) {
|
|
|
8891
9588
|
if (Array.isArray(result)) return { providers: result };
|
|
8892
9589
|
return result;
|
|
8893
9590
|
}
|
|
8894
|
-
var PREFIX = "records/";
|
|
8895
|
-
/** The base of every records failure. `detail` is the human part of the message. */
|
|
8896
|
-
var RecordsError = class extends Error {
|
|
8897
|
-
code;
|
|
8898
|
-
detail;
|
|
8899
|
-
constructor(code, detail) {
|
|
8900
|
-
super(`${PREFIX}${code}: ${detail}`);
|
|
8901
|
-
this.name = "RecordsError";
|
|
8902
|
-
this.code = code;
|
|
8903
|
-
this.detail = detail;
|
|
8904
|
-
}
|
|
8905
|
-
};
|
|
8906
|
-
/** A write guarded by `ifRev` found another revision (or an existing row for `ifRev: 0`). */
|
|
8907
|
-
var RevConflictError = class extends RecordsError {
|
|
8908
|
-
constructor(detail) {
|
|
8909
|
-
super("rev-conflict", detail);
|
|
8910
|
-
this.name = "RevConflictError";
|
|
8911
|
-
}
|
|
8912
|
-
};
|
|
8913
|
-
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
8914
|
-
var RecordSecretUnavailableError = class extends RecordsError {
|
|
8915
|
-
constructor(detail) {
|
|
8916
|
-
super("secret-unavailable", detail);
|
|
8917
|
-
this.name = "RecordSecretUnavailableError";
|
|
8918
|
-
}
|
|
8919
|
-
};
|
|
8920
|
-
var InvalidRecordError = class extends RecordsError {
|
|
8921
|
-
constructor(detail) {
|
|
8922
|
-
super("invalid-record", detail);
|
|
8923
|
-
this.name = "InvalidRecordError";
|
|
8924
|
-
}
|
|
8925
|
-
};
|
|
8926
|
-
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
8927
|
-
var DeclarationRefusedError = class extends RecordsError {
|
|
8928
|
-
constructor(detail) {
|
|
8929
|
-
super("declaration-refused", detail);
|
|
8930
|
-
this.name = "DeclarationRefusedError";
|
|
8931
|
-
}
|
|
8932
|
-
};
|
|
8933
|
-
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
8934
|
-
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
8935
|
-
var RECORD_DATABASES = ["settings", "events"];
|
|
8936
|
-
/** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
|
|
8937
|
-
var RECORD_CLASSES = [
|
|
8938
|
-
"config",
|
|
8939
|
-
"ledger",
|
|
8940
|
-
"audit",
|
|
8941
|
-
"mirror",
|
|
8942
|
-
"ephemeral"
|
|
8943
|
-
];
|
|
8944
|
-
var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
8945
|
-
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
8946
|
-
var RECORD_BATCH_MAX = 1e3;
|
|
8947
|
-
var RECORD_QUERY_MAX = 1e3;
|
|
8948
|
-
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
8949
|
-
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
8950
|
-
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
8951
|
-
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
8952
|
-
/**
|
|
8953
|
-
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
8954
|
-
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
8955
|
-
* (`auth.accessToken`, `headers[].value`).
|
|
8956
|
-
*
|
|
8957
|
-
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
8958
|
-
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
8959
|
-
* key releases exactly that key's secret.
|
|
8960
|
-
*
|
|
8961
|
-
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
8962
|
-
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
8963
|
-
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
8964
|
-
* leaf names its element: `headers[X-Api].value`.
|
|
8965
|
-
*
|
|
8966
|
-
* Pure and browser-safe. Nothing here mutates: every transform returns a new value.
|
|
8967
|
-
*/
|
|
8968
|
-
/** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
|
|
8969
|
-
function parseSecretPath(path) {
|
|
8970
|
-
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
8971
|
-
return path.split(".").map((raw) => {
|
|
8972
|
-
const each = raw.endsWith("[]");
|
|
8973
|
-
const map = raw.endsWith("{}");
|
|
8974
|
-
const key = each || map ? raw.slice(0, -2) : raw;
|
|
8975
|
-
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
8976
|
-
return {
|
|
8977
|
-
key,
|
|
8978
|
-
each,
|
|
8979
|
-
map
|
|
8980
|
-
};
|
|
8981
|
-
});
|
|
8982
|
-
}
|
|
8983
|
-
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
8984
|
-
function secretArrayPrefixes(path) {
|
|
8985
|
-
const segments = parseSecretPath(path);
|
|
8986
|
-
const prefixes = [];
|
|
8987
|
-
const walked = [];
|
|
8988
|
-
for (const segment of segments) {
|
|
8989
|
-
walked.push(segment.key);
|
|
8990
|
-
if (segment.each) prefixes.push(walked.join("."));
|
|
8991
|
-
}
|
|
8992
|
-
return prefixes;
|
|
8993
|
-
}
|
|
8994
|
-
function isRecord$4(value) {
|
|
8995
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8996
|
-
}
|
|
8997
|
-
function elementId(element, idKey, declared, prefix) {
|
|
8998
|
-
const id = isRecord$4(element) ? element[idKey] : void 0;
|
|
8999
|
-
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`);
|
|
9000
|
-
return id;
|
|
9001
|
-
}
|
|
9002
|
-
/**
|
|
9003
|
-
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
9004
|
-
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
9005
|
-
* result is a new body, `data` is untouched.
|
|
9006
|
-
*/
|
|
9007
|
-
var REMOVE_LEAF = Symbol("remove-leaf");
|
|
9008
|
-
function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
|
|
9009
|
-
if (!isRecord$4(node)) return node;
|
|
9010
|
-
const segment = segments[index];
|
|
9011
|
-
if (segment === void 0) return node;
|
|
9012
|
-
if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
|
|
9013
|
-
const child = node[segment.key];
|
|
9014
|
-
const keys = [...walkedKeys, segment.key];
|
|
9015
|
-
const last = index === segments.length - 1;
|
|
9016
|
-
if (segment.each) {
|
|
9017
|
-
if (!Array.isArray(child)) return node;
|
|
9018
|
-
const prefix = keys.join(".");
|
|
9019
|
-
const idKey = arrayKeys[prefix];
|
|
9020
|
-
if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
|
|
9021
|
-
const mapped = child.map((element) => {
|
|
9022
|
-
const id = elementId(element, idKey, declared, prefix);
|
|
9023
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
|
|
9024
|
-
return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
|
|
9025
|
-
});
|
|
9026
|
-
return {
|
|
9027
|
-
...node,
|
|
9028
|
-
[segment.key]: mapped
|
|
9029
|
-
};
|
|
9030
|
-
}
|
|
9031
|
-
if (segment.map) {
|
|
9032
|
-
if (!isRecord$4(child)) return node;
|
|
9033
|
-
const kept = Object.entries(child).map(([mapKey, value]) => {
|
|
9034
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
|
|
9035
|
-
if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
|
|
9036
|
-
return [mapKey, visit({
|
|
9037
|
-
declared,
|
|
9038
|
-
concrete,
|
|
9039
|
-
value
|
|
9040
|
-
})];
|
|
9041
|
-
}).filter(([, value]) => value !== REMOVE_LEAF);
|
|
9042
|
-
return {
|
|
9043
|
-
...node,
|
|
9044
|
-
[segment.key]: Object.fromEntries(kept)
|
|
9045
|
-
};
|
|
9046
|
-
}
|
|
9047
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
9048
|
-
if (last) {
|
|
9049
|
-
const replacement = visit({
|
|
9050
|
-
declared,
|
|
9051
|
-
concrete,
|
|
9052
|
-
value: child
|
|
9053
|
-
});
|
|
9054
|
-
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
9055
|
-
return {
|
|
9056
|
-
...node,
|
|
9057
|
-
[segment.key]: replacement
|
|
9058
|
-
};
|
|
9059
|
-
}
|
|
9060
|
-
return {
|
|
9061
|
-
...node,
|
|
9062
|
-
[segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
|
|
9063
|
-
};
|
|
9064
|
-
}
|
|
9065
|
-
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
9066
|
-
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
9067
|
-
let current = data;
|
|
9068
|
-
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
9069
|
-
return current;
|
|
9070
|
-
}
|
|
9071
|
-
/** Every present secret leaf, read-only. */
|
|
9072
|
-
function collectSecretLeaves(data, paths, arrayKeys) {
|
|
9073
|
-
const found = [];
|
|
9074
|
-
mapSecretLeaves(data, paths, arrayKeys, (leaf) => {
|
|
9075
|
-
found.push(leaf);
|
|
9076
|
-
return leaf.value;
|
|
9077
|
-
});
|
|
9078
|
-
return found;
|
|
9079
|
-
}
|
|
9080
|
-
/**
|
|
9081
|
-
* The keychain collection name a kind's secrets live under. Prefixed so a
|
|
9082
|
-
* record's refs never collide with the refs a legacy collection of the same name
|
|
9083
|
-
* already holds during an adoption.
|
|
9084
|
-
*/
|
|
9085
|
-
function recordSecretCollection(kind) {
|
|
9086
|
-
return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
|
|
9087
|
-
}
|
|
9088
|
-
/** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
|
|
9089
|
-
function recordSecretRef(owner, kind, rowId, concretePath) {
|
|
9090
|
-
return buildSecretRef({
|
|
9091
|
-
owner,
|
|
9092
|
-
scope: {
|
|
9093
|
-
kind: "row",
|
|
9094
|
-
collection: recordSecretCollection(kind),
|
|
9095
|
-
rowId
|
|
9096
|
-
},
|
|
9097
|
-
fieldPath: concretePath
|
|
9098
|
-
});
|
|
9099
|
-
}
|
|
9100
|
-
/**
|
|
9101
|
-
* A stored secret, as an admin read shows it: a VIEW naming the row's own
|
|
9102
|
-
* keychain ref (`set: true`), never the value and no longer the bare redaction
|
|
9103
|
-
* token. The form hands it to the secret field, which reveals the value by ref
|
|
9104
|
-
* through the audited `keychain-admin.reveal`; sent back untouched it keeps the
|
|
9105
|
-
* stored secret (the records door reads a view as KEEP).
|
|
9106
|
-
*
|
|
9107
|
-
* ONE implementation for the entries service and for every addon that serves
|
|
9108
|
-
* its own instances (`RecordIntegrationInstances`).
|
|
9109
|
-
*/
|
|
9110
|
-
function isRecord$3(value) {
|
|
9111
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9112
|
-
}
|
|
9113
|
-
function secretViewsOf(owner, kind, id, decl, data) {
|
|
9114
|
-
if (decl.secretPaths.length === 0) return data;
|
|
9115
|
-
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
9116
|
-
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
9117
|
-
return {
|
|
9118
|
-
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
9119
|
-
v: 1,
|
|
9120
|
-
set: true
|
|
9121
|
-
};
|
|
9122
|
-
});
|
|
9123
|
-
return isRecord$3(shown) ? shown : data;
|
|
9124
|
-
}
|
|
9125
9591
|
/**
|
|
9126
9592
|
* The share-view scope kinds a share-link token can carry. The hub mints
|
|
9127
9593
|
* and validates them (`ShareViewGrantSchema` builds its
|
|
@@ -9375,6 +9841,7 @@ function defineRecordKinds(specs) {
|
|
|
9375
9841
|
function entryBody(shape) {
|
|
9376
9842
|
return object({
|
|
9377
9843
|
name: string().min(1),
|
|
9844
|
+
enabled: boolean().optional(),
|
|
9378
9845
|
...shape
|
|
9379
9846
|
});
|
|
9380
9847
|
}
|
|
@@ -11240,6 +11707,10 @@ Object.freeze({
|
|
|
11240
11707
|
"all",
|
|
11241
11708
|
"one"
|
|
11242
11709
|
]
|
|
11710
|
+
},
|
|
11711
|
+
{
|
|
11712
|
+
"path": "positionUpdatedAt",
|
|
11713
|
+
"valueType": "number"
|
|
11243
11714
|
}
|
|
11244
11715
|
],
|
|
11245
11716
|
"meter": [{
|
|
@@ -11494,22 +11965,6 @@ Object.freeze({
|
|
|
11494
11965
|
"path": "pumpRunning",
|
|
11495
11966
|
"valueType": "boolean"
|
|
11496
11967
|
},
|
|
11497
|
-
{
|
|
11498
|
-
"path": "lastDrink",
|
|
11499
|
-
"valueType": "number"
|
|
11500
|
-
},
|
|
11501
|
-
{
|
|
11502
|
-
"path": "currentHourDrink",
|
|
11503
|
-
"valueType": "number"
|
|
11504
|
-
},
|
|
11505
|
-
{
|
|
11506
|
-
"path": "last24hDrink",
|
|
11507
|
-
"valueType": "number"
|
|
11508
|
-
},
|
|
11509
|
-
{
|
|
11510
|
-
"path": "todayDrink",
|
|
11511
|
-
"valueType": "number"
|
|
11512
|
-
},
|
|
11513
11968
|
{
|
|
11514
11969
|
"path": "error",
|
|
11515
11970
|
"valueType": "string"
|
|
@@ -12075,12 +12530,66 @@ Object.freeze({
|
|
|
12075
12530
|
}
|
|
12076
12531
|
]
|
|
12077
12532
|
});
|
|
12533
|
+
Object.freeze({
|
|
12534
|
+
"actions": { "run": 363e4 },
|
|
12535
|
+
"audio-analyzer": { "classify": 3e4 },
|
|
12536
|
+
"custom-model-registry": { "importModelBundle": 18e5 },
|
|
12537
|
+
"database-snapshot": { "writeSnapshot": 18e5 },
|
|
12538
|
+
"device-manager": {
|
|
12539
|
+
"migrateDevice": 72e4,
|
|
12540
|
+
"runDiscoverySweep": 12e4
|
|
12541
|
+
},
|
|
12542
|
+
"device-provider": { "reloadDevice": 18e4 },
|
|
12543
|
+
"llm": {
|
|
12544
|
+
"generate": 6e5,
|
|
12545
|
+
"generateVision": 6e5,
|
|
12546
|
+
"testProfile": 6e5
|
|
12547
|
+
},
|
|
12548
|
+
"llm-runtime": {
|
|
12549
|
+
"complete": 6e5,
|
|
12550
|
+
"completeApple": 6e5,
|
|
12551
|
+
"ensureStarted": 6e5,
|
|
12552
|
+
"installModel": 36e5
|
|
12553
|
+
},
|
|
12554
|
+
"local-network": { "scanNetwork": 9e4 },
|
|
12555
|
+
"model-convert": { "convert": 6e5 },
|
|
12556
|
+
"pipeline-analytics": {
|
|
12557
|
+
"addRetrainFrameFromRecording": 6e4,
|
|
12558
|
+
"offerRetrainArchive": 12e4,
|
|
12559
|
+
"proposeRetrainAnnotationsWithLlm": 18e4,
|
|
12560
|
+
"resolveRetrainTrainingCorpus": 6e4,
|
|
12561
|
+
"writeRetrainArchive": 36e5
|
|
12562
|
+
},
|
|
12563
|
+
"server-management": { "applyServerUpdate": 96e4 },
|
|
12564
|
+
"terminal-session": { "pullOutput": 15e3 },
|
|
12565
|
+
"training": {
|
|
12566
|
+
"canaryResult": 12e4,
|
|
12567
|
+
"cancelJob": 12e4,
|
|
12568
|
+
"planJob": 6e4,
|
|
12569
|
+
"registerResult": 18e5,
|
|
12570
|
+
"rollbackCanary": 12e4,
|
|
12571
|
+
"startJob": 12e4,
|
|
12572
|
+
"startJobBatch": 12e4
|
|
12573
|
+
},
|
|
12574
|
+
"training-provider": {
|
|
12575
|
+
"cancelJob": 6e4,
|
|
12576
|
+
"cleanupJob": 3e5,
|
|
12577
|
+
"getJob": 6e4,
|
|
12578
|
+
"listJobEvents": 6e4,
|
|
12579
|
+
"listJobs": 12e4,
|
|
12580
|
+
"offerArtifact": 3e5,
|
|
12581
|
+
"readResult": 3e5,
|
|
12582
|
+
"submitJob": 18e5,
|
|
12583
|
+
"uploadDataset": 72e5,
|
|
12584
|
+
"validateCredentials": 3e4
|
|
12585
|
+
}
|
|
12586
|
+
});
|
|
12078
12587
|
object({
|
|
12079
12588
|
code: string().regex(/^[a-z][a-z0-9-]*(\.[a-z0-9-]+)+$/),
|
|
12080
12589
|
params: record(string(), union([string(), number()])).optional()
|
|
12081
12590
|
});
|
|
12082
12591
|
//#endregion
|
|
12083
|
-
//#region ../types/dist/composition-
|
|
12592
|
+
//#region ../types/dist/composition-BmBHuDTQ.mjs
|
|
12084
12593
|
/**
|
|
12085
12594
|
* The ffmpeg build every CamStack node downloads, per platform and arch.
|
|
12086
12595
|
*
|
|
@@ -12384,7 +12893,7 @@ var table = {
|
|
|
12384
12893
|
},
|
|
12385
12894
|
dwell: {
|
|
12386
12895
|
minArgs: 3,
|
|
12387
|
-
maxArgs:
|
|
12896
|
+
maxArgs: 4,
|
|
12388
12897
|
apply: () => {
|
|
12389
12898
|
throw new ExpressionEvalError("dwell: stateful evaluation context is required");
|
|
12390
12899
|
}
|
|
@@ -13427,212 +13936,6 @@ var IntegrationInstanceRefSchema = object({
|
|
|
13427
13936
|
]),
|
|
13428
13937
|
candidateStableId: string().optional()
|
|
13429
13938
|
});
|
|
13430
|
-
/**
|
|
13431
|
-
* `RecordIntegrationInstances` - the `integration-instances` provider over ONE
|
|
13432
|
-
* entry kind, so an addon that holds a connection serves it in ~30 lines.
|
|
13433
|
-
*
|
|
13434
|
-
* Every instance is one record of the addon's own kind, keyed by the
|
|
13435
|
-
* `integrations` registry id. The records door does the secret work: a field the
|
|
13436
|
-
* kind marks `.meta({ secret: true })` is a keychain marker bound to the row, so
|
|
13437
|
-
* deleting the row deletes the secret, and one row's value is never another's.
|
|
13438
|
-
*
|
|
13439
|
-
* Patch rules for a secret (`updateInstance`): omitted, `''`, the redaction
|
|
13440
|
-
* token or the view the form was given KEEP the stored secret;
|
|
13441
|
-
* `{ $secretClear: true }` clears it; any other string replaces it.
|
|
13442
|
-
*/
|
|
13443
|
-
/** The most instances one addon lists (an integrations page, not a table). */
|
|
13444
|
-
var INSTANCES_LIST_MAX = 1e3;
|
|
13445
|
-
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
13446
|
-
function topLevelSecretKeys(paths) {
|
|
13447
|
-
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
13448
|
-
}
|
|
13449
|
-
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
13450
|
-
function secretMapKeys(paths) {
|
|
13451
|
-
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
13452
|
-
}
|
|
13453
|
-
/**
|
|
13454
|
-
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
13455
|
-
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
13456
|
-
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
13457
|
-
*/
|
|
13458
|
-
function secretMapPatch(value) {
|
|
13459
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
13460
|
-
const out = {};
|
|
13461
|
-
for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
|
|
13462
|
-
else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
|
|
13463
|
-
return Object.keys(out).length > 0 ? out : null;
|
|
13464
|
-
}
|
|
13465
|
-
/** Does the kind's body schema carry an `enabled` field? */
|
|
13466
|
-
function declaresEnabled(kind) {
|
|
13467
|
-
const json = toJSONSchema(kind.schema, {
|
|
13468
|
-
unrepresentable: "any",
|
|
13469
|
-
io: "input"
|
|
13470
|
-
});
|
|
13471
|
-
const properties = Reflect.get(json, "properties");
|
|
13472
|
-
return typeof properties === "object" && properties !== null && "enabled" in properties;
|
|
13473
|
-
}
|
|
13474
|
-
var RecordIntegrationInstances = class {
|
|
13475
|
-
records;
|
|
13476
|
-
kind;
|
|
13477
|
-
hooks;
|
|
13478
|
-
handle;
|
|
13479
|
-
secretKeys;
|
|
13480
|
-
secretMaps;
|
|
13481
|
-
nameField;
|
|
13482
|
-
/** The `integrations` registry owns the on/off switch (`role: devices`); the body has none. */
|
|
13483
|
-
registryOwnsEnabled;
|
|
13484
|
-
constructor(records, kind, hooks) {
|
|
13485
|
-
this.records = records;
|
|
13486
|
-
this.kind = kind;
|
|
13487
|
-
this.hooks = hooks;
|
|
13488
|
-
this.handle = records.kind(kind);
|
|
13489
|
-
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
13490
|
-
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
13491
|
-
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
13492
|
-
this.registryOwnsEnabled = hooks.description.role === "devices";
|
|
13493
|
-
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"`);
|
|
13494
|
-
}
|
|
13495
|
-
/**
|
|
13496
|
-
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
13497
|
-
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
13498
|
-
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
13499
|
-
*/
|
|
13500
|
-
async readResolved(id) {
|
|
13501
|
-
try {
|
|
13502
|
-
const record = await this.handle.getResolved(id);
|
|
13503
|
-
return record === null ? null : {
|
|
13504
|
-
id,
|
|
13505
|
-
body: record.data,
|
|
13506
|
-
enabled: record.data.enabled !== false,
|
|
13507
|
-
secrets: "resolved"
|
|
13508
|
-
};
|
|
13509
|
-
} catch (err) {
|
|
13510
|
-
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
13511
|
-
const stored = await this.handle.get(id);
|
|
13512
|
-
if (stored === null) return null;
|
|
13513
|
-
return {
|
|
13514
|
-
id,
|
|
13515
|
-
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
13516
|
-
enabled: stored.data.enabled !== false,
|
|
13517
|
-
secrets: "unavailable"
|
|
13518
|
-
};
|
|
13519
|
-
}
|
|
13520
|
-
}
|
|
13521
|
-
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
13522
|
-
async getResolved(id) {
|
|
13523
|
-
return (await this.readResolved(id))?.body ?? null;
|
|
13524
|
-
}
|
|
13525
|
-
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
13526
|
-
async listResolved() {
|
|
13527
|
-
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
13528
|
-
const out = [];
|
|
13529
|
-
for (const record of page.records) {
|
|
13530
|
-
const read = await this.readResolved(record.id);
|
|
13531
|
-
if (read !== null) out.push(read);
|
|
13532
|
-
}
|
|
13533
|
-
return out;
|
|
13534
|
-
}
|
|
13535
|
-
viewOf(record) {
|
|
13536
|
-
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
13537
|
-
const rawName = record.data[this.nameField];
|
|
13538
|
-
const kind = this.hooks.kindOf?.(record.data);
|
|
13539
|
-
const health = this.hooks.health?.(record.data, record.id);
|
|
13540
|
-
return {
|
|
13541
|
-
id: record.id,
|
|
13542
|
-
name: typeof rawName === "string" ? rawName : record.id,
|
|
13543
|
-
configured: this.hooks.configured(record.data),
|
|
13544
|
-
...this.registryOwnsEnabled ? {} : { enabled: record.data.enabled !== false },
|
|
13545
|
-
formValues: shown,
|
|
13546
|
-
...kind !== void 0 ? { kind } : {},
|
|
13547
|
-
...health?.status !== void 0 ? { status: health.status } : {},
|
|
13548
|
-
...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
|
|
13549
|
-
};
|
|
13550
|
-
}
|
|
13551
|
-
describe = async () => this.hooks.mintId === void 0 ? this.hooks.description : {
|
|
13552
|
-
...this.hooks.description,
|
|
13553
|
-
mintsId: true
|
|
13554
|
-
};
|
|
13555
|
-
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
13556
|
-
listInstances = async () => {
|
|
13557
|
-
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
13558
|
-
};
|
|
13559
|
-
getInstance = async ({ id }) => {
|
|
13560
|
-
const record = await this.handle.get(id);
|
|
13561
|
-
return record === null ? null : this.viewOf(record);
|
|
13562
|
-
};
|
|
13563
|
-
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
13564
|
-
createInstance = async ({ id, name, kind, values }) => {
|
|
13565
|
-
const minted = id ?? this.hooks.mintId?.({
|
|
13566
|
-
name,
|
|
13567
|
-
...kind !== void 0 ? { kind } : {}
|
|
13568
|
-
});
|
|
13569
|
-
if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
|
|
13570
|
-
await this.handle.put({
|
|
13571
|
-
id: minted,
|
|
13572
|
-
data: this.hooks.initialBody(name, kind)
|
|
13573
|
-
}, { ifRev: 0 });
|
|
13574
|
-
const patch = this.patchOf(values ?? {});
|
|
13575
|
-
if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
|
|
13576
|
-
await this.hooks.onChanged?.(minted, "created");
|
|
13577
|
-
return { id: minted };
|
|
13578
|
-
};
|
|
13579
|
-
updateInstance = async ({ id, name, values }) => {
|
|
13580
|
-
const patch = this.patchOf(values);
|
|
13581
|
-
if (name !== void 0) patch[this.nameField] = name;
|
|
13582
|
-
await this.handle.patch(id, patch);
|
|
13583
|
-
await this.hooks.onChanged?.(id, "updated");
|
|
13584
|
-
return { ok: true };
|
|
13585
|
-
};
|
|
13586
|
-
/** The record patch a form `values` object means: secrets kept, cleared or replaced. */
|
|
13587
|
-
patchOf(values) {
|
|
13588
|
-
const patch = {};
|
|
13589
|
-
for (const [key, value] of Object.entries(values)) {
|
|
13590
|
-
if (value === void 0) continue;
|
|
13591
|
-
if (this.secretMaps.has(key)) {
|
|
13592
|
-
const entries = secretMapPatch(value);
|
|
13593
|
-
if (entries !== null) patch[key] = entries;
|
|
13594
|
-
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
13595
|
-
else if (isSecretClear(value)) patch[key] = null;
|
|
13596
|
-
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
13597
|
-
}
|
|
13598
|
-
return patch;
|
|
13599
|
-
}
|
|
13600
|
-
/** The switch lives in the record body; the addon is told so it applies it (D996). */
|
|
13601
|
-
setInstanceEnabled = async ({ id, enabled }) => {
|
|
13602
|
-
if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
|
|
13603
|
-
await this.handle.patch(id, { enabled });
|
|
13604
|
-
await this.hooks.onChanged?.(id, "enabled");
|
|
13605
|
-
return { ok: true };
|
|
13606
|
-
};
|
|
13607
|
-
/** The row and its keychain refs go together (the records door). */
|
|
13608
|
-
deleteInstance = async ({ id }) => {
|
|
13609
|
-
await this.handle.delete(id);
|
|
13610
|
-
await this.hooks.onChanged?.(id, "deleted");
|
|
13611
|
-
return { ok: true };
|
|
13612
|
-
};
|
|
13613
|
-
testInstance = async (input) => {
|
|
13614
|
-
if (this.hooks.test === void 0) return {
|
|
13615
|
-
success: false,
|
|
13616
|
-
status: "unsupported",
|
|
13617
|
-
error: "This integration declares no connection test"
|
|
13618
|
-
};
|
|
13619
|
-
return this.hooks.test(input);
|
|
13620
|
-
};
|
|
13621
|
-
/** The flat provider object to hand to `registerProvider`. */
|
|
13622
|
-
toProvider() {
|
|
13623
|
-
return {
|
|
13624
|
-
describe: this.describe,
|
|
13625
|
-
instanceFormSchema: this.instanceFormSchema,
|
|
13626
|
-
listInstances: this.listInstances,
|
|
13627
|
-
getInstance: this.getInstance,
|
|
13628
|
-
createInstance: this.createInstance,
|
|
13629
|
-
updateInstance: this.updateInstance,
|
|
13630
|
-
setInstanceEnabled: this.setInstanceEnabled,
|
|
13631
|
-
deleteInstance: this.deleteInstance,
|
|
13632
|
-
testInstance: this.testInstance
|
|
13633
|
-
};
|
|
13634
|
-
}
|
|
13635
|
-
};
|
|
13636
13939
|
var EncodeProfileSchema = object({
|
|
13637
13940
|
video: object({
|
|
13638
13941
|
codec: _enum([
|
|
@@ -19941,31 +20244,21 @@ var APPLIANCE_CAP_VOCABULARY = {
|
|
|
19941
20244
|
"pet-fountain": {
|
|
19942
20245
|
scope: "device",
|
|
19943
20246
|
noun: t("Pet fountain", "Fontana per animali"),
|
|
19944
|
-
actions: [
|
|
19945
|
-
|
|
19946
|
-
|
|
19947
|
-
|
|
19948
|
-
|
|
19949
|
-
|
|
19950
|
-
|
|
19951
|
-
|
|
19952
|
-
|
|
19953
|
-
|
|
19954
|
-
|
|
19955
|
-
|
|
19956
|
-
|
|
19957
|
-
|
|
19958
|
-
|
|
19959
|
-
args: { on: false }
|
|
19960
|
-
},
|
|
19961
|
-
{
|
|
19962
|
-
id: "petFountain.resetDailyConsumption",
|
|
19963
|
-
method: "resetDailyConsumption",
|
|
19964
|
-
label: t("Clear daily consumption", "Azzera il consumo giornaliero"),
|
|
19965
|
-
phrase: t("Clear the daily water consumption of {device}", "Azzera il consumo giornaliero di acqua di {device}"),
|
|
19966
|
-
icon: "rotate-ccw"
|
|
19967
|
-
}
|
|
19968
|
-
],
|
|
20247
|
+
actions: [{
|
|
20248
|
+
id: "petFountain.pumpOn",
|
|
20249
|
+
method: "setPump",
|
|
20250
|
+
label: t("Pump on", "Pompa accesa"),
|
|
20251
|
+
phrase: t("Start the pump of {device}", "Avvia la pompa di {device}"),
|
|
20252
|
+
icon: "play",
|
|
20253
|
+
args: { on: true }
|
|
20254
|
+
}, {
|
|
20255
|
+
id: "petFountain.pumpOff",
|
|
20256
|
+
method: "setPump",
|
|
20257
|
+
label: t("Pump off", "Pompa spenta"),
|
|
20258
|
+
phrase: t("Stop the pump of {device}", "Ferma la pompa di {device}"),
|
|
20259
|
+
icon: "square",
|
|
20260
|
+
args: { on: false }
|
|
20261
|
+
}],
|
|
19969
20262
|
state: [{
|
|
19970
20263
|
kind: "boolean",
|
|
19971
20264
|
field: "empty",
|
|
@@ -43998,8 +44291,15 @@ var ActionInputSchema = object({
|
|
|
43998
44291
|
var ActionRunOriginSchema = object({
|
|
43999
44292
|
/** The automation block whose step started it. */
|
|
44000
44293
|
blockId: string().min(1).optional() });
|
|
44001
|
-
/**
|
|
44002
|
-
|
|
44294
|
+
/**
|
|
44295
|
+
* `started` = the caller did not ask to wait. `timed-out` = the run reached the
|
|
44296
|
+
* ceiling (`ACTION_RUN_MAX_MS`) and was stopped; it is never a `ran`.
|
|
44297
|
+
*/
|
|
44298
|
+
var ActionRunOutcomeSchema = union([
|
|
44299
|
+
AutomationRunOutcomeSchema,
|
|
44300
|
+
literal("started"),
|
|
44301
|
+
literal("timed-out")
|
|
44302
|
+
]);
|
|
44003
44303
|
var ActionRunResultSchema = object({
|
|
44004
44304
|
runId: string().min(1),
|
|
44005
44305
|
outcome: ActionRunOutcomeSchema,
|
|
@@ -44521,6 +44821,8 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
44521
44821
|
kind: "mutation",
|
|
44522
44822
|
auth: "admin"
|
|
44523
44823
|
});
|
|
44824
|
+
/** `timeoutMs` of `actions.run`: a waited call outlives any legal run. */
|
|
44825
|
+
var ACTION_RUN_TIMEOUT_MS = 363e4;
|
|
44524
44826
|
/**
|
|
44525
44827
|
* actions — the ONE surface for runnable actions, for the UI and for
|
|
44526
44828
|
* automations. Provided by the core-blocks builtin on the hub.
|
|
@@ -44539,6 +44841,12 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
44539
44841
|
* An admin, and an in-process caller (an automation block), may run any action.
|
|
44540
44842
|
* Every refusal is typed (`[not-linked] …`) and logged.
|
|
44541
44843
|
*
|
|
44844
|
+
* **A run lasts at most `ACTION_RUN_MAX_MS` (60 min).** The provider stops a
|
|
44845
|
+
* run that reaches it and answers `timed-out` (never `ran`); an action whose
|
|
44846
|
+
* `wait` steps alone add up to more is refused at create/update
|
|
44847
|
+
* (`[invalid-steps]`). `run` declares a `timeoutMs` above that ceiling, so a
|
|
44848
|
+
* waited call (an automation step) is never cut by the 60 s transport default.
|
|
44849
|
+
*
|
|
44542
44850
|
* A second `run` of an action that is already running is REFUSED — traced and
|
|
44543
44851
|
* logged — never queued.
|
|
44544
44852
|
*/
|
|
@@ -44565,7 +44873,8 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
44565
44873
|
role: "viewer",
|
|
44566
44874
|
auth: "protected",
|
|
44567
44875
|
kind: "mutation",
|
|
44568
|
-
caller: "required"
|
|
44876
|
+
caller: "required",
|
|
44877
|
+
timeoutMs: ACTION_RUN_TIMEOUT_MS
|
|
44569
44878
|
}), method(ActionIdInput, _void(), {
|
|
44570
44879
|
kind: "mutation",
|
|
44571
44880
|
auth: "admin"
|
|
@@ -49600,6 +49909,9 @@ var MediaPlayerStatusSchema = object({
|
|
|
49600
49909
|
/** Repeat mode. Null when no repeat surface.
|
|
49601
49910
|
* Pair with `DeviceFeature.MediaPlayerRepeat`. */
|
|
49602
49911
|
repeat: MediaPlayerRepeatSchema.nullable(),
|
|
49912
|
+
/** Ms epoch when `position` was read from the device. Null when the driver
|
|
49913
|
+
* does not say; a UI that advances the position while playing counts from it. */
|
|
49914
|
+
positionUpdatedAt: number().nullable().default(null),
|
|
49603
49915
|
/** Ms epoch when the slice was last updated. */
|
|
49604
49916
|
lastChangedAt: number()
|
|
49605
49917
|
});
|
|
@@ -50235,7 +50547,9 @@ var ThresholdTransformDraftSchema = object({
|
|
|
50235
50547
|
comparison: _enum(["gte", "lte"]),
|
|
50236
50548
|
threshold: number(),
|
|
50237
50549
|
startDwellMs: number().nonnegative(),
|
|
50238
|
-
stopDwellMs: number().nonnegative()
|
|
50550
|
+
stopDwellMs: number().nonnegative(),
|
|
50551
|
+
/** Samples a start needs; absent = the compiler's default for the source (2 for running power, else 1). */
|
|
50552
|
+
minSamples: number().int().min(1).optional()
|
|
50239
50553
|
});
|
|
50240
50554
|
var CustomizeTransformDraftSchema = discriminatedUnion("kind", [
|
|
50241
50555
|
IdentityTransformDraftSchema,
|
|
@@ -56112,6 +56426,7 @@ var IntegrationWithStateSchema = object({
|
|
|
56112
56426
|
id: string(),
|
|
56113
56427
|
addonId: string(),
|
|
56114
56428
|
name: string(),
|
|
56429
|
+
/** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
|
|
56115
56430
|
enabled: boolean(),
|
|
56116
56431
|
info: record(string(), unknown()).readonly(),
|
|
56117
56432
|
/** The discovery candidate this integration was set up from (D984). */
|
|
@@ -56124,6 +56439,7 @@ var IntegrationLiteSchema = object({
|
|
|
56124
56439
|
id: string(),
|
|
56125
56440
|
addonId: string(),
|
|
56126
56441
|
name: string(),
|
|
56442
|
+
/** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
|
|
56127
56443
|
enabled: boolean(),
|
|
56128
56444
|
info: record(string(), unknown()).readonly(),
|
|
56129
56445
|
/** The discovery candidate this integration was set up from (D984). */
|
|
@@ -56223,7 +56539,6 @@ var TestConnectionResultSchema = object({
|
|
|
56223
56539
|
var CreateIntegrationInputSchema = object({
|
|
56224
56540
|
addonId: string(),
|
|
56225
56541
|
name: string(),
|
|
56226
|
-
enabled: boolean().optional(),
|
|
56227
56542
|
info: record(string(), unknown()).optional(),
|
|
56228
56543
|
/** `stableId` of the discovery candidate the form was seeded from (D984). */
|
|
56229
56544
|
originStableId: string().optional(),
|
|
@@ -56232,6 +56547,11 @@ var CreateIntegrationInputSchema = object({
|
|
|
56232
56547
|
var UpdateIntegrationInputSchema = object({
|
|
56233
56548
|
id: string(),
|
|
56234
56549
|
name: string().optional(),
|
|
56550
|
+
/**
|
|
56551
|
+
* Accepted for a FIXED builtin only (`info.fixed`: alarm panel, camera grid, core blocks,
|
|
56552
|
+
* terminal), which keeps no instance record: the registry flag is its one store. Any other
|
|
56553
|
+
* integration is switched through `integration-instances.setInstanceEnabled`.
|
|
56554
|
+
*/
|
|
56235
56555
|
enabled: boolean().optional(),
|
|
56236
56556
|
info: record(string(), unknown()).optional()
|
|
56237
56557
|
});
|
|
@@ -56279,7 +56599,7 @@ var IntegrationInstanceIdSchema = string().min(1);
|
|
|
56279
56599
|
var IntegrationInstanceModeSchema = _enum(["single", "multiple"]);
|
|
56280
56600
|
/**
|
|
56281
56601
|
* What the addon's instances ARE for the Integrations page (planning#416). `devices`: each
|
|
56282
|
-
* instance is an integration that brings devices (
|
|
56602
|
+
* instance is an integration that brings devices (its record body owns the on/off switch);
|
|
56283
56603
|
* `services`: a connection configured from the addon's own function page, never listed on
|
|
56284
56604
|
* Integrations.
|
|
56285
56605
|
* It is the same vocabulary as the manifest's `integrationRole`, which stays as an override.
|
|
@@ -56322,18 +56642,38 @@ var IntegrationInstanceKindSchema = object({
|
|
|
56322
56642
|
/** Relative hub path to disconnect that account. */
|
|
56323
56643
|
disconnectPath: string().min(1).optional()
|
|
56324
56644
|
});
|
|
56645
|
+
/**
|
|
56646
|
+
* How devices of an instance are found. `none`: the operator adds them by hand; `lan`: the addon
|
|
56647
|
+
* scans the network before any instance exists (the wizard offers the candidates); `account`: the
|
|
56648
|
+
* devices appear after the instance signs in. `scopedToInstance`: a discovery run belongs to ONE
|
|
56649
|
+
* instance and its candidates are claimed by it.
|
|
56650
|
+
*/
|
|
56651
|
+
var IntegrationInstanceDiscoverySchema = object({
|
|
56652
|
+
mode: _enum([
|
|
56653
|
+
"none",
|
|
56654
|
+
"lan",
|
|
56655
|
+
"account"
|
|
56656
|
+
]),
|
|
56657
|
+
scopedToInstance: boolean()
|
|
56658
|
+
});
|
|
56659
|
+
/**
|
|
56660
|
+
* One link a kind of this provider declares (D1013 rule 5): the body `field` of an instance of
|
|
56661
|
+
* `kind` holds the id of an instance of the function cap `to.cap` (of kind `to.kind`, when set).
|
|
56662
|
+
* The hub indexes these so the target's delete is refused while a link names it.
|
|
56663
|
+
*/
|
|
56664
|
+
var IntegrationInstanceLinkSchema = object({
|
|
56665
|
+
kind: string().min(1),
|
|
56666
|
+
field: string().min(1),
|
|
56667
|
+
to: object({
|
|
56668
|
+
cap: string().min(1),
|
|
56669
|
+
kind: string().min(1).optional()
|
|
56670
|
+
})
|
|
56671
|
+
});
|
|
56325
56672
|
var IntegrationInstanceDescriptionSchema = object({
|
|
56326
56673
|
/** What the instances are for the Integrations page; see {@link IntegrationInstanceRoleSchema}. */
|
|
56327
56674
|
role: IntegrationInstanceRoleSchema,
|
|
56328
56675
|
/** How the devices of an instance are found; absent means `{ mode: 'none' }`. */
|
|
56329
|
-
discovery:
|
|
56330
|
-
mode: _enum([
|
|
56331
|
-
"none",
|
|
56332
|
-
"lan",
|
|
56333
|
-
"account"
|
|
56334
|
-
]),
|
|
56335
|
-
scopedToInstance: boolean()
|
|
56336
|
-
}).optional(),
|
|
56676
|
+
discovery: IntegrationInstanceDiscoverySchema.optional(),
|
|
56337
56677
|
/** `single`: at most one instance can exist (Loki). `multiple`: an account each. */
|
|
56338
56678
|
instanceMode: IntegrationInstanceModeSchema,
|
|
56339
56679
|
/** What the instance is, for the UI (`destination`, `relay`, `account`). */
|
|
@@ -56354,7 +56694,9 @@ var IntegrationInstanceDescriptionSchema = object({
|
|
|
56354
56694
|
* `createInstance` without an `id` works: the provider mints it. Absent means the caller must
|
|
56355
56695
|
* send an id (the UI then mints an opaque one).
|
|
56356
56696
|
*/
|
|
56357
|
-
mintsId: boolean().optional()
|
|
56697
|
+
mintsId: boolean().optional(),
|
|
56698
|
+
/** The links to other instances the provider's kinds declare; absent means none. */
|
|
56699
|
+
links: array(IntegrationInstanceLinkSchema).optional()
|
|
56358
56700
|
});
|
|
56359
56701
|
var IntegrationInstanceStatusSchema = object({
|
|
56360
56702
|
state: _enum([
|
|
@@ -56374,8 +56716,8 @@ var IntegrationInstanceSchema = object({
|
|
|
56374
56716
|
configured: boolean(),
|
|
56375
56717
|
/**
|
|
56376
56718
|
* The instance's own on/off switch (D996), derived from the record body (`enabled !== false`,
|
|
56377
|
-
* so a row written before the field existed is on).
|
|
56378
|
-
*
|
|
56719
|
+
* so a row written before the field existed is on). The same for every role, `devices` included:
|
|
56720
|
+
* the body is the one store, `setInstanceEnabled` the one writer (epic #440, step 3).
|
|
56379
56721
|
*/
|
|
56380
56722
|
enabled: boolean().optional(),
|
|
56381
56723
|
/** The kind of this instance (one of `describe().kinds[].id`), when the provider has kinds. */
|
|
@@ -56425,7 +56767,8 @@ var integrationInstancesCapability = {
|
|
|
56425
56767
|
auth: "admin"
|
|
56426
56768
|
}),
|
|
56427
56769
|
/**
|
|
56428
|
-
* Switch ONE instance on or off
|
|
56770
|
+
* Switch ONE instance on or off, for every role; a missing record is created from the addon's
|
|
56771
|
+
* initial body. A row control, not a form field: `updateInstance.values` is the
|
|
56429
56772
|
* form patch (D62, D996). An off instance keeps its record and secrets and does no work.
|
|
56430
56773
|
*/
|
|
56431
56774
|
setInstanceEnabled: method(object({
|
|
@@ -59488,6 +59831,8 @@ var MigrationIntegrationSchema = object({
|
|
|
59488
59831
|
addonId: string(),
|
|
59489
59832
|
name: string(),
|
|
59490
59833
|
info: Rows,
|
|
59834
|
+
/** The registry's stored switch: read by the one-switch migration, nothing else. */
|
|
59835
|
+
enabled: boolean().optional(),
|
|
59491
59836
|
originStableId: string().optional()
|
|
59492
59837
|
});
|
|
59493
59838
|
var MigrationDeviceSchema = object({
|
|
@@ -69617,14 +69962,6 @@ var PetFountainStatusSchema = object({
|
|
|
69617
69962
|
empty: boolean().nullable(),
|
|
69618
69963
|
/** True while the pump is running. Null while unknown. */
|
|
69619
69964
|
pumpRunning: boolean().nullable(),
|
|
69620
|
-
/** Water drunk in the last drink, in litres. */
|
|
69621
|
-
lastDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
69622
|
-
/** Water drunk in the current hour, in litres. */
|
|
69623
|
-
currentHourDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
69624
|
-
/** Water drunk over the last 24 hours (rolling), in litres. */
|
|
69625
|
-
last24hDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
69626
|
-
/** Water drunk since local midnight, in litres. Null when the fountain has no such sensor. */
|
|
69627
|
-
todayDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
69628
69965
|
/** Decoded fault message. Null means healthy; a non-null string is an active fault. */
|
|
69629
69966
|
error: string().nullable(),
|
|
69630
69967
|
/** Ms epoch when the slice was last refreshed. */
|
|
@@ -69637,21 +69974,15 @@ var petFountainCapability = {
|
|
|
69637
69974
|
deviceNative: true,
|
|
69638
69975
|
mode: "singleton",
|
|
69639
69976
|
deviceTypes: [DeviceType.PetFountain],
|
|
69640
|
-
methods: {
|
|
69641
|
-
|
|
69642
|
-
|
|
69643
|
-
|
|
69644
|
-
|
|
69645
|
-
|
|
69646
|
-
|
|
69647
|
-
|
|
69648
|
-
|
|
69649
|
-
/** Clear the rolling daily consumption counters on the device. */
|
|
69650
|
-
resetDailyConsumption: method(object({ deviceId: DeviceIdSchema$1 }), _void(), {
|
|
69651
|
-
kind: "mutation",
|
|
69652
|
-
auth: "protected"
|
|
69653
|
-
})
|
|
69654
|
-
},
|
|
69977
|
+
methods: {
|
|
69978
|
+
/** Start or stop the pump. */
|
|
69979
|
+
setPump: method(object({
|
|
69980
|
+
deviceId: DeviceIdSchema$1,
|
|
69981
|
+
on: boolean()
|
|
69982
|
+
}), _void(), {
|
|
69983
|
+
kind: "mutation",
|
|
69984
|
+
auth: "protected"
|
|
69985
|
+
}) },
|
|
69655
69986
|
status: {
|
|
69656
69987
|
schema: PetFountainStatusSchema,
|
|
69657
69988
|
kind: "push"
|
|
@@ -69675,14 +70006,6 @@ var petFountainCapability = {
|
|
|
69675
70006
|
waterVolume: {
|
|
69676
70007
|
kind: "gauge",
|
|
69677
70008
|
unit: "L"
|
|
69678
|
-
},
|
|
69679
|
-
todayDrink: {
|
|
69680
|
-
kind: "gauge",
|
|
69681
|
-
unit: "L"
|
|
69682
|
-
},
|
|
69683
|
-
last24hDrink: {
|
|
69684
|
-
kind: "gauge",
|
|
69685
|
-
unit: "L"
|
|
69686
70009
|
}
|
|
69687
70010
|
} }
|
|
69688
70011
|
};
|
|
@@ -88170,13 +88493,6 @@ Object.freeze({
|
|
|
88170
88493
|
access: "view",
|
|
88171
88494
|
role: "viewer"
|
|
88172
88495
|
},
|
|
88173
|
-
"petFountain.resetDailyConsumption": {
|
|
88174
|
-
capName: "pet-fountain",
|
|
88175
|
-
capScope: "device",
|
|
88176
|
-
addonId: null,
|
|
88177
|
-
access: "delete",
|
|
88178
|
-
role: "viewer"
|
|
88179
|
-
},
|
|
88180
88496
|
"petFountain.setPump": {
|
|
88181
88497
|
capName: "pet-fountain",
|
|
88182
88498
|
capScope: "device",
|
|
@@ -94573,11 +94889,6 @@ Object.freeze({
|
|
|
94573
94889
|
form: "single",
|
|
94574
94890
|
optional: false
|
|
94575
94891
|
}],
|
|
94576
|
-
"petFountain.resetDailyConsumption": [{
|
|
94577
|
-
name: "deviceId",
|
|
94578
|
-
form: "single",
|
|
94579
|
-
optional: false
|
|
94580
|
-
}],
|
|
94581
94892
|
"petFountain.setPump": [{
|
|
94582
94893
|
name: "deviceId",
|
|
94583
94894
|
form: "single",
|
|
@@ -98162,74 +98473,6 @@ object({
|
|
|
98162
98473
|
delay: number().nonnegative().optional(),
|
|
98163
98474
|
commands: record(string(), unknown())
|
|
98164
98475
|
});
|
|
98165
|
-
entryBody({ brokerId: string() });
|
|
98166
|
-
function secretsOverMigrationApi(api) {
|
|
98167
|
-
return {
|
|
98168
|
-
resolve: async (refs) => {
|
|
98169
|
-
const { values } = await api.secrets.resolve({ refs: [...refs] });
|
|
98170
|
-
const out = {};
|
|
98171
|
-
for (const ref of refs) {
|
|
98172
|
-
const value = values[ref];
|
|
98173
|
-
out[ref] = value === null || value === void 0 ? { kind: "missing" } : {
|
|
98174
|
-
kind: "value",
|
|
98175
|
-
value,
|
|
98176
|
-
version: 0
|
|
98177
|
-
};
|
|
98178
|
-
}
|
|
98179
|
-
return out;
|
|
98180
|
-
},
|
|
98181
|
-
delete: async (refs) => (await api.secrets.delete({ refs: [...refs] })).deleted
|
|
98182
|
-
};
|
|
98183
|
-
}
|
|
98184
|
-
/** `ctx.records` as the migration API offers it: bind a kind, read and write by id. */
|
|
98185
|
-
function recordsOverMigrationApi(api) {
|
|
98186
|
-
return { kind: (definition) => {
|
|
98187
|
-
const handle = api.records.kind(definition);
|
|
98188
|
-
return {
|
|
98189
|
-
get: (id) => handle.get({ id }),
|
|
98190
|
-
getResolved: (id) => handle.getResolved({ id }),
|
|
98191
|
-
put: (input, opts) => handle.put({
|
|
98192
|
-
...input,
|
|
98193
|
-
...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
|
|
98194
|
-
}),
|
|
98195
|
-
delete: (id) => handle.delete({ id })
|
|
98196
|
-
};
|
|
98197
|
-
} };
|
|
98198
|
-
}
|
|
98199
|
-
function integrationRowsApiOver(api) {
|
|
98200
|
-
return {
|
|
98201
|
-
list: async () => (await api.integrations.list({})).integrations,
|
|
98202
|
-
readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
|
|
98203
|
-
clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
|
|
98204
|
-
};
|
|
98205
|
-
}
|
|
98206
|
-
/**
|
|
98207
|
-
* One serial lane per migration API: a log line is delivered after the line before it, so the
|
|
98208
|
-
* order the steps wrote them in is the order the hub reads them in. A delivery that fails
|
|
98209
|
-
* is reported once through the same door; if that fails too nothing is left to tell, and the
|
|
98210
|
-
* line is dropped rather than thrown into a migration step or left as an unhandled rejection.
|
|
98211
|
-
*/
|
|
98212
|
-
var lanes = /* @__PURE__ */ new WeakMap();
|
|
98213
|
-
function deliver(api, send) {
|
|
98214
|
-
const next = (lanes.get(api) ?? Promise.resolve()).then(send).then(() => void 0).catch(async (error) => {
|
|
98215
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
98216
|
-
await api.log.warn({ message: `a migration log line could not be delivered: ${reason}` }).catch(() => void 0);
|
|
98217
|
-
});
|
|
98218
|
-
lanes.set(api, next);
|
|
98219
|
-
return next;
|
|
98220
|
-
}
|
|
98221
|
-
function warnOver(api) {
|
|
98222
|
-
return (message) => deliver(api, () => api.log.warn({ message }));
|
|
98223
|
-
}
|
|
98224
|
-
/** What the rows-to-records move needs, over the migration API. */
|
|
98225
|
-
function rowsDepsOver(api) {
|
|
98226
|
-
return {
|
|
98227
|
-
api: integrationRowsApiOver(api),
|
|
98228
|
-
records: recordsOverMigrationApi(api),
|
|
98229
|
-
secrets: secretsOverMigrationApi(api),
|
|
98230
|
-
warn: warnOver(api)
|
|
98231
|
-
};
|
|
98232
|
-
}
|
|
98233
98476
|
//#endregion
|
|
98234
98477
|
//#region src/shared/bosch-instances.ts
|
|
98235
98478
|
/**
|