@mycadet/gateway 0.13.0-dev.202610200020.9f20440 → 0.13.0-dev.202610201855.522ff0d

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 (46) hide show
  1. package/node_modules/@mycadet/environments/src/seeds.ts +6 -2
  2. package/node_modules/@mycadet/gateway-client/src/__tests__/gateway-client.test.ts +3 -3
  3. package/node_modules/@mycadet/gateway-client/src/__tests__/package-boundary.test.ts +1 -1
  4. package/node_modules/@mycadet/gateway-client/src/__tests__/status-contracts.test.ts +1 -20
  5. package/node_modules/@mycadet/gateway-client/src/gateway-ipc-contracts.ts +0 -16
  6. package/openapi.json +1 -109
  7. package/package.json +1 -1
  8. package/scripts/generate-openapi.ts +0 -2
  9. package/src/__tests__/handle-inbound-admission.test.ts +0 -3
  10. package/src/__tests__/handle-inbound-trust-verdict.test.ts +0 -3
  11. package/src/__tests__/remote-web-pairing-token.test.ts +2 -133
  12. package/src/__tests__/shared-invite-redeem.test.ts +0 -5
  13. package/src/__tests__/shared-invite-registration.test.ts +0 -5
  14. package/src/__tests__/telegram-webhook-manager.test.ts +0 -5
  15. package/src/__tests__/trust-rules-routes.test.ts +0 -3
  16. package/src/auth/guardian-bootstrap.ts +1 -1
  17. package/src/auth/guardian-refresh.ts +0 -2
  18. package/src/cloud-features.ts +18 -0
  19. package/src/email/register-callback.ts +1 -1
  20. package/src/http/browser-auth-cookies.ts +3 -19
  21. package/src/http/routes/guardian-refresh.ts +0 -1
  22. package/src/http/routes/remote-web-pairing-token.ts +4 -11
  23. package/src/http/routes/trust-rules.suggest.test.ts +0 -3
  24. package/src/http/routes/twilio-voice-webhook.test.ts +0 -3
  25. package/src/index.ts +1 -77
  26. package/src/schema.ts +0 -116
  27. package/src/telegram/webhook-manager.ts +1 -1
  28. package/src/tunnel/allowed-paths.test.ts +1 -5
  29. package/src/tunnel/client.test.ts +0 -3
  30. package/src/tunnel/http-bridge.test.ts +0 -3
  31. package/src/twilio/webhook-sync.test.ts +0 -3
  32. package/src/verification/shared-invite-registration.ts +1 -1
  33. package/src/__tests__/feature-flag-defaults-sync.test.ts +0 -44
  34. package/src/__tests__/feature-flag-resolver.test.ts +0 -151
  35. package/src/__tests__/feature-flag-watcher-callback.test.ts +0 -63
  36. package/src/__tests__/feature-flags-route.test.ts +0 -770
  37. package/src/__tests__/ipc-feature-flag-routes.test.ts +0 -240
  38. package/src/feature-flag-defaults.ts +0 -197
  39. package/src/feature-flag-env-overrides.test.ts +0 -166
  40. package/src/feature-flag-env-overrides.ts +0 -58
  41. package/src/feature-flag-registry.json +0 -87
  42. package/src/feature-flag-resolver.ts +0 -47
  43. package/src/feature-flag-store.ts +0 -115
  44. package/src/feature-flag-watcher.ts +0 -105
  45. package/src/http/routes/feature-flags.ts +0 -185
  46. package/src/ipc/feature-flag-handlers.ts +0 -63
@@ -41,9 +41,13 @@ function portBlock(base: number): PortMap {
41
41
  * package index's `.js`-suffixed runtime re-exports. Keep this file's
42
42
  * imports type-only so it stays loadable on its own.
43
43
  */
44
- export function cloudAssistantHubUrl(envName: string | undefined): string {
44
+ export function cloudWebUrl(envName: string | undefined): string {
45
45
  const seed = (envName && SEEDS[envName]) || SEEDS.dev;
46
- return `${seed.webUrl}/assistant`;
46
+ return seed.webUrl;
47
+ }
48
+
49
+ export function cloudAssistantHubUrl(envName: string | undefined): string {
50
+ return `${cloudWebUrl(envName)}/assistant`;
47
51
  }
48
52
 
49
53
  /**
@@ -115,7 +115,7 @@ describe("ipc-client", () => {
115
115
  const req = JSON.parse(line);
116
116
  const resp = JSON.stringify({
117
117
  id: req.id,
118
- result: { flags: { browser: true } },
118
+ result: { thresholds: { daily: 42 } },
119
119
  });
120
120
  conn.write(resp + "\n");
121
121
  }
@@ -126,8 +126,8 @@ describe("ipc-client", () => {
126
126
  server.listen(socketPath, () => resolve());
127
127
  });
128
128
 
129
- const result = await ipcCall(socketPath, "get_feature_flags");
130
- expect(result).toEqual({ flags: { browser: true } });
129
+ const result = await ipcCall(socketPath, "get_global_thresholds");
130
+ expect(result).toEqual({ thresholds: { daily: 42 } });
131
131
  });
132
132
 
133
133
  test("returns undefined when server sends error response", async () => {
@@ -9,7 +9,7 @@
9
9
  * 3. Remains a lightweight client package with no runtime service dependencies.
10
10
  *
11
11
  * @mycadet/gateway-client is a typed HTTP client for assistant-to-gateway
12
- * calls (trust API, feature flags, log export, deliver). It may depend on
12
+ * calls (trust API, thresholds, log export, deliver). It may depend on
13
13
  * @mycadet/service-contracts for shared type definitions, but must not pull
14
14
  * in runtime service internals.
15
15
  */
@@ -1,27 +1,8 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
 
3
- import {
4
- FeatureFlagsIpcResponseSchema,
5
- TunnelStatusIpcResponseSchema,
6
- } from "../gateway-ipc-contracts.js";
3
+ import { TunnelStatusIpcResponseSchema } from "../gateway-ipc-contracts.js";
7
4
 
8
5
  describe("gateway status IPC contracts", () => {
9
- test("filters unsupported feature flag values independently", () => {
10
- expect(
11
- FeatureFlagsIpcResponseSchema.parse({
12
- enabled: true,
13
- model: "balanced",
14
- count: 3,
15
- nested: { enabled: true },
16
- }),
17
- ).toEqual({ enabled: true, model: "balanced" });
18
- });
19
-
20
- test("rejects non-record feature flag responses", () => {
21
- expect(FeatureFlagsIpcResponseSchema.safeParse([]).success).toBe(false);
22
- expect(FeatureFlagsIpcResponseSchema.safeParse(null).success).toBe(false);
23
- });
24
-
25
6
  test("normalizes a malformed Tunnel public URL to null", () => {
26
7
  expect(
27
8
  TunnelStatusIpcResponseSchema.parse({
@@ -17,22 +17,6 @@ export const GATEWAY_LOG_LEVEL_NAMES = [
17
17
  ] as const;
18
18
  export type GatewayLogLevelName = (typeof GATEWAY_LOG_LEVEL_NAMES)[number];
19
19
 
20
- export const FeatureFlagsIpcResponseSchema = z
21
- .record(z.string(), z.unknown())
22
- .transform((flags): Record<string, boolean | string> => {
23
- const parsed: Record<string, boolean | string> = {};
24
- for (const [key, value] of Object.entries(flags)) {
25
- if (typeof value === "boolean" || typeof value === "string") {
26
- parsed[key] = value;
27
- }
28
- }
29
- return parsed;
30
- });
31
-
32
- export type FeatureFlagsIpcResponse = z.infer<
33
- typeof FeatureFlagsIpcResponseSchema
34
- >;
35
-
36
20
  export const TunnelStatusIpcResponseSchema = z.object({
37
21
  connected: z.boolean(),
38
22
  publicUrl: z.string().nullable().catch(null),
package/openapi.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "openapi": "3.1.0",
3
3
  "info": {
4
4
  "title": "Cadet Gateway API",
5
- "version": "0.12.9",
5
+ "version": "0.13.0",
6
6
  "description": "Auto-generated OpenAPI specification for the Cadet Gateway HTTP endpoints."
7
7
  },
8
8
  "servers": [{ "url": "", "description": "Same-origin — the gateway" }],
@@ -1708,114 +1708,6 @@
1708
1708
  }
1709
1709
  }
1710
1710
  },
1711
- "/v1/feature-flags": {
1712
- "get": {
1713
- "operationId": "featureFlagsGet",
1714
- "summary": "List all feature flags",
1715
- "tags": ["feature-flags"],
1716
- "description": "Returns all feature flags with their current values.",
1717
- "responses": {
1718
- "200": {
1719
- "description": "Successful response",
1720
- "content": {
1721
- "application/json": {
1722
- "schema": {
1723
- "type": "object",
1724
- "properties": {
1725
- "flags": {
1726
- "type": "array",
1727
- "items": {
1728
- "type": "object",
1729
- "properties": {
1730
- "key": { "type": "string" },
1731
- "label": { "type": "string" },
1732
- "enabled": {
1733
- "anyOf": [
1734
- { "type": "boolean" },
1735
- { "type": "string" }
1736
- ]
1737
- },
1738
- "defaultEnabled": {
1739
- "anyOf": [
1740
- { "type": "boolean" },
1741
- { "type": "string" }
1742
- ]
1743
- },
1744
- "description": { "type": "string" }
1745
- },
1746
- "required": [
1747
- "key",
1748
- "label",
1749
- "enabled",
1750
- "defaultEnabled",
1751
- "description"
1752
- ],
1753
- "additionalProperties": false
1754
- }
1755
- }
1756
- },
1757
- "required": ["flags"],
1758
- "additionalProperties": false
1759
- }
1760
- }
1761
- }
1762
- }
1763
- }
1764
- }
1765
- },
1766
- "/v1/feature-flags/{flag_key}": {
1767
- "patch": {
1768
- "operationId": "featureFlagsPatch",
1769
- "summary": "Update a feature flag",
1770
- "tags": ["feature-flags"],
1771
- "description": "Set the enabled state of a single feature flag.",
1772
- "parameters": [
1773
- {
1774
- "name": "flag_key",
1775
- "in": "path",
1776
- "required": true,
1777
- "schema": { "type": "string" },
1778
- "description": "The kebab-case flag identifier"
1779
- }
1780
- ],
1781
- "requestBody": {
1782
- "required": true,
1783
- "content": {
1784
- "application/json": {
1785
- "schema": {
1786
- "type": "object",
1787
- "properties": {
1788
- "enabled": {
1789
- "anyOf": [{ "type": "boolean" }, { "type": "string" }]
1790
- }
1791
- },
1792
- "required": ["enabled"]
1793
- }
1794
- }
1795
- }
1796
- },
1797
- "responses": {
1798
- "200": {
1799
- "description": "Successful response",
1800
- "content": {
1801
- "application/json": {
1802
- "schema": {
1803
- "type": "object",
1804
- "properties": {
1805
- "key": { "type": "string" },
1806
- "enabled": {
1807
- "anyOf": [{ "type": "boolean" }, { "type": "string" }]
1808
- }
1809
- },
1810
- "required": ["key", "enabled"],
1811
- "additionalProperties": false
1812
- }
1813
- }
1814
- }
1815
- }
1816
- }
1817
- }
1818
- },
1819
1711
  "/v1/trust-rules": {
1820
1712
  "get": {
1821
1713
  "operationId": "trustRulesList",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/gateway",
3
- "version": "0.13.0-dev.202610200020.9f20440",
3
+ "version": "0.13.0-dev.202610201855.522ff0d",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/vargasjr-dev/mycadet-temp.git"
@@ -28,7 +28,6 @@ import { ROUTES as channelIngressRoutes } from "../src/http/routes/channel-ingre
28
28
  import { ROUTES as channelPermissionOverrideRoutes } from "../src/http/routes/channel-permission-overrides-routes.js";
29
29
  import { ROUTES as contactsControlPlaneRoutes } from "../src/http/routes/contacts-control-plane-routes.js";
30
30
  import { ROUTES as credentialRequestRoutes } from "../src/http/routes/credential-requests.js";
31
- import { ROUTES as featureFlagRoutes } from "../src/http/routes/feature-flags.js";
32
31
  import { ROUTES as trustRuleRoutes } from "../src/http/routes/trust-rules-routes.js";
33
32
 
34
33
  const ROOT = resolve(import.meta.dir, "..");
@@ -43,7 +42,6 @@ const ALL_ROUTES: GatewayRouteDefinition[] = [
43
42
  ...channelPermissionOverrideRoutes,
44
43
  ...contactsControlPlaneRoutes,
45
44
  ...credentialRequestRoutes,
46
- ...featureFlagRoutes,
47
45
  ...trustRuleRoutes,
48
46
  ];
49
47
 
@@ -57,9 +57,6 @@ mock.module("../verification/text-verification.js", () => ({
57
57
 
58
58
  // The feature-flag resolver stays mocked off: nothing in this graph should
59
59
  // depend on a registry flag resolving true in tests.
60
- mock.module("../feature-flag-resolver.js", () => ({
61
- isFeatureFlagEnabled: () => false,
62
- }));
63
60
 
64
61
  await import("./test-preload.js");
65
62
  const { initGatewayDb, resetGatewayDb } = await import("../db/connection.js");
@@ -66,9 +66,6 @@ mock.module("../verification/text-verification.js", () => ({
66
66
 
67
67
  // The feature-flag resolver stays mocked off: nothing in this graph should
68
68
  // depend on a registry flag resolving true in tests.
69
- mock.module("../feature-flag-resolver.js", () => ({
70
- isFeatureFlagEnabled: () => false,
71
- }));
72
69
 
73
70
  await import("./test-preload.js");
74
71
  const { initGatewayDb, resetGatewayDb, getGatewayDb } =
@@ -1,13 +1,4 @@
1
- import {
2
- afterAll,
3
- afterEach,
4
- beforeAll,
5
- beforeEach,
6
- describe,
7
- expect,
8
- mock,
9
- test,
10
- } from "bun:test";
1
+ import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
11
2
  import { mkdtempSync, mkdirSync, rmSync } from "node:fs";
12
3
  import { tmpdir } from "node:os";
13
4
  import { join } from "node:path";
@@ -58,25 +49,6 @@ const {
58
49
  } = await import("../remote-web/pairing-challenge-store.js");
59
50
  const { bustGuardianIntegrityCache } =
60
51
  await import("../auth/guardian-integrity.js");
61
- const realBrowserAuthCookies = await import("../http/browser-auth-cookies.js");
62
- // Captured before any mock is armed: `mock.module` rewrites the live
63
- // namespace, so a restore needs its own reference to the real function.
64
- const realCookiePathForPublicBaseUrl =
65
- realBrowserAuthCookies.remoteWebRefreshCookiePathForPublicBaseUrl;
66
-
67
- /**
68
- * Swap the cookie-path helper the pairing route reads. A module mock outlives
69
- * the block that arms it, so every caller pairs an arm with a restore.
70
- */
71
- function setCookiePathHelper(
72
- impl: typeof realCookiePathForPublicBaseUrl,
73
- ): void {
74
- mock.module("../http/browser-auth-cookies.js", () => ({
75
- ...realBrowserAuthCookies,
76
- remoteWebRefreshCookiePathForPublicBaseUrl: impl,
77
- }));
78
- }
79
-
80
52
  const GUARDIAN_ID = "guardian-001";
81
53
 
82
54
  let testRoot: string;
@@ -286,7 +258,7 @@ describe("remote web pairing token exchange", () => {
286
258
  expect(cookie).toContain("HttpOnly");
287
259
  expect(cookie).toContain("Secure");
288
260
  expect(cookie).toContain("SameSite=Strict");
289
- expect(cookie).toContain("Path=/v1/guardian/refresh");
261
+ expect(cookie).toContain("Path=/");
290
262
  }
291
263
 
292
264
  const refreshToken = cookieValue(cookies, "cadet_web_refresh");
@@ -528,45 +500,6 @@ describe("remote web pairing token exchange", () => {
528
500
  expect(setCookies(refresh)).toHaveLength(0);
529
501
  });
530
502
 
531
- test("path-prefixed public base URLs keep refresh cookies on the public refresh path", async () => {
532
- const publicBaseUrl = `${PUBLIC_BASE_URL}/assistant-123`;
533
- const expectedCookiePath = "/assistant-123/v1/guardian/refresh";
534
- const challenge = createRemoteWebPairingChallenge(
535
- publicBaseUrl,
536
- TEST_REQUESTER,
537
- );
538
- expect(approveRemoteWebPairingChallenge(challenge.userCode).status).toBe(
539
- "approved",
540
- );
541
-
542
- const exchange = await handleRemoteWebPairingToken(
543
- makeTokenRequest({ deviceCode: challenge.deviceCode }),
544
- );
545
-
546
- const exchangeCookies = setCookies(exchange);
547
- expect(exchangeCookies).toHaveLength(1);
548
- expect(exchangeCookies[0]).toContain(`Path=${expectedCookiePath}`);
549
- const originalRefreshToken = cookieValue(
550
- exchangeCookies,
551
- "cadet_web_refresh",
552
- );
553
- expect(activeRefreshTokens()[0].browserRefreshCookiePath).toBe(
554
- expectedCookiePath,
555
- );
556
-
557
- const refresh = await handleGuardianRefresh(
558
- makeRefreshRequest(originalRefreshToken),
559
- );
560
-
561
- expect(refresh.status).toBe(200);
562
- const refreshCookies = setCookies(refresh);
563
- expect(refreshCookies).toHaveLength(1);
564
- expect(refreshCookies[0]).toContain(`Path=${expectedCookiePath}`);
565
- expect(activeRefreshTokens()[0].browserRefreshCookiePath).toBe(
566
- expectedCookiePath,
567
- );
568
- });
569
-
570
503
  test("cookie refresh rejects legacy device-bound refresh tokens", async () => {
571
504
  const legacyPair = mintAndRecordDeviceBoundTokenPair({
572
505
  guardianPrincipalId: GUARDIAN_ID,
@@ -1094,67 +1027,3 @@ describe("remote web pairing token exchange", () => {
1094
1027
  expect(activeRefreshTokens()[0].pairingUserAgent).toBe(expected);
1095
1028
  });
1096
1029
  });
1097
-
1098
- /**
1099
- * `remoteWebRefreshCookiePathForPublicBaseUrl` cannot return an empty string
1100
- * today, so branching delivery on its truthiness looks identical to branching
1101
- * on `deviceId` under every real input. Forcing the empty path the helper
1102
- * never produces pins which of the two the route actually reads.
1103
- */
1104
- describe("pairing token refresh delivery discriminator", () => {
1105
- beforeAll(() => {
1106
- setCookiePathHelper(() => "");
1107
- });
1108
-
1109
- afterAll(() => {
1110
- setCookiePathHelper(realCookiePathForPublicBaseUrl);
1111
- });
1112
-
1113
- test("a browser exchange still sets the cookie when the cookie path is empty", async () => {
1114
- const challenge = createRemoteWebPairingChallenge(
1115
- PUBLIC_BASE_URL,
1116
- TEST_REQUESTER,
1117
- );
1118
- expect(approveRemoteWebPairingChallenge(challenge.userCode).status).toBe(
1119
- "approved",
1120
- );
1121
-
1122
- const res = await handleRemoteWebPairingToken(
1123
- makeTokenRequest({ deviceCode: challenge.deviceCode }),
1124
- );
1125
-
1126
- expect(res.status).toBe(200);
1127
- const cookies = setCookies(res);
1128
- expect(cookies).toHaveLength(1);
1129
- expect(cookies[0]).toContain("cadet_web_refresh=");
1130
- expect(cookies[0]).toContain("HttpOnly");
1131
-
1132
- const body = (await res.json()) as Record<string, unknown>;
1133
- expect(body.refreshToken).toBeUndefined();
1134
- expect(body.refreshTokenExpiresAt).toBeUndefined();
1135
- });
1136
-
1137
- test("a device-bound exchange bodies the refresh token and sets no cookie", async () => {
1138
- const challenge = createRemoteWebPairingChallenge(
1139
- PUBLIC_BASE_URL,
1140
- TEST_REQUESTER,
1141
- );
1142
- expect(approveRemoteWebPairingChallenge(challenge.userCode).status).toBe(
1143
- "approved",
1144
- );
1145
-
1146
- const res = await handleRemoteWebPairingToken(
1147
- makeTokenRequest({
1148
- deviceCode: challenge.deviceCode,
1149
- deviceId: "host-device",
1150
- }),
1151
- );
1152
-
1153
- expect(res.status).toBe(200);
1154
- expect(setCookies(res)).toHaveLength(0);
1155
-
1156
- const body = (await res.json()) as Record<string, unknown>;
1157
- expect(typeof body.refreshToken).toBe("string");
1158
- expect(typeof body.refreshTokenExpiresAt).toBe("string");
1159
- });
1160
- });
@@ -62,11 +62,6 @@ mock.module("../ipc/assistant-client.js", () => ({
62
62
  },
63
63
  }));
64
64
 
65
- const actualFlagResolver = await import("../feature-flag-resolver.js");
66
- mock.module("../feature-flag-resolver.js", () => ({
67
- ...actualFlagResolver,
68
- isFeatureFlagEnabled: () => false,
69
- }));
70
65
 
71
66
  // Token minting stays real; a test can make the next mint throw to fail a
72
67
  // redemption after its claim.
@@ -37,11 +37,6 @@ mock.module("../ipc/assistant-client.js", () => ({
37
37
  },
38
38
  }));
39
39
 
40
- const actualFlagResolver = await import("../feature-flag-resolver.js");
41
- mock.module("../feature-flag-resolver.js", () => ({
42
- ...actualFlagResolver,
43
- isFeatureFlagEnabled: () => false,
44
- }));
45
40
 
46
41
  type StoredCredential = { value: string | undefined; unreachable: boolean };
47
42
  let storedCredentials: Record<string, StoredCredential> = {};
@@ -34,11 +34,6 @@ mock.module("../db/webhook-ingress-route-store.js", () => ({
34
34
  },
35
35
  }));
36
36
 
37
- const actualFlagResolver = await import("../feature-flag-resolver.js");
38
- mock.module("../feature-flag-resolver.js", () => ({
39
- ...actualFlagResolver,
40
- isFeatureFlagEnabled: () => false,
41
- }));
42
37
 
43
38
  const { reconcileTelegramWebhook } =
44
39
  await import("../telegram/webhook-manager.js");
@@ -18,7 +18,6 @@ import {
18
18
  createTrustRulesDeleteHandler,
19
19
  createTrustRulesResetHandler,
20
20
  } from "../http/routes/trust-rules.js";
21
- import { clearFeatureFlagStoreCache } from "../feature-flag-store.js";
22
21
  import "./test-preload.js";
23
22
 
24
23
  // ---------------------------------------------------------------------------
@@ -30,7 +29,6 @@ let store: TrustRuleStore;
30
29
  beforeEach(async () => {
31
30
  resetGatewayDb();
32
31
  resetTrustRuleCache();
33
- clearFeatureFlagStoreCache();
34
32
  await initGatewayDb();
35
33
  initTrustRuleCache();
36
34
  store = new TrustRuleStore();
@@ -38,7 +36,6 @@ beforeEach(async () => {
38
36
 
39
37
  afterEach(() => {
40
38
  resetTrustRuleCache();
41
- clearFeatureFlagStoreCache();
42
39
  resetGatewayDb();
43
40
  });
44
41
 
@@ -21,7 +21,7 @@ import {
21
21
  } from "../db/schema.js";
22
22
  import { readCredential } from "../credential-reader.js";
23
23
  import { credentialKey } from "../credential-key.js";
24
- import { areCloudFeaturesEnabled } from "../feature-flag-resolver.js";
24
+ import { areCloudFeaturesEnabled } from "../cloud-features.js";
25
25
  import { reportGuardianMintRefused } from "../guardian-integrity-reporter.js";
26
26
  import { ipcCallAssistant } from "../ipc/assistant-client.js";
27
27
  import { getLogger } from "../logger.js";
@@ -48,7 +48,6 @@ export interface RotateResult {
48
48
  refreshToken: string;
49
49
  refreshTokenExpiresAt: number;
50
50
  refreshAfter: number;
51
- browserRefreshCookiePath?: string;
52
51
  }
53
52
 
54
53
  // ---------------------------------------------------------------------------
@@ -335,7 +334,6 @@ function rotateRefreshTokenRecord(
335
334
  refreshToken: refresh.refreshToken,
336
335
  refreshTokenExpiresAt: refresh.refreshTokenExpiresAt,
337
336
  refreshAfter: refresh.refreshAfter,
338
- browserRefreshCookiePath: record.browserRefreshCookiePath ?? undefined,
339
337
  },
340
338
  };
341
339
  });
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Cloud-feature gating for the gateway.
3
+ *
4
+ * Cloud features (email callbacks, Telegram webhooks, guardian bootstrap
5
+ * against the cloud, record-activity pings) are on for every build except a
6
+ * local one that explicitly opts out with `CADET_DISABLE_CLOUD`.
7
+ */
8
+
9
+ export function isCloudServedBuild(): boolean {
10
+ const v = process.env.IS_CLOUD?.trim().toLowerCase();
11
+ return v === "true" || v === "1";
12
+ }
13
+
14
+ export function areCloudFeaturesEnabled(): boolean {
15
+ if (isCloudServedBuild()) return true;
16
+ const v = process.env.CADET_DISABLE_CLOUD?.trim().toLowerCase();
17
+ return !(v === "true" || v === "1");
18
+ }
@@ -2,7 +2,7 @@ import type { ConfigFileCache } from "../config-file-cache.js";
2
2
  import type { CredentialCache } from "../credential-cache.js";
3
3
  import { credentialKey } from "../credential-key.js";
4
4
  import { fetchImpl } from "../fetch.js";
5
- import { areCloudFeaturesEnabled } from "../feature-flag-resolver.js";
5
+ import { areCloudFeaturesEnabled } from "../cloud-features.js";
6
6
  import { getLogger } from "../logger.js";
7
7
  import { resolveCloudAssistantIdOrUndefined } from "../cloud-identity.js";
8
8
 
@@ -1,33 +1,19 @@
1
1
  export const BROWSER_REFRESH_COOKIE = "cadet_web_refresh";
2
- const BROWSER_REFRESH_PATH = "/v1/guardian/refresh";
3
2
 
4
- function normalizeCookiePath(value: string | undefined): string {
5
- if (!value || !value.startsWith("/") || /[;\r\n]/.test(value)) {
6
- return BROWSER_REFRESH_PATH;
7
- }
8
- return value;
9
- }
10
-
11
- export function remoteWebRefreshCookiePathForPublicBaseUrl(
12
- publicBaseUrl: string,
13
- ): string {
14
- const url = new URL(publicBaseUrl);
15
- const pathPrefix = url.pathname.replace(/\/+$/, "");
16
- return normalizeCookiePath(`${pathPrefix}${BROWSER_REFRESH_PATH}`);
17
- }
3
+ /** Domain-scoped: the edge iframes the web UI at /web/assistant/ (its refresh runs at /web/v1/guardian/refresh, the shell's own at /v1/guardian/refresh) and the pairing challenge's publicBaseUrl carries none of that prefix, so a narrow path never matched. */
4
+ export const BROWSER_REFRESH_COOKIE_PATH = "/";
18
5
 
19
6
  function browserAuthCookie(
20
7
  name: string,
21
8
  value: string,
22
9
  maxAgeSeconds: number,
23
- path: string | undefined,
24
10
  ): string {
25
11
  return [
26
12
  `${name}=${encodeURIComponent(value)}`,
27
13
  "HttpOnly",
28
14
  "Secure",
29
15
  "SameSite=Strict",
30
- `Path=${normalizeCookiePath(path)}`,
16
+ `Path=${BROWSER_REFRESH_COOKIE_PATH}`,
31
17
  `Max-Age=${Math.max(0, Math.floor(maxAgeSeconds))}`,
32
18
  ].join("; ");
33
19
  }
@@ -35,7 +21,6 @@ function browserAuthCookie(
35
21
  export function buildRemoteWebBrowserAuthCookies(params: {
36
22
  refreshToken: string;
37
23
  refreshTokenExpiresAtMs: number;
38
- refreshCookiePath?: string;
39
24
  }): string[] {
40
25
  const maxAgeSeconds = Math.ceil(
41
26
  (params.refreshTokenExpiresAtMs - Date.now()) / 1000,
@@ -45,7 +30,6 @@ export function buildRemoteWebBrowserAuthCookies(params: {
45
30
  BROWSER_REFRESH_COOKIE,
46
31
  params.refreshToken,
47
32
  maxAgeSeconds,
48
- params.refreshCookiePath,
49
33
  ),
50
34
  ];
51
35
  }
@@ -44,7 +44,6 @@ function browserRefreshResponse(
44
44
  for (const cookie of buildRemoteWebBrowserAuthCookies({
45
45
  refreshToken: result.refreshToken,
46
46
  refreshTokenExpiresAtMs: result.refreshTokenExpiresAt,
47
- refreshCookiePath: result.browserRefreshCookiePath,
48
47
  })) {
49
48
  headers.append("Set-Cookie", cookie);
50
49
  }
@@ -18,8 +18,8 @@ import {
18
18
  releaseRemoteWebPairingChallengeExchange,
19
19
  } from "../../remote-web/pairing-challenge-store.js";
20
20
  import {
21
+ BROWSER_REFRESH_COOKIE_PATH,
21
22
  buildRemoteWebBrowserAuthCookies,
22
- remoteWebRefreshCookiePathForPublicBaseUrl,
23
23
  } from "../browser-auth-cookies.js";
24
24
  import { errorResponse } from "../loopback-guard.js";
25
25
  import {
@@ -109,9 +109,6 @@ export async function handleRemoteWebPairingToken(
109
109
  };
110
110
  let guardianPrincipalId: string;
111
111
  let pair: RefreshableTokenPair;
112
- // Set on the browser path only: a device-bound pairing carries its refresh
113
- // token in the body, so there is no cookie to scope.
114
- let refreshCookiePath: string | undefined;
115
112
  try {
116
113
  guardianPrincipalId = await ensureCadetGuardianBinding();
117
114
  if (deviceBound) {
@@ -122,13 +119,10 @@ export async function handleRemoteWebPairingToken(
122
119
  identity,
123
120
  });
124
121
  } else {
125
- refreshCookiePath = remoteWebRefreshCookiePathForPublicBaseUrl(
126
- challenge.publicBaseUrl,
127
- );
128
122
  pair = mintAndRecordBrowserTokenPair({
129
123
  guardianPrincipalId,
130
124
  platform: REMOTE_WEB_PLATFORM,
131
- browserRefreshCookiePath: refreshCookiePath,
125
+ browserRefreshCookiePath: BROWSER_REFRESH_COOKIE_PATH,
132
126
  identity,
133
127
  });
134
128
  }
@@ -166,8 +160,8 @@ export async function handleRemoteWebPairingToken(
166
160
  };
167
161
 
168
162
  // Delivery follows the same discriminator the mint did. A browser exchange
169
- // never serializes its refresh token into the body, whatever the cookie
170
- // path helper returns.
163
+ // never serializes its refresh token into the body — it rides the HttpOnly
164
+ // cookie.
171
165
  if (deviceBound) {
172
166
  approved.refreshToken = pair.refreshToken;
173
167
  approved.refreshTokenExpiresAt = new Date(
@@ -177,7 +171,6 @@ export async function handleRemoteWebPairingToken(
177
171
  for (const cookie of buildRemoteWebBrowserAuthCookies({
178
172
  refreshToken: pair.refreshToken,
179
173
  refreshTokenExpiresAtMs: pair.refreshTokenExpiresAt,
180
- refreshCookiePath,
181
174
  })) {
182
175
  headers.append("Set-Cookie", cookie);
183
176
  }