@camstack/addon-import-alexa 0.2.158 → 0.2.159

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.
Files changed (20) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/{MotionZonesSettings-Z-NRG681.mjs → MotionZonesSettings-DGPV-8dv.mjs} +2 -2
  3. package/dist/{PrivacyMaskSettings-DiS2hPpi.mjs → PrivacyMaskSettings-Cn85uMbr.mjs} +4 -4
  4. package/dist/{SceneMonitorEditor-BYYK_XwY.mjs → SceneMonitorEditor-gIlEt9fl.mjs} +3 -3
  5. package/dist/_stub.js +9 -9
  6. package/dist/{_virtual_mf-localSharedImportMap___mfe_internal__addon_import_alexa_page-B4G6E4Vs.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_import_alexa_page-n3jAYuIE.mjs} +3 -3
  7. package/dist/{_virtual_mf___mfe_internal__addon_import_alexa_page__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-DCV5s91A.mjs → _virtual_mf___mfe_internal__addon_import_alexa_page__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-BwgFX4MI.mjs} +1 -1
  8. package/dist/addon.js +602 -97
  9. package/dist/addon.mjs +602 -97
  10. package/dist/{hostInit-DWBMKrvf.mjs → hostInit-CGhFmOcB.mjs} +2 -2
  11. package/dist/{player-overlays-5MrLqX2i.mjs → player-overlays-BHCfJpas.mjs} +1 -1
  12. package/dist/remoteEntry.js +1 -1
  13. package/dist/{responsive-CsfyZVWS.mjs → responsive-Dclc7CfC.mjs} +1 -1
  14. package/dist/{scene-monitor-copy-DOuMmSwJ.mjs → scene-monitor-copy-BcAIeCGo.mjs} +1 -1
  15. package/dist/{square-BGn7yRva.mjs → square-LLOXavH6.mjs} +1 -1
  16. package/dist/{trash-2-BiBTPv8Y.mjs → trash-2-P7HFzsfr.mjs} +1 -1
  17. package/dist/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__addon_import_alexa_page__remoteEntry_js-BniKFfAU.mjs → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__addon_import_alexa_page__remoteEntry_js-C0zVjr31.mjs} +1 -1
  18. package/i18n/en.json +9 -2
  19. package/i18n/it.json +9 -2
  20. package/package.json +1 -1
package/dist/addon.js CHANGED
@@ -990,7 +990,7 @@ var propertyKeyTypes = /* @__PURE__*/ new Set([
990
990
  "number",
991
991
  "symbol"
992
992
  ]);
993
- function escapeRegex(str) {
993
+ function escapeRegex$1(str) {
994
994
  return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
995
995
  }
996
996
  function clone(inst, def, params) {
@@ -1720,7 +1720,7 @@ var $ZodCheckUpperCase = /*@__PURE__*/ $constructor("$ZodCheckUpperCase", (inst,
1720
1720
  });
1721
1721
  var $ZodCheckIncludes = /*@__PURE__*/ $constructor("$ZodCheckIncludes", (inst, def) => {
1722
1722
  $ZodCheck.init(inst, def);
1723
- const escapedRegex = escapeRegex(def.includes);
1723
+ const escapedRegex = escapeRegex$1(def.includes);
1724
1724
  const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
1725
1725
  def.pattern = pattern;
1726
1726
  inst._zod.onattach.push((inst) => {
@@ -1743,7 +1743,7 @@ var $ZodCheckIncludes = /*@__PURE__*/ $constructor("$ZodCheckIncludes", (inst, d
1743
1743
  });
1744
1744
  var $ZodCheckStartsWith = /*@__PURE__*/ $constructor("$ZodCheckStartsWith", (inst, def) => {
1745
1745
  $ZodCheck.init(inst, def);
1746
- const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
1746
+ const pattern = new RegExp(`^${escapeRegex$1(def.prefix)}.*`);
1747
1747
  def.pattern ?? (def.pattern = pattern);
1748
1748
  inst._zod.onattach.push((inst) => {
1749
1749
  const bag = inst._zod.bag;
@@ -1765,7 +1765,7 @@ var $ZodCheckStartsWith = /*@__PURE__*/ $constructor("$ZodCheckStartsWith", (ins
1765
1765
  });
1766
1766
  var $ZodCheckEndsWith = /*@__PURE__*/ $constructor("$ZodCheckEndsWith", (inst, def) => {
1767
1767
  $ZodCheck.init(inst, def);
1768
- const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
1768
+ const pattern = new RegExp(`.*${escapeRegex$1(def.suffix)}$`);
1769
1769
  def.pattern ?? (def.pattern = pattern);
1770
1770
  inst._zod.onattach.push((inst) => {
1771
1771
  const bag = inst._zod.bag;
@@ -3001,7 +3001,7 @@ var $ZodEnum = /*@__PURE__*/ $constructor("$ZodEnum", (inst, def) => {
3001
3001
  const values = getEnumValues(def.entries);
3002
3002
  const valuesSet = new Set(values);
3003
3003
  inst._zod.values = valuesSet;
3004
- inst._zod.pattern = new RegExp(`^(${values.filter((k) => propertyKeyTypes.has(typeof k)).map((o) => typeof o === "string" ? escapeRegex(o) : o.toString()).join("|")})$`);
3004
+ inst._zod.pattern = new RegExp(`^(${values.filter((k) => propertyKeyTypes.has(typeof k)).map((o) => typeof o === "string" ? escapeRegex$1(o) : o.toString()).join("|")})$`);
3005
3005
  inst._zod.parse = (payload, _ctx) => {
3006
3006
  const input = payload.value;
3007
3007
  if (valuesSet.has(input)) return payload;
@@ -3019,7 +3019,7 @@ var $ZodLiteral = /*@__PURE__*/ $constructor("$ZodLiteral", (inst, def) => {
3019
3019
  if (def.values.length === 0) throw new Error("Cannot create literal schema with no valid values");
3020
3020
  const values = new Set(def.values);
3021
3021
  inst._zod.values = values;
3022
- inst._zod.pattern = new RegExp(`^(${def.values.map((o) => typeof o === "string" ? escapeRegex(o) : o ? escapeRegex(o.toString()) : String(o)).join("|")})$`);
3022
+ inst._zod.pattern = new RegExp(`^(${def.values.map((o) => typeof o === "string" ? escapeRegex$1(o) : o ? escapeRegex$1(o.toString()) : String(o)).join("|")})$`);
3023
3023
  inst._zod.parse = (payload, _ctx) => {
3024
3024
  const input = payload.value;
3025
3025
  if (values.has(input)) return payload;
@@ -90637,6 +90637,448 @@ DEFAULT_NATIVE_LEASE_SETTINGS.activityMs;
90637
90637
  DEFAULT_NATIVE_LEASE_SETTINGS.tileBudgetMb;
90638
90638
  DEFAULT_NATIVE_LEASE_SETTINGS.sceneBudgetMb;
90639
90639
  DEFAULT_NATIVE_LEASE_SETTINGS.admission;
90640
+ /**
90641
+ * Where an OAuth round-trip ends: the admin-ui completion route
90642
+ * (`/sso-complete`, the page every popup sign-in already lands on), with the
90643
+ * OUTCOME in the URL fragment.
90644
+ *
90645
+ * The outcome is a status plus a reason CODE from a closed list. It never
90646
+ * carries a token, a code, a client secret or a free-form error message: the
90647
+ * page words each code itself, and an unknown code reads as `unknown` rather
90648
+ * than being echoed. Fragment only, so nothing here reaches a server log.
90649
+ *
90650
+ * Pure and browser-safe.
90651
+ */
90652
+ /** The admin-ui route the hub's OAuth completions land on (relative to its mount). */
90653
+ var OAUTH_LANDING_PATH = "/sso-complete";
90654
+ /**
90655
+ * The landing URL for `outcome`. `origin` is the hub address the flow already
90656
+ * runs on (from the `local-network` palette role, never a literal); `null`
90657
+ * gives a hub-relative URL.
90658
+ */
90659
+ function oauthLandingUrl(origin, outcome) {
90660
+ const params = new URLSearchParams({
90661
+ return: "oauth",
90662
+ status: outcome.status
90663
+ });
90664
+ if (outcome.addonId !== void 0) params.set("addon", outcome.addonId);
90665
+ if (outcome.brokerId !== void 0) params.set("broker", outcome.brokerId);
90666
+ if (outcome.integration !== void 0) params.set("integration", outcome.integration);
90667
+ if (outcome.status === "error") params.set("reason", outcome.reason ?? "unknown");
90668
+ if (outcome.action === "disconnect") params.set("action", "disconnect");
90669
+ return `${origin === null ? "" : origin.replace(/\/+$/, "")}${OAUTH_LANDING_PATH}#${params.toString()}`;
90670
+ }
90671
+ var LOOPBACK_HOSTS = new Set([
90672
+ "127.0.0.1",
90673
+ "localhost",
90674
+ "[::1]"
90675
+ ]);
90676
+ function hostWithoutPort(host) {
90677
+ if (host.startsWith("[")) return host.slice(0, host.indexOf("]") + 1);
90678
+ const colon = host.indexOf(":");
90679
+ return colon === -1 ? host : host.slice(0, colon);
90680
+ }
90681
+ function isLoopbackHost(host) {
90682
+ return LOOPBACK_HOSTS.has(hostWithoutPort(host.toLowerCase()));
90683
+ }
90684
+ /** An allow-list entry is valid when it is a bare host[:port] and `http` only targets loopback. */
90685
+ function isValidUpstream(upstream) {
90686
+ if (upstream.host.length === 0 || !/^[a-z0-9.[\]:-]+$/.test(upstream.host)) return false;
90687
+ return upstream.scheme === "https" || isLoopbackHost(upstream.host);
90688
+ }
90689
+ function findUpstream(route, host) {
90690
+ const wanted = host.toLowerCase();
90691
+ return route.upstreams.find((upstream) => upstream.host === wanted);
90692
+ }
90693
+ /** `<basePath>/<host><pathname><search>` — what the browser is sent to. */
90694
+ function proxyPathFor(route, host, pathname, search = "") {
90695
+ return `${route.basePath}/${host}${pathname.startsWith("/") ? pathname : `/${pathname}`}${search}`;
90696
+ }
90697
+ /** Split `/<attemptId>/<host>/<rest…>[?query]` (the data-plane view of a request). */
90698
+ function parseProxyPath(rawUrl) {
90699
+ const queryAt = rawUrl.indexOf("?");
90700
+ const path = queryAt === -1 ? rawUrl : rawUrl.slice(0, queryAt);
90701
+ const search = queryAt === -1 ? "" : rawUrl.slice(queryAt);
90702
+ const match = /^\/([A-Za-z0-9_-]{8,128})\/([^/]+)(\/.*)?$/.exec(path);
90703
+ if (match === null) return null;
90704
+ const attemptId = match[1];
90705
+ const host = match[2];
90706
+ if (attemptId === void 0 || host === void 0) return null;
90707
+ return {
90708
+ attemptId,
90709
+ host: host.toLowerCase(),
90710
+ pathname: match[3] ?? "/",
90711
+ search
90712
+ };
90713
+ }
90714
+ /** The vendor URL a proxied request targets, or null when the host would not stay `host`. */
90715
+ function upstreamUrlFor(upstream, parsed) {
90716
+ try {
90717
+ const url = new URL(`${upstream.scheme}://${upstream.host}${parsed.pathname}${parsed.search}`);
90718
+ return url.host.toLowerCase() === upstream.host ? url : null;
90719
+ } catch {
90720
+ return null;
90721
+ }
90722
+ }
90723
+ function escapeRegex(value) {
90724
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
90725
+ }
90726
+ /** A Location (or any URL value) to a vendor host becomes a proxy path; anything else is unchanged. */
90727
+ function rewriteLocation(location, currentUpstream, route) {
90728
+ let resolved;
90729
+ try {
90730
+ resolved = new URL(location, `${currentUpstream.scheme}://${currentUpstream.host}/`);
90731
+ } catch {
90732
+ return location;
90733
+ }
90734
+ if (resolved.protocol !== "https:" && resolved.protocol !== "http:") return location;
90735
+ const target = findUpstream(route, resolved.host);
90736
+ if (target === void 0) return location;
90737
+ return `${proxyPathFor(route, target.host, resolved.pathname, resolved.search)}${resolved.hash}`;
90738
+ }
90739
+ /** Characters that may precede a URL that STARTS a value (never `=`, `?`, `&`, `%3D`). */
90740
+ var VALUE_START = String.raw`(?<=^|["'(\s>,\[{])`;
90741
+ /**
90742
+ * Rewrite vendor URLs in a text body: absolute (`https://host/…`), protocol-relative
90743
+ * (`//host/…`) and JSON-escaped (`https:\/\/host\/…`) when they start a value; and, in
90744
+ * HTML/CSS, root-relative references (`href="/x"`, `url(/x)`) which would otherwise
90745
+ * escape the proxy mount and land on the hub.
90746
+ */
90747
+ function rewriteBody(body, kind, currentUpstream, route) {
90748
+ let out = body;
90749
+ for (const upstream of route.upstreams) {
90750
+ const host = escapeRegex(upstream.host);
90751
+ const plain = new RegExp(`${VALUE_START}(?:https?:)?//${host}(?=[/"'?#\\s)\\]},<]|$)`, "g");
90752
+ out = out.replace(plain, `${route.basePath}/${upstream.host}`);
90753
+ const escapedBase = `${route.basePath}/${upstream.host}`.replace(/\//g, "\\/");
90754
+ const escaped = new RegExp(`${VALUE_START}(?:https?:)?\\\\/\\\\/${host}(?=\\\\/|["'?#\\s)\\]},<]|$)`, "g");
90755
+ out = out.replace(escaped, escapedBase);
90756
+ }
90757
+ const current = `${route.basePath}/${currentUpstream.host}/`;
90758
+ const notMounted = `(?!/)(?!${escapeRegex(route.basePath.slice(1))}/)`;
90759
+ if (kind === "html") {
90760
+ const attribute = String.raw`(\b(?:href|src|action|formaction|poster|data-href|data-src)\s*=\s*["'])/`;
90761
+ out = out.replace(new RegExp(`${attribute}${notMounted}`, "gi"), `$1${current}`);
90762
+ }
90763
+ if (kind === "html" || kind === "css") {
90764
+ const cssUrl = String.raw`(url\(\s*["']?)/`;
90765
+ out = out.replace(new RegExp(`${cssUrl}${notMounted}`, "gi"), `$1${current}`);
90766
+ }
90767
+ return out;
90768
+ }
90769
+ /**
90770
+ * A vendor `Set-Cookie` for the browser: no `Domain` (the cookie belongs to the hub
90771
+ * origin), `Path` narrowed to this attempt's prefix, `Secure` kept (the hub is HTTPS).
90772
+ */
90773
+ function rewriteSetCookie(cookie, route) {
90774
+ const kept = cookie.split(";").map((part) => part.trim()).filter((part, index) => {
90775
+ if (index === 0) return true;
90776
+ const name = part.split("=")[0]?.trim().toLowerCase() ?? "";
90777
+ return name !== "domain" && name !== "path";
90778
+ });
90779
+ kept.push(`Path=${route.basePath}/`);
90780
+ return kept.join("; ");
90781
+ }
90782
+ /**
90783
+ * A browser `Referer` that points into this proxy, turned back into the vendor URL it
90784
+ * stands for. A Referer that is not ours is dropped (null): it names the hub.
90785
+ */
90786
+ function rewriteReferer(referer, route) {
90787
+ let url;
90788
+ try {
90789
+ url = new URL(referer, "http://hub.invalid");
90790
+ } catch {
90791
+ return null;
90792
+ }
90793
+ if (!url.pathname.startsWith(`${route.basePath}/`)) return null;
90794
+ const rest = /^\/([^/]+)(\/.*)?$/.exec(url.pathname.slice(route.basePath.length));
90795
+ const host = rest?.[1]?.toLowerCase();
90796
+ if (host === void 0) return null;
90797
+ const upstream = findUpstream(route, host);
90798
+ if (upstream === void 0) return null;
90799
+ return `${upstream.scheme}://${upstream.host}${rest?.[2] ?? "/"}${url.search}`;
90800
+ }
90801
+ /** Cookies the browser holds for the hub itself must never reach a vendor. */
90802
+ function filterForwardedCookies(cookieHeader) {
90803
+ return cookieHeader.split(";").map((part) => part.trim()).filter((part) => part.length > 0 && !part.toLowerCase().startsWith("camstack_")).join("; ");
90804
+ }
90805
+ var MAX_REQUEST_BODY_BYTES = 2 * 1024 * 1024;
90806
+ var MAX_TEXT_BODY_BYTES = 4 * 1024 * 1024;
90807
+ /** Request headers that are never forwarded to the vendor. */
90808
+ var DROP_REQUEST_HEADERS = new Set([
90809
+ "host",
90810
+ "connection",
90811
+ "keep-alive",
90812
+ "proxy-authorization",
90813
+ "proxy-connection",
90814
+ "te",
90815
+ "trailer",
90816
+ "transfer-encoding",
90817
+ "upgrade",
90818
+ "content-length",
90819
+ "accept-encoding",
90820
+ "authorization",
90821
+ "cookie",
90822
+ "origin",
90823
+ "referer",
90824
+ "x-camstack-dataplane-secret",
90825
+ "x-forwarded-for",
90826
+ "x-forwarded-host",
90827
+ "x-forwarded-proto",
90828
+ "x-forwarded-prefix",
90829
+ "x-real-ip",
90830
+ "forwarded"
90831
+ ]);
90832
+ /**
90833
+ * Response headers dropped: framing/CSP/HSTS that break a page under another origin, and
90834
+ * the ones that no longer describe the (decoded, possibly rewritten) body.
90835
+ */
90836
+ var DROP_RESPONSE_HEADERS = new Set([
90837
+ "content-security-policy",
90838
+ "content-security-policy-report-only",
90839
+ "x-frame-options",
90840
+ "strict-transport-security",
90841
+ "public-key-pins",
90842
+ "report-to",
90843
+ "nel",
90844
+ "content-encoding",
90845
+ "content-length",
90846
+ "transfer-encoding",
90847
+ "connection",
90848
+ "keep-alive",
90849
+ "set-cookie",
90850
+ "location"
90851
+ ]);
90852
+ function bodyKindOf(contentType) {
90853
+ const type = contentType.toLowerCase();
90854
+ if (type.includes("text/html") || type.includes("application/xhtml")) return "html";
90855
+ if (type.includes("text/css")) return "css";
90856
+ if (type.startsWith("text/") || type.includes("javascript") || type.includes("json") || type.includes("xml")) return "other";
90857
+ return null;
90858
+ }
90859
+ function firstHeader(value) {
90860
+ return Array.isArray(value) ? value[0] : value;
90861
+ }
90862
+ async function readRequestBody(req) {
90863
+ const chunks = [];
90864
+ let size = 0;
90865
+ for await (const chunk of req) {
90866
+ const buf = typeof chunk === "string" ? Buffer.from(chunk) : Buffer.from(chunk);
90867
+ size += buf.length;
90868
+ if (size > MAX_REQUEST_BODY_BYTES) return "too-large";
90869
+ chunks.push(buf);
90870
+ }
90871
+ return Buffer.concat(chunks);
90872
+ }
90873
+ function sendPlain(res, status, text) {
90874
+ res.writeHead(status, {
90875
+ "content-type": "text/plain; charset=utf-8",
90876
+ "cache-control": "no-store"
90877
+ });
90878
+ res.end(text);
90879
+ }
90880
+ var VendorLoginProxy = class {
90881
+ #addonId;
90882
+ #prefix;
90883
+ #logger;
90884
+ #now;
90885
+ #fetch;
90886
+ #attempts = /* @__PURE__ */ new Map();
90887
+ constructor(options) {
90888
+ this.#addonId = options.addonId;
90889
+ this.#prefix = options.prefix;
90890
+ this.#logger = options.logger;
90891
+ this.#now = options.now ?? (() => Date.now());
90892
+ this.#fetch = options.fetchFn ?? globalThis.fetch.bind(globalThis);
90893
+ }
90894
+ /** The `DataPlaneHandler` to pass to `ctx.dataPlane.serve({ prefix, access: 'admin', … })`. */
90895
+ handler = (req, res) => this.#handle(req, res);
90896
+ /** Register an attempt. A one-shot capability: refused hosts are rejected up front. */
90897
+ open(spec) {
90898
+ for (const upstream of spec.upstreams) if (!isValidUpstream(upstream)) throw new Error(`vendor login proxy: upstream ${upstream.host} is not allowed`);
90899
+ this.#attempts.set(spec.attemptId, {
90900
+ expiresAtMs: spec.expiresAtMs,
90901
+ upstreams: spec.upstreams,
90902
+ evaluate: async (view) => {
90903
+ const verdict = await spec.terminal(view);
90904
+ if (verdict.kind === "continue") return verdict;
90905
+ return {
90906
+ kind: "done",
90907
+ landing: await spec.onDone(verdict.payload)
90908
+ };
90909
+ }
90910
+ });
90911
+ }
90912
+ close(attemptId) {
90913
+ this.#attempts.delete(attemptId);
90914
+ }
90915
+ isOpen(attemptId) {
90916
+ const attempt = this.#attempts.get(attemptId);
90917
+ return attempt !== void 0 && this.#now() <= attempt.expiresAtMs;
90918
+ }
90919
+ /**
90920
+ * The hub-relative path that opens `vendorUrl` through the proxy for this attempt:
90921
+ * the URL the browser is sent to. Null when the host is not in the attempt's list.
90922
+ */
90923
+ entryPath(attemptId, vendorUrl) {
90924
+ const attempt = this.#attempts.get(attemptId);
90925
+ if (attempt === void 0) return null;
90926
+ const url = new URL(vendorUrl);
90927
+ if (findUpstream({
90928
+ basePath: "",
90929
+ upstreams: attempt.upstreams
90930
+ }, url.host) === void 0) return null;
90931
+ return `/addon/${this.#addonId}/${this.#prefix}/${attemptId}/${url.host}${url.pathname}${url.search}`;
90932
+ }
90933
+ #routeFor(attemptId, attempt, forwardedPrefix) {
90934
+ return {
90935
+ basePath: `${forwardedPrefix}/addon/${this.#addonId}/${this.#prefix}/${attemptId}`,
90936
+ upstreams: attempt.upstreams
90937
+ };
90938
+ }
90939
+ async #handle(req, res) {
90940
+ try {
90941
+ await this.#serve(req, res);
90942
+ } catch (err) {
90943
+ this.#logger.warn("vendor login proxy: request failed", { meta: {
90944
+ addonId: this.#addonId,
90945
+ error: err instanceof Error ? err.name : "unknown"
90946
+ } });
90947
+ if (!res.headersSent) sendPlain(res, 502, "The sign-in page could not be reached.");
90948
+ else res.end();
90949
+ }
90950
+ }
90951
+ async #serve(req, res) {
90952
+ const parsed = parseProxyPath(req.url ?? "/");
90953
+ if (parsed === null) {
90954
+ sendPlain(res, 404, "Not found");
90955
+ return;
90956
+ }
90957
+ const forwardedPrefix = (firstHeader(req.headers["x-forwarded-prefix"]) ?? "").replace(/\/+$/, "");
90958
+ const attempt = this.#attempts.get(parsed.attemptId);
90959
+ if (attempt === void 0 || this.#now() > attempt.expiresAtMs) {
90960
+ if (attempt !== void 0) this.#attempts.delete(parsed.attemptId);
90961
+ this.#logger.info("vendor login proxy: attempt refused", { meta: {
90962
+ addonId: this.#addonId,
90963
+ reason: attempt === void 0 ? "missing" : "expired"
90964
+ } });
90965
+ this.#redirect(res, forwardedPrefix, {
90966
+ status: "error",
90967
+ addonId: this.#addonId,
90968
+ reason: "invalid_state"
90969
+ });
90970
+ return;
90971
+ }
90972
+ const route = this.#routeFor(parsed.attemptId, attempt, forwardedPrefix);
90973
+ const upstream = findUpstream(route, parsed.host);
90974
+ const target = upstream === void 0 ? null : upstreamUrlFor(upstream, parsed);
90975
+ if (upstream === void 0 || target === null) {
90976
+ this.#logger.warn("vendor login proxy: host refused", { meta: {
90977
+ addonId: this.#addonId,
90978
+ host: parsed.host
90979
+ } });
90980
+ sendPlain(res, 404, "Not found");
90981
+ return;
90982
+ }
90983
+ const method = (req.method ?? "GET").toUpperCase();
90984
+ let body;
90985
+ if (method !== "GET" && method !== "HEAD") {
90986
+ const read = await readRequestBody(req);
90987
+ if (read === "too-large") {
90988
+ sendPlain(res, 413, "Request too large");
90989
+ return;
90990
+ }
90991
+ body = read;
90992
+ }
90993
+ const headers = this.#requestHeaders(req, route, upstream);
90994
+ const upstreamRes = await this.#fetch(target, {
90995
+ method,
90996
+ headers,
90997
+ redirect: "manual",
90998
+ ...body !== void 0 && body.length > 0 ? { body: new Uint8Array(body) } : {}
90999
+ });
91000
+ const location = upstreamRes.headers.get("location");
91001
+ const setCookies = upstreamRes.headers.getSetCookie();
91002
+ const kind = bodyKindOf(upstreamRes.headers.get("content-type") ?? "");
91003
+ const declaredLength = Number(upstreamRes.headers.get("content-length") ?? "0");
91004
+ const text = kind !== null && !(declaredLength > MAX_TEXT_BODY_BYTES) && method !== "HEAD" ? await upstreamRes.text() : null;
91005
+ this.#logger.debug("vendor login proxy: upstream answered", { meta: {
91006
+ addonId: this.#addonId,
91007
+ host: upstream.host,
91008
+ status: upstreamRes.status,
91009
+ method
91010
+ } });
91011
+ const settled = await attempt.evaluate({
91012
+ status: upstreamRes.status,
91013
+ url: target.toString(),
91014
+ location,
91015
+ setCookies,
91016
+ bodyText: text
91017
+ });
91018
+ if (settled.kind === "done") {
91019
+ this.#attempts.delete(parsed.attemptId);
91020
+ this.#logger.info("vendor login proxy: sign-in finished", { meta: {
91021
+ addonId: this.#addonId,
91022
+ status: settled.landing.status
91023
+ } });
91024
+ this.#redirect(res, forwardedPrefix, settled.landing);
91025
+ return;
91026
+ }
91027
+ const out = {};
91028
+ upstreamRes.headers.forEach((value, name) => {
91029
+ if (!DROP_RESPONSE_HEADERS.has(name.toLowerCase())) out[name] = value;
91030
+ });
91031
+ if (setCookies.length > 0) out["set-cookie"] = setCookies.map((c) => rewriteSetCookie(c, route));
91032
+ if (location !== null) out["location"] = rewriteLocation(location, upstream, route);
91033
+ out["cache-control"] = "no-store";
91034
+ if (text !== null && kind !== null) {
91035
+ const rewritten = rewriteBody(text, kind, upstream, route);
91036
+ res.writeHead(upstreamRes.status, out);
91037
+ res.end(rewritten);
91038
+ return;
91039
+ }
91040
+ res.writeHead(upstreamRes.status, out);
91041
+ await this.#pipeBody(upstreamRes, res);
91042
+ }
91043
+ #requestHeaders(req, route, upstream) {
91044
+ const headers = {};
91045
+ for (const [name, value] of Object.entries(req.headers)) {
91046
+ const lower = name.toLowerCase();
91047
+ if (DROP_REQUEST_HEADERS.has(lower) || value === void 0) continue;
91048
+ headers[lower] = Array.isArray(value) ? value.join(", ") : value;
91049
+ }
91050
+ const cookie = filterForwardedCookies(firstHeader(req.headers["cookie"]) ?? "");
91051
+ if (cookie.length > 0) headers["cookie"] = cookie;
91052
+ if (req.headers["origin"] !== void 0) headers["origin"] = `${upstream.scheme}://${upstream.host}`;
91053
+ const referer = firstHeader(req.headers["referer"]);
91054
+ if (referer !== void 0) {
91055
+ const back = rewriteReferer(referer, route);
91056
+ if (back !== null) headers["referer"] = back;
91057
+ }
91058
+ return headers;
91059
+ }
91060
+ async #pipeBody(upstreamRes, res) {
91061
+ if (upstreamRes.body === null) {
91062
+ res.end();
91063
+ return;
91064
+ }
91065
+ for await (const chunk of upstreamRes.body) {
91066
+ if (!res.write(chunk)) await new Promise((resolve) => {
91067
+ res.once("drain", resolve);
91068
+ res.once("close", resolve);
91069
+ });
91070
+ if (res.destroyed) return;
91071
+ }
91072
+ res.end();
91073
+ }
91074
+ #redirect(res, forwardedPrefix, outcome) {
91075
+ res.writeHead(302, {
91076
+ location: `${forwardedPrefix}${oauthLandingUrl(null, outcome)}`,
91077
+ "cache-control": "no-store"
91078
+ });
91079
+ res.end();
91080
+ }
91081
+ };
90640
91082
  var MB = 1024 * 1024;
90641
91083
  1024 * MB, 3072 * MB;
90642
91084
  //#endregion
@@ -90688,18 +91130,12 @@ var AlexaBrokerEntrySchema = object({
90688
91130
  });
90689
91131
  /**
90690
91132
  * Interactive proxy-login settings (addon-global, not per-broker). alexa-remote2
90691
- * spins a local reverse-proxy to Amazon's login page on `proxyHost:proxyPort`;
90692
- * the operator opens that URL and logs in. `proxyHost` MUST be the host:port the
90693
- * operator's browser uses (alexa-cookie2 rewrites Amazon URLs to absolute
90694
- * `http://<proxyHost>:<proxyPort>/...`), so it is a directly-reachable host —
90695
- * the hub's LAN IP/hostname — NOT behind the hub's HTTPS data-plane mount.
90696
- * Empty `proxyHost` ⇒ the first LAN address of the hub's `appConnections`
90697
- * role (local-network palette) at login-start time.
91133
+ * spins a local reverse-proxy to Amazon's login page on `127.0.0.1:proxyPort`; the
91134
+ * operator never reaches it directly — the hub's login proxy (D955) opens it at
91135
+ * `/addon/import-alexa/login/…` under the hub's own HTTPS origin. The port only has to
91136
+ * be free on the hub's loopback.
90698
91137
  */
90699
- var alexaProxyLoginSchema = object({
90700
- proxyHost: string().default("").describe("Host/IP the browser uses to reach the login proxy (blank = the hub LAN address)"),
90701
- proxyPort: preprocess((v) => v === "" || v === null ? void 0 : v, number().int().min(1).max(65535).default(3456)).describe("Port the local Amazon-login proxy listens on (must be reachable)")
90702
- });
91138
+ var alexaProxyLoginSchema = object({ proxyPort: preprocess((v) => v === "" || v === null ? void 0 : v, number().int().min(1).max(65535).default(3456)).describe("Loopback port the local Amazon-login proxy listens on (never exposed)") });
90703
91139
  /**
90704
91140
  * Echo speech settings. Speech signs in as an import broker, so the targets
90705
91141
  * are what lives here. `email`, `password`, `region` and `session` are the OLD
@@ -90746,10 +91182,7 @@ function readSpeakSettings(config) {
90746
91182
  /** Top-level addon config — broker entries + the proxy-login settings. */
90747
91183
  var alexaAddonConfigSchema = object({
90748
91184
  brokers: array(AlexaBrokerEntrySchema).default([]),
90749
- proxyLogin: alexaProxyLoginSchema.default({
90750
- proxyHost: "",
90751
- proxyPort: 3456
90752
- }),
91185
+ proxyLogin: alexaProxyLoginSchema.default({ proxyPort: 3456 }),
90753
91186
  speak: alexaSpeakSettingsSchema.default({
90754
91187
  email: "",
90755
91188
  password: "",
@@ -132305,6 +132738,31 @@ var ALEXA_API_USER_AGENT_POSTFIX = `AlexaRemote/${{
132305
132738
  //#endregion
132306
132739
  //#region src/alexa-proxy-login.ts
132307
132740
  /**
132741
+ * INTERACTIVE Amazon login via `alexa-remote2`'s built-in proxy auth mode, behind the
132742
+ * hub's vendor login proxy (D955).
132743
+ *
132744
+ * alexa-remote2 (through `alexa-cookie2`) spins a local Express reverse-proxy to
132745
+ * Amazon's real login page and captures the resulting cookie + the richer
132746
+ * `cookieData` registration blob (it embeds the refresh token, so the session can
132747
+ * auto-refresh forever). That listener is bound to LOOPBACK only
132748
+ * (`proxyOwnIp` = `proxyListenBind` = 127.0.0.1): nothing outside this process's host can
132749
+ * reach it. The operator's browser reaches it through the hub's data plane instead
132750
+ * (`VendorLoginProxy`, `/addon/<id>/login/<attempt>/127.0.0.1:<port>/…`), which is
132751
+ * HTTPS under the same origin as the admin page. alexa-cookie2 keeps doing the Amazon
132752
+ * specific work (login cookies, device registration, the `/ax/claim` and CSRF steps)
132753
+ * and the hub proxy only rewrites the loopback-origin URLs it emits into the mount.
132754
+ *
132755
+ * Why not the second proxy replacing alexa-cookie2's: the capture needs the PKCE
132756
+ * verifier, the device id, the initial cookies and the app registration alexa-cookie2
132757
+ * already performs; re-implementing them would add JS-built-URL failure modes.
132758
+ *
132759
+ * The captured `cookieData` is handed to {@link AlexaProxyLoginSessionOptions.onCookie}
132760
+ * — the addon persists it on the broker entry, exactly where a pasted cookie
132761
+ * goes, so the rest of the addon (broker / poll / adoption) is unchanged.
132762
+ */
132763
+ /** The only address the alexa-cookie2 listener binds and advertises. */
132764
+ var ALEXA_PROXY_LOOPBACK_HOST = "127.0.0.1";
132765
+ /**
132308
132766
  * A single interactive proxy-login attempt. One instance = one Amazon login.
132309
132767
  * Construct → {@link start} → poll {@link getStatus} → on `captured` the
132310
132768
  * `onCookie` callback has fired with the blob → {@link dispose}.
@@ -132318,13 +132776,37 @@ var AlexaProxyLoginSession = class {
132318
132776
  #startedAt = Date.now();
132319
132777
  #capturedAt = null;
132320
132778
  #captured = false;
132779
+ #waiters = /* @__PURE__ */ new Set();
132321
132780
  constructor(opts) {
132322
132781
  this.#opts = opts;
132323
132782
  this.#logger = opts.logger;
132324
132783
  }
132325
- /** `http://<proxyOwnIp>:<proxyPort>/` — what the operator opens. */
132784
+ /** What the operator opens: the hub-relative entry of the login proxy. */
132326
132785
  get loginUrl() {
132327
- return `http://${this.#opts.proxyOwnIp}:${this.#opts.proxyPort}/`;
132786
+ return this.#opts.loginUrl;
132787
+ }
132788
+ /** `host:port` of the loopback listener — the one upstream the hub proxy may reach. */
132789
+ get upstreamHost() {
132790
+ return `${ALEXA_PROXY_LOOPBACK_HOST}:${this.#opts.proxyPort}`;
132791
+ }
132792
+ /**
132793
+ * Resolves true once the cookie material is in hand, false after `timeoutMs`.
132794
+ * The Amazon page ends on `/cookie-success` BEFORE alexa-cookie2 finished registering
132795
+ * the app, so the hub waits here before it sends the browser to the result page.
132796
+ */
132797
+ whenCaptured(timeoutMs) {
132798
+ if (this.#captured) return Promise.resolve(true);
132799
+ return new Promise((resolve) => {
132800
+ const timer = setTimeout(() => {
132801
+ this.#waiters.delete(settle);
132802
+ resolve(false);
132803
+ }, timeoutMs);
132804
+ const settle = () => {
132805
+ clearTimeout(timer);
132806
+ resolve(true);
132807
+ };
132808
+ this.#waiters.add(settle);
132809
+ });
132328
132810
  }
132329
132811
  getStatus() {
132330
132812
  return {
@@ -132356,7 +132838,8 @@ var AlexaProxyLoginSession = class {
132356
132838
  remote.on("cookie", () => this.#onCookieEvent(remote));
132357
132839
  remote.init({
132358
132840
  proxyOnly: true,
132359
- proxyOwnIp: this.#opts.proxyOwnIp,
132841
+ proxyOwnIp: ALEXA_PROXY_LOOPBACK_HOST,
132842
+ proxyListenBind: ALEXA_PROXY_LOOPBACK_HOST,
132360
132843
  proxyPort: this.#opts.proxyPort,
132361
132844
  proxyLogLevel: "warn",
132362
132845
  amazonPage,
@@ -132402,6 +132885,8 @@ var AlexaProxyLoginSession = class {
132402
132885
  this.#captured = true;
132403
132886
  this.#capturedAt = Date.now();
132404
132887
  this.#phase = "captured";
132888
+ for (const settle of this.#waiters) settle();
132889
+ this.#waiters.clear();
132405
132890
  this.#logger.info("alexa proxy-login: cookie captured", { meta: { sessionId: this.#opts.sessionId } });
132406
132891
  try {
132407
132892
  this.#opts.onCookie(this.#opts.sessionId, {
@@ -132422,10 +132907,7 @@ var AlexaProxyLoginSession = class {
132422
132907
  if (isProxyReadyError(err)) {
132423
132908
  if (this.#phase === "starting") {
132424
132909
  this.#phase = "awaiting-login";
132425
- this.#logger.info("alexa proxy-login: proxy ready — awaiting Amazon login", { meta: {
132426
- sessionId: this.#opts.sessionId,
132427
- loginUrl: this.loginUrl
132428
- } });
132910
+ this.#logger.info("alexa proxy-login: proxy ready — awaiting Amazon login", { meta: { sessionId: this.#opts.sessionId } });
132429
132911
  }
132430
132912
  return;
132431
132913
  }
@@ -132483,62 +132965,44 @@ function isStringOrObject(value) {
132483
132965
  return typeof value === "string" || typeof value === "object" && value !== null;
132484
132966
  }
132485
132967
  //#endregion
132486
- //#region src/alexa-proxy-host.ts
132487
- /** Typed refusal: names WHY no proxy host could be chosen. */
132488
- var AlexaProxyHostError = class extends Error {
132489
- reason;
132490
- constructor(reason, message, options) {
132491
- super(message, options);
132492
- this.name = "AlexaProxyHostError";
132493
- this.reason = reason;
132494
- }
132495
- };
132496
- var PRIVATE_IPV4 = /^(10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.|169\.254\.)/;
132497
- var IPV4_LITERAL = /^\d{1,3}(\.\d{1,3}){3}$/;
132498
- /** A host a browser on the hub's network reaches directly: private IPv4, `.local`, or a bare name. */
132499
- function isLanHost(host) {
132500
- if (host.length === 0) return false;
132501
- if (IPV4_LITERAL.test(host)) return PRIVATE_IPV4.test(host);
132502
- if (host.includes(":")) return false;
132503
- return host.endsWith(".local") || !host.includes(".");
132504
- }
132505
- function lanHostOf(address) {
132968
+ //#region src/alexa-proxy-login-manager.ts
132969
+ /** The data-plane prefix the hub login proxy is served on. */
132970
+ var ALEXA_LOGIN_PROXY_PREFIX = "login";
132971
+ /** The addon id the result page names to return to. */
132972
+ var ADDON_ID = "import-alexa";
132973
+ /** An attempt lives as long as a sign-in attempt does elsewhere (10 min). */
132974
+ var ATTEMPT_TTL_MS = 600 * 1e3;
132975
+ /** How long the browser waits on the Amazon page for alexa-cookie2 to finish registering. */
132976
+ var CAPTURE_WAIT_MS = 6e4;
132977
+ /**
132978
+ * Terminal condition: alexa-cookie2 turns Amazon's final redirect into a 302 to its own
132979
+ * `/cookie-success` page once it holds the login cookie. Matching on the path of the raw
132980
+ * `Location` keeps this independent of the page's HTML.
132981
+ */
132982
+ function cookieSuccessTerminal(view) {
132983
+ if (view.location === null) return { kind: "continue" };
132506
132984
  try {
132507
- const host = new URL(address).hostname;
132508
- return isLanHost(host) && host !== "localhost" ? host : null;
132985
+ return new URL(view.location, `http://127.0.0.1`).pathname === "/cookie-success" ? {
132986
+ kind: "done",
132987
+ payload: true
132988
+ } : { kind: "continue" };
132509
132989
  } catch {
132510
- return null;
132511
- }
132512
- }
132513
- async function resolveProxyHost(input) {
132514
- const override = input.override.trim();
132515
- if (override.length > 0) return override;
132516
- let addresses;
132517
- try {
132518
- addresses = await input.readAppConnections();
132519
- } catch (err) {
132520
- input.logger.warn("alexa proxy-login: hub addresses unavailable from local-network", { meta: { error: errMsg(err) } });
132521
- throw new AlexaProxyHostError("palette-unavailable", "alexa proxy-login: the hub address list is unavailable — set proxyHost in settings", { cause: err });
132990
+ return { kind: "continue" };
132522
132991
  }
132523
- for (const address of addresses) {
132524
- const host = lanHostOf(address);
132525
- if (host !== null) return host;
132526
- }
132527
- input.logger.warn("alexa proxy-login: no LAN address among the hub appConnections", { meta: { addresses: [...addresses] } });
132528
- throw new AlexaProxyHostError("no-lan-address", "alexa proxy-login: the hub has no LAN address the browser can open directly — set proxyHost in settings");
132529
132992
  }
132530
- //#endregion
132531
- //#region src/alexa-proxy-login-manager.ts
132532
132993
  var AlexaProxyLoginManager = class {
132533
132994
  #logger;
132534
132995
  #getProxyConfig;
132535
- #getAppConnectionAddresses;
132996
+ #getLoginProxy;
132997
+ #captureWaitMs;
132536
132998
  #session = null;
132537
132999
  #captured = /* @__PURE__ */ new Map();
133000
+ #attemptCloser = null;
132538
133001
  constructor(deps) {
132539
133002
  this.#logger = deps.logger;
132540
133003
  this.#getProxyConfig = deps.getProxyConfig;
132541
- this.#getAppConnectionAddresses = deps.getAppConnectionAddresses;
133004
+ this.#getLoginProxy = deps.getLoginProxy;
133005
+ this.#captureWaitMs = deps.captureWaitMs ?? CAPTURE_WAIT_MS;
132542
133006
  }
132543
133007
  /**
132544
133008
  * Start a fresh proxy-login. Cancels any in-flight session first (single
@@ -132546,18 +133010,41 @@ var AlexaProxyLoginManager = class {
132546
133010
  */
132547
133011
  async start(amazonDomain) {
132548
133012
  await this.cancelActive();
132549
- const { proxyHost, proxyPort } = this.#getProxyConfig();
132550
- const host = await resolveProxyHost({
132551
- override: proxyHost,
132552
- readAppConnections: this.#getAppConnectionAddresses,
132553
- logger: this.#logger
132554
- });
133013
+ const loginProxy = this.#getLoginProxy();
133014
+ if (loginProxy === null) throw new Error("alexa proxy-login: the hub login proxy is not available on this hub");
133015
+ const { proxyPort } = this.#getProxyConfig();
133016
+ const upstreamHost = `${ALEXA_PROXY_LOOPBACK_HOST}:${proxyPort}`;
132555
133017
  const sessionId = (0, node_crypto.randomBytes)(9).toString("base64url");
133018
+ loginProxy.open({
133019
+ attemptId: sessionId,
133020
+ expiresAtMs: Date.now() + ATTEMPT_TTL_MS,
133021
+ upstreams: [{
133022
+ host: upstreamHost,
133023
+ scheme: "http"
133024
+ }],
133025
+ terminal: cookieSuccessTerminal,
133026
+ onDone: async () => {
133027
+ return await this.#session?.whenCaptured(this.#captureWaitMs) === true ? {
133028
+ status: "success",
133029
+ addonId: ADDON_ID
133030
+ } : {
133031
+ status: "error",
133032
+ addonId: ADDON_ID,
133033
+ reason: "exchange_failed"
133034
+ };
133035
+ }
133036
+ });
133037
+ const loginUrl = loginProxy.entryPath(sessionId, `http://${upstreamHost}/`);
133038
+ if (loginUrl === null) {
133039
+ loginProxy.close(sessionId);
133040
+ throw new Error("alexa proxy-login: the hub login proxy refused the login address");
133041
+ }
133042
+ this.#attemptCloser = () => loginProxy.close(sessionId);
132556
133043
  const session = new AlexaProxyLoginSession({
132557
133044
  sessionId,
132558
133045
  amazonDomain,
132559
- proxyOwnIp: host,
132560
133046
  proxyPort,
133047
+ loginUrl,
132561
133048
  logger: this.#logger,
132562
133049
  onCookie: (id, captured) => {
132563
133050
  this.#captured.set(id, captured);
@@ -132568,6 +133055,7 @@ var AlexaProxyLoginManager = class {
132568
133055
  await session.start();
132569
133056
  } catch (err) {
132570
133057
  this.#session = null;
133058
+ this.#closeAttempt();
132571
133059
  await session.dispose();
132572
133060
  throw new Error(`alexa proxy-login: failed to start proxy — ${errMsg(err)}`, { cause: err });
132573
133061
  }
@@ -132601,10 +133089,16 @@ var AlexaProxyLoginManager = class {
132601
133089
  await this.cancelActive();
132602
133090
  this.#captured.delete(sessionId);
132603
133091
  }
133092
+ #closeAttempt() {
133093
+ const close = this.#attemptCloser;
133094
+ this.#attemptCloser = null;
133095
+ close?.();
133096
+ }
132604
133097
  /** Cancel + dispose whatever session is currently active. */
132605
133098
  async cancelActive() {
132606
133099
  const session = this.#session;
132607
133100
  this.#session = null;
133101
+ this.#closeAttempt();
132608
133102
  if (session === null) return;
132609
133103
  try {
132610
133104
  await session.cancel();
@@ -136219,10 +136713,7 @@ var SPEAK_PAGE = {
136219
136713
  /** Default config — a fresh install starts with no accounts. */
136220
136714
  var DEFAULTS = {
136221
136715
  brokers: [],
136222
- proxyLogin: {
136223
- proxyHost: "",
136224
- proxyPort: 3456
136225
- },
136716
+ proxyLogin: { proxyPort: 3456 },
136226
136717
  speak: {
136227
136718
  email: "",
136228
136719
  password: "",
@@ -136268,6 +136759,8 @@ var AlexaImportAddon = class extends BaseDeviceProvider {
136268
136759
  deviceClasses = Object.fromEntries(ALEXA_DEVICE_TYPES.map((t) => [t, AlexaDevice]));
136269
136760
  registry = null;
136270
136761
  proxyLogin = null;
136762
+ loginPlane = null;
136763
+ loginProxy = null;
136271
136764
  brokerStore = null;
136272
136765
  activeBrokers = [];
136273
136766
  speak = null;
@@ -136307,16 +136800,13 @@ var AlexaImportAddon = class extends BaseDeviceProvider {
136307
136800
  });
136308
136801
  alexaCommands.setDispatcher((brokerId, command) => this.requireRegistry().sendCommand(brokerId, command));
136309
136802
  await this.registry.restore(this.activeBrokers);
136803
+ await this.serveLoginProxy();
136310
136804
  this.proxyLogin = new AlexaProxyLoginManager({
136311
136805
  logger: this.ctx.logger,
136312
136806
  getProxyConfig: () => {
136313
- const cfg = alexaProxyLoginSchema.parse(this.config.proxyLogin ?? {});
136314
- return {
136315
- proxyHost: cfg.proxyHost,
136316
- proxyPort: cfg.proxyPort
136317
- };
136807
+ return { proxyPort: alexaProxyLoginSchema.parse(this.config.proxyLogin ?? {}).proxyPort };
136318
136808
  },
136319
- getAppConnectionAddresses: async () => (await this.ctx.api.localNetwork.getAddresses.query()).roles.appConnections.resolved
136809
+ getLoginProxy: () => this.loginProxy
136320
136810
  });
136321
136811
  this.ctx.logger.info("Alexa: import addon initialised", { meta: { brokerCount: this.activeBrokers.length } });
136322
136812
  await this.reconcileIntegrationsToBrokers();
@@ -136448,6 +136938,24 @@ var AlexaImportAddon = class extends BaseDeviceProvider {
136448
136938
  }
136449
136939
  this.speak?.brokersChanged();
136450
136940
  }
136941
+ /** The hub's HTTPS face for the Amazon login (D955): admin session only. */
136942
+ async serveLoginProxy() {
136943
+ const proxy = new VendorLoginProxy({
136944
+ addonId: this.ctx.id,
136945
+ prefix: ALEXA_LOGIN_PROXY_PREFIX,
136946
+ logger: this.ctx.logger
136947
+ });
136948
+ try {
136949
+ this.loginPlane = await this.ctx.dataPlane?.serve({
136950
+ prefix: "login",
136951
+ access: "admin",
136952
+ handler: proxy.handler
136953
+ }) ?? null;
136954
+ if (this.loginPlane !== null) this.loginProxy = proxy;
136955
+ } catch (err) {
136956
+ this.ctx.logger.warn("Alexa: login proxy failed to serve — interactive sign-in is unavailable", { meta: { error: errMsg(err) } });
136957
+ }
136958
+ }
136451
136959
  async onShutdown() {
136452
136960
  this.speak?.stop();
136453
136961
  this.speak = null;
@@ -136458,6 +136966,9 @@ var AlexaImportAddon = class extends BaseDeviceProvider {
136458
136966
  this.ctx.logger.warn("Alexa: proxy-login dispose error", { meta: { error: errMsg(err) } });
136459
136967
  }
136460
136968
  this.proxyLogin = null;
136969
+ await this.loginPlane?.dispose().catch(() => void 0);
136970
+ this.loginPlane = null;
136971
+ this.loginProxy = null;
136461
136972
  try {
136462
136973
  await this.registry?.shutdown();
136463
136974
  } catch (err) {
@@ -136703,19 +137214,13 @@ var AlexaImportAddon = class extends BaseDeviceProvider {
136703
137214
  id: "alexa-proxy-login",
136704
137215
  title: "Interactive login (proxy)",
136705
137216
  titleKey: "import-alexa:globalSettings.s_alexa-proxy-login.title",
136706
- description: "The \"Login to Amazon\" button in onboarding opens a local proxy that captures the cookie after you complete the real Amazon login (incl. 2FA). Because Amazon URLs are rewritten to this exact host:port, it must be a directly-reachable address — leave the host blank to auto-detect the server IP, and make sure the port is reachable from the browser you log in from.",
137217
+ description: "The \"Sign in\" button in onboarding opens the real Amazon login page through this hub (same address and HTTPS as this page) and captures the cookie after you complete it (incl. 2FA). The port below is only used on the hub itself and is never exposed.",
136707
137218
  descriptionKey: "import-alexa:globalSettings.s_alexa-proxy-login.description",
136708
137219
  columns: 2,
136709
137220
  fields: [{
136710
- type: "text",
136711
- key: "proxyLogin.proxyHost",
136712
- label: "Login proxy host/IP (blank = auto-detect)",
136713
- labelKey: "import-alexa:globalSettings.s_alexa-proxy-login.proxyLogin_proxyHost.label",
136714
- placeholder: "auto-detect"
136715
- }, {
136716
137221
  type: "number",
136717
137222
  key: "proxyLogin.proxyPort",
136718
- label: "Login proxy port",
137223
+ label: "Internal login port (loopback)",
136719
137224
  labelKey: "import-alexa:globalSettings.s_alexa-proxy-login.proxyLogin_proxyPort.label",
136720
137225
  min: 1,
136721
137226
  max: 65535,