@flowselections/floriday-authenticatie-module 1.0.17 → 1.0.19
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/floriday/FlorydayConnectionPage.d.ts.map +1 -1
- package/dist-lib/components/floriday/FlorydayConnectionPage.js +2 -1
- package/dist-lib/components/settings/FloricodeSettingsCard.d.ts +2 -0
- package/dist-lib/components/settings/FloricodeSettingsCard.d.ts.map +1 -0
- package/dist-lib/components/settings/FloricodeSettingsCard.js +235 -0
- package/dist-lib/index.d.ts.map +1 -1
- package/dist-lib/index.js +2 -0
- package/dist-lib/integrations/supabase/auth-middleware.d.ts +524 -4
- package/dist-lib/integrations/supabase/auth-middleware.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/client.d.ts +524 -4
- package/dist-lib/integrations/supabase/client.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/client.server.d.ts +524 -4
- package/dist-lib/integrations/supabase/client.server.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/types.d.ts +532 -4
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/floricode-credentials.server.d.ts +21 -0
- package/dist-lib/lib/floricode-credentials.server.d.ts.map +1 -0
- package/dist-lib/lib/floricode-credentials.server.js +158 -0
- package/dist-lib/lib/floricode-product-features.d.ts.map +1 -1
- package/dist-lib/lib/floricode-product-features.js +19 -33
- package/dist-lib/lib/floricode-regulatory-features.d.ts.map +1 -1
- package/dist-lib/lib/floricode-regulatory-features.js +51 -41
- package/dist-lib/lib/floricode-sync.server.d.ts +35 -0
- package/dist-lib/lib/floricode-sync.server.d.ts.map +1 -0
- package/dist-lib/lib/floricode-sync.server.js +211 -0
- package/dist-lib/lib/floricode.functions.d.ts +78828 -0
- package/dist-lib/lib/floricode.functions.d.ts.map +1 -0
- package/dist-lib/lib/floricode.functions.js +178 -0
- package/dist-lib/lib/floriday-auction-letters.functions.d.ts +524 -4
- package/dist-lib/lib/floriday-auction-letters.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-auto-process.server.d.ts +34 -0
- package/dist-lib/lib/floriday-auto-process.server.d.ts.map +1 -0
- package/dist-lib/lib/floriday-auto-process.server.js +365 -0
- package/dist-lib/lib/floriday-fulfillment-lookup.server.d.ts +19 -0
- package/dist-lib/lib/floriday-fulfillment-lookup.server.d.ts.map +1 -0
- package/dist-lib/lib/floriday-fulfillment-lookup.server.js +130 -0
- package/dist-lib/lib/floriday-gateway-auth.d.ts +24 -0
- package/dist-lib/lib/floriday-gateway-auth.d.ts.map +1 -0
- package/dist-lib/lib/floriday-gateway-auth.js +127 -0
- package/dist-lib/lib/floriday-labels.functions.d.ts +524 -4
- package/dist-lib/lib/floriday-labels.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-labels.functions.js +3 -2
- package/dist-lib/lib/floriday-public.functions.d.ts +3144 -24
- package/dist-lib/lib/floriday-public.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-rate-limit.server.d.ts +21 -0
- package/dist-lib/lib/floriday-rate-limit.server.d.ts.map +1 -0
- package/dist-lib/lib/floriday-rate-limit.server.js +75 -0
- package/dist-lib/lib/floriday-stickers.functions.d.ts +524 -4
- package/dist-lib/lib/floriday-stickers.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-sync.functions.d.ts +17292 -132
- package/dist-lib/lib/floriday-sync.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-writes.functions.d.ts +3192 -48
- package/dist-lib/lib/floriday-writes.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-writes.functions.js +29 -4
- package/dist-lib/lib/floriday.functions.d.ts +9576 -198
- package/dist-lib/lib/floriday.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday.functions.js +39 -4
- package/dist-lib/lib/planning-helpers.d.ts +30 -0
- package/dist-lib/lib/planning-helpers.d.ts.map +1 -0
- package/dist-lib/lib/planning-helpers.js +62 -0
- package/package.json +3 -2
- package/public/flowselections-assets/floriday-authenticatie/floricode-logo.png +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
export interface RateLimitOptions {
|
|
3
|
+
bucket: string;
|
|
4
|
+
capacity: number;
|
|
5
|
+
refillPerSec: number;
|
|
6
|
+
cost?: number;
|
|
7
|
+
maxWaitMs?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Blokkeert tot er een token beschikbaar is, of gooit een Error als de
|
|
11
|
+
* limiet niet binnen `maxWaitMs` te halen is. Idempotent — het is veilig
|
|
12
|
+
* om vaker aan te roepen dan strikt nodig.
|
|
13
|
+
*/
|
|
14
|
+
export declare function acquireFlorydayRateLimit(supabase: SupabaseClient, opts: RateLimitOptions): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Voer `fn` uit onder de bucket. Bij een 429/`Retry-After` uit Floriday
|
|
17
|
+
* retryen we tot max 3 keer met de gevraagde delay (max 5s per stap).
|
|
18
|
+
*/
|
|
19
|
+
export declare function withFlorydayRateLimit<T>(supabase: SupabaseClient, opts: RateLimitOptions, fn: () => Promise<T>): Promise<T>;
|
|
20
|
+
export declare const LOGISTIC_LABELS_BUCKET: RateLimitOptions;
|
|
21
|
+
//# sourceMappingURL=floriday-rate-limit.server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"floriday-rate-limit.server.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-rate-limit.server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAMD;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC,IAAI,CAAC,CAkCf;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,CAAC,EAC3C,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,gBAAgB,EACtB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CAsBZ;AAED,eAAO,MAAM,sBAAsB,EAAE,gBAIpC,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Floriday rate-limit gate (token bucket in Postgres).
|
|
3
|
+
// ----------------------------------------------------------------------------
|
|
4
|
+
// Floriday-endpoints als /fulfillment-orders/{id}/logistic-labels hebben een
|
|
5
|
+
// harde limiet van 1 req/sec met burst 60. Bij bulk-printen willen we die
|
|
6
|
+
// limiet respecteren om 429's te vermijden. Deze helper vraagt atomair een
|
|
7
|
+
// token bij de RPC `consume_floriday_rate_limit` en slaapt zo nodig kort
|
|
8
|
+
// om binnen de limiet te blijven.
|
|
9
|
+
// ============================================================================
|
|
10
|
+
function sleep(ms) {
|
|
11
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Blokkeert tot er een token beschikbaar is, of gooit een Error als de
|
|
15
|
+
* limiet niet binnen `maxWaitMs` te halen is. Idempotent — het is veilig
|
|
16
|
+
* om vaker aan te roepen dan strikt nodig.
|
|
17
|
+
*/
|
|
18
|
+
export async function acquireFlorydayRateLimit(supabase, opts) {
|
|
19
|
+
const cost = opts.cost ?? 1;
|
|
20
|
+
const maxWaitMs = opts.maxWaitMs ?? 30000;
|
|
21
|
+
const deadline = Date.now() + maxWaitMs;
|
|
22
|
+
// eslint-disable-next-line no-constant-condition
|
|
23
|
+
while (true) {
|
|
24
|
+
const { data, error } = await supabase.rpc("consume_floriday_rate_limit", {
|
|
25
|
+
p_bucket: opts.bucket,
|
|
26
|
+
p_capacity: opts.capacity,
|
|
27
|
+
p_refill_per_sec: opts.refillPerSec,
|
|
28
|
+
p_cost: cost,
|
|
29
|
+
});
|
|
30
|
+
if (error) {
|
|
31
|
+
// Fallback: liever door dan hard falen als de RPC (tijdelijk) hapert.
|
|
32
|
+
console.warn(`[floriday-rate-limit] RPC-fout, sta call toe: ${error.message}`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const row = Array.isArray(data) ? data[0] : data;
|
|
36
|
+
if (row?.granted)
|
|
37
|
+
return;
|
|
38
|
+
const wait = Math.max(50, Math.min(2000, Number(row?.wait_ms ?? 1000)));
|
|
39
|
+
if (Date.now() + wait > deadline) {
|
|
40
|
+
throw new Error(`Rate-limit '${opts.bucket}' niet binnen ${maxWaitMs}ms beschikbaar`);
|
|
41
|
+
}
|
|
42
|
+
await sleep(wait);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Voer `fn` uit onder de bucket. Bij een 429/`Retry-After` uit Floriday
|
|
47
|
+
* retryen we tot max 3 keer met de gevraagde delay (max 5s per stap).
|
|
48
|
+
*/
|
|
49
|
+
export async function withFlorydayRateLimit(supabase, opts, fn) {
|
|
50
|
+
let attempt = 0;
|
|
51
|
+
// eslint-disable-next-line no-constant-condition
|
|
52
|
+
while (true) {
|
|
53
|
+
await acquireFlorydayRateLimit(supabase, opts);
|
|
54
|
+
try {
|
|
55
|
+
return await fn();
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
const msg = String(e?.message ?? e);
|
|
59
|
+
const retryAfterMatch = msg.match(/(?:^|\s)(?:429|rate)[^0-9]*?(\d+)\s*s/i);
|
|
60
|
+
const is429 = msg.includes("429") || /rate\s?limit|too many requests/i.test(msg);
|
|
61
|
+
attempt += 1;
|
|
62
|
+
if (!is429 || attempt >= 3)
|
|
63
|
+
throw e;
|
|
64
|
+
const waitS = retryAfterMatch ? Number(retryAfterMatch[1]) : 1;
|
|
65
|
+
const waitMs = Math.min(5000, Math.max(500, waitS * 1000));
|
|
66
|
+
console.warn(`[floriday-rate-limit] 429 op '${opts.bucket}', wacht ${waitMs}ms (poging ${attempt})`);
|
|
67
|
+
await sleep(waitMs);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export const LOGISTIC_LABELS_BUCKET = {
|
|
72
|
+
bucket: "floriday:logistic-labels",
|
|
73
|
+
capacity: 60,
|
|
74
|
+
refillPerSec: 1,
|
|
75
|
+
};
|