@burdenoff/microfe-movethewheels 2026.1109.3 → 2026.1113.1

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.
@@ -1,82 +1,104 @@
1
1
  import { useMoveTheWheels as e } from "../providers/MoveTheWheelsProvider.js";
2
- import { useCallback as t, useEffect as n, useMemo as r, useRef as i, useState as a } from "react";
3
- import { clearGraphqlFetchResponseCache as o, graphqlFetch as s } from "@burdenoff/fe-libs/shared/graphql";
4
- import { print as c } from "graphql";
2
+ import { captureRequestActor as t, isMutationDocument as n, isPreDispatchRefusal as r, pinnedFetch as i } from "../utils/pinnedRequest.js";
3
+ import { useCallback as a, useEffect as o, useMemo as s, useRef as c, useState as l } from "react";
4
+ import { clearGraphqlFetchResponseCache as u, graphqlFetch as d } from "@burdenoff/fe-libs/shared/graphql";
5
+ import { print as f } from "graphql";
5
6
  // src/movethewheels/hooks/useShipmentStatusAuthority.ts
6
- var l = /* @__PURE__ */ new Set([
7
+ var p = /* @__PURE__ */ new Set([
7
8
  "STATUS_REVISION_CONFLICT",
8
9
  "BAD_USER_INPUT",
9
10
  "FORBIDDEN",
10
11
  "UNAUTHENTICATED",
11
12
  "NOT_FOUND"
12
- ]), u = class extends Error {
13
+ ]), m = class extends Error {
13
14
  code;
14
15
  constructor(e, t) {
15
16
  super(e), this.code = t, this.name = "ShipmentStatusRequestError";
16
17
  }
17
18
  };
18
- function d() {
19
- let { apiGatewayUrl: n, authToken: i, workspaceToken: a, workspaceId: o, tenantId: l } = e(), d = r(() => ({
20
- apiGatewayUrl: n,
21
- authToken: i,
22
- workspaceToken: a,
23
- workspaceId: o,
19
+ async function h(e, n, a, o) {
20
+ try {
21
+ let r = t({
22
+ authToken: e.authToken,
23
+ currentUser: e.currentUser
24
+ });
25
+ return await i(r, {
26
+ gateway: "workspace",
27
+ query: n,
28
+ variables: a,
29
+ ...e.apiGatewayUrl ? { baseUrl: e.apiGatewayUrl } : {},
30
+ ...e.workspaceId ? { workspaceId: e.workspaceId } : {},
31
+ tenantId: e.tenantId || !0,
32
+ organizationId: !0,
33
+ ...o ? { signal: o } : {}
34
+ });
35
+ } catch (e) {
36
+ throw r(e) ? new m(e.message, "UNAUTHENTICATED") : e;
37
+ }
38
+ }
39
+ function g() {
40
+ let { apiGatewayUrl: t, authToken: r, currentUser: i, workspaceToken: o, workspaceId: c, tenantId: l } = e(), u = s(() => ({
41
+ apiGatewayUrl: t,
42
+ authToken: r,
43
+ currentUser: i,
44
+ workspaceToken: o,
45
+ workspaceId: c,
24
46
  tenantId: l
25
47
  }), [
26
- n,
48
+ t,
49
+ r,
27
50
  i,
28
- a,
29
51
  o,
52
+ c,
30
53
  l
31
54
  ]);
32
- return t(async (e, t, n = !1, r) => {
33
- let i = await s({
55
+ return a(async (e, t, r = !1, i) => {
56
+ let a = f(e), o = r || n(a) ? await h(u, a, t, i) : await d({
34
57
  gateway: "workspace",
35
- query: c(e),
58
+ query: a,
36
59
  variables: t,
37
- baseUrl: d.apiGatewayUrl,
38
- authToken: d.authToken,
39
- workspaceToken: d.workspaceToken || !0,
40
- workspaceId: d.workspaceId || !0,
41
- tenantId: d.tenantId || !0,
60
+ baseUrl: u.apiGatewayUrl,
61
+ authToken: u.authToken,
62
+ workspaceToken: u.workspaceToken || !0,
63
+ workspaceId: u.workspaceId || !0,
64
+ tenantId: u.tenantId || !0,
42
65
  organizationId: !0,
43
- signal: r,
44
- skipAuthRetry: n
66
+ signal: i
45
67
  });
46
- if (i.errors?.length) {
47
- let e = i.errors[0], t = i.data === null && i.errors.length === 1 && typeof e?.extensions?.code == "string" ? e.extensions.code : null;
48
- throw new u(e?.message ?? "Unable to load the recorded status.", t);
68
+ if (o.errors?.length) {
69
+ let e = o.errors[0], t = o.data === null && o.errors.length === 1 && typeof e?.extensions?.code == "string" ? e.extensions.code : null;
70
+ throw new m(e?.message ?? "Unable to load the recorded status.", t);
49
71
  }
50
- if (i.data == null) throw new u("No acknowledgement was received.", null);
51
- return i.data;
52
- }, [d]);
72
+ if (o.data == null) throw new m("No acknowledgement was received.", null);
73
+ return o.data;
74
+ }, [u]);
53
75
  }
54
- function f(e, t, r = 0) {
55
- let i = d(), s = JSON.stringify(t), [c, l] = a(null);
56
- n(() => {
57
- let t = new AbortController(), n = {
58
- request: i,
59
- key: s,
60
- revision: r
76
+ function _(e, t, n = 0) {
77
+ let r = g(), i = JSON.stringify(t), [a, s] = l(null);
78
+ o(() => {
79
+ let t = new AbortController(), a = {
80
+ request: r,
81
+ key: i,
82
+ revision: n
61
83
  };
62
- if (l({
63
- ...n,
84
+ if (s({
85
+ ...a,
64
86
  data: null,
65
87
  error: null,
66
- loading: s !== "null"
67
- }), s === "null") return;
68
- r > 0 && o();
69
- let a = JSON.parse(s);
70
- return i(e, a, !1, t.signal).then((e) => {
71
- t.signal.aborted || l({
72
- ...n,
88
+ loading: i !== "null"
89
+ }), i === "null") return;
90
+ n > 0 && u();
91
+ let o = JSON.parse(i);
92
+ return r(e, o, !1, t.signal).then((e) => {
93
+ t.signal.aborted || s({
94
+ ...a,
73
95
  data: e,
74
96
  error: null,
75
97
  loading: !1
76
98
  });
77
99
  }).catch((e) => {
78
- t.signal.aborted || l({
79
- ...n,
100
+ t.signal.aborted || s({
101
+ ...a,
80
102
  data: null,
81
103
  error: e instanceof Error ? e.message : "Unable to load recorded status.",
82
104
  loading: !1
@@ -84,46 +106,46 @@ function f(e, t, r = 0) {
84
106
  }), () => t.abort();
85
107
  }, [
86
108
  e,
109
+ r,
87
110
  i,
88
- s,
89
- r
111
+ n
90
112
  ]);
91
- let u = c?.request === i && c.key === s && c.revision === r;
113
+ let c = a?.request === r && a.key === i && a.revision === n;
92
114
  return {
93
- data: u ? c.data : null,
94
- error: u ? c.error : null,
95
- loading: u ? c.loading : s !== "null"
115
+ data: c ? a.data : null,
116
+ error: c ? a.error : null,
117
+ loading: c ? a.loading : i !== "null"
96
118
  };
97
119
  }
98
- function p() {
99
- let e = d(), t = i(!1), n = i(!1), [r, o] = a(!1), [s, c] = a(null), [f, p] = a(0);
120
+ function v() {
121
+ let e = g(), t = c(!1), n = c(!1), [r, i] = l(!1), [a, o] = l(null), [s, u] = l(0);
100
122
  return {
101
- run: async (r, i, a) => {
123
+ run: async (r, a, s) => {
102
124
  if (t.current || n.current) return null;
103
- t.current = !0, o(!0), c(null);
125
+ t.current = !0, i(!0), o(null);
104
126
  try {
105
- let t = await e(r, i, !0);
106
- if (!a(t)) throw new u("The returned acknowledgement does not identify this decision.", null);
107
- return c({
127
+ let t = await e(r, a, !0);
128
+ if (!s(t)) throw new m("The returned acknowledgement does not identify this decision.", null);
129
+ return o({
108
130
  kind: "APPLIED",
109
131
  message: "Decision recorded. Review the refreshed status and history."
110
- }), p((e) => e + 1), t;
132
+ }), u((e) => e + 1), t;
111
133
  } catch (e) {
112
- let t = e instanceof u && e.code !== null && l.has(e.code);
113
- return n.current = !t, c({
134
+ let t = e instanceof m && e.code !== null && p.has(e.code);
135
+ return n.current = !t, o({
114
136
  kind: t ? "REJECTED" : "UNKNOWN",
115
137
  message: t ? `${e.message} Your input is preserved; refresh and review the recorded status before another action.` : "Acknowledgement is uncertain. Do not resend this action. Refresh the recorded status and review its decisions before beginning a separate new action."
116
138
  }), null;
117
139
  } finally {
118
- t.current = !1, o(!1);
140
+ t.current = !1, i(!1);
119
141
  }
120
142
  },
121
143
  busy: r,
122
- feedback: s,
123
- revision: f,
144
+ feedback: a,
145
+ revision: s,
124
146
  beginSeparateAction: () => {
125
- n.current = !1, c(null);
147
+ n.current = !1, o(null);
126
148
  }
127
149
  };
128
150
  }
129
- export { u as ShipmentStatusRequestError, d as useShipmentStatusApi, p as useShipmentStatusCommand, f as useShipmentStatusQuery };
151
+ export { m as ShipmentStatusRequestError, g as useShipmentStatusApi, v as useShipmentStatusCommand, _ as useShipmentStatusQuery };
@@ -3,7 +3,12 @@ export declare class ShipmentStatusRequestError extends Error {
3
3
  readonly code: string | null;
4
4
  constructor(message: string, code: string | null);
5
5
  }
6
- /** Normal shared gateway transport; mutation acknowledgements are never automatically retried. */
6
+ /**
7
+ * Reads use the shared refreshable gateway transport. Decisions (mutations) are
8
+ * bound to the actor who started them (BOFF-11027): they are sent through the
9
+ * pinned transport with the captured bearer and are never retried, refreshed or
10
+ * replayed under another profile's token.
11
+ */
7
12
  export declare function useShipmentStatusApi(): <T>(document: DocumentNode, variables: Record<string, unknown>, mutation?: boolean, signal?: AbortSignal) => Promise<T>;
8
13
  export declare function useShipmentStatusQuery<T>(document: DocumentNode, variables: Record<string, unknown> | null, revision?: number): {
9
14
  data: T | null;
@@ -0,0 +1,53 @@
1
+ import { GraphQLResponse } from '@burdenoff/fe-libs/shared/graphql';
2
+ export declare const SIGN_IN_REQUIRED_MESSAGE = "Your session has ended. Sign in again, then retry this action.";
3
+ export declare const ACTOR_CHANGED_MESSAGE = "The active account changed before this action was sent. Review it and try again.";
4
+ /**
5
+ * True when the error is a refusal raised before the write was sent, so the
6
+ * caller can report it as "not sent" rather than as an uncertain outcome.
7
+ */
8
+ export declare function isPreDispatchRefusal(error: unknown): boolean;
9
+ /** The parts of the MFE root props that identify the acting user. */
10
+ export interface RequestActorSource {
11
+ authToken?: string | null;
12
+ currentUser?: {
13
+ id?: string | null;
14
+ } | null;
15
+ }
16
+ /** The account and bearer an action was started with. */
17
+ export interface CapturedRequestActor {
18
+ readonly actorId: string;
19
+ readonly authToken: string;
20
+ }
21
+ export interface PinnedFetchOptions {
22
+ gateway: 'workspace' | 'global';
23
+ query: string;
24
+ variables?: Record<string, unknown>;
25
+ /**
26
+ * Workspace whose context (x-workspace-id and workspace token) the operation
27
+ * runs in. Defaults to the active workspace, as `graphqlFetch` does.
28
+ */
29
+ workspaceId?: string;
30
+ /**
31
+ * `false` sends a workspace-gateway operation without workspace authority
32
+ * (self-scoped operations such as accepting an invitation).
33
+ */
34
+ workspaceToken?: false;
35
+ /** Gateway base URL override passed by the host (dev override only). */
36
+ baseUrl?: string;
37
+ /** Context headers, resolved exactly as `graphqlFetch` resolves them. */
38
+ organizationId?: boolean | string;
39
+ tenantId?: boolean | string;
40
+ signal?: AbortSignal;
41
+ }
42
+ /**
43
+ * Record the acting user when an action starts. Call it synchronously at the
44
+ * top of a write so the capture reflects the account the user acted as.
45
+ */
46
+ export declare function captureRequestActor(source: RequestActorSource): CapturedRequestActor;
47
+ /** True when the document's first operation is a mutation. */
48
+ export declare function isMutationDocument(query: string): boolean;
49
+ /**
50
+ * Send one operation of an action bound to the captured actor. Returns the raw
51
+ * GraphQL response so call sites keep their own error and empty-data handling.
52
+ */
53
+ export declare function pinnedFetch<T>(actor: CapturedRequestActor, options: PinnedFetchOptions): Promise<GraphQLResponse<T>>;
@@ -19,8 +19,8 @@ import { CREATE_MTW_REPORT_MUTATION as ge, DELETE_MTW_REPORT_MUTATION as _e, FRE
19
19
  import { useCallback as Ae, useEffect as je, useMemo as Me, useState as V } from "react";
20
20
  import { Fragment as Ne, jsx as H, jsxs as U } from "react/jsx-runtime";
21
21
  import { clearGraphqlFetchResponseCache as Pe } from "@burdenoff/fe-libs/shared/graphql";
22
- import { EmphasisPanel as Fe, PagePurpose as Ie } from "@burdenoff/fe-libs/ui";
23
- import { PermissionProvider as W, usePermissions as Le } from "@burdenoff/fe-libs/shared/providers/shell";
22
+ import { PermissionProvider as W, usePermissions as Fe } from "@burdenoff/fe-libs/shared/providers/shell";
23
+ import { EmphasisPanel as Ie, PagePurpose as Le } from "@burdenoff/fe-libs/ui";
24
24
  // src/movethewheels/pages/ReportsPage.tsx
25
25
  var G = {
26
26
  currency: k,
@@ -49,7 +49,7 @@ function Ve() {
49
49
  });
50
50
  }
51
51
  function q() {
52
- let { apiGatewayUrl: t, authToken: h, workspaceToken: g, workspaceId: _, tenantId: v, currentUser: y } = me(), { settings: b } = he(), x = Le(), C = Me(() => ({
52
+ let { apiGatewayUrl: t, authToken: h, workspaceToken: g, workspaceId: _, tenantId: v, currentUser: y } = me(), { settings: b } = he(), x = Fe(), C = Me(() => ({
53
53
  apiGatewayUrl: t,
54
54
  authToken: h,
55
55
  workspaceToken: g,
@@ -168,7 +168,7 @@ function q() {
168
168
  })]
169
169
  }),
170
170
  children: [
171
- /* @__PURE__ */ H(Ie, {
171
+ /* @__PURE__ */ H(Le, {
172
172
  icon: /* @__PURE__ */ H(n, { size: 18 }),
173
173
  children: "Save the reports you need and generate them whenever you like, or have them generated every day, week or month. Each generation keeps its figures and rows so you can compare periods and download them as CSV or JSON."
174
174
  }),
@@ -177,7 +177,7 @@ function q() {
177
177
  /* @__PURE__ */ H(ne, { message: qe }),
178
178
  /* @__PURE__ */ U("div", {
179
179
  className: "grid grid-cols-1 gap-6 xl:grid-cols-3",
180
- children: [/* @__PURE__ */ U(Fe, {
180
+ children: [/* @__PURE__ */ U(Ie, {
181
181
  className: "space-y-3 xl:col-span-1",
182
182
  children: [/* @__PURE__ */ H("h2", {
183
183
  className: "text-base font-semibold text-text-primary",
@@ -19,8 +19,8 @@ import { formatCurrency as ce, formatDateTime as w, formatDistance as le, format
19
19
  import { DISTANCE_UNIT_OPTIONS as T, ORDER_PRIORITY_OPTIONS as E, WEIGHT_UNIT_OPTIONS as D, browserTimeZone as de, changedSettings as fe, currencyLabel as pe, currencyOptions as me, deliveryWindowError as he, timeZoneOptions as O } from "../utils/moduleSettings.js";
20
20
  import { useEffect as ge, useMemo as k, useState as A } from "react";
21
21
  import { jsx as j, jsxs as M } from "react/jsx-runtime";
22
- import { EmphasisPanel as N, PagePurpose as P } from "@burdenoff/fe-libs/ui";
23
- import { PermissionProvider as F, usePermissions as I } from "@burdenoff/fe-libs/shared/providers/shell";
22
+ import { PermissionProvider as N, usePermissions as P } from "@burdenoff/fe-libs/shared/providers/shell";
23
+ import { EmphasisPanel as F, PagePurpose as I } from "@burdenoff/fe-libs/ui";
24
24
  // src/movethewheels/pages/SettingsPage.tsx
25
25
  var L = "__viewer_local__";
26
26
  function R(e) {
@@ -65,18 +65,18 @@ var _e = [
65
65
  ];
66
66
  function z() {
67
67
  let { workspaceId: e } = x();
68
- return /* @__PURE__ */ j(F, {
68
+ return /* @__PURE__ */ j(N, {
69
69
  scopeId: e ?? null,
70
70
  gateway: "workspace",
71
71
  children: /* @__PURE__ */ j(B, {})
72
72
  });
73
73
  }
74
74
  function B() {
75
- let { navigate: e, basePath: t, workspaceId: r, currentUser: F } = x(), { settings: z, isLoaded: B, error: V, save: ve, reload: ye } = C(), H = I(), [U, W] = A(() => R(z)), [G, K] = A(!1), [be, q] = A(null), { message: xe, notify: Se } = ae();
75
+ let { navigate: e, basePath: t, workspaceId: r, currentUser: N } = x(), { settings: z, isLoaded: B, error: V, save: ve, reload: ye } = C(), H = P(), [U, W] = A(() => R(z)), [G, K] = A(!1), [be, q] = A(null), { message: xe, notify: Se } = ae();
76
76
  ge(() => {
77
77
  W(R(z));
78
78
  }, [z]);
79
- let J = !(!r || !F?.id || H.scopeId !== r || H.isLoading || H.error) && !H.isSuperAdmin && !H.hasPermission("mtw-settings:update"), Y = he(U.defaultDeliveryWindowHours), X = k(() => fe(z, {
79
+ let J = !(!r || !N?.id || H.scopeId !== r || H.isLoading || H.error) && !H.isSuperAdmin && !H.hasPermission("mtw-settings:update"), Y = he(U.defaultDeliveryWindowHours), X = k(() => fe(z, {
80
80
  defaultCurrency: U.defaultCurrency,
81
81
  distanceUnit: U.distanceUnit,
82
82
  weightUnit: U.weightUnit,
@@ -110,7 +110,7 @@ function B() {
110
110
  icon: /* @__PURE__ */ j(a, { size: 24 }),
111
111
  maxWidth: "xl",
112
112
  children: [
113
- /* @__PURE__ */ j(P, {
113
+ /* @__PURE__ */ j(I, {
114
114
  icon: /* @__PURE__ */ j(a, { size: 18 }),
115
115
  children: "Set how MoveTheWheels shows money, distances, weights and times for everyone in this workspace, and what new orders start with. Changes apply to every MoveTheWheels screen as soon as you save."
116
116
  }),
@@ -120,7 +120,7 @@ function B() {
120
120
  className: "grid grid-cols-1 gap-6 xl:grid-cols-3",
121
121
  children: [/* @__PURE__ */ M("div", {
122
122
  className: "min-w-0 space-y-6 xl:col-span-2",
123
- children: [/* @__PURE__ */ M(N, {
123
+ children: [/* @__PURE__ */ M(F, {
124
124
  className: "space-y-6",
125
125
  children: [/* @__PURE__ */ M("div", {
126
126
  className: "flex flex-wrap items-center justify-between gap-3",
@@ -0,0 +1,68 @@
1
+ import { clearGraphqlFetchResponseCache as e, getStoredAuthToken as t, getStoredWorkspaceId as n, graphqlFetchPinned as r, prepareWorkspaceRequest as i, resolveGatewayUrl as a } from "@burdenoff/fe-libs/shared/graphql";
2
+ import { getStoredTenantId as o } from "@burdenoff/fe-libs/shared/graphql/fetch";
3
+ import { getActiveUser as s } from "@burdenoff/fe-libs/shared/providers/shell";
4
+ // src/movethewheels/utils/pinnedRequest.ts
5
+ var c = "Your session has ended. Sign in again, then retry this action.", l = "The active account changed before this action was sent. Review it and try again.", u = [
6
+ c,
7
+ l,
8
+ "The captured session is missing or expired",
9
+ "The active account or workspace changed",
10
+ "Workspace authority expired",
11
+ "Unable to renew workspace authority"
12
+ ];
13
+ function d(e) {
14
+ return e instanceof Error && u.some((t) => e.message.startsWith(t));
15
+ }
16
+ function f(e) {
17
+ let n = s()?.id || null, r = e.currentUser?.id || n;
18
+ if (!r || !n) throw Error(c);
19
+ if (n !== r) throw Error(l);
20
+ let i = t() || e.authToken || "";
21
+ if (!i) throw Error(c);
22
+ return {
23
+ actorId: r,
24
+ authToken: i
25
+ };
26
+ }
27
+ function p(e) {
28
+ if (s()?.id !== e.actorId) throw Error(l);
29
+ }
30
+ function m(e) {
31
+ return /^\s*mutation\b/.test(e);
32
+ }
33
+ async function h(t, s) {
34
+ let { gateway: c, query: l, variables: u, workspaceId: d, baseUrl: f, organizationId: h, tenantId: g, signal: _ } = s;
35
+ p(t);
36
+ let v;
37
+ if (c === "workspace" && s.workspaceToken === !1) v = !1;
38
+ else if (c === "workspace") {
39
+ let e = n(), r = d || e;
40
+ if (r && r === e) {
41
+ let e = await i({
42
+ url: a("workspace", f),
43
+ authToken: t.authToken,
44
+ actorId: t.actorId,
45
+ workspaceId: r,
46
+ tenantId: o() ?? void 0,
47
+ currentQuery: l,
48
+ ..._ ? { signal: _ } : {}
49
+ });
50
+ e.assertCurrent(), v = e.workspaceToken;
51
+ } else v = !0;
52
+ }
53
+ p(t);
54
+ let y = await r({
55
+ gateway: c,
56
+ query: l,
57
+ variables: u,
58
+ authToken: t.authToken,
59
+ ...f ? { baseUrl: f } : {},
60
+ ...d ? { workspaceId: d } : {},
61
+ ...v === void 0 ? {} : { workspaceToken: v },
62
+ ...h === void 0 ? {} : { organizationId: h },
63
+ ...g === void 0 ? {} : { tenantId: g },
64
+ ..._ ? { signal: _ } : {}
65
+ });
66
+ return m(l) && !y.errors?.length && e(), y;
67
+ }
68
+ export { l as ACTOR_CHANGED_MESSAGE, c as SIGN_IN_REQUIRED_MESSAGE, f as captureRequestActor, m as isMutationDocument, d as isPreDispatchRefusal, h as pinnedFetch };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burdenoff/microfe-movethewheels",
3
- "version": "2026.1109.3",
3
+ "version": "2026.1113.1",
4
4
  "description": "Burdenoff MoveTheWheels Microfrontend - Logistics & Supply Chain Management Platform",
5
5
  "type": "module",
6
6
  "files": [
@@ -90,7 +90,7 @@
90
90
  },
91
91
  "dependencies": {
92
92
  "@apollo/client": "^4.3.7",
93
- "@burdenoff/fe-libs": "2026.1017.12",
93
+ "@burdenoff/fe-libs": "2026.1102.4",
94
94
  "@graphql-typed-document-node/core": "^3.2.0",
95
95
  "@react-leaflet/core": "^3.0.0",
96
96
  "@tanstack/react-query": "^5.106.1",
@@ -112,38 +112,39 @@
112
112
  "@escape.tech/graphql-armor-cost-limit": "2.4.3",
113
113
  "@graphql-codegen/core": "6.2.2",
114
114
  "@graphql-codegen/schema-ast": "6.1.1",
115
- "@graphql-codegen/typed-document-node": "7.1.1",
115
+ "@graphql-codegen/typed-document-node": "7.2.0",
116
116
  "@graphql-codegen/typescript": "6.1.2",
117
- "@graphql-codegen/typescript-operations": "6.1.10",
118
- "@graphql-tools/load": "8.1.21",
117
+ "@graphql-codegen/typescript-operations": "6.2.0",
118
+ "@graphql-tools/load": "9.1.0",
119
119
  "@graphql-tools/url-loader": "9.1.14",
120
- "@storybook/addon-docs": "10.6.2",
121
- "@storybook/addon-vitest": "10.6.2",
122
- "@storybook/react": "10.6.2",
123
- "@storybook/react-vite": "10.6.2",
120
+ "@storybook/addon-docs": "10.6.5",
121
+ "@storybook/addon-vitest": "10.6.5",
122
+ "@storybook/react": "10.6.5",
123
+ "@storybook/react-vite": "10.6.5",
124
124
  "@tailwindcss/vite": "^4.3.5",
125
125
  "@types/bun": "^1.4.4",
126
126
  "@types/node": "^24.19.2",
127
127
  "@types/react": "^19.3.0",
128
128
  "@types/react-dom": "^19.3.0",
129
129
  "@vitejs/plugin-react": "^6.2.1",
130
- "@vitest/browser": "4.1.12",
130
+ "@vitest/browser": "5.0.5",
131
131
  "@vitest/browser-playwright": "4.1.12",
132
132
  "@vitest/runner": "4.1.12",
133
133
  "autoprefixer": "^10.6.2",
134
134
  "eslint": "^9.39.5",
135
135
  "lefthook": "^2.2.2",
136
136
  "postcss": "^8.5.32",
137
- "react-test-renderer": "19.3.0",
138
- "storybook": "10.6.2",
137
+ "react-test-renderer": "19.3.1",
138
+ "storybook": "10.6.5",
139
139
  "tailwindcss": "^4.3.5",
140
140
  "typescript": "6.0.3",
141
141
  "unplugin-dts": "1.1.2",
142
142
  "vite": "8.3.5",
143
- "vitest": "4.1.12"
143
+ "vitest": "5.0.5"
144
144
  },
145
145
  "peerDependencies": {
146
146
  "@apollo/client": "^4.0.11",
147
+ "@burdenoff/fe-libs": "^2026.1102.4",
147
148
  "react": "^19.0.0",
148
149
  "react-dom": "^19.0.0",
149
150
  "zustand": "^5.0.0"
@@ -2,6 +2,12 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
2
  import { print, type DocumentNode } from 'graphql';
3
3
  import { graphqlFetch, clearGraphqlFetchResponseCache } from '@burdenoff/fe-libs/shared/graphql';
4
4
  import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
5
+ import {
6
+ captureRequestActor,
7
+ isMutationDocument,
8
+ isPreDispatchRefusal,
9
+ pinnedFetch,
10
+ } from '../utils/pinnedRequest';
5
11
 
6
12
  const KNOWN_REJECTIONS = new Set([
7
13
  'STATUS_REVISION_CONFLICT',
@@ -21,12 +27,61 @@ export class ShipmentStatusRequestError extends Error {
21
27
  }
22
28
  }
23
29
 
24
- /** Normal shared gateway transport; mutation acknowledgements are never automatically retried. */
30
+ interface ShipmentStatusContext {
31
+ apiGatewayUrl?: string;
32
+ authToken?: string;
33
+ currentUser?: { id?: string | null } | null;
34
+ workspaceId?: string;
35
+ tenantId?: string;
36
+ }
37
+
38
+ /**
39
+ * Send one decision as the actor who started it. A refusal raised before
40
+ * dispatch (another account became active, or the captured session expired)
41
+ * is a known rejection: nothing was sent, so the input is preserved and the
42
+ * user can review and retry, instead of being told the outcome is uncertain.
43
+ */
44
+ async function sendDecision<T>(
45
+ context: ShipmentStatusContext,
46
+ query: string,
47
+ variables: Record<string, unknown>,
48
+ signal?: AbortSignal
49
+ ) {
50
+ try {
51
+ const actor = captureRequestActor({
52
+ authToken: context.authToken,
53
+ currentUser: context.currentUser,
54
+ });
55
+ return await pinnedFetch<T>(actor, {
56
+ gateway: 'workspace',
57
+ query,
58
+ variables,
59
+ ...(context.apiGatewayUrl ? { baseUrl: context.apiGatewayUrl } : {}),
60
+ ...(context.workspaceId ? { workspaceId: context.workspaceId } : {}),
61
+ tenantId: context.tenantId || true,
62
+ organizationId: true,
63
+ ...(signal ? { signal } : {}),
64
+ });
65
+ } catch (failure) {
66
+ if (isPreDispatchRefusal(failure)) {
67
+ throw new ShipmentStatusRequestError((failure as Error).message, 'UNAUTHENTICATED');
68
+ }
69
+ throw failure;
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Reads use the shared refreshable gateway transport. Decisions (mutations) are
75
+ * bound to the actor who started them (BOFF-11027): they are sent through the
76
+ * pinned transport with the captured bearer and are never retried, refreshed or
77
+ * replayed under another profile's token.
78
+ */
25
79
  export function useShipmentStatusApi() {
26
- const { apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId } = useMoveTheWheels();
80
+ const { apiGatewayUrl, authToken, currentUser, workspaceToken, workspaceId, tenantId } =
81
+ useMoveTheWheels();
27
82
  const context = useMemo(
28
- () => ({ apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId }),
29
- [apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId]
83
+ () => ({ apiGatewayUrl, authToken, currentUser, workspaceToken, workspaceId, tenantId }),
84
+ [apiGatewayUrl, authToken, currentUser, workspaceToken, workspaceId, tenantId]
30
85
  );
31
86
  return useCallback(
32
87
  async <T>(
@@ -35,19 +90,23 @@ export function useShipmentStatusApi() {
35
90
  mutation = false,
36
91
  signal?: AbortSignal
37
92
  ): Promise<T> => {
38
- const response = await graphqlFetch<T>({
39
- gateway: 'workspace',
40
- query: print(document),
41
- variables,
42
- baseUrl: context.apiGatewayUrl,
43
- authToken: context.authToken,
44
- workspaceToken: context.workspaceToken || true,
45
- workspaceId: context.workspaceId || true,
46
- tenantId: context.tenantId || true,
47
- organizationId: true,
48
- signal,
49
- skipAuthRetry: mutation,
50
- });
93
+ const query = print(document);
94
+ // A mutation document is a decision even if a caller forgot the flag.
95
+ const response =
96
+ mutation || isMutationDocument(query)
97
+ ? await sendDecision<T>(context, query, variables, signal)
98
+ : await graphqlFetch<T>({
99
+ gateway: 'workspace',
100
+ query,
101
+ variables,
102
+ baseUrl: context.apiGatewayUrl,
103
+ authToken: context.authToken,
104
+ workspaceToken: context.workspaceToken || true,
105
+ workspaceId: context.workspaceId || true,
106
+ tenantId: context.tenantId || true,
107
+ organizationId: true,
108
+ signal,
109
+ });
51
110
  if (response.errors?.length) {
52
111
  // A single verified rejection is distinct from a transport failure or partial response.
53
112
  const first = response.errors[0];
@@ -0,0 +1,197 @@
1
+ /**
2
+ * Actor-bound transport for writes (BOFF-11027, following BOFF-10939).
3
+ *
4
+ * The default `graphqlFetch` is refreshable: when an explicit `authToken` has
5
+ * expired it falls back to the token of whichever profile is active in the
6
+ * browser, and its UNAUTHENTICATED retry re-reads storage. A write started by
7
+ * one account could therefore be sent with another account's bearer if the
8
+ * user switches profile while it is in flight.
9
+ *
10
+ * Writes in this MFE go through `pinnedFetch` instead:
11
+ *
12
+ * 1. `captureRequestActor` runs when the user starts the action. It records
13
+ * the acting user and that user's access token, and refuses if the profile
14
+ * active in the browser is a different account.
15
+ * 2. For the active workspace, `prepareWorkspaceRequest` binds the workspace
16
+ * token to the same actor and refuses if the account or workspace selection
17
+ * changed while it was being prepared.
18
+ * 3. `graphqlFetchPinned` sends the captured bearer, refuses an expired one
19
+ * before dispatch and never refreshes or replays the operation under the
20
+ * profile token stored in the browser.
21
+ *
22
+ * Reads stay on the refreshable `graphqlFetch`: they are same-actor reads on
23
+ * long-lived pages where a silent token refresh is the expected behaviour, and
24
+ * a refreshed read cannot change data.
25
+ */
26
+ import {
27
+ clearGraphqlFetchResponseCache,
28
+ getStoredAuthToken,
29
+ getStoredWorkspaceId,
30
+ graphqlFetchPinned,
31
+ prepareWorkspaceRequest,
32
+ resolveGatewayUrl,
33
+ type GraphQLResponse,
34
+ } from '@burdenoff/fe-libs/shared/graphql';
35
+ import { getStoredTenantId } from '@burdenoff/fe-libs/shared/graphql/fetch';
36
+ import { getActiveUser } from '@burdenoff/fe-libs/shared/providers/shell';
37
+
38
+ export const SIGN_IN_REQUIRED_MESSAGE =
39
+ 'Your session has ended. Sign in again, then retry this action.';
40
+ export const ACTOR_CHANGED_MESSAGE =
41
+ 'The active account changed before this action was sent. Review it and try again.';
42
+
43
+ /**
44
+ * Messages of the refusals raised before the operation is dispatched: by the
45
+ * capture below, by `prepareWorkspaceRequest` and by `graphqlFetchPinned`.
46
+ */
47
+ const PRE_DISPATCH_REFUSALS = [
48
+ SIGN_IN_REQUIRED_MESSAGE,
49
+ ACTOR_CHANGED_MESSAGE,
50
+ 'The captured session is missing or expired',
51
+ 'The active account or workspace changed',
52
+ 'Workspace authority expired',
53
+ 'Unable to renew workspace authority',
54
+ ];
55
+
56
+ /**
57
+ * True when the error is a refusal raised before the write was sent, so the
58
+ * caller can report it as "not sent" rather than as an uncertain outcome.
59
+ */
60
+ export function isPreDispatchRefusal(error: unknown): boolean {
61
+ return (
62
+ error instanceof Error &&
63
+ PRE_DISPATCH_REFUSALS.some((prefix) => error.message.startsWith(prefix))
64
+ );
65
+ }
66
+
67
+ /** The parts of the MFE root props that identify the acting user. */
68
+ export interface RequestActorSource {
69
+ authToken?: string | null;
70
+ currentUser?: { id?: string | null } | null;
71
+ }
72
+
73
+ /** The account and bearer an action was started with. */
74
+ export interface CapturedRequestActor {
75
+ readonly actorId: string;
76
+ readonly authToken: string;
77
+ }
78
+
79
+ export interface PinnedFetchOptions {
80
+ gateway: 'workspace' | 'global';
81
+ query: string;
82
+ variables?: Record<string, unknown>;
83
+ /**
84
+ * Workspace whose context (x-workspace-id and workspace token) the operation
85
+ * runs in. Defaults to the active workspace, as `graphqlFetch` does.
86
+ */
87
+ workspaceId?: string;
88
+ /**
89
+ * `false` sends a workspace-gateway operation without workspace authority
90
+ * (self-scoped operations such as accepting an invitation).
91
+ */
92
+ workspaceToken?: false;
93
+ /** Gateway base URL override passed by the host (dev override only). */
94
+ baseUrl?: string;
95
+ /** Context headers, resolved exactly as `graphqlFetch` resolves them. */
96
+ organizationId?: boolean | string;
97
+ tenantId?: boolean | string;
98
+ signal?: AbortSignal;
99
+ }
100
+
101
+ /**
102
+ * Record the acting user when an action starts. Call it synchronously at the
103
+ * top of a write so the capture reflects the account the user acted as.
104
+ */
105
+ export function captureRequestActor(source: RequestActorSource): CapturedRequestActor {
106
+ const activeActorId = getActiveUser()?.id || null;
107
+ const actorId = source.currentUser?.id || activeActorId;
108
+ if (!actorId || !activeActorId) {
109
+ throw new Error(SIGN_IN_REQUIRED_MESSAGE);
110
+ }
111
+ if (activeActorId !== actorId) {
112
+ throw new Error(ACTOR_CHANGED_MESSAGE);
113
+ }
114
+ // The active profile belongs to the acting user, so its stored token is that
115
+ // user's current bearer (it may be fresher than the prop after a refresh).
116
+ // `getStoredAuthToken` returns null for an expired token; the explicit prop
117
+ // is then the only candidate, and the pinned transport refuses it if it has
118
+ // expired too.
119
+ const authToken = getStoredAuthToken() || source.authToken || '';
120
+ if (!authToken) {
121
+ throw new Error(SIGN_IN_REQUIRED_MESSAGE);
122
+ }
123
+ return { actorId, authToken };
124
+ }
125
+
126
+ function assertActorStillActive(actor: CapturedRequestActor): void {
127
+ if (getActiveUser()?.id !== actor.actorId) {
128
+ throw new Error(ACTOR_CHANGED_MESSAGE);
129
+ }
130
+ }
131
+
132
+ /** True when the document's first operation is a mutation. */
133
+ export function isMutationDocument(query: string): boolean {
134
+ return /^\s*mutation\b/.test(query);
135
+ }
136
+
137
+ /**
138
+ * Send one operation of an action bound to the captured actor. Returns the raw
139
+ * GraphQL response so call sites keep their own error and empty-data handling.
140
+ */
141
+ export async function pinnedFetch<T>(
142
+ actor: CapturedRequestActor,
143
+ options: PinnedFetchOptions
144
+ ): Promise<GraphQLResponse<T>> {
145
+ const { gateway, query, variables, workspaceId, baseUrl, organizationId, tenantId, signal } =
146
+ options;
147
+ assertActorStillActive(actor);
148
+
149
+ let workspaceToken: string | boolean | undefined;
150
+ if (gateway === 'workspace' && options.workspaceToken === false) {
151
+ workspaceToken = false;
152
+ } else if (gateway === 'workspace') {
153
+ const activeWorkspaceId = getStoredWorkspaceId();
154
+ const targetWorkspaceId = workspaceId || activeWorkspaceId;
155
+ if (targetWorkspaceId && targetWorkspaceId === activeWorkspaceId) {
156
+ const prepared = await prepareWorkspaceRequest({
157
+ url: resolveGatewayUrl('workspace', baseUrl),
158
+ authToken: actor.authToken,
159
+ actorId: actor.actorId,
160
+ workspaceId: targetWorkspaceId,
161
+ tenantId: getStoredTenantId() ?? undefined,
162
+ currentQuery: query,
163
+ ...(signal ? { signal } : {}),
164
+ });
165
+ prepared.assertCurrent();
166
+ workspaceToken = prepared.workspaceToken;
167
+ } else {
168
+ // A workspace other than the active one (for example a row on a
169
+ // workspace list): the pinned transport mints its workspace token with
170
+ // the captured bearer, so the token subject is still the captured actor.
171
+ workspaceToken = true;
172
+ }
173
+ }
174
+
175
+ // Synchronous with the dispatch below: nothing can switch the profile between
176
+ // this check and the pinned transport reading the request options.
177
+ assertActorStillActive(actor);
178
+ const response = await graphqlFetchPinned<T>({
179
+ gateway,
180
+ query,
181
+ variables,
182
+ authToken: actor.authToken,
183
+ ...(baseUrl ? { baseUrl } : {}),
184
+ ...(workspaceId ? { workspaceId } : {}),
185
+ ...(workspaceToken !== undefined ? { workspaceToken } : {}),
186
+ ...(organizationId !== undefined ? { organizationId } : {}),
187
+ ...(tenantId !== undefined ? { tenantId } : {}),
188
+ ...(signal ? { signal } : {}),
189
+ });
190
+
191
+ // A completed write must not be followed by a refetch served from the
192
+ // 15-second response cache with pre-write data.
193
+ if (isMutationDocument(query) && !response.errors?.length) {
194
+ clearGraphqlFetchResponseCache();
195
+ }
196
+ return response;
197
+ }