@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
|
@@ -820,7 +820,7 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
|
|
|
820
820
|
return EventCategory;
|
|
821
821
|
}({});
|
|
822
822
|
//#endregion
|
|
823
|
-
//#region ../types/dist/device-type-
|
|
823
|
+
//#region ../types/dist/device-type-D1fH5kaC.mjs
|
|
824
824
|
/**
|
|
825
825
|
import { errMsg } from '@camstack/types'
|
|
826
826
|
* Extract a human-readable message from an unknown error value.
|
|
@@ -1051,6 +1051,12 @@ var DeviceFeature = /* @__PURE__ */ function(DeviceFeature) {
|
|
|
1051
1051
|
DeviceFeature["MediaPlayerPrevious"] = "media-player-previous";
|
|
1052
1052
|
/** Media player exposes stop distinct from pause. */
|
|
1053
1053
|
DeviceFeature["MediaPlayerStop"] = "media-player-stop";
|
|
1054
|
+
/** Media player exposes volume up / down in steps (an infrared TV has no level). */
|
|
1055
|
+
DeviceFeature["MediaPlayerVolumeStep"] = "media-player-volume-step";
|
|
1056
|
+
/** Media player exposes channel up / down in steps. */
|
|
1057
|
+
DeviceFeature["MediaPlayerChannelStep"] = "media-player-channel-step";
|
|
1058
|
+
/** Media player exposes power on / off. */
|
|
1059
|
+
DeviceFeature["MediaPlayerPower"] = "media-player-power";
|
|
1054
1060
|
/** Alarm panel requires a PIN code on arm/disarm. */
|
|
1055
1061
|
DeviceFeature["AlarmPinRequired"] = "alarm-pin-required";
|
|
1056
1062
|
/** Presence device carries GPS coordinates (lat/lng/accuracy) in
|
|
@@ -4587,6 +4593,12 @@ var numberProcessor = (schema, ctx, _json, _params) => {
|
|
|
4587
4593
|
var booleanProcessor = (_schema, _ctx, json, _params) => {
|
|
4588
4594
|
json.type = "boolean";
|
|
4589
4595
|
};
|
|
4596
|
+
var bigintProcessor = (_schema, ctx, _json, _params) => {
|
|
4597
|
+
if (ctx.unrepresentable === "throw") throw new Error("BigInt cannot be represented in JSON Schema");
|
|
4598
|
+
};
|
|
4599
|
+
var symbolProcessor = (_schema, ctx, _json, _params) => {
|
|
4600
|
+
if (ctx.unrepresentable === "throw") throw new Error("Symbols cannot be represented in JSON Schema");
|
|
4601
|
+
};
|
|
4590
4602
|
var nullProcessor = (_schema, ctx, json, _params) => {
|
|
4591
4603
|
if (ctx.target === "openapi-3.0") {
|
|
4592
4604
|
json.type = "string";
|
|
@@ -4594,12 +4606,17 @@ var nullProcessor = (_schema, ctx, json, _params) => {
|
|
|
4594
4606
|
json.enum = [null];
|
|
4595
4607
|
} else json.type = "null";
|
|
4596
4608
|
};
|
|
4609
|
+
var undefinedProcessor = (_schema, ctx, _json, _params) => {
|
|
4610
|
+
if (ctx.unrepresentable === "throw") throw new Error("Undefined cannot be represented in JSON Schema");
|
|
4611
|
+
};
|
|
4597
4612
|
var voidProcessor = (_schema, ctx, _json, _params) => {
|
|
4598
4613
|
if (ctx.unrepresentable === "throw") throw new Error("Void cannot be represented in JSON Schema");
|
|
4599
4614
|
};
|
|
4600
4615
|
var neverProcessor = (_schema, _ctx, json, _params) => {
|
|
4601
4616
|
json.not = {};
|
|
4602
4617
|
};
|
|
4618
|
+
var anyProcessor = (_schema, _ctx, _json, _params) => {};
|
|
4619
|
+
var unknownProcessor = (_schema, _ctx, _json, _params) => {};
|
|
4603
4620
|
var dateProcessor = (_schema, ctx, _json, _params) => {
|
|
4604
4621
|
if (ctx.unrepresentable === "throw") throw new Error("Date cannot be represented in JSON Schema");
|
|
4605
4622
|
};
|
|
@@ -4631,12 +4648,53 @@ var literalProcessor = (schema, ctx, json, _params) => {
|
|
|
4631
4648
|
json.enum = vals;
|
|
4632
4649
|
}
|
|
4633
4650
|
};
|
|
4651
|
+
var nanProcessor = (_schema, ctx, _json, _params) => {
|
|
4652
|
+
if (ctx.unrepresentable === "throw") throw new Error("NaN cannot be represented in JSON Schema");
|
|
4653
|
+
};
|
|
4654
|
+
var templateLiteralProcessor = (schema, _ctx, json, _params) => {
|
|
4655
|
+
const _json = json;
|
|
4656
|
+
const pattern = schema._zod.pattern;
|
|
4657
|
+
if (!pattern) throw new Error("Pattern not found in template literal");
|
|
4658
|
+
_json.type = "string";
|
|
4659
|
+
_json.pattern = pattern.source;
|
|
4660
|
+
};
|
|
4661
|
+
var fileProcessor = (schema, _ctx, json, _params) => {
|
|
4662
|
+
const _json = json;
|
|
4663
|
+
const file = {
|
|
4664
|
+
type: "string",
|
|
4665
|
+
format: "binary",
|
|
4666
|
+
contentEncoding: "binary"
|
|
4667
|
+
};
|
|
4668
|
+
const { minimum, maximum, mime } = schema._zod.bag;
|
|
4669
|
+
if (minimum !== void 0) file.minLength = minimum;
|
|
4670
|
+
if (maximum !== void 0) file.maxLength = maximum;
|
|
4671
|
+
if (mime) if (mime.length === 1) {
|
|
4672
|
+
file.contentMediaType = mime[0];
|
|
4673
|
+
Object.assign(_json, file);
|
|
4674
|
+
} else {
|
|
4675
|
+
Object.assign(_json, file);
|
|
4676
|
+
_json.anyOf = mime.map((m) => ({ contentMediaType: m }));
|
|
4677
|
+
}
|
|
4678
|
+
else Object.assign(_json, file);
|
|
4679
|
+
};
|
|
4680
|
+
var successProcessor = (_schema, _ctx, json, _params) => {
|
|
4681
|
+
json.type = "boolean";
|
|
4682
|
+
};
|
|
4634
4683
|
var customProcessor = (_schema, ctx, _json, _params) => {
|
|
4635
4684
|
if (ctx.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema");
|
|
4636
4685
|
};
|
|
4686
|
+
var functionProcessor = (_schema, ctx, _json, _params) => {
|
|
4687
|
+
if (ctx.unrepresentable === "throw") throw new Error("Function types cannot be represented in JSON Schema");
|
|
4688
|
+
};
|
|
4637
4689
|
var transformProcessor = (_schema, ctx, _json, _params) => {
|
|
4638
4690
|
if (ctx.unrepresentable === "throw") throw new Error("Transforms cannot be represented in JSON Schema");
|
|
4639
4691
|
};
|
|
4692
|
+
var mapProcessor = (_schema, ctx, _json, _params) => {
|
|
4693
|
+
if (ctx.unrepresentable === "throw") throw new Error("Map cannot be represented in JSON Schema");
|
|
4694
|
+
};
|
|
4695
|
+
var setProcessor = (_schema, ctx, _json, _params) => {
|
|
4696
|
+
if (ctx.unrepresentable === "throw") throw new Error("Set cannot be represented in JSON Schema");
|
|
4697
|
+
};
|
|
4640
4698
|
var arrayProcessor = (schema, ctx, _json, params) => {
|
|
4641
4699
|
const json = _json;
|
|
4642
4700
|
const def = schema._zod.def;
|
|
@@ -4841,6 +4899,12 @@ var readonlyProcessor = (schema, ctx, json, params) => {
|
|
|
4841
4899
|
seen.ref = def.innerType;
|
|
4842
4900
|
json.readOnly = true;
|
|
4843
4901
|
};
|
|
4902
|
+
var promiseProcessor = (schema, ctx, _json, params) => {
|
|
4903
|
+
const def = schema._zod.def;
|
|
4904
|
+
process$1(def.innerType, ctx, params);
|
|
4905
|
+
const seen = ctx.seen.get(schema);
|
|
4906
|
+
seen.ref = def.innerType;
|
|
4907
|
+
};
|
|
4844
4908
|
var optionalProcessor = (schema, ctx, _json, params) => {
|
|
4845
4909
|
const def = schema._zod.def;
|
|
4846
4910
|
process$1(def.innerType, ctx, params);
|
|
@@ -4853,6 +4917,81 @@ var lazyProcessor = (schema, ctx, _json, params) => {
|
|
|
4853
4917
|
const seen = ctx.seen.get(schema);
|
|
4854
4918
|
seen.ref = innerType;
|
|
4855
4919
|
};
|
|
4920
|
+
var allProcessors = {
|
|
4921
|
+
string: stringProcessor,
|
|
4922
|
+
number: numberProcessor,
|
|
4923
|
+
boolean: booleanProcessor,
|
|
4924
|
+
bigint: bigintProcessor,
|
|
4925
|
+
symbol: symbolProcessor,
|
|
4926
|
+
null: nullProcessor,
|
|
4927
|
+
undefined: undefinedProcessor,
|
|
4928
|
+
void: voidProcessor,
|
|
4929
|
+
never: neverProcessor,
|
|
4930
|
+
any: anyProcessor,
|
|
4931
|
+
unknown: unknownProcessor,
|
|
4932
|
+
date: dateProcessor,
|
|
4933
|
+
enum: enumProcessor,
|
|
4934
|
+
literal: literalProcessor,
|
|
4935
|
+
nan: nanProcessor,
|
|
4936
|
+
template_literal: templateLiteralProcessor,
|
|
4937
|
+
file: fileProcessor,
|
|
4938
|
+
success: successProcessor,
|
|
4939
|
+
custom: customProcessor,
|
|
4940
|
+
function: functionProcessor,
|
|
4941
|
+
transform: transformProcessor,
|
|
4942
|
+
map: mapProcessor,
|
|
4943
|
+
set: setProcessor,
|
|
4944
|
+
array: arrayProcessor,
|
|
4945
|
+
object: objectProcessor,
|
|
4946
|
+
union: unionProcessor,
|
|
4947
|
+
intersection: intersectionProcessor,
|
|
4948
|
+
tuple: tupleProcessor,
|
|
4949
|
+
record: recordProcessor,
|
|
4950
|
+
nullable: nullableProcessor,
|
|
4951
|
+
nonoptional: nonoptionalProcessor,
|
|
4952
|
+
default: defaultProcessor,
|
|
4953
|
+
prefault: prefaultProcessor,
|
|
4954
|
+
catch: catchProcessor,
|
|
4955
|
+
pipe: pipeProcessor,
|
|
4956
|
+
readonly: readonlyProcessor,
|
|
4957
|
+
promise: promiseProcessor,
|
|
4958
|
+
optional: optionalProcessor,
|
|
4959
|
+
lazy: lazyProcessor
|
|
4960
|
+
};
|
|
4961
|
+
function toJSONSchema(input, params) {
|
|
4962
|
+
if ("_idmap" in input) {
|
|
4963
|
+
const registry = input;
|
|
4964
|
+
const ctx = initializeContext({
|
|
4965
|
+
...params,
|
|
4966
|
+
processors: allProcessors
|
|
4967
|
+
});
|
|
4968
|
+
const defs = {};
|
|
4969
|
+
for (const entry of registry._idmap.entries()) {
|
|
4970
|
+
const [_, schema] = entry;
|
|
4971
|
+
process$1(schema, ctx);
|
|
4972
|
+
}
|
|
4973
|
+
const schemas = {};
|
|
4974
|
+
ctx.external = {
|
|
4975
|
+
registry,
|
|
4976
|
+
uri: params?.uri,
|
|
4977
|
+
defs
|
|
4978
|
+
};
|
|
4979
|
+
for (const entry of registry._idmap.entries()) {
|
|
4980
|
+
const [key, schema] = entry;
|
|
4981
|
+
extractDefs(ctx, schema);
|
|
4982
|
+
schemas[key] = finalize(ctx, schema);
|
|
4983
|
+
}
|
|
4984
|
+
if (Object.keys(defs).length > 0) schemas.__shared = { [ctx.target === "draft-2020-12" ? "$defs" : "definitions"]: defs };
|
|
4985
|
+
return { schemas };
|
|
4986
|
+
}
|
|
4987
|
+
const ctx = initializeContext({
|
|
4988
|
+
...params,
|
|
4989
|
+
processors: allProcessors
|
|
4990
|
+
});
|
|
4991
|
+
process$1(input, ctx);
|
|
4992
|
+
extractDefs(ctx, input);
|
|
4993
|
+
return finalize(ctx, input);
|
|
4994
|
+
}
|
|
4856
4995
|
//#endregion
|
|
4857
4996
|
//#region ../../node_modules/zod/v4/classic/iso.js
|
|
4858
4997
|
var ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
|
|
@@ -5877,7 +6016,7 @@ var ZodIssueCode = {
|
|
|
5877
6016
|
var ZodFirstPartyTypeKind;
|
|
5878
6017
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
5879
6018
|
//#endregion
|
|
5880
|
-
//#region ../types/dist/sleep-
|
|
6019
|
+
//#region ../types/dist/sleep-DV4qxEyD.mjs
|
|
5881
6020
|
/**
|
|
5882
6021
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
5883
6022
|
* window to float samples (D455).
|
|
@@ -5956,6 +6095,22 @@ function buildAlawTable() {
|
|
|
5956
6095
|
}
|
|
5957
6096
|
buildUlawTable();
|
|
5958
6097
|
buildAlawTable();
|
|
6098
|
+
/**
|
|
6099
|
+
* An addon whose own migrations did not apply refuses to initialise (D987). The error is typed
|
|
6100
|
+
* so a runner hosting several addons can tell "this addon is blocked" from a crash and keep its
|
|
6101
|
+
* co-located siblings running. Recognised by NAME and shape, never `instanceof`: a forked addon
|
|
6102
|
+
* bundles its own copy of this module, so the class the runner sees is not the one that threw.
|
|
6103
|
+
*/
|
|
6104
|
+
var MIGRATIONS_BLOCKED_ERROR_NAME = "AddonMigrationsBlockedError";
|
|
6105
|
+
var AddonMigrationsBlockedError = class extends Error {
|
|
6106
|
+
/** The ledger ids that did not apply and block the owner. */
|
|
6107
|
+
migrationIds;
|
|
6108
|
+
constructor(migrationIds) {
|
|
6109
|
+
super(`migration(s) ${migrationIds.join(", ")} did not apply and block this addon — fix or retry them (migrations.retry), then restart it`);
|
|
6110
|
+
this.name = MIGRATIONS_BLOCKED_ERROR_NAME;
|
|
6111
|
+
this.migrationIds = migrationIds;
|
|
6112
|
+
}
|
|
6113
|
+
};
|
|
5959
6114
|
/** Is this field's stored value a credential? */
|
|
5960
6115
|
function isSecretConfigField(field) {
|
|
5961
6116
|
if (field.type === "password") return true;
|
|
@@ -6009,9 +6164,16 @@ function isSecretMarker(value) {
|
|
|
6009
6164
|
const ref = value["$secret"];
|
|
6010
6165
|
return typeof ref === "string" && ref.length > 0;
|
|
6011
6166
|
}
|
|
6167
|
+
/** Anything carrying a `$secret` key — a stored marker or a UI view of one. */
|
|
6168
|
+
function isSecretMarkerLike(value) {
|
|
6169
|
+
return isRecord$7(value) && Object.prototype.hasOwnProperty.call(value, "$secret");
|
|
6170
|
+
}
|
|
6012
6171
|
function isSecretClear(value) {
|
|
6013
6172
|
return isRecord$7(value) && value["$secretClear"] === true;
|
|
6014
6173
|
}
|
|
6174
|
+
function isSecretFieldView(value) {
|
|
6175
|
+
return isRecord$7(value) && value["set"] === true && isSecretMarkerLike(value);
|
|
6176
|
+
}
|
|
6015
6177
|
/**
|
|
6016
6178
|
* The UI view of a stored secret field value: a marker becomes "set", inline
|
|
6017
6179
|
* plaintext becomes "set (inline)", nothing becomes `null`. A value never
|
|
@@ -6661,11 +6823,36 @@ function projectStore(store, perNodeKeys, nodeId) {
|
|
|
6661
6823
|
}
|
|
6662
6824
|
return out;
|
|
6663
6825
|
}
|
|
6826
|
+
/**
|
|
6827
|
+
* The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
|
|
6828
|
+
*
|
|
6829
|
+
* A ref is DETERMINISTIC from where the value lives — the owner addon, the
|
|
6830
|
+
* scope (global, one node, one device, one integration, one row of a business
|
|
6831
|
+
* collection) and the field path inside that scope — so saving the same field
|
|
6832
|
+
* twice updates the same ref, and the ref itself says which settings blob
|
|
6833
|
+
* points at it. It is also the AAD of the value's ciphertext: a ciphertext
|
|
6834
|
+
* copied onto another ref does not decrypt.
|
|
6835
|
+
*
|
|
6836
|
+
* Array items are addressed by ITEM ID, never by index
|
|
6837
|
+
* (`providers[authentik].clientSecret`), so reordering a list keeps every ref.
|
|
6838
|
+
*
|
|
6839
|
+
* Pure and browser-safe: no node builtins, no I/O.
|
|
6840
|
+
*/
|
|
6841
|
+
/** The URI scheme of every keychain ref. */
|
|
6842
|
+
var SECRET_REF_SCHEME = "secret://";
|
|
6664
6843
|
var GLOBAL_SCOPE = { kind: "global" };
|
|
6665
6844
|
/** The scope every addon-wide (not per-node, not per-device) setting lives in. */
|
|
6666
6845
|
function globalSecretScope() {
|
|
6667
6846
|
return GLOBAL_SCOPE;
|
|
6668
6847
|
}
|
|
6848
|
+
/**
|
|
6849
|
+
* An addon id as a ref owner. A hub in-process builtin's context id is
|
|
6850
|
+
* `addon:<id>`; the owner of its secrets is `<id>`, exactly as for the same
|
|
6851
|
+
* addon running forked.
|
|
6852
|
+
*/
|
|
6853
|
+
function normalizeSecretOwner(addonId) {
|
|
6854
|
+
return addonId.startsWith("addon:") ? addonId.slice(6) : addonId;
|
|
6855
|
+
}
|
|
6669
6856
|
function encodeSegment(value) {
|
|
6670
6857
|
return encodeURIComponent(value);
|
|
6671
6858
|
}
|
|
@@ -6676,6 +6863,16 @@ function decodeSegment(value) {
|
|
|
6676
6863
|
return null;
|
|
6677
6864
|
}
|
|
6678
6865
|
}
|
|
6866
|
+
/** The scope as it appears inside a ref (`global`, `node/<id>`, …). */
|
|
6867
|
+
function formatSecretScope(scope) {
|
|
6868
|
+
switch (scope.kind) {
|
|
6869
|
+
case "global": return "global";
|
|
6870
|
+
case "node": return `node/${encodeSegment(scope.nodeId)}`;
|
|
6871
|
+
case "device": return `device/${scope.deviceId}`;
|
|
6872
|
+
case "integration": return `integration/${encodeSegment(scope.integrationId)}`;
|
|
6873
|
+
case "row": return `row/${encodeSegment(scope.collection)}/${encodeSegment(scope.rowId)}`;
|
|
6874
|
+
}
|
|
6875
|
+
}
|
|
6679
6876
|
/**
|
|
6680
6877
|
* The field path of a value inside an array item, addressed by the item's id:
|
|
6681
6878
|
* `arrayItemFieldPath('providers', 'authentik', 'clientSecret')` →
|
|
@@ -6684,6 +6881,13 @@ function decodeSegment(value) {
|
|
|
6684
6881
|
function arrayItemFieldPath(arrayKey, itemId, fieldKey) {
|
|
6685
6882
|
return `${arrayKey}[${encodeSegment(itemId)}].${fieldKey}`;
|
|
6686
6883
|
}
|
|
6884
|
+
/** Build a ref. Throws on an empty owner or field path — both are bugs. */
|
|
6885
|
+
function buildSecretRef(parts) {
|
|
6886
|
+
const owner = normalizeSecretOwner(parts.owner);
|
|
6887
|
+
if (owner.length === 0) throw new Error("buildSecretRef: owner is empty");
|
|
6888
|
+
if (parts.fieldPath.length === 0) throw new Error("buildSecretRef: fieldPath is empty");
|
|
6889
|
+
return `${SECRET_REF_SCHEME}${encodeSegment(owner)}/${formatSecretScope(parts.scope)}/${parts.fieldPath}`;
|
|
6890
|
+
}
|
|
6687
6891
|
function parseScope(segments) {
|
|
6688
6892
|
switch (segments[0]) {
|
|
6689
6893
|
case "global": return {
|
|
@@ -6824,7 +7028,7 @@ async function writeMembers(ctx, children, incoming, stored, pathOf) {
|
|
|
6824
7028
|
for (const [member, node] of children) applyMember(out, member, await writeNode(ctx, node, incoming[member], stored[member], pathOf(member)), stored);
|
|
6825
7029
|
return out;
|
|
6826
7030
|
}
|
|
6827
|
-
function rowId(row, idKey) {
|
|
7031
|
+
function rowId$1(row, idKey) {
|
|
6828
7032
|
const raw = row[idKey];
|
|
6829
7033
|
if (typeof raw === "string" && raw.length > 0) return raw;
|
|
6830
7034
|
if (typeof raw === "number" && Number.isFinite(raw)) return String(raw);
|
|
@@ -6841,7 +7045,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
6841
7045
|
}
|
|
6842
7046
|
const storedById = /* @__PURE__ */ new Map();
|
|
6843
7047
|
for (const row of storedRows) {
|
|
6844
|
-
const id = rowId(row, node.idKey);
|
|
7048
|
+
const id = rowId$1(row, node.idKey);
|
|
6845
7049
|
if (id !== null) storedById.set(id, row);
|
|
6846
7050
|
}
|
|
6847
7051
|
const kept = /* @__PURE__ */ new Set();
|
|
@@ -6851,13 +7055,13 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
6851
7055
|
rows.push(row);
|
|
6852
7056
|
continue;
|
|
6853
7057
|
}
|
|
6854
|
-
const id = rowId(row, node.idKey) ?? ctx.mintId();
|
|
7058
|
+
const id = rowId$1(row, node.idKey) ?? ctx.mintId();
|
|
6855
7059
|
kept.add(id);
|
|
6856
7060
|
const withId = {
|
|
6857
7061
|
...row,
|
|
6858
7062
|
[node.idKey]: row[node.idKey] ?? id
|
|
6859
7063
|
};
|
|
6860
|
-
if (rowId(withId, node.idKey) === null) withId[node.idKey] = id;
|
|
7064
|
+
if (rowId$1(withId, node.idKey) === null) withId[node.idKey] = id;
|
|
6861
7065
|
const storedRow = storedById.get(id) ?? {};
|
|
6862
7066
|
rows.push(await writeMembers(ctx, node.item, withId, storedRow, (member) => arrayItemFieldPath(fieldPath, id, member)));
|
|
6863
7067
|
}
|
|
@@ -7609,7 +7813,7 @@ var BaseAddon = class {
|
|
|
7609
7813
|
startMigration: (input) => api.startMigration.mutate(input),
|
|
7610
7814
|
finishMigration: (input) => api.finishMigration.mutate(input)
|
|
7611
7815
|
}, migrations, this.ctx.logger);
|
|
7612
|
-
if (report.blockOwner.length > 0) throw new
|
|
7816
|
+
if (report.blockOwner.length > 0) throw new AddonMigrationsBlockedError(report.blockOwner);
|
|
7613
7817
|
return report;
|
|
7614
7818
|
}
|
|
7615
7819
|
/**
|
|
@@ -7949,6 +8153,10 @@ var BaseAddon = class {
|
|
|
7949
8153
|
const stored = keychain ? await this.readAddonStoreWithRetry() : {};
|
|
7950
8154
|
const patch = {};
|
|
7951
8155
|
for (const key of keys) {
|
|
8156
|
+
if (tree.get(key)?.kind === "array") {
|
|
8157
|
+
patch[key] = [];
|
|
8158
|
+
continue;
|
|
8159
|
+
}
|
|
7952
8160
|
const keychainStored = tree.has(key) || collectSecretMarkerRefs(stored[key]).length > 0;
|
|
7953
8161
|
patch[key] = keychain && keychainStored ? SECRET_CLEAR : "";
|
|
7954
8162
|
}
|
|
@@ -8588,6 +8796,45 @@ function normalizeAddonInitResult(result) {
|
|
|
8588
8796
|
if (Array.isArray(result)) return { providers: result };
|
|
8589
8797
|
return result;
|
|
8590
8798
|
}
|
|
8799
|
+
var PREFIX$1 = "records/";
|
|
8800
|
+
/** The base of every records failure. `detail` is the human part of the message. */
|
|
8801
|
+
var RecordsError = class extends Error {
|
|
8802
|
+
code;
|
|
8803
|
+
detail;
|
|
8804
|
+
constructor(code, detail) {
|
|
8805
|
+
super(`${PREFIX$1}${code}: ${detail}`);
|
|
8806
|
+
this.name = "RecordsError";
|
|
8807
|
+
this.code = code;
|
|
8808
|
+
this.detail = detail;
|
|
8809
|
+
}
|
|
8810
|
+
};
|
|
8811
|
+
/** A write guarded by `ifRev` found another revision (or an existing row for `ifRev: 0`). */
|
|
8812
|
+
var RevConflictError = class extends RecordsError {
|
|
8813
|
+
constructor(detail) {
|
|
8814
|
+
super("rev-conflict", detail);
|
|
8815
|
+
this.name = "RevConflictError";
|
|
8816
|
+
}
|
|
8817
|
+
};
|
|
8818
|
+
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
8819
|
+
var RecordSecretUnavailableError = class extends RecordsError {
|
|
8820
|
+
constructor(detail) {
|
|
8821
|
+
super("secret-unavailable", detail);
|
|
8822
|
+
this.name = "RecordSecretUnavailableError";
|
|
8823
|
+
}
|
|
8824
|
+
};
|
|
8825
|
+
var InvalidRecordError = class extends RecordsError {
|
|
8826
|
+
constructor(detail) {
|
|
8827
|
+
super("invalid-record", detail);
|
|
8828
|
+
this.name = "InvalidRecordError";
|
|
8829
|
+
}
|
|
8830
|
+
};
|
|
8831
|
+
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
8832
|
+
var DeclarationRefusedError = class extends RecordsError {
|
|
8833
|
+
constructor(detail) {
|
|
8834
|
+
super("declaration-refused", detail);
|
|
8835
|
+
this.name = "DeclarationRefusedError";
|
|
8836
|
+
}
|
|
8837
|
+
};
|
|
8591
8838
|
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
8592
8839
|
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
8593
8840
|
var RECORD_DATABASES = ["settings", "events"];
|
|
@@ -8603,6 +8850,152 @@ var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
|
8603
8850
|
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
8604
8851
|
var RECORD_BATCH_MAX = 1e3;
|
|
8605
8852
|
var RECORD_QUERY_MAX = 1e3;
|
|
8853
|
+
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
8854
|
+
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
8855
|
+
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
8856
|
+
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
8857
|
+
/**
|
|
8858
|
+
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
8859
|
+
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
8860
|
+
* (`auth.accessToken`, `headers[].value`).
|
|
8861
|
+
*
|
|
8862
|
+
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
8863
|
+
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
8864
|
+
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
8865
|
+
* leaf names its element: `headers[X-Api].value`.
|
|
8866
|
+
*
|
|
8867
|
+
* Pure and browser-safe. Nothing here mutates: every transform returns a new value.
|
|
8868
|
+
*/
|
|
8869
|
+
/** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
|
|
8870
|
+
function parseSecretPath(path) {
|
|
8871
|
+
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
8872
|
+
return path.split(".").map((raw) => {
|
|
8873
|
+
const each = raw.endsWith("[]");
|
|
8874
|
+
const key = each ? raw.slice(0, -2) : raw;
|
|
8875
|
+
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
8876
|
+
return {
|
|
8877
|
+
key,
|
|
8878
|
+
each
|
|
8879
|
+
};
|
|
8880
|
+
});
|
|
8881
|
+
}
|
|
8882
|
+
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
8883
|
+
function secretArrayPrefixes(path) {
|
|
8884
|
+
const segments = parseSecretPath(path);
|
|
8885
|
+
const prefixes = [];
|
|
8886
|
+
const walked = [];
|
|
8887
|
+
for (const segment of segments) {
|
|
8888
|
+
walked.push(segment.key);
|
|
8889
|
+
if (segment.each) prefixes.push(walked.join("."));
|
|
8890
|
+
}
|
|
8891
|
+
return prefixes;
|
|
8892
|
+
}
|
|
8893
|
+
function isRecord$4(value) {
|
|
8894
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8895
|
+
}
|
|
8896
|
+
function elementId(element, idKey, declared, prefix) {
|
|
8897
|
+
const id = isRecord$4(element) ? element[idKey] : void 0;
|
|
8898
|
+
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`);
|
|
8899
|
+
return id;
|
|
8900
|
+
}
|
|
8901
|
+
/**
|
|
8902
|
+
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
8903
|
+
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
8904
|
+
* result is a new body, `data` is untouched.
|
|
8905
|
+
*/
|
|
8906
|
+
var REMOVE_LEAF = Symbol("remove-leaf");
|
|
8907
|
+
function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
|
|
8908
|
+
if (!isRecord$4(node)) return node;
|
|
8909
|
+
const segment = segments[index];
|
|
8910
|
+
if (segment === void 0) return node;
|
|
8911
|
+
if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
|
|
8912
|
+
const child = node[segment.key];
|
|
8913
|
+
const keys = [...walkedKeys, segment.key];
|
|
8914
|
+
const last = index === segments.length - 1;
|
|
8915
|
+
if (segment.each) {
|
|
8916
|
+
if (!Array.isArray(child)) return node;
|
|
8917
|
+
const prefix = keys.join(".");
|
|
8918
|
+
const idKey = arrayKeys[prefix];
|
|
8919
|
+
if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
|
|
8920
|
+
const mapped = child.map((element) => {
|
|
8921
|
+
const id = elementId(element, idKey, declared, prefix);
|
|
8922
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
|
|
8923
|
+
return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
|
|
8924
|
+
});
|
|
8925
|
+
return {
|
|
8926
|
+
...node,
|
|
8927
|
+
[segment.key]: mapped
|
|
8928
|
+
};
|
|
8929
|
+
}
|
|
8930
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
8931
|
+
if (last) {
|
|
8932
|
+
const replacement = visit({
|
|
8933
|
+
declared,
|
|
8934
|
+
concrete,
|
|
8935
|
+
value: child
|
|
8936
|
+
});
|
|
8937
|
+
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
8938
|
+
return {
|
|
8939
|
+
...node,
|
|
8940
|
+
[segment.key]: replacement
|
|
8941
|
+
};
|
|
8942
|
+
}
|
|
8943
|
+
return {
|
|
8944
|
+
...node,
|
|
8945
|
+
[segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
|
|
8946
|
+
};
|
|
8947
|
+
}
|
|
8948
|
+
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
8949
|
+
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
8950
|
+
let current = data;
|
|
8951
|
+
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
8952
|
+
return current;
|
|
8953
|
+
}
|
|
8954
|
+
/**
|
|
8955
|
+
* The keychain collection name a kind's secrets live under. Prefixed so a
|
|
8956
|
+
* record's refs never collide with the refs a legacy collection of the same name
|
|
8957
|
+
* already holds during an adoption.
|
|
8958
|
+
*/
|
|
8959
|
+
function recordSecretCollection(kind) {
|
|
8960
|
+
return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
|
|
8961
|
+
}
|
|
8962
|
+
/** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
|
|
8963
|
+
function recordSecretRef(owner, kind, rowId, concretePath) {
|
|
8964
|
+
return buildSecretRef({
|
|
8965
|
+
owner,
|
|
8966
|
+
scope: {
|
|
8967
|
+
kind: "row",
|
|
8968
|
+
collection: recordSecretCollection(kind),
|
|
8969
|
+
rowId
|
|
8970
|
+
},
|
|
8971
|
+
fieldPath: concretePath
|
|
8972
|
+
});
|
|
8973
|
+
}
|
|
8974
|
+
/**
|
|
8975
|
+
* A stored secret, as an admin read shows it: a VIEW naming the row's own
|
|
8976
|
+
* keychain ref (`set: true`), never the value and no longer the bare redaction
|
|
8977
|
+
* token. The form hands it to the secret field, which reveals the value by ref
|
|
8978
|
+
* through the audited `keychain-admin.reveal`; sent back untouched it keeps the
|
|
8979
|
+
* stored secret (the records door reads a view as KEEP).
|
|
8980
|
+
*
|
|
8981
|
+
* ONE implementation for the entries service and for every addon that serves
|
|
8982
|
+
* its own instances (`RecordIntegrationInstances`).
|
|
8983
|
+
*/
|
|
8984
|
+
function isRecord$3(value) {
|
|
8985
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8986
|
+
}
|
|
8987
|
+
function secretViewsOf(owner, kind, id, decl, data) {
|
|
8988
|
+
if (decl.secretPaths.length === 0) return data;
|
|
8989
|
+
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
8990
|
+
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
8991
|
+
return {
|
|
8992
|
+
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
8993
|
+
v: 1,
|
|
8994
|
+
set: true
|
|
8995
|
+
};
|
|
8996
|
+
});
|
|
8997
|
+
return isRecord$3(shown) ? shown : data;
|
|
8998
|
+
}
|
|
8606
8999
|
/**
|
|
8607
9000
|
* The share-view scope kinds a share-link token can carry. The hub mints
|
|
8608
9001
|
* and validates them (`ShareViewGrantSchema` builds its
|
|
@@ -8627,6 +9020,73 @@ var PeerBytesTicketSchema = object({
|
|
|
8627
9020
|
*/
|
|
8628
9021
|
declaredBytes: number().int().nonnegative().nullable()
|
|
8629
9022
|
});
|
|
9023
|
+
function defOf(schema) {
|
|
9024
|
+
const zodBag = Reflect.get(schema, "_zod");
|
|
9025
|
+
if (typeof zodBag !== "object" || zodBag === null) return {};
|
|
9026
|
+
const def = Reflect.get(zodBag, "def");
|
|
9027
|
+
if (typeof def !== "object" || def === null) return {};
|
|
9028
|
+
return def;
|
|
9029
|
+
}
|
|
9030
|
+
function declaredHere(schema) {
|
|
9031
|
+
return globalRegistry.get(schema)?.secret === true;
|
|
9032
|
+
}
|
|
9033
|
+
/** Wrapper kinds whose `innerType` is the field itself. */
|
|
9034
|
+
var WRAPPERS = new Set([
|
|
9035
|
+
"optional",
|
|
9036
|
+
"nullable",
|
|
9037
|
+
"default",
|
|
9038
|
+
"prefault",
|
|
9039
|
+
"catch",
|
|
9040
|
+
"readonly",
|
|
9041
|
+
"nonoptional"
|
|
9042
|
+
]);
|
|
9043
|
+
/**
|
|
9044
|
+
* The schema layers that make up ONE field: the schema itself and every
|
|
9045
|
+
* wrapper below it (optional / default / nullable / readonly / catch), plus
|
|
9046
|
+
* both sides of a pipe (`z.preprocess` puts the real schema on `out`,
|
|
9047
|
+
* `.transform` on `in`).
|
|
9048
|
+
*/
|
|
9049
|
+
function layersOf(schema) {
|
|
9050
|
+
const out = [];
|
|
9051
|
+
const queue = [schema];
|
|
9052
|
+
while (queue.length > 0) {
|
|
9053
|
+
const s = queue.shift();
|
|
9054
|
+
if (!s || out.includes(s)) continue;
|
|
9055
|
+
out.push(s);
|
|
9056
|
+
const def = defOf(s);
|
|
9057
|
+
if (def.type !== void 0 && WRAPPERS.has(def.type) && def.innerType) queue.push(def.innerType);
|
|
9058
|
+
if (def.type === "pipe") {
|
|
9059
|
+
if (def.in) queue.push(def.in);
|
|
9060
|
+
if (def.out) queue.push(def.out);
|
|
9061
|
+
}
|
|
9062
|
+
}
|
|
9063
|
+
return out;
|
|
9064
|
+
}
|
|
9065
|
+
/** True when any layer of this field declares `.meta({ secret: true })`. */
|
|
9066
|
+
function isZodSecret(schema) {
|
|
9067
|
+
return layersOf(schema).some(declaredHere);
|
|
9068
|
+
}
|
|
9069
|
+
/**
|
|
9070
|
+
* Every declared secret path in a config schema: dotted keys, `[]` for "each
|
|
9071
|
+
* element of this array" (`connection.password`, `rows[].token`). A declared
|
|
9072
|
+
* object or array is reported as one path and not descended into — everything
|
|
9073
|
+
* under it is secret.
|
|
9074
|
+
*/
|
|
9075
|
+
function collectZodSecretPaths(schema, prefix = "") {
|
|
9076
|
+
if (isZodSecret(schema)) return prefix.length > 0 ? [prefix] : [];
|
|
9077
|
+
const paths = [];
|
|
9078
|
+
for (const layer of layersOf(schema)) {
|
|
9079
|
+
const def = defOf(layer);
|
|
9080
|
+
if (def.type === "object" && def.shape) for (const [key, child] of Object.entries(def.shape)) paths.push(...collectZodSecretPaths(child, prefix ? `${prefix}.${key}` : key));
|
|
9081
|
+
else if (def.type === "array" && def.element) paths.push(...collectZodSecretPaths(def.element, `${prefix}[]`));
|
|
9082
|
+
else if (def.type === "union" && def.options) for (const option of def.options) paths.push(...collectZodSecretPaths(option, prefix));
|
|
9083
|
+
else if (def.type === "intersection") {
|
|
9084
|
+
if (def.left) paths.push(...collectZodSecretPaths(def.left, prefix));
|
|
9085
|
+
if (def.right) paths.push(...collectZodSecretPaths(def.right, prefix));
|
|
9086
|
+
}
|
|
9087
|
+
}
|
|
9088
|
+
return [...new Set(paths)];
|
|
9089
|
+
}
|
|
8630
9090
|
/**
|
|
8631
9091
|
* Record kinds (D881): the declaration an addon makes of one kind of fact, the
|
|
8632
9092
|
* Zod row schema that describes it, and the helper that turns the two into the
|
|
@@ -8693,6 +9153,110 @@ var RecordKindDeclarationSchema = object({
|
|
|
8693
9153
|
}).strict();
|
|
8694
9154
|
/** The kind names: lower-case, dash separated, short enough for an index name. */
|
|
8695
9155
|
var RecordKindNameSchema = string().regex(/^[a-z][a-z0-9-]{0,47}$/);
|
|
9156
|
+
/** Cross-field rules a declaration must satisfy. Throws {@link DeclarationRefusedError}. */
|
|
9157
|
+
function assertValidDeclaration(name, decl) {
|
|
9158
|
+
const refuse = (why) => {
|
|
9159
|
+
throw new DeclarationRefusedError(`kind "${name}": ${why}`);
|
|
9160
|
+
};
|
|
9161
|
+
if (!RecordKindNameSchema.safeParse(name).success) refuse("the name must be lower-case-dashed");
|
|
9162
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9163
|
+
for (const index of decl.indexes) {
|
|
9164
|
+
if (seen.has(index.name)) refuse(`index name "${index.name}" is declared twice`);
|
|
9165
|
+
seen.add(index.name);
|
|
9166
|
+
}
|
|
9167
|
+
const { retention } = decl;
|
|
9168
|
+
const hasSecrets = decl.secretPaths.length > 0;
|
|
9169
|
+
if ("ttlMs" in retention) {
|
|
9170
|
+
if (retention.from === "at" && decl.at !== "required") refuse("a ttl from \"at\" needs at: \"required\"");
|
|
9171
|
+
if (hasSecrets) refuse("a kind with secret fields cannot use engine TTL (its keychain values would be orphaned)");
|
|
9172
|
+
}
|
|
9173
|
+
if ("maxRows" in retention || "maxRowsPerDevice" in retention) {
|
|
9174
|
+
if (retention.maxRowsPerDevice !== void 0 && decl.device !== "required") refuse("maxRowsPerDevice needs device: \"required\"");
|
|
9175
|
+
if (decl.at !== "required") refuse("a row bound trims the oldest \"at\": it needs at: \"required\"");
|
|
9176
|
+
if (hasSecrets) refuse("a kind with secret fields cannot use an engine row bound");
|
|
9177
|
+
const bound = Math.max(retention.maxRows ?? 0, retention.maxRowsPerDevice ?? 0);
|
|
9178
|
+
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)`);
|
|
9179
|
+
}
|
|
9180
|
+
if (decl.deviceRemoval === "delete" && decl.device === "none") refuse("deviceRemoval: \"delete\" needs a device: \"required\" or \"optional\"");
|
|
9181
|
+
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`);
|
|
9182
|
+
}
|
|
9183
|
+
function bodyFieldsOf(schema) {
|
|
9184
|
+
return { ...toJSONSchema(schema, {
|
|
9185
|
+
unrepresentable: "any",
|
|
9186
|
+
io: "input"
|
|
9187
|
+
}) };
|
|
9188
|
+
}
|
|
9189
|
+
function isRecordLike(value) {
|
|
9190
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9191
|
+
}
|
|
9192
|
+
/** Does every branch of the body schema carry `field`? (A discriminated union has several.) */
|
|
9193
|
+
function hasNameField(json, field) {
|
|
9194
|
+
const branches = json["oneOf"] ?? json["anyOf"];
|
|
9195
|
+
if (Array.isArray(branches)) return branches.length > 0 && branches.every((b) => isRecordLike(b) && hasNameField(b, field));
|
|
9196
|
+
const properties = json["properties"];
|
|
9197
|
+
return isRecordLike(properties) && Object.prototype.hasOwnProperty.call(properties, field);
|
|
9198
|
+
}
|
|
9199
|
+
/**
|
|
9200
|
+
* Declare the kinds of a package. The keys are the kind names. The result is
|
|
9201
|
+
* what `ctx.records.declare` sends to the engine and what `ctx.records.kind`
|
|
9202
|
+
* types its handle from.
|
|
9203
|
+
*/
|
|
9204
|
+
function defineRecordKinds(specs) {
|
|
9205
|
+
const out = {};
|
|
9206
|
+
for (const [name, spec] of Object.entries(specs)) {
|
|
9207
|
+
const secretPaths = collectZodSecretPaths(spec.schema);
|
|
9208
|
+
const nameField = spec.entry?.nameField ?? "name";
|
|
9209
|
+
const fields = bodyFieldsOf(spec.schema);
|
|
9210
|
+
if (spec.entry !== void 0 && !hasNameField(fields, nameField)) throw new DeclarationRefusedError(`kind "${name}": an entry kind's schema needs a "${nameField}" field`);
|
|
9211
|
+
const parsed = RecordKindDeclarationSchema.parse({
|
|
9212
|
+
database: spec.database,
|
|
9213
|
+
class: spec.class,
|
|
9214
|
+
writeTrigger: spec.writeTrigger,
|
|
9215
|
+
device: spec.device,
|
|
9216
|
+
at: spec.at,
|
|
9217
|
+
indexes: spec.indexes === void 0 ? void 0 : [...spec.indexes],
|
|
9218
|
+
retention: spec.retention,
|
|
9219
|
+
deviceRemoval: spec.deviceRemoval,
|
|
9220
|
+
maxDataBytes: spec.maxDataBytes,
|
|
9221
|
+
secretPaths: [...secretPaths],
|
|
9222
|
+
secretArrayKeys: spec.secretArrayKeys === void 0 ? void 0 : { ...spec.secretArrayKeys },
|
|
9223
|
+
transactFamily: spec.transactFamily,
|
|
9224
|
+
entry: spec.entry === void 0 ? void 0 : {
|
|
9225
|
+
title: spec.entry.title,
|
|
9226
|
+
nameField,
|
|
9227
|
+
fields
|
|
9228
|
+
}
|
|
9229
|
+
});
|
|
9230
|
+
assertValidDeclaration(name, parsed);
|
|
9231
|
+
out[name] = {
|
|
9232
|
+
name,
|
|
9233
|
+
schema: spec.schema,
|
|
9234
|
+
declaration: parsed
|
|
9235
|
+
};
|
|
9236
|
+
}
|
|
9237
|
+
return out;
|
|
9238
|
+
}
|
|
9239
|
+
/**
|
|
9240
|
+
* Declare one entry kind. An entry is configuration: never trimmed by the
|
|
9241
|
+
* engine, never aged, belonging to no device.
|
|
9242
|
+
*/
|
|
9243
|
+
function defineEntryKind(name, spec) {
|
|
9244
|
+
const defined = defineRecordKinds({ [name]: {
|
|
9245
|
+
schema: spec.schema,
|
|
9246
|
+
class: "config",
|
|
9247
|
+
writeTrigger: spec.writeTrigger ?? "an operator adds or edits an entry in the entries UI",
|
|
9248
|
+
retention: { none: "an entry goes only when the operator deletes it" },
|
|
9249
|
+
...spec.database === void 0 ? {} : { database: spec.database },
|
|
9250
|
+
...spec.indexes === void 0 ? {} : { indexes: spec.indexes },
|
|
9251
|
+
...spec.secretArrayKeys === void 0 ? {} : { secretArrayKeys: spec.secretArrayKeys },
|
|
9252
|
+
entry: {
|
|
9253
|
+
title: spec.title,
|
|
9254
|
+
...spec.nameField === void 0 ? {} : { nameField: spec.nameField }
|
|
9255
|
+
}
|
|
9256
|
+
} })[name];
|
|
9257
|
+
if (defined === void 0) throw new DeclarationRefusedError(`entry kind "${name}" was not built`);
|
|
9258
|
+
return defined;
|
|
9259
|
+
}
|
|
8696
9260
|
object({
|
|
8697
9261
|
field: string().min(1),
|
|
8698
9262
|
on: literal("advance")
|
|
@@ -11368,7 +11932,7 @@ object({
|
|
|
11368
11932
|
params: record(string(), union([string(), number()])).optional()
|
|
11369
11933
|
});
|
|
11370
11934
|
//#endregion
|
|
11371
|
-
//#region ../types/dist/composition-
|
|
11935
|
+
//#region ../types/dist/composition-BodkvOV0.mjs
|
|
11372
11936
|
/**
|
|
11373
11937
|
* The ffmpeg build every CamStack node downloads, per platform and arch.
|
|
11374
11938
|
*
|
|
@@ -12505,7 +13069,14 @@ var CompositionForwardCommandSchema = object({
|
|
|
12505
13069
|
method: string().min(1),
|
|
12506
13070
|
args: record(string().min(1), CompositionForwardArgSchema).optional()
|
|
12507
13071
|
});
|
|
12508
|
-
var CompositionCommandTargetSchema = discriminatedUnion("kind", [
|
|
13072
|
+
var CompositionCommandTargetSchema = discriminatedUnion("kind", [
|
|
13073
|
+
CompositionForwardCommandSchema,
|
|
13074
|
+
CompositionCodeSourceSchema,
|
|
13075
|
+
object({
|
|
13076
|
+
kind: literal("extension"),
|
|
13077
|
+
target: literal("remote")
|
|
13078
|
+
})
|
|
13079
|
+
]);
|
|
12509
13080
|
/** An item key inside an item-array cap (`consumables.items[<key>]`). */
|
|
12510
13081
|
var COMPOSITION_ITEM_KEY_RE = /^[a-z0-9][a-z0-9-]{0,47}$/;
|
|
12511
13082
|
/**
|
|
@@ -12885,6 +13456,144 @@ function buildCapturingReply(envelope) {
|
|
|
12885
13456
|
};
|
|
12886
13457
|
return wrapper;
|
|
12887
13458
|
}
|
|
13459
|
+
/** The most instances one addon lists (an integrations page, not a table). */
|
|
13460
|
+
var INSTANCES_LIST_MAX = 1e3;
|
|
13461
|
+
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
13462
|
+
function topLevelSecretKeys(paths) {
|
|
13463
|
+
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[")));
|
|
13464
|
+
}
|
|
13465
|
+
var RecordIntegrationInstances = class {
|
|
13466
|
+
records;
|
|
13467
|
+
kind;
|
|
13468
|
+
hooks;
|
|
13469
|
+
handle;
|
|
13470
|
+
secretKeys;
|
|
13471
|
+
nameField;
|
|
13472
|
+
constructor(records, kind, hooks) {
|
|
13473
|
+
this.records = records;
|
|
13474
|
+
this.kind = kind;
|
|
13475
|
+
this.hooks = hooks;
|
|
13476
|
+
this.handle = records.kind(kind);
|
|
13477
|
+
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
13478
|
+
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
13479
|
+
}
|
|
13480
|
+
/**
|
|
13481
|
+
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
13482
|
+
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
13483
|
+
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
13484
|
+
*/
|
|
13485
|
+
async readResolved(id) {
|
|
13486
|
+
try {
|
|
13487
|
+
const record = await this.handle.getResolved(id);
|
|
13488
|
+
return record === null ? null : {
|
|
13489
|
+
id,
|
|
13490
|
+
body: record.data,
|
|
13491
|
+
enabled: record.data.enabled !== false,
|
|
13492
|
+
secrets: "resolved"
|
|
13493
|
+
};
|
|
13494
|
+
} catch (err) {
|
|
13495
|
+
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
13496
|
+
const stored = await this.handle.get(id);
|
|
13497
|
+
if (stored === null) return null;
|
|
13498
|
+
return {
|
|
13499
|
+
id,
|
|
13500
|
+
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
13501
|
+
enabled: stored.data.enabled !== false,
|
|
13502
|
+
secrets: "unavailable"
|
|
13503
|
+
};
|
|
13504
|
+
}
|
|
13505
|
+
}
|
|
13506
|
+
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
13507
|
+
async getResolved(id) {
|
|
13508
|
+
return (await this.readResolved(id))?.body ?? null;
|
|
13509
|
+
}
|
|
13510
|
+
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
13511
|
+
async listResolved() {
|
|
13512
|
+
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
13513
|
+
const out = [];
|
|
13514
|
+
for (const record of page.records) {
|
|
13515
|
+
const read = await this.readResolved(record.id);
|
|
13516
|
+
if (read !== null) out.push(read);
|
|
13517
|
+
}
|
|
13518
|
+
return out;
|
|
13519
|
+
}
|
|
13520
|
+
viewOf(record) {
|
|
13521
|
+
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
13522
|
+
const rawName = record.data[this.nameField];
|
|
13523
|
+
return {
|
|
13524
|
+
id: record.id,
|
|
13525
|
+
name: typeof rawName === "string" ? rawName : record.id,
|
|
13526
|
+
configured: this.hooks.configured(record.data),
|
|
13527
|
+
enabled: record.data.enabled !== false,
|
|
13528
|
+
formValues: shown
|
|
13529
|
+
};
|
|
13530
|
+
}
|
|
13531
|
+
describe = async () => this.hooks.description;
|
|
13532
|
+
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
13533
|
+
listInstances = async () => {
|
|
13534
|
+
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
13535
|
+
};
|
|
13536
|
+
getInstance = async ({ id }) => {
|
|
13537
|
+
const record = await this.handle.get(id);
|
|
13538
|
+
return record === null ? null : this.viewOf(record);
|
|
13539
|
+
};
|
|
13540
|
+
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
13541
|
+
createInstance = async ({ id, name }) => {
|
|
13542
|
+
await this.handle.put({
|
|
13543
|
+
id,
|
|
13544
|
+
data: this.hooks.initialBody(name)
|
|
13545
|
+
}, { ifRev: 0 });
|
|
13546
|
+
await this.hooks.onChanged?.(id);
|
|
13547
|
+
return { id };
|
|
13548
|
+
};
|
|
13549
|
+
updateInstance = async ({ id, name, values }) => {
|
|
13550
|
+
const patch = {};
|
|
13551
|
+
for (const [key, value] of Object.entries(values)) {
|
|
13552
|
+
if (value === void 0) continue;
|
|
13553
|
+
if (!this.secretKeys.has(key)) patch[key] = value;
|
|
13554
|
+
else if (isSecretClear(value)) patch[key] = null;
|
|
13555
|
+
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
13556
|
+
}
|
|
13557
|
+
if (name !== void 0) patch[this.nameField] = name;
|
|
13558
|
+
await this.handle.patch(id, patch);
|
|
13559
|
+
await this.hooks.onChanged?.(id);
|
|
13560
|
+
return { ok: true };
|
|
13561
|
+
};
|
|
13562
|
+
/** The switch lives in the record body; the addon is told so it applies it (D996). */
|
|
13563
|
+
setInstanceEnabled = async ({ id, enabled }) => {
|
|
13564
|
+
await this.handle.patch(id, { enabled });
|
|
13565
|
+
await this.hooks.onChanged?.(id);
|
|
13566
|
+
return { ok: true };
|
|
13567
|
+
};
|
|
13568
|
+
/** The row and its keychain refs go together (the records door). */
|
|
13569
|
+
deleteInstance = async ({ id }) => {
|
|
13570
|
+
await this.handle.delete(id);
|
|
13571
|
+
await this.hooks.onChanged?.(id);
|
|
13572
|
+
return { ok: true };
|
|
13573
|
+
};
|
|
13574
|
+
testInstance = async (input) => {
|
|
13575
|
+
if (this.hooks.test === void 0) return {
|
|
13576
|
+
success: false,
|
|
13577
|
+
status: "unsupported",
|
|
13578
|
+
error: "This integration declares no connection test"
|
|
13579
|
+
};
|
|
13580
|
+
return this.hooks.test(input);
|
|
13581
|
+
};
|
|
13582
|
+
/** The flat provider object to hand to `registerProvider`. */
|
|
13583
|
+
toProvider() {
|
|
13584
|
+
return {
|
|
13585
|
+
describe: this.describe,
|
|
13586
|
+
instanceFormSchema: this.instanceFormSchema,
|
|
13587
|
+
listInstances: this.listInstances,
|
|
13588
|
+
getInstance: this.getInstance,
|
|
13589
|
+
createInstance: this.createInstance,
|
|
13590
|
+
updateInstance: this.updateInstance,
|
|
13591
|
+
setInstanceEnabled: this.setInstanceEnabled,
|
|
13592
|
+
deleteInstance: this.deleteInstance,
|
|
13593
|
+
testInstance: this.testInstance
|
|
13594
|
+
};
|
|
13595
|
+
}
|
|
13596
|
+
};
|
|
12888
13597
|
var EncodeProfileSchema = object({
|
|
12889
13598
|
video: object({
|
|
12890
13599
|
codec: _enum([
|
|
@@ -19309,6 +20018,48 @@ var APPLIANCE_CAP_VOCABULARY = {
|
|
|
19309
20018
|
scope: "device",
|
|
19310
20019
|
noun: t("Media player", "Lettore multimediale"),
|
|
19311
20020
|
actions: [
|
|
20021
|
+
{
|
|
20022
|
+
id: "media.turnOn",
|
|
20023
|
+
method: "turnOn",
|
|
20024
|
+
label: t("Turn on", "Accendi"),
|
|
20025
|
+
phrase: t("Turn on {device}", "Accendi {device}"),
|
|
20026
|
+
icon: "power"
|
|
20027
|
+
},
|
|
20028
|
+
{
|
|
20029
|
+
id: "media.turnOff",
|
|
20030
|
+
method: "turnOff",
|
|
20031
|
+
label: t("Turn off", "Spegni"),
|
|
20032
|
+
phrase: t("Turn off {device}", "Spegni {device}"),
|
|
20033
|
+
icon: "power"
|
|
20034
|
+
},
|
|
20035
|
+
{
|
|
20036
|
+
id: "media.volumeUp",
|
|
20037
|
+
method: "volumeUp",
|
|
20038
|
+
label: t("Volume up", "Alza il volume"),
|
|
20039
|
+
phrase: t("Raise the volume of {device}", "Alza il volume di {device}"),
|
|
20040
|
+
icon: "volume-2"
|
|
20041
|
+
},
|
|
20042
|
+
{
|
|
20043
|
+
id: "media.volumeDown",
|
|
20044
|
+
method: "volumeDown",
|
|
20045
|
+
label: t("Volume down", "Abbassa il volume"),
|
|
20046
|
+
phrase: t("Lower the volume of {device}", "Abbassa il volume di {device}"),
|
|
20047
|
+
icon: "volume-2"
|
|
20048
|
+
},
|
|
20049
|
+
{
|
|
20050
|
+
id: "media.channelUp",
|
|
20051
|
+
method: "channelUp",
|
|
20052
|
+
label: t("Channel up", "Canale successivo"),
|
|
20053
|
+
phrase: t("Go to the next channel on {device}", "Passa al canale successivo su {device}"),
|
|
20054
|
+
icon: "skip-forward"
|
|
20055
|
+
},
|
|
20056
|
+
{
|
|
20057
|
+
id: "media.channelDown",
|
|
20058
|
+
method: "channelDown",
|
|
20059
|
+
label: t("Channel down", "Canale precedente"),
|
|
20060
|
+
phrase: t("Go to the previous channel on {device}", "Torna al canale precedente su {device}"),
|
|
20061
|
+
icon: "skip-back"
|
|
20062
|
+
},
|
|
19312
20063
|
{
|
|
19313
20064
|
id: "media.play",
|
|
19314
20065
|
method: "play",
|
|
@@ -47885,6 +48636,188 @@ DeviceType.Control, method(object({
|
|
|
47885
48636
|
kind: "mutation",
|
|
47886
48637
|
auth: "protected"
|
|
47887
48638
|
});
|
|
48639
|
+
/**
|
|
48640
|
+
* Media-player cap. Models HA `media_player.*` (Sonos, Chromecast,
|
|
48641
|
+
* Apple TV, Spotify, Roku, generic OTT receivers, …) on
|
|
48642
|
+
* `DeviceType.MediaPlayer`. Disjoint from the camera streaming
|
|
48643
|
+
* surface — those use `DeviceType.Camera` + the broker pipeline.
|
|
48644
|
+
*
|
|
48645
|
+
* The cap declares a wide method surface; not every backend supports
|
|
48646
|
+
* every method. Drivers signal sub-capability via the
|
|
48647
|
+
* `DeviceFeature.MediaPlayerXxx` flags (paired one-to-one with the
|
|
48648
|
+
* corresponding method) so the UI gates buttons without a slice
|
|
48649
|
+
* fetch — same pattern as `PanTiltZoom` for cameras.
|
|
48650
|
+
*/
|
|
48651
|
+
var MediaPlayerStateSchema = _enum([
|
|
48652
|
+
"off",
|
|
48653
|
+
"on",
|
|
48654
|
+
"idle",
|
|
48655
|
+
"playing",
|
|
48656
|
+
"paused",
|
|
48657
|
+
"buffering",
|
|
48658
|
+
"standby"
|
|
48659
|
+
]);
|
|
48660
|
+
var MediaPlayerRepeatSchema = _enum([
|
|
48661
|
+
"off",
|
|
48662
|
+
"all",
|
|
48663
|
+
"one"
|
|
48664
|
+
]);
|
|
48665
|
+
var MediaInfoSchema = object({
|
|
48666
|
+
/** Free-form media kind (`music`, `tvshow`, `movie`, `app`, `channel`,
|
|
48667
|
+
* `podcast`, …). */
|
|
48668
|
+
type: string(),
|
|
48669
|
+
/** Human-readable title. */
|
|
48670
|
+
title: string(),
|
|
48671
|
+
/** Optional artist / channel / station label. */
|
|
48672
|
+
artist: string().optional(),
|
|
48673
|
+
/** Optional album / season / show name. */
|
|
48674
|
+
album: string().optional(),
|
|
48675
|
+
/** Optional cover-art / thumbnail URL. */
|
|
48676
|
+
imageUrl: string().optional()
|
|
48677
|
+
});
|
|
48678
|
+
/**
|
|
48679
|
+
* Where `state`, `volumeLevel`, `isMuted` and `source` come from. `reported`:
|
|
48680
|
+
* the device said so. `assumed`: the driver has no feedback (infrared) and
|
|
48681
|
+
* tracks what it last SENT; it moves only after a send was accepted, and a
|
|
48682
|
+
* human at the real remote makes it wrong. A UI shows an assumed value as a
|
|
48683
|
+
* guess, never as a reading.
|
|
48684
|
+
*/
|
|
48685
|
+
var MediaPlayerStateSourceSchema = _enum(["reported", "assumed"]);
|
|
48686
|
+
/** The fields of a media-player status a driver can only guess. */
|
|
48687
|
+
var MediaPlayerAssumedFieldSchema = _enum([
|
|
48688
|
+
"state",
|
|
48689
|
+
"volumeLevel",
|
|
48690
|
+
"isMuted",
|
|
48691
|
+
"source"
|
|
48692
|
+
]);
|
|
48693
|
+
var MediaPlayerStatusSchema = object({
|
|
48694
|
+
/** Playback lifecycle state. */
|
|
48695
|
+
state: MediaPlayerStateSchema,
|
|
48696
|
+
/**
|
|
48697
|
+
* Whether the state fields are readings or the driver's own bookkeeping.
|
|
48698
|
+
* A slice written before this field existed parses as `reported`.
|
|
48699
|
+
*/
|
|
48700
|
+
stateSource: MediaPlayerStateSourceSchema.default("reported"),
|
|
48701
|
+
/**
|
|
48702
|
+
* Which fields are the driver's own guess. `stateSource` is `assumed` when
|
|
48703
|
+
* this is not empty; a field not listed here is a reading even then (power
|
|
48704
|
+
* from a running-state source, mute guessed from the last send).
|
|
48705
|
+
*/
|
|
48706
|
+
assumedFields: array(MediaPlayerAssumedFieldSchema).default([]),
|
|
48707
|
+
/** Volume as 0..100 inclusive. Null when the device has no volume
|
|
48708
|
+
* surface. Pair with `DeviceFeature.MediaPlayerVolume`. */
|
|
48709
|
+
volumeLevel: number().min(0).max(100).nullable().meta(readingMeta("percentage")),
|
|
48710
|
+
/** Mute toggle distinct from volume=0. Null when no mute surface.
|
|
48711
|
+
* Pair with `DeviceFeature.MediaPlayerMute`. */
|
|
48712
|
+
isMuted: boolean().nullable(),
|
|
48713
|
+
/** Active source / input. Empty when no source surface. */
|
|
48714
|
+
source: string(),
|
|
48715
|
+
/** Selectable sources. Empty when no source surface.
|
|
48716
|
+
* Pair with `DeviceFeature.MediaPlayerSelectSource`. */
|
|
48717
|
+
availableSources: array(string()),
|
|
48718
|
+
/** Currently-playing media info. Null when nothing is playing. */
|
|
48719
|
+
currentMedia: MediaInfoSchema.nullable(),
|
|
48720
|
+
/** Current playback position in ms. Null when not seekable or
|
|
48721
|
+
* nothing is playing. Pair with `DeviceFeature.MediaPlayerSeek`. */
|
|
48722
|
+
position: number().int().nonnegative().nullable().meta(readingMeta("duration-ms")),
|
|
48723
|
+
/** Total duration of the current media in ms. Null when unknown
|
|
48724
|
+
* (live stream) or nothing is playing. */
|
|
48725
|
+
duration: number().int().nonnegative().nullable().meta(readingMeta("duration-ms")),
|
|
48726
|
+
/** Shuffle toggle. Null when no shuffle surface.
|
|
48727
|
+
* Pair with `DeviceFeature.MediaPlayerShuffle`. */
|
|
48728
|
+
shuffle: boolean().nullable(),
|
|
48729
|
+
/** Repeat mode. Null when no repeat surface.
|
|
48730
|
+
* Pair with `DeviceFeature.MediaPlayerRepeat`. */
|
|
48731
|
+
repeat: MediaPlayerRepeatSchema.nullable(),
|
|
48732
|
+
/** Ms epoch when the slice was last updated. */
|
|
48733
|
+
lastChangedAt: number()
|
|
48734
|
+
});
|
|
48735
|
+
var stepInput = object({
|
|
48736
|
+
deviceId: number().int().nonnegative(),
|
|
48737
|
+
/** How many presses: the caller's count (Alexa `volumeSteps`, `channelCount`). */
|
|
48738
|
+
steps: number().int().min(1).max(50).default(1)
|
|
48739
|
+
});
|
|
48740
|
+
var deviceOnly = object({ deviceId: number().int().nonnegative() });
|
|
48741
|
+
DeviceType.MediaPlayer, method(deviceOnly, _void(), {
|
|
48742
|
+
kind: "mutation",
|
|
48743
|
+
auth: "protected"
|
|
48744
|
+
}), method(deviceOnly, _void(), {
|
|
48745
|
+
kind: "mutation",
|
|
48746
|
+
auth: "protected"
|
|
48747
|
+
}), method(stepInput, _void(), {
|
|
48748
|
+
kind: "mutation",
|
|
48749
|
+
auth: "protected"
|
|
48750
|
+
}), method(stepInput, _void(), {
|
|
48751
|
+
kind: "mutation",
|
|
48752
|
+
auth: "protected"
|
|
48753
|
+
}), method(stepInput, _void(), {
|
|
48754
|
+
kind: "mutation",
|
|
48755
|
+
auth: "protected"
|
|
48756
|
+
}), method(stepInput, _void(), {
|
|
48757
|
+
kind: "mutation",
|
|
48758
|
+
auth: "protected"
|
|
48759
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
48760
|
+
kind: "mutation",
|
|
48761
|
+
auth: "protected"
|
|
48762
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
48763
|
+
kind: "mutation",
|
|
48764
|
+
auth: "protected"
|
|
48765
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
48766
|
+
kind: "mutation",
|
|
48767
|
+
auth: "protected"
|
|
48768
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
48769
|
+
kind: "mutation",
|
|
48770
|
+
auth: "protected"
|
|
48771
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
48772
|
+
kind: "mutation",
|
|
48773
|
+
auth: "protected"
|
|
48774
|
+
}), method(object({
|
|
48775
|
+
deviceId: number().int().nonnegative(),
|
|
48776
|
+
position: number().int().nonnegative()
|
|
48777
|
+
}), _void(), {
|
|
48778
|
+
kind: "mutation",
|
|
48779
|
+
auth: "protected"
|
|
48780
|
+
}), method(object({
|
|
48781
|
+
deviceId: number().int().nonnegative(),
|
|
48782
|
+
volumeLevel: number().min(0).max(100)
|
|
48783
|
+
}), _void(), {
|
|
48784
|
+
kind: "mutation",
|
|
48785
|
+
auth: "protected"
|
|
48786
|
+
}), method(object({
|
|
48787
|
+
deviceId: number().int().nonnegative(),
|
|
48788
|
+
muted: boolean()
|
|
48789
|
+
}), _void(), {
|
|
48790
|
+
kind: "mutation",
|
|
48791
|
+
auth: "protected"
|
|
48792
|
+
}), method(object({
|
|
48793
|
+
deviceId: number().int().nonnegative(),
|
|
48794
|
+
shuffle: boolean()
|
|
48795
|
+
}), _void(), {
|
|
48796
|
+
kind: "mutation",
|
|
48797
|
+
auth: "protected"
|
|
48798
|
+
}), method(object({
|
|
48799
|
+
deviceId: number().int().nonnegative(),
|
|
48800
|
+
repeat: MediaPlayerRepeatSchema
|
|
48801
|
+
}), _void(), {
|
|
48802
|
+
kind: "mutation",
|
|
48803
|
+
auth: "protected"
|
|
48804
|
+
}), method(object({
|
|
48805
|
+
deviceId: number().int().nonnegative(),
|
|
48806
|
+
source: string().min(1)
|
|
48807
|
+
}), _void(), {
|
|
48808
|
+
kind: "mutation",
|
|
48809
|
+
auth: "protected"
|
|
48810
|
+
}), method(object({
|
|
48811
|
+
deviceId: number().int().nonnegative(),
|
|
48812
|
+
/** Media identifier / URL. */
|
|
48813
|
+
mediaId: string().min(1),
|
|
48814
|
+
/** Media kind (`music`, `tvshow`, `movie`, `app`, …) — provider
|
|
48815
|
+
* passes it through to the upstream service. */
|
|
48816
|
+
mediaType: string().min(1)
|
|
48817
|
+
}), _void(), {
|
|
48818
|
+
kind: "mutation",
|
|
48819
|
+
auth: "protected"
|
|
48820
|
+
});
|
|
47888
48821
|
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;
|
|
47889
48822
|
var NUMBER = {
|
|
47890
48823
|
kind: "fixed",
|
|
@@ -53397,31 +54330,53 @@ var IntegrationInstancePatchSchema = object({
|
|
|
53397
54330
|
/** Omitted / '' / redaction token keeps a secret; `{ $secretClear: true }` clears it. */
|
|
53398
54331
|
values: record(string(), unknown())
|
|
53399
54332
|
});
|
|
53400
|
-
|
|
53401
|
-
|
|
53402
|
-
|
|
53403
|
-
|
|
53404
|
-
|
|
53405
|
-
|
|
53406
|
-
|
|
53407
|
-
|
|
53408
|
-
|
|
53409
|
-
|
|
53410
|
-
|
|
53411
|
-
|
|
53412
|
-
|
|
53413
|
-
|
|
53414
|
-
|
|
53415
|
-
|
|
53416
|
-
|
|
53417
|
-
|
|
53418
|
-
|
|
53419
|
-
|
|
53420
|
-
|
|
53421
|
-
}),
|
|
53422
|
-
|
|
53423
|
-
|
|
53424
|
-
|
|
54333
|
+
var integrationInstancesCapability = {
|
|
54334
|
+
name: "integration-instances",
|
|
54335
|
+
scope: "system",
|
|
54336
|
+
mode: "collection",
|
|
54337
|
+
methods: {
|
|
54338
|
+
describe: method(_void(), IntegrationInstanceDescriptionSchema, { auth: "admin" }),
|
|
54339
|
+
/** The form; `id: null` is the create form. */
|
|
54340
|
+
instanceFormSchema: method(object({ id: IntegrationInstanceIdSchema.nullable() }), ConfigSchemaPassthrough$3, { auth: "admin" }),
|
|
54341
|
+
listInstances: method(_void(), array(IntegrationInstanceSchema).readonly(), { auth: "admin" }),
|
|
54342
|
+
getInstance: method(object({ id: IntegrationInstanceIdSchema }), IntegrationInstanceSchema.nullable(), { auth: "admin" }),
|
|
54343
|
+
/** Insert the typed record under the given id (a duplicate id is refused). */
|
|
54344
|
+
createInstance: method(object({
|
|
54345
|
+
id: IntegrationInstanceIdSchema,
|
|
54346
|
+
name: string().min(1)
|
|
54347
|
+
}), object({ id: string() }), {
|
|
54348
|
+
kind: "mutation",
|
|
54349
|
+
auth: "admin"
|
|
54350
|
+
}),
|
|
54351
|
+
updateInstance: method(IntegrationInstancePatchSchema, object({ ok: literal(true) }), {
|
|
54352
|
+
kind: "mutation",
|
|
54353
|
+
auth: "admin"
|
|
54354
|
+
}),
|
|
54355
|
+
/**
|
|
54356
|
+
* Switch ONE instance on or off. A row control, not a form field: `updateInstance.values` is the
|
|
54357
|
+
* form patch (D62, D996). An off instance keeps its record and secrets and does no work.
|
|
54358
|
+
*/
|
|
54359
|
+
setInstanceEnabled: method(object({
|
|
54360
|
+
id: IntegrationInstanceIdSchema,
|
|
54361
|
+
enabled: boolean()
|
|
54362
|
+
}), object({ ok: literal(true) }), {
|
|
54363
|
+
kind: "mutation",
|
|
54364
|
+
auth: "admin"
|
|
54365
|
+
}),
|
|
54366
|
+
/** Delete the record and its keychain refs together. */
|
|
54367
|
+
deleteInstance: method(object({ id: IntegrationInstanceIdSchema }), object({ ok: literal(true) }), {
|
|
54368
|
+
kind: "mutation",
|
|
54369
|
+
auth: "admin"
|
|
54370
|
+
}),
|
|
54371
|
+
testInstance: optionalMethod(object({
|
|
54372
|
+
id: IntegrationInstanceIdSchema.nullable(),
|
|
54373
|
+
values: record(string(), unknown())
|
|
54374
|
+
}), TestConnectionResultSchema$1, {
|
|
54375
|
+
kind: "mutation",
|
|
54376
|
+
auth: "admin"
|
|
54377
|
+
})
|
|
54378
|
+
}
|
|
54379
|
+
};
|
|
53425
54380
|
/**
|
|
53426
54381
|
* Two-way audio / talk-back cap. Clients open a WebRTC audio-only
|
|
53427
54382
|
* session (server-initiated offer pattern, identical to the main
|
|
@@ -55404,164 +56359,6 @@ var LoginMethodContributionSchema = discriminatedUnion("kind", [
|
|
|
55404
56359
|
]);
|
|
55405
56360
|
method(_void(), array(LoginMethodContributionSchema).readonly());
|
|
55406
56361
|
/**
|
|
55407
|
-
* Media-player cap. Models HA `media_player.*` (Sonos, Chromecast,
|
|
55408
|
-
* Apple TV, Spotify, Roku, generic OTT receivers, …) on
|
|
55409
|
-
* `DeviceType.MediaPlayer`. Disjoint from the camera streaming
|
|
55410
|
-
* surface — those use `DeviceType.Camera` + the broker pipeline.
|
|
55411
|
-
*
|
|
55412
|
-
* The cap declares a wide method surface; not every backend supports
|
|
55413
|
-
* every method. Drivers signal sub-capability via the
|
|
55414
|
-
* `DeviceFeature.MediaPlayerXxx` flags (paired one-to-one with the
|
|
55415
|
-
* corresponding method) so the UI gates buttons without a slice
|
|
55416
|
-
* fetch — same pattern as `PanTiltZoom` for cameras.
|
|
55417
|
-
*/
|
|
55418
|
-
var MediaPlayerStateSchema = _enum([
|
|
55419
|
-
"off",
|
|
55420
|
-
"on",
|
|
55421
|
-
"idle",
|
|
55422
|
-
"playing",
|
|
55423
|
-
"paused",
|
|
55424
|
-
"buffering",
|
|
55425
|
-
"standby"
|
|
55426
|
-
]);
|
|
55427
|
-
var MediaPlayerRepeatSchema = _enum([
|
|
55428
|
-
"off",
|
|
55429
|
-
"all",
|
|
55430
|
-
"one"
|
|
55431
|
-
]);
|
|
55432
|
-
var MediaInfoSchema = object({
|
|
55433
|
-
/** Free-form media kind (`music`, `tvshow`, `movie`, `app`, `channel`,
|
|
55434
|
-
* `podcast`, …). */
|
|
55435
|
-
type: string(),
|
|
55436
|
-
/** Human-readable title. */
|
|
55437
|
-
title: string(),
|
|
55438
|
-
/** Optional artist / channel / station label. */
|
|
55439
|
-
artist: string().optional(),
|
|
55440
|
-
/** Optional album / season / show name. */
|
|
55441
|
-
album: string().optional(),
|
|
55442
|
-
/** Optional cover-art / thumbnail URL. */
|
|
55443
|
-
imageUrl: string().optional()
|
|
55444
|
-
});
|
|
55445
|
-
/**
|
|
55446
|
-
* Where `state`, `volumeLevel`, `isMuted` and `source` come from. `reported`:
|
|
55447
|
-
* the device said so. `assumed`: the driver has no feedback (infrared) and
|
|
55448
|
-
* tracks what it last SENT; it moves only after a send was accepted, and a
|
|
55449
|
-
* human at the real remote makes it wrong. A UI shows an assumed value as a
|
|
55450
|
-
* guess, never as a reading.
|
|
55451
|
-
*/
|
|
55452
|
-
var MediaPlayerStateSourceSchema = _enum(["reported", "assumed"]);
|
|
55453
|
-
/** The fields of a media-player status a driver can only guess. */
|
|
55454
|
-
var MediaPlayerAssumedFieldSchema = _enum([
|
|
55455
|
-
"state",
|
|
55456
|
-
"volumeLevel",
|
|
55457
|
-
"isMuted",
|
|
55458
|
-
"source"
|
|
55459
|
-
]);
|
|
55460
|
-
object({
|
|
55461
|
-
/** Playback lifecycle state. */
|
|
55462
|
-
state: MediaPlayerStateSchema,
|
|
55463
|
-
/**
|
|
55464
|
-
* Whether the state fields are readings or the driver's own bookkeeping.
|
|
55465
|
-
* A slice written before this field existed parses as `reported`.
|
|
55466
|
-
*/
|
|
55467
|
-
stateSource: MediaPlayerStateSourceSchema.default("reported"),
|
|
55468
|
-
/**
|
|
55469
|
-
* Which fields are the driver's own guess. `stateSource` is `assumed` when
|
|
55470
|
-
* this is not empty; a field not listed here is a reading even then (power
|
|
55471
|
-
* from a running-state source, mute guessed from the last send).
|
|
55472
|
-
*/
|
|
55473
|
-
assumedFields: array(MediaPlayerAssumedFieldSchema).default([]),
|
|
55474
|
-
/** Volume as 0..100 inclusive. Null when the device has no volume
|
|
55475
|
-
* surface. Pair with `DeviceFeature.MediaPlayerVolume`. */
|
|
55476
|
-
volumeLevel: number().min(0).max(100).nullable().meta(readingMeta("percentage")),
|
|
55477
|
-
/** Mute toggle distinct from volume=0. Null when no mute surface.
|
|
55478
|
-
* Pair with `DeviceFeature.MediaPlayerMute`. */
|
|
55479
|
-
isMuted: boolean().nullable(),
|
|
55480
|
-
/** Active source / input. Empty when no source surface. */
|
|
55481
|
-
source: string(),
|
|
55482
|
-
/** Selectable sources. Empty when no source surface.
|
|
55483
|
-
* Pair with `DeviceFeature.MediaPlayerSelectSource`. */
|
|
55484
|
-
availableSources: array(string()),
|
|
55485
|
-
/** Currently-playing media info. Null when nothing is playing. */
|
|
55486
|
-
currentMedia: MediaInfoSchema.nullable(),
|
|
55487
|
-
/** Current playback position in ms. Null when not seekable or
|
|
55488
|
-
* nothing is playing. Pair with `DeviceFeature.MediaPlayerSeek`. */
|
|
55489
|
-
position: number().int().nonnegative().nullable().meta(readingMeta("duration-ms")),
|
|
55490
|
-
/** Total duration of the current media in ms. Null when unknown
|
|
55491
|
-
* (live stream) or nothing is playing. */
|
|
55492
|
-
duration: number().int().nonnegative().nullable().meta(readingMeta("duration-ms")),
|
|
55493
|
-
/** Shuffle toggle. Null when no shuffle surface.
|
|
55494
|
-
* Pair with `DeviceFeature.MediaPlayerShuffle`. */
|
|
55495
|
-
shuffle: boolean().nullable(),
|
|
55496
|
-
/** Repeat mode. Null when no repeat surface.
|
|
55497
|
-
* Pair with `DeviceFeature.MediaPlayerRepeat`. */
|
|
55498
|
-
repeat: MediaPlayerRepeatSchema.nullable(),
|
|
55499
|
-
/** Ms epoch when the slice was last updated. */
|
|
55500
|
-
lastChangedAt: number()
|
|
55501
|
-
});
|
|
55502
|
-
DeviceType.MediaPlayer, method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
55503
|
-
kind: "mutation",
|
|
55504
|
-
auth: "protected"
|
|
55505
|
-
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
55506
|
-
kind: "mutation",
|
|
55507
|
-
auth: "protected"
|
|
55508
|
-
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
55509
|
-
kind: "mutation",
|
|
55510
|
-
auth: "protected"
|
|
55511
|
-
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
55512
|
-
kind: "mutation",
|
|
55513
|
-
auth: "protected"
|
|
55514
|
-
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
55515
|
-
kind: "mutation",
|
|
55516
|
-
auth: "protected"
|
|
55517
|
-
}), method(object({
|
|
55518
|
-
deviceId: number().int().nonnegative(),
|
|
55519
|
-
position: number().int().nonnegative()
|
|
55520
|
-
}), _void(), {
|
|
55521
|
-
kind: "mutation",
|
|
55522
|
-
auth: "protected"
|
|
55523
|
-
}), method(object({
|
|
55524
|
-
deviceId: number().int().nonnegative(),
|
|
55525
|
-
volumeLevel: number().min(0).max(100)
|
|
55526
|
-
}), _void(), {
|
|
55527
|
-
kind: "mutation",
|
|
55528
|
-
auth: "protected"
|
|
55529
|
-
}), method(object({
|
|
55530
|
-
deviceId: number().int().nonnegative(),
|
|
55531
|
-
muted: boolean()
|
|
55532
|
-
}), _void(), {
|
|
55533
|
-
kind: "mutation",
|
|
55534
|
-
auth: "protected"
|
|
55535
|
-
}), method(object({
|
|
55536
|
-
deviceId: number().int().nonnegative(),
|
|
55537
|
-
shuffle: boolean()
|
|
55538
|
-
}), _void(), {
|
|
55539
|
-
kind: "mutation",
|
|
55540
|
-
auth: "protected"
|
|
55541
|
-
}), method(object({
|
|
55542
|
-
deviceId: number().int().nonnegative(),
|
|
55543
|
-
repeat: MediaPlayerRepeatSchema
|
|
55544
|
-
}), _void(), {
|
|
55545
|
-
kind: "mutation",
|
|
55546
|
-
auth: "protected"
|
|
55547
|
-
}), method(object({
|
|
55548
|
-
deviceId: number().int().nonnegative(),
|
|
55549
|
-
source: string().min(1)
|
|
55550
|
-
}), _void(), {
|
|
55551
|
-
kind: "mutation",
|
|
55552
|
-
auth: "protected"
|
|
55553
|
-
}), method(object({
|
|
55554
|
-
deviceId: number().int().nonnegative(),
|
|
55555
|
-
/** Media identifier / URL. */
|
|
55556
|
-
mediaId: string().min(1),
|
|
55557
|
-
/** Media kind (`music`, `tvshow`, `movie`, `app`, …) — provider
|
|
55558
|
-
* passes it through to the upstream service. */
|
|
55559
|
-
mediaType: string().min(1)
|
|
55560
|
-
}), _void(), {
|
|
55561
|
-
kind: "mutation",
|
|
55562
|
-
auth: "protected"
|
|
55563
|
-
});
|
|
55564
|
-
/**
|
|
55565
56362
|
* mesh-network — collection cap for mesh-VPN providers.
|
|
55566
56363
|
*
|
|
55567
56364
|
* Different shape from `network-access` (public tunnels):
|
|
@@ -63854,6 +64651,21 @@ var NcTemplateVarKindSchema = _enum([
|
|
|
63854
64651
|
"sound",
|
|
63855
64652
|
"system"
|
|
63856
64653
|
]);
|
|
64654
|
+
/**
|
|
64655
|
+
* The default title/body a rule of one SITUATION is delivered with when the
|
|
64656
|
+
* operator wrote no template — served so an editor can pre-fill it (and the
|
|
64657
|
+
* operator can rebuild it from placeholders) instead of starting from a blank
|
|
64658
|
+
* box that, once saved, silently replaces it. `id` names the situation inside
|
|
64659
|
+
* a rule `kind`: `appliance-cycle` is a `sensor` rule whose device is an
|
|
64660
|
+
* appliance finishing a cycle. Texts are raw templates (`{{var}}` intact), in
|
|
64661
|
+
* the hub's current language and with its overrides applied.
|
|
64662
|
+
*/
|
|
64663
|
+
var NcTemplateDefaultSchema = object({
|
|
64664
|
+
id: _enum(["appliance-cycle"]),
|
|
64665
|
+
kind: NcRuleKindSchema,
|
|
64666
|
+
title: string(),
|
|
64667
|
+
body: string()
|
|
64668
|
+
});
|
|
63857
64669
|
/** Which producer renders a template: an ordinary rule, a timelapse, a digest. */
|
|
63858
64670
|
var NcTemplateFamilySchema = _enum([
|
|
63859
64671
|
"rule",
|
|
@@ -64709,7 +65521,11 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
|
|
|
64709
65521
|
}), method(object({}), object({
|
|
64710
65522
|
catalog: array(NcConditionDescriptorSchema),
|
|
64711
65523
|
taxonomy: NcTaxonomySchema.optional()
|
|
64712
|
-
})), method(object({}), object({
|
|
65524
|
+
})), method(object({}), object({
|
|
65525
|
+
vars: array(NcTemplateVarDescriptorSchema),
|
|
65526
|
+
/** Per-situation default texts; absent on a hub that predates them. */
|
|
65527
|
+
defaults: array(NcTemplateDefaultSchema)
|
|
65528
|
+
})), method(NcTemplatePreviewInputSchema, NcTemplatePreviewSchema, {
|
|
64713
65529
|
kind: "mutation",
|
|
64714
65530
|
access: "view"
|
|
64715
65531
|
}), 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 }), {
|
|
@@ -70197,7 +71013,13 @@ var RemoteMediaCommandSchema = _enum([
|
|
|
70197
71013
|
"next",
|
|
70198
71014
|
"previous",
|
|
70199
71015
|
"setMute",
|
|
70200
|
-
"selectSource"
|
|
71016
|
+
"selectSource",
|
|
71017
|
+
"turnOn",
|
|
71018
|
+
"turnOff",
|
|
71019
|
+
"volumeUp",
|
|
71020
|
+
"volumeDown",
|
|
71021
|
+
"channelUp",
|
|
71022
|
+
"channelDown"
|
|
70201
71023
|
]);
|
|
70202
71024
|
/** A send result, or `not-routed`: the role is not bound, so the native cap answers. */
|
|
70203
71025
|
var RemoteMediaCommandResultSchema = discriminatedUnion("status", [...RemoteSendResultSchema.options, object({ status: literal("not-routed") })]);
|
|
@@ -70218,7 +71040,7 @@ method(deviceInput, RemoteConfigSchema, { auth: "admin" }), method(deviceInput.e
|
|
|
70218
71040
|
}), RemoteSendResultSchema, {
|
|
70219
71041
|
kind: "mutation",
|
|
70220
71042
|
auth: "protected"
|
|
70221
|
-
}), method(deviceInput.extend({
|
|
71043
|
+
}), method(deviceInput, MediaPlayerStatusSchema.nullable(), { auth: "protected" }), method(deviceInput.extend({
|
|
70222
71044
|
command: RemoteMediaCommandSchema,
|
|
70223
71045
|
muted: boolean().optional(),
|
|
70224
71046
|
source: string().optional(),
|
|
@@ -72053,7 +72875,11 @@ Object.values(DeviceType), method(_void(), array(StreamSignalSchema).readonly())
|
|
|
72053
72875
|
* `getSettingsUISchema()` surface.
|
|
72054
72876
|
*/
|
|
72055
72877
|
var SwitchStatusSchema = object({
|
|
72056
|
-
|
|
72878
|
+
/**
|
|
72879
|
+
* `null` = the device has never reported its state (a measurement that
|
|
72880
|
+
* has not happened is unknown, never `false`).
|
|
72881
|
+
*/
|
|
72882
|
+
on: boolean().nullable().meta({ label: "On" }),
|
|
72057
72883
|
/** Ms epoch of the last state change. Useful for UI "X minutes ago". */
|
|
72058
72884
|
lastChangedAt: number()
|
|
72059
72885
|
});
|
|
@@ -72065,7 +72891,7 @@ DeviceType.Switch, DeviceType.Siren, DeviceType.Light, DeviceType.Fan, DeviceTyp
|
|
|
72065
72891
|
auth: "protected"
|
|
72066
72892
|
}), object({
|
|
72067
72893
|
deviceId: number(),
|
|
72068
|
-
on: boolean(),
|
|
72894
|
+
on: boolean().nullable(),
|
|
72069
72895
|
lastChangedAt: number()
|
|
72070
72896
|
});
|
|
72071
72897
|
/** C0 controls, DEL and the C1 range: none of them belongs in a name. */
|
|
@@ -75089,6 +75915,7 @@ function buildDescriptor(capName, kind) {
|
|
|
75089
75915
|
* contributes one entry per bound cap present in this map.
|
|
75090
75916
|
*/
|
|
75091
75917
|
var EVENT_KIND_BY_CAP = Object.freeze(Object.fromEntries(Object.entries(CAP_TO_KIND).map(([capName, kind]) => [capName, buildDescriptor(capName, kind)])));
|
|
75918
|
+
DeviceFeature.MediaPlayerPower, DeviceFeature.MediaPlayerVolumeStep, DeviceFeature.MediaPlayerChannelStep, DeviceFeature.MediaPlayerMute, DeviceFeature.MediaPlayerStop, DeviceFeature.MediaPlayerNext, DeviceFeature.MediaPlayerPrevious;
|
|
75092
75919
|
var btn = (idSuffix, row, col, init) => ({
|
|
75093
75920
|
idSuffix,
|
|
75094
75921
|
row,
|
|
@@ -79703,6 +80530,20 @@ Object.freeze({
|
|
|
79703
80530
|
access: "view",
|
|
79704
80531
|
role: "admin"
|
|
79705
80532
|
},
|
|
80533
|
+
"mediaPlayer.channelDown": {
|
|
80534
|
+
capName: "media-player",
|
|
80535
|
+
capScope: "device",
|
|
80536
|
+
addonId: null,
|
|
80537
|
+
access: "create",
|
|
80538
|
+
role: "viewer"
|
|
80539
|
+
},
|
|
80540
|
+
"mediaPlayer.channelUp": {
|
|
80541
|
+
capName: "media-player",
|
|
80542
|
+
capScope: "device",
|
|
80543
|
+
addonId: null,
|
|
80544
|
+
access: "create",
|
|
80545
|
+
role: "viewer"
|
|
80546
|
+
},
|
|
79706
80547
|
"mediaPlayer.getStatus": {
|
|
79707
80548
|
capName: "media-player",
|
|
79708
80549
|
capScope: "device",
|
|
@@ -79794,6 +80635,34 @@ Object.freeze({
|
|
|
79794
80635
|
access: "create",
|
|
79795
80636
|
role: "viewer"
|
|
79796
80637
|
},
|
|
80638
|
+
"mediaPlayer.turnOff": {
|
|
80639
|
+
capName: "media-player",
|
|
80640
|
+
capScope: "device",
|
|
80641
|
+
addonId: null,
|
|
80642
|
+
access: "create",
|
|
80643
|
+
role: "viewer"
|
|
80644
|
+
},
|
|
80645
|
+
"mediaPlayer.turnOn": {
|
|
80646
|
+
capName: "media-player",
|
|
80647
|
+
capScope: "device",
|
|
80648
|
+
addonId: null,
|
|
80649
|
+
access: "create",
|
|
80650
|
+
role: "viewer"
|
|
80651
|
+
},
|
|
80652
|
+
"mediaPlayer.volumeDown": {
|
|
80653
|
+
capName: "media-player",
|
|
80654
|
+
capScope: "device",
|
|
80655
|
+
addonId: null,
|
|
80656
|
+
access: "create",
|
|
80657
|
+
role: "viewer"
|
|
80658
|
+
},
|
|
80659
|
+
"mediaPlayer.volumeUp": {
|
|
80660
|
+
capName: "media-player",
|
|
80661
|
+
capScope: "device",
|
|
80662
|
+
addonId: null,
|
|
80663
|
+
access: "create",
|
|
80664
|
+
role: "viewer"
|
|
80665
|
+
},
|
|
79797
80666
|
"meshNetwork.getStatus": {
|
|
79798
80667
|
capName: "mesh-network",
|
|
79799
80668
|
capScope: "system",
|
|
@@ -83350,6 +84219,13 @@ Object.freeze({
|
|
|
83350
84219
|
access: "create",
|
|
83351
84220
|
role: "admin"
|
|
83352
84221
|
},
|
|
84222
|
+
"remote.getAssumedStatus": {
|
|
84223
|
+
capName: "remote",
|
|
84224
|
+
capScope: "system",
|
|
84225
|
+
addonId: null,
|
|
84226
|
+
access: "view",
|
|
84227
|
+
role: "admin"
|
|
84228
|
+
},
|
|
83353
84229
|
"remote.getConfig": {
|
|
83354
84230
|
capName: "remote",
|
|
83355
84231
|
capScope: "system",
|
|
@@ -87041,6 +87917,16 @@ Object.freeze({
|
|
|
87041
87917
|
form: "single",
|
|
87042
87918
|
optional: true
|
|
87043
87919
|
}],
|
|
87920
|
+
"mediaPlayer.channelDown": [{
|
|
87921
|
+
name: "deviceId",
|
|
87922
|
+
form: "single",
|
|
87923
|
+
optional: false
|
|
87924
|
+
}],
|
|
87925
|
+
"mediaPlayer.channelUp": [{
|
|
87926
|
+
name: "deviceId",
|
|
87927
|
+
form: "single",
|
|
87928
|
+
optional: false
|
|
87929
|
+
}],
|
|
87044
87930
|
"mediaPlayer.getStatus": [{
|
|
87045
87931
|
name: "deviceId",
|
|
87046
87932
|
form: "single",
|
|
@@ -87106,6 +87992,26 @@ Object.freeze({
|
|
|
87106
87992
|
form: "single",
|
|
87107
87993
|
optional: false
|
|
87108
87994
|
}],
|
|
87995
|
+
"mediaPlayer.turnOff": [{
|
|
87996
|
+
name: "deviceId",
|
|
87997
|
+
form: "single",
|
|
87998
|
+
optional: false
|
|
87999
|
+
}],
|
|
88000
|
+
"mediaPlayer.turnOn": [{
|
|
88001
|
+
name: "deviceId",
|
|
88002
|
+
form: "single",
|
|
88003
|
+
optional: false
|
|
88004
|
+
}],
|
|
88005
|
+
"mediaPlayer.volumeDown": [{
|
|
88006
|
+
name: "deviceId",
|
|
88007
|
+
form: "single",
|
|
88008
|
+
optional: false
|
|
88009
|
+
}],
|
|
88010
|
+
"mediaPlayer.volumeUp": [{
|
|
88011
|
+
name: "deviceId",
|
|
88012
|
+
form: "single",
|
|
88013
|
+
optional: false
|
|
88014
|
+
}],
|
|
87109
88015
|
"meter.getStatus": [{
|
|
87110
88016
|
name: "deviceId",
|
|
87111
88017
|
form: "single",
|
|
@@ -88271,6 +89177,11 @@ Object.freeze({
|
|
|
88271
89177
|
form: "single",
|
|
88272
89178
|
optional: true
|
|
88273
89179
|
}],
|
|
89180
|
+
"remote.getAssumedStatus": [{
|
|
89181
|
+
name: "deviceId",
|
|
89182
|
+
form: "single",
|
|
89183
|
+
optional: false
|
|
89184
|
+
}],
|
|
88274
89185
|
"remote.getConfig": [{
|
|
88275
89186
|
name: "deviceId",
|
|
88276
89187
|
form: "single",
|
|
@@ -89526,6 +90437,7 @@ var STATE_SUMMARY_VARS = [
|
|
|
89526
90437
|
[...RULE_TEXT],
|
|
89527
90438
|
([...RULE_TEXT], [...DEVICE_EVENTS]),
|
|
89528
90439
|
([...RULE_TEXT], [...COMBINED_ALARM]),
|
|
90440
|
+
([...RULE_TEXT], [...COMBINED_ALARM]),
|
|
89529
90441
|
([...RULE_TEXT], [...DEVICE_EVENTS]),
|
|
89530
90442
|
([...RULE_TEXT], [...BATTERY, ...CONSUMABLE]),
|
|
89531
90443
|
([...RULE_TEXT], [...CONSUMABLE]),
|
|
@@ -91735,8 +92647,8 @@ function climateProperties(slice) {
|
|
|
91735
92647
|
//#endregion
|
|
91736
92648
|
//#region src/handlers/climate-controller.ts
|
|
91737
92649
|
var CAP_CLIMATE = "climate-control";
|
|
91738
|
-
var CAP_SWITCH$
|
|
91739
|
-
var UNCERTAINTY_MS$
|
|
92650
|
+
var CAP_SWITCH$2 = "switch";
|
|
92651
|
+
var UNCERTAINTY_MS$2 = 500;
|
|
91740
92652
|
var PRESET_NONE = "none";
|
|
91741
92653
|
var ScaleSchema = _enum([
|
|
91742
92654
|
"CELSIUS",
|
|
@@ -92033,7 +92945,7 @@ function successResponse$2(c, properties) {
|
|
|
92033
92945
|
context: { properties: properties.map((p) => ({
|
|
92034
92946
|
...p,
|
|
92035
92947
|
timeOfSample: now,
|
|
92036
|
-
uncertaintyInMilliseconds: UNCERTAINTY_MS$
|
|
92948
|
+
uncertaintyInMilliseconds: UNCERTAINTY_MS$2
|
|
92037
92949
|
})) }
|
|
92038
92950
|
};
|
|
92039
92951
|
}
|
|
@@ -92075,7 +92987,7 @@ async function handlesPower(c) {
|
|
|
92075
92987
|
lastPowerClaim.set(deps, known);
|
|
92076
92988
|
try {
|
|
92077
92989
|
const caps = (await deps.ctx.api.deviceManager.getBindings.query({ deviceId: c.deviceId })).entries.map((e) => e.capName);
|
|
92078
|
-
const claim = caps.includes(CAP_CLIMATE) && !caps.includes(CAP_SWITCH$
|
|
92990
|
+
const claim = caps.includes(CAP_CLIMATE) && !caps.includes(CAP_SWITCH$2);
|
|
92079
92991
|
known.set(c.deviceId, claim);
|
|
92080
92992
|
return claim;
|
|
92081
92993
|
} catch (err) {
|
|
@@ -93135,7 +94047,7 @@ function fanProperties(slice) {
|
|
|
93135
94047
|
//#endregion
|
|
93136
94048
|
//#region src/handlers/fan-controller.ts
|
|
93137
94049
|
var CAP_FAN = "fan-control";
|
|
93138
|
-
var UNCERTAINTY_MS = 500;
|
|
94050
|
+
var UNCERTAINTY_MS$1 = 500;
|
|
93139
94051
|
/** What AdjustRangeValue moves by when the device states no step of its own. */
|
|
93140
94052
|
var DEFAULT_ADJUST = 10;
|
|
93141
94053
|
var SetRangePayload = object({ rangeValue: number() });
|
|
@@ -93147,7 +94059,7 @@ var SetModePayload = object({ mode: string() });
|
|
|
93147
94059
|
function clamp(value) {
|
|
93148
94060
|
return Math.max(0, Math.min(100, Math.round(value)));
|
|
93149
94061
|
}
|
|
93150
|
-
function message(err) {
|
|
94062
|
+
function message$1(err) {
|
|
93151
94063
|
return err instanceof Error ? err.message : String(err);
|
|
93152
94064
|
}
|
|
93153
94065
|
async function readSlice(c, deps) {
|
|
@@ -93159,7 +94071,7 @@ async function readSlice(c, deps) {
|
|
|
93159
94071
|
} catch (err) {
|
|
93160
94072
|
deps.logger.warn("alexa fan-controller: the fan state could not be read", {
|
|
93161
94073
|
tags: { deviceId: c.deviceId },
|
|
93162
|
-
meta: { error: message(err) }
|
|
94074
|
+
meta: { error: message$1(err) }
|
|
93163
94075
|
});
|
|
93164
94076
|
return null;
|
|
93165
94077
|
}
|
|
@@ -93181,7 +94093,7 @@ function successResponse$1(c, properties) {
|
|
|
93181
94093
|
context: { properties: properties.map((p) => ({
|
|
93182
94094
|
...p,
|
|
93183
94095
|
timeOfSample: now,
|
|
93184
|
-
uncertaintyInMilliseconds: UNCERTAINTY_MS
|
|
94096
|
+
uncertaintyInMilliseconds: UNCERTAINTY_MS$1
|
|
93185
94097
|
})) }
|
|
93186
94098
|
};
|
|
93187
94099
|
}
|
|
@@ -93199,7 +94111,7 @@ async function setSpeed(c, deps, slice, speed) {
|
|
|
93199
94111
|
tags: { deviceId: c.deviceId },
|
|
93200
94112
|
meta: {
|
|
93201
94113
|
speed,
|
|
93202
|
-
error: message(err)
|
|
94114
|
+
error: message$1(err)
|
|
93203
94115
|
}
|
|
93204
94116
|
});
|
|
93205
94117
|
return unreachable(c, "the fan did not accept the speed");
|
|
@@ -93242,7 +94154,7 @@ async function handleToggle(c, deps) {
|
|
|
93242
94154
|
tags: { deviceId: c.deviceId },
|
|
93243
94155
|
meta: {
|
|
93244
94156
|
oscillating,
|
|
93245
|
-
error: message(err)
|
|
94157
|
+
error: message$1(err)
|
|
93246
94158
|
}
|
|
93247
94159
|
});
|
|
93248
94160
|
return unreachable(c, "the fan did not accept the command");
|
|
@@ -93262,7 +94174,7 @@ async function customNames(c, deps) {
|
|
|
93262
94174
|
} catch (err) {
|
|
93263
94175
|
deps.logger.warn("alexa fan-controller: the custom presets could not be read", {
|
|
93264
94176
|
tags: { deviceId: c.deviceId },
|
|
93265
|
-
meta: { error: message(err) }
|
|
94177
|
+
meta: { error: message$1(err) }
|
|
93266
94178
|
});
|
|
93267
94179
|
return [];
|
|
93268
94180
|
}
|
|
@@ -93285,7 +94197,7 @@ async function handleMode(c, deps) {
|
|
|
93285
94197
|
tags: { deviceId: c.deviceId },
|
|
93286
94198
|
meta: {
|
|
93287
94199
|
preset: mode.name,
|
|
93288
|
-
error: message(err)
|
|
94200
|
+
error: message$1(err)
|
|
93289
94201
|
}
|
|
93290
94202
|
});
|
|
93291
94203
|
return unreachable(c, "the fan did not accept the preset");
|
|
@@ -93337,7 +94249,7 @@ async function applyCustom(c, deps, name) {
|
|
|
93337
94249
|
tags: { deviceId: c.deviceId },
|
|
93338
94250
|
meta: {
|
|
93339
94251
|
preset: name,
|
|
93340
|
-
error: message(err)
|
|
94252
|
+
error: message$1(err)
|
|
93341
94253
|
}
|
|
93342
94254
|
});
|
|
93343
94255
|
return unreachable(c, "the preset could not be applied");
|
|
@@ -93533,6 +94445,397 @@ var lockAdapter = {
|
|
|
93533
94445
|
shaping: unshaped
|
|
93534
94446
|
};
|
|
93535
94447
|
//#endregion
|
|
94448
|
+
//#region src/endpoints/adapters/media-player-model.ts
|
|
94449
|
+
/**
|
|
94450
|
+
* A media player exported as a TV (planning#398). What Alexa is told depends on
|
|
94451
|
+
* what the player can DO (its features) and what it REPORTS (its slice):
|
|
94452
|
+
*
|
|
94453
|
+
* power → `Alexa.PowerController` (feature `media-player-power`)
|
|
94454
|
+
* volume ±N → `Alexa.StepSpeaker` (feature `media-player-volume-step`)
|
|
94455
|
+
* mute → `Alexa.Speaker` (`muted` only) (feature `media-player-mute`)
|
|
94456
|
+
* channel ±N → `Alexa.ChannelController` (feature `media-player-channel-step`)
|
|
94457
|
+
* transport → `Alexa.PlaybackController` (stop / next / previous by feature; play and
|
|
94458
|
+
* pause only when the player REPORTS its state,
|
|
94459
|
+
* since an assumed one cannot tell)
|
|
94460
|
+
* inputs → `Alexa.InputController` (the reported sources Amazon names)
|
|
94461
|
+
*
|
|
94462
|
+
* A property is reported only for a known value: an assumed `standby`, a null
|
|
94463
|
+
* mute and an unlisted volume or input produce no property at all (D393).
|
|
94464
|
+
*/
|
|
94465
|
+
var CAP_MEDIA_PLAYER = "media-player";
|
|
94466
|
+
/** The input names Amazon accepts for `Alexa.InputController` (alexa-inputcontroller). */
|
|
94467
|
+
var AMAZON_INPUTS = [
|
|
94468
|
+
...Array.from({ length: 7 }, (_, i) => `AUX ${i + 1}`),
|
|
94469
|
+
"BLURAY",
|
|
94470
|
+
"CABLE",
|
|
94471
|
+
"CD",
|
|
94472
|
+
"COAX 1",
|
|
94473
|
+
"COAX 2",
|
|
94474
|
+
"COMPOSITE 1",
|
|
94475
|
+
"DVD",
|
|
94476
|
+
"GAME",
|
|
94477
|
+
"HD RADIO",
|
|
94478
|
+
...Array.from({ length: 10 }, (_, i) => `HDMI ${i + 1}`),
|
|
94479
|
+
"HDMI ARC",
|
|
94480
|
+
...Array.from({ length: 10 }, (_, i) => `INPUT ${i + 1}`),
|
|
94481
|
+
"IPOD",
|
|
94482
|
+
...Array.from({ length: 7 }, (_, i) => `LINE ${i + 1}`),
|
|
94483
|
+
"MEDIA PLAYER",
|
|
94484
|
+
"OPTICAL 1",
|
|
94485
|
+
"OPTICAL 2",
|
|
94486
|
+
"PHONO",
|
|
94487
|
+
"PLAYSTATION",
|
|
94488
|
+
"PLAYSTATION 3",
|
|
94489
|
+
"PLAYSTATION 4",
|
|
94490
|
+
"SATELLITE",
|
|
94491
|
+
"SMARTCAST",
|
|
94492
|
+
"TUNER",
|
|
94493
|
+
"TV",
|
|
94494
|
+
"USB",
|
|
94495
|
+
"USB DAC",
|
|
94496
|
+
"VIDEO 1",
|
|
94497
|
+
"VIDEO 2",
|
|
94498
|
+
"VIDEO 3",
|
|
94499
|
+
"XBOX"
|
|
94500
|
+
];
|
|
94501
|
+
function squash(name) {
|
|
94502
|
+
return name.toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
94503
|
+
}
|
|
94504
|
+
/** The Amazon input a source name stands for ("hdmi1" → "HDMI 1"), or null. */
|
|
94505
|
+
function amazonInputOf(source) {
|
|
94506
|
+
const wanted = squash(source);
|
|
94507
|
+
return AMAZON_INPUTS.find((name) => squash(name) === wanted) ?? null;
|
|
94508
|
+
}
|
|
94509
|
+
/** The sources of a slice that Amazon has a name for, paired with the player's own name. */
|
|
94510
|
+
function inputPairs(status) {
|
|
94511
|
+
const seen = /* @__PURE__ */ new Set();
|
|
94512
|
+
const pairs = [];
|
|
94513
|
+
for (const source of status.availableSources) {
|
|
94514
|
+
const amazon = amazonInputOf(source);
|
|
94515
|
+
if (amazon === null || seen.has(amazon)) continue;
|
|
94516
|
+
seen.add(amazon);
|
|
94517
|
+
pairs.push({
|
|
94518
|
+
amazon,
|
|
94519
|
+
source
|
|
94520
|
+
});
|
|
94521
|
+
}
|
|
94522
|
+
return pairs;
|
|
94523
|
+
}
|
|
94524
|
+
function readMediaPlayerSlice(slice) {
|
|
94525
|
+
const parsed = MediaPlayerStatusSchema.safeParse(slice);
|
|
94526
|
+
return parsed.success ? parsed.data : null;
|
|
94527
|
+
}
|
|
94528
|
+
var PLAYBACK_BY_FEATURE = [
|
|
94529
|
+
[DeviceFeature.MediaPlayerStop, "Stop"],
|
|
94530
|
+
[DeviceFeature.MediaPlayerNext, "Next"],
|
|
94531
|
+
[DeviceFeature.MediaPlayerPrevious, "Previous"]
|
|
94532
|
+
];
|
|
94533
|
+
function playbackOperations(device, status) {
|
|
94534
|
+
return [...status !== null && status.stateSource === "reported" ? ["Play", "Pause"] : [], ...PLAYBACK_BY_FEATURE.filter(([feature]) => device.features.includes(feature)).map(([, operation]) => operation)];
|
|
94535
|
+
}
|
|
94536
|
+
function describeMediaPlayerCapabilities(device) {
|
|
94537
|
+
const has = (feature) => device.features.includes(feature);
|
|
94538
|
+
const status = readMediaPlayerSlice(device.slices[CAP_MEDIA_PLAYER]);
|
|
94539
|
+
const capabilities = [];
|
|
94540
|
+
if (has(DeviceFeature.MediaPlayerPower)) capabilities.push(iface("Alexa.PowerController", "powerState"));
|
|
94541
|
+
if (has(DeviceFeature.MediaPlayerVolumeStep)) capabilities.push({
|
|
94542
|
+
type: "AlexaInterface",
|
|
94543
|
+
interface: "Alexa.StepSpeaker",
|
|
94544
|
+
version: "3"
|
|
94545
|
+
});
|
|
94546
|
+
if (has(DeviceFeature.MediaPlayerMute)) capabilities.push(iface("Alexa.Speaker", "muted"));
|
|
94547
|
+
if (has(DeviceFeature.MediaPlayerChannelStep)) capabilities.push({
|
|
94548
|
+
type: "AlexaInterface",
|
|
94549
|
+
interface: "Alexa.ChannelController",
|
|
94550
|
+
version: "3"
|
|
94551
|
+
});
|
|
94552
|
+
const operations = playbackOperations(device, status);
|
|
94553
|
+
if (operations.length > 0) capabilities.push({
|
|
94554
|
+
type: "AlexaInterface",
|
|
94555
|
+
interface: "Alexa.PlaybackController",
|
|
94556
|
+
version: "3",
|
|
94557
|
+
supportedOperations: operations
|
|
94558
|
+
});
|
|
94559
|
+
const inputs = status === null ? [] : inputPairs(status);
|
|
94560
|
+
if (has(DeviceFeature.MediaPlayerSelectSource) && inputs.length > 0) capabilities.push({
|
|
94561
|
+
...iface("Alexa.InputController", "input"),
|
|
94562
|
+
inputs: inputs.map((i) => ({ name: i.amazon }))
|
|
94563
|
+
});
|
|
94564
|
+
return capabilities;
|
|
94565
|
+
}
|
|
94566
|
+
/** The Alexa properties of a slice: only what is known. */
|
|
94567
|
+
function mediaPlayerProperties(slice) {
|
|
94568
|
+
const status = readMediaPlayerSlice(slice);
|
|
94569
|
+
if (status === null) return [];
|
|
94570
|
+
const out = [];
|
|
94571
|
+
if (status.state === "off") out.push({
|
|
94572
|
+
namespace: "Alexa.PowerController",
|
|
94573
|
+
name: "powerState",
|
|
94574
|
+
value: "OFF"
|
|
94575
|
+
});
|
|
94576
|
+
else if (status.state !== "standby") out.push({
|
|
94577
|
+
namespace: "Alexa.PowerController",
|
|
94578
|
+
name: "powerState",
|
|
94579
|
+
value: "ON"
|
|
94580
|
+
});
|
|
94581
|
+
if (status.isMuted !== null) out.push({
|
|
94582
|
+
namespace: "Alexa.Speaker",
|
|
94583
|
+
name: "muted",
|
|
94584
|
+
value: status.isMuted
|
|
94585
|
+
});
|
|
94586
|
+
const input = inputPairs(status).find((i) => i.source === status.source);
|
|
94587
|
+
if (input !== void 0) out.push({
|
|
94588
|
+
namespace: "Alexa.InputController",
|
|
94589
|
+
name: "input",
|
|
94590
|
+
value: input.amazon
|
|
94591
|
+
});
|
|
94592
|
+
return out;
|
|
94593
|
+
}
|
|
94594
|
+
//#endregion
|
|
94595
|
+
//#region src/handlers/media-player-controller.ts
|
|
94596
|
+
var UNCERTAINTY_MS = 1e3;
|
|
94597
|
+
var CAP_SWITCH$1 = "switch";
|
|
94598
|
+
var StepsPayload = object({ volumeSteps: number().int() });
|
|
94599
|
+
var ChannelPayload = object({ channelCount: number().int() });
|
|
94600
|
+
var MutePayload = object({ mute: boolean() });
|
|
94601
|
+
var InputPayload = object({ input: string() });
|
|
94602
|
+
function message(err) {
|
|
94603
|
+
return err instanceof Error ? err.message : String(err);
|
|
94604
|
+
}
|
|
94605
|
+
function success(c, properties) {
|
|
94606
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
94607
|
+
return {
|
|
94608
|
+
event: {
|
|
94609
|
+
header: {
|
|
94610
|
+
namespace: "Alexa",
|
|
94611
|
+
name: "Response",
|
|
94612
|
+
messageId: c.header.messageId,
|
|
94613
|
+
...c.header.correlationToken !== void 0 ? { correlationToken: c.header.correlationToken } : {},
|
|
94614
|
+
payloadVersion: "3"
|
|
94615
|
+
},
|
|
94616
|
+
endpoint: { endpointId: c.endpoint.endpointId },
|
|
94617
|
+
payload: {}
|
|
94618
|
+
},
|
|
94619
|
+
context: { properties: properties.map((p) => ({
|
|
94620
|
+
...p,
|
|
94621
|
+
timeOfSample: now,
|
|
94622
|
+
uncertaintyInMilliseconds: UNCERTAINTY_MS
|
|
94623
|
+
})) }
|
|
94624
|
+
};
|
|
94625
|
+
}
|
|
94626
|
+
/** PowerController on a media player, not on a switch: decided by the bound caps. */
|
|
94627
|
+
async function claimsMediaPlayerPower(c) {
|
|
94628
|
+
const deps = c.deps.mediaPlayerController;
|
|
94629
|
+
try {
|
|
94630
|
+
const caps = (await deps.ctx.api.deviceManager.getBindings.query({ deviceId: c.deviceId })).entries.map((e) => e.capName);
|
|
94631
|
+
return caps.includes("media-player") && !caps.includes(CAP_SWITCH$1);
|
|
94632
|
+
} catch (err) {
|
|
94633
|
+
deps.logger.warn("alexa media-player-controller: the bound caps could not be read", {
|
|
94634
|
+
tags: { deviceId: c.deviceId },
|
|
94635
|
+
meta: {
|
|
94636
|
+
error: message(err),
|
|
94637
|
+
decidedFrom: "no previous answer: not claimed"
|
|
94638
|
+
}
|
|
94639
|
+
});
|
|
94640
|
+
return false;
|
|
94641
|
+
}
|
|
94642
|
+
}
|
|
94643
|
+
/** How long a step command may run before Alexa is answered anyway (its own budget is ~8 s). */
|
|
94644
|
+
var STEP_ANSWER_BUDGET_MS = 3e3;
|
|
94645
|
+
/** The properties a command may assert: only those the player READS back, never an assumption (D393). */
|
|
94646
|
+
async function reportedProperties(c, namespace) {
|
|
94647
|
+
const deps = c.deps.mediaPlayerController;
|
|
94648
|
+
try {
|
|
94649
|
+
const slice = await deps.ctx.api.deviceState.getCapSlice.query({
|
|
94650
|
+
deviceId: c.deviceId,
|
|
94651
|
+
capName: CAP_MEDIA_PLAYER
|
|
94652
|
+
});
|
|
94653
|
+
const status = readMediaPlayerSlice(slice);
|
|
94654
|
+
if (status === null || status.stateSource !== "reported") return [];
|
|
94655
|
+
return mediaPlayerProperties(slice).filter((p) => p.namespace === namespace);
|
|
94656
|
+
} catch (err) {
|
|
94657
|
+
deps.logger.warn("alexa media-player-controller: the state could not be re-read", {
|
|
94658
|
+
tags: { deviceId: c.deviceId },
|
|
94659
|
+
meta: { error: message(err) }
|
|
94660
|
+
});
|
|
94661
|
+
return [];
|
|
94662
|
+
}
|
|
94663
|
+
}
|
|
94664
|
+
async function attempt(c, what, run, options = {}) {
|
|
94665
|
+
const deps = c.deps.mediaPlayerController;
|
|
94666
|
+
const settled = run().then(() => ({ ok: true }), (error) => ({
|
|
94667
|
+
ok: false,
|
|
94668
|
+
error
|
|
94669
|
+
}));
|
|
94670
|
+
let timer;
|
|
94671
|
+
const outcome = options.slow === true ? await Promise.race([settled, new Promise((resolve) => {
|
|
94672
|
+
timer = setTimeout(() => resolve(null), STEP_ANSWER_BUDGET_MS);
|
|
94673
|
+
})]) : await settled;
|
|
94674
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
94675
|
+
if (outcome === null) {
|
|
94676
|
+
deps.logger.info(`alexa media-player-controller: ${what} still sending, answered`, { tags: { deviceId: c.deviceId } });
|
|
94677
|
+
settled.then((late) => {
|
|
94678
|
+
if (!late.ok) deps.logger.warn(`alexa media-player-controller: ${what} failed after the answer`, {
|
|
94679
|
+
tags: { deviceId: c.deviceId },
|
|
94680
|
+
meta: { error: message(late.error) }
|
|
94681
|
+
});
|
|
94682
|
+
});
|
|
94683
|
+
return success(c, []);
|
|
94684
|
+
}
|
|
94685
|
+
if (!outcome.ok) {
|
|
94686
|
+
deps.logger.warn(`alexa media-player-controller: ${what} failed`, {
|
|
94687
|
+
tags: { deviceId: c.deviceId },
|
|
94688
|
+
meta: { error: message(outcome.error) }
|
|
94689
|
+
});
|
|
94690
|
+
return errorEnvelope(c.header, "ENDPOINT_UNREACHABLE", `the player did not accept ${what}`);
|
|
94691
|
+
}
|
|
94692
|
+
deps.logger.info(`alexa media-player-controller: ${what}`, { tags: { deviceId: c.deviceId } });
|
|
94693
|
+
return success(c, options.namespace === void 0 ? [] : await reportedProperties(c, options.namespace));
|
|
94694
|
+
}
|
|
94695
|
+
async function volume(c) {
|
|
94696
|
+
const payload = StepsPayload.safeParse(c.payload);
|
|
94697
|
+
if (!payload.success || payload.data.volumeSteps === 0) return errorEnvelope(c.header, "INVALID_DIRECTIVE", "volumeSteps is required");
|
|
94698
|
+
const steps = Math.min(Math.abs(payload.data.volumeSteps), 50);
|
|
94699
|
+
const api = c.deps.mediaPlayerController.ctx.api.mediaPlayer;
|
|
94700
|
+
const up = payload.data.volumeSteps > 0;
|
|
94701
|
+
return attempt(c, `volume ${up ? "up" : "down"} ${steps}`, () => up ? api.volumeUp.mutate({
|
|
94702
|
+
deviceId: c.deviceId,
|
|
94703
|
+
steps
|
|
94704
|
+
}) : api.volumeDown.mutate({
|
|
94705
|
+
deviceId: c.deviceId,
|
|
94706
|
+
steps
|
|
94707
|
+
}), { slow: true });
|
|
94708
|
+
}
|
|
94709
|
+
async function channel(c) {
|
|
94710
|
+
const payload = ChannelPayload.safeParse(c.payload);
|
|
94711
|
+
if (!payload.success || payload.data.channelCount === 0) return errorEnvelope(c.header, "INVALID_DIRECTIVE", "channelCount is required");
|
|
94712
|
+
const steps = Math.min(Math.abs(payload.data.channelCount), 50);
|
|
94713
|
+
const api = c.deps.mediaPlayerController.ctx.api.mediaPlayer;
|
|
94714
|
+
const up = payload.data.channelCount > 0;
|
|
94715
|
+
return attempt(c, `channel ${up ? "up" : "down"} ${steps}`, () => up ? api.channelUp.mutate({
|
|
94716
|
+
deviceId: c.deviceId,
|
|
94717
|
+
steps
|
|
94718
|
+
}) : api.channelDown.mutate({
|
|
94719
|
+
deviceId: c.deviceId,
|
|
94720
|
+
steps
|
|
94721
|
+
}), { slow: true });
|
|
94722
|
+
}
|
|
94723
|
+
async function mute(c) {
|
|
94724
|
+
const payload = MutePayload.safeParse(c.payload);
|
|
94725
|
+
if (!payload.success) return errorEnvelope(c.header, "INVALID_DIRECTIVE", "mute is required");
|
|
94726
|
+
const muted = payload.data.mute;
|
|
94727
|
+
const api = c.deps.mediaPlayerController.ctx.api.mediaPlayer;
|
|
94728
|
+
return attempt(c, `mute ${String(muted)}`, () => api.setMute.mutate({
|
|
94729
|
+
deviceId: c.deviceId,
|
|
94730
|
+
muted
|
|
94731
|
+
}), { namespace: "Alexa.Speaker" });
|
|
94732
|
+
}
|
|
94733
|
+
async function power$1(c) {
|
|
94734
|
+
const on = c.header.name === "TurnOn";
|
|
94735
|
+
const api = c.deps.mediaPlayerController.ctx.api.mediaPlayer;
|
|
94736
|
+
return attempt(c, on ? "turn on" : "turn off", () => on ? api.turnOn.mutate({ deviceId: c.deviceId }) : api.turnOff.mutate({ deviceId: c.deviceId }), { namespace: "Alexa.PowerController" });
|
|
94737
|
+
}
|
|
94738
|
+
async function playback(c) {
|
|
94739
|
+
const api = c.deps.mediaPlayerController.ctx.api.mediaPlayer;
|
|
94740
|
+
const input = { deviceId: c.deviceId };
|
|
94741
|
+
switch (c.header.name) {
|
|
94742
|
+
case "Play": return attempt(c, "play", () => api.play.mutate(input));
|
|
94743
|
+
case "Pause": return attempt(c, "pause", () => api.pause.mutate(input));
|
|
94744
|
+
case "Stop": return attempt(c, "stop", () => api.stop.mutate(input));
|
|
94745
|
+
case "Next": return attempt(c, "next", () => api.next.mutate(input));
|
|
94746
|
+
case "Previous": return attempt(c, "previous", () => api.previous.mutate(input));
|
|
94747
|
+
default: return errorEnvelope(c.header, "INVALID_DIRECTIVE", `unsupported ${c.header.name}`);
|
|
94748
|
+
}
|
|
94749
|
+
}
|
|
94750
|
+
async function selectInput(c) {
|
|
94751
|
+
const payload = InputPayload.safeParse(c.payload);
|
|
94752
|
+
if (!payload.success) return errorEnvelope(c.header, "INVALID_DIRECTIVE", "input is required");
|
|
94753
|
+
const deps = c.deps.mediaPlayerController;
|
|
94754
|
+
let source;
|
|
94755
|
+
try {
|
|
94756
|
+
const status = readMediaPlayerSlice(await deps.ctx.api.deviceState.getCapSlice.query({
|
|
94757
|
+
deviceId: c.deviceId,
|
|
94758
|
+
capName: CAP_MEDIA_PLAYER
|
|
94759
|
+
}));
|
|
94760
|
+
source = status === null ? void 0 : inputPairs(status).find((i) => i.amazon === payload.data.input)?.source;
|
|
94761
|
+
} catch (err) {
|
|
94762
|
+
deps.logger.warn("alexa media-player-controller: the sources could not be read", {
|
|
94763
|
+
tags: { deviceId: c.deviceId },
|
|
94764
|
+
meta: { error: message(err) }
|
|
94765
|
+
});
|
|
94766
|
+
return errorEnvelope(c.header, "ENDPOINT_UNREACHABLE", "the player sources could not be read");
|
|
94767
|
+
}
|
|
94768
|
+
if (source === void 0) return errorEnvelope(c.header, "INVALID_VALUE", `the player has no input ${payload.data.input}`);
|
|
94769
|
+
const chosen = source;
|
|
94770
|
+
return attempt(c, `select input ${chosen}`, () => deps.ctx.api.mediaPlayer.selectSource.mutate({
|
|
94771
|
+
deviceId: c.deviceId,
|
|
94772
|
+
source: chosen
|
|
94773
|
+
}), { namespace: "Alexa.InputController" });
|
|
94774
|
+
}
|
|
94775
|
+
/** The one handler behind every media-player directive. */
|
|
94776
|
+
async function handleMediaPlayerDirective(c) {
|
|
94777
|
+
switch (`${c.header.namespace}/${c.header.name}`) {
|
|
94778
|
+
case "Alexa.PowerController/TurnOn":
|
|
94779
|
+
case "Alexa.PowerController/TurnOff": return power$1(c);
|
|
94780
|
+
case "Alexa.StepSpeaker/AdjustVolume": return volume(c);
|
|
94781
|
+
case "Alexa.StepSpeaker/SetMute":
|
|
94782
|
+
case "Alexa.Speaker/SetMute": return mute(c);
|
|
94783
|
+
case "Alexa.ChannelController/SkipChannels": return channel(c);
|
|
94784
|
+
case "Alexa.InputController/SelectInput": return selectInput(c);
|
|
94785
|
+
default: return c.header.namespace === "Alexa.PlaybackController" ? playback(c) : errorEnvelope(c.header, "INVALID_DIRECTIVE", `unsupported ${c.header.name}`);
|
|
94786
|
+
}
|
|
94787
|
+
}
|
|
94788
|
+
//#endregion
|
|
94789
|
+
//#region src/endpoints/adapters/media-player.ts
|
|
94790
|
+
function directive(key, claims) {
|
|
94791
|
+
return {
|
|
94792
|
+
key,
|
|
94793
|
+
needsReachableDevice: true,
|
|
94794
|
+
handle: handleMediaPlayerDirective,
|
|
94795
|
+
...claims === void 0 ? {} : { claims }
|
|
94796
|
+
};
|
|
94797
|
+
}
|
|
94798
|
+
var DIRECTIVES = [
|
|
94799
|
+
directive("Alexa.PowerController/TurnOn", claimsMediaPlayerPower),
|
|
94800
|
+
directive("Alexa.PowerController/TurnOff", claimsMediaPlayerPower),
|
|
94801
|
+
directive("Alexa.StepSpeaker/AdjustVolume"),
|
|
94802
|
+
directive("Alexa.StepSpeaker/SetMute"),
|
|
94803
|
+
directive("Alexa.Speaker/SetMute"),
|
|
94804
|
+
directive("Alexa.ChannelController/SkipChannels"),
|
|
94805
|
+
directive("Alexa.PlaybackController/Play"),
|
|
94806
|
+
directive("Alexa.PlaybackController/Pause"),
|
|
94807
|
+
directive("Alexa.PlaybackController/Stop"),
|
|
94808
|
+
directive("Alexa.PlaybackController/Next"),
|
|
94809
|
+
directive("Alexa.PlaybackController/Previous"),
|
|
94810
|
+
directive("Alexa.InputController/SelectInput")
|
|
94811
|
+
];
|
|
94812
|
+
/**
|
|
94813
|
+
* `media-player` → a TV: power, step volume, mute, channel steps, transport and
|
|
94814
|
+
* inputs, each only when the player says it can (features) and, for the ones
|
|
94815
|
+
* that need a reading, only when it reports one. Registered before `switch`: a
|
|
94816
|
+
* TV is a TV, not a SWITCH.
|
|
94817
|
+
*/
|
|
94818
|
+
var mediaPlayerAdapter = {
|
|
94819
|
+
cap: CAP_MEDIA_PLAYER,
|
|
94820
|
+
stateCaps: [CAP_MEDIA_PLAYER],
|
|
94821
|
+
discoveryReads: [CAP_MEDIA_PLAYER],
|
|
94822
|
+
describe: (device) => {
|
|
94823
|
+
const capabilities = describeMediaPlayerCapabilities(device);
|
|
94824
|
+
if (capabilities.length === 0) return {
|
|
94825
|
+
kind: "skip",
|
|
94826
|
+
reason: "the media player offers nothing Alexa can drive"
|
|
94827
|
+
};
|
|
94828
|
+
return {
|
|
94829
|
+
kind: "publish",
|
|
94830
|
+
capabilities,
|
|
94831
|
+
category: "TV"
|
|
94832
|
+
};
|
|
94833
|
+
},
|
|
94834
|
+
properties: (_cap, slice) => mediaPlayerProperties(slice),
|
|
94835
|
+
directives: DIRECTIVES,
|
|
94836
|
+
shaping: () => null
|
|
94837
|
+
};
|
|
94838
|
+
//#endregion
|
|
93536
94839
|
//#region src/endpoints/adapters/motion.ts
|
|
93537
94840
|
/** `motion` → `Alexa.MotionSensor` (MOTION_SENSOR). */
|
|
93538
94841
|
var motionAdapter = {
|
|
@@ -93740,6 +95043,7 @@ var GENERIC_ADAPTERS = [
|
|
|
93740
95043
|
temperatureAdapter,
|
|
93741
95044
|
humidityAdapter,
|
|
93742
95045
|
fanAdapter,
|
|
95046
|
+
mediaPlayerAdapter,
|
|
93743
95047
|
{
|
|
93744
95048
|
cap: "switch",
|
|
93745
95049
|
stateCaps: ["switch", "brightness"],
|
|
@@ -93875,6 +95179,7 @@ var GENERIC_DEVICE_TYPES = [
|
|
|
93875
95179
|
"climate",
|
|
93876
95180
|
"cover",
|
|
93877
95181
|
"fan",
|
|
95182
|
+
"media-player",
|
|
93878
95183
|
"generic"
|
|
93879
95184
|
];
|
|
93880
95185
|
function toEndpoint(input, plan) {
|
|
@@ -95476,7 +96781,12 @@ var ALLOWED_INTERFACE_VERSIONS = {
|
|
|
95476
96781
|
"Alexa.SmartVision.SnapshotProvider": "1.1",
|
|
95477
96782
|
"Alexa.SmartVision.ObjectDetectionSensor": "1.0",
|
|
95478
96783
|
"Alexa.DataController": "1.0",
|
|
95479
|
-
"Alexa.SceneController": "3"
|
|
96784
|
+
"Alexa.SceneController": "3",
|
|
96785
|
+
"Alexa.StepSpeaker": "3",
|
|
96786
|
+
"Alexa.Speaker": "3",
|
|
96787
|
+
"Alexa.ChannelController": "3",
|
|
96788
|
+
"Alexa.PlaybackController": "3",
|
|
96789
|
+
"Alexa.InputController": "3"
|
|
95480
96790
|
};
|
|
95481
96791
|
/** `imageNetClass` values Amazon accepts (alexa-smartvision-objectdetectionsensor). */
|
|
95482
96792
|
var SMART_VISION_CLASSES = new Set(["person", "package"]);
|
|
@@ -95516,6 +96826,7 @@ var DISPLAY_CATEGORIES = new Set([
|
|
|
95516
96826
|
"THERMOSTAT",
|
|
95517
96827
|
"AIR_CONDITIONER",
|
|
95518
96828
|
"FAN",
|
|
96829
|
+
"TV",
|
|
95519
96830
|
"DOOR",
|
|
95520
96831
|
"GATE",
|
|
95521
96832
|
"GARAGE_DOOR",
|
|
@@ -99666,12 +100977,30 @@ function troubleshootingSection() {
|
|
|
99666
100977
|
]
|
|
99667
100978
|
};
|
|
99668
100979
|
}
|
|
99669
|
-
/**
|
|
99670
|
-
|
|
99671
|
-
function customSkillSecuritySection(input) {
|
|
100980
|
+
/** The enforcement switch of the custom skill's ingress token: part of the skill instance. */
|
|
100981
|
+
function instanceSecuritySection(input) {
|
|
99672
100982
|
return {
|
|
99673
100983
|
id: "export-alexa-custom-security",
|
|
99674
100984
|
title: "Custom-skill security",
|
|
100985
|
+
columns: 1,
|
|
100986
|
+
fields: [{
|
|
100987
|
+
type: "boolean",
|
|
100988
|
+
key: "enforceIngressToken",
|
|
100989
|
+
label: "Require ingress token",
|
|
100990
|
+
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.",
|
|
100991
|
+
default: input.defaults.enforceIngressToken,
|
|
100992
|
+
showWhen: CUSTOM_SKILL_ONLY
|
|
100993
|
+
}]
|
|
100994
|
+
};
|
|
100995
|
+
}
|
|
100996
|
+
/** Custom skill only: the public skill's shared Lambda sends one ingress token
|
|
100997
|
+
* for every hub (`HUB_INGRESS_TOKEN`), so a per-hub token cannot apply to it. The rows are
|
|
100998
|
+
* built only for a custom skill: the mode is not a field of this page. */
|
|
100999
|
+
function customSkillSecuritySection(input) {
|
|
101000
|
+
if (input.skillMode !== "custom") return null;
|
|
101001
|
+
return {
|
|
101002
|
+
id: "export-alexa-custom-security-token",
|
|
101003
|
+
title: "Custom-skill ingress token",
|
|
99675
101004
|
style: "accordion",
|
|
99676
101005
|
defaultCollapsed: true,
|
|
99677
101006
|
columns: 1,
|
|
@@ -99681,8 +101010,7 @@ function customSkillSecuritySection(input) {
|
|
|
99681
101010
|
key: "__ingress-token-info",
|
|
99682
101011
|
label: "Ingress token",
|
|
99683
101012
|
variant: "info",
|
|
99684
|
-
|
|
99685
|
-
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."
|
|
101013
|
+
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."
|
|
99686
101014
|
},
|
|
99687
101015
|
{
|
|
99688
101016
|
type: "addon-action-button",
|
|
@@ -99693,8 +101021,7 @@ function customSkillSecuritySection(input) {
|
|
|
99693
101021
|
buttonLabel: "Show ingress token",
|
|
99694
101022
|
action: "revealIngressToken",
|
|
99695
101023
|
variant: "default",
|
|
99696
|
-
successMessage: "Ingress token: {ingressToken}"
|
|
99697
|
-
showWhen: CUSTOM_SKILL_ONLY
|
|
101024
|
+
successMessage: "Ingress token: {ingressToken}"
|
|
99698
101025
|
},
|
|
99699
101026
|
{
|
|
99700
101027
|
type: "addon-action-button",
|
|
@@ -99706,27 +101033,25 @@ function customSkillSecuritySection(input) {
|
|
|
99706
101033
|
action: "regenerateIngressToken",
|
|
99707
101034
|
variant: "default",
|
|
99708
101035
|
successMessage: "New ingress token: {ingressToken} — put it in HUB_INGRESS_TOKEN now.",
|
|
99709
|
-
confirmMessage: "Rotate the ingress token? With \"Require ingress token\" on, the Lambda is refused until you update HUB_INGRESS_TOKEN."
|
|
99710
|
-
showWhen: CUSTOM_SKILL_ONLY
|
|
99711
|
-
},
|
|
99712
|
-
{
|
|
99713
|
-
type: "boolean",
|
|
99714
|
-
key: "enforceIngressToken",
|
|
99715
|
-
label: "Require ingress token",
|
|
99716
|
-
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.",
|
|
99717
|
-
default: input.defaults.enforceIngressToken,
|
|
99718
|
-
showWhen: CUSTOM_SKILL_ONLY
|
|
101036
|
+
confirmMessage: "Rotate the ingress token? With \"Require ingress token\" on, the Lambda is refused until you update HUB_INGRESS_TOKEN."
|
|
99719
101037
|
}
|
|
99720
101038
|
]
|
|
99721
101039
|
};
|
|
99722
101040
|
}
|
|
99723
|
-
|
|
101041
|
+
/** The skill instance's form (`skills` record). */
|
|
101042
|
+
function buildAlexaInstanceSections(input) {
|
|
99724
101043
|
return [
|
|
99725
101044
|
connectionSection(input),
|
|
99726
101045
|
featuresSection(input),
|
|
101046
|
+
instanceSecuritySection(input)
|
|
101047
|
+
];
|
|
101048
|
+
}
|
|
101049
|
+
function buildAlexaSettingsSections(input) {
|
|
101050
|
+
const security = customSkillSecuritySection(input);
|
|
101051
|
+
return [
|
|
99727
101052
|
accountLinkSection(input),
|
|
99728
101053
|
troubleshootingSection(),
|
|
99729
|
-
|
|
101054
|
+
...security === null ? [] : [security]
|
|
99730
101055
|
];
|
|
99731
101056
|
}
|
|
99732
101057
|
//#endregion
|
|
@@ -100461,7 +101786,7 @@ var ALEXA_ADDON_ID = "export-alexa";
|
|
|
100461
101786
|
* key, id `<addonId>.<key>`, data `{ addonId, key, value }` (never a per-addon scoped table,
|
|
100462
101787
|
* which exists only when something lazily declared it).
|
|
100463
101788
|
*/
|
|
100464
|
-
var ADDON_SETTINGS_TABLE = "addon-settings";
|
|
101789
|
+
var ADDON_SETTINGS_TABLE$1 = "addon-settings";
|
|
100465
101790
|
var RETIRED_PUBLIC_URL_KEYS = ["publicHubUrl"];
|
|
100466
101791
|
async function planDropPublicHubUrl(ports) {
|
|
100467
101792
|
const stored = await ports.readStored();
|
|
@@ -100470,7 +101795,7 @@ async function planDropPublicHubUrl(ports) {
|
|
|
100470
101795
|
const rowId = (key) => `${ALEXA_ADDON_ID}.${key}`;
|
|
100471
101796
|
return { edits: [{
|
|
100472
101797
|
op: "deleteKeys",
|
|
100473
|
-
scope: ADDON_SETTINGS_TABLE,
|
|
101798
|
+
scope: ADDON_SETTINGS_TABLE$1,
|
|
100474
101799
|
keys: present.map(rowId),
|
|
100475
101800
|
precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
|
|
100476
101801
|
addonId: ALEXA_ADDON_ID,
|
|
@@ -100480,24 +101805,351 @@ async function planDropPublicHubUrl(ports) {
|
|
|
100480
101805
|
}] };
|
|
100481
101806
|
}
|
|
100482
101807
|
//#endregion
|
|
101808
|
+
//#region src/skill-records.ts
|
|
101809
|
+
/**
|
|
101810
|
+
* The Alexa export as an integration instance (D985, D996): ONE `skills` record, owned by
|
|
101811
|
+
* `export-alexa` and named after it, holds how the skill reaches this hub and what each exposed
|
|
101812
|
+
* camera carries. The two ledgers of the link (`linkedAccounts`, `tokens`) are a second record,
|
|
101813
|
+
* `skill-links`, under the SAME id: the instance they belong to. The tokens' credentials are
|
|
101814
|
+
* keychain markers bound to that row, matched by user id so a reorder keeps every ref.
|
|
101815
|
+
*/
|
|
101816
|
+
/** A single-instance addon keeps its records under its own addon id. */
|
|
101817
|
+
var ALEXA_INSTANCE_ID = "export-alexa";
|
|
101818
|
+
var alexaSkillsKind = defineEntryKind("skills", {
|
|
101819
|
+
title: "Alexa skill",
|
|
101820
|
+
nameField: "name",
|
|
101821
|
+
schema: object({
|
|
101822
|
+
name: string().min(1),
|
|
101823
|
+
skillMode: _enum(["public", "custom"]),
|
|
101824
|
+
region: _enum([
|
|
101825
|
+
"NA",
|
|
101826
|
+
"EU",
|
|
101827
|
+
"FE"
|
|
101828
|
+
]),
|
|
101829
|
+
expectedAudience: string(),
|
|
101830
|
+
detectionSensors: boolean(),
|
|
101831
|
+
objectDetection: boolean(),
|
|
101832
|
+
snapshots: boolean(),
|
|
101833
|
+
enforceIngressToken: boolean(),
|
|
101834
|
+
enabled: boolean().optional()
|
|
101835
|
+
})
|
|
101836
|
+
});
|
|
101837
|
+
/** What a skill starts as: the defaults the addon's constructor used to carry. */
|
|
101838
|
+
var ALEXA_SKILL_DEFAULT_BODY = {
|
|
101839
|
+
skillMode: "public",
|
|
101840
|
+
region: "NA",
|
|
101841
|
+
expectedAudience: "",
|
|
101842
|
+
detectionSensors: true,
|
|
101843
|
+
objectDetection: true,
|
|
101844
|
+
snapshots: true,
|
|
101845
|
+
enforceIngressToken: false
|
|
101846
|
+
};
|
|
101847
|
+
/** The settings keys that moved into the `skills` record; the migrations name them. */
|
|
101848
|
+
var MOVED_SKILL_KEYS = [
|
|
101849
|
+
"skillMode",
|
|
101850
|
+
"region",
|
|
101851
|
+
"expectedAudience",
|
|
101852
|
+
"detectionSensors",
|
|
101853
|
+
"objectDetection",
|
|
101854
|
+
"snapshots",
|
|
101855
|
+
"enforceIngressToken"
|
|
101856
|
+
];
|
|
101857
|
+
/** The ledger keys that moved into the `skill-links` record. */
|
|
101858
|
+
var MOVED_LEDGER_KEYS = ["linkedAccounts", "tokens"];
|
|
101859
|
+
var LinkedAccountSchema = object({
|
|
101860
|
+
userId: string(),
|
|
101861
|
+
username: string(),
|
|
101862
|
+
linkedAt: number()
|
|
101863
|
+
});
|
|
101864
|
+
var LwaTokenEntrySchema = object({
|
|
101865
|
+
userId: string(),
|
|
101866
|
+
accessToken: string().meta({ secret: true }),
|
|
101867
|
+
expiresAt: number(),
|
|
101868
|
+
receivedAt: number(),
|
|
101869
|
+
refreshToken: string().optional().meta({ secret: true }),
|
|
101870
|
+
brokerUrl: string().optional(),
|
|
101871
|
+
brokerCredential: string().optional().meta({ secret: true })
|
|
101872
|
+
});
|
|
101873
|
+
var alexaSkillLinksKind = defineEntryKind("skill-links", {
|
|
101874
|
+
title: "Alexa account links",
|
|
101875
|
+
nameField: "name",
|
|
101876
|
+
schema: object({
|
|
101877
|
+
name: string().min(1),
|
|
101878
|
+
linkedAccounts: array(LinkedAccountSchema),
|
|
101879
|
+
tokens: array(LwaTokenEntrySchema)
|
|
101880
|
+
}),
|
|
101881
|
+
secretArrayKeys: { tokens: "userId" }
|
|
101882
|
+
});
|
|
101883
|
+
//#endregion
|
|
101884
|
+
//#region src/migrations/settings-to-records.ts
|
|
101885
|
+
/**
|
|
101886
|
+
* The Alexa export's settings move into records (D985, D996). Three migrations of the catalogue
|
|
101887
|
+
* after the retired-URL one, each idempotent, in this order:
|
|
101888
|
+
*
|
|
101889
|
+
* 2. `moveSettingsToSkill` (procedure): the seven skill settings become the `skills` record.
|
|
101890
|
+
* An existing record is never overwritten.
|
|
101891
|
+
* 3. `moveLedgersToLinks` (procedure): `linkedAccounts` and `tokens` become the `skill-links`
|
|
101892
|
+
* record. The record is read BACK (credentials resolved) and must equal what the old
|
|
101893
|
+
* settings carried, byte for byte, BEFORE the old token credentials are cleared; any
|
|
101894
|
+
* difference throws and clears nothing. An existing record is never overwritten.
|
|
101895
|
+
* 4. `planDropMovedSettings` (plan): the moved keys are deleted from the canonical
|
|
101896
|
+
* `addon-settings` rows, and only while the records are confirmed to hold what they carried.
|
|
101897
|
+
*
|
|
101898
|
+
* All three are `tolerate`: the addon keeps reading the legacy keys until a record exists.
|
|
101899
|
+
*/
|
|
101900
|
+
/** The canonical `addon-settings` table: one row per key, id `<addonId>.<key>`. */
|
|
101901
|
+
var ADDON_SETTINGS_TABLE = "addon-settings";
|
|
101902
|
+
var SKILL_NAME = "Alexa skill";
|
|
101903
|
+
var LINKS_NAME = "Alexa account links";
|
|
101904
|
+
function text(stored, key) {
|
|
101905
|
+
const value = stored[key];
|
|
101906
|
+
return typeof value === "string" ? value.trim() : "";
|
|
101907
|
+
}
|
|
101908
|
+
function flag(stored, key, fallback) {
|
|
101909
|
+
const value = stored[key];
|
|
101910
|
+
return typeof value === "boolean" ? value : fallback;
|
|
101911
|
+
}
|
|
101912
|
+
/** The record body the legacy settings describe; a missing or mistyped key takes the default. */
|
|
101913
|
+
function skillBodyFrom(stored) {
|
|
101914
|
+
const d = ALEXA_SKILL_DEFAULT_BODY;
|
|
101915
|
+
const region = stored["region"];
|
|
101916
|
+
return {
|
|
101917
|
+
name: SKILL_NAME,
|
|
101918
|
+
skillMode: stored["skillMode"] === "custom" ? "custom" : "public",
|
|
101919
|
+
region: region === "EU" || region === "FE" ? region : "NA",
|
|
101920
|
+
expectedAudience: text(stored, "expectedAudience"),
|
|
101921
|
+
detectionSensors: flag(stored, "detectionSensors", d.detectionSensors),
|
|
101922
|
+
objectDetection: flag(stored, "objectDetection", d.objectDetection),
|
|
101923
|
+
snapshots: flag(stored, "snapshots", d.snapshots),
|
|
101924
|
+
enforceIngressToken: flag(stored, "enforceIngressToken", d.enforceIngressToken)
|
|
101925
|
+
};
|
|
101926
|
+
}
|
|
101927
|
+
async function moveSettingsToSkill(ports) {
|
|
101928
|
+
const stored = await ports.readStored();
|
|
101929
|
+
if (!MOVED_SKILL_KEYS.some((key) => key in stored)) return {
|
|
101930
|
+
outcome: "already-done",
|
|
101931
|
+
summary: { moved: false }
|
|
101932
|
+
};
|
|
101933
|
+
return await ports.putSkill(skillBodyFrom(stored)) === "created" ? {
|
|
101934
|
+
outcome: "done",
|
|
101935
|
+
summary: { moved: true }
|
|
101936
|
+
} : {
|
|
101937
|
+
outcome: "already-done",
|
|
101938
|
+
summary: { moved: false }
|
|
101939
|
+
};
|
|
101940
|
+
}
|
|
101941
|
+
function accountsOf(value) {
|
|
101942
|
+
return Array.isArray(value) ? value.filter(isLinkedAccount) : [];
|
|
101943
|
+
}
|
|
101944
|
+
function tokensOf(value) {
|
|
101945
|
+
return Array.isArray(value) ? value.filter(isTokenEntry) : [];
|
|
101946
|
+
}
|
|
101947
|
+
function isLinkedAccount(value) {
|
|
101948
|
+
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";
|
|
101949
|
+
}
|
|
101950
|
+
function isTokenEntry(value) {
|
|
101951
|
+
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";
|
|
101952
|
+
}
|
|
101953
|
+
/** Key-order-independent JSON, so "byte-identical" does not depend on how a store orders keys. */
|
|
101954
|
+
function canonical(value) {
|
|
101955
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
101956
|
+
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(",")}}`;
|
|
101957
|
+
return JSON.stringify(value) ?? "null";
|
|
101958
|
+
}
|
|
101959
|
+
async function moveLedgersToLinks(ports) {
|
|
101960
|
+
const stored = await ports.readStored();
|
|
101961
|
+
if (!MOVED_LEDGER_KEYS.some((key) => key in stored)) return {
|
|
101962
|
+
outcome: "already-done",
|
|
101963
|
+
summary: { moved: false }
|
|
101964
|
+
};
|
|
101965
|
+
const linkedAccounts = accountsOf(stored["linkedAccounts"]);
|
|
101966
|
+
const tokens = tokensOf(stored["tokens"]);
|
|
101967
|
+
const put = await ports.putLinks({
|
|
101968
|
+
name: LINKS_NAME,
|
|
101969
|
+
linkedAccounts,
|
|
101970
|
+
tokens
|
|
101971
|
+
});
|
|
101972
|
+
let held = await ports.readLinks();
|
|
101973
|
+
const matches = (record) => record !== null && canonical(record.linkedAccounts) === canonical(linkedAccounts) && canonical(record.tokens) === canonical(tokens);
|
|
101974
|
+
if (put === "exists" && !matches(held) && isCoveredBy(held, linkedAccounts, tokens)) {
|
|
101975
|
+
await ports.replaceLinks({
|
|
101976
|
+
name: LINKS_NAME,
|
|
101977
|
+
linkedAccounts,
|
|
101978
|
+
tokens
|
|
101979
|
+
});
|
|
101980
|
+
held = await ports.readLinks();
|
|
101981
|
+
}
|
|
101982
|
+
if (!matches(held)) {
|
|
101983
|
+
ports.warn("Alexa migration: the skill-links record does not hold what the settings carried; the legacy ledgers are kept");
|
|
101984
|
+
if (put === "created") throw new Error("the Alexa link record does not match the legacy settings; nothing was cleared");
|
|
101985
|
+
return {
|
|
101986
|
+
outcome: "already-done",
|
|
101987
|
+
summary: { moved: false }
|
|
101988
|
+
};
|
|
101989
|
+
}
|
|
101990
|
+
if (tokens.length > 0) await ports.clearOldTokenSecrets();
|
|
101991
|
+
return put === "created" ? {
|
|
101992
|
+
outcome: "done",
|
|
101993
|
+
summary: {
|
|
101994
|
+
moved: true,
|
|
101995
|
+
accounts: linkedAccounts.length
|
|
101996
|
+
}
|
|
101997
|
+
} : {
|
|
101998
|
+
outcome: "done",
|
|
101999
|
+
summary: {
|
|
102000
|
+
moved: true,
|
|
102001
|
+
repaired: true,
|
|
102002
|
+
accounts: linkedAccounts.length
|
|
102003
|
+
}
|
|
102004
|
+
};
|
|
102005
|
+
}
|
|
102006
|
+
/**
|
|
102007
|
+
* The record carries this migration's own name and every account and grant it holds is also in
|
|
102008
|
+
* the settings: rewriting it loses nothing and touches nothing an operator named.
|
|
102009
|
+
*/
|
|
102010
|
+
function isCoveredBy(held, linkedAccounts, tokens) {
|
|
102011
|
+
if (held === null || held.name !== LINKS_NAME) return false;
|
|
102012
|
+
const accounts = new Set(linkedAccounts.map((a) => a.userId));
|
|
102013
|
+
const grants = new Set(tokens.map((t) => t.userId));
|
|
102014
|
+
return held.linkedAccounts.every((a) => accounts.has(a.userId)) && held.tokens.every((t) => grants.has(t.userId));
|
|
102015
|
+
}
|
|
102016
|
+
/**
|
|
102017
|
+
* A ledger key the drop may judge: absent, a list, or the leftover of a credential clear
|
|
102018
|
+
* (`{ $secretClear: true }`, stored where a list belongs by an older build). Anything else is
|
|
102019
|
+
* not understood, so nothing is deleted on its account.
|
|
102020
|
+
*/
|
|
102021
|
+
function isLedgerShape(value) {
|
|
102022
|
+
return value === void 0 || Array.isArray(value) || isSecretClear(value);
|
|
102023
|
+
}
|
|
102024
|
+
/** Whether a stored token entry still carries a credential: text, or a keychain marker. */
|
|
102025
|
+
function carriesCredential(entry) {
|
|
102026
|
+
if (typeof entry !== "object" || entry === null) return false;
|
|
102027
|
+
return [
|
|
102028
|
+
"accessToken",
|
|
102029
|
+
"refreshToken",
|
|
102030
|
+
"brokerCredential"
|
|
102031
|
+
].some((key) => {
|
|
102032
|
+
const value = Reflect.get(entry, key);
|
|
102033
|
+
if (typeof value === "string") return value.length > 0;
|
|
102034
|
+
return typeof value === "object" && value !== null;
|
|
102035
|
+
});
|
|
102036
|
+
}
|
|
102037
|
+
var rowId = (key) => `${ALEXA_INSTANCE_ID}.${key}`;
|
|
102038
|
+
async function planDropMovedSettings(ports) {
|
|
102039
|
+
const stored = await ports.readRawStored();
|
|
102040
|
+
const skillKeys = MOVED_SKILL_KEYS.filter((key) => key in stored);
|
|
102041
|
+
const ledgerKeys = MOVED_LEDGER_KEYS.filter((key) => key in stored);
|
|
102042
|
+
if (skillKeys.length === 0 && ledgerKeys.length === 0) return { edits: [] };
|
|
102043
|
+
const refuse = (reason) => {
|
|
102044
|
+
ports.warn(`Alexa migration: the legacy keys are kept: ${reason}`);
|
|
102045
|
+
throw new Error(`the legacy Alexa keys are not deleted: ${reason}`);
|
|
102046
|
+
};
|
|
102047
|
+
if (skillKeys.length > 0 && !await ports.hasSkill()) return refuse("no Alexa skill record exists");
|
|
102048
|
+
if (ledgerKeys.length > 0) {
|
|
102049
|
+
const links = await ports.readLinks();
|
|
102050
|
+
if (links === null) return refuse("no Alexa link record exists");
|
|
102051
|
+
if (!isLedgerShape(stored["linkedAccounts"])) return refuse("the old linkedAccounts setting is not a list the migration understands");
|
|
102052
|
+
if (!isLedgerShape(stored["tokens"])) return refuse("the old tokens setting is not a list the migration understands");
|
|
102053
|
+
const legacyTokens = stored["tokens"];
|
|
102054
|
+
if (Array.isArray(legacyTokens) && legacyTokens.some(carriesCredential)) return refuse("the old settings still carry Amazon push credentials");
|
|
102055
|
+
const heldAccounts = new Map(links.linkedAccounts.map((a) => [a.userId, a]));
|
|
102056
|
+
const heldTokens = new Set(links.tokens.map((t) => t.userId));
|
|
102057
|
+
for (const account of accountsOf(stored["linkedAccounts"])) {
|
|
102058
|
+
const held = heldAccounts.get(account.userId);
|
|
102059
|
+
if (held === void 0) return refuse(`the record lacks the account ${account.userId}`);
|
|
102060
|
+
if (canonical(held) !== canonical(account)) return refuse(`the record holds the account ${account.userId} differently`);
|
|
102061
|
+
}
|
|
102062
|
+
for (const token of tokensOf(stored["tokens"])) if (!heldTokens.has(token.userId)) return refuse(`the record lacks the grant ${token.userId}`);
|
|
102063
|
+
}
|
|
102064
|
+
const present = [...skillKeys, ...ledgerKeys];
|
|
102065
|
+
return { edits: [{
|
|
102066
|
+
op: "deleteKeys",
|
|
102067
|
+
scope: ADDON_SETTINGS_TABLE,
|
|
102068
|
+
keys: present.map(rowId),
|
|
102069
|
+
precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
|
|
102070
|
+
addonId: ALEXA_INSTANCE_ID,
|
|
102071
|
+
key,
|
|
102072
|
+
value: stored[key]
|
|
102073
|
+
}])))
|
|
102074
|
+
}] };
|
|
102075
|
+
}
|
|
102076
|
+
//#endregion
|
|
100483
102077
|
//#region src/migrations/index.ts
|
|
100484
|
-
|
|
100485
|
-
var
|
|
100486
|
-
|
|
100487
|
-
|
|
100488
|
-
|
|
100489
|
-
|
|
100490
|
-
|
|
100491
|
-
|
|
100492
|
-
|
|
100493
|
-
|
|
100494
|
-
|
|
100495
|
-
|
|
100496
|
-
|
|
100497
|
-
|
|
100498
|
-
|
|
100499
|
-
|
|
100500
|
-
|
|
102078
|
+
var DROP_PUBLIC_HUB_URL_ID = "export-alexa/2026-11-02-drop-public-hub-url";
|
|
102079
|
+
var SETTINGS_TO_INTEGRATION_ID = "export-alexa/2026-11-03-settings-to-integration";
|
|
102080
|
+
var LEDGERS_TO_INTEGRATION_ID = "export-alexa/2026-11-03-ledgers-to-integration";
|
|
102081
|
+
var DROP_MOVED_SETTINGS_ID = "export-alexa/2026-11-03-drop-moved-settings";
|
|
102082
|
+
var FIXTURE_MARK = "the exposed device list the migration does not know";
|
|
102083
|
+
/**
|
|
102084
|
+
* The `export-alexa` catalogue (D987): offered to the engine when the addon initialises. Every
|
|
102085
|
+
* entry is `tolerate`; until a record exists the addon keeps reading the legacy keys.
|
|
102086
|
+
*/
|
|
102087
|
+
var ADDON_MIGRATIONS = [
|
|
102088
|
+
{
|
|
102089
|
+
meta: {
|
|
102090
|
+
id: DROP_PUBLIC_HUB_URL_ID,
|
|
102091
|
+
owner: "export-alexa",
|
|
102092
|
+
level: "addon-state",
|
|
102093
|
+
seq: 1,
|
|
102094
|
+
dependsOn: [],
|
|
102095
|
+
store: "settings",
|
|
102096
|
+
scope: "cluster",
|
|
102097
|
+
onFailure: "tolerate",
|
|
102098
|
+
bodyKind: "plan",
|
|
102099
|
+
description: "Delete the retired publicHubUrl setting; the public URL is the publicEndpoint role",
|
|
102100
|
+
fixtureMark: FIXTURE_MARK
|
|
102101
|
+
},
|
|
102102
|
+
plan: planDropPublicHubUrl
|
|
102103
|
+
},
|
|
102104
|
+
{
|
|
102105
|
+
meta: {
|
|
102106
|
+
id: SETTINGS_TO_INTEGRATION_ID,
|
|
102107
|
+
owner: "export-alexa",
|
|
102108
|
+
level: "addon-state",
|
|
102109
|
+
seq: 2,
|
|
102110
|
+
dependsOn: [],
|
|
102111
|
+
store: "settings",
|
|
102112
|
+
scope: "cluster",
|
|
102113
|
+
onFailure: "tolerate",
|
|
102114
|
+
bodyKind: "procedure",
|
|
102115
|
+
description: "Move the Alexa skill settings (mode, region, audience, feature switches) into the skills record",
|
|
102116
|
+
fixtureMark: FIXTURE_MARK
|
|
102117
|
+
},
|
|
102118
|
+
procedure: moveSettingsToSkill
|
|
102119
|
+
},
|
|
102120
|
+
{
|
|
102121
|
+
meta: {
|
|
102122
|
+
id: LEDGERS_TO_INTEGRATION_ID,
|
|
102123
|
+
owner: "export-alexa",
|
|
102124
|
+
level: "addon-state",
|
|
102125
|
+
seq: 3,
|
|
102126
|
+
dependsOn: [SETTINGS_TO_INTEGRATION_ID],
|
|
102127
|
+
store: "settings",
|
|
102128
|
+
scope: "cluster",
|
|
102129
|
+
onFailure: "tolerate",
|
|
102130
|
+
bodyKind: "procedure",
|
|
102131
|
+
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",
|
|
102132
|
+
fixtureMark: FIXTURE_MARK
|
|
102133
|
+
},
|
|
102134
|
+
procedure: moveLedgersToLinks
|
|
102135
|
+
},
|
|
102136
|
+
{
|
|
102137
|
+
meta: {
|
|
102138
|
+
id: DROP_MOVED_SETTINGS_ID,
|
|
102139
|
+
owner: "export-alexa",
|
|
102140
|
+
level: "addon-state",
|
|
102141
|
+
seq: 4,
|
|
102142
|
+
dependsOn: [SETTINGS_TO_INTEGRATION_ID, LEDGERS_TO_INTEGRATION_ID],
|
|
102143
|
+
store: "settings",
|
|
102144
|
+
scope: "cluster",
|
|
102145
|
+
onFailure: "tolerate",
|
|
102146
|
+
bodyKind: "plan",
|
|
102147
|
+
description: "Delete the Alexa settings and ledger keys that moved into the records",
|
|
102148
|
+
fixtureMark: FIXTURE_MARK
|
|
102149
|
+
},
|
|
102150
|
+
plan: planDropMovedSettings
|
|
102151
|
+
}
|
|
102152
|
+
];
|
|
100501
102153
|
//#endregion
|
|
100502
102154
|
//#region src/oauth-integration.ts
|
|
100503
102155
|
/**
|
|
@@ -101840,6 +103492,11 @@ var SUPPORTED_KINDS = [
|
|
|
101840
103492
|
DeviceType.Cover,
|
|
101841
103493
|
DeviceType.Generic
|
|
101842
103494
|
];
|
|
103495
|
+
/** Whether a stored token entry still carries a keychain marker instead of a resolved credential. */
|
|
103496
|
+
function hasUnresolvedCredential(entry) {
|
|
103497
|
+
if (typeof entry !== "object" || entry === null) return false;
|
|
103498
|
+
return "accessToken" in entry && isSecretMarker(entry.accessToken) || "refreshToken" in entry && isSecretMarker(entry.refreshToken) || "brokerCredential" in entry && isSecretMarker(entry.brokerCredential);
|
|
103499
|
+
}
|
|
101843
103500
|
var ExportAlexaAddon = class extends BaseAddon {
|
|
101844
103501
|
/** Hidden state that is a credential — kept in the keychain, never the blob (D787). */
|
|
101845
103502
|
secretStatePaths = [
|
|
@@ -101875,13 +103532,85 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
101875
103532
|
constructor() {
|
|
101876
103533
|
super({ ...DEFAULT_CONFIG });
|
|
101877
103534
|
}
|
|
103535
|
+
instances = null;
|
|
103536
|
+
/** The `skills` record, once it exists; until then the legacy settings keys answer. */
|
|
103537
|
+
skillRow = null;
|
|
103538
|
+
/** The `skill-links` record, once it exists; until then the legacy ledger keys answer. */
|
|
103539
|
+
linksRow = null;
|
|
103540
|
+
/** The keychain refused the link credentials: the ledger is read-only until it answers (D49). */
|
|
103541
|
+
linksLocked = false;
|
|
103542
|
+
/**
|
|
103543
|
+
* The legacy ledger keys as lists. A store written by an older build may hold something that
|
|
103544
|
+
* is not a list there (a clear instruction stored as the value); the page and the gateway read
|
|
103545
|
+
* a list or nothing.
|
|
103546
|
+
*/
|
|
103547
|
+
legacyLedgers() {
|
|
103548
|
+
return {
|
|
103549
|
+
linkedAccounts: Array.isArray(this.config.linkedAccounts) ? this.config.linkedAccounts : [],
|
|
103550
|
+
tokens: Array.isArray(this.config.tokens) ? this.config.tokens : []
|
|
103551
|
+
};
|
|
103552
|
+
}
|
|
103553
|
+
/**
|
|
103554
|
+
* The settings as the addon reads them: the records where they exist, the legacy keys until
|
|
103555
|
+
* the migrations have moved them.
|
|
103556
|
+
*/
|
|
103557
|
+
get view() {
|
|
103558
|
+
const skill = this.skillRow;
|
|
103559
|
+
const links = this.linksRow;
|
|
103560
|
+
const legacy = this.legacyLedgers();
|
|
103561
|
+
if (skill === null && links === null) return {
|
|
103562
|
+
...this.config,
|
|
103563
|
+
...legacy
|
|
103564
|
+
};
|
|
103565
|
+
return {
|
|
103566
|
+
...this.config,
|
|
103567
|
+
...legacy,
|
|
103568
|
+
...skill === null ? {} : {
|
|
103569
|
+
skillMode: skill.skillMode,
|
|
103570
|
+
region: skill.region,
|
|
103571
|
+
expectedAudience: skill.expectedAudience,
|
|
103572
|
+
detectionSensors: skill.detectionSensors,
|
|
103573
|
+
objectDetection: skill.objectDetection,
|
|
103574
|
+
snapshots: skill.snapshots,
|
|
103575
|
+
enforceIngressToken: skill.enforceIngressToken
|
|
103576
|
+
},
|
|
103577
|
+
...links === null ? {} : {
|
|
103578
|
+
linkedAccounts: links.linkedAccounts,
|
|
103579
|
+
tokens: links.tokens
|
|
103580
|
+
}
|
|
103581
|
+
};
|
|
103582
|
+
}
|
|
101878
103583
|
/**
|
|
101879
103584
|
* The hub's public origin: the `publicEndpoint` role of `local-network`, read on every use
|
|
101880
103585
|
* through `ctx.api` (planning#378). No setting holds it and nothing ranks the palette here.
|
|
101881
103586
|
*/
|
|
101882
103587
|
publicEndpoint = createPublicEndpointReader(() => this.ctx.api.localNetwork.getAddresses.query());
|
|
101883
103588
|
async onInitialize() {
|
|
101884
|
-
|
|
103589
|
+
const records = this.ctx.records;
|
|
103590
|
+
if (records === void 0) throw new Error("export-alexa needs ctx.records — check execution.placement (hub-only)");
|
|
103591
|
+
await records.declare({
|
|
103592
|
+
skills: alexaSkillsKind,
|
|
103593
|
+
"skill-links": alexaSkillLinksKind
|
|
103594
|
+
});
|
|
103595
|
+
this.instances = new RecordIntegrationInstances(records, alexaSkillsKind, {
|
|
103596
|
+
description: {
|
|
103597
|
+
instanceMode: "single",
|
|
103598
|
+
kind: "skills",
|
|
103599
|
+
canTest: false
|
|
103600
|
+
},
|
|
103601
|
+
formSchema: () => this.skillForm(),
|
|
103602
|
+
initialBody: (name) => ({
|
|
103603
|
+
...ALEXA_SKILL_DEFAULT_BODY,
|
|
103604
|
+
name
|
|
103605
|
+
}),
|
|
103606
|
+
configured: () => true,
|
|
103607
|
+
onChanged: async () => {
|
|
103608
|
+
await this.refreshRecords();
|
|
103609
|
+
await this.onConfigChanged();
|
|
103610
|
+
}
|
|
103611
|
+
});
|
|
103612
|
+
await this.runMigrations(defineAddonMigrations(ADDON_MIGRATIONS, this.migrationPorts()));
|
|
103613
|
+
await this.refreshRecords();
|
|
101885
103614
|
if (!this.config.ingressToken) await this.updateGlobalSettings({ ingressToken: generateIngressToken() });
|
|
101886
103615
|
if (!this.config.snapshotSigningKey) await this.updateGlobalSettings({ snapshotSigningKey: generateIngressToken() });
|
|
101887
103616
|
if (!this.config.visionNamespace) await this.updateGlobalSettings({ visionNamespace: (0, node_crypto.randomUUID)() });
|
|
@@ -101899,7 +103628,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
101899
103628
|
});
|
|
101900
103629
|
this.visibilityRef = new AccountVisibilityMirror({
|
|
101901
103630
|
gate: this.accessGateRef,
|
|
101902
|
-
listLinkedUserIds: () => this.
|
|
103631
|
+
listLinkedUserIds: () => this.view.linkedAccounts.map((a) => a.userId),
|
|
101903
103632
|
listExposedDeviceIds: () => this.config.exposed.map((e) => e.deviceId),
|
|
101904
103633
|
getStored: () => this.config.accountVisibility,
|
|
101905
103634
|
setStored: (next) => this.updateGlobalSettings({ accountVisibility: next }),
|
|
@@ -101908,8 +103637,8 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
101908
103637
|
this.visionRef = new AlexaVisionRuntime({
|
|
101909
103638
|
ctx: this.ctx,
|
|
101910
103639
|
logger: this.ctx.logger,
|
|
101911
|
-
integrationOn: () => this.
|
|
101912
|
-
snapshotsOn: () => this.
|
|
103640
|
+
integrationOn: () => this.view.objectDetection,
|
|
103641
|
+
snapshotsOn: () => this.view.snapshots,
|
|
101913
103642
|
isExposed: (deviceId) => this.config.exposed.some((e) => e.deviceId === deviceId),
|
|
101914
103643
|
knownClasses: (deviceId) => this.config.detectionClasses[deviceId]?.classes ?? [],
|
|
101915
103644
|
namespace: () => this.config.visionNamespace,
|
|
@@ -101920,12 +103649,12 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
101920
103649
|
this.actionScenes = new ActionSceneExports({
|
|
101921
103650
|
api: this.ctx.api,
|
|
101922
103651
|
logger: this.ctx.logger,
|
|
101923
|
-
linkedUserIds: () => this.
|
|
103652
|
+
linkedUserIds: () => this.view.linkedAccounts.map((a) => a.userId),
|
|
101924
103653
|
isAdminUser: async (userId) => {
|
|
101925
103654
|
const lookup = await this.accessGate.principal(userId);
|
|
101926
103655
|
return lookup.kind === "found" && lookup.principal.kind === "admin";
|
|
101927
103656
|
},
|
|
101928
|
-
canPush: () => this.
|
|
103657
|
+
canPush: () => this.view.tokens.length > 0,
|
|
101929
103658
|
postAddOrUpdate: (userId, endpoints) => this.requireGateway().postReport(userId, (accessToken) => buildAddOrUpdateReportPayload(userId, endpoints, accessToken), `action scenes add/update (${endpoints.length})`),
|
|
101930
103659
|
postDelete: (userId, ids) => this.requireGateway().postReport(userId, (accessToken) => buildDeleteReportPayload(userId, ids, accessToken), `action scenes delete (${ids.length})`),
|
|
101931
103660
|
persist: (entries) => this.updateGlobalSettings({ exposedActions: [...entries] })
|
|
@@ -101936,7 +103665,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
101936
103665
|
});
|
|
101937
103666
|
const deviceExportProvider = {
|
|
101938
103667
|
getStatus: async () => ({
|
|
101939
|
-
linkState: this.
|
|
103668
|
+
linkState: this.view.linkedAccounts.length > 0 ? "linked" : "unlinked",
|
|
101940
103669
|
exposedDeviceCount: this.config.exposed.length,
|
|
101941
103670
|
setup: await this.buildSetupBlock()
|
|
101942
103671
|
}),
|
|
@@ -102024,6 +103753,10 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102024
103753
|
ctx: this.ctx,
|
|
102025
103754
|
logger: this.ctx.logger
|
|
102026
103755
|
},
|
|
103756
|
+
mediaPlayerController: {
|
|
103757
|
+
ctx: this.ctx,
|
|
103758
|
+
logger: this.ctx.logger
|
|
103759
|
+
},
|
|
102027
103760
|
coverController: {
|
|
102028
103761
|
ctx: this.ctx,
|
|
102029
103762
|
logger: this.ctx.logger,
|
|
@@ -102033,7 +103766,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102033
103766
|
ctx: this.ctx,
|
|
102034
103767
|
logger: this.ctx.logger,
|
|
102035
103768
|
store: this.snapshotStore,
|
|
102036
|
-
enabled: () => this.
|
|
103769
|
+
enabled: () => this.view.snapshots,
|
|
102037
103770
|
publicEndpoint: this.publicEndpoint
|
|
102038
103771
|
},
|
|
102039
103772
|
vision: this.vision.context(),
|
|
@@ -102055,7 +103788,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102055
103788
|
onBrokerAdvertised: (raw) => this.rememberAdvertisedBroker(raw),
|
|
102056
103789
|
snapshotRoute: {
|
|
102057
103790
|
store: this.snapshotStore,
|
|
102058
|
-
enabled: () => this.
|
|
103791
|
+
enabled: () => this.view.snapshots,
|
|
102059
103792
|
verifyToken: (token) => this.verifyAccountLinkToken(token),
|
|
102060
103793
|
mayView: async (userId, deviceId) => {
|
|
102061
103794
|
const lookup = await this.accessGate.principal(userId);
|
|
@@ -102083,13 +103816,13 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102083
103816
|
onExposedDoorbellPress: (deviceId) => {
|
|
102084
103817
|
this.egressPrewarm?.onPress(deviceId);
|
|
102085
103818
|
},
|
|
102086
|
-
listLinkedAccounts: () => this.
|
|
102087
|
-
listTokens: () => this.
|
|
103819
|
+
listLinkedAccounts: () => this.view.linkedAccounts,
|
|
103820
|
+
listTokens: () => this.view.tokens,
|
|
102088
103821
|
upsertToken: (input) => this.upsertToken(input),
|
|
102089
103822
|
removeLinkedAccount: (userId) => this.removeLinkedAccount(userId),
|
|
102090
103823
|
getAdvertisedBrokerUrl: () => this.config.advertisedBrokerUrl || null,
|
|
102091
103824
|
getPublicEndpoint: this.publicEndpoint,
|
|
102092
|
-
getRegion: () => this.
|
|
103825
|
+
getRegion: () => this.view.region,
|
|
102093
103826
|
getExportedSignature: (deviceId) => this.config.exportedSignatures[deviceId] ?? null,
|
|
102094
103827
|
accountMaySee: (userId, deviceId) => this.visibility.allows(userId, deviceId)
|
|
102095
103828
|
});
|
|
@@ -102097,7 +103830,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102097
103830
|
const gatewayForFeed = this.lwaGateway;
|
|
102098
103831
|
this.detectionFeed = new DetectionSensorFeed({
|
|
102099
103832
|
eventBus: this.ctx.eventBus,
|
|
102100
|
-
enabled: () => this.
|
|
103833
|
+
enabled: () => this.view.detectionSensors,
|
|
102101
103834
|
isExposed: (deviceId) => this.config.exposed.some((e) => e.deviceId === deviceId),
|
|
102102
103835
|
readActiveTracks: async (deviceId) => {
|
|
102103
103836
|
return (await this.ctx.api.pipelineAnalytics.getActiveTracks.query({ deviceId })).map((t) => ({
|
|
@@ -102143,8 +103876,8 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102143
103876
|
this.syncEngine = new SyncEngine({
|
|
102144
103877
|
logger: this.ctx.logger,
|
|
102145
103878
|
listExposed: () => this.config.exposed,
|
|
102146
|
-
listLinkedAccounts: () => this.
|
|
102147
|
-
hasProactiveCredentials: () => this.
|
|
103879
|
+
listLinkedAccounts: () => this.view.linkedAccounts,
|
|
103880
|
+
hasProactiveCredentials: () => this.view.tokens.length > 0,
|
|
102148
103881
|
buildEndpoints: (deviceId) => this.buildEndpointsForOneDevice(deviceId),
|
|
102149
103882
|
filterForAccount: (userId, endpoints) => this.filterForAccount(userId, endpoints),
|
|
102150
103883
|
afterPush: (userId, endpoints) => this.requireGateway().scheduleInitialConnectivity(userId, endpoints),
|
|
@@ -102174,10 +103907,10 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102174
103907
|
this.ctx.addDisposer(async () => clearInterval(reaper));
|
|
102175
103908
|
this.ctx.logger.info("export-alexa: initialized", { meta: {
|
|
102176
103909
|
exposedCount: this.config.exposed.length,
|
|
102177
|
-
skillMode: this.
|
|
103910
|
+
skillMode: this.view.skillMode,
|
|
102178
103911
|
skillIdSet: this.effectiveSettings().expectedAudience.length > 0,
|
|
102179
|
-
pushGrants: this.
|
|
102180
|
-
brokerGrants: this.
|
|
103912
|
+
pushGrants: this.view.tokens.length,
|
|
103913
|
+
brokerGrants: this.view.tokens.filter(isBrokerGrant).length
|
|
102181
103914
|
} });
|
|
102182
103915
|
return {
|
|
102183
103916
|
providers: [
|
|
@@ -102185,6 +103918,10 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102185
103918
|
capability: deviceExportCapability,
|
|
102186
103919
|
provider: deviceExportProvider
|
|
102187
103920
|
},
|
|
103921
|
+
{
|
|
103922
|
+
capability: integrationInstancesCapability,
|
|
103923
|
+
provider: this.requireInstances().toProvider()
|
|
103924
|
+
},
|
|
102188
103925
|
{
|
|
102189
103926
|
capability: addonRoutesCapability,
|
|
102190
103927
|
provider: routeProvider
|
|
@@ -102292,18 +104029,18 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102292
104029
|
return buildEndpointsForExposedDevice(deviceId, {
|
|
102293
104030
|
ctx: this.ctx,
|
|
102294
104031
|
logger: this.ctx.logger,
|
|
102295
|
-
snapshots: this.
|
|
102296
|
-
...this.
|
|
104032
|
+
snapshots: this.view.snapshots,
|
|
104033
|
+
...this.view.detectionSensors ? { detectionClasses: async (id) => effectiveSensorClasses(await classesOf(id), parseSensorSelection(await vision.readPrefs(id))) } : {},
|
|
102297
104034
|
alexaName: async (id) => readAlexaName(await vision.readPrefs(id)),
|
|
102298
|
-
...this.
|
|
104035
|
+
...this.view.objectDetection ? { objectDetection: async (id) => vision.buildClasses(id, await classesOf(id)) } : {}
|
|
102299
104036
|
});
|
|
102300
104037
|
}
|
|
102301
104038
|
/** The settings that change every exposed endpoint's shape, as one key. */
|
|
102302
104039
|
shapeSwitches() {
|
|
102303
104040
|
return JSON.stringify({
|
|
102304
|
-
detectionSensors: this.
|
|
102305
|
-
snapshots: this.
|
|
102306
|
-
objectDetection: this.
|
|
104041
|
+
detectionSensors: this.view.detectionSensors,
|
|
104042
|
+
snapshots: this.view.snapshots,
|
|
104043
|
+
objectDetection: this.view.objectDetection
|
|
102307
104044
|
});
|
|
102308
104045
|
}
|
|
102309
104046
|
/**
|
|
@@ -102315,7 +104052,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102315
104052
|
const now = this.shapeSwitches();
|
|
102316
104053
|
if (this.appliedShapeSwitches === null || now === this.appliedShapeSwitches) return;
|
|
102317
104054
|
this.appliedShapeSwitches = now;
|
|
102318
|
-
if (!this.
|
|
104055
|
+
if (!this.view.snapshots) this.snapshotStore.clear();
|
|
102319
104056
|
this.ctx.logger.info("export-alexa: an endpoint-shape switch changed — re-syncing every device", { meta: { switches: now } });
|
|
102320
104057
|
const engine = this.syncEngine;
|
|
102321
104058
|
if (engine === null) return;
|
|
@@ -102325,7 +104062,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102325
104062
|
}
|
|
102326
104063
|
scheduleDetectionClassRefresh() {
|
|
102327
104064
|
const timer = setInterval(() => {
|
|
102328
|
-
if (!this.
|
|
104065
|
+
if (!this.view.detectionSensors && !this.view.objectDetection) return;
|
|
102329
104066
|
this.requireSyncEngine().reconcileAllExposed().catch((err) => {
|
|
102330
104067
|
this.ctx.logger.warn("export-alexa: detection-class refresh failed", { meta: { error: errMsg$1(err) } });
|
|
102331
104068
|
});
|
|
@@ -102467,8 +104204,8 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102467
104204
|
* Throws when nothing can be sent, so the button says why.
|
|
102468
104205
|
*/
|
|
102469
104206
|
async resyncDiscovery() {
|
|
102470
|
-
if (this.
|
|
102471
|
-
if (this.
|
|
104207
|
+
if (this.view.linkedAccounts.length === 0) throw new Error("No linked Amazon account. Link the skill from the Alexa app first.");
|
|
104208
|
+
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.");
|
|
102472
104209
|
const r = await this.requireSyncEngine().resync();
|
|
102473
104210
|
this.ctx.logger.info("export-alexa: manual discovery re-sync", { meta: { ...r } });
|
|
102474
104211
|
return r;
|
|
@@ -102517,11 +104254,13 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102517
104254
|
}
|
|
102518
104255
|
this.ctx.logger.warn("export-alexa: revokeOauthSession reported failure — the session may already be gone", { meta: { sessionId: id } });
|
|
102519
104256
|
}
|
|
102520
|
-
await this.revokeAtBroker(this.
|
|
102521
|
-
const removedAccounts = this.
|
|
102522
|
-
await this.
|
|
104257
|
+
await this.revokeAtBroker(this.view.tokens);
|
|
104258
|
+
const removedAccounts = this.view.linkedAccounts.length;
|
|
104259
|
+
await this.writeLedger({
|
|
102523
104260
|
linkedAccounts: [],
|
|
102524
|
-
tokens: []
|
|
104261
|
+
tokens: []
|
|
104262
|
+
});
|
|
104263
|
+
await this.updateGlobalSettings({
|
|
102525
104264
|
exportedEndpoints: {},
|
|
102526
104265
|
exportedSignatures: {},
|
|
102527
104266
|
accountVisibility: {}
|
|
@@ -102546,25 +104285,25 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102546
104285
|
...input.brokerUrl ? { brokerUrl: input.brokerUrl } : {},
|
|
102547
104286
|
...input.brokerCredential ? { brokerCredential: input.brokerCredential } : {}
|
|
102548
104287
|
};
|
|
102549
|
-
const next = this.
|
|
104288
|
+
const next = this.view.tokens.filter((t) => t.userId !== input.userId);
|
|
102550
104289
|
next.push(entry);
|
|
102551
|
-
await this.
|
|
104290
|
+
await this.writeLedger({ tokens: next });
|
|
102552
104291
|
}
|
|
102553
104292
|
async removeLinkedAccount(userId) {
|
|
102554
|
-
await this.
|
|
102555
|
-
tokens: this.
|
|
102556
|
-
linkedAccounts: this.
|
|
104293
|
+
await this.writeLedger({
|
|
104294
|
+
tokens: this.view.tokens.filter((t) => t.userId !== userId),
|
|
104295
|
+
linkedAccounts: this.view.linkedAccounts.filter((a) => a.userId !== userId)
|
|
102557
104296
|
});
|
|
102558
104297
|
this.ctx.logger.warn("export-alexa: unlinked revoked account", { meta: { userId } });
|
|
102559
104298
|
}
|
|
102560
104299
|
async recordLinkedAccount(input) {
|
|
102561
|
-
if (this.
|
|
102562
|
-
const next = [...this.
|
|
104300
|
+
if (this.view.linkedAccounts.some((a) => a.userId === input.userId)) return;
|
|
104301
|
+
const next = [...this.view.linkedAccounts, {
|
|
102563
104302
|
userId: input.userId,
|
|
102564
104303
|
username: input.username,
|
|
102565
104304
|
linkedAt: Date.now()
|
|
102566
104305
|
}];
|
|
102567
|
-
await this.
|
|
104306
|
+
await this.writeLedger({ linkedAccounts: next });
|
|
102568
104307
|
const engine = this.syncEngine;
|
|
102569
104308
|
if (!engine) return;
|
|
102570
104309
|
engine.pushAllToAccount(input.userId).then((r) => {
|
|
@@ -102583,8 +104322,8 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102583
104322
|
* token carries none). Idempotent via recordLinkedAccount.
|
|
102584
104323
|
*/
|
|
102585
104324
|
async backfillLinkedAccounts() {
|
|
102586
|
-
const linked = new Set(this.
|
|
102587
|
-
const missing = this.
|
|
104325
|
+
const linked = new Set(this.view.linkedAccounts.map((a) => a.userId));
|
|
104326
|
+
const missing = this.view.tokens.filter((t) => !linked.has(t.userId));
|
|
102588
104327
|
for (const t of missing) await this.recordLinkedAccount({
|
|
102589
104328
|
userId: t.userId,
|
|
102590
104329
|
username: t.userId
|
|
@@ -102626,10 +104365,10 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102626
104365
|
* broker no longer recognises is reported, not retried — re-link instead.
|
|
102627
104366
|
*/
|
|
102628
104367
|
async rotateBrokerCredentials() {
|
|
102629
|
-
if (!this.
|
|
104368
|
+
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.");
|
|
102630
104369
|
let rotated = 0;
|
|
102631
104370
|
let failed = 0;
|
|
102632
|
-
for (const t of this.
|
|
104371
|
+
for (const t of this.view.tokens) {
|
|
102633
104372
|
if (!isBrokerGrant(t)) continue;
|
|
102634
104373
|
try {
|
|
102635
104374
|
const next = await rotateBrokerCredential(fetch, t.brokerUrl, t.brokerCredential);
|
|
@@ -102681,17 +104420,139 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102681
104420
|
return buildAlexaSetupBlock({
|
|
102682
104421
|
publicEndpoint: await this.publicEndpoint(),
|
|
102683
104422
|
ingressToken: this.config.ingressToken,
|
|
102684
|
-
skillMode: this.
|
|
104423
|
+
skillMode: this.view.skillMode
|
|
102685
104424
|
});
|
|
102686
104425
|
}
|
|
104426
|
+
requireInstances() {
|
|
104427
|
+
if (this.instances === null) throw new Error("export-alexa: the instances are not open");
|
|
104428
|
+
return this.instances;
|
|
104429
|
+
}
|
|
104430
|
+
skillHandle() {
|
|
104431
|
+
const records = this.ctx.records;
|
|
104432
|
+
if (records === void 0) throw new Error("records are not available");
|
|
104433
|
+
return records.kind(alexaSkillsKind);
|
|
104434
|
+
}
|
|
104435
|
+
linksHandle() {
|
|
104436
|
+
const records = this.ctx.records;
|
|
104437
|
+
if (records === void 0) throw new Error("records are not available");
|
|
104438
|
+
return records.kind(alexaSkillLinksKind);
|
|
104439
|
+
}
|
|
104440
|
+
/** Re-read both records. A failed read changes nothing: the addon keeps what it has. */
|
|
104441
|
+
async refreshRecords() {
|
|
104442
|
+
try {
|
|
104443
|
+
this.skillRow = (await this.skillHandle().getResolved("export-alexa"))?.data ?? null;
|
|
104444
|
+
} catch (err) {
|
|
104445
|
+
this.ctx.logger.warn("export-alexa: the skill record could not be read", {
|
|
104446
|
+
meta: { error: errMsg$1(err) },
|
|
104447
|
+
tags: {
|
|
104448
|
+
topic: "export-alexa",
|
|
104449
|
+
phase: "records-read-failed"
|
|
104450
|
+
}
|
|
104451
|
+
});
|
|
104452
|
+
}
|
|
104453
|
+
try {
|
|
104454
|
+
this.linksRow = (await this.linksHandle().getResolved("export-alexa"))?.data ?? null;
|
|
104455
|
+
this.linksLocked = false;
|
|
104456
|
+
} catch (err) {
|
|
104457
|
+
if (!(err instanceof RecordSecretUnavailableError)) {
|
|
104458
|
+
this.ctx.logger.warn("export-alexa: the link record could not be read", {
|
|
104459
|
+
meta: { error: errMsg$1(err) },
|
|
104460
|
+
tags: {
|
|
104461
|
+
topic: "export-alexa",
|
|
104462
|
+
phase: "records-read-failed"
|
|
104463
|
+
}
|
|
104464
|
+
});
|
|
104465
|
+
return;
|
|
104466
|
+
}
|
|
104467
|
+
this.linksLocked = true;
|
|
104468
|
+
this.ctx.logger.warn("export-alexa: the keychain is locked; the link ledger is read-only", { tags: {
|
|
104469
|
+
topic: "export-alexa",
|
|
104470
|
+
phase: "keychain-locked"
|
|
104471
|
+
} });
|
|
104472
|
+
}
|
|
104473
|
+
}
|
|
104474
|
+
/**
|
|
104475
|
+
* Write the account-link ledgers: to the `skill-links` record once it exists, to the legacy
|
|
104476
|
+
* settings keys until then (the migration moves them).
|
|
104477
|
+
*/
|
|
104478
|
+
async writeLedger(patch) {
|
|
104479
|
+
if (this.linksRow === null) {
|
|
104480
|
+
await this.updateGlobalSettings({
|
|
104481
|
+
...patch.linkedAccounts === void 0 ? {} : { linkedAccounts: patch.linkedAccounts },
|
|
104482
|
+
...patch.tokens === void 0 ? {} : { tokens: patch.tokens }
|
|
104483
|
+
});
|
|
104484
|
+
return;
|
|
104485
|
+
}
|
|
104486
|
+
if (this.linksLocked) throw new Error("the keychain is locked: the Amazon link ledger cannot be changed right now");
|
|
104487
|
+
const next = {
|
|
104488
|
+
name: this.linksRow.name,
|
|
104489
|
+
linkedAccounts: patch.linkedAccounts ?? this.linksRow.linkedAccounts,
|
|
104490
|
+
tokens: patch.tokens ?? this.linksRow.tokens
|
|
104491
|
+
};
|
|
104492
|
+
await this.linksHandle().put({
|
|
104493
|
+
id: ALEXA_INSTANCE_ID,
|
|
104494
|
+
data: next
|
|
104495
|
+
});
|
|
104496
|
+
this.linksRow = next;
|
|
104497
|
+
}
|
|
104498
|
+
/** The ports of the settings migrations: the old settings in, the records out. */
|
|
104499
|
+
migrationPorts() {
|
|
104500
|
+
const skills = this.skillHandle();
|
|
104501
|
+
const links = this.linksHandle();
|
|
104502
|
+
const putOnce = async (handle, body) => {
|
|
104503
|
+
if (await handle.get("export-alexa") !== null) return "exists";
|
|
104504
|
+
try {
|
|
104505
|
+
await handle.put({
|
|
104506
|
+
id: ALEXA_INSTANCE_ID,
|
|
104507
|
+
data: body
|
|
104508
|
+
}, { ifRev: 0 });
|
|
104509
|
+
} catch (err) {
|
|
104510
|
+
if (err instanceof RevConflictError) return "exists";
|
|
104511
|
+
throw err;
|
|
104512
|
+
}
|
|
104513
|
+
return "created";
|
|
104514
|
+
};
|
|
104515
|
+
return {
|
|
104516
|
+
readStored: async () => {
|
|
104517
|
+
const stored = await this.resolveGlobalStore();
|
|
104518
|
+
const tokens = stored["tokens"];
|
|
104519
|
+
if (Array.isArray(tokens) && tokens.some(hasUnresolvedCredential)) throw new Error("the old Amazon push grants could not be resolved");
|
|
104520
|
+
return stored;
|
|
104521
|
+
},
|
|
104522
|
+
readRawStored: async () => await this.ctx.settings?.readAddonStore() ?? {},
|
|
104523
|
+
warn: (message) => {
|
|
104524
|
+
this.ctx.logger.warn(message, { tags: {
|
|
104525
|
+
topic: "export-alexa",
|
|
104526
|
+
phase: "migration"
|
|
104527
|
+
} });
|
|
104528
|
+
},
|
|
104529
|
+
putSkill: (body) => putOnce(skills, body),
|
|
104530
|
+
putLinks: (body) => putOnce(links, body),
|
|
104531
|
+
replaceLinks: async (body) => {
|
|
104532
|
+
await links.put({
|
|
104533
|
+
id: ALEXA_INSTANCE_ID,
|
|
104534
|
+
data: body
|
|
104535
|
+
});
|
|
104536
|
+
},
|
|
104537
|
+
readLinks: async () => (await links.getResolved("export-alexa"))?.data ?? null,
|
|
104538
|
+
hasSkill: async () => await skills.get(ALEXA_INSTANCE_ID) !== null,
|
|
104539
|
+
clearOldTokenSecrets: async () => {
|
|
104540
|
+
await this.clearSecrets(["tokens"]);
|
|
104541
|
+
}
|
|
104542
|
+
};
|
|
104543
|
+
}
|
|
104544
|
+
/** The instance form: how the skill reaches this hub and what each camera carries. */
|
|
104545
|
+
skillForm() {
|
|
104546
|
+
return { sections: buildAlexaInstanceSections({ defaults: ALEXA_SKILL_DEFAULT_BODY }) };
|
|
104547
|
+
}
|
|
102687
104548
|
/** The settings page: see `settings-schema.ts` for its layout. The account-
|
|
102688
104549
|
* linking rows live in the `device-export` setup block instead. */
|
|
102689
104550
|
globalSettingsSchema() {
|
|
102690
104551
|
return { sections: buildAlexaSettingsSections({
|
|
102691
|
-
linkedAccounts: this.
|
|
102692
|
-
tokens: this.
|
|
104552
|
+
linkedAccounts: this.view.linkedAccounts,
|
|
104553
|
+
tokens: this.view.tokens,
|
|
102693
104554
|
now: Date.now(),
|
|
102694
|
-
|
|
104555
|
+
skillMode: this.view.skillMode
|
|
102695
104556
|
}) };
|
|
102696
104557
|
}
|
|
102697
104558
|
/**
|
|
@@ -102732,7 +104593,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102732
104593
|
const settings = entry?.settings ?? DEFAULT_DEVICE_SETTINGS;
|
|
102733
104594
|
const enabled = entry !== null;
|
|
102734
104595
|
const enabledKey = `alexa:${deviceId}:enabled`;
|
|
102735
|
-
const linkedCount = this.
|
|
104596
|
+
const linkedCount = this.view.linkedAccounts.length;
|
|
102736
104597
|
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";
|
|
102737
104598
|
return {
|
|
102738
104599
|
tabs: [{
|
|
@@ -102799,12 +104660,12 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
102799
104660
|
available: this.detectionClassSource === null ? [] : await this.detectionClassSource.classesFor(deviceId).catch(() => []),
|
|
102800
104661
|
saved: parseSensorSelection(store),
|
|
102801
104662
|
enabledKey,
|
|
102802
|
-
masterOn: this.
|
|
104663
|
+
masterOn: this.view.detectionSensors
|
|
102803
104664
|
}), objectDetectionField({
|
|
102804
104665
|
deviceId,
|
|
102805
104666
|
store,
|
|
102806
104667
|
enabledKey,
|
|
102807
|
-
integrationOn: this.
|
|
104668
|
+
integrationOn: this.view.objectDetection
|
|
102808
104669
|
})];
|
|
102809
104670
|
}
|
|
102810
104671
|
/**
|