@camstack/addon-export-alexa 1.2.183 → 1.2.184

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.
@@ -34,6 +34,11 @@
34
34
  * instead of receiving the refresh token. Default on.
35
35
  * ALLOW_MIGRATION "0" = refuse /broker/migrate. Default on.
36
36
  * HUB_INGRESS_TOKEN Optional defense-in-depth header for hub calls.
37
+ * HUB_INSTANCE_ID Optional; the id of this skill's instance on the hub
38
+ * (shown in its Export panel). Set when the hub runs
39
+ * several skills: calls then go to `/directive/<id>`,
40
+ * `/oauth/broker-link/<id>` and `/oauth/lwa-tokens/<id>`.
41
+ * Unset = the hub's first skill, as before.
37
42
  * DEBUG_DIRECTIVES "1" = log one `directive_trace` line per directive
38
43
  * (debug-trace.js; never the bearer). Default off.
39
44
  * Legacy (read only when the *_PARAM is unset): LWA_CLIENT_ID,
@@ -303,6 +308,12 @@ async function handleAcceptGrant(event, deps) {
303
308
  return deliverTokensToLegacyHub(deps, header, { hubUrl, granteeToken, tokens })
304
309
  }
305
310
 
311
+ /** The path suffix that names this skill on a hub that runs several (`HUB_INSTANCE_ID`). */
312
+ function hubInstanceSuffix(deps) {
313
+ const id = deps.env.HUB_INSTANCE_ID
314
+ return typeof id === 'string' && id.length > 0 ? `/${encodeURIComponent(id)}` : ''
315
+ }
316
+
306
317
  /**
307
318
  * The D753 link: store the grant here, give the hub only a credential and a
308
319
  * first access token. The item stays `pending` until the hub accepted it, so a
@@ -317,16 +328,19 @@ async function linkViaBroker(deps, input) {
317
328
  })
318
329
  let resp
319
330
  try {
320
- resp = await deps.fetch(`${input.hubUrl}/addon/export-alexa/oauth/broker-link`, {
321
- method: 'POST',
322
- headers: hubHeaders(deps, input.granteeToken),
323
- body: JSON.stringify({
324
- brokerUrl: deps.publicUrl,
325
- brokerCredential: credential,
326
- lwaAccessToken: item.accessToken,
327
- expiresAt: item.accessExpiresAt,
328
- }),
329
- })
331
+ resp = await deps.fetch(
332
+ `${input.hubUrl}/addon/export-alexa/oauth/broker-link${hubInstanceSuffix(deps)}`,
333
+ {
334
+ method: 'POST',
335
+ headers: hubHeaders(deps, input.granteeToken),
336
+ body: JSON.stringify({
337
+ brokerUrl: deps.publicUrl,
338
+ brokerCredential: credential,
339
+ lwaAccessToken: item.accessToken,
340
+ expiresAt: item.accessExpiresAt,
341
+ }),
342
+ },
343
+ )
330
344
  } catch (err) {
331
345
  await deps.store.remove(item.linkId)
332
346
  return { kind: 'failed', message: `hub broker-link unreachable: ${describe(err)}` }
@@ -344,15 +358,18 @@ async function linkViaBroker(deps, input) {
344
358
 
345
359
  /** Pre-D753 hand-off: the hub receives the refresh token itself. */
346
360
  async function deliverTokensToLegacyHub(deps, header, input) {
347
- const callbackResp = await deps.fetch(`${input.hubUrl}/addon/export-alexa/oauth/lwa-tokens`, {
348
- method: 'POST',
349
- headers: hubHeaders(deps, input.granteeToken),
350
- body: JSON.stringify({
351
- lwaAccessToken: input.tokens.accessToken,
352
- lwaRefreshToken: input.tokens.refreshToken,
353
- expiresAt: deps.now() + input.tokens.expiresInSec * 1000,
354
- }),
355
- })
361
+ const callbackResp = await deps.fetch(
362
+ `${input.hubUrl}/addon/export-alexa/oauth/lwa-tokens${hubInstanceSuffix(deps)}`,
363
+ {
364
+ method: 'POST',
365
+ headers: hubHeaders(deps, input.granteeToken),
366
+ body: JSON.stringify({
367
+ lwaAccessToken: input.tokens.accessToken,
368
+ lwaRefreshToken: input.tokens.refreshToken,
369
+ expiresAt: deps.now() + input.tokens.expiresInSec * 1000,
370
+ }),
371
+ },
372
+ )
356
373
  if (!callbackResp.ok) {
357
374
  const text = await callbackResp.text().catch(() => '')
358
375
  return acceptGrantErrorEnvelope(
@@ -390,7 +407,7 @@ async function forwardDirective(event, deps) {
390
407
  endpoint,
391
408
  )
392
409
  }
393
- const target = `${normaliseHubUrl(claims.hubUrl)}/addon/export-alexa/directive`
410
+ const target = `${normaliseHubUrl(claims.hubUrl)}/addon/export-alexa/directive${hubInstanceSuffix(deps)}`
394
411
  let resp
395
412
  try {
396
413
  resp = await deps.fetch(target, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-export-alexa",
3
- "version": "1.2.183",
3
+ "version": "1.2.184",
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",
@@ -59,7 +59,7 @@
59
59
  }
60
60
  ],
61
61
  "requires": {
62
- "server": ">=1.2.762"
62
+ "server": ">=1.2.769"
63
63
  }
64
64
  },
65
65
  "files": [