@burdenoff/microfe-movethewheels 2026.827.1 → 2026.828.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,6 +1,5 @@
1
- import { useCallback, useEffect, useMemo, useState } from 'react';
1
+ import { useCallback, useEffect, useState } from 'react';
2
2
  import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
3
- import { executeGraphQL } from '../utils/graphqlClient';
4
3
 
5
4
  export interface MovethewheelsReport {
6
5
  id: string;
@@ -20,46 +19,6 @@ export interface GeneratedReport {
20
19
  report: MovethewheelsReport;
21
20
  }
22
21
 
23
- const REPORT_FIELDS = `
24
- id
25
- name
26
- description
27
- type
28
- status
29
- schedule
30
- lastGenerated
31
- createdAt
32
- updatedAt
33
- `;
34
-
35
- const LIST_REPORTS_QUERY = `
36
- query MovethewheelsReports($filter: MovethewheelsReportFilterInput, $pagination: PaginationInput) {
37
- movethewheelsReports(filter: $filter, pagination: $pagination) {
38
- ${REPORT_FIELDS}
39
- }
40
- }
41
- `;
42
-
43
- const CREATE_REPORT_MUTATION = `
44
- mutation CreateMovethewheelsReport($input: CreateMovethewheelsReportInput!) {
45
- createMovethewheelsReport(input: $input) {
46
- ${REPORT_FIELDS}
47
- }
48
- }
49
- `;
50
-
51
- const GENERATE_REPORT_MUTATION = `
52
- mutation GenerateMovethewheelsReport($input: GenerateMovethewheelsReportInput!) {
53
- generateMovethewheelsReport(input: $input) {
54
- generatedAt
55
- result
56
- report {
57
- ${REPORT_FIELDS}
58
- }
59
- }
60
- }
61
- `;
62
-
63
22
  export interface CreateReportInput {
64
23
  name: string;
65
24
  type: string;
@@ -87,44 +46,60 @@ interface UseReportsResult {
87
46
  ) => Promise<GeneratedReport>;
88
47
  }
89
48
 
49
+ function newId(): string {
50
+ if (typeof crypto !== 'undefined' && 'randomUUID' in crypto) {
51
+ return crypto.randomUUID();
52
+ }
53
+ return `${Date.now()}-${Math.random().toString(36).slice(2)}`;
54
+ }
55
+
56
+ function storageKey(workspaceId: string | undefined): string {
57
+ return `movethewheels:reports:${workspaceId ?? 'default'}`;
58
+ }
59
+
60
+ function readReports(workspaceId: string | undefined): MovethewheelsReport[] {
61
+ if (typeof window === 'undefined') return [];
62
+ try {
63
+ const raw = window.localStorage.getItem(storageKey(workspaceId));
64
+ if (!raw) return [];
65
+ const parsed = JSON.parse(raw) as MovethewheelsReport[];
66
+ return Array.isArray(parsed) ? parsed : [];
67
+ } catch {
68
+ return [];
69
+ }
70
+ }
71
+
72
+ function writeReports(workspaceId: string | undefined, reports: MovethewheelsReport[]): void {
73
+ if (typeof window === 'undefined') return;
74
+ try {
75
+ window.localStorage.setItem(storageKey(workspaceId), JSON.stringify(reports));
76
+ } catch {
77
+ // Ignore storage errors.
78
+ }
79
+ }
80
+
90
81
  export function useReports(options: UseReportsOptions = {}): UseReportsResult {
91
82
  const { limit = 100, offset = 0 } = options;
92
- const { apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser } =
93
- useMoveTheWheels();
83
+ const { workspaceId } = useMoveTheWheels();
94
84
  const [reports, setReports] = useState<MovethewheelsReport[]>([]);
95
85
  const [hasMore, setHasMore] = useState(false);
96
86
  const [isLoading, setIsLoading] = useState(false);
97
87
  const [error, setError] = useState<Error | null>(null);
98
88
 
99
- const graphQLOptions = useMemo(
100
- () => ({
101
- apiGatewayUrl,
102
- authToken,
103
- workspaceToken,
104
- workspaceId,
105
- tenantId,
106
- actorId: currentUser?.id,
107
- }),
108
- [apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser?.id]
109
- );
110
-
111
- const load = useCallback(async () => {
89
+ const load = useCallback(() => {
112
90
  setIsLoading(true);
113
91
  setError(null);
114
92
  try {
115
- const data = await executeGraphQL<{ movethewheelsReports: MovethewheelsReport[] }>(
116
- graphQLOptions,
117
- LIST_REPORTS_QUERY,
118
- { pagination: { limit, offset } }
119
- );
120
- setHasMore(data.movethewheelsReports.length === limit);
121
- setReports(data.movethewheelsReports);
122
- } catch (fetchError) {
123
- setError(fetchError instanceof Error ? fetchError : new Error('Failed to load reports'));
93
+ const all = readReports(workspaceId);
94
+ const page = all.slice(offset, offset + limit);
95
+ setHasMore(page.length === limit);
96
+ setReports(page);
97
+ } catch (loadError) {
98
+ setError(loadError instanceof Error ? loadError : new Error('Failed to load reports'));
124
99
  } finally {
125
100
  setIsLoading(false);
126
101
  }
127
- }, [graphQLOptions, limit, offset]);
102
+ }, [workspaceId, limit, offset]);
128
103
 
129
104
  useEffect(() => {
130
105
  void load();
@@ -136,33 +111,44 @@ export function useReports(options: UseReportsOptions = {}): UseReportsResult {
136
111
 
137
112
  const createReport = useCallback(
138
113
  async (input: CreateReportInput): Promise<MovethewheelsReport> => {
139
- const data = await executeGraphQL<{ createMovethewheelsReport: MovethewheelsReport }>(
140
- graphQLOptions,
141
- CREATE_REPORT_MUTATION,
142
- { input }
143
- );
144
- const created = data.createMovethewheelsReport;
145
- setReports((previous) => [created, ...previous]);
114
+ const now = new Date().toISOString();
115
+ const created: MovethewheelsReport = {
116
+ id: newId(),
117
+ name: input.name,
118
+ description: input.description ?? null,
119
+ type: input.type,
120
+ status: input.status ?? 'ready',
121
+ schedule: input.schedule ?? null,
122
+ lastGenerated: null,
123
+ createdAt: now,
124
+ updatedAt: now,
125
+ };
126
+ setReports((previous) => {
127
+ const next = [created, ...previous];
128
+ writeReports(workspaceId, next);
129
+ return next;
130
+ });
146
131
  return created;
147
132
  },
148
- [graphQLOptions]
133
+ [workspaceId]
149
134
  );
150
135
 
151
136
  const generateReport = useCallback(
152
- async (reportId: string, parameters?: Record<string, unknown>): Promise<GeneratedReport> => {
153
- const data = await executeGraphQL<{ generateMovethewheelsReport: GeneratedReport }>(
154
- graphQLOptions,
155
- GENERATE_REPORT_MUTATION,
156
- { input: { reportId, parameters } }
157
- );
158
- const generated = data.generateMovethewheelsReport;
159
- setReports((previous) =>
160
- previous.map((item) => (item.id === reportId ? generated.report : item))
137
+ async (_reportId: string, _parameters?: Record<string, unknown>): Promise<GeneratedReport> => {
138
+ throw new Error(
139
+ 'Report generation is not available: the movethewheelsReports surface was withdrawn from the service.'
161
140
  );
162
- return generated;
163
141
  },
164
- [graphQLOptions]
142
+ []
165
143
  );
166
144
 
167
- return { reports, hasMore, isLoading, error, refetch, createReport, generateReport };
145
+ return {
146
+ reports,
147
+ hasMore,
148
+ isLoading,
149
+ error,
150
+ refetch,
151
+ createReport,
152
+ generateReport,
153
+ };
168
154
  }
@@ -1,6 +1,5 @@
1
1
  import { useCallback, useEffect, useMemo, useState } from 'react';
2
2
  import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
3
- import { executeGraphQL } from '../utils/graphqlClient';
4
3
 
5
4
  export type ModulePreferences = Record<string, unknown>;
6
5
 
@@ -10,26 +9,6 @@ export interface ModuleSettings {
10
9
  workspaceId: string;
11
10
  }
12
11
 
13
- const MODULE_SETTINGS_QUERY = `
14
- query MovethewheelsModuleSettings {
15
- moduleSettings {
16
- preferences
17
- updatedAt
18
- workspaceId
19
- }
20
- }
21
- `;
22
-
23
- const UPDATE_MODULE_SETTINGS_MUTATION = `
24
- mutation UpdateMovethewheelsModuleSettings($input: UpdateMovethewheelsModuleSettingsInput!) {
25
- updateModuleSettings(input: $input) {
26
- preferences
27
- updatedAt
28
- workspaceId
29
- }
30
- }
31
- `;
32
-
33
12
  interface UseModuleSettingsResult {
34
13
  settings: ModuleSettings | null;
35
14
  preferences: ModulePreferences;
@@ -40,41 +19,58 @@ interface UseModuleSettingsResult {
40
19
  savePreferences: (preferences: ModulePreferences) => Promise<ModuleSettings>;
41
20
  }
42
21
 
22
+ function readSettings(workspaceId: string): ModuleSettings | null {
23
+ if (typeof window === 'undefined') return null;
24
+ try {
25
+ const raw = window.localStorage.getItem(`movethewheels:moduleSettings:${workspaceId}`);
26
+ if (!raw) return null;
27
+ const parsed = JSON.parse(raw) as ModuleSettings;
28
+ if (parsed && typeof parsed === 'object' && 'preferences' in parsed) {
29
+ return parsed;
30
+ }
31
+ return null;
32
+ } catch {
33
+ return null;
34
+ }
35
+ }
36
+
37
+ function writeSettings(settings: ModuleSettings): void {
38
+ if (typeof window === 'undefined') return;
39
+ try {
40
+ window.localStorage.setItem(
41
+ `movethewheels:moduleSettings:${settings.workspaceId}`,
42
+ JSON.stringify(settings)
43
+ );
44
+ } catch {
45
+ // Ignore storage errors (e.g. private mode quota).
46
+ }
47
+ }
48
+
43
49
  export function useModuleSettings(): UseModuleSettingsResult {
44
- const { apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser } =
45
- useMoveTheWheels();
50
+ const { workspaceId } = useMoveTheWheels();
46
51
  const [settings, setSettings] = useState<ModuleSettings | null>(null);
47
52
  const [isLoading, setIsLoading] = useState(false);
48
53
  const [isSaving, setIsSaving] = useState(false);
49
54
  const [error, setError] = useState<Error | null>(null);
50
55
 
51
- const graphQLOptions = useMemo(
52
- () => ({
53
- apiGatewayUrl,
54
- authToken,
55
- workspaceToken,
56
- workspaceId,
57
- tenantId,
58
- actorId: currentUser?.id,
59
- }),
60
- [apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser?.id]
61
- );
62
-
63
- const load = useCallback(async () => {
56
+ const load = useCallback(() => {
64
57
  setIsLoading(true);
65
58
  setError(null);
66
59
  try {
67
- const data = await executeGraphQL<{ moduleSettings: ModuleSettings }>(
68
- graphQLOptions,
69
- MODULE_SETTINGS_QUERY
60
+ const stored = workspaceId ? readSettings(workspaceId) : null;
61
+ setSettings(
62
+ stored ?? {
63
+ preferences: {},
64
+ updatedAt: new Date().toISOString(),
65
+ workspaceId: workspaceId ?? '',
66
+ }
70
67
  );
71
- setSettings(data.moduleSettings);
72
- } catch (fetchError) {
73
- setError(fetchError instanceof Error ? fetchError : new Error('Failed to load settings'));
68
+ } catch (loadError) {
69
+ setError(loadError instanceof Error ? loadError : new Error('Failed to load settings'));
74
70
  } finally {
75
71
  setIsLoading(false);
76
72
  }
77
- }, [graphQLOptions]);
73
+ }, [workspaceId]);
78
74
 
79
75
  useEffect(() => {
80
76
  void load();
@@ -89,23 +85,24 @@ export function useModuleSettings(): UseModuleSettingsResult {
89
85
  setIsSaving(true);
90
86
  setError(null);
91
87
  try {
92
- const data = await executeGraphQL<{ updateModuleSettings: ModuleSettings }>(
93
- graphQLOptions,
94
- UPDATE_MODULE_SETTINGS_MUTATION,
95
- { input: { preferences } }
96
- );
97
- setSettings(data.updateModuleSettings);
98
- return data.updateModuleSettings;
99
- } catch (fetchError) {
88
+ const next: ModuleSettings = {
89
+ preferences,
90
+ updatedAt: new Date().toISOString(),
91
+ workspaceId: workspaceId ?? '',
92
+ };
93
+ writeSettings(next);
94
+ setSettings(next);
95
+ return next;
96
+ } catch (saveError) {
100
97
  const normalized =
101
- fetchError instanceof Error ? fetchError : new Error('Failed to save settings');
98
+ saveError instanceof Error ? saveError : new Error('Failed to save settings');
102
99
  setError(normalized);
103
100
  throw normalized;
104
101
  } finally {
105
102
  setIsSaving(false);
106
103
  }
107
104
  },
108
- [graphQLOptions]
105
+ [workspaceId]
109
106
  );
110
107
 
111
108
  // Stabilize the preferences reference. Returning `settings?.preferences ?? {}`