@flowselections/floriday-voorraad 1.0.12 → 1.0.14

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 (123) hide show
  1. package/dist-lib/assets/floriday-logo.png.asset.json +11 -0
  2. package/dist-lib/components/voorraad/ArtikelWizard.d.ts +5 -0
  3. package/dist-lib/components/voorraad/ArtikelWizard.d.ts.map +1 -0
  4. package/dist-lib/components/voorraad/ArtikelWizard.js +1229 -0
  5. package/dist-lib/components/voorraad/ConnectionBadge.d.ts +6 -0
  6. package/dist-lib/components/voorraad/ConnectionBadge.d.ts.map +1 -0
  7. package/dist-lib/components/voorraad/ConnectionBadge.js +12 -0
  8. package/dist-lib/components/voorraad/EditArtikelPage.d.ts +4 -0
  9. package/dist-lib/components/voorraad/EditArtikelPage.d.ts.map +1 -0
  10. package/dist-lib/components/voorraad/EditArtikelPage.js +51 -0
  11. package/dist-lib/components/voorraad/NieuwArtikelPage.d.ts +2 -0
  12. package/dist-lib/components/voorraad/NieuwArtikelPage.d.ts.map +1 -0
  13. package/dist-lib/components/voorraad/NieuwArtikelPage.js +5 -0
  14. package/dist-lib/components/voorraad/StockBulkButtons.d.ts +7 -0
  15. package/dist-lib/components/voorraad/StockBulkButtons.d.ts.map +1 -0
  16. package/dist-lib/components/voorraad/StockBulkButtons.js +356 -0
  17. package/dist-lib/components/voorraad/ValidationOverviewTable.d.ts +7 -0
  18. package/dist-lib/components/voorraad/ValidationOverviewTable.d.ts.map +1 -0
  19. package/dist-lib/components/voorraad/ValidationOverviewTable.js +87 -0
  20. package/dist-lib/components/voorraad/ValidationPage.d.ts +2 -0
  21. package/dist-lib/components/voorraad/ValidationPage.d.ts.map +1 -0
  22. package/dist-lib/components/voorraad/ValidationPage.js +12 -0
  23. package/dist-lib/components/voorraad/VoorraadDashboard.d.ts +6 -0
  24. package/dist-lib/components/voorraad/VoorraadDashboard.d.ts.map +1 -0
  25. package/dist-lib/components/voorraad/VoorraadDashboard.js +42 -0
  26. package/dist-lib/components/voorraad/VoorraadPage.d.ts.map +1 -1
  27. package/dist-lib/components/voorraad/VoorraadPage.js +78 -11
  28. package/dist-lib/components/voorraad/VoorraadPagination.d.ts +10 -0
  29. package/dist-lib/components/voorraad/VoorraadPagination.d.ts.map +1 -0
  30. package/dist-lib/components/voorraad/VoorraadPagination.js +12 -0
  31. package/dist-lib/components/voorraad/VoorraadStockCard.d.ts +8 -0
  32. package/dist-lib/components/voorraad/VoorraadStockCard.d.ts.map +1 -0
  33. package/dist-lib/components/voorraad/VoorraadStockCard.js +33 -0
  34. package/dist-lib/components/voorraad/VoorraadTable.d.ts.map +1 -1
  35. package/dist-lib/components/voorraad/VoorraadTable.js +21 -2
  36. package/dist-lib/hooks/useFloriday.d.ts +55 -0
  37. package/dist-lib/hooks/useFloriday.d.ts.map +1 -0
  38. package/dist-lib/hooks/useFloriday.js +298 -0
  39. package/dist-lib/hooks/useFloridayConnection.d.ts +9 -4
  40. package/dist-lib/hooks/useFloridayConnection.d.ts.map +1 -1
  41. package/dist-lib/hooks/useFloridayConnection.js +23 -23
  42. package/dist-lib/hooks/useFlorydayCustomers.d.ts +17 -0
  43. package/dist-lib/hooks/useFlorydayCustomers.d.ts.map +1 -0
  44. package/dist-lib/hooks/useFlorydayCustomers.js +65 -0
  45. package/dist-lib/hooks/useLocalTradeItems.d.ts +38 -0
  46. package/dist-lib/hooks/useLocalTradeItems.d.ts.map +1 -0
  47. package/dist-lib/hooks/useLocalTradeItems.js +144 -0
  48. package/dist-lib/hooks/useTradeItemSpec.d.ts +42 -0
  49. package/dist-lib/hooks/useTradeItemSpec.d.ts.map +1 -0
  50. package/dist-lib/hooks/useTradeItemSpec.js +448 -0
  51. package/dist-lib/hooks/useTradeItemStock.d.ts +19 -0
  52. package/dist-lib/hooks/useTradeItemStock.d.ts.map +1 -0
  53. package/dist-lib/hooks/useTradeItemStock.js +78 -0
  54. package/dist-lib/hooks/useVbnRegulatoryFeatures.d.ts +3 -0
  55. package/dist-lib/hooks/useVbnRegulatoryFeatures.d.ts.map +1 -0
  56. package/dist-lib/hooks/useVbnRegulatoryFeatures.js +19 -0
  57. package/dist-lib/hooks/useVoorraadData.d.ts +6 -0
  58. package/dist-lib/hooks/useVoorraadData.d.ts.map +1 -1
  59. package/dist-lib/hooks/useVoorraadData.js +65 -10
  60. package/dist-lib/index.d.ts +4 -0
  61. package/dist-lib/index.d.ts.map +1 -1
  62. package/dist-lib/index.js +6 -5
  63. package/dist-lib/integrations/supabase/auth-middleware.d.ts +9085 -1645
  64. package/dist-lib/integrations/supabase/auth-middleware.d.ts.map +1 -1
  65. package/dist-lib/integrations/supabase/client.d.ts +9085 -1645
  66. package/dist-lib/integrations/supabase/client.d.ts.map +1 -1
  67. package/dist-lib/integrations/supabase/client.server.d.ts +9085 -1645
  68. package/dist-lib/integrations/supabase/client.server.d.ts.map +1 -1
  69. package/dist-lib/integrations/supabase/types.d.ts +9298 -1655
  70. package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
  71. package/dist-lib/integrations/supabase/types.js +20 -1
  72. package/dist-lib/lib/__tests__/floricode-required-features.test.d.ts +2 -0
  73. package/dist-lib/lib/__tests__/floricode-required-features.test.d.ts.map +1 -0
  74. package/dist-lib/lib/__tests__/floricode-required-features.test.js +186 -0
  75. package/dist-lib/lib/floricode-client.d.ts +15 -1
  76. package/dist-lib/lib/floricode-client.d.ts.map +1 -1
  77. package/dist-lib/lib/floricode-client.js +42 -4
  78. package/dist-lib/lib/floricode-required-features.functions.d.ts +10026 -0
  79. package/dist-lib/lib/floricode-required-features.functions.d.ts.map +1 -0
  80. package/dist-lib/lib/floricode-required-features.functions.js +170 -0
  81. package/dist-lib/lib/floriday-client.d.ts +45 -19
  82. package/dist-lib/lib/floriday-client.d.ts.map +1 -1
  83. package/dist-lib/lib/floriday-client.js +236 -38
  84. package/dist-lib/lib/floriday-env.d.ts +29 -0
  85. package/dist-lib/lib/floriday-env.d.ts.map +1 -0
  86. package/dist-lib/lib/floriday-env.js +42 -0
  87. package/dist-lib/lib/floriday-env.server.d.ts +15 -0
  88. package/dist-lib/lib/floriday-env.server.d.ts.map +1 -0
  89. package/dist-lib/lib/floriday-env.server.js +13 -0
  90. package/dist-lib/lib/floriday-field-sources.d.ts +18 -0
  91. package/dist-lib/lib/floriday-field-sources.d.ts.map +1 -0
  92. package/dist-lib/lib/floriday-field-sources.js +45 -0
  93. package/dist-lib/lib/floriday-gateway-entities.d.ts +44 -0
  94. package/dist-lib/lib/floriday-gateway-entities.d.ts.map +1 -0
  95. package/dist-lib/lib/floriday-gateway-entities.js +51 -0
  96. package/dist-lib/lib/floriday-gateway.functions.d.ts +39999 -0
  97. package/dist-lib/lib/floriday-gateway.functions.d.ts.map +1 -0
  98. package/dist-lib/lib/floriday-gateway.functions.js +68 -0
  99. package/dist-lib/lib/floriday-gateway.server.d.ts +122 -0
  100. package/dist-lib/lib/floriday-gateway.server.d.ts.map +1 -0
  101. package/dist-lib/lib/floriday-gateway.server.js +230 -0
  102. package/dist-lib/lib/floriday-import-validator.d.ts +26 -0
  103. package/dist-lib/lib/floriday-import-validator.d.ts.map +1 -0
  104. package/dist-lib/lib/floriday-import-validator.js +41 -0
  105. package/dist-lib/lib/floriday-payload.d.ts +47 -3
  106. package/dist-lib/lib/floriday-payload.d.ts.map +1 -1
  107. package/dist-lib/lib/floriday-payload.js +179 -7
  108. package/dist-lib/lib/floriday-schema-to-zod.d.ts +9 -0
  109. package/dist-lib/lib/floriday-schema-to-zod.d.ts.map +1 -0
  110. package/dist-lib/lib/floriday-schema-to-zod.js +53 -0
  111. package/dist-lib/lib/floriday-writes.functions.d.ts +19998 -0
  112. package/dist-lib/lib/floriday-writes.functions.d.ts.map +1 -0
  113. package/dist-lib/lib/floriday-writes.functions.js +74 -0
  114. package/dist-lib/lib/image-resize.d.ts +43 -0
  115. package/dist-lib/lib/image-resize.d.ts.map +1 -0
  116. package/dist-lib/lib/image-resize.js +212 -0
  117. package/dist-lib/lib/normalize-errors-middleware.d.ts +2 -0
  118. package/dist-lib/lib/normalize-errors-middleware.d.ts.map +1 -0
  119. package/dist-lib/lib/normalize-errors-middleware.js +24 -0
  120. package/dist-lib/lib/wizard-step-fields.d.ts +15 -0
  121. package/dist-lib/lib/wizard-step-fields.d.ts.map +1 -0
  122. package/dist-lib/lib/wizard-step-fields.js +51 -0
  123. package/package.json +29 -14
@@ -1,43 +1,241 @@
1
1
  import { supabase } from "../integrations/supabase/client";
2
- async function call(body) {
3
- const { data, error } = await supabase.functions.invoke("floriday-api", { body });
4
- if (error)
5
- throw new Error(error.message);
6
- if (data && typeof data === "object" && "error" in data && data.error) {
7
- throw new Error(String(data.error));
2
+ import { publishTradeItem, updateTradeItemFn } from "./floriday-writes.functions";
3
+ function summarizePayload(payload) {
4
+ if (!payload || typeof payload !== "object")
5
+ return {};
6
+ return {
7
+ name: payload?.name ?? payload?.tradeItemName ?? null,
8
+ vbnCode: payload?.vbnProductCode ?? payload?.vbnCode ?? null,
9
+ botanicalName: payload?.characteristics?.botanicalName ?? null,
10
+ };
11
+ }
12
+ async function logPublishAttempt(params) {
13
+ try {
14
+ const userRes = await supabase.auth.getUser();
15
+ const userId = userRes.data.user?.id;
16
+ if (!userId)
17
+ return;
18
+ await supabase.from("voorraad_publish_attempts").insert({
19
+ user_id: userId,
20
+ connection_id: params.connectionId,
21
+ trade_item_id: params.tradeItemId,
22
+ action: "upsert-trade-item",
23
+ intent: params.intent,
24
+ ok: params.ok,
25
+ gateway_status: params.gatewayStatus,
26
+ gateway_attempt_id: params.gatewayAttemptId,
27
+ error: params.error,
28
+ request_summary: params.summary,
29
+ });
30
+ }
31
+ catch {
32
+ // Audit-log mag de hoofd-flow nooit breken.
8
33
  }
9
- return data;
10
34
  }
35
+ function pickLocalized(value) {
36
+ if (!value)
37
+ return "";
38
+ if (typeof value === "string")
39
+ return value;
40
+ if (typeof value === "object") {
41
+ const obj = value;
42
+ const v = obj.nl ?? obj.en ?? obj.de ?? Object.values(obj)[0];
43
+ return typeof v === "string" ? v : "";
44
+ }
45
+ return String(value);
46
+ }
47
+ export function normaliseTradeItem(raw) {
48
+ const photo = raw.photos?.find((p) => p.primary)?.url ??
49
+ raw.photos?.[0]?.url ??
50
+ raw.images?.[0]?.url ??
51
+ raw.imageUrls?.[0] ??
52
+ null;
53
+ return {
54
+ id: raw.id ?? raw.tradeItemId ?? String(raw.sequenceNumber ?? ""),
55
+ name: pickLocalized(raw.name ?? raw.tradeItemName),
56
+ articleNumber: raw.supplierArticleCode ?? raw.articleCode ?? raw.gtin ?? "",
57
+ imageUrl: photo,
58
+ quantity: raw.physicalStock ?? raw.stock?.physical ?? 0,
59
+ minQuantity: raw.minimumStock ?? raw.stock?.minimum ?? 0,
60
+ reservedQuantity: raw.reservedStock ?? raw.stock?.reserved ?? 0,
61
+ availableQuantity: raw.availableStock ?? raw.stock?.available ?? 0,
62
+ incomingQuantity: raw.incomingStock ?? raw.stock?.incoming ?? 0,
63
+ economicQuantity: raw.economicStock ?? raw.stock?.economic ?? 0,
64
+ raw,
65
+ };
66
+ }
67
+ /**
68
+ * Public surface used by the wizard. All writes go through the HMAC-signed
69
+ * Floriday gateway hosted by the Authentication module. Reads of cached
70
+ * sequence resources (e.g. classifications) go through the same gateway,
71
+ * which is backed by the shared Supabase cache.
72
+ */
11
73
  export const floriday = {
12
- listConnections: () => call({ action: "listConnections" }).then((r) => r.connections),
13
- listTradeItems: (connectionId, limit = 200, offset = 0) => call({
14
- action: "listTradeItems",
15
- connectionId,
16
- limit,
17
- offset,
18
- }).then((r) => r.items ?? []),
19
- listClassifications: (connectionId) => call({
20
- action: "listClassifications",
21
- connectionId,
22
- }),
23
- listCustomerOrganizations: (connectionId) => call({
24
- action: "listCustomerOrganizations",
25
- connectionId,
26
- }),
27
- listAdditionalServices: (connectionId) => call({
28
- action: "listAdditionalServices",
29
- connectionId,
30
- }),
31
- createTradeItem: (connectionId, payload) => call({
32
- action: "createTradeItem",
33
- connectionId,
34
- payload,
35
- }),
36
- uploadImage: (connectionId, fileBase64, contentType, filename) => call({
37
- action: "uploadImage",
38
- connectionId,
39
- fileBase64,
40
- contentType,
41
- filename,
42
- }),
74
+ // Note: listClassifications is verwijderd Floriday Suppliers 2026v1 kent
75
+ // geen trade-item-classifications resource meer. Karakteristieken komen nu
76
+ // uit `gatewaySchemaFn({ resource: "trade-item" })` + `gatewayCodeListFn`.
77
+ createTradeItem: async (connectionId, payload) => {
78
+ const tradeItemId = payload?.tradeItemId ?? crypto?.randomUUID?.() ?? `${Date.now()}`;
79
+ const formVersion = payload?.formVersion ?? "v1";
80
+ try {
81
+ const res = (await publishTradeItem({
82
+ data: { tradeItemId, values: payload, formVersion },
83
+ }));
84
+ await logPublishAttempt({
85
+ connectionId,
86
+ tradeItemId,
87
+ intent: "create",
88
+ ok: true,
89
+ gatewayStatus: res?.status ?? null,
90
+ gatewayAttemptId: res?.attemptId ?? null,
91
+ error: null,
92
+ summary: summarizePayload(payload),
93
+ });
94
+ return {
95
+ ok: true,
96
+ data: res?.data ?? null,
97
+ attemptId: res?.attemptId ?? null,
98
+ tradeItemId,
99
+ };
100
+ }
101
+ catch (e) {
102
+ await logPublishAttempt({
103
+ connectionId,
104
+ tradeItemId,
105
+ intent: "create",
106
+ ok: false,
107
+ gatewayStatus: null,
108
+ gatewayAttemptId: null,
109
+ error: e?.message ?? String(e),
110
+ summary: summarizePayload(payload),
111
+ });
112
+ throw e;
113
+ }
114
+ },
115
+ updateTradeItem: async (connectionId, tradeItemId, payload) => {
116
+ const formVersion = payload?.formVersion ?? "v1";
117
+ try {
118
+ const res = (await updateTradeItemFn({
119
+ data: { tradeItemId, values: payload, formVersion },
120
+ }));
121
+ await logPublishAttempt({
122
+ connectionId,
123
+ tradeItemId,
124
+ intent: "update",
125
+ ok: true,
126
+ gatewayStatus: res?.status ?? null,
127
+ gatewayAttemptId: res?.attemptId ?? null,
128
+ error: null,
129
+ summary: summarizePayload(payload),
130
+ });
131
+ return {
132
+ ok: true,
133
+ data: res?.data ?? null,
134
+ attemptId: res?.attemptId ?? null,
135
+ tradeItemId,
136
+ };
137
+ }
138
+ catch (e) {
139
+ await logPublishAttempt({
140
+ connectionId,
141
+ tradeItemId,
142
+ intent: "update",
143
+ ok: false,
144
+ gatewayStatus: null,
145
+ gatewayAttemptId: null,
146
+ error: e?.message ?? String(e),
147
+ summary: summarizePayload(payload),
148
+ });
149
+ throw e;
150
+ }
151
+ },
152
+ /**
153
+ * Upload een foto naar Floriday via de interne server-route
154
+ * `/api/trade-item-photo`. We sturen het bestand als multipart/form-data
155
+ * en plakken de Supabase-bearer expliciet op de fetch zodat de
156
+ * `Authorization`-header gegarandeerd meegaat (in tegenstelling tot de
157
+ * server-fn route, die bij grote base64-JSON payloads soms geen header
158
+ * meestuurt en resulteert in 401).
159
+ */
160
+ uploadImage: async (connectionId, file, _contentType, filename) => {
161
+ const { data: sessionData } = await supabase.auth.getSession();
162
+ const token = sessionData.session?.access_token;
163
+ if (!token) {
164
+ throw new Error("Geen actieve sessie — log opnieuw in.");
165
+ }
166
+ const form = new FormData();
167
+ form.append("connectionId", connectionId);
168
+ // Geef het bestand een naam mee — anders krijgt server "blob".
169
+ const fname = filename ?? file.name ?? `photo-${Date.now()}.jpg`;
170
+ form.append("file", file, fname);
171
+ // Stille retry: 2× extra pogingen met exponentiële backoff bij 5xx /
172
+ // netwerkfouten. Bij client-side fouten (te klein, verkeerd type) tonen
173
+ // we de server-message meteen aan de gebruiker — geen retry.
174
+ const GENERIC = "Foto kon niet worden geüpload. Probeer het later opnieuw.";
175
+ const backoffs = [0, 300, 900];
176
+ let lastErr = null;
177
+ for (let attempt = 0; attempt < backoffs.length; attempt++) {
178
+ if (backoffs[attempt] > 0) {
179
+ await new Promise((r) => setTimeout(r, backoffs[attempt]));
180
+ }
181
+ try {
182
+ const res = await fetch("/api/trade-item-photo", {
183
+ method: "POST",
184
+ headers: { Authorization: `Bearer ${token}` },
185
+ body: form,
186
+ });
187
+ const ct = res.headers.get("content-type") ?? "";
188
+ const text = await res.text();
189
+ let parsed = null;
190
+ if (ct.toLowerCase().includes("application/json") && text) {
191
+ try {
192
+ parsed = JSON.parse(text);
193
+ }
194
+ catch {
195
+ /* ignore */
196
+ }
197
+ }
198
+ if (!res.ok) {
199
+ const base = parsed?.message || parsed?.error || GENERIC;
200
+ const withDetail = parsed?.detail ? `${base} (${parsed.detail})` : base;
201
+ const withStatus = parsed?.gatewayStatus
202
+ ? `${withDetail} [status ${parsed.gatewayStatus}]`
203
+ : withDetail;
204
+ lastErr = new Error(withStatus);
205
+ if (res.status >= 500 && attempt < backoffs.length - 1)
206
+ continue;
207
+ throw lastErr;
208
+ }
209
+ if (parsed?.ok === false) {
210
+ const base = parsed.message || GENERIC;
211
+ const withDetail = parsed.detail ? `${base} (${parsed.detail})` : base;
212
+ const withStatus = parsed.gatewayStatus
213
+ ? `${withDetail} [status ${parsed.gatewayStatus}]`
214
+ : withDetail;
215
+ lastErr = new Error(withStatus);
216
+ if (parsed.retryable && attempt < backoffs.length - 1)
217
+ continue;
218
+ throw lastErr;
219
+ }
220
+ if (!parsed?.url) {
221
+ lastErr = new Error(GENERIC);
222
+ if (attempt < backoffs.length - 1)
223
+ continue;
224
+ throw lastErr;
225
+ }
226
+ return {
227
+ ok: true,
228
+ imageId: (parsed.imageId ?? parsed.mediaId ?? null),
229
+ mediaId: parsed.mediaId ?? parsed.imageId ?? null,
230
+ url: parsed.url,
231
+ };
232
+ }
233
+ catch (e) {
234
+ lastErr = e instanceof Error ? e : new Error(String(e));
235
+ if (attempt >= backoffs.length - 1)
236
+ break;
237
+ }
238
+ }
239
+ throw lastErr instanceof Error ? lastErr : new Error(GENERIC);
240
+ },
43
241
  };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Client-safe environment helpers voor Floriday.
3
+ *
4
+ * De Auth-gateway accepteert uitsluitend exact "staging" of "live" in de
5
+ * request-body. Eén bron van waarheid: de actieve Floriday-connectie
6
+ * (`floriday_settings.active_environment` of `floriday_connections.environment`).
7
+ *
8
+ * `normalizeFloridayEnvironment` is pure en mag overal worden geïmporteerd.
9
+ * De async resolver die de Supabase-RPC raakt staat in `floriday-env.server.ts`.
10
+ */
11
+ export type FloridayEnvironment = "staging" | "live";
12
+ export type FloridayEnvErrorCode = "NO_ACTIVE_FLORIDAY_CONNECTION" | "INVALID_FLORIDAY_ENVIRONMENT";
13
+ export declare class FloridayEnvError extends Error {
14
+ code: FloridayEnvErrorCode;
15
+ constructor(code: FloridayEnvErrorCode, message: string);
16
+ }
17
+ /**
18
+ * Mapt een ruwe environment-string uit de DB naar exact "staging" of "live".
19
+ * Werpt `FloridayEnvError("INVALID_FLORIDAY_ENVIRONMENT")` bij alles wat niet
20
+ * te mappen valt — geen stille defaults.
21
+ */
22
+ export declare function normalizeFloridayEnvironment(raw: string | null | undefined): FloridayEnvironment;
23
+ /**
24
+ * Detecteer een FloridayEnvError aan de hand van de message-prefix.
25
+ * Bruikbaar in UI-code waar alleen de Error-message beschikbaar is
26
+ * (server-fn errors worden door TanStack platgeslagen naar `new Error(message)`).
27
+ */
28
+ export declare function getFloridayEnvErrorCode(err: unknown): FloridayEnvErrorCode | null;
29
+ //# sourceMappingURL=floriday-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"floriday-env.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,MAAM,CAAC;AAErD,MAAM,MAAM,oBAAoB,GAC5B,+BAA+B,GAC/B,8BAA8B,CAAC;AAEnC,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,IAAI,EAAE,oBAAoB,CAAC;gBACf,IAAI,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM;CAOxD;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC7B,mBAAmB,CAQrB;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,OAAO,GACX,oBAAoB,GAAG,IAAI,CAI7B"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Client-safe environment helpers voor Floriday.
3
+ *
4
+ * De Auth-gateway accepteert uitsluitend exact "staging" of "live" in de
5
+ * request-body. Eén bron van waarheid: de actieve Floriday-connectie
6
+ * (`floriday_settings.active_environment` of `floriday_connections.environment`).
7
+ *
8
+ * `normalizeFloridayEnvironment` is pure en mag overal worden geïmporteerd.
9
+ * De async resolver die de Supabase-RPC raakt staat in `floriday-env.server.ts`.
10
+ */
11
+ export class FloridayEnvError extends Error {
12
+ constructor(code, message) {
13
+ // Prefix met code zodat normalize-errors-middleware / safe() de code
14
+ // intact doorgeeft naar de UI (geen gestructureerde RPC-errors nodig).
15
+ super(`[${code}] ${message}`);
16
+ this.code = code;
17
+ this.name = "FloridayEnvError";
18
+ }
19
+ }
20
+ /**
21
+ * Mapt een ruwe environment-string uit de DB naar exact "staging" of "live".
22
+ * Werpt `FloridayEnvError("INVALID_FLORIDAY_ENVIRONMENT")` bij alles wat niet
23
+ * te mappen valt — geen stille defaults.
24
+ */
25
+ export function normalizeFloridayEnvironment(raw) {
26
+ const v = (raw ?? "").trim().toLowerCase();
27
+ if (v === "staging" || v === "stg")
28
+ return "staging";
29
+ if (v === "live" || v === "production" || v === "prod")
30
+ return "live";
31
+ throw new FloridayEnvError("INVALID_FLORIDAY_ENVIRONMENT", `Ongeldige Floriday-environment: "${raw ?? ""}". Verwacht "staging" of "live".`);
32
+ }
33
+ /**
34
+ * Detecteer een FloridayEnvError aan de hand van de message-prefix.
35
+ * Bruikbaar in UI-code waar alleen de Error-message beschikbaar is
36
+ * (server-fn errors worden door TanStack platgeslagen naar `new Error(message)`).
37
+ */
38
+ export function getFloridayEnvErrorCode(err) {
39
+ const msg = err instanceof Error ? err.message : String(err ?? "");
40
+ const m = msg.match(/\[(NO_ACTIVE_FLORIDAY_CONNECTION|INVALID_FLORIDAY_ENVIRONMENT)\]/);
41
+ return m?.[1] ?? null;
42
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Server-only resolver voor de actieve Floriday-environment.
3
+ *
4
+ * Single source of truth: dezelfde RPC die `useFloridayConnection` client-side
5
+ * gebruikt (`get_active_floriday_connection_public`). Dit voorkomt dat
6
+ * cached-list/write/media-upload elk een eigen environment-bron kiezen.
7
+ *
8
+ * NOOIT importeren vanuit componenten — filename eindigt op `.server.ts`
9
+ * en wordt geblokkeerd door de client-bundler.
10
+ */
11
+ import type { SupabaseClient } from "@supabase/supabase-js";
12
+ import { type FloridayEnvironment } from "./floriday-env";
13
+ export { FloridayEnvError, normalizeFloridayEnvironment, type FloridayEnvironment, } from "./floriday-env";
14
+ export declare function resolveFloridayEnvironment(supabase: SupabaseClient<any, any, any>): Promise<FloridayEnvironment>;
15
+ //# sourceMappingURL=floriday-env.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"floriday-env.server.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-env.server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,KAAK,mBAAmB,GACzB,MAAM,gBAAgB,CAAC;AAExB,wBAAsB,0BAA0B,CAC9C,QAAQ,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GACtC,OAAO,CAAC,mBAAmB,CAAC,CAmB9B"}
@@ -0,0 +1,13 @@
1
+ import { FloridayEnvError, normalizeFloridayEnvironment, } from "./floriday-env";
2
+ export { FloridayEnvError, normalizeFloridayEnvironment, } from "./floriday-env";
3
+ export async function resolveFloridayEnvironment(supabase) {
4
+ const { data, error } = await supabase.rpc("get_active_floriday_connection_public");
5
+ if (error) {
6
+ throw new FloridayEnvError("NO_ACTIVE_FLORIDAY_CONNECTION", `Kon actieve Floriday-connectie niet ophalen: ${error.message}`);
7
+ }
8
+ const row = (Array.isArray(data) ? data[0] : data);
9
+ if (!row || !row.id) {
10
+ throw new FloridayEnvError("NO_ACTIVE_FLORIDAY_CONNECTION", "Geen actieve Floriday-connectie gevonden. Ga naar Instellingen → Floriday.");
11
+ }
12
+ return normalizeFloridayEnvironment(row.active_environment);
13
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Mapping van Floriday-veldnamen naar hun waarde-bron.
3
+ *
4
+ * - CODE_LIST_BY_FIELD: veld met vaste enum-waardes uit /gateway/code-list.
5
+ * - REF_ENTITY_BY_FIELD: veld dat verwijst naar een rij in een stamdata-cache,
6
+ * te lezen via /gateway/cached-list. Waarden zijn kebab-case Floriday-
7
+ * resources (GatewayEntity) — NIET de Supabase-tabelnaam.
8
+ * - REF_TABLE_BY_FIELD: identieke mapping naar de Supabase-cache-tabelnaam,
9
+ * uitsluitend voor directe `supabase.from(...)` reads in deze module.
10
+ */
11
+ import { type GatewayEntity } from "./floriday-gateway-entities";
12
+ export declare const CODE_LIST_BY_FIELD: Record<string, string>;
13
+ export declare const REF_ENTITY_BY_FIELD: Record<string, GatewayEntity>;
14
+ export declare const REF_TABLE_BY_FIELD: Record<string, string>;
15
+ export declare function codeListFor(field: string): string | undefined;
16
+ export declare function refEntityFor(field: string): GatewayEntity | undefined;
17
+ export declare function refTableFor(field: string): string | undefined;
18
+ //# sourceMappingURL=floriday-field-sources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"floriday-field-sources.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-field-sources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAoB,KAAK,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEnF,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAUrD,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAM7D,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAMrD,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE7D;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAErE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE7D"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Mapping van Floriday-veldnamen naar hun waarde-bron.
3
+ *
4
+ * - CODE_LIST_BY_FIELD: veld met vaste enum-waardes uit /gateway/code-list.
5
+ * - REF_ENTITY_BY_FIELD: veld dat verwijst naar een rij in een stamdata-cache,
6
+ * te lezen via /gateway/cached-list. Waarden zijn kebab-case Floriday-
7
+ * resources (GatewayEntity) — NIET de Supabase-tabelnaam.
8
+ * - REF_TABLE_BY_FIELD: identieke mapping naar de Supabase-cache-tabelnaam,
9
+ * uitsluitend voor directe `supabase.from(...)` reads in deze module.
10
+ */
11
+ import { GATEWAY_ENTITIES } from "./floriday-gateway-entities";
12
+ export const CODE_LIST_BY_FIELD = {
13
+ currency: "Currency",
14
+ salesUnit: "SalesUnit",
15
+ auctionLocation: "AuctionLocation",
16
+ supplyType: "SupplyType",
17
+ loadCarrierType: "SupplyLoadCarrierType",
18
+ packingType: "PackingType",
19
+ qualityMark: "QualityMark",
20
+ country: "Country",
21
+ countryOfOrigin: "Country",
22
+ };
23
+ export const REF_ENTITY_BY_FIELD = {
24
+ packingId: GATEWAY_ENTITIES.packings,
25
+ warehouseId: GATEWAY_ENTITIES.warehouses,
26
+ deliveryLocationId: GATEWAY_ENTITIES.deliveryLocations,
27
+ priceGroupId: GATEWAY_ENTITIES.priceGroups,
28
+ collectionId: GATEWAY_ENTITIES.collections,
29
+ };
30
+ export const REF_TABLE_BY_FIELD = {
31
+ packingId: "floriday_packings_cache",
32
+ warehouseId: "floriday_warehouses_cache",
33
+ deliveryLocationId: "floriday_delivery_locations_cache",
34
+ priceGroupId: "floriday_price_groups_cache",
35
+ collectionId: "floriday_collections_cache",
36
+ };
37
+ export function codeListFor(field) {
38
+ return CODE_LIST_BY_FIELD[field];
39
+ }
40
+ export function refEntityFor(field) {
41
+ return REF_ENTITY_BY_FIELD[field];
42
+ }
43
+ export function refTableFor(field) {
44
+ return REF_TABLE_BY_FIELD[field];
45
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Whitelist van kebab-case Floriday-resource-namen die de centrale Auth-gateway
3
+ * accepteert op `/api/public/gateway/cached-list`. 1-op-1 overgenomen uit
4
+ * `src/routes/api/public/gateway/cached-list.ts` aan Auth-zijde.
5
+ *
6
+ * Componenten geven NOOIT een Supabase-tabelnaam (`floriday_<x>_cache`)
7
+ * door als `entity` — gebruik altijd de kebab-case key uit dit bestand.
8
+ */
9
+ export declare const GATEWAY_ENTITIES: {
10
+ readonly salesOrders: "sales-orders";
11
+ readonly tradeItems: "trade-items";
12
+ readonly customerOrganizations: "customer-organizations";
13
+ readonly carriers: "carriers";
14
+ readonly fulfillmentOrders: "fulfillment-orders";
15
+ readonly deliveryOrders: "delivery-orders";
16
+ readonly clockSupplies: "clock-supplies";
17
+ readonly clockPresales: "clock-presales";
18
+ readonly contracts: "contracts";
19
+ readonly blanketOrders: "blanket-orders";
20
+ readonly warehouses: "warehouses";
21
+ readonly deliveryLocations: "delivery-locations";
22
+ readonly packings: "packings";
23
+ readonly connections: "connections";
24
+ readonly customerStickers: "customer-stickers";
25
+ readonly additionalServices: "additional-services";
26
+ readonly commercialServiceTypes: "commercial-service-types";
27
+ readonly collections: "collections";
28
+ readonly priceGroups: "price-groups";
29
+ readonly deliveryConditionSets: "delivery-condition-sets";
30
+ readonly salesStrategies: "sales-strategies";
31
+ readonly baseItems: "base-items";
32
+ readonly contractTradeItemGroups: "contract-trade-item-groups";
33
+ };
34
+ export type GatewayEntity = (typeof GATEWAY_ENTITIES)[keyof typeof GATEWAY_ENTITIES];
35
+ export declare function isGatewayEntity(value: unknown): value is GatewayEntity;
36
+ /**
37
+ * Compat-bridge: zet een Supabase-cache-tabelnaam (`floriday_<x>_cache`) om
38
+ * naar de bijbehorende kebab-case entity. Alleen bedoeld als tijdelijke
39
+ * helper tijdens de migratie — nieuwe code geeft direct een `GatewayEntity`.
40
+ *
41
+ * Retourneert `undefined` wanneer er geen geldige mapping is.
42
+ */
43
+ export declare function tableToEntity(cacheTable: string): GatewayEntity | undefined;
44
+ //# sourceMappingURL=floriday-gateway-entities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"floriday-gateway-entities.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-gateway-entities.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;CAwBnB,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;AAIrF,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAM3E"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Whitelist van kebab-case Floriday-resource-namen die de centrale Auth-gateway
3
+ * accepteert op `/api/public/gateway/cached-list`. 1-op-1 overgenomen uit
4
+ * `src/routes/api/public/gateway/cached-list.ts` aan Auth-zijde.
5
+ *
6
+ * Componenten geven NOOIT een Supabase-tabelnaam (`floriday_<x>_cache`)
7
+ * door als `entity` — gebruik altijd de kebab-case key uit dit bestand.
8
+ */
9
+ export const GATEWAY_ENTITIES = {
10
+ salesOrders: "sales-orders",
11
+ tradeItems: "trade-items",
12
+ customerOrganizations: "customer-organizations",
13
+ carriers: "carriers",
14
+ fulfillmentOrders: "fulfillment-orders",
15
+ deliveryOrders: "delivery-orders",
16
+ clockSupplies: "clock-supplies",
17
+ clockPresales: "clock-presales",
18
+ contracts: "contracts",
19
+ blanketOrders: "blanket-orders",
20
+ warehouses: "warehouses",
21
+ deliveryLocations: "delivery-locations",
22
+ packings: "packings",
23
+ connections: "connections",
24
+ customerStickers: "customer-stickers",
25
+ additionalServices: "additional-services",
26
+ commercialServiceTypes: "commercial-service-types",
27
+ collections: "collections",
28
+ priceGroups: "price-groups",
29
+ deliveryConditionSets: "delivery-condition-sets",
30
+ salesStrategies: "sales-strategies",
31
+ baseItems: "base-items",
32
+ contractTradeItemGroups: "contract-trade-item-groups",
33
+ };
34
+ const ALL = new Set(Object.values(GATEWAY_ENTITIES));
35
+ export function isGatewayEntity(value) {
36
+ return typeof value === "string" && ALL.has(value);
37
+ }
38
+ /**
39
+ * Compat-bridge: zet een Supabase-cache-tabelnaam (`floriday_<x>_cache`) om
40
+ * naar de bijbehorende kebab-case entity. Alleen bedoeld als tijdelijke
41
+ * helper tijdens de migratie — nieuwe code geeft direct een `GatewayEntity`.
42
+ *
43
+ * Retourneert `undefined` wanneer er geen geldige mapping is.
44
+ */
45
+ export function tableToEntity(cacheTable) {
46
+ const stripped = cacheTable
47
+ .replace(/^floriday_/, "")
48
+ .replace(/_cache$/, "")
49
+ .replace(/_/g, "-");
50
+ return isGatewayEntity(stripped) ? stripped : undefined;
51
+ }