@flowselections/floriday-verkoop-module 1.0.57 → 1.0.58
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/verkoop/AnalyticsCards.d.ts +1 -1
- package/dist-lib/components/verkoop/AnalyticsCards.d.ts.map +1 -1
- package/dist-lib/components/verkoop/AutoFulfillmentStatusCard.d.ts +1 -1
- package/dist-lib/components/verkoop/AutoFulfillmentStatusCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/CartAssignmentWizard.d.ts +1 -1
- package/dist-lib/components/verkoop/CartAssignmentWizard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/CreateOrderPage.d.ts +1 -1
- package/dist-lib/components/verkoop/CreateOrderPage.d.ts.map +1 -1
- package/dist-lib/components/verkoop/DiagnoseConnectionDialog.d.ts +1 -1
- package/dist-lib/components/verkoop/DiagnoseConnectionDialog.d.ts.map +1 -1
- package/dist-lib/components/verkoop/EditLocalOrderDialog.d.ts +1 -1
- package/dist-lib/components/verkoop/EditLocalOrderDialog.d.ts.map +1 -1
- package/dist-lib/components/verkoop/EngineBufferCard.d.ts +1 -1
- package/dist-lib/components/verkoop/EngineBufferCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/InvoiceTimingSettings.d.ts +1 -1
- package/dist-lib/components/verkoop/InvoiceTimingSettings.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderAfleverbrievenCard.d.ts +1 -1
- package/dist-lib/components/verkoop/OrderAfleverbrievenCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderCarrierPicker.d.ts +1 -1
- package/dist-lib/components/verkoop/OrderCarrierPicker.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderControlStatusCard.d.ts +1 -1
- package/dist-lib/components/verkoop/OrderControlStatusCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderKarindelingCard.d.ts +1 -1
- package/dist-lib/components/verkoop/OrderKarindelingCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderPickupMomentPicker.d.ts +1 -1
- package/dist-lib/components/verkoop/OrderPickupMomentPicker.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderShipmentsCard.d.ts +1 -1
- package/dist-lib/components/verkoop/OrderShipmentsCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/SalesOrderDetailPage.d.ts +1 -1
- package/dist-lib/components/verkoop/SalesOrderDetailPage.d.ts.map +1 -1
- package/dist-lib/components/verkoop/SalesOrderDetailPage.js +6 -6
- package/dist-lib/components/verkoop/SalesOrderDetailView.d.ts +1 -1
- package/dist-lib/components/verkoop/SalesOrderDetailView.d.ts.map +1 -1
- package/dist-lib/components/verkoop/SalesOrdersFilterPanel.d.ts +1 -1
- package/dist-lib/components/verkoop/SalesOrdersFilterPanel.d.ts.map +1 -1
- package/dist-lib/components/verkoop/SalesOrdersFilters.d.ts +1 -1
- package/dist-lib/components/verkoop/SalesOrdersFilters.d.ts.map +1 -1
- package/dist-lib/components/verkoop/SalesOrdersTable.d.ts +2 -1
- package/dist-lib/components/verkoop/SalesOrdersTable.d.ts.map +1 -1
- package/dist-lib/components/verkoop/SearchableSelect.d.ts +1 -1
- package/dist-lib/components/verkoop/SearchableSelect.d.ts.map +1 -1
- package/dist-lib/components/verkoop/StockConsumptionAlertsBanner.d.ts +1 -1
- package/dist-lib/components/verkoop/StockConsumptionAlertsBanner.d.ts.map +1 -1
- package/dist-lib/components/verkoop/VerkoopOrdersPage.d.ts +1 -1
- package/dist-lib/components/verkoop/VerkoopOrdersPage.d.ts.map +1 -1
- package/dist-lib/components/verkoop/WeekCalendar.d.ts +1 -1
- package/dist-lib/components/verkoop/WeekCalendar.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/auth-middleware.d.ts +252 -0
- package/dist-lib/integrations/supabase/auth-middleware.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/client.d.ts +252 -0
- package/dist-lib/integrations/supabase/client.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/client.js +1 -1
- package/dist-lib/integrations/supabase/client.server.d.ts +252 -0
- package/dist-lib/integrations/supabase/client.server.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/client.server.js +1 -1
- package/dist-lib/integrations/supabase/types.d.ts +252 -0
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/cart-lock.functions.d.ts +252 -0
- package/dist-lib/lib/cart-lock.functions.d.ts.map +1 -1
- package/dist-lib/lib/cart-planning-settings.functions.d.ts +2772 -0
- package/dist-lib/lib/cart-planning-settings.functions.d.ts.map +1 -1
- package/dist-lib/lib/cart-replan.functions.d.ts +756 -0
- package/dist-lib/lib/cart-replan.functions.d.ts.map +1 -1
- package/dist-lib/lib/create-order.functions.d.ts +4284 -0
- package/dist-lib/lib/create-order.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-auto-fulfillment.functions.d.ts +756 -0
- package/dist-lib/lib/floriday-auto-fulfillment.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-logistic-labels.functions.d.ts +504 -0
- package/dist-lib/lib/floriday-logistic-labels.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-mirror.functions.d.ts +252 -0
- package/dist-lib/lib/floriday-mirror.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-public.functions.d.ts +1764 -0
- package/dist-lib/lib/floriday-public.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-writes.functions.d.ts +1260 -0
- package/dist-lib/lib/floriday-writes.functions.d.ts.map +1 -1
- package/dist-lib/lib/invoice-timing.functions.d.ts +1008 -0
- package/dist-lib/lib/invoice-timing.functions.d.ts.map +1 -1
- package/dist-lib/lib/load-carriers.functions.d.ts +252 -0
- package/dist-lib/lib/load-carriers.functions.d.ts.map +1 -1
- package/dist-lib/lib/logistics-engine.functions.d.ts +1275 -5
- package/dist-lib/lib/logistics-engine.functions.d.ts.map +1 -1
- package/dist-lib/lib/logistics-stock.functions.d.ts +504 -0
- package/dist-lib/lib/logistics-stock.functions.d.ts.map +1 -1
- package/dist-lib/lib/order-addresses.functions.d.ts +252 -0
- package/dist-lib/lib/order-addresses.functions.d.ts.map +1 -1
- package/dist-lib/lib/order-buffers.functions.d.ts +756 -0
- package/dist-lib/lib/order-buffers.functions.d.ts.map +1 -1
- package/dist-lib/lib/order-carrier.functions.d.ts +504 -0
- package/dist-lib/lib/order-carrier.functions.d.ts.map +1 -1
- package/dist-lib/lib/order-pickup.functions.d.ts +504 -0
- package/dist-lib/lib/order-pickup.functions.d.ts.map +1 -1
- package/dist-lib/lib/order-shipments.functions.d.ts +1008 -0
- package/dist-lib/lib/order-shipments.functions.d.ts.map +1 -1
- package/dist-lib/lib/salesorders-list.functions.d.ts +252 -0
- package/dist-lib/lib/salesorders-list.functions.d.ts.map +1 -1
- package/dist-lib/lib/salesorders.functions.d.ts +1260 -0
- package/dist-lib/lib/salesorders.functions.d.ts.map +1 -1
- package/dist-lib/lib/stock-consumption-alerts.functions.d.ts +504 -0
- package/dist-lib/lib/stock-consumption-alerts.functions.d.ts.map +1 -1
- package/dist-lib/lib/tradeitems.functions.d.ts +252 -0
- package/dist-lib/lib/tradeitems.functions.d.ts.map +1 -1
- package/dist-lib/lib/useSalesOrderDetailQuery.d.ts +1 -1
- package/dist-lib/lib/useSalesOrderDetailQuery.d.ts.map +1 -1
- package/dist-lib/lib/useSalesOrdersQuery.d.ts +1 -1
- package/dist-lib/lib/useSalesOrdersQuery.d.ts.map +1 -1
- package/package.json +131 -131
- package/dist-lib/components/floriday/FlorydaySyncHealthBanner.d.ts +0 -9
- package/dist-lib/components/floriday/FlorydaySyncHealthBanner.d.ts.map +0 -1
- package/dist-lib/components/floriday/FlorydaySyncHealthBanner.js +0 -26
- package/dist-lib/components/karindeling/AfmetingenTab.d.ts +0 -6
- package/dist-lib/components/karindeling/AfmetingenTab.d.ts.map +0 -1
- package/dist-lib/components/karindeling/AfmetingenTab.js +0 -128
- package/dist-lib/components/karindeling/KarindelingPage.d.ts +0 -2
- package/dist-lib/components/karindeling/KarindelingPage.d.ts.map +0 -1
- package/dist-lib/components/karindeling/KarindelingPage.js +0 -102
- package/dist-lib/components/ui/dropdown-menu.d.ts +0 -9
- package/dist-lib/components/ui/dropdown-menu.d.ts.map +0 -1
- package/dist-lib/components/ui/dropdown-menu.js +0 -14
- package/dist-lib/components/verkoop/CreateOrderDialog.d.ts +0 -5
- package/dist-lib/components/verkoop/CreateOrderDialog.d.ts.map +0 -1
- package/dist-lib/components/verkoop/CreateOrderDialog.js +0 -33
- package/dist-lib/lib/floriday/floriday.server.d.ts +0 -14
- package/dist-lib/lib/floriday/floriday.server.d.ts.map +0 -1
- package/dist-lib/lib/floriday/floriday.server.js +0 -92
- package/dist-lib/lib/floriday/sales-orders.functions.d.ts +0 -4736
- package/dist-lib/lib/floriday/sales-orders.functions.d.ts.map +0 -1
- package/dist-lib/lib/floriday/sales-orders.functions.js +0 -193
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
5
|
-
import { cn } from "@flowselections/core";
|
|
6
|
-
const DropdownMenu = DropdownMenuPrimitive.Root;
|
|
7
|
-
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
|
|
8
|
-
const DropdownMenuContent = React.forwardRef(({ className, sideOffset = 4, ...props }, ref) => (_jsx(DropdownMenuPrimitive.Portal, { children: _jsx(DropdownMenuPrimitive.Content, { ref: ref, sideOffset: sideOffset, className: cn("z-50 min-w-[10rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md", "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0", className), ...props }) })));
|
|
9
|
-
DropdownMenuContent.displayName = "DropdownMenuContent";
|
|
10
|
-
const DropdownMenuItem = React.forwardRef(({ className, ...props }, ref) => (_jsx(DropdownMenuPrimitive.Item, { ref: ref, className: cn("relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors", "focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className), ...props })));
|
|
11
|
-
DropdownMenuItem.displayName = "DropdownMenuItem";
|
|
12
|
-
const DropdownMenuSeparator = React.forwardRef(({ className, ...props }, ref) => (_jsx(DropdownMenuPrimitive.Separator, { ref: ref, className: cn("-mx-1 my-1 h-px bg-muted", className), ...props })));
|
|
13
|
-
DropdownMenuSeparator.displayName = "DropdownMenuSeparator";
|
|
14
|
-
export { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CreateOrderDialog.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/CreateOrderDialog.tsx"],"names":[],"mappings":"AAiBA,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,YAAY,GACb,EAAE;IACD,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACpC,2CAgFA"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import { Button, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, Input, Label, toast, } from "@flowselections/core";
|
|
4
|
-
import { useServerFn } from "@tanstack/react-start";
|
|
5
|
-
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
6
|
-
import { createSalesOrder } from "../../lib/floriday/sales-orders.functions";
|
|
7
|
-
export function CreateOrderDialog({ open, onOpenChange, }) {
|
|
8
|
-
const queryClient = useQueryClient();
|
|
9
|
-
const createFn = useServerFn(createSalesOrder);
|
|
10
|
-
const [customerOrganizationId, setCustomerId] = useState("");
|
|
11
|
-
const [tradeItemId, setTradeItemId] = useState("");
|
|
12
|
-
const [deliveryDateTime, setDelivery] = useState("");
|
|
13
|
-
const [numberOfPieces, setPieces] = useState(1);
|
|
14
|
-
const [pricePerPiece, setPrice] = useState(0);
|
|
15
|
-
const [reference, setReference] = useState("");
|
|
16
|
-
const m = useMutation({
|
|
17
|
-
mutationFn: createFn,
|
|
18
|
-
onSuccess: () => {
|
|
19
|
-
toast.success("Verkooporder aangemaakt");
|
|
20
|
-
queryClient.invalidateQueries({ queryKey: ["floriday", "sales-orders"] });
|
|
21
|
-
onOpenChange(false);
|
|
22
|
-
},
|
|
23
|
-
onError: (e) => toast.error(e?.message ?? "Aanmaken mislukt"),
|
|
24
|
-
});
|
|
25
|
-
return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { className: "max-w-lg", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: "Bestelling aanmaken" }), _jsx(DialogDescription, { children: "Maak een nieuwe verkooporder aan in Floriday." })] }), _jsxs("div", { className: "grid gap-3 py-2", children: [_jsxs("div", { className: "grid gap-1.5", children: [_jsx(Label, { htmlFor: "ref", children: "Referentie" }), _jsx(Input, { id: "ref", value: reference, onChange: (e) => setReference(e.target.value), placeholder: "ORD-2026-\u2026" })] }), _jsxs("div", { className: "grid gap-1.5", children: [_jsx(Label, { htmlFor: "cust", children: "Klant organisatie ID" }), _jsx(Input, { id: "cust", value: customerOrganizationId, onChange: (e) => setCustomerId(e.target.value), placeholder: "GLN of organization id" })] }), _jsxs("div", { className: "grid gap-1.5", children: [_jsx(Label, { htmlFor: "item", children: "Artikel (tradeItemId)" }), _jsx(Input, { id: "item", value: tradeItemId, onChange: (e) => setTradeItemId(e.target.value) })] }), _jsxs("div", { className: "grid grid-cols-3 gap-3", children: [_jsxs("div", { className: "grid gap-1.5", children: [_jsx(Label, { htmlFor: "qty", children: "Aantal stuks" }), _jsx(Input, { id: "qty", type: "number", min: 1, value: numberOfPieces, onChange: (e) => setPieces(Number(e.target.value)) })] }), _jsxs("div", { className: "grid gap-1.5", children: [_jsx(Label, { htmlFor: "price", children: "Prijs/stuk (\u20AC)" }), _jsx(Input, { id: "price", type: "number", step: "0.01", min: 0, value: pricePerPiece, onChange: (e) => setPrice(Number(e.target.value)) })] }), _jsxs("div", { className: "grid gap-1.5", children: [_jsx(Label, { htmlFor: "del", children: "Levering" }), _jsx(Input, { id: "del", type: "datetime-local", value: deliveryDateTime, onChange: (e) => setDelivery(e.target.value) })] })] })] }), _jsxs(DialogFooter, { children: [_jsx(Button, { variant: "outline", onClick: () => onOpenChange(false), disabled: m.isPending, children: "Annuleren" }), _jsx(Button, { onClick: () => m.mutate({
|
|
26
|
-
data: {
|
|
27
|
-
customerOrganizationId,
|
|
28
|
-
deliveryDateTime: deliveryDateTime ? new Date(deliveryDateTime).toISOString() : "",
|
|
29
|
-
reference: reference || undefined,
|
|
30
|
-
lines: [{ tradeItemId, numberOfPieces, pricePerPiece }],
|
|
31
|
-
},
|
|
32
|
-
}), disabled: m.isPending || !customerOrganizationId || !tradeItemId || !deliveryDateTime, children: m.isPending ? "Aanmaken…" : "Aanmaken" })] })] }) }));
|
|
33
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export interface FlorIdayConn {
|
|
2
|
-
id: string;
|
|
3
|
-
environment: "staging" | "production" | string;
|
|
4
|
-
client_id: string;
|
|
5
|
-
client_secret: string;
|
|
6
|
-
api_key: string;
|
|
7
|
-
access_token: string | null;
|
|
8
|
-
token_expires_at: string | null;
|
|
9
|
-
organization_name: string | null;
|
|
10
|
-
gln_code: string | null;
|
|
11
|
-
}
|
|
12
|
-
export declare function getActiveConnection(): Promise<FlorIdayConn>;
|
|
13
|
-
export declare function florIdayFetch<T = unknown>(path: string, init?: RequestInit): Promise<T>;
|
|
14
|
-
//# sourceMappingURL=floriday.server.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"floriday.server.d.ts","sourceRoot":"","sources":["../../../src/lib/floriday/floriday.server.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,SAAS,GAAG,YAAY,GAAG,MAAM,CAAC;IAC/C,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAiBD,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,YAAY,CAAC,CAsBjE;AAqCD,wBAAsB,aAAa,CAAC,CAAC,GAAG,OAAO,EAC7C,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,WAAgB,GACrB,OAAO,CAAC,CAAC,CAAC,CAoBZ"}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// Floriday Suppliers API client (server-only)
|
|
2
|
-
import { supabaseAdmin } from "../../integrations/supabase/client.server";
|
|
3
|
-
function endpoints(env) {
|
|
4
|
-
const isProd = env === "production" || env === "prod";
|
|
5
|
-
return {
|
|
6
|
-
auth: isProd
|
|
7
|
-
? "https://accounts.floriday.io/oauth/token"
|
|
8
|
-
: "https://accounts.staging.floriday.io/oauth/token",
|
|
9
|
-
audience: isProd
|
|
10
|
-
? "https://api.floriday.io"
|
|
11
|
-
: "https://api.staging.floriday.io",
|
|
12
|
-
api: isProd
|
|
13
|
-
? "https://api.floriday.io/suppliers-api-2026v1"
|
|
14
|
-
: "https://api.staging.floriday.io/suppliers-api-2026v1",
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export async function getActiveConnection() {
|
|
18
|
-
const { data: settings } = await supabaseAdmin
|
|
19
|
-
.from("floriday_settings")
|
|
20
|
-
.select("active_environment")
|
|
21
|
-
.eq("id", 1)
|
|
22
|
-
.maybeSingle();
|
|
23
|
-
const env = settings?.active_environment ?? "staging";
|
|
24
|
-
const { data, error } = await supabaseAdmin
|
|
25
|
-
.from("floriday_connections")
|
|
26
|
-
.select("id,environment,client_id,client_secret,api_key,access_token,token_expires_at,organization_name,gln_code,is_active")
|
|
27
|
-
.eq("environment", env)
|
|
28
|
-
.eq("is_active", true)
|
|
29
|
-
.order("updated_at", { ascending: false })
|
|
30
|
-
.limit(1)
|
|
31
|
-
.maybeSingle();
|
|
32
|
-
if (error)
|
|
33
|
-
throw new Error(`Floriday connectie ophalen mislukt: ${error.message}`);
|
|
34
|
-
if (!data)
|
|
35
|
-
throw new Error(`Geen actieve Floriday connectie voor omgeving "${env}"`);
|
|
36
|
-
return data;
|
|
37
|
-
}
|
|
38
|
-
async function fetchToken(conn) {
|
|
39
|
-
const ep = endpoints(conn.environment);
|
|
40
|
-
const body = new URLSearchParams({
|
|
41
|
-
grant_type: "client_credentials",
|
|
42
|
-
client_id: conn.client_id,
|
|
43
|
-
client_secret: conn.client_secret,
|
|
44
|
-
audience: ep.audience,
|
|
45
|
-
});
|
|
46
|
-
const res = await fetch(ep.auth, {
|
|
47
|
-
method: "POST",
|
|
48
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
49
|
-
body,
|
|
50
|
-
});
|
|
51
|
-
const text = await res.text();
|
|
52
|
-
if (!res.ok) {
|
|
53
|
-
throw new Error(`Floriday OAuth fout [${res.status}]: ${text.slice(0, 300)}`);
|
|
54
|
-
}
|
|
55
|
-
const json = JSON.parse(text);
|
|
56
|
-
const token = json.access_token;
|
|
57
|
-
const expiresIn = json.expires_in ?? 3600;
|
|
58
|
-
const expiresAt = new Date(Date.now() + (expiresIn - 60) * 1000).toISOString();
|
|
59
|
-
await supabaseAdmin
|
|
60
|
-
.from("floriday_connections")
|
|
61
|
-
.update({ access_token: token, token_expires_at: expiresAt })
|
|
62
|
-
.eq("id", conn.id);
|
|
63
|
-
return { token, expiresAt };
|
|
64
|
-
}
|
|
65
|
-
async function ensureToken(conn) {
|
|
66
|
-
const exp = conn.token_expires_at ? new Date(conn.token_expires_at).getTime() : 0;
|
|
67
|
-
if (conn.access_token && exp > Date.now() + 60000)
|
|
68
|
-
return conn.access_token;
|
|
69
|
-
const { token } = await fetchToken(conn);
|
|
70
|
-
return token;
|
|
71
|
-
}
|
|
72
|
-
export async function florIdayFetch(path, init = {}) {
|
|
73
|
-
const conn = await getActiveConnection();
|
|
74
|
-
const token = await ensureToken(conn);
|
|
75
|
-
const ep = endpoints(conn.environment);
|
|
76
|
-
const url = path.startsWith("http") ? path : `${ep.api}${path}`;
|
|
77
|
-
const res = await fetch(url, {
|
|
78
|
-
...init,
|
|
79
|
-
headers: {
|
|
80
|
-
Accept: "application/json",
|
|
81
|
-
"Content-Type": "application/json",
|
|
82
|
-
Authorization: `Bearer ${token}`,
|
|
83
|
-
"x-api-key": conn.api_key,
|
|
84
|
-
...init.headers,
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
const text = await res.text();
|
|
88
|
-
if (!res.ok) {
|
|
89
|
-
throw new Error(`Floriday API ${res.status} ${path}: ${text.slice(0, 400)}`);
|
|
90
|
-
}
|
|
91
|
-
return (text ? JSON.parse(text) : null);
|
|
92
|
-
}
|