@nebulit/embuilder 0.1.44 → 0.1.45
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.
- package/package.json +1 -1
- package/templates/frontend/src/lib/api-client.ts +60 -98
- package/templates/frontend/src/lib/api.ts +28 -1028
- package/templates/frontend/src/pages/Register.tsx +3 -3
- package/templates/frontend/src/components/tables/ReservationTemplates.tsx +0 -189
- package/templates/frontend/src/pages/Menus.tsx +0 -224
package/package.json
CHANGED
|
@@ -4,133 +4,95 @@
|
|
|
4
4
|
const DEFAULT_API_URL = import.meta.env.VITE_BASE_URL ?? "http://localhost:3000";
|
|
5
5
|
|
|
6
6
|
export const getApiUrl = (): string => {
|
|
7
|
-
|
|
7
|
+
return DEFAULT_API_URL;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export const setApiUrl = (url: string): void => {
|
|
11
|
-
|
|
11
|
+
localStorage.setItem("api_base_url", url);
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export interface ApiContext {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
token: string;
|
|
16
|
+
tenantId?: string;
|
|
17
|
+
userId?: string;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
interface ApiRequestOptions {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
method?: "GET" | "POST" | "PUT" | "DELETE";
|
|
22
|
+
body?: unknown;
|
|
23
|
+
headers?: Record<string, string>;
|
|
24
|
+
correlationId?: string;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
interface ApiResponse<T> {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
data?: T;
|
|
29
|
+
error?: string;
|
|
30
|
+
ok: boolean;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export async function apiRequest<T>(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
endpoint: string,
|
|
35
|
+
ctx: ApiContext,
|
|
36
|
+
options: ApiRequestOptions = {}
|
|
37
37
|
): Promise<ApiResponse<T>> {
|
|
38
|
-
|
|
38
|
+
const {method = "GET", body, headers = {}, correlationId} = options;
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
const baseUrl = getApiUrl();
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (ctx.token) {
|
|
48
|
-
requestHeaders["Authorization"] = `Bearer ${ctx.token}`;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (ctx.tenantId) {
|
|
52
|
-
requestHeaders["x-tenant-id"] = ctx.tenantId;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (ctx.userId) {
|
|
56
|
-
requestHeaders["x-user-id"] = ctx.userId;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (correlationId) {
|
|
60
|
-
requestHeaders["correlation_id"] = correlationId;
|
|
61
|
-
}
|
|
42
|
+
const requestHeaders: Record<string, string> = {
|
|
43
|
+
"Content-Type": "application/json",
|
|
44
|
+
...headers,
|
|
45
|
+
};
|
|
62
46
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
headers: requestHeaders,
|
|
67
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
68
|
-
});
|
|
47
|
+
if (ctx.token) {
|
|
48
|
+
requestHeaders["Authorization"] = `Bearer ${ctx.token}`;
|
|
49
|
+
}
|
|
69
50
|
|
|
70
|
-
const data = await response.json();
|
|
71
51
|
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
52
|
+
if (ctx.userId) {
|
|
53
|
+
requestHeaders["x-user-id"] = ctx.userId;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* if (ctx.tenantId) {
|
|
57
|
+
* requestHeaders["x-tenant-id"] = ctx.tenantId;
|
|
58
|
+
* }
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
if (correlationId) {
|
|
62
|
+
requestHeaders["correlation_id"] = correlationId;
|
|
77
63
|
}
|
|
78
64
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
65
|
+
try {
|
|
66
|
+
const response = await fetch(`${baseUrl}${endpoint}`, {
|
|
67
|
+
method,
|
|
68
|
+
headers: requestHeaders,
|
|
69
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const data = await response.json();
|
|
73
|
+
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
return {
|
|
76
|
+
ok: false,
|
|
77
|
+
error: data.error || `HTTP ${response.status}: ${response.statusText}`,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return {ok: true, data};
|
|
82
|
+
} catch (error) {
|
|
83
|
+
return {
|
|
84
|
+
ok: false,
|
|
85
|
+
error: error instanceof Error ? error.message : "Network error",
|
|
86
|
+
};
|
|
87
|
+
}
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
// Query endpoints (GET)
|
|
89
91
|
export const queryEndpoints = {
|
|
90
|
-
|
|
91
|
-
shifts: "/api/query/shifts-collection",
|
|
92
|
-
clerks: "/api/query/clerks-collection",
|
|
93
|
-
clerksToInvite: "/api/query/clerkstoinvite-collection",
|
|
94
|
-
tasks: "/api/query/tasks-collection",
|
|
95
|
-
menus: "/api/query/uploadedmenus-collection",
|
|
96
|
-
serviceDays: "/api/query/servicedays-collection",
|
|
97
|
-
timeslots: "/api/query/configuredtimeslots-collection",
|
|
98
|
-
vacations: "/api/query/plannedvacations-collection",
|
|
99
|
-
shiftAssignments: "/api/query/shiftassignments-collection",
|
|
100
|
-
shiftsForAssignments: "/api/query/shiftsforassignments-collection",
|
|
101
|
-
images: "/api/query/uploadedimages-collection",
|
|
92
|
+
//tables: "/api/query/tables-collection",
|
|
102
93
|
};
|
|
103
94
|
|
|
104
95
|
// Command endpoints (POST)
|
|
105
96
|
export const commandEndpoints = {
|
|
106
|
-
|
|
107
|
-
addTable: "/api/addtable",
|
|
108
|
-
updateTable: "/api/updatetable",
|
|
109
|
-
removeTable: "/api/removetable",
|
|
110
|
-
blockTableReservation: "/api/blocktablereservation",
|
|
111
|
-
unblockTableReservation: "/api/unblocktablereservation",
|
|
112
|
-
createShift: "/api/createshift",
|
|
113
|
-
activateShift: "/api/activateshift",
|
|
114
|
-
deleteShift: "/api/deleteshift",
|
|
115
|
-
assignShift: "/api/assignshift",
|
|
116
|
-
unassignShift: "/api/unassignshift",
|
|
117
|
-
registerClerk: "/api/registerclerk",
|
|
118
|
-
deactivateClerk: "/api/deactivateclerk",
|
|
119
|
-
removeClerk: "/api/removeclerk",
|
|
120
|
-
confirmInvitation: "/api/confirminvitation",
|
|
121
|
-
|
|
122
|
-
updateTask: "/api/updatetask",
|
|
123
|
-
deleteTask: "/api/deletetask",
|
|
124
|
-
uploadMenu: "/api/uploadmenu",
|
|
125
|
-
deleteMenu: "/api/deletemenu",
|
|
126
|
-
uploadImage: "/api/uploadimage",
|
|
127
|
-
cancelReservation: "/api/cancelreservation",
|
|
128
|
-
addServiceDay: "/api/addserviceday",
|
|
129
|
-
configureTimeslot: "/api/configuretimeslot",
|
|
130
|
-
planVacation: "/api/planvacation",
|
|
131
|
-
cancelVacation: "/api/cancelvacation",
|
|
132
|
-
activateOnlineReservation: "/api/activateonlinereservation",
|
|
133
|
-
deactivateOnlineReservation: "/api/deactivateonlinereservation",
|
|
134
|
-
registerNoShow: "/api/registernoshow",
|
|
135
|
-
registerShowUp: "/api/registershowup",
|
|
97
|
+
//addTable: "/api/addtable",
|
|
136
98
|
};
|