react-shopwave-connect 0.4.6 → 0.4.7
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/README.md +11 -3
- package/dist/core/index.cjs +274 -130
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +292 -145
- package/dist/core/index.d.ts +292 -145
- package/dist/core/index.js +269 -131
- package/dist/core/index.js.map +1 -1
- package/dist/hooks/index.cjs +265 -112
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +90 -23
- package/dist/hooks/index.d.ts +90 -23
- package/dist/hooks/index.js +265 -113
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +294 -130
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +301 -145
- package/dist/index.d.ts +301 -145
- package/dist/index.js +288 -131
- package/dist/index.js.map +1 -1
- package/dist/next/index.cjs +67 -0
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +33 -2
- package/dist/next/index.d.ts +33 -2
- package/dist/next/index.js +67 -0
- package/dist/next/index.js.map +1 -1
- package/dist/server/index.cjs +68 -0
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +40 -3
- package/dist/server/index.d.ts +40 -3
- package/dist/server/index.js +68 -1
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -94,9 +94,10 @@ declare function apiSend<T>(path: string, method: "POST" | "PUT", payload: unkno
|
|
|
94
94
|
/**
|
|
95
95
|
* DELETE helper. Shopwave answers deletes with 205 and an empty body; if a body
|
|
96
96
|
* does come back and carries API errors, they are thrown. Returns the parsed
|
|
97
|
-
* body (`null` when empty).
|
|
97
|
+
* body (`null` when empty). `extras`, when given, travel in the `extras` header
|
|
98
|
+
* (the server forwards only keys its delete route allows).
|
|
98
99
|
*/
|
|
99
|
-
declare function apiDelete(path: string, options?: RequestOptions): Promise<unknown>;
|
|
100
|
+
declare function apiDelete(path: string, options?: RequestOptions, extras?: Extras): Promise<unknown>;
|
|
100
101
|
//#endregion
|
|
101
102
|
//#region src/core/errors.d.ts
|
|
102
103
|
/** Map of Shopwave API errors as found in `api.message.errors`, keyed by error code. */
|
|
@@ -360,6 +361,42 @@ declare function fetchProductTags(options?: RequestOptions): Promise<string[]>;
|
|
|
360
361
|
*/
|
|
361
362
|
declare function fetchProductInstanceTags(options?: RequestOptions): Promise<string[]>;
|
|
362
363
|
//#endregion
|
|
364
|
+
//#region src/core/store.d.ts
|
|
365
|
+
interface Store {
|
|
366
|
+
id: number;
|
|
367
|
+
lat: number;
|
|
368
|
+
lng: number;
|
|
369
|
+
addressLine1: string;
|
|
370
|
+
addressLine2: string | null;
|
|
371
|
+
addressLine3: string;
|
|
372
|
+
phoneNumber: string;
|
|
373
|
+
city: string;
|
|
374
|
+
postcode: string;
|
|
375
|
+
countryId: number | null;
|
|
376
|
+
timezoneId: number | null;
|
|
377
|
+
storeDeleteDate: string | null;
|
|
378
|
+
email: string | null;
|
|
379
|
+
sandbox: boolean | null;
|
|
380
|
+
}
|
|
381
|
+
interface StoreResponse {
|
|
382
|
+
stores: {
|
|
383
|
+
[key: number]: Store;
|
|
384
|
+
};
|
|
385
|
+
api: apiResponse;
|
|
386
|
+
}
|
|
387
|
+
interface FetchStoresParams {
|
|
388
|
+
/** Optional id filter. */
|
|
389
|
+
storeIds?: Array<number>;
|
|
390
|
+
/** Whether to include soft-deleted records. Defaults to `false`. */
|
|
391
|
+
deleted?: boolean;
|
|
392
|
+
/** @deprecated Pass `options.token` instead. Sent the same way (Authorization header). */
|
|
393
|
+
token?: string;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Fetches stores. Returns the flattened `Store[]`.
|
|
397
|
+
*/
|
|
398
|
+
declare function fetchStores(params?: FetchStoresParams, options?: RequestOptions): Promise<Store[]>;
|
|
399
|
+
//#endregion
|
|
363
400
|
//#region src/core/promotion.d.ts
|
|
364
401
|
/** Promotion rule identifiers as stored by the Shopwave API. */
|
|
365
402
|
declare enum PromotionRuleSet {
|
|
@@ -413,147 +450,6 @@ interface FetchPromotionsParams {
|
|
|
413
450
|
*/
|
|
414
451
|
declare function fetchPromotions(params?: FetchPromotionsParams, options?: RequestOptions): Promise<Promotion[]>;
|
|
415
452
|
//#endregion
|
|
416
|
-
//#region src/core/store.d.ts
|
|
417
|
-
interface Store {
|
|
418
|
-
id: number;
|
|
419
|
-
lat: number;
|
|
420
|
-
lng: number;
|
|
421
|
-
addressLine1: string;
|
|
422
|
-
addressLine2: string | null;
|
|
423
|
-
addressLine3: string;
|
|
424
|
-
phoneNumber: string;
|
|
425
|
-
city: string;
|
|
426
|
-
postcode: string;
|
|
427
|
-
countryId: number | null;
|
|
428
|
-
timezoneId: number | null;
|
|
429
|
-
storeDeleteDate: string | null;
|
|
430
|
-
email: string | null;
|
|
431
|
-
sandbox: boolean | null;
|
|
432
|
-
}
|
|
433
|
-
interface StoreResponse {
|
|
434
|
-
stores: {
|
|
435
|
-
[key: number]: Store;
|
|
436
|
-
};
|
|
437
|
-
api: apiResponse;
|
|
438
|
-
}
|
|
439
|
-
interface FetchStoresParams {
|
|
440
|
-
/** Optional id filter. */
|
|
441
|
-
storeIds?: Array<number>;
|
|
442
|
-
/** Whether to include soft-deleted records. Defaults to `false`. */
|
|
443
|
-
deleted?: boolean;
|
|
444
|
-
/** @deprecated Pass `options.token` instead. Sent the same way (Authorization header). */
|
|
445
|
-
token?: string;
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* Fetches stores. Returns the flattened `Store[]`.
|
|
449
|
-
*/
|
|
450
|
-
declare function fetchStores(params?: FetchStoresParams, options?: RequestOptions): Promise<Store[]>;
|
|
451
|
-
//#endregion
|
|
452
|
-
//#region src/core/report.d.ts
|
|
453
|
-
interface ReportKey {
|
|
454
|
-
name: string;
|
|
455
|
-
type: string;
|
|
456
|
-
item?: ReportKey[];
|
|
457
|
-
}
|
|
458
|
-
interface ReportData {
|
|
459
|
-
keys: ReportKey[];
|
|
460
|
-
data: any[][];
|
|
461
|
-
}
|
|
462
|
-
interface ReportResponse {
|
|
463
|
-
reports: {
|
|
464
|
-
[key: string]: ReportData;
|
|
465
|
-
};
|
|
466
|
-
api: apiResponse;
|
|
467
|
-
}
|
|
468
|
-
interface ReportQuery {
|
|
469
|
-
FROM: string;
|
|
470
|
-
WHERE?: {
|
|
471
|
-
AND?: string[];
|
|
472
|
-
OR?: string[];
|
|
473
|
-
};
|
|
474
|
-
SELECT?: string[];
|
|
475
|
-
LIMIT?: number;
|
|
476
|
-
OFFSET?: number;
|
|
477
|
-
}
|
|
478
|
-
interface ReportQueryMap {
|
|
479
|
-
[key: string]: ReportQuery;
|
|
480
|
-
}
|
|
481
|
-
/**
|
|
482
|
-
* Runs one or more report queries and returns the `reports` map keyed by query
|
|
483
|
-
* name. The query is JSON-encoded into the `extras.query` header, matching the
|
|
484
|
-
* original endpoint contract.
|
|
485
|
-
*/
|
|
486
|
-
declare function fetchReport(query: ReportQueryMap, options?: RequestOptions): Promise<ReportResponse["reports"]>;
|
|
487
|
-
//#endregion
|
|
488
|
-
//#region src/core/session.d.ts
|
|
489
|
-
/**
|
|
490
|
-
* Login status returned by the app's `/api/session` route. It deliberately
|
|
491
|
-
* never contains tokens — those stay in the encrypted httpOnly cookie.
|
|
492
|
-
*/
|
|
493
|
-
interface SessionStatus {
|
|
494
|
-
loggedIn: boolean;
|
|
495
|
-
/** Access-token expiry (epoch ms), when known. */
|
|
496
|
-
expiresAt?: number;
|
|
497
|
-
}
|
|
498
|
-
/**
|
|
499
|
-
* Reads the current login status from `GET /api/session`.
|
|
500
|
-
*
|
|
501
|
-
* Works with the new `react-shopwave-connect/next` session route
|
|
502
|
-
* (`{ loggedIn }`) and with older routes that returned the raw session
|
|
503
|
-
* (`{ token: {...} }`) — in that case only a boolean is surfaced.
|
|
504
|
-
*/
|
|
505
|
-
declare function fetchSession(options?: RequestOptions): Promise<SessionStatus>;
|
|
506
|
-
/**
|
|
507
|
-
* Path that starts a login and returns to `returnTo` afterwards.
|
|
508
|
-
* Navigate the browser to it (`window.location.href = loginPath(...)`).
|
|
509
|
-
*/
|
|
510
|
-
declare function loginPath(returnTo?: string, authPath?: string): string;
|
|
511
|
-
/** Path that logs out of the app and the Shopwave auth server. */
|
|
512
|
-
declare function logoutPath(authPath?: string): string;
|
|
513
|
-
/**
|
|
514
|
-
* Ends the current server session (no redirect).
|
|
515
|
-
*
|
|
516
|
-
* Prefer navigating to {@link logoutPath} when using
|
|
517
|
-
* `react-shopwave-connect/next`: it also signs the user out of the auth server.
|
|
518
|
-
*/
|
|
519
|
-
declare function logout(options?: RequestOptions): Promise<void>;
|
|
520
|
-
//#endregion
|
|
521
|
-
//#region src/core/entity.d.ts
|
|
522
|
-
/**
|
|
523
|
-
* Low-level, untyped mutations: the caller supplies the route and payload.
|
|
524
|
-
*
|
|
525
|
-
* Prefer the typed functions in `./entities` (`saveProduct`, `deleteCategory`,
|
|
526
|
-
* …): they know each route, build the request envelope, check the response and
|
|
527
|
-
* return the saved entity with its id. Keep these for routes that have no typed
|
|
528
|
-
* function yet (e.g. `/api/merchant`).
|
|
529
|
-
*/
|
|
530
|
-
/**
|
|
531
|
-
* Deletes `/api/{resourcePath}/{entityId}`.
|
|
532
|
-
*/
|
|
533
|
-
declare function deleteEntity(resourcePath: string, entityId: number | string, options?: RequestOptions): Promise<void>;
|
|
534
|
-
interface SubmitEntityArgs {
|
|
535
|
-
/** Fully-resolved endpoint, e.g. `/api/products` or `/api/products/42`. */
|
|
536
|
-
endpoint: string;
|
|
537
|
-
/** Defaults to PUT when an `entityId` exists, otherwise POST. */
|
|
538
|
-
method?: "POST" | "PUT";
|
|
539
|
-
/** The request payload (already transformed by the caller). */
|
|
540
|
-
payload: unknown;
|
|
541
|
-
}
|
|
542
|
-
interface SubmitEntityResponse<R = any> {
|
|
543
|
-
result?: R;
|
|
544
|
-
[key: string]: unknown;
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* Sends a create/update mutation. Returns the response's `result` field when it
|
|
548
|
-
* has one (older app routes wrapped their answer that way), otherwise the whole
|
|
549
|
-
* parsed response body. Throws `ShopwaveApiError` on HTTP or API errors.
|
|
550
|
-
*/
|
|
551
|
-
declare function submitEntity<R = any>({
|
|
552
|
-
endpoint,
|
|
553
|
-
method,
|
|
554
|
-
payload
|
|
555
|
-
}: SubmitEntityArgs, options?: RequestOptions): Promise<R | undefined>;
|
|
556
|
-
//#endregion
|
|
557
453
|
//#region src/core/entities.d.ts
|
|
558
454
|
/**
|
|
559
455
|
* How each Shopwave entity is addressed, shared by the client functions below
|
|
@@ -596,8 +492,15 @@ interface EntityDefinition {
|
|
|
596
492
|
* start = end and the record is expired without ever running.
|
|
597
493
|
*/
|
|
598
494
|
retireStartField?: string;
|
|
495
|
+
/**
|
|
496
|
+
* Header naming child records to delete instead of the whole record
|
|
497
|
+
* (`productComponentInstanceIds: 1,2`). Only `item()` DELETE uses it, and only when
|
|
498
|
+
* the caller's `extras` carry this one key (a non-empty list of ids); every other
|
|
499
|
+
* `extras` key is still dropped. Only for `deleteMode: "delete"`.
|
|
500
|
+
*/
|
|
501
|
+
childIdsHeader?: string;
|
|
599
502
|
}
|
|
600
|
-
type EntityKind = "product" | "category" | "store" | "promotion" | "employee" | "consumer";
|
|
503
|
+
type EntityKind = "product" | "category" | "store" | "promotion" | "employee" | "consumer" | "productComponent";
|
|
601
504
|
/** Entities that can be created/updated through the API. */
|
|
602
505
|
type WritableEntityKind = Exclude<EntityKind, "consumer">;
|
|
603
506
|
/** Entities that can be deleted (or retired) through the API. */
|
|
@@ -614,6 +517,27 @@ type DeletableEntityKind = Exclude<EntityKind, "consumer">;
|
|
|
614
517
|
* - employee: POST updates `roleId`, `joinedDate`, `exitDate` (names can't be
|
|
615
518
|
* changed); no DELETE (live API: "Cannot DELETE /employee") → retired via `exitDate`.
|
|
616
519
|
* - consumer: read-only (`GET` with `ids`, comma-separated); live POST → 404.
|
|
520
|
+
* - productComponent: modifier groups, `/product/component` (live, staging, 11 Nov 2026). The
|
|
521
|
+
* API reference lists no read filters; these are what the live API does:
|
|
522
|
+
* - Reads filter by `componentIds` (group ids) or `productIds` (the parent product; option
|
|
523
|
+
* products don't match). `productComponentIds` is ignored on reads: every group comes back.
|
|
524
|
+
* `deleted: false` gives live groups only, `true` deleted groups only, no header both.
|
|
525
|
+
* No match → 204 with an empty body. No order, sort, priority or position field anywhere.
|
|
526
|
+
* - Groups are keyed by id; `products` (option products) by product id; `productInstances`
|
|
527
|
+
* (option rows) by row id. Reads reformat values: price `"100"` → `"100.0"`,
|
|
528
|
+
* vatPercentage `"0.2000"` → `"0.200"`. `tags` and `name` are stored as sent (no trimming;
|
|
529
|
+
* a `tags` array is joined with commas; `tags` null or left out → null).
|
|
530
|
+
* - POST upserts (201, echoed under the ref). For each option product in `products`, its rows
|
|
531
|
+
* are replaced: every row sent is created afresh with a new id (a row `id` is ignored, also
|
|
532
|
+
* on a price change) and rows left out are removed. Option products left out of the save
|
|
533
|
+
* are untouched, and an empty `productInstances` removes nothing. A save without `products`
|
|
534
|
+
* updates only the group's own fields. The echo isn't proof of what was stored: renames of
|
|
535
|
+
* groups created moments earlier by a test run echoed the new name but never stuck (re-read
|
|
536
|
+
* for 90 s), while older groups, and groups created in Shopwave's own admin, renamed at
|
|
537
|
+
* once. Cause not yet known.
|
|
538
|
+
* - DELETE with `productComponentIds` (plural, comma list) → 205, soft delete. Adding
|
|
539
|
+
* `productComponentInstanceIds` deletes just those rows (205); they stay in live reads with
|
|
540
|
+
* `deleteDate` set. The singular `productComponentId` hangs (504 after 60 s).
|
|
617
541
|
*/
|
|
618
542
|
declare const SHOPWAVE_ENTITIES: Readonly<Record<EntityKind, EntityDefinition>>;
|
|
619
543
|
interface EntityTypes {
|
|
@@ -623,6 +547,7 @@ interface EntityTypes {
|
|
|
623
547
|
promotion: Promotion;
|
|
624
548
|
employee: Employee;
|
|
625
549
|
consumer: Consumer;
|
|
550
|
+
productComponent: ProductComponent;
|
|
626
551
|
}
|
|
627
552
|
/**
|
|
628
553
|
* What a save accepts: any subset of the entity's fields (plus extra API
|
|
@@ -710,6 +635,228 @@ declare const deleteEmployee: (id: EntityId, options?: RequestOptions) => Promis
|
|
|
710
635
|
declare const fetchEmployee: (id: EntityId, params?: FetchByIdParams, options?: RequestOptions) => Promise<Employee | null>;
|
|
711
636
|
declare const fetchConsumer: (id: EntityId, params?: FetchByIdParams, options?: RequestOptions) => Promise<Consumer | null>;
|
|
712
637
|
//#endregion
|
|
638
|
+
//#region src/core/productComponent.d.ts
|
|
639
|
+
/**
|
|
640
|
+
* Product components are modifier groups: a group belongs to a parent product
|
|
641
|
+
* (`productId`) and offers other products as options. Each option product has
|
|
642
|
+
* one or more option rows (`productInstances`). See `SHOPWAVE_ENTITIES.productComponent`
|
|
643
|
+
* for what the live API does on reads, saves and deletes.
|
|
644
|
+
*/
|
|
645
|
+
/** One option row of a product component. */
|
|
646
|
+
interface ProductComponentInstance {
|
|
647
|
+
id: number;
|
|
648
|
+
/** Name override for the option; `null` or `""` means the product's own name. Stored as sent. */
|
|
649
|
+
name: string | null;
|
|
650
|
+
/** Price as a decimal string, pence excluding VAT (reads return `"100.0"` for `"100"`). */
|
|
651
|
+
price: string;
|
|
652
|
+
/** VAT as a fraction string (`"0.200"`). */
|
|
653
|
+
vatPercentage: string;
|
|
654
|
+
quantity: number;
|
|
655
|
+
/** Comma-separated price tags, or `null`. Stored as sent (not trimmed). */
|
|
656
|
+
tags: string | null;
|
|
657
|
+
size?: string | null;
|
|
658
|
+
activeDate?: string | null;
|
|
659
|
+
/** Set once the row has been deleted; deleted rows still appear in live reads. */
|
|
660
|
+
deleteDate?: string | null;
|
|
661
|
+
}
|
|
662
|
+
/** A product offered as an option in a product component, with its option rows. */
|
|
663
|
+
interface ProductComponentProduct {
|
|
664
|
+
id: number;
|
|
665
|
+
name: string;
|
|
666
|
+
barcode?: string | null;
|
|
667
|
+
details?: string | null;
|
|
668
|
+
unit?: number | null;
|
|
669
|
+
activeDate?: string | null;
|
|
670
|
+
/** Option rows, keyed by row id on reads. */
|
|
671
|
+
productInstances: Record<string, ProductComponentInstance>;
|
|
672
|
+
}
|
|
673
|
+
/** A product component (modifier group). */
|
|
674
|
+
interface ProductComponent {
|
|
675
|
+
id: number;
|
|
676
|
+
name: string;
|
|
677
|
+
/** The parent product the group belongs to. */
|
|
678
|
+
productId: number;
|
|
679
|
+
minQuantity: number;
|
|
680
|
+
maxQuantity: number;
|
|
681
|
+
productTimestamp?: string;
|
|
682
|
+
/** Set once the group has been deleted (only `deleted: true` reads return it then). */
|
|
683
|
+
deleteDate?: string | null;
|
|
684
|
+
/** Option products, keyed by product id. */
|
|
685
|
+
products: Record<string, ProductComponentProduct>;
|
|
686
|
+
}
|
|
687
|
+
/** An option row as a caller holds it: every field optional, `tags` also as a list. */
|
|
688
|
+
type ProductComponentInstanceInput = Partial<Omit<ProductComponentInstance, "tags">> & {
|
|
689
|
+
tags?: string | ReadonlyArray<string> | null;
|
|
690
|
+
};
|
|
691
|
+
/** An option product as a caller holds it: rows keyed (as read) or as a list. */
|
|
692
|
+
type ProductComponentProductInput = Partial<Omit<ProductComponentProduct, "productInstances">> & {
|
|
693
|
+
productInstances?: Readonly<Record<string, ProductComponentInstanceInput>> | ReadonlyArray<ProductComponentInstanceInput>;
|
|
694
|
+
};
|
|
695
|
+
/**
|
|
696
|
+
* What {@link saveProductComponent} accepts. Include `id` to update; leave it out to create.
|
|
697
|
+
* `products` may be keyed by product id (as read) or a list.
|
|
698
|
+
*/
|
|
699
|
+
type ProductComponentSaveInput = Partial<Omit<ProductComponent, "products">> & {
|
|
700
|
+
products?: Readonly<Record<string, ProductComponentProductInput>> | ReadonlyArray<ProductComponentProductInput>;
|
|
701
|
+
[field: string]: unknown;
|
|
702
|
+
};
|
|
703
|
+
/**
|
|
704
|
+
* Builds the save body for a product component from a group as read (or as a form holds it):
|
|
705
|
+
* - `products` keyed by product id (a product without `id` takes its key);
|
|
706
|
+
* - each product's rows keyed `"0"`, `"1"`, …, like every other ref in a save;
|
|
707
|
+
* - rows that have a `deleteDate` are left out: the API recreates every row it's sent, so
|
|
708
|
+
* sending one back would bring a deleted option back as a new row;
|
|
709
|
+
* - server row fields (`id`, `activeDate`, `deleteDate`, `timestamp`) are removed, since the
|
|
710
|
+
* API gives every row it's sent a new id anyway;
|
|
711
|
+
* - a `tags` list becomes a comma string.
|
|
712
|
+
*
|
|
713
|
+
* The API replaces the rows of every option product in the save and leaves the others alone,
|
|
714
|
+
* so send all the rows to keep for each product included. To remove an option product
|
|
715
|
+
* entirely, delete its rows with {@link deleteProductComponentInstances}.
|
|
716
|
+
*/
|
|
717
|
+
declare function toProductComponentForSave(input: ProductComponentSaveInput): Record<string, unknown>;
|
|
718
|
+
interface FetchProductComponentsParams {
|
|
719
|
+
/** Parent products whose groups to read. */
|
|
720
|
+
productIds?: ReadonlyArray<number | string>;
|
|
721
|
+
/** Groups to read, by id. */
|
|
722
|
+
productComponentIds?: ReadonlyArray<number | string>;
|
|
723
|
+
/** `false` (default): live groups only. `true`: deleted groups only. */
|
|
724
|
+
deleted?: boolean;
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Reads product components, optionally filtered by parent product and/or group id.
|
|
728
|
+
* With no filter it returns every group on the merchant. Returns `[]` when nothing matches
|
|
729
|
+
* (the API answers 204), and when a filter list is empty (no request is made).
|
|
730
|
+
*
|
|
731
|
+
* Rows deleted with {@link deleteProductComponentInstances} are still returned, with
|
|
732
|
+
* `deleteDate` set; skip them when listing options.
|
|
733
|
+
*/
|
|
734
|
+
declare function fetchProductComponents(params?: FetchProductComponentsParams, options?: RequestOptions): Promise<ProductComponent[]>;
|
|
735
|
+
/**
|
|
736
|
+
* Reads one product component by id, or `null` when there's no such live group.
|
|
737
|
+
* Note that `{ deleted: true }` returns the group only if it *has* been deleted.
|
|
738
|
+
*/
|
|
739
|
+
declare const fetchProductComponent: (id: EntityId, params?: FetchByIdParams, options?: RequestOptions) => Promise<ProductComponent | null>;
|
|
740
|
+
/**
|
|
741
|
+
* Creates (no `id`) or updates (with `id`) a product component and returns it with its id.
|
|
742
|
+
* The body is built with {@link toProductComponentForSave}. Every option row sent is stored
|
|
743
|
+
* under a new id, so re-read with {@link fetchProductComponent} for the stored rows.
|
|
744
|
+
*/
|
|
745
|
+
declare const saveProductComponent: (input: ProductComponentSaveInput, options?: RequestOptions) => Promise<Saved<ProductComponent>>;
|
|
746
|
+
/** Deletes a product component (soft delete: `deleted: true` reads still return it). */
|
|
747
|
+
declare const deleteProductComponent: (id: EntityId, options?: RequestOptions) => Promise<void>;
|
|
748
|
+
/**
|
|
749
|
+
* Deletes some option rows of a product component, leaving the group and its other rows.
|
|
750
|
+
* The rows stay in reads with `deleteDate` set. Throws without calling the API when
|
|
751
|
+
* `instanceIds` is empty, because a delete without them would delete the whole group.
|
|
752
|
+
*/
|
|
753
|
+
declare function deleteProductComponentInstances(id: EntityId, instanceIds: ReadonlyArray<number | string>, options?: RequestOptions): Promise<void>;
|
|
754
|
+
//#endregion
|
|
755
|
+
//#region src/core/report.d.ts
|
|
756
|
+
interface ReportKey {
|
|
757
|
+
name: string;
|
|
758
|
+
type: string;
|
|
759
|
+
item?: ReportKey[];
|
|
760
|
+
}
|
|
761
|
+
interface ReportData {
|
|
762
|
+
keys: ReportKey[];
|
|
763
|
+
data: any[][];
|
|
764
|
+
}
|
|
765
|
+
interface ReportResponse {
|
|
766
|
+
reports: {
|
|
767
|
+
[key: string]: ReportData;
|
|
768
|
+
};
|
|
769
|
+
api: apiResponse;
|
|
770
|
+
}
|
|
771
|
+
interface ReportQuery {
|
|
772
|
+
FROM: string;
|
|
773
|
+
WHERE?: {
|
|
774
|
+
AND?: string[];
|
|
775
|
+
OR?: string[];
|
|
776
|
+
};
|
|
777
|
+
SELECT?: string[];
|
|
778
|
+
LIMIT?: number;
|
|
779
|
+
OFFSET?: number;
|
|
780
|
+
}
|
|
781
|
+
interface ReportQueryMap {
|
|
782
|
+
[key: string]: ReportQuery;
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Runs one or more report queries and returns the `reports` map keyed by query
|
|
786
|
+
* name. The query is JSON-encoded into the `extras.query` header, matching the
|
|
787
|
+
* original endpoint contract.
|
|
788
|
+
*/
|
|
789
|
+
declare function fetchReport(query: ReportQueryMap, options?: RequestOptions): Promise<ReportResponse["reports"]>;
|
|
790
|
+
//#endregion
|
|
791
|
+
//#region src/core/session.d.ts
|
|
792
|
+
/**
|
|
793
|
+
* Login status returned by the app's `/api/session` route. It deliberately
|
|
794
|
+
* never contains tokens — those stay in the encrypted httpOnly cookie.
|
|
795
|
+
*/
|
|
796
|
+
interface SessionStatus {
|
|
797
|
+
loggedIn: boolean;
|
|
798
|
+
/** Access-token expiry (epoch ms), when known. */
|
|
799
|
+
expiresAt?: number;
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Reads the current login status from `GET /api/session`.
|
|
803
|
+
*
|
|
804
|
+
* Works with the new `react-shopwave-connect/next` session route
|
|
805
|
+
* (`{ loggedIn }`) and with older routes that returned the raw session
|
|
806
|
+
* (`{ token: {...} }`) — in that case only a boolean is surfaced.
|
|
807
|
+
*/
|
|
808
|
+
declare function fetchSession(options?: RequestOptions): Promise<SessionStatus>;
|
|
809
|
+
/**
|
|
810
|
+
* Path that starts a login and returns to `returnTo` afterwards.
|
|
811
|
+
* Navigate the browser to it (`window.location.href = loginPath(...)`).
|
|
812
|
+
*/
|
|
813
|
+
declare function loginPath(returnTo?: string, authPath?: string): string;
|
|
814
|
+
/** Path that logs out of the app and the Shopwave auth server. */
|
|
815
|
+
declare function logoutPath(authPath?: string): string;
|
|
816
|
+
/**
|
|
817
|
+
* Ends the current server session (no redirect).
|
|
818
|
+
*
|
|
819
|
+
* Prefer navigating to {@link logoutPath} when using
|
|
820
|
+
* `react-shopwave-connect/next`: it also signs the user out of the auth server.
|
|
821
|
+
*/
|
|
822
|
+
declare function logout(options?: RequestOptions): Promise<void>;
|
|
823
|
+
//#endregion
|
|
824
|
+
//#region src/core/entity.d.ts
|
|
825
|
+
/**
|
|
826
|
+
* Low-level, untyped mutations: the caller supplies the route and payload.
|
|
827
|
+
*
|
|
828
|
+
* Prefer the typed functions in `./entities` (`saveProduct`, `deleteCategory`,
|
|
829
|
+
* …): they know each route, build the request envelope, check the response and
|
|
830
|
+
* return the saved entity with its id. Keep these for routes that have no typed
|
|
831
|
+
* function yet (e.g. `/api/merchant`).
|
|
832
|
+
*/
|
|
833
|
+
/**
|
|
834
|
+
* Deletes `/api/{resourcePath}/{entityId}`.
|
|
835
|
+
*/
|
|
836
|
+
declare function deleteEntity(resourcePath: string, entityId: number | string, options?: RequestOptions): Promise<void>;
|
|
837
|
+
interface SubmitEntityArgs {
|
|
838
|
+
/** Fully-resolved endpoint, e.g. `/api/products` or `/api/products/42`. */
|
|
839
|
+
endpoint: string;
|
|
840
|
+
/** Defaults to PUT when an `entityId` exists, otherwise POST. */
|
|
841
|
+
method?: "POST" | "PUT";
|
|
842
|
+
/** The request payload (already transformed by the caller). */
|
|
843
|
+
payload: unknown;
|
|
844
|
+
}
|
|
845
|
+
interface SubmitEntityResponse<R = any> {
|
|
846
|
+
result?: R;
|
|
847
|
+
[key: string]: unknown;
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Sends a create/update mutation. Returns the response's `result` field when it
|
|
851
|
+
* has one (older app routes wrapped their answer that way), otherwise the whole
|
|
852
|
+
* parsed response body. Throws `ShopwaveApiError` on HTTP or API errors.
|
|
853
|
+
*/
|
|
854
|
+
declare function submitEntity<R = any>({
|
|
855
|
+
endpoint,
|
|
856
|
+
method,
|
|
857
|
+
payload
|
|
858
|
+
}: SubmitEntityArgs, options?: RequestOptions): Promise<R | undefined>;
|
|
859
|
+
//#endregion
|
|
713
860
|
//#region src/core/basket.d.ts
|
|
714
861
|
interface BasketItem {
|
|
715
862
|
productId: number;
|
|
@@ -1455,6 +1602,15 @@ declare function useProductTags(options?: LookupOptions): QueryState<string[]>;
|
|
|
1455
1602
|
*/
|
|
1456
1603
|
declare function useProductInstanceTags(options?: LookupOptions): QueryState<string[]>;
|
|
1457
1604
|
//#endregion
|
|
1605
|
+
//#region src/hooks/useProductComponent.d.ts
|
|
1606
|
+
/**
|
|
1607
|
+
* Auto-fetches product components (modifier groups) on mount and whenever the params change:
|
|
1608
|
+
* a product's groups with `{ productIds: [id] }`, one group with `{ productComponentIds: [id] }`,
|
|
1609
|
+
* or every group with no filter. Option rows with a `deleteDate` are included; skip them when
|
|
1610
|
+
* listing options.
|
|
1611
|
+
*/
|
|
1612
|
+
declare function useProductComponent(params?: FetchProductComponentsParams, options?: RequestOptions): QueryState<ProductComponent[]>;
|
|
1613
|
+
//#endregion
|
|
1458
1614
|
//#region src/hooks/usePromotion.d.ts
|
|
1459
1615
|
/**
|
|
1460
1616
|
* Auto-fetches promotions on mount and whenever the params change.
|
|
@@ -1608,5 +1764,5 @@ interface UseBasketReportReturn {
|
|
|
1608
1764
|
*/
|
|
1609
1765
|
declare function useBasketReport(options?: RequestOptions): UseBasketReportReturn;
|
|
1610
1766
|
//#endregion
|
|
1611
|
-
export { Basket, BasketFilters, BasketItem, BasketPagination, BasketReportRow, BasketSummary, Category, CategoryResponse, CombineBasketRowsParams, Consumer, ConsumerResponse, CropRect, DEFAULT_BASKET_FILTERS, DEFAULT_PAGINATION, DeletableEntityKind, Employee, EmployeeResponse, EntityDefinition, EntityId, EntityInput, EntityKind, EntityTypes, ErrorMessage, Extras, FetchByIdParams, FetchCategoriesParams, FetchEmployeesParams, FetchProductsParams, FetchPromotionsParams, FetchStoresParams, FitImageOptions, ImageFitPlan, ImageRule, ImageRuleError, ImageSize, ImageTooSmallError, LookupDefinition, LookupKind, MERCHANT_COLOUR_KEYS, MERCHANT_FIELD_MAX_LENGTH, MERCHANT_IMAGE_SLOTS, MERCHANT_IMAGE_SLOT_KEYS, MERCHANT_LINK_KEYS, MERCHANT_LINK_PATHS, MERCHANT_OBJECT_FIELDS, MERCHANT_READ_ONLY_FIELDS, Merchant, MerchantColourKey, MerchantColourSet, MerchantColours, MerchantImageIds, MerchantImageSlot, MerchantImageSlotDefinition, MerchantLinkKey, MerchantLinks, MerchantPatch, MerchantResponse, MessageInfo, MutationState, ParsedBasket, PrepareImageOptions, Product, ProductInstance, ProductInstanceInput, ProductInstances, ProductResponse, ProductSaveInput, Promotion, PromotionResponse, PromotionRuleSet, QueryState, ReportData, ReportKey, ReportQuery, ReportQueryMap, ReportResponse, RepricedInstance, RequestOptions, ResourceDefinition, ResourceKind, SHOPWAVE_ENTITIES, SHOPWAVE_IMAGE_BASE_URL, SHOPWAVE_LOOKUPS, SHOPWAVE_RESOURCES, SHOPWAVE_UPLOAD, Saved, SessionStatus, ShopwaveApiError, ShopwaveErrorMap, Store, StoreResponse, SubmitEntityArgs, SubmitEntityResponse, SuccessMessage, UPLOAD_KINDS, UPLOAD_PREFIXES, UpdateMerchantOptions, UploadImageParams, UploadKind, UploadMerchantImageOptions, UploadPrefix, UploadedImage, UseBasketReportReturn, User, UserEmployee, UserResponse, WritableEntityKind, apiDelete, apiGet, apiRequest, apiResponse, apiSend, assertNoApiErrors, authorizationFor, buildBasketReportQuery, buildConsumerMap, checkImageRule, collectConsumerIds, collectProductIds, combineBasketRows, computeBasketSummary, coverCrop, deleteCategory, deleteEmployee, deleteEntity, deleteEntityById, deleteProduct, deletePromotion, deleteStore, fetchCategories, fetchCategory, fetchConsumer, fetchConsumers, fetchEmployee, fetchEmployees, fetchEntityById, fetchMerchant, fetchProduct, fetchProductInstanceTags, fetchProductTags, fetchProducts, fetchProductsMap, fetchPromotion, fetchPromotions, fetchReport, fetchSession, fetchStore, fetchStores, fetchUser, findRepricedInstances, fitImageToSize, formatDateForQuery, getApiErrorMap, getApiErrors, getImageUrl, getMerchantImage, getMerchantImageUrl, imageFileName, isSameInstancePrice, isUploadKind, isUploadPrefix, loginPath, logout, logoutPath, merchantLinksFromForm, merchantLinksToForm, normalizeMerchantLinks, normalizeTagList, parseAspectRatio, parseBasketReportData, planImageFit, prepareImage, productImageRole, readImageSize, rolesById, saveCategory, saveEmployee, saveEntities, saveEntity, saveProduct, savePromotion, saveStore, setMerchantImage, submitEntity, toProductInstancesForSave, toShopwaveApiError, toStoredImageIds, toStoredProductImages, updateMerchant, uploadImage, uploadMerchantImage, useBasketReport, useCategory, useConsumer, useDelete, useEmployee, useLogout, useMerchant, useProduct, useProductInstanceTags, useProductTags, usePromotion, useReport, useSession, useStore, useSubmit, useUpdateMerchant, useUploadImage, useUploadMerchantImage, useUser, validateMerchant, withToken };
|
|
1767
|
+
export { Basket, BasketFilters, BasketItem, BasketPagination, BasketReportRow, BasketSummary, Category, CategoryResponse, CombineBasketRowsParams, Consumer, ConsumerResponse, CropRect, DEFAULT_BASKET_FILTERS, DEFAULT_PAGINATION, DeletableEntityKind, Employee, EmployeeResponse, EntityDefinition, EntityId, EntityInput, EntityKind, EntityTypes, ErrorMessage, Extras, FetchByIdParams, FetchCategoriesParams, FetchEmployeesParams, FetchProductComponentsParams, FetchProductsParams, FetchPromotionsParams, FetchStoresParams, FitImageOptions, ImageFitPlan, ImageRule, ImageRuleError, ImageSize, ImageTooSmallError, LookupDefinition, LookupKind, MERCHANT_COLOUR_KEYS, MERCHANT_FIELD_MAX_LENGTH, MERCHANT_IMAGE_SLOTS, MERCHANT_IMAGE_SLOT_KEYS, MERCHANT_LINK_KEYS, MERCHANT_LINK_PATHS, MERCHANT_OBJECT_FIELDS, MERCHANT_READ_ONLY_FIELDS, Merchant, MerchantColourKey, MerchantColourSet, MerchantColours, MerchantImageIds, MerchantImageSlot, MerchantImageSlotDefinition, MerchantLinkKey, MerchantLinks, MerchantPatch, MerchantResponse, MessageInfo, MutationState, ParsedBasket, PrepareImageOptions, Product, ProductComponent, ProductComponentInstance, ProductComponentInstanceInput, ProductComponentProduct, ProductComponentProductInput, ProductComponentSaveInput, ProductInstance, ProductInstanceInput, ProductInstances, ProductResponse, ProductSaveInput, Promotion, PromotionResponse, PromotionRuleSet, QueryState, ReportData, ReportKey, ReportQuery, ReportQueryMap, ReportResponse, RepricedInstance, RequestOptions, ResourceDefinition, ResourceKind, SHOPWAVE_ENTITIES, SHOPWAVE_IMAGE_BASE_URL, SHOPWAVE_LOOKUPS, SHOPWAVE_RESOURCES, SHOPWAVE_UPLOAD, Saved, SessionStatus, ShopwaveApiError, ShopwaveErrorMap, Store, StoreResponse, SubmitEntityArgs, SubmitEntityResponse, SuccessMessage, UPLOAD_KINDS, UPLOAD_PREFIXES, UpdateMerchantOptions, UploadImageParams, UploadKind, UploadMerchantImageOptions, UploadPrefix, UploadedImage, UseBasketReportReturn, User, UserEmployee, UserResponse, WritableEntityKind, apiDelete, apiGet, apiRequest, apiResponse, apiSend, assertNoApiErrors, authorizationFor, buildBasketReportQuery, buildConsumerMap, checkImageRule, collectConsumerIds, collectProductIds, combineBasketRows, computeBasketSummary, coverCrop, deleteCategory, deleteEmployee, deleteEntity, deleteEntityById, deleteProduct, deleteProductComponent, deleteProductComponentInstances, deletePromotion, deleteStore, fetchCategories, fetchCategory, fetchConsumer, fetchConsumers, fetchEmployee, fetchEmployees, fetchEntityById, fetchMerchant, fetchProduct, fetchProductComponent, fetchProductComponents, fetchProductInstanceTags, fetchProductTags, fetchProducts, fetchProductsMap, fetchPromotion, fetchPromotions, fetchReport, fetchSession, fetchStore, fetchStores, fetchUser, findRepricedInstances, fitImageToSize, formatDateForQuery, getApiErrorMap, getApiErrors, getImageUrl, getMerchantImage, getMerchantImageUrl, imageFileName, isSameInstancePrice, isUploadKind, isUploadPrefix, loginPath, logout, logoutPath, merchantLinksFromForm, merchantLinksToForm, normalizeMerchantLinks, normalizeTagList, parseAspectRatio, parseBasketReportData, planImageFit, prepareImage, productImageRole, readImageSize, rolesById, saveCategory, saveEmployee, saveEntities, saveEntity, saveProduct, saveProductComponent, savePromotion, saveStore, setMerchantImage, submitEntity, toProductComponentForSave, toProductInstancesForSave, toShopwaveApiError, toStoredImageIds, toStoredProductImages, updateMerchant, uploadImage, uploadMerchantImage, useBasketReport, useCategory, useConsumer, useDelete, useEmployee, useLogout, useMerchant, useProduct, useProductComponent, useProductInstanceTags, useProductTags, usePromotion, useReport, useSession, useStore, useSubmit, useUpdateMerchant, useUploadImage, useUploadMerchantImage, useUser, validateMerchant, withToken };
|
|
1612
1768
|
//# sourceMappingURL=index.d.ts.map
|