@flowselections/floriday-voorraad 1.0.40 → 1.0.42
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/dist-lib/components/voorraad/ValidationOverviewTable.d.ts.map +1 -1
- package/dist-lib/components/voorraad/ValidationOverviewTable.js +45 -14
- package/dist-lib/integrations/supabase/auth-middleware.d.ts +914 -19
- package/dist-lib/integrations/supabase/auth-middleware.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/client.d.ts +914 -19
- package/dist-lib/integrations/supabase/client.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/client.server.d.ts +914 -19
- package/dist-lib/integrations/supabase/client.server.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/types.d.ts +914 -17
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/floricode-required-features.functions.d.ts +914 -19
- package/dist-lib/lib/floricode-required-features.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-2026v1.server.d.ts +1 -1
- package/dist-lib/lib/floriday-2026v1.server.d.ts.map +1 -1
- package/dist-lib/lib/floriday-2026v1.server.js +4 -0
- package/dist-lib/lib/floriday-customer-offer.functions.d.ts +914 -19
- package/dist-lib/lib/floriday-customer-offer.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-env.functions.d.ts +1790 -0
- package/dist-lib/lib/floriday-env.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-gateway.functions.d.ts +5370 -0
- package/dist-lib/lib/floriday-gateway.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-gateway.server.d.ts +7 -1
- package/dist-lib/lib/floriday-gateway.server.d.ts.map +1 -1
- package/dist-lib/lib/floriday-gateway.server.js +50 -3
- package/dist-lib/lib/floriday-relink.d.ts +16 -0
- package/dist-lib/lib/floriday-relink.d.ts.map +1 -0
- package/dist-lib/lib/floriday-relink.js +14 -0
- package/dist-lib/lib/floriday-vbn-required.functions.d.ts +1790 -0
- package/dist-lib/lib/floriday-vbn-required.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-warehouse.functions.d.ts +2685 -0
- package/dist-lib/lib/floriday-warehouse.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-write-gate.server.d.ts +60 -0
- package/dist-lib/lib/floriday-write-gate.server.d.ts.map +1 -0
- package/dist-lib/lib/floriday-write-gate.server.js +196 -0
- package/dist-lib/lib/floriday-writes.functions.d.ts +1790 -0
- package/dist-lib/lib/floriday-writes.functions.d.ts.map +1 -1
- package/dist-lib/lib/inventory-settings.functions.d.ts +1790 -0
- package/dist-lib/lib/inventory-settings.functions.d.ts.map +1 -1
- package/dist-lib/lib/logistics-buffer-events.server.d.ts +13 -0
- package/dist-lib/lib/logistics-buffer-events.server.d.ts.map +1 -0
- package/dist-lib/lib/logistics-buffer-events.server.js +365 -0
- package/dist-lib/lib/logistics-events.d.ts.map +1 -1
- package/dist-lib/lib/logistics-events.js +36 -7
- package/dist-lib/lib/logistics-tasks.server.d.ts.map +1 -1
- package/dist-lib/lib/logistics-tasks.server.js +38 -6
- package/dist-lib/lib/module-health.functions.d.ts +1790 -0
- package/dist-lib/lib/module-health.functions.d.ts.map +1 -1
- package/dist-lib/lib/stock-sync.functions.d.ts +1790 -0
- package/dist-lib/lib/stock-sync.functions.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fail-closed poort voor ÁL het schrijvende verkeer naar Floriday.
|
|
3
|
+
*
|
|
4
|
+
* Contract (koppelprompt 4 + 5):
|
|
5
|
+
* - Voor elke schrijfactie: `public.logistics_floriday_write_allowed(<actie>)`.
|
|
6
|
+
* Alleen bij exact `true` mag er verstuurd worden.
|
|
7
|
+
* - Statuswijzigingen en afhandelingen vragen daarnaast
|
|
8
|
+
* `public.logistics_floriday_order_approved(order_ref)`.
|
|
9
|
+
* - Fail closed: onbekende actie, ontbrekende functie, databasefout of een
|
|
10
|
+
* ander antwoord dan `true` → NIET versturen. Nooit terugvallen.
|
|
11
|
+
* - Elke weigering en elke verzending wordt vastgelegd via
|
|
12
|
+
* `logistics_floriday_log_refusal` / `logistics_floriday_log_send`.
|
|
13
|
+
* - Lezen valt hier nooit onder; alleen schrijven.
|
|
14
|
+
*
|
|
15
|
+
* Server-only bestand: nooit importeren vanuit clientcode.
|
|
16
|
+
*/
|
|
17
|
+
export declare const WRITE_GATE_MODULE = "voorraad";
|
|
18
|
+
/** Herkenbare markering zodat de wachtrij een weigering als "wachten" ziet. */
|
|
19
|
+
export declare const WRITE_GATE_MARK = "[poort]";
|
|
20
|
+
export type GateAction = "stock_publish" | "trade_item_update" | "status_update" | "fulfillment_order_send";
|
|
21
|
+
export declare class FloridayWriteRefused extends Error {
|
|
22
|
+
readonly refused = true;
|
|
23
|
+
constructor(reason: string);
|
|
24
|
+
}
|
|
25
|
+
export declare function isWriteRefusal(message: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Vertaalt een gateway-schrijfactie naar één van de vier toegestane
|
|
28
|
+
* actienamen. Herkent de code de actie niet, dan is het antwoord `null` en
|
|
29
|
+
* wordt er per definitie geweigerd.
|
|
30
|
+
*/
|
|
31
|
+
export declare function classifyWriteAction(input: {
|
|
32
|
+
action?: string;
|
|
33
|
+
path?: string;
|
|
34
|
+
}): GateAction | null;
|
|
35
|
+
export declare function logFloridaySend(input: {
|
|
36
|
+
orderRef: string;
|
|
37
|
+
action: string;
|
|
38
|
+
ok: boolean;
|
|
39
|
+
httpStatus?: number | null;
|
|
40
|
+
detail?: string | null;
|
|
41
|
+
}): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Vraagt toestemming voor één schrijfactie. Gooit `FloridayWriteRefused`
|
|
44
|
+
* wanneer er niet verstuurd mag worden — er is geen andere uitkomst.
|
|
45
|
+
*/
|
|
46
|
+
export declare function ensureFloridayWriteAllowed(input: {
|
|
47
|
+
action?: string;
|
|
48
|
+
path?: string;
|
|
49
|
+
referenceId?: string;
|
|
50
|
+
orderRef?: string;
|
|
51
|
+
}): Promise<GateAction>;
|
|
52
|
+
/**
|
|
53
|
+
* Mag de voorraadwachtrij überhaupt draaien? Gebruikt dezelfde poort, zodat
|
|
54
|
+
* cronjobs en achtergrondtaken elke ronde opnieuw toestemming vragen.
|
|
55
|
+
*/
|
|
56
|
+
export declare function stockPublishAllowed(): Promise<{
|
|
57
|
+
allowed: boolean;
|
|
58
|
+
reason: string | null;
|
|
59
|
+
}>;
|
|
60
|
+
//# sourceMappingURL=floriday-write-gate.server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"floriday-write-gate.server.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-write-gate.server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,eAAO,MAAM,iBAAiB,aAAa,CAAC;AAE5C,+EAA+E;AAC/E,eAAO,MAAM,eAAe,YAAY,CAAC;AAEzC,MAAM,MAAM,UAAU,GAClB,eAAe,GACf,mBAAmB,GACnB,eAAe,GACf,wBAAwB,CAAC;AAE7B,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,OAAO,QAAQ;gBACZ,MAAM,EAAE,MAAM;CAI3B;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,UAAU,GAAG,IAAI,CAwBpB;AAwCD,wBAAsB,eAAe,CAAC,KAAK,EAAE;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,OAAO,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,GAAG,OAAO,CAAC,IAAI,CAAC,CAehB;AAED;;;GAGG;AACH,wBAAsB,0BAA0B,CAAC,KAAK,EAAE;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,UAAU,CAAC,CAsEtB;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC;IACnD,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,CAAC,CAYD"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fail-closed poort voor ÁL het schrijvende verkeer naar Floriday.
|
|
3
|
+
*
|
|
4
|
+
* Contract (koppelprompt 4 + 5):
|
|
5
|
+
* - Voor elke schrijfactie: `public.logistics_floriday_write_allowed(<actie>)`.
|
|
6
|
+
* Alleen bij exact `true` mag er verstuurd worden.
|
|
7
|
+
* - Statuswijzigingen en afhandelingen vragen daarnaast
|
|
8
|
+
* `public.logistics_floriday_order_approved(order_ref)`.
|
|
9
|
+
* - Fail closed: onbekende actie, ontbrekende functie, databasefout of een
|
|
10
|
+
* ander antwoord dan `true` → NIET versturen. Nooit terugvallen.
|
|
11
|
+
* - Elke weigering en elke verzending wordt vastgelegd via
|
|
12
|
+
* `logistics_floriday_log_refusal` / `logistics_floriday_log_send`.
|
|
13
|
+
* - Lezen valt hier nooit onder; alleen schrijven.
|
|
14
|
+
*
|
|
15
|
+
* Server-only bestand: nooit importeren vanuit clientcode.
|
|
16
|
+
*/
|
|
17
|
+
export const WRITE_GATE_MODULE = "voorraad";
|
|
18
|
+
/** Herkenbare markering zodat de wachtrij een weigering als "wachten" ziet. */
|
|
19
|
+
export const WRITE_GATE_MARK = "[poort]";
|
|
20
|
+
export class FloridayWriteRefused extends Error {
|
|
21
|
+
constructor(reason) {
|
|
22
|
+
super(`${WRITE_GATE_MARK} Niet verstuurd naar Floriday: ${reason}`);
|
|
23
|
+
this.refused = true;
|
|
24
|
+
this.name = "FloridayWriteRefused";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function isWriteRefusal(message) {
|
|
28
|
+
return String(message ?? "").includes(WRITE_GATE_MARK);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Vertaalt een gateway-schrijfactie naar één van de vier toegestane
|
|
32
|
+
* actienamen. Herkent de code de actie niet, dan is het antwoord `null` en
|
|
33
|
+
* wordt er per definitie geweigerd.
|
|
34
|
+
*/
|
|
35
|
+
export function classifyWriteAction(input) {
|
|
36
|
+
const a = (input.action ?? "").toLowerCase();
|
|
37
|
+
const p = (input.path ?? "").toLowerCase();
|
|
38
|
+
if (/fulfillment/.test(a) || /fulfillment-orders/.test(p)) {
|
|
39
|
+
return "fulfillment_order_send";
|
|
40
|
+
}
|
|
41
|
+
if (/status/.test(a) || /\/status\b/.test(p))
|
|
42
|
+
return "status_update";
|
|
43
|
+
if (/(stock|supply|availabilit|allocation|batch)/.test(a) ||
|
|
44
|
+
/(continuous-stock|base-supply|supply-lines|availabilit)/.test(p)) {
|
|
45
|
+
return "stock_publish";
|
|
46
|
+
}
|
|
47
|
+
if (/(trade-item|tradeitem|item|product|media|photo|image|packing|warehouse|offer|price)/.test(a) ||
|
|
48
|
+
/(trade-items|media|packings|warehouses|customer-offers|price)/.test(p)) {
|
|
49
|
+
return "trade_item_update";
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
/** Naam van deze omgeving; afgeleid van de runtime, nooit hardcoded. */
|
|
54
|
+
function resolveShell() {
|
|
55
|
+
const base = process.env.PUBLIC_BASE_URL ??
|
|
56
|
+
process.env.MODULE_BASE_URL ??
|
|
57
|
+
process.env.SUPABASE_URL ??
|
|
58
|
+
"";
|
|
59
|
+
try {
|
|
60
|
+
return base ? new URL(base).host : "onbekend";
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return "onbekend";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function admin() {
|
|
67
|
+
const { getAdminClient } = await import("./supabase-admin.server");
|
|
68
|
+
return getAdminClient();
|
|
69
|
+
}
|
|
70
|
+
async function logRefusal(orderRef, reason, action) {
|
|
71
|
+
try {
|
|
72
|
+
const db = await admin();
|
|
73
|
+
await db.rpc("logistics_floriday_log_refusal", {
|
|
74
|
+
_order_ref: orderRef,
|
|
75
|
+
_reason: reason,
|
|
76
|
+
_module: WRITE_GATE_MODULE,
|
|
77
|
+
_shell: resolveShell(),
|
|
78
|
+
_action: action,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
/* logboek mag de weigering nooit omzetten in een verzending */
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export async function logFloridaySend(input) {
|
|
86
|
+
try {
|
|
87
|
+
const db = await admin();
|
|
88
|
+
await db.rpc("logistics_floriday_log_send", {
|
|
89
|
+
_order_ref: input.orderRef,
|
|
90
|
+
_action: input.action,
|
|
91
|
+
_ok: input.ok,
|
|
92
|
+
_http_status: input.httpStatus ?? null,
|
|
93
|
+
_detail: input.detail ?? null,
|
|
94
|
+
_module: WRITE_GATE_MODULE,
|
|
95
|
+
_shell: resolveShell(),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
/* logboek mag de verwerking niet blokkeren */
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Vraagt toestemming voor één schrijfactie. Gooit `FloridayWriteRefused`
|
|
104
|
+
* wanneer er niet verstuurd mag worden — er is geen andere uitkomst.
|
|
105
|
+
*/
|
|
106
|
+
export async function ensureFloridayWriteAllowed(input) {
|
|
107
|
+
const orderRef = String(input.orderRef ?? input.referenceId ?? "").trim() || "-";
|
|
108
|
+
const gateAction = classifyWriteAction(input);
|
|
109
|
+
if (!gateAction) {
|
|
110
|
+
const reason = `onbekende schrijfactie "${input.action ?? input.path ?? "?"}"`;
|
|
111
|
+
await logRefusal(orderRef, reason, String(input.action ?? ""));
|
|
112
|
+
throw new FloridayWriteRefused(reason);
|
|
113
|
+
}
|
|
114
|
+
let db;
|
|
115
|
+
try {
|
|
116
|
+
db = await admin();
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
const reason = `database niet bereikbaar: ${e?.message ?? e}`;
|
|
120
|
+
await logRefusal(orderRef, reason, gateAction);
|
|
121
|
+
throw new FloridayWriteRefused(reason);
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const { data, error } = await db.rpc("logistics_floriday_write_allowed", {
|
|
125
|
+
_action: gateAction,
|
|
126
|
+
});
|
|
127
|
+
if (error) {
|
|
128
|
+
const reason = `poortfunctie niet leesbaar: ${error.message}`;
|
|
129
|
+
await logRefusal(orderRef, reason, gateAction);
|
|
130
|
+
throw new FloridayWriteRefused(reason);
|
|
131
|
+
}
|
|
132
|
+
if (data !== true) {
|
|
133
|
+
const reason = `schakelaar voor "${gateAction}" staat uit`;
|
|
134
|
+
await logRefusal(orderRef, reason, gateAction);
|
|
135
|
+
throw new FloridayWriteRefused(reason);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (e) {
|
|
139
|
+
if (e instanceof FloridayWriteRefused)
|
|
140
|
+
throw e;
|
|
141
|
+
const reason = `poort niet bereikbaar: ${e?.message ?? e}`;
|
|
142
|
+
await logRefusal(orderRef, reason, gateAction);
|
|
143
|
+
throw new FloridayWriteRefused(reason);
|
|
144
|
+
}
|
|
145
|
+
// Statusverkeer vraagt daarnaast om een goedgekeurde karrencontrole.
|
|
146
|
+
if (gateAction === "status_update" || gateAction === "fulfillment_order_send") {
|
|
147
|
+
if (orderRef === "-") {
|
|
148
|
+
const reason = "geen ordernummer bekend";
|
|
149
|
+
await logRefusal(orderRef, reason, gateAction);
|
|
150
|
+
throw new FloridayWriteRefused(reason);
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
const { data, error } = await db.rpc("logistics_floriday_order_approved", {
|
|
154
|
+
_order_ref: orderRef,
|
|
155
|
+
});
|
|
156
|
+
if (error) {
|
|
157
|
+
const reason = `goedkeuring niet leesbaar: ${error.message}`;
|
|
158
|
+
await logRefusal(orderRef, reason, gateAction);
|
|
159
|
+
throw new FloridayWriteRefused(reason);
|
|
160
|
+
}
|
|
161
|
+
if (data !== true) {
|
|
162
|
+
const reason = "karrencontrole niet goedgekeurd";
|
|
163
|
+
await logRefusal(orderRef, reason, gateAction);
|
|
164
|
+
throw new FloridayWriteRefused(reason);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
if (e instanceof FloridayWriteRefused)
|
|
169
|
+
throw e;
|
|
170
|
+
const reason = `goedkeuring niet leesbaar: ${e?.message ?? e}`;
|
|
171
|
+
await logRefusal(orderRef, reason, gateAction);
|
|
172
|
+
throw new FloridayWriteRefused(reason);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return gateAction;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Mag de voorraadwachtrij überhaupt draaien? Gebruikt dezelfde poort, zodat
|
|
179
|
+
* cronjobs en achtergrondtaken elke ronde opnieuw toestemming vragen.
|
|
180
|
+
*/
|
|
181
|
+
export async function stockPublishAllowed() {
|
|
182
|
+
try {
|
|
183
|
+
const db = await admin();
|
|
184
|
+
const { data, error } = await db.rpc("logistics_floriday_write_allowed", {
|
|
185
|
+
_action: "stock_publish",
|
|
186
|
+
});
|
|
187
|
+
if (error)
|
|
188
|
+
return { allowed: false, reason: `poort niet leesbaar: ${error.message}` };
|
|
189
|
+
if (data !== true)
|
|
190
|
+
return { allowed: false, reason: "voorraadschakelaar staat uit" };
|
|
191
|
+
return { allowed: true, reason: null };
|
|
192
|
+
}
|
|
193
|
+
catch (e) {
|
|
194
|
+
return { allowed: false, reason: `poort niet bereikbaar: ${e?.message ?? e}` };
|
|
195
|
+
}
|
|
196
|
+
}
|