@camstack/addon-export-alexa 1.2.194 → 1.2.195
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/export-alexa.addon.js +521 -97
- package/dist/export-alexa.addon.mjs +521 -97
- package/lambda-template/README.md +1 -0
- package/lambda-template/authorize-page.js +5 -0
- package/lambda-template/index.js +31 -8
- package/package.json +2 -2
|
@@ -6079,7 +6079,7 @@ var ZodIssueCode = {
|
|
|
6079
6079
|
var ZodFirstPartyTypeKind;
|
|
6080
6080
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
6081
6081
|
//#endregion
|
|
6082
|
-
//#region ../types/dist/sleep-
|
|
6082
|
+
//#region ../types/dist/sleep-D0roI_CZ.mjs
|
|
6083
6083
|
/**
|
|
6084
6084
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
6085
6085
|
* window to float samples (D455).
|
|
@@ -16189,6 +16189,10 @@ Object.freeze({
|
|
|
16189
16189
|
"path": "lastEvent.eventType",
|
|
16190
16190
|
"valueType": "string"
|
|
16191
16191
|
},
|
|
16192
|
+
{
|
|
16193
|
+
"path": "lastEvent.sourceId",
|
|
16194
|
+
"valueType": "string"
|
|
16195
|
+
},
|
|
16192
16196
|
{
|
|
16193
16197
|
"path": "lastEvent.timestamp",
|
|
16194
16198
|
"valueType": "number"
|
|
@@ -19209,6 +19213,7 @@ function buildAddonRouteProvider(id, routes) {
|
|
|
19209
19213
|
query: input.query,
|
|
19210
19214
|
body: input.body,
|
|
19211
19215
|
headers: input.headers,
|
|
19216
|
+
...match.route.perInstance === true && input.instanceId !== void 0 ? { instanceId: input.instanceId } : {},
|
|
19212
19217
|
...input.user ? { user: input.user } : {},
|
|
19213
19218
|
...input.scopedToken !== void 0 ? { scopedToken: input.scopedToken } : {}
|
|
19214
19219
|
};
|
|
@@ -19276,6 +19281,18 @@ function buildCapturingReply(envelope) {
|
|
|
19276
19281
|
};
|
|
19277
19282
|
return wrapper;
|
|
19278
19283
|
}
|
|
19284
|
+
/** The instance a link was made for, with the default one spelled as the addon id. */
|
|
19285
|
+
function oauthLinkInstanceId(link, addonId) {
|
|
19286
|
+
return link.instanceId ?? addonId;
|
|
19287
|
+
}
|
|
19288
|
+
/**
|
|
19289
|
+
* True when a verified link may be used on a request addressed to
|
|
19290
|
+
* `requestInstanceId` (`AddonHttpRequest.instanceId`, absent on a route that
|
|
19291
|
+
* is not per-instance, which is the default instance).
|
|
19292
|
+
*/
|
|
19293
|
+
function oauthLinkServesInstance(link, requestInstanceId, addonId) {
|
|
19294
|
+
return oauthLinkInstanceId(link, addonId) === (requestInstanceId ?? addonId);
|
|
19295
|
+
}
|
|
19279
19296
|
/**
|
|
19280
19297
|
* notification-output — canonical, capability-gated notification delivery.
|
|
19281
19298
|
*
|
|
@@ -44064,6 +44081,41 @@ function macroOnly(macro) {
|
|
|
44064
44081
|
};
|
|
44065
44082
|
}
|
|
44066
44083
|
}
|
|
44084
|
+
var EventVocabularyKindSchema = _enum([
|
|
44085
|
+
"press",
|
|
44086
|
+
"long-press",
|
|
44087
|
+
"long-press-start",
|
|
44088
|
+
"release",
|
|
44089
|
+
"repeat",
|
|
44090
|
+
"double-press",
|
|
44091
|
+
"other"
|
|
44092
|
+
]);
|
|
44093
|
+
/** The part of the device an event comes from: a button, a channel. */
|
|
44094
|
+
var EventVocabularySourceSchema = object({
|
|
44095
|
+
id: string().min(1),
|
|
44096
|
+
label: string().min(1)
|
|
44097
|
+
});
|
|
44098
|
+
/** One scalar field of an event's `data`, by dotted path. */
|
|
44099
|
+
var EventVocabularyFieldSchema = object({
|
|
44100
|
+
path: string().min(1),
|
|
44101
|
+
kind: _enum([
|
|
44102
|
+
"string",
|
|
44103
|
+
"number",
|
|
44104
|
+
"boolean",
|
|
44105
|
+
"enum"
|
|
44106
|
+
]),
|
|
44107
|
+
enumValues: array(string()).optional(),
|
|
44108
|
+
label: string().min(1).optional()
|
|
44109
|
+
});
|
|
44110
|
+
var EventVocabularyEntrySchema = object({
|
|
44111
|
+
/** The native token, verbatim. */
|
|
44112
|
+
id: string().min(1),
|
|
44113
|
+
source: EventVocabularySourceSchema.optional(),
|
|
44114
|
+
label: string().min(1),
|
|
44115
|
+
description: string().optional(),
|
|
44116
|
+
kind: EventVocabularyKindSchema.optional(),
|
|
44117
|
+
payload: array(EventVocabularyFieldSchema).optional()
|
|
44118
|
+
});
|
|
44067
44119
|
Math.PI / 180;
|
|
44068
44120
|
/**
|
|
44069
44121
|
* WHEN something happens, as data (D983) — the one time vocabulary of the
|
|
@@ -44271,6 +44323,33 @@ var ScheduleLeafSchema = object({
|
|
|
44271
44323
|
/** @deprecated legacy cron — new schedules use `at`. */
|
|
44272
44324
|
cron: string().min(1).max(120).optional()
|
|
44273
44325
|
}).refine((leaf) => leaf.at === void 0 !== (leaf.cron === void 0), { message: "a schedule names exactly one of `at` (a time spec) and `cron` (legacy)" }).refine((leaf) => leaf.days === void 0 || leaf.at !== void 0, { message: "`days` goes with `at`; a cron expression carries its own days" });
|
|
44326
|
+
/**
|
|
44327
|
+
* One payload predicate of a `device-fired` row: the value at `path` inside
|
|
44328
|
+
* the fire's `data` (dotted) equals `equals`. Compared strictly, no coercion.
|
|
44329
|
+
*/
|
|
44330
|
+
var DeviceFiredMatchSchema = object({
|
|
44331
|
+
path: string().min(1).max(120),
|
|
44332
|
+
equals: union([
|
|
44333
|
+
string(),
|
|
44334
|
+
number$1(),
|
|
44335
|
+
boolean()
|
|
44336
|
+
])
|
|
44337
|
+
});
|
|
44338
|
+
/**
|
|
44339
|
+
* "fires": one device of the `event-emitter` capability reported an event
|
|
44340
|
+
* (D1045). Every list is an OR, the lists together an AND; an absent list does
|
|
44341
|
+
* not narrow. `eventIds` are the device's own tokens, `sourceIds` the parts of
|
|
44342
|
+
* the device (a button), `kinds` the shared press kinds of its vocabulary.
|
|
44343
|
+
*/
|
|
44344
|
+
var DeviceFiredLeafSchema = object({
|
|
44345
|
+
kind: literal("device-fired"),
|
|
44346
|
+
...eventLeafId,
|
|
44347
|
+
deviceId: number$1().int().nonnegative(),
|
|
44348
|
+
eventIds: array(string().min(1)).min(1).max(64).optional(),
|
|
44349
|
+
sourceIds: array(string().min(1)).min(1).max(64).optional(),
|
|
44350
|
+
kinds: array(EventVocabularyKindSchema).min(1).optional(),
|
|
44351
|
+
match: array(DeviceFiredMatchSchema).min(1).max(8).optional()
|
|
44352
|
+
});
|
|
44274
44353
|
var ManualLeafSchema = object({
|
|
44275
44354
|
kind: literal("manual"),
|
|
44276
44355
|
...eventLeafId
|
|
@@ -44412,6 +44491,7 @@ var AutomationWhenSchema = lazy(() => discriminatedUnion("kind", [
|
|
|
44412
44491
|
}),
|
|
44413
44492
|
DeviceBecomesLeafSchema,
|
|
44414
44493
|
DeviceEventLeafSchema,
|
|
44494
|
+
DeviceFiredLeafSchema,
|
|
44415
44495
|
ScheduleLeafSchema,
|
|
44416
44496
|
ManualLeafSchema,
|
|
44417
44497
|
IntervalLeafSchema,
|
|
@@ -44426,6 +44506,7 @@ var AutomationWhenSchema = lazy(() => discriminatedUnion("kind", [
|
|
|
44426
44506
|
var EVENT_KINDS = new Set([
|
|
44427
44507
|
"device-becomes",
|
|
44428
44508
|
"device-event",
|
|
44509
|
+
"device-fired",
|
|
44429
44510
|
"schedule",
|
|
44430
44511
|
"manual",
|
|
44431
44512
|
"interval",
|
|
@@ -44506,6 +44587,7 @@ function hasEmptyContainer(node) {
|
|
|
44506
44587
|
var LEAF_WORDS = {
|
|
44507
44588
|
"device-becomes": "a device value that becomes",
|
|
44508
44589
|
"device-event": "a device event",
|
|
44590
|
+
"device-fired": "a device firing an event",
|
|
44509
44591
|
schedule: "a schedule",
|
|
44510
44592
|
manual: "a manual run",
|
|
44511
44593
|
interval: "an interval",
|
|
@@ -44771,9 +44853,12 @@ function convertLegacyWhen(half) {
|
|
|
44771
44853
|
* every caller — automations, Actions, and the notification centre, which runs
|
|
44772
44854
|
* only Actions (planning#473).
|
|
44773
44855
|
*/
|
|
44856
|
+
/** The longest one `wait` step lasts. It is cut by a restart of the run and does not survive a hub restart. */
|
|
44857
|
+
var WAIT_MAX_SECONDS = 3600;
|
|
44858
|
+
var WAIT_TOO_LONG = `a wait is at most one hour (${WAIT_MAX_SECONDS} s)`;
|
|
44774
44859
|
var AutomationWaitStepSchema = object({
|
|
44775
44860
|
kind: literal("wait"),
|
|
44776
|
-
seconds: number$1().min(0).max(
|
|
44861
|
+
seconds: number$1().min(0).max(WAIT_MAX_SECONDS, WAIT_TOO_LONG)
|
|
44777
44862
|
});
|
|
44778
44863
|
/** The legacy `deviceId` of a cap step: still READ, never written (D983). */
|
|
44779
44864
|
var LegacyStepDeviceSchema = union([
|
|
@@ -44843,39 +44928,227 @@ var elseNeedsIf = {
|
|
|
44843
44928
|
path: ["else"]
|
|
44844
44929
|
};
|
|
44845
44930
|
var GuardedWaitStepSchema = AutomationWaitStepSchema.extend(stepGuardShape).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
|
|
44846
|
-
var GuardedCapStepSchema = AutomationCapStepBaseSchema.extend(stepGuardShape).refine((step) => step.target !== void 0 || step.deviceId !== void 0, {
|
|
44847
|
-
message: "a cap step needs a target",
|
|
44848
|
-
path: ["target"]
|
|
44849
|
-
}).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
|
|
44850
|
-
message: "a domain target needs the vocabulary action it applies to (actionId)",
|
|
44851
|
-
path: ["actionId"]
|
|
44852
|
-
}).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
|
|
44853
44931
|
/**
|
|
44854
44932
|
* A step of a STANDALONE list (an action, a scheduler point, a preset): the
|
|
44855
44933
|
* same two step kinds an automation runs, minus a guard that reads the
|
|
44856
44934
|
* automation's trigger, which such a list does not have.
|
|
44857
44935
|
*/
|
|
44858
|
-
var ActionStepSchema = discriminatedUnion("kind", [GuardedWaitStepSchema,
|
|
44936
|
+
var ActionStepSchema = discriminatedUnion("kind", [GuardedWaitStepSchema, AutomationCapStepBaseSchema.extend(stepGuardShape).refine((step) => step.target !== void 0 || step.deviceId !== void 0, {
|
|
44937
|
+
message: "a cap step needs a target",
|
|
44938
|
+
path: ["target"]
|
|
44939
|
+
}).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
|
|
44940
|
+
message: "a domain target needs the vocabulary action it applies to (actionId)",
|
|
44941
|
+
path: ["actionId"]
|
|
44942
|
+
}).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf)]).superRefine((step, ctx) => {
|
|
44859
44943
|
if (step.if !== void 0 && hasTriggeredByLeaves(step.if)) ctx.addIssue({
|
|
44860
44944
|
code: "custom",
|
|
44861
44945
|
message: TRIGGERED_BY_NEEDS_AUTOMATION,
|
|
44862
44946
|
path: ["if"]
|
|
44863
44947
|
});
|
|
44864
44948
|
});
|
|
44949
|
+
/**
|
|
44950
|
+
* Flow control of an AUTOMATION's list (#500). A standalone list (an action, a
|
|
44951
|
+
* scheduler point, a preset) stays `wait` and `cap`: it has no run of its own
|
|
44952
|
+
* to end and no variable bag to write.
|
|
44953
|
+
*/
|
|
44954
|
+
var continueOnErrorShape = {
|
|
44955
|
+
/** A failure of this step is traced `failed-continued` and the next step runs. */
|
|
44956
|
+
continueOnError: literal(true).optional() };
|
|
44957
|
+
/** An automation's cap step: the shared guarded cap step, plus `continueOnError`. */
|
|
44958
|
+
var AutomationGuardedCapStepSchema = AutomationCapStepBaseSchema.extend({
|
|
44959
|
+
...stepGuardShape,
|
|
44960
|
+
...continueOnErrorShape
|
|
44961
|
+
}).refine((step) => step.target !== void 0 || step.deviceId !== void 0, {
|
|
44962
|
+
message: "a cap step needs a target",
|
|
44963
|
+
path: ["target"]
|
|
44964
|
+
}).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
|
|
44965
|
+
message: "a domain target needs the vocabulary action it applies to (actionId)",
|
|
44966
|
+
path: ["actionId"]
|
|
44967
|
+
}).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
|
|
44968
|
+
/** End the run here, on purpose. `reason` may carry `{{vars.x}}` slots. */
|
|
44969
|
+
var AutomationStopStepSchema = object({
|
|
44970
|
+
kind: literal("stop"),
|
|
44971
|
+
reason: string().min(1, "a stop needs a reason: it is what the run trace shows").max(200),
|
|
44972
|
+
/** `ok`: the run ends as a success. `failed`: it ends as a failure, with the reason. */
|
|
44973
|
+
outcome: _enum(["ok", "failed"]),
|
|
44974
|
+
/** Stop only when this reads true; false or unknown does not stop. */
|
|
44975
|
+
if: AutomationWhenSchema.optional()
|
|
44976
|
+
});
|
|
44977
|
+
var SET_VAR_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]{0,39}$/;
|
|
44978
|
+
/** Names the run itself writes and reads (`leaf` is what `triggered-by` judges): a step may not overwrite them. */
|
|
44979
|
+
var RESERVED_RUN_VARS = [
|
|
44980
|
+
"kind",
|
|
44981
|
+
"leaf",
|
|
44982
|
+
"at"
|
|
44983
|
+
];
|
|
44984
|
+
/**
|
|
44985
|
+
* Write variables into the run's bag, for the steps after it. SUBSTITUTION
|
|
44986
|
+
* only, never evaluation: a text value may carry `{{vars.x}}` slots.
|
|
44987
|
+
*/
|
|
44988
|
+
var AutomationSetStepSchema = object({
|
|
44989
|
+
kind: literal("set"),
|
|
44990
|
+
vars: record(string(), union([
|
|
44991
|
+
string().max(500),
|
|
44992
|
+
number$1(),
|
|
44993
|
+
boolean()
|
|
44994
|
+
])).refine((vars) => Object.keys(vars).every((name) => SET_VAR_NAME_RE.test(name)), { message: "a variable name is letters, digits and _, not starting with a digit (max 40)" }).refine((vars) => Object.keys(vars).length >= 1, { message: "set needs at least one variable" }).refine((vars) => Object.keys(vars).length <= 20, { message: `set holds at most 20 variables` }).refine((vars) => Object.keys(vars).every((name) => !RESERVED_RUN_VARS.includes(name)), { message: `the names ${RESERVED_RUN_VARS.join(", ")} belong to the run and cannot be set` }),
|
|
44995
|
+
/** Set only when this reads true; false or unknown leaves the bag as it is. */
|
|
44996
|
+
if: AutomationWhenSchema.optional()
|
|
44997
|
+
});
|
|
44998
|
+
var AutomationRunActionStepSchema = object({
|
|
44999
|
+
kind: literal("action"),
|
|
45000
|
+
/** An entry of the `actions` surface (`internal:<uuid>` or `<addonId>:<localId>`). */
|
|
45001
|
+
actionId: string().min(1),
|
|
45002
|
+
/** Values for the action's declared variables; the others take their default. */
|
|
45003
|
+
variables: record(string(), union([
|
|
45004
|
+
string(),
|
|
45005
|
+
number$1(),
|
|
45006
|
+
boolean()
|
|
45007
|
+
])).optional(),
|
|
45008
|
+
...continueOnErrorShape
|
|
45009
|
+
});
|
|
45010
|
+
/**
|
|
45011
|
+
* A step INSIDE a branch of a `choose`: a flow step with no condition of its
|
|
45012
|
+
* own (the branch is the condition) and no block inside it. Strict, so an `if`
|
|
45013
|
+
* written on such a step is refused rather than dropped.
|
|
45014
|
+
*/
|
|
45015
|
+
/** The longest a `wait-until` may wait: six hours. */
|
|
45016
|
+
var WAIT_UNTIL_TIMEOUT_MAX_S = 21600;
|
|
45017
|
+
/**
|
|
45018
|
+
* Pause the run until a condition is true (#500). The timeout is mandatory: a
|
|
45019
|
+
* run never waits without an end. `onTimeout` says what a wait that ran out
|
|
45020
|
+
* does: `continue` goes on to the next step, `stop` ends the run as a failure.
|
|
45021
|
+
* A condition that cannot be read is not "true": the wait goes on (D49).
|
|
45022
|
+
*/
|
|
45023
|
+
var AutomationWaitUntilStepSchema = object({
|
|
45024
|
+
kind: literal("wait-until"),
|
|
45025
|
+
when: AutomationWhenSchema,
|
|
45026
|
+
timeoutS: number$1().int().min(1, "a wait needs a timeout of at least one second").max(WAIT_UNTIL_TIMEOUT_MAX_S, `a wait for a condition is at most six hours (${WAIT_UNTIL_TIMEOUT_MAX_S} s)`),
|
|
45027
|
+
onTimeout: _enum(["continue", "stop"])
|
|
45028
|
+
}).strict();
|
|
45029
|
+
/** The step kinds that hold steps of their own, or pause on a condition: they nest two levels at most. */
|
|
45030
|
+
var BLOCK_STEP_KINDS = [
|
|
45031
|
+
"choose",
|
|
45032
|
+
"repeat",
|
|
45033
|
+
"parallel",
|
|
45034
|
+
"wait-until"
|
|
45035
|
+
];
|
|
45036
|
+
var NEST_TOO_DEEP = `steps nest two levels at most: a step inside a nested choose or repeat can be a plain step only`;
|
|
45037
|
+
function kindOf(input) {
|
|
45038
|
+
return typeof input === "object" && input !== null ? Reflect.get(input, "kind") : void 0;
|
|
45039
|
+
}
|
|
45040
|
+
/** Where the nesting ends, a block step is refused in words rather than as an unknown kind. */
|
|
45041
|
+
function nestTooDeep(issue) {
|
|
45042
|
+
const kind = kindOf(issue.input);
|
|
45043
|
+
return typeof kind === "string" && BLOCK_STEP_KINDS.includes(kind) ? NEST_TOO_DEEP : void 0;
|
|
45044
|
+
}
|
|
45045
|
+
var plainStepSchemas = [
|
|
45046
|
+
AutomationWaitStepSchema.strict(),
|
|
45047
|
+
AutomationCapStepBaseSchema.extend(continueOnErrorShape).strict().refine((step) => step.target !== void 0 || step.deviceId !== void 0, {
|
|
45048
|
+
message: "a cap step needs a target",
|
|
45049
|
+
path: ["target"]
|
|
45050
|
+
}).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
|
|
45051
|
+
message: "a domain target needs the vocabulary action it applies to (actionId)",
|
|
45052
|
+
path: ["actionId"]
|
|
45053
|
+
}),
|
|
45054
|
+
AutomationStopStepSchema.omit({ if: true }).strict(),
|
|
45055
|
+
AutomationSetStepSchema.omit({ if: true }).strict(),
|
|
45056
|
+
AutomationRunActionStepSchema.strict()
|
|
45057
|
+
];
|
|
45058
|
+
/**
|
|
45059
|
+
* A plain step: a flow step with no condition of its own and no step inside
|
|
45060
|
+
* it. The second (last) level of nesting holds these only.
|
|
45061
|
+
*/
|
|
45062
|
+
var AutomationBranchStepSchema = discriminatedUnion("kind", plainStepSchemas, { error: nestTooDeep });
|
|
45063
|
+
/** A step that can run beside others: it writes no variable and does not end the run. */
|
|
45064
|
+
var AutomationParallelMemberSchema = AutomationBranchStepSchema.refine((step) => step.kind === "cap" || step.kind === "action" || step.kind === "wait", "a parallel holds device commands, actions and waits only: a set or a stop beside other steps has no order");
|
|
45065
|
+
/**
|
|
45066
|
+
* Several steps at once (#500): all are started together and all are awaited.
|
|
45067
|
+
* A failure fails the run once the others finished, as in a sequence; a member
|
|
45068
|
+
* marked "continue if this fails" does not.
|
|
45069
|
+
*/
|
|
45070
|
+
var AutomationParallelStepSchema = object({
|
|
45071
|
+
kind: literal("parallel"),
|
|
45072
|
+
steps: array(AutomationParallelMemberSchema).min(2, "a parallel needs at least two steps").max(5, `a parallel takes at most 5 steps`)
|
|
45073
|
+
}).strict();
|
|
45074
|
+
var REPEAT_NEEDS_MAX = "a repeat on a condition needs a maximum number of iterations";
|
|
45075
|
+
/** A loop on a condition: the bound is mandatory, so a run never loops without an end. */
|
|
45076
|
+
var repeatConditionShape = {
|
|
45077
|
+
when: AutomationWhenSchema,
|
|
45078
|
+
maxIterations: number$1({ error: REPEAT_NEEDS_MAX }).int().min(1, REPEAT_NEEDS_MAX).max(50, `a repeat on a condition runs at most 50 times`),
|
|
45079
|
+
/** A pause between two iterations, never after the last. */
|
|
45080
|
+
waitS: number$1().int().min(1).max(WAIT_MAX_SECONDS, WAIT_TOO_LONG).optional()
|
|
45081
|
+
};
|
|
45082
|
+
/** What decides how many times a `repeat` runs. */
|
|
45083
|
+
var AutomationRepeatLoopSchema = discriminatedUnion("by", [
|
|
45084
|
+
object({
|
|
45085
|
+
by: literal("count"),
|
|
45086
|
+
count: number$1().int().min(1).max(20, `a repeat runs at most 20 times`)
|
|
45087
|
+
}).strict(),
|
|
45088
|
+
object({
|
|
45089
|
+
by: literal("while"),
|
|
45090
|
+
...repeatConditionShape
|
|
45091
|
+
}).strict(),
|
|
45092
|
+
object({
|
|
45093
|
+
by: literal("until"),
|
|
45094
|
+
...repeatConditionShape
|
|
45095
|
+
}).strict(),
|
|
45096
|
+
object({
|
|
45097
|
+
by: literal("forEach"),
|
|
45098
|
+
target: object({
|
|
45099
|
+
kind: literal("devices"),
|
|
45100
|
+
ids: array(number$1().int()).min(1, "a repeat over devices needs at least one device").max(50, `a repeat over devices takes at most 50 devices`)
|
|
45101
|
+
}).strict()
|
|
45102
|
+
}).strict()
|
|
45103
|
+
]);
|
|
45104
|
+
/**
|
|
45105
|
+
* The same steps several times (#500). Every form is bounded at save, so a
|
|
45106
|
+
* run cannot loop without an end. A failure or a `stop` in the steps ends the
|
|
45107
|
+
* loop and the run, as in a sequence.
|
|
45108
|
+
*/
|
|
45109
|
+
function repeatSchemaOf(step) {
|
|
45110
|
+
return object({
|
|
45111
|
+
kind: literal("repeat"),
|
|
45112
|
+
loop: AutomationRepeatLoopSchema,
|
|
45113
|
+
steps: array(step).min(1, "a repeat needs at least one step").max(10, `a repeat takes at most 10 steps`)
|
|
45114
|
+
}).strict();
|
|
45115
|
+
}
|
|
45116
|
+
/**
|
|
45117
|
+
* One step, several ways (#500): the branches are read in order and the FIRST
|
|
45118
|
+
* whose condition is true runs; `else` runs when every branch is false. A
|
|
45119
|
+
* branch that cannot be read ends the choice: nothing runs, not the branches
|
|
45120
|
+
* after it and not the else (D49). The #472 `if` / `else` of a wait or cap
|
|
45121
|
+
* step is the one-branch case and stays as it is stored.
|
|
45122
|
+
*/
|
|
45123
|
+
function chooseSchemaOf(step) {
|
|
45124
|
+
const steps = array(step).max(10);
|
|
45125
|
+
return object({
|
|
45126
|
+
kind: literal("choose"),
|
|
45127
|
+
branches: array(object({
|
|
45128
|
+
if: AutomationWhenSchema,
|
|
45129
|
+
steps: steps.min(1, "a branch needs at least one step")
|
|
45130
|
+
})).min(1, "a choose needs at least one branch").max(6, `a choose takes at most 6 branches`),
|
|
45131
|
+
else: steps.optional()
|
|
45132
|
+
});
|
|
45133
|
+
}
|
|
45134
|
+
var AutomationBodyStepSchema = discriminatedUnion("kind", [
|
|
45135
|
+
...plainStepSchemas,
|
|
45136
|
+
AutomationWaitUntilStepSchema,
|
|
45137
|
+
AutomationParallelStepSchema,
|
|
45138
|
+
chooseSchemaOf(AutomationBranchStepSchema),
|
|
45139
|
+
repeatSchemaOf(AutomationBranchStepSchema)
|
|
45140
|
+
]);
|
|
45141
|
+
var AutomationRepeatStepSchema = repeatSchemaOf(AutomationBodyStepSchema);
|
|
44865
45142
|
var AutomationActionSchema = discriminatedUnion("kind", [
|
|
44866
45143
|
GuardedWaitStepSchema,
|
|
44867
|
-
|
|
44868
|
-
|
|
44869
|
-
|
|
44870
|
-
|
|
44871
|
-
|
|
44872
|
-
|
|
44873
|
-
|
|
44874
|
-
|
|
44875
|
-
number$1(),
|
|
44876
|
-
boolean()
|
|
44877
|
-
])).optional()
|
|
44878
|
-
}),
|
|
45144
|
+
AutomationGuardedCapStepSchema,
|
|
45145
|
+
AutomationStopStepSchema,
|
|
45146
|
+
AutomationSetStepSchema,
|
|
45147
|
+
chooseSchemaOf(AutomationBodyStepSchema),
|
|
45148
|
+
AutomationWaitUntilStepSchema,
|
|
45149
|
+
AutomationParallelStepSchema,
|
|
45150
|
+
AutomationRepeatStepSchema,
|
|
45151
|
+
AutomationRunActionStepSchema,
|
|
44879
45152
|
object({
|
|
44880
45153
|
kind: literal("code"),
|
|
44881
45154
|
/** Compiled into the automation's OWN block by esbuild — not a third
|
|
@@ -44938,11 +45211,6 @@ function convertLegacyRecipe(legacy) {
|
|
|
44938
45211
|
...rest
|
|
44939
45212
|
};
|
|
44940
45213
|
}
|
|
44941
|
-
/**
|
|
44942
|
-
* Where recipes are PARSED (the core-blocks cap, the MCP tool, the literal a
|
|
44943
|
-
* saved block carries): the new shape as it is, or the old shape converted to
|
|
44944
|
-
* it. The output type is always the new one.
|
|
44945
|
-
*/
|
|
44946
45214
|
var AutomationRecipeSchema = union([CurrentAutomationRecipeSchema, LegacyAutomationRecipeSchema.transform(convertLegacyRecipe)]);
|
|
44947
45215
|
var DETECTION_DESCRIPTIONS = {
|
|
44948
45216
|
deviceId: "the camera that saw it",
|
|
@@ -44963,6 +45231,16 @@ var BECOMES_DESCRIPTIONS = {
|
|
|
44963
45231
|
from: "the value before the change, empty when it is not known",
|
|
44964
45232
|
to: "the value it changed to"
|
|
44965
45233
|
};
|
|
45234
|
+
/**
|
|
45235
|
+
* A fire's payload is offered too, as `data.<path>` (`{{vars.data.channel}}`):
|
|
45236
|
+
* those names depend on the device, so they are not in this list.
|
|
45237
|
+
*/
|
|
45238
|
+
var FIRED_DESCRIPTIONS = {
|
|
45239
|
+
deviceId: "the device that fired",
|
|
45240
|
+
eventType: "the event, as the device names it",
|
|
45241
|
+
sourceId: "the part of the device that fired (a button), empty when it names none",
|
|
45242
|
+
eventKind: "the kind of press (press, long-press …), empty when the device declares none"
|
|
45243
|
+
};
|
|
44966
45244
|
function describe$1(descriptions) {
|
|
44967
45245
|
return Object.entries(descriptions).map(([name, description]) => ({
|
|
44968
45246
|
name,
|
|
@@ -44971,12 +45249,50 @@ function describe$1(descriptions) {
|
|
|
44971
45249
|
}
|
|
44972
45250
|
describe$1(DETECTION_DESCRIPTIONS);
|
|
44973
45251
|
describe$1(STATIONARY_DESCRIPTIONS);
|
|
45252
|
+
describe$1(FIRED_DESCRIPTIONS).map((v) => v.name === "deviceId" ? {
|
|
45253
|
+
...v,
|
|
45254
|
+
hintKey: "firedDeviceId"
|
|
45255
|
+
} : v);
|
|
44974
45256
|
describe$1(BECOMES_DESCRIPTIONS).map((v) => v.name === "deviceId" ? {
|
|
44975
45257
|
...v,
|
|
44976
45258
|
hintKey: "becomesDeviceId"
|
|
44977
45259
|
} : v);
|
|
44978
45260
|
new Set(Object.values(COCO_TO_MACRO.mapping));
|
|
44979
45261
|
/**
|
|
45262
|
+
* Generic stateless event emitter. Installed on a `DeviceType.EventEmitter`
|
|
45263
|
+
* device. Carries the device's EXACT declared event vocabulary verbatim
|
|
45264
|
+
* (NO normalization). Two shapes:
|
|
45265
|
+
* - structured source (HA `event.*` entity) → `vocabulary` is the fixed
|
|
45266
|
+
* declared set (e.g. press_short, press_long, …).
|
|
45267
|
+
* - generic/legacy source (HA bus events, e.g. zha_event) → `vocabulary`
|
|
45268
|
+
* is [] (open) and `lastEvent.data` carries the complex payload.
|
|
45269
|
+
* `vocabulary` (D1044) names each event for a person and types it for a
|
|
45270
|
+
* rule; `eventTypes` is its list of native tokens, kept for older readers.
|
|
45271
|
+
* A fire names the part of the device it came from in `sourceId` when the
|
|
45272
|
+
* vocabulary declares sources (a remote's buttons).
|
|
45273
|
+
* `seq` is monotonic so two identical events still produce distinct slice writes.
|
|
45274
|
+
*/
|
|
45275
|
+
var EventFireSchema = object({
|
|
45276
|
+
deviceId: number$1(),
|
|
45277
|
+
eventType: string(),
|
|
45278
|
+
sourceId: string().optional(),
|
|
45279
|
+
data: record(string(), unknown()).nullable(),
|
|
45280
|
+
timestamp: number$1().meta(readingMeta("none")),
|
|
45281
|
+
seq: number$1().meta(readingMeta("count"))
|
|
45282
|
+
});
|
|
45283
|
+
var EventEmitterStatusSchema = object({
|
|
45284
|
+
eventTypes: array(string()),
|
|
45285
|
+
/**
|
|
45286
|
+
* Required of a provider by the type. A status written before the field
|
|
45287
|
+
* existed still parses, as an empty vocabulary: read it through
|
|
45288
|
+
* `readEventVocabulary`, which then answers with the plain tokens.
|
|
45289
|
+
*/
|
|
45290
|
+
vocabulary: array(EventVocabularyEntrySchema).default([]),
|
|
45291
|
+
lastEvent: EventFireSchema.nullable(),
|
|
45292
|
+
eventCountSinceStart: number$1().meta(readingMeta("count"))
|
|
45293
|
+
});
|
|
45294
|
+
DeviceType.EventEmitter;
|
|
45295
|
+
/**
|
|
44980
45296
|
* Schedulers (D983) — an entity that performs actions over the day.
|
|
44981
45297
|
*
|
|
44982
45298
|
* A scheduler has profiles; a profile has weekdays and a timeline of POINTS.
|
|
@@ -45027,12 +45343,16 @@ var HoldOverrideSchema = discriminatedUnion("mode", [object({ mode: literal("res
|
|
|
45027
45343
|
})]);
|
|
45028
45344
|
/** A missed edge up to this late still runs. */
|
|
45029
45345
|
var DEFAULT_MAX_LATE_MS = 10 * 6e4;
|
|
45346
|
+
var SchedulerStepSchema = ActionStepSchema.refine((step) => step.kind !== "wait" || step.seconds <= 300, {
|
|
45347
|
+
message: `a scheduler point waits at most five minutes (300 s); put a longer wait in an action`,
|
|
45348
|
+
path: ["seconds"]
|
|
45349
|
+
});
|
|
45030
45350
|
var SchedulerPointSchema = object({
|
|
45031
45351
|
id: string().min(1).max(64),
|
|
45032
45352
|
at: SchedulerTimeSpecSchema,
|
|
45033
45353
|
mode: SchedulerPointModeSchema,
|
|
45034
45354
|
/** The actions of an `edge` or `hold`; a `release` has none. */
|
|
45035
|
-
steps: array(
|
|
45355
|
+
steps: array(SchedulerStepSchema).max(20).default([]),
|
|
45036
45356
|
/** Checked when the point runs (an edge) or is applied (a hold). */
|
|
45037
45357
|
conditions: SchedulerStateTreeSchema.optional(),
|
|
45038
45358
|
/** Hold only; absent means `respect`. */
|
|
@@ -45230,6 +45550,7 @@ var AutomationConditionTraceNodeSchema = object({
|
|
|
45230
45550
|
"triggered-by",
|
|
45231
45551
|
"device-becomes",
|
|
45232
45552
|
"device-event",
|
|
45553
|
+
"device-fired",
|
|
45233
45554
|
"schedule",
|
|
45234
45555
|
"interval",
|
|
45235
45556
|
"manual",
|
|
@@ -45300,18 +45621,46 @@ var StepTraceBaseSchema = object({
|
|
|
45300
45621
|
]).optional(),
|
|
45301
45622
|
/** Why the condition read what it read, in the evaluator's own words. */
|
|
45302
45623
|
conditionReason: string().optional(),
|
|
45303
|
-
/** `empty`: the target resolved to no device, so nothing was done — never silently `ok`. `skipped`: its `if` was false (or unknown) and nothing ran in its place. */
|
|
45624
|
+
/** `empty`: the target resolved to no device, so nothing was done — never silently `ok`. `skipped`: its `if` was false (or unknown) and nothing ran in its place. `failed-continued`: it failed and was marked to be passed over (#500). */
|
|
45304
45625
|
outcome: _enum([
|
|
45305
45626
|
"ok",
|
|
45306
45627
|
"error",
|
|
45307
45628
|
"not-run",
|
|
45308
45629
|
"empty",
|
|
45309
|
-
"skipped"
|
|
45630
|
+
"skipped",
|
|
45631
|
+
"failed-continued",
|
|
45632
|
+
"timed-out"
|
|
45310
45633
|
]),
|
|
45311
45634
|
message: string().optional()
|
|
45312
45635
|
});
|
|
45636
|
+
/** What a block step adds to its row: which list ran, what each branch read, how many rounds. */
|
|
45637
|
+
var blockTraceShape = {
|
|
45638
|
+
/** A `choose` step (#500): the list that ran, `branches.<n>` or `else`. Absent when none did. */
|
|
45639
|
+
branch: string().optional(),
|
|
45640
|
+
/** A `choose` step: what each branch read, in order, up to the one that decided. */
|
|
45641
|
+
branchChecks: array(object({
|
|
45642
|
+
condition: _enum([
|
|
45643
|
+
"true",
|
|
45644
|
+
"false",
|
|
45645
|
+
"unknown"
|
|
45646
|
+
]),
|
|
45647
|
+
conditionReason: string().optional()
|
|
45648
|
+
})).optional(),
|
|
45649
|
+
/** A `repeat` step (#500): how many times its steps ran. */
|
|
45650
|
+
iterations: number$1().int().optional()
|
|
45651
|
+
};
|
|
45652
|
+
/** A step one level down: it may be a block step itself, whose own steps are plain rows (the nesting ends there). */
|
|
45653
|
+
var NestedStepTraceSchema = StepTraceBaseSchema.extend({
|
|
45654
|
+
...blockTraceShape,
|
|
45655
|
+
steps: array(StepTraceBaseSchema).optional()
|
|
45656
|
+
});
|
|
45313
45657
|
/** A step trace; the `else` steps that ran are one level of the same shape (the nesting is bounded at one). */
|
|
45314
|
-
var AutomationStepTraceSchema = StepTraceBaseSchema.extend({
|
|
45658
|
+
var AutomationStepTraceSchema = StepTraceBaseSchema.extend({
|
|
45659
|
+
else: array(StepTraceBaseSchema).optional(),
|
|
45660
|
+
...blockTraceShape,
|
|
45661
|
+
/** A `choose` step: the steps of the list that ran. A `parallel`: its members. A `repeat`: the LAST iteration. */
|
|
45662
|
+
steps: array(NestedStepTraceSchema).optional()
|
|
45663
|
+
});
|
|
45315
45664
|
var AutomationRunTraceSchema = object({
|
|
45316
45665
|
runId: string().min(1),
|
|
45317
45666
|
startedAt: number$1(),
|
|
@@ -45801,7 +46150,9 @@ var AddonHttpRouteSchema = object({
|
|
|
45801
46150
|
]).optional(),
|
|
45802
46151
|
description: string().optional(),
|
|
45803
46152
|
/** The hub limits this route per client address before the handler runs. */
|
|
45804
|
-
rateLimit: _enum(["auth"]).optional()
|
|
46153
|
+
rateLimit: _enum(["auth"]).optional(),
|
|
46154
|
+
/** Served once per integration instance; the handler reads `instanceId`. */
|
|
46155
|
+
perInstance: boolean().optional()
|
|
45805
46156
|
});
|
|
45806
46157
|
/**
|
|
45807
46158
|
* Cross-process route invocation envelope. The hub captures the
|
|
@@ -45818,6 +46169,8 @@ var InvokeRequestSchema = object({
|
|
|
45818
46169
|
query: record(string(), string()),
|
|
45819
46170
|
body: unknown(),
|
|
45820
46171
|
headers: record(string(), string()),
|
|
46172
|
+
/** The instance the hub resolved for a `perInstance` route. */
|
|
46173
|
+
instanceId: string().optional(),
|
|
45821
46174
|
user: object({
|
|
45822
46175
|
id: string(),
|
|
45823
46176
|
username: string(),
|
|
@@ -55075,29 +55428,6 @@ var EnumSensorStatusSchema = object({
|
|
|
55075
55428
|
lastFetchedAt: number$1()
|
|
55076
55429
|
});
|
|
55077
55430
|
DeviceType.Sensor;
|
|
55078
|
-
/**
|
|
55079
|
-
* Generic stateless event emitter. Installed on a `DeviceType.EventEmitter`
|
|
55080
|
-
* device. Carries the device's EXACT declared event vocabulary verbatim
|
|
55081
|
-
* (NO normalization). Two shapes:
|
|
55082
|
-
* - structured source (HA `event.*` entity) → `eventTypes` is the fixed
|
|
55083
|
-
* declared vocabulary (e.g. ['press_short','press_long',...]).
|
|
55084
|
-
* - generic/legacy source (HA bus events, e.g. zha_event) → `eventTypes`
|
|
55085
|
-
* is [] (open) and `lastEvent.data` carries the complex payload.
|
|
55086
|
-
* `seq` is monotonic so two identical events still produce distinct slice writes.
|
|
55087
|
-
*/
|
|
55088
|
-
var EventFireSchema = object({
|
|
55089
|
-
deviceId: number$1(),
|
|
55090
|
-
eventType: string(),
|
|
55091
|
-
data: record(string(), unknown()).nullable(),
|
|
55092
|
-
timestamp: number$1().meta(readingMeta("none")),
|
|
55093
|
-
seq: number$1().meta(readingMeta("count"))
|
|
55094
|
-
});
|
|
55095
|
-
var EventEmitterStatusSchema = object({
|
|
55096
|
-
eventTypes: array(string()),
|
|
55097
|
-
lastEvent: EventFireSchema.nullable(),
|
|
55098
|
-
eventCountSinceStart: number$1().meta(readingMeta("count"))
|
|
55099
|
-
});
|
|
55100
|
-
DeviceType.EventEmitter;
|
|
55101
55431
|
var IdentitySchema = object({
|
|
55102
55432
|
id: string(),
|
|
55103
55433
|
name: string(),
|
|
@@ -69288,7 +69618,18 @@ var OauthIntegrationDescriptorSchema = object({
|
|
|
69288
69618
|
* The value is baked into the authorization code at `/authorize` and travels
|
|
69289
69619
|
* on the tokens, so editing this field changes FUTURE links only.
|
|
69290
69620
|
*/
|
|
69291
|
-
refreshTokenTtlSec: union([number$1().int().positive(), literal("never")]).optional()
|
|
69621
|
+
refreshTokenTtlSec: union([number$1().int().positive(), literal("never")]).optional(),
|
|
69622
|
+
/**
|
|
69623
|
+
* The integration instances an account can be linked to (planning#415),
|
|
69624
|
+
* beside the default one. `/api/oauth2/authorize?instance=<id>` is accepted
|
|
69625
|
+
* only for an id listed here; with no `instance=` the link is made to the
|
|
69626
|
+
* default instance, which is never listed and always accepted — it is the
|
|
69627
|
+
* address third parties already hold. Omit for a single-instance integration.
|
|
69628
|
+
*/
|
|
69629
|
+
instances: array(object({
|
|
69630
|
+
id: string(),
|
|
69631
|
+
displayName: string()
|
|
69632
|
+
})).optional()
|
|
69292
69633
|
});
|
|
69293
69634
|
var oauthIntegrationCapability = {
|
|
69294
69635
|
name: "oauth-integration",
|
|
@@ -75433,6 +75774,13 @@ var SsoBridgeClaimsSchema = object({
|
|
|
75433
75774
|
/** OAuth authorization-code binding — set only on `oauth-code` tokens. */
|
|
75434
75775
|
redirectUri: string().optional(),
|
|
75435
75776
|
integrationId: string().optional(),
|
|
75777
|
+
/**
|
|
75778
|
+
* The integration INSTANCE an OAuth link was made for (planning#415). Set on
|
|
75779
|
+
* `oauth-code`, `oauth-access` and `oauth-refresh` tokens of a link made
|
|
75780
|
+
* with `instance=`; absent on a link to the default instance. A cloud relay
|
|
75781
|
+
* reads it off the access token to route; the hub answers from the session.
|
|
75782
|
+
*/
|
|
75783
|
+
instanceId: string().optional(),
|
|
75436
75784
|
/** JWT ID — unique per issued code; consumed-set enforces single-use. */
|
|
75437
75785
|
jti: string().optional(),
|
|
75438
75786
|
/** PKCE S256 challenge — set only on `oauth-code` tokens issued to a public
|
|
@@ -77521,6 +77869,8 @@ var OauthSessionSummarySchema = object({
|
|
|
77521
77869
|
userId: string(),
|
|
77522
77870
|
username: string(),
|
|
77523
77871
|
integrationId: string(),
|
|
77872
|
+
/** The instance the link was made for; `null` = the default instance. */
|
|
77873
|
+
instanceId: string().nullable().optional(),
|
|
77524
77874
|
scopes: array(TokenScopeSchema),
|
|
77525
77875
|
createdAt: number$1(),
|
|
77526
77876
|
lastUsedAt: number$1(),
|
|
@@ -77620,6 +77970,9 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(_void(), ob
|
|
|
77620
77970
|
access: "view"
|
|
77621
77971
|
}), method(object({
|
|
77622
77972
|
integrationId: string(),
|
|
77973
|
+
/** The integration instance the link is for. Omit for the default
|
|
77974
|
+
* instance — never pass the addon id to mean it. */
|
|
77975
|
+
instanceId: string().optional(),
|
|
77623
77976
|
userId: string(),
|
|
77624
77977
|
username: string(),
|
|
77625
77978
|
scopes: array(TokenScopeSchema),
|
|
@@ -77658,7 +78011,13 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(_void(), ob
|
|
|
77658
78011
|
}), method(object({ token: string() }), object({
|
|
77659
78012
|
userId: string(),
|
|
77660
78013
|
username: string(),
|
|
77661
|
-
scopes: array(TokenScopeSchema)
|
|
78014
|
+
scopes: array(TokenScopeSchema),
|
|
78015
|
+
/** The instance the link was made for, read from the SESSION.
|
|
78016
|
+
* Absent = the default instance. `oauthLinkServesInstance` is the
|
|
78017
|
+
* helper a per-instance route calls to compare it with the instance
|
|
78018
|
+
* of its path; no route declares `perInstance` yet (the Alexa
|
|
78019
|
+
* per-instance route, T3, is the first consumer). */
|
|
78020
|
+
instanceId: string().optional()
|
|
77662
78021
|
}).nullable(), { access: "view" }), method(object({ userId: string() }), array(ExternalIdentitySchema), { auth: "admin" }), method(ExternalIdentityKeySchema, object({
|
|
77663
78022
|
userId: string(),
|
|
77664
78023
|
issuer: string()
|
|
@@ -104674,6 +105033,21 @@ async function rotateBrokerCredential(fetchImpl, brokerUrl, credential) {
|
|
|
104674
105033
|
async function revokeBrokerCredential(fetchImpl, brokerUrl, credential) {
|
|
104675
105034
|
await call(fetchImpl, brokerUrl, "/broker/revoke", { bearer: credential }, unknown());
|
|
104676
105035
|
}
|
|
105036
|
+
function judgeTokenInstance(token, skill) {
|
|
105037
|
+
if (token.instanceId !== void 0) return oauthLinkServesInstance({ instanceId: token.instanceId }, skill.id, "export-alexa") ? { kind: "serves" } : {
|
|
105038
|
+
kind: "refused",
|
|
105039
|
+
reason: "token-instance-mismatch"
|
|
105040
|
+
};
|
|
105041
|
+
if (skill.id === "export-alexa") return { kind: "serves" };
|
|
105042
|
+
return skill.hasLinkedUser(token.userId) ? { kind: "serves" } : {
|
|
105043
|
+
kind: "refused",
|
|
105044
|
+
reason: "token-instance-unstated"
|
|
105045
|
+
};
|
|
105046
|
+
}
|
|
105047
|
+
/** The operator-facing sentence for a refusal, sent back to the Lambda and logged. */
|
|
105048
|
+
function describeTokenInstanceRefusal(reason) {
|
|
105049
|
+
return reason === "token-instance-mismatch" ? "the account was linked to another skill instance of this hub" : "the account link names no skill instance and this skill has not linked the account; update the skill Lambda and link again";
|
|
105050
|
+
}
|
|
104677
105051
|
//#endregion
|
|
104678
105052
|
//#region src/handlers/lwa-tokens-callback.ts
|
|
104679
105053
|
/**
|
|
@@ -104698,13 +105072,33 @@ async function revokeBrokerCredential(fetchImpl, brokerUrl, credential) {
|
|
|
104698
105072
|
var OauthVerifiedResultSchema$1 = object({
|
|
104699
105073
|
userId: string(),
|
|
104700
105074
|
username: string(),
|
|
104701
|
-
scopes: array(TokenScopeSchema)
|
|
105075
|
+
scopes: array(TokenScopeSchema),
|
|
105076
|
+
/** The instance the link was made for; absent = the default instance (D1047). */
|
|
105077
|
+
instanceId: string().optional()
|
|
104702
105078
|
}).nullable();
|
|
104703
105079
|
var LwaTokensCallbackBodySchema = object({
|
|
104704
105080
|
lwaAccessToken: string().min(1),
|
|
104705
105081
|
lwaRefreshToken: string().min(1),
|
|
104706
105082
|
expiresAt: number$1().int().nonnegative()
|
|
104707
105083
|
});
|
|
105084
|
+
/**
|
|
105085
|
+
* Refuse (403, logged with the reason) a caller whose token was linked to another instance.
|
|
105086
|
+
* True when the reply was sent; the caller must return.
|
|
105087
|
+
*/
|
|
105088
|
+
function refusedForInstance(caller, reply, deps, label) {
|
|
105089
|
+
const verdict = deps.judgeInstance(caller);
|
|
105090
|
+
if (verdict.kind === "serves") return false;
|
|
105091
|
+
deps.logger.warn(`${label}: refused — ${verdict.reason}`, { meta: {
|
|
105092
|
+
instanceId: deps.instanceId,
|
|
105093
|
+
tokenInstanceId: caller.instanceId ?? null,
|
|
105094
|
+
userId: caller.userId
|
|
105095
|
+
} });
|
|
105096
|
+
reply.code(403).send({
|
|
105097
|
+
error: verdict.reason,
|
|
105098
|
+
message: describeTokenInstanceRefusal(verdict.reason)
|
|
105099
|
+
});
|
|
105100
|
+
return true;
|
|
105101
|
+
}
|
|
104708
105102
|
async function handleLwaTokensCallback(request, reply, deps) {
|
|
104709
105103
|
const parsed = LwaTokensCallbackBodySchema.safeParse(request.body);
|
|
104710
105104
|
if (!parsed.success) {
|
|
@@ -104724,6 +105118,7 @@ async function handleLwaTokensCallback(request, reply, deps) {
|
|
|
104724
105118
|
});
|
|
104725
105119
|
return;
|
|
104726
105120
|
}
|
|
105121
|
+
if (refusedForInstance(caller, reply, deps, "alexa lwa-tokens-callback")) return;
|
|
104727
105122
|
const { userId, username } = caller;
|
|
104728
105123
|
await deps.upsertToken({
|
|
104729
105124
|
userId,
|
|
@@ -104750,10 +105145,14 @@ async function resolveCaller(request, deps) {
|
|
|
104750
105145
|
if (!bearer) return null;
|
|
104751
105146
|
const rawVerified = await deps.ctx.api.userManagement.oauthVerifyAccessToken.query({ token: bearer });
|
|
104752
105147
|
const verifiedParse = OauthVerifiedResultSchema$1.safeParse(rawVerified);
|
|
104753
|
-
if (verifiedParse.success && verifiedParse.data)
|
|
104754
|
-
userId
|
|
104755
|
-
|
|
104756
|
-
|
|
105148
|
+
if (verifiedParse.success && verifiedParse.data) {
|
|
105149
|
+
const { userId, username, instanceId } = verifiedParse.data;
|
|
105150
|
+
return {
|
|
105151
|
+
userId,
|
|
105152
|
+
username,
|
|
105153
|
+
...instanceId !== void 0 ? { instanceId } : {}
|
|
105154
|
+
};
|
|
105155
|
+
}
|
|
104757
105156
|
deps.logger.debug("alexa lwa-tokens-callback: bearer present but did not verify");
|
|
104758
105157
|
return null;
|
|
104759
105158
|
}
|
|
@@ -104826,6 +105225,7 @@ async function handleBrokerLinkCallback(request, reply, deps) {
|
|
|
104826
105225
|
});
|
|
104827
105226
|
return;
|
|
104828
105227
|
}
|
|
105228
|
+
if (refusedForInstance(caller, reply, deps, "alexa broker-link")) return;
|
|
104829
105229
|
await deps.upsertToken({
|
|
104830
105230
|
userId: caller.userId,
|
|
104831
105231
|
accessToken: body.lwaAccessToken,
|
|
@@ -105106,12 +105506,16 @@ async function handleSnapshotFetch(req, reply, deps) {
|
|
|
105106
105506
|
* we register via the `addon-routes` capability.
|
|
105107
105507
|
*
|
|
105108
105508
|
* Public URLs (assuming the hub is reachable as `https://<hub>`):
|
|
105109
|
-
* POST /addon/export-alexa/
|
|
105110
|
-
* POST /addon/export-alexa/oauth/broker-link
|
|
105111
|
-
* POST /addon/export-alexa/oauth/lwa-tokens
|
|
105509
|
+
* POST /addon/export-alexa[/instances/:instanceId]/directive
|
|
105510
|
+
* POST /addon/export-alexa[/instances/:instanceId]/oauth/broker-link (Lambda → hub, D753)
|
|
105511
|
+
* POST /addon/export-alexa[/instances/:instanceId]/oauth/lwa-tokens (Lambda → hub, pre-D753)
|
|
105512
|
+
*
|
|
105513
|
+
* The three are `perInstance` routes (D1046): the hub reads the instance segment. Without one
|
|
105514
|
+
* the skill is found by its ingress token, then falls back to the default skill
|
|
105515
|
+
* (`instance-routing.ts`). The same three with a trailing `/:instanceId` are the addresses a
|
|
105516
|
+
* Lambda built with `HUB_INSTANCE_ID` before D1046 still calls (planning#422); they stay.
|
|
105112
105517
|
*
|
|
105113
|
-
*
|
|
105114
|
-
* to the first skill (`instance-routing.ts`).
|
|
105518
|
+
* A token linked to another instance is refused (`token-instance.ts`, D1047).
|
|
105115
105519
|
*
|
|
105116
105520
|
* OAuth account-linking is handled by the core `/oauth2/*` server
|
|
105117
105521
|
* (integration=export-alexa). This addon registers an `oauth-integration`
|
|
@@ -105120,23 +105524,26 @@ async function handleSnapshotFetch(req, reply, deps) {
|
|
|
105120
105524
|
var OauthVerifiedResultSchema = object({
|
|
105121
105525
|
userId: string(),
|
|
105122
105526
|
username: string(),
|
|
105123
|
-
scopes: array(TokenScopeSchema)
|
|
105527
|
+
scopes: array(TokenScopeSchema),
|
|
105528
|
+
/** The instance the link was made for; absent = the default instance (D1047). */
|
|
105529
|
+
instanceId: string().optional()
|
|
105124
105530
|
}).nullable();
|
|
105125
105531
|
/** Header the D753 Lambda sends its broker origin on. */
|
|
105126
105532
|
var BROKER_HEADER = "x-camstack-broker";
|
|
105127
105533
|
function buildRoutes(deps) {
|
|
105128
105534
|
const forSkill = (description, path, handler) => [{
|
|
105129
105535
|
method: "POST",
|
|
105130
|
-
path
|
|
105536
|
+
path,
|
|
105131
105537
|
access: "public",
|
|
105132
|
-
|
|
105133
|
-
|
|
105538
|
+
perInstance: true,
|
|
105539
|
+
description: `${description} (the skill named by the instance segment; without one, the skill that presents its ingress token, else the default skill)`,
|
|
105540
|
+
handler: (req, reply) => routeToSkill(req, reply, deps, explicitInstance(req.instanceId), handler)
|
|
105134
105541
|
}, {
|
|
105135
105542
|
method: "POST",
|
|
105136
|
-
path
|
|
105543
|
+
path: `${path}/:instanceId`,
|
|
105137
105544
|
access: "public",
|
|
105138
|
-
description: `${description} (
|
|
105139
|
-
handler: (req, reply) => routeToSkill(req, reply, deps,
|
|
105545
|
+
description: `${description} (one skill, named after the path: the address older Lambdas call)`,
|
|
105546
|
+
handler: (req, reply) => routeToSkill(req, reply, deps, req.params["instanceId"], handler)
|
|
105140
105547
|
}];
|
|
105141
105548
|
return [
|
|
105142
105549
|
...forSkill("Alexa Smart Home directive ingress (forwarded by the user-owned Lambda)", "/directive", (req, reply, skill) => handleDirective(req, reply, deps, skill)),
|
|
@@ -105157,6 +105564,14 @@ function buildRoutes(deps) {
|
|
|
105157
105564
|
}
|
|
105158
105565
|
];
|
|
105159
105566
|
}
|
|
105567
|
+
/**
|
|
105568
|
+
* The instance a per-instance request names for the resolver. The default instance (no segment,
|
|
105569
|
+
* or the addon id) names none: its address is shared with a Lambda that finds its skill by the
|
|
105570
|
+
* ingress header (planning#422), so the resolver keeps that lookup for it.
|
|
105571
|
+
*/
|
|
105572
|
+
function explicitInstance(instanceId) {
|
|
105573
|
+
return instanceId === void 0 || instanceId === "export-alexa" ? void 0 : instanceId;
|
|
105574
|
+
}
|
|
105160
105575
|
/** Resolve the request's skill, or answer that there is none. */
|
|
105161
105576
|
async function routeToSkill(request, reply, deps, pathInstanceId, handler) {
|
|
105162
105577
|
const skill = deps.resolveSkill({
|
|
@@ -105269,6 +105684,19 @@ async function handleDirective(request, reply, deps, skill) {
|
|
|
105269
105684
|
reply.code(200).send(preParseErrorEnvelope("INVALID_AUTHORIZATION_CREDENTIAL", verdict.kind === "stale" ? "token was issued for another hub address; re-link the Alexa skill" : `hub has no public endpoint (${verdict.reason.code}); set it on the Network page`));
|
|
105270
105685
|
return;
|
|
105271
105686
|
}
|
|
105687
|
+
const instanceVerdict = judgeTokenInstance(verified, skill);
|
|
105688
|
+
if (instanceVerdict.kind === "refused") {
|
|
105689
|
+
deps.logger.warn(`alexa directive: refused — ${instanceVerdict.reason}`, {
|
|
105690
|
+
...arrival.deviceId !== void 0 ? { tags: { deviceId: arrival.deviceId } } : {},
|
|
105691
|
+
meta: {
|
|
105692
|
+
instanceId: skill.id,
|
|
105693
|
+
tokenInstanceId: verified.instanceId ?? null,
|
|
105694
|
+
userId: verified.userId
|
|
105695
|
+
}
|
|
105696
|
+
});
|
|
105697
|
+
reply.code(200).send(preParseErrorEnvelope("INVALID_AUTHORIZATION_CREDENTIAL", describeTokenInstanceRefusal(instanceVerdict.reason)));
|
|
105698
|
+
return;
|
|
105699
|
+
}
|
|
105272
105700
|
try {
|
|
105273
105701
|
assertDeviceScope(verified.scopes);
|
|
105274
105702
|
} catch {
|
|
@@ -106036,25 +106464,6 @@ var ADDON_MIGRATIONS = [
|
|
|
106036
106464
|
//#endregion
|
|
106037
106465
|
//#region src/oauth-integration.ts
|
|
106038
106466
|
/**
|
|
106039
|
-
* The `export-alexa` OAuth client — the descriptor behind
|
|
106040
|
-
* `/api/oauth2/authorize?integration=export-alexa`.
|
|
106041
|
-
*
|
|
106042
|
-
* Shaped deliberately like
|
|
106043
|
-
* `packages/addon-provider-homeassistant/src/ha-export/oauth-integration.ts`:
|
|
106044
|
-
* one named `OauthIntegrationDescriptor` per integration, in its own module,
|
|
106045
|
-
* registered from the addon's `onInitialize` through `oauthIntegrationCapability`
|
|
106046
|
-
* ([D101](../../../docs/decisions/adr-0101.md)). The two integrations differ
|
|
106047
|
-
* only in the FIELDS below, never in how they are declared — which is the whole
|
|
106048
|
-
* claim being made: a third one is configuration, not framework work.
|
|
106049
|
-
*
|
|
106050
|
-
* Typed rather than inlined, and that is not cosmetic. As an untyped object
|
|
106051
|
-
* literal this needed three `as const` assertions to satisfy the schema and was
|
|
106052
|
-
* checked for the first time at `/authorize`, i.e. in front of an operator
|
|
106053
|
-
* mid-link. The annotation moves that to compile time.
|
|
106054
|
-
*
|
|
106055
|
-
* @see docs/decisions/adr-0092.md — why `client_secret` is never checked here.
|
|
106056
|
-
*/
|
|
106057
|
-
/**
|
|
106058
106467
|
* Where Alexa lands after consent — Amazon's three regional account-linking
|
|
106059
106468
|
* origins, fixed and public. Contrast Home Assistant, whose callback is on the
|
|
106060
106469
|
* operator's own LAN and needs `allowedPrivateHostPaths`; that difference is
|
|
@@ -106090,7 +106499,7 @@ var ALEXA_REDIRECT_PREFIXES = [
|
|
|
106090
106499
|
* no `requiresPkce` here. That is a property of the two clients, expressed
|
|
106091
106500
|
* through the same descriptor field.
|
|
106092
106501
|
*/
|
|
106093
|
-
function buildAlexaOauthIntegration(publicOrigin) {
|
|
106502
|
+
function buildAlexaOauthIntegration(publicOrigin, instances = []) {
|
|
106094
106503
|
return {
|
|
106095
106504
|
integrationId: "export-alexa",
|
|
106096
106505
|
displayName: "Alexa Smart Home",
|
|
@@ -106127,7 +106536,8 @@ function buildAlexaOauthIntegration(publicOrigin) {
|
|
|
106127
106536
|
* "Unlink Amazon account" button does; see `unlinkAlexaAccounts`.
|
|
106128
106537
|
*/
|
|
106129
106538
|
refreshTokenTtlSec: "never",
|
|
106130
|
-
...publicOrigin ? { hubUrl: publicOrigin } : {}
|
|
106539
|
+
...publicOrigin ? { hubUrl: publicOrigin } : {},
|
|
106540
|
+
...instances.length > 0 ? { instances: [...instances] } : {}
|
|
106131
106541
|
};
|
|
106132
106542
|
}
|
|
106133
106543
|
//#endregion
|
|
@@ -109870,15 +110280,22 @@ var SkillRuntime = class {
|
|
|
109870
110280
|
}
|
|
109871
110281
|
/** The routes' view of this skill: what a directive or a Lambda callback acts on. */
|
|
109872
110282
|
routed() {
|
|
110283
|
+
const hasLinkedUser = (userId) => this.view.linkedAccounts.some((a) => a.userId === userId);
|
|
109873
110284
|
return {
|
|
109874
110285
|
id: this.instanceId,
|
|
109875
110286
|
getSettings: () => this.effectiveSettings(),
|
|
109876
110287
|
directiveDeps: this.directiveDeps(),
|
|
110288
|
+
hasLinkedUser,
|
|
109877
110289
|
lwaTokensCallbackDeps: {
|
|
109878
110290
|
ctx: this.ctx,
|
|
109879
110291
|
logger: this.ctx.logger,
|
|
109880
110292
|
upsertToken: (input) => this.upsertToken(input),
|
|
109881
|
-
recordLinkedAccount: (input) => this.recordLinkedAccount(input)
|
|
110293
|
+
recordLinkedAccount: (input) => this.recordLinkedAccount(input),
|
|
110294
|
+
instanceId: this.instanceId,
|
|
110295
|
+
judgeInstance: (caller) => judgeTokenInstance(caller, {
|
|
110296
|
+
id: this.instanceId,
|
|
110297
|
+
hasLinkedUser
|
|
110298
|
+
})
|
|
109882
110299
|
},
|
|
109883
110300
|
onBrokerAdvertised: (raw) => this.rememberAdvertisedBroker(raw)
|
|
109884
110301
|
};
|
|
@@ -111250,7 +111667,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
111250
111667
|
const oauthIntegrationProvider = { getDescriptor: async () => {
|
|
111251
111668
|
const endpoint = await this.publicEndpoint();
|
|
111252
111669
|
if (!endpoint.ok) this.ctx.logger.warn(`export-alexa: linking without a routing claim — ${endpoint.reason.code}: ${endpoint.reason.message}`);
|
|
111253
|
-
return buildAlexaOauthIntegration(endpoint.ok ? endpoint.origin : void 0);
|
|
111670
|
+
return buildAlexaOauthIntegration(endpoint.ok ? endpoint.origin : void 0, this.linkableInstances());
|
|
111254
111671
|
} };
|
|
111255
111672
|
const reaper = setInterval(() => {
|
|
111256
111673
|
this.reapDeadEgressHandles();
|
|
@@ -111298,6 +111715,13 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
111298
111715
|
async onConfigChanged() {
|
|
111299
111716
|
for (const runtime of this.runtimes.values()) await runtime.applyShapeSwitches();
|
|
111300
111717
|
}
|
|
111718
|
+
/** The running skills an account may be linked to with `instance=` (all but the default). */
|
|
111719
|
+
linkableInstances() {
|
|
111720
|
+
return [...this.runtimes.values()].filter((r) => !r.isDefault).map((r) => ({
|
|
111721
|
+
id: r.instanceId,
|
|
111722
|
+
displayName: r.skillName
|
|
111723
|
+
}));
|
|
111724
|
+
}
|
|
111301
111725
|
/** Build and start the runtime of one skill. */
|
|
111302
111726
|
async startRuntime(instanceId) {
|
|
111303
111727
|
const runtime = new SkillRuntime(instanceId, this.host());
|