@flowselections/floriday-klanten-module 1.0.69 → 1.0.74
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/klanten/FactureringKredietCard.js +1 -1
- package/dist-lib/components/klanten/ImportKlanten.js +2 -2
- package/dist-lib/components/klanten/KlantDetail.d.ts.map +1 -1
- package/dist-lib/components/klanten/KlantDetail.js +3 -1
- package/dist-lib/components/klanten/KlantFormulier.js +1 -1
- package/dist-lib/components/klanten/KlantenOverzicht.d.ts.map +1 -1
- package/dist-lib/components/klanten/KlantenOverzicht.js +5 -2
- package/dist-lib/components/klanten/TwinfieldQueueAdminCard.d.ts +3 -0
- package/dist-lib/components/klanten/TwinfieldQueueAdminCard.d.ts.map +1 -0
- package/dist-lib/components/klanten/TwinfieldQueueAdminCard.js +36 -0
- package/dist-lib/integrations/supabase/types.d.ts +2986 -81
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/customer-schemas.js +2 -2
- package/dist-lib/lib/invoice-address.d.ts +3 -0
- package/dist-lib/lib/invoice-address.d.ts.map +1 -0
- package/dist-lib/lib/invoice-address.js +14 -0
- package/dist-lib/lib/server-routes/twinfield-run-queue.server.d.ts +35 -0
- package/dist-lib/lib/server-routes/twinfield-run-queue.server.d.ts.map +1 -0
- package/dist-lib/lib/server-routes/twinfield-run-queue.server.js +81 -0
- package/dist-lib/lib/twinfield-queue-admin.functions.d.ts +21 -0
- package/dist-lib/lib/twinfield-queue-admin.functions.d.ts.map +1 -0
- package/dist-lib/lib/twinfield-queue-admin.functions.js +32 -0
- package/package.json +16 -2
- package/schema/klanten.sql +52 -2
|
@@ -195,7 +195,7 @@ const customerCreateBaseSchema = z.object({
|
|
|
195
195
|
customer_number: fmtStr(16, NUMBER_RE, "Alleen letters, cijfers, - en _ (maximaal 16 tekens)"),
|
|
196
196
|
language: fmtStr(16, /^(nl|en|de|fr)$/i, "Kies een van de beschikbare talen"),
|
|
197
197
|
website: optWebsite(),
|
|
198
|
-
billing_email: optEmail("
|
|
198
|
+
billing_email: optEmail("Vul een geldig e-mailadres voor facturen in"),
|
|
199
199
|
address_type: optStr(64),
|
|
200
200
|
address_line1: optStr(128),
|
|
201
201
|
address_line2: optStr(128),
|
|
@@ -286,7 +286,7 @@ const customerImportRowBaseSchema = z
|
|
|
286
286
|
customer_number: fmtStr(16, NUMBER_RE, "Alleen letters, cijfers, - en _ (maximaal 16 tekens)"),
|
|
287
287
|
language: fmtStr(16, /^(nl|en|de|fr)$/i, "Kies een van de beschikbare talen"),
|
|
288
288
|
website: optWebsite(),
|
|
289
|
-
billing_email: optEmail("
|
|
289
|
+
billing_email: optEmail("Vul een geldig e-mailadres voor facturen in"),
|
|
290
290
|
address_type: optStr(64),
|
|
291
291
|
address_line1: optStr(128),
|
|
292
292
|
address_line2: optStr(128),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoice-address.d.ts","sourceRoot":"","sources":["../../src/lib/invoice-address.ts"],"names":[],"mappings":"AAUA,oFAAoF;AACpF,wBAAgB,2BAA2B,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,EAAE,CAGnG"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Velden die Facturatie nodig heeft voor het factuuradres (huisnummer telt niet mee: staat vaak in de straat). */
|
|
2
|
+
const FIELDS = [
|
|
3
|
+
{ key: "street", label: "straat" },
|
|
4
|
+
{ key: "postal_code", label: "postcode" },
|
|
5
|
+
{ key: "city", label: "plaats" },
|
|
6
|
+
{ key: "country", label: "land" },
|
|
7
|
+
];
|
|
8
|
+
const filled = (v) => v !== null && v !== undefined && String(v).trim() !== "";
|
|
9
|
+
/** Geeft de ontbrekende onderdelen van het factuuradres terug (leeg = volledig). */
|
|
10
|
+
export function missingInvoiceAddressFields(c) {
|
|
11
|
+
if (!c)
|
|
12
|
+
return FIELDS.map((f) => f.label);
|
|
13
|
+
return FIELDS.filter((f) => !filled(c[f.key])).map((f) => f.label);
|
|
14
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Standaard aantal wachtrijregels per ronde (zoals vóór 1.0.70); instelbaar via app_settings. */
|
|
2
|
+
export declare const DEFAULT_PUSH_BATCH = 50;
|
|
3
|
+
export declare const PUSH_BATCH_SETTING = "klanten_twinfield_push_batch";
|
|
4
|
+
/** Leest de limiet uit een app_settings-waarde. Ontbreekt = 50; ongeldig = 50 met melding. Geldig: geheel getal 1–200. */
|
|
5
|
+
export declare function parsePushBatch(raw: unknown): {
|
|
6
|
+
limit: number;
|
|
7
|
+
melding?: string;
|
|
8
|
+
};
|
|
9
|
+
type QueueResult = {
|
|
10
|
+
claimed: number;
|
|
11
|
+
succeeded: number;
|
|
12
|
+
failed: number;
|
|
13
|
+
skipped: number;
|
|
14
|
+
};
|
|
15
|
+
type SyncResult = {
|
|
16
|
+
bijgewerkt: number;
|
|
17
|
+
conflicten: number;
|
|
18
|
+
aanmaken: number;
|
|
19
|
+
koppelen: number;
|
|
20
|
+
nietMeerInTwinfield: number;
|
|
21
|
+
};
|
|
22
|
+
export interface RunQueueDeps {
|
|
23
|
+
/** Service-client van de shell; ontbreekt hij, dan de eigen service-client. */
|
|
24
|
+
supabase?: unknown;
|
|
25
|
+
runQueue?: (limit: number) => Promise<QueueResult>;
|
|
26
|
+
runSync?: () => Promise<SyncResult>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* POST /api/public/twinfield/run-queue: alleen x-cron-secret tegen twinfield_cron_auth (id 1).
|
|
30
|
+
* Volgorde: controle → cronjob bijwerken (nooit aanmaken) → push → inleesronde (Twinfield → klanten).
|
|
31
|
+
* Antwoord: alleen tellingen en statussen.
|
|
32
|
+
*/
|
|
33
|
+
export declare function handleTwinfieldRunQueue(request: Request, supabaseOrDeps?: unknown): Promise<Response>;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=twinfield-run-queue.server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"twinfield-run-queue.server.d.ts","sourceRoot":"","sources":["../../../src/lib/server-routes/twinfield-run-queue.server.ts"],"names":[],"mappings":"AAEA,kGAAkG;AAClG,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,eAAO,MAAM,kBAAkB,iCAAiC,CAAC;AAEjE,0HAA0H;AAC1H,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAShF;AAID,KAAK,WAAW,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAC3F,KAAK,UAAU,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,mBAAmB,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9H,MAAM,WAAW,YAAY;IAC3B,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;IACnD,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;CACrC;AAED;;;;GAIG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqD3G"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { isCronSecretValid } from "../accounting/twinfield/cron-auth.js";
|
|
2
|
+
/** Standaard aantal wachtrijregels per ronde (zoals vóór 1.0.70); instelbaar via app_settings. */
|
|
3
|
+
export const DEFAULT_PUSH_BATCH = 50;
|
|
4
|
+
export const PUSH_BATCH_SETTING = "klanten_twinfield_push_batch";
|
|
5
|
+
/** Leest de limiet uit een app_settings-waarde. Ontbreekt = 50; ongeldig = 50 met melding. Geldig: geheel getal 1–200. */
|
|
6
|
+
export function parsePushBatch(raw) {
|
|
7
|
+
if (raw === null || raw === undefined || raw === "")
|
|
8
|
+
return { limit: DEFAULT_PUSH_BATCH };
|
|
9
|
+
let v = raw;
|
|
10
|
+
if (typeof v === "string") {
|
|
11
|
+
try {
|
|
12
|
+
v = JSON.parse(v);
|
|
13
|
+
}
|
|
14
|
+
catch { /* blijft tekst */ }
|
|
15
|
+
}
|
|
16
|
+
const n = typeof v === "number" ? v : typeof v === "string" && /^\d+$/.test(v.trim()) ? Number(v) : NaN;
|
|
17
|
+
if (Number.isInteger(n) && n >= 1 && n <= 200)
|
|
18
|
+
return { limit: n };
|
|
19
|
+
return { limit: DEFAULT_PUSH_BATCH, melding: `${PUSH_BATCH_SETTING} ongeldig; ${DEFAULT_PUSH_BATCH} gebruikt` };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* POST /api/public/twinfield/run-queue: alleen x-cron-secret tegen twinfield_cron_auth (id 1).
|
|
23
|
+
* Volgorde: controle → cronjob bijwerken (nooit aanmaken) → push → inleesronde (Twinfield → klanten).
|
|
24
|
+
* Antwoord: alleen tellingen en statussen.
|
|
25
|
+
*/
|
|
26
|
+
export async function handleTwinfieldRunQueue(request, supabaseOrDeps) {
|
|
27
|
+
if (request.method !== "POST")
|
|
28
|
+
return new Response("Method Not Allowed", { status: 405 });
|
|
29
|
+
const deps = supabaseOrDeps && typeof supabaseOrDeps === "object" &&
|
|
30
|
+
("runQueue" in supabaseOrDeps || "supabase" in supabaseOrDeps || "runSync" in supabaseOrDeps)
|
|
31
|
+
? supabaseOrDeps
|
|
32
|
+
: { supabase: supabaseOrDeps };
|
|
33
|
+
let db = deps.supabase;
|
|
34
|
+
if (!db)
|
|
35
|
+
db = (await import("../../integrations/supabase/client.server.js")).supabaseAdmin;
|
|
36
|
+
const { data, error } = await db.from("twinfield_cron_auth").select("secret").eq("id", 1).maybeSingle();
|
|
37
|
+
const stored = data?.secret;
|
|
38
|
+
if (error || !stored) {
|
|
39
|
+
return Response.json({ error: "twinfield_cron_auth heeft geen geheim; wachtrij niet gestart" }, { status: 500 });
|
|
40
|
+
}
|
|
41
|
+
if (!isCronSecretValid(request.headers.get("x-cron-secret"), stored)) {
|
|
42
|
+
return new Response("Unauthorized", { status: 401 });
|
|
43
|
+
}
|
|
44
|
+
// 1. Cronjob van deze shell bijwerken bij afwijking; de route maakt hem nooit aan.
|
|
45
|
+
let cron;
|
|
46
|
+
try {
|
|
47
|
+
const r = await db.rpc("klanten_ensure_cron", { p_alleen_bijwerken: true });
|
|
48
|
+
cron = r.error ? "fout" : String(r.data?.status ?? "onbekend");
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
cron = "fout";
|
|
52
|
+
}
|
|
53
|
+
// 2. Limiet uit de instelling.
|
|
54
|
+
let batch = { limit: DEFAULT_PUSH_BATCH };
|
|
55
|
+
try {
|
|
56
|
+
const s = await db.from("app_settings").select("value").eq("key", PUSH_BATCH_SETTING).maybeSingle();
|
|
57
|
+
batch = parsePushBatch(s.data?.value);
|
|
58
|
+
}
|
|
59
|
+
catch { /* standaard */ }
|
|
60
|
+
// 3. Push.
|
|
61
|
+
let push;
|
|
62
|
+
try {
|
|
63
|
+
const run = deps.runQueue ?? (await import("../accounting/twinfield/worker.server.js")).runTwinfieldPushQueueInternal;
|
|
64
|
+
const r = await run(batch.limit);
|
|
65
|
+
push = { claimed: r.claimed, succeeded: r.succeeded, failed: r.failed, skipped: r.skipped };
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return Response.json({ error: "wachtrij mislukt", cron, limiet: batch.limit }, { status: 500 });
|
|
69
|
+
}
|
|
70
|
+
// 4. Inleesronde: wijzigingen uit Twinfield (leeslaag) naar klanten. Een fout hierin laat de push gelukt.
|
|
71
|
+
let inlezen;
|
|
72
|
+
try {
|
|
73
|
+
const run = deps.runSync ?? (await import("../accounting/twinfield/sync.server.js")).runTwinfieldInboundSync;
|
|
74
|
+
const r = await run();
|
|
75
|
+
inlezen = { bijgewerkt: r.bijgewerkt, conflicten: r.conflicten, aanmaken: r.aanmaken, koppelen: r.koppelen, nietMeerInTwinfield: r.nietMeerInTwinfield };
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
inlezen = { status: "fout" };
|
|
79
|
+
}
|
|
80
|
+
return Response.json({ ...push, limiet: batch.limit, ...(batch.melding ? { melding: batch.melding } : {}), inlezen, cron });
|
|
81
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Bij openen van het beheerblok: cronjob van deze shell vastleggen (mag aanmaken) en limiet tonen. */
|
|
2
|
+
export declare const ensureTwinfieldQueueJob: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
3
|
+
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
4
|
+
userId: string;
|
|
5
|
+
claims: import("@supabase/auth-js").JwtPayload;
|
|
6
|
+
}, undefined, undefined, undefined>], undefined, Promise<{
|
|
7
|
+
status: string;
|
|
8
|
+
limiet: number;
|
|
9
|
+
standaard: 50;
|
|
10
|
+
melding: string | null;
|
|
11
|
+
}>>;
|
|
12
|
+
export declare const setTwinfieldQueueBatch: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
13
|
+
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
14
|
+
userId: string;
|
|
15
|
+
claims: import("@supabase/auth-js").JwtPayload;
|
|
16
|
+
}, undefined, undefined, undefined>], (d: unknown) => {
|
|
17
|
+
limiet: number;
|
|
18
|
+
}, Promise<{
|
|
19
|
+
limiet: number;
|
|
20
|
+
}>>;
|
|
21
|
+
//# sourceMappingURL=twinfield-queue-admin.functions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"twinfield-queue-admin.functions.d.ts","sourceRoot":"","sources":["../../src/lib/twinfield-queue-admin.functions.ts"],"names":[],"mappings":"AAKA,uGAAuG;AACvG,eAAO,MAAM,uBAAuB;;;;;;;;;GAUhC,CAAC;AAEL,eAAO,MAAM,sBAAsB;;;;0CAEb,OAAO;;;;GAUzB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware.js";
|
|
4
|
+
import { DEFAULT_PUSH_BATCH, PUSH_BATCH_SETTING, parsePushBatch } from "./server-routes/twinfield-run-queue.server.js";
|
|
5
|
+
/** Bij openen van het beheerblok: cronjob van deze shell vastleggen (mag aanmaken) en limiet tonen. */
|
|
6
|
+
export const ensureTwinfieldQueueJob = createServerFn({ method: "POST" })
|
|
7
|
+
.middleware([requireSupabaseAuth])
|
|
8
|
+
.handler(async ({ context }) => {
|
|
9
|
+
// klanten_toegang('beheerder') in de functie zelf controleert de rol.
|
|
10
|
+
const { data, error } = await context.supabase.rpc("klanten_ensure_cron", { p_alleen_bijwerken: false });
|
|
11
|
+
if (error)
|
|
12
|
+
throw new Error(error.message);
|
|
13
|
+
const { data: s } = await context.supabase
|
|
14
|
+
.from("app_settings").select("value").eq("key", PUSH_BATCH_SETTING).maybeSingle();
|
|
15
|
+
const batch = parsePushBatch(s?.value);
|
|
16
|
+
return { status: String(data?.status ?? "onbekend"), limiet: batch.limit, standaard: DEFAULT_PUSH_BATCH, melding: batch.melding ?? null };
|
|
17
|
+
});
|
|
18
|
+
export const setTwinfieldQueueBatch = createServerFn({ method: "POST" })
|
|
19
|
+
.middleware([requireSupabaseAuth])
|
|
20
|
+
.inputValidator((d) => z.object({ limiet: z.number().int().min(1).max(200) }).parse(d))
|
|
21
|
+
.handler(async ({ context, data }) => {
|
|
22
|
+
const { data: isAdmin } = await context.supabase.rpc("has_role", { _user_id: context.userId, _role: "admin" });
|
|
23
|
+
if (isAdmin !== true)
|
|
24
|
+
throw new Error("Alleen beheerders mogen dit aanpassen.");
|
|
25
|
+
const { supabaseAdmin } = await import("../integrations/supabase/client.server.js");
|
|
26
|
+
const { error } = await supabaseAdmin
|
|
27
|
+
.from("app_settings")
|
|
28
|
+
.upsert({ key: PUSH_BATCH_SETTING, value: String(data.limiet) }, { onConflict: "key" });
|
|
29
|
+
if (error)
|
|
30
|
+
throw new Error(error.message);
|
|
31
|
+
return { limiet: data.limiet };
|
|
32
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowselections/floriday-klanten-module",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.74",
|
|
4
4
|
"private": false,
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -12,7 +12,11 @@
|
|
|
12
12
|
"default": "./dist-lib/index.js"
|
|
13
13
|
},
|
|
14
14
|
"./styles": "./dist-lib/styles.css",
|
|
15
|
-
"./schema.sql": "./schema/klanten.sql"
|
|
15
|
+
"./schema.sql": "./schema/klanten.sql",
|
|
16
|
+
"./server-routes": {
|
|
17
|
+
"types": "./dist-lib/lib/server-routes/twinfield-run-queue.server.d.ts",
|
|
18
|
+
"default": "./dist-lib/lib/server-routes/twinfield-run-queue.server.js"
|
|
19
|
+
}
|
|
16
20
|
},
|
|
17
21
|
"flowselections": {
|
|
18
22
|
"moduleId": "Klanten",
|
|
@@ -80,6 +84,16 @@
|
|
|
80
84
|
"name": "Klantstickers",
|
|
81
85
|
"description": "Leest klantstickers met AI"
|
|
82
86
|
}
|
|
87
|
+
],
|
|
88
|
+
"serverRoutes": [
|
|
89
|
+
{
|
|
90
|
+
"routePath": "/api/public/twinfield/run-queue",
|
|
91
|
+
"import": "@flowselections/floriday-klanten-module/server-routes",
|
|
92
|
+
"handler": "handleTwinfieldRunQueue",
|
|
93
|
+
"methods": [
|
|
94
|
+
"POST"
|
|
95
|
+
]
|
|
96
|
+
}
|
|
83
97
|
]
|
|
84
98
|
},
|
|
85
99
|
"files": [
|
package/schema/klanten.sql
CHANGED
|
@@ -1022,6 +1022,45 @@ BEGIN
|
|
|
1022
1022
|
END LOOP;
|
|
1023
1023
|
RETURN _n;
|
|
1024
1024
|
END; $function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.import_floriday_delivery_locations(_org_id text) RETURNS integer L');
|
|
1025
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klanten_ensure_cron(p_alleen_bijwerken boolean)
|
|
1026
|
+
RETURNS jsonb
|
|
1027
|
+
LANGUAGE plpgsql
|
|
1028
|
+
SECURITY DEFINER
|
|
1029
|
+
SET search_path TO 'public'
|
|
1030
|
+
AS $function$
|
|
1031
|
+
DECLARE _cmd constant text := $c$SELECT public.flowselections_cron_post('/api/public/twinfield/run-queue', '{}'::jsonb, 60000, 'twinfield_cron_auth')$c$;
|
|
1032
|
+
_sched constant text := '*/5 * * * *'; _id bigint; _old_cmd text; _old_sched text;
|
|
1033
|
+
BEGIN
|
|
1034
|
+
PERFORM public.klanten_toegang('beheerder');
|
|
1035
|
+
IF to_regclass('cron.job') IS NULL THEN RETURN jsonb_build_object('status','geen_pg_cron'); END IF;
|
|
1036
|
+
IF to_regprocedure('public.flowselections_cron_post(text,jsonb,integer,text)') IS NULL THEN
|
|
1037
|
+
RETURN jsonb_build_object('status','core_helper_ontbreekt');
|
|
1038
|
+
END IF;
|
|
1039
|
+
EXECUTE 'SELECT jobid, command, schedule FROM cron.job WHERE jobname = $1 ORDER BY jobid LIMIT 1'
|
|
1040
|
+
INTO _id, _old_cmd, _old_sched USING 'klanten-twinfield-push-queue';
|
|
1041
|
+
IF _id IS NULL THEN
|
|
1042
|
+
IF COALESCE(p_alleen_bijwerken, false) THEN RETURN jsonb_build_object('status','job_ontbreekt'); END IF;
|
|
1043
|
+
EXECUTE 'SELECT cron.schedule($1, $2, $3)' INTO _id USING 'klanten-twinfield-push-queue', _sched, _cmd;
|
|
1044
|
+
RETURN jsonb_build_object('status','ingepland','jobid',_id,'schedule',_sched,'command',_cmd);
|
|
1045
|
+
END IF;
|
|
1046
|
+
IF _old_cmd = _cmd AND _old_sched = _sched THEN
|
|
1047
|
+
RETURN jsonb_build_object('status','gelijk','jobid',_id,'schedule',_sched,'command',_cmd);
|
|
1048
|
+
END IF;
|
|
1049
|
+
EXECUTE 'SELECT cron.alter_job(job_id := $1, schedule := $2, command := $3)' USING _id, _sched, _cmd;
|
|
1050
|
+
RETURN jsonb_build_object('status','bijgewerkt','jobid',_id,'schedule',_sched,'command',_cmd,'oud_command',_old_cmd,'oud_schedule',_old_sched);
|
|
1051
|
+
END;
|
|
1052
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.klanten_ensure_cron(p_alleen_bijwerken boolean) RETURNS jsonb LANG');
|
|
1053
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klanten_ensure_cron()
|
|
1054
|
+
RETURNS jsonb
|
|
1055
|
+
LANGUAGE plpgsql
|
|
1056
|
+
SECURITY DEFINER
|
|
1057
|
+
SET search_path TO 'public'
|
|
1058
|
+
AS $function$
|
|
1059
|
+
BEGIN
|
|
1060
|
+
PERFORM public.klanten_toegang('beheerder');
|
|
1061
|
+
RETURN public.klanten_ensure_cron(p_alleen_bijwerken => false);
|
|
1062
|
+
END;
|
|
1063
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.klanten_ensure_cron() RETURNS jsonb LANGUAGE plpgsql SECURITY DEFI');
|
|
1025
1064
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klanten_install_check()
|
|
1026
1065
|
RETURNS jsonb
|
|
1027
1066
|
LANGUAGE plpgsql
|
|
@@ -1039,7 +1078,7 @@ BEGIN
|
|
|
1039
1078
|
'import_floriday_delivery_locations','refresh_external_customers_grouped','enqueue_twinfield_push'] LOOP
|
|
1040
1079
|
IF NOT EXISTS (SELECT 1 FROM pg_proc WHERE proname=_o AND pronamespace='public'::regnamespace) THEN _missing := _missing || (_o||'()'); END IF;
|
|
1041
1080
|
END LOOP;
|
|
1042
|
-
FOR _r IN SELECT v.naam, v.niveau, p.oid AS oid, p.prosrc FROM (VALUES ('import_floriday_delivery_locations','ingelogd'),('next_twinfield_code','ingelogd'),('refresh_floriday_delivery_locations','ingelogd'),('reorder_customer_price_groups','ingelogd'),('retry_twinfield_push','ingelogd'),('set_primary_delivery_location','ingelogd'),('sync_floriday_prices_into_price_groups','ingelogd'),('klanten_auto_promote_status','ingelogd'),('klanten_refresh_grouped_if_stale','ingelogd'),('floriday_effective_price','ingelogd'),('has_twinfield_link','ingelogd'),('local_effective_price','ingelogd'),('refresh_external_customers_grouped','ingelogd'),('floriday_customer_candidates','ingelogd'),('floriday_customer_promotion_preview','ingelogd'),('klanten_install_check','ingelogd'),('schedule_floriday_network_sync','beheerder'),('klanten_set_auto_promote','beheerder'),('klanten_promote_round','beheerder'),('promote_floriday_customer','beheerder'),('run_twinfield_queue_tick','server'),('twinfield_sync_apply','server'),('twinfield_sync_insert','server'),('twinfield_sync_mark_missing','server'),('promote_floriday_order_customers','server'),('klanten_correctie_landcodes','server'),('customer_soft_key','open'),('server_now','open'),('klanten_is_server','open'),('klanten_toegang','open'),('klanten_landnaam_kandidaten','open'),('enqueue_twinfield_push','trigger'),('log_customer_changes','trigger'),('tg_customer_price_groups_touch','trigger'),('trg_floriday_delivery_location_import','trigger'),('trg_refresh_external_customers_grouped','trigger'),('validate_twinfield_required_fields','trigger')) v(naam, niveau)
|
|
1081
|
+
FOR _r IN SELECT v.naam, v.niveau, p.oid AS oid, p.prosrc FROM (VALUES ('import_floriday_delivery_locations','ingelogd'),('next_twinfield_code','ingelogd'),('refresh_floriday_delivery_locations','ingelogd'),('reorder_customer_price_groups','ingelogd'),('retry_twinfield_push','ingelogd'),('set_primary_delivery_location','ingelogd'),('sync_floriday_prices_into_price_groups','ingelogd'),('klanten_auto_promote_status','ingelogd'),('klanten_refresh_grouped_if_stale','ingelogd'),('floriday_effective_price','ingelogd'),('has_twinfield_link','ingelogd'),('local_effective_price','ingelogd'),('refresh_external_customers_grouped','ingelogd'),('floriday_customer_candidates','ingelogd'),('floriday_customer_promotion_preview','ingelogd'),('klanten_install_check','ingelogd'),('schedule_floriday_network_sync','beheerder'),('klanten_set_auto_promote','beheerder'),('klanten_promote_round','beheerder'),('promote_floriday_customer','beheerder'),('klanten_ensure_cron','beheerder'),('run_twinfield_queue_tick','server'),('twinfield_sync_apply','server'),('twinfield_sync_insert','server'),('twinfield_sync_mark_missing','server'),('promote_floriday_order_customers','server'),('klanten_correctie_landcodes','server'),('customer_soft_key','open'),('server_now','open'),('klanten_is_server','open'),('klanten_toegang','open'),('klanten_landnaam_kandidaten','open'),('enqueue_twinfield_push','trigger'),('log_customer_changes','trigger'),('tg_customer_price_groups_touch','trigger'),('trg_floriday_delivery_location_import','trigger'),('trg_refresh_external_customers_grouped','trigger'),('validate_twinfield_required_fields','trigger')) v(naam, niveau)
|
|
1043
1082
|
LEFT JOIN pg_proc p ON p.proname = v.naam AND p.pronamespace = 'public'::regnamespace ORDER BY v.niveau, v.naam LOOP
|
|
1044
1083
|
_f := _f || jsonb_build_object('functie', _r.naam, 'niveau',
|
|
1045
1084
|
CASE _r.niveau WHEN 'open' THEN 'bewust open (hulpfunctie zonder gegevens)'
|
|
@@ -1062,7 +1101,18 @@ BEGIN
|
|
|
1062
1101
|
_p := _p || jsonb_build_object('policy', split_part(_o,'|',1), 'tabel', split_part(_o,'|',2),
|
|
1063
1102
|
'aanwezig', EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND policyname = split_part(_o,'|',1) AND tablename = split_part(_o,'|',2)));
|
|
1064
1103
|
END LOOP;
|
|
1065
|
-
|
|
1104
|
+
_o := NULL;
|
|
1105
|
+
IF to_regclass('cron.job') IS NOT NULL THEN
|
|
1106
|
+
EXECUTE 'SELECT command FROM cron.job WHERE jobname = ''klanten-twinfield-push-queue'' LIMIT 1' INTO _o;
|
|
1107
|
+
END IF;
|
|
1108
|
+
_res := jsonb_build_object('Klanten: Twinfield-pushjob wijst naar deze shell', jsonb_build_object(
|
|
1109
|
+
'ok', _o IS NOT NULL AND _o ILIKE '%flowselections_cron_post(''/api/public/twinfield/run-queue''%' AND _o NOT ILIKE '%https://%',
|
|
1110
|
+
'reden', CASE WHEN to_regclass('cron.job') IS NULL THEN 'geen pg_cron'
|
|
1111
|
+
WHEN _o IS NULL THEN 'job ontbreekt; roep klanten_ensure_cron() aan'
|
|
1112
|
+
WHEN _o ILIKE '%https://%' THEN 'vaste host; roep klanten_ensure_cron() aan'
|
|
1113
|
+
WHEN _o NOT ILIKE '%flowselections_cron_post(''/api/public/twinfield/run-queue''%' THEN 'ander commando; roep klanten_ensure_cron() aan'
|
|
1114
|
+
ELSE 'in orde' END));
|
|
1115
|
+
_res := _res || jsonb_build_object('ontbreekt', to_jsonb(_missing),
|
|
1066
1116
|
'cron_promote', EXISTS (SELECT 1 FROM pg_extension WHERE extname='pg_cron'),
|
|
1067
1117
|
'functies', _f, 'triggers', _t, 'policies', _p,
|
|
1068
1118
|
'functies_zonder_controle', (SELECT COALESCE(jsonb_agg(x->>'functie'), '[]'::jsonb) FROM jsonb_array_elements(_f) x WHERE (x->>'interne_controle') = 'false'),
|