@omnizoek/react 0.1.0
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/index.cjs +210 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +223 -0
- package/dist/index.d.ts +223 -0
- package/dist/index.js +166 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
OmniProvider: () => OmniProvider,
|
|
34
|
+
useAddressEnrich: () => useAddressEnrich,
|
|
35
|
+
useEmissionZone: () => useEmissionZone,
|
|
36
|
+
useEnergyLabel: () => useEnergyLabel,
|
|
37
|
+
useGridTrigger: () => useGridTrigger,
|
|
38
|
+
useHolidaySurcharge: () => useHolidaySurcharge,
|
|
39
|
+
useIbanToBic: () => useIbanToBic,
|
|
40
|
+
useMinimumWage: () => useMinimumWage,
|
|
41
|
+
useOmniClient: () => useOmniClient,
|
|
42
|
+
useTransitDisruptions: () => useTransitDisruptions,
|
|
43
|
+
useValidateFinance: () => useValidateFinance,
|
|
44
|
+
useVatVerify: () => useVatVerify
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(index_exports);
|
|
47
|
+
|
|
48
|
+
// src/context.tsx
|
|
49
|
+
var import_react = require("react");
|
|
50
|
+
var import_sdk = require("@omnizoek/sdk");
|
|
51
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
52
|
+
var OmniContext = (0, import_react.createContext)(null);
|
|
53
|
+
function OmniProvider({
|
|
54
|
+
apiKey,
|
|
55
|
+
baseUrl,
|
|
56
|
+
options,
|
|
57
|
+
children
|
|
58
|
+
}) {
|
|
59
|
+
const client = (0, import_react.useMemo)(
|
|
60
|
+
() => new import_sdk.OmniClient({ apiKey, baseUrl, ...options }),
|
|
61
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62
|
+
[apiKey, baseUrl]
|
|
63
|
+
);
|
|
64
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OmniContext.Provider, { value: client, children });
|
|
65
|
+
}
|
|
66
|
+
function useOmniClient() {
|
|
67
|
+
const client = (0, import_react.useContext)(OmniContext);
|
|
68
|
+
if (!client) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
'[OmniZoek] useOmniClient must be called inside an <OmniProvider>. Wrap your app or component tree with <OmniProvider apiKey="...">.'
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return client;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/hooks/useOmniQuery.ts
|
|
77
|
+
var import_swr = __toESM(require("swr"), 1);
|
|
78
|
+
function useOmniQuery(endpointKey, params, fetcher, options) {
|
|
79
|
+
const client = useOmniClient();
|
|
80
|
+
const isEnabled = options?.enabled !== false;
|
|
81
|
+
const swrKey = isEnabled && params != null ? [endpointKey, params] : null;
|
|
82
|
+
const { data, error, isLoading, isValidating, mutate } = (0, import_swr.default)(
|
|
83
|
+
swrKey,
|
|
84
|
+
([, p]) => fetcher(client, p),
|
|
85
|
+
{ shouldRetryOnError: false }
|
|
86
|
+
);
|
|
87
|
+
return {
|
|
88
|
+
data,
|
|
89
|
+
loading: isLoading,
|
|
90
|
+
validating: isValidating,
|
|
91
|
+
error: error ?? null,
|
|
92
|
+
refetch: () => mutate()
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/hooks/useAddressEnrich.ts
|
|
97
|
+
function useAddressEnrich(params, options) {
|
|
98
|
+
return useOmniQuery(
|
|
99
|
+
"geo.enrichAddress",
|
|
100
|
+
params,
|
|
101
|
+
(client, p) => client.geo.enrichAddress(p),
|
|
102
|
+
options
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/hooks/useIbanToBic.ts
|
|
107
|
+
function useIbanToBic(params, options) {
|
|
108
|
+
return useOmniQuery(
|
|
109
|
+
"finance.ibanToBic",
|
|
110
|
+
params,
|
|
111
|
+
(client, p) => client.finance.ibanToBic(p),
|
|
112
|
+
options
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/hooks/useVatVerify.ts
|
|
117
|
+
function useVatVerify(params, options) {
|
|
118
|
+
return useOmniQuery(
|
|
119
|
+
"finance.vatVerify",
|
|
120
|
+
params,
|
|
121
|
+
(client, p) => client.finance.vatVerify(p),
|
|
122
|
+
options
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/hooks/useValidateFinance.ts
|
|
127
|
+
function useValidateFinance(params, options) {
|
|
128
|
+
return useOmniQuery(
|
|
129
|
+
"compliance.validateFinance",
|
|
130
|
+
params,
|
|
131
|
+
(client, p) => client.compliance.validateFinance(p),
|
|
132
|
+
options
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/hooks/useMinimumWage.ts
|
|
137
|
+
function useMinimumWage(params, options) {
|
|
138
|
+
return useOmniQuery(
|
|
139
|
+
"hr.minimumWage",
|
|
140
|
+
params,
|
|
141
|
+
(client, p) => client.hr.minimumWage(p),
|
|
142
|
+
options
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/hooks/useHolidaySurcharge.ts
|
|
147
|
+
function useHolidaySurcharge(params, options) {
|
|
148
|
+
return useOmniQuery(
|
|
149
|
+
"hr.holidaySurcharge",
|
|
150
|
+
params,
|
|
151
|
+
(client, p) => client.hr.holidaySurcharge(p),
|
|
152
|
+
options
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/hooks/useEnergyLabel.ts
|
|
157
|
+
function useEnergyLabel(params, options) {
|
|
158
|
+
return useOmniQuery(
|
|
159
|
+
"realEstate.energyLabel",
|
|
160
|
+
params,
|
|
161
|
+
(client, p) => client.realEstate.energyLabel(p),
|
|
162
|
+
options
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/hooks/useEmissionZone.ts
|
|
167
|
+
function useEmissionZone(params, options) {
|
|
168
|
+
return useOmniQuery(
|
|
169
|
+
"logistics.emissionZone",
|
|
170
|
+
params,
|
|
171
|
+
(client, p) => client.logistics.emissionZone(p),
|
|
172
|
+
options
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/hooks/useTransitDisruptions.ts
|
|
177
|
+
function useTransitDisruptions(params, options) {
|
|
178
|
+
return useOmniQuery(
|
|
179
|
+
"logistics.transitDisruptions",
|
|
180
|
+
params,
|
|
181
|
+
(client, p) => client.logistics.transitDisruptions(p),
|
|
182
|
+
options
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/hooks/useGridTrigger.ts
|
|
187
|
+
function useGridTrigger(params, options) {
|
|
188
|
+
return useOmniQuery(
|
|
189
|
+
"energy.gridTrigger",
|
|
190
|
+
params ?? {},
|
|
191
|
+
(client, p) => client.energy.gridTrigger(p),
|
|
192
|
+
options
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
196
|
+
0 && (module.exports = {
|
|
197
|
+
OmniProvider,
|
|
198
|
+
useAddressEnrich,
|
|
199
|
+
useEmissionZone,
|
|
200
|
+
useEnergyLabel,
|
|
201
|
+
useGridTrigger,
|
|
202
|
+
useHolidaySurcharge,
|
|
203
|
+
useIbanToBic,
|
|
204
|
+
useMinimumWage,
|
|
205
|
+
useOmniClient,
|
|
206
|
+
useTransitDisruptions,
|
|
207
|
+
useValidateFinance,
|
|
208
|
+
useVatVerify
|
|
209
|
+
});
|
|
210
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/context.tsx","../src/hooks/useOmniQuery.ts","../src/hooks/useAddressEnrich.ts","../src/hooks/useIbanToBic.ts","../src/hooks/useVatVerify.ts","../src/hooks/useValidateFinance.ts","../src/hooks/useMinimumWage.ts","../src/hooks/useHolidaySurcharge.ts","../src/hooks/useEnergyLabel.ts","../src/hooks/useEmissionZone.ts","../src/hooks/useTransitDisruptions.ts","../src/hooks/useGridTrigger.ts"],"sourcesContent":["/**\n * @omnizoek/react — React hooks for the OmniZoek API\n *\n * @example\n * ```tsx\n * import { OmniProvider, useAddressEnrich } from \"@omnizoek/react\";\n *\n * // Wrap once at the root:\n * <OmniProvider apiKey={process.env.NEXT_PUBLIC_OMNI_API_KEY!}>\n * <App />\n * </OmniProvider>\n *\n * // Use hooks anywhere in the tree:\n * const { data, loading } = useAddressEnrich({ postcode: \"1012LG\", houseNumber: \"1\" });\n * ```\n */\n\n// Provider + context\nexport { OmniProvider, useOmniClient } from \"./context.js\";\nexport type { OmniProviderProps } from \"./context.js\";\n\n// Shared result type\nexport type { OmniHookResult, UseOmniQueryOptions } from \"./hooks/useOmniQuery.js\";\n\n// Hooks\nexport { useAddressEnrich } from \"./hooks/useAddressEnrich.js\";\nexport { useIbanToBic } from \"./hooks/useIbanToBic.js\";\nexport { useVatVerify } from \"./hooks/useVatVerify.js\";\nexport { useValidateFinance } from \"./hooks/useValidateFinance.js\";\nexport { useMinimumWage } from \"./hooks/useMinimumWage.js\";\nexport { useHolidaySurcharge } from \"./hooks/useHolidaySurcharge.js\";\nexport { useEnergyLabel } from \"./hooks/useEnergyLabel.js\";\nexport { useEmissionZone } from \"./hooks/useEmissionZone.js\";\nexport { useTransitDisruptions } from \"./hooks/useTransitDisruptions.js\";\nexport { useGridTrigger } from \"./hooks/useGridTrigger.js\";\n","/**\n * context.tsx — OmniProvider and useOmniClient.\n *\n * Wrap your app (or a subtree) once with <OmniProvider apiKey=\"...\">\n * to make all hooks available without prop-drilling the API key.\n *\n * @example\n * ```tsx\n * // app/layout.tsx (Next.js App Router)\n * \"use client\";\n *\n * import { OmniProvider } from \"@omnizoek/react\";\n *\n * export default function RootLayout({ children }) {\n * return (\n * <OmniProvider apiKey={process.env.NEXT_PUBLIC_OMNI_API_KEY!}>\n * {children}\n * </OmniProvider>\n * );\n * }\n * ```\n */\n\nimport {\n createContext,\n useContext,\n useMemo,\n type ReactNode,\n} from \"react\";\nimport { OmniClient, type OmniClientOptions } from \"@omnizoek/sdk\";\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\nconst OmniContext = createContext<OmniClient | null>(null);\n\n// ---------------------------------------------------------------------------\n// Provider\n// ---------------------------------------------------------------------------\n\nexport interface OmniProviderProps {\n /** Your OmniZoek API key (omni_live_… or omni_test_…) */\n apiKey: string;\n /** Override the API base URL — useful for testing against a local mock */\n baseUrl?: string;\n /** Additional client options forwarded to OmniClient */\n options?: Omit<OmniClientOptions, \"apiKey\" | \"baseUrl\">;\n children: ReactNode;\n}\n\n/**\n * Provides an OmniClient instance to all descendant hooks.\n * The client is created once and recreated only when `apiKey` or `baseUrl` changes.\n */\nexport function OmniProvider({\n apiKey,\n baseUrl,\n options,\n children,\n}: OmniProviderProps) {\n const client = useMemo(\n () => new OmniClient({ apiKey, baseUrl, ...options }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [apiKey, baseUrl],\n );\n\n return <OmniContext.Provider value={client}>{children}</OmniContext.Provider>;\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\n/**\n * Returns the OmniClient instance from the nearest OmniProvider.\n * Throws if called outside of an OmniProvider.\n */\nexport function useOmniClient(): OmniClient {\n const client = useContext(OmniContext);\n if (!client) {\n throw new Error(\n \"[OmniZoek] useOmniClient must be called inside an <OmniProvider>. \" +\n \"Wrap your app or component tree with <OmniProvider apiKey=\\\"...\\\">.\",\n );\n }\n return client;\n}\n","/**\n * useOmniQuery.ts — Internal generic hook powering all endpoint hooks.\n *\n * Not exported from the package — consumers use the named endpoint hooks.\n */\n\nimport useSWR from \"swr\";\nimport type { OmniClient } from \"@omnizoek/sdk\";\nimport { useOmniClient } from \"../context.js\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface OmniHookResult<T> {\n /** Response data, or `undefined` while loading or on error */\n data: T | undefined;\n /** `true` on the initial load (no cached data yet) */\n loading: boolean;\n /** `true` whenever a background revalidation is in flight */\n validating: boolean;\n /** Typed error from the SDK, or `null` */\n error: Error | null;\n /** Manually trigger a refetch / revalidation */\n refetch: () => Promise<T | undefined>;\n}\n\nexport interface UseOmniQueryOptions {\n /**\n * Set to `false` to skip the request entirely.\n * Useful when required inputs haven't been filled in yet.\n * @default true\n */\n enabled?: boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Generic hook\n// ---------------------------------------------------------------------------\n\n/**\n * Internal hook shared by all endpoint-specific hooks.\n *\n * @param endpointKey Stable string identifying this endpoint (used as SWR cache key prefix)\n * @param params Request params — pass `null` or `undefined` to skip the request\n * @param fetcher Function that calls the relevant OmniClient method\n * @param options Hook options (enabled, etc.)\n */\nexport function useOmniQuery<P, R>(\n endpointKey: string,\n params: P | null | undefined,\n fetcher: (client: OmniClient, params: P) => Promise<R>,\n options?: UseOmniQueryOptions,\n): OmniHookResult<R> {\n const client = useOmniClient();\n const isEnabled = options?.enabled !== false;\n\n // SWR key: null → skip request; array → fetch\n const swrKey: [string, P] | null =\n isEnabled && params != null ? [endpointKey, params] : null;\n\n const { data, error, isLoading, isValidating, mutate } = useSWR<R, Error>(\n swrKey,\n ([, p]: [string, P]) => fetcher(client, p),\n { shouldRetryOnError: false },\n );\n\n return {\n data,\n loading: isLoading,\n validating: isValidating,\n error: error ?? null,\n refetch: () => mutate(),\n };\n}\n","import type { AddressEnrichParams, AddressEnrichResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Enrich a Dutch address using postcode + house number.\n *\n * Calls `GET /v1/geo/enrich` via the BAG (Basisregistratie Adressen en Gebouwen).\n * Returns street, city, coordinates, BAG ID, surface area, and energy label.\n *\n * Pass `null` as `params` to skip the request (e.g. while the user is still typing).\n *\n * @example\n * ```tsx\n * const { data, loading, error } = useAddressEnrich(\n * postcode && houseNumber ? { postcode, houseNumber } : null\n * );\n * if (loading) return <Spinner />;\n * return <span>{data?.street} {data?.city}</span>;\n * ```\n */\nexport function useAddressEnrich(\n params: AddressEnrichParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<AddressEnrichResponse> {\n return useOmniQuery(\n \"geo.enrichAddress\",\n params,\n (client, p) => client.geo.enrichAddress(p),\n options,\n );\n}\n","import type { IbanToBicParams, IbanToBicResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Resolve a Dutch IBAN to its BIC code and bank name.\n *\n * Calls `GET /v1/finance/iban-to-bic`.\n * Pass `null` as `params` to skip the request.\n *\n * @example\n * ```tsx\n * const { data, loading } = useIbanToBic(iban ? { iban } : null);\n * return <span>{data?.bank_name} ({data?.bic})</span>;\n * ```\n */\nexport function useIbanToBic(\n params: IbanToBicParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<IbanToBicResponse> {\n return useOmniQuery(\n \"finance.ibanToBic\",\n params,\n (client, p) => client.finance.ibanToBic(p),\n options,\n );\n}\n","import type { VatVerifyParams, VatVerifyResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Verify a European VAT number via VIES.\n *\n * Calls `GET /v1/finance/vat-verify`.\n * Pass `null` as `params` to skip the request.\n *\n * @example\n * ```tsx\n * const { data, loading } = useVatVerify(\n * vatNumber ? { countryCode: \"NL\", vatNumber } : null\n * );\n * return <span>{data?.valid ? \"✅ Geldig\" : \"❌ Ongeldig\"}</span>;\n * ```\n */\nexport function useVatVerify(\n params: VatVerifyParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<VatVerifyResponse> {\n return useOmniQuery(\n \"finance.vatVerify\",\n params,\n (client, p) => client.finance.vatVerify(p),\n options,\n );\n}\n","import type { ValidateFinanceParams, FinanceValidationResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Validate a BSN or IBAN number using local checksum algorithms.\n *\n * Calls `GET /v1/compliance/validate-finance`.\n * No external service called — pure algorithm check.\n * Pass `null` as `params` to skip the request.\n *\n * @example\n * ```tsx\n * // BSN validation\n * const { data } = useValidateFinance(bsn ? { type: \"bsn\", number: bsn } : null);\n *\n * // IBAN validation\n * const { data } = useValidateFinance(iban ? { type: \"iban\", number: iban } : null);\n *\n * return <span>{data?.valid ? \"✅\" : \"❌\"} {data?.detail}</span>;\n * ```\n */\nexport function useValidateFinance(\n params: ValidateFinanceParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<FinanceValidationResponse> {\n return useOmniQuery(\n \"compliance.validateFinance\",\n params,\n (client, p) => client.compliance.validateFinance(p),\n options,\n );\n}\n","import type { MinimumWageParams, MinimumWageResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Retrieve the Dutch statutory minimum wage (WML) for a given age.\n *\n * Calls `GET /v1/hr/minimum-wage`.\n * Pass `null` as `params` to skip the request.\n *\n * @example\n * ```tsx\n * const { data, loading } = useMinimumWage(age ? { age } : null);\n * return <span>Minimumloon: €{data?.hourly_eur.toFixed(2)}/uur</span>;\n * ```\n */\nexport function useMinimumWage(\n params: MinimumWageParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<MinimumWageResponse> {\n return useOmniQuery(\n \"hr.minimumWage\",\n params,\n (client, p) => client.hr.minimumWage(p),\n options,\n );\n}\n","import type { HolidaySurchargeParams, HolidaySurchargeResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Check whether a date is a Dutch public holiday and get the applicable\n * surcharge multiplier for a given industry (e.g. \"horeca\", \"retail\").\n *\n * Calls `GET /v1/hr/holiday-surcharge`.\n * Pass `null` as `params` to skip the request.\n *\n * @example\n * ```tsx\n * const { data } = useHolidaySurcharge(\n * date ? { date, industry: \"horeca\" } : null\n * );\n * if (data?.is_holiday) {\n * return <span>Toeslag: {data.surcharge_multiplier}× ({data.holiday_name})</span>;\n * }\n * ```\n */\nexport function useHolidaySurcharge(\n params: HolidaySurchargeParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<HolidaySurchargeResponse> {\n return useOmniQuery(\n \"hr.holidaySurcharge\",\n params,\n (client, p) => client.hr.holidaySurcharge(p),\n options,\n );\n}\n","import type { EnergyLabelParams, EnergyLabelResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Retrieve the EP-Online energy label for a Dutch property.\n *\n * Calls `GET /v1/real-estate/energy-label`.\n * Pass `null` as `params` to skip the request.\n *\n * @example\n * ```tsx\n * const { data, loading } = useEnergyLabel(\n * postcode && houseNumber ? { postcode, houseNumber } : null\n * );\n * return <span>Energielabel: {data?.energy_label ?? \"–\"}</span>;\n * ```\n */\nexport function useEnergyLabel(\n params: EnergyLabelParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<EnergyLabelResponse> {\n return useOmniQuery(\n \"realEstate.energyLabel\",\n params,\n (client, p) => client.realEstate.energyLabel(p),\n options,\n );\n}\n","import type { EmissionZoneParams, EmissionZoneResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Check whether a Dutch vehicle (by licence plate) is zero-emission compliant\n * for urban emission zones.\n *\n * Calls `GET /v1/logistics/emission-zone`.\n * Pass `null` as `params` to skip the request.\n *\n * @example\n * ```tsx\n * const { data } = useEmissionZone(kenteken ? { kenteken } : null);\n * return <span>{data?.ze_compliant ? \"✅ ZE-compliant\" : \"❌ Niet toegestaan\"}</span>;\n * ```\n */\nexport function useEmissionZone(\n params: EmissionZoneParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<EmissionZoneResponse> {\n return useOmniQuery(\n \"logistics.emissionZone\",\n params,\n (client, p) => client.logistics.emissionZone(p),\n options,\n );\n}\n","import type { TransitDisruptionsParams, TransitDisruptionsResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Fetch current NS train disruptions for a given station.\n *\n * Calls `GET /v1/logistics/transit-disruptions`.\n * Pass `null` as `params` to skip the request.\n *\n * @example\n * ```tsx\n * const { data, loading } = useTransitDisruptions({ stationCode: \"ASD\" });\n *\n * if (loading) return <Spinner />;\n * return (\n * <ul>\n * {data?.disruptions.map(d => <li key={d.title}>{d.title}</li>)}\n * </ul>\n * );\n * ```\n */\nexport function useTransitDisruptions(\n params: TransitDisruptionsParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<TransitDisruptionsResponse> {\n return useOmniQuery(\n \"logistics.transitDisruptions\",\n params,\n (client, p) => client.logistics.transitDisruptions(p),\n options,\n );\n}\n","import type { GridTriggerParams, GridTriggerResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Check the current ENTSO-E day-ahead electricity price and whether it is\n * negative (a signal to run high-consumption processes).\n *\n * Calls `GET /v1/energy/grid-trigger`.\n * Always fetches unless `options.enabled` is `false`.\n *\n * @example\n * ```tsx\n * const { data } = useGridTrigger();\n *\n * if (data?.trigger) {\n * return <Banner>⚡ Stroomprijs negatief — goedkoop laden!</Banner>;\n * }\n * ```\n */\nexport function useGridTrigger(\n params?: GridTriggerParams,\n options?: UseOmniQueryOptions,\n): OmniHookResult<GridTriggerResponse> {\n // Always pass a params object (even empty) so the request fires by default.\n return useOmniQuery(\n \"energy.gridTrigger\",\n params ?? {},\n (client, p) => client.energy.gridTrigger(p),\n options,\n );\n}\n"],"mappings":"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","names":["useSWR"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { OmniClientOptions, OmniClient, AddressEnrichParams, AddressEnrichResponse, IbanToBicParams, IbanToBicResponse, VatVerifyParams, VatVerifyResponse, ValidateFinanceParams, FinanceValidationResponse, MinimumWageParams, MinimumWageResponse, HolidaySurchargeParams, HolidaySurchargeResponse, EnergyLabelParams, EnergyLabelResponse, EmissionZoneParams, EmissionZoneResponse, TransitDisruptionsParams, TransitDisruptionsResponse, GridTriggerParams, GridTriggerResponse } from '@omnizoek/sdk';
|
|
4
|
+
|
|
5
|
+
interface OmniProviderProps {
|
|
6
|
+
/** Your OmniZoek API key (omni_live_… or omni_test_…) */
|
|
7
|
+
apiKey: string;
|
|
8
|
+
/** Override the API base URL — useful for testing against a local mock */
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
/** Additional client options forwarded to OmniClient */
|
|
11
|
+
options?: Omit<OmniClientOptions, "apiKey" | "baseUrl">;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Provides an OmniClient instance to all descendant hooks.
|
|
16
|
+
* The client is created once and recreated only when `apiKey` or `baseUrl` changes.
|
|
17
|
+
*/
|
|
18
|
+
declare function OmniProvider({ apiKey, baseUrl, options, children, }: OmniProviderProps): react_jsx_runtime.JSX.Element;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the OmniClient instance from the nearest OmniProvider.
|
|
21
|
+
* Throws if called outside of an OmniProvider.
|
|
22
|
+
*/
|
|
23
|
+
declare function useOmniClient(): OmniClient;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* useOmniQuery.ts — Internal generic hook powering all endpoint hooks.
|
|
27
|
+
*
|
|
28
|
+
* Not exported from the package — consumers use the named endpoint hooks.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
interface OmniHookResult<T> {
|
|
32
|
+
/** Response data, or `undefined` while loading or on error */
|
|
33
|
+
data: T | undefined;
|
|
34
|
+
/** `true` on the initial load (no cached data yet) */
|
|
35
|
+
loading: boolean;
|
|
36
|
+
/** `true` whenever a background revalidation is in flight */
|
|
37
|
+
validating: boolean;
|
|
38
|
+
/** Typed error from the SDK, or `null` */
|
|
39
|
+
error: Error | null;
|
|
40
|
+
/** Manually trigger a refetch / revalidation */
|
|
41
|
+
refetch: () => Promise<T | undefined>;
|
|
42
|
+
}
|
|
43
|
+
interface UseOmniQueryOptions {
|
|
44
|
+
/**
|
|
45
|
+
* Set to `false` to skip the request entirely.
|
|
46
|
+
* Useful when required inputs haven't been filled in yet.
|
|
47
|
+
* @default true
|
|
48
|
+
*/
|
|
49
|
+
enabled?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Enrich a Dutch address using postcode + house number.
|
|
54
|
+
*
|
|
55
|
+
* Calls `GET /v1/geo/enrich` via the BAG (Basisregistratie Adressen en Gebouwen).
|
|
56
|
+
* Returns street, city, coordinates, BAG ID, surface area, and energy label.
|
|
57
|
+
*
|
|
58
|
+
* Pass `null` as `params` to skip the request (e.g. while the user is still typing).
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```tsx
|
|
62
|
+
* const { data, loading, error } = useAddressEnrich(
|
|
63
|
+
* postcode && houseNumber ? { postcode, houseNumber } : null
|
|
64
|
+
* );
|
|
65
|
+
* if (loading) return <Spinner />;
|
|
66
|
+
* return <span>{data?.street} {data?.city}</span>;
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare function useAddressEnrich(params: AddressEnrichParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<AddressEnrichResponse>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Resolve a Dutch IBAN to its BIC code and bank name.
|
|
73
|
+
*
|
|
74
|
+
* Calls `GET /v1/finance/iban-to-bic`.
|
|
75
|
+
* Pass `null` as `params` to skip the request.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```tsx
|
|
79
|
+
* const { data, loading } = useIbanToBic(iban ? { iban } : null);
|
|
80
|
+
* return <span>{data?.bank_name} ({data?.bic})</span>;
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
declare function useIbanToBic(params: IbanToBicParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<IbanToBicResponse>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Verify a European VAT number via VIES.
|
|
87
|
+
*
|
|
88
|
+
* Calls `GET /v1/finance/vat-verify`.
|
|
89
|
+
* Pass `null` as `params` to skip the request.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```tsx
|
|
93
|
+
* const { data, loading } = useVatVerify(
|
|
94
|
+
* vatNumber ? { countryCode: "NL", vatNumber } : null
|
|
95
|
+
* );
|
|
96
|
+
* return <span>{data?.valid ? "✅ Geldig" : "❌ Ongeldig"}</span>;
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare function useVatVerify(params: VatVerifyParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<VatVerifyResponse>;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Validate a BSN or IBAN number using local checksum algorithms.
|
|
103
|
+
*
|
|
104
|
+
* Calls `GET /v1/compliance/validate-finance`.
|
|
105
|
+
* No external service called — pure algorithm check.
|
|
106
|
+
* Pass `null` as `params` to skip the request.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```tsx
|
|
110
|
+
* // BSN validation
|
|
111
|
+
* const { data } = useValidateFinance(bsn ? { type: "bsn", number: bsn } : null);
|
|
112
|
+
*
|
|
113
|
+
* // IBAN validation
|
|
114
|
+
* const { data } = useValidateFinance(iban ? { type: "iban", number: iban } : null);
|
|
115
|
+
*
|
|
116
|
+
* return <span>{data?.valid ? "✅" : "❌"} {data?.detail}</span>;
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
declare function useValidateFinance(params: ValidateFinanceParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<FinanceValidationResponse>;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Retrieve the Dutch statutory minimum wage (WML) for a given age.
|
|
123
|
+
*
|
|
124
|
+
* Calls `GET /v1/hr/minimum-wage`.
|
|
125
|
+
* Pass `null` as `params` to skip the request.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```tsx
|
|
129
|
+
* const { data, loading } = useMinimumWage(age ? { age } : null);
|
|
130
|
+
* return <span>Minimumloon: €{data?.hourly_eur.toFixed(2)}/uur</span>;
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
declare function useMinimumWage(params: MinimumWageParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<MinimumWageResponse>;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Check whether a date is a Dutch public holiday and get the applicable
|
|
137
|
+
* surcharge multiplier for a given industry (e.g. "horeca", "retail").
|
|
138
|
+
*
|
|
139
|
+
* Calls `GET /v1/hr/holiday-surcharge`.
|
|
140
|
+
* Pass `null` as `params` to skip the request.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```tsx
|
|
144
|
+
* const { data } = useHolidaySurcharge(
|
|
145
|
+
* date ? { date, industry: "horeca" } : null
|
|
146
|
+
* );
|
|
147
|
+
* if (data?.is_holiday) {
|
|
148
|
+
* return <span>Toeslag: {data.surcharge_multiplier}× ({data.holiday_name})</span>;
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
declare function useHolidaySurcharge(params: HolidaySurchargeParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<HolidaySurchargeResponse>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Retrieve the EP-Online energy label for a Dutch property.
|
|
156
|
+
*
|
|
157
|
+
* Calls `GET /v1/real-estate/energy-label`.
|
|
158
|
+
* Pass `null` as `params` to skip the request.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```tsx
|
|
162
|
+
* const { data, loading } = useEnergyLabel(
|
|
163
|
+
* postcode && houseNumber ? { postcode, houseNumber } : null
|
|
164
|
+
* );
|
|
165
|
+
* return <span>Energielabel: {data?.energy_label ?? "–"}</span>;
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
declare function useEnergyLabel(params: EnergyLabelParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<EnergyLabelResponse>;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Check whether a Dutch vehicle (by licence plate) is zero-emission compliant
|
|
172
|
+
* for urban emission zones.
|
|
173
|
+
*
|
|
174
|
+
* Calls `GET /v1/logistics/emission-zone`.
|
|
175
|
+
* Pass `null` as `params` to skip the request.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```tsx
|
|
179
|
+
* const { data } = useEmissionZone(kenteken ? { kenteken } : null);
|
|
180
|
+
* return <span>{data?.ze_compliant ? "✅ ZE-compliant" : "❌ Niet toegestaan"}</span>;
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare function useEmissionZone(params: EmissionZoneParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<EmissionZoneResponse>;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Fetch current NS train disruptions for a given station.
|
|
187
|
+
*
|
|
188
|
+
* Calls `GET /v1/logistics/transit-disruptions`.
|
|
189
|
+
* Pass `null` as `params` to skip the request.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```tsx
|
|
193
|
+
* const { data, loading } = useTransitDisruptions({ stationCode: "ASD" });
|
|
194
|
+
*
|
|
195
|
+
* if (loading) return <Spinner />;
|
|
196
|
+
* return (
|
|
197
|
+
* <ul>
|
|
198
|
+
* {data?.disruptions.map(d => <li key={d.title}>{d.title}</li>)}
|
|
199
|
+
* </ul>
|
|
200
|
+
* );
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
declare function useTransitDisruptions(params: TransitDisruptionsParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<TransitDisruptionsResponse>;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Check the current ENTSO-E day-ahead electricity price and whether it is
|
|
207
|
+
* negative (a signal to run high-consumption processes).
|
|
208
|
+
*
|
|
209
|
+
* Calls `GET /v1/energy/grid-trigger`.
|
|
210
|
+
* Always fetches unless `options.enabled` is `false`.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```tsx
|
|
214
|
+
* const { data } = useGridTrigger();
|
|
215
|
+
*
|
|
216
|
+
* if (data?.trigger) {
|
|
217
|
+
* return <Banner>⚡ Stroomprijs negatief — goedkoop laden!</Banner>;
|
|
218
|
+
* }
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
declare function useGridTrigger(params?: GridTriggerParams, options?: UseOmniQueryOptions): OmniHookResult<GridTriggerResponse>;
|
|
222
|
+
|
|
223
|
+
export { type OmniHookResult, OmniProvider, type OmniProviderProps, type UseOmniQueryOptions, useAddressEnrich, useEmissionZone, useEnergyLabel, useGridTrigger, useHolidaySurcharge, useIbanToBic, useMinimumWage, useOmniClient, useTransitDisruptions, useValidateFinance, useVatVerify };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { OmniClientOptions, OmniClient, AddressEnrichParams, AddressEnrichResponse, IbanToBicParams, IbanToBicResponse, VatVerifyParams, VatVerifyResponse, ValidateFinanceParams, FinanceValidationResponse, MinimumWageParams, MinimumWageResponse, HolidaySurchargeParams, HolidaySurchargeResponse, EnergyLabelParams, EnergyLabelResponse, EmissionZoneParams, EmissionZoneResponse, TransitDisruptionsParams, TransitDisruptionsResponse, GridTriggerParams, GridTriggerResponse } from '@omnizoek/sdk';
|
|
4
|
+
|
|
5
|
+
interface OmniProviderProps {
|
|
6
|
+
/** Your OmniZoek API key (omni_live_… or omni_test_…) */
|
|
7
|
+
apiKey: string;
|
|
8
|
+
/** Override the API base URL — useful for testing against a local mock */
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
/** Additional client options forwarded to OmniClient */
|
|
11
|
+
options?: Omit<OmniClientOptions, "apiKey" | "baseUrl">;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Provides an OmniClient instance to all descendant hooks.
|
|
16
|
+
* The client is created once and recreated only when `apiKey` or `baseUrl` changes.
|
|
17
|
+
*/
|
|
18
|
+
declare function OmniProvider({ apiKey, baseUrl, options, children, }: OmniProviderProps): react_jsx_runtime.JSX.Element;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the OmniClient instance from the nearest OmniProvider.
|
|
21
|
+
* Throws if called outside of an OmniProvider.
|
|
22
|
+
*/
|
|
23
|
+
declare function useOmniClient(): OmniClient;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* useOmniQuery.ts — Internal generic hook powering all endpoint hooks.
|
|
27
|
+
*
|
|
28
|
+
* Not exported from the package — consumers use the named endpoint hooks.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
interface OmniHookResult<T> {
|
|
32
|
+
/** Response data, or `undefined` while loading or on error */
|
|
33
|
+
data: T | undefined;
|
|
34
|
+
/** `true` on the initial load (no cached data yet) */
|
|
35
|
+
loading: boolean;
|
|
36
|
+
/** `true` whenever a background revalidation is in flight */
|
|
37
|
+
validating: boolean;
|
|
38
|
+
/** Typed error from the SDK, or `null` */
|
|
39
|
+
error: Error | null;
|
|
40
|
+
/** Manually trigger a refetch / revalidation */
|
|
41
|
+
refetch: () => Promise<T | undefined>;
|
|
42
|
+
}
|
|
43
|
+
interface UseOmniQueryOptions {
|
|
44
|
+
/**
|
|
45
|
+
* Set to `false` to skip the request entirely.
|
|
46
|
+
* Useful when required inputs haven't been filled in yet.
|
|
47
|
+
* @default true
|
|
48
|
+
*/
|
|
49
|
+
enabled?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Enrich a Dutch address using postcode + house number.
|
|
54
|
+
*
|
|
55
|
+
* Calls `GET /v1/geo/enrich` via the BAG (Basisregistratie Adressen en Gebouwen).
|
|
56
|
+
* Returns street, city, coordinates, BAG ID, surface area, and energy label.
|
|
57
|
+
*
|
|
58
|
+
* Pass `null` as `params` to skip the request (e.g. while the user is still typing).
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```tsx
|
|
62
|
+
* const { data, loading, error } = useAddressEnrich(
|
|
63
|
+
* postcode && houseNumber ? { postcode, houseNumber } : null
|
|
64
|
+
* );
|
|
65
|
+
* if (loading) return <Spinner />;
|
|
66
|
+
* return <span>{data?.street} {data?.city}</span>;
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare function useAddressEnrich(params: AddressEnrichParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<AddressEnrichResponse>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Resolve a Dutch IBAN to its BIC code and bank name.
|
|
73
|
+
*
|
|
74
|
+
* Calls `GET /v1/finance/iban-to-bic`.
|
|
75
|
+
* Pass `null` as `params` to skip the request.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```tsx
|
|
79
|
+
* const { data, loading } = useIbanToBic(iban ? { iban } : null);
|
|
80
|
+
* return <span>{data?.bank_name} ({data?.bic})</span>;
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
declare function useIbanToBic(params: IbanToBicParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<IbanToBicResponse>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Verify a European VAT number via VIES.
|
|
87
|
+
*
|
|
88
|
+
* Calls `GET /v1/finance/vat-verify`.
|
|
89
|
+
* Pass `null` as `params` to skip the request.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```tsx
|
|
93
|
+
* const { data, loading } = useVatVerify(
|
|
94
|
+
* vatNumber ? { countryCode: "NL", vatNumber } : null
|
|
95
|
+
* );
|
|
96
|
+
* return <span>{data?.valid ? "✅ Geldig" : "❌ Ongeldig"}</span>;
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare function useVatVerify(params: VatVerifyParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<VatVerifyResponse>;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Validate a BSN or IBAN number using local checksum algorithms.
|
|
103
|
+
*
|
|
104
|
+
* Calls `GET /v1/compliance/validate-finance`.
|
|
105
|
+
* No external service called — pure algorithm check.
|
|
106
|
+
* Pass `null` as `params` to skip the request.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```tsx
|
|
110
|
+
* // BSN validation
|
|
111
|
+
* const { data } = useValidateFinance(bsn ? { type: "bsn", number: bsn } : null);
|
|
112
|
+
*
|
|
113
|
+
* // IBAN validation
|
|
114
|
+
* const { data } = useValidateFinance(iban ? { type: "iban", number: iban } : null);
|
|
115
|
+
*
|
|
116
|
+
* return <span>{data?.valid ? "✅" : "❌"} {data?.detail}</span>;
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
declare function useValidateFinance(params: ValidateFinanceParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<FinanceValidationResponse>;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Retrieve the Dutch statutory minimum wage (WML) for a given age.
|
|
123
|
+
*
|
|
124
|
+
* Calls `GET /v1/hr/minimum-wage`.
|
|
125
|
+
* Pass `null` as `params` to skip the request.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```tsx
|
|
129
|
+
* const { data, loading } = useMinimumWage(age ? { age } : null);
|
|
130
|
+
* return <span>Minimumloon: €{data?.hourly_eur.toFixed(2)}/uur</span>;
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
declare function useMinimumWage(params: MinimumWageParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<MinimumWageResponse>;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Check whether a date is a Dutch public holiday and get the applicable
|
|
137
|
+
* surcharge multiplier for a given industry (e.g. "horeca", "retail").
|
|
138
|
+
*
|
|
139
|
+
* Calls `GET /v1/hr/holiday-surcharge`.
|
|
140
|
+
* Pass `null` as `params` to skip the request.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```tsx
|
|
144
|
+
* const { data } = useHolidaySurcharge(
|
|
145
|
+
* date ? { date, industry: "horeca" } : null
|
|
146
|
+
* );
|
|
147
|
+
* if (data?.is_holiday) {
|
|
148
|
+
* return <span>Toeslag: {data.surcharge_multiplier}× ({data.holiday_name})</span>;
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
declare function useHolidaySurcharge(params: HolidaySurchargeParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<HolidaySurchargeResponse>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Retrieve the EP-Online energy label for a Dutch property.
|
|
156
|
+
*
|
|
157
|
+
* Calls `GET /v1/real-estate/energy-label`.
|
|
158
|
+
* Pass `null` as `params` to skip the request.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```tsx
|
|
162
|
+
* const { data, loading } = useEnergyLabel(
|
|
163
|
+
* postcode && houseNumber ? { postcode, houseNumber } : null
|
|
164
|
+
* );
|
|
165
|
+
* return <span>Energielabel: {data?.energy_label ?? "–"}</span>;
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
declare function useEnergyLabel(params: EnergyLabelParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<EnergyLabelResponse>;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Check whether a Dutch vehicle (by licence plate) is zero-emission compliant
|
|
172
|
+
* for urban emission zones.
|
|
173
|
+
*
|
|
174
|
+
* Calls `GET /v1/logistics/emission-zone`.
|
|
175
|
+
* Pass `null` as `params` to skip the request.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```tsx
|
|
179
|
+
* const { data } = useEmissionZone(kenteken ? { kenteken } : null);
|
|
180
|
+
* return <span>{data?.ze_compliant ? "✅ ZE-compliant" : "❌ Niet toegestaan"}</span>;
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare function useEmissionZone(params: EmissionZoneParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<EmissionZoneResponse>;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Fetch current NS train disruptions for a given station.
|
|
187
|
+
*
|
|
188
|
+
* Calls `GET /v1/logistics/transit-disruptions`.
|
|
189
|
+
* Pass `null` as `params` to skip the request.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```tsx
|
|
193
|
+
* const { data, loading } = useTransitDisruptions({ stationCode: "ASD" });
|
|
194
|
+
*
|
|
195
|
+
* if (loading) return <Spinner />;
|
|
196
|
+
* return (
|
|
197
|
+
* <ul>
|
|
198
|
+
* {data?.disruptions.map(d => <li key={d.title}>{d.title}</li>)}
|
|
199
|
+
* </ul>
|
|
200
|
+
* );
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
declare function useTransitDisruptions(params: TransitDisruptionsParams | null | undefined, options?: UseOmniQueryOptions): OmniHookResult<TransitDisruptionsResponse>;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Check the current ENTSO-E day-ahead electricity price and whether it is
|
|
207
|
+
* negative (a signal to run high-consumption processes).
|
|
208
|
+
*
|
|
209
|
+
* Calls `GET /v1/energy/grid-trigger`.
|
|
210
|
+
* Always fetches unless `options.enabled` is `false`.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```tsx
|
|
214
|
+
* const { data } = useGridTrigger();
|
|
215
|
+
*
|
|
216
|
+
* if (data?.trigger) {
|
|
217
|
+
* return <Banner>⚡ Stroomprijs negatief — goedkoop laden!</Banner>;
|
|
218
|
+
* }
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
declare function useGridTrigger(params?: GridTriggerParams, options?: UseOmniQueryOptions): OmniHookResult<GridTriggerResponse>;
|
|
222
|
+
|
|
223
|
+
export { type OmniHookResult, OmniProvider, type OmniProviderProps, type UseOmniQueryOptions, useAddressEnrich, useEmissionZone, useEnergyLabel, useGridTrigger, useHolidaySurcharge, useIbanToBic, useMinimumWage, useOmniClient, useTransitDisruptions, useValidateFinance, useVatVerify };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// src/context.tsx
|
|
2
|
+
import {
|
|
3
|
+
createContext,
|
|
4
|
+
useContext,
|
|
5
|
+
useMemo
|
|
6
|
+
} from "react";
|
|
7
|
+
import { OmniClient } from "@omnizoek/sdk";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
var OmniContext = createContext(null);
|
|
10
|
+
function OmniProvider({
|
|
11
|
+
apiKey,
|
|
12
|
+
baseUrl,
|
|
13
|
+
options,
|
|
14
|
+
children
|
|
15
|
+
}) {
|
|
16
|
+
const client = useMemo(
|
|
17
|
+
() => new OmniClient({ apiKey, baseUrl, ...options }),
|
|
18
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
19
|
+
[apiKey, baseUrl]
|
|
20
|
+
);
|
|
21
|
+
return /* @__PURE__ */ jsx(OmniContext.Provider, { value: client, children });
|
|
22
|
+
}
|
|
23
|
+
function useOmniClient() {
|
|
24
|
+
const client = useContext(OmniContext);
|
|
25
|
+
if (!client) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
'[OmniZoek] useOmniClient must be called inside an <OmniProvider>. Wrap your app or component tree with <OmniProvider apiKey="...">.'
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return client;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/hooks/useOmniQuery.ts
|
|
34
|
+
import useSWR from "swr";
|
|
35
|
+
function useOmniQuery(endpointKey, params, fetcher, options) {
|
|
36
|
+
const client = useOmniClient();
|
|
37
|
+
const isEnabled = options?.enabled !== false;
|
|
38
|
+
const swrKey = isEnabled && params != null ? [endpointKey, params] : null;
|
|
39
|
+
const { data, error, isLoading, isValidating, mutate } = useSWR(
|
|
40
|
+
swrKey,
|
|
41
|
+
([, p]) => fetcher(client, p),
|
|
42
|
+
{ shouldRetryOnError: false }
|
|
43
|
+
);
|
|
44
|
+
return {
|
|
45
|
+
data,
|
|
46
|
+
loading: isLoading,
|
|
47
|
+
validating: isValidating,
|
|
48
|
+
error: error ?? null,
|
|
49
|
+
refetch: () => mutate()
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/hooks/useAddressEnrich.ts
|
|
54
|
+
function useAddressEnrich(params, options) {
|
|
55
|
+
return useOmniQuery(
|
|
56
|
+
"geo.enrichAddress",
|
|
57
|
+
params,
|
|
58
|
+
(client, p) => client.geo.enrichAddress(p),
|
|
59
|
+
options
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/hooks/useIbanToBic.ts
|
|
64
|
+
function useIbanToBic(params, options) {
|
|
65
|
+
return useOmniQuery(
|
|
66
|
+
"finance.ibanToBic",
|
|
67
|
+
params,
|
|
68
|
+
(client, p) => client.finance.ibanToBic(p),
|
|
69
|
+
options
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/hooks/useVatVerify.ts
|
|
74
|
+
function useVatVerify(params, options) {
|
|
75
|
+
return useOmniQuery(
|
|
76
|
+
"finance.vatVerify",
|
|
77
|
+
params,
|
|
78
|
+
(client, p) => client.finance.vatVerify(p),
|
|
79
|
+
options
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/hooks/useValidateFinance.ts
|
|
84
|
+
function useValidateFinance(params, options) {
|
|
85
|
+
return useOmniQuery(
|
|
86
|
+
"compliance.validateFinance",
|
|
87
|
+
params,
|
|
88
|
+
(client, p) => client.compliance.validateFinance(p),
|
|
89
|
+
options
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/hooks/useMinimumWage.ts
|
|
94
|
+
function useMinimumWage(params, options) {
|
|
95
|
+
return useOmniQuery(
|
|
96
|
+
"hr.minimumWage",
|
|
97
|
+
params,
|
|
98
|
+
(client, p) => client.hr.minimumWage(p),
|
|
99
|
+
options
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/hooks/useHolidaySurcharge.ts
|
|
104
|
+
function useHolidaySurcharge(params, options) {
|
|
105
|
+
return useOmniQuery(
|
|
106
|
+
"hr.holidaySurcharge",
|
|
107
|
+
params,
|
|
108
|
+
(client, p) => client.hr.holidaySurcharge(p),
|
|
109
|
+
options
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/hooks/useEnergyLabel.ts
|
|
114
|
+
function useEnergyLabel(params, options) {
|
|
115
|
+
return useOmniQuery(
|
|
116
|
+
"realEstate.energyLabel",
|
|
117
|
+
params,
|
|
118
|
+
(client, p) => client.realEstate.energyLabel(p),
|
|
119
|
+
options
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// src/hooks/useEmissionZone.ts
|
|
124
|
+
function useEmissionZone(params, options) {
|
|
125
|
+
return useOmniQuery(
|
|
126
|
+
"logistics.emissionZone",
|
|
127
|
+
params,
|
|
128
|
+
(client, p) => client.logistics.emissionZone(p),
|
|
129
|
+
options
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/hooks/useTransitDisruptions.ts
|
|
134
|
+
function useTransitDisruptions(params, options) {
|
|
135
|
+
return useOmniQuery(
|
|
136
|
+
"logistics.transitDisruptions",
|
|
137
|
+
params,
|
|
138
|
+
(client, p) => client.logistics.transitDisruptions(p),
|
|
139
|
+
options
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/hooks/useGridTrigger.ts
|
|
144
|
+
function useGridTrigger(params, options) {
|
|
145
|
+
return useOmniQuery(
|
|
146
|
+
"energy.gridTrigger",
|
|
147
|
+
params ?? {},
|
|
148
|
+
(client, p) => client.energy.gridTrigger(p),
|
|
149
|
+
options
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
export {
|
|
153
|
+
OmniProvider,
|
|
154
|
+
useAddressEnrich,
|
|
155
|
+
useEmissionZone,
|
|
156
|
+
useEnergyLabel,
|
|
157
|
+
useGridTrigger,
|
|
158
|
+
useHolidaySurcharge,
|
|
159
|
+
useIbanToBic,
|
|
160
|
+
useMinimumWage,
|
|
161
|
+
useOmniClient,
|
|
162
|
+
useTransitDisruptions,
|
|
163
|
+
useValidateFinance,
|
|
164
|
+
useVatVerify
|
|
165
|
+
};
|
|
166
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/context.tsx","../src/hooks/useOmniQuery.ts","../src/hooks/useAddressEnrich.ts","../src/hooks/useIbanToBic.ts","../src/hooks/useVatVerify.ts","../src/hooks/useValidateFinance.ts","../src/hooks/useMinimumWage.ts","../src/hooks/useHolidaySurcharge.ts","../src/hooks/useEnergyLabel.ts","../src/hooks/useEmissionZone.ts","../src/hooks/useTransitDisruptions.ts","../src/hooks/useGridTrigger.ts"],"sourcesContent":["/**\n * context.tsx — OmniProvider and useOmniClient.\n *\n * Wrap your app (or a subtree) once with <OmniProvider apiKey=\"...\">\n * to make all hooks available without prop-drilling the API key.\n *\n * @example\n * ```tsx\n * // app/layout.tsx (Next.js App Router)\n * \"use client\";\n *\n * import { OmniProvider } from \"@omnizoek/react\";\n *\n * export default function RootLayout({ children }) {\n * return (\n * <OmniProvider apiKey={process.env.NEXT_PUBLIC_OMNI_API_KEY!}>\n * {children}\n * </OmniProvider>\n * );\n * }\n * ```\n */\n\nimport {\n createContext,\n useContext,\n useMemo,\n type ReactNode,\n} from \"react\";\nimport { OmniClient, type OmniClientOptions } from \"@omnizoek/sdk\";\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\nconst OmniContext = createContext<OmniClient | null>(null);\n\n// ---------------------------------------------------------------------------\n// Provider\n// ---------------------------------------------------------------------------\n\nexport interface OmniProviderProps {\n /** Your OmniZoek API key (omni_live_… or omni_test_…) */\n apiKey: string;\n /** Override the API base URL — useful for testing against a local mock */\n baseUrl?: string;\n /** Additional client options forwarded to OmniClient */\n options?: Omit<OmniClientOptions, \"apiKey\" | \"baseUrl\">;\n children: ReactNode;\n}\n\n/**\n * Provides an OmniClient instance to all descendant hooks.\n * The client is created once and recreated only when `apiKey` or `baseUrl` changes.\n */\nexport function OmniProvider({\n apiKey,\n baseUrl,\n options,\n children,\n}: OmniProviderProps) {\n const client = useMemo(\n () => new OmniClient({ apiKey, baseUrl, ...options }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [apiKey, baseUrl],\n );\n\n return <OmniContext.Provider value={client}>{children}</OmniContext.Provider>;\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\n/**\n * Returns the OmniClient instance from the nearest OmniProvider.\n * Throws if called outside of an OmniProvider.\n */\nexport function useOmniClient(): OmniClient {\n const client = useContext(OmniContext);\n if (!client) {\n throw new Error(\n \"[OmniZoek] useOmniClient must be called inside an <OmniProvider>. \" +\n \"Wrap your app or component tree with <OmniProvider apiKey=\\\"...\\\">.\",\n );\n }\n return client;\n}\n","/**\n * useOmniQuery.ts — Internal generic hook powering all endpoint hooks.\n *\n * Not exported from the package — consumers use the named endpoint hooks.\n */\n\nimport useSWR from \"swr\";\nimport type { OmniClient } from \"@omnizoek/sdk\";\nimport { useOmniClient } from \"../context.js\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface OmniHookResult<T> {\n /** Response data, or `undefined` while loading or on error */\n data: T | undefined;\n /** `true` on the initial load (no cached data yet) */\n loading: boolean;\n /** `true` whenever a background revalidation is in flight */\n validating: boolean;\n /** Typed error from the SDK, or `null` */\n error: Error | null;\n /** Manually trigger a refetch / revalidation */\n refetch: () => Promise<T | undefined>;\n}\n\nexport interface UseOmniQueryOptions {\n /**\n * Set to `false` to skip the request entirely.\n * Useful when required inputs haven't been filled in yet.\n * @default true\n */\n enabled?: boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Generic hook\n// ---------------------------------------------------------------------------\n\n/**\n * Internal hook shared by all endpoint-specific hooks.\n *\n * @param endpointKey Stable string identifying this endpoint (used as SWR cache key prefix)\n * @param params Request params — pass `null` or `undefined` to skip the request\n * @param fetcher Function that calls the relevant OmniClient method\n * @param options Hook options (enabled, etc.)\n */\nexport function useOmniQuery<P, R>(\n endpointKey: string,\n params: P | null | undefined,\n fetcher: (client: OmniClient, params: P) => Promise<R>,\n options?: UseOmniQueryOptions,\n): OmniHookResult<R> {\n const client = useOmniClient();\n const isEnabled = options?.enabled !== false;\n\n // SWR key: null → skip request; array → fetch\n const swrKey: [string, P] | null =\n isEnabled && params != null ? [endpointKey, params] : null;\n\n const { data, error, isLoading, isValidating, mutate } = useSWR<R, Error>(\n swrKey,\n ([, p]: [string, P]) => fetcher(client, p),\n { shouldRetryOnError: false },\n );\n\n return {\n data,\n loading: isLoading,\n validating: isValidating,\n error: error ?? null,\n refetch: () => mutate(),\n };\n}\n","import type { AddressEnrichParams, AddressEnrichResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Enrich a Dutch address using postcode + house number.\n *\n * Calls `GET /v1/geo/enrich` via the BAG (Basisregistratie Adressen en Gebouwen).\n * Returns street, city, coordinates, BAG ID, surface area, and energy label.\n *\n * Pass `null` as `params` to skip the request (e.g. while the user is still typing).\n *\n * @example\n * ```tsx\n * const { data, loading, error } = useAddressEnrich(\n * postcode && houseNumber ? { postcode, houseNumber } : null\n * );\n * if (loading) return <Spinner />;\n * return <span>{data?.street} {data?.city}</span>;\n * ```\n */\nexport function useAddressEnrich(\n params: AddressEnrichParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<AddressEnrichResponse> {\n return useOmniQuery(\n \"geo.enrichAddress\",\n params,\n (client, p) => client.geo.enrichAddress(p),\n options,\n );\n}\n","import type { IbanToBicParams, IbanToBicResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Resolve a Dutch IBAN to its BIC code and bank name.\n *\n * Calls `GET /v1/finance/iban-to-bic`.\n * Pass `null` as `params` to skip the request.\n *\n * @example\n * ```tsx\n * const { data, loading } = useIbanToBic(iban ? { iban } : null);\n * return <span>{data?.bank_name} ({data?.bic})</span>;\n * ```\n */\nexport function useIbanToBic(\n params: IbanToBicParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<IbanToBicResponse> {\n return useOmniQuery(\n \"finance.ibanToBic\",\n params,\n (client, p) => client.finance.ibanToBic(p),\n options,\n );\n}\n","import type { VatVerifyParams, VatVerifyResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Verify a European VAT number via VIES.\n *\n * Calls `GET /v1/finance/vat-verify`.\n * Pass `null` as `params` to skip the request.\n *\n * @example\n * ```tsx\n * const { data, loading } = useVatVerify(\n * vatNumber ? { countryCode: \"NL\", vatNumber } : null\n * );\n * return <span>{data?.valid ? \"✅ Geldig\" : \"❌ Ongeldig\"}</span>;\n * ```\n */\nexport function useVatVerify(\n params: VatVerifyParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<VatVerifyResponse> {\n return useOmniQuery(\n \"finance.vatVerify\",\n params,\n (client, p) => client.finance.vatVerify(p),\n options,\n );\n}\n","import type { ValidateFinanceParams, FinanceValidationResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Validate a BSN or IBAN number using local checksum algorithms.\n *\n * Calls `GET /v1/compliance/validate-finance`.\n * No external service called — pure algorithm check.\n * Pass `null` as `params` to skip the request.\n *\n * @example\n * ```tsx\n * // BSN validation\n * const { data } = useValidateFinance(bsn ? { type: \"bsn\", number: bsn } : null);\n *\n * // IBAN validation\n * const { data } = useValidateFinance(iban ? { type: \"iban\", number: iban } : null);\n *\n * return <span>{data?.valid ? \"✅\" : \"❌\"} {data?.detail}</span>;\n * ```\n */\nexport function useValidateFinance(\n params: ValidateFinanceParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<FinanceValidationResponse> {\n return useOmniQuery(\n \"compliance.validateFinance\",\n params,\n (client, p) => client.compliance.validateFinance(p),\n options,\n );\n}\n","import type { MinimumWageParams, MinimumWageResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Retrieve the Dutch statutory minimum wage (WML) for a given age.\n *\n * Calls `GET /v1/hr/minimum-wage`.\n * Pass `null` as `params` to skip the request.\n *\n * @example\n * ```tsx\n * const { data, loading } = useMinimumWage(age ? { age } : null);\n * return <span>Minimumloon: €{data?.hourly_eur.toFixed(2)}/uur</span>;\n * ```\n */\nexport function useMinimumWage(\n params: MinimumWageParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<MinimumWageResponse> {\n return useOmniQuery(\n \"hr.minimumWage\",\n params,\n (client, p) => client.hr.minimumWage(p),\n options,\n );\n}\n","import type { HolidaySurchargeParams, HolidaySurchargeResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Check whether a date is a Dutch public holiday and get the applicable\n * surcharge multiplier for a given industry (e.g. \"horeca\", \"retail\").\n *\n * Calls `GET /v1/hr/holiday-surcharge`.\n * Pass `null` as `params` to skip the request.\n *\n * @example\n * ```tsx\n * const { data } = useHolidaySurcharge(\n * date ? { date, industry: \"horeca\" } : null\n * );\n * if (data?.is_holiday) {\n * return <span>Toeslag: {data.surcharge_multiplier}× ({data.holiday_name})</span>;\n * }\n * ```\n */\nexport function useHolidaySurcharge(\n params: HolidaySurchargeParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<HolidaySurchargeResponse> {\n return useOmniQuery(\n \"hr.holidaySurcharge\",\n params,\n (client, p) => client.hr.holidaySurcharge(p),\n options,\n );\n}\n","import type { EnergyLabelParams, EnergyLabelResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Retrieve the EP-Online energy label for a Dutch property.\n *\n * Calls `GET /v1/real-estate/energy-label`.\n * Pass `null` as `params` to skip the request.\n *\n * @example\n * ```tsx\n * const { data, loading } = useEnergyLabel(\n * postcode && houseNumber ? { postcode, houseNumber } : null\n * );\n * return <span>Energielabel: {data?.energy_label ?? \"–\"}</span>;\n * ```\n */\nexport function useEnergyLabel(\n params: EnergyLabelParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<EnergyLabelResponse> {\n return useOmniQuery(\n \"realEstate.energyLabel\",\n params,\n (client, p) => client.realEstate.energyLabel(p),\n options,\n );\n}\n","import type { EmissionZoneParams, EmissionZoneResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Check whether a Dutch vehicle (by licence plate) is zero-emission compliant\n * for urban emission zones.\n *\n * Calls `GET /v1/logistics/emission-zone`.\n * Pass `null` as `params` to skip the request.\n *\n * @example\n * ```tsx\n * const { data } = useEmissionZone(kenteken ? { kenteken } : null);\n * return <span>{data?.ze_compliant ? \"✅ ZE-compliant\" : \"❌ Niet toegestaan\"}</span>;\n * ```\n */\nexport function useEmissionZone(\n params: EmissionZoneParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<EmissionZoneResponse> {\n return useOmniQuery(\n \"logistics.emissionZone\",\n params,\n (client, p) => client.logistics.emissionZone(p),\n options,\n );\n}\n","import type { TransitDisruptionsParams, TransitDisruptionsResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Fetch current NS train disruptions for a given station.\n *\n * Calls `GET /v1/logistics/transit-disruptions`.\n * Pass `null` as `params` to skip the request.\n *\n * @example\n * ```tsx\n * const { data, loading } = useTransitDisruptions({ stationCode: \"ASD\" });\n *\n * if (loading) return <Spinner />;\n * return (\n * <ul>\n * {data?.disruptions.map(d => <li key={d.title}>{d.title}</li>)}\n * </ul>\n * );\n * ```\n */\nexport function useTransitDisruptions(\n params: TransitDisruptionsParams | null | undefined,\n options?: UseOmniQueryOptions,\n): OmniHookResult<TransitDisruptionsResponse> {\n return useOmniQuery(\n \"logistics.transitDisruptions\",\n params,\n (client, p) => client.logistics.transitDisruptions(p),\n options,\n );\n}\n","import type { GridTriggerParams, GridTriggerResponse } from \"@omnizoek/sdk\";\nimport { useOmniQuery, type OmniHookResult, type UseOmniQueryOptions } from \"./useOmniQuery.js\";\n\n/**\n * Check the current ENTSO-E day-ahead electricity price and whether it is\n * negative (a signal to run high-consumption processes).\n *\n * Calls `GET /v1/energy/grid-trigger`.\n * Always fetches unless `options.enabled` is `false`.\n *\n * @example\n * ```tsx\n * const { data } = useGridTrigger();\n *\n * if (data?.trigger) {\n * return <Banner>⚡ Stroomprijs negatief — goedkoop laden!</Banner>;\n * }\n * ```\n */\nexport function useGridTrigger(\n params?: GridTriggerParams,\n options?: UseOmniQueryOptions,\n): OmniHookResult<GridTriggerResponse> {\n // Always pass a params object (even empty) so the request fires by default.\n return useOmniQuery(\n \"energy.gridTrigger\",\n params ?? {},\n (client, p) => client.energy.gridTrigger(p),\n options,\n );\n}\n"],"mappings":";AAuBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,kBAA0C;AAsC1C;AAhCT,IAAM,cAAc,cAAiC,IAAI;AAoBlD,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAsB;AACpB,QAAM,SAAS;AAAA,IACb,MAAM,IAAI,WAAW,EAAE,QAAQ,SAAS,GAAG,QAAQ,CAAC;AAAA;AAAA,IAEpD,CAAC,QAAQ,OAAO;AAAA,EAClB;AAEA,SAAO,oBAAC,YAAY,UAAZ,EAAqB,OAAO,QAAS,UAAS;AACxD;AAUO,SAAS,gBAA4B;AAC1C,QAAM,SAAS,WAAW,WAAW;AACrC,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AACA,SAAO;AACT;;;ACjFA,OAAO,YAAY;AA0CZ,SAAS,aACd,aACA,QACA,SACA,SACmB;AACnB,QAAM,SAAS,cAAc;AAC7B,QAAM,YAAY,SAAS,YAAY;AAGvC,QAAM,SACJ,aAAa,UAAU,OAAO,CAAC,aAAa,MAAM,IAAI;AAExD,QAAM,EAAE,MAAM,OAAO,WAAW,cAAc,OAAO,IAAI;AAAA,IACvD;AAAA,IACA,CAAC,CAAC,EAAE,CAAC,MAAmB,QAAQ,QAAQ,CAAC;AAAA,IACzC,EAAE,oBAAoB,MAAM;AAAA,EAC9B;AAEA,SAAO;AAAA,IACL;AAAA,IACA,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,OAAO,SAAS;AAAA,IAChB,SAAS,MAAM,OAAO;AAAA,EACxB;AACF;;;ACtDO,SAAS,iBACd,QACA,SACuC;AACvC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,CAAC,QAAQ,MAAM,OAAO,IAAI,cAAc,CAAC;AAAA,IACzC;AAAA,EACF;AACF;;;ACfO,SAAS,aACd,QACA,SACmC;AACnC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,CAAC,QAAQ,MAAM,OAAO,QAAQ,UAAU,CAAC;AAAA,IACzC;AAAA,EACF;AACF;;;ACRO,SAAS,aACd,QACA,SACmC;AACnC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,CAAC,QAAQ,MAAM,OAAO,QAAQ,UAAU,CAAC;AAAA,IACzC;AAAA,EACF;AACF;;;ACNO,SAAS,mBACd,QACA,SAC2C;AAC3C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,CAAC,QAAQ,MAAM,OAAO,WAAW,gBAAgB,CAAC;AAAA,IAClD;AAAA,EACF;AACF;;;AChBO,SAAS,eACd,QACA,SACqC;AACrC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,CAAC,QAAQ,MAAM,OAAO,GAAG,YAAY,CAAC;AAAA,IACtC;AAAA,EACF;AACF;;;ACLO,SAAS,oBACd,QACA,SAC0C;AAC1C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,CAAC,QAAQ,MAAM,OAAO,GAAG,iBAAiB,CAAC;AAAA,IAC3C;AAAA,EACF;AACF;;;ACbO,SAAS,eACd,QACA,SACqC;AACrC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,CAAC,QAAQ,MAAM,OAAO,WAAW,YAAY,CAAC;AAAA,IAC9C;AAAA,EACF;AACF;;;ACXO,SAAS,gBACd,QACA,SACsC;AACtC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,CAAC,QAAQ,MAAM,OAAO,UAAU,aAAa,CAAC;AAAA,IAC9C;AAAA,EACF;AACF;;;ACLO,SAAS,sBACd,QACA,SAC4C;AAC5C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,CAAC,QAAQ,MAAM,OAAO,UAAU,mBAAmB,CAAC;AAAA,IACpD;AAAA,EACF;AACF;;;ACZO,SAAS,eACd,QACA,SACqC;AAErC,SAAO;AAAA,IACL;AAAA,IACA,UAAU,CAAC;AAAA,IACX,CAAC,QAAQ,MAAM,OAAO,OAAO,YAAY,CAAC;AAAA,IAC1C;AAAA,EACF;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@omnizoek/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React hooks for the OmniZoek API — address enrichment, IBAN, vehicle, energy labels and more.",
|
|
5
|
+
"author": "OmniZoek <support@omnizoek.nl>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://omnizoek.nl/docs",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/JakoRens/searchworks-nl.git",
|
|
11
|
+
"directory": "omni-react"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"omnizoek",
|
|
15
|
+
"react",
|
|
16
|
+
"hooks",
|
|
17
|
+
"netherlands",
|
|
18
|
+
"postcode",
|
|
19
|
+
"bag",
|
|
20
|
+
"iban",
|
|
21
|
+
"rdw",
|
|
22
|
+
"energielabel"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js",
|
|
32
|
+
"require": "./dist/index.cjs"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup",
|
|
40
|
+
"dev": "tsup --watch",
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"prepublishOnly": "npm run build"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@omnizoek/sdk": ">=0.1.1",
|
|
46
|
+
"react": ">=17",
|
|
47
|
+
"swr": ">=2"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@omnizoek/sdk": "^0.1.1",
|
|
51
|
+
"@types/react": "^18.0.0",
|
|
52
|
+
"react": "^18.0.0",
|
|
53
|
+
"swr": "^2.2.0",
|
|
54
|
+
"tsup": "^8.0.0",
|
|
55
|
+
"typescript": "^5.4.0"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=18"
|
|
59
|
+
}
|
|
60
|
+
}
|