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,481 @@
1
+ //#region src/core/types.d.ts
2
+ /**
3
+ * Shared API envelope types.
4
+ *
5
+ * Preserved exactly from the original `model/message.ts` so existing
6
+ * response handling keeps working.
7
+ */
8
+ interface ErrorMessage {
9
+ id: number;
10
+ title: string;
11
+ details: string;
12
+ moreInfo: string;
13
+ }
14
+ interface SuccessMessage {
15
+ id: number;
16
+ title: string;
17
+ details: string;
18
+ }
19
+ interface MessageInfo {
20
+ errors: {
21
+ [key: number]: ErrorMessage;
22
+ };
23
+ success: {
24
+ [key: number]: SuccessMessage;
25
+ };
26
+ }
27
+ interface apiResponse {
28
+ message: MessageInfo;
29
+ codeBaseVersion: number;
30
+ executionTime_milliSeconds: number;
31
+ }
32
+ //#endregion
33
+ //#region src/core/request.d.ts
34
+ /**
35
+ * Per-call configuration shared by every core API function.
36
+ *
37
+ * Nothing here is React-specific. By accepting these options per call, the
38
+ * core layer works in the browser/Next (relative `/api/...` URLs, the default)
39
+ * AND in Node / CLI / Vue / Angular by passing an absolute `baseUrl`, an auth
40
+ * `token`, and/or a custom `fetch` implementation.
41
+ */
42
+ interface RequestOptions {
43
+ /**
44
+ * Prefixed in front of every request path. Leave undefined in the browser to
45
+ * use relative URLs (e.g. `/api/products`). In Node/CLI pass something like
46
+ * `https://api.shopwave.com`.
47
+ */
48
+ baseUrl?: string;
49
+ /** OAuth/session token forwarded in the `extras.token` header. */
50
+ token?: string;
51
+ /**
52
+ * Custom fetch implementation. Defaults to the global `fetch`. Useful for
53
+ * Node < 18, testing, or injecting interceptors.
54
+ */
55
+ fetch?: typeof fetch;
56
+ /** Optional abort signal for cancellation (used by the hooks layer). */
57
+ signal?: AbortSignal;
58
+ }
59
+ /** The Shopwave API ships request metadata inside a single `extras` header. */
60
+ type Extras = Record<string, unknown>;
61
+ /**
62
+ * Returns a JSON string of API errors if the response carries any, otherwise
63
+ * `null`. Mirrors the original `!responseJson.api.message.errors` checks.
64
+ */
65
+ declare function getApiErrors(api?: apiResponse): string | null;
66
+ /**
67
+ * GET helper. Sends request metadata via the `extras` header exactly like the
68
+ * original hooks did, parses JSON, and returns the typed payload.
69
+ */
70
+ declare function apiGet<T>(path: string, extras: Extras, options?: RequestOptions): Promise<T>;
71
+ /**
72
+ * JSON body helper for POST/PUT mutations.
73
+ */
74
+ declare function apiSend<T>(path: string, method: "POST" | "PUT", payload: unknown, options?: RequestOptions): Promise<T>;
75
+ /**
76
+ * DELETE helper.
77
+ */
78
+ declare function apiDelete(path: string, options?: RequestOptions): Promise<void>;
79
+ //#endregion
80
+ //#region src/core/category.d.ts
81
+ interface Category {
82
+ id: number;
83
+ title: string;
84
+ parentId: number | null;
85
+ deleteDate: string;
86
+ activeDate: string;
87
+ type: number;
88
+ }
89
+ interface CategoryResponse {
90
+ categories: {
91
+ [key: number]: Category;
92
+ };
93
+ api: apiResponse;
94
+ }
95
+ interface FetchCategoriesParams {
96
+ categoryIds?: Array<number>;
97
+ /** Whether to include soft-deleted records. Defaults to `false`. */
98
+ deleted?: boolean;
99
+ /** Token override (also accepted via `options.token`). */
100
+ token?: string;
101
+ }
102
+ /**
103
+ * Fetches categories. Framework-agnostic: returns the flattened `Category[]`
104
+ * or throws on API errors.
105
+ */
106
+ declare function fetchCategories(params?: FetchCategoriesParams, options?: RequestOptions): Promise<Category[]>;
107
+ //#endregion
108
+ //#region src/core/consumer.d.ts
109
+ interface Consumer {
110
+ id: number;
111
+ activeCount: number;
112
+ firstName: string;
113
+ lastName: string;
114
+ email: string;
115
+ }
116
+ interface ConsumerResponse {
117
+ consumers: {
118
+ [key: number]: Consumer;
119
+ };
120
+ api: apiResponse;
121
+ }
122
+ /**
123
+ * Fetches consumers by id. Returns an empty array when no ids are supplied
124
+ * (the original hook short-circuited in that case).
125
+ */
126
+ declare function fetchConsumers(consumerIds: number[] | null | undefined, options?: RequestOptions): Promise<Consumer[]>;
127
+ //#endregion
128
+ //#region src/core/employee.d.ts
129
+ declare const rolesById: {
130
+ readonly "1": "Owner";
131
+ readonly "2": "Manager";
132
+ readonly "3": "Assistant";
133
+ readonly "4": "Guest";
134
+ readonly "5": "Assistant Manager";
135
+ };
136
+ interface Employee {
137
+ id: number;
138
+ firstName: string;
139
+ lastName: string;
140
+ email: string;
141
+ roleId: number;
142
+ joinedDate: string;
143
+ exitDate: string;
144
+ stores: {
145
+ [key: number]: {
146
+ id: number;
147
+ roleId: number;
148
+ };
149
+ };
150
+ }
151
+ interface EmployeeResponse {
152
+ employees: {
153
+ [key: number]: Employee;
154
+ };
155
+ api: apiResponse;
156
+ }
157
+ interface FetchEmployeesParams {
158
+ /** Optional id filter. Forwarded when provided. */
159
+ employeeIds?: Array<number>;
160
+ /** Whether to include soft-deleted records. Defaults to `false`. */
161
+ deleted?: boolean;
162
+ }
163
+ /**
164
+ * Fetches employees. Returns the flattened `Employee[]`.
165
+ */
166
+ declare function fetchEmployees(params?: FetchEmployeesParams, options?: RequestOptions): Promise<Employee[]>;
167
+ //#endregion
168
+ //#region src/core/product.d.ts
169
+ interface ProductInstance {
170
+ id: number;
171
+ price: string;
172
+ taxPercentage: string;
173
+ timestamp: string;
174
+ size: string;
175
+ name: string;
176
+ activeDate: string;
177
+ tags: string;
178
+ }
179
+ interface Product {
180
+ id: number;
181
+ barcode: string;
182
+ name: string;
183
+ details: string;
184
+ tags: string;
185
+ unit: number;
186
+ timestamp: string;
187
+ activeDate: string;
188
+ deleteDate: string;
189
+ images: Array<string>;
190
+ categories: Array<number>;
191
+ instances: {
192
+ [key: number]: ProductInstance;
193
+ };
194
+ }
195
+ interface ProductResponse {
196
+ products: {
197
+ [key: number]: Product;
198
+ };
199
+ api: apiResponse;
200
+ }
201
+ interface FetchProductsParams {
202
+ productIds?: Array<number>;
203
+ storeId?: number;
204
+ /** Whether to include soft-deleted records. Defaults to `false`. */
205
+ deleted?: boolean;
206
+ /** Token override (also accepted via `options.token`). */
207
+ token?: string;
208
+ }
209
+ /**
210
+ * Fetches products. Returns the flattened `Product[]`.
211
+ */
212
+ declare function fetchProducts(params?: FetchProductsParams, options?: RequestOptions): Promise<Product[]>;
213
+ /**
214
+ * Fetches products by id and returns them keyed by id, transparently batching
215
+ * the request (default 200 ids per call) to stay within API limits. Extracted
216
+ * from the original `useBasketReport` inline batching loop so it can be reused
217
+ * outside React.
218
+ */
219
+ declare function fetchProductsMap(productIds: number[] | null | undefined, options?: RequestOptions, batchSize?: number): Promise<{
220
+ [id: number]: Product;
221
+ }>;
222
+ //#endregion
223
+ //#region src/core/promotion.d.ts
224
+ /** Promotion rule identifiers as stored by the Shopwave API. */
225
+ declare enum PromotionRuleSet {
226
+ Percentage = "|%^/",
227
+ Combo = "&%</",
228
+ MealDeal = "&=^/",
229
+ }
230
+ interface Promotion {
231
+ id: number;
232
+ merchantId: number;
233
+ storeIds: number[];
234
+ categoryIds: {
235
+ [key: string]: number;
236
+ };
237
+ productIds: {
238
+ [key: string]: any;
239
+ };
240
+ title: string;
241
+ details: string | null;
242
+ terms: string | null;
243
+ startDate: string;
244
+ endDate: string;
245
+ daysAvailable: number[];
246
+ automatic: number;
247
+ rule: PromotionRuleSet;
248
+ x: number;
249
+ y: number | null;
250
+ }
251
+ interface PromotionResponse {
252
+ promotions: {
253
+ [key: number]: Promotion;
254
+ };
255
+ api: apiResponse;
256
+ }
257
+ interface FetchPromotionsParams {
258
+ /** Optional id filter. Forwarded when provided. */
259
+ promotionIds?: Array<number>;
260
+ /** Whether to include soft-deleted records. Defaults to `false`. */
261
+ deleted?: boolean;
262
+ /** Token override (also accepted via `options.token`). */
263
+ token?: string;
264
+ }
265
+ /**
266
+ * Fetches promotions. Returns the flattened `Promotion[]`.
267
+ */
268
+ declare function fetchPromotions(params?: FetchPromotionsParams, options?: RequestOptions): Promise<Promotion[]>;
269
+ //#endregion
270
+ //#region src/core/store.d.ts
271
+ interface Store {
272
+ id: number;
273
+ lat: number;
274
+ lng: number;
275
+ addressLine1: string;
276
+ addressLine2: string | null;
277
+ addressLine3: string;
278
+ phoneNumber: string;
279
+ city: string;
280
+ postcode: string;
281
+ countryId: number | null;
282
+ timezoneId: number | null;
283
+ storeDeleteDate: string | null;
284
+ email: string | null;
285
+ sandbox: boolean | null;
286
+ }
287
+ interface StoreResponse {
288
+ stores: {
289
+ [key: number]: Store;
290
+ };
291
+ api: apiResponse;
292
+ }
293
+ interface FetchStoresParams {
294
+ /** Whether to include soft-deleted records. Defaults to `false`. */
295
+ deleted?: boolean;
296
+ }
297
+ /**
298
+ * Fetches stores. Returns the flattened `Store[]`.
299
+ */
300
+ declare function fetchStores(params?: FetchStoresParams, options?: RequestOptions): Promise<Store[]>;
301
+ //#endregion
302
+ //#region src/core/report.d.ts
303
+ interface ReportKey {
304
+ name: string;
305
+ type: string;
306
+ item?: ReportKey[];
307
+ }
308
+ interface ReportData {
309
+ keys: ReportKey[];
310
+ data: any[][];
311
+ }
312
+ interface ReportResponse {
313
+ reports: {
314
+ [key: string]: ReportData;
315
+ };
316
+ api: apiResponse;
317
+ }
318
+ interface ReportQuery {
319
+ FROM: string;
320
+ WHERE?: {
321
+ AND?: string[];
322
+ OR?: string[];
323
+ };
324
+ SELECT?: string[];
325
+ LIMIT?: number;
326
+ OFFSET?: number;
327
+ }
328
+ interface ReportQueryMap {
329
+ [key: string]: ReportQuery;
330
+ }
331
+ /**
332
+ * Runs one or more report queries and returns the `reports` map keyed by query
333
+ * name. The query is JSON-encoded into the `extras.query` header, matching the
334
+ * original endpoint contract.
335
+ */
336
+ declare function fetchReport(query: ReportQueryMap, options?: RequestOptions): Promise<ReportResponse["reports"]>;
337
+ //#endregion
338
+ //#region src/core/session.d.ts
339
+ /**
340
+ * Ends the current server session.
341
+ *
342
+ * This is the framework-agnostic half of the original `useLogout` hook. The
343
+ * Next.js-specific redirect logic (router.push to the auth server logout URL,
344
+ * built from server actions) is intentionally NOT included here because it is
345
+ * tied to `next/navigation` and `'use server'` actions — see the README.
346
+ */
347
+ declare function logout(options?: RequestOptions): Promise<void>;
348
+ //#endregion
349
+ //#region src/core/entity.d.ts
350
+ /**
351
+ * Generic CRUD-style mutations extracted from `useHandleDelete` /
352
+ * `useHandleSubmit`. The original hooks also surfaced notistack snackbars; that
353
+ * UI concern is deliberately left to the hooks/host layer so core stays
354
+ * dependency-free.
355
+ */
356
+ /**
357
+ * Deletes `/api/{resourcePath}/{entityId}`.
358
+ */
359
+ declare function deleteEntity(resourcePath: string, entityId: number | string, options?: RequestOptions): Promise<void>;
360
+ interface SubmitEntityArgs {
361
+ /** Fully-resolved endpoint, e.g. `/api/products` or `/api/products/42`. */
362
+ endpoint: string;
363
+ /** Defaults to PUT when an `entityId` exists, otherwise POST. */
364
+ method?: "POST" | "PUT";
365
+ /** The request payload (already transformed by the caller). */
366
+ payload: unknown;
367
+ }
368
+ interface SubmitEntityResponse<R = any> {
369
+ result?: R;
370
+ [key: string]: unknown;
371
+ }
372
+ /**
373
+ * Sends a create/update mutation and returns the parsed `result` field
374
+ * (matching the original `result.result` access).
375
+ */
376
+ declare function submitEntity<R = any>({
377
+ endpoint,
378
+ method,
379
+ payload
380
+ }: SubmitEntityArgs, options?: RequestOptions): Promise<R | undefined>;
381
+ //#endregion
382
+ //#region src/core/basket.d.ts
383
+ interface BasketItem {
384
+ productId: number;
385
+ productName: string;
386
+ quantity: number;
387
+ price: number;
388
+ tax: number;
389
+ }
390
+ interface Basket {
391
+ id: number;
392
+ name: string;
393
+ consumerId: number;
394
+ products: BasketItem[];
395
+ total: number;
396
+ taxTotal: number;
397
+ status: "pending" | "completed" | "cancelled";
398
+ completeDate: string;
399
+ }
400
+ interface BasketReportRow {
401
+ id: number;
402
+ basketId: number;
403
+ basketName: string;
404
+ consumerId: number;
405
+ consumerName: string;
406
+ consumerEmail: string;
407
+ products: BasketItem[];
408
+ basketTotal: number;
409
+ tax: number;
410
+ dateTime: string;
411
+ status: string;
412
+ }
413
+ interface BasketSummary {
414
+ totalBaskets: number;
415
+ totalRevenue: number;
416
+ totalTax: number;
417
+ uniqueConsumers: number;
418
+ }
419
+ interface BasketFilters {
420
+ search: string;
421
+ dateRange: {
422
+ start: Date | null;
423
+ end: Date | null;
424
+ };
425
+ consumerId: number | null;
426
+ status: "all" | "pending" | "completed" | "cancelled";
427
+ }
428
+ interface BasketPagination {
429
+ page: number;
430
+ pageSize: number;
431
+ total: number;
432
+ }
433
+ declare const DEFAULT_BASKET_FILTERS: BasketFilters;
434
+ declare const DEFAULT_PAGINATION: BasketPagination;
435
+ /** Intermediate shape produced by {@link parseBasketReportData}. */
436
+ interface ParsedBasket {
437
+ id: number;
438
+ name: string;
439
+ consumerId: number;
440
+ products: BasketItem[];
441
+ total: number;
442
+ taxTotal: number;
443
+ status: "completed";
444
+ completeDate: string;
445
+ }
446
+ /** Formats a date as `YYYY-MM-DD HH:mm:ss` for the report query. */
447
+ declare function formatDateForQuery(date: Date, isEndOfDay?: boolean): string;
448
+ /** Builds the `Basket` report query from a set of filters. */
449
+ declare function buildBasketReportQuery(filters: BasketFilters): ReportQueryMap;
450
+ /** Flattens the raw report rows/keys into structured baskets. */
451
+ declare function parseBasketReportData(reports: ReportResponse["reports"] | null | undefined): ParsedBasket[];
452
+ /** Unique non-null consumer ids referenced by a set of baskets. */
453
+ declare function collectConsumerIds(baskets: ParsedBasket[]): number[] | null;
454
+ /** Unique product ids referenced by a set of baskets. */
455
+ declare function collectProductIds(baskets: ParsedBasket[]): number[] | null;
456
+ interface CombineBasketRowsParams {
457
+ baskets: ParsedBasket[];
458
+ consumerMap: {
459
+ [id: number]: Consumer;
460
+ };
461
+ productMap: {
462
+ [id: number]: Product;
463
+ };
464
+ search?: string;
465
+ }
466
+ /** Joins baskets with consumer + product lookups, applies search, sorts. */
467
+ declare function combineBasketRows({
468
+ baskets,
469
+ consumerMap,
470
+ productMap,
471
+ search
472
+ }: CombineBasketRowsParams): BasketReportRow[];
473
+ /** Aggregate totals for a set of report rows. */
474
+ declare function computeBasketSummary(rows: BasketReportRow[]): BasketSummary;
475
+ /** Builds a consumer id → consumer lookup. */
476
+ declare function buildConsumerMap(consumers: Consumer[] | null | undefined): {
477
+ [id: number]: Consumer;
478
+ };
479
+ //#endregion
480
+ export { Basket, BasketFilters, BasketItem, BasketPagination, BasketReportRow, BasketSummary, Category, CategoryResponse, CombineBasketRowsParams, Consumer, ConsumerResponse, DEFAULT_BASKET_FILTERS, DEFAULT_PAGINATION, Employee, EmployeeResponse, ErrorMessage, Extras, FetchCategoriesParams, FetchEmployeesParams, FetchProductsParams, FetchPromotionsParams, FetchStoresParams, MessageInfo, ParsedBasket, Product, ProductInstance, ProductResponse, Promotion, PromotionResponse, PromotionRuleSet, ReportData, ReportKey, ReportQuery, ReportQueryMap, ReportResponse, RequestOptions, Store, StoreResponse, SubmitEntityArgs, SubmitEntityResponse, SuccessMessage, apiDelete, apiGet, apiResponse, apiSend, buildBasketReportQuery, buildConsumerMap, collectConsumerIds, collectProductIds, combineBasketRows, computeBasketSummary, deleteEntity, fetchCategories, fetchConsumers, fetchEmployees, fetchProducts, fetchProductsMap, fetchPromotions, fetchReport, fetchStores, formatDateForQuery, getApiErrors, logout, parseBasketReportData, rolesById, submitEntity };
481
+ //# sourceMappingURL=index.d.ts.map