@camstack/addon-export-alexa 1.2.145 → 1.2.146
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/dist/export-alexa.addon.js +759 -20
- package/dist/export-alexa.addon.mjs +759 -20
- package/lambda-template/broker.js +27 -7
- package/lambda-template/debug-trace.js +2 -1
- package/package.json +1 -1
|
@@ -161,7 +161,11 @@ async function exchangeGrantCode(deps, code, redirectUri) {
|
|
|
161
161
|
})
|
|
162
162
|
const tokens = res.ok ? readLwaTokens(res, null) : null
|
|
163
163
|
if (!tokens) {
|
|
164
|
-
throw new BrokerError(
|
|
164
|
+
throw new BrokerError(
|
|
165
|
+
502,
|
|
166
|
+
'lwa_exchange_failed',
|
|
167
|
+
`LWA exchange ${res.status} ${lwaErrorCode(res) || ''}`.trim(),
|
|
168
|
+
)
|
|
165
169
|
}
|
|
166
170
|
return tokens
|
|
167
171
|
}
|
|
@@ -171,12 +175,21 @@ async function refreshGrant(deps, refreshToken) {
|
|
|
171
175
|
const res = await lwaTokenCall(deps, { grant_type: 'refresh_token', refresh_token: refreshToken })
|
|
172
176
|
if (!res.ok) {
|
|
173
177
|
if (lwaErrorCode(res) === 'invalid_grant') {
|
|
174
|
-
throw new BrokerError(
|
|
178
|
+
throw new BrokerError(
|
|
179
|
+
410,
|
|
180
|
+
'grant_revoked',
|
|
181
|
+
'Amazon no longer honours this grant; re-link the skill',
|
|
182
|
+
)
|
|
175
183
|
}
|
|
176
|
-
throw new BrokerError(
|
|
184
|
+
throw new BrokerError(
|
|
185
|
+
502,
|
|
186
|
+
'lwa_unavailable',
|
|
187
|
+
`LWA refresh ${res.status} ${lwaErrorCode(res) || ''}`.trim(),
|
|
188
|
+
)
|
|
177
189
|
}
|
|
178
190
|
const tokens = readLwaTokens(res, refreshToken)
|
|
179
|
-
if (!tokens)
|
|
191
|
+
if (!tokens)
|
|
192
|
+
throw new BrokerError(502, 'lwa_malformed', 'LWA refresh answered without an access token')
|
|
180
193
|
return tokens
|
|
181
194
|
}
|
|
182
195
|
|
|
@@ -213,7 +226,12 @@ async function createLink(deps, opts) {
|
|
|
213
226
|
}
|
|
214
227
|
|
|
215
228
|
async function activateLink(deps, item) {
|
|
216
|
-
const next = {
|
|
229
|
+
const next = {
|
|
230
|
+
...item,
|
|
231
|
+
status: 'active',
|
|
232
|
+
ttl: nowSec(deps) + IDLE_TTL_SEC,
|
|
233
|
+
version: item.version + 1,
|
|
234
|
+
}
|
|
217
235
|
const ok = await deps.store.replace(next, item.version)
|
|
218
236
|
if (!ok) throw new BrokerError(409, 'conflict', 'link changed while activating')
|
|
219
237
|
return next
|
|
@@ -222,7 +240,8 @@ async function activateLink(deps, item) {
|
|
|
222
240
|
/** Resolve the request's credential to an ACTIVE item, or throw 401. */
|
|
223
241
|
async function authenticate(deps, event) {
|
|
224
242
|
const parsed = parseCredential(readBearer(event))
|
|
225
|
-
if (!parsed)
|
|
243
|
+
if (!parsed)
|
|
244
|
+
throw new BrokerError(401, 'invalid_credential', 'broker credential missing or malformed')
|
|
226
245
|
const item = await deps.store.get(parsed.linkId)
|
|
227
246
|
// One answer for "no such link", "not active" and "wrong secret" — the
|
|
228
247
|
// response must not tell a prober which linkIds exist.
|
|
@@ -291,7 +310,8 @@ async function handleBrokerRoute(event, deps) {
|
|
|
291
310
|
return await ROUTES[event.rawPath](event, deps)
|
|
292
311
|
} catch (err) {
|
|
293
312
|
if (err instanceof BrokerError) {
|
|
294
|
-
if (err.status >= 500)
|
|
313
|
+
if (err.status >= 500)
|
|
314
|
+
deps.log.warn('broker: request failed', { route: event.rawPath, code: err.code })
|
|
295
315
|
return jsonResponse(err.status, { error: err.code, message: err.message })
|
|
296
316
|
}
|
|
297
317
|
throw err
|
|
@@ -74,7 +74,8 @@ function summariseResponse(body) {
|
|
|
74
74
|
} else {
|
|
75
75
|
out.payloadKeys = payloadShape(payload)
|
|
76
76
|
}
|
|
77
|
-
const props =
|
|
77
|
+
const props =
|
|
78
|
+
body.context && Array.isArray(body.context.properties) ? body.context.properties : null
|
|
78
79
|
if (props) {
|
|
79
80
|
out.properties = props.map(
|
|
80
81
|
(p) => `${str(p && p.namespace)}.${str(p && p.name)}=${summariseValue(p && p.value)}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camstack/addon-export-alexa",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.146",
|
|
4
4
|
"description": "Alexa Smart Home Skill export — hub-side OAuth provider + directive handler. The companion AWS Lambda forwards Alexa directives to this addon's /addon/export-alexa/directive endpoint.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"camstack",
|