@burdenoff/fe-libs 2026.615.1 → 2026.616.2

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,29 @@ export interface GatewayBaseMapping {
34
34
  * @param localDefaults - Override defaults for local development
35
35
  */
36
36
  export declare function resolveGatewayBases(extraMappings?: GatewayBaseMapping[], localDefaults?: GatewayBases): GatewayBases;
37
+ /**
38
+ * Attach Cloudflare Access service-token headers to a request iff a token is
39
+ * provided AND the request targets one of the CF-protected gateway origins.
40
+ * Pure + exported so it can be unit-tested without mocking `import.meta.env`.
41
+ */
42
+ export declare function maybeAttachCfAccessHeaders(request: Request, gatewayOrigins: ReadonlySet<string>, clientId?: string, clientSecret?: string): Request;
43
+ /**
44
+ * Options for installGatewayFetchRewrite.
45
+ */
46
+ export interface GatewayFetchRewriteOptions {
47
+ /**
48
+ * Cloudflare Access service-token. Vite only statically inlines custom VITE_
49
+ * env vars in APP source, not inside this bundled library, so the app reads
50
+ * `import.meta.env.VITE_CF_ACCESS_CLIENT_ID/_SECRET` in its own source and
51
+ * forwards them here. When both are present, CF-Access-Client-Id/Secret headers
52
+ * are attached to requests targeting a configured gateway origin. Omit on
53
+ * prod/local (gateways are not CF-gated).
54
+ */
55
+ cfAccess?: {
56
+ clientId?: string;
57
+ clientSecret?: string;
58
+ };
59
+ }
37
60
  /**
38
61
  * Install a global fetch interceptor that rewrites GraphQL request URLs
39
62
  * to the correct gateway domain based on the URL path.
@@ -42,8 +65,9 @@ export declare function resolveGatewayBases(extraMappings?: GatewayBaseMapping[]
42
65
  * - `/workspaces/graphql` → workspaceBase
43
66
  *
44
67
  * @param bases - Gateway base URLs to rewrite to
68
+ * @param options - Optional CF Access service-token for header injection
45
69
  */
46
- export declare function installGatewayFetchRewrite(bases: GatewayBases): void;
70
+ export declare function installGatewayFetchRewrite(bases: GatewayBases, options?: GatewayFetchRewriteOptions): void;
47
71
  /**
48
72
  * Suppress verbose console output in production/non-debug environments.
49
73
  *
@@ -1 +1 @@
1
- {"version":3,"file":"gatewayFetchRewrite.d.ts","sourceRoot":"","sources":["../../../src/shared/utils/gatewayFetchRewrite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,kBAAkB;IACjC,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,KAAK,EAAE,YAAY,CAAC;CACrB;AAmID;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,aAAa,CAAC,EAAE,kBAAkB,EAAE,EACpC,aAAa,CAAC,EAAE,YAAY,GAC3B,YAAY,CAad;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAqHpE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAyB,GAAG,IAAI,CAQtE"}
1
+ {"version":3,"file":"gatewayFetchRewrite.d.ts","sourceRoot":"","sources":["../../../src/shared/utils/gatewayFetchRewrite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,kBAAkB;IACjC,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,KAAK,EAAE,YAAY,CAAC;CACrB;AAmID;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,aAAa,CAAC,EAAE,kBAAkB,EAAE,EACpC,aAAa,CAAC,EAAE,YAAY,GAC3B,YAAY,CAad;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,EACnC,QAAQ,CAAC,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAaT;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACzD;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,YAAY,EACnB,OAAO,CAAC,EAAE,0BAA0B,GACnC,IAAI,CA6IN;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAyB,GAAG,IAAI,CAQtE"}
@@ -81,22 +81,38 @@ function v(e, t) {
81
81
  for (let e of a) if (n === e.hostname) return e.bases;
82
82
  return t ?? i;
83
83
  }
84
- function y(e) {
85
- let { globalBase: t, workspaceBase: n } = e;
86
- if (!t || !n) return;
87
- let r = globalThis.fetch.bind(globalThis), i = window.location.origin, o = new Set([i, "https://gw-global.local.burdenoff.com"]), s = new Set([i, "https://gw-wspace.local.burdenoff.com"]), c = (e) => /(?:^|\/)global\/graphql$/.test(e) ? "/global/graphql" : /(?:^|\/)workspaces\/graphql$/.test(e) ? "/workspaces/graphql" : "", u = (e) => {
88
- let r = new URL(e, window.location.origin), i = c(r.pathname);
89
- return i === "/global/graphql" && o.has(r.origin) ? `${t}${i}${r.search}${r.hash}` : i === "/workspaces/graphql" && s.has(r.origin) ? `${n}${i}${r.search}${r.hash}` : e;
90
- }, d = async (e) => {
91
- if (!(e.method.toUpperCase() === "POST" && /(?:^|\/)graphql$/.test(new URL(e.url).pathname))) return r(e);
92
- let t = await e.clone().text(), n = _(e.clone()), i = m(t);
93
- if (!i?.length) return r(e);
94
- let o = t.trimStart().startsWith("["), s = i.map((e) => p(n, e));
84
+ function y(e, t, n, r) {
85
+ if (!n || !r) return e;
86
+ let i;
87
+ try {
88
+ i = new URL(e.url).origin;
89
+ } catch {
90
+ return e;
91
+ }
92
+ if (!t.has(i)) return e;
93
+ let a = new Headers(e.headers);
94
+ return a.set("CF-Access-Client-Id", n), a.set("CF-Access-Client-Secret", r), new Request(e, { headers: a });
95
+ }
96
+ function b(e, t) {
97
+ let { globalBase: n, workspaceBase: r } = e;
98
+ if (!n || !r) return;
99
+ let i = globalThis.fetch.bind(globalThis), o = window.location.origin, s = t?.cfAccess?.clientId, c = t?.cfAccess?.clientSecret, u = !!(s && c), d = /* @__PURE__ */ new Set();
100
+ if (u) for (let e of [n, r]) try {
101
+ d.add(new URL(e).origin);
102
+ } catch {}
103
+ let f = (e) => u ? y(e, d, s, c) : e, v = new Set([o, "https://gw-global.local.burdenoff.com"]), b = new Set([o, "https://gw-wspace.local.burdenoff.com"]), x = (e) => /(?:^|\/)global\/graphql$/.test(e) ? "/global/graphql" : /(?:^|\/)workspaces\/graphql$/.test(e) ? "/workspaces/graphql" : "", S = (e) => {
104
+ let t = new URL(e, window.location.origin), i = x(t.pathname);
105
+ return i === "/global/graphql" && v.has(t.origin) ? `${n}${i}${t.search}${t.hash}` : i === "/workspaces/graphql" && b.has(t.origin) ? `${r}${i}${t.search}${t.hash}` : e;
106
+ }, C = async (e) => {
107
+ if (!(e.method.toUpperCase() === "POST" && /(?:^|\/)graphql$/.test(new URL(e.url).pathname))) return i(e);
108
+ let t = await e.clone().text(), n = _(e.clone()), r = m(t);
109
+ if (!r?.length) return i(e);
110
+ let o = t.trimStart().startsWith("["), s = r.map((e) => p(n, e));
95
111
  if (g() && s.every(Boolean)) {
96
112
  let e = l(), t = s.map((t) => e.get(t)), n = Date.now();
97
113
  if (t.every((e) => e && e.expiresAt > n)) return h(t.map((e) => e.value), o);
98
114
  }
99
- let c = await r(e);
115
+ let c = await i(e);
100
116
  if (!c.ok || !s.some(Boolean) || !g()) return c;
101
117
  try {
102
118
  let e = await c.clone().json(), t = Array.isArray(e) ? e : [e], n = l();
@@ -109,18 +125,18 @@ function y(e) {
109
125
  });
110
126
  } catch {}
111
127
  return c;
112
- }, f = r, v = ((e, t) => {
113
- if (e == null) return r(e, t);
128
+ }, w = i, T = ((e, t) => {
129
+ if (e == null) return i(e, t);
114
130
  if (e instanceof Request) {
115
- let n = u(e.url), r = new Request(n, e);
116
- return d(t ? new Request(r, t) : r);
131
+ let n = S(e.url), r = new Request(n, e);
132
+ return C(f(t ? new Request(r, t) : r));
117
133
  }
118
134
  let n = typeof e == "string" ? e : e.toString();
119
- return d(new Request(u(n), t));
135
+ return C(f(new Request(S(n), t)));
120
136
  });
121
- f.preconnect && (v.preconnect = f.preconnect), globalThis.fetch = v;
137
+ w.preconnect && (T.preconnect = w.preconnect), globalThis.fetch = T;
122
138
  }
123
- function b(e = "VITE_VERBOSE_CONSOLE") {
139
+ function x(e = "VITE_VERBOSE_CONSOLE") {
124
140
  ({
125
141
  BASE_URL: "/",
126
142
  DEV: !1,
@@ -130,4 +146,4 @@ function b(e = "VITE_VERBOSE_CONSOLE") {
130
146
  })?.[e] !== "true" && (console.log = () => {}, console.info = () => {}, console.debug = () => {});
131
147
  }
132
148
  //#endregion
133
- export { y as installGatewayFetchRewrite, v as resolveGatewayBases, b as suppressConsole };
149
+ export { b as installGatewayFetchRewrite, v as resolveGatewayBases, x as suppressConsole };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burdenoff/fe-libs",
3
- "version": "2026.615.1",
3
+ "version": "2026.616.2",
4
4
  "description": "Burdenoff frontend primitives and domain libraries",
5
5
  "type": "module",
6
6
  "imports": {