@flowselections/floriday-voorraad 1.0.65 → 1.0.67

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 (25) hide show
  1. package/dist-lib/hooks-entry.d.ts +11 -0
  2. package/dist-lib/hooks-entry.d.ts.map +1 -0
  3. package/dist-lib/hooks-entry.js +10 -0
  4. package/dist-lib/integrations/supabase/types.d.ts +372 -0
  5. package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
  6. package/dist-lib/lib/inventory-settings.functions.d.ts +1 -1
  7. package/dist-lib/server-hooks/floriday-base-supply.d.ts +3 -0
  8. package/dist-lib/server-hooks/floriday-base-supply.d.ts.map +1 -0
  9. package/dist-lib/server-hooks/floriday-base-supply.js +73 -0
  10. package/dist-lib/server-hooks/floriday-continuous-stock-pull.d.ts +3 -0
  11. package/dist-lib/server-hooks/floriday-continuous-stock-pull.d.ts.map +1 -0
  12. package/dist-lib/server-hooks/floriday-continuous-stock-pull.js +168 -0
  13. package/dist-lib/server-hooks/floriday-continuous-stock.d.ts +3 -0
  14. package/dist-lib/server-hooks/floriday-continuous-stock.d.ts.map +1 -0
  15. package/dist-lib/server-hooks/floriday-continuous-stock.js +111 -0
  16. package/dist-lib/server-hooks/floriday-stock-reconcile.d.ts +3 -0
  17. package/dist-lib/server-hooks/floriday-stock-reconcile.d.ts.map +1 -0
  18. package/dist-lib/server-hooks/floriday-stock-reconcile.js +235 -0
  19. package/dist-lib/server-hooks/guard.d.ts +3 -0
  20. package/dist-lib/server-hooks/guard.d.ts.map +1 -0
  21. package/dist-lib/server-hooks/guard.js +60 -0
  22. package/dist-lib/server-hooks/logistics-tasks-run.d.ts +3 -0
  23. package/dist-lib/server-hooks/logistics-tasks-run.d.ts.map +1 -0
  24. package/dist-lib/server-hooks/logistics-tasks-run.js +37 -0
  25. package/package.json +53 -2
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Gemeenschappelijke poort voor alle Voorraad-verwerkers (losse app én Shell).
3
+ *
4
+ * Volgorde: OPTIONS → sleutel (401 JSON) → schakelaar per verwerker in
5
+ * `module_runtime_config` (`voorraad_hook_enabled.<naam>`) → verwerking.
6
+ * Staat de schakelaar uit of ontbreekt hij, dan gebeurt er niets
7
+ * (behalve voor de verwerkers waarvan de standaard "aan" is).
8
+ *
9
+ * Server-only.
10
+ */
11
+ const CORS = {
12
+ "Access-Control-Allow-Origin": "*",
13
+ "Access-Control-Allow-Methods": "POST, OPTIONS",
14
+ "Access-Control-Allow-Headers": "content-type, apikey, x-api-key, authorization",
15
+ };
16
+ /** Standaard als de instelling (nog) niet bestaat. Gelijk aan de migratie. */
17
+ const DEFAULT_ON = new Set(["floriday_base_supply", "logistics_tasks"]);
18
+ function json(body, status = 200) {
19
+ return new Response(JSON.stringify(body), {
20
+ status,
21
+ headers: { "Content-Type": "application/json", ...CORS },
22
+ });
23
+ }
24
+ function keyOk(request) {
25
+ const apikey = request.headers.get("apikey") ??
26
+ request.headers.get("x-api-key") ??
27
+ request.headers.get("authorization")?.replace(/^Bearer\s+/i, "");
28
+ const expected = process.env.SUPABASE_PUBLISHABLE_KEY ??
29
+ process.env.SUPABASE_ANON_KEY ??
30
+ process.env.VITE_SUPABASE_PUBLISHABLE_KEY ??
31
+ "";
32
+ return !!expected && !!apikey && apikey === expected;
33
+ }
34
+ export async function hookEnabled(name) {
35
+ const { getAdminClient } = await import("../lib/supabase-admin.server.js");
36
+ const admin = getAdminClient();
37
+ const { data } = await admin
38
+ .from("module_runtime_config")
39
+ .select("value")
40
+ .eq("key", `voorraad_hook_enabled.${name}`)
41
+ .maybeSingle();
42
+ if (!data)
43
+ return DEFAULT_ON.has(name);
44
+ return String(data.value).trim().toLowerCase() === "true";
45
+ }
46
+ export async function runGuardedHook(request, name, handle, label) {
47
+ if (request.method === "OPTIONS")
48
+ return new Response(null, { status: 204, headers: CORS });
49
+ if (!keyOk(request))
50
+ return json({ error: "Unauthorized" }, 401);
51
+ try {
52
+ if (!(await hookEnabled(name)))
53
+ return json({ ok: true, skipped: "disabled", hook: name });
54
+ return await handle(request);
55
+ }
56
+ catch (e) {
57
+ console.error(`[voorraad] ${label} fatal:`, e?.message ?? e);
58
+ return json({ error: "Verwerking mislukt" }, 500);
59
+ }
60
+ }
@@ -0,0 +1,3 @@
1
+ /** Shell-handler voor /api/public/hooks/logistics-tasks-run. Schakelaar: voorraad_hook_enabled.logistics_tasks. */
2
+ export declare function handleLogisticsTasksRun(request: Request): Promise<Response>;
3
+ //# sourceMappingURL=logistics-tasks-run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logistics-tasks-run.d.ts","sourceRoot":"","sources":["../../src/server-hooks/logistics-tasks-run.ts"],"names":[],"mappings":"AAyCA,mHAAmH;AACnH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAEjF"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Cron-endpoint (elke minuut): verwerkt openstaande Logistics Engine-taken
3
+ * (`stock.reserve`) volledig op de achtergrond, inclusief automatische
4
+ * herpogingen. Geen UI, geen gebruikersinteractie.
5
+ *
6
+ * Authenticatie: apikey-header met de anon key (dit endpoint zit onder
7
+ * `/api/public/*`, dus platform-auth wordt overgeslagen; wij verifiëren de
8
+ * apikey zelf).
9
+ */
10
+ import { runGuardedHook } from "./guard";
11
+ async function handle(request) {
12
+ const apikey = request.headers.get("apikey") ??
13
+ request.headers.get("x-api-key") ??
14
+ request.headers.get("authorization")?.replace(/^Bearer\s+/i, "");
15
+ const expected = process.env.SUPABASE_PUBLISHABLE_KEY ?? process.env.SUPABASE_ANON_KEY ?? "";
16
+ if (!expected || !apikey || apikey !== expected) {
17
+ return new Response(JSON.stringify({ error: "Unauthorized" }), {
18
+ status: 401,
19
+ headers: { "Content-Type": "application/json" },
20
+ });
21
+ }
22
+ try {
23
+ const { runLogisticsTasks } = await import("../lib/logistics-tasks.server.js");
24
+ const summary = await runLogisticsTasks();
25
+ return new Response(JSON.stringify({ ok: true, ...summary }), {
26
+ headers: { "Content-Type": "application/json" },
27
+ });
28
+ }
29
+ catch (e) {
30
+ console.error("[voorraad] logistics-tasks-run mislukt:", e?.message ?? e);
31
+ return new Response(JSON.stringify({ ok: false, error: e?.message ?? String(e) }), { status: 500, headers: { "Content-Type": "application/json" } });
32
+ }
33
+ }
34
+ /** Shell-handler voor /api/public/hooks/logistics-tasks-run. Schakelaar: voorraad_hook_enabled.logistics_tasks. */
35
+ export async function handleLogisticsTasksRun(request) {
36
+ return runGuardedHook(request, "logistics_tasks", handle, "logistics-tasks-run");
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowselections/floriday-voorraad",
3
- "version": "1.0.65",
3
+ "version": "1.0.67",
4
4
  "sideEffects": false,
5
5
  "type": "module",
6
6
  "main": "./dist-lib/index.js",
@@ -9,6 +9,10 @@
9
9
  ".": {
10
10
  "types": "./dist-lib/index.d.ts",
11
11
  "default": "./dist-lib/index.js"
12
+ },
13
+ "./hooks": {
14
+ "types": "./dist-lib/hooks-entry.d.ts",
15
+ "default": "./dist-lib/hooks-entry.js"
12
16
  }
13
17
  },
14
18
  "files": [
@@ -100,7 +104,7 @@
100
104
  "export": "FustenPage",
101
105
  "route": "voorraad_/fusten",
102
106
  "title": "Fusten",
103
- "nav": false
107
+ "nav": true
104
108
  },
105
109
  {
106
110
  "export": "PublicatiesPage",
@@ -108,6 +112,53 @@
108
112
  "title": "Publicaties",
109
113
  "nav": false
110
114
  }
115
+ ],
116
+ "serverRoutes": [
117
+ {
118
+ "routePath": "/api/public/hooks/floriday-base-supply",
119
+ "import": "@flowselections/floriday-voorraad/hooks",
120
+ "handler": "handleFloridayBaseSupply",
121
+ "methods": [
122
+ "POST",
123
+ "OPTIONS"
124
+ ]
125
+ },
126
+ {
127
+ "routePath": "/api/public/hooks/floriday-continuous-stock",
128
+ "import": "@flowselections/floriday-voorraad/hooks",
129
+ "handler": "handleFloridayContinuousStock",
130
+ "methods": [
131
+ "POST",
132
+ "OPTIONS"
133
+ ]
134
+ },
135
+ {
136
+ "routePath": "/api/public/hooks/floriday-continuous-stock-pull",
137
+ "import": "@flowselections/floriday-voorraad/hooks",
138
+ "handler": "handleFloridayContinuousStockPull",
139
+ "methods": [
140
+ "POST",
141
+ "OPTIONS"
142
+ ]
143
+ },
144
+ {
145
+ "routePath": "/api/public/hooks/floriday-stock-reconcile",
146
+ "import": "@flowselections/floriday-voorraad/hooks",
147
+ "handler": "handleFloridayStockReconcile",
148
+ "methods": [
149
+ "POST",
150
+ "OPTIONS"
151
+ ]
152
+ },
153
+ {
154
+ "routePath": "/api/public/hooks/logistics-tasks-run",
155
+ "import": "@flowselections/floriday-voorraad/hooks",
156
+ "handler": "handleLogisticsTasksRun",
157
+ "methods": [
158
+ "POST",
159
+ "OPTIONS"
160
+ ]
161
+ }
111
162
  ]
112
163
  }
113
164
  }