react-shopwave-connect 0.1.1

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.
@@ -0,0 +1,424 @@
1
+ //#region src/hooks/shared.d.ts
2
+ /**
3
+ * Consistent return shape for every auto-fetching ("query") hook.
4
+ */
5
+ interface QueryState<T> {
6
+ data: T | null;
7
+ loading: boolean;
8
+ error: string | null;
9
+ /** Re-runs the underlying fetch. */
10
+ refetch: () => void;
11
+ }
12
+ /**
13
+ * Consistent return shape for manually-triggered ("mutation") hooks.
14
+ */
15
+ interface MutationState<TData, TArgs extends any[]> {
16
+ /** Triggers the request. Resolves to the result, or `null` on error. */
17
+ mutate: (...args: TArgs) => Promise<TData | null>;
18
+ data: TData | null;
19
+ loading: boolean;
20
+ error: string | null;
21
+ }
22
+ //#endregion
23
+ //#region src/core/types.d.ts
24
+ /**
25
+ * Shared API envelope types.
26
+ *
27
+ * Preserved exactly from the original `model/message.ts` so existing
28
+ * response handling keeps working.
29
+ */
30
+ interface ErrorMessage {
31
+ id: number;
32
+ title: string;
33
+ details: string;
34
+ moreInfo: string;
35
+ }
36
+ interface SuccessMessage {
37
+ id: number;
38
+ title: string;
39
+ details: string;
40
+ }
41
+ interface MessageInfo {
42
+ errors: {
43
+ [key: number]: ErrorMessage;
44
+ };
45
+ success: {
46
+ [key: number]: SuccessMessage;
47
+ };
48
+ }
49
+ interface apiResponse {
50
+ message: MessageInfo;
51
+ codeBaseVersion: number;
52
+ executionTime_milliSeconds: number;
53
+ }
54
+ //#endregion
55
+ //#region src/core/request.d.ts
56
+ /**
57
+ * Per-call configuration shared by every core API function.
58
+ *
59
+ * Nothing here is React-specific. By accepting these options per call, the
60
+ * core layer works in the browser/Next (relative `/api/...` URLs, the default)
61
+ * AND in Node / CLI / Vue / Angular by passing an absolute `baseUrl`, an auth
62
+ * `token`, and/or a custom `fetch` implementation.
63
+ */
64
+ interface RequestOptions {
65
+ /**
66
+ * Prefixed in front of every request path. Leave undefined in the browser to
67
+ * use relative URLs (e.g. `/api/products`). In Node/CLI pass something like
68
+ * `https://api.shopwave.com`.
69
+ */
70
+ baseUrl?: string;
71
+ /** OAuth/session token forwarded in the `extras.token` header. */
72
+ token?: string;
73
+ /**
74
+ * Custom fetch implementation. Defaults to the global `fetch`. Useful for
75
+ * Node < 18, testing, or injecting interceptors.
76
+ */
77
+ fetch?: typeof fetch;
78
+ /** Optional abort signal for cancellation (used by the hooks layer). */
79
+ signal?: AbortSignal;
80
+ }
81
+ //#endregion
82
+ //#region src/core/category.d.ts
83
+ interface Category {
84
+ id: number;
85
+ title: string;
86
+ parentId: number | null;
87
+ deleteDate: string;
88
+ activeDate: string;
89
+ type: number;
90
+ }
91
+ interface FetchCategoriesParams {
92
+ categoryIds?: Array<number>;
93
+ /** Whether to include soft-deleted records. Defaults to `false`. */
94
+ deleted?: boolean;
95
+ /** Token override (also accepted via `options.token`). */
96
+ token?: string;
97
+ }
98
+ //#endregion
99
+ //#region src/core/consumer.d.ts
100
+ interface Consumer {
101
+ id: number;
102
+ activeCount: number;
103
+ firstName: string;
104
+ lastName: string;
105
+ email: string;
106
+ }
107
+ //#endregion
108
+ //#region src/core/employee.d.ts
109
+ interface Employee {
110
+ id: number;
111
+ firstName: string;
112
+ lastName: string;
113
+ email: string;
114
+ roleId: number;
115
+ joinedDate: string;
116
+ exitDate: string;
117
+ stores: {
118
+ [key: number]: {
119
+ id: number;
120
+ roleId: number;
121
+ };
122
+ };
123
+ }
124
+ interface FetchEmployeesParams {
125
+ /** Optional id filter. Forwarded when provided. */
126
+ employeeIds?: Array<number>;
127
+ /** Whether to include soft-deleted records. Defaults to `false`. */
128
+ deleted?: boolean;
129
+ }
130
+ //#endregion
131
+ //#region src/core/product.d.ts
132
+ interface ProductInstance {
133
+ id: number;
134
+ price: string;
135
+ taxPercentage: string;
136
+ timestamp: string;
137
+ size: string;
138
+ name: string;
139
+ activeDate: string;
140
+ tags: string;
141
+ }
142
+ interface Product {
143
+ id: number;
144
+ barcode: string;
145
+ name: string;
146
+ details: string;
147
+ tags: string;
148
+ unit: number;
149
+ timestamp: string;
150
+ activeDate: string;
151
+ deleteDate: string;
152
+ images: Array<string>;
153
+ categories: Array<number>;
154
+ instances: {
155
+ [key: number]: ProductInstance;
156
+ };
157
+ }
158
+ interface FetchProductsParams {
159
+ productIds?: Array<number>;
160
+ storeId?: number;
161
+ /** Whether to include soft-deleted records. Defaults to `false`. */
162
+ deleted?: boolean;
163
+ /** Token override (also accepted via `options.token`). */
164
+ token?: string;
165
+ }
166
+ //#endregion
167
+ //#region src/core/promotion.d.ts
168
+ /** Promotion rule identifiers as stored by the Shopwave API. */
169
+ declare enum PromotionRuleSet {
170
+ Percentage = "|%^/",
171
+ Combo = "&%</",
172
+ MealDeal = "&=^/",
173
+ }
174
+ interface Promotion {
175
+ id: number;
176
+ merchantId: number;
177
+ storeIds: number[];
178
+ categoryIds: {
179
+ [key: string]: number;
180
+ };
181
+ productIds: {
182
+ [key: string]: any;
183
+ };
184
+ title: string;
185
+ details: string | null;
186
+ terms: string | null;
187
+ startDate: string;
188
+ endDate: string;
189
+ daysAvailable: number[];
190
+ automatic: number;
191
+ rule: PromotionRuleSet;
192
+ x: number;
193
+ y: number | null;
194
+ }
195
+ interface FetchPromotionsParams {
196
+ /** Optional id filter. Forwarded when provided. */
197
+ promotionIds?: Array<number>;
198
+ /** Whether to include soft-deleted records. Defaults to `false`. */
199
+ deleted?: boolean;
200
+ /** Token override (also accepted via `options.token`). */
201
+ token?: string;
202
+ }
203
+ //#endregion
204
+ //#region src/core/store.d.ts
205
+ interface Store {
206
+ id: number;
207
+ lat: number;
208
+ lng: number;
209
+ addressLine1: string;
210
+ addressLine2: string | null;
211
+ addressLine3: string;
212
+ phoneNumber: string;
213
+ city: string;
214
+ postcode: string;
215
+ countryId: number | null;
216
+ timezoneId: number | null;
217
+ storeDeleteDate: string | null;
218
+ email: string | null;
219
+ sandbox: boolean | null;
220
+ }
221
+ interface FetchStoresParams {
222
+ /** Whether to include soft-deleted records. Defaults to `false`. */
223
+ deleted?: boolean;
224
+ }
225
+ //#endregion
226
+ //#region src/core/report.d.ts
227
+ interface ReportKey {
228
+ name: string;
229
+ type: string;
230
+ item?: ReportKey[];
231
+ }
232
+ interface ReportData {
233
+ keys: ReportKey[];
234
+ data: any[][];
235
+ }
236
+ interface ReportResponse {
237
+ reports: {
238
+ [key: string]: ReportData;
239
+ };
240
+ api: apiResponse;
241
+ }
242
+ interface ReportQuery {
243
+ FROM: string;
244
+ WHERE?: {
245
+ AND?: string[];
246
+ OR?: string[];
247
+ };
248
+ SELECT?: string[];
249
+ LIMIT?: number;
250
+ OFFSET?: number;
251
+ }
252
+ interface ReportQueryMap {
253
+ [key: string]: ReportQuery;
254
+ }
255
+ //#endregion
256
+ //#region src/core/entity.d.ts
257
+ interface SubmitEntityArgs {
258
+ /** Fully-resolved endpoint, e.g. `/api/products` or `/api/products/42`. */
259
+ endpoint: string;
260
+ /** Defaults to PUT when an `entityId` exists, otherwise POST. */
261
+ method?: "POST" | "PUT";
262
+ /** The request payload (already transformed by the caller). */
263
+ payload: unknown;
264
+ }
265
+ //#endregion
266
+ //#region src/core/basket.d.ts
267
+ interface BasketItem {
268
+ productId: number;
269
+ productName: string;
270
+ quantity: number;
271
+ price: number;
272
+ tax: number;
273
+ }
274
+ interface BasketReportRow {
275
+ id: number;
276
+ basketId: number;
277
+ basketName: string;
278
+ consumerId: number;
279
+ consumerName: string;
280
+ consumerEmail: string;
281
+ products: BasketItem[];
282
+ basketTotal: number;
283
+ tax: number;
284
+ dateTime: string;
285
+ status: string;
286
+ }
287
+ interface BasketSummary {
288
+ totalBaskets: number;
289
+ totalRevenue: number;
290
+ totalTax: number;
291
+ uniqueConsumers: number;
292
+ }
293
+ interface BasketFilters {
294
+ search: string;
295
+ dateRange: {
296
+ start: Date | null;
297
+ end: Date | null;
298
+ };
299
+ consumerId: number | null;
300
+ status: "all" | "pending" | "completed" | "cancelled";
301
+ }
302
+ interface BasketPagination {
303
+ page: number;
304
+ pageSize: number;
305
+ total: number;
306
+ }
307
+ //#endregion
308
+ //#region src/hooks/useCategory.d.ts
309
+ /**
310
+ * Auto-fetches categories on mount and whenever the params change.
311
+ * Manual reloads are available via `refetch` (replaces the old `reloadFlag`).
312
+ */
313
+ declare function useCategory(params?: FetchCategoriesParams, options?: RequestOptions): QueryState<Category[]>;
314
+ //#endregion
315
+ //#region src/hooks/useConsumer.d.ts
316
+ /**
317
+ * Auto-fetches consumers by id. Disabled (no request) until at least one id is
318
+ * supplied, mirroring the original early-return behaviour.
319
+ */
320
+ declare function useConsumer(consumerIds: number[] | null, options?: RequestOptions): QueryState<Consumer[]>;
321
+ //#endregion
322
+ //#region src/hooks/useEmployee.d.ts
323
+ /**
324
+ * Auto-fetches employees on mount and whenever the params change.
325
+ */
326
+ declare function useEmployee(params?: FetchEmployeesParams, options?: RequestOptions): QueryState<Employee[]>;
327
+ //#endregion
328
+ //#region src/hooks/useProduct.d.ts
329
+ /**
330
+ * Auto-fetches products on mount and whenever the params change.
331
+ */
332
+ declare function useProduct(params?: FetchProductsParams, options?: RequestOptions): QueryState<Product[]>;
333
+ //#endregion
334
+ //#region src/hooks/usePromotion.d.ts
335
+ /**
336
+ * Auto-fetches promotions on mount and whenever the params change.
337
+ * Manual reloads are available via `refetch`.
338
+ */
339
+ declare function usePromotion(params?: FetchPromotionsParams, options?: RequestOptions): QueryState<Promotion[]>;
340
+ //#endregion
341
+ //#region src/hooks/useStore.d.ts
342
+ /**
343
+ * Auto-fetches stores on mount. Manual reloads via `refetch`
344
+ * (replaces the old `reloadFlag` argument).
345
+ */
346
+ declare function useStore(params?: FetchStoresParams, options?: RequestOptions): QueryState<Store[]>;
347
+ //#endregion
348
+ //#region src/hooks/useReport.d.ts
349
+ /**
350
+ * Auto-fetches one or more reports. Disabled (no request) until a non-null
351
+ * query is supplied, mirroring the original early-return behaviour.
352
+ */
353
+ declare function useReport(query: ReportQueryMap | null, options?: RequestOptions): QueryState<ReportResponse["reports"]>;
354
+ //#endregion
355
+ //#region src/hooks/useDelete.d.ts
356
+ /**
357
+ * Manually-triggered delete. Returns `{ mutate, loading, error, data }`.
358
+ *
359
+ * Note: the original `useHandleDelete` surfaced notistack toasts. That UI
360
+ * concern is left to the host app — handle success/error from the returned
361
+ * state or the promise resolved by `mutate`.
362
+ *
363
+ * @example
364
+ * const { mutate, loading } = useDelete();
365
+ * await mutate("products", 42);
366
+ */
367
+ declare function useDelete(options?: RequestOptions): MutationState<void, [resourcePath: string, entityId: number | string]>;
368
+ //#endregion
369
+ //#region src/hooks/useSubmit.d.ts
370
+ /**
371
+ * Manually-triggered create/update. Returns `{ mutate, loading, error, data }`,
372
+ * where `data` is the API `result` payload.
373
+ *
374
+ * The original `useHandleSubmit` bundled validation, payload transformation and
375
+ * notistack toasts. Those are app concerns: resolve the endpoint/method/payload
376
+ * in your component and pass them in, then react to the returned state.
377
+ *
378
+ * @example
379
+ * const { mutate, loading } = useSubmit<Product>();
380
+ * const saved = await mutate({
381
+ * endpoint: id ? `/api/products/${id}` : "/api/products",
382
+ * method: id ? "PUT" : "POST",
383
+ * payload,
384
+ * });
385
+ */
386
+ declare function useSubmit<R = any>(options?: RequestOptions): MutationState<R | undefined, [args: SubmitEntityArgs]>;
387
+ //#endregion
388
+ //#region src/hooks/useLogout.d.ts
389
+ /**
390
+ * Manually-triggered logout (ends the server session).
391
+ *
392
+ * This is framework-agnostic and does NOT redirect. The original `useLogout`
393
+ * also pushed the browser to the auth-server logout URL via `next/navigation`
394
+ * and `'use server'` actions; that part is Next-specific and stays in your app.
395
+ *
396
+ * @example
397
+ * const { mutate: doLogout } = useLogout();
398
+ * await doLogout();
399
+ * router.push(logoutUrl); // app-specific redirect
400
+ */
401
+ declare function useLogout(options?: RequestOptions): MutationState<void, []>;
402
+ //#endregion
403
+ //#region src/hooks/useBasketReport.d.ts
404
+ interface UseBasketReportReturn {
405
+ rows: BasketReportRow[];
406
+ summary: BasketSummary;
407
+ loading: boolean;
408
+ error: string | null;
409
+ filters: BasketFilters;
410
+ setFilters: (filters: Partial<BasketFilters>) => void;
411
+ pagination: BasketPagination;
412
+ setPagination: (page: number, pageSize: number) => void;
413
+ refresh: () => void;
414
+ }
415
+ /**
416
+ * Composite hook that orchestrates the report → consumers → products pipeline
417
+ * for the basket report screen. All the data-shaping logic now lives in the
418
+ * framework-agnostic `core/basket` helpers; this hook is the thin React glue
419
+ * (state, memoisation, effects) on top of them.
420
+ */
421
+ declare function useBasketReport(options?: RequestOptions): UseBasketReportReturn;
422
+ //#endregion
423
+ export { type MutationState, type QueryState, type UseBasketReportReturn, useBasketReport, useCategory, useConsumer, useDelete, useEmployee, useLogout, useProduct, usePromotion, useReport, useStore, useSubmit };
424
+ //# sourceMappingURL=index.d.ts.map