@camstack/addon-export-alexa 1.2.179 → 1.2.181
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 +13 -0
- package/dist/export-alexa.addon.js +2161 -300
- package/dist/export-alexa.addon.mjs +2161 -300
- package/package.json +5 -2
|
@@ -791,7 +791,7 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
|
|
|
791
791
|
return EventCategory;
|
|
792
792
|
}({});
|
|
793
793
|
//#endregion
|
|
794
|
-
//#region ../types/dist/device-type-
|
|
794
|
+
//#region ../types/dist/device-type-D1fH5kaC.mjs
|
|
795
795
|
/**
|
|
796
796
|
import { errMsg } from '@camstack/types'
|
|
797
797
|
* Extract a human-readable message from an unknown error value.
|
|
@@ -1022,6 +1022,12 @@ var DeviceFeature = /* @__PURE__ */ function(DeviceFeature) {
|
|
|
1022
1022
|
DeviceFeature["MediaPlayerPrevious"] = "media-player-previous";
|
|
1023
1023
|
/** Media player exposes stop distinct from pause. */
|
|
1024
1024
|
DeviceFeature["MediaPlayerStop"] = "media-player-stop";
|
|
1025
|
+
/** Media player exposes volume up / down in steps (an infrared TV has no level). */
|
|
1026
|
+
DeviceFeature["MediaPlayerVolumeStep"] = "media-player-volume-step";
|
|
1027
|
+
/** Media player exposes channel up / down in steps. */
|
|
1028
|
+
DeviceFeature["MediaPlayerChannelStep"] = "media-player-channel-step";
|
|
1029
|
+
/** Media player exposes power on / off. */
|
|
1030
|
+
DeviceFeature["MediaPlayerPower"] = "media-player-power";
|
|
1025
1031
|
/** Alarm panel requires a PIN code on arm/disarm. */
|
|
1026
1032
|
DeviceFeature["AlarmPinRequired"] = "alarm-pin-required";
|
|
1027
1033
|
/** Presence device carries GPS coordinates (lat/lng/accuracy) in
|
|
@@ -4558,6 +4564,12 @@ var numberProcessor = (schema, ctx, _json, _params) => {
|
|
|
4558
4564
|
var booleanProcessor = (_schema, _ctx, json, _params) => {
|
|
4559
4565
|
json.type = "boolean";
|
|
4560
4566
|
};
|
|
4567
|
+
var bigintProcessor = (_schema, ctx, _json, _params) => {
|
|
4568
|
+
if (ctx.unrepresentable === "throw") throw new Error("BigInt cannot be represented in JSON Schema");
|
|
4569
|
+
};
|
|
4570
|
+
var symbolProcessor = (_schema, ctx, _json, _params) => {
|
|
4571
|
+
if (ctx.unrepresentable === "throw") throw new Error("Symbols cannot be represented in JSON Schema");
|
|
4572
|
+
};
|
|
4561
4573
|
var nullProcessor = (_schema, ctx, json, _params) => {
|
|
4562
4574
|
if (ctx.target === "openapi-3.0") {
|
|
4563
4575
|
json.type = "string";
|
|
@@ -4565,12 +4577,17 @@ var nullProcessor = (_schema, ctx, json, _params) => {
|
|
|
4565
4577
|
json.enum = [null];
|
|
4566
4578
|
} else json.type = "null";
|
|
4567
4579
|
};
|
|
4580
|
+
var undefinedProcessor = (_schema, ctx, _json, _params) => {
|
|
4581
|
+
if (ctx.unrepresentable === "throw") throw new Error("Undefined cannot be represented in JSON Schema");
|
|
4582
|
+
};
|
|
4568
4583
|
var voidProcessor = (_schema, ctx, _json, _params) => {
|
|
4569
4584
|
if (ctx.unrepresentable === "throw") throw new Error("Void cannot be represented in JSON Schema");
|
|
4570
4585
|
};
|
|
4571
4586
|
var neverProcessor = (_schema, _ctx, json, _params) => {
|
|
4572
4587
|
json.not = {};
|
|
4573
4588
|
};
|
|
4589
|
+
var anyProcessor = (_schema, _ctx, _json, _params) => {};
|
|
4590
|
+
var unknownProcessor = (_schema, _ctx, _json, _params) => {};
|
|
4574
4591
|
var dateProcessor = (_schema, ctx, _json, _params) => {
|
|
4575
4592
|
if (ctx.unrepresentable === "throw") throw new Error("Date cannot be represented in JSON Schema");
|
|
4576
4593
|
};
|
|
@@ -4602,12 +4619,53 @@ var literalProcessor = (schema, ctx, json, _params) => {
|
|
|
4602
4619
|
json.enum = vals;
|
|
4603
4620
|
}
|
|
4604
4621
|
};
|
|
4622
|
+
var nanProcessor = (_schema, ctx, _json, _params) => {
|
|
4623
|
+
if (ctx.unrepresentable === "throw") throw new Error("NaN cannot be represented in JSON Schema");
|
|
4624
|
+
};
|
|
4625
|
+
var templateLiteralProcessor = (schema, _ctx, json, _params) => {
|
|
4626
|
+
const _json = json;
|
|
4627
|
+
const pattern = schema._zod.pattern;
|
|
4628
|
+
if (!pattern) throw new Error("Pattern not found in template literal");
|
|
4629
|
+
_json.type = "string";
|
|
4630
|
+
_json.pattern = pattern.source;
|
|
4631
|
+
};
|
|
4632
|
+
var fileProcessor = (schema, _ctx, json, _params) => {
|
|
4633
|
+
const _json = json;
|
|
4634
|
+
const file = {
|
|
4635
|
+
type: "string",
|
|
4636
|
+
format: "binary",
|
|
4637
|
+
contentEncoding: "binary"
|
|
4638
|
+
};
|
|
4639
|
+
const { minimum, maximum, mime } = schema._zod.bag;
|
|
4640
|
+
if (minimum !== void 0) file.minLength = minimum;
|
|
4641
|
+
if (maximum !== void 0) file.maxLength = maximum;
|
|
4642
|
+
if (mime) if (mime.length === 1) {
|
|
4643
|
+
file.contentMediaType = mime[0];
|
|
4644
|
+
Object.assign(_json, file);
|
|
4645
|
+
} else {
|
|
4646
|
+
Object.assign(_json, file);
|
|
4647
|
+
_json.anyOf = mime.map((m) => ({ contentMediaType: m }));
|
|
4648
|
+
}
|
|
4649
|
+
else Object.assign(_json, file);
|
|
4650
|
+
};
|
|
4651
|
+
var successProcessor = (_schema, _ctx, json, _params) => {
|
|
4652
|
+
json.type = "boolean";
|
|
4653
|
+
};
|
|
4605
4654
|
var customProcessor = (_schema, ctx, _json, _params) => {
|
|
4606
4655
|
if (ctx.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema");
|
|
4607
4656
|
};
|
|
4657
|
+
var functionProcessor = (_schema, ctx, _json, _params) => {
|
|
4658
|
+
if (ctx.unrepresentable === "throw") throw new Error("Function types cannot be represented in JSON Schema");
|
|
4659
|
+
};
|
|
4608
4660
|
var transformProcessor = (_schema, ctx, _json, _params) => {
|
|
4609
4661
|
if (ctx.unrepresentable === "throw") throw new Error("Transforms cannot be represented in JSON Schema");
|
|
4610
4662
|
};
|
|
4663
|
+
var mapProcessor = (_schema, ctx, _json, _params) => {
|
|
4664
|
+
if (ctx.unrepresentable === "throw") throw new Error("Map cannot be represented in JSON Schema");
|
|
4665
|
+
};
|
|
4666
|
+
var setProcessor = (_schema, ctx, _json, _params) => {
|
|
4667
|
+
if (ctx.unrepresentable === "throw") throw new Error("Set cannot be represented in JSON Schema");
|
|
4668
|
+
};
|
|
4611
4669
|
var arrayProcessor = (schema, ctx, _json, params) => {
|
|
4612
4670
|
const json = _json;
|
|
4613
4671
|
const def = schema._zod.def;
|
|
@@ -4812,6 +4870,12 @@ var readonlyProcessor = (schema, ctx, json, params) => {
|
|
|
4812
4870
|
seen.ref = def.innerType;
|
|
4813
4871
|
json.readOnly = true;
|
|
4814
4872
|
};
|
|
4873
|
+
var promiseProcessor = (schema, ctx, _json, params) => {
|
|
4874
|
+
const def = schema._zod.def;
|
|
4875
|
+
process$1(def.innerType, ctx, params);
|
|
4876
|
+
const seen = ctx.seen.get(schema);
|
|
4877
|
+
seen.ref = def.innerType;
|
|
4878
|
+
};
|
|
4815
4879
|
var optionalProcessor = (schema, ctx, _json, params) => {
|
|
4816
4880
|
const def = schema._zod.def;
|
|
4817
4881
|
process$1(def.innerType, ctx, params);
|
|
@@ -4824,6 +4888,81 @@ var lazyProcessor = (schema, ctx, _json, params) => {
|
|
|
4824
4888
|
const seen = ctx.seen.get(schema);
|
|
4825
4889
|
seen.ref = innerType;
|
|
4826
4890
|
};
|
|
4891
|
+
var allProcessors = {
|
|
4892
|
+
string: stringProcessor,
|
|
4893
|
+
number: numberProcessor,
|
|
4894
|
+
boolean: booleanProcessor,
|
|
4895
|
+
bigint: bigintProcessor,
|
|
4896
|
+
symbol: symbolProcessor,
|
|
4897
|
+
null: nullProcessor,
|
|
4898
|
+
undefined: undefinedProcessor,
|
|
4899
|
+
void: voidProcessor,
|
|
4900
|
+
never: neverProcessor,
|
|
4901
|
+
any: anyProcessor,
|
|
4902
|
+
unknown: unknownProcessor,
|
|
4903
|
+
date: dateProcessor,
|
|
4904
|
+
enum: enumProcessor,
|
|
4905
|
+
literal: literalProcessor,
|
|
4906
|
+
nan: nanProcessor,
|
|
4907
|
+
template_literal: templateLiteralProcessor,
|
|
4908
|
+
file: fileProcessor,
|
|
4909
|
+
success: successProcessor,
|
|
4910
|
+
custom: customProcessor,
|
|
4911
|
+
function: functionProcessor,
|
|
4912
|
+
transform: transformProcessor,
|
|
4913
|
+
map: mapProcessor,
|
|
4914
|
+
set: setProcessor,
|
|
4915
|
+
array: arrayProcessor,
|
|
4916
|
+
object: objectProcessor,
|
|
4917
|
+
union: unionProcessor,
|
|
4918
|
+
intersection: intersectionProcessor,
|
|
4919
|
+
tuple: tupleProcessor,
|
|
4920
|
+
record: recordProcessor,
|
|
4921
|
+
nullable: nullableProcessor,
|
|
4922
|
+
nonoptional: nonoptionalProcessor,
|
|
4923
|
+
default: defaultProcessor,
|
|
4924
|
+
prefault: prefaultProcessor,
|
|
4925
|
+
catch: catchProcessor,
|
|
4926
|
+
pipe: pipeProcessor,
|
|
4927
|
+
readonly: readonlyProcessor,
|
|
4928
|
+
promise: promiseProcessor,
|
|
4929
|
+
optional: optionalProcessor,
|
|
4930
|
+
lazy: lazyProcessor
|
|
4931
|
+
};
|
|
4932
|
+
function toJSONSchema(input, params) {
|
|
4933
|
+
if ("_idmap" in input) {
|
|
4934
|
+
const registry = input;
|
|
4935
|
+
const ctx = initializeContext({
|
|
4936
|
+
...params,
|
|
4937
|
+
processors: allProcessors
|
|
4938
|
+
});
|
|
4939
|
+
const defs = {};
|
|
4940
|
+
for (const entry of registry._idmap.entries()) {
|
|
4941
|
+
const [_, schema] = entry;
|
|
4942
|
+
process$1(schema, ctx);
|
|
4943
|
+
}
|
|
4944
|
+
const schemas = {};
|
|
4945
|
+
ctx.external = {
|
|
4946
|
+
registry,
|
|
4947
|
+
uri: params?.uri,
|
|
4948
|
+
defs
|
|
4949
|
+
};
|
|
4950
|
+
for (const entry of registry._idmap.entries()) {
|
|
4951
|
+
const [key, schema] = entry;
|
|
4952
|
+
extractDefs(ctx, schema);
|
|
4953
|
+
schemas[key] = finalize(ctx, schema);
|
|
4954
|
+
}
|
|
4955
|
+
if (Object.keys(defs).length > 0) schemas.__shared = { [ctx.target === "draft-2020-12" ? "$defs" : "definitions"]: defs };
|
|
4956
|
+
return { schemas };
|
|
4957
|
+
}
|
|
4958
|
+
const ctx = initializeContext({
|
|
4959
|
+
...params,
|
|
4960
|
+
processors: allProcessors
|
|
4961
|
+
});
|
|
4962
|
+
process$1(input, ctx);
|
|
4963
|
+
extractDefs(ctx, input);
|
|
4964
|
+
return finalize(ctx, input);
|
|
4965
|
+
}
|
|
4827
4966
|
//#endregion
|
|
4828
4967
|
//#region ../../node_modules/zod/v4/classic/iso.js
|
|
4829
4968
|
var ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
|
|
@@ -5848,7 +5987,7 @@ var ZodIssueCode = {
|
|
|
5848
5987
|
var ZodFirstPartyTypeKind;
|
|
5849
5988
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
5850
5989
|
//#endregion
|
|
5851
|
-
//#region ../types/dist/sleep-
|
|
5990
|
+
//#region ../types/dist/sleep-DV4qxEyD.mjs
|
|
5852
5991
|
/**
|
|
5853
5992
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
5854
5993
|
* window to float samples (D455).
|
|
@@ -5927,6 +6066,22 @@ function buildAlawTable() {
|
|
|
5927
6066
|
}
|
|
5928
6067
|
buildUlawTable();
|
|
5929
6068
|
buildAlawTable();
|
|
6069
|
+
/**
|
|
6070
|
+
* An addon whose own migrations did not apply refuses to initialise (D987). The error is typed
|
|
6071
|
+
* so a runner hosting several addons can tell "this addon is blocked" from a crash and keep its
|
|
6072
|
+
* co-located siblings running. Recognised by NAME and shape, never `instanceof`: a forked addon
|
|
6073
|
+
* bundles its own copy of this module, so the class the runner sees is not the one that threw.
|
|
6074
|
+
*/
|
|
6075
|
+
var MIGRATIONS_BLOCKED_ERROR_NAME = "AddonMigrationsBlockedError";
|
|
6076
|
+
var AddonMigrationsBlockedError = class extends Error {
|
|
6077
|
+
/** The ledger ids that did not apply and block the owner. */
|
|
6078
|
+
migrationIds;
|
|
6079
|
+
constructor(migrationIds) {
|
|
6080
|
+
super(`migration(s) ${migrationIds.join(", ")} did not apply and block this addon — fix or retry them (migrations.retry), then restart it`);
|
|
6081
|
+
this.name = MIGRATIONS_BLOCKED_ERROR_NAME;
|
|
6082
|
+
this.migrationIds = migrationIds;
|
|
6083
|
+
}
|
|
6084
|
+
};
|
|
5930
6085
|
/** Is this field's stored value a credential? */
|
|
5931
6086
|
function isSecretConfigField(field) {
|
|
5932
6087
|
if (field.type === "password") return true;
|
|
@@ -5980,9 +6135,16 @@ function isSecretMarker(value) {
|
|
|
5980
6135
|
const ref = value["$secret"];
|
|
5981
6136
|
return typeof ref === "string" && ref.length > 0;
|
|
5982
6137
|
}
|
|
6138
|
+
/** Anything carrying a `$secret` key — a stored marker or a UI view of one. */
|
|
6139
|
+
function isSecretMarkerLike(value) {
|
|
6140
|
+
return isRecord$7(value) && Object.prototype.hasOwnProperty.call(value, "$secret");
|
|
6141
|
+
}
|
|
5983
6142
|
function isSecretClear(value) {
|
|
5984
6143
|
return isRecord$7(value) && value["$secretClear"] === true;
|
|
5985
6144
|
}
|
|
6145
|
+
function isSecretFieldView(value) {
|
|
6146
|
+
return isRecord$7(value) && value["set"] === true && isSecretMarkerLike(value);
|
|
6147
|
+
}
|
|
5986
6148
|
/**
|
|
5987
6149
|
* The UI view of a stored secret field value: a marker becomes "set", inline
|
|
5988
6150
|
* plaintext becomes "set (inline)", nothing becomes `null`. A value never
|
|
@@ -6632,11 +6794,36 @@ function projectStore(store, perNodeKeys, nodeId) {
|
|
|
6632
6794
|
}
|
|
6633
6795
|
return out;
|
|
6634
6796
|
}
|
|
6797
|
+
/**
|
|
6798
|
+
* The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
|
|
6799
|
+
*
|
|
6800
|
+
* A ref is DETERMINISTIC from where the value lives — the owner addon, the
|
|
6801
|
+
* scope (global, one node, one device, one integration, one row of a business
|
|
6802
|
+
* collection) and the field path inside that scope — so saving the same field
|
|
6803
|
+
* twice updates the same ref, and the ref itself says which settings blob
|
|
6804
|
+
* points at it. It is also the AAD of the value's ciphertext: a ciphertext
|
|
6805
|
+
* copied onto another ref does not decrypt.
|
|
6806
|
+
*
|
|
6807
|
+
* Array items are addressed by ITEM ID, never by index
|
|
6808
|
+
* (`providers[authentik].clientSecret`), so reordering a list keeps every ref.
|
|
6809
|
+
*
|
|
6810
|
+
* Pure and browser-safe: no node builtins, no I/O.
|
|
6811
|
+
*/
|
|
6812
|
+
/** The URI scheme of every keychain ref. */
|
|
6813
|
+
var SECRET_REF_SCHEME = "secret://";
|
|
6635
6814
|
var GLOBAL_SCOPE = { kind: "global" };
|
|
6636
6815
|
/** The scope every addon-wide (not per-node, not per-device) setting lives in. */
|
|
6637
6816
|
function globalSecretScope() {
|
|
6638
6817
|
return GLOBAL_SCOPE;
|
|
6639
6818
|
}
|
|
6819
|
+
/**
|
|
6820
|
+
* An addon id as a ref owner. A hub in-process builtin's context id is
|
|
6821
|
+
* `addon:<id>`; the owner of its secrets is `<id>`, exactly as for the same
|
|
6822
|
+
* addon running forked.
|
|
6823
|
+
*/
|
|
6824
|
+
function normalizeSecretOwner(addonId) {
|
|
6825
|
+
return addonId.startsWith("addon:") ? addonId.slice(6) : addonId;
|
|
6826
|
+
}
|
|
6640
6827
|
function encodeSegment(value) {
|
|
6641
6828
|
return encodeURIComponent(value);
|
|
6642
6829
|
}
|
|
@@ -6647,6 +6834,16 @@ function decodeSegment(value) {
|
|
|
6647
6834
|
return null;
|
|
6648
6835
|
}
|
|
6649
6836
|
}
|
|
6837
|
+
/** The scope as it appears inside a ref (`global`, `node/<id>`, …). */
|
|
6838
|
+
function formatSecretScope(scope) {
|
|
6839
|
+
switch (scope.kind) {
|
|
6840
|
+
case "global": return "global";
|
|
6841
|
+
case "node": return `node/${encodeSegment(scope.nodeId)}`;
|
|
6842
|
+
case "device": return `device/${scope.deviceId}`;
|
|
6843
|
+
case "integration": return `integration/${encodeSegment(scope.integrationId)}`;
|
|
6844
|
+
case "row": return `row/${encodeSegment(scope.collection)}/${encodeSegment(scope.rowId)}`;
|
|
6845
|
+
}
|
|
6846
|
+
}
|
|
6650
6847
|
/**
|
|
6651
6848
|
* The field path of a value inside an array item, addressed by the item's id:
|
|
6652
6849
|
* `arrayItemFieldPath('providers', 'authentik', 'clientSecret')` →
|
|
@@ -6655,6 +6852,13 @@ function decodeSegment(value) {
|
|
|
6655
6852
|
function arrayItemFieldPath(arrayKey, itemId, fieldKey) {
|
|
6656
6853
|
return `${arrayKey}[${encodeSegment(itemId)}].${fieldKey}`;
|
|
6657
6854
|
}
|
|
6855
|
+
/** Build a ref. Throws on an empty owner or field path — both are bugs. */
|
|
6856
|
+
function buildSecretRef(parts) {
|
|
6857
|
+
const owner = normalizeSecretOwner(parts.owner);
|
|
6858
|
+
if (owner.length === 0) throw new Error("buildSecretRef: owner is empty");
|
|
6859
|
+
if (parts.fieldPath.length === 0) throw new Error("buildSecretRef: fieldPath is empty");
|
|
6860
|
+
return `${SECRET_REF_SCHEME}${encodeSegment(owner)}/${formatSecretScope(parts.scope)}/${parts.fieldPath}`;
|
|
6861
|
+
}
|
|
6658
6862
|
function parseScope(segments) {
|
|
6659
6863
|
switch (segments[0]) {
|
|
6660
6864
|
case "global": return {
|
|
@@ -6795,7 +6999,7 @@ async function writeMembers(ctx, children, incoming, stored, pathOf) {
|
|
|
6795
6999
|
for (const [member, node] of children) applyMember(out, member, await writeNode(ctx, node, incoming[member], stored[member], pathOf(member)), stored);
|
|
6796
7000
|
return out;
|
|
6797
7001
|
}
|
|
6798
|
-
function rowId(row, idKey) {
|
|
7002
|
+
function rowId$1(row, idKey) {
|
|
6799
7003
|
const raw = row[idKey];
|
|
6800
7004
|
if (typeof raw === "string" && raw.length > 0) return raw;
|
|
6801
7005
|
if (typeof raw === "number" && Number.isFinite(raw)) return String(raw);
|
|
@@ -6812,7 +7016,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
6812
7016
|
}
|
|
6813
7017
|
const storedById = /* @__PURE__ */ new Map();
|
|
6814
7018
|
for (const row of storedRows) {
|
|
6815
|
-
const id = rowId(row, node.idKey);
|
|
7019
|
+
const id = rowId$1(row, node.idKey);
|
|
6816
7020
|
if (id !== null) storedById.set(id, row);
|
|
6817
7021
|
}
|
|
6818
7022
|
const kept = /* @__PURE__ */ new Set();
|
|
@@ -6822,13 +7026,13 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
6822
7026
|
rows.push(row);
|
|
6823
7027
|
continue;
|
|
6824
7028
|
}
|
|
6825
|
-
const id = rowId(row, node.idKey) ?? ctx.mintId();
|
|
7029
|
+
const id = rowId$1(row, node.idKey) ?? ctx.mintId();
|
|
6826
7030
|
kept.add(id);
|
|
6827
7031
|
const withId = {
|
|
6828
7032
|
...row,
|
|
6829
7033
|
[node.idKey]: row[node.idKey] ?? id
|
|
6830
7034
|
};
|
|
6831
|
-
if (rowId(withId, node.idKey) === null) withId[node.idKey] = id;
|
|
7035
|
+
if (rowId$1(withId, node.idKey) === null) withId[node.idKey] = id;
|
|
6832
7036
|
const storedRow = storedById.get(id) ?? {};
|
|
6833
7037
|
rows.push(await writeMembers(ctx, node.item, withId, storedRow, (member) => arrayItemFieldPath(fieldPath, id, member)));
|
|
6834
7038
|
}
|
|
@@ -7580,7 +7784,7 @@ var BaseAddon = class {
|
|
|
7580
7784
|
startMigration: (input) => api.startMigration.mutate(input),
|
|
7581
7785
|
finishMigration: (input) => api.finishMigration.mutate(input)
|
|
7582
7786
|
}, migrations, this.ctx.logger);
|
|
7583
|
-
if (report.blockOwner.length > 0) throw new
|
|
7787
|
+
if (report.blockOwner.length > 0) throw new AddonMigrationsBlockedError(report.blockOwner);
|
|
7584
7788
|
return report;
|
|
7585
7789
|
}
|
|
7586
7790
|
/**
|
|
@@ -7920,6 +8124,10 @@ var BaseAddon = class {
|
|
|
7920
8124
|
const stored = keychain ? await this.readAddonStoreWithRetry() : {};
|
|
7921
8125
|
const patch = {};
|
|
7922
8126
|
for (const key of keys) {
|
|
8127
|
+
if (tree.get(key)?.kind === "array") {
|
|
8128
|
+
patch[key] = [];
|
|
8129
|
+
continue;
|
|
8130
|
+
}
|
|
7923
8131
|
const keychainStored = tree.has(key) || collectSecretMarkerRefs(stored[key]).length > 0;
|
|
7924
8132
|
patch[key] = keychain && keychainStored ? SECRET_CLEAR : "";
|
|
7925
8133
|
}
|
|
@@ -8559,6 +8767,45 @@ function normalizeAddonInitResult(result) {
|
|
|
8559
8767
|
if (Array.isArray(result)) return { providers: result };
|
|
8560
8768
|
return result;
|
|
8561
8769
|
}
|
|
8770
|
+
var PREFIX$1 = "records/";
|
|
8771
|
+
/** The base of every records failure. `detail` is the human part of the message. */
|
|
8772
|
+
var RecordsError = class extends Error {
|
|
8773
|
+
code;
|
|
8774
|
+
detail;
|
|
8775
|
+
constructor(code, detail) {
|
|
8776
|
+
super(`${PREFIX$1}${code}: ${detail}`);
|
|
8777
|
+
this.name = "RecordsError";
|
|
8778
|
+
this.code = code;
|
|
8779
|
+
this.detail = detail;
|
|
8780
|
+
}
|
|
8781
|
+
};
|
|
8782
|
+
/** A write guarded by `ifRev` found another revision (or an existing row for `ifRev: 0`). */
|
|
8783
|
+
var RevConflictError = class extends RecordsError {
|
|
8784
|
+
constructor(detail) {
|
|
8785
|
+
super("rev-conflict", detail);
|
|
8786
|
+
this.name = "RevConflictError";
|
|
8787
|
+
}
|
|
8788
|
+
};
|
|
8789
|
+
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
8790
|
+
var RecordSecretUnavailableError = class extends RecordsError {
|
|
8791
|
+
constructor(detail) {
|
|
8792
|
+
super("secret-unavailable", detail);
|
|
8793
|
+
this.name = "RecordSecretUnavailableError";
|
|
8794
|
+
}
|
|
8795
|
+
};
|
|
8796
|
+
var InvalidRecordError = class extends RecordsError {
|
|
8797
|
+
constructor(detail) {
|
|
8798
|
+
super("invalid-record", detail);
|
|
8799
|
+
this.name = "InvalidRecordError";
|
|
8800
|
+
}
|
|
8801
|
+
};
|
|
8802
|
+
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
8803
|
+
var DeclarationRefusedError = class extends RecordsError {
|
|
8804
|
+
constructor(detail) {
|
|
8805
|
+
super("declaration-refused", detail);
|
|
8806
|
+
this.name = "DeclarationRefusedError";
|
|
8807
|
+
}
|
|
8808
|
+
};
|
|
8562
8809
|
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
8563
8810
|
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
8564
8811
|
var RECORD_DATABASES = ["settings", "events"];
|
|
@@ -8574,6 +8821,152 @@ var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
|
8574
8821
|
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
8575
8822
|
var RECORD_BATCH_MAX = 1e3;
|
|
8576
8823
|
var RECORD_QUERY_MAX = 1e3;
|
|
8824
|
+
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
8825
|
+
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
8826
|
+
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
8827
|
+
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
8828
|
+
/**
|
|
8829
|
+
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
8830
|
+
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
8831
|
+
* (`auth.accessToken`, `headers[].value`).
|
|
8832
|
+
*
|
|
8833
|
+
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
8834
|
+
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
8835
|
+
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
8836
|
+
* leaf names its element: `headers[X-Api].value`.
|
|
8837
|
+
*
|
|
8838
|
+
* Pure and browser-safe. Nothing here mutates: every transform returns a new value.
|
|
8839
|
+
*/
|
|
8840
|
+
/** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
|
|
8841
|
+
function parseSecretPath(path) {
|
|
8842
|
+
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
8843
|
+
return path.split(".").map((raw) => {
|
|
8844
|
+
const each = raw.endsWith("[]");
|
|
8845
|
+
const key = each ? raw.slice(0, -2) : raw;
|
|
8846
|
+
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
8847
|
+
return {
|
|
8848
|
+
key,
|
|
8849
|
+
each
|
|
8850
|
+
};
|
|
8851
|
+
});
|
|
8852
|
+
}
|
|
8853
|
+
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
8854
|
+
function secretArrayPrefixes(path) {
|
|
8855
|
+
const segments = parseSecretPath(path);
|
|
8856
|
+
const prefixes = [];
|
|
8857
|
+
const walked = [];
|
|
8858
|
+
for (const segment of segments) {
|
|
8859
|
+
walked.push(segment.key);
|
|
8860
|
+
if (segment.each) prefixes.push(walked.join("."));
|
|
8861
|
+
}
|
|
8862
|
+
return prefixes;
|
|
8863
|
+
}
|
|
8864
|
+
function isRecord$4(value) {
|
|
8865
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8866
|
+
}
|
|
8867
|
+
function elementId(element, idKey, declared, prefix) {
|
|
8868
|
+
const id = isRecord$4(element) ? element[idKey] : void 0;
|
|
8869
|
+
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`);
|
|
8870
|
+
return id;
|
|
8871
|
+
}
|
|
8872
|
+
/**
|
|
8873
|
+
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
8874
|
+
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
8875
|
+
* result is a new body, `data` is untouched.
|
|
8876
|
+
*/
|
|
8877
|
+
var REMOVE_LEAF = Symbol("remove-leaf");
|
|
8878
|
+
function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
|
|
8879
|
+
if (!isRecord$4(node)) return node;
|
|
8880
|
+
const segment = segments[index];
|
|
8881
|
+
if (segment === void 0) return node;
|
|
8882
|
+
if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
|
|
8883
|
+
const child = node[segment.key];
|
|
8884
|
+
const keys = [...walkedKeys, segment.key];
|
|
8885
|
+
const last = index === segments.length - 1;
|
|
8886
|
+
if (segment.each) {
|
|
8887
|
+
if (!Array.isArray(child)) return node;
|
|
8888
|
+
const prefix = keys.join(".");
|
|
8889
|
+
const idKey = arrayKeys[prefix];
|
|
8890
|
+
if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
|
|
8891
|
+
const mapped = child.map((element) => {
|
|
8892
|
+
const id = elementId(element, idKey, declared, prefix);
|
|
8893
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
|
|
8894
|
+
return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
|
|
8895
|
+
});
|
|
8896
|
+
return {
|
|
8897
|
+
...node,
|
|
8898
|
+
[segment.key]: mapped
|
|
8899
|
+
};
|
|
8900
|
+
}
|
|
8901
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
8902
|
+
if (last) {
|
|
8903
|
+
const replacement = visit({
|
|
8904
|
+
declared,
|
|
8905
|
+
concrete,
|
|
8906
|
+
value: child
|
|
8907
|
+
});
|
|
8908
|
+
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
8909
|
+
return {
|
|
8910
|
+
...node,
|
|
8911
|
+
[segment.key]: replacement
|
|
8912
|
+
};
|
|
8913
|
+
}
|
|
8914
|
+
return {
|
|
8915
|
+
...node,
|
|
8916
|
+
[segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
|
|
8917
|
+
};
|
|
8918
|
+
}
|
|
8919
|
+
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
8920
|
+
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
8921
|
+
let current = data;
|
|
8922
|
+
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
8923
|
+
return current;
|
|
8924
|
+
}
|
|
8925
|
+
/**
|
|
8926
|
+
* The keychain collection name a kind's secrets live under. Prefixed so a
|
|
8927
|
+
* record's refs never collide with the refs a legacy collection of the same name
|
|
8928
|
+
* already holds during an adoption.
|
|
8929
|
+
*/
|
|
8930
|
+
function recordSecretCollection(kind) {
|
|
8931
|
+
return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
|
|
8932
|
+
}
|
|
8933
|
+
/** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
|
|
8934
|
+
function recordSecretRef(owner, kind, rowId, concretePath) {
|
|
8935
|
+
return buildSecretRef({
|
|
8936
|
+
owner,
|
|
8937
|
+
scope: {
|
|
8938
|
+
kind: "row",
|
|
8939
|
+
collection: recordSecretCollection(kind),
|
|
8940
|
+
rowId
|
|
8941
|
+
},
|
|
8942
|
+
fieldPath: concretePath
|
|
8943
|
+
});
|
|
8944
|
+
}
|
|
8945
|
+
/**
|
|
8946
|
+
* A stored secret, as an admin read shows it: a VIEW naming the row's own
|
|
8947
|
+
* keychain ref (`set: true`), never the value and no longer the bare redaction
|
|
8948
|
+
* token. The form hands it to the secret field, which reveals the value by ref
|
|
8949
|
+
* through the audited `keychain-admin.reveal`; sent back untouched it keeps the
|
|
8950
|
+
* stored secret (the records door reads a view as KEEP).
|
|
8951
|
+
*
|
|
8952
|
+
* ONE implementation for the entries service and for every addon that serves
|
|
8953
|
+
* its own instances (`RecordIntegrationInstances`).
|
|
8954
|
+
*/
|
|
8955
|
+
function isRecord$3(value) {
|
|
8956
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8957
|
+
}
|
|
8958
|
+
function secretViewsOf(owner, kind, id, decl, data) {
|
|
8959
|
+
if (decl.secretPaths.length === 0) return data;
|
|
8960
|
+
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
8961
|
+
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
8962
|
+
return {
|
|
8963
|
+
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
8964
|
+
v: 1,
|
|
8965
|
+
set: true
|
|
8966
|
+
};
|
|
8967
|
+
});
|
|
8968
|
+
return isRecord$3(shown) ? shown : data;
|
|
8969
|
+
}
|
|
8577
8970
|
/**
|
|
8578
8971
|
* The share-view scope kinds a share-link token can carry. The hub mints
|
|
8579
8972
|
* and validates them (`ShareViewGrantSchema` builds its
|
|
@@ -8598,6 +8991,73 @@ var PeerBytesTicketSchema = object({
|
|
|
8598
8991
|
*/
|
|
8599
8992
|
declaredBytes: number().int().nonnegative().nullable()
|
|
8600
8993
|
});
|
|
8994
|
+
function defOf(schema) {
|
|
8995
|
+
const zodBag = Reflect.get(schema, "_zod");
|
|
8996
|
+
if (typeof zodBag !== "object" || zodBag === null) return {};
|
|
8997
|
+
const def = Reflect.get(zodBag, "def");
|
|
8998
|
+
if (typeof def !== "object" || def === null) return {};
|
|
8999
|
+
return def;
|
|
9000
|
+
}
|
|
9001
|
+
function declaredHere(schema) {
|
|
9002
|
+
return globalRegistry.get(schema)?.secret === true;
|
|
9003
|
+
}
|
|
9004
|
+
/** Wrapper kinds whose `innerType` is the field itself. */
|
|
9005
|
+
var WRAPPERS = new Set([
|
|
9006
|
+
"optional",
|
|
9007
|
+
"nullable",
|
|
9008
|
+
"default",
|
|
9009
|
+
"prefault",
|
|
9010
|
+
"catch",
|
|
9011
|
+
"readonly",
|
|
9012
|
+
"nonoptional"
|
|
9013
|
+
]);
|
|
9014
|
+
/**
|
|
9015
|
+
* The schema layers that make up ONE field: the schema itself and every
|
|
9016
|
+
* wrapper below it (optional / default / nullable / readonly / catch), plus
|
|
9017
|
+
* both sides of a pipe (`z.preprocess` puts the real schema on `out`,
|
|
9018
|
+
* `.transform` on `in`).
|
|
9019
|
+
*/
|
|
9020
|
+
function layersOf(schema) {
|
|
9021
|
+
const out = [];
|
|
9022
|
+
const queue = [schema];
|
|
9023
|
+
while (queue.length > 0) {
|
|
9024
|
+
const s = queue.shift();
|
|
9025
|
+
if (!s || out.includes(s)) continue;
|
|
9026
|
+
out.push(s);
|
|
9027
|
+
const def = defOf(s);
|
|
9028
|
+
if (def.type !== void 0 && WRAPPERS.has(def.type) && def.innerType) queue.push(def.innerType);
|
|
9029
|
+
if (def.type === "pipe") {
|
|
9030
|
+
if (def.in) queue.push(def.in);
|
|
9031
|
+
if (def.out) queue.push(def.out);
|
|
9032
|
+
}
|
|
9033
|
+
}
|
|
9034
|
+
return out;
|
|
9035
|
+
}
|
|
9036
|
+
/** True when any layer of this field declares `.meta({ secret: true })`. */
|
|
9037
|
+
function isZodSecret(schema) {
|
|
9038
|
+
return layersOf(schema).some(declaredHere);
|
|
9039
|
+
}
|
|
9040
|
+
/**
|
|
9041
|
+
* Every declared secret path in a config schema: dotted keys, `[]` for "each
|
|
9042
|
+
* element of this array" (`connection.password`, `rows[].token`). A declared
|
|
9043
|
+
* object or array is reported as one path and not descended into — everything
|
|
9044
|
+
* under it is secret.
|
|
9045
|
+
*/
|
|
9046
|
+
function collectZodSecretPaths(schema, prefix = "") {
|
|
9047
|
+
if (isZodSecret(schema)) return prefix.length > 0 ? [prefix] : [];
|
|
9048
|
+
const paths = [];
|
|
9049
|
+
for (const layer of layersOf(schema)) {
|
|
9050
|
+
const def = defOf(layer);
|
|
9051
|
+
if (def.type === "object" && def.shape) for (const [key, child] of Object.entries(def.shape)) paths.push(...collectZodSecretPaths(child, prefix ? `${prefix}.${key}` : key));
|
|
9052
|
+
else if (def.type === "array" && def.element) paths.push(...collectZodSecretPaths(def.element, `${prefix}[]`));
|
|
9053
|
+
else if (def.type === "union" && def.options) for (const option of def.options) paths.push(...collectZodSecretPaths(option, prefix));
|
|
9054
|
+
else if (def.type === "intersection") {
|
|
9055
|
+
if (def.left) paths.push(...collectZodSecretPaths(def.left, prefix));
|
|
9056
|
+
if (def.right) paths.push(...collectZodSecretPaths(def.right, prefix));
|
|
9057
|
+
}
|
|
9058
|
+
}
|
|
9059
|
+
return [...new Set(paths)];
|
|
9060
|
+
}
|
|
8601
9061
|
/**
|
|
8602
9062
|
* Record kinds (D881): the declaration an addon makes of one kind of fact, the
|
|
8603
9063
|
* Zod row schema that describes it, and the helper that turns the two into the
|
|
@@ -8664,6 +9124,110 @@ var RecordKindDeclarationSchema = object({
|
|
|
8664
9124
|
}).strict();
|
|
8665
9125
|
/** The kind names: lower-case, dash separated, short enough for an index name. */
|
|
8666
9126
|
var RecordKindNameSchema = string().regex(/^[a-z][a-z0-9-]{0,47}$/);
|
|
9127
|
+
/** Cross-field rules a declaration must satisfy. Throws {@link DeclarationRefusedError}. */
|
|
9128
|
+
function assertValidDeclaration(name, decl) {
|
|
9129
|
+
const refuse = (why) => {
|
|
9130
|
+
throw new DeclarationRefusedError(`kind "${name}": ${why}`);
|
|
9131
|
+
};
|
|
9132
|
+
if (!RecordKindNameSchema.safeParse(name).success) refuse("the name must be lower-case-dashed");
|
|
9133
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9134
|
+
for (const index of decl.indexes) {
|
|
9135
|
+
if (seen.has(index.name)) refuse(`index name "${index.name}" is declared twice`);
|
|
9136
|
+
seen.add(index.name);
|
|
9137
|
+
}
|
|
9138
|
+
const { retention } = decl;
|
|
9139
|
+
const hasSecrets = decl.secretPaths.length > 0;
|
|
9140
|
+
if ("ttlMs" in retention) {
|
|
9141
|
+
if (retention.from === "at" && decl.at !== "required") refuse("a ttl from \"at\" needs at: \"required\"");
|
|
9142
|
+
if (hasSecrets) refuse("a kind with secret fields cannot use engine TTL (its keychain values would be orphaned)");
|
|
9143
|
+
}
|
|
9144
|
+
if ("maxRows" in retention || "maxRowsPerDevice" in retention) {
|
|
9145
|
+
if (retention.maxRowsPerDevice !== void 0 && decl.device !== "required") refuse("maxRowsPerDevice needs device: \"required\"");
|
|
9146
|
+
if (decl.at !== "required") refuse("a row bound trims the oldest \"at\": it needs at: \"required\"");
|
|
9147
|
+
if (hasSecrets) refuse("a kind with secret fields cannot use an engine row bound");
|
|
9148
|
+
const bound = Math.max(retention.maxRows ?? 0, retention.maxRowsPerDevice ?? 0);
|
|
9149
|
+
if (decl.database === "settings" && bound > 5e4) refuse(`a row bound above ${RECORD_SETTINGS_MAX_ROWS} belongs in database: "events" (a big delete on the settings thread stalls every configuration read)`);
|
|
9150
|
+
}
|
|
9151
|
+
if (decl.deviceRemoval === "delete" && decl.device === "none") refuse("deviceRemoval: \"delete\" needs a device: \"required\" or \"optional\"");
|
|
9152
|
+
for (const path of decl.secretPaths) for (const prefix of secretArrayPrefixes(path)) if (decl.secretArrayKeys[prefix] === void 0) refuse(`secret path "${path}" crosses the array "${prefix}": declare its id key in secretArrayKeys`);
|
|
9153
|
+
}
|
|
9154
|
+
function bodyFieldsOf(schema) {
|
|
9155
|
+
return { ...toJSONSchema(schema, {
|
|
9156
|
+
unrepresentable: "any",
|
|
9157
|
+
io: "input"
|
|
9158
|
+
}) };
|
|
9159
|
+
}
|
|
9160
|
+
function isRecordLike(value) {
|
|
9161
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9162
|
+
}
|
|
9163
|
+
/** Does every branch of the body schema carry `field`? (A discriminated union has several.) */
|
|
9164
|
+
function hasNameField(json, field) {
|
|
9165
|
+
const branches = json["oneOf"] ?? json["anyOf"];
|
|
9166
|
+
if (Array.isArray(branches)) return branches.length > 0 && branches.every((b) => isRecordLike(b) && hasNameField(b, field));
|
|
9167
|
+
const properties = json["properties"];
|
|
9168
|
+
return isRecordLike(properties) && Object.prototype.hasOwnProperty.call(properties, field);
|
|
9169
|
+
}
|
|
9170
|
+
/**
|
|
9171
|
+
* Declare the kinds of a package. The keys are the kind names. The result is
|
|
9172
|
+
* what `ctx.records.declare` sends to the engine and what `ctx.records.kind`
|
|
9173
|
+
* types its handle from.
|
|
9174
|
+
*/
|
|
9175
|
+
function defineRecordKinds(specs) {
|
|
9176
|
+
const out = {};
|
|
9177
|
+
for (const [name, spec] of Object.entries(specs)) {
|
|
9178
|
+
const secretPaths = collectZodSecretPaths(spec.schema);
|
|
9179
|
+
const nameField = spec.entry?.nameField ?? "name";
|
|
9180
|
+
const fields = bodyFieldsOf(spec.schema);
|
|
9181
|
+
if (spec.entry !== void 0 && !hasNameField(fields, nameField)) throw new DeclarationRefusedError(`kind "${name}": an entry kind's schema needs a "${nameField}" field`);
|
|
9182
|
+
const parsed = RecordKindDeclarationSchema.parse({
|
|
9183
|
+
database: spec.database,
|
|
9184
|
+
class: spec.class,
|
|
9185
|
+
writeTrigger: spec.writeTrigger,
|
|
9186
|
+
device: spec.device,
|
|
9187
|
+
at: spec.at,
|
|
9188
|
+
indexes: spec.indexes === void 0 ? void 0 : [...spec.indexes],
|
|
9189
|
+
retention: spec.retention,
|
|
9190
|
+
deviceRemoval: spec.deviceRemoval,
|
|
9191
|
+
maxDataBytes: spec.maxDataBytes,
|
|
9192
|
+
secretPaths: [...secretPaths],
|
|
9193
|
+
secretArrayKeys: spec.secretArrayKeys === void 0 ? void 0 : { ...spec.secretArrayKeys },
|
|
9194
|
+
transactFamily: spec.transactFamily,
|
|
9195
|
+
entry: spec.entry === void 0 ? void 0 : {
|
|
9196
|
+
title: spec.entry.title,
|
|
9197
|
+
nameField,
|
|
9198
|
+
fields
|
|
9199
|
+
}
|
|
9200
|
+
});
|
|
9201
|
+
assertValidDeclaration(name, parsed);
|
|
9202
|
+
out[name] = {
|
|
9203
|
+
name,
|
|
9204
|
+
schema: spec.schema,
|
|
9205
|
+
declaration: parsed
|
|
9206
|
+
};
|
|
9207
|
+
}
|
|
9208
|
+
return out;
|
|
9209
|
+
}
|
|
9210
|
+
/**
|
|
9211
|
+
* Declare one entry kind. An entry is configuration: never trimmed by the
|
|
9212
|
+
* engine, never aged, belonging to no device.
|
|
9213
|
+
*/
|
|
9214
|
+
function defineEntryKind(name, spec) {
|
|
9215
|
+
const defined = defineRecordKinds({ [name]: {
|
|
9216
|
+
schema: spec.schema,
|
|
9217
|
+
class: "config",
|
|
9218
|
+
writeTrigger: spec.writeTrigger ?? "an operator adds or edits an entry in the entries UI",
|
|
9219
|
+
retention: { none: "an entry goes only when the operator deletes it" },
|
|
9220
|
+
...spec.database === void 0 ? {} : { database: spec.database },
|
|
9221
|
+
...spec.indexes === void 0 ? {} : { indexes: spec.indexes },
|
|
9222
|
+
...spec.secretArrayKeys === void 0 ? {} : { secretArrayKeys: spec.secretArrayKeys },
|
|
9223
|
+
entry: {
|
|
9224
|
+
title: spec.title,
|
|
9225
|
+
...spec.nameField === void 0 ? {} : { nameField: spec.nameField }
|
|
9226
|
+
}
|
|
9227
|
+
} })[name];
|
|
9228
|
+
if (defined === void 0) throw new DeclarationRefusedError(`entry kind "${name}" was not built`);
|
|
9229
|
+
return defined;
|
|
9230
|
+
}
|
|
8667
9231
|
object({
|
|
8668
9232
|
field: string().min(1),
|
|
8669
9233
|
on: literal("advance")
|
|
@@ -11339,7 +11903,7 @@ object({
|
|
|
11339
11903
|
params: record(string(), union([string(), number()])).optional()
|
|
11340
11904
|
});
|
|
11341
11905
|
//#endregion
|
|
11342
|
-
//#region ../types/dist/composition-
|
|
11906
|
+
//#region ../types/dist/composition-BodkvOV0.mjs
|
|
11343
11907
|
/**
|
|
11344
11908
|
* The ffmpeg build every CamStack node downloads, per platform and arch.
|
|
11345
11909
|
*
|
|
@@ -12476,7 +13040,14 @@ var CompositionForwardCommandSchema = object({
|
|
|
12476
13040
|
method: string().min(1),
|
|
12477
13041
|
args: record(string().min(1), CompositionForwardArgSchema).optional()
|
|
12478
13042
|
});
|
|
12479
|
-
var CompositionCommandTargetSchema = discriminatedUnion("kind", [
|
|
13043
|
+
var CompositionCommandTargetSchema = discriminatedUnion("kind", [
|
|
13044
|
+
CompositionForwardCommandSchema,
|
|
13045
|
+
CompositionCodeSourceSchema,
|
|
13046
|
+
object({
|
|
13047
|
+
kind: literal("extension"),
|
|
13048
|
+
target: literal("remote")
|
|
13049
|
+
})
|
|
13050
|
+
]);
|
|
12480
13051
|
/** An item key inside an item-array cap (`consumables.items[<key>]`). */
|
|
12481
13052
|
var COMPOSITION_ITEM_KEY_RE = /^[a-z0-9][a-z0-9-]{0,47}$/;
|
|
12482
13053
|
/**
|
|
@@ -12856,6 +13427,144 @@ function buildCapturingReply(envelope) {
|
|
|
12856
13427
|
};
|
|
12857
13428
|
return wrapper;
|
|
12858
13429
|
}
|
|
13430
|
+
/** The most instances one addon lists (an integrations page, not a table). */
|
|
13431
|
+
var INSTANCES_LIST_MAX = 1e3;
|
|
13432
|
+
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
13433
|
+
function topLevelSecretKeys(paths) {
|
|
13434
|
+
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[")));
|
|
13435
|
+
}
|
|
13436
|
+
var RecordIntegrationInstances = class {
|
|
13437
|
+
records;
|
|
13438
|
+
kind;
|
|
13439
|
+
hooks;
|
|
13440
|
+
handle;
|
|
13441
|
+
secretKeys;
|
|
13442
|
+
nameField;
|
|
13443
|
+
constructor(records, kind, hooks) {
|
|
13444
|
+
this.records = records;
|
|
13445
|
+
this.kind = kind;
|
|
13446
|
+
this.hooks = hooks;
|
|
13447
|
+
this.handle = records.kind(kind);
|
|
13448
|
+
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
13449
|
+
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
13450
|
+
}
|
|
13451
|
+
/**
|
|
13452
|
+
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
13453
|
+
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
13454
|
+
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
13455
|
+
*/
|
|
13456
|
+
async readResolved(id) {
|
|
13457
|
+
try {
|
|
13458
|
+
const record = await this.handle.getResolved(id);
|
|
13459
|
+
return record === null ? null : {
|
|
13460
|
+
id,
|
|
13461
|
+
body: record.data,
|
|
13462
|
+
enabled: record.data.enabled !== false,
|
|
13463
|
+
secrets: "resolved"
|
|
13464
|
+
};
|
|
13465
|
+
} catch (err) {
|
|
13466
|
+
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
13467
|
+
const stored = await this.handle.get(id);
|
|
13468
|
+
if (stored === null) return null;
|
|
13469
|
+
return {
|
|
13470
|
+
id,
|
|
13471
|
+
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
13472
|
+
enabled: stored.data.enabled !== false,
|
|
13473
|
+
secrets: "unavailable"
|
|
13474
|
+
};
|
|
13475
|
+
}
|
|
13476
|
+
}
|
|
13477
|
+
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
13478
|
+
async getResolved(id) {
|
|
13479
|
+
return (await this.readResolved(id))?.body ?? null;
|
|
13480
|
+
}
|
|
13481
|
+
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
13482
|
+
async listResolved() {
|
|
13483
|
+
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
13484
|
+
const out = [];
|
|
13485
|
+
for (const record of page.records) {
|
|
13486
|
+
const read = await this.readResolved(record.id);
|
|
13487
|
+
if (read !== null) out.push(read);
|
|
13488
|
+
}
|
|
13489
|
+
return out;
|
|
13490
|
+
}
|
|
13491
|
+
viewOf(record) {
|
|
13492
|
+
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
13493
|
+
const rawName = record.data[this.nameField];
|
|
13494
|
+
return {
|
|
13495
|
+
id: record.id,
|
|
13496
|
+
name: typeof rawName === "string" ? rawName : record.id,
|
|
13497
|
+
configured: this.hooks.configured(record.data),
|
|
13498
|
+
enabled: record.data.enabled !== false,
|
|
13499
|
+
formValues: shown
|
|
13500
|
+
};
|
|
13501
|
+
}
|
|
13502
|
+
describe = async () => this.hooks.description;
|
|
13503
|
+
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
13504
|
+
listInstances = async () => {
|
|
13505
|
+
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
13506
|
+
};
|
|
13507
|
+
getInstance = async ({ id }) => {
|
|
13508
|
+
const record = await this.handle.get(id);
|
|
13509
|
+
return record === null ? null : this.viewOf(record);
|
|
13510
|
+
};
|
|
13511
|
+
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
13512
|
+
createInstance = async ({ id, name }) => {
|
|
13513
|
+
await this.handle.put({
|
|
13514
|
+
id,
|
|
13515
|
+
data: this.hooks.initialBody(name)
|
|
13516
|
+
}, { ifRev: 0 });
|
|
13517
|
+
await this.hooks.onChanged?.(id);
|
|
13518
|
+
return { id };
|
|
13519
|
+
};
|
|
13520
|
+
updateInstance = async ({ id, name, values }) => {
|
|
13521
|
+
const patch = {};
|
|
13522
|
+
for (const [key, value] of Object.entries(values)) {
|
|
13523
|
+
if (value === void 0) continue;
|
|
13524
|
+
if (!this.secretKeys.has(key)) patch[key] = value;
|
|
13525
|
+
else if (isSecretClear(value)) patch[key] = null;
|
|
13526
|
+
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
13527
|
+
}
|
|
13528
|
+
if (name !== void 0) patch[this.nameField] = name;
|
|
13529
|
+
await this.handle.patch(id, patch);
|
|
13530
|
+
await this.hooks.onChanged?.(id);
|
|
13531
|
+
return { ok: true };
|
|
13532
|
+
};
|
|
13533
|
+
/** The switch lives in the record body; the addon is told so it applies it (D996). */
|
|
13534
|
+
setInstanceEnabled = async ({ id, enabled }) => {
|
|
13535
|
+
await this.handle.patch(id, { enabled });
|
|
13536
|
+
await this.hooks.onChanged?.(id);
|
|
13537
|
+
return { ok: true };
|
|
13538
|
+
};
|
|
13539
|
+
/** The row and its keychain refs go together (the records door). */
|
|
13540
|
+
deleteInstance = async ({ id }) => {
|
|
13541
|
+
await this.handle.delete(id);
|
|
13542
|
+
await this.hooks.onChanged?.(id);
|
|
13543
|
+
return { ok: true };
|
|
13544
|
+
};
|
|
13545
|
+
testInstance = async (input) => {
|
|
13546
|
+
if (this.hooks.test === void 0) return {
|
|
13547
|
+
success: false,
|
|
13548
|
+
status: "unsupported",
|
|
13549
|
+
error: "This integration declares no connection test"
|
|
13550
|
+
};
|
|
13551
|
+
return this.hooks.test(input);
|
|
13552
|
+
};
|
|
13553
|
+
/** The flat provider object to hand to `registerProvider`. */
|
|
13554
|
+
toProvider() {
|
|
13555
|
+
return {
|
|
13556
|
+
describe: this.describe,
|
|
13557
|
+
instanceFormSchema: this.instanceFormSchema,
|
|
13558
|
+
listInstances: this.listInstances,
|
|
13559
|
+
getInstance: this.getInstance,
|
|
13560
|
+
createInstance: this.createInstance,
|
|
13561
|
+
updateInstance: this.updateInstance,
|
|
13562
|
+
setInstanceEnabled: this.setInstanceEnabled,
|
|
13563
|
+
deleteInstance: this.deleteInstance,
|
|
13564
|
+
testInstance: this.testInstance
|
|
13565
|
+
};
|
|
13566
|
+
}
|
|
13567
|
+
};
|
|
12859
13568
|
var EncodeProfileSchema = object({
|
|
12860
13569
|
video: object({
|
|
12861
13570
|
codec: _enum([
|
|
@@ -19280,6 +19989,48 @@ var APPLIANCE_CAP_VOCABULARY = {
|
|
|
19280
19989
|
scope: "device",
|
|
19281
19990
|
noun: t("Media player", "Lettore multimediale"),
|
|
19282
19991
|
actions: [
|
|
19992
|
+
{
|
|
19993
|
+
id: "media.turnOn",
|
|
19994
|
+
method: "turnOn",
|
|
19995
|
+
label: t("Turn on", "Accendi"),
|
|
19996
|
+
phrase: t("Turn on {device}", "Accendi {device}"),
|
|
19997
|
+
icon: "power"
|
|
19998
|
+
},
|
|
19999
|
+
{
|
|
20000
|
+
id: "media.turnOff",
|
|
20001
|
+
method: "turnOff",
|
|
20002
|
+
label: t("Turn off", "Spegni"),
|
|
20003
|
+
phrase: t("Turn off {device}", "Spegni {device}"),
|
|
20004
|
+
icon: "power"
|
|
20005
|
+
},
|
|
20006
|
+
{
|
|
20007
|
+
id: "media.volumeUp",
|
|
20008
|
+
method: "volumeUp",
|
|
20009
|
+
label: t("Volume up", "Alza il volume"),
|
|
20010
|
+
phrase: t("Raise the volume of {device}", "Alza il volume di {device}"),
|
|
20011
|
+
icon: "volume-2"
|
|
20012
|
+
},
|
|
20013
|
+
{
|
|
20014
|
+
id: "media.volumeDown",
|
|
20015
|
+
method: "volumeDown",
|
|
20016
|
+
label: t("Volume down", "Abbassa il volume"),
|
|
20017
|
+
phrase: t("Lower the volume of {device}", "Abbassa il volume di {device}"),
|
|
20018
|
+
icon: "volume-2"
|
|
20019
|
+
},
|
|
20020
|
+
{
|
|
20021
|
+
id: "media.channelUp",
|
|
20022
|
+
method: "channelUp",
|
|
20023
|
+
label: t("Channel up", "Canale successivo"),
|
|
20024
|
+
phrase: t("Go to the next channel on {device}", "Passa al canale successivo su {device}"),
|
|
20025
|
+
icon: "skip-forward"
|
|
20026
|
+
},
|
|
20027
|
+
{
|
|
20028
|
+
id: "media.channelDown",
|
|
20029
|
+
method: "channelDown",
|
|
20030
|
+
label: t("Channel down", "Canale precedente"),
|
|
20031
|
+
phrase: t("Go to the previous channel on {device}", "Torna al canale precedente su {device}"),
|
|
20032
|
+
icon: "skip-back"
|
|
20033
|
+
},
|
|
19283
20034
|
{
|
|
19284
20035
|
id: "media.play",
|
|
19285
20036
|
method: "play",
|
|
@@ -47856,6 +48607,188 @@ DeviceType.Control, method(object({
|
|
|
47856
48607
|
kind: "mutation",
|
|
47857
48608
|
auth: "protected"
|
|
47858
48609
|
});
|
|
48610
|
+
/**
|
|
48611
|
+
* Media-player cap. Models HA `media_player.*` (Sonos, Chromecast,
|
|
48612
|
+
* Apple TV, Spotify, Roku, generic OTT receivers, …) on
|
|
48613
|
+
* `DeviceType.MediaPlayer`. Disjoint from the camera streaming
|
|
48614
|
+
* surface — those use `DeviceType.Camera` + the broker pipeline.
|
|
48615
|
+
*
|
|
48616
|
+
* The cap declares a wide method surface; not every backend supports
|
|
48617
|
+
* every method. Drivers signal sub-capability via the
|
|
48618
|
+
* `DeviceFeature.MediaPlayerXxx` flags (paired one-to-one with the
|
|
48619
|
+
* corresponding method) so the UI gates buttons without a slice
|
|
48620
|
+
* fetch — same pattern as `PanTiltZoom` for cameras.
|
|
48621
|
+
*/
|
|
48622
|
+
var MediaPlayerStateSchema = _enum([
|
|
48623
|
+
"off",
|
|
48624
|
+
"on",
|
|
48625
|
+
"idle",
|
|
48626
|
+
"playing",
|
|
48627
|
+
"paused",
|
|
48628
|
+
"buffering",
|
|
48629
|
+
"standby"
|
|
48630
|
+
]);
|
|
48631
|
+
var MediaPlayerRepeatSchema = _enum([
|
|
48632
|
+
"off",
|
|
48633
|
+
"all",
|
|
48634
|
+
"one"
|
|
48635
|
+
]);
|
|
48636
|
+
var MediaInfoSchema = object({
|
|
48637
|
+
/** Free-form media kind (`music`, `tvshow`, `movie`, `app`, `channel`,
|
|
48638
|
+
* `podcast`, …). */
|
|
48639
|
+
type: string(),
|
|
48640
|
+
/** Human-readable title. */
|
|
48641
|
+
title: string(),
|
|
48642
|
+
/** Optional artist / channel / station label. */
|
|
48643
|
+
artist: string().optional(),
|
|
48644
|
+
/** Optional album / season / show name. */
|
|
48645
|
+
album: string().optional(),
|
|
48646
|
+
/** Optional cover-art / thumbnail URL. */
|
|
48647
|
+
imageUrl: string().optional()
|
|
48648
|
+
});
|
|
48649
|
+
/**
|
|
48650
|
+
* Where `state`, `volumeLevel`, `isMuted` and `source` come from. `reported`:
|
|
48651
|
+
* the device said so. `assumed`: the driver has no feedback (infrared) and
|
|
48652
|
+
* tracks what it last SENT; it moves only after a send was accepted, and a
|
|
48653
|
+
* human at the real remote makes it wrong. A UI shows an assumed value as a
|
|
48654
|
+
* guess, never as a reading.
|
|
48655
|
+
*/
|
|
48656
|
+
var MediaPlayerStateSourceSchema = _enum(["reported", "assumed"]);
|
|
48657
|
+
/** The fields of a media-player status a driver can only guess. */
|
|
48658
|
+
var MediaPlayerAssumedFieldSchema = _enum([
|
|
48659
|
+
"state",
|
|
48660
|
+
"volumeLevel",
|
|
48661
|
+
"isMuted",
|
|
48662
|
+
"source"
|
|
48663
|
+
]);
|
|
48664
|
+
var MediaPlayerStatusSchema = object({
|
|
48665
|
+
/** Playback lifecycle state. */
|
|
48666
|
+
state: MediaPlayerStateSchema,
|
|
48667
|
+
/**
|
|
48668
|
+
* Whether the state fields are readings or the driver's own bookkeeping.
|
|
48669
|
+
* A slice written before this field existed parses as `reported`.
|
|
48670
|
+
*/
|
|
48671
|
+
stateSource: MediaPlayerStateSourceSchema.default("reported"),
|
|
48672
|
+
/**
|
|
48673
|
+
* Which fields are the driver's own guess. `stateSource` is `assumed` when
|
|
48674
|
+
* this is not empty; a field not listed here is a reading even then (power
|
|
48675
|
+
* from a running-state source, mute guessed from the last send).
|
|
48676
|
+
*/
|
|
48677
|
+
assumedFields: array(MediaPlayerAssumedFieldSchema).default([]),
|
|
48678
|
+
/** Volume as 0..100 inclusive. Null when the device has no volume
|
|
48679
|
+
* surface. Pair with `DeviceFeature.MediaPlayerVolume`. */
|
|
48680
|
+
volumeLevel: number().min(0).max(100).nullable().meta(readingMeta("percentage")),
|
|
48681
|
+
/** Mute toggle distinct from volume=0. Null when no mute surface.
|
|
48682
|
+
* Pair with `DeviceFeature.MediaPlayerMute`. */
|
|
48683
|
+
isMuted: boolean().nullable(),
|
|
48684
|
+
/** Active source / input. Empty when no source surface. */
|
|
48685
|
+
source: string(),
|
|
48686
|
+
/** Selectable sources. Empty when no source surface.
|
|
48687
|
+
* Pair with `DeviceFeature.MediaPlayerSelectSource`. */
|
|
48688
|
+
availableSources: array(string()),
|
|
48689
|
+
/** Currently-playing media info. Null when nothing is playing. */
|
|
48690
|
+
currentMedia: MediaInfoSchema.nullable(),
|
|
48691
|
+
/** Current playback position in ms. Null when not seekable or
|
|
48692
|
+
* nothing is playing. Pair with `DeviceFeature.MediaPlayerSeek`. */
|
|
48693
|
+
position: number().int().nonnegative().nullable().meta(readingMeta("duration-ms")),
|
|
48694
|
+
/** Total duration of the current media in ms. Null when unknown
|
|
48695
|
+
* (live stream) or nothing is playing. */
|
|
48696
|
+
duration: number().int().nonnegative().nullable().meta(readingMeta("duration-ms")),
|
|
48697
|
+
/** Shuffle toggle. Null when no shuffle surface.
|
|
48698
|
+
* Pair with `DeviceFeature.MediaPlayerShuffle`. */
|
|
48699
|
+
shuffle: boolean().nullable(),
|
|
48700
|
+
/** Repeat mode. Null when no repeat surface.
|
|
48701
|
+
* Pair with `DeviceFeature.MediaPlayerRepeat`. */
|
|
48702
|
+
repeat: MediaPlayerRepeatSchema.nullable(),
|
|
48703
|
+
/** Ms epoch when the slice was last updated. */
|
|
48704
|
+
lastChangedAt: number()
|
|
48705
|
+
});
|
|
48706
|
+
var stepInput = object({
|
|
48707
|
+
deviceId: number().int().nonnegative(),
|
|
48708
|
+
/** How many presses: the caller's count (Alexa `volumeSteps`, `channelCount`). */
|
|
48709
|
+
steps: number().int().min(1).max(50).default(1)
|
|
48710
|
+
});
|
|
48711
|
+
var deviceOnly = object({ deviceId: number().int().nonnegative() });
|
|
48712
|
+
DeviceType.MediaPlayer, method(deviceOnly, _void(), {
|
|
48713
|
+
kind: "mutation",
|
|
48714
|
+
auth: "protected"
|
|
48715
|
+
}), method(deviceOnly, _void(), {
|
|
48716
|
+
kind: "mutation",
|
|
48717
|
+
auth: "protected"
|
|
48718
|
+
}), method(stepInput, _void(), {
|
|
48719
|
+
kind: "mutation",
|
|
48720
|
+
auth: "protected"
|
|
48721
|
+
}), method(stepInput, _void(), {
|
|
48722
|
+
kind: "mutation",
|
|
48723
|
+
auth: "protected"
|
|
48724
|
+
}), method(stepInput, _void(), {
|
|
48725
|
+
kind: "mutation",
|
|
48726
|
+
auth: "protected"
|
|
48727
|
+
}), method(stepInput, _void(), {
|
|
48728
|
+
kind: "mutation",
|
|
48729
|
+
auth: "protected"
|
|
48730
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
48731
|
+
kind: "mutation",
|
|
48732
|
+
auth: "protected"
|
|
48733
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
48734
|
+
kind: "mutation",
|
|
48735
|
+
auth: "protected"
|
|
48736
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
48737
|
+
kind: "mutation",
|
|
48738
|
+
auth: "protected"
|
|
48739
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
48740
|
+
kind: "mutation",
|
|
48741
|
+
auth: "protected"
|
|
48742
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
48743
|
+
kind: "mutation",
|
|
48744
|
+
auth: "protected"
|
|
48745
|
+
}), method(object({
|
|
48746
|
+
deviceId: number().int().nonnegative(),
|
|
48747
|
+
position: number().int().nonnegative()
|
|
48748
|
+
}), _void(), {
|
|
48749
|
+
kind: "mutation",
|
|
48750
|
+
auth: "protected"
|
|
48751
|
+
}), method(object({
|
|
48752
|
+
deviceId: number().int().nonnegative(),
|
|
48753
|
+
volumeLevel: number().min(0).max(100)
|
|
48754
|
+
}), _void(), {
|
|
48755
|
+
kind: "mutation",
|
|
48756
|
+
auth: "protected"
|
|
48757
|
+
}), method(object({
|
|
48758
|
+
deviceId: number().int().nonnegative(),
|
|
48759
|
+
muted: boolean()
|
|
48760
|
+
}), _void(), {
|
|
48761
|
+
kind: "mutation",
|
|
48762
|
+
auth: "protected"
|
|
48763
|
+
}), method(object({
|
|
48764
|
+
deviceId: number().int().nonnegative(),
|
|
48765
|
+
shuffle: boolean()
|
|
48766
|
+
}), _void(), {
|
|
48767
|
+
kind: "mutation",
|
|
48768
|
+
auth: "protected"
|
|
48769
|
+
}), method(object({
|
|
48770
|
+
deviceId: number().int().nonnegative(),
|
|
48771
|
+
repeat: MediaPlayerRepeatSchema
|
|
48772
|
+
}), _void(), {
|
|
48773
|
+
kind: "mutation",
|
|
48774
|
+
auth: "protected"
|
|
48775
|
+
}), method(object({
|
|
48776
|
+
deviceId: number().int().nonnegative(),
|
|
48777
|
+
source: string().min(1)
|
|
48778
|
+
}), _void(), {
|
|
48779
|
+
kind: "mutation",
|
|
48780
|
+
auth: "protected"
|
|
48781
|
+
}), method(object({
|
|
48782
|
+
deviceId: number().int().nonnegative(),
|
|
48783
|
+
/** Media identifier / URL. */
|
|
48784
|
+
mediaId: string().min(1),
|
|
48785
|
+
/** Media kind (`music`, `tvshow`, `movie`, `app`, …) — provider
|
|
48786
|
+
* passes it through to the upstream service. */
|
|
48787
|
+
mediaType: string().min(1)
|
|
48788
|
+
}), _void(), {
|
|
48789
|
+
kind: "mutation",
|
|
48790
|
+
auth: "protected"
|
|
48791
|
+
});
|
|
47859
48792
|
DeviceType.Camera, DeviceType.Sensor, DeviceType.Button, DeviceType.Switch, DeviceType.PetFeeder, DeviceType.Container, DeviceType.Thermostat, DeviceType.EventEmitter, DeviceType.Camera, DeviceType.Hub, DeviceType.Light, DeviceType.Siren, DeviceType.Switch, DeviceType.Sensor, DeviceType.Thermostat, DeviceType.Climate, DeviceType.Button, DeviceType.EventEmitter, DeviceType.Update, DeviceType.Generic, DeviceType.Notifier, DeviceType.Script, DeviceType.Automation, DeviceType.Lock, DeviceType.Cover, DeviceType.Valve, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.Fan, DeviceType.MediaPlayer, DeviceType.AlarmPanel, DeviceType.Control, DeviceType.Presence, DeviceType.Weather, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.Container, DeviceType.Image, DeviceType.PetFeeder, DeviceType.PetFountain, DeviceType.Dishwasher, DeviceType.Washer, DeviceType.Heater, DeviceType.Dryer, DeviceType.Gateway, DeviceType.Camera, DeviceType.Fan, DeviceType.Lock, DeviceType.Camera, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Thermostat, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Heater, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Thermostat, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Heater, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Thermostat, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Heater, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Thermostat, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Heater, DeviceType.Gateway, DeviceType.Hub, DeviceType.Camera, DeviceType.Sensor, DeviceType.MediaPlayer, DeviceType.Vacuum, DeviceType.Generic, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.PetFountain, DeviceType.Fan, DeviceType.Humidifier, DeviceType.Climate, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.MediaPlayer, DeviceType.WaterHeater, DeviceType.Humidifier, DeviceType.Fan, DeviceType.Climate, DeviceType.Thermostat, DeviceType.PetFeeder, DeviceType.Heater;
|
|
47860
48793
|
var NUMBER = {
|
|
47861
48794
|
kind: "fixed",
|
|
@@ -53368,31 +54301,53 @@ var IntegrationInstancePatchSchema = object({
|
|
|
53368
54301
|
/** Omitted / '' / redaction token keeps a secret; `{ $secretClear: true }` clears it. */
|
|
53369
54302
|
values: record(string(), unknown())
|
|
53370
54303
|
});
|
|
53371
|
-
|
|
53372
|
-
|
|
53373
|
-
|
|
53374
|
-
|
|
53375
|
-
|
|
53376
|
-
|
|
53377
|
-
|
|
53378
|
-
|
|
53379
|
-
|
|
53380
|
-
|
|
53381
|
-
|
|
53382
|
-
|
|
53383
|
-
|
|
53384
|
-
|
|
53385
|
-
|
|
53386
|
-
|
|
53387
|
-
|
|
53388
|
-
|
|
53389
|
-
|
|
53390
|
-
|
|
53391
|
-
|
|
53392
|
-
}),
|
|
53393
|
-
|
|
53394
|
-
|
|
53395
|
-
|
|
54304
|
+
var integrationInstancesCapability = {
|
|
54305
|
+
name: "integration-instances",
|
|
54306
|
+
scope: "system",
|
|
54307
|
+
mode: "collection",
|
|
54308
|
+
methods: {
|
|
54309
|
+
describe: method(_void(), IntegrationInstanceDescriptionSchema, { auth: "admin" }),
|
|
54310
|
+
/** The form; `id: null` is the create form. */
|
|
54311
|
+
instanceFormSchema: method(object({ id: IntegrationInstanceIdSchema.nullable() }), ConfigSchemaPassthrough$3, { auth: "admin" }),
|
|
54312
|
+
listInstances: method(_void(), array(IntegrationInstanceSchema).readonly(), { auth: "admin" }),
|
|
54313
|
+
getInstance: method(object({ id: IntegrationInstanceIdSchema }), IntegrationInstanceSchema.nullable(), { auth: "admin" }),
|
|
54314
|
+
/** Insert the typed record under the given id (a duplicate id is refused). */
|
|
54315
|
+
createInstance: method(object({
|
|
54316
|
+
id: IntegrationInstanceIdSchema,
|
|
54317
|
+
name: string().min(1)
|
|
54318
|
+
}), object({ id: string() }), {
|
|
54319
|
+
kind: "mutation",
|
|
54320
|
+
auth: "admin"
|
|
54321
|
+
}),
|
|
54322
|
+
updateInstance: method(IntegrationInstancePatchSchema, object({ ok: literal(true) }), {
|
|
54323
|
+
kind: "mutation",
|
|
54324
|
+
auth: "admin"
|
|
54325
|
+
}),
|
|
54326
|
+
/**
|
|
54327
|
+
* Switch ONE instance on or off. A row control, not a form field: `updateInstance.values` is the
|
|
54328
|
+
* form patch (D62, D996). An off instance keeps its record and secrets and does no work.
|
|
54329
|
+
*/
|
|
54330
|
+
setInstanceEnabled: method(object({
|
|
54331
|
+
id: IntegrationInstanceIdSchema,
|
|
54332
|
+
enabled: boolean()
|
|
54333
|
+
}), object({ ok: literal(true) }), {
|
|
54334
|
+
kind: "mutation",
|
|
54335
|
+
auth: "admin"
|
|
54336
|
+
}),
|
|
54337
|
+
/** Delete the record and its keychain refs together. */
|
|
54338
|
+
deleteInstance: method(object({ id: IntegrationInstanceIdSchema }), object({ ok: literal(true) }), {
|
|
54339
|
+
kind: "mutation",
|
|
54340
|
+
auth: "admin"
|
|
54341
|
+
}),
|
|
54342
|
+
testInstance: optionalMethod(object({
|
|
54343
|
+
id: IntegrationInstanceIdSchema.nullable(),
|
|
54344
|
+
values: record(string(), unknown())
|
|
54345
|
+
}), TestConnectionResultSchema$1, {
|
|
54346
|
+
kind: "mutation",
|
|
54347
|
+
auth: "admin"
|
|
54348
|
+
})
|
|
54349
|
+
}
|
|
54350
|
+
};
|
|
53396
54351
|
/**
|
|
53397
54352
|
* Two-way audio / talk-back cap. Clients open a WebRTC audio-only
|
|
53398
54353
|
* session (server-initiated offer pattern, identical to the main
|
|
@@ -55375,164 +56330,6 @@ var LoginMethodContributionSchema = discriminatedUnion("kind", [
|
|
|
55375
56330
|
]);
|
|
55376
56331
|
method(_void(), array(LoginMethodContributionSchema).readonly());
|
|
55377
56332
|
/**
|
|
55378
|
-
* Media-player cap. Models HA `media_player.*` (Sonos, Chromecast,
|
|
55379
|
-
* Apple TV, Spotify, Roku, generic OTT receivers, …) on
|
|
55380
|
-
* `DeviceType.MediaPlayer`. Disjoint from the camera streaming
|
|
55381
|
-
* surface — those use `DeviceType.Camera` + the broker pipeline.
|
|
55382
|
-
*
|
|
55383
|
-
* The cap declares a wide method surface; not every backend supports
|
|
55384
|
-
* every method. Drivers signal sub-capability via the
|
|
55385
|
-
* `DeviceFeature.MediaPlayerXxx` flags (paired one-to-one with the
|
|
55386
|
-
* corresponding method) so the UI gates buttons without a slice
|
|
55387
|
-
* fetch — same pattern as `PanTiltZoom` for cameras.
|
|
55388
|
-
*/
|
|
55389
|
-
var MediaPlayerStateSchema = _enum([
|
|
55390
|
-
"off",
|
|
55391
|
-
"on",
|
|
55392
|
-
"idle",
|
|
55393
|
-
"playing",
|
|
55394
|
-
"paused",
|
|
55395
|
-
"buffering",
|
|
55396
|
-
"standby"
|
|
55397
|
-
]);
|
|
55398
|
-
var MediaPlayerRepeatSchema = _enum([
|
|
55399
|
-
"off",
|
|
55400
|
-
"all",
|
|
55401
|
-
"one"
|
|
55402
|
-
]);
|
|
55403
|
-
var MediaInfoSchema = object({
|
|
55404
|
-
/** Free-form media kind (`music`, `tvshow`, `movie`, `app`, `channel`,
|
|
55405
|
-
* `podcast`, …). */
|
|
55406
|
-
type: string(),
|
|
55407
|
-
/** Human-readable title. */
|
|
55408
|
-
title: string(),
|
|
55409
|
-
/** Optional artist / channel / station label. */
|
|
55410
|
-
artist: string().optional(),
|
|
55411
|
-
/** Optional album / season / show name. */
|
|
55412
|
-
album: string().optional(),
|
|
55413
|
-
/** Optional cover-art / thumbnail URL. */
|
|
55414
|
-
imageUrl: string().optional()
|
|
55415
|
-
});
|
|
55416
|
-
/**
|
|
55417
|
-
* Where `state`, `volumeLevel`, `isMuted` and `source` come from. `reported`:
|
|
55418
|
-
* the device said so. `assumed`: the driver has no feedback (infrared) and
|
|
55419
|
-
* tracks what it last SENT; it moves only after a send was accepted, and a
|
|
55420
|
-
* human at the real remote makes it wrong. A UI shows an assumed value as a
|
|
55421
|
-
* guess, never as a reading.
|
|
55422
|
-
*/
|
|
55423
|
-
var MediaPlayerStateSourceSchema = _enum(["reported", "assumed"]);
|
|
55424
|
-
/** The fields of a media-player status a driver can only guess. */
|
|
55425
|
-
var MediaPlayerAssumedFieldSchema = _enum([
|
|
55426
|
-
"state",
|
|
55427
|
-
"volumeLevel",
|
|
55428
|
-
"isMuted",
|
|
55429
|
-
"source"
|
|
55430
|
-
]);
|
|
55431
|
-
object({
|
|
55432
|
-
/** Playback lifecycle state. */
|
|
55433
|
-
state: MediaPlayerStateSchema,
|
|
55434
|
-
/**
|
|
55435
|
-
* Whether the state fields are readings or the driver's own bookkeeping.
|
|
55436
|
-
* A slice written before this field existed parses as `reported`.
|
|
55437
|
-
*/
|
|
55438
|
-
stateSource: MediaPlayerStateSourceSchema.default("reported"),
|
|
55439
|
-
/**
|
|
55440
|
-
* Which fields are the driver's own guess. `stateSource` is `assumed` when
|
|
55441
|
-
* this is not empty; a field not listed here is a reading even then (power
|
|
55442
|
-
* from a running-state source, mute guessed from the last send).
|
|
55443
|
-
*/
|
|
55444
|
-
assumedFields: array(MediaPlayerAssumedFieldSchema).default([]),
|
|
55445
|
-
/** Volume as 0..100 inclusive. Null when the device has no volume
|
|
55446
|
-
* surface. Pair with `DeviceFeature.MediaPlayerVolume`. */
|
|
55447
|
-
volumeLevel: number().min(0).max(100).nullable().meta(readingMeta("percentage")),
|
|
55448
|
-
/** Mute toggle distinct from volume=0. Null when no mute surface.
|
|
55449
|
-
* Pair with `DeviceFeature.MediaPlayerMute`. */
|
|
55450
|
-
isMuted: boolean().nullable(),
|
|
55451
|
-
/** Active source / input. Empty when no source surface. */
|
|
55452
|
-
source: string(),
|
|
55453
|
-
/** Selectable sources. Empty when no source surface.
|
|
55454
|
-
* Pair with `DeviceFeature.MediaPlayerSelectSource`. */
|
|
55455
|
-
availableSources: array(string()),
|
|
55456
|
-
/** Currently-playing media info. Null when nothing is playing. */
|
|
55457
|
-
currentMedia: MediaInfoSchema.nullable(),
|
|
55458
|
-
/** Current playback position in ms. Null when not seekable or
|
|
55459
|
-
* nothing is playing. Pair with `DeviceFeature.MediaPlayerSeek`. */
|
|
55460
|
-
position: number().int().nonnegative().nullable().meta(readingMeta("duration-ms")),
|
|
55461
|
-
/** Total duration of the current media in ms. Null when unknown
|
|
55462
|
-
* (live stream) or nothing is playing. */
|
|
55463
|
-
duration: number().int().nonnegative().nullable().meta(readingMeta("duration-ms")),
|
|
55464
|
-
/** Shuffle toggle. Null when no shuffle surface.
|
|
55465
|
-
* Pair with `DeviceFeature.MediaPlayerShuffle`. */
|
|
55466
|
-
shuffle: boolean().nullable(),
|
|
55467
|
-
/** Repeat mode. Null when no repeat surface.
|
|
55468
|
-
* Pair with `DeviceFeature.MediaPlayerRepeat`. */
|
|
55469
|
-
repeat: MediaPlayerRepeatSchema.nullable(),
|
|
55470
|
-
/** Ms epoch when the slice was last updated. */
|
|
55471
|
-
lastChangedAt: number()
|
|
55472
|
-
});
|
|
55473
|
-
DeviceType.MediaPlayer, method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
55474
|
-
kind: "mutation",
|
|
55475
|
-
auth: "protected"
|
|
55476
|
-
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
55477
|
-
kind: "mutation",
|
|
55478
|
-
auth: "protected"
|
|
55479
|
-
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
55480
|
-
kind: "mutation",
|
|
55481
|
-
auth: "protected"
|
|
55482
|
-
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
55483
|
-
kind: "mutation",
|
|
55484
|
-
auth: "protected"
|
|
55485
|
-
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
55486
|
-
kind: "mutation",
|
|
55487
|
-
auth: "protected"
|
|
55488
|
-
}), method(object({
|
|
55489
|
-
deviceId: number().int().nonnegative(),
|
|
55490
|
-
position: number().int().nonnegative()
|
|
55491
|
-
}), _void(), {
|
|
55492
|
-
kind: "mutation",
|
|
55493
|
-
auth: "protected"
|
|
55494
|
-
}), method(object({
|
|
55495
|
-
deviceId: number().int().nonnegative(),
|
|
55496
|
-
volumeLevel: number().min(0).max(100)
|
|
55497
|
-
}), _void(), {
|
|
55498
|
-
kind: "mutation",
|
|
55499
|
-
auth: "protected"
|
|
55500
|
-
}), method(object({
|
|
55501
|
-
deviceId: number().int().nonnegative(),
|
|
55502
|
-
muted: boolean()
|
|
55503
|
-
}), _void(), {
|
|
55504
|
-
kind: "mutation",
|
|
55505
|
-
auth: "protected"
|
|
55506
|
-
}), method(object({
|
|
55507
|
-
deviceId: number().int().nonnegative(),
|
|
55508
|
-
shuffle: boolean()
|
|
55509
|
-
}), _void(), {
|
|
55510
|
-
kind: "mutation",
|
|
55511
|
-
auth: "protected"
|
|
55512
|
-
}), method(object({
|
|
55513
|
-
deviceId: number().int().nonnegative(),
|
|
55514
|
-
repeat: MediaPlayerRepeatSchema
|
|
55515
|
-
}), _void(), {
|
|
55516
|
-
kind: "mutation",
|
|
55517
|
-
auth: "protected"
|
|
55518
|
-
}), method(object({
|
|
55519
|
-
deviceId: number().int().nonnegative(),
|
|
55520
|
-
source: string().min(1)
|
|
55521
|
-
}), _void(), {
|
|
55522
|
-
kind: "mutation",
|
|
55523
|
-
auth: "protected"
|
|
55524
|
-
}), method(object({
|
|
55525
|
-
deviceId: number().int().nonnegative(),
|
|
55526
|
-
/** Media identifier / URL. */
|
|
55527
|
-
mediaId: string().min(1),
|
|
55528
|
-
/** Media kind (`music`, `tvshow`, `movie`, `app`, …) — provider
|
|
55529
|
-
* passes it through to the upstream service. */
|
|
55530
|
-
mediaType: string().min(1)
|
|
55531
|
-
}), _void(), {
|
|
55532
|
-
kind: "mutation",
|
|
55533
|
-
auth: "protected"
|
|
55534
|
-
});
|
|
55535
|
-
/**
|
|
55536
56333
|
* mesh-network — collection cap for mesh-VPN providers.
|
|
55537
56334
|
*
|
|
55538
56335
|
* Different shape from `network-access` (public tunnels):
|
|
@@ -63825,6 +64622,21 @@ var NcTemplateVarKindSchema = _enum([
|
|
|
63825
64622
|
"sound",
|
|
63826
64623
|
"system"
|
|
63827
64624
|
]);
|
|
64625
|
+
/**
|
|
64626
|
+
* The default title/body a rule of one SITUATION is delivered with when the
|
|
64627
|
+
* operator wrote no template — served so an editor can pre-fill it (and the
|
|
64628
|
+
* operator can rebuild it from placeholders) instead of starting from a blank
|
|
64629
|
+
* box that, once saved, silently replaces it. `id` names the situation inside
|
|
64630
|
+
* a rule `kind`: `appliance-cycle` is a `sensor` rule whose device is an
|
|
64631
|
+
* appliance finishing a cycle. Texts are raw templates (`{{var}}` intact), in
|
|
64632
|
+
* the hub's current language and with its overrides applied.
|
|
64633
|
+
*/
|
|
64634
|
+
var NcTemplateDefaultSchema = object({
|
|
64635
|
+
id: _enum(["appliance-cycle"]),
|
|
64636
|
+
kind: NcRuleKindSchema,
|
|
64637
|
+
title: string(),
|
|
64638
|
+
body: string()
|
|
64639
|
+
});
|
|
63828
64640
|
/** Which producer renders a template: an ordinary rule, a timelapse, a digest. */
|
|
63829
64641
|
var NcTemplateFamilySchema = _enum([
|
|
63830
64642
|
"rule",
|
|
@@ -64680,7 +65492,11 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
|
|
|
64680
65492
|
}), method(object({}), object({
|
|
64681
65493
|
catalog: array(NcConditionDescriptorSchema),
|
|
64682
65494
|
taxonomy: NcTaxonomySchema.optional()
|
|
64683
|
-
})), method(object({}), object({
|
|
65495
|
+
})), method(object({}), object({
|
|
65496
|
+
vars: array(NcTemplateVarDescriptorSchema),
|
|
65497
|
+
/** Per-situation default texts; absent on a hub that predates them. */
|
|
65498
|
+
defaults: array(NcTemplateDefaultSchema)
|
|
65499
|
+
})), method(NcTemplatePreviewInputSchema, NcTemplatePreviewSchema, {
|
|
64684
65500
|
kind: "mutation",
|
|
64685
65501
|
access: "view"
|
|
64686
65502
|
}), method(object({ filter: NcHistoryFilterSchema.default({ limit: 100 }) }), object({ entries: array(NcHistoryEntrySchema) }), { auth: "admin" }), method(object({}), NcRuleLastRunsSchema, { auth: "admin" }), method(object({ artifactId: string().min(1) }), object({ url: string().nullable() }), { auth: "admin" }), method(object({}), object({ snoozes: array(NcSnoozeSchema) }), { caller: "required" }), method(object({ snooze: NcSnoozeInputSchema }), object({ snooze: NcSnoozeSchema }), {
|
|
@@ -70168,7 +70984,13 @@ var RemoteMediaCommandSchema = _enum([
|
|
|
70168
70984
|
"next",
|
|
70169
70985
|
"previous",
|
|
70170
70986
|
"setMute",
|
|
70171
|
-
"selectSource"
|
|
70987
|
+
"selectSource",
|
|
70988
|
+
"turnOn",
|
|
70989
|
+
"turnOff",
|
|
70990
|
+
"volumeUp",
|
|
70991
|
+
"volumeDown",
|
|
70992
|
+
"channelUp",
|
|
70993
|
+
"channelDown"
|
|
70172
70994
|
]);
|
|
70173
70995
|
/** A send result, or `not-routed`: the role is not bound, so the native cap answers. */
|
|
70174
70996
|
var RemoteMediaCommandResultSchema = discriminatedUnion("status", [...RemoteSendResultSchema.options, object({ status: literal("not-routed") })]);
|
|
@@ -70189,7 +71011,7 @@ method(deviceInput, RemoteConfigSchema, { auth: "admin" }), method(deviceInput.e
|
|
|
70189
71011
|
}), RemoteSendResultSchema, {
|
|
70190
71012
|
kind: "mutation",
|
|
70191
71013
|
auth: "protected"
|
|
70192
|
-
}), method(deviceInput.extend({
|
|
71014
|
+
}), method(deviceInput, MediaPlayerStatusSchema.nullable(), { auth: "protected" }), method(deviceInput.extend({
|
|
70193
71015
|
command: RemoteMediaCommandSchema,
|
|
70194
71016
|
muted: boolean().optional(),
|
|
70195
71017
|
source: string().optional(),
|
|
@@ -72024,7 +72846,11 @@ Object.values(DeviceType), method(_void(), array(StreamSignalSchema).readonly())
|
|
|
72024
72846
|
* `getSettingsUISchema()` surface.
|
|
72025
72847
|
*/
|
|
72026
72848
|
var SwitchStatusSchema = object({
|
|
72027
|
-
|
|
72849
|
+
/**
|
|
72850
|
+
* `null` = the device has never reported its state (a measurement that
|
|
72851
|
+
* has not happened is unknown, never `false`).
|
|
72852
|
+
*/
|
|
72853
|
+
on: boolean().nullable().meta({ label: "On" }),
|
|
72028
72854
|
/** Ms epoch of the last state change. Useful for UI "X minutes ago". */
|
|
72029
72855
|
lastChangedAt: number()
|
|
72030
72856
|
});
|
|
@@ -72036,7 +72862,7 @@ DeviceType.Switch, DeviceType.Siren, DeviceType.Light, DeviceType.Fan, DeviceTyp
|
|
|
72036
72862
|
auth: "protected"
|
|
72037
72863
|
}), object({
|
|
72038
72864
|
deviceId: number(),
|
|
72039
|
-
on: boolean(),
|
|
72865
|
+
on: boolean().nullable(),
|
|
72040
72866
|
lastChangedAt: number()
|
|
72041
72867
|
});
|
|
72042
72868
|
/** C0 controls, DEL and the C1 range: none of them belongs in a name. */
|
|
@@ -75060,6 +75886,7 @@ function buildDescriptor(capName, kind) {
|
|
|
75060
75886
|
* contributes one entry per bound cap present in this map.
|
|
75061
75887
|
*/
|
|
75062
75888
|
var EVENT_KIND_BY_CAP = Object.freeze(Object.fromEntries(Object.entries(CAP_TO_KIND).map(([capName, kind]) => [capName, buildDescriptor(capName, kind)])));
|
|
75889
|
+
DeviceFeature.MediaPlayerPower, DeviceFeature.MediaPlayerVolumeStep, DeviceFeature.MediaPlayerChannelStep, DeviceFeature.MediaPlayerMute, DeviceFeature.MediaPlayerStop, DeviceFeature.MediaPlayerNext, DeviceFeature.MediaPlayerPrevious;
|
|
75063
75890
|
var btn = (idSuffix, row, col, init) => ({
|
|
75064
75891
|
idSuffix,
|
|
75065
75892
|
row,
|
|
@@ -79674,6 +80501,20 @@ Object.freeze({
|
|
|
79674
80501
|
access: "view",
|
|
79675
80502
|
role: "admin"
|
|
79676
80503
|
},
|
|
80504
|
+
"mediaPlayer.channelDown": {
|
|
80505
|
+
capName: "media-player",
|
|
80506
|
+
capScope: "device",
|
|
80507
|
+
addonId: null,
|
|
80508
|
+
access: "create",
|
|
80509
|
+
role: "viewer"
|
|
80510
|
+
},
|
|
80511
|
+
"mediaPlayer.channelUp": {
|
|
80512
|
+
capName: "media-player",
|
|
80513
|
+
capScope: "device",
|
|
80514
|
+
addonId: null,
|
|
80515
|
+
access: "create",
|
|
80516
|
+
role: "viewer"
|
|
80517
|
+
},
|
|
79677
80518
|
"mediaPlayer.getStatus": {
|
|
79678
80519
|
capName: "media-player",
|
|
79679
80520
|
capScope: "device",
|
|
@@ -79765,6 +80606,34 @@ Object.freeze({
|
|
|
79765
80606
|
access: "create",
|
|
79766
80607
|
role: "viewer"
|
|
79767
80608
|
},
|
|
80609
|
+
"mediaPlayer.turnOff": {
|
|
80610
|
+
capName: "media-player",
|
|
80611
|
+
capScope: "device",
|
|
80612
|
+
addonId: null,
|
|
80613
|
+
access: "create",
|
|
80614
|
+
role: "viewer"
|
|
80615
|
+
},
|
|
80616
|
+
"mediaPlayer.turnOn": {
|
|
80617
|
+
capName: "media-player",
|
|
80618
|
+
capScope: "device",
|
|
80619
|
+
addonId: null,
|
|
80620
|
+
access: "create",
|
|
80621
|
+
role: "viewer"
|
|
80622
|
+
},
|
|
80623
|
+
"mediaPlayer.volumeDown": {
|
|
80624
|
+
capName: "media-player",
|
|
80625
|
+
capScope: "device",
|
|
80626
|
+
addonId: null,
|
|
80627
|
+
access: "create",
|
|
80628
|
+
role: "viewer"
|
|
80629
|
+
},
|
|
80630
|
+
"mediaPlayer.volumeUp": {
|
|
80631
|
+
capName: "media-player",
|
|
80632
|
+
capScope: "device",
|
|
80633
|
+
addonId: null,
|
|
80634
|
+
access: "create",
|
|
80635
|
+
role: "viewer"
|
|
80636
|
+
},
|
|
79768
80637
|
"meshNetwork.getStatus": {
|
|
79769
80638
|
capName: "mesh-network",
|
|
79770
80639
|
capScope: "system",
|
|
@@ -83321,6 +84190,13 @@ Object.freeze({
|
|
|
83321
84190
|
access: "create",
|
|
83322
84191
|
role: "admin"
|
|
83323
84192
|
},
|
|
84193
|
+
"remote.getAssumedStatus": {
|
|
84194
|
+
capName: "remote",
|
|
84195
|
+
capScope: "system",
|
|
84196
|
+
addonId: null,
|
|
84197
|
+
access: "view",
|
|
84198
|
+
role: "admin"
|
|
84199
|
+
},
|
|
83324
84200
|
"remote.getConfig": {
|
|
83325
84201
|
capName: "remote",
|
|
83326
84202
|
capScope: "system",
|
|
@@ -87012,6 +87888,16 @@ Object.freeze({
|
|
|
87012
87888
|
form: "single",
|
|
87013
87889
|
optional: true
|
|
87014
87890
|
}],
|
|
87891
|
+
"mediaPlayer.channelDown": [{
|
|
87892
|
+
name: "deviceId",
|
|
87893
|
+
form: "single",
|
|
87894
|
+
optional: false
|
|
87895
|
+
}],
|
|
87896
|
+
"mediaPlayer.channelUp": [{
|
|
87897
|
+
name: "deviceId",
|
|
87898
|
+
form: "single",
|
|
87899
|
+
optional: false
|
|
87900
|
+
}],
|
|
87015
87901
|
"mediaPlayer.getStatus": [{
|
|
87016
87902
|
name: "deviceId",
|
|
87017
87903
|
form: "single",
|
|
@@ -87077,6 +87963,26 @@ Object.freeze({
|
|
|
87077
87963
|
form: "single",
|
|
87078
87964
|
optional: false
|
|
87079
87965
|
}],
|
|
87966
|
+
"mediaPlayer.turnOff": [{
|
|
87967
|
+
name: "deviceId",
|
|
87968
|
+
form: "single",
|
|
87969
|
+
optional: false
|
|
87970
|
+
}],
|
|
87971
|
+
"mediaPlayer.turnOn": [{
|
|
87972
|
+
name: "deviceId",
|
|
87973
|
+
form: "single",
|
|
87974
|
+
optional: false
|
|
87975
|
+
}],
|
|
87976
|
+
"mediaPlayer.volumeDown": [{
|
|
87977
|
+
name: "deviceId",
|
|
87978
|
+
form: "single",
|
|
87979
|
+
optional: false
|
|
87980
|
+
}],
|
|
87981
|
+
"mediaPlayer.volumeUp": [{
|
|
87982
|
+
name: "deviceId",
|
|
87983
|
+
form: "single",
|
|
87984
|
+
optional: false
|
|
87985
|
+
}],
|
|
87080
87986
|
"meter.getStatus": [{
|
|
87081
87987
|
name: "deviceId",
|
|
87082
87988
|
form: "single",
|
|
@@ -88242,6 +89148,11 @@ Object.freeze({
|
|
|
88242
89148
|
form: "single",
|
|
88243
89149
|
optional: true
|
|
88244
89150
|
}],
|
|
89151
|
+
"remote.getAssumedStatus": [{
|
|
89152
|
+
name: "deviceId",
|
|
89153
|
+
form: "single",
|
|
89154
|
+
optional: false
|
|
89155
|
+
}],
|
|
88245
89156
|
"remote.getConfig": [{
|
|
88246
89157
|
name: "deviceId",
|
|
88247
89158
|
form: "single",
|
|
@@ -89497,6 +90408,7 @@ var STATE_SUMMARY_VARS = [
|
|
|
89497
90408
|
[...RULE_TEXT],
|
|
89498
90409
|
([...RULE_TEXT], [...DEVICE_EVENTS]),
|
|
89499
90410
|
([...RULE_TEXT], [...COMBINED_ALARM]),
|
|
90411
|
+
([...RULE_TEXT], [...COMBINED_ALARM]),
|
|
89500
90412
|
([...RULE_TEXT], [...DEVICE_EVENTS]),
|
|
89501
90413
|
([...RULE_TEXT], [...BATTERY, ...CONSUMABLE]),
|
|
89502
90414
|
([...RULE_TEXT], [...CONSUMABLE]),
|
|
@@ -91706,8 +92618,8 @@ function climateProperties(slice) {
|
|
|
91706
92618
|
//#endregion
|
|
91707
92619
|
//#region src/handlers/climate-controller.ts
|
|
91708
92620
|
var CAP_CLIMATE = "climate-control";
|
|
91709
|
-
var CAP_SWITCH$
|
|
91710
|
-
var UNCERTAINTY_MS$
|
|
92621
|
+
var CAP_SWITCH$2 = "switch";
|
|
92622
|
+
var UNCERTAINTY_MS$2 = 500;
|
|
91711
92623
|
var PRESET_NONE = "none";
|
|
91712
92624
|
var ScaleSchema = _enum([
|
|
91713
92625
|
"CELSIUS",
|
|
@@ -92004,7 +92916,7 @@ function successResponse$2(c, properties) {
|
|
|
92004
92916
|
context: { properties: properties.map((p) => ({
|
|
92005
92917
|
...p,
|
|
92006
92918
|
timeOfSample: now,
|
|
92007
|
-
uncertaintyInMilliseconds: UNCERTAINTY_MS$
|
|
92919
|
+
uncertaintyInMilliseconds: UNCERTAINTY_MS$2
|
|
92008
92920
|
})) }
|
|
92009
92921
|
};
|
|
92010
92922
|
}
|
|
@@ -92046,7 +92958,7 @@ async function handlesPower(c) {
|
|
|
92046
92958
|
lastPowerClaim.set(deps, known);
|
|
92047
92959
|
try {
|
|
92048
92960
|
const caps = (await deps.ctx.api.deviceManager.getBindings.query({ deviceId: c.deviceId })).entries.map((e) => e.capName);
|
|
92049
|
-
const claim = caps.includes(CAP_CLIMATE) && !caps.includes(CAP_SWITCH$
|
|
92961
|
+
const claim = caps.includes(CAP_CLIMATE) && !caps.includes(CAP_SWITCH$2);
|
|
92050
92962
|
known.set(c.deviceId, claim);
|
|
92051
92963
|
return claim;
|
|
92052
92964
|
} catch (err) {
|
|
@@ -93106,7 +94018,7 @@ function fanProperties(slice) {
|
|
|
93106
94018
|
//#endregion
|
|
93107
94019
|
//#region src/handlers/fan-controller.ts
|
|
93108
94020
|
var CAP_FAN = "fan-control";
|
|
93109
|
-
var UNCERTAINTY_MS = 500;
|
|
94021
|
+
var UNCERTAINTY_MS$1 = 500;
|
|
93110
94022
|
/** What AdjustRangeValue moves by when the device states no step of its own. */
|
|
93111
94023
|
var DEFAULT_ADJUST = 10;
|
|
93112
94024
|
var SetRangePayload = object({ rangeValue: number() });
|
|
@@ -93118,7 +94030,7 @@ var SetModePayload = object({ mode: string() });
|
|
|
93118
94030
|
function clamp(value) {
|
|
93119
94031
|
return Math.max(0, Math.min(100, Math.round(value)));
|
|
93120
94032
|
}
|
|
93121
|
-
function message(err) {
|
|
94033
|
+
function message$1(err) {
|
|
93122
94034
|
return err instanceof Error ? err.message : String(err);
|
|
93123
94035
|
}
|
|
93124
94036
|
async function readSlice(c, deps) {
|
|
@@ -93130,7 +94042,7 @@ async function readSlice(c, deps) {
|
|
|
93130
94042
|
} catch (err) {
|
|
93131
94043
|
deps.logger.warn("alexa fan-controller: the fan state could not be read", {
|
|
93132
94044
|
tags: { deviceId: c.deviceId },
|
|
93133
|
-
meta: { error: message(err) }
|
|
94045
|
+
meta: { error: message$1(err) }
|
|
93134
94046
|
});
|
|
93135
94047
|
return null;
|
|
93136
94048
|
}
|
|
@@ -93152,7 +94064,7 @@ function successResponse$1(c, properties) {
|
|
|
93152
94064
|
context: { properties: properties.map((p) => ({
|
|
93153
94065
|
...p,
|
|
93154
94066
|
timeOfSample: now,
|
|
93155
|
-
uncertaintyInMilliseconds: UNCERTAINTY_MS
|
|
94067
|
+
uncertaintyInMilliseconds: UNCERTAINTY_MS$1
|
|
93156
94068
|
})) }
|
|
93157
94069
|
};
|
|
93158
94070
|
}
|
|
@@ -93170,7 +94082,7 @@ async function setSpeed(c, deps, slice, speed) {
|
|
|
93170
94082
|
tags: { deviceId: c.deviceId },
|
|
93171
94083
|
meta: {
|
|
93172
94084
|
speed,
|
|
93173
|
-
error: message(err)
|
|
94085
|
+
error: message$1(err)
|
|
93174
94086
|
}
|
|
93175
94087
|
});
|
|
93176
94088
|
return unreachable(c, "the fan did not accept the speed");
|
|
@@ -93213,7 +94125,7 @@ async function handleToggle(c, deps) {
|
|
|
93213
94125
|
tags: { deviceId: c.deviceId },
|
|
93214
94126
|
meta: {
|
|
93215
94127
|
oscillating,
|
|
93216
|
-
error: message(err)
|
|
94128
|
+
error: message$1(err)
|
|
93217
94129
|
}
|
|
93218
94130
|
});
|
|
93219
94131
|
return unreachable(c, "the fan did not accept the command");
|
|
@@ -93233,7 +94145,7 @@ async function customNames(c, deps) {
|
|
|
93233
94145
|
} catch (err) {
|
|
93234
94146
|
deps.logger.warn("alexa fan-controller: the custom presets could not be read", {
|
|
93235
94147
|
tags: { deviceId: c.deviceId },
|
|
93236
|
-
meta: { error: message(err) }
|
|
94148
|
+
meta: { error: message$1(err) }
|
|
93237
94149
|
});
|
|
93238
94150
|
return [];
|
|
93239
94151
|
}
|
|
@@ -93256,7 +94168,7 @@ async function handleMode(c, deps) {
|
|
|
93256
94168
|
tags: { deviceId: c.deviceId },
|
|
93257
94169
|
meta: {
|
|
93258
94170
|
preset: mode.name,
|
|
93259
|
-
error: message(err)
|
|
94171
|
+
error: message$1(err)
|
|
93260
94172
|
}
|
|
93261
94173
|
});
|
|
93262
94174
|
return unreachable(c, "the fan did not accept the preset");
|
|
@@ -93308,7 +94220,7 @@ async function applyCustom(c, deps, name) {
|
|
|
93308
94220
|
tags: { deviceId: c.deviceId },
|
|
93309
94221
|
meta: {
|
|
93310
94222
|
preset: name,
|
|
93311
|
-
error: message(err)
|
|
94223
|
+
error: message$1(err)
|
|
93312
94224
|
}
|
|
93313
94225
|
});
|
|
93314
94226
|
return unreachable(c, "the preset could not be applied");
|
|
@@ -93504,6 +94416,397 @@ var lockAdapter = {
|
|
|
93504
94416
|
shaping: unshaped
|
|
93505
94417
|
};
|
|
93506
94418
|
//#endregion
|
|
94419
|
+
//#region src/endpoints/adapters/media-player-model.ts
|
|
94420
|
+
/**
|
|
94421
|
+
* A media player exported as a TV (planning#398). What Alexa is told depends on
|
|
94422
|
+
* what the player can DO (its features) and what it REPORTS (its slice):
|
|
94423
|
+
*
|
|
94424
|
+
* power → `Alexa.PowerController` (feature `media-player-power`)
|
|
94425
|
+
* volume ±N → `Alexa.StepSpeaker` (feature `media-player-volume-step`)
|
|
94426
|
+
* mute → `Alexa.Speaker` (`muted` only) (feature `media-player-mute`)
|
|
94427
|
+
* channel ±N → `Alexa.ChannelController` (feature `media-player-channel-step`)
|
|
94428
|
+
* transport → `Alexa.PlaybackController` (stop / next / previous by feature; play and
|
|
94429
|
+
* pause only when the player REPORTS its state,
|
|
94430
|
+
* since an assumed one cannot tell)
|
|
94431
|
+
* inputs → `Alexa.InputController` (the reported sources Amazon names)
|
|
94432
|
+
*
|
|
94433
|
+
* A property is reported only for a known value: an assumed `standby`, a null
|
|
94434
|
+
* mute and an unlisted volume or input produce no property at all (D393).
|
|
94435
|
+
*/
|
|
94436
|
+
var CAP_MEDIA_PLAYER = "media-player";
|
|
94437
|
+
/** The input names Amazon accepts for `Alexa.InputController` (alexa-inputcontroller). */
|
|
94438
|
+
var AMAZON_INPUTS = [
|
|
94439
|
+
...Array.from({ length: 7 }, (_, i) => `AUX ${i + 1}`),
|
|
94440
|
+
"BLURAY",
|
|
94441
|
+
"CABLE",
|
|
94442
|
+
"CD",
|
|
94443
|
+
"COAX 1",
|
|
94444
|
+
"COAX 2",
|
|
94445
|
+
"COMPOSITE 1",
|
|
94446
|
+
"DVD",
|
|
94447
|
+
"GAME",
|
|
94448
|
+
"HD RADIO",
|
|
94449
|
+
...Array.from({ length: 10 }, (_, i) => `HDMI ${i + 1}`),
|
|
94450
|
+
"HDMI ARC",
|
|
94451
|
+
...Array.from({ length: 10 }, (_, i) => `INPUT ${i + 1}`),
|
|
94452
|
+
"IPOD",
|
|
94453
|
+
...Array.from({ length: 7 }, (_, i) => `LINE ${i + 1}`),
|
|
94454
|
+
"MEDIA PLAYER",
|
|
94455
|
+
"OPTICAL 1",
|
|
94456
|
+
"OPTICAL 2",
|
|
94457
|
+
"PHONO",
|
|
94458
|
+
"PLAYSTATION",
|
|
94459
|
+
"PLAYSTATION 3",
|
|
94460
|
+
"PLAYSTATION 4",
|
|
94461
|
+
"SATELLITE",
|
|
94462
|
+
"SMARTCAST",
|
|
94463
|
+
"TUNER",
|
|
94464
|
+
"TV",
|
|
94465
|
+
"USB",
|
|
94466
|
+
"USB DAC",
|
|
94467
|
+
"VIDEO 1",
|
|
94468
|
+
"VIDEO 2",
|
|
94469
|
+
"VIDEO 3",
|
|
94470
|
+
"XBOX"
|
|
94471
|
+
];
|
|
94472
|
+
function squash(name) {
|
|
94473
|
+
return name.toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
94474
|
+
}
|
|
94475
|
+
/** The Amazon input a source name stands for ("hdmi1" → "HDMI 1"), or null. */
|
|
94476
|
+
function amazonInputOf(source) {
|
|
94477
|
+
const wanted = squash(source);
|
|
94478
|
+
return AMAZON_INPUTS.find((name) => squash(name) === wanted) ?? null;
|
|
94479
|
+
}
|
|
94480
|
+
/** The sources of a slice that Amazon has a name for, paired with the player's own name. */
|
|
94481
|
+
function inputPairs(status) {
|
|
94482
|
+
const seen = /* @__PURE__ */ new Set();
|
|
94483
|
+
const pairs = [];
|
|
94484
|
+
for (const source of status.availableSources) {
|
|
94485
|
+
const amazon = amazonInputOf(source);
|
|
94486
|
+
if (amazon === null || seen.has(amazon)) continue;
|
|
94487
|
+
seen.add(amazon);
|
|
94488
|
+
pairs.push({
|
|
94489
|
+
amazon,
|
|
94490
|
+
source
|
|
94491
|
+
});
|
|
94492
|
+
}
|
|
94493
|
+
return pairs;
|
|
94494
|
+
}
|
|
94495
|
+
function readMediaPlayerSlice(slice) {
|
|
94496
|
+
const parsed = MediaPlayerStatusSchema.safeParse(slice);
|
|
94497
|
+
return parsed.success ? parsed.data : null;
|
|
94498
|
+
}
|
|
94499
|
+
var PLAYBACK_BY_FEATURE = [
|
|
94500
|
+
[DeviceFeature.MediaPlayerStop, "Stop"],
|
|
94501
|
+
[DeviceFeature.MediaPlayerNext, "Next"],
|
|
94502
|
+
[DeviceFeature.MediaPlayerPrevious, "Previous"]
|
|
94503
|
+
];
|
|
94504
|
+
function playbackOperations(device, status) {
|
|
94505
|
+
return [...status !== null && status.stateSource === "reported" ? ["Play", "Pause"] : [], ...PLAYBACK_BY_FEATURE.filter(([feature]) => device.features.includes(feature)).map(([, operation]) => operation)];
|
|
94506
|
+
}
|
|
94507
|
+
function describeMediaPlayerCapabilities(device) {
|
|
94508
|
+
const has = (feature) => device.features.includes(feature);
|
|
94509
|
+
const status = readMediaPlayerSlice(device.slices[CAP_MEDIA_PLAYER]);
|
|
94510
|
+
const capabilities = [];
|
|
94511
|
+
if (has(DeviceFeature.MediaPlayerPower)) capabilities.push(iface("Alexa.PowerController", "powerState"));
|
|
94512
|
+
if (has(DeviceFeature.MediaPlayerVolumeStep)) capabilities.push({
|
|
94513
|
+
type: "AlexaInterface",
|
|
94514
|
+
interface: "Alexa.StepSpeaker",
|
|
94515
|
+
version: "3"
|
|
94516
|
+
});
|
|
94517
|
+
if (has(DeviceFeature.MediaPlayerMute)) capabilities.push(iface("Alexa.Speaker", "muted"));
|
|
94518
|
+
if (has(DeviceFeature.MediaPlayerChannelStep)) capabilities.push({
|
|
94519
|
+
type: "AlexaInterface",
|
|
94520
|
+
interface: "Alexa.ChannelController",
|
|
94521
|
+
version: "3"
|
|
94522
|
+
});
|
|
94523
|
+
const operations = playbackOperations(device, status);
|
|
94524
|
+
if (operations.length > 0) capabilities.push({
|
|
94525
|
+
type: "AlexaInterface",
|
|
94526
|
+
interface: "Alexa.PlaybackController",
|
|
94527
|
+
version: "3",
|
|
94528
|
+
supportedOperations: operations
|
|
94529
|
+
});
|
|
94530
|
+
const inputs = status === null ? [] : inputPairs(status);
|
|
94531
|
+
if (has(DeviceFeature.MediaPlayerSelectSource) && inputs.length > 0) capabilities.push({
|
|
94532
|
+
...iface("Alexa.InputController", "input"),
|
|
94533
|
+
inputs: inputs.map((i) => ({ name: i.amazon }))
|
|
94534
|
+
});
|
|
94535
|
+
return capabilities;
|
|
94536
|
+
}
|
|
94537
|
+
/** The Alexa properties of a slice: only what is known. */
|
|
94538
|
+
function mediaPlayerProperties(slice) {
|
|
94539
|
+
const status = readMediaPlayerSlice(slice);
|
|
94540
|
+
if (status === null) return [];
|
|
94541
|
+
const out = [];
|
|
94542
|
+
if (status.state === "off") out.push({
|
|
94543
|
+
namespace: "Alexa.PowerController",
|
|
94544
|
+
name: "powerState",
|
|
94545
|
+
value: "OFF"
|
|
94546
|
+
});
|
|
94547
|
+
else if (status.state !== "standby") out.push({
|
|
94548
|
+
namespace: "Alexa.PowerController",
|
|
94549
|
+
name: "powerState",
|
|
94550
|
+
value: "ON"
|
|
94551
|
+
});
|
|
94552
|
+
if (status.isMuted !== null) out.push({
|
|
94553
|
+
namespace: "Alexa.Speaker",
|
|
94554
|
+
name: "muted",
|
|
94555
|
+
value: status.isMuted
|
|
94556
|
+
});
|
|
94557
|
+
const input = inputPairs(status).find((i) => i.source === status.source);
|
|
94558
|
+
if (input !== void 0) out.push({
|
|
94559
|
+
namespace: "Alexa.InputController",
|
|
94560
|
+
name: "input",
|
|
94561
|
+
value: input.amazon
|
|
94562
|
+
});
|
|
94563
|
+
return out;
|
|
94564
|
+
}
|
|
94565
|
+
//#endregion
|
|
94566
|
+
//#region src/handlers/media-player-controller.ts
|
|
94567
|
+
var UNCERTAINTY_MS = 1e3;
|
|
94568
|
+
var CAP_SWITCH$1 = "switch";
|
|
94569
|
+
var StepsPayload = object({ volumeSteps: number().int() });
|
|
94570
|
+
var ChannelPayload = object({ channelCount: number().int() });
|
|
94571
|
+
var MutePayload = object({ mute: boolean() });
|
|
94572
|
+
var InputPayload = object({ input: string() });
|
|
94573
|
+
function message(err) {
|
|
94574
|
+
return err instanceof Error ? err.message : String(err);
|
|
94575
|
+
}
|
|
94576
|
+
function success(c, properties) {
|
|
94577
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
94578
|
+
return {
|
|
94579
|
+
event: {
|
|
94580
|
+
header: {
|
|
94581
|
+
namespace: "Alexa",
|
|
94582
|
+
name: "Response",
|
|
94583
|
+
messageId: c.header.messageId,
|
|
94584
|
+
...c.header.correlationToken !== void 0 ? { correlationToken: c.header.correlationToken } : {},
|
|
94585
|
+
payloadVersion: "3"
|
|
94586
|
+
},
|
|
94587
|
+
endpoint: { endpointId: c.endpoint.endpointId },
|
|
94588
|
+
payload: {}
|
|
94589
|
+
},
|
|
94590
|
+
context: { properties: properties.map((p) => ({
|
|
94591
|
+
...p,
|
|
94592
|
+
timeOfSample: now,
|
|
94593
|
+
uncertaintyInMilliseconds: UNCERTAINTY_MS
|
|
94594
|
+
})) }
|
|
94595
|
+
};
|
|
94596
|
+
}
|
|
94597
|
+
/** PowerController on a media player, not on a switch: decided by the bound caps. */
|
|
94598
|
+
async function claimsMediaPlayerPower(c) {
|
|
94599
|
+
const deps = c.deps.mediaPlayerController;
|
|
94600
|
+
try {
|
|
94601
|
+
const caps = (await deps.ctx.api.deviceManager.getBindings.query({ deviceId: c.deviceId })).entries.map((e) => e.capName);
|
|
94602
|
+
return caps.includes("media-player") && !caps.includes(CAP_SWITCH$1);
|
|
94603
|
+
} catch (err) {
|
|
94604
|
+
deps.logger.warn("alexa media-player-controller: the bound caps could not be read", {
|
|
94605
|
+
tags: { deviceId: c.deviceId },
|
|
94606
|
+
meta: {
|
|
94607
|
+
error: message(err),
|
|
94608
|
+
decidedFrom: "no previous answer: not claimed"
|
|
94609
|
+
}
|
|
94610
|
+
});
|
|
94611
|
+
return false;
|
|
94612
|
+
}
|
|
94613
|
+
}
|
|
94614
|
+
/** How long a step command may run before Alexa is answered anyway (its own budget is ~8 s). */
|
|
94615
|
+
var STEP_ANSWER_BUDGET_MS = 3e3;
|
|
94616
|
+
/** The properties a command may assert: only those the player READS back, never an assumption (D393). */
|
|
94617
|
+
async function reportedProperties(c, namespace) {
|
|
94618
|
+
const deps = c.deps.mediaPlayerController;
|
|
94619
|
+
try {
|
|
94620
|
+
const slice = await deps.ctx.api.deviceState.getCapSlice.query({
|
|
94621
|
+
deviceId: c.deviceId,
|
|
94622
|
+
capName: CAP_MEDIA_PLAYER
|
|
94623
|
+
});
|
|
94624
|
+
const status = readMediaPlayerSlice(slice);
|
|
94625
|
+
if (status === null || status.stateSource !== "reported") return [];
|
|
94626
|
+
return mediaPlayerProperties(slice).filter((p) => p.namespace === namespace);
|
|
94627
|
+
} catch (err) {
|
|
94628
|
+
deps.logger.warn("alexa media-player-controller: the state could not be re-read", {
|
|
94629
|
+
tags: { deviceId: c.deviceId },
|
|
94630
|
+
meta: { error: message(err) }
|
|
94631
|
+
});
|
|
94632
|
+
return [];
|
|
94633
|
+
}
|
|
94634
|
+
}
|
|
94635
|
+
async function attempt(c, what, run, options = {}) {
|
|
94636
|
+
const deps = c.deps.mediaPlayerController;
|
|
94637
|
+
const settled = run().then(() => ({ ok: true }), (error) => ({
|
|
94638
|
+
ok: false,
|
|
94639
|
+
error
|
|
94640
|
+
}));
|
|
94641
|
+
let timer;
|
|
94642
|
+
const outcome = options.slow === true ? await Promise.race([settled, new Promise((resolve) => {
|
|
94643
|
+
timer = setTimeout(() => resolve(null), STEP_ANSWER_BUDGET_MS);
|
|
94644
|
+
})]) : await settled;
|
|
94645
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
94646
|
+
if (outcome === null) {
|
|
94647
|
+
deps.logger.info(`alexa media-player-controller: ${what} still sending, answered`, { tags: { deviceId: c.deviceId } });
|
|
94648
|
+
settled.then((late) => {
|
|
94649
|
+
if (!late.ok) deps.logger.warn(`alexa media-player-controller: ${what} failed after the answer`, {
|
|
94650
|
+
tags: { deviceId: c.deviceId },
|
|
94651
|
+
meta: { error: message(late.error) }
|
|
94652
|
+
});
|
|
94653
|
+
});
|
|
94654
|
+
return success(c, []);
|
|
94655
|
+
}
|
|
94656
|
+
if (!outcome.ok) {
|
|
94657
|
+
deps.logger.warn(`alexa media-player-controller: ${what} failed`, {
|
|
94658
|
+
tags: { deviceId: c.deviceId },
|
|
94659
|
+
meta: { error: message(outcome.error) }
|
|
94660
|
+
});
|
|
94661
|
+
return errorEnvelope(c.header, "ENDPOINT_UNREACHABLE", `the player did not accept ${what}`);
|
|
94662
|
+
}
|
|
94663
|
+
deps.logger.info(`alexa media-player-controller: ${what}`, { tags: { deviceId: c.deviceId } });
|
|
94664
|
+
return success(c, options.namespace === void 0 ? [] : await reportedProperties(c, options.namespace));
|
|
94665
|
+
}
|
|
94666
|
+
async function volume(c) {
|
|
94667
|
+
const payload = StepsPayload.safeParse(c.payload);
|
|
94668
|
+
if (!payload.success || payload.data.volumeSteps === 0) return errorEnvelope(c.header, "INVALID_DIRECTIVE", "volumeSteps is required");
|
|
94669
|
+
const steps = Math.min(Math.abs(payload.data.volumeSteps), 50);
|
|
94670
|
+
const api = c.deps.mediaPlayerController.ctx.api.mediaPlayer;
|
|
94671
|
+
const up = payload.data.volumeSteps > 0;
|
|
94672
|
+
return attempt(c, `volume ${up ? "up" : "down"} ${steps}`, () => up ? api.volumeUp.mutate({
|
|
94673
|
+
deviceId: c.deviceId,
|
|
94674
|
+
steps
|
|
94675
|
+
}) : api.volumeDown.mutate({
|
|
94676
|
+
deviceId: c.deviceId,
|
|
94677
|
+
steps
|
|
94678
|
+
}), { slow: true });
|
|
94679
|
+
}
|
|
94680
|
+
async function channel(c) {
|
|
94681
|
+
const payload = ChannelPayload.safeParse(c.payload);
|
|
94682
|
+
if (!payload.success || payload.data.channelCount === 0) return errorEnvelope(c.header, "INVALID_DIRECTIVE", "channelCount is required");
|
|
94683
|
+
const steps = Math.min(Math.abs(payload.data.channelCount), 50);
|
|
94684
|
+
const api = c.deps.mediaPlayerController.ctx.api.mediaPlayer;
|
|
94685
|
+
const up = payload.data.channelCount > 0;
|
|
94686
|
+
return attempt(c, `channel ${up ? "up" : "down"} ${steps}`, () => up ? api.channelUp.mutate({
|
|
94687
|
+
deviceId: c.deviceId,
|
|
94688
|
+
steps
|
|
94689
|
+
}) : api.channelDown.mutate({
|
|
94690
|
+
deviceId: c.deviceId,
|
|
94691
|
+
steps
|
|
94692
|
+
}), { slow: true });
|
|
94693
|
+
}
|
|
94694
|
+
async function mute(c) {
|
|
94695
|
+
const payload = MutePayload.safeParse(c.payload);
|
|
94696
|
+
if (!payload.success) return errorEnvelope(c.header, "INVALID_DIRECTIVE", "mute is required");
|
|
94697
|
+
const muted = payload.data.mute;
|
|
94698
|
+
const api = c.deps.mediaPlayerController.ctx.api.mediaPlayer;
|
|
94699
|
+
return attempt(c, `mute ${String(muted)}`, () => api.setMute.mutate({
|
|
94700
|
+
deviceId: c.deviceId,
|
|
94701
|
+
muted
|
|
94702
|
+
}), { namespace: "Alexa.Speaker" });
|
|
94703
|
+
}
|
|
94704
|
+
async function power$1(c) {
|
|
94705
|
+
const on = c.header.name === "TurnOn";
|
|
94706
|
+
const api = c.deps.mediaPlayerController.ctx.api.mediaPlayer;
|
|
94707
|
+
return attempt(c, on ? "turn on" : "turn off", () => on ? api.turnOn.mutate({ deviceId: c.deviceId }) : api.turnOff.mutate({ deviceId: c.deviceId }), { namespace: "Alexa.PowerController" });
|
|
94708
|
+
}
|
|
94709
|
+
async function playback(c) {
|
|
94710
|
+
const api = c.deps.mediaPlayerController.ctx.api.mediaPlayer;
|
|
94711
|
+
const input = { deviceId: c.deviceId };
|
|
94712
|
+
switch (c.header.name) {
|
|
94713
|
+
case "Play": return attempt(c, "play", () => api.play.mutate(input));
|
|
94714
|
+
case "Pause": return attempt(c, "pause", () => api.pause.mutate(input));
|
|
94715
|
+
case "Stop": return attempt(c, "stop", () => api.stop.mutate(input));
|
|
94716
|
+
case "Next": return attempt(c, "next", () => api.next.mutate(input));
|
|
94717
|
+
case "Previous": return attempt(c, "previous", () => api.previous.mutate(input));
|
|
94718
|
+
default: return errorEnvelope(c.header, "INVALID_DIRECTIVE", `unsupported ${c.header.name}`);
|
|
94719
|
+
}
|
|
94720
|
+
}
|
|
94721
|
+
async function selectInput(c) {
|
|
94722
|
+
const payload = InputPayload.safeParse(c.payload);
|
|
94723
|
+
if (!payload.success) return errorEnvelope(c.header, "INVALID_DIRECTIVE", "input is required");
|
|
94724
|
+
const deps = c.deps.mediaPlayerController;
|
|
94725
|
+
let source;
|
|
94726
|
+
try {
|
|
94727
|
+
const status = readMediaPlayerSlice(await deps.ctx.api.deviceState.getCapSlice.query({
|
|
94728
|
+
deviceId: c.deviceId,
|
|
94729
|
+
capName: CAP_MEDIA_PLAYER
|
|
94730
|
+
}));
|
|
94731
|
+
source = status === null ? void 0 : inputPairs(status).find((i) => i.amazon === payload.data.input)?.source;
|
|
94732
|
+
} catch (err) {
|
|
94733
|
+
deps.logger.warn("alexa media-player-controller: the sources could not be read", {
|
|
94734
|
+
tags: { deviceId: c.deviceId },
|
|
94735
|
+
meta: { error: message(err) }
|
|
94736
|
+
});
|
|
94737
|
+
return errorEnvelope(c.header, "ENDPOINT_UNREACHABLE", "the player sources could not be read");
|
|
94738
|
+
}
|
|
94739
|
+
if (source === void 0) return errorEnvelope(c.header, "INVALID_VALUE", `the player has no input ${payload.data.input}`);
|
|
94740
|
+
const chosen = source;
|
|
94741
|
+
return attempt(c, `select input ${chosen}`, () => deps.ctx.api.mediaPlayer.selectSource.mutate({
|
|
94742
|
+
deviceId: c.deviceId,
|
|
94743
|
+
source: chosen
|
|
94744
|
+
}), { namespace: "Alexa.InputController" });
|
|
94745
|
+
}
|
|
94746
|
+
/** The one handler behind every media-player directive. */
|
|
94747
|
+
async function handleMediaPlayerDirective(c) {
|
|
94748
|
+
switch (`${c.header.namespace}/${c.header.name}`) {
|
|
94749
|
+
case "Alexa.PowerController/TurnOn":
|
|
94750
|
+
case "Alexa.PowerController/TurnOff": return power$1(c);
|
|
94751
|
+
case "Alexa.StepSpeaker/AdjustVolume": return volume(c);
|
|
94752
|
+
case "Alexa.StepSpeaker/SetMute":
|
|
94753
|
+
case "Alexa.Speaker/SetMute": return mute(c);
|
|
94754
|
+
case "Alexa.ChannelController/SkipChannels": return channel(c);
|
|
94755
|
+
case "Alexa.InputController/SelectInput": return selectInput(c);
|
|
94756
|
+
default: return c.header.namespace === "Alexa.PlaybackController" ? playback(c) : errorEnvelope(c.header, "INVALID_DIRECTIVE", `unsupported ${c.header.name}`);
|
|
94757
|
+
}
|
|
94758
|
+
}
|
|
94759
|
+
//#endregion
|
|
94760
|
+
//#region src/endpoints/adapters/media-player.ts
|
|
94761
|
+
function directive(key, claims) {
|
|
94762
|
+
return {
|
|
94763
|
+
key,
|
|
94764
|
+
needsReachableDevice: true,
|
|
94765
|
+
handle: handleMediaPlayerDirective,
|
|
94766
|
+
...claims === void 0 ? {} : { claims }
|
|
94767
|
+
};
|
|
94768
|
+
}
|
|
94769
|
+
var DIRECTIVES = [
|
|
94770
|
+
directive("Alexa.PowerController/TurnOn", claimsMediaPlayerPower),
|
|
94771
|
+
directive("Alexa.PowerController/TurnOff", claimsMediaPlayerPower),
|
|
94772
|
+
directive("Alexa.StepSpeaker/AdjustVolume"),
|
|
94773
|
+
directive("Alexa.StepSpeaker/SetMute"),
|
|
94774
|
+
directive("Alexa.Speaker/SetMute"),
|
|
94775
|
+
directive("Alexa.ChannelController/SkipChannels"),
|
|
94776
|
+
directive("Alexa.PlaybackController/Play"),
|
|
94777
|
+
directive("Alexa.PlaybackController/Pause"),
|
|
94778
|
+
directive("Alexa.PlaybackController/Stop"),
|
|
94779
|
+
directive("Alexa.PlaybackController/Next"),
|
|
94780
|
+
directive("Alexa.PlaybackController/Previous"),
|
|
94781
|
+
directive("Alexa.InputController/SelectInput")
|
|
94782
|
+
];
|
|
94783
|
+
/**
|
|
94784
|
+
* `media-player` → a TV: power, step volume, mute, channel steps, transport and
|
|
94785
|
+
* inputs, each only when the player says it can (features) and, for the ones
|
|
94786
|
+
* that need a reading, only when it reports one. Registered before `switch`: a
|
|
94787
|
+
* TV is a TV, not a SWITCH.
|
|
94788
|
+
*/
|
|
94789
|
+
var mediaPlayerAdapter = {
|
|
94790
|
+
cap: CAP_MEDIA_PLAYER,
|
|
94791
|
+
stateCaps: [CAP_MEDIA_PLAYER],
|
|
94792
|
+
discoveryReads: [CAP_MEDIA_PLAYER],
|
|
94793
|
+
describe: (device) => {
|
|
94794
|
+
const capabilities = describeMediaPlayerCapabilities(device);
|
|
94795
|
+
if (capabilities.length === 0) return {
|
|
94796
|
+
kind: "skip",
|
|
94797
|
+
reason: "the media player offers nothing Alexa can drive"
|
|
94798
|
+
};
|
|
94799
|
+
return {
|
|
94800
|
+
kind: "publish",
|
|
94801
|
+
capabilities,
|
|
94802
|
+
category: "TV"
|
|
94803
|
+
};
|
|
94804
|
+
},
|
|
94805
|
+
properties: (_cap, slice) => mediaPlayerProperties(slice),
|
|
94806
|
+
directives: DIRECTIVES,
|
|
94807
|
+
shaping: () => null
|
|
94808
|
+
};
|
|
94809
|
+
//#endregion
|
|
93507
94810
|
//#region src/endpoints/adapters/motion.ts
|
|
93508
94811
|
/** `motion` → `Alexa.MotionSensor` (MOTION_SENSOR). */
|
|
93509
94812
|
var motionAdapter = {
|
|
@@ -93711,6 +95014,7 @@ var GENERIC_ADAPTERS = [
|
|
|
93711
95014
|
temperatureAdapter,
|
|
93712
95015
|
humidityAdapter,
|
|
93713
95016
|
fanAdapter,
|
|
95017
|
+
mediaPlayerAdapter,
|
|
93714
95018
|
{
|
|
93715
95019
|
cap: "switch",
|
|
93716
95020
|
stateCaps: ["switch", "brightness"],
|
|
@@ -93846,6 +95150,7 @@ var GENERIC_DEVICE_TYPES = [
|
|
|
93846
95150
|
"climate",
|
|
93847
95151
|
"cover",
|
|
93848
95152
|
"fan",
|
|
95153
|
+
"media-player",
|
|
93849
95154
|
"generic"
|
|
93850
95155
|
];
|
|
93851
95156
|
function toEndpoint(input, plan) {
|
|
@@ -95447,7 +96752,12 @@ var ALLOWED_INTERFACE_VERSIONS = {
|
|
|
95447
96752
|
"Alexa.SmartVision.SnapshotProvider": "1.1",
|
|
95448
96753
|
"Alexa.SmartVision.ObjectDetectionSensor": "1.0",
|
|
95449
96754
|
"Alexa.DataController": "1.0",
|
|
95450
|
-
"Alexa.SceneController": "3"
|
|
96755
|
+
"Alexa.SceneController": "3",
|
|
96756
|
+
"Alexa.StepSpeaker": "3",
|
|
96757
|
+
"Alexa.Speaker": "3",
|
|
96758
|
+
"Alexa.ChannelController": "3",
|
|
96759
|
+
"Alexa.PlaybackController": "3",
|
|
96760
|
+
"Alexa.InputController": "3"
|
|
95451
96761
|
};
|
|
95452
96762
|
/** `imageNetClass` values Amazon accepts (alexa-smartvision-objectdetectionsensor). */
|
|
95453
96763
|
var SMART_VISION_CLASSES = new Set(["person", "package"]);
|
|
@@ -95487,6 +96797,7 @@ var DISPLAY_CATEGORIES = new Set([
|
|
|
95487
96797
|
"THERMOSTAT",
|
|
95488
96798
|
"AIR_CONDITIONER",
|
|
95489
96799
|
"FAN",
|
|
96800
|
+
"TV",
|
|
95490
96801
|
"DOOR",
|
|
95491
96802
|
"GATE",
|
|
95492
96803
|
"GARAGE_DOOR",
|
|
@@ -99637,12 +100948,30 @@ function troubleshootingSection() {
|
|
|
99637
100948
|
]
|
|
99638
100949
|
};
|
|
99639
100950
|
}
|
|
99640
|
-
/**
|
|
99641
|
-
|
|
99642
|
-
function customSkillSecuritySection(input) {
|
|
100951
|
+
/** The enforcement switch of the custom skill's ingress token: part of the skill instance. */
|
|
100952
|
+
function instanceSecuritySection(input) {
|
|
99643
100953
|
return {
|
|
99644
100954
|
id: "export-alexa-custom-security",
|
|
99645
100955
|
title: "Custom-skill security",
|
|
100956
|
+
columns: 1,
|
|
100957
|
+
fields: [{
|
|
100958
|
+
type: "boolean",
|
|
100959
|
+
key: "enforceIngressToken",
|
|
100960
|
+
label: "Require ingress token",
|
|
100961
|
+
description: "When on, this hub refuses skill calls without the matching token. Turn it on only after HUB_INGRESS_TOKEN is set in your Lambda. The token itself is shown on the addon page.",
|
|
100962
|
+
default: input.defaults.enforceIngressToken,
|
|
100963
|
+
showWhen: CUSTOM_SKILL_ONLY
|
|
100964
|
+
}]
|
|
100965
|
+
};
|
|
100966
|
+
}
|
|
100967
|
+
/** Custom skill only: the public skill's shared Lambda sends one ingress token
|
|
100968
|
+
* for every hub (`HUB_INGRESS_TOKEN`), so a per-hub token cannot apply to it. The rows are
|
|
100969
|
+
* built only for a custom skill: the mode is not a field of this page. */
|
|
100970
|
+
function customSkillSecuritySection(input) {
|
|
100971
|
+
if (input.skillMode !== "custom") return null;
|
|
100972
|
+
return {
|
|
100973
|
+
id: "export-alexa-custom-security-token",
|
|
100974
|
+
title: "Custom-skill ingress token",
|
|
99646
100975
|
style: "accordion",
|
|
99647
100976
|
defaultCollapsed: true,
|
|
99648
100977
|
columns: 1,
|
|
@@ -99652,8 +100981,7 @@ function customSkillSecuritySection(input) {
|
|
|
99652
100981
|
key: "__ingress-token-info",
|
|
99653
100982
|
label: "Ingress token",
|
|
99654
100983
|
variant: "info",
|
|
99655
|
-
|
|
99656
|
-
content: "An optional shared secret your skill Lambda sends on every call to this hub. Show it, put it in the Lambda's HUB_INGRESS_TOKEN environment variable, then turn on \"Require ingress token\". After a rotation, update the Lambda."
|
|
100984
|
+
content: "An optional shared secret your skill Lambda sends on every call to this hub. Show it, put it in the Lambda's HUB_INGRESS_TOKEN environment variable, then turn on \"Require ingress token\" on the skill. After a rotation, update the Lambda."
|
|
99657
100985
|
},
|
|
99658
100986
|
{
|
|
99659
100987
|
type: "addon-action-button",
|
|
@@ -99664,8 +100992,7 @@ function customSkillSecuritySection(input) {
|
|
|
99664
100992
|
buttonLabel: "Show ingress token",
|
|
99665
100993
|
action: "revealIngressToken",
|
|
99666
100994
|
variant: "default",
|
|
99667
|
-
successMessage: "Ingress token: {ingressToken}"
|
|
99668
|
-
showWhen: CUSTOM_SKILL_ONLY
|
|
100995
|
+
successMessage: "Ingress token: {ingressToken}"
|
|
99669
100996
|
},
|
|
99670
100997
|
{
|
|
99671
100998
|
type: "addon-action-button",
|
|
@@ -99677,27 +101004,25 @@ function customSkillSecuritySection(input) {
|
|
|
99677
101004
|
action: "regenerateIngressToken",
|
|
99678
101005
|
variant: "default",
|
|
99679
101006
|
successMessage: "New ingress token: {ingressToken} — put it in HUB_INGRESS_TOKEN now.",
|
|
99680
|
-
confirmMessage: "Rotate the ingress token? With \"Require ingress token\" on, the Lambda is refused until you update HUB_INGRESS_TOKEN."
|
|
99681
|
-
showWhen: CUSTOM_SKILL_ONLY
|
|
99682
|
-
},
|
|
99683
|
-
{
|
|
99684
|
-
type: "boolean",
|
|
99685
|
-
key: "enforceIngressToken",
|
|
99686
|
-
label: "Require ingress token",
|
|
99687
|
-
description: "When on, this hub refuses skill calls without the matching token. Turn it on only after HUB_INGRESS_TOKEN is set in your Lambda.",
|
|
99688
|
-
default: input.defaults.enforceIngressToken,
|
|
99689
|
-
showWhen: CUSTOM_SKILL_ONLY
|
|
101007
|
+
confirmMessage: "Rotate the ingress token? With \"Require ingress token\" on, the Lambda is refused until you update HUB_INGRESS_TOKEN."
|
|
99690
101008
|
}
|
|
99691
101009
|
]
|
|
99692
101010
|
};
|
|
99693
101011
|
}
|
|
99694
|
-
|
|
101012
|
+
/** The skill instance's form (`skills` record). */
|
|
101013
|
+
function buildAlexaInstanceSections(input) {
|
|
99695
101014
|
return [
|
|
99696
101015
|
connectionSection(input),
|
|
99697
101016
|
featuresSection(input),
|
|
101017
|
+
instanceSecuritySection(input)
|
|
101018
|
+
];
|
|
101019
|
+
}
|
|
101020
|
+
function buildAlexaSettingsSections(input) {
|
|
101021
|
+
const security = customSkillSecuritySection(input);
|
|
101022
|
+
return [
|
|
99698
101023
|
accountLinkSection(input),
|
|
99699
101024
|
troubleshootingSection(),
|
|
99700
|
-
|
|
101025
|
+
...security === null ? [] : [security]
|
|
99701
101026
|
];
|
|
99702
101027
|
}
|
|
99703
101028
|
//#endregion
|
|
@@ -100432,7 +101757,7 @@ var ALEXA_ADDON_ID = "export-alexa";
|
|
|
100432
101757
|
* key, id `<addonId>.<key>`, data `{ addonId, key, value }` (never a per-addon scoped table,
|
|
100433
101758
|
* which exists only when something lazily declared it).
|
|
100434
101759
|
*/
|
|
100435
|
-
var ADDON_SETTINGS_TABLE = "addon-settings";
|
|
101760
|
+
var ADDON_SETTINGS_TABLE$1 = "addon-settings";
|
|
100436
101761
|
var RETIRED_PUBLIC_URL_KEYS = ["publicHubUrl"];
|
|
100437
101762
|
async function planDropPublicHubUrl(ports) {
|
|
100438
101763
|
const stored = await ports.readStored();
|
|
@@ -100441,7 +101766,7 @@ async function planDropPublicHubUrl(ports) {
|
|
|
100441
101766
|
const rowId = (key) => `${ALEXA_ADDON_ID}.${key}`;
|
|
100442
101767
|
return { edits: [{
|
|
100443
101768
|
op: "deleteKeys",
|
|
100444
|
-
scope: ADDON_SETTINGS_TABLE,
|
|
101769
|
+
scope: ADDON_SETTINGS_TABLE$1,
|
|
100445
101770
|
keys: present.map(rowId),
|
|
100446
101771
|
precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
|
|
100447
101772
|
addonId: ALEXA_ADDON_ID,
|
|
@@ -100451,24 +101776,351 @@ async function planDropPublicHubUrl(ports) {
|
|
|
100451
101776
|
}] };
|
|
100452
101777
|
}
|
|
100453
101778
|
//#endregion
|
|
101779
|
+
//#region src/skill-records.ts
|
|
101780
|
+
/**
|
|
101781
|
+
* The Alexa export as an integration instance (D985, D996): ONE `skills` record, owned by
|
|
101782
|
+
* `export-alexa` and named after it, holds how the skill reaches this hub and what each exposed
|
|
101783
|
+
* camera carries. The two ledgers of the link (`linkedAccounts`, `tokens`) are a second record,
|
|
101784
|
+
* `skill-links`, under the SAME id: the instance they belong to. The tokens' credentials are
|
|
101785
|
+
* keychain markers bound to that row, matched by user id so a reorder keeps every ref.
|
|
101786
|
+
*/
|
|
101787
|
+
/** A single-instance addon keeps its records under its own addon id. */
|
|
101788
|
+
var ALEXA_INSTANCE_ID = "export-alexa";
|
|
101789
|
+
var alexaSkillsKind = defineEntryKind("skills", {
|
|
101790
|
+
title: "Alexa skill",
|
|
101791
|
+
nameField: "name",
|
|
101792
|
+
schema: object({
|
|
101793
|
+
name: string().min(1),
|
|
101794
|
+
skillMode: _enum(["public", "custom"]),
|
|
101795
|
+
region: _enum([
|
|
101796
|
+
"NA",
|
|
101797
|
+
"EU",
|
|
101798
|
+
"FE"
|
|
101799
|
+
]),
|
|
101800
|
+
expectedAudience: string(),
|
|
101801
|
+
detectionSensors: boolean(),
|
|
101802
|
+
objectDetection: boolean(),
|
|
101803
|
+
snapshots: boolean(),
|
|
101804
|
+
enforceIngressToken: boolean(),
|
|
101805
|
+
enabled: boolean().optional()
|
|
101806
|
+
})
|
|
101807
|
+
});
|
|
101808
|
+
/** What a skill starts as: the defaults the addon's constructor used to carry. */
|
|
101809
|
+
var ALEXA_SKILL_DEFAULT_BODY = {
|
|
101810
|
+
skillMode: "public",
|
|
101811
|
+
region: "NA",
|
|
101812
|
+
expectedAudience: "",
|
|
101813
|
+
detectionSensors: true,
|
|
101814
|
+
objectDetection: true,
|
|
101815
|
+
snapshots: true,
|
|
101816
|
+
enforceIngressToken: false
|
|
101817
|
+
};
|
|
101818
|
+
/** The settings keys that moved into the `skills` record; the migrations name them. */
|
|
101819
|
+
var MOVED_SKILL_KEYS = [
|
|
101820
|
+
"skillMode",
|
|
101821
|
+
"region",
|
|
101822
|
+
"expectedAudience",
|
|
101823
|
+
"detectionSensors",
|
|
101824
|
+
"objectDetection",
|
|
101825
|
+
"snapshots",
|
|
101826
|
+
"enforceIngressToken"
|
|
101827
|
+
];
|
|
101828
|
+
/** The ledger keys that moved into the `skill-links` record. */
|
|
101829
|
+
var MOVED_LEDGER_KEYS = ["linkedAccounts", "tokens"];
|
|
101830
|
+
var LinkedAccountSchema = object({
|
|
101831
|
+
userId: string(),
|
|
101832
|
+
username: string(),
|
|
101833
|
+
linkedAt: number()
|
|
101834
|
+
});
|
|
101835
|
+
var LwaTokenEntrySchema = object({
|
|
101836
|
+
userId: string(),
|
|
101837
|
+
accessToken: string().meta({ secret: true }),
|
|
101838
|
+
expiresAt: number(),
|
|
101839
|
+
receivedAt: number(),
|
|
101840
|
+
refreshToken: string().optional().meta({ secret: true }),
|
|
101841
|
+
brokerUrl: string().optional(),
|
|
101842
|
+
brokerCredential: string().optional().meta({ secret: true })
|
|
101843
|
+
});
|
|
101844
|
+
var alexaSkillLinksKind = defineEntryKind("skill-links", {
|
|
101845
|
+
title: "Alexa account links",
|
|
101846
|
+
nameField: "name",
|
|
101847
|
+
schema: object({
|
|
101848
|
+
name: string().min(1),
|
|
101849
|
+
linkedAccounts: array(LinkedAccountSchema),
|
|
101850
|
+
tokens: array(LwaTokenEntrySchema)
|
|
101851
|
+
}),
|
|
101852
|
+
secretArrayKeys: { tokens: "userId" }
|
|
101853
|
+
});
|
|
101854
|
+
//#endregion
|
|
101855
|
+
//#region src/migrations/settings-to-records.ts
|
|
101856
|
+
/**
|
|
101857
|
+
* The Alexa export's settings move into records (D985, D996). Three migrations of the catalogue
|
|
101858
|
+
* after the retired-URL one, each idempotent, in this order:
|
|
101859
|
+
*
|
|
101860
|
+
* 2. `moveSettingsToSkill` (procedure): the seven skill settings become the `skills` record.
|
|
101861
|
+
* An existing record is never overwritten.
|
|
101862
|
+
* 3. `moveLedgersToLinks` (procedure): `linkedAccounts` and `tokens` become the `skill-links`
|
|
101863
|
+
* record. The record is read BACK (credentials resolved) and must equal what the old
|
|
101864
|
+
* settings carried, byte for byte, BEFORE the old token credentials are cleared; any
|
|
101865
|
+
* difference throws and clears nothing. An existing record is never overwritten.
|
|
101866
|
+
* 4. `planDropMovedSettings` (plan): the moved keys are deleted from the canonical
|
|
101867
|
+
* `addon-settings` rows, and only while the records are confirmed to hold what they carried.
|
|
101868
|
+
*
|
|
101869
|
+
* All three are `tolerate`: the addon keeps reading the legacy keys until a record exists.
|
|
101870
|
+
*/
|
|
101871
|
+
/** The canonical `addon-settings` table: one row per key, id `<addonId>.<key>`. */
|
|
101872
|
+
var ADDON_SETTINGS_TABLE = "addon-settings";
|
|
101873
|
+
var SKILL_NAME = "Alexa skill";
|
|
101874
|
+
var LINKS_NAME = "Alexa account links";
|
|
101875
|
+
function text(stored, key) {
|
|
101876
|
+
const value = stored[key];
|
|
101877
|
+
return typeof value === "string" ? value.trim() : "";
|
|
101878
|
+
}
|
|
101879
|
+
function flag(stored, key, fallback) {
|
|
101880
|
+
const value = stored[key];
|
|
101881
|
+
return typeof value === "boolean" ? value : fallback;
|
|
101882
|
+
}
|
|
101883
|
+
/** The record body the legacy settings describe; a missing or mistyped key takes the default. */
|
|
101884
|
+
function skillBodyFrom(stored) {
|
|
101885
|
+
const d = ALEXA_SKILL_DEFAULT_BODY;
|
|
101886
|
+
const region = stored["region"];
|
|
101887
|
+
return {
|
|
101888
|
+
name: SKILL_NAME,
|
|
101889
|
+
skillMode: stored["skillMode"] === "custom" ? "custom" : "public",
|
|
101890
|
+
region: region === "EU" || region === "FE" ? region : "NA",
|
|
101891
|
+
expectedAudience: text(stored, "expectedAudience"),
|
|
101892
|
+
detectionSensors: flag(stored, "detectionSensors", d.detectionSensors),
|
|
101893
|
+
objectDetection: flag(stored, "objectDetection", d.objectDetection),
|
|
101894
|
+
snapshots: flag(stored, "snapshots", d.snapshots),
|
|
101895
|
+
enforceIngressToken: flag(stored, "enforceIngressToken", d.enforceIngressToken)
|
|
101896
|
+
};
|
|
101897
|
+
}
|
|
101898
|
+
async function moveSettingsToSkill(ports) {
|
|
101899
|
+
const stored = await ports.readStored();
|
|
101900
|
+
if (!MOVED_SKILL_KEYS.some((key) => key in stored)) return {
|
|
101901
|
+
outcome: "already-done",
|
|
101902
|
+
summary: { moved: false }
|
|
101903
|
+
};
|
|
101904
|
+
return await ports.putSkill(skillBodyFrom(stored)) === "created" ? {
|
|
101905
|
+
outcome: "done",
|
|
101906
|
+
summary: { moved: true }
|
|
101907
|
+
} : {
|
|
101908
|
+
outcome: "already-done",
|
|
101909
|
+
summary: { moved: false }
|
|
101910
|
+
};
|
|
101911
|
+
}
|
|
101912
|
+
function accountsOf(value) {
|
|
101913
|
+
return Array.isArray(value) ? value.filter(isLinkedAccount) : [];
|
|
101914
|
+
}
|
|
101915
|
+
function tokensOf(value) {
|
|
101916
|
+
return Array.isArray(value) ? value.filter(isTokenEntry) : [];
|
|
101917
|
+
}
|
|
101918
|
+
function isLinkedAccount(value) {
|
|
101919
|
+
return typeof value === "object" && value !== null && "userId" in value && typeof value.userId === "string" && "username" in value && typeof value.username === "string" && "linkedAt" in value && typeof value.linkedAt === "number";
|
|
101920
|
+
}
|
|
101921
|
+
function isTokenEntry(value) {
|
|
101922
|
+
return typeof value === "object" && value !== null && "userId" in value && typeof value.userId === "string" && "accessToken" in value && typeof value.accessToken === "string" && "expiresAt" in value && typeof value.expiresAt === "number" && "receivedAt" in value && typeof value.receivedAt === "number";
|
|
101923
|
+
}
|
|
101924
|
+
/** Key-order-independent JSON, so "byte-identical" does not depend on how a store orders keys. */
|
|
101925
|
+
function canonical(value) {
|
|
101926
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
101927
|
+
if (typeof value === "object" && value !== null) return `{${Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(",")}}`;
|
|
101928
|
+
return JSON.stringify(value) ?? "null";
|
|
101929
|
+
}
|
|
101930
|
+
async function moveLedgersToLinks(ports) {
|
|
101931
|
+
const stored = await ports.readStored();
|
|
101932
|
+
if (!MOVED_LEDGER_KEYS.some((key) => key in stored)) return {
|
|
101933
|
+
outcome: "already-done",
|
|
101934
|
+
summary: { moved: false }
|
|
101935
|
+
};
|
|
101936
|
+
const linkedAccounts = accountsOf(stored["linkedAccounts"]);
|
|
101937
|
+
const tokens = tokensOf(stored["tokens"]);
|
|
101938
|
+
const put = await ports.putLinks({
|
|
101939
|
+
name: LINKS_NAME,
|
|
101940
|
+
linkedAccounts,
|
|
101941
|
+
tokens
|
|
101942
|
+
});
|
|
101943
|
+
let held = await ports.readLinks();
|
|
101944
|
+
const matches = (record) => record !== null && canonical(record.linkedAccounts) === canonical(linkedAccounts) && canonical(record.tokens) === canonical(tokens);
|
|
101945
|
+
if (put === "exists" && !matches(held) && isCoveredBy(held, linkedAccounts, tokens)) {
|
|
101946
|
+
await ports.replaceLinks({
|
|
101947
|
+
name: LINKS_NAME,
|
|
101948
|
+
linkedAccounts,
|
|
101949
|
+
tokens
|
|
101950
|
+
});
|
|
101951
|
+
held = await ports.readLinks();
|
|
101952
|
+
}
|
|
101953
|
+
if (!matches(held)) {
|
|
101954
|
+
ports.warn("Alexa migration: the skill-links record does not hold what the settings carried; the legacy ledgers are kept");
|
|
101955
|
+
if (put === "created") throw new Error("the Alexa link record does not match the legacy settings; nothing was cleared");
|
|
101956
|
+
return {
|
|
101957
|
+
outcome: "already-done",
|
|
101958
|
+
summary: { moved: false }
|
|
101959
|
+
};
|
|
101960
|
+
}
|
|
101961
|
+
if (tokens.length > 0) await ports.clearOldTokenSecrets();
|
|
101962
|
+
return put === "created" ? {
|
|
101963
|
+
outcome: "done",
|
|
101964
|
+
summary: {
|
|
101965
|
+
moved: true,
|
|
101966
|
+
accounts: linkedAccounts.length
|
|
101967
|
+
}
|
|
101968
|
+
} : {
|
|
101969
|
+
outcome: "done",
|
|
101970
|
+
summary: {
|
|
101971
|
+
moved: true,
|
|
101972
|
+
repaired: true,
|
|
101973
|
+
accounts: linkedAccounts.length
|
|
101974
|
+
}
|
|
101975
|
+
};
|
|
101976
|
+
}
|
|
101977
|
+
/**
|
|
101978
|
+
* The record carries this migration's own name and every account and grant it holds is also in
|
|
101979
|
+
* the settings: rewriting it loses nothing and touches nothing an operator named.
|
|
101980
|
+
*/
|
|
101981
|
+
function isCoveredBy(held, linkedAccounts, tokens) {
|
|
101982
|
+
if (held === null || held.name !== LINKS_NAME) return false;
|
|
101983
|
+
const accounts = new Set(linkedAccounts.map((a) => a.userId));
|
|
101984
|
+
const grants = new Set(tokens.map((t) => t.userId));
|
|
101985
|
+
return held.linkedAccounts.every((a) => accounts.has(a.userId)) && held.tokens.every((t) => grants.has(t.userId));
|
|
101986
|
+
}
|
|
101987
|
+
/**
|
|
101988
|
+
* A ledger key the drop may judge: absent, a list, or the leftover of a credential clear
|
|
101989
|
+
* (`{ $secretClear: true }`, stored where a list belongs by an older build). Anything else is
|
|
101990
|
+
* not understood, so nothing is deleted on its account.
|
|
101991
|
+
*/
|
|
101992
|
+
function isLedgerShape(value) {
|
|
101993
|
+
return value === void 0 || Array.isArray(value) || isSecretClear(value);
|
|
101994
|
+
}
|
|
101995
|
+
/** Whether a stored token entry still carries a credential: text, or a keychain marker. */
|
|
101996
|
+
function carriesCredential(entry) {
|
|
101997
|
+
if (typeof entry !== "object" || entry === null) return false;
|
|
101998
|
+
return [
|
|
101999
|
+
"accessToken",
|
|
102000
|
+
"refreshToken",
|
|
102001
|
+
"brokerCredential"
|
|
102002
|
+
].some((key) => {
|
|
102003
|
+
const value = Reflect.get(entry, key);
|
|
102004
|
+
if (typeof value === "string") return value.length > 0;
|
|
102005
|
+
return typeof value === "object" && value !== null;
|
|
102006
|
+
});
|
|
102007
|
+
}
|
|
102008
|
+
var rowId = (key) => `${ALEXA_INSTANCE_ID}.${key}`;
|
|
102009
|
+
async function planDropMovedSettings(ports) {
|
|
102010
|
+
const stored = await ports.readRawStored();
|
|
102011
|
+
const skillKeys = MOVED_SKILL_KEYS.filter((key) => key in stored);
|
|
102012
|
+
const ledgerKeys = MOVED_LEDGER_KEYS.filter((key) => key in stored);
|
|
102013
|
+
if (skillKeys.length === 0 && ledgerKeys.length === 0) return { edits: [] };
|
|
102014
|
+
const refuse = (reason) => {
|
|
102015
|
+
ports.warn(`Alexa migration: the legacy keys are kept: ${reason}`);
|
|
102016
|
+
throw new Error(`the legacy Alexa keys are not deleted: ${reason}`);
|
|
102017
|
+
};
|
|
102018
|
+
if (skillKeys.length > 0 && !await ports.hasSkill()) return refuse("no Alexa skill record exists");
|
|
102019
|
+
if (ledgerKeys.length > 0) {
|
|
102020
|
+
const links = await ports.readLinks();
|
|
102021
|
+
if (links === null) return refuse("no Alexa link record exists");
|
|
102022
|
+
if (!isLedgerShape(stored["linkedAccounts"])) return refuse("the old linkedAccounts setting is not a list the migration understands");
|
|
102023
|
+
if (!isLedgerShape(stored["tokens"])) return refuse("the old tokens setting is not a list the migration understands");
|
|
102024
|
+
const legacyTokens = stored["tokens"];
|
|
102025
|
+
if (Array.isArray(legacyTokens) && legacyTokens.some(carriesCredential)) return refuse("the old settings still carry Amazon push credentials");
|
|
102026
|
+
const heldAccounts = new Map(links.linkedAccounts.map((a) => [a.userId, a]));
|
|
102027
|
+
const heldTokens = new Set(links.tokens.map((t) => t.userId));
|
|
102028
|
+
for (const account of accountsOf(stored["linkedAccounts"])) {
|
|
102029
|
+
const held = heldAccounts.get(account.userId);
|
|
102030
|
+
if (held === void 0) return refuse(`the record lacks the account ${account.userId}`);
|
|
102031
|
+
if (canonical(held) !== canonical(account)) return refuse(`the record holds the account ${account.userId} differently`);
|
|
102032
|
+
}
|
|
102033
|
+
for (const token of tokensOf(stored["tokens"])) if (!heldTokens.has(token.userId)) return refuse(`the record lacks the grant ${token.userId}`);
|
|
102034
|
+
}
|
|
102035
|
+
const present = [...skillKeys, ...ledgerKeys];
|
|
102036
|
+
return { edits: [{
|
|
102037
|
+
op: "deleteKeys",
|
|
102038
|
+
scope: ADDON_SETTINGS_TABLE,
|
|
102039
|
+
keys: present.map(rowId),
|
|
102040
|
+
precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
|
|
102041
|
+
addonId: ALEXA_INSTANCE_ID,
|
|
102042
|
+
key,
|
|
102043
|
+
value: stored[key]
|
|
102044
|
+
}])))
|
|
102045
|
+
}] };
|
|
102046
|
+
}
|
|
102047
|
+
//#endregion
|
|
100454
102048
|
//#region src/migrations/index.ts
|
|
100455
|
-
|
|
100456
|
-
var
|
|
100457
|
-
|
|
100458
|
-
|
|
100459
|
-
|
|
100460
|
-
|
|
100461
|
-
|
|
100462
|
-
|
|
100463
|
-
|
|
100464
|
-
|
|
100465
|
-
|
|
100466
|
-
|
|
100467
|
-
|
|
100468
|
-
|
|
100469
|
-
|
|
100470
|
-
|
|
100471
|
-
|
|
102049
|
+
var DROP_PUBLIC_HUB_URL_ID = "export-alexa/2026-11-02-drop-public-hub-url";
|
|
102050
|
+
var SETTINGS_TO_INTEGRATION_ID = "export-alexa/2026-11-03-settings-to-integration";
|
|
102051
|
+
var LEDGERS_TO_INTEGRATION_ID = "export-alexa/2026-11-03-ledgers-to-integration";
|
|
102052
|
+
var DROP_MOVED_SETTINGS_ID = "export-alexa/2026-11-03-drop-moved-settings";
|
|
102053
|
+
var FIXTURE_MARK = "the exposed device list the migration does not know";
|
|
102054
|
+
/**
|
|
102055
|
+
* The `export-alexa` catalogue (D987): offered to the engine when the addon initialises. Every
|
|
102056
|
+
* entry is `tolerate`; until a record exists the addon keeps reading the legacy keys.
|
|
102057
|
+
*/
|
|
102058
|
+
var ADDON_MIGRATIONS = [
|
|
102059
|
+
{
|
|
102060
|
+
meta: {
|
|
102061
|
+
id: DROP_PUBLIC_HUB_URL_ID,
|
|
102062
|
+
owner: "export-alexa",
|
|
102063
|
+
level: "addon-state",
|
|
102064
|
+
seq: 1,
|
|
102065
|
+
dependsOn: [],
|
|
102066
|
+
store: "settings",
|
|
102067
|
+
scope: "cluster",
|
|
102068
|
+
onFailure: "tolerate",
|
|
102069
|
+
bodyKind: "plan",
|
|
102070
|
+
description: "Delete the retired publicHubUrl setting; the public URL is the publicEndpoint role",
|
|
102071
|
+
fixtureMark: FIXTURE_MARK
|
|
102072
|
+
},
|
|
102073
|
+
plan: planDropPublicHubUrl
|
|
102074
|
+
},
|
|
102075
|
+
{
|
|
102076
|
+
meta: {
|
|
102077
|
+
id: SETTINGS_TO_INTEGRATION_ID,
|
|
102078
|
+
owner: "export-alexa",
|
|
102079
|
+
level: "addon-state",
|
|
102080
|
+
seq: 2,
|
|
102081
|
+
dependsOn: [],
|
|
102082
|
+
store: "settings",
|
|
102083
|
+
scope: "cluster",
|
|
102084
|
+
onFailure: "tolerate",
|
|
102085
|
+
bodyKind: "procedure",
|
|
102086
|
+
description: "Move the Alexa skill settings (mode, region, audience, feature switches) into the skills record",
|
|
102087
|
+
fixtureMark: FIXTURE_MARK
|
|
102088
|
+
},
|
|
102089
|
+
procedure: moveSettingsToSkill
|
|
102090
|
+
},
|
|
102091
|
+
{
|
|
102092
|
+
meta: {
|
|
102093
|
+
id: LEDGERS_TO_INTEGRATION_ID,
|
|
102094
|
+
owner: "export-alexa",
|
|
102095
|
+
level: "addon-state",
|
|
102096
|
+
seq: 3,
|
|
102097
|
+
dependsOn: [SETTINGS_TO_INTEGRATION_ID],
|
|
102098
|
+
store: "settings",
|
|
102099
|
+
scope: "cluster",
|
|
102100
|
+
onFailure: "tolerate",
|
|
102101
|
+
bodyKind: "procedure",
|
|
102102
|
+
description: "Move the linked accounts and Amazon push grants into the skill-links record; the old credentials are cleared only after the record reads back identical",
|
|
102103
|
+
fixtureMark: FIXTURE_MARK
|
|
102104
|
+
},
|
|
102105
|
+
procedure: moveLedgersToLinks
|
|
102106
|
+
},
|
|
102107
|
+
{
|
|
102108
|
+
meta: {
|
|
102109
|
+
id: DROP_MOVED_SETTINGS_ID,
|
|
102110
|
+
owner: "export-alexa",
|
|
102111
|
+
level: "addon-state",
|
|
102112
|
+
seq: 4,
|
|
102113
|
+
dependsOn: [SETTINGS_TO_INTEGRATION_ID, LEDGERS_TO_INTEGRATION_ID],
|
|
102114
|
+
store: "settings",
|
|
102115
|
+
scope: "cluster",
|
|
102116
|
+
onFailure: "tolerate",
|
|
102117
|
+
bodyKind: "plan",
|
|
102118
|
+
description: "Delete the Alexa settings and ledger keys that moved into the records",
|
|
102119
|
+
fixtureMark: FIXTURE_MARK
|
|
102120
|
+
},
|
|
102121
|
+
plan: planDropMovedSettings
|
|
102122
|
+
}
|
|
102123
|
+
];
|
|
100472
102124
|
//#endregion
|
|
100473
102125
|
//#region src/oauth-integration.ts
|
|
100474
102126
|
/**
|
|
@@ -101811,6 +103463,11 @@ var SUPPORTED_KINDS = [
|
|
|
101811
103463
|
DeviceType.Cover,
|
|
101812
103464
|
DeviceType.Generic
|
|
101813
103465
|
];
|
|
103466
|
+
/** Whether a stored token entry still carries a keychain marker instead of a resolved credential. */
|
|
103467
|
+
function hasUnresolvedCredential(entry) {
|
|
103468
|
+
if (typeof entry !== "object" || entry === null) return false;
|
|
103469
|
+
return "accessToken" in entry && isSecretMarker(entry.accessToken) || "refreshToken" in entry && isSecretMarker(entry.refreshToken) || "brokerCredential" in entry && isSecretMarker(entry.brokerCredential);
|
|
103470
|
+
}
|
|
101814
103471
|
var ExportAlexaAddon = class extends BaseAddon {
|
|
101815
103472
|
/** Hidden state that is a credential — kept in the keychain, never the blob (D787). */
|
|
101816
103473
|
secretStatePaths = [
|
|
@@ -101846,13 +103503,85 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
101846
103503
|
constructor() {
|
|
101847
103504
|
super({ ...DEFAULT_CONFIG });
|
|
101848
103505
|
}
|
|
103506
|
+
instances = null;
|
|
103507
|
+
/** The `skills` record, once it exists; until then the legacy settings keys answer. */
|
|
103508
|
+
skillRow = null;
|
|
103509
|
+
/** The `skill-links` record, once it exists; until then the legacy ledger keys answer. */
|
|
103510
|
+
linksRow = null;
|
|
103511
|
+
/** The keychain refused the link credentials: the ledger is read-only until it answers (D49). */
|
|
103512
|
+
linksLocked = false;
|
|
103513
|
+
/**
|
|
103514
|
+
* The legacy ledger keys as lists. A store written by an older build may hold something that
|
|
103515
|
+
* is not a list there (a clear instruction stored as the value); the page and the gateway read
|
|
103516
|
+
* a list or nothing.
|
|
103517
|
+
*/
|
|
103518
|
+
legacyLedgers() {
|
|
103519
|
+
return {
|
|
103520
|
+
linkedAccounts: Array.isArray(this.config.linkedAccounts) ? this.config.linkedAccounts : [],
|
|
103521
|
+
tokens: Array.isArray(this.config.tokens) ? this.config.tokens : []
|
|
103522
|
+
};
|
|
103523
|
+
}
|
|
103524
|
+
/**
|
|
103525
|
+
* The settings as the addon reads them: the records where they exist, the legacy keys until
|
|
103526
|
+
* the migrations have moved them.
|
|
103527
|
+
*/
|
|
103528
|
+
get view() {
|
|
103529
|
+
const skill = this.skillRow;
|
|
103530
|
+
const links = this.linksRow;
|
|
103531
|
+
const legacy = this.legacyLedgers();
|
|
103532
|
+
if (skill === null && links === null) return {
|
|
103533
|
+
...this.config,
|
|
103534
|
+
...legacy
|
|
103535
|
+
};
|
|
103536
|
+
return {
|
|
103537
|
+
...this.config,
|
|
103538
|
+
...legacy,
|
|
103539
|
+
...skill === null ? {} : {
|
|
103540
|
+
skillMode: skill.skillMode,
|
|
103541
|
+
region: skill.region,
|
|
103542
|
+
expectedAudience: skill.expectedAudience,
|
|
103543
|
+
detectionSensors: skill.detectionSensors,
|
|
103544
|
+
objectDetection: skill.objectDetection,
|
|
103545
|
+
snapshots: skill.snapshots,
|
|
103546
|
+
enforceIngressToken: skill.enforceIngressToken
|
|
103547
|
+
},
|
|
103548
|
+
...links === null ? {} : {
|
|
103549
|
+
linkedAccounts: links.linkedAccounts,
|
|
103550
|
+
tokens: links.tokens
|
|
103551
|
+
}
|
|
103552
|
+
};
|
|
103553
|
+
}
|
|
101849
103554
|
/**
|
|
101850
103555
|
* The hub's public origin: the `publicEndpoint` role of `local-network`, read on every use
|
|
101851
103556
|
* through `ctx.api` (planning#378). No setting holds it and nothing ranks the palette here.
|
|
101852
103557
|
*/
|
|
101853
103558
|
publicEndpoint = createPublicEndpointReader(() => this.ctx.api.localNetwork.getAddresses.query());
|
|
101854
103559
|
async onInitialize() {
|
|
101855
|
-
|
|
103560
|
+
const records = this.ctx.records;
|
|
103561
|
+
if (records === void 0) throw new Error("export-alexa needs ctx.records — check execution.placement (hub-only)");
|
|
103562
|
+
await records.declare({
|
|
103563
|
+
skills: alexaSkillsKind,
|
|
103564
|
+
"skill-links": alexaSkillLinksKind
|
|
103565
|
+
});
|
|
103566
|
+
this.instances = new RecordIntegrationInstances(records, alexaSkillsKind, {
|
|
103567
|
+
description: {
|
|
103568
|
+
instanceMode: "single",
|
|
103569
|
+
kind: "skills",
|
|
103570
|
+
canTest: false
|
|
103571
|
+
},
|
|
103572
|
+
formSchema: () => this.skillForm(),
|
|
103573
|
+
initialBody: (name) => ({
|
|
103574
|
+
...ALEXA_SKILL_DEFAULT_BODY,
|
|
103575
|
+
name
|
|
103576
|
+
}),
|
|
103577
|
+
configured: () => true,
|
|
103578
|
+
onChanged: async () => {
|
|
103579
|
+
await this.refreshRecords();
|
|
103580
|
+
await this.onConfigChanged();
|
|
103581
|
+
}
|
|
103582
|
+
});
|
|
103583
|
+
await this.runMigrations(defineAddonMigrations(ADDON_MIGRATIONS, this.migrationPorts()));
|
|
103584
|
+
await this.refreshRecords();
|
|
101856
103585
|
if (!this.config.ingressToken) await this.updateGlobalSettings({ ingressToken: generateIngressToken() });
|
|
101857
103586
|
if (!this.config.snapshotSigningKey) await this.updateGlobalSettings({ snapshotSigningKey: generateIngressToken() });
|
|
101858
103587
|
if (!this.config.visionNamespace) await this.updateGlobalSettings({ visionNamespace: randomUUID() });
|
|
@@ -101870,7 +103599,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
101870
103599
|
});
|
|
101871
103600
|
this.visibilityRef = new AccountVisibilityMirror({
|
|
101872
103601
|
gate: this.accessGateRef,
|
|
101873
|
-
listLinkedUserIds: () => this.
|
|
103602
|
+
listLinkedUserIds: () => this.view.linkedAccounts.map((a) => a.userId),
|
|
101874
103603
|
listExposedDeviceIds: () => this.config.exposed.map((e) => e.deviceId),
|
|
101875
103604
|
getStored: () => this.config.accountVisibility,
|
|
101876
103605
|
setStored: (next) => this.updateGlobalSettings({ accountVisibility: next }),
|
|
@@ -101879,8 +103608,8 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
101879
103608
|
this.visionRef = new AlexaVisionRuntime({
|
|
101880
103609
|
ctx: this.ctx,
|
|
101881
103610
|
logger: this.ctx.logger,
|
|
101882
|
-
integrationOn: () => this.
|
|
101883
|
-
snapshotsOn: () => this.
|
|
103611
|
+
integrationOn: () => this.view.objectDetection,
|
|
103612
|
+
snapshotsOn: () => this.view.snapshots,
|
|
101884
103613
|
isExposed: (deviceId) => this.config.exposed.some((e) => e.deviceId === deviceId),
|
|
101885
103614
|
knownClasses: (deviceId) => this.config.detectionClasses[deviceId]?.classes ?? [],
|
|
101886
103615
|
namespace: () => this.config.visionNamespace,
|
|
@@ -101891,12 +103620,12 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
101891
103620
|
this.actionScenes = new ActionSceneExports({
|
|
101892
103621
|
api: this.ctx.api,
|
|
101893
103622
|
logger: this.ctx.logger,
|
|
101894
|
-
linkedUserIds: () => this.
|
|
103623
|
+
linkedUserIds: () => this.view.linkedAccounts.map((a) => a.userId),
|
|
101895
103624
|
isAdminUser: async (userId) => {
|
|
101896
103625
|
const lookup = await this.accessGate.principal(userId);
|
|
101897
103626
|
return lookup.kind === "found" && lookup.principal.kind === "admin";
|
|
101898
103627
|
},
|
|
101899
|
-
canPush: () => this.
|
|
103628
|
+
canPush: () => this.view.tokens.length > 0,
|
|
101900
103629
|
postAddOrUpdate: (userId, endpoints) => this.requireGateway().postReport(userId, (accessToken) => buildAddOrUpdateReportPayload(userId, endpoints, accessToken), `action scenes add/update (${endpoints.length})`),
|
|
101901
103630
|
postDelete: (userId, ids) => this.requireGateway().postReport(userId, (accessToken) => buildDeleteReportPayload(userId, ids, accessToken), `action scenes delete (${ids.length})`),
|
|
101902
103631
|
persist: (entries) => this.updateGlobalSettings({ exposedActions: [...entries] })
|
|
@@ -101907,7 +103636,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
101907
103636
|
});
|
|
101908
103637
|
const deviceExportProvider = {
|
|
101909
103638
|
getStatus: async () => ({
|
|
101910
|
-
linkState: this.
|
|
103639
|
+
linkState: this.view.linkedAccounts.length > 0 ? "linked" : "unlinked",
|
|
101911
103640
|
exposedDeviceCount: this.config.exposed.length,
|
|
101912
103641
|
setup: await this.buildSetupBlock()
|
|
101913
103642
|
}),
|
|
@@ -101995,6 +103724,10 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
101995
103724
|
ctx: this.ctx,
|
|
101996
103725
|
logger: this.ctx.logger
|
|
101997
103726
|
},
|
|
103727
|
+
mediaPlayerController: {
|
|
103728
|
+
ctx: this.ctx,
|
|
103729
|
+
logger: this.ctx.logger
|
|
103730
|
+
},
|
|
101998
103731
|
coverController: {
|
|
101999
103732
|
ctx: this.ctx,
|
|
102000
103733
|
logger: this.ctx.logger,
|
|
@@ -102004,7 +103737,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102004
103737
|
ctx: this.ctx,
|
|
102005
103738
|
logger: this.ctx.logger,
|
|
102006
103739
|
store: this.snapshotStore,
|
|
102007
|
-
enabled: () => this.
|
|
103740
|
+
enabled: () => this.view.snapshots,
|
|
102008
103741
|
publicEndpoint: this.publicEndpoint
|
|
102009
103742
|
},
|
|
102010
103743
|
vision: this.vision.context(),
|
|
@@ -102026,7 +103759,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102026
103759
|
onBrokerAdvertised: (raw) => this.rememberAdvertisedBroker(raw),
|
|
102027
103760
|
snapshotRoute: {
|
|
102028
103761
|
store: this.snapshotStore,
|
|
102029
|
-
enabled: () => this.
|
|
103762
|
+
enabled: () => this.view.snapshots,
|
|
102030
103763
|
verifyToken: (token) => this.verifyAccountLinkToken(token),
|
|
102031
103764
|
mayView: async (userId, deviceId) => {
|
|
102032
103765
|
const lookup = await this.accessGate.principal(userId);
|
|
@@ -102054,13 +103787,13 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102054
103787
|
onExposedDoorbellPress: (deviceId) => {
|
|
102055
103788
|
this.egressPrewarm?.onPress(deviceId);
|
|
102056
103789
|
},
|
|
102057
|
-
listLinkedAccounts: () => this.
|
|
102058
|
-
listTokens: () => this.
|
|
103790
|
+
listLinkedAccounts: () => this.view.linkedAccounts,
|
|
103791
|
+
listTokens: () => this.view.tokens,
|
|
102059
103792
|
upsertToken: (input) => this.upsertToken(input),
|
|
102060
103793
|
removeLinkedAccount: (userId) => this.removeLinkedAccount(userId),
|
|
102061
103794
|
getAdvertisedBrokerUrl: () => this.config.advertisedBrokerUrl || null,
|
|
102062
103795
|
getPublicEndpoint: this.publicEndpoint,
|
|
102063
|
-
getRegion: () => this.
|
|
103796
|
+
getRegion: () => this.view.region,
|
|
102064
103797
|
getExportedSignature: (deviceId) => this.config.exportedSignatures[deviceId] ?? null,
|
|
102065
103798
|
accountMaySee: (userId, deviceId) => this.visibility.allows(userId, deviceId)
|
|
102066
103799
|
});
|
|
@@ -102068,7 +103801,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102068
103801
|
const gatewayForFeed = this.lwaGateway;
|
|
102069
103802
|
this.detectionFeed = new DetectionSensorFeed({
|
|
102070
103803
|
eventBus: this.ctx.eventBus,
|
|
102071
|
-
enabled: () => this.
|
|
103804
|
+
enabled: () => this.view.detectionSensors,
|
|
102072
103805
|
isExposed: (deviceId) => this.config.exposed.some((e) => e.deviceId === deviceId),
|
|
102073
103806
|
readActiveTracks: async (deviceId) => {
|
|
102074
103807
|
return (await this.ctx.api.pipelineAnalytics.getActiveTracks.query({ deviceId })).map((t) => ({
|
|
@@ -102114,8 +103847,8 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102114
103847
|
this.syncEngine = new SyncEngine({
|
|
102115
103848
|
logger: this.ctx.logger,
|
|
102116
103849
|
listExposed: () => this.config.exposed,
|
|
102117
|
-
listLinkedAccounts: () => this.
|
|
102118
|
-
hasProactiveCredentials: () => this.
|
|
103850
|
+
listLinkedAccounts: () => this.view.linkedAccounts,
|
|
103851
|
+
hasProactiveCredentials: () => this.view.tokens.length > 0,
|
|
102119
103852
|
buildEndpoints: (deviceId) => this.buildEndpointsForOneDevice(deviceId),
|
|
102120
103853
|
filterForAccount: (userId, endpoints) => this.filterForAccount(userId, endpoints),
|
|
102121
103854
|
afterPush: (userId, endpoints) => this.requireGateway().scheduleInitialConnectivity(userId, endpoints),
|
|
@@ -102145,10 +103878,10 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102145
103878
|
this.ctx.addDisposer(async () => clearInterval(reaper));
|
|
102146
103879
|
this.ctx.logger.info("export-alexa: initialized", { meta: {
|
|
102147
103880
|
exposedCount: this.config.exposed.length,
|
|
102148
|
-
skillMode: this.
|
|
103881
|
+
skillMode: this.view.skillMode,
|
|
102149
103882
|
skillIdSet: this.effectiveSettings().expectedAudience.length > 0,
|
|
102150
|
-
pushGrants: this.
|
|
102151
|
-
brokerGrants: this.
|
|
103883
|
+
pushGrants: this.view.tokens.length,
|
|
103884
|
+
brokerGrants: this.view.tokens.filter(isBrokerGrant).length
|
|
102152
103885
|
} });
|
|
102153
103886
|
return {
|
|
102154
103887
|
providers: [
|
|
@@ -102156,6 +103889,10 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102156
103889
|
capability: deviceExportCapability,
|
|
102157
103890
|
provider: deviceExportProvider
|
|
102158
103891
|
},
|
|
103892
|
+
{
|
|
103893
|
+
capability: integrationInstancesCapability,
|
|
103894
|
+
provider: this.requireInstances().toProvider()
|
|
103895
|
+
},
|
|
102159
103896
|
{
|
|
102160
103897
|
capability: addonRoutesCapability,
|
|
102161
103898
|
provider: routeProvider
|
|
@@ -102263,18 +104000,18 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102263
104000
|
return buildEndpointsForExposedDevice(deviceId, {
|
|
102264
104001
|
ctx: this.ctx,
|
|
102265
104002
|
logger: this.ctx.logger,
|
|
102266
|
-
snapshots: this.
|
|
102267
|
-
...this.
|
|
104003
|
+
snapshots: this.view.snapshots,
|
|
104004
|
+
...this.view.detectionSensors ? { detectionClasses: async (id) => effectiveSensorClasses(await classesOf(id), parseSensorSelection(await vision.readPrefs(id))) } : {},
|
|
102268
104005
|
alexaName: async (id) => readAlexaName(await vision.readPrefs(id)),
|
|
102269
|
-
...this.
|
|
104006
|
+
...this.view.objectDetection ? { objectDetection: async (id) => vision.buildClasses(id, await classesOf(id)) } : {}
|
|
102270
104007
|
});
|
|
102271
104008
|
}
|
|
102272
104009
|
/** The settings that change every exposed endpoint's shape, as one key. */
|
|
102273
104010
|
shapeSwitches() {
|
|
102274
104011
|
return JSON.stringify({
|
|
102275
|
-
detectionSensors: this.
|
|
102276
|
-
snapshots: this.
|
|
102277
|
-
objectDetection: this.
|
|
104012
|
+
detectionSensors: this.view.detectionSensors,
|
|
104013
|
+
snapshots: this.view.snapshots,
|
|
104014
|
+
objectDetection: this.view.objectDetection
|
|
102278
104015
|
});
|
|
102279
104016
|
}
|
|
102280
104017
|
/**
|
|
@@ -102286,7 +104023,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102286
104023
|
const now = this.shapeSwitches();
|
|
102287
104024
|
if (this.appliedShapeSwitches === null || now === this.appliedShapeSwitches) return;
|
|
102288
104025
|
this.appliedShapeSwitches = now;
|
|
102289
|
-
if (!this.
|
|
104026
|
+
if (!this.view.snapshots) this.snapshotStore.clear();
|
|
102290
104027
|
this.ctx.logger.info("export-alexa: an endpoint-shape switch changed — re-syncing every device", { meta: { switches: now } });
|
|
102291
104028
|
const engine = this.syncEngine;
|
|
102292
104029
|
if (engine === null) return;
|
|
@@ -102296,7 +104033,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102296
104033
|
}
|
|
102297
104034
|
scheduleDetectionClassRefresh() {
|
|
102298
104035
|
const timer = setInterval(() => {
|
|
102299
|
-
if (!this.
|
|
104036
|
+
if (!this.view.detectionSensors && !this.view.objectDetection) return;
|
|
102300
104037
|
this.requireSyncEngine().reconcileAllExposed().catch((err) => {
|
|
102301
104038
|
this.ctx.logger.warn("export-alexa: detection-class refresh failed", { meta: { error: errMsg$1(err) } });
|
|
102302
104039
|
});
|
|
@@ -102438,8 +104175,8 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102438
104175
|
* Throws when nothing can be sent, so the button says why.
|
|
102439
104176
|
*/
|
|
102440
104177
|
async resyncDiscovery() {
|
|
102441
|
-
if (this.
|
|
102442
|
-
if (this.
|
|
104178
|
+
if (this.view.linkedAccounts.length === 0) throw new Error("No linked Amazon account. Link the skill from the Alexa app first.");
|
|
104179
|
+
if (this.view.tokens.length === 0) throw new Error("No Amazon push grant is stored for the linked account, so nothing can be sent. Re-link the skill from the Alexa app.");
|
|
102443
104180
|
const r = await this.requireSyncEngine().resync();
|
|
102444
104181
|
this.ctx.logger.info("export-alexa: manual discovery re-sync", { meta: { ...r } });
|
|
102445
104182
|
return r;
|
|
@@ -102488,11 +104225,13 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102488
104225
|
}
|
|
102489
104226
|
this.ctx.logger.warn("export-alexa: revokeOauthSession reported failure — the session may already be gone", { meta: { sessionId: id } });
|
|
102490
104227
|
}
|
|
102491
|
-
await this.revokeAtBroker(this.
|
|
102492
|
-
const removedAccounts = this.
|
|
102493
|
-
await this.
|
|
104228
|
+
await this.revokeAtBroker(this.view.tokens);
|
|
104229
|
+
const removedAccounts = this.view.linkedAccounts.length;
|
|
104230
|
+
await this.writeLedger({
|
|
102494
104231
|
linkedAccounts: [],
|
|
102495
|
-
tokens: []
|
|
104232
|
+
tokens: []
|
|
104233
|
+
});
|
|
104234
|
+
await this.updateGlobalSettings({
|
|
102496
104235
|
exportedEndpoints: {},
|
|
102497
104236
|
exportedSignatures: {},
|
|
102498
104237
|
accountVisibility: {}
|
|
@@ -102517,25 +104256,25 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102517
104256
|
...input.brokerUrl ? { brokerUrl: input.brokerUrl } : {},
|
|
102518
104257
|
...input.brokerCredential ? { brokerCredential: input.brokerCredential } : {}
|
|
102519
104258
|
};
|
|
102520
|
-
const next = this.
|
|
104259
|
+
const next = this.view.tokens.filter((t) => t.userId !== input.userId);
|
|
102521
104260
|
next.push(entry);
|
|
102522
|
-
await this.
|
|
104261
|
+
await this.writeLedger({ tokens: next });
|
|
102523
104262
|
}
|
|
102524
104263
|
async removeLinkedAccount(userId) {
|
|
102525
|
-
await this.
|
|
102526
|
-
tokens: this.
|
|
102527
|
-
linkedAccounts: this.
|
|
104264
|
+
await this.writeLedger({
|
|
104265
|
+
tokens: this.view.tokens.filter((t) => t.userId !== userId),
|
|
104266
|
+
linkedAccounts: this.view.linkedAccounts.filter((a) => a.userId !== userId)
|
|
102528
104267
|
});
|
|
102529
104268
|
this.ctx.logger.warn("export-alexa: unlinked revoked account", { meta: { userId } });
|
|
102530
104269
|
}
|
|
102531
104270
|
async recordLinkedAccount(input) {
|
|
102532
|
-
if (this.
|
|
102533
|
-
const next = [...this.
|
|
104271
|
+
if (this.view.linkedAccounts.some((a) => a.userId === input.userId)) return;
|
|
104272
|
+
const next = [...this.view.linkedAccounts, {
|
|
102534
104273
|
userId: input.userId,
|
|
102535
104274
|
username: input.username,
|
|
102536
104275
|
linkedAt: Date.now()
|
|
102537
104276
|
}];
|
|
102538
|
-
await this.
|
|
104277
|
+
await this.writeLedger({ linkedAccounts: next });
|
|
102539
104278
|
const engine = this.syncEngine;
|
|
102540
104279
|
if (!engine) return;
|
|
102541
104280
|
engine.pushAllToAccount(input.userId).then((r) => {
|
|
@@ -102554,8 +104293,8 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102554
104293
|
* token carries none). Idempotent via recordLinkedAccount.
|
|
102555
104294
|
*/
|
|
102556
104295
|
async backfillLinkedAccounts() {
|
|
102557
|
-
const linked = new Set(this.
|
|
102558
|
-
const missing = this.
|
|
104296
|
+
const linked = new Set(this.view.linkedAccounts.map((a) => a.userId));
|
|
104297
|
+
const missing = this.view.tokens.filter((t) => !linked.has(t.userId));
|
|
102559
104298
|
for (const t of missing) await this.recordLinkedAccount({
|
|
102560
104299
|
userId: t.userId,
|
|
102561
104300
|
username: t.userId
|
|
@@ -102597,10 +104336,10 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102597
104336
|
* broker no longer recognises is reported, not retried — re-link instead.
|
|
102598
104337
|
*/
|
|
102599
104338
|
async rotateBrokerCredentials() {
|
|
102600
|
-
if (!this.
|
|
104339
|
+
if (!this.view.tokens.some(isBrokerGrant)) throw new Error("No link is held at the skill's token broker, so there is no credential to rotate. Link the skill from the Alexa app first.");
|
|
102601
104340
|
let rotated = 0;
|
|
102602
104341
|
let failed = 0;
|
|
102603
|
-
for (const t of this.
|
|
104342
|
+
for (const t of this.view.tokens) {
|
|
102604
104343
|
if (!isBrokerGrant(t)) continue;
|
|
102605
104344
|
try {
|
|
102606
104345
|
const next = await rotateBrokerCredential(fetch, t.brokerUrl, t.brokerCredential);
|
|
@@ -102652,17 +104391,139 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102652
104391
|
return buildAlexaSetupBlock({
|
|
102653
104392
|
publicEndpoint: await this.publicEndpoint(),
|
|
102654
104393
|
ingressToken: this.config.ingressToken,
|
|
102655
|
-
skillMode: this.
|
|
104394
|
+
skillMode: this.view.skillMode
|
|
102656
104395
|
});
|
|
102657
104396
|
}
|
|
104397
|
+
requireInstances() {
|
|
104398
|
+
if (this.instances === null) throw new Error("export-alexa: the instances are not open");
|
|
104399
|
+
return this.instances;
|
|
104400
|
+
}
|
|
104401
|
+
skillHandle() {
|
|
104402
|
+
const records = this.ctx.records;
|
|
104403
|
+
if (records === void 0) throw new Error("records are not available");
|
|
104404
|
+
return records.kind(alexaSkillsKind);
|
|
104405
|
+
}
|
|
104406
|
+
linksHandle() {
|
|
104407
|
+
const records = this.ctx.records;
|
|
104408
|
+
if (records === void 0) throw new Error("records are not available");
|
|
104409
|
+
return records.kind(alexaSkillLinksKind);
|
|
104410
|
+
}
|
|
104411
|
+
/** Re-read both records. A failed read changes nothing: the addon keeps what it has. */
|
|
104412
|
+
async refreshRecords() {
|
|
104413
|
+
try {
|
|
104414
|
+
this.skillRow = (await this.skillHandle().getResolved("export-alexa"))?.data ?? null;
|
|
104415
|
+
} catch (err) {
|
|
104416
|
+
this.ctx.logger.warn("export-alexa: the skill record could not be read", {
|
|
104417
|
+
meta: { error: errMsg$1(err) },
|
|
104418
|
+
tags: {
|
|
104419
|
+
topic: "export-alexa",
|
|
104420
|
+
phase: "records-read-failed"
|
|
104421
|
+
}
|
|
104422
|
+
});
|
|
104423
|
+
}
|
|
104424
|
+
try {
|
|
104425
|
+
this.linksRow = (await this.linksHandle().getResolved("export-alexa"))?.data ?? null;
|
|
104426
|
+
this.linksLocked = false;
|
|
104427
|
+
} catch (err) {
|
|
104428
|
+
if (!(err instanceof RecordSecretUnavailableError)) {
|
|
104429
|
+
this.ctx.logger.warn("export-alexa: the link record could not be read", {
|
|
104430
|
+
meta: { error: errMsg$1(err) },
|
|
104431
|
+
tags: {
|
|
104432
|
+
topic: "export-alexa",
|
|
104433
|
+
phase: "records-read-failed"
|
|
104434
|
+
}
|
|
104435
|
+
});
|
|
104436
|
+
return;
|
|
104437
|
+
}
|
|
104438
|
+
this.linksLocked = true;
|
|
104439
|
+
this.ctx.logger.warn("export-alexa: the keychain is locked; the link ledger is read-only", { tags: {
|
|
104440
|
+
topic: "export-alexa",
|
|
104441
|
+
phase: "keychain-locked"
|
|
104442
|
+
} });
|
|
104443
|
+
}
|
|
104444
|
+
}
|
|
104445
|
+
/**
|
|
104446
|
+
* Write the account-link ledgers: to the `skill-links` record once it exists, to the legacy
|
|
104447
|
+
* settings keys until then (the migration moves them).
|
|
104448
|
+
*/
|
|
104449
|
+
async writeLedger(patch) {
|
|
104450
|
+
if (this.linksRow === null) {
|
|
104451
|
+
await this.updateGlobalSettings({
|
|
104452
|
+
...patch.linkedAccounts === void 0 ? {} : { linkedAccounts: patch.linkedAccounts },
|
|
104453
|
+
...patch.tokens === void 0 ? {} : { tokens: patch.tokens }
|
|
104454
|
+
});
|
|
104455
|
+
return;
|
|
104456
|
+
}
|
|
104457
|
+
if (this.linksLocked) throw new Error("the keychain is locked: the Amazon link ledger cannot be changed right now");
|
|
104458
|
+
const next = {
|
|
104459
|
+
name: this.linksRow.name,
|
|
104460
|
+
linkedAccounts: patch.linkedAccounts ?? this.linksRow.linkedAccounts,
|
|
104461
|
+
tokens: patch.tokens ?? this.linksRow.tokens
|
|
104462
|
+
};
|
|
104463
|
+
await this.linksHandle().put({
|
|
104464
|
+
id: ALEXA_INSTANCE_ID,
|
|
104465
|
+
data: next
|
|
104466
|
+
});
|
|
104467
|
+
this.linksRow = next;
|
|
104468
|
+
}
|
|
104469
|
+
/** The ports of the settings migrations: the old settings in, the records out. */
|
|
104470
|
+
migrationPorts() {
|
|
104471
|
+
const skills = this.skillHandle();
|
|
104472
|
+
const links = this.linksHandle();
|
|
104473
|
+
const putOnce = async (handle, body) => {
|
|
104474
|
+
if (await handle.get("export-alexa") !== null) return "exists";
|
|
104475
|
+
try {
|
|
104476
|
+
await handle.put({
|
|
104477
|
+
id: ALEXA_INSTANCE_ID,
|
|
104478
|
+
data: body
|
|
104479
|
+
}, { ifRev: 0 });
|
|
104480
|
+
} catch (err) {
|
|
104481
|
+
if (err instanceof RevConflictError) return "exists";
|
|
104482
|
+
throw err;
|
|
104483
|
+
}
|
|
104484
|
+
return "created";
|
|
104485
|
+
};
|
|
104486
|
+
return {
|
|
104487
|
+
readStored: async () => {
|
|
104488
|
+
const stored = await this.resolveGlobalStore();
|
|
104489
|
+
const tokens = stored["tokens"];
|
|
104490
|
+
if (Array.isArray(tokens) && tokens.some(hasUnresolvedCredential)) throw new Error("the old Amazon push grants could not be resolved");
|
|
104491
|
+
return stored;
|
|
104492
|
+
},
|
|
104493
|
+
readRawStored: async () => await this.ctx.settings?.readAddonStore() ?? {},
|
|
104494
|
+
warn: (message) => {
|
|
104495
|
+
this.ctx.logger.warn(message, { tags: {
|
|
104496
|
+
topic: "export-alexa",
|
|
104497
|
+
phase: "migration"
|
|
104498
|
+
} });
|
|
104499
|
+
},
|
|
104500
|
+
putSkill: (body) => putOnce(skills, body),
|
|
104501
|
+
putLinks: (body) => putOnce(links, body),
|
|
104502
|
+
replaceLinks: async (body) => {
|
|
104503
|
+
await links.put({
|
|
104504
|
+
id: ALEXA_INSTANCE_ID,
|
|
104505
|
+
data: body
|
|
104506
|
+
});
|
|
104507
|
+
},
|
|
104508
|
+
readLinks: async () => (await links.getResolved("export-alexa"))?.data ?? null,
|
|
104509
|
+
hasSkill: async () => await skills.get(ALEXA_INSTANCE_ID) !== null,
|
|
104510
|
+
clearOldTokenSecrets: async () => {
|
|
104511
|
+
await this.clearSecrets(["tokens"]);
|
|
104512
|
+
}
|
|
104513
|
+
};
|
|
104514
|
+
}
|
|
104515
|
+
/** The instance form: how the skill reaches this hub and what each camera carries. */
|
|
104516
|
+
skillForm() {
|
|
104517
|
+
return { sections: buildAlexaInstanceSections({ defaults: ALEXA_SKILL_DEFAULT_BODY }) };
|
|
104518
|
+
}
|
|
102658
104519
|
/** The settings page: see `settings-schema.ts` for its layout. The account-
|
|
102659
104520
|
* linking rows live in the `device-export` setup block instead. */
|
|
102660
104521
|
globalSettingsSchema() {
|
|
102661
104522
|
return { sections: buildAlexaSettingsSections({
|
|
102662
|
-
linkedAccounts: this.
|
|
102663
|
-
tokens: this.
|
|
104523
|
+
linkedAccounts: this.view.linkedAccounts,
|
|
104524
|
+
tokens: this.view.tokens,
|
|
102664
104525
|
now: Date.now(),
|
|
102665
|
-
|
|
104526
|
+
skillMode: this.view.skillMode
|
|
102666
104527
|
}) };
|
|
102667
104528
|
}
|
|
102668
104529
|
/**
|
|
@@ -102703,7 +104564,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102703
104564
|
const settings = entry?.settings ?? DEFAULT_DEVICE_SETTINGS;
|
|
102704
104565
|
const enabled = entry !== null;
|
|
102705
104566
|
const enabledKey = `alexa:${deviceId}:enabled`;
|
|
102706
|
-
const linkedCount = this.
|
|
104567
|
+
const linkedCount = this.view.linkedAccounts.length;
|
|
102707
104568
|
const statusLabel = enabled ? `Exposed${linkedCount > 0 ? `, ${linkedCount} linked Alexa account(s)` : " (no linked Alexa account yet)"}` : linkedCount > 0 ? `${linkedCount} linked Alexa account(s) — device not exposed` : "Not exposed";
|
|
102708
104569
|
return {
|
|
102709
104570
|
tabs: [{
|
|
@@ -102770,12 +104631,12 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102770
104631
|
available: this.detectionClassSource === null ? [] : await this.detectionClassSource.classesFor(deviceId).catch(() => []),
|
|
102771
104632
|
saved: parseSensorSelection(store),
|
|
102772
104633
|
enabledKey,
|
|
102773
|
-
masterOn: this.
|
|
104634
|
+
masterOn: this.view.detectionSensors
|
|
102774
104635
|
}), objectDetectionField({
|
|
102775
104636
|
deviceId,
|
|
102776
104637
|
store,
|
|
102777
104638
|
enabledKey,
|
|
102778
|
-
integrationOn: this.
|
|
104639
|
+
integrationOn: this.view.objectDetection
|
|
102779
104640
|
})];
|
|
102780
104641
|
}
|
|
102781
104642
|
/**
|