@flowselections/floriday-authenticatie-module 1.0.50 → 1.0.52
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/integrations/supabase/auth-middleware.d.ts +713 -6
- package/dist-lib/integrations/supabase/auth-middleware.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/client.server.d.ts +713 -6
- package/dist-lib/integrations/supabase/client.server.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/types.d.ts +729 -6
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/cron/index.d.ts +1 -0
- package/dist-lib/lib/cron/index.d.ts.map +1 -1
- package/dist-lib/lib/cron/index.js +1 -0
- package/dist-lib/lib/cron/retry-floriday-documents.d.ts +28 -0
- package/dist-lib/lib/cron/retry-floriday-documents.d.ts.map +1 -0
- package/dist-lib/lib/cron/retry-floriday-documents.js +220 -0
- package/dist-lib/lib/floricode.functions.d.ts +4991 -42
- package/dist-lib/lib/floricode.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-api-log.functions.d.ts +6417 -54
- package/dist-lib/lib/floriday-api-log.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-auction-letters.functions.d.ts +713 -6
- package/dist-lib/lib/floriday-auction-letters.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-auction-letters.functions.js +22 -0
- package/dist-lib/lib/floriday-document-queue.d.ts +21 -0
- package/dist-lib/lib/floriday-document-queue.d.ts.map +1 -0
- package/dist-lib/lib/floriday-document-queue.js +96 -0
- package/dist-lib/lib/floriday-labels.functions.d.ts +713 -6
- package/dist-lib/lib/floriday-labels.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-public.functions.d.ts +4278 -36
- package/dist-lib/lib/floriday-public.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-stickers.functions.d.ts +713 -6
- package/dist-lib/lib/floriday-stickers.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-stickers.functions.js +23 -0
- package/dist-lib/lib/floriday-sync.functions.d.ts +2 -2
- package/dist-lib/lib/floriday-sync.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-tray-stickers.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-tray-stickers.functions.js +21 -0
- package/dist-lib/lib/floriday-writes.functions.d.ts +5704 -48
- package/dist-lib/lib/floriday-writes.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday.functions.d.ts +15730 -440
- package/dist-lib/lib/floriday.functions.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -7,9 +7,31 @@
|
|
|
7
7
|
import { createServerFn } from "@tanstack/react-start";
|
|
8
8
|
import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware.js";
|
|
9
9
|
import { SUPPLIERS_API_VERSION, florydayFetch, getActiveFlorydayCredentials, getActiveFlorydayEnvironment, } from "./floriday.functions.js";
|
|
10
|
+
import { enqueueDocumentRetry, markDocumentDone } from "./floriday-document-queue.js";
|
|
10
11
|
const BUCKET = "floriday-auction-letters";
|
|
11
12
|
const SIGNED_URL_TTL_S = 60 * 60;
|
|
13
|
+
/** Ophalen met automatische herhaalpoging bij mislukken (documentwachtrij). */
|
|
12
14
|
async function ensureAuctionLetterInStorage(supabase, env, connectionId, clockSupplyId, auctionLetterCode) {
|
|
15
|
+
const documentKey = `${clockSupplyId}:${auctionLetterCode ?? ""}`;
|
|
16
|
+
try {
|
|
17
|
+
const out = await fetchAuctionLetterToStorage(supabase, env, connectionId, clockSupplyId, auctionLetterCode);
|
|
18
|
+
await markDocumentDone(supabase, connectionId, "auction-letter", documentKey);
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
await enqueueDocumentRetry(supabase, {
|
|
23
|
+
connectionId,
|
|
24
|
+
environment: env,
|
|
25
|
+
kind: "auction-letter",
|
|
26
|
+
documentKey,
|
|
27
|
+
params: { clockSupplyId, auctionLetterCode },
|
|
28
|
+
orderRef: clockSupplyId,
|
|
29
|
+
error: e,
|
|
30
|
+
});
|
|
31
|
+
throw e;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function fetchAuctionLetterToStorage(supabase, env, connectionId, clockSupplyId, auctionLetterCode) {
|
|
13
35
|
let q = supabase
|
|
14
36
|
.from("floriday_auction_letters_cache")
|
|
15
37
|
.select("storage_path, auction_letter_code, content_type")
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import type { FlorydayEnvironment } from "./floriday.functions.js";
|
|
3
|
+
export type DocumentQueueKind = "customer-sticker" | "auction-letter" | "tray-stickers";
|
|
4
|
+
export declare const DOCUMENT_QUEUE_TABLE = "floriday_document_fetch_queue";
|
|
5
|
+
export declare const DOCUMENT_QUEUE_MAX_ATTEMPTS = 6;
|
|
6
|
+
/** Wachttijd na poging n (1-based), in minuten. */
|
|
7
|
+
export declare const DOCUMENT_QUEUE_BACKOFF_MIN: number[];
|
|
8
|
+
export interface EnqueueInput {
|
|
9
|
+
connectionId: string;
|
|
10
|
+
environment: FlorydayEnvironment;
|
|
11
|
+
kind: DocumentQueueKind;
|
|
12
|
+
documentKey: string;
|
|
13
|
+
params: Record<string, unknown>;
|
|
14
|
+
orderRef?: string | null;
|
|
15
|
+
error: unknown;
|
|
16
|
+
}
|
|
17
|
+
/** HTTP-status uit een foutmelding als "Floriday … 404: …". */
|
|
18
|
+
export declare function httpStatusFromError(e: unknown): number | null;
|
|
19
|
+
export declare function enqueueDocumentRetry(supabase: SupabaseClient, input: EnqueueInput): Promise<void>;
|
|
20
|
+
export declare function markDocumentDone(supabase: SupabaseClient, connectionId: string, kind: DocumentQueueKind, documentKey: string): Promise<void>;
|
|
21
|
+
//# sourceMappingURL=floriday-document-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"floriday-document-queue.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-document-queue.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAEnE,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,eAAe,CAAC;AAExF,eAAO,MAAM,oBAAoB,kCAAkC,CAAC;AACpE,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAC7C,mDAAmD;AACnD,eAAO,MAAM,0BAA0B,UAA6B,CAAC;AAErE,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,mBAAmB,CAAC;IACjC,IAAI,EAAE,iBAAiB,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,+DAA+D;AAC/D,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAI7D;AA2BD,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,IAAI,CAAC,CAyBf;AAED,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,cAAc,EACxB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,iBAAiB,EACvB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CA4Bf"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Wachtrij voor automatische herhaalpogingen van Floriday-documenten.
|
|
3
|
+
// ----------------------------------------------------------------------------
|
|
4
|
+
// Alleen klantstickers, veilingbrieven en fuststickers. Verzendbrief en
|
|
5
|
+
// logistiek label horen bij de Logistiek Engine (daar zit een eigen
|
|
6
|
+
// herhaalpoging) — die worden hier bewust NIET in de wachtrij gezet.
|
|
7
|
+
//
|
|
8
|
+
// Mislukt een ophaalpoging, dan komt het document in
|
|
9
|
+
// `floriday_document_fetch_queue`. Een bestaande regel wordt NIET gereset
|
|
10
|
+
// (een mislukte handmatige poging start de teller dus niet opnieuw).
|
|
11
|
+
// De cron `retry-floriday-documents` pakt de regels op.
|
|
12
|
+
// ============================================================================
|
|
13
|
+
export const DOCUMENT_QUEUE_TABLE = "floriday_document_fetch_queue";
|
|
14
|
+
export const DOCUMENT_QUEUE_MAX_ATTEMPTS = 6;
|
|
15
|
+
/** Wachttijd na poging n (1-based), in minuten. */
|
|
16
|
+
export const DOCUMENT_QUEUE_BACKOFF_MIN = [5, 15, 60, 180, 360, 720];
|
|
17
|
+
/** HTTP-status uit een foutmelding als "Floriday … 404: …". */
|
|
18
|
+
export function httpStatusFromError(e) {
|
|
19
|
+
const msg = String(e?.message ?? e ?? "");
|
|
20
|
+
const m = msg.match(/\b([1-5]\d\d):/);
|
|
21
|
+
return m ? Number(m[1]) : null;
|
|
22
|
+
}
|
|
23
|
+
async function adminClient() {
|
|
24
|
+
try {
|
|
25
|
+
const mod = await import("../integrations/supabase/client.server.js");
|
|
26
|
+
return mod.supabaseAdmin;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Schrijfacties lopen via de service-role (gebruikers mogen alleen lezen). */
|
|
33
|
+
async function writeWith(supabase, op) {
|
|
34
|
+
const first = await op(supabase);
|
|
35
|
+
if (!first.error)
|
|
36
|
+
return;
|
|
37
|
+
const admin = await adminClient();
|
|
38
|
+
if (!admin || admin === supabase) {
|
|
39
|
+
console.warn(`[document-queue] schrijven mislukt: ${first.error.message}`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const second = await op(admin);
|
|
43
|
+
if (second.error)
|
|
44
|
+
console.warn(`[document-queue] schrijven mislukt: ${second.error.message}`);
|
|
45
|
+
}
|
|
46
|
+
export async function enqueueDocumentRetry(supabase, input) {
|
|
47
|
+
try {
|
|
48
|
+
const msg = String(input.error?.message ?? input.error ?? "Onbekende fout");
|
|
49
|
+
await writeWith(supabase, (sb) => sb.from(DOCUMENT_QUEUE_TABLE).upsert({
|
|
50
|
+
connection_id: input.connectionId,
|
|
51
|
+
environment: input.environment,
|
|
52
|
+
kind: input.kind,
|
|
53
|
+
document_key: input.documentKey,
|
|
54
|
+
params: input.params,
|
|
55
|
+
order_ref: input.orderRef ?? null,
|
|
56
|
+
status: "pending",
|
|
57
|
+
attempts: 0,
|
|
58
|
+
max_attempts: DOCUMENT_QUEUE_MAX_ATTEMPTS,
|
|
59
|
+
next_attempt_at: new Date(Date.now() + DOCUMENT_QUEUE_BACKOFF_MIN[0] * 60000).toISOString(),
|
|
60
|
+
last_error: msg.slice(0, 1000),
|
|
61
|
+
last_http_status: httpStatusFromError(input.error),
|
|
62
|
+
}, { onConflict: "connection_id,kind,document_key", ignoreDuplicates: true }));
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
console.warn(`[document-queue] enqueue mislukt: ${e?.message ?? e}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export async function markDocumentDone(supabase, connectionId, kind, documentKey) {
|
|
69
|
+
try {
|
|
70
|
+
// Snel pad: niets te doen als er geen open regel is (lezen mag iedereen).
|
|
71
|
+
const { data } = await supabase
|
|
72
|
+
.from(DOCUMENT_QUEUE_TABLE)
|
|
73
|
+
.select("id")
|
|
74
|
+
.eq("connection_id", connectionId)
|
|
75
|
+
.eq("kind", kind)
|
|
76
|
+
.eq("document_key", documentKey)
|
|
77
|
+
.neq("status", "done")
|
|
78
|
+
.limit(1);
|
|
79
|
+
if (!data || data.length === 0)
|
|
80
|
+
return;
|
|
81
|
+
await writeWith(supabase, (sb) => sb
|
|
82
|
+
.from(DOCUMENT_QUEUE_TABLE)
|
|
83
|
+
.update({
|
|
84
|
+
status: "done",
|
|
85
|
+
completed_at: new Date().toISOString(),
|
|
86
|
+
locked_at: null,
|
|
87
|
+
locked_by: null,
|
|
88
|
+
})
|
|
89
|
+
.eq("connection_id", connectionId)
|
|
90
|
+
.eq("kind", kind)
|
|
91
|
+
.eq("document_key", documentKey));
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
console.warn(`[document-queue] markDone mislukt: ${e?.message ?? e}`);
|
|
95
|
+
}
|
|
96
|
+
}
|