react-shopwave-connect 0.4.1 → 0.4.3

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.
@@ -546,6 +546,26 @@ declare function useEmployee(params?: FetchEmployeesParams, options?: RequestOpt
546
546
  */
547
547
  declare function useProduct(params?: FetchProductsParams, options?: RequestOptions): QueryState<Product[]>;
548
548
  //#endregion
549
+ //#region src/hooks/useProductTags.d.ts
550
+ type LookupOptions = RequestOptions & {
551
+ /** Fetch only when true (e.g. once a tag field is first opened). Defaults to true. */
552
+ enabled?: boolean;
553
+ };
554
+ /**
555
+ * The merchant's distinct product tags, for a tag field's suggestions.
556
+ * `data` is `string[]` once loaded.
557
+ *
558
+ * @example
559
+ * const [opened, setOpened] = useState(false);
560
+ * const { data: tags, loading } = useProductTags({ enabled: opened });
561
+ */
562
+ declare function useProductTags(options?: LookupOptions): QueryState<string[]>;
563
+ /**
564
+ * The merchant's distinct price-instance (channel) tags: Eat In, Takeout, …
565
+ * `data` is `string[]` once loaded.
566
+ */
567
+ declare function useProductInstanceTags(options?: LookupOptions): QueryState<string[]>;
568
+ //#endregion
549
569
  //#region src/hooks/usePromotion.d.ts
550
570
  /**
551
571
  * Auto-fetches promotions on mount and whenever the params change.
@@ -699,5 +719,5 @@ interface UseBasketReportReturn {
699
719
  */
700
720
  declare function useBasketReport(options?: RequestOptions): UseBasketReportReturn;
701
721
  //#endregion
702
- export { type MutationState, type QueryState, type UseBasketReportReturn, useBasketReport, useCategory, useConsumer, useDelete, useEmployee, useLogout, useMerchant, useProduct, usePromotion, useReport, useSession, useStore, useSubmit, useUpdateMerchant, useUploadImage, useUploadMerchantImage, useUser };
722
+ export { type MutationState, type QueryState, type UseBasketReportReturn, useBasketReport, useCategory, useConsumer, useDelete, useEmployee, useLogout, useMerchant, useProduct, useProductInstanceTags, useProductTags, usePromotion, useReport, useSession, useStore, useSubmit, useUpdateMerchant, useUploadImage, useUploadMerchantImage, useUser };
703
723
  //# sourceMappingURL=index.d.cts.map
@@ -546,6 +546,26 @@ declare function useEmployee(params?: FetchEmployeesParams, options?: RequestOpt
546
546
  */
547
547
  declare function useProduct(params?: FetchProductsParams, options?: RequestOptions): QueryState<Product[]>;
548
548
  //#endregion
549
+ //#region src/hooks/useProductTags.d.ts
550
+ type LookupOptions = RequestOptions & {
551
+ /** Fetch only when true (e.g. once a tag field is first opened). Defaults to true. */
552
+ enabled?: boolean;
553
+ };
554
+ /**
555
+ * The merchant's distinct product tags, for a tag field's suggestions.
556
+ * `data` is `string[]` once loaded.
557
+ *
558
+ * @example
559
+ * const [opened, setOpened] = useState(false);
560
+ * const { data: tags, loading } = useProductTags({ enabled: opened });
561
+ */
562
+ declare function useProductTags(options?: LookupOptions): QueryState<string[]>;
563
+ /**
564
+ * The merchant's distinct price-instance (channel) tags: Eat In, Takeout, …
565
+ * `data` is `string[]` once loaded.
566
+ */
567
+ declare function useProductInstanceTags(options?: LookupOptions): QueryState<string[]>;
568
+ //#endregion
549
569
  //#region src/hooks/usePromotion.d.ts
550
570
  /**
551
571
  * Auto-fetches promotions on mount and whenever the params change.
@@ -699,5 +719,5 @@ interface UseBasketReportReturn {
699
719
  */
700
720
  declare function useBasketReport(options?: RequestOptions): UseBasketReportReturn;
701
721
  //#endregion
702
- export { type MutationState, type QueryState, type UseBasketReportReturn, useBasketReport, useCategory, useConsumer, useDelete, useEmployee, useLogout, useMerchant, useProduct, usePromotion, useReport, useSession, useStore, useSubmit, useUpdateMerchant, useUploadImage, useUploadMerchantImage, useUser };
722
+ export { type MutationState, type QueryState, type UseBasketReportReturn, useBasketReport, useCategory, useConsumer, useDelete, useEmployee, useLogout, useMerchant, useProduct, useProductInstanceTags, useProductTags, usePromotion, useReport, useSession, useStore, useSubmit, useUpdateMerchant, useUploadImage, useUploadMerchantImage, useUser };
703
723
  //# sourceMappingURL=index.d.ts.map
@@ -259,6 +259,106 @@ async function fetchProductsMap(productIds, options = {}, batchSize = 200) {
259
259
  return result;
260
260
  }
261
261
 
262
+ //#endregion
263
+ //#region src/core/resources.ts
264
+ /**
265
+ * - merchant: `GET /merchant`; `POST /merchant` with `{ merchant: { id, … } }`
266
+ * updates it (without an `id` the API would create a second merchant, so the
267
+ * route requires one).
268
+ * - user: `GET /user` (read-only here; the API's `POST /user` invites users and
269
+ * needs the admin scope).
270
+ */
271
+ const SHOPWAVE_RESOURCES = Object.freeze({
272
+ merchant: {
273
+ route: "merchant",
274
+ key: "merchant",
275
+ upstream: "merchant",
276
+ writable: true
277
+ },
278
+ user: {
279
+ route: "user",
280
+ key: "user",
281
+ upstream: "user",
282
+ writable: false
283
+ }
284
+ });
285
+ /** `UploadKind` → the API's `contentType` value. */
286
+ const UPLOAD_KINDS = Object.freeze({
287
+ merchant: "merchant",
288
+ merchantFeature: "merchantFeature",
289
+ product: "product",
290
+ user: "user",
291
+ applicationLogo: "applicaionLogo",
292
+ applicationImages: "applicaionImages"
293
+ });
294
+ /** How uploads are addressed (app route and Shopwave uploader). */
295
+ const SHOPWAVE_UPLOAD = Object.freeze({
296
+ route: "upload",
297
+ upstream: "uploader",
298
+ kindHeader: "contentType",
299
+ fileField: "file",
300
+ kindField: "kind"
301
+ });
302
+ function isUploadKind(value) {
303
+ return typeof value === "string" && Object.prototype.hasOwnProperty.call(UPLOAD_KINDS, value);
304
+ }
305
+ const SHOPWAVE_LOOKUPS = Object.freeze({
306
+ productTags: {
307
+ route: "products/tags",
308
+ key: "tags",
309
+ upstream: "product/tags"
310
+ },
311
+ productInstanceTags: {
312
+ route: "products/instance-tags",
313
+ key: "tags",
314
+ upstream: "product/instance/tags"
315
+ }
316
+ });
317
+
318
+ //#endregion
319
+ //#region src/core/productTags.ts
320
+ /**
321
+ * Turns a tag list from the API into clean strings: trims each tag, drops
322
+ * blanks and anything that isn't text, and removes exact duplicates (first one
323
+ * wins). The API's own order is kept. A map is accepted too (its values are
324
+ * used), in case the API ever answers keyed by id.
325
+ */
326
+ function normalizeTagList(value) {
327
+ const list = Array.isArray(value) ? value : value && typeof value === "object" ? Object.values(value) : [];
328
+ const seen = /* @__PURE__ */ new Set();
329
+ const out = [];
330
+ for (const item of list) {
331
+ if (typeof item !== "string" && typeof item !== "number") continue;
332
+ const tag = String(item).trim();
333
+ if (!tag || seen.has(tag)) continue;
334
+ seen.add(tag);
335
+ out.push(tag);
336
+ }
337
+ return out;
338
+ }
339
+ async function fetchLookup(kind, options) {
340
+ const def = SHOPWAVE_LOOKUPS[kind];
341
+ if (!def) throw new Error(`Unknown Shopwave lookup "${kind}"`);
342
+ const json = await apiGet(`/api/${def.route}`, {}, options);
343
+ assertNoApiErrors(json, 200);
344
+ return normalizeTagList(json?.[def.key]);
345
+ }
346
+ /**
347
+ * Every distinct tag used on the merchant's products (`GET /product/tags`),
348
+ * for a tag field's suggestions. Returns `[]` when there are none.
349
+ */
350
+ function fetchProductTags(options = {}) {
351
+ return fetchLookup("productTags", options);
352
+ }
353
+ /**
354
+ * Every distinct tag used on the merchant's price instances
355
+ * (`GET /product/instance/tags`): the channel names (Eat In, Takeout, …).
356
+ * Returns `[]` when there are none.
357
+ */
358
+ function fetchProductInstanceTags(options = {}) {
359
+ return fetchLookup("productInstanceTags", options);
360
+ }
361
+
262
362
  //#endregion
263
363
  //#region src/core/promotion.ts
264
364
  /**
@@ -512,50 +612,6 @@ function buildConsumerMap(consumers) {
512
612
  return map;
513
613
  }
514
614
 
515
- //#endregion
516
- //#region src/core/resources.ts
517
- /**
518
- * - merchant: `GET /merchant`; `POST /merchant` with `{ merchant: { id, … } }`
519
- * updates it (without an `id` the API would create a second merchant, so the
520
- * route requires one).
521
- * - user: `GET /user` (read-only here; the API's `POST /user` invites users and
522
- * needs the admin scope).
523
- */
524
- const SHOPWAVE_RESOURCES = Object.freeze({
525
- merchant: {
526
- route: "merchant",
527
- key: "merchant",
528
- upstream: "merchant",
529
- writable: true
530
- },
531
- user: {
532
- route: "user",
533
- key: "user",
534
- upstream: "user",
535
- writable: false
536
- }
537
- });
538
- /** `UploadKind` → the API's `contentType` value. */
539
- const UPLOAD_KINDS = Object.freeze({
540
- merchant: "merchant",
541
- merchantFeature: "merchantFeature",
542
- product: "product",
543
- user: "user",
544
- applicationLogo: "applicaionLogo",
545
- applicationImages: "applicaionImages"
546
- });
547
- /** How uploads are addressed (app route and Shopwave uploader). */
548
- const SHOPWAVE_UPLOAD = Object.freeze({
549
- route: "upload",
550
- upstream: "uploader",
551
- kindHeader: "contentType",
552
- fileField: "file",
553
- kindField: "kind"
554
- });
555
- function isUploadKind(value) {
556
- return typeof value === "string" && Object.prototype.hasOwnProperty.call(UPLOAD_KINDS, value);
557
- }
558
-
559
615
  //#endregion
560
616
  //#region src/core/imageFit.ts
561
617
  /**
@@ -1100,6 +1156,33 @@ function useProduct(params = {}, options) {
1100
1156
  ]);
1101
1157
  }
1102
1158
 
1159
+ //#endregion
1160
+ //#region src/hooks/useProductTags.ts
1161
+ /**
1162
+ * The merchant's distinct product tags, for a tag field's suggestions.
1163
+ * `data` is `string[]` once loaded.
1164
+ *
1165
+ * @example
1166
+ * const [opened, setOpened] = useState(false);
1167
+ * const { data: tags, loading } = useProductTags({ enabled: opened });
1168
+ */
1169
+ function useProductTags(options) {
1170
+ return useQuery((signal) => fetchProductTags({
1171
+ ...options,
1172
+ signal
1173
+ }), [options?.baseUrl, options?.token], options?.enabled ?? true);
1174
+ }
1175
+ /**
1176
+ * The merchant's distinct price-instance (channel) tags: Eat In, Takeout, …
1177
+ * `data` is `string[]` once loaded.
1178
+ */
1179
+ function useProductInstanceTags(options) {
1180
+ return useQuery((signal) => fetchProductInstanceTags({
1181
+ ...options,
1182
+ signal
1183
+ }), [options?.baseUrl, options?.token], options?.enabled ?? true);
1184
+ }
1185
+
1103
1186
  //#endregion
1104
1187
  //#region src/hooks/usePromotion.ts
1105
1188
  /**
@@ -1410,5 +1493,5 @@ function useBasketReport(options) {
1410
1493
  }
1411
1494
 
1412
1495
  //#endregion
1413
- export { useBasketReport, useCategory, useConsumer, useDelete, useEmployee, useLogout, useMerchant, useProduct, usePromotion, useReport, useSession, useStore, useSubmit, useUpdateMerchant, useUploadImage, useUploadMerchantImage, useUser };
1496
+ export { useBasketReport, useCategory, useConsumer, useDelete, useEmployee, useLogout, useMerchant, useProduct, useProductInstanceTags, useProductTags, usePromotion, useReport, useSession, useStore, useSubmit, useUpdateMerchant, useUploadImage, useUploadMerchantImage, useUser };
1414
1497
  //# sourceMappingURL=index.js.map