@camstack/addon-google-services 0.2.40 → 0.2.42
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 +12 -0
- package/dist/google-services.addon.js +1963 -1652
- package/dist/google-services.addon.mjs +1964 -1652
- package/dist/index.js +0 -1
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
|
@@ -5981,7 +5981,7 @@ var ZodIssueCode = {
|
|
|
5981
5981
|
var ZodFirstPartyTypeKind;
|
|
5982
5982
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
5983
5983
|
//#endregion
|
|
5984
|
-
//#region ../types/dist/sleep-
|
|
5984
|
+
//#region ../types/dist/sleep-D7ZKm4nb.mjs
|
|
5985
5985
|
/**
|
|
5986
5986
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
5987
5987
|
* window to float samples (D455).
|
|
@@ -6665,137 +6665,121 @@ async function runAddonMigrations(host, migrations, logger, options = {}) {
|
|
|
6665
6665
|
blockOwner
|
|
6666
6666
|
};
|
|
6667
6667
|
}
|
|
6668
|
-
/**
|
|
6669
|
-
|
|
6670
|
-
|
|
6671
|
-
|
|
6672
|
-
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
|
|
6685
|
-
|
|
6686
|
-
const set = async (next) => {
|
|
6687
|
-
const validated = deps.schema.parse(next);
|
|
6688
|
-
await deps.write({ [deps.key]: validated });
|
|
6689
|
-
};
|
|
6690
|
-
const update = async (fn) => {
|
|
6691
|
-
await set(fn(await get()));
|
|
6692
|
-
};
|
|
6668
|
+
/** The record calls the one-switch migration makes, over the migration API. */
|
|
6669
|
+
function switchRecordsOverMigrationApi(api) {
|
|
6670
|
+
return { kind: (definition) => {
|
|
6671
|
+
const handle = api.records.kind(definition);
|
|
6672
|
+
return {
|
|
6673
|
+
get: (id) => handle.get({ id }),
|
|
6674
|
+
put: (input, opts) => handle.put({
|
|
6675
|
+
...input,
|
|
6676
|
+
...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
|
|
6677
|
+
}),
|
|
6678
|
+
patch: (id, partial) => handle.patch({
|
|
6679
|
+
id,
|
|
6680
|
+
partial
|
|
6681
|
+
})
|
|
6682
|
+
};
|
|
6683
|
+
} };
|
|
6684
|
+
}
|
|
6685
|
+
function integrationRowsApiOver(api) {
|
|
6693
6686
|
return {
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6687
|
+
list: async () => (await api.integrations.list({})).integrations,
|
|
6688
|
+
readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
|
|
6689
|
+
clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
|
|
6697
6690
|
};
|
|
6698
6691
|
}
|
|
6692
|
+
var PREFIX = "records/";
|
|
6699
6693
|
/**
|
|
6700
|
-
*
|
|
6701
|
-
*
|
|
6702
|
-
*
|
|
6703
|
-
*
|
|
6704
|
-
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
6705
|
-
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
6706
|
-
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
6707
|
-
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
6708
|
-
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
6709
|
-
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
6710
|
-
*
|
|
6711
|
-
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
6712
|
-
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
6713
|
-
* schema and routes reads/writes through these helpers.
|
|
6714
|
-
*
|
|
6715
|
-
* ## No bare-key fallback — deliberate
|
|
6716
|
-
*
|
|
6717
|
-
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
6718
|
-
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
6719
|
-
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
6720
|
-
* the store is invisible to every node, hub included, so one node's
|
|
6721
|
-
* selection can never leak onto another. (This generalizes the
|
|
6722
|
-
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
6723
|
-
* arbitrary set of per-node field keys.)
|
|
6724
|
-
*
|
|
6725
|
-
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
6726
|
-
* LEAF module: import it via its deep path, never from the root barrel.
|
|
6727
|
-
*/
|
|
6728
|
-
/**
|
|
6729
|
-
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
6730
|
-
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
6731
|
-
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
6732
|
-
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
6694
|
+
* Cross-realm brand. An addon bundles its own copy of this module (D15) while
|
|
6695
|
+
* `ctx.records` is the HOST's door, so an error thrown by the host is an
|
|
6696
|
+
* instance of the host's classes, not of the addon's. The brand plus the code
|
|
6697
|
+
* make `instanceof` answer by identity of the failure, not of the copy.
|
|
6733
6698
|
*/
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
if (slashIdx < 0) return raw;
|
|
6738
|
-
const bare = raw.slice(0, slashIdx);
|
|
6739
|
-
return bare === "" ? "hub" : bare;
|
|
6740
|
-
}
|
|
6741
|
-
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
6742
|
-
function nodeScopedKey(base, nodeId) {
|
|
6743
|
-
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
6699
|
+
var RECORDS_ERROR_BRAND = Symbol.for("camstack.records-error");
|
|
6700
|
+
function carriesBrand(value) {
|
|
6701
|
+
return typeof value === "object" && value !== null && Reflect.get(value, RECORDS_ERROR_BRAND) === true;
|
|
6744
6702
|
}
|
|
6703
|
+
/** The base of every records failure. `detail` is the human part of the message. */
|
|
6704
|
+
var RecordsError = class extends Error {
|
|
6705
|
+
/** The code a subclass stands for; the base stands for every code. */
|
|
6706
|
+
static code = void 0;
|
|
6707
|
+
/**
|
|
6708
|
+
* `instanceof` across copies of this module: any branded error is a
|
|
6709
|
+
* `RecordsError`, and is an instance of a subclass only when its code is the
|
|
6710
|
+
* subclass's code. Same-copy answers are unchanged.
|
|
6711
|
+
*/
|
|
6712
|
+
static [Symbol.hasInstance](value) {
|
|
6713
|
+
if (Function.prototype[Symbol.hasInstance].call(this, value)) return true;
|
|
6714
|
+
if (!carriesBrand(value)) return false;
|
|
6715
|
+
return this.code === void 0 || value.code === this.code;
|
|
6716
|
+
}
|
|
6717
|
+
code;
|
|
6718
|
+
detail;
|
|
6719
|
+
[RECORDS_ERROR_BRAND] = true;
|
|
6720
|
+
constructor(code, detail) {
|
|
6721
|
+
super(`${PREFIX}${code}: ${detail}`);
|
|
6722
|
+
this.name = "RecordsError";
|
|
6723
|
+
this.code = code;
|
|
6724
|
+
this.detail = detail;
|
|
6725
|
+
}
|
|
6726
|
+
};
|
|
6727
|
+
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
6728
|
+
var RecordSecretUnavailableError = class RecordSecretUnavailableError extends RecordsError {
|
|
6729
|
+
static code = "secret-unavailable";
|
|
6730
|
+
constructor(detail) {
|
|
6731
|
+
super(RecordSecretUnavailableError.code, detail);
|
|
6732
|
+
this.name = "RecordSecretUnavailableError";
|
|
6733
|
+
}
|
|
6734
|
+
};
|
|
6735
|
+
var InvalidRecordError = class InvalidRecordError extends RecordsError {
|
|
6736
|
+
static code = "invalid-record";
|
|
6737
|
+
constructor(detail) {
|
|
6738
|
+
super(InvalidRecordError.code, detail);
|
|
6739
|
+
this.name = "InvalidRecordError";
|
|
6740
|
+
}
|
|
6741
|
+
};
|
|
6742
|
+
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
6743
|
+
var DeclarationRefusedError = class DeclarationRefusedError extends RecordsError {
|
|
6744
|
+
static code = "declaration-refused";
|
|
6745
|
+
constructor(detail) {
|
|
6746
|
+
super(DeclarationRefusedError.code, detail);
|
|
6747
|
+
this.name = "DeclarationRefusedError";
|
|
6748
|
+
}
|
|
6749
|
+
};
|
|
6745
6750
|
/**
|
|
6746
|
-
*
|
|
6747
|
-
*
|
|
6748
|
-
*
|
|
6749
|
-
* schema `default` win on `undefined`.
|
|
6751
|
+
* The link primitive's declaration half (D1013 rule 5): what a link field names and how a kind
|
|
6752
|
+
* records it. Split from `instance-link.ts` so `RecordIntegrationInstances` can read the links of
|
|
6753
|
+
* its kind without importing the builders that import it.
|
|
6750
6754
|
*/
|
|
6751
|
-
|
|
6752
|
-
|
|
6755
|
+
/** The body field of a link: the id of the instance it names; the target rides in the field meta. */
|
|
6756
|
+
function linkField(target) {
|
|
6757
|
+
return string().meta({ link: target });
|
|
6753
6758
|
}
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
* patch is not mutated.
|
|
6760
|
-
*/
|
|
6761
|
-
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
6762
|
-
const out = {};
|
|
6763
|
-
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
6764
|
-
return out;
|
|
6759
|
+
function linkTargetOf(meta) {
|
|
6760
|
+
if (typeof meta !== "object" || meta === null) return void 0;
|
|
6761
|
+
const link = Reflect.get(meta, "link");
|
|
6762
|
+
const parsed = LinkTargetSchema.safeParse(link);
|
|
6763
|
+
return parsed.success ? parsed.data : void 0;
|
|
6765
6764
|
}
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
const out = {};
|
|
6782
|
-
for (const [key, value] of Object.entries(store)) {
|
|
6783
|
-
if (key.includes("@")) continue;
|
|
6784
|
-
if (perNodeKeys.has(key)) continue;
|
|
6785
|
-
out[key] = value;
|
|
6786
|
-
}
|
|
6787
|
-
for (const base of perNodeKeys) {
|
|
6788
|
-
const value = readNodeValue(store, base, nodeId);
|
|
6789
|
-
if (value !== void 0) out[base] = value;
|
|
6765
|
+
var LinkTargetSchema = object({
|
|
6766
|
+
cap: string().min(1),
|
|
6767
|
+
kind: string().min(1).optional()
|
|
6768
|
+
});
|
|
6769
|
+
/** The links a kind declares, read from the meta of its body fields. */
|
|
6770
|
+
function linksOfKind(kind) {
|
|
6771
|
+
const schema = kind.schema;
|
|
6772
|
+
if (!(schema instanceof ZodObject)) return [];
|
|
6773
|
+
const links = [];
|
|
6774
|
+
for (const [field, fieldSchema] of Object.entries(schema.shape)) {
|
|
6775
|
+
const to = linkTargetOf(globalRegistry.get(fieldSchema));
|
|
6776
|
+
if (to !== void 0) links.push({
|
|
6777
|
+
field,
|
|
6778
|
+
to
|
|
6779
|
+
});
|
|
6790
6780
|
}
|
|
6791
|
-
return
|
|
6781
|
+
return links;
|
|
6792
6782
|
}
|
|
6793
|
-
/** Every scope, in the order the guard and the docs list them. */
|
|
6794
|
-
var SCOPED_SETTINGS_SCOPES = [
|
|
6795
|
-
"cluster",
|
|
6796
|
-
"device-defaults",
|
|
6797
|
-
"node"
|
|
6798
|
-
];
|
|
6799
6783
|
/**
|
|
6800
6784
|
* The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
|
|
6801
6785
|
*
|
|
@@ -6930,6 +6914,643 @@ function parseSecretRef(ref) {
|
|
|
6930
6914
|
fieldPath
|
|
6931
6915
|
};
|
|
6932
6916
|
}
|
|
6917
|
+
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
6918
|
+
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
6919
|
+
var RECORD_DATABASES = ["settings", "events"];
|
|
6920
|
+
/** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
|
|
6921
|
+
var RECORD_CLASSES = [
|
|
6922
|
+
"config",
|
|
6923
|
+
"ledger",
|
|
6924
|
+
"audit",
|
|
6925
|
+
"mirror",
|
|
6926
|
+
"ephemeral"
|
|
6927
|
+
];
|
|
6928
|
+
var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
6929
|
+
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
6930
|
+
var RECORD_BATCH_MAX = 1e3;
|
|
6931
|
+
var RECORD_QUERY_MAX = 1e3;
|
|
6932
|
+
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
6933
|
+
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
6934
|
+
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
6935
|
+
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
6936
|
+
/**
|
|
6937
|
+
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
6938
|
+
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
6939
|
+
* (`auth.accessToken`, `headers[].value`).
|
|
6940
|
+
*
|
|
6941
|
+
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
6942
|
+
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
6943
|
+
* key releases exactly that key's secret.
|
|
6944
|
+
*
|
|
6945
|
+
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
6946
|
+
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
6947
|
+
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
6948
|
+
* leaf names its element: `headers[X-Api].value`.
|
|
6949
|
+
*
|
|
6950
|
+
* Pure and browser-safe. Nothing here mutates: every transform returns a new value.
|
|
6951
|
+
*/
|
|
6952
|
+
/** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
|
|
6953
|
+
function parseSecretPath(path) {
|
|
6954
|
+
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
6955
|
+
return path.split(".").map((raw) => {
|
|
6956
|
+
const each = raw.endsWith("[]");
|
|
6957
|
+
const map = raw.endsWith("{}");
|
|
6958
|
+
const key = each || map ? raw.slice(0, -2) : raw;
|
|
6959
|
+
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
6960
|
+
return {
|
|
6961
|
+
key,
|
|
6962
|
+
each,
|
|
6963
|
+
map
|
|
6964
|
+
};
|
|
6965
|
+
});
|
|
6966
|
+
}
|
|
6967
|
+
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
6968
|
+
function secretArrayPrefixes(path) {
|
|
6969
|
+
const segments = parseSecretPath(path);
|
|
6970
|
+
const prefixes = [];
|
|
6971
|
+
const walked = [];
|
|
6972
|
+
for (const segment of segments) {
|
|
6973
|
+
walked.push(segment.key);
|
|
6974
|
+
if (segment.each) prefixes.push(walked.join("."));
|
|
6975
|
+
}
|
|
6976
|
+
return prefixes;
|
|
6977
|
+
}
|
|
6978
|
+
function isRecord$6(value) {
|
|
6979
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6980
|
+
}
|
|
6981
|
+
function elementId(element, idKey, declared, prefix) {
|
|
6982
|
+
const id = isRecord$6(element) ? element[idKey] : void 0;
|
|
6983
|
+
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`);
|
|
6984
|
+
return id;
|
|
6985
|
+
}
|
|
6986
|
+
/**
|
|
6987
|
+
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
6988
|
+
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
6989
|
+
* result is a new body, `data` is untouched.
|
|
6990
|
+
*/
|
|
6991
|
+
var REMOVE_LEAF = Symbol("remove-leaf");
|
|
6992
|
+
function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
|
|
6993
|
+
if (!isRecord$6(node)) return node;
|
|
6994
|
+
const segment = segments[index];
|
|
6995
|
+
if (segment === void 0) return node;
|
|
6996
|
+
if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
|
|
6997
|
+
const child = node[segment.key];
|
|
6998
|
+
const keys = [...walkedKeys, segment.key];
|
|
6999
|
+
const last = index === segments.length - 1;
|
|
7000
|
+
if (segment.each) {
|
|
7001
|
+
if (!Array.isArray(child)) return node;
|
|
7002
|
+
const prefix = keys.join(".");
|
|
7003
|
+
const idKey = arrayKeys[prefix];
|
|
7004
|
+
if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
|
|
7005
|
+
const mapped = child.map((element) => {
|
|
7006
|
+
const id = elementId(element, idKey, declared, prefix);
|
|
7007
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
|
|
7008
|
+
return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
|
|
7009
|
+
});
|
|
7010
|
+
return {
|
|
7011
|
+
...node,
|
|
7012
|
+
[segment.key]: mapped
|
|
7013
|
+
};
|
|
7014
|
+
}
|
|
7015
|
+
if (segment.map) {
|
|
7016
|
+
if (!isRecord$6(child)) return node;
|
|
7017
|
+
const kept = Object.entries(child).map(([mapKey, value]) => {
|
|
7018
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
|
|
7019
|
+
if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
|
|
7020
|
+
return [mapKey, visit({
|
|
7021
|
+
declared,
|
|
7022
|
+
concrete,
|
|
7023
|
+
value
|
|
7024
|
+
})];
|
|
7025
|
+
}).filter(([, value]) => value !== REMOVE_LEAF);
|
|
7026
|
+
return {
|
|
7027
|
+
...node,
|
|
7028
|
+
[segment.key]: Object.fromEntries(kept)
|
|
7029
|
+
};
|
|
7030
|
+
}
|
|
7031
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
7032
|
+
if (last) {
|
|
7033
|
+
const replacement = visit({
|
|
7034
|
+
declared,
|
|
7035
|
+
concrete,
|
|
7036
|
+
value: child
|
|
7037
|
+
});
|
|
7038
|
+
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
7039
|
+
return {
|
|
7040
|
+
...node,
|
|
7041
|
+
[segment.key]: replacement
|
|
7042
|
+
};
|
|
7043
|
+
}
|
|
7044
|
+
return {
|
|
7045
|
+
...node,
|
|
7046
|
+
[segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
|
|
7047
|
+
};
|
|
7048
|
+
}
|
|
7049
|
+
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
7050
|
+
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
7051
|
+
let current = data;
|
|
7052
|
+
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
7053
|
+
return current;
|
|
7054
|
+
}
|
|
7055
|
+
/**
|
|
7056
|
+
* The keychain collection name a kind's secrets live under. Prefixed so a
|
|
7057
|
+
* record's refs never collide with the refs a legacy collection of the same name
|
|
7058
|
+
* already holds during an adoption.
|
|
7059
|
+
*/
|
|
7060
|
+
function recordSecretCollection(kind) {
|
|
7061
|
+
return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
|
|
7062
|
+
}
|
|
7063
|
+
/** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
|
|
7064
|
+
function recordSecretRef(owner, kind, rowId, concretePath) {
|
|
7065
|
+
return buildSecretRef({
|
|
7066
|
+
owner,
|
|
7067
|
+
scope: {
|
|
7068
|
+
kind: "row",
|
|
7069
|
+
collection: recordSecretCollection(kind),
|
|
7070
|
+
rowId
|
|
7071
|
+
},
|
|
7072
|
+
fieldPath: concretePath
|
|
7073
|
+
});
|
|
7074
|
+
}
|
|
7075
|
+
/**
|
|
7076
|
+
* A stored secret, as an admin read shows it: a VIEW naming the row's own
|
|
7077
|
+
* keychain ref (`set: true`), never the value and no longer the bare redaction
|
|
7078
|
+
* token. The form hands it to the secret field, which reveals the value by ref
|
|
7079
|
+
* through the audited `keychain-admin.reveal`; sent back untouched it keeps the
|
|
7080
|
+
* stored secret (the records door reads a view as KEEP).
|
|
7081
|
+
*
|
|
7082
|
+
* ONE implementation for the entries service and for every addon that serves
|
|
7083
|
+
* its own instances (`RecordIntegrationInstances`).
|
|
7084
|
+
*/
|
|
7085
|
+
function isRecord$5(value) {
|
|
7086
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7087
|
+
}
|
|
7088
|
+
function secretViewsOf(owner, kind, id, decl, data) {
|
|
7089
|
+
if (decl.secretPaths.length === 0) return data;
|
|
7090
|
+
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
7091
|
+
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
7092
|
+
return {
|
|
7093
|
+
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
7094
|
+
v: 1,
|
|
7095
|
+
set: true
|
|
7096
|
+
};
|
|
7097
|
+
});
|
|
7098
|
+
return isRecord$5(shown) ? shown : data;
|
|
7099
|
+
}
|
|
7100
|
+
/** The most instances one addon lists (an integrations page, not a table). */
|
|
7101
|
+
var INSTANCES_LIST_MAX = 1e3;
|
|
7102
|
+
/**
|
|
7103
|
+
* The ONE reader of an instance's switch (D996): an absent field means on, so a row written
|
|
7104
|
+
* before the field existed needs no migration. Every consumer of an instance body asks this.
|
|
7105
|
+
*/
|
|
7106
|
+
function isInstanceEnabled(body) {
|
|
7107
|
+
return body.enabled !== false;
|
|
7108
|
+
}
|
|
7109
|
+
/** The body key of the switch; only {@link RecordIntegrationInstances.setInstanceEnabled} writes it. */
|
|
7110
|
+
var SWITCH_KEY = "enabled";
|
|
7111
|
+
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
7112
|
+
function topLevelSecretKeys(paths) {
|
|
7113
|
+
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
7114
|
+
}
|
|
7115
|
+
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
7116
|
+
function secretMapKeys(paths) {
|
|
7117
|
+
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
7118
|
+
}
|
|
7119
|
+
/**
|
|
7120
|
+
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
7121
|
+
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
7122
|
+
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
7123
|
+
*/
|
|
7124
|
+
function secretMapPatch(value) {
|
|
7125
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
7126
|
+
const out = {};
|
|
7127
|
+
for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
|
|
7128
|
+
else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
|
|
7129
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
7130
|
+
}
|
|
7131
|
+
var RecordIntegrationInstances = class {
|
|
7132
|
+
records;
|
|
7133
|
+
kind;
|
|
7134
|
+
hooks;
|
|
7135
|
+
handle;
|
|
7136
|
+
secretKeys;
|
|
7137
|
+
secretMaps;
|
|
7138
|
+
nameField;
|
|
7139
|
+
switchListeners = /* @__PURE__ */ new Set();
|
|
7140
|
+
constructor(records, kind, hooks) {
|
|
7141
|
+
this.records = records;
|
|
7142
|
+
this.kind = kind;
|
|
7143
|
+
this.hooks = hooks;
|
|
7144
|
+
this.handle = records.kind(kind);
|
|
7145
|
+
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
7146
|
+
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
7147
|
+
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
7148
|
+
}
|
|
7149
|
+
/**
|
|
7150
|
+
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
7151
|
+
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
7152
|
+
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
7153
|
+
*/
|
|
7154
|
+
async readResolved(id) {
|
|
7155
|
+
try {
|
|
7156
|
+
const record = await this.handle.getResolved(id);
|
|
7157
|
+
return record === null ? null : {
|
|
7158
|
+
id,
|
|
7159
|
+
body: record.data,
|
|
7160
|
+
enabled: isInstanceEnabled(record.data),
|
|
7161
|
+
secrets: "resolved"
|
|
7162
|
+
};
|
|
7163
|
+
} catch (err) {
|
|
7164
|
+
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
7165
|
+
const stored = await this.handle.get(id);
|
|
7166
|
+
if (stored === null) return null;
|
|
7167
|
+
return {
|
|
7168
|
+
id,
|
|
7169
|
+
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
7170
|
+
enabled: isInstanceEnabled(stored.data),
|
|
7171
|
+
secrets: "unavailable"
|
|
7172
|
+
};
|
|
7173
|
+
}
|
|
7174
|
+
}
|
|
7175
|
+
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
7176
|
+
async getResolved(id) {
|
|
7177
|
+
return (await this.readResolved(id))?.body ?? null;
|
|
7178
|
+
}
|
|
7179
|
+
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
7180
|
+
async listResolved() {
|
|
7181
|
+
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
7182
|
+
const out = [];
|
|
7183
|
+
for (const record of page.records) {
|
|
7184
|
+
const read = await this.readResolved(record.id);
|
|
7185
|
+
if (read !== null) out.push(read);
|
|
7186
|
+
}
|
|
7187
|
+
return out;
|
|
7188
|
+
}
|
|
7189
|
+
viewOf(record) {
|
|
7190
|
+
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
7191
|
+
const rawName = record.data[this.nameField];
|
|
7192
|
+
const kind = this.hooks.kindOf?.(record.data);
|
|
7193
|
+
const health = this.hooks.health?.(record.data, record.id);
|
|
7194
|
+
return {
|
|
7195
|
+
id: record.id,
|
|
7196
|
+
name: typeof rawName === "string" ? rawName : record.id,
|
|
7197
|
+
configured: this.hooks.configured(record.data),
|
|
7198
|
+
enabled: isInstanceEnabled(record.data),
|
|
7199
|
+
formValues: shown,
|
|
7200
|
+
...kind !== void 0 ? { kind } : {},
|
|
7201
|
+
...health?.status !== void 0 ? { status: health.status } : {},
|
|
7202
|
+
...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
|
|
7203
|
+
};
|
|
7204
|
+
}
|
|
7205
|
+
describe = async () => {
|
|
7206
|
+
const declared = linksOfKind(this.kind);
|
|
7207
|
+
const links = this.hooks.description.links !== void 0 || declared.length === 0 ? {} : { links: declared.map((link) => ({
|
|
7208
|
+
kind: this.kind.name,
|
|
7209
|
+
field: link.field,
|
|
7210
|
+
to: link.to
|
|
7211
|
+
})) };
|
|
7212
|
+
return {
|
|
7213
|
+
...this.hooks.description,
|
|
7214
|
+
...links,
|
|
7215
|
+
...this.hooks.mintId === void 0 ? {} : { mintsId: true }
|
|
7216
|
+
};
|
|
7217
|
+
};
|
|
7218
|
+
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
7219
|
+
listInstances = async () => {
|
|
7220
|
+
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
7221
|
+
};
|
|
7222
|
+
getInstance = async ({ id }) => {
|
|
7223
|
+
const record = await this.handle.get(id);
|
|
7224
|
+
return record === null ? null : this.viewOf(record);
|
|
7225
|
+
};
|
|
7226
|
+
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
7227
|
+
createInstance = async ({ id, name, kind, values }) => {
|
|
7228
|
+
const minted = id ?? this.hooks.mintId?.({
|
|
7229
|
+
name,
|
|
7230
|
+
...kind !== void 0 ? { kind } : {}
|
|
7231
|
+
});
|
|
7232
|
+
if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
|
|
7233
|
+
await this.handle.put({
|
|
7234
|
+
id: minted,
|
|
7235
|
+
data: this.hooks.initialBody(name, kind)
|
|
7236
|
+
}, { ifRev: 0 });
|
|
7237
|
+
const patch = this.patchOf(values ?? {});
|
|
7238
|
+
if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
|
|
7239
|
+
await this.hooks.onChanged?.(minted, "created");
|
|
7240
|
+
return { id: minted };
|
|
7241
|
+
};
|
|
7242
|
+
updateInstance = async ({ id, name, values }) => {
|
|
7243
|
+
const patch = this.patchOf(values);
|
|
7244
|
+
if (name !== void 0) patch[this.nameField] = name;
|
|
7245
|
+
await this.handle.patch(id, patch);
|
|
7246
|
+
await this.hooks.onChanged?.(id, "updated");
|
|
7247
|
+
return { ok: true };
|
|
7248
|
+
};
|
|
7249
|
+
/** The record patch a form `values` object means: secrets kept, cleared or replaced. */
|
|
7250
|
+
patchOf(values) {
|
|
7251
|
+
const patch = {};
|
|
7252
|
+
for (const [key, value] of Object.entries(values)) {
|
|
7253
|
+
if (value === void 0) continue;
|
|
7254
|
+
if (key === "enabled") continue;
|
|
7255
|
+
if (this.secretMaps.has(key)) {
|
|
7256
|
+
const entries = secretMapPatch(value);
|
|
7257
|
+
if (entries !== null) patch[key] = entries;
|
|
7258
|
+
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
7259
|
+
else if (isSecretClear(value)) patch[key] = null;
|
|
7260
|
+
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
7261
|
+
}
|
|
7262
|
+
return patch;
|
|
7263
|
+
}
|
|
7264
|
+
/**
|
|
7265
|
+
* Listen to the switch of ANY instance of this helper (in the process that serves it). The
|
|
7266
|
+
* durable replacement of the `integration.enabled` / `integration.disabled` events (D8): the
|
|
7267
|
+
* addon reconciles from the record, whichever way it flipped.
|
|
7268
|
+
*/
|
|
7269
|
+
onSwitched(listener) {
|
|
7270
|
+
this.switchListeners.add(listener);
|
|
7271
|
+
}
|
|
7272
|
+
/**
|
|
7273
|
+
* The ONE writer of the switch (D996, D1014): the record body's `enabled`, for every role. A
|
|
7274
|
+
* configured thing is an instance, so an id with no record yet (a default integration that was
|
|
7275
|
+
* never configured) gets its record from `initialBody` before the switch is written.
|
|
7276
|
+
*/
|
|
7277
|
+
setInstanceEnabled = async ({ id, enabled }) => {
|
|
7278
|
+
if (await this.handle.get(id) === null) await this.handle.put({
|
|
7279
|
+
id,
|
|
7280
|
+
data: this.hooks.initialBody(id)
|
|
7281
|
+
}, { ifRev: 0 });
|
|
7282
|
+
await this.handle.patch(id, { [SWITCH_KEY]: enabled });
|
|
7283
|
+
await this.hooks.onChanged?.(id, "enabled");
|
|
7284
|
+
for (const listener of this.switchListeners) await listener(id, enabled);
|
|
7285
|
+
return { ok: true };
|
|
7286
|
+
};
|
|
7287
|
+
/** The row and its keychain refs go together (the records door). */
|
|
7288
|
+
deleteInstance = async ({ id }) => {
|
|
7289
|
+
await this.handle.delete(id);
|
|
7290
|
+
await this.hooks.onChanged?.(id, "deleted");
|
|
7291
|
+
return { ok: true };
|
|
7292
|
+
};
|
|
7293
|
+
testInstance = async (input) => {
|
|
7294
|
+
if (this.hooks.test === void 0) return {
|
|
7295
|
+
success: false,
|
|
7296
|
+
status: "unsupported",
|
|
7297
|
+
error: "This integration declares no connection test"
|
|
7298
|
+
};
|
|
7299
|
+
return this.hooks.test(input);
|
|
7300
|
+
};
|
|
7301
|
+
/** The flat provider object to hand to `registerProvider`. */
|
|
7302
|
+
toProvider() {
|
|
7303
|
+
return {
|
|
7304
|
+
describe: this.describe,
|
|
7305
|
+
instanceFormSchema: this.instanceFormSchema,
|
|
7306
|
+
listInstances: this.listInstances,
|
|
7307
|
+
getInstance: this.getInstance,
|
|
7308
|
+
createInstance: this.createInstance,
|
|
7309
|
+
updateInstance: this.updateInstance,
|
|
7310
|
+
setInstanceEnabled: this.setInstanceEnabled,
|
|
7311
|
+
deleteInstance: this.deleteInstance,
|
|
7312
|
+
testInstance: this.testInstance
|
|
7313
|
+
};
|
|
7314
|
+
}
|
|
7315
|
+
};
|
|
7316
|
+
/**
|
|
7317
|
+
* The one-switch migration (epic #440, step 3). An integration's on/off state used to live in the
|
|
7318
|
+
* registry's `enabled` column for a device addon; it now lives only in the instance record's
|
|
7319
|
+
* body (`enabled`, D1007 superseded). This moves a registry `enabled = false` into the body, once.
|
|
7320
|
+
*
|
|
7321
|
+
* For every registry row of the addon that is OFF:
|
|
7322
|
+
* - no record under its id: the record is created from `initialBody(name)` with `enabled: false`
|
|
7323
|
+
* (a default integration that never had settings, Reolink's among them);
|
|
7324
|
+
* - a record whose body states no `enabled`: `enabled: false` is written into it;
|
|
7325
|
+
* - a record that already states `enabled` (either way) is the newer truth and is left alone.
|
|
7326
|
+
* A row that is ON writes nothing: an absent field reads as on. A rerun finds every off row with
|
|
7327
|
+
* a stated switch and does nothing, so nothing switched off comes back on and nothing switched on
|
|
7328
|
+
* goes off. The registry column itself is neither read afterwards nor written; its drop is step 5.
|
|
7329
|
+
*
|
|
7330
|
+
* It runs in the addon process, BEFORE the addon registers its `integration-instances` provider,
|
|
7331
|
+
* which is also why `integrations.list` still answers the stored column at that point.
|
|
7332
|
+
*/
|
|
7333
|
+
function registrySwitchToBodyId(addonId, date) {
|
|
7334
|
+
return `${addonId}/${date}-registry-switch-to-body`;
|
|
7335
|
+
}
|
|
7336
|
+
async function moveRegistrySwitchToBody(ports, spec) {
|
|
7337
|
+
const rows = await ports.listIntegrations(spec.addonId);
|
|
7338
|
+
let created = 0;
|
|
7339
|
+
let switched = 0;
|
|
7340
|
+
let kept = 0;
|
|
7341
|
+
for (const row of rows) {
|
|
7342
|
+
if (row.enabled) continue;
|
|
7343
|
+
const body = await ports.readBody(row.id);
|
|
7344
|
+
if (body === null) {
|
|
7345
|
+
if (await ports.createRecord(row.id, {
|
|
7346
|
+
...spec.initialBody(row.name),
|
|
7347
|
+
["enabled"]: false
|
|
7348
|
+
}) === "created") created += 1;
|
|
7349
|
+
else kept += 1;
|
|
7350
|
+
continue;
|
|
7351
|
+
}
|
|
7352
|
+
if ("enabled" in body) {
|
|
7353
|
+
kept += 1;
|
|
7354
|
+
continue;
|
|
7355
|
+
}
|
|
7356
|
+
await ports.switchOff(row.id);
|
|
7357
|
+
switched += 1;
|
|
7358
|
+
}
|
|
7359
|
+
const summary = {
|
|
7360
|
+
integrations: rows.length,
|
|
7361
|
+
off: rows.filter((r) => !r.enabled).length,
|
|
7362
|
+
created,
|
|
7363
|
+
switched,
|
|
7364
|
+
kept
|
|
7365
|
+
};
|
|
7366
|
+
return created === 0 && switched === 0 ? {
|
|
7367
|
+
outcome: "already-done",
|
|
7368
|
+
summary
|
|
7369
|
+
} : {
|
|
7370
|
+
outcome: "done",
|
|
7371
|
+
summary
|
|
7372
|
+
};
|
|
7373
|
+
}
|
|
7374
|
+
/** A migration entry: an addon states its kind and how a new body starts, nothing else. */
|
|
7375
|
+
function registrySwitchToBodyMigration(spec) {
|
|
7376
|
+
return {
|
|
7377
|
+
meta: {
|
|
7378
|
+
id: registrySwitchToBodyId(spec.addonId, spec.date),
|
|
7379
|
+
owner: spec.addonId,
|
|
7380
|
+
level: "addon-state",
|
|
7381
|
+
seq: spec.seq,
|
|
7382
|
+
dependsOn: [],
|
|
7383
|
+
store: "settings",
|
|
7384
|
+
scope: "cluster",
|
|
7385
|
+
onFailure: "block-owner",
|
|
7386
|
+
bodyKind: "procedure",
|
|
7387
|
+
description: "Move the registry enabled flag of every switched-off integration into its instance record body, creating the record when there is none",
|
|
7388
|
+
fixtureMark: "enabled"
|
|
7389
|
+
},
|
|
7390
|
+
procedure: (ports) => moveRegistrySwitchToBody(ports, {
|
|
7391
|
+
addonId: spec.addonId,
|
|
7392
|
+
initialBody: spec.initialBody
|
|
7393
|
+
})
|
|
7394
|
+
};
|
|
7395
|
+
}
|
|
7396
|
+
/** The hub and records sides of {@link registrySwitchToBodyMigration}. */
|
|
7397
|
+
function registrySwitchPortsOver(deps) {
|
|
7398
|
+
const handle = deps.records.kind({
|
|
7399
|
+
name: deps.kind.name,
|
|
7400
|
+
declaration: deps.kind.declaration,
|
|
7401
|
+
schema: record(string(), unknown())
|
|
7402
|
+
});
|
|
7403
|
+
return {
|
|
7404
|
+
listIntegrations: async (addonId) => (await deps.api.list()).filter((i) => i.addonId === addonId).map((i) => ({
|
|
7405
|
+
id: i.id,
|
|
7406
|
+
name: i.name,
|
|
7407
|
+
enabled: i.enabled !== false
|
|
7408
|
+
})),
|
|
7409
|
+
readBody: async (id) => (await handle.get(id))?.data ?? null,
|
|
7410
|
+
createRecord: async (id, body) => {
|
|
7411
|
+
if (await handle.get(id) !== null) return "exists";
|
|
7412
|
+
await handle.put({
|
|
7413
|
+
id,
|
|
7414
|
+
data: body
|
|
7415
|
+
}, { ifRev: 0 });
|
|
7416
|
+
return "created";
|
|
7417
|
+
},
|
|
7418
|
+
switchOff: async (id) => {
|
|
7419
|
+
await handle.patch(id, { [SWITCH_KEY]: false });
|
|
7420
|
+
}
|
|
7421
|
+
};
|
|
7422
|
+
}
|
|
7423
|
+
/**
|
|
7424
|
+
* Build a {@link DurableState} over a single store key. Transport-agnostic:
|
|
7425
|
+
* `read`/`write` are the addon-store or device-store accessors. The whole
|
|
7426
|
+
* validated value round-trips on every read/write — the schema is the
|
|
7427
|
+
* single source of truth for what is persisted, so no hand-listed field
|
|
7428
|
+
* set can drop a key on save.
|
|
7429
|
+
*/
|
|
7430
|
+
function createDurableState(deps) {
|
|
7431
|
+
const get = async () => {
|
|
7432
|
+
const raw = (await deps.read())[deps.key];
|
|
7433
|
+
if (raw === void 0) return deps.fallback;
|
|
7434
|
+
const parsed = deps.schema.safeParse(raw);
|
|
7435
|
+
if (!parsed.success) {
|
|
7436
|
+
deps.onParseError?.(deps.key, parsed.error);
|
|
7437
|
+
return deps.fallback;
|
|
7438
|
+
}
|
|
7439
|
+
return parsed.data;
|
|
7440
|
+
};
|
|
7441
|
+
const set = async (next) => {
|
|
7442
|
+
const validated = deps.schema.parse(next);
|
|
7443
|
+
await deps.write({ [deps.key]: validated });
|
|
7444
|
+
};
|
|
7445
|
+
const update = async (fn) => {
|
|
7446
|
+
await set(fn(await get()));
|
|
7447
|
+
};
|
|
7448
|
+
return {
|
|
7449
|
+
get,
|
|
7450
|
+
set,
|
|
7451
|
+
update
|
|
7452
|
+
};
|
|
7453
|
+
}
|
|
7454
|
+
/**
|
|
7455
|
+
* Per-node scoping for the shared addon-settings blob.
|
|
7456
|
+
*
|
|
7457
|
+
* An addon's settings store is hub-central (the `addon-settings` cap is
|
|
7458
|
+
* hub-routed — the hub instance answers for every node), so fields whose
|
|
7459
|
+
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
7460
|
+
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
7461
|
+
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
7462
|
+
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
7463
|
+
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
7464
|
+
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
7465
|
+
*
|
|
7466
|
+
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
7467
|
+
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
7468
|
+
* schema and routes reads/writes through these helpers.
|
|
7469
|
+
*
|
|
7470
|
+
* ## No bare-key fallback — deliberate
|
|
7471
|
+
*
|
|
7472
|
+
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
7473
|
+
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
7474
|
+
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
7475
|
+
* the store is invisible to every node, hub included, so one node's
|
|
7476
|
+
* selection can never leak onto another. (This generalizes the
|
|
7477
|
+
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
7478
|
+
* arbitrary set of per-node field keys.)
|
|
7479
|
+
*
|
|
7480
|
+
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
7481
|
+
* LEAF module: import it via its deep path, never from the root barrel.
|
|
7482
|
+
*/
|
|
7483
|
+
/**
|
|
7484
|
+
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
7485
|
+
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
7486
|
+
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
7487
|
+
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
7488
|
+
*/
|
|
7489
|
+
function normalizeNodeId(raw) {
|
|
7490
|
+
if (raw === void 0 || raw === null || raw === "") return "hub";
|
|
7491
|
+
const slashIdx = raw.indexOf("/");
|
|
7492
|
+
if (slashIdx < 0) return raw;
|
|
7493
|
+
const bare = raw.slice(0, slashIdx);
|
|
7494
|
+
return bare === "" ? "hub" : bare;
|
|
7495
|
+
}
|
|
7496
|
+
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
7497
|
+
function nodeScopedKey(base, nodeId) {
|
|
7498
|
+
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
7499
|
+
}
|
|
7500
|
+
/**
|
|
7501
|
+
* Read a node's value for a per-node field from the raw shared store:
|
|
7502
|
+
* the node-scoped key when present, otherwise `undefined`.
|
|
7503
|
+
* Deliberately NO bare-key fallback (see module doc) — the caller lets the
|
|
7504
|
+
* schema `default` win on `undefined`.
|
|
7505
|
+
*/
|
|
7506
|
+
function readNodeValue(store, base, nodeId) {
|
|
7507
|
+
return store[nodeScopedKey(base, nodeId)];
|
|
7508
|
+
}
|
|
7509
|
+
/**
|
|
7510
|
+
* Re-map a UI/settings patch so every bare perNode field persists under the
|
|
7511
|
+
* TARGET node's scoped key; all other keys pass through unchanged. Used on
|
|
7512
|
+
* the write path so a save for one node never clobbers another node's value
|
|
7513
|
+
* (and the bare key is never written). Returns a new object — the input
|
|
7514
|
+
* patch is not mutated.
|
|
7515
|
+
*/
|
|
7516
|
+
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
7517
|
+
const out = {};
|
|
7518
|
+
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
7519
|
+
return out;
|
|
7520
|
+
}
|
|
7521
|
+
/**
|
|
7522
|
+
* Project the raw shared store onto the bare schema keys for ONE node so a
|
|
7523
|
+
* UI schema (whose field keys are bare) hydrates from that node's own
|
|
7524
|
+
* values:
|
|
7525
|
+
*
|
|
7526
|
+
* - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
|
|
7527
|
+
* - Every bare perNode key is dropped from the pass-through (a stray bare
|
|
7528
|
+
* legacy key must never hydrate any node — no bare fallback).
|
|
7529
|
+
* - THIS node's effective value ({@link readNodeValue}) is then laid onto
|
|
7530
|
+
* each bare perNode key; when the node has no scoped key the bare key is
|
|
7531
|
+
* left ABSENT so the field's schema `default` wins.
|
|
7532
|
+
*
|
|
7533
|
+
* Returns a new object — the input store is not mutated.
|
|
7534
|
+
*/
|
|
7535
|
+
function projectStore(store, perNodeKeys, nodeId) {
|
|
7536
|
+
const out = {};
|
|
7537
|
+
for (const [key, value] of Object.entries(store)) {
|
|
7538
|
+
if (key.includes("@")) continue;
|
|
7539
|
+
if (perNodeKeys.has(key)) continue;
|
|
7540
|
+
out[key] = value;
|
|
7541
|
+
}
|
|
7542
|
+
for (const base of perNodeKeys) {
|
|
7543
|
+
const value = readNodeValue(store, base, nodeId);
|
|
7544
|
+
if (value !== void 0) out[base] = value;
|
|
7545
|
+
}
|
|
7546
|
+
return out;
|
|
7547
|
+
}
|
|
7548
|
+
/** Every scope, in the order the guard and the docs list them. */
|
|
7549
|
+
var SCOPED_SETTINGS_SCOPES = [
|
|
7550
|
+
"cluster",
|
|
7551
|
+
"device-defaults",
|
|
7552
|
+
"node"
|
|
7553
|
+
];
|
|
6933
7554
|
/** A write to a secret path could not be stored in the keychain, so it was refused. */
|
|
6934
7555
|
var KeychainWriteRefusedError = class extends Error {
|
|
6935
7556
|
fieldPath;
|
|
@@ -6940,7 +7561,7 @@ var KeychainWriteRefusedError = class extends Error {
|
|
|
6940
7561
|
}
|
|
6941
7562
|
};
|
|
6942
7563
|
var KEEP = { kind: "keep" };
|
|
6943
|
-
function isRecord$
|
|
7564
|
+
function isRecord$4(value) {
|
|
6944
7565
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6945
7566
|
}
|
|
6946
7567
|
function defaultMintId() {
|
|
@@ -6953,7 +7574,7 @@ function collectSecretMarkerRefs(value, out = []) {
|
|
|
6953
7574
|
return out;
|
|
6954
7575
|
}
|
|
6955
7576
|
if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
|
|
6956
|
-
else if (isRecord$
|
|
7577
|
+
else if (isRecord$4(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
|
|
6957
7578
|
return out;
|
|
6958
7579
|
}
|
|
6959
7580
|
async function storedValueEquals(secrets, marker, candidate) {
|
|
@@ -7008,7 +7629,7 @@ function rowId(row, idKey) {
|
|
|
7008
7629
|
return null;
|
|
7009
7630
|
}
|
|
7010
7631
|
async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
7011
|
-
const storedRows = Array.isArray(stored) ? stored.filter(isRecord$
|
|
7632
|
+
const storedRows = Array.isArray(stored) ? stored.filter(isRecord$4) : [];
|
|
7012
7633
|
if (!Array.isArray(incoming)) {
|
|
7013
7634
|
ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
|
|
7014
7635
|
return {
|
|
@@ -7024,7 +7645,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
7024
7645
|
const kept = /* @__PURE__ */ new Set();
|
|
7025
7646
|
const rows = [];
|
|
7026
7647
|
for (const row of incoming) {
|
|
7027
|
-
if (!isRecord$
|
|
7648
|
+
if (!isRecord$4(row)) {
|
|
7028
7649
|
rows.push(row);
|
|
7029
7650
|
continue;
|
|
7030
7651
|
}
|
|
@@ -7049,7 +7670,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
|
|
|
7049
7670
|
case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
|
|
7050
7671
|
case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
|
|
7051
7672
|
case "object": {
|
|
7052
|
-
if (!isRecord$
|
|
7673
|
+
if (!isRecord$4(incoming)) {
|
|
7053
7674
|
if (incoming === void 0) return KEEP;
|
|
7054
7675
|
ctx.deletes.push(...collectSecretMarkerRefs(stored));
|
|
7055
7676
|
return {
|
|
@@ -7057,7 +7678,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
|
|
|
7057
7678
|
value: incoming
|
|
7058
7679
|
};
|
|
7059
7680
|
}
|
|
7060
|
-
const storedObj = isRecord$
|
|
7681
|
+
const storedObj = isRecord$4(stored) ? stored : {};
|
|
7061
7682
|
return {
|
|
7062
7683
|
kind: "value",
|
|
7063
7684
|
value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
|
|
@@ -7180,7 +7801,7 @@ async function resolveSecretMarkers(value, secrets, options = {}) {
|
|
|
7180
7801
|
value: items
|
|
7181
7802
|
};
|
|
7182
7803
|
}
|
|
7183
|
-
if (isRecord$
|
|
7804
|
+
if (isRecord$4(v)) {
|
|
7184
7805
|
const out = {};
|
|
7185
7806
|
for (const [k, child] of Object.entries(v)) {
|
|
7186
7807
|
const s = substitute(child);
|
|
@@ -7212,7 +7833,7 @@ var SecretOverwriteRefusedError = class extends Error {
|
|
|
7212
7833
|
this.name = "SecretOverwriteRefusedError";
|
|
7213
7834
|
}
|
|
7214
7835
|
};
|
|
7215
|
-
function isRecord$
|
|
7836
|
+
function isRecord$3(value) {
|
|
7216
7837
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7217
7838
|
}
|
|
7218
7839
|
function resolvedValue(pass, marker) {
|
|
@@ -7241,7 +7862,7 @@ function inArray(pass, incoming, stored) {
|
|
|
7241
7862
|
return incoming.map((item, index) => {
|
|
7242
7863
|
const twin = stored[index];
|
|
7243
7864
|
if (isSecretMarker(twin)) return typeof item === "string" && item === resolvedValue(pass, twin) ? twin : item;
|
|
7244
|
-
if (isRecord$
|
|
7865
|
+
if (isRecord$3(item) && isRecord$3(twin)) return inArrayRow(pass, item, twin);
|
|
7245
7866
|
if (Array.isArray(item) && Array.isArray(twin)) return inArray(pass, item, twin);
|
|
7246
7867
|
return item;
|
|
7247
7868
|
});
|
|
@@ -7252,7 +7873,7 @@ function inArrayRow(pass, incoming, stored) {
|
|
|
7252
7873
|
const twin = stored[key];
|
|
7253
7874
|
if (isSecretMarker(twin)) {
|
|
7254
7875
|
if (typeof value === "string" && value === resolvedValue(pass, twin)) out[key] = twin;
|
|
7255
|
-
} else if (isRecord$
|
|
7876
|
+
} else if (isRecord$3(value) && isRecord$3(twin)) out[key] = inArrayRow(pass, value, twin);
|
|
7256
7877
|
else if (Array.isArray(value) && Array.isArray(twin)) out[key] = inArray(pass, value, twin);
|
|
7257
7878
|
}
|
|
7258
7879
|
return out;
|
|
@@ -7260,7 +7881,7 @@ function inArrayRow(pass, incoming, stored) {
|
|
|
7260
7881
|
async function walk(pass, incoming, stored) {
|
|
7261
7882
|
if (isSecretMarker(stored)) return atMarker(pass, incoming, stored);
|
|
7262
7883
|
if (Array.isArray(incoming) && Array.isArray(stored)) return inArray(pass, incoming, stored);
|
|
7263
|
-
if (!isRecord$
|
|
7884
|
+
if (!isRecord$3(incoming) || !isRecord$3(stored)) return incoming;
|
|
7264
7885
|
const out = { ...incoming };
|
|
7265
7886
|
for (const [key, value] of Object.entries(incoming)) out[key] = await walk(pass, value, stored[key]);
|
|
7266
7887
|
return out;
|
|
@@ -7291,7 +7912,7 @@ async function restoreUnchangedSecrets(input) {
|
|
|
7291
7912
|
function isJsonEqual(a, b) {
|
|
7292
7913
|
if (Object.is(a, b)) return true;
|
|
7293
7914
|
if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((v, i) => isJsonEqual(v, b[i]));
|
|
7294
|
-
if (isRecord$
|
|
7915
|
+
if (isRecord$3(a) && isRecord$3(b)) {
|
|
7295
7916
|
const keys = Object.keys(a);
|
|
7296
7917
|
if (keys.length !== Object.keys(b).length) return false;
|
|
7297
7918
|
return keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && isJsonEqual(a[k], b[k]));
|
|
@@ -7315,7 +7936,7 @@ function markerKeysOf(blob, owner) {
|
|
|
7315
7936
|
}
|
|
7316
7937
|
function nodeFromStored(value, owner) {
|
|
7317
7938
|
if (isSecretMarker(value)) return isSecretRefOwnedBy(value.$secret, owner) ? { kind: "leaf" } : null;
|
|
7318
|
-
if (!isRecord$
|
|
7939
|
+
if (!isRecord$3(value)) return null;
|
|
7319
7940
|
const children = /* @__PURE__ */ new Map();
|
|
7320
7941
|
for (const [key, child] of Object.entries(value)) {
|
|
7321
7942
|
const node = nodeFromStored(child, owner);
|
|
@@ -7812,13 +8433,48 @@ var BaseAddon = class {
|
|
|
7812
8433
|
if (api === void 0) throw new Error(`${this.ctx.id}: the migration API is not available on this context`);
|
|
7813
8434
|
return this.runBound(sets.flatMap((set) => set.bind(api)), options);
|
|
7814
8435
|
}
|
|
7815
|
-
|
|
8436
|
+
/**
|
|
8437
|
+
* A device addon states its instance kind once, before its migrations run, and the one-switch
|
|
8438
|
+
* migration (registry `enabled` to the instance body, epic #440 step 3) joins whatever
|
|
8439
|
+
* catalogue the addon runs, in the SAME declaration (the engine replaces an owner's catalogue
|
|
8440
|
+
* on every declare).
|
|
8441
|
+
*/
|
|
8442
|
+
declareRegistrySwitch(spec) {
|
|
8443
|
+
this.registrySwitchSpec = spec;
|
|
8444
|
+
}
|
|
8445
|
+
registrySwitchSpec = null;
|
|
8446
|
+
registrySwitchBound() {
|
|
8447
|
+
const spec = this.registrySwitchSpec;
|
|
8448
|
+
if (spec === null) return [];
|
|
8449
|
+
const api = this.ctx.migrationApi;
|
|
8450
|
+
if (api === void 0) {
|
|
8451
|
+
this.ctx.logger.warn("the registry switch migration is skipped: the migration API is not available on this context");
|
|
8452
|
+
return [];
|
|
8453
|
+
}
|
|
8454
|
+
return migrationSet([registrySwitchToBodyMigration({
|
|
8455
|
+
addonId: this.ctx.id,
|
|
8456
|
+
date: "2026-11-06",
|
|
8457
|
+
seq: 1e3,
|
|
8458
|
+
initialBody: spec.initialBody
|
|
8459
|
+
})], (a) => registrySwitchPortsOver({
|
|
8460
|
+
api: integrationRowsApiOver(a),
|
|
8461
|
+
records: switchRecordsOverMigrationApi(a),
|
|
8462
|
+
kind: spec.kind
|
|
8463
|
+
})).bind(api);
|
|
8464
|
+
}
|
|
8465
|
+
async runBound(declared, options) {
|
|
8466
|
+
const added = this.registrySwitchBound();
|
|
8467
|
+
const migrations = [...declared, ...added];
|
|
8468
|
+
const phased = options?.only === void 0 || added.length === 0 ? options : {
|
|
8469
|
+
...options,
|
|
8470
|
+
only: [...options.only, ...added.map((m) => m.meta.id)]
|
|
8471
|
+
};
|
|
7816
8472
|
const api = this.ctx.api.migrations;
|
|
7817
8473
|
const report = await runAddonMigrations({
|
|
7818
8474
|
declareOwner: (input) => api.declareOwner.mutate(input),
|
|
7819
8475
|
startMigration: (input) => api.startMigration.mutate(input),
|
|
7820
8476
|
finishMigration: (input) => api.finishMigration.mutate(input)
|
|
7821
|
-
}, migrations, this.ctx.logger,
|
|
8477
|
+
}, migrations, this.ctx.logger, phased);
|
|
7822
8478
|
if (report.blockOwner.length > 0) throw new AddonMigrationsBlockedError(report.blockOwner);
|
|
7823
8479
|
return report;
|
|
7824
8480
|
}
|
|
@@ -8891,245 +9547,94 @@ function normalizeAddonInitResult(result) {
|
|
|
8891
9547
|
if (Array.isArray(result)) return { providers: result };
|
|
8892
9548
|
return result;
|
|
8893
9549
|
}
|
|
8894
|
-
|
|
8895
|
-
|
|
8896
|
-
|
|
8897
|
-
|
|
8898
|
-
detail;
|
|
8899
|
-
constructor(code, detail) {
|
|
8900
|
-
super(`${PREFIX}${code}: ${detail}`);
|
|
8901
|
-
this.name = "RecordsError";
|
|
8902
|
-
this.code = code;
|
|
8903
|
-
this.detail = detail;
|
|
8904
|
-
}
|
|
8905
|
-
};
|
|
8906
|
-
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
8907
|
-
var RecordSecretUnavailableError = class extends RecordsError {
|
|
8908
|
-
constructor(detail) {
|
|
8909
|
-
super("secret-unavailable", detail);
|
|
8910
|
-
this.name = "RecordSecretUnavailableError";
|
|
8911
|
-
}
|
|
8912
|
-
};
|
|
8913
|
-
var InvalidRecordError = class extends RecordsError {
|
|
8914
|
-
constructor(detail) {
|
|
8915
|
-
super("invalid-record", detail);
|
|
8916
|
-
this.name = "InvalidRecordError";
|
|
8917
|
-
}
|
|
8918
|
-
};
|
|
8919
|
-
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
8920
|
-
var DeclarationRefusedError = class extends RecordsError {
|
|
8921
|
-
constructor(detail) {
|
|
8922
|
-
super("declaration-refused", detail);
|
|
8923
|
-
this.name = "DeclarationRefusedError";
|
|
8924
|
-
}
|
|
8925
|
-
};
|
|
8926
|
-
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
8927
|
-
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
8928
|
-
var RECORD_DATABASES = ["settings", "events"];
|
|
8929
|
-
/** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
|
|
8930
|
-
var RECORD_CLASSES = [
|
|
8931
|
-
"config",
|
|
8932
|
-
"ledger",
|
|
8933
|
-
"audit",
|
|
8934
|
-
"mirror",
|
|
8935
|
-
"ephemeral"
|
|
8936
|
-
];
|
|
8937
|
-
var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
8938
|
-
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
8939
|
-
var RECORD_BATCH_MAX = 1e3;
|
|
8940
|
-
var RECORD_QUERY_MAX = 1e3;
|
|
8941
|
-
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
8942
|
-
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
8943
|
-
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
8944
|
-
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
9550
|
+
object({
|
|
9551
|
+
field: string().min(1),
|
|
9552
|
+
on: literal("advance")
|
|
9553
|
+
});
|
|
8945
9554
|
/**
|
|
8946
|
-
*
|
|
8947
|
-
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
8948
|
-
* (`auth.accessToken`, `headers[].value`).
|
|
8949
|
-
*
|
|
8950
|
-
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
8951
|
-
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
8952
|
-
* key releases exactly that key's secret.
|
|
9555
|
+
* Output schema shared by the contribution + live methods.
|
|
8953
9556
|
*
|
|
8954
|
-
*
|
|
8955
|
-
*
|
|
8956
|
-
*
|
|
8957
|
-
*
|
|
9557
|
+
* Mirrors the `ConfigUISchemaWithValues` shape (sections[] + optional
|
|
9558
|
+
* tabs[]) without importing from `../interfaces/config-ui.js` — a
|
|
9559
|
+
* concrete-but-lenient Zod object keeps tRPC output inference happy
|
|
9560
|
+
* (using `z.unknown()` here collapses unrelated router branches to
|
|
9561
|
+
* `unknown` when the generator re-inlines the huge AppRouter type).
|
|
8958
9562
|
*
|
|
8959
|
-
*
|
|
8960
|
-
|
|
8961
|
-
|
|
8962
|
-
function parseSecretPath(path) {
|
|
8963
|
-
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
8964
|
-
return path.split(".").map((raw) => {
|
|
8965
|
-
const each = raw.endsWith("[]");
|
|
8966
|
-
const map = raw.endsWith("{}");
|
|
8967
|
-
const key = each || map ? raw.slice(0, -2) : raw;
|
|
8968
|
-
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
8969
|
-
return {
|
|
8970
|
-
key,
|
|
8971
|
-
each,
|
|
8972
|
-
map
|
|
8973
|
-
};
|
|
8974
|
-
});
|
|
8975
|
-
}
|
|
8976
|
-
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
8977
|
-
function secretArrayPrefixes(path) {
|
|
8978
|
-
const segments = parseSecretPath(path);
|
|
8979
|
-
const prefixes = [];
|
|
8980
|
-
const walked = [];
|
|
8981
|
-
for (const segment of segments) {
|
|
8982
|
-
walked.push(segment.key);
|
|
8983
|
-
if (segment.each) prefixes.push(walked.join("."));
|
|
8984
|
-
}
|
|
8985
|
-
return prefixes;
|
|
8986
|
-
}
|
|
8987
|
-
function isRecord$4(value) {
|
|
8988
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8989
|
-
}
|
|
8990
|
-
function elementId(element, idKey, declared, prefix) {
|
|
8991
|
-
const id = isRecord$4(element) ? element[idKey] : void 0;
|
|
8992
|
-
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`);
|
|
8993
|
-
return id;
|
|
8994
|
-
}
|
|
8995
|
-
/**
|
|
8996
|
-
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
8997
|
-
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
8998
|
-
* result is a new body, `data` is untouched.
|
|
9563
|
+
* `.passthrough()` on sections/fields accepts whatever FormBuilder
|
|
9564
|
+
* extensions the caller adds (showWhen, displayScale, …) without
|
|
9565
|
+
* rebuilding every time a new field kind is introduced.
|
|
8999
9566
|
*/
|
|
9000
|
-
var
|
|
9001
|
-
|
|
9002
|
-
|
|
9003
|
-
|
|
9004
|
-
|
|
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
|
-
...node,
|
|
9037
|
-
[segment.key]: Object.fromEntries(kept)
|
|
9038
|
-
};
|
|
9039
|
-
}
|
|
9040
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
9041
|
-
if (last) {
|
|
9042
|
-
const replacement = visit({
|
|
9043
|
-
declared,
|
|
9044
|
-
concrete,
|
|
9045
|
-
value: child
|
|
9046
|
-
});
|
|
9047
|
-
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
9048
|
-
return {
|
|
9049
|
-
...node,
|
|
9050
|
-
[segment.key]: replacement
|
|
9051
|
-
};
|
|
9052
|
-
}
|
|
9567
|
+
var ContributionSectionSchema = object({
|
|
9568
|
+
id: string(),
|
|
9569
|
+
title: string(),
|
|
9570
|
+
description: string().optional(),
|
|
9571
|
+
style: _enum(["card", "accordion"]).optional(),
|
|
9572
|
+
defaultCollapsed: boolean().optional(),
|
|
9573
|
+
columns: union([
|
|
9574
|
+
literal(1),
|
|
9575
|
+
literal(2),
|
|
9576
|
+
literal(3),
|
|
9577
|
+
literal(4)
|
|
9578
|
+
]).optional(),
|
|
9579
|
+
tab: string().optional(),
|
|
9580
|
+
location: _enum([
|
|
9581
|
+
"settings",
|
|
9582
|
+
"top-tab",
|
|
9583
|
+
"hero"
|
|
9584
|
+
]).optional(),
|
|
9585
|
+
order: number().optional(),
|
|
9586
|
+
fields: array(any())
|
|
9587
|
+
});
|
|
9588
|
+
object({
|
|
9589
|
+
tabs: array(object({
|
|
9590
|
+
id: string(),
|
|
9591
|
+
label: string(),
|
|
9592
|
+
icon: string(),
|
|
9593
|
+
order: number().optional()
|
|
9594
|
+
})).optional(),
|
|
9595
|
+
sections: array(ContributionSectionSchema)
|
|
9596
|
+
}).nullable();
|
|
9597
|
+
object({ deviceId: number() }), object({ deviceId: number() }), object({
|
|
9598
|
+
deviceId: number(),
|
|
9599
|
+
patch: record(string(), unknown())
|
|
9600
|
+
}), object({ success: literal(true) });
|
|
9601
|
+
object({ deviceId: number() }), unknown().nullable();
|
|
9602
|
+
function method(input, output, options) {
|
|
9053
9603
|
return {
|
|
9054
|
-
|
|
9055
|
-
|
|
9604
|
+
input,
|
|
9605
|
+
output,
|
|
9606
|
+
kind: options?.kind ?? "query",
|
|
9607
|
+
...options?.auth !== void 0 ? { auth: options.auth } : {},
|
|
9608
|
+
...options?.access !== void 0 ? { access: options.access } : {},
|
|
9609
|
+
...options?.role !== void 0 ? { role: options.role } : {},
|
|
9610
|
+
...options?.caller !== void 0 ? { caller: options.caller } : {},
|
|
9611
|
+
timeoutMs: options?.timeoutMs
|
|
9056
9612
|
};
|
|
9057
9613
|
}
|
|
9058
|
-
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
9059
|
-
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
9060
|
-
let current = data;
|
|
9061
|
-
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
9062
|
-
return current;
|
|
9063
|
-
}
|
|
9064
9614
|
/**
|
|
9065
|
-
*
|
|
9066
|
-
*
|
|
9067
|
-
*
|
|
9615
|
+
* A wrapper/system-only method: served exclusively by the cap's system-level
|
|
9616
|
+
* provider (`InferProvider`), and OPTIONAL on `InferNativeProvider` so per-device
|
|
9617
|
+
* driver natives don't stub out a wrapper concern (e.g. a cross-device cache
|
|
9618
|
+
* overview). The `systemOnly: true` literal is what `InferNativeProvider` keys on.
|
|
9068
9619
|
*/
|
|
9069
|
-
function
|
|
9070
|
-
return
|
|
9071
|
-
|
|
9072
|
-
|
|
9073
|
-
|
|
9074
|
-
return buildSecretRef({
|
|
9075
|
-
owner,
|
|
9076
|
-
scope: {
|
|
9077
|
-
kind: "row",
|
|
9078
|
-
collection: recordSecretCollection(kind),
|
|
9079
|
-
rowId
|
|
9080
|
-
},
|
|
9081
|
-
fieldPath: concretePath
|
|
9082
|
-
});
|
|
9620
|
+
function systemMethod(input, output, options) {
|
|
9621
|
+
return {
|
|
9622
|
+
...method(input, output, options),
|
|
9623
|
+
systemOnly: true
|
|
9624
|
+
};
|
|
9083
9625
|
}
|
|
9084
9626
|
/**
|
|
9085
|
-
* A
|
|
9086
|
-
*
|
|
9087
|
-
*
|
|
9088
|
-
*
|
|
9089
|
-
* stored secret (the records door reads a view as KEEP).
|
|
9090
|
-
*
|
|
9091
|
-
* ONE implementation for the entries service and for every addon that serves
|
|
9092
|
-
* its own instances (`RecordIntegrationInstances`).
|
|
9627
|
+
* A method a SOURCE of a collection cap may legitimately not serve — OPTIONAL
|
|
9628
|
+
* on `InferProvider`. The `providerOptional: true` literal is what
|
|
9629
|
+
* `InferProvider` keys on; see {@link CapabilityMethodSchema.providerOptional}
|
|
9630
|
+
* for when this is the honest answer and when it is a soft stub.
|
|
9093
9631
|
*/
|
|
9094
|
-
function
|
|
9095
|
-
return
|
|
9096
|
-
|
|
9097
|
-
|
|
9098
|
-
|
|
9099
|
-
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
9100
|
-
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
9101
|
-
return {
|
|
9102
|
-
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
9103
|
-
v: 1,
|
|
9104
|
-
set: true
|
|
9105
|
-
};
|
|
9106
|
-
});
|
|
9107
|
-
return isRecord$3(shown) ? shown : data;
|
|
9632
|
+
function optionalMethod(input, output, options) {
|
|
9633
|
+
return {
|
|
9634
|
+
...method(input, output, options),
|
|
9635
|
+
providerOptional: true
|
|
9636
|
+
};
|
|
9108
9637
|
}
|
|
9109
|
-
/**
|
|
9110
|
-
* The share-view scope kinds a share-link token can carry. The hub mints
|
|
9111
|
-
* and validates them (`ShareViewGrantSchema` builds its
|
|
9112
|
-
* enum from this list); a data plane names the kinds it ACCEPTS in `share`.
|
|
9113
|
-
*/
|
|
9114
|
-
var SHARE_VIEW_KINDS = ["grid-view", "events-view"];
|
|
9115
|
-
/** The wire shape of {@link PeerBytesTicket} — see the type for what it is. */
|
|
9116
|
-
var PeerBytesTicketSchema = object({
|
|
9117
|
-
/** `http://127.0.0.1:<port>/<token>`. One `GET` takes it. */
|
|
9118
|
-
url: string().min(1),
|
|
9119
|
-
/**
|
|
9120
|
-
* The HOST node this URL means something on — the hub or a named agent,
|
|
9121
|
-
* never a runner. {@link AddonPeerBytes.open} compares it to its own and
|
|
9122
|
-
* refuses `cross-node` by name when they differ, without dialling.
|
|
9123
|
-
*/
|
|
9124
|
-
hostNodeId: string().min(1),
|
|
9125
|
-
expiresAtMs: number().int().nonnegative(),
|
|
9126
|
-
/**
|
|
9127
|
-
* What the producer DECLARED the body to be, when it knows — `null` when it
|
|
9128
|
-
* does not. Never `0` for unknown (D393): a consumer sizing a bound off this
|
|
9129
|
-
* must be able to tell "the producer did not say" from "the body is empty".
|
|
9130
|
-
*/
|
|
9131
|
-
declaredBytes: number().int().nonnegative().nullable()
|
|
9132
|
-
});
|
|
9133
9638
|
function defOf(schema) {
|
|
9134
9639
|
const zodBag = Reflect.get(schema, "_zod");
|
|
9135
9640
|
if (typeof zodBag !== "object" || zodBag === null) return {};
|
|
@@ -9359,6 +9864,7 @@ function defineRecordKinds(specs) {
|
|
|
9359
9864
|
function entryBody(shape) {
|
|
9360
9865
|
return object({
|
|
9361
9866
|
name: string().min(1),
|
|
9867
|
+
enabled: boolean().optional(),
|
|
9362
9868
|
...shape
|
|
9363
9869
|
});
|
|
9364
9870
|
}
|
|
@@ -9385,94 +9891,30 @@ function defineEntryKind(name, spec) {
|
|
|
9385
9891
|
if (defined === void 0) throw new DeclarationRefusedError(`entry kind "${name}" was not built`);
|
|
9386
9892
|
return defined;
|
|
9387
9893
|
}
|
|
9388
|
-
object({
|
|
9389
|
-
field: string().min(1),
|
|
9390
|
-
on: literal("advance")
|
|
9391
|
-
});
|
|
9392
9894
|
/**
|
|
9393
|
-
*
|
|
9394
|
-
*
|
|
9395
|
-
*
|
|
9396
|
-
* tabs[]) without importing from `../interfaces/config-ui.js` — a
|
|
9397
|
-
* concrete-but-lenient Zod object keeps tRPC output inference happy
|
|
9398
|
-
* (using `z.unknown()` here collapses unrelated router branches to
|
|
9399
|
-
* `unknown` when the generator re-inlines the huge AppRouter type).
|
|
9400
|
-
*
|
|
9401
|
-
* `.passthrough()` on sections/fields accepts whatever FormBuilder
|
|
9402
|
-
* extensions the caller adds (showWhen, displayScale, …) without
|
|
9403
|
-
* rebuilding every time a new field kind is introduced.
|
|
9895
|
+
* The share-view scope kinds a share-link token can carry. The hub mints
|
|
9896
|
+
* and validates them (`ShareViewGrantSchema` builds its
|
|
9897
|
+
* enum from this list); a data plane names the kinds it ACCEPTS in `share`.
|
|
9404
9898
|
*/
|
|
9405
|
-
var
|
|
9406
|
-
|
|
9407
|
-
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
|
|
9412
|
-
|
|
9413
|
-
|
|
9414
|
-
|
|
9415
|
-
|
|
9416
|
-
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
order: number().optional(),
|
|
9424
|
-
fields: array(any())
|
|
9899
|
+
var SHARE_VIEW_KINDS = ["grid-view", "events-view"];
|
|
9900
|
+
/** The wire shape of {@link PeerBytesTicket} — see the type for what it is. */
|
|
9901
|
+
var PeerBytesTicketSchema = object({
|
|
9902
|
+
/** `http://127.0.0.1:<port>/<token>`. One `GET` takes it. */
|
|
9903
|
+
url: string().min(1),
|
|
9904
|
+
/**
|
|
9905
|
+
* The HOST node this URL means something on — the hub or a named agent,
|
|
9906
|
+
* never a runner. {@link AddonPeerBytes.open} compares it to its own and
|
|
9907
|
+
* refuses `cross-node` by name when they differ, without dialling.
|
|
9908
|
+
*/
|
|
9909
|
+
hostNodeId: string().min(1),
|
|
9910
|
+
expiresAtMs: number().int().nonnegative(),
|
|
9911
|
+
/**
|
|
9912
|
+
* What the producer DECLARED the body to be, when it knows — `null` when it
|
|
9913
|
+
* does not. Never `0` for unknown (D393): a consumer sizing a bound off this
|
|
9914
|
+
* must be able to tell "the producer did not say" from "the body is empty".
|
|
9915
|
+
*/
|
|
9916
|
+
declaredBytes: number().int().nonnegative().nullable()
|
|
9425
9917
|
});
|
|
9426
|
-
object({
|
|
9427
|
-
tabs: array(object({
|
|
9428
|
-
id: string(),
|
|
9429
|
-
label: string(),
|
|
9430
|
-
icon: string(),
|
|
9431
|
-
order: number().optional()
|
|
9432
|
-
})).optional(),
|
|
9433
|
-
sections: array(ContributionSectionSchema)
|
|
9434
|
-
}).nullable();
|
|
9435
|
-
object({ deviceId: number() }), object({ deviceId: number() }), object({
|
|
9436
|
-
deviceId: number(),
|
|
9437
|
-
patch: record(string(), unknown())
|
|
9438
|
-
}), object({ success: literal(true) });
|
|
9439
|
-
object({ deviceId: number() }), unknown().nullable();
|
|
9440
|
-
function method(input, output, options) {
|
|
9441
|
-
return {
|
|
9442
|
-
input,
|
|
9443
|
-
output,
|
|
9444
|
-
kind: options?.kind ?? "query",
|
|
9445
|
-
...options?.auth !== void 0 ? { auth: options.auth } : {},
|
|
9446
|
-
...options?.access !== void 0 ? { access: options.access } : {},
|
|
9447
|
-
...options?.role !== void 0 ? { role: options.role } : {},
|
|
9448
|
-
...options?.caller !== void 0 ? { caller: options.caller } : {},
|
|
9449
|
-
timeoutMs: options?.timeoutMs
|
|
9450
|
-
};
|
|
9451
|
-
}
|
|
9452
|
-
/**
|
|
9453
|
-
* A wrapper/system-only method: served exclusively by the cap's system-level
|
|
9454
|
-
* provider (`InferProvider`), and OPTIONAL on `InferNativeProvider` so per-device
|
|
9455
|
-
* driver natives don't stub out a wrapper concern (e.g. a cross-device cache
|
|
9456
|
-
* overview). The `systemOnly: true` literal is what `InferNativeProvider` keys on.
|
|
9457
|
-
*/
|
|
9458
|
-
function systemMethod(input, output, options) {
|
|
9459
|
-
return {
|
|
9460
|
-
...method(input, output, options),
|
|
9461
|
-
systemOnly: true
|
|
9462
|
-
};
|
|
9463
|
-
}
|
|
9464
|
-
/**
|
|
9465
|
-
* A method a SOURCE of a collection cap may legitimately not serve — OPTIONAL
|
|
9466
|
-
* on `InferProvider`. The `providerOptional: true` literal is what
|
|
9467
|
-
* `InferProvider` keys on; see {@link CapabilityMethodSchema.providerOptional}
|
|
9468
|
-
* for when this is the honest answer and when it is a soft stub.
|
|
9469
|
-
*/
|
|
9470
|
-
function optionalMethod(input, output, options) {
|
|
9471
|
-
return {
|
|
9472
|
-
...method(input, output, options),
|
|
9473
|
-
providerOptional: true
|
|
9474
|
-
};
|
|
9475
|
-
}
|
|
9476
9918
|
var READING_QUANTITIES = [
|
|
9477
9919
|
"temperature",
|
|
9478
9920
|
"pressure",
|
|
@@ -10051,7 +10493,6 @@ var CAP_NAMES = Object.freeze([
|
|
|
10051
10493
|
"climate-control",
|
|
10052
10494
|
"color",
|
|
10053
10495
|
"composer",
|
|
10054
|
-
"connection-test",
|
|
10055
10496
|
"connectivity",
|
|
10056
10497
|
"consumables",
|
|
10057
10498
|
"contact",
|
|
@@ -11198,6 +11639,10 @@ Object.freeze({
|
|
|
11198
11639
|
"all",
|
|
11199
11640
|
"one"
|
|
11200
11641
|
]
|
|
11642
|
+
},
|
|
11643
|
+
{
|
|
11644
|
+
"path": "positionUpdatedAt",
|
|
11645
|
+
"valueType": "number"
|
|
11201
11646
|
}
|
|
11202
11647
|
],
|
|
11203
11648
|
"meter": [{
|
|
@@ -11452,22 +11897,6 @@ Object.freeze({
|
|
|
11452
11897
|
"path": "pumpRunning",
|
|
11453
11898
|
"valueType": "boolean"
|
|
11454
11899
|
},
|
|
11455
|
-
{
|
|
11456
|
-
"path": "lastDrink",
|
|
11457
|
-
"valueType": "number"
|
|
11458
|
-
},
|
|
11459
|
-
{
|
|
11460
|
-
"path": "currentHourDrink",
|
|
11461
|
-
"valueType": "number"
|
|
11462
|
-
},
|
|
11463
|
-
{
|
|
11464
|
-
"path": "last24hDrink",
|
|
11465
|
-
"valueType": "number"
|
|
11466
|
-
},
|
|
11467
|
-
{
|
|
11468
|
-
"path": "todayDrink",
|
|
11469
|
-
"valueType": "number"
|
|
11470
|
-
},
|
|
11471
11900
|
{
|
|
11472
11901
|
"path": "error",
|
|
11473
11902
|
"valueType": "string"
|
|
@@ -12033,6 +12462,59 @@ Object.freeze({
|
|
|
12033
12462
|
}
|
|
12034
12463
|
]
|
|
12035
12464
|
});
|
|
12465
|
+
Object.freeze({
|
|
12466
|
+
"actions": { "run": 363e4 },
|
|
12467
|
+
"audio-analyzer": { "classify": 3e4 },
|
|
12468
|
+
"custom-model-registry": { "importModelBundle": 18e5 },
|
|
12469
|
+
"database-snapshot": { "writeSnapshot": 18e5 },
|
|
12470
|
+
"device-manager": {
|
|
12471
|
+
"migrateDevice": 72e4,
|
|
12472
|
+
"runDiscoverySweep": 12e4
|
|
12473
|
+
},
|
|
12474
|
+
"device-provider": { "reloadDevice": 18e4 },
|
|
12475
|
+
"llm": {
|
|
12476
|
+
"generate": 6e5,
|
|
12477
|
+
"generateVision": 6e5,
|
|
12478
|
+
"testProfile": 6e5
|
|
12479
|
+
},
|
|
12480
|
+
"llm-runtime": {
|
|
12481
|
+
"complete": 6e5,
|
|
12482
|
+
"completeApple": 6e5,
|
|
12483
|
+
"ensureStarted": 6e5,
|
|
12484
|
+
"installModel": 36e5
|
|
12485
|
+
},
|
|
12486
|
+
"local-network": { "scanNetwork": 9e4 },
|
|
12487
|
+
"model-convert": { "convert": 6e5 },
|
|
12488
|
+
"pipeline-analytics": {
|
|
12489
|
+
"addRetrainFrameFromRecording": 6e4,
|
|
12490
|
+
"offerRetrainArchive": 12e4,
|
|
12491
|
+
"proposeRetrainAnnotationsWithLlm": 18e4,
|
|
12492
|
+
"resolveRetrainTrainingCorpus": 6e4,
|
|
12493
|
+
"writeRetrainArchive": 36e5
|
|
12494
|
+
},
|
|
12495
|
+
"server-management": { "applyServerUpdate": 96e4 },
|
|
12496
|
+
"terminal-session": { "pullOutput": 15e3 },
|
|
12497
|
+
"training": {
|
|
12498
|
+
"canaryResult": 12e4,
|
|
12499
|
+
"cancelJob": 12e4,
|
|
12500
|
+
"planJob": 6e4,
|
|
12501
|
+
"registerResult": 18e5,
|
|
12502
|
+
"rollbackCanary": 12e4,
|
|
12503
|
+
"startJob": 12e4,
|
|
12504
|
+
"startJobBatch": 12e4
|
|
12505
|
+
},
|
|
12506
|
+
"training-provider": {
|
|
12507
|
+
"cancelJob": 6e4,
|
|
12508
|
+
"cleanupJob": 3e5,
|
|
12509
|
+
"getJob": 6e4,
|
|
12510
|
+
"listJobEvents": 6e4,
|
|
12511
|
+
"listJobs": 12e4,
|
|
12512
|
+
"offerArtifact": 3e5,
|
|
12513
|
+
"readResult": 3e5,
|
|
12514
|
+
"submitJob": 18e5,
|
|
12515
|
+
"uploadDataset": 72e5
|
|
12516
|
+
}
|
|
12517
|
+
});
|
|
12036
12518
|
object({
|
|
12037
12519
|
code: string().regex(/^[a-z][a-z0-9-]*(\.[a-z0-9-]+)+$/),
|
|
12038
12520
|
params: record(string(), union([string(), number()])).optional()
|
|
@@ -12052,7 +12534,7 @@ function userError(code, params, englishFallback) {
|
|
|
12052
12534
|
return new CamstackError(code, params, englishFallback);
|
|
12053
12535
|
}
|
|
12054
12536
|
//#endregion
|
|
12055
|
-
//#region ../types/dist/composition-
|
|
12537
|
+
//#region ../types/dist/composition-BmBHuDTQ.mjs
|
|
12056
12538
|
/**
|
|
12057
12539
|
* The ffmpeg build every CamStack node downloads, per platform and arch.
|
|
12058
12540
|
*
|
|
@@ -12356,7 +12838,7 @@ var table = {
|
|
|
12356
12838
|
},
|
|
12357
12839
|
dwell: {
|
|
12358
12840
|
minArgs: 3,
|
|
12359
|
-
maxArgs:
|
|
12841
|
+
maxArgs: 4,
|
|
12360
12842
|
apply: () => {
|
|
12361
12843
|
throw new ExpressionEvalError("dwell: stateful evaluation context is required");
|
|
12362
12844
|
}
|
|
@@ -13516,254 +13998,6 @@ function buildCapturingReply(envelope) {
|
|
|
13516
13998
|
};
|
|
13517
13999
|
return wrapper;
|
|
13518
14000
|
}
|
|
13519
|
-
/**
|
|
13520
|
-
* The link primitive's declaration half (D1013 rule 5): what a link field names and how a kind
|
|
13521
|
-
* records it. Split from `instance-link.ts` so `RecordIntegrationInstances` can read the links of
|
|
13522
|
-
* its kind without importing the builders that import it.
|
|
13523
|
-
*/
|
|
13524
|
-
/** The body field of a link: the id of the instance it names; the target rides in the field meta. */
|
|
13525
|
-
function linkField(target) {
|
|
13526
|
-
return string().meta({ link: target });
|
|
13527
|
-
}
|
|
13528
|
-
function linkTargetOf(meta) {
|
|
13529
|
-
if (typeof meta !== "object" || meta === null) return void 0;
|
|
13530
|
-
const link = Reflect.get(meta, "link");
|
|
13531
|
-
const parsed = LinkTargetSchema.safeParse(link);
|
|
13532
|
-
return parsed.success ? parsed.data : void 0;
|
|
13533
|
-
}
|
|
13534
|
-
var LinkTargetSchema = object({
|
|
13535
|
-
cap: string().min(1),
|
|
13536
|
-
kind: string().min(1).optional()
|
|
13537
|
-
});
|
|
13538
|
-
/** The links a kind declares, read from the meta of its body fields. */
|
|
13539
|
-
function linksOfKind(kind) {
|
|
13540
|
-
const schema = kind.schema;
|
|
13541
|
-
if (!(schema instanceof ZodObject)) return [];
|
|
13542
|
-
const links = [];
|
|
13543
|
-
for (const [field, fieldSchema] of Object.entries(schema.shape)) {
|
|
13544
|
-
const to = linkTargetOf(globalRegistry.get(fieldSchema));
|
|
13545
|
-
if (to !== void 0) links.push({
|
|
13546
|
-
field,
|
|
13547
|
-
to
|
|
13548
|
-
});
|
|
13549
|
-
}
|
|
13550
|
-
return links;
|
|
13551
|
-
}
|
|
13552
|
-
/**
|
|
13553
|
-
* `RecordIntegrationInstances` - the `integration-instances` provider over ONE
|
|
13554
|
-
* entry kind, so an addon that holds a connection serves it in ~30 lines.
|
|
13555
|
-
*
|
|
13556
|
-
* Every instance is one record of the addon's own kind, keyed by the
|
|
13557
|
-
* `integrations` registry id. The records door does the secret work: a field the
|
|
13558
|
-
* kind marks `.meta({ secret: true })` is a keychain marker bound to the row, so
|
|
13559
|
-
* deleting the row deletes the secret, and one row's value is never another's.
|
|
13560
|
-
*
|
|
13561
|
-
* Patch rules for a secret (`updateInstance`): omitted, `''`, the redaction
|
|
13562
|
-
* token or the view the form was given KEEP the stored secret;
|
|
13563
|
-
* `{ $secretClear: true }` clears it; any other string replaces it.
|
|
13564
|
-
*/
|
|
13565
|
-
/** The most instances one addon lists (an integrations page, not a table). */
|
|
13566
|
-
var INSTANCES_LIST_MAX = 1e3;
|
|
13567
|
-
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
13568
|
-
function topLevelSecretKeys(paths) {
|
|
13569
|
-
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
13570
|
-
}
|
|
13571
|
-
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
13572
|
-
function secretMapKeys(paths) {
|
|
13573
|
-
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
13574
|
-
}
|
|
13575
|
-
/**
|
|
13576
|
-
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
13577
|
-
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
13578
|
-
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
13579
|
-
*/
|
|
13580
|
-
function secretMapPatch(value) {
|
|
13581
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
13582
|
-
const out = {};
|
|
13583
|
-
for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
|
|
13584
|
-
else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
|
|
13585
|
-
return Object.keys(out).length > 0 ? out : null;
|
|
13586
|
-
}
|
|
13587
|
-
/** Does the kind's body schema carry an `enabled` field? */
|
|
13588
|
-
function declaresEnabled(kind) {
|
|
13589
|
-
const json = toJSONSchema(kind.schema, {
|
|
13590
|
-
unrepresentable: "any",
|
|
13591
|
-
io: "input"
|
|
13592
|
-
});
|
|
13593
|
-
const properties = Reflect.get(json, "properties");
|
|
13594
|
-
return typeof properties === "object" && properties !== null && "enabled" in properties;
|
|
13595
|
-
}
|
|
13596
|
-
var RecordIntegrationInstances = class {
|
|
13597
|
-
records;
|
|
13598
|
-
kind;
|
|
13599
|
-
hooks;
|
|
13600
|
-
handle;
|
|
13601
|
-
secretKeys;
|
|
13602
|
-
secretMaps;
|
|
13603
|
-
nameField;
|
|
13604
|
-
/** The `integrations` registry owns the on/off switch (`role: devices`); the body has none. */
|
|
13605
|
-
registryOwnsEnabled;
|
|
13606
|
-
constructor(records, kind, hooks) {
|
|
13607
|
-
this.records = records;
|
|
13608
|
-
this.kind = kind;
|
|
13609
|
-
this.hooks = hooks;
|
|
13610
|
-
this.handle = records.kind(kind);
|
|
13611
|
-
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
13612
|
-
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
13613
|
-
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
13614
|
-
this.registryOwnsEnabled = hooks.description.role === "devices";
|
|
13615
|
-
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"`);
|
|
13616
|
-
}
|
|
13617
|
-
/**
|
|
13618
|
-
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
13619
|
-
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
13620
|
-
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
13621
|
-
*/
|
|
13622
|
-
async readResolved(id) {
|
|
13623
|
-
try {
|
|
13624
|
-
const record = await this.handle.getResolved(id);
|
|
13625
|
-
return record === null ? null : {
|
|
13626
|
-
id,
|
|
13627
|
-
body: record.data,
|
|
13628
|
-
enabled: record.data.enabled !== false,
|
|
13629
|
-
secrets: "resolved"
|
|
13630
|
-
};
|
|
13631
|
-
} catch (err) {
|
|
13632
|
-
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
13633
|
-
const stored = await this.handle.get(id);
|
|
13634
|
-
if (stored === null) return null;
|
|
13635
|
-
return {
|
|
13636
|
-
id,
|
|
13637
|
-
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
13638
|
-
enabled: stored.data.enabled !== false,
|
|
13639
|
-
secrets: "unavailable"
|
|
13640
|
-
};
|
|
13641
|
-
}
|
|
13642
|
-
}
|
|
13643
|
-
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
13644
|
-
async getResolved(id) {
|
|
13645
|
-
return (await this.readResolved(id))?.body ?? null;
|
|
13646
|
-
}
|
|
13647
|
-
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
13648
|
-
async listResolved() {
|
|
13649
|
-
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
13650
|
-
const out = [];
|
|
13651
|
-
for (const record of page.records) {
|
|
13652
|
-
const read = await this.readResolved(record.id);
|
|
13653
|
-
if (read !== null) out.push(read);
|
|
13654
|
-
}
|
|
13655
|
-
return out;
|
|
13656
|
-
}
|
|
13657
|
-
viewOf(record) {
|
|
13658
|
-
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
13659
|
-
const rawName = record.data[this.nameField];
|
|
13660
|
-
const kind = this.hooks.kindOf?.(record.data);
|
|
13661
|
-
const health = this.hooks.health?.(record.data, record.id);
|
|
13662
|
-
return {
|
|
13663
|
-
id: record.id,
|
|
13664
|
-
name: typeof rawName === "string" ? rawName : record.id,
|
|
13665
|
-
configured: this.hooks.configured(record.data),
|
|
13666
|
-
...this.registryOwnsEnabled ? {} : { enabled: record.data.enabled !== false },
|
|
13667
|
-
formValues: shown,
|
|
13668
|
-
...kind !== void 0 ? { kind } : {},
|
|
13669
|
-
...health?.status !== void 0 ? { status: health.status } : {},
|
|
13670
|
-
...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
|
|
13671
|
-
};
|
|
13672
|
-
}
|
|
13673
|
-
describe = async () => {
|
|
13674
|
-
const declared = linksOfKind(this.kind);
|
|
13675
|
-
const links = this.hooks.description.links !== void 0 || declared.length === 0 ? {} : { links: declared.map((link) => ({
|
|
13676
|
-
kind: this.kind.name,
|
|
13677
|
-
field: link.field,
|
|
13678
|
-
to: link.to
|
|
13679
|
-
})) };
|
|
13680
|
-
return {
|
|
13681
|
-
...this.hooks.description,
|
|
13682
|
-
...links,
|
|
13683
|
-
...this.hooks.mintId === void 0 ? {} : { mintsId: true }
|
|
13684
|
-
};
|
|
13685
|
-
};
|
|
13686
|
-
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
13687
|
-
listInstances = async () => {
|
|
13688
|
-
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
13689
|
-
};
|
|
13690
|
-
getInstance = async ({ id }) => {
|
|
13691
|
-
const record = await this.handle.get(id);
|
|
13692
|
-
return record === null ? null : this.viewOf(record);
|
|
13693
|
-
};
|
|
13694
|
-
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
13695
|
-
createInstance = async ({ id, name, kind, values }) => {
|
|
13696
|
-
const minted = id ?? this.hooks.mintId?.({
|
|
13697
|
-
name,
|
|
13698
|
-
...kind !== void 0 ? { kind } : {}
|
|
13699
|
-
});
|
|
13700
|
-
if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
|
|
13701
|
-
await this.handle.put({
|
|
13702
|
-
id: minted,
|
|
13703
|
-
data: this.hooks.initialBody(name, kind)
|
|
13704
|
-
}, { ifRev: 0 });
|
|
13705
|
-
const patch = this.patchOf(values ?? {});
|
|
13706
|
-
if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
|
|
13707
|
-
await this.hooks.onChanged?.(minted, "created");
|
|
13708
|
-
return { id: minted };
|
|
13709
|
-
};
|
|
13710
|
-
updateInstance = async ({ id, name, values }) => {
|
|
13711
|
-
const patch = this.patchOf(values);
|
|
13712
|
-
if (name !== void 0) patch[this.nameField] = name;
|
|
13713
|
-
await this.handle.patch(id, patch);
|
|
13714
|
-
await this.hooks.onChanged?.(id, "updated");
|
|
13715
|
-
return { ok: true };
|
|
13716
|
-
};
|
|
13717
|
-
/** The record patch a form `values` object means: secrets kept, cleared or replaced. */
|
|
13718
|
-
patchOf(values) {
|
|
13719
|
-
const patch = {};
|
|
13720
|
-
for (const [key, value] of Object.entries(values)) {
|
|
13721
|
-
if (value === void 0) continue;
|
|
13722
|
-
if (this.secretMaps.has(key)) {
|
|
13723
|
-
const entries = secretMapPatch(value);
|
|
13724
|
-
if (entries !== null) patch[key] = entries;
|
|
13725
|
-
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
13726
|
-
else if (isSecretClear(value)) patch[key] = null;
|
|
13727
|
-
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
13728
|
-
}
|
|
13729
|
-
return patch;
|
|
13730
|
-
}
|
|
13731
|
-
/** The switch lives in the record body; the addon is told so it applies it (D996). */
|
|
13732
|
-
setInstanceEnabled = async ({ id, enabled }) => {
|
|
13733
|
-
if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
|
|
13734
|
-
await this.handle.patch(id, { enabled });
|
|
13735
|
-
await this.hooks.onChanged?.(id, "enabled");
|
|
13736
|
-
return { ok: true };
|
|
13737
|
-
};
|
|
13738
|
-
/** The row and its keychain refs go together (the records door). */
|
|
13739
|
-
deleteInstance = async ({ id }) => {
|
|
13740
|
-
await this.handle.delete(id);
|
|
13741
|
-
await this.hooks.onChanged?.(id, "deleted");
|
|
13742
|
-
return { ok: true };
|
|
13743
|
-
};
|
|
13744
|
-
testInstance = async (input) => {
|
|
13745
|
-
if (this.hooks.test === void 0) return {
|
|
13746
|
-
success: false,
|
|
13747
|
-
status: "unsupported",
|
|
13748
|
-
error: "This integration declares no connection test"
|
|
13749
|
-
};
|
|
13750
|
-
return this.hooks.test(input);
|
|
13751
|
-
};
|
|
13752
|
-
/** The flat provider object to hand to `registerProvider`. */
|
|
13753
|
-
toProvider() {
|
|
13754
|
-
return {
|
|
13755
|
-
describe: this.describe,
|
|
13756
|
-
instanceFormSchema: this.instanceFormSchema,
|
|
13757
|
-
listInstances: this.listInstances,
|
|
13758
|
-
getInstance: this.getInstance,
|
|
13759
|
-
createInstance: this.createInstance,
|
|
13760
|
-
updateInstance: this.updateInstance,
|
|
13761
|
-
setInstanceEnabled: this.setInstanceEnabled,
|
|
13762
|
-
deleteInstance: this.deleteInstance,
|
|
13763
|
-
testInstance: this.testInstance
|
|
13764
|
-
};
|
|
13765
|
-
}
|
|
13766
|
-
};
|
|
13767
14001
|
/** No part holds the id a call named. */
|
|
13768
14002
|
var UnknownInstanceError = class extends Error {
|
|
13769
14003
|
instanceId;
|
|
@@ -13793,6 +14027,17 @@ function composeInstanceKinds(parts, base) {
|
|
|
13793
14027
|
if (part === void 0) throw new UnknownInstanceKindError(kindId);
|
|
13794
14028
|
return part;
|
|
13795
14029
|
};
|
|
14030
|
+
/**
|
|
14031
|
+
* The part a DRAFT test runs on. A named kind is that kind; an unnamed one is the provider's only
|
|
14032
|
+
* testable kind. Several testable kinds and none named is a typed refusal that lists them, never a throw.
|
|
14033
|
+
*/
|
|
14034
|
+
const draftPart = (kindId) => {
|
|
14035
|
+
if (kindId !== void 0) return parts.find((candidate) => candidate.kind.id === kindId) ?? { error: `Unknown instance kind '${kindId}'` };
|
|
14036
|
+
const testable = parts.filter((part) => part.kind.canTest !== false);
|
|
14037
|
+
const only = testable.length === 1 ? testable[0] : parts.length === 1 ? parts[0] : void 0;
|
|
14038
|
+
if (only !== void 0) return only;
|
|
14039
|
+
return { error: `This provider has several kinds: name one of ${(testable.length > 0 ? testable : parts).map((part) => part.kind.id).join(", ")}` };
|
|
14040
|
+
};
|
|
13796
14041
|
const holderOf = async (id) => {
|
|
13797
14042
|
for (const part of parts) if (await part.provider.getInstance({ id }) !== null) return part;
|
|
13798
14043
|
throw new UnknownInstanceError(id);
|
|
@@ -13828,7 +14073,13 @@ function composeInstanceKinds(parts, base) {
|
|
|
13828
14073
|
setInstanceEnabled: async (input) => (await holderOf(input.id)).provider.setInstanceEnabled(input),
|
|
13829
14074
|
deleteInstance: async (input) => (await holderOf(input.id)).provider.deleteInstance(input),
|
|
13830
14075
|
testInstance: async (input) => {
|
|
13831
|
-
const
|
|
14076
|
+
const resolved = input.id === null ? draftPart(input.kind) : await holderOf(input.id);
|
|
14077
|
+
if ("error" in resolved) return {
|
|
14078
|
+
success: false,
|
|
14079
|
+
status: "inconclusive",
|
|
14080
|
+
error: resolved.error
|
|
14081
|
+
};
|
|
14082
|
+
const test = resolved.provider.testInstance;
|
|
13832
14083
|
if (test === void 0) return {
|
|
13833
14084
|
success: false,
|
|
13834
14085
|
status: "inconclusive",
|
|
@@ -13838,6 +14089,432 @@ function composeInstanceKinds(parts, base) {
|
|
|
13838
14089
|
}
|
|
13839
14090
|
};
|
|
13840
14091
|
}
|
|
14092
|
+
/**
|
|
14093
|
+
* notification-output — canonical, capability-gated notification delivery.
|
|
14094
|
+
*
|
|
14095
|
+
* Apprise-derived model (see
|
|
14096
|
+
* `docs/superpowers/specs/2026-07-03-notification-output-notifier-matrix.md`):
|
|
14097
|
+
* callers emit ONE canonical `Notification`; each provider declares a
|
|
14098
|
+
* per-kind capability descriptor (`TargetKind`), and the pure degrade
|
|
14099
|
+
* engine (`@camstack/types` `prepareNotification`) transcodes / degrades the
|
|
14100
|
+
* message to what the kind supports — callers never special-case a service.
|
|
14101
|
+
*
|
|
14102
|
+
* DESIGN DECISIONS (locked):
|
|
14103
|
+
* - Target CRUD lives on THIS cap (`upsertTarget` / `deleteTarget` /
|
|
14104
|
+
* `setTargetEnabled`), each provider persisting via the `settings-store`
|
|
14105
|
+
* cap. Rationale: the admin UI needs one uniform surface across the
|
|
14106
|
+
* notifiers addon AND the HA addon; the addon-`globalSettingsSchema`-array
|
|
14107
|
+
* alternative would fork the UI per addon and cannot host the
|
|
14108
|
+
* discovery→adopt flow.
|
|
14109
|
+
* - `listTargetKinds` / `listTargets` / `discoverTargets` return arrays →
|
|
14110
|
+
* the generated cap-mount auto-`concatCollection`-fans them across every
|
|
14111
|
+
* registered provider (notifiers addon + HA addon) so one catalog is
|
|
14112
|
+
* routable. `send` / `testTarget` / CRUD route to ONE provider by the
|
|
14113
|
+
* `addonId` the generated collection router extracts from the call input.
|
|
14114
|
+
* - `Attachment.bytes` is `Uint8Array`. Transport-safe: superjson (the tRPC
|
|
14115
|
+
* transformer) + UDS MsgPack both round-trip typed arrays — already used by
|
|
14116
|
+
* `storage` / `storage-provider` / `recording` caps over the same path. No
|
|
14117
|
+
* base64 fallback needed.
|
|
14118
|
+
*
|
|
14119
|
+
* TODO (deferred, closed-set change — separate decision): add
|
|
14120
|
+
* `providerKind: 'notify'` so notification providers surface on the unified
|
|
14121
|
+
* admin "Integrations" page.
|
|
14122
|
+
*/
|
|
14123
|
+
/**
|
|
14124
|
+
* Zentik-derived typed-media enum — the superset across every kind. Each
|
|
14125
|
+
* adapter picks what it supports and the degrade engine filters the rest.
|
|
14126
|
+
*/
|
|
14127
|
+
var AttachmentMediaTypeSchema = _enum([
|
|
14128
|
+
"image",
|
|
14129
|
+
"video",
|
|
14130
|
+
"gif",
|
|
14131
|
+
"audio",
|
|
14132
|
+
"icon"
|
|
14133
|
+
]);
|
|
14134
|
+
/**
|
|
14135
|
+
* A single attachment. Exactly one of `url` (remote source, most adapters
|
|
14136
|
+
* prefer this) or `bytes` (inline source; required for Pushover-style
|
|
14137
|
+
* bytes-only kinds) MUST be present — the degrade engine expresses a
|
|
14138
|
+
* url→bytes fetch as a `needsFetch` directive the adapter executes.
|
|
14139
|
+
*/
|
|
14140
|
+
var AttachmentSchema = object({
|
|
14141
|
+
mediaType: AttachmentMediaTypeSchema,
|
|
14142
|
+
url: string().optional(),
|
|
14143
|
+
bytes: _instanceof(Uint8Array).optional(),
|
|
14144
|
+
mime: string().optional(),
|
|
14145
|
+
name: string().optional()
|
|
14146
|
+
}).refine((a) => a.url !== void 0 || a.bytes !== void 0, { message: "Attachment requires either `url` or `bytes`" });
|
|
14147
|
+
var NotificationFormatSchema = _enum([
|
|
14148
|
+
"text",
|
|
14149
|
+
"markdown",
|
|
14150
|
+
"html"
|
|
14151
|
+
]);
|
|
14152
|
+
/**
|
|
14153
|
+
* The CLOSED icon vocabulary an action button may use.
|
|
14154
|
+
*
|
|
14155
|
+
* A closed set, not a free string, and that is the whole point: an arbitrary
|
|
14156
|
+
* icon name is one that ntfy renders, zentik silently drops, and nobody
|
|
14157
|
+
* notices — the same class of gap as a zone vocabulary nothing produced
|
|
14158
|
+
* ([D35](../../../docs/decisions/adr-0035.md)). Every adapter maps this set or
|
|
14159
|
+
* declares `actionIcons: false` and the degrade engine strips the field.
|
|
14160
|
+
*
|
|
14161
|
+
* Named by INTENT, never by glyph. "check" would tie the vocabulary to one
|
|
14162
|
+
* renderer's icon set; "acknowledge" survives an adapter that draws it
|
|
14163
|
+
* differently.
|
|
14164
|
+
*
|
|
14165
|
+
* ── A TOKEN IS NOT A WIRE VALUE ─────────────────────────────────────
|
|
14166
|
+
*
|
|
14167
|
+
* These names are for US. **No adapter may forward one verbatim.** Each maps
|
|
14168
|
+
* the whole set onto its own renderer's vocabulary through a
|
|
14169
|
+
* `Record<NotificationActionIcon, string>` — a Record, never a lookup with a
|
|
14170
|
+
* fallback, so adding a member here fails every adapter's build until someone
|
|
14171
|
+
* decides its glyph, which is the only place that decision can be made
|
|
14172
|
+
* honestly.
|
|
14173
|
+
*
|
|
14174
|
+
* This paragraph is the bug. Zentik declared `actionIcons: true` and passed
|
|
14175
|
+
* `disarm` straight through; iOS feeds that string to
|
|
14176
|
+
* `UNNotificationActionIcon(systemImageName:)`, `disarm` is not an SF Symbol,
|
|
14177
|
+
* and every snooze and alarm button arrived BLANK. A pass-through is not a
|
|
14178
|
+
* mapping, and "the field is documented" is not "the value renders".
|
|
14179
|
+
*
|
|
14180
|
+
* Adding a member is TRAIN-BOUND. The enum lives in the published
|
|
14181
|
+
* `@camstack/server` closure and the cap seam validates against the HUB's copy,
|
|
14182
|
+
* so an addon that emits a token the running hub does not know does not lose an
|
|
14183
|
+
* icon — its whole `send` fails Zod validation and the notification never
|
|
14184
|
+
* arrives. Never emit a new token from an addon before the train carrying it.
|
|
14185
|
+
*/
|
|
14186
|
+
var NotificationActionIconSchema = _enum([
|
|
14187
|
+
"acknowledge",
|
|
14188
|
+
"dismiss",
|
|
14189
|
+
"silence",
|
|
14190
|
+
"snooze",
|
|
14191
|
+
"view",
|
|
14192
|
+
"play",
|
|
14193
|
+
"open",
|
|
14194
|
+
"close",
|
|
14195
|
+
"lock",
|
|
14196
|
+
"unlock",
|
|
14197
|
+
"arm",
|
|
14198
|
+
"arm-home",
|
|
14199
|
+
"arm-away",
|
|
14200
|
+
"arm-night",
|
|
14201
|
+
"disarm",
|
|
14202
|
+
"light",
|
|
14203
|
+
"alert",
|
|
14204
|
+
"camera"
|
|
14205
|
+
]);
|
|
14206
|
+
/** A single tap-through action button. */
|
|
14207
|
+
var NotificationActionSchema = object({
|
|
14208
|
+
id: string(),
|
|
14209
|
+
label: string(),
|
|
14210
|
+
url: string().optional(),
|
|
14211
|
+
/** Dropped by the degrade engine for a kind with `caps.actionIcons: false`. */
|
|
14212
|
+
icon: NotificationActionIconSchema.optional(),
|
|
14213
|
+
/**
|
|
14214
|
+
* Renders in a warning style where the notifier supports it.
|
|
14215
|
+
*
|
|
14216
|
+
* A HINT, never a gate. The callback's authority is its token and nothing
|
|
14217
|
+
* else — see `notification-center/action-token.ts` for what that does and
|
|
14218
|
+
* does not buy.
|
|
14219
|
+
*/
|
|
14220
|
+
destructive: boolean().optional(),
|
|
14221
|
+
/**
|
|
14222
|
+
* How the tap should REACH the url.
|
|
14223
|
+
*
|
|
14224
|
+
* `navigate` (absent, and every button authored before this field) opens it:
|
|
14225
|
+
* the phone leaves the notification and shows whatever the callback returns.
|
|
14226
|
+
* That is right for a button whose answer the operator wants to read.
|
|
14227
|
+
*
|
|
14228
|
+
* `background` fires it as a POST and stays put. It exists for the buttons
|
|
14229
|
+
* whose whole point is not to interrupt — "silence this for 30 minutes" is
|
|
14230
|
+
* an answer to the notification, and being thrown into a browser tab to
|
|
14231
|
+
* confirm it costs more attention than the notification did. A backend that
|
|
14232
|
+
* cannot do a background call renders it as an ordinary link (the adapters
|
|
14233
|
+
* fall back rather than dropping the button), so this is a preference, never
|
|
14234
|
+
* a requirement.
|
|
14235
|
+
*/
|
|
14236
|
+
mode: _enum(["navigate", "background"]).optional()
|
|
14237
|
+
});
|
|
14238
|
+
/** A delivery parameter value: what a notifier declared it takes. */
|
|
14239
|
+
var DeliveryParamValueSchema = union([
|
|
14240
|
+
string(),
|
|
14241
|
+
number(),
|
|
14242
|
+
boolean()
|
|
14243
|
+
]);
|
|
14244
|
+
/**
|
|
14245
|
+
* One extra delivery parameter a notifier KIND declares (D938). A rule that
|
|
14246
|
+
* addresses a target of that kind may set it; a kind that declares nothing is
|
|
14247
|
+
* never handed one. The admin UI derives its control from this descriptor —
|
|
14248
|
+
* no editor knows a service by name.
|
|
14249
|
+
*
|
|
14250
|
+
* Optional fields are `.optional()`, never `.default()` (a Zod default does not
|
|
14251
|
+
* run on the addon cap path).
|
|
14252
|
+
*/
|
|
14253
|
+
var DeliveryParamSchema = object({
|
|
14254
|
+
key: string().min(1),
|
|
14255
|
+
label: string(),
|
|
14256
|
+
/** i18n key of the label, resolved by the declaring addon's namespace. */
|
|
14257
|
+
labelKey: string().optional(),
|
|
14258
|
+
type: _enum([
|
|
14259
|
+
"enum",
|
|
14260
|
+
"number",
|
|
14261
|
+
"boolean",
|
|
14262
|
+
"string"
|
|
14263
|
+
]),
|
|
14264
|
+
/** `enum` only: the closed set of accepted values. */
|
|
14265
|
+
options: array(object({
|
|
14266
|
+
value: string(),
|
|
14267
|
+
label: string()
|
|
14268
|
+
})).optional(),
|
|
14269
|
+
/** `number` only. */
|
|
14270
|
+
min: number().optional(),
|
|
14271
|
+
max: number().optional(),
|
|
14272
|
+
/** What the notifier does when the rule sets nothing; shown as the placeholder. */
|
|
14273
|
+
default: DeliveryParamValueSchema.optional()
|
|
14274
|
+
});
|
|
14275
|
+
/**
|
|
14276
|
+
* The canonical notification. `body` is the only hard field (Apprise model).
|
|
14277
|
+
* `priority` is a 5-level ORDINAL (1=lowest … 3=normal(default) … 5=urgent),
|
|
14278
|
+
* NOT a fixed severity enum — each kind declares its own `caps.levels` and
|
|
14279
|
+
* the adapter maps this ordinal onto its native level. `level?` is an
|
|
14280
|
+
* optional kind-native level id (`emergency`, `silent`, …) that overrides
|
|
14281
|
+
* `priority` for that one target.
|
|
14282
|
+
*/
|
|
14283
|
+
var NotificationSchema = object({
|
|
14284
|
+
body: string(),
|
|
14285
|
+
title: string().optional(),
|
|
14286
|
+
format: NotificationFormatSchema.default("text"),
|
|
14287
|
+
priority: number().int().min(1).max(5).default(3),
|
|
14288
|
+
level: string().optional(),
|
|
14289
|
+
attachments: array(AttachmentSchema).optional(),
|
|
14290
|
+
clickUrl: string().optional(),
|
|
14291
|
+
actions: array(NotificationActionSchema).optional(),
|
|
14292
|
+
sound: string().optional(),
|
|
14293
|
+
ttl: number().optional(),
|
|
14294
|
+
tag: string().optional(),
|
|
14295
|
+
deviceId: number().optional(),
|
|
14296
|
+
eventId: string().optional(),
|
|
14297
|
+
metadata: record(string(), unknown()).optional(),
|
|
14298
|
+
/**
|
|
14299
|
+
* Values for the parameters the target's kind DECLARES in
|
|
14300
|
+
* {@link TargetKindSchema} `deliveryParams`. Already validated against the
|
|
14301
|
+
* declaration by the sender; a notifier reads only the keys it declared.
|
|
14302
|
+
*/
|
|
14303
|
+
delivery: record(string(), DeliveryParamValueSchema).optional()
|
|
14304
|
+
});
|
|
14305
|
+
/** One declared native severity/priority level for a kind. */
|
|
14306
|
+
var TargetKindLevelSchema = object({
|
|
14307
|
+
id: string(),
|
|
14308
|
+
label: string(),
|
|
14309
|
+
/** Which canonical priority (1..5) this level maps to. `null` = qualitative-only. */
|
|
14310
|
+
ordinal: number().int().min(1).max(5).nullable(),
|
|
14311
|
+
flags: object({
|
|
14312
|
+
critical: boolean().optional(),
|
|
14313
|
+
silent: boolean().optional(),
|
|
14314
|
+
noPush: boolean().optional()
|
|
14315
|
+
}).optional(),
|
|
14316
|
+
/** e.g. Pushover `emergency` requires `retry` / `expire`. */
|
|
14317
|
+
requires: array(string()).optional(),
|
|
14318
|
+
description: string().optional()
|
|
14319
|
+
});
|
|
14320
|
+
/** The full capability block consulted before dispatch. */
|
|
14321
|
+
var TargetKindCapsSchema = object({
|
|
14322
|
+
attachments: object({
|
|
14323
|
+
mediaTypes: array(AttachmentMediaTypeSchema),
|
|
14324
|
+
mode: _enum([
|
|
14325
|
+
"url",
|
|
14326
|
+
"bytes",
|
|
14327
|
+
"both"
|
|
14328
|
+
]),
|
|
14329
|
+
max: number().int().nonnegative(),
|
|
14330
|
+
maxBytes: number().int().positive().optional()
|
|
14331
|
+
}),
|
|
14332
|
+
/** Max action buttons (0 = none). */
|
|
14333
|
+
actions: number().int().nonnegative(),
|
|
14334
|
+
/**
|
|
14335
|
+
* Whether this kind renders a per-action ICON.
|
|
14336
|
+
*
|
|
14337
|
+
* `.optional()`, deliberately NOT `.default(false)`: a Zod default does not
|
|
14338
|
+
* run on the addon cap path — three production failures in one day taught
|
|
14339
|
+
* this repo that once. Absent is read as false by the degrade engine, which
|
|
14340
|
+
* is the safe direction: an icon that is not rendered costs nothing, an icon
|
|
14341
|
+
* assumed and dropped costs the operator's trust in the field.
|
|
14342
|
+
*/
|
|
14343
|
+
actionIcons: boolean().optional(),
|
|
14344
|
+
levels: array(TargetKindLevelSchema),
|
|
14345
|
+
format: array(NotificationFormatSchema),
|
|
14346
|
+
clickUrl: boolean(),
|
|
14347
|
+
sound: boolean(),
|
|
14348
|
+
ttl: boolean(),
|
|
14349
|
+
bodyMaxLen: number().int().positive()
|
|
14350
|
+
});
|
|
14351
|
+
/**
|
|
14352
|
+
* `configSchema` is a `ConfigUISchema` tree passed through to the admin
|
|
14353
|
+
* FormBuilder. Stored as `z.unknown()` at the cap seam (mirrors
|
|
14354
|
+
* `device-provider.getChildCreationSchema` `CreationSchemaOutputSchema`) —
|
|
14355
|
+
* the union is large and not meant for runtime validation here; the exported
|
|
14356
|
+
* `TargetKind` type re-tightens `configSchema` to `ConfigUISchema`.
|
|
14357
|
+
*/
|
|
14358
|
+
var ConfigSchemaPassthrough$4 = unknown();
|
|
14359
|
+
var TargetKindSchema = object({
|
|
14360
|
+
kind: string(),
|
|
14361
|
+
label: string(),
|
|
14362
|
+
icon: string(),
|
|
14363
|
+
/** Stamped by each provider so the concat-fanned catalog stays routable. */
|
|
14364
|
+
addonId: string(),
|
|
14365
|
+
/**
|
|
14366
|
+
* URL of the kind's bundled BRAND icon, served by the providing addon over
|
|
14367
|
+
* its own `addon-routes` surface (`/addon/<addonId>/icons/<kind>`). Absent
|
|
14368
|
+
* when the addon bundles no icon for that kind — the client then falls back
|
|
14369
|
+
* to a neutral glyph rather than rendering the raw `icon` NAME as text.
|
|
14370
|
+
*
|
|
14371
|
+
* Root-relative on purpose: it resolves against whatever origin serves a web
|
|
14372
|
+
* client, and a native client joins it onto its own hub base.
|
|
14373
|
+
*
|
|
14374
|
+
* DECLARED here deliberately. It used to travel as an undeclared passthrough
|
|
14375
|
+
* field that survived only because the runtime cap-router forwards provider
|
|
14376
|
+
* output verbatim — so every consumer had to re-declare it by hand to stop
|
|
14377
|
+
* its own Zod parse from stripping it, and the whole arrangement would have
|
|
14378
|
+
* broken silently the moment output validation was tightened anywhere.
|
|
14379
|
+
*/
|
|
14380
|
+
iconUrl: string().optional(),
|
|
14381
|
+
/**
|
|
14382
|
+
* Media type of {@link iconUrl} (`image/svg+xml`, `image/png`, …).
|
|
14383
|
+
*
|
|
14384
|
+
* The server knows this and therefore says it, because the client cannot
|
|
14385
|
+
* safely guess: a React-Native client renders SVG and raster through two
|
|
14386
|
+
* DIFFERENT components (`react-native-svg` vs `expo-image` — expo-image does
|
|
14387
|
+
* not decode SVG on iOS/Android), so without this it silently fell back to a
|
|
14388
|
+
* placeholder glyph for every vector icon while the web build looked fine.
|
|
14389
|
+
*
|
|
14390
|
+
* Absent when {@link iconUrl} is absent, or for a legacy provider that has
|
|
14391
|
+
* not been updated — a client that cannot determine the type should prefer
|
|
14392
|
+
* its raster path, which is the safe default for an unknown image.
|
|
14393
|
+
*/
|
|
14394
|
+
iconMediaType: string().optional(),
|
|
14395
|
+
configSchema: ConfigSchemaPassthrough$4,
|
|
14396
|
+
/**
|
|
14397
|
+
* The config keys that decide WHERE this kind's secrets are sent (server,
|
|
14398
|
+
* base URL, instance, chat, recipient). A save that changes any of them
|
|
14399
|
+
* while leaving a secret redacted is refused by the provider (D634), so an
|
|
14400
|
+
* editor uses this to ask for the secret on exactly those edits instead of
|
|
14401
|
+
* on every edit.
|
|
14402
|
+
*
|
|
14403
|
+
* Optional: absent from a provider that holds no secret (the Home Assistant
|
|
14404
|
+
* kinds) and from a provider older than this field — an editor that finds
|
|
14405
|
+
* it absent must assume ANY edit may need the secret.
|
|
14406
|
+
*/
|
|
14407
|
+
destinationKeys: array(string()).optional(),
|
|
14408
|
+
supportsDiscovery: boolean(),
|
|
14409
|
+
/**
|
|
14410
|
+
* Extra delivery parameters a rule may set for a target of this kind (D938).
|
|
14411
|
+
* Absent = none; the rule editor then offers nothing.
|
|
14412
|
+
*/
|
|
14413
|
+
deliveryParams: array(DeliveryParamSchema).optional(),
|
|
14414
|
+
caps: TargetKindCapsSchema
|
|
14415
|
+
});
|
|
14416
|
+
/**
|
|
14417
|
+
* A persisted target. `config` holds secrets; providers REDACT secret fields
|
|
14418
|
+
* (return a presence marker only) when serving `listTargets` — never
|
|
14419
|
+
* round-trip a stored secret to the UI.
|
|
14420
|
+
*/
|
|
14421
|
+
var TargetSchema = object({
|
|
14422
|
+
id: string(),
|
|
14423
|
+
name: string(),
|
|
14424
|
+
kind: string(),
|
|
14425
|
+
addonId: string(),
|
|
14426
|
+
enabled: boolean(),
|
|
14427
|
+
config: record(string(), unknown())
|
|
14428
|
+
});
|
|
14429
|
+
/** A discovery-surfaced candidate (config is partial + non-secret). */
|
|
14430
|
+
var DiscoveredTargetSchema = object({
|
|
14431
|
+
kind: string(),
|
|
14432
|
+
suggestedName: string(),
|
|
14433
|
+
config: record(string(), unknown())
|
|
14434
|
+
});
|
|
14435
|
+
/** The degrade engine's report — what was resolved / dropped / degraded. */
|
|
14436
|
+
var RenderedAsSchema = object({
|
|
14437
|
+
level: string(),
|
|
14438
|
+
format: NotificationFormatSchema,
|
|
14439
|
+
attachmentsSent: number().int().nonnegative(),
|
|
14440
|
+
actionsSent: number().int().nonnegative(),
|
|
14441
|
+
truncated: boolean(),
|
|
14442
|
+
dropped: array(string())
|
|
14443
|
+
});
|
|
14444
|
+
var SendResultSchema = object({
|
|
14445
|
+
success: boolean(),
|
|
14446
|
+
error: string().optional(),
|
|
14447
|
+
renderedAs: RenderedAsSchema.optional()
|
|
14448
|
+
});
|
|
14449
|
+
/** Same shape as SendResult — kept as a distinct name for the test panel. */
|
|
14450
|
+
var TestResultSchema = SendResultSchema;
|
|
14451
|
+
/**
|
|
14452
|
+
* Pre-save credential probe against a partial (unsaved) target config.
|
|
14453
|
+
* `resolvedUrl` never includes secrets (token stripped from path).
|
|
14454
|
+
*/
|
|
14455
|
+
var ProbeTargetConfigResultSchema = object({
|
|
14456
|
+
ok: boolean(),
|
|
14457
|
+
resolvedUrl: string(),
|
|
14458
|
+
httpStatus: number().int().optional(),
|
|
14459
|
+
stateInstance: string().optional(),
|
|
14460
|
+
error: string().optional()
|
|
14461
|
+
});
|
|
14462
|
+
method(object({}), array(TargetKindSchema)), method(object({}), array(TargetSchema), { auth: "admin" }), method(object({ targetId: string() }), TargetSchema, { auth: "admin" }), method(object({
|
|
14463
|
+
kind: string(),
|
|
14464
|
+
config: record(string(), unknown()).optional(),
|
|
14465
|
+
/**
|
|
14466
|
+
* When editing / duplicating, the blank password field never round-trips
|
|
14467
|
+
* the stored token. Pass the source target id so the provider can restore
|
|
14468
|
+
* secrets server-side before dialling (same merge as upsert).
|
|
14469
|
+
*/
|
|
14470
|
+
targetId: string().optional()
|
|
14471
|
+
}), array(DiscoveredTargetSchema), { auth: "admin" }), method(object({
|
|
14472
|
+
kind: string(),
|
|
14473
|
+
config: record(string(), unknown()),
|
|
14474
|
+
/** See `discoverTargets.targetId` — restore stored secrets for a blank password. */
|
|
14475
|
+
targetId: string().optional()
|
|
14476
|
+
}), ProbeTargetConfigResultSchema, {
|
|
14477
|
+
kind: "mutation",
|
|
14478
|
+
auth: "admin"
|
|
14479
|
+
}), method(object({
|
|
14480
|
+
targetId: string(),
|
|
14481
|
+
notification: NotificationSchema
|
|
14482
|
+
}), SendResultSchema, {
|
|
14483
|
+
kind: "mutation",
|
|
14484
|
+
auth: "admin"
|
|
14485
|
+
}), method(object({
|
|
14486
|
+
targetId: string(),
|
|
14487
|
+
sample: NotificationSchema.optional()
|
|
14488
|
+
}), TestResultSchema, {
|
|
14489
|
+
kind: "mutation",
|
|
14490
|
+
auth: "admin"
|
|
14491
|
+
}), method(object({
|
|
14492
|
+
target: TargetSchema,
|
|
14493
|
+
/**
|
|
14494
|
+
* Duplicate flow: create a NEW target id while copying secrets from an
|
|
14495
|
+
* existing row. The UI never holds the stored token; blank / redacted
|
|
14496
|
+
* password fields are restored from this source (D634 still applies if
|
|
14497
|
+
* destinations diverge without a re-typed secret).
|
|
14498
|
+
*/
|
|
14499
|
+
cloneSecretsFrom: string().optional()
|
|
14500
|
+
}), TargetSchema, {
|
|
14501
|
+
kind: "mutation",
|
|
14502
|
+
auth: "admin"
|
|
14503
|
+
}), method(object({ targetId: string() }), _void(), {
|
|
14504
|
+
kind: "mutation",
|
|
14505
|
+
auth: "admin"
|
|
14506
|
+
}), method(object({
|
|
14507
|
+
targetId: string(),
|
|
14508
|
+
enabled: boolean()
|
|
14509
|
+
}), _void(), {
|
|
14510
|
+
kind: "mutation",
|
|
14511
|
+
auth: "admin"
|
|
14512
|
+
});
|
|
14513
|
+
looseObject({
|
|
14514
|
+
name: string().min(1),
|
|
14515
|
+
enabled: boolean().optional()
|
|
14516
|
+
});
|
|
14517
|
+
TargetSchema.omit({ id: true });
|
|
13841
14518
|
var EncodeProfileSchema = object({
|
|
13842
14519
|
video: object({
|
|
13843
14520
|
codec: _enum([
|
|
@@ -20022,31 +20699,21 @@ var APPLIANCE_CAP_VOCABULARY = {
|
|
|
20022
20699
|
"pet-fountain": {
|
|
20023
20700
|
scope: "device",
|
|
20024
20701
|
noun: t("Pet fountain", "Fontana per animali"),
|
|
20025
|
-
actions: [
|
|
20026
|
-
|
|
20027
|
-
|
|
20028
|
-
|
|
20029
|
-
|
|
20030
|
-
|
|
20031
|
-
|
|
20032
|
-
|
|
20033
|
-
|
|
20034
|
-
|
|
20035
|
-
|
|
20036
|
-
|
|
20037
|
-
|
|
20038
|
-
|
|
20039
|
-
|
|
20040
|
-
args: { on: false }
|
|
20041
|
-
},
|
|
20042
|
-
{
|
|
20043
|
-
id: "petFountain.resetDailyConsumption",
|
|
20044
|
-
method: "resetDailyConsumption",
|
|
20045
|
-
label: t("Clear daily consumption", "Azzera il consumo giornaliero"),
|
|
20046
|
-
phrase: t("Clear the daily water consumption of {device}", "Azzera il consumo giornaliero di acqua di {device}"),
|
|
20047
|
-
icon: "rotate-ccw"
|
|
20048
|
-
}
|
|
20049
|
-
],
|
|
20702
|
+
actions: [{
|
|
20703
|
+
id: "petFountain.pumpOn",
|
|
20704
|
+
method: "setPump",
|
|
20705
|
+
label: t("Pump on", "Pompa accesa"),
|
|
20706
|
+
phrase: t("Start the pump of {device}", "Avvia la pompa di {device}"),
|
|
20707
|
+
icon: "play",
|
|
20708
|
+
args: { on: true }
|
|
20709
|
+
}, {
|
|
20710
|
+
id: "petFountain.pumpOff",
|
|
20711
|
+
method: "setPump",
|
|
20712
|
+
label: t("Pump off", "Pompa spenta"),
|
|
20713
|
+
phrase: t("Stop the pump of {device}", "Ferma la pompa di {device}"),
|
|
20714
|
+
icon: "square",
|
|
20715
|
+
args: { on: false }
|
|
20716
|
+
}],
|
|
20050
20717
|
state: [{
|
|
20051
20718
|
kind: "boolean",
|
|
20052
20719
|
field: "empty",
|
|
@@ -22065,7 +22732,6 @@ var SYSTEM_CAP_VOCABULARY = {
|
|
|
22065
22732
|
"calendar-source": system(INTERNAL),
|
|
22066
22733
|
calendars: system("calendars feed schedules and conditions, not device actions"),
|
|
22067
22734
|
composer: system("device composition — an authoring tool, not an action"),
|
|
22068
|
-
"connection-test": system(INTERNAL),
|
|
22069
22735
|
"core-blocks": system(INTERNAL),
|
|
22070
22736
|
"custom-model-registry": system(ML),
|
|
22071
22737
|
"data-store-provider": system(INTERNAL),
|
|
@@ -43791,610 +44457,196 @@ var AutomationRunTraceSchema = object({
|
|
|
43791
44457
|
startedAt: number(),
|
|
43792
44458
|
endedAt: number(),
|
|
43793
44459
|
trigger: AutomationTriggerTraceSchema,
|
|
43794
|
-
conditions: array(AutomationConditionTraceNodeSchema),
|
|
43795
|
-
verdict: AutomationRunVerdictSchema.optional(),
|
|
43796
|
-
steps: array(AutomationStepTraceSchema),
|
|
43797
|
-
outcome: AutomationRunOutcomeSchema,
|
|
43798
|
-
/** How many identical consecutive skips this trace stands for (>= 1). */
|
|
43799
|
-
repeat: number().int().min(1),
|
|
43800
|
-
/** When the latest of those repeats happened. */
|
|
43801
|
-
lastAt: number(),
|
|
43802
|
-
/**
|
|
43803
|
-
* A scheduler point's own outcome (D983). `outcome` carries the closest
|
|
43804
|
-
* automation outcome so a reader that does not know schedulers still reads
|
|
43805
|
-
* the trace; this field says exactly what happened.
|
|
43806
|
-
*/
|
|
43807
|
-
scheduler: SchedulerOutcomeSchema.optional()
|
|
43808
|
-
});
|
|
43809
|
-
/**
|
|
43810
|
-
* What the hub's `runs` ledger holds for one owner (`automation:<blockId>` or
|
|
43811
|
-
* `action:<actionId>`): the cooldown stamp and the trace ring.
|
|
43812
|
-
*/
|
|
43813
|
-
var AutomationStateDocSchema = object({
|
|
43814
|
-
version: literal(1),
|
|
43815
|
-
lastRunStartedAt: number().nullable(),
|
|
43816
|
-
traces: array(AutomationRunTraceSchema)
|
|
43817
|
-
});
|
|
43818
|
-
/**
|
|
43819
|
-
* Actions — named, runnable things an operator (or an automation) can start,
|
|
43820
|
-
* declared as LIST ENTRIES, never as devices.
|
|
43821
|
-
*
|
|
43822
|
-
* An entry is either **internal** (a short list of cap/wait steps kept in the
|
|
43823
|
-
* hub's `actions` record kind) or declared by an addon through the
|
|
43824
|
-
* `action-source` collection (a Home Assistant script, a scene …). The one
|
|
43825
|
-
* surface the UI and automations talk to is the `actions` cap; it keeps no
|
|
43826
|
-
* catalog of its own (D3) — every `list` asks the providers live.
|
|
43827
|
-
*
|
|
43828
|
-
* This file is the data half: the entry schema, the variables an entry may
|
|
43829
|
-
* declare, and the pure resolution of the values a run was given. It holds no
|
|
43830
|
-
* runtime.
|
|
43831
|
-
*/
|
|
43832
|
-
/** What a variable's value is. `select` takes one of `options`. */
|
|
43833
|
-
var ActionVariableTypeSchema = _enum([
|
|
43834
|
-
"string",
|
|
43835
|
-
"number",
|
|
43836
|
-
"boolean",
|
|
43837
|
-
"select"
|
|
43838
|
-
]);
|
|
43839
|
-
var ACTION_VARIABLE_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
43840
|
-
var ActionVariableValueSchema = union([
|
|
43841
|
-
string(),
|
|
43842
|
-
number(),
|
|
43843
|
-
boolean()
|
|
43844
|
-
]);
|
|
43845
|
-
/**
|
|
43846
|
-
* One declared variable. Steps reference it as `{ $var: 'name' }` (the whole
|
|
43847
|
-
* value) or `{{vars.name}}` (inside a string) in their args.
|
|
43848
|
-
*/
|
|
43849
|
-
var ActionVariableSchema = object({
|
|
43850
|
-
name: string().regex(ACTION_VARIABLE_NAME_RE),
|
|
43851
|
-
label: string().min(1).max(120).optional(),
|
|
43852
|
-
type: ActionVariableTypeSchema,
|
|
43853
|
-
required: boolean().optional(),
|
|
43854
|
-
default: ActionVariableValueSchema.optional(),
|
|
43855
|
-
/** The allowed values of a `select`. */
|
|
43856
|
-
options: array(string().min(1)).min(1).optional()
|
|
43857
|
-
}).superRefine((v, ctx) => {
|
|
43858
|
-
if (v.type === "select" && v.options === void 0) ctx.addIssue({
|
|
43859
|
-
code: "custom",
|
|
43860
|
-
message: "a select variable needs options",
|
|
43861
|
-
path: ["options"]
|
|
43862
|
-
});
|
|
43863
|
-
if (v.default !== void 0 && variableValueError(v, v.default) !== null) ctx.addIssue({
|
|
43864
|
-
code: "custom",
|
|
43865
|
-
message: variableValueError(v, v.default) ?? "invalid default",
|
|
43866
|
-
path: ["default"]
|
|
43867
|
-
});
|
|
43868
|
-
});
|
|
43869
|
-
/** Why `value` is not a legal value for the variable, or null when it is. */
|
|
43870
|
-
function variableValueError(variable, value) {
|
|
43871
|
-
switch (variable.type) {
|
|
43872
|
-
case "string": return typeof value === "string" ? null : `variable "${variable.name}" must be a string`;
|
|
43873
|
-
case "number": return typeof value === "number" && Number.isFinite(value) ? null : `variable "${variable.name}" must be a number`;
|
|
43874
|
-
case "boolean": return typeof value === "boolean" ? null : `variable "${variable.name}" must be true or false`;
|
|
43875
|
-
case "select": return typeof value === "string" && (variable.options ?? []).includes(value) ? null : `variable "${variable.name}" must be one of ${(variable.options ?? []).join(", ")}`;
|
|
43876
|
-
}
|
|
43877
|
-
}
|
|
43878
|
-
var ActionSourceKindSchema = _enum(["internal", "addon"]);
|
|
43879
|
-
function isInternalActionId(actionId) {
|
|
43880
|
-
return actionId.startsWith("internal:") && actionId.length > 9;
|
|
43881
|
-
}
|
|
43882
|
-
/** The addon behind a `<addonId>:<localId>` id, or null for anything else (internal included). */
|
|
43883
|
-
function addonIdOfActionId(actionId) {
|
|
43884
|
-
if (isInternalActionId(actionId)) return null;
|
|
43885
|
-
const at = actionId.indexOf(":");
|
|
43886
|
-
return at > 0 && at < actionId.length - 1 ? actionId.slice(0, at) : null;
|
|
43887
|
-
}
|
|
43888
|
-
var ActionStatusSchema = object({
|
|
43889
|
-
isRunning: boolean(),
|
|
43890
|
-
/** Ms epoch the latest run STARTED; null when it never ran. */
|
|
43891
|
-
lastRunAt: number().nullable(),
|
|
43892
|
-
/** The latest run's failure; null on success or when it never ran. */
|
|
43893
|
-
lastError: string().nullable()
|
|
43894
|
-
});
|
|
43895
|
-
var ActionEntrySchema = object({
|
|
43896
|
-
/** `internal:<uuid>` or `<addonId>:<localId>`. */
|
|
43897
|
-
id: string().min(3),
|
|
43898
|
-
name: string().min(1).max(120),
|
|
43899
|
-
/** The addon that declared it; `core-blocks` for an internal one. */
|
|
43900
|
-
addonId: string().min(1),
|
|
43901
|
-
source: ActionSourceKindSchema,
|
|
43902
|
-
/** An addon-declared entry is edited where it was declared. */
|
|
43903
|
-
readOnly: boolean(),
|
|
43904
|
-
/** Internal only: cap and wait steps. No action-in-action, so no cycles. */
|
|
43905
|
-
steps: array(ActionStepSchema).min(1).max(50).optional(),
|
|
43906
|
-
variables: array(ActionVariableSchema).max(20).optional(),
|
|
43907
|
-
status: ActionStatusSchema
|
|
43908
|
-
}).superRefine((entry, ctx) => {
|
|
43909
|
-
if (entry.source === "internal") {
|
|
43910
|
-
if (!isInternalActionId(entry.id)) ctx.addIssue({
|
|
43911
|
-
code: "custom",
|
|
43912
|
-
message: "an internal action id is internal:<uuid>",
|
|
43913
|
-
path: ["id"]
|
|
43914
|
-
});
|
|
43915
|
-
return;
|
|
43916
|
-
}
|
|
43917
|
-
if (entry.steps !== void 0) ctx.addIssue({
|
|
43918
|
-
code: "custom",
|
|
43919
|
-
message: "only an internal action carries steps",
|
|
43920
|
-
path: ["steps"]
|
|
43921
|
-
});
|
|
43922
|
-
if (!entry.readOnly) ctx.addIssue({
|
|
43923
|
-
code: "custom",
|
|
43924
|
-
message: "an addon action is read-only here",
|
|
43925
|
-
path: ["readOnly"]
|
|
43926
|
-
});
|
|
43927
|
-
if (addonIdOfActionId(entry.id) === null) ctx.addIssue({
|
|
43928
|
-
code: "custom",
|
|
43929
|
-
message: "an addon action id is <addonId>:<localId>",
|
|
43930
|
-
path: ["id"]
|
|
43931
|
-
});
|
|
43932
|
-
});
|
|
43933
|
-
/** What an operator writes for an internal action. */
|
|
43934
|
-
var ActionInputSchema = object({
|
|
43935
|
-
name: string().min(1).max(120),
|
|
43936
|
-
steps: array(ActionStepSchema).min(1).max(50),
|
|
43937
|
-
variables: array(ActionVariableSchema).max(20).optional()
|
|
43938
|
-
});
|
|
43939
|
-
/** Who started a run. Absent = the operator pressed it. */
|
|
43940
|
-
var ActionRunOriginSchema = object({
|
|
43941
|
-
/** The automation block whose step started it. */
|
|
43942
|
-
blockId: string().min(1).optional() });
|
|
43943
|
-
/** `started` = the caller did not ask to wait. */
|
|
43944
|
-
var ActionRunOutcomeSchema = union([AutomationRunOutcomeSchema, literal("started")]);
|
|
43945
|
-
var ActionRunResultSchema = object({
|
|
43946
|
-
runId: string().min(1),
|
|
43947
|
-
outcome: ActionRunOutcomeSchema,
|
|
43948
|
-
/** Why it did not run, or what failed. */
|
|
43949
|
-
message: string().optional()
|
|
43950
|
-
});
|
|
43951
|
-
_enum([
|
|
43952
|
-
"not-found",
|
|
43953
|
-
"read-only",
|
|
43954
|
-
"invalid-variables",
|
|
43955
|
-
"invalid-steps",
|
|
43956
|
-
"not-linked",
|
|
43957
|
-
"busy"
|
|
43958
|
-
]);
|
|
43959
|
-
object({
|
|
43960
|
-
actionId: string(),
|
|
43961
|
-
runId: string(),
|
|
43962
|
-
isRunning: boolean(),
|
|
43963
|
-
/** Set when the run ended. */
|
|
43964
|
-
outcome: AutomationRunOutcomeSchema.optional(),
|
|
43965
|
-
lastRunAt: number().nullable(),
|
|
43966
|
-
lastError: string().nullable()
|
|
43967
|
-
});
|
|
43968
|
-
/** A bare number accepted as a base unit — the save succeeded, say so. */
|
|
43969
|
-
var UnitWarningSchema = object({
|
|
43970
|
-
/** Where in the saved record, e.g. `conditions.children.0` or `steps.2.args.grams`. */
|
|
43971
|
-
path: string(),
|
|
43972
|
-
deviceId: number().int().optional(),
|
|
43973
|
-
field: string(),
|
|
43974
|
-
value: number(),
|
|
43975
|
-
assumedUnit: string(),
|
|
43976
|
-
message: string()
|
|
43977
|
-
});
|
|
43978
|
-
/**
|
|
43979
|
-
* notification-output — canonical, capability-gated notification delivery.
|
|
43980
|
-
*
|
|
43981
|
-
* Apprise-derived model (see
|
|
43982
|
-
* `docs/superpowers/specs/2026-07-03-notification-output-notifier-matrix.md`):
|
|
43983
|
-
* callers emit ONE canonical `Notification`; each provider declares a
|
|
43984
|
-
* per-kind capability descriptor (`TargetKind`), and the pure degrade
|
|
43985
|
-
* engine (`@camstack/types` `prepareNotification`) transcodes / degrades the
|
|
43986
|
-
* message to what the kind supports — callers never special-case a service.
|
|
43987
|
-
*
|
|
43988
|
-
* DESIGN DECISIONS (locked):
|
|
43989
|
-
* - Target CRUD lives on THIS cap (`upsertTarget` / `deleteTarget` /
|
|
43990
|
-
* `setTargetEnabled`), each provider persisting via the `settings-store`
|
|
43991
|
-
* cap. Rationale: the admin UI needs one uniform surface across the
|
|
43992
|
-
* notifiers addon AND the HA addon; the addon-`globalSettingsSchema`-array
|
|
43993
|
-
* alternative would fork the UI per addon and cannot host the
|
|
43994
|
-
* discovery→adopt flow.
|
|
43995
|
-
* - `listTargetKinds` / `listTargets` / `discoverTargets` return arrays →
|
|
43996
|
-
* the generated cap-mount auto-`concatCollection`-fans them across every
|
|
43997
|
-
* registered provider (notifiers addon + HA addon) so one catalog is
|
|
43998
|
-
* routable. `send` / `testTarget` / CRUD route to ONE provider by the
|
|
43999
|
-
* `addonId` the generated collection router extracts from the call input.
|
|
44000
|
-
* - `Attachment.bytes` is `Uint8Array`. Transport-safe: superjson (the tRPC
|
|
44001
|
-
* transformer) + UDS MsgPack both round-trip typed arrays — already used by
|
|
44002
|
-
* `storage` / `storage-provider` / `recording` caps over the same path. No
|
|
44003
|
-
* base64 fallback needed.
|
|
44004
|
-
*
|
|
44005
|
-
* TODO (deferred, closed-set change — separate decision): add
|
|
44006
|
-
* `providerKind: 'notify'` so notification providers surface on the unified
|
|
44007
|
-
* admin "Integrations" page.
|
|
44008
|
-
*/
|
|
44009
|
-
/**
|
|
44010
|
-
* Zentik-derived typed-media enum — the superset across every kind. Each
|
|
44011
|
-
* adapter picks what it supports and the degrade engine filters the rest.
|
|
44012
|
-
*/
|
|
44013
|
-
var AttachmentMediaTypeSchema = _enum([
|
|
44014
|
-
"image",
|
|
44015
|
-
"video",
|
|
44016
|
-
"gif",
|
|
44017
|
-
"audio",
|
|
44018
|
-
"icon"
|
|
44019
|
-
]);
|
|
44020
|
-
/**
|
|
44021
|
-
* A single attachment. Exactly one of `url` (remote source, most adapters
|
|
44022
|
-
* prefer this) or `bytes` (inline source; required for Pushover-style
|
|
44023
|
-
* bytes-only kinds) MUST be present — the degrade engine expresses a
|
|
44024
|
-
* url→bytes fetch as a `needsFetch` directive the adapter executes.
|
|
44025
|
-
*/
|
|
44026
|
-
var AttachmentSchema = object({
|
|
44027
|
-
mediaType: AttachmentMediaTypeSchema,
|
|
44028
|
-
url: string().optional(),
|
|
44029
|
-
bytes: _instanceof(Uint8Array).optional(),
|
|
44030
|
-
mime: string().optional(),
|
|
44031
|
-
name: string().optional()
|
|
44032
|
-
}).refine((a) => a.url !== void 0 || a.bytes !== void 0, { message: "Attachment requires either `url` or `bytes`" });
|
|
44033
|
-
var NotificationFormatSchema = _enum([
|
|
44034
|
-
"text",
|
|
44035
|
-
"markdown",
|
|
44036
|
-
"html"
|
|
44037
|
-
]);
|
|
44038
|
-
/**
|
|
44039
|
-
* The CLOSED icon vocabulary an action button may use.
|
|
44040
|
-
*
|
|
44041
|
-
* A closed set, not a free string, and that is the whole point: an arbitrary
|
|
44042
|
-
* icon name is one that ntfy renders, zentik silently drops, and nobody
|
|
44043
|
-
* notices — the same class of gap as a zone vocabulary nothing produced
|
|
44044
|
-
* ([D35](../../../docs/decisions/adr-0035.md)). Every adapter maps this set or
|
|
44045
|
-
* declares `actionIcons: false` and the degrade engine strips the field.
|
|
44046
|
-
*
|
|
44047
|
-
* Named by INTENT, never by glyph. "check" would tie the vocabulary to one
|
|
44048
|
-
* renderer's icon set; "acknowledge" survives an adapter that draws it
|
|
44049
|
-
* differently.
|
|
44050
|
-
*
|
|
44051
|
-
* ── A TOKEN IS NOT A WIRE VALUE ─────────────────────────────────────
|
|
44052
|
-
*
|
|
44053
|
-
* These names are for US. **No adapter may forward one verbatim.** Each maps
|
|
44054
|
-
* the whole set onto its own renderer's vocabulary through a
|
|
44055
|
-
* `Record<NotificationActionIcon, string>` — a Record, never a lookup with a
|
|
44056
|
-
* fallback, so adding a member here fails every adapter's build until someone
|
|
44057
|
-
* decides its glyph, which is the only place that decision can be made
|
|
44058
|
-
* honestly.
|
|
44059
|
-
*
|
|
44060
|
-
* This paragraph is the bug. Zentik declared `actionIcons: true` and passed
|
|
44061
|
-
* `disarm` straight through; iOS feeds that string to
|
|
44062
|
-
* `UNNotificationActionIcon(systemImageName:)`, `disarm` is not an SF Symbol,
|
|
44063
|
-
* and every snooze and alarm button arrived BLANK. A pass-through is not a
|
|
44064
|
-
* mapping, and "the field is documented" is not "the value renders".
|
|
44065
|
-
*
|
|
44066
|
-
* Adding a member is TRAIN-BOUND. The enum lives in the published
|
|
44067
|
-
* `@camstack/server` closure and the cap seam validates against the HUB's copy,
|
|
44068
|
-
* so an addon that emits a token the running hub does not know does not lose an
|
|
44069
|
-
* icon — its whole `send` fails Zod validation and the notification never
|
|
44070
|
-
* arrives. Never emit a new token from an addon before the train carrying it.
|
|
44071
|
-
*/
|
|
44072
|
-
var NotificationActionIconSchema = _enum([
|
|
44073
|
-
"acknowledge",
|
|
44074
|
-
"dismiss",
|
|
44075
|
-
"silence",
|
|
44076
|
-
"snooze",
|
|
44077
|
-
"view",
|
|
44078
|
-
"play",
|
|
44079
|
-
"open",
|
|
44080
|
-
"close",
|
|
44081
|
-
"lock",
|
|
44082
|
-
"unlock",
|
|
44083
|
-
"arm",
|
|
44084
|
-
"arm-home",
|
|
44085
|
-
"arm-away",
|
|
44086
|
-
"arm-night",
|
|
44087
|
-
"disarm",
|
|
44088
|
-
"light",
|
|
44089
|
-
"alert",
|
|
44090
|
-
"camera"
|
|
44091
|
-
]);
|
|
44092
|
-
/** A single tap-through action button. */
|
|
44093
|
-
var NotificationActionSchema = object({
|
|
44094
|
-
id: string(),
|
|
44095
|
-
label: string(),
|
|
44096
|
-
url: string().optional(),
|
|
44097
|
-
/** Dropped by the degrade engine for a kind with `caps.actionIcons: false`. */
|
|
44098
|
-
icon: NotificationActionIconSchema.optional(),
|
|
44099
|
-
/**
|
|
44100
|
-
* Renders in a warning style where the notifier supports it.
|
|
44101
|
-
*
|
|
44102
|
-
* A HINT, never a gate. The callback's authority is its token and nothing
|
|
44103
|
-
* else — see `notification-center/action-token.ts` for what that does and
|
|
44104
|
-
* does not buy.
|
|
44105
|
-
*/
|
|
44106
|
-
destructive: boolean().optional(),
|
|
44107
|
-
/**
|
|
44108
|
-
* How the tap should REACH the url.
|
|
44109
|
-
*
|
|
44110
|
-
* `navigate` (absent, and every button authored before this field) opens it:
|
|
44111
|
-
* the phone leaves the notification and shows whatever the callback returns.
|
|
44112
|
-
* That is right for a button whose answer the operator wants to read.
|
|
44113
|
-
*
|
|
44114
|
-
* `background` fires it as a POST and stays put. It exists for the buttons
|
|
44115
|
-
* whose whole point is not to interrupt — "silence this for 30 minutes" is
|
|
44116
|
-
* an answer to the notification, and being thrown into a browser tab to
|
|
44117
|
-
* confirm it costs more attention than the notification did. A backend that
|
|
44118
|
-
* cannot do a background call renders it as an ordinary link (the adapters
|
|
44119
|
-
* fall back rather than dropping the button), so this is a preference, never
|
|
44120
|
-
* a requirement.
|
|
44121
|
-
*/
|
|
44122
|
-
mode: _enum(["navigate", "background"]).optional()
|
|
44123
|
-
});
|
|
44124
|
-
/** A delivery parameter value: what a notifier declared it takes. */
|
|
44125
|
-
var DeliveryParamValueSchema = union([
|
|
44126
|
-
string(),
|
|
44127
|
-
number(),
|
|
44128
|
-
boolean()
|
|
44129
|
-
]);
|
|
44130
|
-
/**
|
|
44131
|
-
* One extra delivery parameter a notifier KIND declares (D938). A rule that
|
|
44132
|
-
* addresses a target of that kind may set it; a kind that declares nothing is
|
|
44133
|
-
* never handed one. The admin UI derives its control from this descriptor —
|
|
44134
|
-
* no editor knows a service by name.
|
|
44135
|
-
*
|
|
44136
|
-
* Optional fields are `.optional()`, never `.default()` (a Zod default does not
|
|
44137
|
-
* run on the addon cap path).
|
|
44138
|
-
*/
|
|
44139
|
-
var DeliveryParamSchema = object({
|
|
44140
|
-
key: string().min(1),
|
|
44141
|
-
label: string(),
|
|
44142
|
-
/** i18n key of the label, resolved by the declaring addon's namespace. */
|
|
44143
|
-
labelKey: string().optional(),
|
|
44144
|
-
type: _enum([
|
|
44145
|
-
"enum",
|
|
44146
|
-
"number",
|
|
44147
|
-
"boolean",
|
|
44148
|
-
"string"
|
|
44149
|
-
]),
|
|
44150
|
-
/** `enum` only: the closed set of accepted values. */
|
|
44151
|
-
options: array(object({
|
|
44152
|
-
value: string(),
|
|
44153
|
-
label: string()
|
|
44154
|
-
})).optional(),
|
|
44155
|
-
/** `number` only. */
|
|
44156
|
-
min: number().optional(),
|
|
44157
|
-
max: number().optional(),
|
|
44158
|
-
/** What the notifier does when the rule sets nothing; shown as the placeholder. */
|
|
44159
|
-
default: DeliveryParamValueSchema.optional()
|
|
44160
|
-
});
|
|
44161
|
-
/**
|
|
44162
|
-
* The canonical notification. `body` is the only hard field (Apprise model).
|
|
44163
|
-
* `priority` is a 5-level ORDINAL (1=lowest … 3=normal(default) … 5=urgent),
|
|
44164
|
-
* NOT a fixed severity enum — each kind declares its own `caps.levels` and
|
|
44165
|
-
* the adapter maps this ordinal onto its native level. `level?` is an
|
|
44166
|
-
* optional kind-native level id (`emergency`, `silent`, …) that overrides
|
|
44167
|
-
* `priority` for that one target.
|
|
44168
|
-
*/
|
|
44169
|
-
var NotificationSchema = object({
|
|
44170
|
-
body: string(),
|
|
44171
|
-
title: string().optional(),
|
|
44172
|
-
format: NotificationFormatSchema.default("text"),
|
|
44173
|
-
priority: number().int().min(1).max(5).default(3),
|
|
44174
|
-
level: string().optional(),
|
|
44175
|
-
attachments: array(AttachmentSchema).optional(),
|
|
44176
|
-
clickUrl: string().optional(),
|
|
44177
|
-
actions: array(NotificationActionSchema).optional(),
|
|
44178
|
-
sound: string().optional(),
|
|
44179
|
-
ttl: number().optional(),
|
|
44180
|
-
tag: string().optional(),
|
|
44181
|
-
deviceId: number().optional(),
|
|
44182
|
-
eventId: string().optional(),
|
|
44183
|
-
metadata: record(string(), unknown()).optional(),
|
|
44184
|
-
/**
|
|
44185
|
-
* Values for the parameters the target's kind DECLARES in
|
|
44186
|
-
* {@link TargetKindSchema} `deliveryParams`. Already validated against the
|
|
44187
|
-
* declaration by the sender; a notifier reads only the keys it declared.
|
|
44188
|
-
*/
|
|
44189
|
-
delivery: record(string(), DeliveryParamValueSchema).optional()
|
|
44190
|
-
});
|
|
44191
|
-
/** One declared native severity/priority level for a kind. */
|
|
44192
|
-
var TargetKindLevelSchema = object({
|
|
44193
|
-
id: string(),
|
|
44194
|
-
label: string(),
|
|
44195
|
-
/** Which canonical priority (1..5) this level maps to. `null` = qualitative-only. */
|
|
44196
|
-
ordinal: number().int().min(1).max(5).nullable(),
|
|
44197
|
-
flags: object({
|
|
44198
|
-
critical: boolean().optional(),
|
|
44199
|
-
silent: boolean().optional(),
|
|
44200
|
-
noPush: boolean().optional()
|
|
44201
|
-
}).optional(),
|
|
44202
|
-
/** e.g. Pushover `emergency` requires `retry` / `expire`. */
|
|
44203
|
-
requires: array(string()).optional(),
|
|
44204
|
-
description: string().optional()
|
|
44205
|
-
});
|
|
44206
|
-
/** The full capability block consulted before dispatch. */
|
|
44207
|
-
var TargetKindCapsSchema = object({
|
|
44208
|
-
attachments: object({
|
|
44209
|
-
mediaTypes: array(AttachmentMediaTypeSchema),
|
|
44210
|
-
mode: _enum([
|
|
44211
|
-
"url",
|
|
44212
|
-
"bytes",
|
|
44213
|
-
"both"
|
|
44214
|
-
]),
|
|
44215
|
-
max: number().int().nonnegative(),
|
|
44216
|
-
maxBytes: number().int().positive().optional()
|
|
44217
|
-
}),
|
|
44218
|
-
/** Max action buttons (0 = none). */
|
|
44219
|
-
actions: number().int().nonnegative(),
|
|
44220
|
-
/**
|
|
44221
|
-
* Whether this kind renders a per-action ICON.
|
|
44222
|
-
*
|
|
44223
|
-
* `.optional()`, deliberately NOT `.default(false)`: a Zod default does not
|
|
44224
|
-
* run on the addon cap path — three production failures in one day taught
|
|
44225
|
-
* this repo that once. Absent is read as false by the degrade engine, which
|
|
44226
|
-
* is the safe direction: an icon that is not rendered costs nothing, an icon
|
|
44227
|
-
* assumed and dropped costs the operator's trust in the field.
|
|
44228
|
-
*/
|
|
44229
|
-
actionIcons: boolean().optional(),
|
|
44230
|
-
levels: array(TargetKindLevelSchema),
|
|
44231
|
-
format: array(NotificationFormatSchema),
|
|
44232
|
-
clickUrl: boolean(),
|
|
44233
|
-
sound: boolean(),
|
|
44234
|
-
ttl: boolean(),
|
|
44235
|
-
bodyMaxLen: number().int().positive()
|
|
44236
|
-
});
|
|
44237
|
-
/**
|
|
44238
|
-
* `configSchema` is a `ConfigUISchema` tree passed through to the admin
|
|
44239
|
-
* FormBuilder. Stored as `z.unknown()` at the cap seam (mirrors
|
|
44240
|
-
* `device-provider.getChildCreationSchema` `CreationSchemaOutputSchema`) —
|
|
44241
|
-
* the union is large and not meant for runtime validation here; the exported
|
|
44242
|
-
* `TargetKind` type re-tightens `configSchema` to `ConfigUISchema`.
|
|
44243
|
-
*/
|
|
44244
|
-
var ConfigSchemaPassthrough$4 = unknown();
|
|
44245
|
-
var TargetKindSchema = object({
|
|
44246
|
-
kind: string(),
|
|
44247
|
-
label: string(),
|
|
44248
|
-
icon: string(),
|
|
44249
|
-
/** Stamped by each provider so the concat-fanned catalog stays routable. */
|
|
44250
|
-
addonId: string(),
|
|
44251
|
-
/**
|
|
44252
|
-
* URL of the kind's bundled BRAND icon, served by the providing addon over
|
|
44253
|
-
* its own `addon-routes` surface (`/addon/<addonId>/icons/<kind>`). Absent
|
|
44254
|
-
* when the addon bundles no icon for that kind — the client then falls back
|
|
44255
|
-
* to a neutral glyph rather than rendering the raw `icon` NAME as text.
|
|
44256
|
-
*
|
|
44257
|
-
* Root-relative on purpose: it resolves against whatever origin serves a web
|
|
44258
|
-
* client, and a native client joins it onto its own hub base.
|
|
44259
|
-
*
|
|
44260
|
-
* DECLARED here deliberately. It used to travel as an undeclared passthrough
|
|
44261
|
-
* field that survived only because the runtime cap-router forwards provider
|
|
44262
|
-
* output verbatim — so every consumer had to re-declare it by hand to stop
|
|
44263
|
-
* its own Zod parse from stripping it, and the whole arrangement would have
|
|
44264
|
-
* broken silently the moment output validation was tightened anywhere.
|
|
44265
|
-
*/
|
|
44266
|
-
iconUrl: string().optional(),
|
|
44267
|
-
/**
|
|
44268
|
-
* Media type of {@link iconUrl} (`image/svg+xml`, `image/png`, …).
|
|
44269
|
-
*
|
|
44270
|
-
* The server knows this and therefore says it, because the client cannot
|
|
44271
|
-
* safely guess: a React-Native client renders SVG and raster through two
|
|
44272
|
-
* DIFFERENT components (`react-native-svg` vs `expo-image` — expo-image does
|
|
44273
|
-
* not decode SVG on iOS/Android), so without this it silently fell back to a
|
|
44274
|
-
* placeholder glyph for every vector icon while the web build looked fine.
|
|
44275
|
-
*
|
|
44276
|
-
* Absent when {@link iconUrl} is absent, or for a legacy provider that has
|
|
44277
|
-
* not been updated — a client that cannot determine the type should prefer
|
|
44278
|
-
* its raster path, which is the safe default for an unknown image.
|
|
44279
|
-
*/
|
|
44280
|
-
iconMediaType: string().optional(),
|
|
44281
|
-
configSchema: ConfigSchemaPassthrough$4,
|
|
44282
|
-
/**
|
|
44283
|
-
* The config keys that decide WHERE this kind's secrets are sent (server,
|
|
44284
|
-
* base URL, instance, chat, recipient). A save that changes any of them
|
|
44285
|
-
* while leaving a secret redacted is refused by the provider (D634), so an
|
|
44286
|
-
* editor uses this to ask for the secret on exactly those edits instead of
|
|
44287
|
-
* on every edit.
|
|
44288
|
-
*
|
|
44289
|
-
* Optional: absent from a provider that holds no secret (the Home Assistant
|
|
44290
|
-
* kinds) and from a provider older than this field — an editor that finds
|
|
44291
|
-
* it absent must assume ANY edit may need the secret.
|
|
44292
|
-
*/
|
|
44293
|
-
destinationKeys: array(string()).optional(),
|
|
44294
|
-
supportsDiscovery: boolean(),
|
|
44460
|
+
conditions: array(AutomationConditionTraceNodeSchema),
|
|
44461
|
+
verdict: AutomationRunVerdictSchema.optional(),
|
|
44462
|
+
steps: array(AutomationStepTraceSchema),
|
|
44463
|
+
outcome: AutomationRunOutcomeSchema,
|
|
44464
|
+
/** How many identical consecutive skips this trace stands for (>= 1). */
|
|
44465
|
+
repeat: number().int().min(1),
|
|
44466
|
+
/** When the latest of those repeats happened. */
|
|
44467
|
+
lastAt: number(),
|
|
44295
44468
|
/**
|
|
44296
|
-
*
|
|
44297
|
-
*
|
|
44469
|
+
* A scheduler point's own outcome (D983). `outcome` carries the closest
|
|
44470
|
+
* automation outcome so a reader that does not know schedulers still reads
|
|
44471
|
+
* the trace; this field says exactly what happened.
|
|
44298
44472
|
*/
|
|
44299
|
-
|
|
44300
|
-
caps: TargetKindCapsSchema
|
|
44473
|
+
scheduler: SchedulerOutcomeSchema.optional()
|
|
44301
44474
|
});
|
|
44302
44475
|
/**
|
|
44303
|
-
*
|
|
44304
|
-
*
|
|
44305
|
-
* round-trip a stored secret to the UI.
|
|
44476
|
+
* What the hub's `runs` ledger holds for one owner (`automation:<blockId>` or
|
|
44477
|
+
* `action:<actionId>`): the cooldown stamp and the trace ring.
|
|
44306
44478
|
*/
|
|
44307
|
-
var
|
|
44308
|
-
|
|
44309
|
-
|
|
44310
|
-
|
|
44311
|
-
addonId: string(),
|
|
44312
|
-
enabled: boolean(),
|
|
44313
|
-
config: record(string(), unknown())
|
|
44479
|
+
var AutomationStateDocSchema = object({
|
|
44480
|
+
version: literal(1),
|
|
44481
|
+
lastRunStartedAt: number().nullable(),
|
|
44482
|
+
traces: array(AutomationRunTraceSchema)
|
|
44314
44483
|
});
|
|
44315
|
-
/**
|
|
44316
|
-
|
|
44317
|
-
|
|
44318
|
-
|
|
44319
|
-
|
|
44484
|
+
/**
|
|
44485
|
+
* Actions — named, runnable things an operator (or an automation) can start,
|
|
44486
|
+
* declared as LIST ENTRIES, never as devices.
|
|
44487
|
+
*
|
|
44488
|
+
* An entry is either **internal** (a short list of cap/wait steps kept in the
|
|
44489
|
+
* hub's `actions` record kind) or declared by an addon through the
|
|
44490
|
+
* `action-source` collection (a Home Assistant script, a scene …). The one
|
|
44491
|
+
* surface the UI and automations talk to is the `actions` cap; it keeps no
|
|
44492
|
+
* catalog of its own (D3) — every `list` asks the providers live.
|
|
44493
|
+
*
|
|
44494
|
+
* This file is the data half: the entry schema, the variables an entry may
|
|
44495
|
+
* declare, and the pure resolution of the values a run was given. It holds no
|
|
44496
|
+
* runtime.
|
|
44497
|
+
*/
|
|
44498
|
+
/** What a variable's value is. `select` takes one of `options`. */
|
|
44499
|
+
var ActionVariableTypeSchema = _enum([
|
|
44500
|
+
"string",
|
|
44501
|
+
"number",
|
|
44502
|
+
"boolean",
|
|
44503
|
+
"select"
|
|
44504
|
+
]);
|
|
44505
|
+
var ACTION_VARIABLE_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
44506
|
+
var ActionVariableValueSchema = union([
|
|
44507
|
+
string(),
|
|
44508
|
+
number(),
|
|
44509
|
+
boolean()
|
|
44510
|
+
]);
|
|
44511
|
+
/**
|
|
44512
|
+
* One declared variable. Steps reference it as `{ $var: 'name' }` (the whole
|
|
44513
|
+
* value) or `{{vars.name}}` (inside a string) in their args.
|
|
44514
|
+
*/
|
|
44515
|
+
var ActionVariableSchema = object({
|
|
44516
|
+
name: string().regex(ACTION_VARIABLE_NAME_RE),
|
|
44517
|
+
label: string().min(1).max(120).optional(),
|
|
44518
|
+
type: ActionVariableTypeSchema,
|
|
44519
|
+
required: boolean().optional(),
|
|
44520
|
+
default: ActionVariableValueSchema.optional(),
|
|
44521
|
+
/** The allowed values of a `select`. */
|
|
44522
|
+
options: array(string().min(1)).min(1).optional()
|
|
44523
|
+
}).superRefine((v, ctx) => {
|
|
44524
|
+
if (v.type === "select" && v.options === void 0) ctx.addIssue({
|
|
44525
|
+
code: "custom",
|
|
44526
|
+
message: "a select variable needs options",
|
|
44527
|
+
path: ["options"]
|
|
44528
|
+
});
|
|
44529
|
+
if (v.default !== void 0 && variableValueError(v, v.default) !== null) ctx.addIssue({
|
|
44530
|
+
code: "custom",
|
|
44531
|
+
message: variableValueError(v, v.default) ?? "invalid default",
|
|
44532
|
+
path: ["default"]
|
|
44533
|
+
});
|
|
44320
44534
|
});
|
|
44321
|
-
/**
|
|
44322
|
-
|
|
44323
|
-
|
|
44324
|
-
|
|
44325
|
-
|
|
44326
|
-
|
|
44327
|
-
|
|
44328
|
-
|
|
44535
|
+
/** Why `value` is not a legal value for the variable, or null when it is. */
|
|
44536
|
+
function variableValueError(variable, value) {
|
|
44537
|
+
switch (variable.type) {
|
|
44538
|
+
case "string": return typeof value === "string" ? null : `variable "${variable.name}" must be a string`;
|
|
44539
|
+
case "number": return typeof value === "number" && Number.isFinite(value) ? null : `variable "${variable.name}" must be a number`;
|
|
44540
|
+
case "boolean": return typeof value === "boolean" ? null : `variable "${variable.name}" must be true or false`;
|
|
44541
|
+
case "select": return typeof value === "string" && (variable.options ?? []).includes(value) ? null : `variable "${variable.name}" must be one of ${(variable.options ?? []).join(", ")}`;
|
|
44542
|
+
}
|
|
44543
|
+
}
|
|
44544
|
+
var ActionSourceKindSchema = _enum(["internal", "addon"]);
|
|
44545
|
+
function isInternalActionId(actionId) {
|
|
44546
|
+
return actionId.startsWith("internal:") && actionId.length > 9;
|
|
44547
|
+
}
|
|
44548
|
+
/** The addon behind a `<addonId>:<localId>` id, or null for anything else (internal included). */
|
|
44549
|
+
function addonIdOfActionId(actionId) {
|
|
44550
|
+
if (isInternalActionId(actionId)) return null;
|
|
44551
|
+
const at = actionId.indexOf(":");
|
|
44552
|
+
return at > 0 && at < actionId.length - 1 ? actionId.slice(0, at) : null;
|
|
44553
|
+
}
|
|
44554
|
+
var ActionStatusSchema = object({
|
|
44555
|
+
isRunning: boolean(),
|
|
44556
|
+
/** Ms epoch the latest run STARTED; null when it never ran. */
|
|
44557
|
+
lastRunAt: number().nullable(),
|
|
44558
|
+
/** The latest run's failure; null on success or when it never ran. */
|
|
44559
|
+
lastError: string().nullable()
|
|
44329
44560
|
});
|
|
44330
|
-
var
|
|
44331
|
-
|
|
44332
|
-
|
|
44333
|
-
|
|
44561
|
+
var ActionEntrySchema = object({
|
|
44562
|
+
/** `internal:<uuid>` or `<addonId>:<localId>`. */
|
|
44563
|
+
id: string().min(3),
|
|
44564
|
+
name: string().min(1).max(120),
|
|
44565
|
+
/** The addon that declared it; `core-blocks` for an internal one. */
|
|
44566
|
+
addonId: string().min(1),
|
|
44567
|
+
source: ActionSourceKindSchema,
|
|
44568
|
+
/** An addon-declared entry is edited where it was declared. */
|
|
44569
|
+
readOnly: boolean(),
|
|
44570
|
+
/** Internal only: cap and wait steps. No action-in-action, so no cycles. */
|
|
44571
|
+
steps: array(ActionStepSchema).min(1).max(50).optional(),
|
|
44572
|
+
variables: array(ActionVariableSchema).max(20).optional(),
|
|
44573
|
+
status: ActionStatusSchema
|
|
44574
|
+
}).superRefine((entry, ctx) => {
|
|
44575
|
+
if (entry.source === "internal") {
|
|
44576
|
+
if (!isInternalActionId(entry.id)) ctx.addIssue({
|
|
44577
|
+
code: "custom",
|
|
44578
|
+
message: "an internal action id is internal:<uuid>",
|
|
44579
|
+
path: ["id"]
|
|
44580
|
+
});
|
|
44581
|
+
return;
|
|
44582
|
+
}
|
|
44583
|
+
if (entry.steps !== void 0) ctx.addIssue({
|
|
44584
|
+
code: "custom",
|
|
44585
|
+
message: "only an internal action carries steps",
|
|
44586
|
+
path: ["steps"]
|
|
44587
|
+
});
|
|
44588
|
+
if (!entry.readOnly) ctx.addIssue({
|
|
44589
|
+
code: "custom",
|
|
44590
|
+
message: "an addon action is read-only here",
|
|
44591
|
+
path: ["readOnly"]
|
|
44592
|
+
});
|
|
44593
|
+
if (addonIdOfActionId(entry.id) === null) ctx.addIssue({
|
|
44594
|
+
code: "custom",
|
|
44595
|
+
message: "an addon action id is <addonId>:<localId>",
|
|
44596
|
+
path: ["id"]
|
|
44597
|
+
});
|
|
44334
44598
|
});
|
|
44335
|
-
/**
|
|
44336
|
-
var
|
|
44599
|
+
/** What an operator writes for an internal action. */
|
|
44600
|
+
var ActionInputSchema = object({
|
|
44601
|
+
name: string().min(1).max(120),
|
|
44602
|
+
steps: array(ActionStepSchema).min(1).max(50),
|
|
44603
|
+
variables: array(ActionVariableSchema).max(20).optional()
|
|
44604
|
+
});
|
|
44605
|
+
/** Who started a run. Absent = the operator pressed it. */
|
|
44606
|
+
var ActionRunOriginSchema = object({
|
|
44607
|
+
/** The automation block whose step started it. */
|
|
44608
|
+
blockId: string().min(1).optional() });
|
|
44337
44609
|
/**
|
|
44338
|
-
*
|
|
44339
|
-
* `
|
|
44610
|
+
* `started` = the caller did not ask to wait. `timed-out` = the run reached the
|
|
44611
|
+
* ceiling (`ACTION_RUN_MAX_MS`) and was stopped; it is never a `ran`.
|
|
44340
44612
|
*/
|
|
44341
|
-
var
|
|
44342
|
-
|
|
44343
|
-
|
|
44344
|
-
|
|
44345
|
-
|
|
44346
|
-
|
|
44613
|
+
var ActionRunOutcomeSchema = union([
|
|
44614
|
+
AutomationRunOutcomeSchema,
|
|
44615
|
+
literal("started"),
|
|
44616
|
+
literal("timed-out")
|
|
44617
|
+
]);
|
|
44618
|
+
var ActionRunResultSchema = object({
|
|
44619
|
+
runId: string().min(1),
|
|
44620
|
+
outcome: ActionRunOutcomeSchema,
|
|
44621
|
+
/** Why it did not run, or what failed. */
|
|
44622
|
+
message: string().optional()
|
|
44347
44623
|
});
|
|
44348
|
-
|
|
44349
|
-
|
|
44350
|
-
|
|
44351
|
-
|
|
44352
|
-
|
|
44353
|
-
|
|
44354
|
-
|
|
44355
|
-
|
|
44356
|
-
|
|
44357
|
-
|
|
44358
|
-
|
|
44359
|
-
|
|
44360
|
-
/**
|
|
44361
|
-
|
|
44362
|
-
|
|
44363
|
-
|
|
44364
|
-
|
|
44365
|
-
|
|
44366
|
-
|
|
44367
|
-
|
|
44368
|
-
|
|
44369
|
-
|
|
44370
|
-
|
|
44371
|
-
|
|
44372
|
-
|
|
44373
|
-
|
|
44374
|
-
}), TestResultSchema, {
|
|
44375
|
-
kind: "mutation",
|
|
44376
|
-
auth: "admin"
|
|
44377
|
-
}), method(object({
|
|
44378
|
-
target: TargetSchema,
|
|
44379
|
-
/**
|
|
44380
|
-
* Duplicate flow: create a NEW target id while copying secrets from an
|
|
44381
|
-
* existing row. The UI never holds the stored token; blank / redacted
|
|
44382
|
-
* password fields are restored from this source (D634 still applies if
|
|
44383
|
-
* destinations diverge without a re-typed secret).
|
|
44384
|
-
*/
|
|
44385
|
-
cloneSecretsFrom: string().optional()
|
|
44386
|
-
}), TargetSchema, {
|
|
44387
|
-
kind: "mutation",
|
|
44388
|
-
auth: "admin"
|
|
44389
|
-
}), method(object({ targetId: string() }), _void(), {
|
|
44390
|
-
kind: "mutation",
|
|
44391
|
-
auth: "admin"
|
|
44392
|
-
}), method(object({
|
|
44393
|
-
targetId: string(),
|
|
44394
|
-
enabled: boolean()
|
|
44395
|
-
}), _void(), {
|
|
44396
|
-
kind: "mutation",
|
|
44397
|
-
auth: "admin"
|
|
44624
|
+
_enum([
|
|
44625
|
+
"not-found",
|
|
44626
|
+
"read-only",
|
|
44627
|
+
"invalid-variables",
|
|
44628
|
+
"invalid-steps",
|
|
44629
|
+
"not-linked",
|
|
44630
|
+
"busy"
|
|
44631
|
+
]);
|
|
44632
|
+
object({
|
|
44633
|
+
actionId: string(),
|
|
44634
|
+
runId: string(),
|
|
44635
|
+
isRunning: boolean(),
|
|
44636
|
+
/** Set when the run ended. */
|
|
44637
|
+
outcome: AutomationRunOutcomeSchema.optional(),
|
|
44638
|
+
lastRunAt: number().nullable(),
|
|
44639
|
+
lastError: string().nullable()
|
|
44640
|
+
});
|
|
44641
|
+
/** A bare number accepted as a base unit — the save succeeded, say so. */
|
|
44642
|
+
var UnitWarningSchema = object({
|
|
44643
|
+
/** Where in the saved record, e.g. `conditions.children.0` or `steps.2.args.grams`. */
|
|
44644
|
+
path: string(),
|
|
44645
|
+
deviceId: number().int().optional(),
|
|
44646
|
+
field: string(),
|
|
44647
|
+
value: number(),
|
|
44648
|
+
assumedUnit: string(),
|
|
44649
|
+
message: string()
|
|
44398
44650
|
});
|
|
44399
44651
|
_enum([
|
|
44400
44652
|
"automation",
|
|
@@ -44463,6 +44715,8 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
44463
44715
|
kind: "mutation",
|
|
44464
44716
|
auth: "admin"
|
|
44465
44717
|
});
|
|
44718
|
+
/** `timeoutMs` of `actions.run`: a waited call outlives any legal run. */
|
|
44719
|
+
var ACTION_RUN_TIMEOUT_MS = 363e4;
|
|
44466
44720
|
/**
|
|
44467
44721
|
* actions — the ONE surface for runnable actions, for the UI and for
|
|
44468
44722
|
* automations. Provided by the core-blocks builtin on the hub.
|
|
@@ -44481,6 +44735,12 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
44481
44735
|
* An admin, and an in-process caller (an automation block), may run any action.
|
|
44482
44736
|
* Every refusal is typed (`[not-linked] …`) and logged.
|
|
44483
44737
|
*
|
|
44738
|
+
* **A run lasts at most `ACTION_RUN_MAX_MS` (60 min).** The provider stops a
|
|
44739
|
+
* run that reaches it and answers `timed-out` (never `ran`); an action whose
|
|
44740
|
+
* `wait` steps alone add up to more is refused at create/update
|
|
44741
|
+
* (`[invalid-steps]`). `run` declares a `timeoutMs` above that ceiling, so a
|
|
44742
|
+
* waited call (an automation step) is never cut by the 60 s transport default.
|
|
44743
|
+
*
|
|
44484
44744
|
* A second `run` of an action that is already running is REFUSED — traced and
|
|
44485
44745
|
* logged — never queued.
|
|
44486
44746
|
*/
|
|
@@ -44507,7 +44767,8 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
|
|
|
44507
44767
|
role: "viewer",
|
|
44508
44768
|
auth: "protected",
|
|
44509
44769
|
kind: "mutation",
|
|
44510
|
-
caller: "required"
|
|
44770
|
+
caller: "required",
|
|
44771
|
+
timeoutMs: ACTION_RUN_TIMEOUT_MS
|
|
44511
44772
|
}), method(ActionIdInput, _void(), {
|
|
44512
44773
|
kind: "mutation",
|
|
44513
44774
|
auth: "admin"
|
|
@@ -48293,37 +48554,6 @@ method(object({
|
|
|
48293
48554
|
kind: "mutation",
|
|
48294
48555
|
auth: "admin"
|
|
48295
48556
|
}), method(object({ blockIds: array(string()) }), object({ states: array(CompositionBlockStateSchema) }), { auth: "admin" });
|
|
48296
|
-
var ConnectionTestOutcomeSchema = discriminatedUnion("outcome", [
|
|
48297
|
-
object({
|
|
48298
|
-
outcome: literal("validated"),
|
|
48299
|
-
/** Round-trip of the sign-in, when the provider measured it. */
|
|
48300
|
-
latencyMs: number().nonnegative().optional(),
|
|
48301
|
-
/** Optional human detail worth showing next to the tick
|
|
48302
|
-
* ("3 devices visible on this account"). */
|
|
48303
|
-
detail: string().optional()
|
|
48304
|
-
}).strict(),
|
|
48305
|
-
object({
|
|
48306
|
-
outcome: literal("rejected"),
|
|
48307
|
-
error: string()
|
|
48308
|
-
}).strict(),
|
|
48309
|
-
object({
|
|
48310
|
-
outcome: literal("inconclusive"),
|
|
48311
|
-
error: string()
|
|
48312
|
-
}).strict()
|
|
48313
|
-
]);
|
|
48314
|
-
var ConnectionTestInputSchema = object({
|
|
48315
|
-
/** Candidate integration settings, exactly as the create form collected them. */
|
|
48316
|
-
settings: record(string(), unknown()) });
|
|
48317
|
-
/**
|
|
48318
|
-
* What the provider's test actually DOES, so the UI can say it in words before
|
|
48319
|
-
* the operator presses the button ("Signs in to the Dreo cloud"). Purely
|
|
48320
|
-
* descriptive — it never changes routing.
|
|
48321
|
-
*/
|
|
48322
|
-
var ConnectionTestDescriptorSchema = object({ label: string() });
|
|
48323
|
-
method(ConnectionTestInputSchema, ConnectionTestOutcomeSchema, {
|
|
48324
|
-
kind: "mutation",
|
|
48325
|
-
auth: "admin"
|
|
48326
|
-
}), method(_void(), ConnectionTestDescriptorSchema, { auth: "admin" });
|
|
48327
48557
|
object({
|
|
48328
48558
|
/** True when the upstream system considers the entity connected. */
|
|
48329
48559
|
connected: boolean(),
|
|
@@ -48581,6 +48811,9 @@ var MediaPlayerStatusSchema = object({
|
|
|
48581
48811
|
/** Repeat mode. Null when no repeat surface.
|
|
48582
48812
|
* Pair with `DeviceFeature.MediaPlayerRepeat`. */
|
|
48583
48813
|
repeat: MediaPlayerRepeatSchema.nullable(),
|
|
48814
|
+
/** Ms epoch when `position` was read from the device. Null when the driver
|
|
48815
|
+
* does not say; a UI that advances the position while playing counts from it. */
|
|
48816
|
+
positionUpdatedAt: number().nullable().default(null),
|
|
48584
48817
|
/** Ms epoch when the slice was last updated. */
|
|
48585
48818
|
lastChangedAt: number()
|
|
48586
48819
|
});
|
|
@@ -49160,7 +49393,9 @@ var ThresholdTransformDraftSchema = object({
|
|
|
49160
49393
|
comparison: _enum(["gte", "lte"]),
|
|
49161
49394
|
threshold: number(),
|
|
49162
49395
|
startDwellMs: number().nonnegative(),
|
|
49163
|
-
stopDwellMs: number().nonnegative()
|
|
49396
|
+
stopDwellMs: number().nonnegative(),
|
|
49397
|
+
/** Samples a start needs; absent = the compiler's default for the source (2 for running power, else 1). */
|
|
49398
|
+
minSamples: number().int().min(1).optional()
|
|
49164
49399
|
});
|
|
49165
49400
|
var CustomizeTransformDraftSchema = discriminatedUnion("kind", [
|
|
49166
49401
|
IdentityTransformDraftSchema,
|
|
@@ -54113,6 +54348,7 @@ var IntegrationWithStateSchema = object({
|
|
|
54113
54348
|
id: string(),
|
|
54114
54349
|
addonId: string(),
|
|
54115
54350
|
name: string(),
|
|
54351
|
+
/** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
|
|
54116
54352
|
enabled: boolean(),
|
|
54117
54353
|
info: record(string(), unknown()).readonly(),
|
|
54118
54354
|
/** The discovery candidate this integration was set up from (D984). */
|
|
@@ -54125,6 +54361,7 @@ var IntegrationLiteSchema = object({
|
|
|
54125
54361
|
id: string(),
|
|
54126
54362
|
addonId: string(),
|
|
54127
54363
|
name: string(),
|
|
54364
|
+
/** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
|
|
54128
54365
|
enabled: boolean(),
|
|
54129
54366
|
info: record(string(), unknown()).readonly(),
|
|
54130
54367
|
/** The discovery candidate this integration was set up from (D984). */
|
|
@@ -54170,10 +54407,9 @@ var AvailableIntegrationTypeSchema = object({
|
|
|
54170
54407
|
* locations" checkbox. Provider-declared in the addon manifest. */
|
|
54171
54408
|
supportsLocationImport: boolean(),
|
|
54172
54409
|
/**
|
|
54173
|
-
* True when this integration
|
|
54174
|
-
*
|
|
54175
|
-
*
|
|
54176
|
-
* rather than offering a button that always answers the same nonsense.
|
|
54410
|
+
* True when this integration's instances declare a Test (`integration-instances.describe().canTest`,
|
|
54411
|
+
* D1016). An integration that cannot be tested must say so up front rather than offering a
|
|
54412
|
+
* button that always answers the same nonsense.
|
|
54177
54413
|
*/
|
|
54178
54414
|
canTest: boolean(),
|
|
54179
54415
|
existingInstances: array(object({
|
|
@@ -54224,15 +54460,21 @@ var TestConnectionResultSchema = object({
|
|
|
54224
54460
|
var CreateIntegrationInputSchema = object({
|
|
54225
54461
|
addonId: string(),
|
|
54226
54462
|
name: string(),
|
|
54227
|
-
enabled: boolean().optional(),
|
|
54228
54463
|
info: record(string(), unknown()).optional(),
|
|
54229
54464
|
/** `stableId` of the discovery candidate the form was seeded from (D984). */
|
|
54230
54465
|
originStableId: string().optional(),
|
|
54231
|
-
settings: record(string(), unknown()).optional()
|
|
54466
|
+
settings: record(string(), unknown()).optional(),
|
|
54467
|
+
/** The instance kind being created, for a provider with several; omitted = its only testable kind. */
|
|
54468
|
+
kind: string().min(1).optional()
|
|
54232
54469
|
});
|
|
54233
54470
|
var UpdateIntegrationInputSchema = object({
|
|
54234
54471
|
id: string(),
|
|
54235
54472
|
name: string().optional(),
|
|
54473
|
+
/**
|
|
54474
|
+
* Accepted for a FIXED builtin only (`info.fixed`: alarm panel, camera grid, core blocks,
|
|
54475
|
+
* terminal), which keeps no instance record: the registry flag is its one store. Any other
|
|
54476
|
+
* integration is switched through `integration-instances.setInstanceEnabled`.
|
|
54477
|
+
*/
|
|
54236
54478
|
enabled: boolean().optional(),
|
|
54237
54479
|
info: record(string(), unknown()).optional()
|
|
54238
54480
|
});
|
|
@@ -54249,13 +54491,7 @@ method(_void(), array(IntegrationWithStateSchema)), method(object({ id: string()
|
|
|
54249
54491
|
}), method(object({ id: string() }), DeleteIntegrationResultSchema, {
|
|
54250
54492
|
kind: "mutation",
|
|
54251
54493
|
auth: "admin"
|
|
54252
|
-
}), method(_void(), array(AvailableIntegrationTypeSchema), { auth: "admin" })
|
|
54253
|
-
addonId: string(),
|
|
54254
|
-
settings: record(string(), unknown())
|
|
54255
|
-
}), TestConnectionResultSchema, {
|
|
54256
|
-
kind: "mutation",
|
|
54257
|
-
auth: "admin"
|
|
54258
|
-
});
|
|
54494
|
+
}), method(_void(), array(AvailableIntegrationTypeSchema), { auth: "admin" });
|
|
54259
54495
|
/**
|
|
54260
54496
|
* `integration-instances` - the connection of an addon that holds ONE or SEVERAL
|
|
54261
54497
|
* (an account, a relay, a destination) as typed records (D985, D986). The addon's
|
|
@@ -54280,7 +54516,7 @@ var IntegrationInstanceIdSchema = string().min(1);
|
|
|
54280
54516
|
var IntegrationInstanceModeSchema = _enum(["single", "multiple"]);
|
|
54281
54517
|
/**
|
|
54282
54518
|
* What the addon's instances ARE for the Integrations page (planning#416). `devices`: each
|
|
54283
|
-
* instance is an integration that brings devices (
|
|
54519
|
+
* instance is an integration that brings devices (its record body owns the on/off switch);
|
|
54284
54520
|
* `services`: a connection configured from the addon's own function page, never listed on
|
|
54285
54521
|
* Integrations.
|
|
54286
54522
|
* It is the same vocabulary as the manifest's `integrationRole`, which stays as an override.
|
|
@@ -54397,8 +54633,8 @@ var IntegrationInstanceSchema = object({
|
|
|
54397
54633
|
configured: boolean(),
|
|
54398
54634
|
/**
|
|
54399
54635
|
* The instance's own on/off switch (D996), derived from the record body (`enabled !== false`,
|
|
54400
|
-
* so a row written before the field existed is on).
|
|
54401
|
-
*
|
|
54636
|
+
* so a row written before the field existed is on). The same for every role, `devices` included:
|
|
54637
|
+
* the body is the one store, `setInstanceEnabled` the one writer (epic #440, step 3).
|
|
54402
54638
|
*/
|
|
54403
54639
|
enabled: boolean().optional(),
|
|
54404
54640
|
/** The kind of this instance (one of `describe().kinds[].id`), when the provider has kinds. */
|
|
@@ -54448,7 +54684,8 @@ var integrationInstancesCapability = {
|
|
|
54448
54684
|
auth: "admin"
|
|
54449
54685
|
}),
|
|
54450
54686
|
/**
|
|
54451
|
-
* Switch ONE instance on or off
|
|
54687
|
+
* Switch ONE instance on or off, for every role; a missing record is created from the addon's
|
|
54688
|
+
* initial body. A row control, not a form field: `updateInstance.values` is the
|
|
54452
54689
|
* form patch (D62, D996). An off instance keeps its record and secrets and does no work.
|
|
54453
54690
|
*/
|
|
54454
54691
|
setInstanceEnabled: method(object({
|
|
@@ -57259,6 +57496,8 @@ var MigrationIntegrationSchema = object({
|
|
|
57259
57496
|
addonId: string(),
|
|
57260
57497
|
name: string(),
|
|
57261
57498
|
info: Rows,
|
|
57499
|
+
/** The registry's stored switch: read by the one-switch migration, nothing else. */
|
|
57500
|
+
enabled: boolean().optional(),
|
|
57262
57501
|
originStableId: string().optional()
|
|
57263
57502
|
});
|
|
57264
57503
|
var MigrationDeviceSchema = object({
|
|
@@ -62495,13 +62734,6 @@ var AddBrokerInputSchema = object({
|
|
|
62495
62734
|
});
|
|
62496
62735
|
var AddBrokerResultSchema = object({ id: string() });
|
|
62497
62736
|
var IdInputSchema = object({ id: string() });
|
|
62498
|
-
var TestResultSchema$1 = discriminatedUnion("ok", [object({
|
|
62499
|
-
ok: literal(true),
|
|
62500
|
-
latencyMs: number()
|
|
62501
|
-
}), object({
|
|
62502
|
-
ok: literal(false),
|
|
62503
|
-
error: string()
|
|
62504
|
-
})]);
|
|
62505
62737
|
var StartEmbeddedInputSchema = object({
|
|
62506
62738
|
port: number().int().min(1).max(65535).default(1883),
|
|
62507
62739
|
/** Allow anonymous connect (no username/password). Default: false. */
|
|
@@ -62524,9 +62756,6 @@ method(_void(), array(BrokerInfoSchema)), method(IdInputSchema, BrokerConnection
|
|
|
62524
62756
|
}), method(IdInputSchema, _void(), {
|
|
62525
62757
|
kind: "mutation",
|
|
62526
62758
|
auth: "admin"
|
|
62527
|
-
}), method(IdInputSchema, TestResultSchema$1, {
|
|
62528
|
-
kind: "mutation",
|
|
62529
|
-
auth: "admin"
|
|
62530
62759
|
}), method(StartEmbeddedInputSchema, StartEmbeddedResultSchema, {
|
|
62531
62760
|
kind: "mutation",
|
|
62532
62761
|
auth: "admin"
|
|
@@ -66777,14 +67006,6 @@ object({
|
|
|
66777
67006
|
empty: boolean().nullable(),
|
|
66778
67007
|
/** True while the pump is running. Null while unknown. */
|
|
66779
67008
|
pumpRunning: boolean().nullable(),
|
|
66780
|
-
/** Water drunk in the last drink, in litres. */
|
|
66781
|
-
lastDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
66782
|
-
/** Water drunk in the current hour, in litres. */
|
|
66783
|
-
currentHourDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
66784
|
-
/** Water drunk over the last 24 hours (rolling), in litres. */
|
|
66785
|
-
last24hDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
66786
|
-
/** Water drunk since local midnight, in litres. Null when the fountain has no such sensor. */
|
|
66787
|
-
todayDrink: number().min(0).nullable().meta(readingMeta("volume")),
|
|
66788
67009
|
/** Decoded fault message. Null means healthy; a non-null string is an active fault. */
|
|
66789
67010
|
error: string().nullable(),
|
|
66790
67011
|
/** Ms epoch when the slice was last refreshed. */
|
|
@@ -66797,9 +67018,6 @@ DeviceType.PetFountain, method(object({
|
|
|
66797
67018
|
}), _void(), {
|
|
66798
67019
|
kind: "mutation",
|
|
66799
67020
|
auth: "protected"
|
|
66800
|
-
}), method(object({ deviceId: DeviceIdSchema$1 }), _void(), {
|
|
66801
|
-
kind: "mutation",
|
|
66802
|
-
auth: "protected"
|
|
66803
67021
|
});
|
|
66804
67022
|
/**
|
|
66805
67023
|
* The wire shapes of the Auto tune plan and apply (D745), used by the
|
|
@@ -74162,7 +74380,7 @@ var TrainingProviderTypeSchema = object({
|
|
|
74162
74380
|
label: string(),
|
|
74163
74381
|
/** Path under the addon package (e.g. `assets/training-modal/icon.svg`). */
|
|
74164
74382
|
iconAsset: string(),
|
|
74165
|
-
/** Owning `training-provider` addon
|
|
74383
|
+
/** Owning `training-provider` addon. */
|
|
74166
74384
|
addonId: string(),
|
|
74167
74385
|
/**
|
|
74168
74386
|
* Fields for one entry of this type (credentials + defaults). Absent on a
|
|
@@ -74207,36 +74425,6 @@ var TrainingProviderDescriptorSchema = object({
|
|
|
74207
74425
|
*/
|
|
74208
74426
|
formValues: record(string(), unknown()).optional()
|
|
74209
74427
|
});
|
|
74210
|
-
/**
|
|
74211
|
-
* Patch one entry's name, credentials and defaults. Pin with owning `{ addonId }`.
|
|
74212
|
-
* An omitted or empty `tokenSecret` means KEEP the stored secret (D787).
|
|
74213
|
-
* `{ $secretClear: true }` clears it.
|
|
74214
|
-
*/
|
|
74215
|
-
var TrainingProviderUpdateEntryInputSchema = object({
|
|
74216
|
-
entryId: string().min(1),
|
|
74217
|
-
name: string().min(1),
|
|
74218
|
-
tokenId: string().optional(),
|
|
74219
|
-
tokenSecret: union([string(), object({ $secretClear: literal(true) })]).optional(),
|
|
74220
|
-
environment: string().optional(),
|
|
74221
|
-
gpuType: string().optional(),
|
|
74222
|
-
region: string().optional(),
|
|
74223
|
-
costCapUsd: number().nonnegative().optional(),
|
|
74224
|
-
maxRuntimeSec: number().int().positive().optional(),
|
|
74225
|
-
failedDatasetGraceHours: number().nonnegative().optional()
|
|
74226
|
-
});
|
|
74227
|
-
var TrainingCredentialCheckSchema = object({
|
|
74228
|
-
ok: boolean(),
|
|
74229
|
-
/** Workspace / account name, when the provider says. */
|
|
74230
|
-
account: string().optional(),
|
|
74231
|
-
reason: _enum([
|
|
74232
|
-
"missing",
|
|
74233
|
-
"invalid",
|
|
74234
|
-
"forbidden",
|
|
74235
|
-
"network",
|
|
74236
|
-
"quota"
|
|
74237
|
-
]).optional(),
|
|
74238
|
-
detail: string().optional()
|
|
74239
|
-
});
|
|
74240
74428
|
var ProviderJobStateSchema = _enum([
|
|
74241
74429
|
"pending",
|
|
74242
74430
|
"starting",
|
|
@@ -74284,22 +74472,6 @@ var TrainingLogLineSchema = object({
|
|
|
74284
74472
|
text: string()
|
|
74285
74473
|
});
|
|
74286
74474
|
method(object({}), array(TrainingProviderDescriptorSchema).readonly(), { auth: "admin" }), method(object({}), array(TrainingProviderTypeSchema).readonly(), { auth: "admin" }), method(object({}), array(TrainingProviderEntrySchema).readonly(), { auth: "admin" }), method(object({
|
|
74287
|
-
typeId: string().min(1),
|
|
74288
|
-
name: string().min(1)
|
|
74289
|
-
}), object({ entryId: string() }), {
|
|
74290
|
-
kind: "mutation",
|
|
74291
|
-
auth: "admin"
|
|
74292
|
-
}), method(object({ entryId: string().min(1) }), object({ ok: literal(true) }), {
|
|
74293
|
-
kind: "mutation",
|
|
74294
|
-
auth: "admin"
|
|
74295
|
-
}), method(TrainingProviderUpdateEntryInputSchema, object({ ok: literal(true) }), {
|
|
74296
|
-
kind: "mutation",
|
|
74297
|
-
auth: "admin"
|
|
74298
|
-
}), method(object({ entryId: string().min(1) }), TrainingCredentialCheckSchema, {
|
|
74299
|
-
kind: "mutation",
|
|
74300
|
-
auth: "admin",
|
|
74301
|
-
timeoutMs: 3e4
|
|
74302
|
-
}), method(object({
|
|
74303
74475
|
entryId: string().min(1),
|
|
74304
74476
|
gpuType: string(),
|
|
74305
74477
|
region: string(),
|
|
@@ -77685,20 +77857,6 @@ Object.freeze({
|
|
|
77685
77857
|
access: "view",
|
|
77686
77858
|
role: "admin"
|
|
77687
77859
|
},
|
|
77688
|
-
"connectionTest.describeTest": {
|
|
77689
|
-
capName: "connection-test",
|
|
77690
|
-
capScope: "system",
|
|
77691
|
-
addonId: null,
|
|
77692
|
-
access: "view",
|
|
77693
|
-
role: "admin"
|
|
77694
|
-
},
|
|
77695
|
-
"connectionTest.testSettings": {
|
|
77696
|
-
capName: "connection-test",
|
|
77697
|
-
capScope: "system",
|
|
77698
|
-
addonId: null,
|
|
77699
|
-
access: "create",
|
|
77700
|
-
role: "admin"
|
|
77701
|
-
},
|
|
77702
77860
|
"connectivity.getStatus": {
|
|
77703
77861
|
capName: "connectivity",
|
|
77704
77862
|
capScope: "device",
|
|
@@ -80065,13 +80223,6 @@ Object.freeze({
|
|
|
80065
80223
|
access: "view",
|
|
80066
80224
|
role: "admin"
|
|
80067
80225
|
},
|
|
80068
|
-
"integrations.testConnection": {
|
|
80069
|
-
capName: "integrations",
|
|
80070
|
-
capScope: "system",
|
|
80071
|
-
addonId: null,
|
|
80072
|
-
access: "create",
|
|
80073
|
-
role: "admin"
|
|
80074
|
-
},
|
|
80075
80226
|
"integrations.update": {
|
|
80076
80227
|
capName: "integrations",
|
|
80077
80228
|
capScope: "system",
|
|
@@ -81304,13 +81455,6 @@ Object.freeze({
|
|
|
81304
81455
|
access: "create",
|
|
81305
81456
|
role: "admin"
|
|
81306
81457
|
},
|
|
81307
|
-
"mqttBroker.testConnection": {
|
|
81308
|
-
capName: "mqtt-broker",
|
|
81309
|
-
capScope: "system",
|
|
81310
|
-
addonId: null,
|
|
81311
|
-
access: "create",
|
|
81312
|
-
role: "admin"
|
|
81313
|
-
},
|
|
81314
81458
|
"nativeObjectDetection.getOptions": {
|
|
81315
81459
|
capName: "native-object-detection",
|
|
81316
81460
|
capScope: "device",
|
|
@@ -82186,13 +82330,6 @@ Object.freeze({
|
|
|
82186
82330
|
access: "view",
|
|
82187
82331
|
role: "viewer"
|
|
82188
82332
|
},
|
|
82189
|
-
"petFountain.resetDailyConsumption": {
|
|
82190
|
-
capName: "pet-fountain",
|
|
82191
|
-
capScope: "device",
|
|
82192
|
-
addonId: null,
|
|
82193
|
-
access: "delete",
|
|
82194
|
-
role: "viewer"
|
|
82195
|
-
},
|
|
82196
82333
|
"petFountain.setPump": {
|
|
82197
82334
|
capName: "pet-fountain",
|
|
82198
82335
|
capScope: "device",
|
|
@@ -86148,20 +86285,6 @@ Object.freeze({
|
|
|
86148
86285
|
access: "create",
|
|
86149
86286
|
role: "admin"
|
|
86150
86287
|
},
|
|
86151
|
-
"trainingProvider.createEntry": {
|
|
86152
|
-
capName: "training-provider",
|
|
86153
|
-
capScope: "system",
|
|
86154
|
-
addonId: null,
|
|
86155
|
-
access: "create",
|
|
86156
|
-
role: "admin"
|
|
86157
|
-
},
|
|
86158
|
-
"trainingProvider.deleteEntry": {
|
|
86159
|
-
capName: "training-provider",
|
|
86160
|
-
capScope: "system",
|
|
86161
|
-
addonId: null,
|
|
86162
|
-
access: "delete",
|
|
86163
|
-
role: "admin"
|
|
86164
|
-
},
|
|
86165
86288
|
"trainingProvider.describe": {
|
|
86166
86289
|
capName: "training-provider",
|
|
86167
86290
|
capScope: "system",
|
|
@@ -86232,13 +86355,6 @@ Object.freeze({
|
|
|
86232
86355
|
access: "create",
|
|
86233
86356
|
role: "admin"
|
|
86234
86357
|
},
|
|
86235
|
-
"trainingProvider.updateEntry": {
|
|
86236
|
-
capName: "training-provider",
|
|
86237
|
-
capScope: "system",
|
|
86238
|
-
addonId: null,
|
|
86239
|
-
access: "create",
|
|
86240
|
-
role: "admin"
|
|
86241
|
-
},
|
|
86242
86358
|
"trainingProvider.uploadDataset": {
|
|
86243
86359
|
capName: "training-provider",
|
|
86244
86360
|
capScope: "system",
|
|
@@ -86246,13 +86362,6 @@ Object.freeze({
|
|
|
86246
86362
|
access: "create",
|
|
86247
86363
|
role: "admin"
|
|
86248
86364
|
},
|
|
86249
|
-
"trainingProvider.validateCredentials": {
|
|
86250
|
-
capName: "training-provider",
|
|
86251
|
-
capScope: "system",
|
|
86252
|
-
addonId: null,
|
|
86253
|
-
access: "create",
|
|
86254
|
-
role: "admin"
|
|
86255
|
-
},
|
|
86256
86365
|
"turnProvider.getTurnServers": {
|
|
86257
86366
|
capName: "turn-provider",
|
|
86258
86367
|
capScope: "system",
|
|
@@ -88589,11 +88698,6 @@ Object.freeze({
|
|
|
88589
88698
|
form: "single",
|
|
88590
88699
|
optional: false
|
|
88591
88700
|
}],
|
|
88592
|
-
"petFountain.resetDailyConsumption": [{
|
|
88593
|
-
name: "deviceId",
|
|
88594
|
-
form: "single",
|
|
88595
|
-
optional: false
|
|
88596
|
-
}],
|
|
88597
88701
|
"petFountain.setPump": [{
|
|
88598
88702
|
name: "deviceId",
|
|
88599
88703
|
form: "single",
|
|
@@ -91381,11 +91485,6 @@ function linkFieldDescriptor(key, target, labels) {
|
|
|
91381
91485
|
...target.kind !== void 0 ? { kind: target.kind } : {}
|
|
91382
91486
|
};
|
|
91383
91487
|
}
|
|
91384
|
-
/**
|
|
91385
|
-
* Declare the record kind of a service that links to other instances. The body is
|
|
91386
|
-
* `{ name, ...links, ...fields }`; the links are recorded in the kind (read back by
|
|
91387
|
-
* {@link linksOfKind}) so the hub can index who points at what.
|
|
91388
|
-
*/
|
|
91389
91488
|
function declareLinkKind(spec) {
|
|
91390
91489
|
const linkShape = {};
|
|
91391
91490
|
for (const [field, target] of Object.entries(spec.links)) linkShape[field] = linkField(target);
|
|
@@ -91442,7 +91541,6 @@ function buildLinkedInstances(records, spec) {
|
|
|
91442
91541
|
});
|
|
91443
91542
|
return instances;
|
|
91444
91543
|
}
|
|
91445
|
-
entryBody({ brokerId: string() });
|
|
91446
91544
|
/**
|
|
91447
91545
|
* The calendars an account imports leave the account (D1013). An account record used to carry a
|
|
91448
91546
|
* `calendarIds` array; each calendar is now a record of its own that LINKS to the account
|
|
@@ -91545,22 +91643,12 @@ var GoogleBrokerEntrySchema = object({
|
|
|
91545
91643
|
fromAddress: string().default(""),
|
|
91546
91644
|
fromName: string().default("")
|
|
91547
91645
|
});
|
|
91548
|
-
|
|
91549
|
-
|
|
91550
|
-
|
|
91551
|
-
|
|
91552
|
-
|
|
91553
|
-
clientSecret: string().optional().meta({ secret: true }),
|
|
91554
|
-
/** @deprecated Pre-broker singleton — cleared after migrateLegacyToBrokers. */
|
|
91555
|
-
calendarFilter: string().optional(),
|
|
91556
|
-
/** @deprecated Pre-broker singleton — cleared after migrateLegacyToBrokers. */
|
|
91557
|
-
fromAddress: string().optional(),
|
|
91558
|
-
/** @deprecated Pre-broker singleton — cleared after migrateLegacyToBrokers. */
|
|
91559
|
-
fromName: string().optional()
|
|
91560
|
-
});
|
|
91646
|
+
/**
|
|
91647
|
+
* The addon keeps no addon-level settings: every account is a `brokers` record and its tokens
|
|
91648
|
+
* live in the durable `oauthAccounts` state.
|
|
91649
|
+
*/
|
|
91650
|
+
var GoogleServicesConfigSchema = object({});
|
|
91561
91651
|
var DEFAULT_GOOGLE_CONFIG = GoogleServicesConfigSchema.parse({});
|
|
91562
|
-
/** Flat pre-broker config (singleton). Parsed only for one-shot migration. */
|
|
91563
|
-
var LegacyGoogleFlatConfigSchema = GoogleServicesConfigSchema;
|
|
91564
91652
|
var DEFAULT_OAUTH_STATE = {
|
|
91565
91653
|
refreshToken: "",
|
|
91566
91654
|
accessToken: "",
|
|
@@ -91630,52 +91718,6 @@ function brokerEntryToSettings(entry) {
|
|
|
91630
91718
|
fromName: entry.fromName
|
|
91631
91719
|
};
|
|
91632
91720
|
}
|
|
91633
|
-
/**
|
|
91634
|
-
* One-shot: flat singleton config + legacy `oauth` state → `google_001`.
|
|
91635
|
-
* Idempotent when `brokers` already present.
|
|
91636
|
-
*/
|
|
91637
|
-
function migrateLegacyToBrokers(rawConfig, legacyOauth) {
|
|
91638
|
-
const loose = LegacyGoogleFlatConfigSchema.safeParse(rawConfig);
|
|
91639
|
-
const flat = loose.success ? loose.data : {};
|
|
91640
|
-
const existingBrokers = flat.brokers ?? [];
|
|
91641
|
-
if (existingBrokers.length > 0) return {
|
|
91642
|
-
brokers: existingBrokers.map((b) => GoogleBrokerEntrySchema.parse(b)),
|
|
91643
|
-
oauthAccounts: [],
|
|
91644
|
-
didMigrate: false
|
|
91645
|
-
};
|
|
91646
|
-
const hasClient = (flat.clientId ?? "").length > 0 || (flat.clientSecret ?? "").length > 0;
|
|
91647
|
-
const hasOauth = legacyOauth !== null && legacyOauth.refreshToken.length > 0;
|
|
91648
|
-
if (!hasClient && !hasOauth) return {
|
|
91649
|
-
brokers: [],
|
|
91650
|
-
oauthAccounts: [],
|
|
91651
|
-
didMigrate: false
|
|
91652
|
-
};
|
|
91653
|
-
const id = "google_001";
|
|
91654
|
-
const email = legacyOauth?.accountEmail?.trim() ?? "";
|
|
91655
|
-
const name = email.length > 0 ? email : "Google account";
|
|
91656
|
-
const entry = GoogleBrokerEntrySchema.parse({
|
|
91657
|
-
id,
|
|
91658
|
-
name,
|
|
91659
|
-
clientId: flat.clientId ?? "",
|
|
91660
|
-
clientSecret: flat.clientSecret ?? "",
|
|
91661
|
-
calendarFilter: flat.calendarFilter ?? "",
|
|
91662
|
-
fromAddress: flat.fromAddress ?? "",
|
|
91663
|
-
fromName: flat.fromName ?? ""
|
|
91664
|
-
});
|
|
91665
|
-
const oauthAccounts = legacyOauth !== null && (legacyOauth.refreshToken.length > 0 || legacyOauth.accessToken.length > 0) ? [{
|
|
91666
|
-
id,
|
|
91667
|
-
refreshToken: legacyOauth.refreshToken,
|
|
91668
|
-
accessToken: legacyOauth.accessToken,
|
|
91669
|
-
accessExpiresAt: legacyOauth.accessExpiresAt,
|
|
91670
|
-
accountEmail: legacyOauth.accountEmail,
|
|
91671
|
-
needsReauth: false
|
|
91672
|
-
}] : [];
|
|
91673
|
-
return {
|
|
91674
|
-
brokers: [entry],
|
|
91675
|
-
oauthAccounts,
|
|
91676
|
-
didMigrate: true
|
|
91677
|
-
};
|
|
91678
|
-
}
|
|
91679
91721
|
/** Local calendar id stamped as `brokerId:googleCalendarId`. */
|
|
91680
91722
|
function stampCalendarId(brokerId, googleCalendarId) {
|
|
91681
91723
|
return `${brokerId}:${googleCalendarId}`;
|
|
@@ -91791,9 +91833,6 @@ var GoogleBrokerRegistry = class {
|
|
|
91791
91833
|
connectedSize() {
|
|
91792
91834
|
return this.entries.filter((e) => this.isConnected(e.id)).length;
|
|
91793
91835
|
}
|
|
91794
|
-
toConfig() {
|
|
91795
|
-
return { brokers: [...this.entries] };
|
|
91796
|
-
}
|
|
91797
91836
|
seedCounterFromEntries(entries) {
|
|
91798
91837
|
let maxSeen = 0;
|
|
91799
91838
|
for (const e of entries) {
|
|
@@ -92704,6 +92743,245 @@ async function planDropSharedCalendarIds(ports) {
|
|
|
92704
92743
|
} })
|
|
92705
92744
|
}] };
|
|
92706
92745
|
}
|
|
92746
|
+
//#endregion
|
|
92747
|
+
//#region src/migrations/drop-config-brokers-and-legacy-oauth.ts
|
|
92748
|
+
/**
|
|
92749
|
+
* The addon-level `brokers` setting and the singleton `oauth` state are gone (planning#440 step 5):
|
|
92750
|
+
* every account is a `brokers` record and its tokens live in `oauthAccounts`. This deletes the two
|
|
92751
|
+
* leftover keys, each only when nothing in them is still the only copy:
|
|
92752
|
+
*
|
|
92753
|
+
* - `brokers` goes when the `brokers` kind holds records, or when the setting itself is empty. A
|
|
92754
|
+
* non-empty setting with an empty kind was never copied: it stays.
|
|
92755
|
+
* - `oauth` goes when it carries no token (the empty state the old boot migration left behind), or
|
|
92756
|
+
* when `oauthAccounts` already holds accounts. A token with no account to hold it stays.
|
|
92757
|
+
*
|
|
92758
|
+
* Each edit carries a precondition read, so a row that changed since the plan was made is not
|
|
92759
|
+
* deleted; a second run finds nothing to plan.
|
|
92760
|
+
*/
|
|
92761
|
+
var BROKERS_KEY = "brokers";
|
|
92762
|
+
var LEGACY_OAUTH_KEY = "oauth";
|
|
92763
|
+
/** The flat singleton client the boot migration used to clear. */
|
|
92764
|
+
var FLAT_KEYS = [
|
|
92765
|
+
"clientId",
|
|
92766
|
+
"clientSecret",
|
|
92767
|
+
"calendarFilter",
|
|
92768
|
+
"fromAddress",
|
|
92769
|
+
"fromName"
|
|
92770
|
+
];
|
|
92771
|
+
var OAUTH_ACCOUNTS_KEY = "oauthAccounts";
|
|
92772
|
+
function present$1(answer, key) {
|
|
92773
|
+
if (answer.kind === "unreadable") throw new Error(`google-services: the stored '${key}' cannot be read (${answer.reason})`);
|
|
92774
|
+
return answer.kind === "absent" ? null : { value: answer.value };
|
|
92775
|
+
}
|
|
92776
|
+
function field(value, key) {
|
|
92777
|
+
return typeof value === "object" && value !== null ? Reflect.get(value, key) : void 0;
|
|
92778
|
+
}
|
|
92779
|
+
/** A token field that holds nothing: absent or the empty string. A secret marker is something. */
|
|
92780
|
+
function isBlank(value) {
|
|
92781
|
+
return value === void 0 || value === null || value === "";
|
|
92782
|
+
}
|
|
92783
|
+
function stringList(value) {
|
|
92784
|
+
if (!Array.isArray(value)) return null;
|
|
92785
|
+
const out = [];
|
|
92786
|
+
for (const item of value) {
|
|
92787
|
+
if (typeof item !== "string") return null;
|
|
92788
|
+
out.push(item);
|
|
92789
|
+
}
|
|
92790
|
+
return out;
|
|
92791
|
+
}
|
|
92792
|
+
function holdsAccounts(value) {
|
|
92793
|
+
const accounts = field(value, "accounts");
|
|
92794
|
+
return Array.isArray(accounts) && accounts.length > 0;
|
|
92795
|
+
}
|
|
92796
|
+
async function planDropConfigBrokersAndLegacyOauth(ports) {
|
|
92797
|
+
const rows = {};
|
|
92798
|
+
const keys = [];
|
|
92799
|
+
const take = (key, value) => {
|
|
92800
|
+
const id = `${GOOGLE_ADDON_ID}.${key}`;
|
|
92801
|
+
keys.push(id);
|
|
92802
|
+
rows[id] = {
|
|
92803
|
+
addonId: GOOGLE_ADDON_ID,
|
|
92804
|
+
key,
|
|
92805
|
+
value
|
|
92806
|
+
};
|
|
92807
|
+
};
|
|
92808
|
+
const brokers = present$1(await ports.readStored(BROKERS_KEY), BROKERS_KEY);
|
|
92809
|
+
if (brokers !== null) {
|
|
92810
|
+
if (!(Array.isArray(brokers.value) && brokers.value.length > 0) || (await ports.listBrokers()).length > 0) take(BROKERS_KEY, brokers.value);
|
|
92811
|
+
}
|
|
92812
|
+
for (const key of FLAT_KEYS) {
|
|
92813
|
+
const flat = present$1(await ports.readStored(key), key);
|
|
92814
|
+
if (flat !== null && (await ports.listBrokers()).length > 0) take(key, flat.value);
|
|
92815
|
+
}
|
|
92816
|
+
const shared = present$1(await ports.readStored(SHARED_CALENDAR_IDS_KEY), SHARED_CALENDAR_IDS_KEY);
|
|
92817
|
+
if (shared !== null) {
|
|
92818
|
+
const sharedIds = stringList(shared.value);
|
|
92819
|
+
if (sharedIds === null) throw new Error(`google-services: the stored '${SHARED_CALENDAR_IDS_KEY}' is not a list of ids — nothing dropped`);
|
|
92820
|
+
else {
|
|
92821
|
+
const brokers = await ports.listBrokers();
|
|
92822
|
+
const same = (ids) => ids === void 0 || ids.length === sharedIds.length && ids.every((id) => sharedIds.includes(id));
|
|
92823
|
+
if (brokers.length > 0 && brokers.every((b) => same(b.calendarIds))) take(SHARED_CALENDAR_IDS_KEY, shared.value);
|
|
92824
|
+
}
|
|
92825
|
+
}
|
|
92826
|
+
const oauth = present$1(await ports.readStored(LEGACY_OAUTH_KEY), LEGACY_OAUTH_KEY);
|
|
92827
|
+
if (oauth !== null) {
|
|
92828
|
+
const tokenless = isBlank(field(oauth.value, "refreshToken")) && isBlank(field(oauth.value, "accessToken"));
|
|
92829
|
+
const accounts = present$1(await ports.readStored(OAUTH_ACCOUNTS_KEY), OAUTH_ACCOUNTS_KEY);
|
|
92830
|
+
if (tokenless || accounts !== null && holdsAccounts(accounts.value)) take(LEGACY_OAUTH_KEY, oauth.value);
|
|
92831
|
+
}
|
|
92832
|
+
if (keys.length === 0) return { edits: [] };
|
|
92833
|
+
return { edits: [{
|
|
92834
|
+
op: "deleteKeys",
|
|
92835
|
+
scope: ADDON_SETTINGS_TABLE,
|
|
92836
|
+
keys,
|
|
92837
|
+
precondition: preconditionOf(rows)
|
|
92838
|
+
}] };
|
|
92839
|
+
}
|
|
92840
|
+
//#endregion
|
|
92841
|
+
//#region src/migrations/legacy-brokers-to-records.ts
|
|
92842
|
+
/**
|
|
92843
|
+
* The accounts a pre-record install kept in the addon settings become `brokers` records and
|
|
92844
|
+
* `oauthAccounts` entries (planning#440 step 5). Three legacy shapes feed it, the ones the boot
|
|
92845
|
+
* migration used to read:
|
|
92846
|
+
*
|
|
92847
|
+
* - the `brokers` setting (a list of entries);
|
|
92848
|
+
* - the flat singleton (`clientId`, `clientSecret`, `calendarFilter`, `fromAddress`, `fromName`),
|
|
92849
|
+
* which becomes `google_001`;
|
|
92850
|
+
* - the singleton `oauth` state, whose token follows its account (`google_001`, or the first
|
|
92851
|
+
* broker when brokers already existed).
|
|
92852
|
+
*
|
|
92853
|
+
* Reads come RESOLVED (the settings view answers values, not keychain markers); a value the
|
|
92854
|
+
* keychain could not serve is not a string and REFUSES the step, so nothing is written from a
|
|
92855
|
+
* guess. Each record is read back with its secret before the step reports done, and an account
|
|
92856
|
+
* that already has a record is never overwritten. The shared `calendarIds` set goes onto every
|
|
92857
|
+
* broker this step creates (the calendar migrations before it found no broker to give it to),
|
|
92858
|
+
* 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
|
|
92859
|
+
* migration deletes them only after this one landed.
|
|
92860
|
+
*/
|
|
92861
|
+
var LEGACY_BROKER_ID = "google_001";
|
|
92862
|
+
var LEGACY_FLAT_KEYS = [
|
|
92863
|
+
"clientId",
|
|
92864
|
+
"clientSecret",
|
|
92865
|
+
"calendarFilter",
|
|
92866
|
+
"fromAddress",
|
|
92867
|
+
"fromName"
|
|
92868
|
+
];
|
|
92869
|
+
function present(answer, key) {
|
|
92870
|
+
if (answer.kind === "unreadable") throw new Error(`google-services: the stored '${key}' cannot be read (${answer.reason})`);
|
|
92871
|
+
return answer.kind === "absent" ? void 0 : answer.value;
|
|
92872
|
+
}
|
|
92873
|
+
function text(value, what) {
|
|
92874
|
+
if (value === void 0 || value === null) return "";
|
|
92875
|
+
if (typeof value === "string") return value;
|
|
92876
|
+
throw new Error(`google-services: ${what} is not a plain value (is the keychain available?)`);
|
|
92877
|
+
}
|
|
92878
|
+
function legacyOauthOf(value) {
|
|
92879
|
+
if (typeof value !== "object" || value === null) return null;
|
|
92880
|
+
const refreshToken = text(Reflect.get(value, "refreshToken"), "the legacy oauth refreshToken");
|
|
92881
|
+
if (refreshToken.length === 0) return null;
|
|
92882
|
+
const expires = Reflect.get(value, "accessExpiresAt");
|
|
92883
|
+
return {
|
|
92884
|
+
refreshToken,
|
|
92885
|
+
accessToken: text(Reflect.get(value, "accessToken"), "the legacy oauth accessToken"),
|
|
92886
|
+
accessExpiresAt: typeof expires === "number" ? expires : 0,
|
|
92887
|
+
accountEmail: text(Reflect.get(value, "accountEmail"), "the legacy oauth accountEmail").trim()
|
|
92888
|
+
};
|
|
92889
|
+
}
|
|
92890
|
+
async function flatFields(ports) {
|
|
92891
|
+
const out = {};
|
|
92892
|
+
for (const key of LEGACY_FLAT_KEYS) out[key] = text(present(await ports.readStored(key), key), `the stored '${key}'`);
|
|
92893
|
+
return out;
|
|
92894
|
+
}
|
|
92895
|
+
async function legacyEntries(ports, oauth) {
|
|
92896
|
+
const listed = present(await ports.readStored("brokers"), "brokers");
|
|
92897
|
+
if (Array.isArray(listed) && listed.length > 0) return listed.map((item) => {
|
|
92898
|
+
const parsed = GoogleBrokerEntrySchema.safeParse(item);
|
|
92899
|
+
if (!parsed.success) throw new Error(`google-services: a stored broker is invalid — ${parsed.error.message}`);
|
|
92900
|
+
return parsed.data;
|
|
92901
|
+
});
|
|
92902
|
+
const flat = await flatFields(ports);
|
|
92903
|
+
if (!flat["clientId"] && !flat["clientSecret"] && oauth === null) return [];
|
|
92904
|
+
const email = oauth?.accountEmail ?? "";
|
|
92905
|
+
return [GoogleBrokerEntrySchema.parse({
|
|
92906
|
+
id: LEGACY_BROKER_ID,
|
|
92907
|
+
name: email.length > 0 ? email : "Google account",
|
|
92908
|
+
...flat
|
|
92909
|
+
})];
|
|
92910
|
+
}
|
|
92911
|
+
async function sharedCalendarIds(ports) {
|
|
92912
|
+
const value = present(await ports.readStored("calendarIds"), "calendarIds");
|
|
92913
|
+
if (value === void 0) return null;
|
|
92914
|
+
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");
|
|
92915
|
+
return value;
|
|
92916
|
+
}
|
|
92917
|
+
/** The keys a legacy install left that no record holds yet, for the init warning. */
|
|
92918
|
+
async function leftoverLegacyKeys(ports) {
|
|
92919
|
+
const left = [];
|
|
92920
|
+
const listed = await ports.readStored("brokers");
|
|
92921
|
+
if (listed.kind === "present" && Array.isArray(listed.value) && listed.value.length > 0) left.push("brokers");
|
|
92922
|
+
for (const key of ["clientId", "clientSecret"]) {
|
|
92923
|
+
const answer = await ports.readStored(key);
|
|
92924
|
+
if (answer.kind === "present" && answer.value !== "" && answer.value !== null) left.push(key);
|
|
92925
|
+
}
|
|
92926
|
+
const oauth = await ports.readStored("oauth");
|
|
92927
|
+
if (oauth.kind === "present") {
|
|
92928
|
+
const token = typeof oauth.value === "object" && oauth.value !== null ? Reflect.get(oauth.value, "refreshToken") : void 0;
|
|
92929
|
+
if (token !== void 0 && token !== "" && token !== null) left.push("oauth");
|
|
92930
|
+
}
|
|
92931
|
+
return left;
|
|
92932
|
+
}
|
|
92933
|
+
async function copyLegacyBrokersToRecords(ports) {
|
|
92934
|
+
const oauth = legacyOauthOf(present(await ports.readStored("oauth"), "oauth"));
|
|
92935
|
+
const entries = await legacyEntries(ports, oauth);
|
|
92936
|
+
if (entries.length === 0) return {
|
|
92937
|
+
outcome: "already-done",
|
|
92938
|
+
summary: { reason: "no-legacy-data" }
|
|
92939
|
+
};
|
|
92940
|
+
const have = new Set((await ports.listBrokers()).map((b) => b.id));
|
|
92941
|
+
const shared = await sharedCalendarIds(ports);
|
|
92942
|
+
let created = 0;
|
|
92943
|
+
let selections = 0;
|
|
92944
|
+
for (const entry of entries) {
|
|
92945
|
+
if (have.has(entry.id)) continue;
|
|
92946
|
+
await ports.putBroker(entry);
|
|
92947
|
+
const back = await ports.readBroker(entry.id);
|
|
92948
|
+
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`);
|
|
92949
|
+
created += 1;
|
|
92950
|
+
if (shared !== null && await ports.setBrokerCalendarIds(entry.id, shared)) selections += 1;
|
|
92951
|
+
}
|
|
92952
|
+
if (selections > 0) await moveCalendarIdsToRecords(ports, { calendarIdOf: (accountId, stamped) => {
|
|
92953
|
+
const parsed = parseStampedCalendarId(stamped);
|
|
92954
|
+
return parsed?.brokerId === accountId ? parsed.googleCalendarId : null;
|
|
92955
|
+
} });
|
|
92956
|
+
let account = 0;
|
|
92957
|
+
const primary = entries[0];
|
|
92958
|
+
if (oauth !== null && primary !== void 0) {
|
|
92959
|
+
if ((await ports.listOauthAccountIds()).length === 0) {
|
|
92960
|
+
await ports.putOauthAccount({
|
|
92961
|
+
id: primary.id,
|
|
92962
|
+
refreshToken: oauth.refreshToken,
|
|
92963
|
+
accessToken: oauth.accessToken,
|
|
92964
|
+
accessExpiresAt: oauth.accessExpiresAt,
|
|
92965
|
+
accountEmail: oauth.accountEmail,
|
|
92966
|
+
needsReauth: false
|
|
92967
|
+
});
|
|
92968
|
+
const back = await ports.readOauthAccount(primary.id);
|
|
92969
|
+
if (back === null || back.refreshToken !== oauth.refreshToken) throw new Error(`google-services: the oauth account of '${primary.id}' did not read back`);
|
|
92970
|
+
account = 1;
|
|
92971
|
+
}
|
|
92972
|
+
}
|
|
92973
|
+
return {
|
|
92974
|
+
outcome: created + account === 0 ? "already-done" : "done",
|
|
92975
|
+
summary: {
|
|
92976
|
+
brokers: created,
|
|
92977
|
+
oauthAccounts: account
|
|
92978
|
+
}
|
|
92979
|
+
};
|
|
92980
|
+
}
|
|
92981
|
+
//#endregion
|
|
92982
|
+
//#region src/migrations/index.ts
|
|
92983
|
+
var CALENDAR_IDS_TO_RECORDS_ID = "google-services/2026-11-07-calendar-ids-to-calendar-records";
|
|
92984
|
+
var LEGACY_BROKERS_TO_RECORDS_ID = "google-services/2026-11-06-legacy-brokers-to-records";
|
|
92707
92985
|
/** The `google-services` catalogue (D987): offered to the engine when the addon initialises. */
|
|
92708
92986
|
var ADDON_MIGRATIONS = [
|
|
92709
92987
|
{
|
|
@@ -92740,7 +93018,7 @@ var ADDON_MIGRATIONS = [
|
|
|
92740
93018
|
},
|
|
92741
93019
|
{
|
|
92742
93020
|
meta: {
|
|
92743
|
-
id:
|
|
93021
|
+
id: CALENDAR_IDS_TO_RECORDS_ID,
|
|
92744
93022
|
owner: "google-services",
|
|
92745
93023
|
level: "addon-state",
|
|
92746
93024
|
seq: 3,
|
|
@@ -92756,6 +93034,38 @@ var ADDON_MIGRATIONS = [
|
|
|
92756
93034
|
const parsed = parseStampedCalendarId(entry);
|
|
92757
93035
|
return parsed?.brokerId === accountId ? parsed.googleCalendarId : null;
|
|
92758
93036
|
} })
|
|
93037
|
+
},
|
|
93038
|
+
{
|
|
93039
|
+
meta: {
|
|
93040
|
+
id: LEGACY_BROKERS_TO_RECORDS_ID,
|
|
93041
|
+
owner: "google-services",
|
|
93042
|
+
level: "addon-state",
|
|
93043
|
+
seq: 4,
|
|
93044
|
+
dependsOn: [CALENDAR_IDS_TO_RECORDS_ID],
|
|
93045
|
+
store: "settings",
|
|
93046
|
+
scope: "cluster",
|
|
93047
|
+
onFailure: "tolerate",
|
|
93048
|
+
bodyKind: "procedure",
|
|
93049
|
+
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",
|
|
93050
|
+
fixtureMark: "the client secret of a flat singleton, read back from its record"
|
|
93051
|
+
},
|
|
93052
|
+
procedure: copyLegacyBrokersToRecords
|
|
93053
|
+
},
|
|
93054
|
+
{
|
|
93055
|
+
meta: {
|
|
93056
|
+
id: "google-services/2026-11-06-drop-config-brokers-and-legacy-oauth",
|
|
93057
|
+
owner: "google-services",
|
|
93058
|
+
level: "addon-state",
|
|
93059
|
+
seq: 5,
|
|
93060
|
+
dependsOn: [LEGACY_BROKERS_TO_RECORDS_ID],
|
|
93061
|
+
store: "settings",
|
|
93062
|
+
scope: "cluster",
|
|
93063
|
+
onFailure: "tolerate",
|
|
93064
|
+
bodyKind: "plan",
|
|
93065
|
+
description: "Delete the addon-level brokers setting once the brokers records exist, and the singleton oauth state once it holds no token",
|
|
93066
|
+
fixtureMark: "the brokers setting kept when its records are missing"
|
|
93067
|
+
},
|
|
93068
|
+
plan: planDropConfigBrokersAndLegacyOauth
|
|
92759
93069
|
}
|
|
92760
93070
|
];
|
|
92761
93071
|
//#endregion
|
|
@@ -92841,6 +93151,22 @@ var GoogleBrokerStore = class GoogleBrokerStore {
|
|
|
92841
93151
|
}
|
|
92842
93152
|
return out;
|
|
92843
93153
|
}
|
|
93154
|
+
async putOne(entry) {
|
|
93155
|
+
const { id, name, clientId, clientSecret, calendarFilter, fromAddress, fromName } = entry;
|
|
93156
|
+
const parsed = googleBrokersEntryKind.schema.safeParse({
|
|
93157
|
+
name,
|
|
93158
|
+
clientId,
|
|
93159
|
+
clientSecret,
|
|
93160
|
+
calendarFilter,
|
|
93161
|
+
fromAddress,
|
|
93162
|
+
fromName
|
|
93163
|
+
});
|
|
93164
|
+
if (!parsed.success) throw new Error(`invalid Google broker '${id}': ${parsed.error.message}`);
|
|
93165
|
+
await this.kind.put({
|
|
93166
|
+
id,
|
|
93167
|
+
data: parsed.data
|
|
93168
|
+
});
|
|
93169
|
+
}
|
|
92844
93170
|
async replaceAll(entries) {
|
|
92845
93171
|
const page = await this.kind.query({ limit: 1e3 });
|
|
92846
93172
|
const nextIds = new Set(entries.map((e) => e.id));
|
|
@@ -92882,19 +93208,8 @@ var GoogleCallbackError = class extends Error {
|
|
|
92882
93208
|
var CALLBACK_PATH = "/oauth/callback";
|
|
92883
93209
|
var START_PATH = "/oauth/start";
|
|
92884
93210
|
var DISCONNECT_PATH = "/oauth/disconnect";
|
|
92885
|
-
var LegacyOauthStateSchema = object({
|
|
92886
|
-
refreshToken: string().default("").meta({ secret: true }),
|
|
92887
|
-
accessToken: string().default("").meta({ secret: true }),
|
|
92888
|
-
accessExpiresAt: number().default(0),
|
|
92889
|
-
accountEmail: string().default("")
|
|
92890
|
-
});
|
|
92891
93211
|
var GoogleServicesAddon = class extends BaseAddon {
|
|
92892
|
-
secretStatePaths = [
|
|
92893
|
-
"oauthAccounts.accounts[id].refreshToken",
|
|
92894
|
-
"oauthAccounts.accounts[id].accessToken",
|
|
92895
|
-
"oauth.refreshToken",
|
|
92896
|
-
"oauth.accessToken"
|
|
92897
|
-
];
|
|
93212
|
+
secretStatePaths = ["oauthAccounts.accounts[id].refreshToken", "oauthAccounts.accounts[id].accessToken"];
|
|
92898
93213
|
oauthAccountsHandle = null;
|
|
92899
93214
|
registry = new GoogleBrokerRegistry();
|
|
92900
93215
|
brokerStore = null;
|
|
@@ -92911,40 +93226,6 @@ var GoogleServicesAddon = class extends BaseAddon {
|
|
|
92911
93226
|
}
|
|
92912
93227
|
async onInitialize() {
|
|
92913
93228
|
this.oauthAccountsHandle = this.state("oauthAccounts", GoogleOauthAccountsStateSchema, { accounts: [] });
|
|
92914
|
-
let oauthAccounts = await this.oauthAccountsHandle.get();
|
|
92915
|
-
const legacyHandle = this.state("oauth", LegacyOauthStateSchema, { ...DEFAULT_OAUTH_STATE });
|
|
92916
|
-
const legacyOauth = await legacyHandle.get();
|
|
92917
|
-
const migrated = migrateLegacyToBrokers(this.config, legacyOauth);
|
|
92918
|
-
if (migrated.didMigrate) {
|
|
92919
|
-
await this.updateGlobalSettings({
|
|
92920
|
-
brokers: [...migrated.brokers],
|
|
92921
|
-
clientId: void 0,
|
|
92922
|
-
clientSecret: void 0,
|
|
92923
|
-
calendarFilter: void 0,
|
|
92924
|
-
fromAddress: void 0,
|
|
92925
|
-
fromName: void 0
|
|
92926
|
-
});
|
|
92927
|
-
if (migrated.oauthAccounts.length > 0) {
|
|
92928
|
-
oauthAccounts = { accounts: [...migrated.oauthAccounts] };
|
|
92929
|
-
await this.oauthAccountsHandle.set(oauthAccounts);
|
|
92930
|
-
}
|
|
92931
|
-
await legacyHandle.set({ ...DEFAULT_OAUTH_STATE });
|
|
92932
|
-
this.ctx.logger.info("google-services: migrated singleton OAuth to broker google_001", { meta: {
|
|
92933
|
-
brokerId: "google_001",
|
|
92934
|
-
accountEmail: legacyOauth.accountEmail || void 0
|
|
92935
|
-
} });
|
|
92936
|
-
} else if (oauthAccounts.accounts.length === 0 && legacyOauth.refreshToken.length > 0 && this.config.brokers.length > 0) {
|
|
92937
|
-
oauthAccounts = { accounts: [{
|
|
92938
|
-
id: this.config.brokers[0].id,
|
|
92939
|
-
refreshToken: legacyOauth.refreshToken,
|
|
92940
|
-
accessToken: legacyOauth.accessToken,
|
|
92941
|
-
accessExpiresAt: legacyOauth.accessExpiresAt,
|
|
92942
|
-
accountEmail: legacyOauth.accountEmail,
|
|
92943
|
-
needsReauth: false
|
|
92944
|
-
}] };
|
|
92945
|
-
await this.oauthAccountsHandle.set(oauthAccounts);
|
|
92946
|
-
await legacyHandle.set({ ...DEFAULT_OAUTH_STATE });
|
|
92947
|
-
}
|
|
92948
93229
|
const records = this.ctx.records;
|
|
92949
93230
|
if (records === void 0) throw new Error("google-services: ctx.records is required (hub-only addon)");
|
|
92950
93231
|
await records.declare({
|
|
@@ -92958,12 +93239,9 @@ var GoogleServicesAddon = class extends BaseAddon {
|
|
|
92958
93239
|
onChanged: () => this.refreshCalendarSelection()
|
|
92959
93240
|
});
|
|
92960
93241
|
this.activeBrokers = await this.loadPersistedBrokers();
|
|
92961
|
-
if ((await this.brokerStore.listResolved()).length === 0 && this.config.brokers.length > 0) {
|
|
92962
|
-
await this.brokerStore.replaceAll(this.config.brokers);
|
|
92963
|
-
this.activeBrokers = await this.loadPersistedBrokers();
|
|
92964
|
-
}
|
|
92965
93242
|
await this.migrateCalendarIds(records);
|
|
92966
93243
|
await this.refreshCalendarSelection();
|
|
93244
|
+
const oauthAccounts = await this.oauthAccountsHandle.get();
|
|
92967
93245
|
this.registry.seedFrom(this.activeBrokers, oauthAccounts.accounts);
|
|
92968
93246
|
await this.refreshPublicOrigin();
|
|
92969
93247
|
const calendarProvider = createGoogleCalendarSource({
|
|
@@ -93399,27 +93677,61 @@ var GoogleServicesAddon = class extends BaseAddon {
|
|
|
93399
93677
|
brokers,
|
|
93400
93678
|
calendars: records.kind(googleCalendarsEntryKind),
|
|
93401
93679
|
warn: (message) => this.ctx.logger.warn(message)
|
|
93402
|
-
})
|
|
93680
|
+
}),
|
|
93681
|
+
...this.legacyBrokerPorts()
|
|
93682
|
+
};
|
|
93683
|
+
const report = await this.runMigrations(defineAddonMigrations(ADDON_MIGRATIONS, ports));
|
|
93684
|
+
if (report.applied.length > 0) this.activeBrokers = await this.loadPersistedBrokers();
|
|
93685
|
+
if (this.activeBrokers.length === 0) {
|
|
93686
|
+
const left = await leftoverLegacyKeys(ports);
|
|
93687
|
+
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: {
|
|
93688
|
+
leftoverKeys: left,
|
|
93689
|
+
failed: report.failed
|
|
93690
|
+
} });
|
|
93691
|
+
}
|
|
93692
|
+
}
|
|
93693
|
+
/** The legacy-broker migration's writes: a broker record and an `oauthAccounts` entry, each read back. */
|
|
93694
|
+
legacyBrokerPorts() {
|
|
93695
|
+
return {
|
|
93696
|
+
putBroker: async (entry) => {
|
|
93697
|
+
const store = this.brokerStore;
|
|
93698
|
+
if (store === null) throw new Error("google-services: the brokers store is not ready");
|
|
93699
|
+
await store.putOne(entry);
|
|
93700
|
+
},
|
|
93701
|
+
readBroker: async (id) => {
|
|
93702
|
+
const store = this.brokerStore;
|
|
93703
|
+
if (store === null) throw new Error("google-services: the brokers store is not ready");
|
|
93704
|
+
const found = (await store.listResolved()).find((b) => b.id === id);
|
|
93705
|
+
return found === void 0 ? null : found;
|
|
93706
|
+
},
|
|
93707
|
+
listOauthAccountIds: async () => {
|
|
93708
|
+
const handle = this.oauthAccountsHandle;
|
|
93709
|
+
if (handle === null) return [];
|
|
93710
|
+
return (await handle.get()).accounts.map((a) => a.id);
|
|
93711
|
+
},
|
|
93712
|
+
putOauthAccount: async (account) => {
|
|
93713
|
+
const handle = this.oauthAccountsHandle;
|
|
93714
|
+
if (handle === null) throw new Error("google-services: oauthAccounts is not ready");
|
|
93715
|
+
const current = await handle.get();
|
|
93716
|
+
await handle.set({ accounts: [...current.accounts, account] });
|
|
93717
|
+
},
|
|
93718
|
+
readOauthAccount: async (id) => {
|
|
93719
|
+
const handle = this.oauthAccountsHandle;
|
|
93720
|
+
if (handle === null) return null;
|
|
93721
|
+
return (await handle.get()).accounts.find((a) => a.id === id) ?? null;
|
|
93722
|
+
}
|
|
93403
93723
|
};
|
|
93404
|
-
if ((await this.runMigrations(defineAddonMigrations(ADDON_MIGRATIONS, ports))).applied.length > 0) this.activeBrokers = await this.loadPersistedBrokers();
|
|
93405
93724
|
}
|
|
93406
93725
|
async loadPersistedBrokers() {
|
|
93407
93726
|
const store = this.brokerStore;
|
|
93408
|
-
|
|
93409
|
-
const fromRecords = await store.listResolved();
|
|
93410
|
-
if (fromRecords.length > 0) return fromRecords;
|
|
93411
|
-
}
|
|
93412
|
-
return this.config.brokers;
|
|
93727
|
+
return store === null ? [] : store.listResolved();
|
|
93413
93728
|
}
|
|
93414
93729
|
async persistBrokers() {
|
|
93415
93730
|
const entries = [...this.registry.listEntries()];
|
|
93416
93731
|
this.activeBrokers = entries;
|
|
93417
93732
|
const store = this.brokerStore;
|
|
93418
|
-
if (store
|
|
93419
|
-
|
|
93420
|
-
return;
|
|
93421
|
-
}
|
|
93422
|
-
await this.updateGlobalSettings({ brokers: entries });
|
|
93733
|
+
if (store === null) throw new Error("google-services: the brokers store is not ready");
|
|
93734
|
+
await store.replaceAll(entries);
|
|
93423
93735
|
}
|
|
93424
93736
|
async persistOauthAccounts() {
|
|
93425
93737
|
if (!this.oauthAccountsHandle) return;
|
|
@@ -93570,4 +93882,4 @@ function asSettingsCap(cap) {
|
|
|
93570
93882
|
if (cap === "calendar-source" || cap === "smtp-provider") return cap;
|
|
93571
93883
|
}
|
|
93572
93884
|
//#endregion
|
|
93573
|
-
export {
|
|
93885
|
+
export { GOOGLE_OAUTH_SCOPES as C, GoogleServicesAddon, GoogleServicesAddon as default, GOOGLE_GMAIL_SEND_SCOPE as S, OAUTH_START_PATH as T, GoogleBrokerRegistry as _, refreshAccessToken as a, DEFAULT_GOOGLE_CONFIG as b, selectGmailAccount as c, mapGoogleEvent as d, GOOGLE_CONSOLE_APIS_URL as f, redirectUriDisplay as g, introHtml as h, needsRefresh as i, createGoogleCalendarApi as l, connectHtml as m, buildAuthorizeUrl as n, buildRawMime as o, GOOGLE_CONSOLE_CREDENTIALS_URL as p, exchangeCode as r, createGmailSmtpProvider as s, applyTokenResponse as t, createGoogleCalendarSource as u, parseStampedCalendarId as v, GoogleServicesConfigSchema as w, GOOGLE_BROKER_KIND as x, stampCalendarId as y };
|