@camstack/addon-export-google 0.1.125 → 0.1.127
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/export-google.addon.js +1244 -367
- package/dist/export-google.addon.mjs +1244 -367
- package/package.json +5 -2
|
@@ -2,6 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
+
let node_crypto = require("node:crypto");
|
|
5
6
|
//#region src/google-home/cap-dispatch.ts
|
|
6
7
|
async function dispatchCapCall(api, call) {
|
|
7
8
|
switch (call.kind) {
|
|
@@ -6059,7 +6060,7 @@ var ZodIssueCode = {
|
|
|
6059
6060
|
var ZodFirstPartyTypeKind;
|
|
6060
6061
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
6061
6062
|
//#endregion
|
|
6062
|
-
//#region ../types/dist/sleep-
|
|
6063
|
+
//#region ../types/dist/sleep-9TIHFj1w.mjs
|
|
6063
6064
|
/**
|
|
6064
6065
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
6065
6066
|
* window to float samples (D455).
|
|
@@ -6207,9 +6208,16 @@ function isSecretMarker(value) {
|
|
|
6207
6208
|
const ref = value["$secret"];
|
|
6208
6209
|
return typeof ref === "string" && ref.length > 0;
|
|
6209
6210
|
}
|
|
6211
|
+
/** Anything carrying a `$secret` key — a stored marker or a UI view of one. */
|
|
6212
|
+
function isSecretMarkerLike(value) {
|
|
6213
|
+
return isRecord$7(value) && Object.prototype.hasOwnProperty.call(value, "$secret");
|
|
6214
|
+
}
|
|
6210
6215
|
function isSecretClear(value) {
|
|
6211
6216
|
return isRecord$7(value) && value["$secretClear"] === true;
|
|
6212
6217
|
}
|
|
6218
|
+
function isSecretFieldView(value) {
|
|
6219
|
+
return isRecord$7(value) && value["set"] === true && isSecretMarkerLike(value);
|
|
6220
|
+
}
|
|
6213
6221
|
/**
|
|
6214
6222
|
* The UI view of a stored secret field value: a marker becomes "set", inline
|
|
6215
6223
|
* plaintext becomes "set (inline)", nothing becomes `null`. A value never
|
|
@@ -6652,7 +6660,7 @@ var NOT_RUN = {
|
|
|
6652
6660
|
* throws: an unreachable or refusing engine is logged and reported `declared: false`,
|
|
6653
6661
|
* because the hub (and this addon's boot) must not hang on a migration.
|
|
6654
6662
|
*/
|
|
6655
|
-
async function runAddonMigrations(host, migrations, logger) {
|
|
6663
|
+
async function runAddonMigrations(host, migrations, logger, options = {}) {
|
|
6656
6664
|
const first = migrations[0];
|
|
6657
6665
|
if (first === void 0) return NOT_RUN;
|
|
6658
6666
|
const owner = first.meta.owner;
|
|
@@ -6681,7 +6689,9 @@ async function runAddonMigrations(host, migrations, logger) {
|
|
|
6681
6689
|
else if (status === "blocked") blocked.push(id);
|
|
6682
6690
|
else skipped.push(id);
|
|
6683
6691
|
};
|
|
6692
|
+
const selected = options.only === void 0 ? null : new Set(options.only);
|
|
6684
6693
|
for (const step of declaration.steps) {
|
|
6694
|
+
if (selected !== null && !selected.has(step.id)) continue;
|
|
6685
6695
|
const bound = byId.get(step.id);
|
|
6686
6696
|
if (bound === void 0 || step.action === "skip") {
|
|
6687
6697
|
skipped.push(step.id);
|
|
@@ -6859,11 +6869,36 @@ function projectStore(store, perNodeKeys, nodeId) {
|
|
|
6859
6869
|
}
|
|
6860
6870
|
return out;
|
|
6861
6871
|
}
|
|
6872
|
+
/**
|
|
6873
|
+
* The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
|
|
6874
|
+
*
|
|
6875
|
+
* A ref is DETERMINISTIC from where the value lives — the owner addon, the
|
|
6876
|
+
* scope (global, one node, one device, one integration, one row of a business
|
|
6877
|
+
* collection) and the field path inside that scope — so saving the same field
|
|
6878
|
+
* twice updates the same ref, and the ref itself says which settings blob
|
|
6879
|
+
* points at it. It is also the AAD of the value's ciphertext: a ciphertext
|
|
6880
|
+
* copied onto another ref does not decrypt.
|
|
6881
|
+
*
|
|
6882
|
+
* Array items are addressed by ITEM ID, never by index
|
|
6883
|
+
* (`providers[authentik].clientSecret`), so reordering a list keeps every ref.
|
|
6884
|
+
*
|
|
6885
|
+
* Pure and browser-safe: no node builtins, no I/O.
|
|
6886
|
+
*/
|
|
6887
|
+
/** The URI scheme of every keychain ref. */
|
|
6888
|
+
var SECRET_REF_SCHEME = "secret://";
|
|
6862
6889
|
var GLOBAL_SCOPE = { kind: "global" };
|
|
6863
6890
|
/** The scope every addon-wide (not per-node, not per-device) setting lives in. */
|
|
6864
6891
|
function globalSecretScope() {
|
|
6865
6892
|
return GLOBAL_SCOPE;
|
|
6866
6893
|
}
|
|
6894
|
+
/**
|
|
6895
|
+
* An addon id as a ref owner. A hub in-process builtin's context id is
|
|
6896
|
+
* `addon:<id>`; the owner of its secrets is `<id>`, exactly as for the same
|
|
6897
|
+
* addon running forked.
|
|
6898
|
+
*/
|
|
6899
|
+
function normalizeSecretOwner(addonId) {
|
|
6900
|
+
return addonId.startsWith("addon:") ? addonId.slice(6) : addonId;
|
|
6901
|
+
}
|
|
6867
6902
|
function encodeSegment(value) {
|
|
6868
6903
|
return encodeURIComponent(value);
|
|
6869
6904
|
}
|
|
@@ -6874,6 +6909,16 @@ function decodeSegment(value) {
|
|
|
6874
6909
|
return null;
|
|
6875
6910
|
}
|
|
6876
6911
|
}
|
|
6912
|
+
/** The scope as it appears inside a ref (`global`, `node/<id>`, …). */
|
|
6913
|
+
function formatSecretScope(scope) {
|
|
6914
|
+
switch (scope.kind) {
|
|
6915
|
+
case "global": return "global";
|
|
6916
|
+
case "node": return `node/${encodeSegment(scope.nodeId)}`;
|
|
6917
|
+
case "device": return `device/${scope.deviceId}`;
|
|
6918
|
+
case "integration": return `integration/${encodeSegment(scope.integrationId)}`;
|
|
6919
|
+
case "row": return `row/${encodeSegment(scope.collection)}/${encodeSegment(scope.rowId)}`;
|
|
6920
|
+
}
|
|
6921
|
+
}
|
|
6877
6922
|
/**
|
|
6878
6923
|
* The field path of a value inside an array item, addressed by the item's id:
|
|
6879
6924
|
* `arrayItemFieldPath('providers', 'authentik', 'clientSecret')` →
|
|
@@ -6882,6 +6927,13 @@ function decodeSegment(value) {
|
|
|
6882
6927
|
function arrayItemFieldPath(arrayKey, itemId, fieldKey) {
|
|
6883
6928
|
return `${arrayKey}[${encodeSegment(itemId)}].${fieldKey}`;
|
|
6884
6929
|
}
|
|
6930
|
+
/** Build a ref. Throws on an empty owner or field path — both are bugs. */
|
|
6931
|
+
function buildSecretRef(parts) {
|
|
6932
|
+
const owner = normalizeSecretOwner(parts.owner);
|
|
6933
|
+
if (owner.length === 0) throw new Error("buildSecretRef: owner is empty");
|
|
6934
|
+
if (parts.fieldPath.length === 0) throw new Error("buildSecretRef: fieldPath is empty");
|
|
6935
|
+
return `${SECRET_REF_SCHEME}${encodeSegment(owner)}/${formatSecretScope(parts.scope)}/${parts.fieldPath}`;
|
|
6936
|
+
}
|
|
6885
6937
|
function parseScope(segments) {
|
|
6886
6938
|
switch (segments[0]) {
|
|
6887
6939
|
case "global": return {
|
|
@@ -7799,14 +7851,18 @@ var BaseAddon = class {
|
|
|
7799
7851
|
* nothing; the boot continues. A migration that FAILED (or was blocked by one)
|
|
7800
7852
|
* and declares `onFailure: 'block-owner'` makes this throw, so the addon does not
|
|
7801
7853
|
* serve data whose shape it cannot trust; `tolerate` migrations never do.
|
|
7854
|
+
*
|
|
7855
|
+
* ALWAYS pass the whole catalogue; a phase that must run only some of it passes
|
|
7856
|
+
* `{ only: [ids] }` — never a filtered catalogue (the engine would judge the
|
|
7857
|
+
* omitted applied ids "newer").
|
|
7802
7858
|
*/
|
|
7803
|
-
async runMigrations(migrations) {
|
|
7859
|
+
async runMigrations(migrations, options) {
|
|
7804
7860
|
const api = this.ctx.api.migrations;
|
|
7805
7861
|
const report = await runAddonMigrations({
|
|
7806
7862
|
declareOwner: (input) => api.declareOwner.mutate(input),
|
|
7807
7863
|
startMigration: (input) => api.startMigration.mutate(input),
|
|
7808
7864
|
finishMigration: (input) => api.finishMigration.mutate(input)
|
|
7809
|
-
}, migrations, this.ctx.logger);
|
|
7865
|
+
}, migrations, this.ctx.logger, options);
|
|
7810
7866
|
if (report.blockOwner.length > 0) throw new AddonMigrationsBlockedError(report.blockOwner);
|
|
7811
7867
|
return report;
|
|
7812
7868
|
}
|
|
@@ -7948,10 +8004,9 @@ var BaseAddon = class {
|
|
|
7948
8004
|
*
|
|
7949
8005
|
* Override it only when an `instanceMode: multiple` addon's instances differ: an NVR integration
|
|
7950
8006
|
* needs its connection fields, the default integration the addon's own sections. It is the
|
|
7951
|
-
* SHAPE of the form only — the values live
|
|
7952
|
-
* unchanged (`integrations.setSettings` for an account integration).
|
|
8007
|
+
* SHAPE of the form only — the values live on the instance record.
|
|
7953
8008
|
*/
|
|
7954
|
-
async
|
|
8009
|
+
async integrationFormSchema(_instance) {
|
|
7955
8010
|
return null;
|
|
7956
8011
|
}
|
|
7957
8012
|
/**
|
|
@@ -7997,7 +8052,7 @@ var BaseAddon = class {
|
|
|
7997
8052
|
* per-instance schema when it declares one, else its global schema (what they always showed).
|
|
7998
8053
|
*/
|
|
7999
8054
|
async getIntegrationFormSchema(instance, nodeId) {
|
|
8000
|
-
const scoped = await this.
|
|
8055
|
+
const scoped = await this.integrationFormSchema(instance);
|
|
8001
8056
|
if (scoped === null) return this.getGlobalSettings(void 0, void 0, nodeId);
|
|
8002
8057
|
return hydrateSchema(scoped, {}, { inlineSecretsAsViews: true });
|
|
8003
8058
|
}
|
|
@@ -8809,6 +8864,13 @@ var RevConflictError = class extends RecordsError {
|
|
|
8809
8864
|
this.name = "RevConflictError";
|
|
8810
8865
|
}
|
|
8811
8866
|
};
|
|
8867
|
+
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
8868
|
+
var RecordSecretUnavailableError = class extends RecordsError {
|
|
8869
|
+
constructor(detail) {
|
|
8870
|
+
super("secret-unavailable", detail);
|
|
8871
|
+
this.name = "RecordSecretUnavailableError";
|
|
8872
|
+
}
|
|
8873
|
+
};
|
|
8812
8874
|
var InvalidRecordError = class extends RecordsError {
|
|
8813
8875
|
constructor(detail) {
|
|
8814
8876
|
super("invalid-record", detail);
|
|
@@ -8839,6 +8901,8 @@ var RECORD_BATCH_MAX = 1e3;
|
|
|
8839
8901
|
var RECORD_QUERY_MAX = 1e3;
|
|
8840
8902
|
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
8841
8903
|
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
8904
|
+
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
8905
|
+
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
8842
8906
|
/**
|
|
8843
8907
|
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
8844
8908
|
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
@@ -8881,6 +8945,128 @@ function secretArrayPrefixes(path) {
|
|
|
8881
8945
|
}
|
|
8882
8946
|
return prefixes;
|
|
8883
8947
|
}
|
|
8948
|
+
function isRecord$4(value) {
|
|
8949
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8950
|
+
}
|
|
8951
|
+
function elementId(element, idKey, declared, prefix) {
|
|
8952
|
+
const id = isRecord$4(element) ? element[idKey] : void 0;
|
|
8953
|
+
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`);
|
|
8954
|
+
return id;
|
|
8955
|
+
}
|
|
8956
|
+
/**
|
|
8957
|
+
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
8958
|
+
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
8959
|
+
* result is a new body, `data` is untouched.
|
|
8960
|
+
*/
|
|
8961
|
+
var REMOVE_LEAF = Symbol("remove-leaf");
|
|
8962
|
+
function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
|
|
8963
|
+
if (!isRecord$4(node)) return node;
|
|
8964
|
+
const segment = segments[index];
|
|
8965
|
+
if (segment === void 0) return node;
|
|
8966
|
+
if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
|
|
8967
|
+
const child = node[segment.key];
|
|
8968
|
+
const keys = [...walkedKeys, segment.key];
|
|
8969
|
+
const last = index === segments.length - 1;
|
|
8970
|
+
if (segment.each) {
|
|
8971
|
+
if (!Array.isArray(child)) return node;
|
|
8972
|
+
const prefix = keys.join(".");
|
|
8973
|
+
const idKey = arrayKeys[prefix];
|
|
8974
|
+
if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
|
|
8975
|
+
const mapped = child.map((element) => {
|
|
8976
|
+
const id = elementId(element, idKey, declared, prefix);
|
|
8977
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
|
|
8978
|
+
return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
|
|
8979
|
+
});
|
|
8980
|
+
return {
|
|
8981
|
+
...node,
|
|
8982
|
+
[segment.key]: mapped
|
|
8983
|
+
};
|
|
8984
|
+
}
|
|
8985
|
+
if (segment.map) {
|
|
8986
|
+
if (!isRecord$4(child)) return node;
|
|
8987
|
+
const kept = Object.entries(child).map(([mapKey, value]) => {
|
|
8988
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
|
|
8989
|
+
if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
|
|
8990
|
+
return [mapKey, visit({
|
|
8991
|
+
declared,
|
|
8992
|
+
concrete,
|
|
8993
|
+
value
|
|
8994
|
+
})];
|
|
8995
|
+
}).filter(([, value]) => value !== REMOVE_LEAF);
|
|
8996
|
+
return {
|
|
8997
|
+
...node,
|
|
8998
|
+
[segment.key]: Object.fromEntries(kept)
|
|
8999
|
+
};
|
|
9000
|
+
}
|
|
9001
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
9002
|
+
if (last) {
|
|
9003
|
+
const replacement = visit({
|
|
9004
|
+
declared,
|
|
9005
|
+
concrete,
|
|
9006
|
+
value: child
|
|
9007
|
+
});
|
|
9008
|
+
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
9009
|
+
return {
|
|
9010
|
+
...node,
|
|
9011
|
+
[segment.key]: replacement
|
|
9012
|
+
};
|
|
9013
|
+
}
|
|
9014
|
+
return {
|
|
9015
|
+
...node,
|
|
9016
|
+
[segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
|
|
9017
|
+
};
|
|
9018
|
+
}
|
|
9019
|
+
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
9020
|
+
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
9021
|
+
let current = data;
|
|
9022
|
+
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
9023
|
+
return current;
|
|
9024
|
+
}
|
|
9025
|
+
/**
|
|
9026
|
+
* The keychain collection name a kind's secrets live under. Prefixed so a
|
|
9027
|
+
* record's refs never collide with the refs a legacy collection of the same name
|
|
9028
|
+
* already holds during an adoption.
|
|
9029
|
+
*/
|
|
9030
|
+
function recordSecretCollection(kind) {
|
|
9031
|
+
return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
|
|
9032
|
+
}
|
|
9033
|
+
/** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
|
|
9034
|
+
function recordSecretRef(owner, kind, rowId, concretePath) {
|
|
9035
|
+
return buildSecretRef({
|
|
9036
|
+
owner,
|
|
9037
|
+
scope: {
|
|
9038
|
+
kind: "row",
|
|
9039
|
+
collection: recordSecretCollection(kind),
|
|
9040
|
+
rowId
|
|
9041
|
+
},
|
|
9042
|
+
fieldPath: concretePath
|
|
9043
|
+
});
|
|
9044
|
+
}
|
|
9045
|
+
/**
|
|
9046
|
+
* A stored secret, as an admin read shows it: a VIEW naming the row's own
|
|
9047
|
+
* keychain ref (`set: true`), never the value and no longer the bare redaction
|
|
9048
|
+
* token. The form hands it to the secret field, which reveals the value by ref
|
|
9049
|
+
* through the audited `keychain-admin.reveal`; sent back untouched it keeps the
|
|
9050
|
+
* stored secret (the records door reads a view as KEEP).
|
|
9051
|
+
*
|
|
9052
|
+
* ONE implementation for the entries service and for every addon that serves
|
|
9053
|
+
* its own instances (`RecordIntegrationInstances`).
|
|
9054
|
+
*/
|
|
9055
|
+
function isRecord$3(value) {
|
|
9056
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9057
|
+
}
|
|
9058
|
+
function secretViewsOf(owner, kind, id, decl, data) {
|
|
9059
|
+
if (decl.secretPaths.length === 0) return data;
|
|
9060
|
+
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
9061
|
+
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
9062
|
+
return {
|
|
9063
|
+
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
9064
|
+
v: 1,
|
|
9065
|
+
set: true
|
|
9066
|
+
};
|
|
9067
|
+
});
|
|
9068
|
+
return isRecord$3(shown) ? shown : data;
|
|
9069
|
+
}
|
|
8884
9070
|
/**
|
|
8885
9071
|
* The share-view scope kinds a share-link token can carry. The hub mints
|
|
8886
9072
|
* and validates them (`ShareViewGrantSchema` builds its
|
|
@@ -9133,6 +9319,7 @@ function defineEntryKind(name, spec) {
|
|
|
9133
9319
|
class: "config",
|
|
9134
9320
|
writeTrigger: spec.writeTrigger ?? "an operator adds or edits an entry in the entries UI",
|
|
9135
9321
|
retention: { none: "an entry goes only when the operator deletes it" },
|
|
9322
|
+
...spec.maxDataBytes === void 0 ? {} : { maxDataBytes: spec.maxDataBytes },
|
|
9136
9323
|
...spec.database === void 0 ? {} : { database: spec.database },
|
|
9137
9324
|
...spec.indexes === void 0 ? {} : { indexes: spec.indexes },
|
|
9138
9325
|
...spec.secretArrayKeys === void 0 ? {} : { secretArrayKeys: spec.secretArrayKeys },
|
|
@@ -11798,7 +11985,7 @@ object({
|
|
|
11798
11985
|
params: record(string(), union([string(), number()])).optional()
|
|
11799
11986
|
});
|
|
11800
11987
|
//#endregion
|
|
11801
|
-
//#region ../types/dist/composition-
|
|
11988
|
+
//#region ../types/dist/composition-pOHbTzRB.mjs
|
|
11802
11989
|
/**
|
|
11803
11990
|
* The ffmpeg build every CamStack node downloads, per platform and arch.
|
|
11804
11991
|
*
|
|
@@ -13262,6 +13449,205 @@ function buildCapturingReply(envelope) {
|
|
|
13262
13449
|
};
|
|
13263
13450
|
return wrapper;
|
|
13264
13451
|
}
|
|
13452
|
+
/**
|
|
13453
|
+
* `RecordIntegrationInstances` - the `integration-instances` provider over ONE
|
|
13454
|
+
* entry kind, so an addon that holds a connection serves it in ~30 lines.
|
|
13455
|
+
*
|
|
13456
|
+
* Every instance is one record of the addon's own kind, keyed by the
|
|
13457
|
+
* `integrations` registry id. The records door does the secret work: a field the
|
|
13458
|
+
* kind marks `.meta({ secret: true })` is a keychain marker bound to the row, so
|
|
13459
|
+
* deleting the row deletes the secret, and one row's value is never another's.
|
|
13460
|
+
*
|
|
13461
|
+
* Patch rules for a secret (`updateInstance`): omitted, `''`, the redaction
|
|
13462
|
+
* token or the view the form was given KEEP the stored secret;
|
|
13463
|
+
* `{ $secretClear: true }` clears it; any other string replaces it.
|
|
13464
|
+
*/
|
|
13465
|
+
/** The most instances one addon lists (an integrations page, not a table). */
|
|
13466
|
+
var INSTANCES_LIST_MAX = 1e3;
|
|
13467
|
+
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
13468
|
+
function topLevelSecretKeys(paths) {
|
|
13469
|
+
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
13470
|
+
}
|
|
13471
|
+
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
13472
|
+
function secretMapKeys(paths) {
|
|
13473
|
+
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
13474
|
+
}
|
|
13475
|
+
/**
|
|
13476
|
+
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
13477
|
+
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
13478
|
+
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
13479
|
+
*/
|
|
13480
|
+
function secretMapPatch(value) {
|
|
13481
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
13482
|
+
const out = {};
|
|
13483
|
+
for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
|
|
13484
|
+
else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
|
|
13485
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
13486
|
+
}
|
|
13487
|
+
/** Does the kind's body schema carry an `enabled` field? */
|
|
13488
|
+
function declaresEnabled(kind) {
|
|
13489
|
+
const json = toJSONSchema(kind.schema, {
|
|
13490
|
+
unrepresentable: "any",
|
|
13491
|
+
io: "input"
|
|
13492
|
+
});
|
|
13493
|
+
const properties = Reflect.get(json, "properties");
|
|
13494
|
+
return typeof properties === "object" && properties !== null && "enabled" in properties;
|
|
13495
|
+
}
|
|
13496
|
+
var RecordIntegrationInstances = class {
|
|
13497
|
+
records;
|
|
13498
|
+
kind;
|
|
13499
|
+
hooks;
|
|
13500
|
+
handle;
|
|
13501
|
+
secretKeys;
|
|
13502
|
+
secretMaps;
|
|
13503
|
+
nameField;
|
|
13504
|
+
/** The `integrations` registry owns the on/off switch (`role: devices`); the body has none. */
|
|
13505
|
+
registryOwnsEnabled;
|
|
13506
|
+
constructor(records, kind, hooks) {
|
|
13507
|
+
this.records = records;
|
|
13508
|
+
this.kind = kind;
|
|
13509
|
+
this.hooks = hooks;
|
|
13510
|
+
this.handle = records.kind(kind);
|
|
13511
|
+
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
13512
|
+
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
13513
|
+
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
13514
|
+
this.registryOwnsEnabled = hooks.description.role === "devices";
|
|
13515
|
+
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"`);
|
|
13516
|
+
}
|
|
13517
|
+
/**
|
|
13518
|
+
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
13519
|
+
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
13520
|
+
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
13521
|
+
*/
|
|
13522
|
+
async readResolved(id) {
|
|
13523
|
+
try {
|
|
13524
|
+
const record = await this.handle.getResolved(id);
|
|
13525
|
+
return record === null ? null : {
|
|
13526
|
+
id,
|
|
13527
|
+
body: record.data,
|
|
13528
|
+
enabled: record.data.enabled !== false,
|
|
13529
|
+
secrets: "resolved"
|
|
13530
|
+
};
|
|
13531
|
+
} catch (err) {
|
|
13532
|
+
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
13533
|
+
const stored = await this.handle.get(id);
|
|
13534
|
+
if (stored === null) return null;
|
|
13535
|
+
return {
|
|
13536
|
+
id,
|
|
13537
|
+
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
13538
|
+
enabled: stored.data.enabled !== false,
|
|
13539
|
+
secrets: "unavailable"
|
|
13540
|
+
};
|
|
13541
|
+
}
|
|
13542
|
+
}
|
|
13543
|
+
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
13544
|
+
async getResolved(id) {
|
|
13545
|
+
return (await this.readResolved(id))?.body ?? null;
|
|
13546
|
+
}
|
|
13547
|
+
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
13548
|
+
async listResolved() {
|
|
13549
|
+
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
13550
|
+
const out = [];
|
|
13551
|
+
for (const record of page.records) {
|
|
13552
|
+
const read = await this.readResolved(record.id);
|
|
13553
|
+
if (read !== null) out.push(read);
|
|
13554
|
+
}
|
|
13555
|
+
return out;
|
|
13556
|
+
}
|
|
13557
|
+
viewOf(record) {
|
|
13558
|
+
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
13559
|
+
const rawName = record.data[this.nameField];
|
|
13560
|
+
const kind = this.hooks.kindOf?.(record.data);
|
|
13561
|
+
const health = this.hooks.health?.(record.data, record.id);
|
|
13562
|
+
return {
|
|
13563
|
+
id: record.id,
|
|
13564
|
+
name: typeof rawName === "string" ? rawName : record.id,
|
|
13565
|
+
configured: this.hooks.configured(record.data),
|
|
13566
|
+
...this.registryOwnsEnabled ? {} : { enabled: record.data.enabled !== false },
|
|
13567
|
+
formValues: shown,
|
|
13568
|
+
...kind !== void 0 ? { kind } : {},
|
|
13569
|
+
...health?.status !== void 0 ? { status: health.status } : {},
|
|
13570
|
+
...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
|
|
13571
|
+
};
|
|
13572
|
+
}
|
|
13573
|
+
describe = async () => this.hooks.mintId === void 0 ? this.hooks.description : {
|
|
13574
|
+
...this.hooks.description,
|
|
13575
|
+
mintsId: true
|
|
13576
|
+
};
|
|
13577
|
+
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
13578
|
+
listInstances = async () => {
|
|
13579
|
+
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
13580
|
+
};
|
|
13581
|
+
getInstance = async ({ id }) => {
|
|
13582
|
+
const record = await this.handle.get(id);
|
|
13583
|
+
return record === null ? null : this.viewOf(record);
|
|
13584
|
+
};
|
|
13585
|
+
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
13586
|
+
createInstance = async ({ id, name, kind }) => {
|
|
13587
|
+
const minted = id ?? this.hooks.mintId?.({
|
|
13588
|
+
name,
|
|
13589
|
+
...kind !== void 0 ? { kind } : {}
|
|
13590
|
+
});
|
|
13591
|
+
if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
|
|
13592
|
+
await this.handle.put({
|
|
13593
|
+
id: minted,
|
|
13594
|
+
data: this.hooks.initialBody(name, kind)
|
|
13595
|
+
}, { ifRev: 0 });
|
|
13596
|
+
await this.hooks.onChanged?.(minted, "created");
|
|
13597
|
+
return { id: minted };
|
|
13598
|
+
};
|
|
13599
|
+
updateInstance = async ({ id, name, values }) => {
|
|
13600
|
+
const patch = {};
|
|
13601
|
+
for (const [key, value] of Object.entries(values)) {
|
|
13602
|
+
if (value === void 0) continue;
|
|
13603
|
+
if (this.secretMaps.has(key)) {
|
|
13604
|
+
const entries = secretMapPatch(value);
|
|
13605
|
+
if (entries !== null) patch[key] = entries;
|
|
13606
|
+
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
13607
|
+
else if (isSecretClear(value)) patch[key] = null;
|
|
13608
|
+
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
13609
|
+
}
|
|
13610
|
+
if (name !== void 0) patch[this.nameField] = name;
|
|
13611
|
+
await this.handle.patch(id, patch);
|
|
13612
|
+
await this.hooks.onChanged?.(id, "updated");
|
|
13613
|
+
return { ok: true };
|
|
13614
|
+
};
|
|
13615
|
+
/** The switch lives in the record body; the addon is told so it applies it (D996). */
|
|
13616
|
+
setInstanceEnabled = async ({ id, enabled }) => {
|
|
13617
|
+
if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
|
|
13618
|
+
await this.handle.patch(id, { enabled });
|
|
13619
|
+
await this.hooks.onChanged?.(id, "enabled");
|
|
13620
|
+
return { ok: true };
|
|
13621
|
+
};
|
|
13622
|
+
/** The row and its keychain refs go together (the records door). */
|
|
13623
|
+
deleteInstance = async ({ id }) => {
|
|
13624
|
+
await this.handle.delete(id);
|
|
13625
|
+
await this.hooks.onChanged?.(id, "deleted");
|
|
13626
|
+
return { ok: true };
|
|
13627
|
+
};
|
|
13628
|
+
testInstance = async (input) => {
|
|
13629
|
+
if (this.hooks.test === void 0) return {
|
|
13630
|
+
success: false,
|
|
13631
|
+
status: "unsupported",
|
|
13632
|
+
error: "This integration declares no connection test"
|
|
13633
|
+
};
|
|
13634
|
+
return this.hooks.test(input);
|
|
13635
|
+
};
|
|
13636
|
+
/** The flat provider object to hand to `registerProvider`. */
|
|
13637
|
+
toProvider() {
|
|
13638
|
+
return {
|
|
13639
|
+
describe: this.describe,
|
|
13640
|
+
instanceFormSchema: this.instanceFormSchema,
|
|
13641
|
+
listInstances: this.listInstances,
|
|
13642
|
+
getInstance: this.getInstance,
|
|
13643
|
+
createInstance: this.createInstance,
|
|
13644
|
+
updateInstance: this.updateInstance,
|
|
13645
|
+
setInstanceEnabled: this.setInstanceEnabled,
|
|
13646
|
+
deleteInstance: this.deleteInstance,
|
|
13647
|
+
testInstance: this.testInstance
|
|
13648
|
+
};
|
|
13649
|
+
}
|
|
13650
|
+
};
|
|
13265
13651
|
var EncodeProfileSchema = object({
|
|
13266
13652
|
video: object({
|
|
13267
13653
|
codec: _enum([
|
|
@@ -14307,7 +14693,13 @@ var MigrationLedgerEntrySchema = object({
|
|
|
14307
14693
|
* joined by the engine from the catalogues it knows this boot. Absent when no
|
|
14308
14694
|
* catalogue lists the id (a newer database).
|
|
14309
14695
|
*/
|
|
14310
|
-
meta: MigrationMetaSchema.optional()
|
|
14696
|
+
meta: MigrationMetaSchema.optional(),
|
|
14697
|
+
/**
|
|
14698
|
+
* Set when this is an applied row of an addon owner whose catalogue the answering
|
|
14699
|
+
* process has not loaded (the owner has not declared yet): the row is applied, the
|
|
14700
|
+
* process just cannot judge it. Never `skipped-newer` — that needs the owner loaded.
|
|
14701
|
+
*/
|
|
14702
|
+
ownerNotLoaded: boolean().optional()
|
|
14311
14703
|
});
|
|
14312
14704
|
/** A catalogued migration that is not applied, with where it stands. */
|
|
14313
14705
|
var MigrationPendingEntrySchema = object({
|
|
@@ -48919,6 +49311,9 @@ var RunningProposalEvidenceSchema = object({
|
|
|
48919
49311
|
runsFound: number().int().nonnegative(),
|
|
48920
49312
|
pausesFound: number().int().nonnegative(),
|
|
48921
49313
|
longestPauseMs: number().nonnegative(),
|
|
49314
|
+
/** Episodes shorter than ~90 s (an anti-crease pulse, a display waking): never a run, never a pause. */
|
|
49315
|
+
pulsesFound: number().int().nonnegative(),
|
|
49316
|
+
longestPulseMs: number().nonnegative(),
|
|
48922
49317
|
idleFloorW: number(),
|
|
48923
49318
|
noiseCeilingW: number(),
|
|
48924
49319
|
plateauW: number(),
|
|
@@ -50089,13 +50484,6 @@ var ExportInstanceUnknownError = class extends Error {
|
|
|
50089
50484
|
function statusInstanceOf(input) {
|
|
50090
50485
|
return "instanceId" in input ? input.instanceId : void 0;
|
|
50091
50486
|
}
|
|
50092
|
-
/**
|
|
50093
|
-
* A single-instance provider's check: an absent id or its own passes, any other throws
|
|
50094
|
-
* `ExportInstanceUnknownError`.
|
|
50095
|
-
*/
|
|
50096
|
-
function assertOwnExportInstance(addon, own, instanceId) {
|
|
50097
|
-
if (instanceId !== void 0 && instanceId !== own) throw new ExportInstanceUnknownError(addon, instanceId);
|
|
50098
|
-
}
|
|
50099
50487
|
var LinkStateSchema = _enum([
|
|
50100
50488
|
"unlinked",
|
|
50101
50489
|
"linked",
|
|
@@ -50200,12 +50588,12 @@ var deviceExportCapability = {
|
|
|
50200
50588
|
kind: "poll"
|
|
50201
50589
|
},
|
|
50202
50590
|
/**
|
|
50203
|
-
* Each export provider
|
|
50204
|
-
* (enabled toggle, preferred stream, addon-specific knobs
|
|
50205
|
-
*
|
|
50206
|
-
* `
|
|
50207
|
-
* `
|
|
50208
|
-
*
|
|
50591
|
+
* Each export provider MAY contribute its own per-device "Export" panel
|
|
50592
|
+
* (enabled toggle, preferred stream, addon-specific knobs). The three
|
|
50593
|
+
* framework methods are mounted on the cap router when present.
|
|
50594
|
+
* `IDeviceExportProvider` leaves them optional: an exporter with no
|
|
50595
|
+
* per-device panel omits them (a `deviceConfig` cap's UI is derived and
|
|
50596
|
+
* never hand-written — D14 — and an exporter is not one of those).
|
|
50209
50597
|
*/
|
|
50210
50598
|
exposesDeviceSettings: true,
|
|
50211
50599
|
methods: {
|
|
@@ -53896,11 +54284,7 @@ var CreateIntegrationInputSchema = object({
|
|
|
53896
54284
|
info: record(string(), unknown()).optional(),
|
|
53897
54285
|
/** `stableId` of the discovery candidate the form was seeded from (D984). */
|
|
53898
54286
|
originStableId: string().optional(),
|
|
53899
|
-
settings: record(string(), unknown()).optional()
|
|
53900
|
-
/** Keys of `settings` the form's schema declares secret (by type) — kept in
|
|
53901
|
-
* the keychain, not the table (D787). */
|
|
53902
|
-
secretKeys: array(string()).optional(),
|
|
53903
|
-
skipRestart: boolean().optional()
|
|
54287
|
+
settings: record(string(), unknown()).optional()
|
|
53904
54288
|
});
|
|
53905
54289
|
var UpdateIntegrationInputSchema = object({
|
|
53906
54290
|
id: string(),
|
|
@@ -53921,16 +54305,6 @@ method(_void(), array(IntegrationWithStateSchema)), method(object({ id: string()
|
|
|
53921
54305
|
}), method(object({ id: string() }), DeleteIntegrationResultSchema, {
|
|
53922
54306
|
kind: "mutation",
|
|
53923
54307
|
auth: "admin"
|
|
53924
|
-
}), method(object({ id: string() }), record(string(), unknown()), { auth: "admin" }), method(object({
|
|
53925
|
-
id: string(),
|
|
53926
|
-
settings: record(string(), unknown()),
|
|
53927
|
-
/** Keys the form's schema declares secret (by type) — keychain-stored (D787). */
|
|
53928
|
-
secretKeys: array(string()).optional(),
|
|
53929
|
-
/** The integration's own addon applies the change in-process and asks the hub not to respawn it. */
|
|
53930
|
-
skipRestart: boolean().optional()
|
|
53931
|
-
}), object({ success: boolean() }), {
|
|
53932
|
-
kind: "mutation",
|
|
53933
|
-
auth: "admin"
|
|
53934
54308
|
}), method(_void(), array(AvailableIntegrationTypeSchema), { auth: "admin" }), method(object({
|
|
53935
54309
|
addonId: string(),
|
|
53936
54310
|
settings: record(string(), unknown())
|
|
@@ -54055,32 +54429,57 @@ var IntegrationInstancePatchSchema = object({
|
|
|
54055
54429
|
/** Omitted / '' / redaction token keeps a secret; `{ $secretClear: true }` clears it. */
|
|
54056
54430
|
values: record(string(), unknown())
|
|
54057
54431
|
});
|
|
54058
|
-
|
|
54059
|
-
|
|
54060
|
-
|
|
54061
|
-
|
|
54062
|
-
|
|
54063
|
-
|
|
54064
|
-
|
|
54065
|
-
|
|
54066
|
-
|
|
54067
|
-
|
|
54068
|
-
|
|
54069
|
-
|
|
54070
|
-
|
|
54071
|
-
|
|
54072
|
-
|
|
54073
|
-
|
|
54074
|
-
|
|
54075
|
-
|
|
54076
|
-
|
|
54077
|
-
|
|
54078
|
-
|
|
54079
|
-
|
|
54080
|
-
}),
|
|
54081
|
-
|
|
54082
|
-
|
|
54083
|
-
})
|
|
54432
|
+
var integrationInstancesCapability = {
|
|
54433
|
+
name: "integration-instances",
|
|
54434
|
+
scope: "system",
|
|
54435
|
+
mode: "collection",
|
|
54436
|
+
methods: {
|
|
54437
|
+
describe: method(_void(), IntegrationInstanceDescriptionSchema, { auth: "admin" }),
|
|
54438
|
+
/** The form; `id: null` is the create form. */
|
|
54439
|
+
instanceFormSchema: method(object({ id: IntegrationInstanceIdSchema.nullable() }), ConfigSchemaPassthrough$3, { auth: "admin" }),
|
|
54440
|
+
listInstances: method(_void(), array(IntegrationInstanceSchema).readonly(), { auth: "admin" }),
|
|
54441
|
+
getInstance: method(object({ id: IntegrationInstanceIdSchema }), IntegrationInstanceSchema.nullable(), { auth: "admin" }),
|
|
54442
|
+
/**
|
|
54443
|
+
* Insert the typed record. With `id` it is stored under that id (a duplicate id is refused);
|
|
54444
|
+
* without one the PROVIDER mints it and answers it. `kind` picks one of `describe().kinds`.
|
|
54445
|
+
*/
|
|
54446
|
+
createInstance: method(object({
|
|
54447
|
+
id: IntegrationInstanceIdSchema.optional(),
|
|
54448
|
+
name: string().min(1),
|
|
54449
|
+
kind: string().min(1).optional()
|
|
54450
|
+
}), object({ id: string() }), {
|
|
54451
|
+
kind: "mutation",
|
|
54452
|
+
auth: "admin"
|
|
54453
|
+
}),
|
|
54454
|
+
updateInstance: method(IntegrationInstancePatchSchema, object({ ok: literal(true) }), {
|
|
54455
|
+
kind: "mutation",
|
|
54456
|
+
auth: "admin"
|
|
54457
|
+
}),
|
|
54458
|
+
/**
|
|
54459
|
+
* Switch ONE instance on or off. A row control, not a form field: `updateInstance.values` is the
|
|
54460
|
+
* form patch (D62, D996). An off instance keeps its record and secrets and does no work.
|
|
54461
|
+
*/
|
|
54462
|
+
setInstanceEnabled: method(object({
|
|
54463
|
+
id: IntegrationInstanceIdSchema,
|
|
54464
|
+
enabled: boolean()
|
|
54465
|
+
}), object({ ok: literal(true) }), {
|
|
54466
|
+
kind: "mutation",
|
|
54467
|
+
auth: "admin"
|
|
54468
|
+
}),
|
|
54469
|
+
/** Delete the record and its keychain refs together. */
|
|
54470
|
+
deleteInstance: method(object({ id: IntegrationInstanceIdSchema }), object({ ok: literal(true) }), {
|
|
54471
|
+
kind: "mutation",
|
|
54472
|
+
auth: "admin"
|
|
54473
|
+
}),
|
|
54474
|
+
testInstance: optionalMethod(object({
|
|
54475
|
+
id: IntegrationInstanceIdSchema.nullable(),
|
|
54476
|
+
values: record(string(), unknown())
|
|
54477
|
+
}), TestConnectionResultSchema$1, {
|
|
54478
|
+
kind: "mutation",
|
|
54479
|
+
auth: "admin"
|
|
54480
|
+
})
|
|
54481
|
+
}
|
|
54482
|
+
};
|
|
54084
54483
|
/**
|
|
54085
54484
|
* Two-way audio / talk-back cap. Clients open a WebRTC audio-only
|
|
54086
54485
|
* session (server-initiated offer pattern, identical to the main
|
|
@@ -56630,6 +57029,27 @@ method(object({}), object({ entries: array(MigrationLedgerEntrySchema) }), { aut
|
|
|
56630
57029
|
}), {
|
|
56631
57030
|
kind: "mutation",
|
|
56632
57031
|
auth: "admin"
|
|
57032
|
+
}), method(object({ integrationId: string().min(1) }), record(string(), unknown()), { auth: "admin" }), method(object({ integrationId: string().min(1) }), object({
|
|
57033
|
+
rows: number().int().nonnegative(),
|
|
57034
|
+
secrets: number().int().nonnegative()
|
|
57035
|
+
}), {
|
|
57036
|
+
kind: "mutation",
|
|
57037
|
+
auth: "admin"
|
|
57038
|
+
}), method(object({
|
|
57039
|
+
integrationId: string().min(1),
|
|
57040
|
+
patch: record(string(), unknown())
|
|
57041
|
+
}), object({ written: boolean() }), {
|
|
57042
|
+
kind: "mutation",
|
|
57043
|
+
auth: "admin"
|
|
57044
|
+
}), method(object({
|
|
57045
|
+
integrationId: string().min(1),
|
|
57046
|
+
keys: array(string().min(1))
|
|
57047
|
+
}), object({
|
|
57048
|
+
present: boolean(),
|
|
57049
|
+
removed: record(string(), unknown())
|
|
57050
|
+
}), {
|
|
57051
|
+
kind: "mutation",
|
|
57052
|
+
auth: "admin"
|
|
56633
57053
|
});
|
|
56634
57054
|
method(object({
|
|
56635
57055
|
sourceUrl: string(),
|
|
@@ -75814,11 +76234,15 @@ discriminatedUnion("kind", [object({
|
|
|
75814
76234
|
* 1. idle floor F = time-weighted median; noise ceiling N = highest value seen
|
|
75815
76235
|
* near F. A device that is not near one level most of the time has no floor.
|
|
75816
76236
|
* 2. coarse activity = above max(2N, N + 5 W); consecutive stretches are episodes.
|
|
75817
|
-
* 3.
|
|
75818
|
-
*
|
|
76237
|
+
* 3. an episode shorter than `PULSE_MAX_MS` is a PULSE (an anti-crease tumble, a
|
|
76238
|
+
* display waking): it is neither a run nor a pause. Among the remaining
|
|
76239
|
+
* episodes, gaps over `PAUSE_MAX_MS` always separate runs; the rest split in
|
|
76240
|
+
* two by the largest log-scale jump (>= 3x): the short ones are pauses INSIDE
|
|
76241
|
+
* a run (a soak), the long ones separate runs. A stretch under `MIN_RUN_MS`
|
|
76242
|
+
* is no run.
|
|
75819
76243
|
* 4. T = geometric mean of N and the plateau's 10th percentile, snapped to a
|
|
75820
|
-
* grid a person would type; stop dwell covers the longest pause
|
|
75821
|
-
* covers the longest standby blip above T.
|
|
76244
|
+
* grid a person would type; stop dwell covers the longest pause and the
|
|
76245
|
+
* kind's floor; start dwell covers the longest pulse and standby blip above T.
|
|
75822
76246
|
* 5. the numbers are proved by REPLAY through the real `dwell` evaluation: each
|
|
75823
76247
|
* run must hold exactly one true interval and nothing may flap outside.
|
|
75824
76248
|
*/
|
|
@@ -75829,6 +76253,10 @@ var MINUTE_MS$1 = 60 * SECOND_MS;
|
|
|
75829
76253
|
30 * SECOND_MS;
|
|
75830
76254
|
60 * SECOND_MS;
|
|
75831
76255
|
20 * MINUTE_MS$1;
|
|
76256
|
+
90 * SECOND_MS;
|
|
76257
|
+
30 * MINUTE_MS$1;
|
|
76258
|
+
10 * MINUTE_MS$1;
|
|
76259
|
+
DeviceType.Dryer, 3 * MINUTE_MS$1, DeviceType.Dishwasher, 3 * MINUTE_MS$1, DeviceType.Washer, 10 * MINUTE_MS$1;
|
|
75832
76260
|
10 * SECOND_MS;
|
|
75833
76261
|
10 * SECOND_MS;
|
|
75834
76262
|
DeviceFeature.FanSpeed, DeviceFeature.FanPreset, DeviceFeature.FanDirection, DeviceFeature.FanOscillating, DeviceFeature.CoverStoppable, DeviceFeature.CoverPositionable, DeviceFeature.CoverTilt, DeviceFeature.ValvePositionable, DeviceFeature.MediaPlayerVolume, DeviceFeature.ClimateFanMode;
|
|
@@ -79584,13 +80012,6 @@ Object.freeze({
|
|
|
79584
80012
|
access: "view",
|
|
79585
80013
|
role: "admin"
|
|
79586
80014
|
},
|
|
79587
|
-
"integrations.getSettings": {
|
|
79588
|
-
capName: "integrations",
|
|
79589
|
-
capScope: "system",
|
|
79590
|
-
addonId: null,
|
|
79591
|
-
access: "view",
|
|
79592
|
-
role: "admin"
|
|
79593
|
-
},
|
|
79594
80015
|
"integrations.list": {
|
|
79595
80016
|
capName: "integrations",
|
|
79596
80017
|
capScope: "system",
|
|
@@ -79598,13 +80019,6 @@ Object.freeze({
|
|
|
79598
80019
|
access: "view",
|
|
79599
80020
|
role: "admin"
|
|
79600
80021
|
},
|
|
79601
|
-
"integrations.setSettings": {
|
|
79602
|
-
capName: "integrations",
|
|
79603
|
-
capScope: "system",
|
|
79604
|
-
addonId: null,
|
|
79605
|
-
access: "create",
|
|
79606
|
-
role: "admin"
|
|
79607
|
-
},
|
|
79608
80022
|
"integrations.testConnection": {
|
|
79609
80023
|
capName: "integrations",
|
|
79610
80024
|
capScope: "system",
|
|
@@ -80599,6 +81013,13 @@ Object.freeze({
|
|
|
80599
81013
|
access: "view",
|
|
80600
81014
|
role: "admin"
|
|
80601
81015
|
},
|
|
81016
|
+
"migrations.clearLegacyIntegrationRows": {
|
|
81017
|
+
capName: "migrations",
|
|
81018
|
+
capScope: "system",
|
|
81019
|
+
addonId: null,
|
|
81020
|
+
access: "delete",
|
|
81021
|
+
role: "admin"
|
|
81022
|
+
},
|
|
80602
81023
|
"migrations.declareOwner": {
|
|
80603
81024
|
capName: "migrations",
|
|
80604
81025
|
capScope: "system",
|
|
@@ -80606,6 +81027,13 @@ Object.freeze({
|
|
|
80606
81027
|
access: "create",
|
|
80607
81028
|
role: "admin"
|
|
80608
81029
|
},
|
|
81030
|
+
"migrations.deleteLegacyIntegrationRowKeys": {
|
|
81031
|
+
capName: "migrations",
|
|
81032
|
+
capScope: "system",
|
|
81033
|
+
addonId: null,
|
|
81034
|
+
access: "delete",
|
|
81035
|
+
role: "admin"
|
|
81036
|
+
},
|
|
80609
81037
|
"migrations.dryRun": {
|
|
80610
81038
|
capName: "migrations",
|
|
80611
81039
|
capScope: "system",
|
|
@@ -80641,6 +81069,20 @@ Object.freeze({
|
|
|
80641
81069
|
access: "create",
|
|
80642
81070
|
role: "admin"
|
|
80643
81071
|
},
|
|
81072
|
+
"migrations.patchLegacyIntegrationRows": {
|
|
81073
|
+
capName: "migrations",
|
|
81074
|
+
capScope: "system",
|
|
81075
|
+
addonId: null,
|
|
81076
|
+
access: "create",
|
|
81077
|
+
role: "admin"
|
|
81078
|
+
},
|
|
81079
|
+
"migrations.readLegacyIntegrationRows": {
|
|
81080
|
+
capName: "migrations",
|
|
81081
|
+
capScope: "system",
|
|
81082
|
+
addonId: null,
|
|
81083
|
+
access: "view",
|
|
81084
|
+
role: "admin"
|
|
81085
|
+
},
|
|
80644
81086
|
"migrations.restorePreMigration": {
|
|
80645
81087
|
capName: "migrations",
|
|
80646
81088
|
capScope: "system",
|
|
@@ -91068,7 +91510,11 @@ var ActionSceneExports = class {
|
|
|
91068
91510
|
* scenes. The addon is its only writer; the in-memory copy it loads at boot is what every
|
|
91069
91511
|
* fulfillment intent reads.
|
|
91070
91512
|
*/
|
|
91071
|
-
/**
|
|
91513
|
+
/**
|
|
91514
|
+
* The id the first Google Home instance keeps: the one every record and every pasted fulfillment
|
|
91515
|
+
* URL was created under. New instances get minted ids; the legacy `/fulfillment` route answers
|
|
91516
|
+
* for this one.
|
|
91517
|
+
*/
|
|
91072
91518
|
var GOOGLE_INSTANCE_ID = "export-google";
|
|
91073
91519
|
var ExposedDeviceEntrySchema = object({
|
|
91074
91520
|
deviceId: number(),
|
|
@@ -91098,6 +91544,204 @@ var EMPTY_GOOGLE_EXPORTS = {
|
|
|
91098
91544
|
};
|
|
91099
91545
|
/** The settings keys that moved into the record; the migrations name them. */
|
|
91100
91546
|
var MOVED_EXPOSURE_KEYS = ["exposed", "exposedActions"];
|
|
91547
|
+
var GoogleHomeBodySchema = object({
|
|
91548
|
+
name: string().min(1),
|
|
91549
|
+
enabled: boolean().optional()
|
|
91550
|
+
});
|
|
91551
|
+
var GOOGLE_HOMES_KIND_NAME = "google-homes";
|
|
91552
|
+
var GOOGLE_HOME_NAME = "Google Home";
|
|
91553
|
+
var googleHomesKind = defineEntryKind(GOOGLE_HOMES_KIND_NAME, {
|
|
91554
|
+
title: "Google Home instances",
|
|
91555
|
+
nameField: "name",
|
|
91556
|
+
schema: GoogleHomeBodySchema
|
|
91557
|
+
});
|
|
91558
|
+
var LinkedAccountSchema = object({
|
|
91559
|
+
userId: string(),
|
|
91560
|
+
username: string(),
|
|
91561
|
+
linkedAt: number()
|
|
91562
|
+
});
|
|
91563
|
+
var GoogleLinksBodySchema = object({
|
|
91564
|
+
name: string().min(1),
|
|
91565
|
+
linkedAccounts: array(LinkedAccountSchema)
|
|
91566
|
+
});
|
|
91567
|
+
var GOOGLE_LINKS_KIND_NAME = "google-links";
|
|
91568
|
+
var GOOGLE_LINKS_NAME = "Google links";
|
|
91569
|
+
var googleLinksKind = defineEntryKind(GOOGLE_LINKS_KIND_NAME, {
|
|
91570
|
+
title: "Google linked accounts",
|
|
91571
|
+
nameField: "name",
|
|
91572
|
+
schema: GoogleLinksBodySchema
|
|
91573
|
+
});
|
|
91574
|
+
var EMPTY_GOOGLE_LINKS = {
|
|
91575
|
+
name: GOOGLE_LINKS_NAME,
|
|
91576
|
+
linkedAccounts: []
|
|
91577
|
+
};
|
|
91578
|
+
/** The settings key that moved into the `google-links` record; the migrations name it. */
|
|
91579
|
+
var MOVED_LINKS_KEY = "linkedAccounts";
|
|
91580
|
+
//#endregion
|
|
91581
|
+
//#region src/google-instance.ts
|
|
91582
|
+
/** The most instances one hub lists. */
|
|
91583
|
+
var INSTANCES_MAX = 1e3;
|
|
91584
|
+
var GoogleInstance = class {
|
|
91585
|
+
id;
|
|
91586
|
+
home;
|
|
91587
|
+
exportsRow;
|
|
91588
|
+
linksRow;
|
|
91589
|
+
stores;
|
|
91590
|
+
logger;
|
|
91591
|
+
scenes;
|
|
91592
|
+
tail = Promise.resolve();
|
|
91593
|
+
constructor(id, home, exportsRow, linksRow, stores, logger, makeScenes) {
|
|
91594
|
+
this.id = id;
|
|
91595
|
+
this.home = home;
|
|
91596
|
+
this.exportsRow = exportsRow;
|
|
91597
|
+
this.linksRow = linksRow;
|
|
91598
|
+
this.stores = stores;
|
|
91599
|
+
this.logger = logger;
|
|
91600
|
+
this.scenes = makeScenes((entries) => this.writeExports({ actions: [...entries] }), exportsRow.actions);
|
|
91601
|
+
}
|
|
91602
|
+
get name() {
|
|
91603
|
+
return this.home.name;
|
|
91604
|
+
}
|
|
91605
|
+
get enabled() {
|
|
91606
|
+
return this.home.enabled !== false;
|
|
91607
|
+
}
|
|
91608
|
+
get devices() {
|
|
91609
|
+
return this.exportsRow.devices;
|
|
91610
|
+
}
|
|
91611
|
+
get linkedAccounts() {
|
|
91612
|
+
return this.linksRow.linkedAccounts;
|
|
91613
|
+
}
|
|
91614
|
+
applyHome(home) {
|
|
91615
|
+
this.home = home;
|
|
91616
|
+
}
|
|
91617
|
+
isExposed(deviceId) {
|
|
91618
|
+
return this.exportsRow.devices.some((entry) => entry.deviceId === deviceId);
|
|
91619
|
+
}
|
|
91620
|
+
/** One write at a time per instance: two concurrent changes must not lose each other. */
|
|
91621
|
+
serial(work) {
|
|
91622
|
+
const run = this.tail.then(work, work);
|
|
91623
|
+
this.tail = run.catch(() => void 0);
|
|
91624
|
+
return run;
|
|
91625
|
+
}
|
|
91626
|
+
/** Persist a change of the exposure: the record first, the in-memory copy after it landed. */
|
|
91627
|
+
writeExports(patch) {
|
|
91628
|
+
return this.serial(async () => {
|
|
91629
|
+
const next = {
|
|
91630
|
+
name: this.exportsRow.name,
|
|
91631
|
+
devices: patch.devices ?? this.exportsRow.devices,
|
|
91632
|
+
actions: patch.actions ?? this.exportsRow.actions
|
|
91633
|
+
};
|
|
91634
|
+
await this.stores.exports.put({
|
|
91635
|
+
id: this.id,
|
|
91636
|
+
data: next
|
|
91637
|
+
});
|
|
91638
|
+
this.exportsRow = next;
|
|
91639
|
+
});
|
|
91640
|
+
}
|
|
91641
|
+
/** Google's SYNC is the first thing a completed link does: the only "linked" signal there is. */
|
|
91642
|
+
recordLink(caller) {
|
|
91643
|
+
return this.serial(async () => {
|
|
91644
|
+
if (this.linksRow.linkedAccounts.some((a) => a.userId === caller.userId)) return;
|
|
91645
|
+
const next = {
|
|
91646
|
+
name: this.linksRow.name,
|
|
91647
|
+
linkedAccounts: [...this.linksRow.linkedAccounts, {
|
|
91648
|
+
userId: caller.userId,
|
|
91649
|
+
username: caller.username,
|
|
91650
|
+
linkedAt: Date.now()
|
|
91651
|
+
}]
|
|
91652
|
+
};
|
|
91653
|
+
await this.stores.links.put({
|
|
91654
|
+
id: this.id,
|
|
91655
|
+
data: next
|
|
91656
|
+
});
|
|
91657
|
+
this.linksRow = next;
|
|
91658
|
+
this.logger.info("export-google: recorded linked account", { meta: {
|
|
91659
|
+
instanceId: this.id,
|
|
91660
|
+
userId: caller.userId
|
|
91661
|
+
} });
|
|
91662
|
+
});
|
|
91663
|
+
}
|
|
91664
|
+
removeLink(userId) {
|
|
91665
|
+
return this.serial(async () => {
|
|
91666
|
+
const kept = this.linksRow.linkedAccounts.filter((a) => a.userId !== userId);
|
|
91667
|
+
if (kept.length === this.linksRow.linkedAccounts.length) return;
|
|
91668
|
+
const next = {
|
|
91669
|
+
name: this.linksRow.name,
|
|
91670
|
+
linkedAccounts: kept
|
|
91671
|
+
};
|
|
91672
|
+
await this.stores.links.put({
|
|
91673
|
+
id: this.id,
|
|
91674
|
+
data: next
|
|
91675
|
+
});
|
|
91676
|
+
this.linksRow = next;
|
|
91677
|
+
});
|
|
91678
|
+
}
|
|
91679
|
+
};
|
|
91680
|
+
var GoogleInstanceRegistry = class {
|
|
91681
|
+
stores;
|
|
91682
|
+
logger;
|
|
91683
|
+
makeScenes;
|
|
91684
|
+
loaded = /* @__PURE__ */ new Map();
|
|
91685
|
+
loading = /* @__PURE__ */ new Map();
|
|
91686
|
+
constructor(stores, logger, makeScenes) {
|
|
91687
|
+
this.stores = stores;
|
|
91688
|
+
this.logger = logger;
|
|
91689
|
+
this.makeScenes = makeScenes;
|
|
91690
|
+
}
|
|
91691
|
+
/** The instance, loaded (home, exposure AND links) on first use; null when no such instance. */
|
|
91692
|
+
get(id) {
|
|
91693
|
+
const ready = this.loaded.get(id);
|
|
91694
|
+
if (ready !== void 0) return Promise.resolve(ready);
|
|
91695
|
+
const inFlight = this.loading.get(id);
|
|
91696
|
+
if (inFlight !== void 0) return inFlight;
|
|
91697
|
+
const started = this.load(id).finally(() => {
|
|
91698
|
+
this.loading.delete(id);
|
|
91699
|
+
});
|
|
91700
|
+
this.loading.set(id, started);
|
|
91701
|
+
return started;
|
|
91702
|
+
}
|
|
91703
|
+
/** An instance already loaded; never reads. */
|
|
91704
|
+
peek(id) {
|
|
91705
|
+
return this.loaded.get(id);
|
|
91706
|
+
}
|
|
91707
|
+
async load(id) {
|
|
91708
|
+
const home = await this.stores.homes.get(id);
|
|
91709
|
+
if (home === null) return null;
|
|
91710
|
+
const [exported, links] = await Promise.all([this.stores.exports.get(id), this.stores.links.get(id)]);
|
|
91711
|
+
const instance = new GoogleInstance(id, home.data, exported?.data ?? EMPTY_GOOGLE_EXPORTS, links?.data ?? EMPTY_GOOGLE_LINKS, this.stores, this.logger, this.makeScenes);
|
|
91712
|
+
this.loaded.set(id, instance);
|
|
91713
|
+
return instance;
|
|
91714
|
+
}
|
|
91715
|
+
/** Every instance row, as stored. */
|
|
91716
|
+
async list() {
|
|
91717
|
+
return (await this.stores.homes.query({ limit: INSTANCES_MAX })).records.map((record) => ({
|
|
91718
|
+
id: record.id,
|
|
91719
|
+
body: record.data
|
|
91720
|
+
}));
|
|
91721
|
+
}
|
|
91722
|
+
/** The instance row changed (name, switch): a loaded instance takes it. */
|
|
91723
|
+
async refreshHome(id) {
|
|
91724
|
+
const home = await this.stores.homes.get(id);
|
|
91725
|
+
const instance = this.loaded.get(id);
|
|
91726
|
+
if (home === null) {
|
|
91727
|
+
this.loaded.delete(id);
|
|
91728
|
+
return;
|
|
91729
|
+
}
|
|
91730
|
+
if (instance === void 0) {
|
|
91731
|
+
await this.get(id);
|
|
91732
|
+
return;
|
|
91733
|
+
}
|
|
91734
|
+
instance.applyHome(home.data);
|
|
91735
|
+
}
|
|
91736
|
+
/** The instance is gone: its exposure and links rows go with it, and nothing serves it. */
|
|
91737
|
+
async remove(id) {
|
|
91738
|
+
this.loaded.delete(id);
|
|
91739
|
+
this.loading.delete(id);
|
|
91740
|
+
await this.stores.exports.delete(id);
|
|
91741
|
+
await this.stores.links.delete(id);
|
|
91742
|
+
this.logger.info("export-google: instance deleted with its exposure and links", { meta: { instanceId: id } });
|
|
91743
|
+
}
|
|
91744
|
+
};
|
|
91101
91745
|
//#endregion
|
|
91102
91746
|
//#region src/google-home/trait-catalog.ts
|
|
91103
91747
|
/**
|
|
@@ -91782,11 +92426,17 @@ var OauthVerifiedResultSchema = object({
|
|
|
91782
92426
|
}).nullable();
|
|
91783
92427
|
function buildRoutes(deps) {
|
|
91784
92428
|
return [{
|
|
92429
|
+
method: "POST",
|
|
92430
|
+
path: "/fulfillment/:instanceId",
|
|
92431
|
+
access: "public",
|
|
92432
|
+
description: "Google Home smart-home fulfillment of one instance (SYNC / QUERY / EXECUTE / DISCONNECT)",
|
|
92433
|
+
handler: (req, reply) => handleFulfillmentRequest(req, reply, deps, req.params["instanceId"] ?? "")
|
|
92434
|
+
}, {
|
|
91785
92435
|
method: "POST",
|
|
91786
92436
|
path: "/fulfillment",
|
|
91787
92437
|
access: "public",
|
|
91788
|
-
description:
|
|
91789
|
-
handler: (req, reply) => handleFulfillmentRequest(req, reply, deps)
|
|
92438
|
+
description: `Legacy fulfillment URL: answers for the first instance (${GOOGLE_INSTANCE_ID})`,
|
|
92439
|
+
handler: (req, reply) => handleFulfillmentRequest(req, reply, deps, GOOGLE_INSTANCE_ID)
|
|
91790
92440
|
}];
|
|
91791
92441
|
}
|
|
91792
92442
|
/** Read `Authorization: Bearer <token>` case-insensitively. Node lower-cases
|
|
@@ -91798,7 +92448,7 @@ function readBearer(headers) {
|
|
|
91798
92448
|
}
|
|
91799
92449
|
return null;
|
|
91800
92450
|
}
|
|
91801
|
-
async function handleFulfillmentRequest(request, reply, deps) {
|
|
92451
|
+
async function handleFulfillmentRequest(request, reply, deps, instanceId) {
|
|
91802
92452
|
const bearer = readBearer(request.headers);
|
|
91803
92453
|
if (bearer === null) {
|
|
91804
92454
|
deps.logger.warn("google fulfillment: rejected — no bearer token");
|
|
@@ -91817,84 +92467,19 @@ async function handleFulfillmentRequest(request, reply, deps) {
|
|
|
91817
92467
|
username: verified.data.username,
|
|
91818
92468
|
scopes: verified.data.scopes
|
|
91819
92469
|
};
|
|
91820
|
-
const
|
|
92470
|
+
const lookup = await deps.resolveFulfillment(instanceId);
|
|
92471
|
+
if (!lookup.ok) {
|
|
92472
|
+
deps.logger.warn("google fulfillment: rejected — instance not served", { meta: {
|
|
92473
|
+
instanceId,
|
|
92474
|
+
reason: lookup.code
|
|
92475
|
+
} });
|
|
92476
|
+
reply.code(404).send({ error: lookup.code });
|
|
92477
|
+
return;
|
|
92478
|
+
}
|
|
92479
|
+
const result = await handleFulfillment(request.body, lookup.deps, caller);
|
|
91821
92480
|
reply.code(result.status).send(result.body);
|
|
91822
92481
|
}
|
|
91823
92482
|
//#endregion
|
|
91824
|
-
//#region src/oauth-integration.ts
|
|
91825
|
-
/**
|
|
91826
|
-
* The `export-google` OAuth client — the descriptor behind
|
|
91827
|
-
* `/api/oauth2/authorize?integration=export-google`.
|
|
91828
|
-
*
|
|
91829
|
-
* Shaped exactly like `packages/addon-export-alexa/src/oauth-integration.ts`
|
|
91830
|
-
* and `packages/addon-provider-homeassistant/src/ha-export/oauth-integration.ts`,
|
|
91831
|
-
* which is the claim that file already makes and this one tests: a third
|
|
91832
|
-
* integration is CONFIGURATION, not framework work
|
|
91833
|
-
* ([D101](../../../docs/decisions/adr-0101.md)). Nothing in the kernel learned
|
|
91834
|
-
* the word "Google".
|
|
91835
|
-
*/
|
|
91836
|
-
/**
|
|
91837
|
-
* Where Google lands after consent. Both origins are fixed and public and both
|
|
91838
|
-
* are needed: `oauth-redirect` is production, `oauth-redirect-sandbox` is what
|
|
91839
|
-
* the Actions console uses while the Action is in test mode — which is the ONLY
|
|
91840
|
-
* mode a self-hosted hub will ever be in, since publishing an Action requires
|
|
91841
|
-
* Google certification the operator cannot obtain for a private integration.
|
|
91842
|
-
*
|
|
91843
|
-
* Google appends the project id (`.../r/<project-id>`), so these stay prefixes.
|
|
91844
|
-
*/
|
|
91845
|
-
var GOOGLE_REDIRECT_PREFIXES = ["https://oauth-redirect.googleusercontent.com/r/", "https://oauth-redirect-sandbox.googleusercontent.com/r/"];
|
|
91846
|
-
/**
|
|
91847
|
-
* What a linked Google Home NEEDS — the single meaning `requestedScopes`
|
|
91848
|
-
* carries everywhere (see `oauth-integration.cap.ts`).
|
|
91849
|
-
*
|
|
91850
|
-
* `category:device [view, create]`, and each half is consumed by a named check
|
|
91851
|
-
* in `fulfillment-router.ts`: `view` gates SYNC and QUERY, `create` gates
|
|
91852
|
-
* EXECUTE. It is a category rather than a `capability:` list because the trait
|
|
91853
|
-
* catalog is meant to grow, and a new trait row must not force every operator
|
|
91854
|
-
* to re-link.
|
|
91855
|
-
*
|
|
91856
|
-
* **No `addon:` grant, and that is measured rather than assumed.** The single
|
|
91857
|
-
* hub-side entry point, `POST /addon/export-google/fulfillment`, is
|
|
91858
|
-
* `access: 'public'` and authenticates the token itself via
|
|
91859
|
-
* `oauthVerifyAccessToken`, so it never passes through the
|
|
91860
|
-
* `access: 'authenticated'` gate that [D103](../../../docs/decisions/adr-0103.md)
|
|
91861
|
-
* checks an `addon:` grant on. Same field, same meaning, different routes.
|
|
91862
|
-
*
|
|
91863
|
-
* Google's smart-home account linking is a CONFIDENTIAL client — the client id
|
|
91864
|
-
* and secret live in the Actions console, which is why there is no
|
|
91865
|
-
* `requiresPkce` here. Note that the hub does not verify that secret either
|
|
91866
|
-
* ([D92](../../../docs/decisions/adr-0092.md)); the security of the link rests
|
|
91867
|
-
* on the authorization code and the redirect-prefix allow-list above.
|
|
91868
|
-
*/
|
|
91869
|
-
function buildGoogleOauthIntegration() {
|
|
91870
|
-
return {
|
|
91871
|
-
integrationId: "export-google",
|
|
91872
|
-
displayName: "Google Home",
|
|
91873
|
-
requestedScopes: [{
|
|
91874
|
-
type: "category",
|
|
91875
|
-
target: "device",
|
|
91876
|
-
access: ["view", "create"]
|
|
91877
|
-
}],
|
|
91878
|
-
allowedRedirectPrefixes: [...GOOGLE_REDIRECT_PREFIXES],
|
|
91879
|
-
/**
|
|
91880
|
-
* No expiry, for the reason Alexa's descriptor spells out at length: a
|
|
91881
|
-
* smart-home link is meant to last until the user unlinks it, there is no
|
|
91882
|
-
* unattended re-link, and a 30-day refresh silently kills the integration a
|
|
91883
|
-
* month after setup.
|
|
91884
|
-
*
|
|
91885
|
-
* What bounds a leaked refresh token is revocation, not time — and for THIS
|
|
91886
|
-
* integration revocation bites on the very next call, because the one entry
|
|
91887
|
-
* point (`/fulfillment`) calls `oauthVerifyAccessToken` before doing any
|
|
91888
|
-
* work, and that refuses once the session carries `revokedAt`.
|
|
91889
|
-
*
|
|
91890
|
-
* Google also has its own severing path: `action.devices.DISCONNECT`, which
|
|
91891
|
-
* `fulfillment-router.ts` handles by dropping the linked-account record so
|
|
91892
|
-
* `getStatus` stops claiming the export is live.
|
|
91893
|
-
*/
|
|
91894
|
-
refreshTokenTtlSec: "never"
|
|
91895
|
-
};
|
|
91896
|
-
}
|
|
91897
|
-
//#endregion
|
|
91898
92483
|
//#region src/migrations/drop-public-hub-url.ts
|
|
91899
92484
|
/**
|
|
91900
92485
|
* The hub's public URL is no longer a setting of this addon (D986 §5): Google reads the
|
|
@@ -92018,10 +92603,84 @@ async function planDropMovedExposure(ports) {
|
|
|
92018
92603
|
}] };
|
|
92019
92604
|
}
|
|
92020
92605
|
//#endregion
|
|
92606
|
+
//#region src/migrations/instance-and-links.ts
|
|
92607
|
+
/**
|
|
92608
|
+
* Google becomes a multi-instance exporter (planning#422 P2). Two migrations, both `block-owner`:
|
|
92609
|
+
* the addon must not serve a link ledger it cannot trust, and after them nothing reads the old key.
|
|
92610
|
+
*
|
|
92611
|
+
* 1. `moveInstanceAndLinks` (procedure): the first instance is the `google-homes` row under the
|
|
92612
|
+
* id `export-google`, and the `linkedAccounts` setting becomes the `google-links` row under
|
|
92613
|
+
* the same id. An existing row is never overwritten; a row this pass just wrote is read BACK
|
|
92614
|
+
* and must equal what the settings carried, or the pass throws.
|
|
92615
|
+
* 2. `planDropMovedLinks` (plan): the key is deleted only while the record holds every user the
|
|
92616
|
+
* settings carried; a record that cannot be read leaves the key in place.
|
|
92617
|
+
*/
|
|
92618
|
+
function linksOf(value) {
|
|
92619
|
+
if (!Array.isArray(value)) return [];
|
|
92620
|
+
return value.flatMap((entry) => {
|
|
92621
|
+
const parsed = LinkedAccountSchema.safeParse(entry);
|
|
92622
|
+
return parsed.success ? [parsed.data] : [];
|
|
92623
|
+
});
|
|
92624
|
+
}
|
|
92625
|
+
async function moveInstanceAndLinks(ports) {
|
|
92626
|
+
const stored = await ports.readStored();
|
|
92627
|
+
const hasLinks = MOVED_LINKS_KEY in stored;
|
|
92628
|
+
const linkedAccounts = linksOf(stored[MOVED_LINKS_KEY]);
|
|
92629
|
+
const raw = stored[MOVED_LINKS_KEY];
|
|
92630
|
+
const understood = Array.isArray(raw) ? raw.length : 0;
|
|
92631
|
+
if (understood > linkedAccounts.length) ports.warn(`Google migration: ${understood - linkedAccounts.length} linked account(s) were not understood and are left out`);
|
|
92632
|
+
const home = await ports.putHome({ name: GOOGLE_HOME_NAME });
|
|
92633
|
+
const links = hasLinks ? await ports.putLinks({
|
|
92634
|
+
name: GOOGLE_LINKS_NAME,
|
|
92635
|
+
linkedAccounts
|
|
92636
|
+
}) : "exists";
|
|
92637
|
+
if (await ports.readHome() === null) throw new Error("the Google Home instance row is not there after it was written");
|
|
92638
|
+
if (links === "created") {
|
|
92639
|
+
const held = await ports.readLinks();
|
|
92640
|
+
if (held === null || canonical(held.linkedAccounts) !== canonical(linkedAccounts)) throw new Error("the Google links record does not match the legacy settings; nothing was cleared");
|
|
92641
|
+
}
|
|
92642
|
+
if (home === "exists" && links === "exists") return {
|
|
92643
|
+
outcome: "already-done",
|
|
92644
|
+
summary: { moved: false }
|
|
92645
|
+
};
|
|
92646
|
+
return {
|
|
92647
|
+
outcome: "done",
|
|
92648
|
+
summary: {
|
|
92649
|
+
instance: home === "created",
|
|
92650
|
+
linked: links === "created" ? linkedAccounts.length : 0
|
|
92651
|
+
}
|
|
92652
|
+
};
|
|
92653
|
+
}
|
|
92654
|
+
async function planDropMovedLinks(ports) {
|
|
92655
|
+
const stored = await ports.readStored();
|
|
92656
|
+
if (!("linkedAccounts" in stored)) return { edits: [] };
|
|
92657
|
+
const refuse = (reason) => {
|
|
92658
|
+
ports.warn(`Google migration: the legacy linkedAccounts key is kept: ${reason}`);
|
|
92659
|
+
throw new Error(`the legacy Google linkedAccounts key is not deleted: ${reason}`);
|
|
92660
|
+
};
|
|
92661
|
+
const held = await ports.readLinks();
|
|
92662
|
+
if (held === null) return refuse("no links record exists");
|
|
92663
|
+
const heldUsers = new Set(held.linkedAccounts.map((a) => a.userId));
|
|
92664
|
+
for (const account of linksOf(stored[MOVED_LINKS_KEY])) if (!heldUsers.has(account.userId)) return refuse(`the record lacks the user ${account.userId}`);
|
|
92665
|
+
const id = `${GOOGLE_INSTANCE_ID}.${MOVED_LINKS_KEY}`;
|
|
92666
|
+
return { edits: [{
|
|
92667
|
+
op: "deleteKeys",
|
|
92668
|
+
scope: ADDON_SETTINGS_TABLE,
|
|
92669
|
+
keys: [id],
|
|
92670
|
+
precondition: preconditionOf({ [id]: {
|
|
92671
|
+
addonId: GOOGLE_INSTANCE_ID,
|
|
92672
|
+
key: MOVED_LINKS_KEY,
|
|
92673
|
+
value: stored[MOVED_LINKS_KEY]
|
|
92674
|
+
} })
|
|
92675
|
+
}] };
|
|
92676
|
+
}
|
|
92677
|
+
//#endregion
|
|
92021
92678
|
//#region src/migrations/index.ts
|
|
92022
92679
|
var DROP_PUBLIC_HUB_URL_ID = "export-google/2026-11-02-drop-public-hub-url";
|
|
92023
92680
|
var EXPOSURE_TO_RECORD_ID = "export-google/2026-11-04-exposure-to-record";
|
|
92024
92681
|
var DROP_MOVED_EXPOSURE_ID = "export-google/2026-11-04-drop-moved-exposure";
|
|
92682
|
+
var INSTANCE_AND_LINKS_ID = "export-google/2026-11-04-instance-and-links";
|
|
92683
|
+
var DROP_MOVED_LINKS_ID = "export-google/2026-11-04-drop-moved-links";
|
|
92025
92684
|
var FIXTURE_MARK = "the linked account list the migration does not know";
|
|
92026
92685
|
/** The `export-google` catalogue (D987): offered to the engine when the addon initialises. */
|
|
92027
92686
|
var ADDON_MIGRATIONS = [
|
|
@@ -92072,9 +92731,115 @@ var ADDON_MIGRATIONS = [
|
|
|
92072
92731
|
fixtureMark: FIXTURE_MARK
|
|
92073
92732
|
},
|
|
92074
92733
|
plan: planDropMovedExposure
|
|
92734
|
+
},
|
|
92735
|
+
{
|
|
92736
|
+
meta: {
|
|
92737
|
+
id: INSTANCE_AND_LINKS_ID,
|
|
92738
|
+
owner: "export-google",
|
|
92739
|
+
level: "addon-state",
|
|
92740
|
+
seq: 4,
|
|
92741
|
+
dependsOn: [],
|
|
92742
|
+
store: "settings",
|
|
92743
|
+
scope: "cluster",
|
|
92744
|
+
onFailure: "block-owner",
|
|
92745
|
+
bodyKind: "procedure",
|
|
92746
|
+
description: "Create the first Google Home instance under the id export-google and move the linked accounts into its google-links record; both rows are read back before anything is deleted",
|
|
92747
|
+
fixtureMark: FIXTURE_MARK
|
|
92748
|
+
},
|
|
92749
|
+
procedure: moveInstanceAndLinks
|
|
92750
|
+
},
|
|
92751
|
+
{
|
|
92752
|
+
meta: {
|
|
92753
|
+
id: DROP_MOVED_LINKS_ID,
|
|
92754
|
+
owner: "export-google",
|
|
92755
|
+
level: "addon-state",
|
|
92756
|
+
seq: 5,
|
|
92757
|
+
dependsOn: [INSTANCE_AND_LINKS_ID],
|
|
92758
|
+
store: "settings",
|
|
92759
|
+
scope: "cluster",
|
|
92760
|
+
onFailure: "block-owner",
|
|
92761
|
+
bodyKind: "plan",
|
|
92762
|
+
description: "Delete the linkedAccounts settings key once the google-links record holds what it carried",
|
|
92763
|
+
fixtureMark: FIXTURE_MARK
|
|
92764
|
+
},
|
|
92765
|
+
plan: planDropMovedLinks
|
|
92075
92766
|
}
|
|
92076
92767
|
];
|
|
92077
92768
|
//#endregion
|
|
92769
|
+
//#region src/oauth-integration.ts
|
|
92770
|
+
/**
|
|
92771
|
+
* The `export-google` OAuth client — the descriptor behind
|
|
92772
|
+
* `/api/oauth2/authorize?integration=export-google`.
|
|
92773
|
+
*
|
|
92774
|
+
* Shaped exactly like `packages/addon-export-alexa/src/oauth-integration.ts`
|
|
92775
|
+
* and `packages/addon-provider-homeassistant/src/ha-export/oauth-integration.ts`,
|
|
92776
|
+
* which is the claim that file already makes and this one tests: a third
|
|
92777
|
+
* integration is CONFIGURATION, not framework work
|
|
92778
|
+
* ([D101](../../../docs/decisions/adr-0101.md)). Nothing in the kernel learned
|
|
92779
|
+
* the word "Google".
|
|
92780
|
+
*/
|
|
92781
|
+
/**
|
|
92782
|
+
* Where Google lands after consent. Both origins are fixed and public and both
|
|
92783
|
+
* are needed: `oauth-redirect` is production, `oauth-redirect-sandbox` is what
|
|
92784
|
+
* the Actions console uses while the Action is in test mode — which is the ONLY
|
|
92785
|
+
* mode a self-hosted hub will ever be in, since publishing an Action requires
|
|
92786
|
+
* Google certification the operator cannot obtain for a private integration.
|
|
92787
|
+
*
|
|
92788
|
+
* Google appends the project id (`.../r/<project-id>`), so these stay prefixes.
|
|
92789
|
+
*/
|
|
92790
|
+
var GOOGLE_REDIRECT_PREFIXES = ["https://oauth-redirect.googleusercontent.com/r/", "https://oauth-redirect-sandbox.googleusercontent.com/r/"];
|
|
92791
|
+
/**
|
|
92792
|
+
* What a linked Google Home NEEDS — the single meaning `requestedScopes`
|
|
92793
|
+
* carries everywhere (see `oauth-integration.cap.ts`).
|
|
92794
|
+
*
|
|
92795
|
+
* `category:device [view, create]`, and each half is consumed by a named check
|
|
92796
|
+
* in `fulfillment-router.ts`: `view` gates SYNC and QUERY, `create` gates
|
|
92797
|
+
* EXECUTE. It is a category rather than a `capability:` list because the trait
|
|
92798
|
+
* catalog is meant to grow, and a new trait row must not force every operator
|
|
92799
|
+
* to re-link.
|
|
92800
|
+
*
|
|
92801
|
+
* **No `addon:` grant, and that is measured rather than assumed.** The single
|
|
92802
|
+
* hub-side entry point, `POST /addon/export-google/fulfillment`, is
|
|
92803
|
+
* `access: 'public'` and authenticates the token itself via
|
|
92804
|
+
* `oauthVerifyAccessToken`, so it never passes through the
|
|
92805
|
+
* `access: 'authenticated'` gate that [D103](../../../docs/decisions/adr-0103.md)
|
|
92806
|
+
* checks an `addon:` grant on. Same field, same meaning, different routes.
|
|
92807
|
+
*
|
|
92808
|
+
* Google's smart-home account linking is a CONFIDENTIAL client — the client id
|
|
92809
|
+
* and secret live in the Actions console, which is why there is no
|
|
92810
|
+
* `requiresPkce` here. Note that the hub does not verify that secret either
|
|
92811
|
+
* ([D92](../../../docs/decisions/adr-0092.md)); the security of the link rests
|
|
92812
|
+
* on the authorization code and the redirect-prefix allow-list above.
|
|
92813
|
+
*/
|
|
92814
|
+
function buildGoogleOauthIntegration() {
|
|
92815
|
+
return {
|
|
92816
|
+
integrationId: "export-google",
|
|
92817
|
+
displayName: "Google Home",
|
|
92818
|
+
requestedScopes: [{
|
|
92819
|
+
type: "category",
|
|
92820
|
+
target: "device",
|
|
92821
|
+
access: ["view", "create"]
|
|
92822
|
+
}],
|
|
92823
|
+
allowedRedirectPrefixes: [...GOOGLE_REDIRECT_PREFIXES],
|
|
92824
|
+
/**
|
|
92825
|
+
* No expiry, for the reason Alexa's descriptor spells out at length: a
|
|
92826
|
+
* smart-home link is meant to last until the user unlinks it, there is no
|
|
92827
|
+
* unattended re-link, and a 30-day refresh silently kills the integration a
|
|
92828
|
+
* month after setup.
|
|
92829
|
+
*
|
|
92830
|
+
* What bounds a leaked refresh token is revocation, not time — and for THIS
|
|
92831
|
+
* integration revocation bites on the very next call, because the one entry
|
|
92832
|
+
* point (`/fulfillment`) calls `oauthVerifyAccessToken` before doing any
|
|
92833
|
+
* work, and that refuses once the session carries `revokedAt`.
|
|
92834
|
+
*
|
|
92835
|
+
* Google also has its own severing path: `action.devices.DISCONNECT`, which
|
|
92836
|
+
* `fulfillment-router.ts` handles by dropping the linked-account record so
|
|
92837
|
+
* `getStatus` stops claiming the export is live.
|
|
92838
|
+
*/
|
|
92839
|
+
refreshTokenTtlSec: "never"
|
|
92840
|
+
};
|
|
92841
|
+
}
|
|
92842
|
+
//#endregion
|
|
92078
92843
|
//#region src/public-endpoint.ts
|
|
92079
92844
|
/** The typed refusal when the role resolves to nothing. */
|
|
92080
92845
|
var NO_PUBLIC_ENDPOINT_REASON = {
|
|
@@ -92114,6 +92879,7 @@ var buildConsoleSetupFromRole = async (input) => {
|
|
|
92114
92879
|
}]
|
|
92115
92880
|
};
|
|
92116
92881
|
const origin = result.origin;
|
|
92882
|
+
const fulfillmentPath = input.instanceId === void 0 ? `/addon/${input.addonId}/fulfillment` : `/addon/${input.addonId}/fulfillment/${input.instanceId}`;
|
|
92117
92883
|
return {
|
|
92118
92884
|
note: [
|
|
92119
92885
|
"In the Google Home Developer Console create a cloud-to-cloud integration, then paste these three URLs.",
|
|
@@ -92124,7 +92890,7 @@ var buildConsoleSetupFromRole = async (input) => {
|
|
|
92124
92890
|
fields: [
|
|
92125
92891
|
{
|
|
92126
92892
|
label: "Fulfillment URL",
|
|
92127
|
-
value: `${origin}
|
|
92893
|
+
value: `${origin}${fulfillmentPath}`
|
|
92128
92894
|
},
|
|
92129
92895
|
{
|
|
92130
92896
|
label: "Authorization URL",
|
|
@@ -92143,7 +92909,7 @@ var buildConsoleSetupFromRole = async (input) => {
|
|
|
92143
92909
|
};
|
|
92144
92910
|
//#endregion
|
|
92145
92911
|
//#region src/types.ts
|
|
92146
|
-
var DEFAULT_SETTINGS = {
|
|
92912
|
+
var DEFAULT_SETTINGS = {};
|
|
92147
92913
|
//#endregion
|
|
92148
92914
|
//#region src/export-google.addon.ts
|
|
92149
92915
|
/**
|
|
@@ -92151,9 +92917,14 @@ var DEFAULT_SETTINGS = { linkedAccounts: [] };
|
|
|
92151
92917
|
*
|
|
92152
92918
|
* Architecture:
|
|
92153
92919
|
*
|
|
92154
|
-
* Google Home / Assistant --HTTPS--> POST /addon/export-google/fulfillment
|
|
92920
|
+
* Google Home / Assistant --HTTPS--> POST /addon/export-google/fulfillment/<instanceId>
|
|
92155
92921
|
* (hub Fastify → addon-routes cap)
|
|
92156
92922
|
*
|
|
92923
|
+
* The addon is MULTI-instance (planning#422): every Actions-console project is one
|
|
92924
|
+
* `integration-instances` row of the `google-homes` kind with its own exposure and its own
|
|
92925
|
+
* link ledger. The first instance keeps the id `export-google`, so the legacy
|
|
92926
|
+
* `/fulfillment` URL still answers for it. One OAuth client serves every instance.
|
|
92927
|
+
*
|
|
92157
92928
|
* There is no cloud function in the middle. Google's smart-home platform calls
|
|
92158
92929
|
* the fulfillment URL the operator configured, so the hub answers directly —
|
|
92159
92930
|
* a shorter path than Alexa's, which needs an operator-owned Lambda because
|
|
@@ -92161,7 +92932,8 @@ var DEFAULT_SETTINGS = { linkedAccounts: [] };
|
|
|
92161
92932
|
*
|
|
92162
92933
|
* Capabilities registered:
|
|
92163
92934
|
* - `device-export` — the operator picks which devices Google sees.
|
|
92164
|
-
* - `addon-routes` — mounts `/addon/export-google/fulfillment`.
|
|
92935
|
+
* - `addon-routes` — mounts `/addon/export-google/fulfillment[/<instanceId>]`.
|
|
92936
|
+
* - `integration-instances` — the Google Home instances (role `services`).
|
|
92165
92937
|
* - `oauth-integration` — declares this addon a linkable client of the
|
|
92166
92938
|
* hub's core `/api/oauth2/*` server.
|
|
92167
92939
|
*
|
|
@@ -92183,36 +92955,27 @@ var DEFAULT_SETTINGS = { linkedAccounts: [] };
|
|
|
92183
92955
|
* decides, so widening scope is one row.
|
|
92184
92956
|
*/
|
|
92185
92957
|
var ADDON_ID = "export-google";
|
|
92958
|
+
/** The per-device toggle key: `google:<instanceId>:<deviceId>:enabled`. */
|
|
92959
|
+
var DEVICE_KEY = /^google:([^:]+):(\d+):enabled$/;
|
|
92960
|
+
var deviceKey = (instanceId, deviceId) => `google:${instanceId}:${deviceId}:enabled`;
|
|
92186
92961
|
var ExportGoogleAddon = class extends BaseAddon {
|
|
92187
92962
|
gateway = null;
|
|
92188
|
-
|
|
92189
|
-
|
|
92190
|
-
|
|
92191
|
-
* path needs. No settings key backs it.
|
|
92192
|
-
*/
|
|
92193
|
-
exportsRow = EMPTY_GOOGLE_EXPORTS;
|
|
92194
|
-
exportsHandle = null;
|
|
92195
|
-
get exposedDevices() {
|
|
92196
|
-
return this.exportsRow.devices;
|
|
92197
|
-
}
|
|
92198
|
-
/** Persist a change of the exposure: the record first, the in-memory copy after it landed. */
|
|
92199
|
-
async writeExports(patch) {
|
|
92200
|
-
const handle = this.exportsHandle;
|
|
92201
|
-
if (handle === null) throw new Error("export-google: the exposure record is not open");
|
|
92202
|
-
const next = {
|
|
92203
|
-
name: this.exportsRow.name,
|
|
92204
|
-
devices: patch.devices ?? this.exportsRow.devices,
|
|
92205
|
-
actions: patch.actions ?? this.exportsRow.actions
|
|
92206
|
-
};
|
|
92207
|
-
await handle.put({
|
|
92208
|
-
id: GOOGLE_INSTANCE_ID,
|
|
92209
|
-
data: next
|
|
92210
|
-
});
|
|
92211
|
-
this.exportsRow = next;
|
|
92212
|
-
}
|
|
92963
|
+
registry = null;
|
|
92964
|
+
instances = null;
|
|
92965
|
+
fulfillments = /* @__PURE__ */ new WeakMap();
|
|
92213
92966
|
constructor() {
|
|
92214
92967
|
super({ ...DEFAULT_SETTINGS });
|
|
92215
92968
|
}
|
|
92969
|
+
requireRegistry() {
|
|
92970
|
+
if (this.registry === null) throw new Error("export-google: addon not initialized");
|
|
92971
|
+
return this.registry;
|
|
92972
|
+
}
|
|
92973
|
+
/** The instance or a typed refusal naming it: a device-export call never guesses one. */
|
|
92974
|
+
async requireInstance(instanceId) {
|
|
92975
|
+
const instance = await this.requireRegistry().get(instanceId);
|
|
92976
|
+
if (instance === null) throw new ExportInstanceUnknownError(ADDON_ID, instanceId);
|
|
92977
|
+
return instance;
|
|
92978
|
+
}
|
|
92216
92979
|
async onInitialize() {
|
|
92217
92980
|
const gateway = createApiDeviceGateway({
|
|
92218
92981
|
api: this.ctx.api,
|
|
@@ -92221,9 +92984,53 @@ var ExportGoogleAddon = class extends BaseAddon {
|
|
|
92221
92984
|
this.gateway = gateway;
|
|
92222
92985
|
const records = this.ctx.records;
|
|
92223
92986
|
if (records === void 0) throw new Error("export-google needs ctx.records — check execution.placement (hub-only)");
|
|
92224
|
-
await records.declare({
|
|
92225
|
-
|
|
92226
|
-
|
|
92987
|
+
await records.declare({
|
|
92988
|
+
"google-homes": googleHomesKind,
|
|
92989
|
+
"google-exports": googleExportsKind,
|
|
92990
|
+
"google-links": googleLinksKind
|
|
92991
|
+
});
|
|
92992
|
+
const stores = {
|
|
92993
|
+
homes: records.kind(googleHomesKind),
|
|
92994
|
+
exports: records.kind(googleExportsKind),
|
|
92995
|
+
links: records.kind(googleLinksKind)
|
|
92996
|
+
};
|
|
92997
|
+
const registry = new GoogleInstanceRegistry(stores, this.ctx.logger, (persist, initial) => new ActionSceneExports({
|
|
92998
|
+
api: this.ctx.api,
|
|
92999
|
+
logger: this.ctx.logger,
|
|
93000
|
+
isAdminUser: async (userId) => {
|
|
93001
|
+
return (await this.ctx.api.userManagement.listUsers.query()).some((u) => u.id === userId && u.isAdmin);
|
|
93002
|
+
},
|
|
93003
|
+
persist
|
|
93004
|
+
}, initial));
|
|
93005
|
+
this.registry = registry;
|
|
93006
|
+
this.instances = new RecordIntegrationInstances(records, googleHomesKind, {
|
|
93007
|
+
description: {
|
|
93008
|
+
role: "services",
|
|
93009
|
+
instanceMode: "multiple",
|
|
93010
|
+
kind: "homes",
|
|
93011
|
+
canTest: false
|
|
93012
|
+
},
|
|
93013
|
+
formSchema: (id) => this.homeForm(id),
|
|
93014
|
+
initialBody: (name) => ({ name }),
|
|
93015
|
+
mintId: () => `google-home-${(0, node_crypto.randomUUID)().slice(0, 8)}`,
|
|
93016
|
+
health: (body, id) => {
|
|
93017
|
+
if (body.enabled === false) return { status: {
|
|
93018
|
+
state: "off",
|
|
93019
|
+
label: "Off"
|
|
93020
|
+
} };
|
|
93021
|
+
const linked = registry.peek(id)?.linkedAccounts.length;
|
|
93022
|
+
if (linked === void 0) return { status: { state: "unknown" } };
|
|
93023
|
+
return linked > 0 ? { status: {
|
|
93024
|
+
state: "ok",
|
|
93025
|
+
label: `${linked} linked account(s)`
|
|
93026
|
+
} } : { status: {
|
|
93027
|
+
state: "unknown",
|
|
93028
|
+
label: "Not linked yet"
|
|
93029
|
+
} };
|
|
93030
|
+
},
|
|
93031
|
+
configured: () => true,
|
|
93032
|
+
onChanged: (id, change) => this.onInstanceChanged(id, change)
|
|
93033
|
+
});
|
|
92227
93034
|
await this.runMigrations(defineAddonMigrations(ADDON_MIGRATIONS, {
|
|
92228
93035
|
readStored: async () => this.resolveGlobalStore(),
|
|
92229
93036
|
warn: (message) => {
|
|
@@ -92233,9 +93040,9 @@ var ExportGoogleAddon = class extends BaseAddon {
|
|
|
92233
93040
|
} });
|
|
92234
93041
|
},
|
|
92235
93042
|
putExports: async (body) => {
|
|
92236
|
-
if (await
|
|
93043
|
+
if (await stores.exports.get("export-google") !== null) return "exists";
|
|
92237
93044
|
try {
|
|
92238
|
-
await
|
|
93045
|
+
await stores.exports.put({
|
|
92239
93046
|
id: GOOGLE_INSTANCE_ID,
|
|
92240
93047
|
data: body
|
|
92241
93048
|
}, { ifRev: 0 });
|
|
@@ -92245,108 +93052,55 @@ var ExportGoogleAddon = class extends BaseAddon {
|
|
|
92245
93052
|
}
|
|
92246
93053
|
return "created";
|
|
92247
93054
|
},
|
|
92248
|
-
readExports: async () => (await
|
|
92249
|
-
|
|
92250
|
-
|
|
92251
|
-
|
|
92252
|
-
|
|
92253
|
-
|
|
92254
|
-
|
|
92255
|
-
|
|
92256
|
-
|
|
92257
|
-
|
|
92258
|
-
|
|
92259
|
-
|
|
92260
|
-
|
|
92261
|
-
});
|
|
92262
|
-
const ownInstance = (instanceId) => assertOwnExportInstance("export-google", ADDON_ID, instanceId);
|
|
92263
|
-
const deviceExportProvider = {
|
|
92264
|
-
getStatus: async (input) => {
|
|
92265
|
-
ownInstance(statusInstanceOf(input));
|
|
92266
|
-
return {
|
|
92267
|
-
linkState: this.config.linkedAccounts.length > 0 ? "linked" : "unlinked",
|
|
92268
|
-
exposedDeviceCount: this.exposedDevices.length,
|
|
92269
|
-
setup: await this.buildSetupBlock()
|
|
92270
|
-
};
|
|
92271
|
-
},
|
|
92272
|
-
listInstances: async () => [{
|
|
92273
|
-
instanceId: ADDON_ID,
|
|
92274
|
-
name: "Google Home",
|
|
92275
|
-
enabled: true,
|
|
92276
|
-
kind: "google-home"
|
|
92277
|
-
}],
|
|
92278
|
-
listSupportedDeviceKinds: async ({ instanceId }) => {
|
|
92279
|
-
ownInstance(instanceId);
|
|
92280
|
-
return [...SUPPORTED_DEVICE_KINDS];
|
|
92281
|
-
},
|
|
92282
|
-
listExposedDevices: async ({ instanceId }) => {
|
|
92283
|
-
ownInstance(instanceId);
|
|
92284
|
-
return this.exposedDevices.map((entry) => ({ deviceId: String(entry.deviceId) }));
|
|
92285
|
-
},
|
|
92286
|
-
exposeDevice: async ({ instanceId, deviceId }) => {
|
|
92287
|
-
ownInstance(instanceId);
|
|
92288
|
-
return this.exposeDevice(deviceId);
|
|
92289
|
-
},
|
|
92290
|
-
unexposeDevice: async ({ instanceId, deviceId }) => {
|
|
92291
|
-
ownInstance(instanceId);
|
|
92292
|
-
return this.unexposeDevice(deviceId);
|
|
92293
|
-
},
|
|
92294
|
-
listSupportedEntityKinds: async () => ["device", "action"],
|
|
92295
|
-
listExposedEntities: async ({ instanceId }) => {
|
|
92296
|
-
ownInstance(instanceId);
|
|
92297
|
-
await actionScenes.reconcile();
|
|
92298
|
-
return [...this.exposedDevices.map((entry) => ({ entity: {
|
|
92299
|
-
kind: "device",
|
|
92300
|
-
deviceId: String(entry.deviceId)
|
|
92301
|
-
} })), ...actionScenes.list()];
|
|
92302
|
-
},
|
|
92303
|
-
exposeEntity: async ({ instanceId, entity }) => {
|
|
92304
|
-
ownInstance(instanceId);
|
|
92305
|
-
if (entity.kind === "device") return this.exposeDevice(entity.deviceId);
|
|
92306
|
-
if (entity.kind === "action") return actionScenes.expose(entity.actionId);
|
|
92307
|
-
throw new Error("export-google: a notification target cannot be exported to Google Home");
|
|
93055
|
+
readExports: async () => (await stores.exports.get("export-google"))?.data ?? null,
|
|
93056
|
+
putHome: async (body) => {
|
|
93057
|
+
if (await stores.homes.get("export-google") !== null) return "exists";
|
|
93058
|
+
try {
|
|
93059
|
+
await stores.homes.put({
|
|
93060
|
+
id: GOOGLE_INSTANCE_ID,
|
|
93061
|
+
data: body
|
|
93062
|
+
}, { ifRev: 0 });
|
|
93063
|
+
} catch (err) {
|
|
93064
|
+
if (err instanceof RevConflictError) return "exists";
|
|
93065
|
+
throw err;
|
|
93066
|
+
}
|
|
93067
|
+
return "created";
|
|
92308
93068
|
},
|
|
92309
|
-
|
|
92310
|
-
|
|
92311
|
-
|
|
92312
|
-
|
|
92313
|
-
|
|
93069
|
+
putLinks: async (body) => {
|
|
93070
|
+
if (await stores.links.get("export-google") !== null) return "exists";
|
|
93071
|
+
try {
|
|
93072
|
+
await stores.links.put({
|
|
93073
|
+
id: GOOGLE_INSTANCE_ID,
|
|
93074
|
+
data: body
|
|
93075
|
+
}, { ifRev: 0 });
|
|
93076
|
+
} catch (err) {
|
|
93077
|
+
if (err instanceof RevConflictError) return "exists";
|
|
93078
|
+
throw err;
|
|
93079
|
+
}
|
|
93080
|
+
return "created";
|
|
92314
93081
|
},
|
|
92315
|
-
|
|
92316
|
-
|
|
92317
|
-
|
|
92318
|
-
|
|
93082
|
+
readHome: async () => (await stores.homes.get("export-google"))?.data ?? null,
|
|
93083
|
+
readLinks: async () => (await stores.links.get("export-google"))?.data ?? null
|
|
93084
|
+
}));
|
|
93085
|
+
for (const row of await registry.list()) {
|
|
93086
|
+
const instance = await registry.get(row.id);
|
|
93087
|
+
if (instance === null) continue;
|
|
93088
|
+
instance.scenes.reconcile().catch((err) => {
|
|
93089
|
+
this.ctx.logger.warn("export-google: action scene reconcile at boot failed", { meta: {
|
|
93090
|
+
instanceId: instance.id,
|
|
93091
|
+
error: errMsg$1(err)
|
|
93092
|
+
} });
|
|
93093
|
+
});
|
|
93094
|
+
}
|
|
93095
|
+
const deviceExportProvider = this.buildDeviceExportProvider();
|
|
92319
93096
|
const routeProvider = buildAddonRouteProvider(ADDON_ID, buildRoutes({
|
|
92320
93097
|
ctx: this.ctx,
|
|
92321
93098
|
logger: this.ctx.logger,
|
|
92322
|
-
|
|
92323
|
-
logger: this.ctx.logger,
|
|
92324
|
-
sync: {
|
|
92325
|
-
gateway,
|
|
92326
|
-
logger: this.ctx.logger,
|
|
92327
|
-
listExposed: () => this.exposedDevices.map((entry) => entry.deviceId),
|
|
92328
|
-
actions: actionScenes
|
|
92329
|
-
},
|
|
92330
|
-
query: {
|
|
92331
|
-
gateway,
|
|
92332
|
-
logger: this.ctx.logger,
|
|
92333
|
-
isExposed: (deviceId) => this.isExposed(deviceId),
|
|
92334
|
-
actions: actionScenes
|
|
92335
|
-
},
|
|
92336
|
-
execute: {
|
|
92337
|
-
gateway,
|
|
92338
|
-
logger: this.ctx.logger,
|
|
92339
|
-
isExposed: (deviceId) => this.isExposed(deviceId),
|
|
92340
|
-
actions: actionScenes
|
|
92341
|
-
},
|
|
92342
|
-
recordLink: (caller) => this.recordLink(caller),
|
|
92343
|
-
removeLink: (userId) => this.removeLink(userId)
|
|
92344
|
-
}
|
|
93099
|
+
resolveFulfillment: (instanceId) => this.resolveFulfillment(instanceId)
|
|
92345
93100
|
}));
|
|
92346
93101
|
const oauthIntegrationProvider = { getDescriptor: async () => buildGoogleOauthIntegration() };
|
|
92347
93102
|
this.ctx.logger.info("export-google: initialized", { meta: {
|
|
92348
|
-
|
|
92349
|
-
linkedAccounts: this.config.linkedAccounts.length,
|
|
93103
|
+
instances: (await registry.list()).length,
|
|
92350
93104
|
willReportState: false
|
|
92351
93105
|
} });
|
|
92352
93106
|
return [
|
|
@@ -92361,16 +93115,151 @@ var ExportGoogleAddon = class extends BaseAddon {
|
|
|
92361
93115
|
{
|
|
92362
93116
|
capability: oauthIntegrationCapability,
|
|
92363
93117
|
provider: oauthIntegrationProvider
|
|
93118
|
+
},
|
|
93119
|
+
{
|
|
93120
|
+
capability: integrationInstancesCapability,
|
|
93121
|
+
provider: this.instances.toProvider()
|
|
92364
93122
|
}
|
|
92365
93123
|
];
|
|
92366
93124
|
}
|
|
92367
93125
|
async onShutdown() {
|
|
92368
93126
|
this.gateway = null;
|
|
93127
|
+
this.registry = null;
|
|
92369
93128
|
}
|
|
92370
|
-
|
|
92371
|
-
|
|
93129
|
+
async onInstanceChanged(id, change) {
|
|
93130
|
+
const registry = this.requireRegistry();
|
|
93131
|
+
if (change === "deleted") await registry.remove(id);
|
|
93132
|
+
else if (change === "created") await registry.get(id);
|
|
93133
|
+
else await registry.refreshHome(id);
|
|
92372
93134
|
}
|
|
92373
|
-
|
|
93135
|
+
homeForm(id) {
|
|
93136
|
+
const target = id === null ? "<instance id>" : id;
|
|
93137
|
+
return this.schema({ sections: [{
|
|
93138
|
+
id: ADDON_ID,
|
|
93139
|
+
title: "Connection",
|
|
93140
|
+
description: "Publishes switches, dimmable lights, locks and covers to Google Home. The hub answers Google directly — no cloud function, and no Google credential is stored here.",
|
|
93141
|
+
columns: 1,
|
|
93142
|
+
fields: [{
|
|
93143
|
+
type: "info",
|
|
93144
|
+
key: "__google-setup-banner",
|
|
93145
|
+
label: "Setup overview",
|
|
93146
|
+
variant: "info",
|
|
93147
|
+
content: [
|
|
93148
|
+
"This hub must be reachable from the public internet over HTTPS (Cloudflare Tunnel, Tailscale Funnel, …) — Google calls the fulfillment URL from its own cloud.",
|
|
93149
|
+
`Create a cloud-to-cloud integration in the Google Home Developer Console, paste the three URLs from the Export panel (the fulfillment URL ends in /fulfillment/${target}), and link your account from the Home app.`,
|
|
93150
|
+
"Each Google Home instance is one Actions-console project with its own devices and linked accounts.",
|
|
93151
|
+
"Cameras are not exported, and state is not pushed: Google polls. Ask \"Hey Google, sync my devices\" after exposing something new."
|
|
93152
|
+
].join("\n")
|
|
93153
|
+
}]
|
|
93154
|
+
}] });
|
|
93155
|
+
}
|
|
93156
|
+
async resolveFulfillment(instanceId) {
|
|
93157
|
+
const instance = await this.requireRegistry().get(instanceId);
|
|
93158
|
+
if (instance === null) return {
|
|
93159
|
+
ok: false,
|
|
93160
|
+
code: "unknown_instance"
|
|
93161
|
+
};
|
|
93162
|
+
if (!instance.enabled) return {
|
|
93163
|
+
ok: false,
|
|
93164
|
+
code: "instance_disabled"
|
|
93165
|
+
};
|
|
93166
|
+
return {
|
|
93167
|
+
ok: true,
|
|
93168
|
+
deps: this.fulfillmentFor(instance)
|
|
93169
|
+
};
|
|
93170
|
+
}
|
|
93171
|
+
/** The fulfillment wiring of ONE instance: its exposure, its links, nobody else's. */
|
|
93172
|
+
fulfillmentFor(instance) {
|
|
93173
|
+
const cached = this.fulfillments.get(instance);
|
|
93174
|
+
if (cached !== void 0) return cached;
|
|
93175
|
+
const gateway = this.requireGateway();
|
|
93176
|
+
const logger = this.ctx.logger;
|
|
93177
|
+
const deps = {
|
|
93178
|
+
logger,
|
|
93179
|
+
sync: {
|
|
93180
|
+
gateway,
|
|
93181
|
+
logger,
|
|
93182
|
+
listExposed: () => instance.devices.map((entry) => entry.deviceId),
|
|
93183
|
+
actions: instance.scenes
|
|
93184
|
+
},
|
|
93185
|
+
query: {
|
|
93186
|
+
gateway,
|
|
93187
|
+
logger,
|
|
93188
|
+
isExposed: (deviceId) => instance.isExposed(deviceId),
|
|
93189
|
+
actions: instance.scenes
|
|
93190
|
+
},
|
|
93191
|
+
execute: {
|
|
93192
|
+
gateway,
|
|
93193
|
+
logger,
|
|
93194
|
+
isExposed: (deviceId) => instance.isExposed(deviceId),
|
|
93195
|
+
actions: instance.scenes
|
|
93196
|
+
},
|
|
93197
|
+
recordLink: (caller) => instance.recordLink(caller),
|
|
93198
|
+
removeLink: (userId) => instance.removeLink(userId)
|
|
93199
|
+
};
|
|
93200
|
+
this.fulfillments.set(instance, deps);
|
|
93201
|
+
return deps;
|
|
93202
|
+
}
|
|
93203
|
+
buildDeviceExportProvider() {
|
|
93204
|
+
return {
|
|
93205
|
+
getStatus: async (input) => {
|
|
93206
|
+
const requested = statusInstanceOf(input);
|
|
93207
|
+
const rows = await this.requireRegistry().list();
|
|
93208
|
+
const target = requested ?? rows[0]?.id;
|
|
93209
|
+
if (target === void 0) return {
|
|
93210
|
+
linkState: "unlinked",
|
|
93211
|
+
exposedDeviceCount: 0,
|
|
93212
|
+
setup: await this.buildSetupBlock(void 0, 0)
|
|
93213
|
+
};
|
|
93214
|
+
const instance = await this.requireInstance(target);
|
|
93215
|
+
return {
|
|
93216
|
+
linkState: instance.linkedAccounts.length > 0 ? "linked" : "unlinked",
|
|
93217
|
+
exposedDeviceCount: instance.devices.length,
|
|
93218
|
+
setup: await this.buildSetupBlock(instance.id, instance.linkedAccounts.length)
|
|
93219
|
+
};
|
|
93220
|
+
},
|
|
93221
|
+
listInstances: async () => (await this.requireRegistry().list()).map((row) => ({
|
|
93222
|
+
instanceId: row.id,
|
|
93223
|
+
name: row.body.name,
|
|
93224
|
+
enabled: row.body.enabled !== false,
|
|
93225
|
+
kind: "google-home"
|
|
93226
|
+
})),
|
|
93227
|
+
listSupportedDeviceKinds: async ({ instanceId }) => {
|
|
93228
|
+
await this.requireInstance(instanceId ?? "export-google");
|
|
93229
|
+
return [...SUPPORTED_DEVICE_KINDS];
|
|
93230
|
+
},
|
|
93231
|
+
listExposedDevices: async ({ instanceId }) => {
|
|
93232
|
+
return (await this.requireInstance(instanceId ?? "export-google")).devices.map((entry) => ({ deviceId: String(entry.deviceId) }));
|
|
93233
|
+
},
|
|
93234
|
+
exposeDevice: async ({ instanceId, deviceId }) => this.exposeDevice(await this.requireInstance(instanceId ?? "export-google"), deviceId),
|
|
93235
|
+
unexposeDevice: async ({ instanceId, deviceId }) => this.unexposeDevice(await this.requireInstance(instanceId ?? "export-google"), deviceId),
|
|
93236
|
+
listSupportedEntityKinds: async () => ["device", "action"],
|
|
93237
|
+
listExposedEntities: async ({ instanceId }) => {
|
|
93238
|
+
const instance = await this.requireInstance(instanceId ?? "export-google");
|
|
93239
|
+
await instance.scenes.reconcile();
|
|
93240
|
+
return [...instance.devices.map((entry) => ({ entity: {
|
|
93241
|
+
kind: "device",
|
|
93242
|
+
deviceId: String(entry.deviceId)
|
|
93243
|
+
} })), ...instance.scenes.list()];
|
|
93244
|
+
},
|
|
93245
|
+
exposeEntity: async ({ instanceId, entity }) => {
|
|
93246
|
+
const instance = await this.requireInstance(instanceId ?? "export-google");
|
|
93247
|
+
if (entity.kind === "device") return this.exposeDevice(instance, entity.deviceId);
|
|
93248
|
+
if (entity.kind === "action") return instance.scenes.expose(entity.actionId);
|
|
93249
|
+
throw new Error("export-google: a notification target cannot be exported to Google Home");
|
|
93250
|
+
},
|
|
93251
|
+
unexposeEntity: async ({ instanceId, entity }) => {
|
|
93252
|
+
const instance = await this.requireInstance(instanceId ?? "export-google");
|
|
93253
|
+
if (entity.kind === "device") return this.unexposeDevice(instance, entity.deviceId);
|
|
93254
|
+
if (entity.kind === "action") return instance.scenes.unexpose(entity.actionId);
|
|
93255
|
+
throw new Error("export-google: a notification target cannot be exported to Google Home");
|
|
93256
|
+
},
|
|
93257
|
+
getDeviceSettingsContribution: (input) => this.buildDeviceSettingsContribution(Number(input.deviceId)),
|
|
93258
|
+
getDeviceLiveContribution: async () => null,
|
|
93259
|
+
applyDeviceSettingsPatch: (input) => this.applyDeviceSettingsPatch(Number(input.deviceId), input.patch)
|
|
93260
|
+
};
|
|
93261
|
+
}
|
|
93262
|
+
async exposeDevice(instance, deviceIdRaw) {
|
|
92374
93263
|
const deviceId = Number.parseInt(deviceIdRaw, 10);
|
|
92375
93264
|
if (!Number.isFinite(deviceId)) throw new Error(`export-google: deviceId must be numeric — got "${deviceIdRaw}"`);
|
|
92376
93265
|
const facts = await this.requireGateway().loadFacts(deviceId).catch((err) => {
|
|
@@ -92381,47 +93270,38 @@ var ExportGoogleAddon = class extends BaseAddon {
|
|
|
92381
93270
|
this.ctx.logger.warn("export-google: refused to expose — no exported capability", {
|
|
92382
93271
|
tags: { deviceId },
|
|
92383
93272
|
meta: {
|
|
93273
|
+
instanceId: instance.id,
|
|
92384
93274
|
deviceType: facts.deviceType,
|
|
92385
93275
|
capNames: facts.capNames
|
|
92386
93276
|
}
|
|
92387
93277
|
});
|
|
92388
93278
|
throw new Error(`export-google: device ${deviceId} has no capability this addon exports (bound: ${facts.capNames.join(", ") || "none"})`);
|
|
92389
93279
|
}
|
|
92390
|
-
const next =
|
|
92391
|
-
|
|
93280
|
+
const next = instance.devices.filter((e) => e.deviceId !== deviceId);
|
|
93281
|
+
await instance.writeExports({ devices: [...next, {
|
|
92392
93282
|
deviceId,
|
|
92393
93283
|
exposedAt: Date.now()
|
|
93284
|
+
}] });
|
|
93285
|
+
this.ctx.logger.info("export-google: exposed device — visible after the next Google SYNC (\"Hey Google, sync my devices\")", {
|
|
93286
|
+
tags: { deviceId },
|
|
93287
|
+
meta: { instanceId: instance.id }
|
|
92394
93288
|
});
|
|
92395
|
-
await this.writeExports({ devices: next });
|
|
92396
|
-
this.ctx.logger.info("export-google: exposed device — visible after the next Google SYNC (\"Hey Google, sync my devices\")", { tags: { deviceId } });
|
|
92397
93289
|
}
|
|
92398
|
-
async unexposeDevice(deviceIdRaw) {
|
|
93290
|
+
async unexposeDevice(instance, deviceIdRaw) {
|
|
92399
93291
|
const deviceId = Number.parseInt(deviceIdRaw, 10);
|
|
92400
93292
|
if (!Number.isFinite(deviceId)) return;
|
|
92401
|
-
const next =
|
|
92402
|
-
if (next.length ===
|
|
92403
|
-
await
|
|
92404
|
-
this.ctx.logger.info("export-google: unexposed device — removed from Google on its next SYNC", {
|
|
93293
|
+
const next = instance.devices.filter((e) => e.deviceId !== deviceId);
|
|
93294
|
+
if (next.length === instance.devices.length) return;
|
|
93295
|
+
await instance.writeExports({ devices: next });
|
|
93296
|
+
this.ctx.logger.info("export-google: unexposed device — removed from Google on its next SYNC", {
|
|
93297
|
+
tags: { deviceId },
|
|
93298
|
+
meta: { instanceId: instance.id }
|
|
93299
|
+
});
|
|
92405
93300
|
}
|
|
92406
93301
|
requireGateway() {
|
|
92407
93302
|
if (this.gateway === null) throw new Error("export-google: addon not initialized");
|
|
92408
93303
|
return this.gateway;
|
|
92409
93304
|
}
|
|
92410
|
-
async recordLink(caller) {
|
|
92411
|
-
if (this.config.linkedAccounts.some((account) => account.userId === caller.userId)) return;
|
|
92412
|
-
const next = [...this.config.linkedAccounts, {
|
|
92413
|
-
userId: caller.userId,
|
|
92414
|
-
username: caller.username,
|
|
92415
|
-
linkedAt: Date.now()
|
|
92416
|
-
}];
|
|
92417
|
-
await this.updateGlobalSettings({ linkedAccounts: next });
|
|
92418
|
-
this.ctx.logger.info("export-google: recorded linked account", { meta: { userId: caller.userId } });
|
|
92419
|
-
}
|
|
92420
|
-
async removeLink(userId) {
|
|
92421
|
-
const next = this.config.linkedAccounts.filter((account) => account.userId !== userId);
|
|
92422
|
-
if (next.length === this.config.linkedAccounts.length) return;
|
|
92423
|
-
await this.updateGlobalSettings({ linkedAccounts: next });
|
|
92424
|
-
}
|
|
92425
93305
|
/**
|
|
92426
93306
|
* The three URLs the operator pastes into the Actions console, plus the
|
|
92427
93307
|
* linked-account count.
|
|
@@ -92431,88 +93311,85 @@ var ExportGoogleAddon = class extends BaseAddon {
|
|
|
92431
93311
|
* value still travels in the `getStatus` response — so it would be the wrong
|
|
92432
93312
|
* tool for a real credential anyway (docs/decisions/adr-0269-a-google-export-that-holds-no-google-credential.md).
|
|
92433
93313
|
*/
|
|
92434
|
-
async buildSetupBlock() {
|
|
93314
|
+
async buildSetupBlock(instanceId, linkedAccounts) {
|
|
92435
93315
|
return buildConsoleSetupFromRole({
|
|
92436
93316
|
addonId: ADDON_ID,
|
|
92437
|
-
|
|
93317
|
+
...instanceId !== void 0 ? { instanceId } : {},
|
|
93318
|
+
linkedAccounts,
|
|
92438
93319
|
read: () => this.ctx.api.localNetwork.getAddresses.query()
|
|
92439
93320
|
});
|
|
92440
93321
|
}
|
|
92441
|
-
globalSettingsSchema() {
|
|
92442
|
-
return this.schema({ sections: [{
|
|
92443
|
-
id: ADDON_ID,
|
|
92444
|
-
title: "Connection",
|
|
92445
|
-
description: "Publishes switches, dimmable lights, locks and covers to Google Home. The hub answers Google directly — no cloud function, and no Google credential is stored here.",
|
|
92446
|
-
columns: 1,
|
|
92447
|
-
fields: [{
|
|
92448
|
-
type: "info",
|
|
92449
|
-
key: "__google-setup-banner",
|
|
92450
|
-
label: "Setup overview",
|
|
92451
|
-
variant: "info",
|
|
92452
|
-
content: [
|
|
92453
|
-
"This hub must be reachable from the public internet over HTTPS (Cloudflare Tunnel, Tailscale Funnel, …) — Google calls the fulfillment URL from its own cloud.",
|
|
92454
|
-
"Create a cloud-to-cloud integration in the Google Home Developer Console, paste the three URLs from the Export panel, and link your account from the Home app.",
|
|
92455
|
-
"Cameras are not exported, and state is not pushed: Google polls. Ask \"Hey Google, sync my devices\" after exposing something new."
|
|
92456
|
-
].join("\n")
|
|
92457
|
-
}]
|
|
92458
|
-
}] });
|
|
92459
|
-
}
|
|
92460
93322
|
/**
|
|
92461
|
-
* Per-device "Export" panel. Offered only for devices this
|
|
92462
|
-
* represent — a toggle on a camera would be a switch that promises
|
|
92463
|
-
* `buildSyncDevice` then refuses.
|
|
93323
|
+
* Per-device "Export" panel: one section per enabled instance. Offered only for devices this
|
|
93324
|
+
* addon can actually represent — a toggle on a camera would be a switch that promises
|
|
93325
|
+
* something `buildSyncDevice` then refuses.
|
|
92464
93326
|
*/
|
|
92465
93327
|
async buildDeviceSettingsContribution(deviceId) {
|
|
92466
93328
|
const facts = await this.requireGateway().loadFacts(deviceId).catch(() => null);
|
|
92467
93329
|
if (facts === null) return null;
|
|
92468
93330
|
const descriptors = traitsForCaps(facts.capNames);
|
|
92469
93331
|
if (descriptors.length === 0) return null;
|
|
92470
|
-
const
|
|
92471
|
-
const
|
|
92472
|
-
const
|
|
92473
|
-
|
|
92474
|
-
|
|
92475
|
-
|
|
92476
|
-
|
|
92477
|
-
|
|
92478
|
-
|
|
92479
|
-
|
|
92480
|
-
|
|
92481
|
-
|
|
92482
|
-
title: "Google Home Export",
|
|
93332
|
+
const registry = this.requireRegistry();
|
|
93333
|
+
const rows = (await registry.list()).filter((row) => row.body.enabled !== false);
|
|
93334
|
+
const sections = [];
|
|
93335
|
+
for (const row of rows) {
|
|
93336
|
+
const instance = await registry.get(row.id);
|
|
93337
|
+
if (instance === null) continue;
|
|
93338
|
+
const enabled = instance.isExposed(deviceId);
|
|
93339
|
+
const linked = instance.linkedAccounts.length;
|
|
93340
|
+
const statusLabel = enabled ? `Exposed as ${descriptors.map((d) => d.trait.replace("action.devices.traits.", "")).join(" + ")}${linked > 0 ? `, ${linked} linked Google account(s)` : " (no linked Google account yet)"}` : "Not exposed";
|
|
93341
|
+
sections.push({
|
|
93342
|
+
id: `${ADDON_ID}:${instance.id}`,
|
|
93343
|
+
title: rows.length === 1 ? "Google Home Export" : `Google Home Export — ${instance.name}`,
|
|
92483
93344
|
description: "Surface this device to the linked Google Home account.",
|
|
92484
93345
|
tab: "export",
|
|
92485
93346
|
columns: 1,
|
|
92486
|
-
order: 30,
|
|
93347
|
+
order: 30 + sections.length,
|
|
92487
93348
|
fields: [{
|
|
92488
93349
|
type: "info",
|
|
92489
|
-
key:
|
|
93350
|
+
key: `__google-status:${instance.id}`,
|
|
92490
93351
|
label: "Status",
|
|
92491
|
-
content:
|
|
93352
|
+
content: statusLabel,
|
|
92492
93353
|
variant: "info"
|
|
92493
93354
|
}, {
|
|
92494
93355
|
type: "boolean",
|
|
92495
|
-
key:
|
|
93356
|
+
key: deviceKey(instance.id, deviceId),
|
|
92496
93357
|
label: "Expose to Google Home",
|
|
92497
93358
|
description: "Google picks the change up on its next sync — say \"Hey Google, sync my devices\" to force one.",
|
|
92498
93359
|
style: "switch",
|
|
92499
93360
|
value: enabled,
|
|
92500
93361
|
immediate: true
|
|
92501
93362
|
}]
|
|
92502
|
-
}
|
|
93363
|
+
});
|
|
93364
|
+
}
|
|
93365
|
+
if (sections.length === 0) return null;
|
|
93366
|
+
return {
|
|
93367
|
+
tabs: [{
|
|
93368
|
+
id: "export",
|
|
93369
|
+
label: "Export",
|
|
93370
|
+
icon: "share-2",
|
|
93371
|
+
order: 80
|
|
93372
|
+
}],
|
|
93373
|
+
sections
|
|
92503
93374
|
};
|
|
92504
93375
|
}
|
|
92505
93376
|
async applyDeviceSettingsPatch(deviceId, patch) {
|
|
92506
|
-
const
|
|
92507
|
-
|
|
92508
|
-
|
|
92509
|
-
|
|
92510
|
-
|
|
92511
|
-
|
|
93377
|
+
for (const [key, next] of Object.entries(patch)) {
|
|
93378
|
+
const match = DEVICE_KEY.exec(key);
|
|
93379
|
+
if (match === null || Number(match[2]) !== deviceId) continue;
|
|
93380
|
+
const instanceId = match[1] ?? "";
|
|
93381
|
+
if (typeof next !== "boolean") {
|
|
93382
|
+
this.ctx.logger.warn("export-google: ignored export toggle — value was not a boolean", {
|
|
93383
|
+
tags: { deviceId },
|
|
93384
|
+
meta: { instanceId }
|
|
93385
|
+
});
|
|
93386
|
+
continue;
|
|
93387
|
+
}
|
|
93388
|
+
const instance = await this.requireInstance(instanceId);
|
|
93389
|
+
if (next === instance.isExposed(deviceId)) continue;
|
|
93390
|
+
if (next) await this.exposeDevice(instance, String(deviceId));
|
|
93391
|
+
else await this.unexposeDevice(instance, String(deviceId));
|
|
92512
93392
|
}
|
|
92513
|
-
if (next === this.isExposed(deviceId)) return { success: true };
|
|
92514
|
-
if (next) await this.exposeDevice(String(deviceId));
|
|
92515
|
-
else await this.unexposeDevice(String(deviceId));
|
|
92516
93393
|
return { success: true };
|
|
92517
93394
|
}
|
|
92518
93395
|
};
|