@camstack/addon-google-services 0.2.40 → 0.2.41
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/google-services.addon.js +1940 -1655
- package/dist/google-services.addon.mjs +1941 -1655
- package/dist/index.js +0 -1
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
|
@@ -5985,7 +5985,7 @@ var ZodIssueCode = {
|
|
|
5985
5985
|
var ZodFirstPartyTypeKind;
|
|
5986
5986
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
5987
5987
|
//#endregion
|
|
5988
|
-
//#region ../types/dist/sleep-
|
|
5988
|
+
//#region ../types/dist/sleep-CdKka2ri.mjs
|
|
5989
5989
|
/**
|
|
5990
5990
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
5991
5991
|
* window to float samples (D455).
|
|
@@ -6669,137 +6669,95 @@ async function runAddonMigrations(host, migrations, logger, options = {}) {
|
|
|
6669
6669
|
blockOwner
|
|
6670
6670
|
};
|
|
6671
6671
|
}
|
|
6672
|
-
/**
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
|
|
6685
|
-
|
|
6686
|
-
|
|
6687
|
-
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
const set = async (next) => {
|
|
6691
|
-
const validated = deps.schema.parse(next);
|
|
6692
|
-
await deps.write({ [deps.key]: validated });
|
|
6693
|
-
};
|
|
6694
|
-
const update = async (fn) => {
|
|
6695
|
-
await set(fn(await get()));
|
|
6696
|
-
};
|
|
6672
|
+
/** The record calls the one-switch migration makes, over the migration API. */
|
|
6673
|
+
function switchRecordsOverMigrationApi(api) {
|
|
6674
|
+
return { kind: (definition) => {
|
|
6675
|
+
const handle = api.records.kind(definition);
|
|
6676
|
+
return {
|
|
6677
|
+
get: (id) => handle.get({ id }),
|
|
6678
|
+
put: (input, opts) => handle.put({
|
|
6679
|
+
...input,
|
|
6680
|
+
...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
|
|
6681
|
+
}),
|
|
6682
|
+
patch: (id, partial) => handle.patch({
|
|
6683
|
+
id,
|
|
6684
|
+
partial
|
|
6685
|
+
})
|
|
6686
|
+
};
|
|
6687
|
+
} };
|
|
6688
|
+
}
|
|
6689
|
+
function integrationRowsApiOver(api) {
|
|
6697
6690
|
return {
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6691
|
+
list: async () => (await api.integrations.list({})).integrations,
|
|
6692
|
+
readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
|
|
6693
|
+
clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
|
|
6701
6694
|
};
|
|
6702
6695
|
}
|
|
6696
|
+
var PREFIX = "records/";
|
|
6697
|
+
/** The base of every records failure. `detail` is the human part of the message. */
|
|
6698
|
+
var RecordsError = class extends Error {
|
|
6699
|
+
code;
|
|
6700
|
+
detail;
|
|
6701
|
+
constructor(code, detail) {
|
|
6702
|
+
super(`${PREFIX}${code}: ${detail}`);
|
|
6703
|
+
this.name = "RecordsError";
|
|
6704
|
+
this.code = code;
|
|
6705
|
+
this.detail = detail;
|
|
6706
|
+
}
|
|
6707
|
+
};
|
|
6708
|
+
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
6709
|
+
var RecordSecretUnavailableError = class extends RecordsError {
|
|
6710
|
+
constructor(detail) {
|
|
6711
|
+
super("secret-unavailable", detail);
|
|
6712
|
+
this.name = "RecordSecretUnavailableError";
|
|
6713
|
+
}
|
|
6714
|
+
};
|
|
6715
|
+
var InvalidRecordError = class extends RecordsError {
|
|
6716
|
+
constructor(detail) {
|
|
6717
|
+
super("invalid-record", detail);
|
|
6718
|
+
this.name = "InvalidRecordError";
|
|
6719
|
+
}
|
|
6720
|
+
};
|
|
6721
|
+
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
6722
|
+
var DeclarationRefusedError = class extends RecordsError {
|
|
6723
|
+
constructor(detail) {
|
|
6724
|
+
super("declaration-refused", detail);
|
|
6725
|
+
this.name = "DeclarationRefusedError";
|
|
6726
|
+
}
|
|
6727
|
+
};
|
|
6703
6728
|
/**
|
|
6704
|
-
*
|
|
6705
|
-
*
|
|
6706
|
-
*
|
|
6707
|
-
* hub-routed — the hub instance answers for every node), so fields whose
|
|
6708
|
-
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
6709
|
-
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
6710
|
-
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
6711
|
-
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
6712
|
-
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
6713
|
-
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
6714
|
-
*
|
|
6715
|
-
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
6716
|
-
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
6717
|
-
* schema and routes reads/writes through these helpers.
|
|
6718
|
-
*
|
|
6719
|
-
* ## No bare-key fallback — deliberate
|
|
6720
|
-
*
|
|
6721
|
-
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
6722
|
-
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
6723
|
-
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
6724
|
-
* the store is invisible to every node, hub included, so one node's
|
|
6725
|
-
* selection can never leak onto another. (This generalizes the
|
|
6726
|
-
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
6727
|
-
* arbitrary set of per-node field keys.)
|
|
6728
|
-
*
|
|
6729
|
-
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
6730
|
-
* LEAF module: import it via its deep path, never from the root barrel.
|
|
6731
|
-
*/
|
|
6732
|
-
/**
|
|
6733
|
-
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
6734
|
-
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
6735
|
-
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
6736
|
-
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
6737
|
-
*/
|
|
6738
|
-
function normalizeNodeId(raw) {
|
|
6739
|
-
if (raw === void 0 || raw === null || raw === "") return "hub";
|
|
6740
|
-
const slashIdx = raw.indexOf("/");
|
|
6741
|
-
if (slashIdx < 0) return raw;
|
|
6742
|
-
const bare = raw.slice(0, slashIdx);
|
|
6743
|
-
return bare === "" ? "hub" : bare;
|
|
6744
|
-
}
|
|
6745
|
-
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
6746
|
-
function nodeScopedKey(base, nodeId) {
|
|
6747
|
-
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
6748
|
-
}
|
|
6749
|
-
/**
|
|
6750
|
-
* Read a node's value for a per-node field from the raw shared store:
|
|
6751
|
-
* the node-scoped key when present, otherwise `undefined`.
|
|
6752
|
-
* Deliberately NO bare-key fallback (see module doc) — the caller lets the
|
|
6753
|
-
* schema `default` win on `undefined`.
|
|
6729
|
+
* The link primitive's declaration half (D1013 rule 5): what a link field names and how a kind
|
|
6730
|
+
* records it. Split from `instance-link.ts` so `RecordIntegrationInstances` can read the links of
|
|
6731
|
+
* its kind without importing the builders that import it.
|
|
6754
6732
|
*/
|
|
6755
|
-
|
|
6756
|
-
|
|
6733
|
+
/** The body field of a link: the id of the instance it names; the target rides in the field meta. */
|
|
6734
|
+
function linkField(target) {
|
|
6735
|
+
return string().meta({ link: target });
|
|
6757
6736
|
}
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
* patch is not mutated.
|
|
6764
|
-
*/
|
|
6765
|
-
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
6766
|
-
const out = {};
|
|
6767
|
-
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
6768
|
-
return out;
|
|
6737
|
+
function linkTargetOf(meta) {
|
|
6738
|
+
if (typeof meta !== "object" || meta === null) return void 0;
|
|
6739
|
+
const link = Reflect.get(meta, "link");
|
|
6740
|
+
const parsed = LinkTargetSchema.safeParse(link);
|
|
6741
|
+
return parsed.success ? parsed.data : void 0;
|
|
6769
6742
|
}
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
const out = {};
|
|
6786
|
-
for (const [key, value] of Object.entries(store)) {
|
|
6787
|
-
if (key.includes("@")) continue;
|
|
6788
|
-
if (perNodeKeys.has(key)) continue;
|
|
6789
|
-
out[key] = value;
|
|
6790
|
-
}
|
|
6791
|
-
for (const base of perNodeKeys) {
|
|
6792
|
-
const value = readNodeValue(store, base, nodeId);
|
|
6793
|
-
if (value !== void 0) out[base] = value;
|
|
6743
|
+
var LinkTargetSchema = object({
|
|
6744
|
+
cap: string().min(1),
|
|
6745
|
+
kind: string().min(1).optional()
|
|
6746
|
+
});
|
|
6747
|
+
/** The links a kind declares, read from the meta of its body fields. */
|
|
6748
|
+
function linksOfKind(kind) {
|
|
6749
|
+
const schema = kind.schema;
|
|
6750
|
+
if (!(schema instanceof ZodObject)) return [];
|
|
6751
|
+
const links = [];
|
|
6752
|
+
for (const [field, fieldSchema] of Object.entries(schema.shape)) {
|
|
6753
|
+
const to = linkTargetOf(globalRegistry.get(fieldSchema));
|
|
6754
|
+
if (to !== void 0) links.push({
|
|
6755
|
+
field,
|
|
6756
|
+
to
|
|
6757
|
+
});
|
|
6794
6758
|
}
|
|
6795
|
-
return
|
|
6759
|
+
return links;
|
|
6796
6760
|
}
|
|
6797
|
-
/** Every scope, in the order the guard and the docs list them. */
|
|
6798
|
-
var SCOPED_SETTINGS_SCOPES = [
|
|
6799
|
-
"cluster",
|
|
6800
|
-
"device-defaults",
|
|
6801
|
-
"node"
|
|
6802
|
-
];
|
|
6803
6761
|
/**
|
|
6804
6762
|
* The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
|
|
6805
6763
|
*
|
|
@@ -6934,6 +6892,643 @@ function parseSecretRef(ref) {
|
|
|
6934
6892
|
fieldPath
|
|
6935
6893
|
};
|
|
6936
6894
|
}
|
|
6895
|
+
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
6896
|
+
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
6897
|
+
var RECORD_DATABASES = ["settings", "events"];
|
|
6898
|
+
/** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
|
|
6899
|
+
var RECORD_CLASSES = [
|
|
6900
|
+
"config",
|
|
6901
|
+
"ledger",
|
|
6902
|
+
"audit",
|
|
6903
|
+
"mirror",
|
|
6904
|
+
"ephemeral"
|
|
6905
|
+
];
|
|
6906
|
+
var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
6907
|
+
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
6908
|
+
var RECORD_BATCH_MAX = 1e3;
|
|
6909
|
+
var RECORD_QUERY_MAX = 1e3;
|
|
6910
|
+
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
6911
|
+
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
6912
|
+
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
6913
|
+
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
6914
|
+
/**
|
|
6915
|
+
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
6916
|
+
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
6917
|
+
* (`auth.accessToken`, `headers[].value`).
|
|
6918
|
+
*
|
|
6919
|
+
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
6920
|
+
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
6921
|
+
* key releases exactly that key's secret.
|
|
6922
|
+
*
|
|
6923
|
+
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
6924
|
+
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
6925
|
+
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
6926
|
+
* leaf names its element: `headers[X-Api].value`.
|
|
6927
|
+
*
|
|
6928
|
+
* Pure and browser-safe. Nothing here mutates: every transform returns a new value.
|
|
6929
|
+
*/
|
|
6930
|
+
/** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
|
|
6931
|
+
function parseSecretPath(path) {
|
|
6932
|
+
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
6933
|
+
return path.split(".").map((raw) => {
|
|
6934
|
+
const each = raw.endsWith("[]");
|
|
6935
|
+
const map = raw.endsWith("{}");
|
|
6936
|
+
const key = each || map ? raw.slice(0, -2) : raw;
|
|
6937
|
+
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
6938
|
+
return {
|
|
6939
|
+
key,
|
|
6940
|
+
each,
|
|
6941
|
+
map
|
|
6942
|
+
};
|
|
6943
|
+
});
|
|
6944
|
+
}
|
|
6945
|
+
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
6946
|
+
function secretArrayPrefixes(path) {
|
|
6947
|
+
const segments = parseSecretPath(path);
|
|
6948
|
+
const prefixes = [];
|
|
6949
|
+
const walked = [];
|
|
6950
|
+
for (const segment of segments) {
|
|
6951
|
+
walked.push(segment.key);
|
|
6952
|
+
if (segment.each) prefixes.push(walked.join("."));
|
|
6953
|
+
}
|
|
6954
|
+
return prefixes;
|
|
6955
|
+
}
|
|
6956
|
+
function isRecord$6(value) {
|
|
6957
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6958
|
+
}
|
|
6959
|
+
function elementId(element, idKey, declared, prefix) {
|
|
6960
|
+
const id = isRecord$6(element) ? element[idKey] : void 0;
|
|
6961
|
+
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`);
|
|
6962
|
+
return id;
|
|
6963
|
+
}
|
|
6964
|
+
/**
|
|
6965
|
+
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
6966
|
+
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
6967
|
+
* result is a new body, `data` is untouched.
|
|
6968
|
+
*/
|
|
6969
|
+
var REMOVE_LEAF = Symbol("remove-leaf");
|
|
6970
|
+
function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
|
|
6971
|
+
if (!isRecord$6(node)) return node;
|
|
6972
|
+
const segment = segments[index];
|
|
6973
|
+
if (segment === void 0) return node;
|
|
6974
|
+
if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
|
|
6975
|
+
const child = node[segment.key];
|
|
6976
|
+
const keys = [...walkedKeys, segment.key];
|
|
6977
|
+
const last = index === segments.length - 1;
|
|
6978
|
+
if (segment.each) {
|
|
6979
|
+
if (!Array.isArray(child)) return node;
|
|
6980
|
+
const prefix = keys.join(".");
|
|
6981
|
+
const idKey = arrayKeys[prefix];
|
|
6982
|
+
if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
|
|
6983
|
+
const mapped = child.map((element) => {
|
|
6984
|
+
const id = elementId(element, idKey, declared, prefix);
|
|
6985
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
|
|
6986
|
+
return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
|
|
6987
|
+
});
|
|
6988
|
+
return {
|
|
6989
|
+
...node,
|
|
6990
|
+
[segment.key]: mapped
|
|
6991
|
+
};
|
|
6992
|
+
}
|
|
6993
|
+
if (segment.map) {
|
|
6994
|
+
if (!isRecord$6(child)) return node;
|
|
6995
|
+
const kept = Object.entries(child).map(([mapKey, value]) => {
|
|
6996
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
|
|
6997
|
+
if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
|
|
6998
|
+
return [mapKey, visit({
|
|
6999
|
+
declared,
|
|
7000
|
+
concrete,
|
|
7001
|
+
value
|
|
7002
|
+
})];
|
|
7003
|
+
}).filter(([, value]) => value !== REMOVE_LEAF);
|
|
7004
|
+
return {
|
|
7005
|
+
...node,
|
|
7006
|
+
[segment.key]: Object.fromEntries(kept)
|
|
7007
|
+
};
|
|
7008
|
+
}
|
|
7009
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
7010
|
+
if (last) {
|
|
7011
|
+
const replacement = visit({
|
|
7012
|
+
declared,
|
|
7013
|
+
concrete,
|
|
7014
|
+
value: child
|
|
7015
|
+
});
|
|
7016
|
+
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
7017
|
+
return {
|
|
7018
|
+
...node,
|
|
7019
|
+
[segment.key]: replacement
|
|
7020
|
+
};
|
|
7021
|
+
}
|
|
7022
|
+
return {
|
|
7023
|
+
...node,
|
|
7024
|
+
[segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
|
|
7025
|
+
};
|
|
7026
|
+
}
|
|
7027
|
+
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
7028
|
+
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
7029
|
+
let current = data;
|
|
7030
|
+
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
7031
|
+
return current;
|
|
7032
|
+
}
|
|
7033
|
+
/**
|
|
7034
|
+
* The keychain collection name a kind's secrets live under. Prefixed so a
|
|
7035
|
+
* record's refs never collide with the refs a legacy collection of the same name
|
|
7036
|
+
* already holds during an adoption.
|
|
7037
|
+
*/
|
|
7038
|
+
function recordSecretCollection(kind) {
|
|
7039
|
+
return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
|
|
7040
|
+
}
|
|
7041
|
+
/** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
|
|
7042
|
+
function recordSecretRef(owner, kind, rowId, concretePath) {
|
|
7043
|
+
return buildSecretRef({
|
|
7044
|
+
owner,
|
|
7045
|
+
scope: {
|
|
7046
|
+
kind: "row",
|
|
7047
|
+
collection: recordSecretCollection(kind),
|
|
7048
|
+
rowId
|
|
7049
|
+
},
|
|
7050
|
+
fieldPath: concretePath
|
|
7051
|
+
});
|
|
7052
|
+
}
|
|
7053
|
+
/**
|
|
7054
|
+
* A stored secret, as an admin read shows it: a VIEW naming the row's own
|
|
7055
|
+
* keychain ref (`set: true`), never the value and no longer the bare redaction
|
|
7056
|
+
* token. The form hands it to the secret field, which reveals the value by ref
|
|
7057
|
+
* through the audited `keychain-admin.reveal`; sent back untouched it keeps the
|
|
7058
|
+
* stored secret (the records door reads a view as KEEP).
|
|
7059
|
+
*
|
|
7060
|
+
* ONE implementation for the entries service and for every addon that serves
|
|
7061
|
+
* its own instances (`RecordIntegrationInstances`).
|
|
7062
|
+
*/
|
|
7063
|
+
function isRecord$5(value) {
|
|
7064
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7065
|
+
}
|
|
7066
|
+
function secretViewsOf(owner, kind, id, decl, data) {
|
|
7067
|
+
if (decl.secretPaths.length === 0) return data;
|
|
7068
|
+
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
7069
|
+
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
7070
|
+
return {
|
|
7071
|
+
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
7072
|
+
v: 1,
|
|
7073
|
+
set: true
|
|
7074
|
+
};
|
|
7075
|
+
});
|
|
7076
|
+
return isRecord$5(shown) ? shown : data;
|
|
7077
|
+
}
|
|
7078
|
+
/** The most instances one addon lists (an integrations page, not a table). */
|
|
7079
|
+
var INSTANCES_LIST_MAX = 1e3;
|
|
7080
|
+
/**
|
|
7081
|
+
* The ONE reader of an instance's switch (D996): an absent field means on, so a row written
|
|
7082
|
+
* before the field existed needs no migration. Every consumer of an instance body asks this.
|
|
7083
|
+
*/
|
|
7084
|
+
function isInstanceEnabled(body) {
|
|
7085
|
+
return body.enabled !== false;
|
|
7086
|
+
}
|
|
7087
|
+
/** The body key of the switch; only {@link RecordIntegrationInstances.setInstanceEnabled} writes it. */
|
|
7088
|
+
var SWITCH_KEY = "enabled";
|
|
7089
|
+
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
7090
|
+
function topLevelSecretKeys(paths) {
|
|
7091
|
+
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
7092
|
+
}
|
|
7093
|
+
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
7094
|
+
function secretMapKeys(paths) {
|
|
7095
|
+
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
7096
|
+
}
|
|
7097
|
+
/**
|
|
7098
|
+
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
7099
|
+
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
7100
|
+
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
7101
|
+
*/
|
|
7102
|
+
function secretMapPatch(value) {
|
|
7103
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
7104
|
+
const out = {};
|
|
7105
|
+
for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
|
|
7106
|
+
else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
|
|
7107
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
7108
|
+
}
|
|
7109
|
+
var RecordIntegrationInstances = class {
|
|
7110
|
+
records;
|
|
7111
|
+
kind;
|
|
7112
|
+
hooks;
|
|
7113
|
+
handle;
|
|
7114
|
+
secretKeys;
|
|
7115
|
+
secretMaps;
|
|
7116
|
+
nameField;
|
|
7117
|
+
switchListeners = /* @__PURE__ */ new Set();
|
|
7118
|
+
constructor(records, kind, hooks) {
|
|
7119
|
+
this.records = records;
|
|
7120
|
+
this.kind = kind;
|
|
7121
|
+
this.hooks = hooks;
|
|
7122
|
+
this.handle = records.kind(kind);
|
|
7123
|
+
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
7124
|
+
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
7125
|
+
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
7126
|
+
}
|
|
7127
|
+
/**
|
|
7128
|
+
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
7129
|
+
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
7130
|
+
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
7131
|
+
*/
|
|
7132
|
+
async readResolved(id) {
|
|
7133
|
+
try {
|
|
7134
|
+
const record = await this.handle.getResolved(id);
|
|
7135
|
+
return record === null ? null : {
|
|
7136
|
+
id,
|
|
7137
|
+
body: record.data,
|
|
7138
|
+
enabled: isInstanceEnabled(record.data),
|
|
7139
|
+
secrets: "resolved"
|
|
7140
|
+
};
|
|
7141
|
+
} catch (err) {
|
|
7142
|
+
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
7143
|
+
const stored = await this.handle.get(id);
|
|
7144
|
+
if (stored === null) return null;
|
|
7145
|
+
return {
|
|
7146
|
+
id,
|
|
7147
|
+
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
7148
|
+
enabled: isInstanceEnabled(stored.data),
|
|
7149
|
+
secrets: "unavailable"
|
|
7150
|
+
};
|
|
7151
|
+
}
|
|
7152
|
+
}
|
|
7153
|
+
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
7154
|
+
async getResolved(id) {
|
|
7155
|
+
return (await this.readResolved(id))?.body ?? null;
|
|
7156
|
+
}
|
|
7157
|
+
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
7158
|
+
async listResolved() {
|
|
7159
|
+
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
7160
|
+
const out = [];
|
|
7161
|
+
for (const record of page.records) {
|
|
7162
|
+
const read = await this.readResolved(record.id);
|
|
7163
|
+
if (read !== null) out.push(read);
|
|
7164
|
+
}
|
|
7165
|
+
return out;
|
|
7166
|
+
}
|
|
7167
|
+
viewOf(record) {
|
|
7168
|
+
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
7169
|
+
const rawName = record.data[this.nameField];
|
|
7170
|
+
const kind = this.hooks.kindOf?.(record.data);
|
|
7171
|
+
const health = this.hooks.health?.(record.data, record.id);
|
|
7172
|
+
return {
|
|
7173
|
+
id: record.id,
|
|
7174
|
+
name: typeof rawName === "string" ? rawName : record.id,
|
|
7175
|
+
configured: this.hooks.configured(record.data),
|
|
7176
|
+
enabled: isInstanceEnabled(record.data),
|
|
7177
|
+
formValues: shown,
|
|
7178
|
+
...kind !== void 0 ? { kind } : {},
|
|
7179
|
+
...health?.status !== void 0 ? { status: health.status } : {},
|
|
7180
|
+
...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
|
|
7181
|
+
};
|
|
7182
|
+
}
|
|
7183
|
+
describe = async () => {
|
|
7184
|
+
const declared = linksOfKind(this.kind);
|
|
7185
|
+
const links = this.hooks.description.links !== void 0 || declared.length === 0 ? {} : { links: declared.map((link) => ({
|
|
7186
|
+
kind: this.kind.name,
|
|
7187
|
+
field: link.field,
|
|
7188
|
+
to: link.to
|
|
7189
|
+
})) };
|
|
7190
|
+
return {
|
|
7191
|
+
...this.hooks.description,
|
|
7192
|
+
...links,
|
|
7193
|
+
...this.hooks.mintId === void 0 ? {} : { mintsId: true }
|
|
7194
|
+
};
|
|
7195
|
+
};
|
|
7196
|
+
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
7197
|
+
listInstances = async () => {
|
|
7198
|
+
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
7199
|
+
};
|
|
7200
|
+
getInstance = async ({ id }) => {
|
|
7201
|
+
const record = await this.handle.get(id);
|
|
7202
|
+
return record === null ? null : this.viewOf(record);
|
|
7203
|
+
};
|
|
7204
|
+
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
7205
|
+
createInstance = async ({ id, name, kind, values }) => {
|
|
7206
|
+
const minted = id ?? this.hooks.mintId?.({
|
|
7207
|
+
name,
|
|
7208
|
+
...kind !== void 0 ? { kind } : {}
|
|
7209
|
+
});
|
|
7210
|
+
if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
|
|
7211
|
+
await this.handle.put({
|
|
7212
|
+
id: minted,
|
|
7213
|
+
data: this.hooks.initialBody(name, kind)
|
|
7214
|
+
}, { ifRev: 0 });
|
|
7215
|
+
const patch = this.patchOf(values ?? {});
|
|
7216
|
+
if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
|
|
7217
|
+
await this.hooks.onChanged?.(minted, "created");
|
|
7218
|
+
return { id: minted };
|
|
7219
|
+
};
|
|
7220
|
+
updateInstance = async ({ id, name, values }) => {
|
|
7221
|
+
const patch = this.patchOf(values);
|
|
7222
|
+
if (name !== void 0) patch[this.nameField] = name;
|
|
7223
|
+
await this.handle.patch(id, patch);
|
|
7224
|
+
await this.hooks.onChanged?.(id, "updated");
|
|
7225
|
+
return { ok: true };
|
|
7226
|
+
};
|
|
7227
|
+
/** The record patch a form `values` object means: secrets kept, cleared or replaced. */
|
|
7228
|
+
patchOf(values) {
|
|
7229
|
+
const patch = {};
|
|
7230
|
+
for (const [key, value] of Object.entries(values)) {
|
|
7231
|
+
if (value === void 0) continue;
|
|
7232
|
+
if (key === "enabled") continue;
|
|
7233
|
+
if (this.secretMaps.has(key)) {
|
|
7234
|
+
const entries = secretMapPatch(value);
|
|
7235
|
+
if (entries !== null) patch[key] = entries;
|
|
7236
|
+
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
7237
|
+
else if (isSecretClear(value)) patch[key] = null;
|
|
7238
|
+
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
7239
|
+
}
|
|
7240
|
+
return patch;
|
|
7241
|
+
}
|
|
7242
|
+
/**
|
|
7243
|
+
* Listen to the switch of ANY instance of this helper (in the process that serves it). The
|
|
7244
|
+
* durable replacement of the `integration.enabled` / `integration.disabled` events (D8): the
|
|
7245
|
+
* addon reconciles from the record, whichever way it flipped.
|
|
7246
|
+
*/
|
|
7247
|
+
onSwitched(listener) {
|
|
7248
|
+
this.switchListeners.add(listener);
|
|
7249
|
+
}
|
|
7250
|
+
/**
|
|
7251
|
+
* The ONE writer of the switch (D996, D1014): the record body's `enabled`, for every role. A
|
|
7252
|
+
* configured thing is an instance, so an id with no record yet (a default integration that was
|
|
7253
|
+
* never configured) gets its record from `initialBody` before the switch is written.
|
|
7254
|
+
*/
|
|
7255
|
+
setInstanceEnabled = async ({ id, enabled }) => {
|
|
7256
|
+
if (await this.handle.get(id) === null) await this.handle.put({
|
|
7257
|
+
id,
|
|
7258
|
+
data: this.hooks.initialBody(id)
|
|
7259
|
+
}, { ifRev: 0 });
|
|
7260
|
+
await this.handle.patch(id, { [SWITCH_KEY]: enabled });
|
|
7261
|
+
await this.hooks.onChanged?.(id, "enabled");
|
|
7262
|
+
for (const listener of this.switchListeners) await listener(id, enabled);
|
|
7263
|
+
return { ok: true };
|
|
7264
|
+
};
|
|
7265
|
+
/** The row and its keychain refs go together (the records door). */
|
|
7266
|
+
deleteInstance = async ({ id }) => {
|
|
7267
|
+
await this.handle.delete(id);
|
|
7268
|
+
await this.hooks.onChanged?.(id, "deleted");
|
|
7269
|
+
return { ok: true };
|
|
7270
|
+
};
|
|
7271
|
+
testInstance = async (input) => {
|
|
7272
|
+
if (this.hooks.test === void 0) return {
|
|
7273
|
+
success: false,
|
|
7274
|
+
status: "unsupported",
|
|
7275
|
+
error: "This integration declares no connection test"
|
|
7276
|
+
};
|
|
7277
|
+
return this.hooks.test(input);
|
|
7278
|
+
};
|
|
7279
|
+
/** The flat provider object to hand to `registerProvider`. */
|
|
7280
|
+
toProvider() {
|
|
7281
|
+
return {
|
|
7282
|
+
describe: this.describe,
|
|
7283
|
+
instanceFormSchema: this.instanceFormSchema,
|
|
7284
|
+
listInstances: this.listInstances,
|
|
7285
|
+
getInstance: this.getInstance,
|
|
7286
|
+
createInstance: this.createInstance,
|
|
7287
|
+
updateInstance: this.updateInstance,
|
|
7288
|
+
setInstanceEnabled: this.setInstanceEnabled,
|
|
7289
|
+
deleteInstance: this.deleteInstance,
|
|
7290
|
+
testInstance: this.testInstance
|
|
7291
|
+
};
|
|
7292
|
+
}
|
|
7293
|
+
};
|
|
7294
|
+
/**
|
|
7295
|
+
* The one-switch migration (epic #440, step 3). An integration's on/off state used to live in the
|
|
7296
|
+
* registry's `enabled` column for a device addon; it now lives only in the instance record's
|
|
7297
|
+
* body (`enabled`, D1007 superseded). This moves a registry `enabled = false` into the body, once.
|
|
7298
|
+
*
|
|
7299
|
+
* For every registry row of the addon that is OFF:
|
|
7300
|
+
* - no record under its id: the record is created from `initialBody(name)` with `enabled: false`
|
|
7301
|
+
* (a default integration that never had settings, Reolink's among them);
|
|
7302
|
+
* - a record whose body states no `enabled`: `enabled: false` is written into it;
|
|
7303
|
+
* - a record that already states `enabled` (either way) is the newer truth and is left alone.
|
|
7304
|
+
* A row that is ON writes nothing: an absent field reads as on. A rerun finds every off row with
|
|
7305
|
+
* a stated switch and does nothing, so nothing switched off comes back on and nothing switched on
|
|
7306
|
+
* goes off. The registry column itself is neither read afterwards nor written; its drop is step 5.
|
|
7307
|
+
*
|
|
7308
|
+
* It runs in the addon process, BEFORE the addon registers its `integration-instances` provider,
|
|
7309
|
+
* which is also why `integrations.list` still answers the stored column at that point.
|
|
7310
|
+
*/
|
|
7311
|
+
function registrySwitchToBodyId(addonId, date) {
|
|
7312
|
+
return `${addonId}/${date}-registry-switch-to-body`;
|
|
7313
|
+
}
|
|
7314
|
+
async function moveRegistrySwitchToBody(ports, spec) {
|
|
7315
|
+
const rows = await ports.listIntegrations(spec.addonId);
|
|
7316
|
+
let created = 0;
|
|
7317
|
+
let switched = 0;
|
|
7318
|
+
let kept = 0;
|
|
7319
|
+
for (const row of rows) {
|
|
7320
|
+
if (row.enabled) continue;
|
|
7321
|
+
const body = await ports.readBody(row.id);
|
|
7322
|
+
if (body === null) {
|
|
7323
|
+
if (await ports.createRecord(row.id, {
|
|
7324
|
+
...spec.initialBody(row.name),
|
|
7325
|
+
["enabled"]: false
|
|
7326
|
+
}) === "created") created += 1;
|
|
7327
|
+
else kept += 1;
|
|
7328
|
+
continue;
|
|
7329
|
+
}
|
|
7330
|
+
if ("enabled" in body) {
|
|
7331
|
+
kept += 1;
|
|
7332
|
+
continue;
|
|
7333
|
+
}
|
|
7334
|
+
await ports.switchOff(row.id);
|
|
7335
|
+
switched += 1;
|
|
7336
|
+
}
|
|
7337
|
+
const summary = {
|
|
7338
|
+
integrations: rows.length,
|
|
7339
|
+
off: rows.filter((r) => !r.enabled).length,
|
|
7340
|
+
created,
|
|
7341
|
+
switched,
|
|
7342
|
+
kept
|
|
7343
|
+
};
|
|
7344
|
+
return created === 0 && switched === 0 ? {
|
|
7345
|
+
outcome: "already-done",
|
|
7346
|
+
summary
|
|
7347
|
+
} : {
|
|
7348
|
+
outcome: "done",
|
|
7349
|
+
summary
|
|
7350
|
+
};
|
|
7351
|
+
}
|
|
7352
|
+
/** A migration entry: an addon states its kind and how a new body starts, nothing else. */
|
|
7353
|
+
function registrySwitchToBodyMigration(spec) {
|
|
7354
|
+
return {
|
|
7355
|
+
meta: {
|
|
7356
|
+
id: registrySwitchToBodyId(spec.addonId, spec.date),
|
|
7357
|
+
owner: spec.addonId,
|
|
7358
|
+
level: "addon-state",
|
|
7359
|
+
seq: spec.seq,
|
|
7360
|
+
dependsOn: [],
|
|
7361
|
+
store: "settings",
|
|
7362
|
+
scope: "cluster",
|
|
7363
|
+
onFailure: "block-owner",
|
|
7364
|
+
bodyKind: "procedure",
|
|
7365
|
+
description: "Move the registry enabled flag of every switched-off integration into its instance record body, creating the record when there is none",
|
|
7366
|
+
fixtureMark: "enabled"
|
|
7367
|
+
},
|
|
7368
|
+
procedure: (ports) => moveRegistrySwitchToBody(ports, {
|
|
7369
|
+
addonId: spec.addonId,
|
|
7370
|
+
initialBody: spec.initialBody
|
|
7371
|
+
})
|
|
7372
|
+
};
|
|
7373
|
+
}
|
|
7374
|
+
/** The hub and records sides of {@link registrySwitchToBodyMigration}. */
|
|
7375
|
+
function registrySwitchPortsOver(deps) {
|
|
7376
|
+
const handle = deps.records.kind({
|
|
7377
|
+
name: deps.kind.name,
|
|
7378
|
+
declaration: deps.kind.declaration,
|
|
7379
|
+
schema: record(string(), unknown())
|
|
7380
|
+
});
|
|
7381
|
+
return {
|
|
7382
|
+
listIntegrations: async (addonId) => (await deps.api.list()).filter((i) => i.addonId === addonId).map((i) => ({
|
|
7383
|
+
id: i.id,
|
|
7384
|
+
name: i.name,
|
|
7385
|
+
enabled: i.enabled !== false
|
|
7386
|
+
})),
|
|
7387
|
+
readBody: async (id) => (await handle.get(id))?.data ?? null,
|
|
7388
|
+
createRecord: async (id, body) => {
|
|
7389
|
+
if (await handle.get(id) !== null) return "exists";
|
|
7390
|
+
await handle.put({
|
|
7391
|
+
id,
|
|
7392
|
+
data: body
|
|
7393
|
+
}, { ifRev: 0 });
|
|
7394
|
+
return "created";
|
|
7395
|
+
},
|
|
7396
|
+
switchOff: async (id) => {
|
|
7397
|
+
await handle.patch(id, { [SWITCH_KEY]: false });
|
|
7398
|
+
}
|
|
7399
|
+
};
|
|
7400
|
+
}
|
|
7401
|
+
/**
|
|
7402
|
+
* Build a {@link DurableState} over a single store key. Transport-agnostic:
|
|
7403
|
+
* `read`/`write` are the addon-store or device-store accessors. The whole
|
|
7404
|
+
* validated value round-trips on every read/write — the schema is the
|
|
7405
|
+
* single source of truth for what is persisted, so no hand-listed field
|
|
7406
|
+
* set can drop a key on save.
|
|
7407
|
+
*/
|
|
7408
|
+
function createDurableState(deps) {
|
|
7409
|
+
const get = async () => {
|
|
7410
|
+
const raw = (await deps.read())[deps.key];
|
|
7411
|
+
if (raw === void 0) return deps.fallback;
|
|
7412
|
+
const parsed = deps.schema.safeParse(raw);
|
|
7413
|
+
if (!parsed.success) {
|
|
7414
|
+
deps.onParseError?.(deps.key, parsed.error);
|
|
7415
|
+
return deps.fallback;
|
|
7416
|
+
}
|
|
7417
|
+
return parsed.data;
|
|
7418
|
+
};
|
|
7419
|
+
const set = async (next) => {
|
|
7420
|
+
const validated = deps.schema.parse(next);
|
|
7421
|
+
await deps.write({ [deps.key]: validated });
|
|
7422
|
+
};
|
|
7423
|
+
const update = async (fn) => {
|
|
7424
|
+
await set(fn(await get()));
|
|
7425
|
+
};
|
|
7426
|
+
return {
|
|
7427
|
+
get,
|
|
7428
|
+
set,
|
|
7429
|
+
update
|
|
7430
|
+
};
|
|
7431
|
+
}
|
|
7432
|
+
/**
|
|
7433
|
+
* Per-node scoping for the shared addon-settings blob.
|
|
7434
|
+
*
|
|
7435
|
+
* An addon's settings store is hub-central (the `addon-settings` cap is
|
|
7436
|
+
* hub-routed — the hub instance answers for every node), so fields whose
|
|
7437
|
+
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
7438
|
+
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
7439
|
+
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
7440
|
+
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
7441
|
+
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
7442
|
+
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
7443
|
+
*
|
|
7444
|
+
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
7445
|
+
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
7446
|
+
* schema and routes reads/writes through these helpers.
|
|
7447
|
+
*
|
|
7448
|
+
* ## No bare-key fallback — deliberate
|
|
7449
|
+
*
|
|
7450
|
+
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
7451
|
+
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
7452
|
+
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
7453
|
+
* the store is invisible to every node, hub included, so one node's
|
|
7454
|
+
* selection can never leak onto another. (This generalizes the
|
|
7455
|
+
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
7456
|
+
* arbitrary set of per-node field keys.)
|
|
7457
|
+
*
|
|
7458
|
+
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
7459
|
+
* LEAF module: import it via its deep path, never from the root barrel.
|
|
7460
|
+
*/
|
|
7461
|
+
/**
|
|
7462
|
+
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
7463
|
+
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
7464
|
+
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
7465
|
+
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
7466
|
+
*/
|
|
7467
|
+
function normalizeNodeId(raw) {
|
|
7468
|
+
if (raw === void 0 || raw === null || raw === "") return "hub";
|
|
7469
|
+
const slashIdx = raw.indexOf("/");
|
|
7470
|
+
if (slashIdx < 0) return raw;
|
|
7471
|
+
const bare = raw.slice(0, slashIdx);
|
|
7472
|
+
return bare === "" ? "hub" : bare;
|
|
7473
|
+
}
|
|
7474
|
+
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
7475
|
+
function nodeScopedKey(base, nodeId) {
|
|
7476
|
+
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
7477
|
+
}
|
|
7478
|
+
/**
|
|
7479
|
+
* Read a node's value for a per-node field from the raw shared store:
|
|
7480
|
+
* the node-scoped key when present, otherwise `undefined`.
|
|
7481
|
+
* Deliberately NO bare-key fallback (see module doc) — the caller lets the
|
|
7482
|
+
* schema `default` win on `undefined`.
|
|
7483
|
+
*/
|
|
7484
|
+
function readNodeValue(store, base, nodeId) {
|
|
7485
|
+
return store[nodeScopedKey(base, nodeId)];
|
|
7486
|
+
}
|
|
7487
|
+
/**
|
|
7488
|
+
* Re-map a UI/settings patch so every bare perNode field persists under the
|
|
7489
|
+
* TARGET node's scoped key; all other keys pass through unchanged. Used on
|
|
7490
|
+
* the write path so a save for one node never clobbers another node's value
|
|
7491
|
+
* (and the bare key is never written). Returns a new object — the input
|
|
7492
|
+
* patch is not mutated.
|
|
7493
|
+
*/
|
|
7494
|
+
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
7495
|
+
const out = {};
|
|
7496
|
+
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
7497
|
+
return out;
|
|
7498
|
+
}
|
|
7499
|
+
/**
|
|
7500
|
+
* Project the raw shared store onto the bare schema keys for ONE node so a
|
|
7501
|
+
* UI schema (whose field keys are bare) hydrates from that node's own
|
|
7502
|
+
* values:
|
|
7503
|
+
*
|
|
7504
|
+
* - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
|
|
7505
|
+
* - Every bare perNode key is dropped from the pass-through (a stray bare
|
|
7506
|
+
* legacy key must never hydrate any node — no bare fallback).
|
|
7507
|
+
* - THIS node's effective value ({@link readNodeValue}) is then laid onto
|
|
7508
|
+
* each bare perNode key; when the node has no scoped key the bare key is
|
|
7509
|
+
* left ABSENT so the field's schema `default` wins.
|
|
7510
|
+
*
|
|
7511
|
+
* Returns a new object — the input store is not mutated.
|
|
7512
|
+
*/
|
|
7513
|
+
function projectStore(store, perNodeKeys, nodeId) {
|
|
7514
|
+
const out = {};
|
|
7515
|
+
for (const [key, value] of Object.entries(store)) {
|
|
7516
|
+
if (key.includes("@")) continue;
|
|
7517
|
+
if (perNodeKeys.has(key)) continue;
|
|
7518
|
+
out[key] = value;
|
|
7519
|
+
}
|
|
7520
|
+
for (const base of perNodeKeys) {
|
|
7521
|
+
const value = readNodeValue(store, base, nodeId);
|
|
7522
|
+
if (value !== void 0) out[base] = value;
|
|
7523
|
+
}
|
|
7524
|
+
return out;
|
|
7525
|
+
}
|
|
7526
|
+
/** Every scope, in the order the guard and the docs list them. */
|
|
7527
|
+
var SCOPED_SETTINGS_SCOPES = [
|
|
7528
|
+
"cluster",
|
|
7529
|
+
"device-defaults",
|
|
7530
|
+
"node"
|
|
7531
|
+
];
|
|
6937
7532
|
/** A write to a secret path could not be stored in the keychain, so it was refused. */
|
|
6938
7533
|
var KeychainWriteRefusedError = class extends Error {
|
|
6939
7534
|
fieldPath;
|
|
@@ -6944,7 +7539,7 @@ var KeychainWriteRefusedError = class extends Error {
|
|
|
6944
7539
|
}
|
|
6945
7540
|
};
|
|
6946
7541
|
var KEEP = { kind: "keep" };
|
|
6947
|
-
function isRecord$
|
|
7542
|
+
function isRecord$4(value) {
|
|
6948
7543
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6949
7544
|
}
|
|
6950
7545
|
function defaultMintId() {
|
|
@@ -6957,7 +7552,7 @@ function collectSecretMarkerRefs(value, out = []) {
|
|
|
6957
7552
|
return out;
|
|
6958
7553
|
}
|
|
6959
7554
|
if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
|
|
6960
|
-
else if (isRecord$
|
|
7555
|
+
else if (isRecord$4(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
|
|
6961
7556
|
return out;
|
|
6962
7557
|
}
|
|
6963
7558
|
async function storedValueEquals(secrets, marker, candidate) {
|
|
@@ -7012,7 +7607,7 @@ function rowId(row, idKey) {
|
|
|
7012
7607
|
return null;
|
|
7013
7608
|
}
|
|
7014
7609
|
async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
7015
|
-
const storedRows = Array.isArray(stored) ? stored.filter(isRecord$
|
|
7610
|
+
const storedRows = Array.isArray(stored) ? stored.filter(isRecord$4) : [];
|
|
7016
7611
|
if (!Array.isArray(incoming)) {
|
|
7017
7612
|
ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
|
|
7018
7613
|
return {
|
|
@@ -7028,7 +7623,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
7028
7623
|
const kept = /* @__PURE__ */ new Set();
|
|
7029
7624
|
const rows = [];
|
|
7030
7625
|
for (const row of incoming) {
|
|
7031
|
-
if (!isRecord$
|
|
7626
|
+
if (!isRecord$4(row)) {
|
|
7032
7627
|
rows.push(row);
|
|
7033
7628
|
continue;
|
|
7034
7629
|
}
|
|
@@ -7053,7 +7648,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
|
|
|
7053
7648
|
case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
|
|
7054
7649
|
case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
|
|
7055
7650
|
case "object": {
|
|
7056
|
-
if (!isRecord$
|
|
7651
|
+
if (!isRecord$4(incoming)) {
|
|
7057
7652
|
if (incoming === void 0) return KEEP;
|
|
7058
7653
|
ctx.deletes.push(...collectSecretMarkerRefs(stored));
|
|
7059
7654
|
return {
|
|
@@ -7061,7 +7656,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
|
|
|
7061
7656
|
value: incoming
|
|
7062
7657
|
};
|
|
7063
7658
|
}
|
|
7064
|
-
const storedObj = isRecord$
|
|
7659
|
+
const storedObj = isRecord$4(stored) ? stored : {};
|
|
7065
7660
|
return {
|
|
7066
7661
|
kind: "value",
|
|
7067
7662
|
value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
|
|
@@ -7184,7 +7779,7 @@ async function resolveSecretMarkers(value, secrets, options = {}) {
|
|
|
7184
7779
|
value: items
|
|
7185
7780
|
};
|
|
7186
7781
|
}
|
|
7187
|
-
if (isRecord$
|
|
7782
|
+
if (isRecord$4(v)) {
|
|
7188
7783
|
const out = {};
|
|
7189
7784
|
for (const [k, child] of Object.entries(v)) {
|
|
7190
7785
|
const s = substitute(child);
|
|
@@ -7216,7 +7811,7 @@ var SecretOverwriteRefusedError = class extends Error {
|
|
|
7216
7811
|
this.name = "SecretOverwriteRefusedError";
|
|
7217
7812
|
}
|
|
7218
7813
|
};
|
|
7219
|
-
function isRecord$
|
|
7814
|
+
function isRecord$3(value) {
|
|
7220
7815
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7221
7816
|
}
|
|
7222
7817
|
function resolvedValue(pass, marker) {
|
|
@@ -7245,7 +7840,7 @@ function inArray(pass, incoming, stored) {
|
|
|
7245
7840
|
return incoming.map((item, index) => {
|
|
7246
7841
|
const twin = stored[index];
|
|
7247
7842
|
if (isSecretMarker(twin)) return typeof item === "string" && item === resolvedValue(pass, twin) ? twin : item;
|
|
7248
|
-
if (isRecord$
|
|
7843
|
+
if (isRecord$3(item) && isRecord$3(twin)) return inArrayRow(pass, item, twin);
|
|
7249
7844
|
if (Array.isArray(item) && Array.isArray(twin)) return inArray(pass, item, twin);
|
|
7250
7845
|
return item;
|
|
7251
7846
|
});
|
|
@@ -7256,7 +7851,7 @@ function inArrayRow(pass, incoming, stored) {
|
|
|
7256
7851
|
const twin = stored[key];
|
|
7257
7852
|
if (isSecretMarker(twin)) {
|
|
7258
7853
|
if (typeof value === "string" && value === resolvedValue(pass, twin)) out[key] = twin;
|
|
7259
|
-
} else if (isRecord$
|
|
7854
|
+
} else if (isRecord$3(value) && isRecord$3(twin)) out[key] = inArrayRow(pass, value, twin);
|
|
7260
7855
|
else if (Array.isArray(value) && Array.isArray(twin)) out[key] = inArray(pass, value, twin);
|
|
7261
7856
|
}
|
|
7262
7857
|
return out;
|
|
@@ -7264,7 +7859,7 @@ function inArrayRow(pass, incoming, stored) {
|
|
|
7264
7859
|
async function walk(pass, incoming, stored) {
|
|
7265
7860
|
if (isSecretMarker(stored)) return atMarker(pass, incoming, stored);
|
|
7266
7861
|
if (Array.isArray(incoming) && Array.isArray(stored)) return inArray(pass, incoming, stored);
|
|
7267
|
-
if (!isRecord$
|
|
7862
|
+
if (!isRecord$3(incoming) || !isRecord$3(stored)) return incoming;
|
|
7268
7863
|
const out = { ...incoming };
|
|
7269
7864
|
for (const [key, value] of Object.entries(incoming)) out[key] = await walk(pass, value, stored[key]);
|
|
7270
7865
|
return out;
|
|
@@ -7295,7 +7890,7 @@ async function restoreUnchangedSecrets(input) {
|
|
|
7295
7890
|
function isJsonEqual(a, b) {
|
|
7296
7891
|
if (Object.is(a, b)) return true;
|
|
7297
7892
|
if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((v, i) => isJsonEqual(v, b[i]));
|
|
7298
|
-
if (isRecord$
|
|
7893
|
+
if (isRecord$3(a) && isRecord$3(b)) {
|
|
7299
7894
|
const keys = Object.keys(a);
|
|
7300
7895
|
if (keys.length !== Object.keys(b).length) return false;
|
|
7301
7896
|
return keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && isJsonEqual(a[k], b[k]));
|
|
@@ -7319,7 +7914,7 @@ function markerKeysOf(blob, owner) {
|
|
|
7319
7914
|
}
|
|
7320
7915
|
function nodeFromStored(value, owner) {
|
|
7321
7916
|
if (isSecretMarker(value)) return isSecretRefOwnedBy(value.$secret, owner) ? { kind: "leaf" } : null;
|
|
7322
|
-
if (!isRecord$
|
|
7917
|
+
if (!isRecord$3(value)) return null;
|
|
7323
7918
|
const children = /* @__PURE__ */ new Map();
|
|
7324
7919
|
for (const [key, child] of Object.entries(value)) {
|
|
7325
7920
|
const node = nodeFromStored(child, owner);
|
|
@@ -7816,13 +8411,48 @@ var BaseAddon = class {
|
|
|
7816
8411
|
if (api === void 0) throw new Error(`${this.ctx.id}: the migration API is not available on this context`);
|
|
7817
8412
|
return this.runBound(sets.flatMap((set) => set.bind(api)), options);
|
|
7818
8413
|
}
|
|
7819
|
-
|
|
8414
|
+
/**
|
|
8415
|
+
* A device addon states its instance kind once, before its migrations run, and the one-switch
|
|
8416
|
+
* migration (registry `enabled` to the instance body, epic #440 step 3) joins whatever
|
|
8417
|
+
* catalogue the addon runs, in the SAME declaration (the engine replaces an owner's catalogue
|
|
8418
|
+
* on every declare).
|
|
8419
|
+
*/
|
|
8420
|
+
declareRegistrySwitch(spec) {
|
|
8421
|
+
this.registrySwitchSpec = spec;
|
|
8422
|
+
}
|
|
8423
|
+
registrySwitchSpec = null;
|
|
8424
|
+
registrySwitchBound() {
|
|
8425
|
+
const spec = this.registrySwitchSpec;
|
|
8426
|
+
if (spec === null) return [];
|
|
8427
|
+
const api = this.ctx.migrationApi;
|
|
8428
|
+
if (api === void 0) {
|
|
8429
|
+
this.ctx.logger.warn("the registry switch migration is skipped: the migration API is not available on this context");
|
|
8430
|
+
return [];
|
|
8431
|
+
}
|
|
8432
|
+
return migrationSet([registrySwitchToBodyMigration({
|
|
8433
|
+
addonId: this.ctx.id,
|
|
8434
|
+
date: "2026-11-06",
|
|
8435
|
+
seq: 1e3,
|
|
8436
|
+
initialBody: spec.initialBody
|
|
8437
|
+
})], (a) => registrySwitchPortsOver({
|
|
8438
|
+
api: integrationRowsApiOver(a),
|
|
8439
|
+
records: switchRecordsOverMigrationApi(a),
|
|
8440
|
+
kind: spec.kind
|
|
8441
|
+
})).bind(api);
|
|
8442
|
+
}
|
|
8443
|
+
async runBound(declared, options) {
|
|
8444
|
+
const added = this.registrySwitchBound();
|
|
8445
|
+
const migrations = [...declared, ...added];
|
|
8446
|
+
const phased = options?.only === void 0 || added.length === 0 ? options : {
|
|
8447
|
+
...options,
|
|
8448
|
+
only: [...options.only, ...added.map((m) => m.meta.id)]
|
|
8449
|
+
};
|
|
7820
8450
|
const api = this.ctx.api.migrations;
|
|
7821
8451
|
const report = await runAddonMigrations({
|
|
7822
8452
|
declareOwner: (input) => api.declareOwner.mutate(input),
|
|
7823
8453
|
startMigration: (input) => api.startMigration.mutate(input),
|
|
7824
8454
|
finishMigration: (input) => api.finishMigration.mutate(input)
|
|
7825
|
-
}, migrations, this.ctx.logger,
|
|
8455
|
+
}, migrations, this.ctx.logger, phased);
|
|
7826
8456
|
if (report.blockOwner.length > 0) throw new AddonMigrationsBlockedError(report.blockOwner);
|
|
7827
8457
|
return report;
|
|
7828
8458
|
}
|
|
@@ -8895,245 +9525,94 @@ function normalizeAddonInitResult(result) {
|
|
|
8895
9525
|
if (Array.isArray(result)) return { providers: result };
|
|
8896
9526
|
return result;
|
|
8897
9527
|
}
|
|
8898
|
-
|
|
8899
|
-
|
|
8900
|
-
|
|
8901
|
-
|
|
8902
|
-
detail;
|
|
8903
|
-
constructor(code, detail) {
|
|
8904
|
-
super(`${PREFIX}${code}: ${detail}`);
|
|
8905
|
-
this.name = "RecordsError";
|
|
8906
|
-
this.code = code;
|
|
8907
|
-
this.detail = detail;
|
|
8908
|
-
}
|
|
8909
|
-
};
|
|
8910
|
-
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
8911
|
-
var RecordSecretUnavailableError = class extends RecordsError {
|
|
8912
|
-
constructor(detail) {
|
|
8913
|
-
super("secret-unavailable", detail);
|
|
8914
|
-
this.name = "RecordSecretUnavailableError";
|
|
8915
|
-
}
|
|
8916
|
-
};
|
|
8917
|
-
var InvalidRecordError = class extends RecordsError {
|
|
8918
|
-
constructor(detail) {
|
|
8919
|
-
super("invalid-record", detail);
|
|
8920
|
-
this.name = "InvalidRecordError";
|
|
8921
|
-
}
|
|
8922
|
-
};
|
|
8923
|
-
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
8924
|
-
var DeclarationRefusedError = class extends RecordsError {
|
|
8925
|
-
constructor(detail) {
|
|
8926
|
-
super("declaration-refused", detail);
|
|
8927
|
-
this.name = "DeclarationRefusedError";
|
|
8928
|
-
}
|
|
8929
|
-
};
|
|
8930
|
-
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
8931
|
-
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
8932
|
-
var RECORD_DATABASES = ["settings", "events"];
|
|
8933
|
-
/** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
|
|
8934
|
-
var RECORD_CLASSES = [
|
|
8935
|
-
"config",
|
|
8936
|
-
"ledger",
|
|
8937
|
-
"audit",
|
|
8938
|
-
"mirror",
|
|
8939
|
-
"ephemeral"
|
|
8940
|
-
];
|
|
8941
|
-
var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
8942
|
-
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
8943
|
-
var RECORD_BATCH_MAX = 1e3;
|
|
8944
|
-
var RECORD_QUERY_MAX = 1e3;
|
|
8945
|
-
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
8946
|
-
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
8947
|
-
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
8948
|
-
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
9528
|
+
object({
|
|
9529
|
+
field: string().min(1),
|
|
9530
|
+
on: literal("advance")
|
|
9531
|
+
});
|
|
8949
9532
|
/**
|
|
8950
|
-
*
|
|
8951
|
-
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
8952
|
-
* (`auth.accessToken`, `headers[].value`).
|
|
8953
|
-
*
|
|
8954
|
-
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
8955
|
-
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
8956
|
-
* key releases exactly that key's secret.
|
|
9533
|
+
* Output schema shared by the contribution + live methods.
|
|
8957
9534
|
*
|
|
8958
|
-
*
|
|
8959
|
-
*
|
|
8960
|
-
*
|
|
8961
|
-
*
|
|
9535
|
+
* Mirrors the `ConfigUISchemaWithValues` shape (sections[] + optional
|
|
9536
|
+
* tabs[]) without importing from `../interfaces/config-ui.js` — a
|
|
9537
|
+
* concrete-but-lenient Zod object keeps tRPC output inference happy
|
|
9538
|
+
* (using `z.unknown()` here collapses unrelated router branches to
|
|
9539
|
+
* `unknown` when the generator re-inlines the huge AppRouter type).
|
|
8962
9540
|
*
|
|
8963
|
-
*
|
|
8964
|
-
|
|
8965
|
-
|
|
8966
|
-
function parseSecretPath(path) {
|
|
8967
|
-
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
8968
|
-
return path.split(".").map((raw) => {
|
|
8969
|
-
const each = raw.endsWith("[]");
|
|
8970
|
-
const map = raw.endsWith("{}");
|
|
8971
|
-
const key = each || map ? raw.slice(0, -2) : raw;
|
|
8972
|
-
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
8973
|
-
return {
|
|
8974
|
-
key,
|
|
8975
|
-
each,
|
|
8976
|
-
map
|
|
8977
|
-
};
|
|
8978
|
-
});
|
|
8979
|
-
}
|
|
8980
|
-
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
8981
|
-
function secretArrayPrefixes(path) {
|
|
8982
|
-
const segments = parseSecretPath(path);
|
|
8983
|
-
const prefixes = [];
|
|
8984
|
-
const walked = [];
|
|
8985
|
-
for (const segment of segments) {
|
|
8986
|
-
walked.push(segment.key);
|
|
8987
|
-
if (segment.each) prefixes.push(walked.join("."));
|
|
8988
|
-
}
|
|
8989
|
-
return prefixes;
|
|
8990
|
-
}
|
|
8991
|
-
function isRecord$4(value) {
|
|
8992
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8993
|
-
}
|
|
8994
|
-
function elementId(element, idKey, declared, prefix) {
|
|
8995
|
-
const id = isRecord$4(element) ? element[idKey] : void 0;
|
|
8996
|
-
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`);
|
|
8997
|
-
return id;
|
|
8998
|
-
}
|
|
8999
|
-
/**
|
|
9000
|
-
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
9001
|
-
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
9002
|
-
* result is a new body, `data` is untouched.
|
|
9541
|
+
* `.passthrough()` on sections/fields accepts whatever FormBuilder
|
|
9542
|
+
* extensions the caller adds (showWhen, displayScale, …) without
|
|
9543
|
+
* rebuilding every time a new field kind is introduced.
|
|
9003
9544
|
*/
|
|
9004
|
-
var
|
|
9005
|
-
|
|
9006
|
-
|
|
9007
|
-
|
|
9008
|
-
|
|
9009
|
-
|
|
9010
|
-
|
|
9011
|
-
|
|
9012
|
-
|
|
9013
|
-
|
|
9014
|
-
|
|
9015
|
-
|
|
9016
|
-
|
|
9017
|
-
|
|
9018
|
-
|
|
9019
|
-
|
|
9020
|
-
|
|
9021
|
-
|
|
9022
|
-
|
|
9023
|
-
|
|
9024
|
-
|
|
9025
|
-
|
|
9026
|
-
|
|
9027
|
-
|
|
9028
|
-
|
|
9029
|
-
|
|
9030
|
-
|
|
9031
|
-
|
|
9032
|
-
|
|
9033
|
-
|
|
9034
|
-
|
|
9035
|
-
|
|
9036
|
-
|
|
9037
|
-
|
|
9038
|
-
|
|
9039
|
-
|
|
9040
|
-
...node,
|
|
9041
|
-
[segment.key]: Object.fromEntries(kept)
|
|
9042
|
-
};
|
|
9043
|
-
}
|
|
9044
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
9045
|
-
if (last) {
|
|
9046
|
-
const replacement = visit({
|
|
9047
|
-
declared,
|
|
9048
|
-
concrete,
|
|
9049
|
-
value: child
|
|
9050
|
-
});
|
|
9051
|
-
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
9052
|
-
return {
|
|
9053
|
-
...node,
|
|
9054
|
-
[segment.key]: replacement
|
|
9055
|
-
};
|
|
9056
|
-
}
|
|
9545
|
+
var ContributionSectionSchema = object({
|
|
9546
|
+
id: string(),
|
|
9547
|
+
title: string(),
|
|
9548
|
+
description: string().optional(),
|
|
9549
|
+
style: _enum(["card", "accordion"]).optional(),
|
|
9550
|
+
defaultCollapsed: boolean().optional(),
|
|
9551
|
+
columns: union([
|
|
9552
|
+
literal(1),
|
|
9553
|
+
literal(2),
|
|
9554
|
+
literal(3),
|
|
9555
|
+
literal(4)
|
|
9556
|
+
]).optional(),
|
|
9557
|
+
tab: string().optional(),
|
|
9558
|
+
location: _enum([
|
|
9559
|
+
"settings",
|
|
9560
|
+
"top-tab",
|
|
9561
|
+
"hero"
|
|
9562
|
+
]).optional(),
|
|
9563
|
+
order: number().optional(),
|
|
9564
|
+
fields: array(any())
|
|
9565
|
+
});
|
|
9566
|
+
object({
|
|
9567
|
+
tabs: array(object({
|
|
9568
|
+
id: string(),
|
|
9569
|
+
label: string(),
|
|
9570
|
+
icon: string(),
|
|
9571
|
+
order: number().optional()
|
|
9572
|
+
})).optional(),
|
|
9573
|
+
sections: array(ContributionSectionSchema)
|
|
9574
|
+
}).nullable();
|
|
9575
|
+
object({ deviceId: number() }), object({ deviceId: number() }), object({
|
|
9576
|
+
deviceId: number(),
|
|
9577
|
+
patch: record(string(), unknown())
|
|
9578
|
+
}), object({ success: literal(true) });
|
|
9579
|
+
object({ deviceId: number() }), unknown().nullable();
|
|
9580
|
+
function method(input, output, options) {
|
|
9057
9581
|
return {
|
|
9058
|
-
|
|
9059
|
-
|
|
9582
|
+
input,
|
|
9583
|
+
output,
|
|
9584
|
+
kind: options?.kind ?? "query",
|
|
9585
|
+
...options?.auth !== void 0 ? { auth: options.auth } : {},
|
|
9586
|
+
...options?.access !== void 0 ? { access: options.access } : {},
|
|
9587
|
+
...options?.role !== void 0 ? { role: options.role } : {},
|
|
9588
|
+
...options?.caller !== void 0 ? { caller: options.caller } : {},
|
|
9589
|
+
timeoutMs: options?.timeoutMs
|
|
9060
9590
|
};
|
|
9061
9591
|
}
|
|
9062
|
-
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
9063
|
-
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
9064
|
-
let current = data;
|
|
9065
|
-
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
9066
|
-
return current;
|
|
9067
|
-
}
|
|
9068
9592
|
/**
|
|
9069
|
-
*
|
|
9070
|
-
*
|
|
9071
|
-
*
|
|
9593
|
+
* A wrapper/system-only method: served exclusively by the cap's system-level
|
|
9594
|
+
* provider (`InferProvider`), and OPTIONAL on `InferNativeProvider` so per-device
|
|
9595
|
+
* driver natives don't stub out a wrapper concern (e.g. a cross-device cache
|
|
9596
|
+
* overview). The `systemOnly: true` literal is what `InferNativeProvider` keys on.
|
|
9072
9597
|
*/
|
|
9073
|
-
function
|
|
9074
|
-
return
|
|
9075
|
-
|
|
9076
|
-
|
|
9077
|
-
|
|
9078
|
-
return buildSecretRef({
|
|
9079
|
-
owner,
|
|
9080
|
-
scope: {
|
|
9081
|
-
kind: "row",
|
|
9082
|
-
collection: recordSecretCollection(kind),
|
|
9083
|
-
rowId
|
|
9084
|
-
},
|
|
9085
|
-
fieldPath: concretePath
|
|
9086
|
-
});
|
|
9598
|
+
function systemMethod(input, output, options) {
|
|
9599
|
+
return {
|
|
9600
|
+
...method(input, output, options),
|
|
9601
|
+
systemOnly: true
|
|
9602
|
+
};
|
|
9087
9603
|
}
|
|
9088
9604
|
/**
|
|
9089
|
-
* A
|
|
9090
|
-
*
|
|
9091
|
-
*
|
|
9092
|
-
*
|
|
9093
|
-
* stored secret (the records door reads a view as KEEP).
|
|
9094
|
-
*
|
|
9095
|
-
* ONE implementation for the entries service and for every addon that serves
|
|
9096
|
-
* its own instances (`RecordIntegrationInstances`).
|
|
9605
|
+
* A method a SOURCE of a collection cap may legitimately not serve — OPTIONAL
|
|
9606
|
+
* on `InferProvider`. The `providerOptional: true` literal is what
|
|
9607
|
+
* `InferProvider` keys on; see {@link CapabilityMethodSchema.providerOptional}
|
|
9608
|
+
* for when this is the honest answer and when it is a soft stub.
|
|
9097
9609
|
*/
|
|
9098
|
-
function
|
|
9099
|
-
return
|
|
9100
|
-
|
|
9101
|
-
|
|
9102
|
-
|
|
9103
|
-
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
9104
|
-
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
9105
|
-
return {
|
|
9106
|
-
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
9107
|
-
v: 1,
|
|
9108
|
-
set: true
|
|
9109
|
-
};
|
|
9110
|
-
});
|
|
9111
|
-
return isRecord$3(shown) ? shown : data;
|
|
9610
|
+
function optionalMethod(input, output, options) {
|
|
9611
|
+
return {
|
|
9612
|
+
...method(input, output, options),
|
|
9613
|
+
providerOptional: true
|
|
9614
|
+
};
|
|
9112
9615
|
}
|
|
9113
|
-
/**
|
|
9114
|
-
* The share-view scope kinds a share-link token can carry. The hub mints
|
|
9115
|
-
* and validates them (`ShareViewGrantSchema` builds its
|
|
9116
|
-
* enum from this list); a data plane names the kinds it ACCEPTS in `share`.
|
|
9117
|
-
*/
|
|
9118
|
-
var SHARE_VIEW_KINDS = ["grid-view", "events-view"];
|
|
9119
|
-
/** The wire shape of {@link PeerBytesTicket} — see the type for what it is. */
|
|
9120
|
-
var PeerBytesTicketSchema = object({
|
|
9121
|
-
/** `http://127.0.0.1:<port>/<token>`. One `GET` takes it. */
|
|
9122
|
-
url: string().min(1),
|
|
9123
|
-
/**
|
|
9124
|
-
* The HOST node this URL means something on — the hub or a named agent,
|
|
9125
|
-
* never a runner. {@link AddonPeerBytes.open} compares it to its own and
|
|
9126
|
-
* refuses `cross-node` by name when they differ, without dialling.
|
|
9127
|
-
*/
|
|
9128
|
-
hostNodeId: string().min(1),
|
|
9129
|
-
expiresAtMs: number().int().nonnegative(),
|
|
9130
|
-
/**
|
|
9131
|
-
* What the producer DECLARED the body to be, when it knows — `null` when it
|
|
9132
|
-
* does not. Never `0` for unknown (D393): a consumer sizing a bound off this
|
|
9133
|
-
* must be able to tell "the producer did not say" from "the body is empty".
|
|
9134
|
-
*/
|
|
9135
|
-
declaredBytes: number().int().nonnegative().nullable()
|
|
9136
|
-
});
|
|
9137
9616
|
function defOf(schema) {
|
|
9138
9617
|
const zodBag = Reflect.get(schema, "_zod");
|
|
9139
9618
|
if (typeof zodBag !== "object" || zodBag === null) return {};
|
|
@@ -9363,6 +9842,7 @@ function defineRecordKinds(specs) {
|
|
|
9363
9842
|
function entryBody(shape) {
|
|
9364
9843
|
return object({
|
|
9365
9844
|
name: string().min(1),
|
|
9845
|
+
enabled: boolean().optional(),
|
|
9366
9846
|
...shape
|
|
9367
9847
|
});
|
|
9368
9848
|
}
|
|
@@ -9389,94 +9869,30 @@ function defineEntryKind(name, spec) {
|
|
|
9389
9869
|
if (defined === void 0) throw new DeclarationRefusedError(`entry kind "${name}" was not built`);
|
|
9390
9870
|
return defined;
|
|
9391
9871
|
}
|
|
9392
|
-
object({
|
|
9393
|
-
field: string().min(1),
|
|
9394
|
-
on: literal("advance")
|
|
9395
|
-
});
|
|
9396
9872
|
/**
|
|
9397
|
-
*
|
|
9398
|
-
*
|
|
9399
|
-
*
|
|
9400
|
-
* tabs[]) without importing from `../interfaces/config-ui.js` — a
|
|
9401
|
-
* concrete-but-lenient Zod object keeps tRPC output inference happy
|
|
9402
|
-
* (using `z.unknown()` here collapses unrelated router branches to
|
|
9403
|
-
* `unknown` when the generator re-inlines the huge AppRouter type).
|
|
9404
|
-
*
|
|
9405
|
-
* `.passthrough()` on sections/fields accepts whatever FormBuilder
|
|
9406
|
-
* extensions the caller adds (showWhen, displayScale, …) without
|
|
9407
|
-
* rebuilding every time a new field kind is introduced.
|
|
9873
|
+
* The share-view scope kinds a share-link token can carry. The hub mints
|
|
9874
|
+
* and validates them (`ShareViewGrantSchema` builds its
|
|
9875
|
+
* enum from this list); a data plane names the kinds it ACCEPTS in `share`.
|
|
9408
9876
|
*/
|
|
9409
|
-
var
|
|
9410
|
-
|
|
9411
|
-
|
|
9412
|
-
|
|
9413
|
-
|
|
9414
|
-
|
|
9415
|
-
|
|
9416
|
-
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
|
|
9427
|
-
order: number().optional(),
|
|
9428
|
-
fields: array(any())
|
|
9877
|
+
var SHARE_VIEW_KINDS = ["grid-view", "events-view"];
|
|
9878
|
+
/** The wire shape of {@link PeerBytesTicket} — see the type for what it is. */
|
|
9879
|
+
var PeerBytesTicketSchema = object({
|
|
9880
|
+
/** `http://127.0.0.1:<port>/<token>`. One `GET` takes it. */
|
|
9881
|
+
url: string().min(1),
|
|
9882
|
+
/**
|
|
9883
|
+
* The HOST node this URL means something on — the hub or a named agent,
|
|
9884
|
+
* never a runner. {@link AddonPeerBytes.open} compares it to its own and
|
|
9885
|
+
* refuses `cross-node` by name when they differ, without dialling.
|
|
9886
|
+
*/
|
|
9887
|
+
hostNodeId: string().min(1),
|
|
9888
|
+
expiresAtMs: number().int().nonnegative(),
|
|
9889
|
+
/**
|
|
9890
|
+
* What the producer DECLARED the body to be, when it knows — `null` when it
|
|
9891
|
+
* does not. Never `0` for unknown (D393): a consumer sizing a bound off this
|
|
9892
|
+
* must be able to tell "the producer did not say" from "the body is empty".
|
|
9893
|
+
*/
|
|
9894
|
+
declaredBytes: number().int().nonnegative().nullable()
|
|
9429
9895
|
});
|
|
9430
|
-
object({
|
|
9431
|
-
tabs: array(object({
|
|
9432
|
-
id: string(),
|
|
9433
|
-
label: string(),
|
|
9434
|
-
icon: string(),
|
|
9435
|
-
order: number().optional()
|
|
9436
|
-
})).optional(),
|
|
9437
|
-
sections: array(ContributionSectionSchema)
|
|
9438
|
-
}).nullable();
|
|
9439
|
-
object({ deviceId: number() }), object({ deviceId: number() }), object({
|
|
9440
|
-
deviceId: number(),
|
|
9441
|
-
patch: record(string(), unknown())
|
|
9442
|
-
}), object({ success: literal(true) });
|
|
9443
|
-
object({ deviceId: number() }), unknown().nullable();
|
|
9444
|
-
function method(input, output, options) {
|
|
9445
|
-
return {
|
|
9446
|
-
input,
|
|
9447
|
-
output,
|
|
9448
|
-
kind: options?.kind ?? "query",
|
|
9449
|
-
...options?.auth !== void 0 ? { auth: options.auth } : {},
|
|
9450
|
-
...options?.access !== void 0 ? { access: options.access } : {},
|
|
9451
|
-
...options?.role !== void 0 ? { role: options.role } : {},
|
|
9452
|
-
...options?.caller !== void 0 ? { caller: options.caller } : {},
|
|
9453
|
-
timeoutMs: options?.timeoutMs
|
|
9454
|
-
};
|
|
9455
|
-
}
|
|
9456
|
-
/**
|
|
9457
|
-
* A wrapper/system-only method: served exclusively by the cap's system-level
|
|
9458
|
-
* provider (`InferProvider`), and OPTIONAL on `InferNativeProvider` so per-device
|
|
9459
|
-
* driver natives don't stub out a wrapper concern (e.g. a cross-device cache
|
|
9460
|
-
* overview). The `systemOnly: true` literal is what `InferNativeProvider` keys on.
|
|
9461
|
-
*/
|
|
9462
|
-
function systemMethod(input, output, options) {
|
|
9463
|
-
return {
|
|
9464
|
-
...method(input, output, options),
|
|
9465
|
-
systemOnly: true
|
|
9466
|
-
};
|
|
9467
|
-
}
|
|
9468
|
-
/**
|
|
9469
|
-
* A method a SOURCE of a collection cap may legitimately not serve — OPTIONAL
|
|
9470
|
-
* on `InferProvider`. The `providerOptional: true` literal is what
|
|
9471
|
-
* `InferProvider` keys on; see {@link CapabilityMethodSchema.providerOptional}
|
|
9472
|
-
* for when this is the honest answer and when it is a soft stub.
|
|
9473
|
-
*/
|
|
9474
|
-
function optionalMethod(input, output, options) {
|
|
9475
|
-
return {
|
|
9476
|
-
...method(input, output, options),
|
|
9477
|
-
providerOptional: true
|
|
9478
|
-
};
|
|
9479
|
-
}
|
|
9480
9896
|
var READING_QUANTITIES = [
|
|
9481
9897
|
"temperature",
|
|
9482
9898
|
"pressure",
|
|
@@ -10055,7 +10471,6 @@ var CAP_NAMES = Object.freeze([
|
|
|
10055
10471
|
"climate-control",
|
|
10056
10472
|
"color",
|
|
10057
10473
|
"composer",
|
|
10058
|
-
"connection-test",
|
|
10059
10474
|
"connectivity",
|
|
10060
10475
|
"consumables",
|
|
10061
10476
|
"contact",
|
|
@@ -11202,6 +11617,10 @@ Object.freeze({
|
|
|
11202
11617
|
"all",
|
|
11203
11618
|
"one"
|
|
11204
11619
|
]
|
|
11620
|
+
},
|
|
11621
|
+
{
|
|
11622
|
+
"path": "positionUpdatedAt",
|
|
11623
|
+
"valueType": "number"
|
|
11205
11624
|
}
|
|
11206
11625
|
],
|
|
11207
11626
|
"meter": [{
|
|
@@ -11456,22 +11875,6 @@ Object.freeze({
|
|
|
11456
11875
|
"path": "pumpRunning",
|
|
11457
11876
|
"valueType": "boolean"
|
|
11458
11877
|
},
|
|
11459
|
-
{
|
|
11460
|
-
"path": "lastDrink",
|
|
11461
|
-
"valueType": "number"
|
|
11462
|
-
},
|
|
11463
|
-
{
|
|
11464
|
-
"path": "currentHourDrink",
|
|
11465
|
-
"valueType": "number"
|
|
11466
|
-
},
|
|
11467
|
-
{
|
|
11468
|
-
"path": "last24hDrink",
|
|
11469
|
-
"valueType": "number"
|
|
11470
|
-
},
|
|
11471
|
-
{
|
|
11472
|
-
"path": "todayDrink",
|
|
11473
|
-
"valueType": "number"
|
|
11474
|
-
},
|
|
11475
11878
|
{
|
|
11476
11879
|
"path": "error",
|
|
11477
11880
|
"valueType": "string"
|
|
@@ -12037,6 +12440,59 @@ Object.freeze({
|
|
|
12037
12440
|
}
|
|
12038
12441
|
]
|
|
12039
12442
|
});
|
|
12443
|
+
Object.freeze({
|
|
12444
|
+
"actions": { "run": 363e4 },
|
|
12445
|
+
"audio-analyzer": { "classify": 3e4 },
|
|
12446
|
+
"custom-model-registry": { "importModelBundle": 18e5 },
|
|
12447
|
+
"database-snapshot": { "writeSnapshot": 18e5 },
|
|
12448
|
+
"device-manager": {
|
|
12449
|
+
"migrateDevice": 72e4,
|
|
12450
|
+
"runDiscoverySweep": 12e4
|
|
12451
|
+
},
|
|
12452
|
+
"device-provider": { "reloadDevice": 18e4 },
|
|
12453
|
+
"llm": {
|
|
12454
|
+
"generate": 6e5,
|
|
12455
|
+
"generateVision": 6e5,
|
|
12456
|
+
"testProfile": 6e5
|
|
12457
|
+
},
|
|
12458
|
+
"llm-runtime": {
|
|
12459
|
+
"complete": 6e5,
|
|
12460
|
+
"completeApple": 6e5,
|
|
12461
|
+
"ensureStarted": 6e5,
|
|
12462
|
+
"installModel": 36e5
|
|
12463
|
+
},
|
|
12464
|
+
"local-network": { "scanNetwork": 9e4 },
|
|
12465
|
+
"model-convert": { "convert": 6e5 },
|
|
12466
|
+
"pipeline-analytics": {
|
|
12467
|
+
"addRetrainFrameFromRecording": 6e4,
|
|
12468
|
+
"offerRetrainArchive": 12e4,
|
|
12469
|
+
"proposeRetrainAnnotationsWithLlm": 18e4,
|
|
12470
|
+
"resolveRetrainTrainingCorpus": 6e4,
|
|
12471
|
+
"writeRetrainArchive": 36e5
|
|
12472
|
+
},
|
|
12473
|
+
"server-management": { "applyServerUpdate": 96e4 },
|
|
12474
|
+
"terminal-session": { "pullOutput": 15e3 },
|
|
12475
|
+
"training": {
|
|
12476
|
+
"canaryResult": 12e4,
|
|
12477
|
+
"cancelJob": 12e4,
|
|
12478
|
+
"planJob": 6e4,
|
|
12479
|
+
"registerResult": 18e5,
|
|
12480
|
+
"rollbackCanary": 12e4,
|
|
12481
|
+
"startJob": 12e4,
|
|
12482
|
+
"startJobBatch": 12e4
|
|
12483
|
+
},
|
|
12484
|
+
"training-provider": {
|
|
12485
|
+
"cancelJob": 6e4,
|
|
12486
|
+
"cleanupJob": 3e5,
|
|
12487
|
+
"getJob": 6e4,
|
|
12488
|
+
"listJobEvents": 6e4,
|
|
12489
|
+
"listJobs": 12e4,
|
|
12490
|
+
"offerArtifact": 3e5,
|
|
12491
|
+
"readResult": 3e5,
|
|
12492
|
+
"submitJob": 18e5,
|
|
12493
|
+
"uploadDataset": 72e5
|
|
12494
|
+
}
|
|
12495
|
+
});
|
|
12040
12496
|
object({
|
|
12041
12497
|
code: string().regex(/^[a-z][a-z0-9-]*(\.[a-z0-9-]+)+$/),
|
|
12042
12498
|
params: record(string(), union([string(), number()])).optional()
|
|
@@ -12056,7 +12512,7 @@ function userError(code, params, englishFallback) {
|
|
|
12056
12512
|
return new CamstackError(code, params, englishFallback);
|
|
12057
12513
|
}
|
|
12058
12514
|
//#endregion
|
|
12059
|
-
//#region ../types/dist/composition-
|
|
12515
|
+
//#region ../types/dist/composition-BmBHuDTQ.mjs
|
|
12060
12516
|
/**
|
|
12061
12517
|
* The ffmpeg build every CamStack node downloads, per platform and arch.
|
|
12062
12518
|
*
|
|
@@ -12360,7 +12816,7 @@ var table = {
|
|
|
12360
12816
|
},
|
|
12361
12817
|
dwell: {
|
|
12362
12818
|
minArgs: 3,
|
|
12363
|
-
maxArgs:
|
|
12819
|
+
maxArgs: 4,
|
|
12364
12820
|
apply: () => {
|
|
12365
12821
|
throw new ExpressionEvalError("dwell: stateful evaluation context is required");
|
|
12366
12822
|
}
|
|
@@ -13520,254 +13976,6 @@ function buildCapturingReply(envelope) {
|
|
|
13520
13976
|
};
|
|
13521
13977
|
return wrapper;
|
|
13522
13978
|
}
|
|
13523
|
-
/**
|
|
13524
|
-
* The link primitive's declaration half (D1013 rule 5): what a link field names and how a kind
|
|
13525
|
-
* records it. Split from `instance-link.ts` so `RecordIntegrationInstances` can read the links of
|
|
13526
|
-
* its kind without importing the builders that import it.
|
|
13527
|
-
*/
|
|
13528
|
-
/** The body field of a link: the id of the instance it names; the target rides in the field meta. */
|
|
13529
|
-
function linkField(target) {
|
|
13530
|
-
return string().meta({ link: target });
|
|
13531
|
-
}
|
|
13532
|
-
function linkTargetOf(meta) {
|
|
13533
|
-
if (typeof meta !== "object" || meta === null) return void 0;
|
|
13534
|
-
const link = Reflect.get(meta, "link");
|
|
13535
|
-
const parsed = LinkTargetSchema.safeParse(link);
|
|
13536
|
-
return parsed.success ? parsed.data : void 0;
|
|
13537
|
-
}
|
|
13538
|
-
var LinkTargetSchema = object({
|
|
13539
|
-
cap: string().min(1),
|
|
13540
|
-
kind: string().min(1).optional()
|
|
13541
|
-
});
|
|
13542
|
-
/** The links a kind declares, read from the meta of its body fields. */
|
|
13543
|
-
function linksOfKind(kind) {
|
|
13544
|
-
const schema = kind.schema;
|
|
13545
|
-
if (!(schema instanceof ZodObject)) return [];
|
|
13546
|
-
const links = [];
|
|
13547
|
-
for (const [field, fieldSchema] of Object.entries(schema.shape)) {
|
|
13548
|
-
const to = linkTargetOf(globalRegistry.get(fieldSchema));
|
|
13549
|
-
if (to !== void 0) links.push({
|
|
13550
|
-
field,
|
|
13551
|
-
to
|
|
13552
|
-
});
|
|
13553
|
-
}
|
|
13554
|
-
return links;
|
|
13555
|
-
}
|
|
13556
|
-
/**
|
|
13557
|
-
* `RecordIntegrationInstances` - the `integration-instances` provider over ONE
|
|
13558
|
-
* entry kind, so an addon that holds a connection serves it in ~30 lines.
|
|
13559
|
-
*
|
|
13560
|
-
* Every instance is one record of the addon's own kind, keyed by the
|
|
13561
|
-
* `integrations` registry id. The records door does the secret work: a field the
|
|
13562
|
-
* kind marks `.meta({ secret: true })` is a keychain marker bound to the row, so
|
|
13563
|
-
* deleting the row deletes the secret, and one row's value is never another's.
|
|
13564
|
-
*
|
|
13565
|
-
* Patch rules for a secret (`updateInstance`): omitted, `''`, the redaction
|
|
13566
|
-
* token or the view the form was given KEEP the stored secret;
|
|
13567
|
-
* `{ $secretClear: true }` clears it; any other string replaces it.
|
|
13568
|
-
*/
|
|
13569
|
-
/** The most instances one addon lists (an integrations page, not a table). */
|
|
13570
|
-
var INSTANCES_LIST_MAX = 1e3;
|
|
13571
|
-
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
13572
|
-
function topLevelSecretKeys(paths) {
|
|
13573
|
-
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
13574
|
-
}
|
|
13575
|
-
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
13576
|
-
function secretMapKeys(paths) {
|
|
13577
|
-
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
13578
|
-
}
|
|
13579
|
-
/**
|
|
13580
|
-
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
13581
|
-
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
13582
|
-
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
13583
|
-
*/
|
|
13584
|
-
function secretMapPatch(value) {
|
|
13585
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
13586
|
-
const out = {};
|
|
13587
|
-
for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
|
|
13588
|
-
else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
|
|
13589
|
-
return Object.keys(out).length > 0 ? out : null;
|
|
13590
|
-
}
|
|
13591
|
-
/** Does the kind's body schema carry an `enabled` field? */
|
|
13592
|
-
function declaresEnabled(kind) {
|
|
13593
|
-
const json = toJSONSchema(kind.schema, {
|
|
13594
|
-
unrepresentable: "any",
|
|
13595
|
-
io: "input"
|
|
13596
|
-
});
|
|
13597
|
-
const properties = Reflect.get(json, "properties");
|
|
13598
|
-
return typeof properties === "object" && properties !== null && "enabled" in properties;
|
|
13599
|
-
}
|
|
13600
|
-
var RecordIntegrationInstances = class {
|
|
13601
|
-
records;
|
|
13602
|
-
kind;
|
|
13603
|
-
hooks;
|
|
13604
|
-
handle;
|
|
13605
|
-
secretKeys;
|
|
13606
|
-
secretMaps;
|
|
13607
|
-
nameField;
|
|
13608
|
-
/** The `integrations` registry owns the on/off switch (`role: devices`); the body has none. */
|
|
13609
|
-
registryOwnsEnabled;
|
|
13610
|
-
constructor(records, kind, hooks) {
|
|
13611
|
-
this.records = records;
|
|
13612
|
-
this.kind = kind;
|
|
13613
|
-
this.hooks = hooks;
|
|
13614
|
-
this.handle = records.kind(kind);
|
|
13615
|
-
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
13616
|
-
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
13617
|
-
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
13618
|
-
this.registryOwnsEnabled = hooks.description.role === "devices";
|
|
13619
|
-
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"`);
|
|
13620
|
-
}
|
|
13621
|
-
/**
|
|
13622
|
-
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
13623
|
-
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
13624
|
-
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
13625
|
-
*/
|
|
13626
|
-
async readResolved(id) {
|
|
13627
|
-
try {
|
|
13628
|
-
const record = await this.handle.getResolved(id);
|
|
13629
|
-
return record === null ? null : {
|
|
13630
|
-
id,
|
|
13631
|
-
body: record.data,
|
|
13632
|
-
enabled: record.data.enabled !== false,
|
|
13633
|
-
secrets: "resolved"
|
|
13634
|
-
};
|
|
13635
|
-
} catch (err) {
|
|
13636
|
-
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
13637
|
-
const stored = await this.handle.get(id);
|
|
13638
|
-
if (stored === null) return null;
|
|
13639
|
-
return {
|
|
13640
|
-
id,
|
|
13641
|
-
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
13642
|
-
enabled: stored.data.enabled !== false,
|
|
13643
|
-
secrets: "unavailable"
|
|
13644
|
-
};
|
|
13645
|
-
}
|
|
13646
|
-
}
|
|
13647
|
-
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
13648
|
-
async getResolved(id) {
|
|
13649
|
-
return (await this.readResolved(id))?.body ?? null;
|
|
13650
|
-
}
|
|
13651
|
-
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
13652
|
-
async listResolved() {
|
|
13653
|
-
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
13654
|
-
const out = [];
|
|
13655
|
-
for (const record of page.records) {
|
|
13656
|
-
const read = await this.readResolved(record.id);
|
|
13657
|
-
if (read !== null) out.push(read);
|
|
13658
|
-
}
|
|
13659
|
-
return out;
|
|
13660
|
-
}
|
|
13661
|
-
viewOf(record) {
|
|
13662
|
-
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
13663
|
-
const rawName = record.data[this.nameField];
|
|
13664
|
-
const kind = this.hooks.kindOf?.(record.data);
|
|
13665
|
-
const health = this.hooks.health?.(record.data, record.id);
|
|
13666
|
-
return {
|
|
13667
|
-
id: record.id,
|
|
13668
|
-
name: typeof rawName === "string" ? rawName : record.id,
|
|
13669
|
-
configured: this.hooks.configured(record.data),
|
|
13670
|
-
...this.registryOwnsEnabled ? {} : { enabled: record.data.enabled !== false },
|
|
13671
|
-
formValues: shown,
|
|
13672
|
-
...kind !== void 0 ? { kind } : {},
|
|
13673
|
-
...health?.status !== void 0 ? { status: health.status } : {},
|
|
13674
|
-
...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
|
|
13675
|
-
};
|
|
13676
|
-
}
|
|
13677
|
-
describe = async () => {
|
|
13678
|
-
const declared = linksOfKind(this.kind);
|
|
13679
|
-
const links = this.hooks.description.links !== void 0 || declared.length === 0 ? {} : { links: declared.map((link) => ({
|
|
13680
|
-
kind: this.kind.name,
|
|
13681
|
-
field: link.field,
|
|
13682
|
-
to: link.to
|
|
13683
|
-
})) };
|
|
13684
|
-
return {
|
|
13685
|
-
...this.hooks.description,
|
|
13686
|
-
...links,
|
|
13687
|
-
...this.hooks.mintId === void 0 ? {} : { mintsId: true }
|
|
13688
|
-
};
|
|
13689
|
-
};
|
|
13690
|
-
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
13691
|
-
listInstances = async () => {
|
|
13692
|
-
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
13693
|
-
};
|
|
13694
|
-
getInstance = async ({ id }) => {
|
|
13695
|
-
const record = await this.handle.get(id);
|
|
13696
|
-
return record === null ? null : this.viewOf(record);
|
|
13697
|
-
};
|
|
13698
|
-
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
13699
|
-
createInstance = async ({ id, name, kind, values }) => {
|
|
13700
|
-
const minted = id ?? this.hooks.mintId?.({
|
|
13701
|
-
name,
|
|
13702
|
-
...kind !== void 0 ? { kind } : {}
|
|
13703
|
-
});
|
|
13704
|
-
if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
|
|
13705
|
-
await this.handle.put({
|
|
13706
|
-
id: minted,
|
|
13707
|
-
data: this.hooks.initialBody(name, kind)
|
|
13708
|
-
}, { ifRev: 0 });
|
|
13709
|
-
const patch = this.patchOf(values ?? {});
|
|
13710
|
-
if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
|
|
13711
|
-
await this.hooks.onChanged?.(minted, "created");
|
|
13712
|
-
return { id: minted };
|
|
13713
|
-
};
|
|
13714
|
-
updateInstance = async ({ id, name, values }) => {
|
|
13715
|
-
const patch = this.patchOf(values);
|
|
13716
|
-
if (name !== void 0) patch[this.nameField] = name;
|
|
13717
|
-
await this.handle.patch(id, patch);
|
|
13718
|
-
await this.hooks.onChanged?.(id, "updated");
|
|
13719
|
-
return { ok: true };
|
|
13720
|
-
};
|
|
13721
|
-
/** The record patch a form `values` object means: secrets kept, cleared or replaced. */
|
|
13722
|
-
patchOf(values) {
|
|
13723
|
-
const patch = {};
|
|
13724
|
-
for (const [key, value] of Object.entries(values)) {
|
|
13725
|
-
if (value === void 0) continue;
|
|
13726
|
-
if (this.secretMaps.has(key)) {
|
|
13727
|
-
const entries = secretMapPatch(value);
|
|
13728
|
-
if (entries !== null) patch[key] = entries;
|
|
13729
|
-
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
13730
|
-
else if (isSecretClear(value)) patch[key] = null;
|
|
13731
|
-
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
13732
|
-
}
|
|
13733
|
-
return patch;
|
|
13734
|
-
}
|
|
13735
|
-
/** The switch lives in the record body; the addon is told so it applies it (D996). */
|
|
13736
|
-
setInstanceEnabled = async ({ id, enabled }) => {
|
|
13737
|
-
if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
|
|
13738
|
-
await this.handle.patch(id, { enabled });
|
|
13739
|
-
await this.hooks.onChanged?.(id, "enabled");
|
|
13740
|
-
return { ok: true };
|
|
13741
|
-
};
|
|
13742
|
-
/** The row and its keychain refs go together (the records door). */
|
|
13743
|
-
deleteInstance = async ({ id }) => {
|
|
13744
|
-
await this.handle.delete(id);
|
|
13745
|
-
await this.hooks.onChanged?.(id, "deleted");
|
|
13746
|
-
return { ok: true };
|
|
13747
|
-
};
|
|
13748
|
-
testInstance = async (input) => {
|
|
13749
|
-
if (this.hooks.test === void 0) return {
|
|
13750
|
-
success: false,
|
|
13751
|
-
status: "unsupported",
|
|
13752
|
-
error: "This integration declares no connection test"
|
|
13753
|
-
};
|
|
13754
|
-
return this.hooks.test(input);
|
|
13755
|
-
};
|
|
13756
|
-
/** The flat provider object to hand to `registerProvider`. */
|
|
13757
|
-
toProvider() {
|
|
13758
|
-
return {
|
|
13759
|
-
describe: this.describe,
|
|
13760
|
-
instanceFormSchema: this.instanceFormSchema,
|
|
13761
|
-
listInstances: this.listInstances,
|
|
13762
|
-
getInstance: this.getInstance,
|
|
13763
|
-
createInstance: this.createInstance,
|
|
13764
|
-
updateInstance: this.updateInstance,
|
|
13765
|
-
setInstanceEnabled: this.setInstanceEnabled,
|
|
13766
|
-
deleteInstance: this.deleteInstance,
|
|
13767
|
-
testInstance: this.testInstance
|
|
13768
|
-
};
|
|
13769
|
-
}
|
|
13770
|
-
};
|
|
13771
13979
|
/** No part holds the id a call named. */
|
|
13772
13980
|
var UnknownInstanceError = class extends Error {
|
|
13773
13981
|
instanceId;
|
|
@@ -13797,6 +14005,17 @@ function composeInstanceKinds(parts, base) {
|
|
|
13797
14005
|
if (part === void 0) throw new UnknownInstanceKindError(kindId);
|
|
13798
14006
|
return part;
|
|
13799
14007
|
};
|
|
14008
|
+
/**
|
|
14009
|
+
* The part a DRAFT test runs on. A named kind is that kind; an unnamed one is the provider's only
|
|
14010
|
+
* testable kind. Several testable kinds and none named is a typed refusal that lists them, never a throw.
|
|
14011
|
+
*/
|
|
14012
|
+
const draftPart = (kindId) => {
|
|
14013
|
+
if (kindId !== void 0) return parts.find((candidate) => candidate.kind.id === kindId) ?? { error: `Unknown instance kind '${kindId}'` };
|
|
14014
|
+
const testable = parts.filter((part) => part.kind.canTest !== false);
|
|
14015
|
+
const only = testable.length === 1 ? testable[0] : parts.length === 1 ? parts[0] : void 0;
|
|
14016
|
+
if (only !== void 0) return only;
|
|
14017
|
+
return { error: `This provider has several kinds: name one of ${(testable.length > 0 ? testable : parts).map((part) => part.kind.id).join(", ")}` };
|
|
14018
|
+
};
|
|
13800
14019
|
const holderOf = async (id) => {
|
|
13801
14020
|
for (const part of parts) if (await part.provider.getInstance({ id }) !== null) return part;
|
|
13802
14021
|
throw new UnknownInstanceError(id);
|
|
@@ -13832,7 +14051,13 @@ function composeInstanceKinds(parts, base) {
|
|
|
13832
14051
|
setInstanceEnabled: async (input) => (await holderOf(input.id)).provider.setInstanceEnabled(input),
|
|
13833
14052
|
deleteInstance: async (input) => (await holderOf(input.id)).provider.deleteInstance(input),
|
|
13834
14053
|
testInstance: async (input) => {
|
|
13835
|
-
const
|
|
14054
|
+
const resolved = input.id === null ? draftPart(input.kind) : await holderOf(input.id);
|
|
14055
|
+
if ("error" in resolved) return {
|
|
14056
|
+
success: false,
|
|
14057
|
+
status: "inconclusive",
|
|
14058
|
+
error: resolved.error
|
|
14059
|
+
};
|
|
14060
|
+
const test = resolved.provider.testInstance;
|
|
13836
14061
|
if (test === void 0) return {
|
|
13837
14062
|
success: false,
|
|
13838
14063
|
status: "inconclusive",
|
|
@@ -13842,6 +14067,432 @@ function composeInstanceKinds(parts, base) {
|
|
|
13842
14067
|
}
|
|
13843
14068
|
};
|
|
13844
14069
|
}
|
|
14070
|
+
/**
|
|
14071
|
+
* notification-output — canonical, capability-gated notification delivery.
|
|
14072
|
+
*
|
|
14073
|
+
* Apprise-derived model (see
|
|
14074
|
+
* `docs/superpowers/specs/2026-07-03-notification-output-notifier-matrix.md`):
|
|
14075
|
+
* callers emit ONE canonical `Notification`; each provider declares a
|
|
14076
|
+
* per-kind capability descriptor (`TargetKind`), and the pure degrade
|
|
14077
|
+
* engine (`@camstack/types` `prepareNotification`) transcodes / degrades the
|
|
14078
|
+
* message to what the kind supports — callers never special-case a service.
|
|
14079
|
+
*
|
|
14080
|
+
* DESIGN DECISIONS (locked):
|
|
14081
|
+
* - Target CRUD lives on THIS cap (`upsertTarget` / `deleteTarget` /
|
|
14082
|
+
* `setTargetEnabled`), each provider persisting via the `settings-store`
|
|
14083
|
+
* cap. Rationale: the admin UI needs one uniform surface across the
|
|
14084
|
+
* notifiers addon AND the HA addon; the addon-`globalSettingsSchema`-array
|
|
14085
|
+
* alternative would fork the UI per addon and cannot host the
|
|
14086
|
+
* discovery→adopt flow.
|
|
14087
|
+
* - `listTargetKinds` / `listTargets` / `discoverTargets` return arrays →
|
|
14088
|
+
* the generated cap-mount auto-`concatCollection`-fans them across every
|
|
14089
|
+
* registered provider (notifiers addon + HA addon) so one catalog is
|
|
14090
|
+
* routable. `send` / `testTarget` / CRUD route to ONE provider by the
|
|
14091
|
+
* `addonId` the generated collection router extracts from the call input.
|
|
14092
|
+
* - `Attachment.bytes` is `Uint8Array`. Transport-safe: superjson (the tRPC
|
|
14093
|
+
* transformer) + UDS MsgPack both round-trip typed arrays — already used by
|
|
14094
|
+
* `storage` / `storage-provider` / `recording` caps over the same path. No
|
|
14095
|
+
* base64 fallback needed.
|
|
14096
|
+
*
|
|
14097
|
+
* TODO (deferred, closed-set change — separate decision): add
|
|
14098
|
+
* `providerKind: 'notify'` so notification providers surface on the unified
|
|
14099
|
+
* admin "Integrations" page.
|
|
14100
|
+
*/
|
|
14101
|
+
/**
|
|
14102
|
+
* Zentik-derived typed-media enum — the superset across every kind. Each
|
|
14103
|
+
* adapter picks what it supports and the degrade engine filters the rest.
|
|
14104
|
+
*/
|
|
14105
|
+
var AttachmentMediaTypeSchema = _enum([
|
|
14106
|
+
"image",
|
|
14107
|
+
"video",
|
|
14108
|
+
"gif",
|
|
14109
|
+
"audio",
|
|
14110
|
+
"icon"
|
|
14111
|
+
]);
|
|
14112
|
+
/**
|
|
14113
|
+
* A single attachment. Exactly one of `url` (remote source, most adapters
|
|
14114
|
+
* prefer this) or `bytes` (inline source; required for Pushover-style
|
|
14115
|
+
* bytes-only kinds) MUST be present — the degrade engine expresses a
|
|
14116
|
+
* url→bytes fetch as a `needsFetch` directive the adapter executes.
|
|
14117
|
+
*/
|
|
14118
|
+
var AttachmentSchema = object({
|
|
14119
|
+
mediaType: AttachmentMediaTypeSchema,
|
|
14120
|
+
url: string().optional(),
|
|
14121
|
+
bytes: _instanceof(Uint8Array).optional(),
|
|
14122
|
+
mime: string().optional(),
|
|
14123
|
+
name: string().optional()
|
|
14124
|
+
}).refine((a) => a.url !== void 0 || a.bytes !== void 0, { message: "Attachment requires either `url` or `bytes`" });
|
|
14125
|
+
var NotificationFormatSchema = _enum([
|
|
14126
|
+
"text",
|
|
14127
|
+
"markdown",
|
|
14128
|
+
"html"
|
|
14129
|
+
]);
|
|
14130
|
+
/**
|
|
14131
|
+
* The CLOSED icon vocabulary an action button may use.
|
|
14132
|
+
*
|
|
14133
|
+
* A closed set, not a free string, and that is the whole point: an arbitrary
|
|
14134
|
+
* icon name is one that ntfy renders, zentik silently drops, and nobody
|
|
14135
|
+
* notices — the same class of gap as a zone vocabulary nothing produced
|
|
14136
|
+
* ([D35](../../../docs/decisions/adr-0035.md)). Every adapter maps this set or
|
|
14137
|
+
* declares `actionIcons: false` and the degrade engine strips the field.
|
|
14138
|
+
*
|
|
14139
|
+
* Named by INTENT, never by glyph. "check" would tie the vocabulary to one
|
|
14140
|
+
* renderer's icon set; "acknowledge" survives an adapter that draws it
|
|
14141
|
+
* differently.
|
|
14142
|
+
*
|
|
14143
|
+
* ── A TOKEN IS NOT A WIRE VALUE ─────────────────────────────────────
|
|
14144
|
+
*
|
|
14145
|
+
* These names are for US. **No adapter may forward one verbatim.** Each maps
|
|
14146
|
+
* the whole set onto its own renderer's vocabulary through a
|
|
14147
|
+
* `Record<NotificationActionIcon, string>` — a Record, never a lookup with a
|
|
14148
|
+
* fallback, so adding a member here fails every adapter's build until someone
|
|
14149
|
+
* decides its glyph, which is the only place that decision can be made
|
|
14150
|
+
* honestly.
|
|
14151
|
+
*
|
|
14152
|
+
* This paragraph is the bug. Zentik declared `actionIcons: true` and passed
|
|
14153
|
+
* `disarm` straight through; iOS feeds that string to
|
|
14154
|
+
* `UNNotificationActionIcon(systemImageName:)`, `disarm` is not an SF Symbol,
|
|
14155
|
+
* and every snooze and alarm button arrived BLANK. A pass-through is not a
|
|
14156
|
+
* mapping, and "the field is documented" is not "the value renders".
|
|
14157
|
+
*
|
|
14158
|
+
* Adding a member is TRAIN-BOUND. The enum lives in the published
|
|
14159
|
+
* `@camstack/server` closure and the cap seam validates against the HUB's copy,
|
|
14160
|
+
* so an addon that emits a token the running hub does not know does not lose an
|
|
14161
|
+
* icon — its whole `send` fails Zod validation and the notification never
|
|
14162
|
+
* arrives. Never emit a new token from an addon before the train carrying it.
|
|
14163
|
+
*/
|
|
14164
|
+
var NotificationActionIconSchema = _enum([
|
|
14165
|
+
"acknowledge",
|
|
14166
|
+
"dismiss",
|
|
14167
|
+
"silence",
|
|
14168
|
+
"snooze",
|
|
14169
|
+
"view",
|
|
14170
|
+
"play",
|
|
14171
|
+
"open",
|
|
14172
|
+
"close",
|
|
14173
|
+
"lock",
|
|
14174
|
+
"unlock",
|
|
14175
|
+
"arm",
|
|
14176
|
+
"arm-home",
|
|
14177
|
+
"arm-away",
|
|
14178
|
+
"arm-night",
|
|
14179
|
+
"disarm",
|
|
14180
|
+
"light",
|
|
14181
|
+
"alert",
|
|
14182
|
+
"camera"
|
|
14183
|
+
]);
|
|
14184
|
+
/** A single tap-through action button. */
|
|
14185
|
+
var NotificationActionSchema = object({
|
|
14186
|
+
id: string(),
|
|
14187
|
+
label: string(),
|
|
14188
|
+
url: string().optional(),
|
|
14189
|
+
/** Dropped by the degrade engine for a kind with `caps.actionIcons: false`. */
|
|
14190
|
+
icon: NotificationActionIconSchema.optional(),
|
|
14191
|
+
/**
|
|
14192
|
+
* Renders in a warning style where the notifier supports it.
|
|
14193
|
+
*
|
|
14194
|
+
* A HINT, never a gate. The callback's authority is its token and nothing
|
|
14195
|
+
* else — see `notification-center/action-token.ts` for what that does and
|
|
14196
|
+
* does not buy.
|
|
14197
|
+
*/
|
|
14198
|
+
destructive: boolean().optional(),
|
|
14199
|
+
/**
|
|
14200
|
+
* How the tap should REACH the url.
|
|
14201
|
+
*
|
|
14202
|
+
* `navigate` (absent, and every button authored before this field) opens it:
|
|
14203
|
+
* the phone leaves the notification and shows whatever the callback returns.
|
|
14204
|
+
* That is right for a button whose answer the operator wants to read.
|
|
14205
|
+
*
|
|
14206
|
+
* `background` fires it as a POST and stays put. It exists for the buttons
|
|
14207
|
+
* whose whole point is not to interrupt — "silence this for 30 minutes" is
|
|
14208
|
+
* an answer to the notification, and being thrown into a browser tab to
|
|
14209
|
+
* confirm it costs more attention than the notification did. A backend that
|
|
14210
|
+
* cannot do a background call renders it as an ordinary link (the adapters
|
|
14211
|
+
* fall back rather than dropping the button), so this is a preference, never
|
|
14212
|
+
* a requirement.
|
|
14213
|
+
*/
|
|
14214
|
+
mode: _enum(["navigate", "background"]).optional()
|
|
14215
|
+
});
|
|
14216
|
+
/** A delivery parameter value: what a notifier declared it takes. */
|
|
14217
|
+
var DeliveryParamValueSchema = union([
|
|
14218
|
+
string(),
|
|
14219
|
+
number(),
|
|
14220
|
+
boolean()
|
|
14221
|
+
]);
|
|
14222
|
+
/**
|
|
14223
|
+
* One extra delivery parameter a notifier KIND declares (D938). A rule that
|
|
14224
|
+
* addresses a target of that kind may set it; a kind that declares nothing is
|
|
14225
|
+
* never handed one. The admin UI derives its control from this descriptor —
|
|
14226
|
+
* no editor knows a service by name.
|
|
14227
|
+
*
|
|
14228
|
+
* Optional fields are `.optional()`, never `.default()` (a Zod default does not
|
|
14229
|
+
* run on the addon cap path).
|
|
14230
|
+
*/
|
|
14231
|
+
var DeliveryParamSchema = object({
|
|
14232
|
+
key: string().min(1),
|
|
14233
|
+
label: string(),
|
|
14234
|
+
/** i18n key of the label, resolved by the declaring addon's namespace. */
|
|
14235
|
+
labelKey: string().optional(),
|
|
14236
|
+
type: _enum([
|
|
14237
|
+
"enum",
|
|
14238
|
+
"number",
|
|
14239
|
+
"boolean",
|
|
14240
|
+
"string"
|
|
14241
|
+
]),
|
|
14242
|
+
/** `enum` only: the closed set of accepted values. */
|
|
14243
|
+
options: array(object({
|
|
14244
|
+
value: string(),
|
|
14245
|
+
label: string()
|
|
14246
|
+
})).optional(),
|
|
14247
|
+
/** `number` only. */
|
|
14248
|
+
min: number().optional(),
|
|
14249
|
+
max: number().optional(),
|
|
14250
|
+
/** What the notifier does when the rule sets nothing; shown as the placeholder. */
|
|
14251
|
+
default: DeliveryParamValueSchema.optional()
|
|
14252
|
+
});
|
|
14253
|
+
/**
|
|
14254
|
+
* The canonical notification. `body` is the only hard field (Apprise model).
|
|
14255
|
+
* `priority` is a 5-level ORDINAL (1=lowest … 3=normal(default) … 5=urgent),
|
|
14256
|
+
* NOT a fixed severity enum — each kind declares its own `caps.levels` and
|
|
14257
|
+
* the adapter maps this ordinal onto its native level. `level?` is an
|
|
14258
|
+
* optional kind-native level id (`emergency`, `silent`, …) that overrides
|
|
14259
|
+
* `priority` for that one target.
|
|
14260
|
+
*/
|
|
14261
|
+
var NotificationSchema = object({
|
|
14262
|
+
body: string(),
|
|
14263
|
+
title: string().optional(),
|
|
14264
|
+
format: NotificationFormatSchema.default("text"),
|
|
14265
|
+
priority: number().int().min(1).max(5).default(3),
|
|
14266
|
+
level: string().optional(),
|
|
14267
|
+
attachments: array(AttachmentSchema).optional(),
|
|
14268
|
+
clickUrl: string().optional(),
|
|
14269
|
+
actions: array(NotificationActionSchema).optional(),
|
|
14270
|
+
sound: string().optional(),
|
|
14271
|
+
ttl: number().optional(),
|
|
14272
|
+
tag: string().optional(),
|
|
14273
|
+
deviceId: number().optional(),
|
|
14274
|
+
eventId: string().optional(),
|
|
14275
|
+
metadata: record(string(), unknown()).optional(),
|
|
14276
|
+
/**
|
|
14277
|
+
* Values for the parameters the target's kind DECLARES in
|
|
14278
|
+
* {@link TargetKindSchema} `deliveryParams`. Already validated against the
|
|
14279
|
+
* declaration by the sender; a notifier reads only the keys it declared.
|
|
14280
|
+
*/
|
|
14281
|
+
delivery: record(string(), DeliveryParamValueSchema).optional()
|
|
14282
|
+
});
|
|
14283
|
+
/** One declared native severity/priority level for a kind. */
|
|
14284
|
+
var TargetKindLevelSchema = object({
|
|
14285
|
+
id: string(),
|
|
14286
|
+
label: string(),
|
|
14287
|
+
/** Which canonical priority (1..5) this level maps to. `null` = qualitative-only. */
|
|
14288
|
+
ordinal: number().int().min(1).max(5).nullable(),
|
|
14289
|
+
flags: object({
|
|
14290
|
+
critical: boolean().optional(),
|
|
14291
|
+
silent: boolean().optional(),
|
|
14292
|
+
noPush: boolean().optional()
|
|
14293
|
+
}).optional(),
|
|
14294
|
+
/** e.g. Pushover `emergency` requires `retry` / `expire`. */
|
|
14295
|
+
requires: array(string()).optional(),
|
|
14296
|
+
description: string().optional()
|
|
14297
|
+
});
|
|
14298
|
+
/** The full capability block consulted before dispatch. */
|
|
14299
|
+
var TargetKindCapsSchema = object({
|
|
14300
|
+
attachments: object({
|
|
14301
|
+
mediaTypes: array(AttachmentMediaTypeSchema),
|
|
14302
|
+
mode: _enum([
|
|
14303
|
+
"url",
|
|
14304
|
+
"bytes",
|
|
14305
|
+
"both"
|
|
14306
|
+
]),
|
|
14307
|
+
max: number().int().nonnegative(),
|
|
14308
|
+
maxBytes: number().int().positive().optional()
|
|
14309
|
+
}),
|
|
14310
|
+
/** Max action buttons (0 = none). */
|
|
14311
|
+
actions: number().int().nonnegative(),
|
|
14312
|
+
/**
|
|
14313
|
+
* Whether this kind renders a per-action ICON.
|
|
14314
|
+
*
|
|
14315
|
+
* `.optional()`, deliberately NOT `.default(false)`: a Zod default does not
|
|
14316
|
+
* run on the addon cap path — three production failures in one day taught
|
|
14317
|
+
* this repo that once. Absent is read as false by the degrade engine, which
|
|
14318
|
+
* is the safe direction: an icon that is not rendered costs nothing, an icon
|
|
14319
|
+
* assumed and dropped costs the operator's trust in the field.
|
|
14320
|
+
*/
|
|
14321
|
+
actionIcons: boolean().optional(),
|
|
14322
|
+
levels: array(TargetKindLevelSchema),
|
|
14323
|
+
format: array(NotificationFormatSchema),
|
|
14324
|
+
clickUrl: boolean(),
|
|
14325
|
+
sound: boolean(),
|
|
14326
|
+
ttl: boolean(),
|
|
14327
|
+
bodyMaxLen: number().int().positive()
|
|
14328
|
+
});
|
|
14329
|
+
/**
|
|
14330
|
+
* `configSchema` is a `ConfigUISchema` tree passed through to the admin
|
|
14331
|
+
* FormBuilder. Stored as `z.unknown()` at the cap seam (mirrors
|
|
14332
|
+
* `device-provider.getChildCreationSchema` `CreationSchemaOutputSchema`) —
|
|
14333
|
+
* the union is large and not meant for runtime validation here; the exported
|
|
14334
|
+
* `TargetKind` type re-tightens `configSchema` to `ConfigUISchema`.
|
|
14335
|
+
*/
|
|
14336
|
+
var ConfigSchemaPassthrough$4 = unknown();
|
|
14337
|
+
var TargetKindSchema = object({
|
|
14338
|
+
kind: string(),
|
|
14339
|
+
label: string(),
|
|
14340
|
+
icon: string(),
|
|
14341
|
+
/** Stamped by each provider so the concat-fanned catalog stays routable. */
|
|
14342
|
+
addonId: string(),
|
|
14343
|
+
/**
|
|
14344
|
+
* URL of the kind's bundled BRAND icon, served by the providing addon over
|
|
14345
|
+
* its own `addon-routes` surface (`/addon/<addonId>/icons/<kind>`). Absent
|
|
14346
|
+
* when the addon bundles no icon for that kind — the client then falls back
|
|
14347
|
+
* to a neutral glyph rather than rendering the raw `icon` NAME as text.
|
|
14348
|
+
*
|
|
14349
|
+
* Root-relative on purpose: it resolves against whatever origin serves a web
|
|
14350
|
+
* client, and a native client joins it onto its own hub base.
|
|
14351
|
+
*
|
|
14352
|
+
* DECLARED here deliberately. It used to travel as an undeclared passthrough
|
|
14353
|
+
* field that survived only because the runtime cap-router forwards provider
|
|
14354
|
+
* output verbatim — so every consumer had to re-declare it by hand to stop
|
|
14355
|
+
* its own Zod parse from stripping it, and the whole arrangement would have
|
|
14356
|
+
* broken silently the moment output validation was tightened anywhere.
|
|
14357
|
+
*/
|
|
14358
|
+
iconUrl: string().optional(),
|
|
14359
|
+
/**
|
|
14360
|
+
* Media type of {@link iconUrl} (`image/svg+xml`, `image/png`, …).
|
|
14361
|
+
*
|
|
14362
|
+
* The server knows this and therefore says it, because the client cannot
|
|
14363
|
+
* safely guess: a React-Native client renders SVG and raster through two
|
|
14364
|
+
* DIFFERENT components (`react-native-svg` vs `expo-image` — expo-image does
|
|
14365
|
+
* not decode SVG on iOS/Android), so without this it silently fell back to a
|
|
14366
|
+
* placeholder glyph for every vector icon while the web build looked fine.
|
|
14367
|
+
*
|
|
14368
|
+
* Absent when {@link iconUrl} is absent, or for a legacy provider that has
|
|
14369
|
+
* not been updated — a client that cannot determine the type should prefer
|
|
14370
|
+
* its raster path, which is the safe default for an unknown image.
|
|
14371
|
+
*/
|
|
14372
|
+
iconMediaType: string().optional(),
|
|
14373
|
+
configSchema: ConfigSchemaPassthrough$4,
|
|
14374
|
+
/**
|
|
14375
|
+
* The config keys that decide WHERE this kind's secrets are sent (server,
|
|
14376
|
+
* base URL, instance, chat, recipient). A save that changes any of them
|
|
14377
|
+
* while leaving a secret redacted is refused by the provider (D634), so an
|
|
14378
|
+
* editor uses this to ask for the secret on exactly those edits instead of
|
|
14379
|
+
* on every edit.
|
|
14380
|
+
*
|
|
14381
|
+
* Optional: absent from a provider that holds no secret (the Home Assistant
|
|
14382
|
+
* kinds) and from a provider older than this field — an editor that finds
|
|
14383
|
+
* it absent must assume ANY edit may need the secret.
|
|
14384
|
+
*/
|
|
14385
|
+
destinationKeys: array(string()).optional(),
|
|
14386
|
+
supportsDiscovery: boolean(),
|
|
14387
|
+
/**
|
|
14388
|
+
* Extra delivery parameters a rule may set for a target of this kind (D938).
|
|
14389
|
+
* Absent = none; the rule editor then offers nothing.
|
|
14390
|
+
*/
|
|
14391
|
+
deliveryParams: array(DeliveryParamSchema).optional(),
|
|
14392
|
+
caps: TargetKindCapsSchema
|
|
14393
|
+
});
|
|
14394
|
+
/**
|
|
14395
|
+
* A persisted target. `config` holds secrets; providers REDACT secret fields
|
|
14396
|
+
* (return a presence marker only) when serving `listTargets` — never
|
|
14397
|
+
* round-trip a stored secret to the UI.
|
|
14398
|
+
*/
|
|
14399
|
+
var TargetSchema = object({
|
|
14400
|
+
id: string(),
|
|
14401
|
+
name: string(),
|
|
14402
|
+
kind: string(),
|
|
14403
|
+
addonId: string(),
|
|
14404
|
+
enabled: boolean(),
|
|
14405
|
+
config: record(string(), unknown())
|
|
14406
|
+
});
|
|
14407
|
+
/** A discovery-surfaced candidate (config is partial + non-secret). */
|
|
14408
|
+
var DiscoveredTargetSchema = object({
|
|
14409
|
+
kind: string(),
|
|
14410
|
+
suggestedName: string(),
|
|
14411
|
+
config: record(string(), unknown())
|
|
14412
|
+
});
|
|
14413
|
+
/** The degrade engine's report — what was resolved / dropped / degraded. */
|
|
14414
|
+
var RenderedAsSchema = object({
|
|
14415
|
+
level: string(),
|
|
14416
|
+
format: NotificationFormatSchema,
|
|
14417
|
+
attachmentsSent: number().int().nonnegative(),
|
|
14418
|
+
actionsSent: number().int().nonnegative(),
|
|
14419
|
+
truncated: boolean(),
|
|
14420
|
+
dropped: array(string())
|
|
14421
|
+
});
|
|
14422
|
+
var SendResultSchema = object({
|
|
14423
|
+
success: boolean(),
|
|
14424
|
+
error: string().optional(),
|
|
14425
|
+
renderedAs: RenderedAsSchema.optional()
|
|
14426
|
+
});
|
|
14427
|
+
/** Same shape as SendResult — kept as a distinct name for the test panel. */
|
|
14428
|
+
var TestResultSchema = SendResultSchema;
|
|
14429
|
+
/**
|
|
14430
|
+
* Pre-save credential probe against a partial (unsaved) target config.
|
|
14431
|
+
* `resolvedUrl` never includes secrets (token stripped from path).
|
|
14432
|
+
*/
|
|
14433
|
+
var ProbeTargetConfigResultSchema = object({
|
|
14434
|
+
ok: boolean(),
|
|
14435
|
+
resolvedUrl: string(),
|
|
14436
|
+
httpStatus: number().int().optional(),
|
|
14437
|
+
stateInstance: string().optional(),
|
|
14438
|
+
error: string().optional()
|
|
14439
|
+
});
|
|
14440
|
+
method(object({}), array(TargetKindSchema)), method(object({}), array(TargetSchema), { auth: "admin" }), method(object({ targetId: string() }), TargetSchema, { auth: "admin" }), method(object({
|
|
14441
|
+
kind: string(),
|
|
14442
|
+
config: record(string(), unknown()).optional(),
|
|
14443
|
+
/**
|
|
14444
|
+
* When editing / duplicating, the blank password field never round-trips
|
|
14445
|
+
* the stored token. Pass the source target id so the provider can restore
|
|
14446
|
+
* secrets server-side before dialling (same merge as upsert).
|
|
14447
|
+
*/
|
|
14448
|
+
targetId: string().optional()
|
|
14449
|
+
}), array(DiscoveredTargetSchema), { auth: "admin" }), method(object({
|
|
14450
|
+
kind: string(),
|
|
14451
|
+
config: record(string(), unknown()),
|
|
14452
|
+
/** See `discoverTargets.targetId` — restore stored secrets for a blank password. */
|
|
14453
|
+
targetId: string().optional()
|
|
14454
|
+
}), ProbeTargetConfigResultSchema, {
|
|
14455
|
+
kind: "mutation",
|
|
14456
|
+
auth: "admin"
|
|
14457
|
+
}), method(object({
|
|
14458
|
+
targetId: string(),
|
|
14459
|
+
notification: NotificationSchema
|
|
14460
|
+
}), SendResultSchema, {
|
|
14461
|
+
kind: "mutation",
|
|
14462
|
+
auth: "admin"
|
|
14463
|
+
}), method(object({
|
|
14464
|
+
targetId: string(),
|
|
14465
|
+
sample: NotificationSchema.optional()
|
|
14466
|
+
}), TestResultSchema, {
|
|
14467
|
+
kind: "mutation",
|
|
14468
|
+
auth: "admin"
|
|
14469
|
+
}), method(object({
|
|
14470
|
+
target: TargetSchema,
|
|
14471
|
+
/**
|
|
14472
|
+
* Duplicate flow: create a NEW target id while copying secrets from an
|
|
14473
|
+
* existing row. The UI never holds the stored token; blank / redacted
|
|
14474
|
+
* password fields are restored from this source (D634 still applies if
|
|
14475
|
+
* destinations diverge without a re-typed secret).
|
|
14476
|
+
*/
|
|
14477
|
+
cloneSecretsFrom: string().optional()
|
|
14478
|
+
}), TargetSchema, {
|
|
14479
|
+
kind: "mutation",
|
|
14480
|
+
auth: "admin"
|
|
14481
|
+
}), method(object({ targetId: string() }), _void(), {
|
|
14482
|
+
kind: "mutation",
|
|
14483
|
+
auth: "admin"
|
|
14484
|
+
}), method(object({
|
|
14485
|
+
targetId: string(),
|
|
14486
|
+
enabled: boolean()
|
|
14487
|
+
}), _void(), {
|
|
14488
|
+
kind: "mutation",
|
|
14489
|
+
auth: "admin"
|
|
14490
|
+
});
|
|
14491
|
+
looseObject({
|
|
14492
|
+
name: string().min(1),
|
|
14493
|
+
enabled: boolean().optional()
|
|
14494
|
+
});
|
|
14495
|
+
TargetSchema.omit({ id: true });
|
|
13845
14496
|
var EncodeProfileSchema = object({
|
|
13846
14497
|
video: object({
|
|
13847
14498
|
codec: _enum([
|
|
@@ -20026,31 +20677,21 @@ var APPLIANCE_CAP_VOCABULARY = {
|
|
|
20026
20677
|
"pet-fountain": {
|
|
20027
20678
|
scope: "device",
|
|
20028
20679
|
noun: t("Pet fountain", "Fontana per animali"),
|
|
20029
|
-
actions: [
|
|
20030
|
-
|
|
20031
|
-
|
|
20032
|
-
|
|
20033
|
-
|
|
20034
|
-
|
|
20035
|
-
|
|
20036
|
-
|
|
20037
|
-
|
|
20038
|
-
|
|
20039
|
-
|
|
20040
|
-
|
|
20041
|
-
|
|
20042
|
-
|
|
20043
|
-
|
|
20044
|
-
args: { on: false }
|
|
20045
|
-
},
|
|
20046
|
-
{
|
|
20047
|
-
id: "petFountain.resetDailyConsumption",
|
|
20048
|
-
method: "resetDailyConsumption",
|
|
20049
|
-
label: t("Clear daily consumption", "Azzera il consumo giornaliero"),
|
|
20050
|
-
phrase: t("Clear the daily water consumption of {device}", "Azzera il consumo giornaliero di acqua di {device}"),
|
|
20051
|
-
icon: "rotate-ccw"
|
|
20052
|
-
}
|
|
20053
|
-
],
|
|
20680
|
+
actions: [{
|
|
20681
|
+
id: "petFountain.pumpOn",
|
|
20682
|
+
method: "setPump",
|
|
20683
|
+
label: t("Pump on", "Pompa accesa"),
|
|
20684
|
+
phrase: t("Start the pump of {device}", "Avvia la pompa di {device}"),
|
|
20685
|
+
icon: "play",
|
|
20686
|
+
args: { on: true }
|
|
20687
|
+
}, {
|
|
20688
|
+
id: "petFountain.pumpOff",
|
|
20689
|
+
method: "setPump",
|
|
20690
|
+
label: t("Pump off", "Pompa spenta"),
|
|
20691
|
+
phrase: t("Stop the pump of {device}", "Ferma la pompa di {device}"),
|
|
20692
|
+
icon: "square",
|
|
20693
|
+
args: { on: false }
|
|
20694
|
+
}],
|
|
20054
20695
|
state: [{
|
|
20055
20696
|
kind: "boolean",
|
|
20056
20697
|
field: "empty",
|
|
@@ -22069,7 +22710,6 @@ var SYSTEM_CAP_VOCABULARY = {
|
|
|
22069
22710
|
"calendar-source": system(INTERNAL),
|
|
22070
22711
|
calendars: system("calendars feed schedules and conditions, not device actions"),
|
|
22071
22712
|
composer: system("device composition — an authoring tool, not an action"),
|
|
22072
|
-
"connection-test": system(INTERNAL),
|
|
22073
22713
|
"core-blocks": system(INTERNAL),
|
|
22074
22714
|
"custom-model-registry": system(ML),
|
|
22075
22715
|
"data-store-provider": system(INTERNAL),
|
|
@@ -43795,610 +44435,196 @@ var AutomationRunTraceSchema = object({
|
|
|
43795
44435
|
startedAt: number(),
|
|
43796
44436
|
endedAt: number(),
|
|
43797
44437
|
trigger: AutomationTriggerTraceSchema,
|
|
43798
|
-
conditions: array(AutomationConditionTraceNodeSchema),
|
|
43799
|
-
verdict: AutomationRunVerdictSchema.optional(),
|
|
43800
|
-
steps: array(AutomationStepTraceSchema),
|
|
43801
|
-
outcome: AutomationRunOutcomeSchema,
|
|
43802
|
-
/** How many identical consecutive skips this trace stands for (>= 1). */
|
|
43803
|
-
repeat: number().int().min(1),
|
|
43804
|
-
/** When the latest of those repeats happened. */
|
|
43805
|
-
lastAt: number(),
|
|
43806
|
-
/**
|
|
43807
|
-
* A scheduler point's own outcome (D983). `outcome` carries the closest
|
|
43808
|
-
* automation outcome so a reader that does not know schedulers still reads
|
|
43809
|
-
* the trace; this field says exactly what happened.
|
|
43810
|
-
*/
|
|
43811
|
-
scheduler: SchedulerOutcomeSchema.optional()
|
|
43812
|
-
});
|
|
43813
|
-
/**
|
|
43814
|
-
* What the hub's `runs` ledger holds for one owner (`automation:<blockId>` or
|
|
43815
|
-
* `action:<actionId>`): the cooldown stamp and the trace ring.
|
|
43816
|
-
*/
|
|
43817
|
-
var AutomationStateDocSchema = object({
|
|
43818
|
-
version: literal(1),
|
|
43819
|
-
lastRunStartedAt: number().nullable(),
|
|
43820
|
-
traces: array(AutomationRunTraceSchema)
|
|
43821
|
-
});
|
|
43822
|
-
/**
|
|
43823
|
-
* Actions — named, runnable things an operator (or an automation) can start,
|
|
43824
|
-
* declared as LIST ENTRIES, never as devices.
|
|
43825
|
-
*
|
|
43826
|
-
* An entry is either **internal** (a short list of cap/wait steps kept in the
|
|
43827
|
-
* hub's `actions` record kind) or declared by an addon through the
|
|
43828
|
-
* `action-source` collection (a Home Assistant script, a scene …). The one
|
|
43829
|
-
* surface the UI and automations talk to is the `actions` cap; it keeps no
|
|
43830
|
-
* catalog of its own (D3) — every `list` asks the providers live.
|
|
43831
|
-
*
|
|
43832
|
-
* This file is the data half: the entry schema, the variables an entry may
|
|
43833
|
-
* declare, and the pure resolution of the values a run was given. It holds no
|
|
43834
|
-
* runtime.
|
|
43835
|
-
*/
|
|
43836
|
-
/** What a variable's value is. `select` takes one of `options`. */
|
|
43837
|
-
var ActionVariableTypeSchema = _enum([
|
|
43838
|
-
"string",
|
|
43839
|
-
"number",
|
|
43840
|
-
"boolean",
|
|
43841
|
-
"select"
|
|
43842
|
-
]);
|
|
43843
|
-
var ACTION_VARIABLE_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
43844
|
-
var ActionVariableValueSchema = union([
|
|
43845
|
-
string(),
|
|
43846
|
-
number(),
|
|
43847
|
-
boolean()
|
|
43848
|
-
]);
|
|
43849
|
-
/**
|
|
43850
|
-
* One declared variable. Steps reference it as `{ $var: 'name' }` (the whole
|
|
43851
|
-
* value) or `{{vars.name}}` (inside a string) in their args.
|
|
43852
|
-
*/
|
|
43853
|
-
var ActionVariableSchema = object({
|
|
43854
|
-
name: string().regex(ACTION_VARIABLE_NAME_RE),
|
|
43855
|
-
label: string().min(1).max(120).optional(),
|
|
43856
|
-
type: ActionVariableTypeSchema,
|
|
43857
|
-
required: boolean().optional(),
|
|
43858
|
-
default: ActionVariableValueSchema.optional(),
|
|
43859
|
-
/** The allowed values of a `select`. */
|
|
43860
|
-
options: array(string().min(1)).min(1).optional()
|
|
43861
|
-
}).superRefine((v, ctx) => {
|
|
43862
|
-
if (v.type === "select" && v.options === void 0) ctx.addIssue({
|
|
43863
|
-
code: "custom",
|
|
43864
|
-
message: "a select variable needs options",
|
|
43865
|
-
path: ["options"]
|
|
43866
|
-
});
|
|
43867
|
-
if (v.default !== void 0 && variableValueError(v, v.default) !== null) ctx.addIssue({
|
|
43868
|
-
code: "custom",
|
|
43869
|
-
message: variableValueError(v, v.default) ?? "invalid default",
|
|
43870
|
-
path: ["default"]
|
|
43871
|
-
});
|
|
43872
|
-
});
|
|
43873
|
-
/** Why `value` is not a legal value for the variable, or null when it is. */
|
|
43874
|
-
function variableValueError(variable, value) {
|
|
43875
|
-
switch (variable.type) {
|
|
43876
|
-
case "string": return typeof value === "string" ? null : `variable "${variable.name}" must be a string`;
|
|
43877
|
-
case "number": return typeof value === "number" && Number.isFinite(value) ? null : `variable "${variable.name}" must be a number`;
|
|
43878
|
-
case "boolean": return typeof value === "boolean" ? null : `variable "${variable.name}" must be true or false`;
|
|
43879
|
-
case "select": return typeof value === "string" && (variable.options ?? []).includes(value) ? null : `variable "${variable.name}" must be one of ${(variable.options ?? []).join(", ")}`;
|
|
43880
|
-
}
|
|
43881
|
-
}
|
|
43882
|
-
var ActionSourceKindSchema = _enum(["internal", "addon"]);
|
|
43883
|
-
function isInternalActionId(actionId) {
|
|
43884
|
-
return actionId.startsWith("internal:") && actionId.length > 9;
|
|
43885
|
-
}
|
|
43886
|
-
/** The addon behind a `<addonId>:<localId>` id, or null for anything else (internal included). */
|
|
43887
|
-
function addonIdOfActionId(actionId) {
|
|
43888
|
-
if (isInternalActionId(actionId)) return null;
|
|
43889
|
-
const at = actionId.indexOf(":");
|
|
43890
|
-
return at > 0 && at < actionId.length - 1 ? actionId.slice(0, at) : null;
|
|
43891
|
-
}
|
|
43892
|
-
var ActionStatusSchema = object({
|
|
43893
|
-
isRunning: boolean(),
|
|
43894
|
-
/** Ms epoch the latest run STARTED; null when it never ran. */
|
|
43895
|
-
lastRunAt: number().nullable(),
|
|
43896
|
-
/** The latest run's failure; null on success or when it never ran. */
|
|
43897
|
-
lastError: string().nullable()
|
|
43898
|
-
});
|
|
43899
|
-
var ActionEntrySchema = object({
|
|
43900
|
-
/** `internal:<uuid>` or `<addonId>:<localId>`. */
|
|
43901
|
-
id: string().min(3),
|
|
43902
|
-
name: string().min(1).max(120),
|
|
43903
|
-
/** The addon that declared it; `core-blocks` for an internal one. */
|
|
43904
|
-
addonId: string().min(1),
|
|
43905
|
-
source: ActionSourceKindSchema,
|
|
43906
|
-
/** An addon-declared entry is edited where it was declared. */
|
|
43907
|
-
readOnly: boolean(),
|
|
43908
|
-
/** Internal only: cap and wait steps. No action-in-action, so no cycles. */
|
|
43909
|
-
steps: array(ActionStepSchema).min(1).max(50).optional(),
|
|
43910
|
-
variables: array(ActionVariableSchema).max(20).optional(),
|
|
43911
|
-
status: ActionStatusSchema
|
|
43912
|
-
}).superRefine((entry, ctx) => {
|
|
43913
|
-
if (entry.source === "internal") {
|
|
43914
|
-
if (!isInternalActionId(entry.id)) ctx.addIssue({
|
|
43915
|
-
code: "custom",
|
|
43916
|
-
message: "an internal action id is internal:<uuid>",
|
|
43917
|
-
path: ["id"]
|
|
43918
|
-
});
|
|
43919
|
-
return;
|
|
43920
|
-
}
|
|
43921
|
-
if (entry.steps !== void 0) ctx.addIssue({
|
|
43922
|
-
code: "custom",
|
|
43923
|
-
message: "only an internal action carries steps",
|
|
43924
|
-
path: ["steps"]
|
|
43925
|
-
});
|
|
43926
|
-
if (!entry.readOnly) ctx.addIssue({
|
|
43927
|
-
code: "custom",
|
|
43928
|
-
message: "an addon action is read-only here",
|
|
43929
|
-
path: ["readOnly"]
|
|
43930
|
-
});
|
|
43931
|
-
if (addonIdOfActionId(entry.id) === null) ctx.addIssue({
|
|
43932
|
-
code: "custom",
|
|
43933
|
-
message: "an addon action id is <addonId>:<localId>",
|
|
43934
|
-
path: ["id"]
|
|
43935
|
-
});
|
|
43936
|
-
});
|
|
43937
|
-
/** What an operator writes for an internal action. */
|
|
43938
|
-
var ActionInputSchema = object({
|
|
43939
|
-
name: string().min(1).max(120),
|
|
43940
|
-
steps: array(ActionStepSchema).min(1).max(50),
|
|
43941
|
-
variables: array(ActionVariableSchema).max(20).optional()
|
|
43942
|
-
});
|
|
43943
|
-
/** Who started a run. Absent = the operator pressed it. */
|
|
43944
|
-
var ActionRunOriginSchema = object({
|
|
43945
|
-
/** The automation block whose step started it. */
|
|
43946
|
-
blockId: string().min(1).optional() });
|
|
43947
|
-
/** `started` = the caller did not ask to wait. */
|
|
43948
|
-
var ActionRunOutcomeSchema = union([AutomationRunOutcomeSchema, literal("started")]);
|
|
43949
|
-
var ActionRunResultSchema = object({
|
|
43950
|
-
runId: string().min(1),
|
|
43951
|
-
outcome: ActionRunOutcomeSchema,
|
|
43952
|
-
/** Why it did not run, or what failed. */
|
|
43953
|
-
message: string().optional()
|
|
43954
|
-
});
|
|
43955
|
-
_enum([
|
|
43956
|
-
"not-found",
|
|
43957
|
-
"read-only",
|
|
43958
|
-
"invalid-variables",
|
|
43959
|
-
"invalid-steps",
|
|
43960
|
-
"not-linked",
|
|
43961
|
-
"busy"
|
|
43962
|
-
]);
|
|
43963
|
-
object({
|
|
43964
|
-
actionId: string(),
|
|
43965
|
-
runId: string(),
|
|
43966
|
-
isRunning: boolean(),
|
|
43967
|
-
/** Set when the run ended. */
|
|
43968
|
-
outcome: AutomationRunOutcomeSchema.optional(),
|
|
43969
|
-
lastRunAt: number().nullable(),
|
|
43970
|
-
lastError: string().nullable()
|
|
43971
|
-
});
|
|
43972
|
-
/** A bare number accepted as a base unit — the save succeeded, say so. */
|
|
43973
|
-
var UnitWarningSchema = object({
|
|
43974
|
-
/** Where in the saved record, e.g. `conditions.children.0` or `steps.2.args.grams`. */
|
|
43975
|
-
path: string(),
|
|
43976
|
-
deviceId: number().int().optional(),
|
|
43977
|
-
field: string(),
|
|
43978
|
-
value: number(),
|
|
43979
|
-
assumedUnit: string(),
|
|
43980
|
-
message: string()
|
|
43981
|
-
});
|
|
43982
|
-
/**
|
|
43983
|
-
* notification-output — canonical, capability-gated notification delivery.
|
|
43984
|
-
*
|
|
43985
|
-
* Apprise-derived model (see
|
|
43986
|
-
* `docs/superpowers/specs/2026-07-03-notification-output-notifier-matrix.md`):
|
|
43987
|
-
* callers emit ONE canonical `Notification`; each provider declares a
|
|
43988
|
-
* per-kind capability descriptor (`TargetKind`), and the pure degrade
|
|
43989
|
-
* engine (`@camstack/types` `prepareNotification`) transcodes / degrades the
|
|
43990
|
-
* message to what the kind supports — callers never special-case a service.
|
|
43991
|
-
*
|
|
43992
|
-
* DESIGN DECISIONS (locked):
|
|
43993
|
-
* - Target CRUD lives on THIS cap (`upsertTarget` / `deleteTarget` /
|
|
43994
|
-
* `setTargetEnabled`), each provider persisting via the `settings-store`
|
|
43995
|
-
* cap. Rationale: the admin UI needs one uniform surface across the
|
|
43996
|
-
* notifiers addon AND the HA addon; the addon-`globalSettingsSchema`-array
|
|
43997
|
-
* alternative would fork the UI per addon and cannot host the
|
|
43998
|
-
* discovery→adopt flow.
|
|
43999
|
-
* - `listTargetKinds` / `listTargets` / `discoverTargets` return arrays →
|
|
44000
|
-
* the generated cap-mount auto-`concatCollection`-fans them across every
|
|
44001
|
-
* registered provider (notifiers addon + HA addon) so one catalog is
|
|
44002
|
-
* routable. `send` / `testTarget` / CRUD route to ONE provider by the
|
|
44003
|
-
* `addonId` the generated collection router extracts from the call input.
|
|
44004
|
-
* - `Attachment.bytes` is `Uint8Array`. Transport-safe: superjson (the tRPC
|
|
44005
|
-
* transformer) + UDS MsgPack both round-trip typed arrays — already used by
|
|
44006
|
-
* `storage` / `storage-provider` / `recording` caps over the same path. No
|
|
44007
|
-
* base64 fallback needed.
|
|
44008
|
-
*
|
|
44009
|
-
* TODO (deferred, closed-set change — separate decision): add
|
|
44010
|
-
* `providerKind: 'notify'` so notification providers surface on the unified
|
|
44011
|
-
* admin "Integrations" page.
|
|
44012
|
-
*/
|
|
44013
|
-
/**
|
|
44014
|
-
* Zentik-derived typed-media enum — the superset across every kind. Each
|
|
44015
|
-
* adapter picks what it supports and the degrade engine filters the rest.
|
|
44016
|
-
*/
|
|
44017
|
-
var AttachmentMediaTypeSchema = _enum([
|
|
44018
|
-
"image",
|
|
44019
|
-
"video",
|
|
44020
|
-
"gif",
|
|
44021
|
-
"audio",
|
|
44022
|
-
"icon"
|
|
44023
|
-
]);
|
|
44024
|
-
/**
|
|
44025
|
-
* A single attachment. Exactly one of `url` (remote source, most adapters
|
|
44026
|
-
* prefer this) or `bytes` (inline source; required for Pushover-style
|
|
44027
|
-
* bytes-only kinds) MUST be present — the degrade engine expresses a
|
|
44028
|
-
* url→bytes fetch as a `needsFetch` directive the adapter executes.
|
|
44029
|
-
*/
|
|
44030
|
-
var AttachmentSchema = object({
|
|
44031
|
-
mediaType: AttachmentMediaTypeSchema,
|
|
44032
|
-
url: string().optional(),
|
|
44033
|
-
bytes: _instanceof(Uint8Array).optional(),
|
|
44034
|
-
mime: string().optional(),
|
|
44035
|
-
name: string().optional()
|
|
44036
|
-
}).refine((a) => a.url !== void 0 || a.bytes !== void 0, { message: "Attachment requires either `url` or `bytes`" });
|
|
44037
|
-
var NotificationFormatSchema = _enum([
|
|
44038
|
-
"text",
|
|
44039
|
-
"markdown",
|
|
44040
|
-
"html"
|
|
44041
|
-
]);
|
|
44042
|
-
/**
|
|
44043
|
-
* The CLOSED icon vocabulary an action button may use.
|
|
44044
|
-
*
|
|
44045
|
-
* A closed set, not a free string, and that is the whole point: an arbitrary
|
|
44046
|
-
* icon name is one that ntfy renders, zentik silently drops, and nobody
|
|
44047
|
-
* notices — the same class of gap as a zone vocabulary nothing produced
|
|
44048
|
-
* ([D35](../../../docs/decisions/adr-0035.md)). Every adapter maps this set or
|
|
44049
|
-
* declares `actionIcons: false` and the degrade engine strips the field.
|
|
44050
|
-
*
|
|
44051
|
-
* Named by INTENT, never by glyph. "check" would tie the vocabulary to one
|
|
44052
|
-
* renderer's icon set; "acknowledge" survives an adapter that draws it
|
|
44053
|
-
* differently.
|
|
44054
|
-
*
|
|
44055
|
-
* ── A TOKEN IS NOT A WIRE VALUE ─────────────────────────────────────
|
|
44056
|
-
*
|
|
44057
|
-
* These names are for US. **No adapter may forward one verbatim.** Each maps
|
|
44058
|
-
* the whole set onto its own renderer's vocabulary through a
|
|
44059
|
-
* `Record<NotificationActionIcon, string>` — a Record, never a lookup with a
|
|
44060
|
-
* fallback, so adding a member here fails every adapter's build until someone
|
|
44061
|
-
* decides its glyph, which is the only place that decision can be made
|
|
44062
|
-
* honestly.
|
|
44063
|
-
*
|
|
44064
|
-
* This paragraph is the bug. Zentik declared `actionIcons: true` and passed
|
|
44065
|
-
* `disarm` straight through; iOS feeds that string to
|
|
44066
|
-
* `UNNotificationActionIcon(systemImageName:)`, `disarm` is not an SF Symbol,
|
|
44067
|
-
* and every snooze and alarm button arrived BLANK. A pass-through is not a
|
|
44068
|
-
* mapping, and "the field is documented" is not "the value renders".
|
|
44069
|
-
*
|
|
44070
|
-
* Adding a member is TRAIN-BOUND. The enum lives in the published
|
|
44071
|
-
* `@camstack/server` closure and the cap seam validates against the HUB's copy,
|
|
44072
|
-
* so an addon that emits a token the running hub does not know does not lose an
|
|
44073
|
-
* icon — its whole `send` fails Zod validation and the notification never
|
|
44074
|
-
* arrives. Never emit a new token from an addon before the train carrying it.
|
|
44075
|
-
*/
|
|
44076
|
-
var NotificationActionIconSchema = _enum([
|
|
44077
|
-
"acknowledge",
|
|
44078
|
-
"dismiss",
|
|
44079
|
-
"silence",
|
|
44080
|
-
"snooze",
|
|
44081
|
-
"view",
|
|
44082
|
-
"play",
|
|
44083
|
-
"open",
|
|
44084
|
-
"close",
|
|
44085
|
-
"lock",
|
|
44086
|
-
"unlock",
|
|
44087
|
-
"arm",
|
|
44088
|
-
"arm-home",
|
|
44089
|
-
"arm-away",
|
|
44090
|
-
"arm-night",
|
|
44091
|
-
"disarm",
|
|
44092
|
-
"light",
|
|
44093
|
-
"alert",
|
|
44094
|
-
"camera"
|
|
44095
|
-
]);
|
|
44096
|
-
/** A single tap-through action button. */
|
|
44097
|
-
var NotificationActionSchema = object({
|
|
44098
|
-
id: string(),
|
|
44099
|
-
label: string(),
|
|
44100
|
-
url: string().optional(),
|
|
44101
|
-
/** Dropped by the degrade engine for a kind with `caps.actionIcons: false`. */
|
|
44102
|
-
icon: NotificationActionIconSchema.optional(),
|
|
44103
|
-
/**
|
|
44104
|
-
* Renders in a warning style where the notifier supports it.
|
|
44105
|
-
*
|
|
44106
|
-
* A HINT, never a gate. The callback's authority is its token and nothing
|
|
44107
|
-
* else — see `notification-center/action-token.ts` for what that does and
|
|
44108
|
-
* does not buy.
|
|
44109
|
-
*/
|
|
44110
|
-
destructive: boolean().optional(),
|
|
44111
|
-
/**
|
|
44112
|
-
* How the tap should REACH the url.
|
|
44113
|
-
*
|
|
44114
|
-
* `navigate` (absent, and every button authored before this field) opens it:
|
|
44115
|
-
* the phone leaves the notification and shows whatever the callback returns.
|
|
44116
|
-
* That is right for a button whose answer the operator wants to read.
|
|
44117
|
-
*
|
|
44118
|
-
* `background` fires it as a POST and stays put. It exists for the buttons
|
|
44119
|
-
* whose whole point is not to interrupt — "silence this for 30 minutes" is
|
|
44120
|
-
* an answer to the notification, and being thrown into a browser tab to
|
|
44121
|
-
* confirm it costs more attention than the notification did. A backend that
|
|
44122
|
-
* cannot do a background call renders it as an ordinary link (the adapters
|
|
44123
|
-
* fall back rather than dropping the button), so this is a preference, never
|
|
44124
|
-
* a requirement.
|
|
44125
|
-
*/
|
|
44126
|
-
mode: _enum(["navigate", "background"]).optional()
|
|
44127
|
-
});
|
|
44128
|
-
/** A delivery parameter value: what a notifier declared it takes. */
|
|
44129
|
-
var DeliveryParamValueSchema = union([
|
|
44130
|
-
string(),
|
|
44131
|
-
number(),
|
|
44132
|
-
boolean()
|
|
44133
|
-
]);
|
|
44134
|
-
/**
|
|
44135
|
-
* One extra delivery parameter a notifier KIND declares (D938). A rule that
|
|
44136
|
-
* addresses a target of that kind may set it; a kind that declares nothing is
|
|
44137
|
-
* never handed one. The admin UI derives its control from this descriptor —
|
|
44138
|
-
* no editor knows a service by name.
|
|
44139
|
-
*
|
|
44140
|
-
* Optional fields are `.optional()`, never `.default()` (a Zod default does not
|
|
44141
|
-
* run on the addon cap path).
|
|
44142
|
-
*/
|
|
44143
|
-
var DeliveryParamSchema = object({
|
|
44144
|
-
key: string().min(1),
|
|
44145
|
-
label: string(),
|
|
44146
|
-
/** i18n key of the label, resolved by the declaring addon's namespace. */
|
|
44147
|
-
labelKey: string().optional(),
|
|
44148
|
-
type: _enum([
|
|
44149
|
-
"enum",
|
|
44150
|
-
"number",
|
|
44151
|
-
"boolean",
|
|
44152
|
-
"string"
|
|
44153
|
-
]),
|
|
44154
|
-
/** `enum` only: the closed set of accepted values. */
|
|
44155
|
-
options: array(object({
|
|
44156
|
-
value: string(),
|
|
44157
|
-
label: string()
|
|
44158
|
-
})).optional(),
|
|
44159
|
-
/** `number` only. */
|
|
44160
|
-
min: number().optional(),
|
|
44161
|
-
max: number().optional(),
|
|
44162
|
-
/** What the notifier does when the rule sets nothing; shown as the placeholder. */
|
|
44163
|
-
default: DeliveryParamValueSchema.optional()
|
|
44164
|
-
});
|
|
44165
|
-
/**
|
|
44166
|
-
* The canonical notification. `body` is the only hard field (Apprise model).
|
|
44167
|
-
* `priority` is a 5-level ORDINAL (1=lowest … 3=normal(default) … 5=urgent),
|
|
44168
|
-
* NOT a fixed severity enum — each kind declares its own `caps.levels` and
|
|
44169
|
-
* the adapter maps this ordinal onto its native level. `level?` is an
|
|
44170
|
-
* optional kind-native level id (`emergency`, `silent`, …) that overrides
|
|
44171
|
-
* `priority` for that one target.
|
|
44172
|
-
*/
|
|
44173
|
-
var NotificationSchema = object({
|
|
44174
|
-
body: string(),
|
|
44175
|
-
title: string().optional(),
|
|
44176
|
-
format: NotificationFormatSchema.default("text"),
|
|
44177
|
-
priority: number().int().min(1).max(5).default(3),
|
|
44178
|
-
level: string().optional(),
|
|
44179
|
-
attachments: array(AttachmentSchema).optional(),
|
|
44180
|
-
clickUrl: string().optional(),
|
|
44181
|
-
actions: array(NotificationActionSchema).optional(),
|
|
44182
|
-
sound: string().optional(),
|
|
44183
|
-
ttl: number().optional(),
|
|
44184
|
-
tag: string().optional(),
|
|
44185
|
-
deviceId: number().optional(),
|
|
44186
|
-
eventId: string().optional(),
|
|
44187
|
-
metadata: record(string(), unknown()).optional(),
|
|
44188
|
-
/**
|
|
44189
|
-
* Values for the parameters the target's kind DECLARES in
|
|
44190
|
-
* {@link TargetKindSchema} `deliveryParams`. Already validated against the
|
|
44191
|
-
* declaration by the sender; a notifier reads only the keys it declared.
|
|
44192
|
-
*/
|
|
44193
|
-
delivery: record(string(), DeliveryParamValueSchema).optional()
|
|
44194
|
-
});
|
|
44195
|
-
/** One declared native severity/priority level for a kind. */
|
|
44196
|
-
var TargetKindLevelSchema = object({
|
|
44197
|
-
id: string(),
|
|
44198
|
-
label: string(),
|
|
44199
|
-
/** Which canonical priority (1..5) this level maps to. `null` = qualitative-only. */
|
|
44200
|
-
ordinal: number().int().min(1).max(5).nullable(),
|
|
44201
|
-
flags: object({
|
|
44202
|
-
critical: boolean().optional(),
|
|
44203
|
-
silent: boolean().optional(),
|
|
44204
|
-
noPush: boolean().optional()
|
|
44205
|
-
}).optional(),
|
|
44206
|
-
/** e.g. Pushover `emergency` requires `retry` / `expire`. */
|
|
44207
|
-
requires: array(string()).optional(),
|
|
44208
|
-
description: string().optional()
|
|
44209
|
-
});
|
|
44210
|
-
/** The full capability block consulted before dispatch. */
|
|
44211
|
-
var TargetKindCapsSchema = object({
|
|
44212
|
-
attachments: object({
|
|
44213
|
-
mediaTypes: array(AttachmentMediaTypeSchema),
|
|
44214
|
-
mode: _enum([
|
|
44215
|
-
"url",
|
|
44216
|
-
"bytes",
|
|
44217
|
-
"both"
|
|
44218
|
-
]),
|
|
44219
|
-
max: number().int().nonnegative(),
|
|
44220
|
-
maxBytes: number().int().positive().optional()
|
|
44221
|
-
}),
|
|
44222
|
-
/** Max action buttons (0 = none). */
|
|
44223
|
-
actions: number().int().nonnegative(),
|
|
44224
|
-
/**
|
|
44225
|
-
* Whether this kind renders a per-action ICON.
|
|
44226
|
-
*
|
|
44227
|
-
* `.optional()`, deliberately NOT `.default(false)`: a Zod default does not
|
|
44228
|
-
* run on the addon cap path — three production failures in one day taught
|
|
44229
|
-
* this repo that once. Absent is read as false by the degrade engine, which
|
|
44230
|
-
* is the safe direction: an icon that is not rendered costs nothing, an icon
|
|
44231
|
-
* assumed and dropped costs the operator's trust in the field.
|
|
44232
|
-
*/
|
|
44233
|
-
actionIcons: boolean().optional(),
|
|
44234
|
-
levels: array(TargetKindLevelSchema),
|
|
44235
|
-
format: array(NotificationFormatSchema),
|
|
44236
|
-
clickUrl: boolean(),
|
|
44237
|
-
sound: boolean(),
|
|
44238
|
-
ttl: boolean(),
|
|
44239
|
-
bodyMaxLen: number().int().positive()
|
|
44240
|
-
});
|
|
44241
|
-
/**
|
|
44242
|
-
* `configSchema` is a `ConfigUISchema` tree passed through to the admin
|
|
44243
|
-
* FormBuilder. Stored as `z.unknown()` at the cap seam (mirrors
|
|
44244
|
-
* `device-provider.getChildCreationSchema` `CreationSchemaOutputSchema`) —
|
|
44245
|
-
* the union is large and not meant for runtime validation here; the exported
|
|
44246
|
-
* `TargetKind` type re-tightens `configSchema` to `ConfigUISchema`.
|
|
44247
|
-
*/
|
|
44248
|
-
var ConfigSchemaPassthrough$4 = unknown();
|
|
44249
|
-
var TargetKindSchema = object({
|
|
44250
|
-
kind: string(),
|
|
44251
|
-
label: string(),
|
|
44252
|
-
icon: string(),
|
|
44253
|
-
/** Stamped by each provider so the concat-fanned catalog stays routable. */
|
|
44254
|
-
addonId: string(),
|
|
44255
|
-
/**
|
|
44256
|
-
* URL of the kind's bundled BRAND icon, served by the providing addon over
|
|
44257
|
-
* its own `addon-routes` surface (`/addon/<addonId>/icons/<kind>`). Absent
|
|
44258
|
-
* when the addon bundles no icon for that kind — the client then falls back
|
|
44259
|
-
* to a neutral glyph rather than rendering the raw `icon` NAME as text.
|
|
44260
|
-
*
|
|
44261
|
-
* Root-relative on purpose: it resolves against whatever origin serves a web
|
|
44262
|
-
* client, and a native client joins it onto its own hub base.
|
|
44263
|
-
*
|
|
44264
|
-
* DECLARED here deliberately. It used to travel as an undeclared passthrough
|
|
44265
|
-
* field that survived only because the runtime cap-router forwards provider
|
|
44266
|
-
* output verbatim — so every consumer had to re-declare it by hand to stop
|
|
44267
|
-
* its own Zod parse from stripping it, and the whole arrangement would have
|
|
44268
|
-
* broken silently the moment output validation was tightened anywhere.
|
|
44269
|
-
*/
|
|
44270
|
-
iconUrl: string().optional(),
|
|
44271
|
-
/**
|
|
44272
|
-
* Media type of {@link iconUrl} (`image/svg+xml`, `image/png`, …).
|
|
44273
|
-
*
|
|
44274
|
-
* The server knows this and therefore says it, because the client cannot
|
|
44275
|
-
* safely guess: a React-Native client renders SVG and raster through two
|
|
44276
|
-
* DIFFERENT components (`react-native-svg` vs `expo-image` — expo-image does
|
|
44277
|
-
* not decode SVG on iOS/Android), so without this it silently fell back to a
|
|
44278
|
-
* placeholder glyph for every vector icon while the web build looked fine.
|
|
44279
|
-
*
|
|
44280
|
-
* Absent when {@link iconUrl} is absent, or for a legacy provider that has
|
|
44281
|
-
* not been updated — a client that cannot determine the type should prefer
|
|
44282
|
-
* its raster path, which is the safe default for an unknown image.
|
|
44283
|
-
*/
|
|
44284
|
-
iconMediaType: string().optional(),
|
|
44285
|
-
configSchema: ConfigSchemaPassthrough$4,
|
|
44286
|
-
/**
|
|
44287
|
-
* The config keys that decide WHERE this kind's secrets are sent (server,
|
|
44288
|
-
* base URL, instance, chat, recipient). A save that changes any of them
|
|
44289
|
-
* while leaving a secret redacted is refused by the provider (D634), so an
|
|
44290
|
-
* editor uses this to ask for the secret on exactly those edits instead of
|
|
44291
|
-
* on every edit.
|
|
44292
|
-
*
|
|
44293
|
-
* Optional: absent from a provider that holds no secret (the Home Assistant
|
|
44294
|
-
* kinds) and from a provider older than this field — an editor that finds
|
|
44295
|
-
* it absent must assume ANY edit may need the secret.
|
|
44296
|
-
*/
|
|
44297
|
-
destinationKeys: array(string()).optional(),
|
|
44298
|
-
supportsDiscovery: boolean(),
|
|
44438
|
+
conditions: array(AutomationConditionTraceNodeSchema),
|
|
44439
|
+
verdict: AutomationRunVerdictSchema.optional(),
|
|
44440
|
+
steps: array(AutomationStepTraceSchema),
|
|
44441
|
+
outcome: AutomationRunOutcomeSchema,
|
|
44442
|
+
/** How many identical consecutive skips this trace stands for (>= 1). */
|
|
44443
|
+
repeat: number().int().min(1),
|
|
44444
|
+
/** When the latest of those repeats happened. */
|
|
44445
|
+
lastAt: number(),
|
|
44299
44446
|
/**
|
|
44300
|
-
*
|
|
44301
|
-
*
|
|
44447
|
+
* A scheduler point's own outcome (D983). `outcome` carries the closest
|
|
44448
|
+
* automation outcome so a reader that does not know schedulers still reads
|
|
44449
|
+
* the trace; this field says exactly what happened.
|
|
44302
44450
|
*/
|
|
44303
|
-
|
|
44304
|
-
caps: TargetKindCapsSchema
|
|
44451
|
+
scheduler: SchedulerOutcomeSchema.optional()
|
|
44305
44452
|
});
|
|
44306
44453
|
/**
|
|
44307
|
-
*
|
|
44308
|
-
*
|
|
44309
|
-
* round-trip a stored secret to the UI.
|
|
44454
|
+
* What the hub's `runs` ledger holds for one owner (`automation:<blockId>` or
|
|
44455
|
+
* `action:<actionId>`): the cooldown stamp and the trace ring.
|
|
44310
44456
|
*/
|
|
44311
|
-
var
|
|
44312
|
-
|
|
44313
|
-
|
|
44314
|
-
|
|
44315
|
-
addonId: string(),
|
|
44316
|
-
enabled: boolean(),
|
|
44317
|
-
config: record(string(), unknown())
|
|
44457
|
+
var AutomationStateDocSchema = object({
|
|
44458
|
+
version: literal(1),
|
|
44459
|
+
lastRunStartedAt: number().nullable(),
|
|
44460
|
+
traces: array(AutomationRunTraceSchema)
|
|
44318
44461
|
});
|
|
44319
|
-
/**
|
|
44320
|
-
|
|
44321
|
-
|
|
44322
|
-
|
|
44323
|
-
|
|
44462
|
+
/**
|
|
44463
|
+
* Actions — named, runnable things an operator (or an automation) can start,
|
|
44464
|
+
* declared as LIST ENTRIES, never as devices.
|
|
44465
|
+
*
|
|
44466
|
+
* An entry is either **internal** (a short list of cap/wait steps kept in the
|
|
44467
|
+
* hub's `actions` record kind) or declared by an addon through the
|
|
44468
|
+
* `action-source` collection (a Home Assistant script, a scene …). The one
|
|
44469
|
+
* surface the UI and automations talk to is the `actions` cap; it keeps no
|
|
44470
|
+
* catalog of its own (D3) — every `list` asks the providers live.
|
|
44471
|
+
*
|
|
44472
|
+
* This file is the data half: the entry schema, the variables an entry may
|
|
44473
|
+
* declare, and the pure resolution of the values a run was given. It holds no
|
|
44474
|
+
* runtime.
|
|
44475
|
+
*/
|
|
44476
|
+
/** What a variable's value is. `select` takes one of `options`. */
|
|
44477
|
+
var ActionVariableTypeSchema = _enum([
|
|
44478
|
+
"string",
|
|
44479
|
+
"number",
|
|
44480
|
+
"boolean",
|
|
44481
|
+
"select"
|
|
44482
|
+
]);
|
|
44483
|
+
var ACTION_VARIABLE_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
44484
|
+
var ActionVariableValueSchema = union([
|
|
44485
|
+
string(),
|
|
44486
|
+
number(),
|
|
44487
|
+
boolean()
|
|
44488
|
+
]);
|
|
44489
|
+
/**
|
|
44490
|
+
* One declared variable. Steps reference it as `{ $var: 'name' }` (the whole
|
|
44491
|
+
* value) or `{{vars.name}}` (inside a string) in their args.
|
|
44492
|
+
*/
|
|
44493
|
+
var ActionVariableSchema = object({
|
|
44494
|
+
name: string().regex(ACTION_VARIABLE_NAME_RE),
|
|
44495
|
+
label: string().min(1).max(120).optional(),
|
|
44496
|
+
type: ActionVariableTypeSchema,
|
|
44497
|
+
required: boolean().optional(),
|
|
44498
|
+
default: ActionVariableValueSchema.optional(),
|
|
44499
|
+
/** The allowed values of a `select`. */
|
|
44500
|
+
options: array(string().min(1)).min(1).optional()
|
|
44501
|
+
}).superRefine((v, ctx) => {
|
|
44502
|
+
if (v.type === "select" && v.options === void 0) ctx.addIssue({
|
|
44503
|
+
code: "custom",
|
|
44504
|
+
message: "a select variable needs options",
|
|
44505
|
+
path: ["options"]
|
|
44506
|
+
});
|
|
44507
|
+
if (v.default !== void 0 && variableValueError(v, v.default) !== null) ctx.addIssue({
|
|
44508
|
+
code: "custom",
|
|
44509
|
+
message: variableValueError(v, v.default) ?? "invalid default",
|
|
44510
|
+
path: ["default"]
|
|
44511
|
+
});
|
|
44324
44512
|
});
|
|
44325
|
-
/**
|
|
44326
|
-
|
|
44327
|
-
|
|
44328
|
-
|
|
44329
|
-
|
|
44330
|
-
|
|
44331
|
-
|
|
44332
|
-
|
|
44513
|
+
/** Why `value` is not a legal value for the variable, or null when it is. */
|
|
44514
|
+
function variableValueError(variable, value) {
|
|
44515
|
+
switch (variable.type) {
|
|
44516
|
+
case "string": return typeof value === "string" ? null : `variable "${variable.name}" must be a string`;
|
|
44517
|
+
case "number": return typeof value === "number" && Number.isFinite(value) ? null : `variable "${variable.name}" must be a number`;
|
|
44518
|
+
case "boolean": return typeof value === "boolean" ? null : `variable "${variable.name}" must be true or false`;
|
|
44519
|
+
case "select": return typeof value === "string" && (variable.options ?? []).includes(value) ? null : `variable "${variable.name}" must be one of ${(variable.options ?? []).join(", ")}`;
|
|
44520
|
+
}
|
|
44521
|
+
}
|
|
44522
|
+
var ActionSourceKindSchema = _enum(["internal", "addon"]);
|
|
44523
|
+
function isInternalActionId(actionId) {
|
|
44524
|
+
return actionId.startsWith("internal:") && actionId.length > 9;
|
|
44525
|
+
}
|
|
44526
|
+
/** The addon behind a `<addonId>:<localId>` id, or null for anything else (internal included). */
|
|
44527
|
+
function addonIdOfActionId(actionId) {
|
|
44528
|
+
if (isInternalActionId(actionId)) return null;
|
|
44529
|
+
const at = actionId.indexOf(":");
|
|
44530
|
+
return at > 0 && at < actionId.length - 1 ? actionId.slice(0, at) : null;
|
|
44531
|
+
}
|
|
44532
|
+
var ActionStatusSchema = object({
|
|
44533
|
+
isRunning: boolean(),
|
|
44534
|
+
/** Ms epoch the latest run STARTED; null when it never ran. */
|
|
44535
|
+
lastRunAt: number().nullable(),
|
|
44536
|
+
/** The latest run's failure; null on success or when it never ran. */
|
|
44537
|
+
lastError: string().nullable()
|
|
44333
44538
|
});
|
|
44334
|
-
var
|
|
44335
|
-
|
|
44336
|
-
|
|
44337
|
-
|
|
44539
|
+
var ActionEntrySchema = object({
|
|
44540
|
+
/** `internal:<uuid>` or `<addonId>:<localId>`. */
|
|
44541
|
+
id: string().min(3),
|
|
44542
|
+
name: string().min(1).max(120),
|
|
44543
|
+
/** The addon that declared it; `core-blocks` for an internal one. */
|
|
44544
|
+
addonId: string().min(1),
|
|
44545
|
+
source: ActionSourceKindSchema,
|
|
44546
|
+
/** An addon-declared entry is edited where it was declared. */
|
|
44547
|
+
readOnly: boolean(),
|
|
44548
|
+
/** Internal only: cap and wait steps. No action-in-action, so no cycles. */
|
|
44549
|
+
steps: array(ActionStepSchema).min(1).max(50).optional(),
|
|
44550
|
+
variables: array(ActionVariableSchema).max(20).optional(),
|
|
44551
|
+
status: ActionStatusSchema
|
|
44552
|
+
}).superRefine((entry, ctx) => {
|
|
44553
|
+
if (entry.source === "internal") {
|
|
44554
|
+
if (!isInternalActionId(entry.id)) ctx.addIssue({
|
|
44555
|
+
code: "custom",
|
|
44556
|
+
message: "an internal action id is internal:<uuid>",
|
|
44557
|
+
path: ["id"]
|
|
44558
|
+
});
|
|
44559
|
+
return;
|
|
44560
|
+
}
|
|
44561
|
+
if (entry.steps !== void 0) ctx.addIssue({
|
|
44562
|
+
code: "custom",
|
|
44563
|
+
message: "only an internal action carries steps",
|
|
44564
|
+
path: ["steps"]
|
|
44565
|
+
});
|
|
44566
|
+
if (!entry.readOnly) ctx.addIssue({
|
|
44567
|
+
code: "custom",
|
|
44568
|
+
message: "an addon action is read-only here",
|
|
44569
|
+
path: ["readOnly"]
|
|
44570
|
+
});
|
|
44571
|
+
if (addonIdOfActionId(entry.id) === null) ctx.addIssue({
|
|
44572
|
+
code: "custom",
|
|
44573
|
+
message: "an addon action id is <addonId>:<localId>",
|
|
44574
|
+
path: ["id"]
|
|
44575
|
+
});
|
|
44338
44576
|
});
|
|
44339
|
-
/**
|
|
44340
|
-
var
|
|
44577
|
+
/** What an operator writes for an internal action. */
|
|
44578
|
+
var ActionInputSchema = object({
|
|
44579
|
+
name: string().min(1).max(120),
|
|
44580
|
+
steps: array(ActionStepSchema).min(1).max(50),
|
|
44581
|
+
variables: array(ActionVariableSchema).max(20).optional()
|
|
44582
|
+
});
|
|
44583
|
+
/** Who started a run. Absent = the operator pressed it. */
|
|
44584
|
+
var ActionRunOriginSchema = object({
|
|
44585
|
+
/** The automation block whose step started it. */
|
|
44586
|
+
blockId: string().min(1).optional() });
|
|
44341
44587
|
/**
|
|
44342
|
-
*
|
|
44343
|
-
* `
|
|
44588
|
+
* `started` = the caller did not ask to wait. `timed-out` = the run reached the
|
|
44589
|
+
* ceiling (`ACTION_RUN_MAX_MS`) and was stopped; it is never a `ran`.
|
|
44344
44590
|
*/
|
|
44345
|
-
var
|
|
44346
|
-
|
|
44347
|
-
|
|
44348
|
-
|
|
44349
|
-
|
|
44350
|
-
|
|
44591
|
+
var ActionRunOutcomeSchema = union([
|
|
44592
|
+
AutomationRunOutcomeSchema,
|
|
44593
|
+
literal("started"),
|
|
44594
|
+
literal("timed-out")
|
|
44595
|
+
]);
|
|
44596
|
+
var ActionRunResultSchema = object({
|
|
44597
|
+
runId: string().min(1),
|
|
44598
|
+
outcome: ActionRunOutcomeSchema,
|
|
44599
|
+
/** Why it did not run, or what failed. */
|
|
44600
|
+
message: string().optional()
|
|
44351
44601
|
});
|
|
44352
|
-
|
|
44353
|
-
|
|
44354
|
-
|
|
44355
|
-
|
|
44356
|
-
|
|
44357
|
-
|
|
44358
|
-
|
|
44359
|
-
|
|
44360
|
-
|
|
44361
|
-
|
|
44362
|
-
|
|
44363
|
-
|
|
44364
|
-
/**
|
|
44365
|
-
|
|
44366
|
-
|
|
44367
|
-
|
|
44368
|
-
|
|
44369
|
-
|
|
44370
|
-
|
|
44371
|
-
|
|
44372
|
-
|
|
44373
|
-
|
|
44374
|
-
|
|
44375
|
-
|
|
44376
|
-
|
|
44377
|
-
|
|
44378
|
-
}), TestResultSchema, {
|
|
44379
|
-
kind: "mutation",
|
|
44380
|
-
auth: "admin"
|
|
44381
|
-
}), method(object({
|
|
44382
|
-
target: TargetSchema,
|
|
44383
|
-
/**
|
|
44384
|
-
* Duplicate flow: create a NEW target id while copying secrets from an
|
|
44385
|
-
* existing row. The UI never holds the stored token; blank / redacted
|
|
44386
|
-
* password fields are restored from this source (D634 still applies if
|
|
44387
|
-
* destinations diverge without a re-typed secret).
|
|
44388
|
-
*/
|
|
44389
|
-
cloneSecretsFrom: string().optional()
|
|
44390
|
-
}), TargetSchema, {
|
|
44391
|
-
kind: "mutation",
|
|
44392
|
-
auth: "admin"
|
|
44393
|
-
}), method(object({ targetId: string() }), _void(), {
|
|
44394
|
-
kind: "mutation",
|
|
44395
|
-
auth: "admin"
|
|
44396
|
-
}), method(object({
|
|
44397
|
-
targetId: string(),
|
|
44398
|
-
enabled: boolean()
|
|
44399
|
-
}), _void(), {
|
|
44400
|
-
kind: "mutation",
|
|
44401
|
-
auth: "admin"
|
|
44602
|
+
_enum([
|
|
44603
|
+
"not-found",
|
|
44604
|
+
"read-only",
|
|
44605
|
+
"invalid-variables",
|
|
44606
|
+
"invalid-steps",
|
|
44607
|
+
"not-linked",
|
|
44608
|
+
"busy"
|
|
44609
|
+
]);
|
|
44610
|
+
object({
|
|
44611
|
+
actionId: string(),
|
|
44612
|
+
runId: string(),
|
|
44613
|
+
isRunning: boolean(),
|
|
44614
|
+
/** Set when the run ended. */
|
|
44615
|
+
outcome: AutomationRunOutcomeSchema.optional(),
|
|
44616
|
+
lastRunAt: number().nullable(),
|
|
44617
|
+
lastError: string().nullable()
|
|
44618
|
+
});
|
|
44619
|
+
/** A bare number accepted as a base unit — the save succeeded, say so. */
|
|
44620
|
+
var UnitWarningSchema = object({
|
|
44621
|
+
/** Where in the saved record, e.g. `conditions.children.0` or `steps.2.args.grams`. */
|
|
44622
|
+
path: string(),
|
|
44623
|
+
deviceId: number().int().optional(),
|
|
44624
|
+
field: string(),
|
|
44625
|
+
value: number(),
|
|
44626
|
+
assumedUnit: string(),
|
|
44627
|
+
message: string()
|
|
44402
44628
|
});
|
|
44403
44629
|
_enum([
|
|
44404
44630
|
"automation",
|
|
@@ -44467,6 +44693,8 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
44467
44693
|
kind: "mutation",
|
|
44468
44694
|
auth: "admin"
|
|
44469
44695
|
});
|
|
44696
|
+
/** `timeoutMs` of `actions.run`: a waited call outlives any legal run. */
|
|
44697
|
+
var ACTION_RUN_TIMEOUT_MS = 363e4;
|
|
44470
44698
|
/**
|
|
44471
44699
|
* actions — the ONE surface for runnable actions, for the UI and for
|
|
44472
44700
|
* automations. Provided by the core-blocks builtin on the hub.
|
|
@@ -44485,6 +44713,12 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
44485
44713
|
* An admin, and an in-process caller (an automation block), may run any action.
|
|
44486
44714
|
* Every refusal is typed (`[not-linked] …`) and logged.
|
|
44487
44715
|
*
|
|
44716
|
+
* **A run lasts at most `ACTION_RUN_MAX_MS` (60 min).** The provider stops a
|
|
44717
|
+
* run that reaches it and answers `timed-out` (never `ran`); an action whose
|
|
44718
|
+
* `wait` steps alone add up to more is refused at create/update
|
|
44719
|
+
* (`[invalid-steps]`). `run` declares a `timeoutMs` above that ceiling, so a
|
|
44720
|
+
* waited call (an automation step) is never cut by the 60 s transport default.
|
|
44721
|
+
*
|
|
44488
44722
|
* A second `run` of an action that is already running is REFUSED — traced and
|
|
44489
44723
|
* logged — never queued.
|
|
44490
44724
|
*/
|
|
@@ -44511,7 +44745,8 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
44511
44745
|
role: "viewer",
|
|
44512
44746
|
auth: "protected",
|
|
44513
44747
|
kind: "mutation",
|
|
44514
|
-
caller: "required"
|
|
44748
|
+
caller: "required",
|
|
44749
|
+
timeoutMs: ACTION_RUN_TIMEOUT_MS
|
|
44515
44750
|
}), method(ActionIdInput, _void(), {
|
|
44516
44751
|
kind: "mutation",
|
|
44517
44752
|
auth: "admin"
|
|
@@ -48297,37 +48532,6 @@ method(object({
|
|
|
48297
48532
|
kind: "mutation",
|
|
48298
48533
|
auth: "admin"
|
|
48299
48534
|
}), method(object({ blockIds: array(string()) }), object({ states: array(CompositionBlockStateSchema) }), { auth: "admin" });
|
|
48300
|
-
var ConnectionTestOutcomeSchema = discriminatedUnion("outcome", [
|
|
48301
|
-
object({
|
|
48302
|
-
outcome: literal("validated"),
|
|
48303
|
-
/** Round-trip of the sign-in, when the provider measured it. */
|
|
48304
|
-
latencyMs: number().nonnegative().optional(),
|
|
48305
|
-
/** Optional human detail worth showing next to the tick
|
|
48306
|
-
* ("3 devices visible on this account"). */
|
|
48307
|
-
detail: string().optional()
|
|
48308
|
-
}).strict(),
|
|
48309
|
-
object({
|
|
48310
|
-
outcome: literal("rejected"),
|
|
48311
|
-
error: string()
|
|
48312
|
-
}).strict(),
|
|
48313
|
-
object({
|
|
48314
|
-
outcome: literal("inconclusive"),
|
|
48315
|
-
error: string()
|
|
48316
|
-
}).strict()
|
|
48317
|
-
]);
|
|
48318
|
-
var ConnectionTestInputSchema = object({
|
|
48319
|
-
/** Candidate integration settings, exactly as the create form collected them. */
|
|
48320
|
-
settings: record(string(), unknown()) });
|
|
48321
|
-
/**
|
|
48322
|
-
* What the provider's test actually DOES, so the UI can say it in words before
|
|
48323
|
-
* the operator presses the button ("Signs in to the Dreo cloud"). Purely
|
|
48324
|
-
* descriptive — it never changes routing.
|
|
48325
|
-
*/
|
|
48326
|
-
var ConnectionTestDescriptorSchema = object({ label: string() });
|
|
48327
|
-
method(ConnectionTestInputSchema, ConnectionTestOutcomeSchema, {
|
|
48328
|
-
kind: "mutation",
|
|
48329
|
-
auth: "admin"
|
|
48330
|
-
}), method(_void(), ConnectionTestDescriptorSchema, { auth: "admin" });
|
|
48331
48535
|
object({
|
|
48332
48536
|
/** True when the upstream system considers the entity connected. */
|
|
48333
48537
|
connected: boolean(),
|
|
@@ -48585,6 +48789,9 @@ var MediaPlayerStatusSchema = object({
|
|
|
48585
48789
|
/** Repeat mode. Null when no repeat surface.
|
|
48586
48790
|
* Pair with `DeviceFeature.MediaPlayerRepeat`. */
|
|
48587
48791
|
repeat: MediaPlayerRepeatSchema.nullable(),
|
|
48792
|
+
/** Ms epoch when `position` was read from the device. Null when the driver
|
|
48793
|
+
* does not say; a UI that advances the position while playing counts from it. */
|
|
48794
|
+
positionUpdatedAt: number().nullable().default(null),
|
|
48588
48795
|
/** Ms epoch when the slice was last updated. */
|
|
48589
48796
|
lastChangedAt: number()
|
|
48590
48797
|
});
|
|
@@ -49164,7 +49371,9 @@ var ThresholdTransformDraftSchema = object({
|
|
|
49164
49371
|
comparison: _enum(["gte", "lte"]),
|
|
49165
49372
|
threshold: number(),
|
|
49166
49373
|
startDwellMs: number().nonnegative(),
|
|
49167
|
-
stopDwellMs: number().nonnegative()
|
|
49374
|
+
stopDwellMs: number().nonnegative(),
|
|
49375
|
+
/** Samples a start needs; absent = the compiler's default for the source (2 for running power, else 1). */
|
|
49376
|
+
minSamples: number().int().min(1).optional()
|
|
49168
49377
|
});
|
|
49169
49378
|
var CustomizeTransformDraftSchema = discriminatedUnion("kind", [
|
|
49170
49379
|
IdentityTransformDraftSchema,
|
|
@@ -54117,6 +54326,7 @@ var IntegrationWithStateSchema = object({
|
|
|
54117
54326
|
id: string(),
|
|
54118
54327
|
addonId: string(),
|
|
54119
54328
|
name: string(),
|
|
54329
|
+
/** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
|
|
54120
54330
|
enabled: boolean(),
|
|
54121
54331
|
info: record(string(), unknown()).readonly(),
|
|
54122
54332
|
/** The discovery candidate this integration was set up from (D984). */
|
|
@@ -54129,6 +54339,7 @@ var IntegrationLiteSchema = object({
|
|
|
54129
54339
|
id: string(),
|
|
54130
54340
|
addonId: string(),
|
|
54131
54341
|
name: string(),
|
|
54342
|
+
/** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
|
|
54132
54343
|
enabled: boolean(),
|
|
54133
54344
|
info: record(string(), unknown()).readonly(),
|
|
54134
54345
|
/** The discovery candidate this integration was set up from (D984). */
|
|
@@ -54174,10 +54385,9 @@ var AvailableIntegrationTypeSchema = object({
|
|
|
54174
54385
|
* locations" checkbox. Provider-declared in the addon manifest. */
|
|
54175
54386
|
supportsLocationImport: boolean(),
|
|
54176
54387
|
/**
|
|
54177
|
-
* True when this integration
|
|
54178
|
-
*
|
|
54179
|
-
*
|
|
54180
|
-
* rather than offering a button that always answers the same nonsense.
|
|
54388
|
+
* True when this integration's instances declare a Test (`integration-instances.describe().canTest`,
|
|
54389
|
+
* D1016). An integration that cannot be tested must say so up front rather than offering a
|
|
54390
|
+
* button that always answers the same nonsense.
|
|
54181
54391
|
*/
|
|
54182
54392
|
canTest: boolean(),
|
|
54183
54393
|
existingInstances: array(object({
|
|
@@ -54228,15 +54438,21 @@ var TestConnectionResultSchema = object({
|
|
|
54228
54438
|
var CreateIntegrationInputSchema = object({
|
|
54229
54439
|
addonId: string(),
|
|
54230
54440
|
name: string(),
|
|
54231
|
-
enabled: boolean().optional(),
|
|
54232
54441
|
info: record(string(), unknown()).optional(),
|
|
54233
54442
|
/** `stableId` of the discovery candidate the form was seeded from (D984). */
|
|
54234
54443
|
originStableId: string().optional(),
|
|
54235
|
-
settings: record(string(), unknown()).optional()
|
|
54444
|
+
settings: record(string(), unknown()).optional(),
|
|
54445
|
+
/** The instance kind being created, for a provider with several; omitted = its only testable kind. */
|
|
54446
|
+
kind: string().min(1).optional()
|
|
54236
54447
|
});
|
|
54237
54448
|
var UpdateIntegrationInputSchema = object({
|
|
54238
54449
|
id: string(),
|
|
54239
54450
|
name: string().optional(),
|
|
54451
|
+
/**
|
|
54452
|
+
* Accepted for a FIXED builtin only (`info.fixed`: alarm panel, camera grid, core blocks,
|
|
54453
|
+
* terminal), which keeps no instance record: the registry flag is its one store. Any other
|
|
54454
|
+
* integration is switched through `integration-instances.setInstanceEnabled`.
|
|
54455
|
+
*/
|
|
54240
54456
|
enabled: boolean().optional(),
|
|
54241
54457
|
info: record(string(), unknown()).optional()
|
|
54242
54458
|
});
|
|
@@ -54253,13 +54469,7 @@ method(_void(), array(IntegrationWithStateSchema)), method(object({ id: string()
|
|
|
54253
54469
|
}), method(object({ id: string() }), DeleteIntegrationResultSchema, {
|
|
54254
54470
|
kind: "mutation",
|
|
54255
54471
|
auth: "admin"
|
|
54256
|
-
}), method(_void(), array(AvailableIntegrationTypeSchema), { auth: "admin" })
|
|
54257
|
-
addonId: string(),
|
|
54258
|
-
settings: record(string(), unknown())
|
|
54259
|
-
}), TestConnectionResultSchema, {
|
|
54260
|
-
kind: "mutation",
|
|
54261
|
-
auth: "admin"
|
|
54262
|
-
});
|
|
54472
|
+
}), method(_void(), array(AvailableIntegrationTypeSchema), { auth: "admin" });
|
|
54263
54473
|
/**
|
|
54264
54474
|
* `integration-instances` - the connection of an addon that holds ONE or SEVERAL
|
|
54265
54475
|
* (an account, a relay, a destination) as typed records (D985, D986). The addon's
|
|
@@ -54284,7 +54494,7 @@ var IntegrationInstanceIdSchema = string().min(1);
|
|
|
54284
54494
|
var IntegrationInstanceModeSchema = _enum(["single", "multiple"]);
|
|
54285
54495
|
/**
|
|
54286
54496
|
* What the addon's instances ARE for the Integrations page (planning#416). `devices`: each
|
|
54287
|
-
* instance is an integration that brings devices (
|
|
54497
|
+
* instance is an integration that brings devices (its record body owns the on/off switch);
|
|
54288
54498
|
* `services`: a connection configured from the addon's own function page, never listed on
|
|
54289
54499
|
* Integrations.
|
|
54290
54500
|
* It is the same vocabulary as the manifest's `integrationRole`, which stays as an override.
|
|
@@ -54401,8 +54611,8 @@ var IntegrationInstanceSchema = object({
|
|
|
54401
54611
|
configured: boolean(),
|
|
54402
54612
|
/**
|
|
54403
54613
|
* The instance's own on/off switch (D996), derived from the record body (`enabled !== false`,
|
|
54404
|
-
* so a row written before the field existed is on).
|
|
54405
|
-
*
|
|
54614
|
+
* so a row written before the field existed is on). The same for every role, `devices` included:
|
|
54615
|
+
* the body is the one store, `setInstanceEnabled` the one writer (epic #440, step 3).
|
|
54406
54616
|
*/
|
|
54407
54617
|
enabled: boolean().optional(),
|
|
54408
54618
|
/** The kind of this instance (one of `describe().kinds[].id`), when the provider has kinds. */
|
|
@@ -54452,7 +54662,8 @@ var integrationInstancesCapability = {
|
|
|
54452
54662
|
auth: "admin"
|
|
54453
54663
|
}),
|
|
54454
54664
|
/**
|
|
54455
|
-
* Switch ONE instance on or off
|
|
54665
|
+
* Switch ONE instance on or off, for every role; a missing record is created from the addon's
|
|
54666
|
+
* initial body. A row control, not a form field: `updateInstance.values` is the
|
|
54456
54667
|
* form patch (D62, D996). An off instance keeps its record and secrets and does no work.
|
|
54457
54668
|
*/
|
|
54458
54669
|
setInstanceEnabled: method(object({
|
|
@@ -57263,6 +57474,8 @@ var MigrationIntegrationSchema = object({
|
|
|
57263
57474
|
addonId: string(),
|
|
57264
57475
|
name: string(),
|
|
57265
57476
|
info: Rows,
|
|
57477
|
+
/** The registry's stored switch: read by the one-switch migration, nothing else. */
|
|
57478
|
+
enabled: boolean().optional(),
|
|
57266
57479
|
originStableId: string().optional()
|
|
57267
57480
|
});
|
|
57268
57481
|
var MigrationDeviceSchema = object({
|
|
@@ -62499,13 +62712,6 @@ var AddBrokerInputSchema = object({
|
|
|
62499
62712
|
});
|
|
62500
62713
|
var AddBrokerResultSchema = object({ id: string() });
|
|
62501
62714
|
var IdInputSchema = object({ id: string() });
|
|
62502
|
-
var TestResultSchema$1 = discriminatedUnion("ok", [object({
|
|
62503
|
-
ok: literal(true),
|
|
62504
|
-
latencyMs: number()
|
|
62505
|
-
}), object({
|
|
62506
|
-
ok: literal(false),
|
|
62507
|
-
error: string()
|
|
62508
|
-
})]);
|
|
62509
62715
|
var StartEmbeddedInputSchema = object({
|
|
62510
62716
|
port: number().int().min(1).max(65535).default(1883),
|
|
62511
62717
|
/** Allow anonymous connect (no username/password). Default: false. */
|
|
@@ -62528,9 +62734,6 @@ method(_void(), array(BrokerInfoSchema)), method(IdInputSchema, BrokerConnection
|
|
|
62528
62734
|
}), method(IdInputSchema, _void(), {
|
|
62529
62735
|
kind: "mutation",
|
|
62530
62736
|
auth: "admin"
|
|
62531
|
-
}), method(IdInputSchema, TestResultSchema$1, {
|
|
62532
|
-
kind: "mutation",
|
|
62533
|
-
auth: "admin"
|
|
62534
62737
|
}), method(StartEmbeddedInputSchema, StartEmbeddedResultSchema, {
|
|
62535
62738
|
kind: "mutation",
|
|
62536
62739
|
auth: "admin"
|
|
@@ -66781,14 +66984,6 @@ object({
|
|
|
66781
66984
|
empty: boolean().nullable(),
|
|
66782
66985
|
/** True while the pump is running. Null while unknown. */
|
|
66783
66986
|
pumpRunning: boolean().nullable(),
|
|
66784
|
-
/** Water drunk in the last drink, in litres. */
|
|
66785
|
-
lastDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
66786
|
-
/** Water drunk in the current hour, in litres. */
|
|
66787
|
-
currentHourDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
66788
|
-
/** Water drunk over the last 24 hours (rolling), in litres. */
|
|
66789
|
-
last24hDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
66790
|
-
/** Water drunk since local midnight, in litres. Null when the fountain has no such sensor. */
|
|
66791
|
-
todayDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
66792
66987
|
/** Decoded fault message. Null means healthy; a non-null string is an active fault. */
|
|
66793
66988
|
error: string().nullable(),
|
|
66794
66989
|
/** Ms epoch when the slice was last refreshed. */
|
|
@@ -66801,9 +66996,6 @@ DeviceType.PetFountain, method(object({
|
|
|
66801
66996
|
}), _void(), {
|
|
66802
66997
|
kind: "mutation",
|
|
66803
66998
|
auth: "protected"
|
|
66804
|
-
}), method(object({ deviceId: DeviceIdSchema$1 }), _void(), {
|
|
66805
|
-
kind: "mutation",
|
|
66806
|
-
auth: "protected"
|
|
66807
66999
|
});
|
|
66808
67000
|
/**
|
|
66809
67001
|
* The wire shapes of the Auto tune plan and apply (D745), used by the
|
|
@@ -74166,7 +74358,7 @@ var TrainingProviderTypeSchema = object({
|
|
|
74166
74358
|
label: string(),
|
|
74167
74359
|
/** Path under the addon package (e.g. `assets/training-modal/icon.svg`). */
|
|
74168
74360
|
iconAsset: string(),
|
|
74169
|
-
/** Owning `training-provider` addon
|
|
74361
|
+
/** Owning `training-provider` addon. */
|
|
74170
74362
|
addonId: string(),
|
|
74171
74363
|
/**
|
|
74172
74364
|
* Fields for one entry of this type (credentials + defaults). Absent on a
|
|
@@ -74211,36 +74403,6 @@ var TrainingProviderDescriptorSchema = object({
|
|
|
74211
74403
|
*/
|
|
74212
74404
|
formValues: record(string(), unknown()).optional()
|
|
74213
74405
|
});
|
|
74214
|
-
/**
|
|
74215
|
-
* Patch one entry's name, credentials and defaults. Pin with owning `{ addonId }`.
|
|
74216
|
-
* An omitted or empty `tokenSecret` means KEEP the stored secret (D787).
|
|
74217
|
-
* `{ $secretClear: true }` clears it.
|
|
74218
|
-
*/
|
|
74219
|
-
var TrainingProviderUpdateEntryInputSchema = object({
|
|
74220
|
-
entryId: string().min(1),
|
|
74221
|
-
name: string().min(1),
|
|
74222
|
-
tokenId: string().optional(),
|
|
74223
|
-
tokenSecret: union([string(), object({ $secretClear: literal(true) })]).optional(),
|
|
74224
|
-
environment: string().optional(),
|
|
74225
|
-
gpuType: string().optional(),
|
|
74226
|
-
region: string().optional(),
|
|
74227
|
-
costCapUsd: number().nonnegative().optional(),
|
|
74228
|
-
maxRuntimeSec: number().int().positive().optional(),
|
|
74229
|
-
failedDatasetGraceHours: number().nonnegative().optional()
|
|
74230
|
-
});
|
|
74231
|
-
var TrainingCredentialCheckSchema = object({
|
|
74232
|
-
ok: boolean(),
|
|
74233
|
-
/** Workspace / account name, when the provider says. */
|
|
74234
|
-
account: string().optional(),
|
|
74235
|
-
reason: _enum([
|
|
74236
|
-
"missing",
|
|
74237
|
-
"invalid",
|
|
74238
|
-
"forbidden",
|
|
74239
|
-
"network",
|
|
74240
|
-
"quota"
|
|
74241
|
-
]).optional(),
|
|
74242
|
-
detail: string().optional()
|
|
74243
|
-
});
|
|
74244
74406
|
var ProviderJobStateSchema = _enum([
|
|
74245
74407
|
"pending",
|
|
74246
74408
|
"starting",
|
|
@@ -74288,22 +74450,6 @@ var TrainingLogLineSchema = object({
|
|
|
74288
74450
|
text: string()
|
|
74289
74451
|
});
|
|
74290
74452
|
method(object({}), array(TrainingProviderDescriptorSchema).readonly(), { auth: "admin" }), method(object({}), array(TrainingProviderTypeSchema).readonly(), { auth: "admin" }), method(object({}), array(TrainingProviderEntrySchema).readonly(), { auth: "admin" }), method(object({
|
|
74291
|
-
typeId: string().min(1),
|
|
74292
|
-
name: string().min(1)
|
|
74293
|
-
}), object({ entryId: string() }), {
|
|
74294
|
-
kind: "mutation",
|
|
74295
|
-
auth: "admin"
|
|
74296
|
-
}), method(object({ entryId: string().min(1) }), object({ ok: literal(true) }), {
|
|
74297
|
-
kind: "mutation",
|
|
74298
|
-
auth: "admin"
|
|
74299
|
-
}), method(TrainingProviderUpdateEntryInputSchema, object({ ok: literal(true) }), {
|
|
74300
|
-
kind: "mutation",
|
|
74301
|
-
auth: "admin"
|
|
74302
|
-
}), method(object({ entryId: string().min(1) }), TrainingCredentialCheckSchema, {
|
|
74303
|
-
kind: "mutation",
|
|
74304
|
-
auth: "admin",
|
|
74305
|
-
timeoutMs: 3e4
|
|
74306
|
-
}), method(object({
|
|
74307
74453
|
entryId: string().min(1),
|
|
74308
74454
|
gpuType: string(),
|
|
74309
74455
|
region: string(),
|
|
@@ -77689,20 +77835,6 @@ Object.freeze({
|
|
|
77689
77835
|
access: "view",
|
|
77690
77836
|
role: "admin"
|
|
77691
77837
|
},
|
|
77692
|
-
"connectionTest.describeTest": {
|
|
77693
|
-
capName: "connection-test",
|
|
77694
|
-
capScope: "system",
|
|
77695
|
-
addonId: null,
|
|
77696
|
-
access: "view",
|
|
77697
|
-
role: "admin"
|
|
77698
|
-
},
|
|
77699
|
-
"connectionTest.testSettings": {
|
|
77700
|
-
capName: "connection-test",
|
|
77701
|
-
capScope: "system",
|
|
77702
|
-
addonId: null,
|
|
77703
|
-
access: "create",
|
|
77704
|
-
role: "admin"
|
|
77705
|
-
},
|
|
77706
77838
|
"connectivity.getStatus": {
|
|
77707
77839
|
capName: "connectivity",
|
|
77708
77840
|
capScope: "device",
|
|
@@ -80069,13 +80201,6 @@ Object.freeze({
|
|
|
80069
80201
|
access: "view",
|
|
80070
80202
|
role: "admin"
|
|
80071
80203
|
},
|
|
80072
|
-
"integrations.testConnection": {
|
|
80073
|
-
capName: "integrations",
|
|
80074
|
-
capScope: "system",
|
|
80075
|
-
addonId: null,
|
|
80076
|
-
access: "create",
|
|
80077
|
-
role: "admin"
|
|
80078
|
-
},
|
|
80079
80204
|
"integrations.update": {
|
|
80080
80205
|
capName: "integrations",
|
|
80081
80206
|
capScope: "system",
|
|
@@ -81308,13 +81433,6 @@ Object.freeze({
|
|
|
81308
81433
|
access: "create",
|
|
81309
81434
|
role: "admin"
|
|
81310
81435
|
},
|
|
81311
|
-
"mqttBroker.testConnection": {
|
|
81312
|
-
capName: "mqtt-broker",
|
|
81313
|
-
capScope: "system",
|
|
81314
|
-
addonId: null,
|
|
81315
|
-
access: "create",
|
|
81316
|
-
role: "admin"
|
|
81317
|
-
},
|
|
81318
81436
|
"nativeObjectDetection.getOptions": {
|
|
81319
81437
|
capName: "native-object-detection",
|
|
81320
81438
|
capScope: "device",
|
|
@@ -82190,13 +82308,6 @@ Object.freeze({
|
|
|
82190
82308
|
access: "view",
|
|
82191
82309
|
role: "viewer"
|
|
82192
82310
|
},
|
|
82193
|
-
"petFountain.resetDailyConsumption": {
|
|
82194
|
-
capName: "pet-fountain",
|
|
82195
|
-
capScope: "device",
|
|
82196
|
-
addonId: null,
|
|
82197
|
-
access: "delete",
|
|
82198
|
-
role: "viewer"
|
|
82199
|
-
},
|
|
82200
82311
|
"petFountain.setPump": {
|
|
82201
82312
|
capName: "pet-fountain",
|
|
82202
82313
|
capScope: "device",
|
|
@@ -86152,20 +86263,6 @@ Object.freeze({
|
|
|
86152
86263
|
access: "create",
|
|
86153
86264
|
role: "admin"
|
|
86154
86265
|
},
|
|
86155
|
-
"trainingProvider.createEntry": {
|
|
86156
|
-
capName: "training-provider",
|
|
86157
|
-
capScope: "system",
|
|
86158
|
-
addonId: null,
|
|
86159
|
-
access: "create",
|
|
86160
|
-
role: "admin"
|
|
86161
|
-
},
|
|
86162
|
-
"trainingProvider.deleteEntry": {
|
|
86163
|
-
capName: "training-provider",
|
|
86164
|
-
capScope: "system",
|
|
86165
|
-
addonId: null,
|
|
86166
|
-
access: "delete",
|
|
86167
|
-
role: "admin"
|
|
86168
|
-
},
|
|
86169
86266
|
"trainingProvider.describe": {
|
|
86170
86267
|
capName: "training-provider",
|
|
86171
86268
|
capScope: "system",
|
|
@@ -86236,13 +86333,6 @@ Object.freeze({
|
|
|
86236
86333
|
access: "create",
|
|
86237
86334
|
role: "admin"
|
|
86238
86335
|
},
|
|
86239
|
-
"trainingProvider.updateEntry": {
|
|
86240
|
-
capName: "training-provider",
|
|
86241
|
-
capScope: "system",
|
|
86242
|
-
addonId: null,
|
|
86243
|
-
access: "create",
|
|
86244
|
-
role: "admin"
|
|
86245
|
-
},
|
|
86246
86336
|
"trainingProvider.uploadDataset": {
|
|
86247
86337
|
capName: "training-provider",
|
|
86248
86338
|
capScope: "system",
|
|
@@ -86250,13 +86340,6 @@ Object.freeze({
|
|
|
86250
86340
|
access: "create",
|
|
86251
86341
|
role: "admin"
|
|
86252
86342
|
},
|
|
86253
|
-
"trainingProvider.validateCredentials": {
|
|
86254
|
-
capName: "training-provider",
|
|
86255
|
-
capScope: "system",
|
|
86256
|
-
addonId: null,
|
|
86257
|
-
access: "create",
|
|
86258
|
-
role: "admin"
|
|
86259
|
-
},
|
|
86260
86343
|
"turnProvider.getTurnServers": {
|
|
86261
86344
|
capName: "turn-provider",
|
|
86262
86345
|
capScope: "system",
|
|
@@ -88593,11 +88676,6 @@ Object.freeze({
|
|
|
88593
88676
|
form: "single",
|
|
88594
88677
|
optional: false
|
|
88595
88678
|
}],
|
|
88596
|
-
"petFountain.resetDailyConsumption": [{
|
|
88597
|
-
name: "deviceId",
|
|
88598
|
-
form: "single",
|
|
88599
|
-
optional: false
|
|
88600
|
-
}],
|
|
88601
88679
|
"petFountain.setPump": [{
|
|
88602
88680
|
name: "deviceId",
|
|
88603
88681
|
form: "single",
|
|
@@ -91385,11 +91463,6 @@ function linkFieldDescriptor(key, target, labels) {
|
|
|
91385
91463
|
...target.kind !== void 0 ? { kind: target.kind } : {}
|
|
91386
91464
|
};
|
|
91387
91465
|
}
|
|
91388
|
-
/**
|
|
91389
|
-
* Declare the record kind of a service that links to other instances. The body is
|
|
91390
|
-
* `{ name, ...links, ...fields }`; the links are recorded in the kind (read back by
|
|
91391
|
-
* {@link linksOfKind}) so the hub can index who points at what.
|
|
91392
|
-
*/
|
|
91393
91466
|
function declareLinkKind(spec) {
|
|
91394
91467
|
const linkShape = {};
|
|
91395
91468
|
for (const [field, target] of Object.entries(spec.links)) linkShape[field] = linkField(target);
|
|
@@ -91446,7 +91519,6 @@ function buildLinkedInstances(records, spec) {
|
|
|
91446
91519
|
});
|
|
91447
91520
|
return instances;
|
|
91448
91521
|
}
|
|
91449
|
-
entryBody({ brokerId: string() });
|
|
91450
91522
|
/**
|
|
91451
91523
|
* The calendars an account imports leave the account (D1013). An account record used to carry a
|
|
91452
91524
|
* `calendarIds` array; each calendar is now a record of its own that LINKS to the account
|
|
@@ -91549,22 +91621,12 @@ var GoogleBrokerEntrySchema = object({
|
|
|
91549
91621
|
fromAddress: string().default(""),
|
|
91550
91622
|
fromName: string().default("")
|
|
91551
91623
|
});
|
|
91552
|
-
|
|
91553
|
-
|
|
91554
|
-
|
|
91555
|
-
|
|
91556
|
-
|
|
91557
|
-
clientSecret: string().optional().meta({ secret: true }),
|
|
91558
|
-
/** @deprecated Pre-broker singleton — cleared after migrateLegacyToBrokers. */
|
|
91559
|
-
calendarFilter: string().optional(),
|
|
91560
|
-
/** @deprecated Pre-broker singleton — cleared after migrateLegacyToBrokers. */
|
|
91561
|
-
fromAddress: string().optional(),
|
|
91562
|
-
/** @deprecated Pre-broker singleton — cleared after migrateLegacyToBrokers. */
|
|
91563
|
-
fromName: string().optional()
|
|
91564
|
-
});
|
|
91624
|
+
/**
|
|
91625
|
+
* The addon keeps no addon-level settings: every account is a `brokers` record and its tokens
|
|
91626
|
+
* live in the durable `oauthAccounts` state.
|
|
91627
|
+
*/
|
|
91628
|
+
var GoogleServicesConfigSchema = object({});
|
|
91565
91629
|
var DEFAULT_GOOGLE_CONFIG = GoogleServicesConfigSchema.parse({});
|
|
91566
|
-
/** Flat pre-broker config (singleton). Parsed only for one-shot migration. */
|
|
91567
|
-
var LegacyGoogleFlatConfigSchema = GoogleServicesConfigSchema;
|
|
91568
91630
|
var DEFAULT_OAUTH_STATE = {
|
|
91569
91631
|
refreshToken: "",
|
|
91570
91632
|
accessToken: "",
|
|
@@ -91634,52 +91696,6 @@ function brokerEntryToSettings(entry) {
|
|
|
91634
91696
|
fromName: entry.fromName
|
|
91635
91697
|
};
|
|
91636
91698
|
}
|
|
91637
|
-
/**
|
|
91638
|
-
* One-shot: flat singleton config + legacy `oauth` state → `google_001`.
|
|
91639
|
-
* Idempotent when `brokers` already present.
|
|
91640
|
-
*/
|
|
91641
|
-
function migrateLegacyToBrokers(rawConfig, legacyOauth) {
|
|
91642
|
-
const loose = LegacyGoogleFlatConfigSchema.safeParse(rawConfig);
|
|
91643
|
-
const flat = loose.success ? loose.data : {};
|
|
91644
|
-
const existingBrokers = flat.brokers ?? [];
|
|
91645
|
-
if (existingBrokers.length > 0) return {
|
|
91646
|
-
brokers: existingBrokers.map((b) => GoogleBrokerEntrySchema.parse(b)),
|
|
91647
|
-
oauthAccounts: [],
|
|
91648
|
-
didMigrate: false
|
|
91649
|
-
};
|
|
91650
|
-
const hasClient = (flat.clientId ?? "").length > 0 || (flat.clientSecret ?? "").length > 0;
|
|
91651
|
-
const hasOauth = legacyOauth !== null && legacyOauth.refreshToken.length > 0;
|
|
91652
|
-
if (!hasClient && !hasOauth) return {
|
|
91653
|
-
brokers: [],
|
|
91654
|
-
oauthAccounts: [],
|
|
91655
|
-
didMigrate: false
|
|
91656
|
-
};
|
|
91657
|
-
const id = "google_001";
|
|
91658
|
-
const email = legacyOauth?.accountEmail?.trim() ?? "";
|
|
91659
|
-
const name = email.length > 0 ? email : "Google account";
|
|
91660
|
-
const entry = GoogleBrokerEntrySchema.parse({
|
|
91661
|
-
id,
|
|
91662
|
-
name,
|
|
91663
|
-
clientId: flat.clientId ?? "",
|
|
91664
|
-
clientSecret: flat.clientSecret ?? "",
|
|
91665
|
-
calendarFilter: flat.calendarFilter ?? "",
|
|
91666
|
-
fromAddress: flat.fromAddress ?? "",
|
|
91667
|
-
fromName: flat.fromName ?? ""
|
|
91668
|
-
});
|
|
91669
|
-
const oauthAccounts = legacyOauth !== null && (legacyOauth.refreshToken.length > 0 || legacyOauth.accessToken.length > 0) ? [{
|
|
91670
|
-
id,
|
|
91671
|
-
refreshToken: legacyOauth.refreshToken,
|
|
91672
|
-
accessToken: legacyOauth.accessToken,
|
|
91673
|
-
accessExpiresAt: legacyOauth.accessExpiresAt,
|
|
91674
|
-
accountEmail: legacyOauth.accountEmail,
|
|
91675
|
-
needsReauth: false
|
|
91676
|
-
}] : [];
|
|
91677
|
-
return {
|
|
91678
|
-
brokers: [entry],
|
|
91679
|
-
oauthAccounts,
|
|
91680
|
-
didMigrate: true
|
|
91681
|
-
};
|
|
91682
|
-
}
|
|
91683
91699
|
/** Local calendar id stamped as `brokerId:googleCalendarId`. */
|
|
91684
91700
|
function stampCalendarId(brokerId, googleCalendarId) {
|
|
91685
91701
|
return `${brokerId}:${googleCalendarId}`;
|
|
@@ -91795,9 +91811,6 @@ var GoogleBrokerRegistry = class {
|
|
|
91795
91811
|
connectedSize() {
|
|
91796
91812
|
return this.entries.filter((e) => this.isConnected(e.id)).length;
|
|
91797
91813
|
}
|
|
91798
|
-
toConfig() {
|
|
91799
|
-
return { brokers: [...this.entries] };
|
|
91800
|
-
}
|
|
91801
91814
|
seedCounterFromEntries(entries) {
|
|
91802
91815
|
let maxSeen = 0;
|
|
91803
91816
|
for (const e of entries) {
|
|
@@ -92708,6 +92721,245 @@ async function planDropSharedCalendarIds(ports) {
|
|
|
92708
92721
|
} })
|
|
92709
92722
|
}] };
|
|
92710
92723
|
}
|
|
92724
|
+
//#endregion
|
|
92725
|
+
//#region src/migrations/drop-config-brokers-and-legacy-oauth.ts
|
|
92726
|
+
/**
|
|
92727
|
+
* The addon-level `brokers` setting and the singleton `oauth` state are gone (planning#440 step 5):
|
|
92728
|
+
* every account is a `brokers` record and its tokens live in `oauthAccounts`. This deletes the two
|
|
92729
|
+
* leftover keys, each only when nothing in them is still the only copy:
|
|
92730
|
+
*
|
|
92731
|
+
* - `brokers` goes when the `brokers` kind holds records, or when the setting itself is empty. A
|
|
92732
|
+
* non-empty setting with an empty kind was never copied: it stays.
|
|
92733
|
+
* - `oauth` goes when it carries no token (the empty state the old boot migration left behind), or
|
|
92734
|
+
* when `oauthAccounts` already holds accounts. A token with no account to hold it stays.
|
|
92735
|
+
*
|
|
92736
|
+
* Each edit carries a precondition read, so a row that changed since the plan was made is not
|
|
92737
|
+
* deleted; a second run finds nothing to plan.
|
|
92738
|
+
*/
|
|
92739
|
+
var BROKERS_KEY = "brokers";
|
|
92740
|
+
var LEGACY_OAUTH_KEY = "oauth";
|
|
92741
|
+
/** The flat singleton client the boot migration used to clear. */
|
|
92742
|
+
var FLAT_KEYS = [
|
|
92743
|
+
"clientId",
|
|
92744
|
+
"clientSecret",
|
|
92745
|
+
"calendarFilter",
|
|
92746
|
+
"fromAddress",
|
|
92747
|
+
"fromName"
|
|
92748
|
+
];
|
|
92749
|
+
var OAUTH_ACCOUNTS_KEY = "oauthAccounts";
|
|
92750
|
+
function present$1(answer, key) {
|
|
92751
|
+
if (answer.kind === "unreadable") throw new Error(`google-services: the stored '${key}' cannot be read (${answer.reason})`);
|
|
92752
|
+
return answer.kind === "absent" ? null : { value: answer.value };
|
|
92753
|
+
}
|
|
92754
|
+
function field(value, key) {
|
|
92755
|
+
return typeof value === "object" && value !== null ? Reflect.get(value, key) : void 0;
|
|
92756
|
+
}
|
|
92757
|
+
/** A token field that holds nothing: absent or the empty string. A secret marker is something. */
|
|
92758
|
+
function isBlank(value) {
|
|
92759
|
+
return value === void 0 || value === null || value === "";
|
|
92760
|
+
}
|
|
92761
|
+
function stringList(value) {
|
|
92762
|
+
if (!Array.isArray(value)) return null;
|
|
92763
|
+
const out = [];
|
|
92764
|
+
for (const item of value) {
|
|
92765
|
+
if (typeof item !== "string") return null;
|
|
92766
|
+
out.push(item);
|
|
92767
|
+
}
|
|
92768
|
+
return out;
|
|
92769
|
+
}
|
|
92770
|
+
function holdsAccounts(value) {
|
|
92771
|
+
const accounts = field(value, "accounts");
|
|
92772
|
+
return Array.isArray(accounts) && accounts.length > 0;
|
|
92773
|
+
}
|
|
92774
|
+
async function planDropConfigBrokersAndLegacyOauth(ports) {
|
|
92775
|
+
const rows = {};
|
|
92776
|
+
const keys = [];
|
|
92777
|
+
const take = (key, value) => {
|
|
92778
|
+
const id = `${GOOGLE_ADDON_ID}.${key}`;
|
|
92779
|
+
keys.push(id);
|
|
92780
|
+
rows[id] = {
|
|
92781
|
+
addonId: GOOGLE_ADDON_ID,
|
|
92782
|
+
key,
|
|
92783
|
+
value
|
|
92784
|
+
};
|
|
92785
|
+
};
|
|
92786
|
+
const brokers = present$1(await ports.readStored(BROKERS_KEY), BROKERS_KEY);
|
|
92787
|
+
if (brokers !== null) {
|
|
92788
|
+
if (!(Array.isArray(brokers.value) && brokers.value.length > 0) || (await ports.listBrokers()).length > 0) take(BROKERS_KEY, brokers.value);
|
|
92789
|
+
}
|
|
92790
|
+
for (const key of FLAT_KEYS) {
|
|
92791
|
+
const flat = present$1(await ports.readStored(key), key);
|
|
92792
|
+
if (flat !== null && (await ports.listBrokers()).length > 0) take(key, flat.value);
|
|
92793
|
+
}
|
|
92794
|
+
const shared = present$1(await ports.readStored(SHARED_CALENDAR_IDS_KEY), SHARED_CALENDAR_IDS_KEY);
|
|
92795
|
+
if (shared !== null) {
|
|
92796
|
+
const sharedIds = stringList(shared.value);
|
|
92797
|
+
if (sharedIds === null) throw new Error(`google-services: the stored '${SHARED_CALENDAR_IDS_KEY}' is not a list of ids — nothing dropped`);
|
|
92798
|
+
else {
|
|
92799
|
+
const brokers = await ports.listBrokers();
|
|
92800
|
+
const same = (ids) => ids === void 0 || ids.length === sharedIds.length && ids.every((id) => sharedIds.includes(id));
|
|
92801
|
+
if (brokers.length > 0 && brokers.every((b) => same(b.calendarIds))) take(SHARED_CALENDAR_IDS_KEY, shared.value);
|
|
92802
|
+
}
|
|
92803
|
+
}
|
|
92804
|
+
const oauth = present$1(await ports.readStored(LEGACY_OAUTH_KEY), LEGACY_OAUTH_KEY);
|
|
92805
|
+
if (oauth !== null) {
|
|
92806
|
+
const tokenless = isBlank(field(oauth.value, "refreshToken")) && isBlank(field(oauth.value, "accessToken"));
|
|
92807
|
+
const accounts = present$1(await ports.readStored(OAUTH_ACCOUNTS_KEY), OAUTH_ACCOUNTS_KEY);
|
|
92808
|
+
if (tokenless || accounts !== null && holdsAccounts(accounts.value)) take(LEGACY_OAUTH_KEY, oauth.value);
|
|
92809
|
+
}
|
|
92810
|
+
if (keys.length === 0) return { edits: [] };
|
|
92811
|
+
return { edits: [{
|
|
92812
|
+
op: "deleteKeys",
|
|
92813
|
+
scope: ADDON_SETTINGS_TABLE,
|
|
92814
|
+
keys,
|
|
92815
|
+
precondition: preconditionOf(rows)
|
|
92816
|
+
}] };
|
|
92817
|
+
}
|
|
92818
|
+
//#endregion
|
|
92819
|
+
//#region src/migrations/legacy-brokers-to-records.ts
|
|
92820
|
+
/**
|
|
92821
|
+
* The accounts a pre-record install kept in the addon settings become `brokers` records and
|
|
92822
|
+
* `oauthAccounts` entries (planning#440 step 5). Three legacy shapes feed it, the ones the boot
|
|
92823
|
+
* migration used to read:
|
|
92824
|
+
*
|
|
92825
|
+
* - the `brokers` setting (a list of entries);
|
|
92826
|
+
* - the flat singleton (`clientId`, `clientSecret`, `calendarFilter`, `fromAddress`, `fromName`),
|
|
92827
|
+
* which becomes `google_001`;
|
|
92828
|
+
* - the singleton `oauth` state, whose token follows its account (`google_001`, or the first
|
|
92829
|
+
* broker when brokers already existed).
|
|
92830
|
+
*
|
|
92831
|
+
* Reads come RESOLVED (the settings view answers values, not keychain markers); a value the
|
|
92832
|
+
* keychain could not serve is not a string and REFUSES the step, so nothing is written from a
|
|
92833
|
+
* guess. Each record is read back with its secret before the step reports done, and an account
|
|
92834
|
+
* that already has a record is never overwritten. The shared `calendarIds` set goes onto every
|
|
92835
|
+
* broker this step creates (the calendar migrations before it found no broker to give it to),
|
|
92836
|
+
* then becomes calendar records, so the selection is not lost whichever order the steps ran in. The legacy keys stay where they are: the drop
|
|
92837
|
+
* migration deletes them only after this one landed.
|
|
92838
|
+
*/
|
|
92839
|
+
var LEGACY_BROKER_ID = "google_001";
|
|
92840
|
+
var LEGACY_FLAT_KEYS = [
|
|
92841
|
+
"clientId",
|
|
92842
|
+
"clientSecret",
|
|
92843
|
+
"calendarFilter",
|
|
92844
|
+
"fromAddress",
|
|
92845
|
+
"fromName"
|
|
92846
|
+
];
|
|
92847
|
+
function present(answer, key) {
|
|
92848
|
+
if (answer.kind === "unreadable") throw new Error(`google-services: the stored '${key}' cannot be read (${answer.reason})`);
|
|
92849
|
+
return answer.kind === "absent" ? void 0 : answer.value;
|
|
92850
|
+
}
|
|
92851
|
+
function text(value, what) {
|
|
92852
|
+
if (value === void 0 || value === null) return "";
|
|
92853
|
+
if (typeof value === "string") return value;
|
|
92854
|
+
throw new Error(`google-services: ${what} is not a plain value (is the keychain available?)`);
|
|
92855
|
+
}
|
|
92856
|
+
function legacyOauthOf(value) {
|
|
92857
|
+
if (typeof value !== "object" || value === null) return null;
|
|
92858
|
+
const refreshToken = text(Reflect.get(value, "refreshToken"), "the legacy oauth refreshToken");
|
|
92859
|
+
if (refreshToken.length === 0) return null;
|
|
92860
|
+
const expires = Reflect.get(value, "accessExpiresAt");
|
|
92861
|
+
return {
|
|
92862
|
+
refreshToken,
|
|
92863
|
+
accessToken: text(Reflect.get(value, "accessToken"), "the legacy oauth accessToken"),
|
|
92864
|
+
accessExpiresAt: typeof expires === "number" ? expires : 0,
|
|
92865
|
+
accountEmail: text(Reflect.get(value, "accountEmail"), "the legacy oauth accountEmail").trim()
|
|
92866
|
+
};
|
|
92867
|
+
}
|
|
92868
|
+
async function flatFields(ports) {
|
|
92869
|
+
const out = {};
|
|
92870
|
+
for (const key of LEGACY_FLAT_KEYS) out[key] = text(present(await ports.readStored(key), key), `the stored '${key}'`);
|
|
92871
|
+
return out;
|
|
92872
|
+
}
|
|
92873
|
+
async function legacyEntries(ports, oauth) {
|
|
92874
|
+
const listed = present(await ports.readStored("brokers"), "brokers");
|
|
92875
|
+
if (Array.isArray(listed) && listed.length > 0) return listed.map((item) => {
|
|
92876
|
+
const parsed = GoogleBrokerEntrySchema.safeParse(item);
|
|
92877
|
+
if (!parsed.success) throw new Error(`google-services: a stored broker is invalid — ${parsed.error.message}`);
|
|
92878
|
+
return parsed.data;
|
|
92879
|
+
});
|
|
92880
|
+
const flat = await flatFields(ports);
|
|
92881
|
+
if (!flat["clientId"] && !flat["clientSecret"] && oauth === null) return [];
|
|
92882
|
+
const email = oauth?.accountEmail ?? "";
|
|
92883
|
+
return [GoogleBrokerEntrySchema.parse({
|
|
92884
|
+
id: LEGACY_BROKER_ID,
|
|
92885
|
+
name: email.length > 0 ? email : "Google account",
|
|
92886
|
+
...flat
|
|
92887
|
+
})];
|
|
92888
|
+
}
|
|
92889
|
+
async function sharedCalendarIds(ports) {
|
|
92890
|
+
const value = present(await ports.readStored("calendarIds"), "calendarIds");
|
|
92891
|
+
if (value === void 0) return null;
|
|
92892
|
+
if (!Array.isArray(value) || !value.every((item) => typeof item === "string")) throw new Error("google-services: the shared calendarIds is not a list of ids — nothing copied");
|
|
92893
|
+
return value;
|
|
92894
|
+
}
|
|
92895
|
+
/** The keys a legacy install left that no record holds yet, for the init warning. */
|
|
92896
|
+
async function leftoverLegacyKeys(ports) {
|
|
92897
|
+
const left = [];
|
|
92898
|
+
const listed = await ports.readStored("brokers");
|
|
92899
|
+
if (listed.kind === "present" && Array.isArray(listed.value) && listed.value.length > 0) left.push("brokers");
|
|
92900
|
+
for (const key of ["clientId", "clientSecret"]) {
|
|
92901
|
+
const answer = await ports.readStored(key);
|
|
92902
|
+
if (answer.kind === "present" && answer.value !== "" && answer.value !== null) left.push(key);
|
|
92903
|
+
}
|
|
92904
|
+
const oauth = await ports.readStored("oauth");
|
|
92905
|
+
if (oauth.kind === "present") {
|
|
92906
|
+
const token = typeof oauth.value === "object" && oauth.value !== null ? Reflect.get(oauth.value, "refreshToken") : void 0;
|
|
92907
|
+
if (token !== void 0 && token !== "" && token !== null) left.push("oauth");
|
|
92908
|
+
}
|
|
92909
|
+
return left;
|
|
92910
|
+
}
|
|
92911
|
+
async function copyLegacyBrokersToRecords(ports) {
|
|
92912
|
+
const oauth = legacyOauthOf(present(await ports.readStored("oauth"), "oauth"));
|
|
92913
|
+
const entries = await legacyEntries(ports, oauth);
|
|
92914
|
+
if (entries.length === 0) return {
|
|
92915
|
+
outcome: "already-done",
|
|
92916
|
+
summary: { reason: "no-legacy-data" }
|
|
92917
|
+
};
|
|
92918
|
+
const have = new Set((await ports.listBrokers()).map((b) => b.id));
|
|
92919
|
+
const shared = await sharedCalendarIds(ports);
|
|
92920
|
+
let created = 0;
|
|
92921
|
+
let selections = 0;
|
|
92922
|
+
for (const entry of entries) {
|
|
92923
|
+
if (have.has(entry.id)) continue;
|
|
92924
|
+
await ports.putBroker(entry);
|
|
92925
|
+
const back = await ports.readBroker(entry.id);
|
|
92926
|
+
if (back === null || back.clientId !== entry.clientId || back.clientSecret !== entry.clientSecret) throw new Error(`google-services: broker '${entry.id}' did not read back as written`);
|
|
92927
|
+
created += 1;
|
|
92928
|
+
if (shared !== null && await ports.setBrokerCalendarIds(entry.id, shared)) selections += 1;
|
|
92929
|
+
}
|
|
92930
|
+
if (selections > 0) await moveCalendarIdsToRecords(ports, { calendarIdOf: (accountId, stamped) => {
|
|
92931
|
+
const parsed = parseStampedCalendarId(stamped);
|
|
92932
|
+
return parsed?.brokerId === accountId ? parsed.googleCalendarId : null;
|
|
92933
|
+
} });
|
|
92934
|
+
let account = 0;
|
|
92935
|
+
const primary = entries[0];
|
|
92936
|
+
if (oauth !== null && primary !== void 0) {
|
|
92937
|
+
if ((await ports.listOauthAccountIds()).length === 0) {
|
|
92938
|
+
await ports.putOauthAccount({
|
|
92939
|
+
id: primary.id,
|
|
92940
|
+
refreshToken: oauth.refreshToken,
|
|
92941
|
+
accessToken: oauth.accessToken,
|
|
92942
|
+
accessExpiresAt: oauth.accessExpiresAt,
|
|
92943
|
+
accountEmail: oauth.accountEmail,
|
|
92944
|
+
needsReauth: false
|
|
92945
|
+
});
|
|
92946
|
+
const back = await ports.readOauthAccount(primary.id);
|
|
92947
|
+
if (back === null || back.refreshToken !== oauth.refreshToken) throw new Error(`google-services: the oauth account of '${primary.id}' did not read back`);
|
|
92948
|
+
account = 1;
|
|
92949
|
+
}
|
|
92950
|
+
}
|
|
92951
|
+
return {
|
|
92952
|
+
outcome: created + account === 0 ? "already-done" : "done",
|
|
92953
|
+
summary: {
|
|
92954
|
+
brokers: created,
|
|
92955
|
+
oauthAccounts: account
|
|
92956
|
+
}
|
|
92957
|
+
};
|
|
92958
|
+
}
|
|
92959
|
+
//#endregion
|
|
92960
|
+
//#region src/migrations/index.ts
|
|
92961
|
+
var CALENDAR_IDS_TO_RECORDS_ID = "google-services/2026-11-07-calendar-ids-to-calendar-records";
|
|
92962
|
+
var LEGACY_BROKERS_TO_RECORDS_ID = "google-services/2026-11-06-legacy-brokers-to-records";
|
|
92711
92963
|
/** The `google-services` catalogue (D987): offered to the engine when the addon initialises. */
|
|
92712
92964
|
var ADDON_MIGRATIONS = [
|
|
92713
92965
|
{
|
|
@@ -92744,7 +92996,7 @@ var ADDON_MIGRATIONS = [
|
|
|
92744
92996
|
},
|
|
92745
92997
|
{
|
|
92746
92998
|
meta: {
|
|
92747
|
-
id:
|
|
92999
|
+
id: CALENDAR_IDS_TO_RECORDS_ID,
|
|
92748
93000
|
owner: "google-services",
|
|
92749
93001
|
level: "addon-state",
|
|
92750
93002
|
seq: 3,
|
|
@@ -92760,6 +93012,38 @@ var ADDON_MIGRATIONS = [
|
|
|
92760
93012
|
const parsed = parseStampedCalendarId(entry);
|
|
92761
93013
|
return parsed?.brokerId === accountId ? parsed.googleCalendarId : null;
|
|
92762
93014
|
} })
|
|
93015
|
+
},
|
|
93016
|
+
{
|
|
93017
|
+
meta: {
|
|
93018
|
+
id: LEGACY_BROKERS_TO_RECORDS_ID,
|
|
93019
|
+
owner: "google-services",
|
|
93020
|
+
level: "addon-state",
|
|
93021
|
+
seq: 4,
|
|
93022
|
+
dependsOn: [CALENDAR_IDS_TO_RECORDS_ID],
|
|
93023
|
+
store: "settings",
|
|
93024
|
+
scope: "cluster",
|
|
93025
|
+
onFailure: "tolerate",
|
|
93026
|
+
bodyKind: "procedure",
|
|
93027
|
+
description: "Copy the addon-level brokers setting or the flat singleton client, and the legacy oauth token, into broker records and oauthAccounts, each read back",
|
|
93028
|
+
fixtureMark: "the client secret of a flat singleton, read back from its record"
|
|
93029
|
+
},
|
|
93030
|
+
procedure: copyLegacyBrokersToRecords
|
|
93031
|
+
},
|
|
93032
|
+
{
|
|
93033
|
+
meta: {
|
|
93034
|
+
id: "google-services/2026-11-06-drop-config-brokers-and-legacy-oauth",
|
|
93035
|
+
owner: "google-services",
|
|
93036
|
+
level: "addon-state",
|
|
93037
|
+
seq: 5,
|
|
93038
|
+
dependsOn: [LEGACY_BROKERS_TO_RECORDS_ID],
|
|
93039
|
+
store: "settings",
|
|
93040
|
+
scope: "cluster",
|
|
93041
|
+
onFailure: "tolerate",
|
|
93042
|
+
bodyKind: "plan",
|
|
93043
|
+
description: "Delete the addon-level brokers setting once the brokers records exist, and the singleton oauth state once it holds no token",
|
|
93044
|
+
fixtureMark: "the brokers setting kept when its records are missing"
|
|
93045
|
+
},
|
|
93046
|
+
plan: planDropConfigBrokersAndLegacyOauth
|
|
92763
93047
|
}
|
|
92764
93048
|
];
|
|
92765
93049
|
//#endregion
|
|
@@ -92845,6 +93129,22 @@ var GoogleBrokerStore = class GoogleBrokerStore {
|
|
|
92845
93129
|
}
|
|
92846
93130
|
return out;
|
|
92847
93131
|
}
|
|
93132
|
+
async putOne(entry) {
|
|
93133
|
+
const { id, name, clientId, clientSecret, calendarFilter, fromAddress, fromName } = entry;
|
|
93134
|
+
const parsed = googleBrokersEntryKind.schema.safeParse({
|
|
93135
|
+
name,
|
|
93136
|
+
clientId,
|
|
93137
|
+
clientSecret,
|
|
93138
|
+
calendarFilter,
|
|
93139
|
+
fromAddress,
|
|
93140
|
+
fromName
|
|
93141
|
+
});
|
|
93142
|
+
if (!parsed.success) throw new Error(`invalid Google broker '${id}': ${parsed.error.message}`);
|
|
93143
|
+
await this.kind.put({
|
|
93144
|
+
id,
|
|
93145
|
+
data: parsed.data
|
|
93146
|
+
});
|
|
93147
|
+
}
|
|
92848
93148
|
async replaceAll(entries) {
|
|
92849
93149
|
const page = await this.kind.query({ limit: 1e3 });
|
|
92850
93150
|
const nextIds = new Set(entries.map((e) => e.id));
|
|
@@ -92886,19 +93186,8 @@ var GoogleCallbackError = class extends Error {
|
|
|
92886
93186
|
var CALLBACK_PATH = "/oauth/callback";
|
|
92887
93187
|
var START_PATH = "/oauth/start";
|
|
92888
93188
|
var DISCONNECT_PATH = "/oauth/disconnect";
|
|
92889
|
-
var LegacyOauthStateSchema = object({
|
|
92890
|
-
refreshToken: string().default("").meta({ secret: true }),
|
|
92891
|
-
accessToken: string().default("").meta({ secret: true }),
|
|
92892
|
-
accessExpiresAt: number().default(0),
|
|
92893
|
-
accountEmail: string().default("")
|
|
92894
|
-
});
|
|
92895
93189
|
var GoogleServicesAddon = class extends BaseAddon {
|
|
92896
|
-
secretStatePaths = [
|
|
92897
|
-
"oauthAccounts.accounts[id].refreshToken",
|
|
92898
|
-
"oauthAccounts.accounts[id].accessToken",
|
|
92899
|
-
"oauth.refreshToken",
|
|
92900
|
-
"oauth.accessToken"
|
|
92901
|
-
];
|
|
93190
|
+
secretStatePaths = ["oauthAccounts.accounts[id].refreshToken", "oauthAccounts.accounts[id].accessToken"];
|
|
92902
93191
|
oauthAccountsHandle = null;
|
|
92903
93192
|
registry = new GoogleBrokerRegistry();
|
|
92904
93193
|
brokerStore = null;
|
|
@@ -92915,40 +93204,6 @@ var GoogleServicesAddon = class extends BaseAddon {
|
|
|
92915
93204
|
}
|
|
92916
93205
|
async onInitialize() {
|
|
92917
93206
|
this.oauthAccountsHandle = this.state("oauthAccounts", GoogleOauthAccountsStateSchema, { accounts: [] });
|
|
92918
|
-
let oauthAccounts = await this.oauthAccountsHandle.get();
|
|
92919
|
-
const legacyHandle = this.state("oauth", LegacyOauthStateSchema, { ...DEFAULT_OAUTH_STATE });
|
|
92920
|
-
const legacyOauth = await legacyHandle.get();
|
|
92921
|
-
const migrated = migrateLegacyToBrokers(this.config, legacyOauth);
|
|
92922
|
-
if (migrated.didMigrate) {
|
|
92923
|
-
await this.updateGlobalSettings({
|
|
92924
|
-
brokers: [...migrated.brokers],
|
|
92925
|
-
clientId: void 0,
|
|
92926
|
-
clientSecret: void 0,
|
|
92927
|
-
calendarFilter: void 0,
|
|
92928
|
-
fromAddress: void 0,
|
|
92929
|
-
fromName: void 0
|
|
92930
|
-
});
|
|
92931
|
-
if (migrated.oauthAccounts.length > 0) {
|
|
92932
|
-
oauthAccounts = { accounts: [...migrated.oauthAccounts] };
|
|
92933
|
-
await this.oauthAccountsHandle.set(oauthAccounts);
|
|
92934
|
-
}
|
|
92935
|
-
await legacyHandle.set({ ...DEFAULT_OAUTH_STATE });
|
|
92936
|
-
this.ctx.logger.info("google-services: migrated singleton OAuth to broker google_001", { meta: {
|
|
92937
|
-
brokerId: "google_001",
|
|
92938
|
-
accountEmail: legacyOauth.accountEmail || void 0
|
|
92939
|
-
} });
|
|
92940
|
-
} else if (oauthAccounts.accounts.length === 0 && legacyOauth.refreshToken.length > 0 && this.config.brokers.length > 0) {
|
|
92941
|
-
oauthAccounts = { accounts: [{
|
|
92942
|
-
id: this.config.brokers[0].id,
|
|
92943
|
-
refreshToken: legacyOauth.refreshToken,
|
|
92944
|
-
accessToken: legacyOauth.accessToken,
|
|
92945
|
-
accessExpiresAt: legacyOauth.accessExpiresAt,
|
|
92946
|
-
accountEmail: legacyOauth.accountEmail,
|
|
92947
|
-
needsReauth: false
|
|
92948
|
-
}] };
|
|
92949
|
-
await this.oauthAccountsHandle.set(oauthAccounts);
|
|
92950
|
-
await legacyHandle.set({ ...DEFAULT_OAUTH_STATE });
|
|
92951
|
-
}
|
|
92952
93207
|
const records = this.ctx.records;
|
|
92953
93208
|
if (records === void 0) throw new Error("google-services: ctx.records is required (hub-only addon)");
|
|
92954
93209
|
await records.declare({
|
|
@@ -92962,12 +93217,9 @@ var GoogleServicesAddon = class extends BaseAddon {
|
|
|
92962
93217
|
onChanged: () => this.refreshCalendarSelection()
|
|
92963
93218
|
});
|
|
92964
93219
|
this.activeBrokers = await this.loadPersistedBrokers();
|
|
92965
|
-
if ((await this.brokerStore.listResolved()).length === 0 && this.config.brokers.length > 0) {
|
|
92966
|
-
await this.brokerStore.replaceAll(this.config.brokers);
|
|
92967
|
-
this.activeBrokers = await this.loadPersistedBrokers();
|
|
92968
|
-
}
|
|
92969
93220
|
await this.migrateCalendarIds(records);
|
|
92970
93221
|
await this.refreshCalendarSelection();
|
|
93222
|
+
const oauthAccounts = await this.oauthAccountsHandle.get();
|
|
92971
93223
|
this.registry.seedFrom(this.activeBrokers, oauthAccounts.accounts);
|
|
92972
93224
|
await this.refreshPublicOrigin();
|
|
92973
93225
|
const calendarProvider = createGoogleCalendarSource({
|
|
@@ -93403,27 +93655,61 @@ var GoogleServicesAddon = class extends BaseAddon {
|
|
|
93403
93655
|
brokers,
|
|
93404
93656
|
calendars: records.kind(googleCalendarsEntryKind),
|
|
93405
93657
|
warn: (message) => this.ctx.logger.warn(message)
|
|
93406
|
-
})
|
|
93658
|
+
}),
|
|
93659
|
+
...this.legacyBrokerPorts()
|
|
93660
|
+
};
|
|
93661
|
+
const report = await this.runMigrations(defineAddonMigrations(ADDON_MIGRATIONS, ports));
|
|
93662
|
+
if (report.applied.length > 0) this.activeBrokers = await this.loadPersistedBrokers();
|
|
93663
|
+
if (this.activeBrokers.length === 0) {
|
|
93664
|
+
const left = await leftoverLegacyKeys(ports);
|
|
93665
|
+
if (left.length > 0) this.ctx.logger.error("google-services: legacy account data was NOT copied into broker records — Google stays unavailable until it is", { meta: {
|
|
93666
|
+
leftoverKeys: left,
|
|
93667
|
+
failed: report.failed
|
|
93668
|
+
} });
|
|
93669
|
+
}
|
|
93670
|
+
}
|
|
93671
|
+
/** The legacy-broker migration's writes: a broker record and an `oauthAccounts` entry, each read back. */
|
|
93672
|
+
legacyBrokerPorts() {
|
|
93673
|
+
return {
|
|
93674
|
+
putBroker: async (entry) => {
|
|
93675
|
+
const store = this.brokerStore;
|
|
93676
|
+
if (store === null) throw new Error("google-services: the brokers store is not ready");
|
|
93677
|
+
await store.putOne(entry);
|
|
93678
|
+
},
|
|
93679
|
+
readBroker: async (id) => {
|
|
93680
|
+
const store = this.brokerStore;
|
|
93681
|
+
if (store === null) throw new Error("google-services: the brokers store is not ready");
|
|
93682
|
+
const found = (await store.listResolved()).find((b) => b.id === id);
|
|
93683
|
+
return found === void 0 ? null : found;
|
|
93684
|
+
},
|
|
93685
|
+
listOauthAccountIds: async () => {
|
|
93686
|
+
const handle = this.oauthAccountsHandle;
|
|
93687
|
+
if (handle === null) return [];
|
|
93688
|
+
return (await handle.get()).accounts.map((a) => a.id);
|
|
93689
|
+
},
|
|
93690
|
+
putOauthAccount: async (account) => {
|
|
93691
|
+
const handle = this.oauthAccountsHandle;
|
|
93692
|
+
if (handle === null) throw new Error("google-services: oauthAccounts is not ready");
|
|
93693
|
+
const current = await handle.get();
|
|
93694
|
+
await handle.set({ accounts: [...current.accounts, account] });
|
|
93695
|
+
},
|
|
93696
|
+
readOauthAccount: async (id) => {
|
|
93697
|
+
const handle = this.oauthAccountsHandle;
|
|
93698
|
+
if (handle === null) return null;
|
|
93699
|
+
return (await handle.get()).accounts.find((a) => a.id === id) ?? null;
|
|
93700
|
+
}
|
|
93407
93701
|
};
|
|
93408
|
-
if ((await this.runMigrations(defineAddonMigrations(ADDON_MIGRATIONS, ports))).applied.length > 0) this.activeBrokers = await this.loadPersistedBrokers();
|
|
93409
93702
|
}
|
|
93410
93703
|
async loadPersistedBrokers() {
|
|
93411
93704
|
const store = this.brokerStore;
|
|
93412
|
-
|
|
93413
|
-
const fromRecords = await store.listResolved();
|
|
93414
|
-
if (fromRecords.length > 0) return fromRecords;
|
|
93415
|
-
}
|
|
93416
|
-
return this.config.brokers;
|
|
93705
|
+
return store === null ? [] : store.listResolved();
|
|
93417
93706
|
}
|
|
93418
93707
|
async persistBrokers() {
|
|
93419
93708
|
const entries = [...this.registry.listEntries()];
|
|
93420
93709
|
this.activeBrokers = entries;
|
|
93421
93710
|
const store = this.brokerStore;
|
|
93422
|
-
if (store
|
|
93423
|
-
|
|
93424
|
-
return;
|
|
93425
|
-
}
|
|
93426
|
-
await this.updateGlobalSettings({ brokers: entries });
|
|
93711
|
+
if (store === null) throw new Error("google-services: the brokers store is not ready");
|
|
93712
|
+
await store.replaceAll(entries);
|
|
93427
93713
|
}
|
|
93428
93714
|
async persistOauthAccounts() {
|
|
93429
93715
|
if (!this.oauthAccountsHandle) return;
|
|
@@ -93595,7 +93881,6 @@ exports.createGoogleCalendarSource = createGoogleCalendarSource;
|
|
|
93595
93881
|
exports.exchangeCode = exchangeCode;
|
|
93596
93882
|
exports.introHtml = introHtml;
|
|
93597
93883
|
exports.mapGoogleEvent = mapGoogleEvent;
|
|
93598
|
-
exports.migrateLegacyToBrokers = migrateLegacyToBrokers;
|
|
93599
93884
|
exports.needsRefresh = needsRefresh;
|
|
93600
93885
|
exports.parseStampedCalendarId = parseStampedCalendarId;
|
|
93601
93886
|
exports.redirectUriDisplay = redirectUriDisplay;
|