react-shopwave-connect 0.4.3 → 0.4.4

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.
@@ -275,18 +275,37 @@ declare const SHOPWAVE_RESOURCES: Readonly<Record<ResourceKind, ResourceDefiniti
275
275
  type UploadKind = "merchant" | "merchantFeature" | "product" | "user" | "applicationLogo" | "applicationImages";
276
276
  /** `UploadKind` → the API's `contentType` value. */
277
277
  declare const UPLOAD_KINDS: Readonly<Record<UploadKind, string>>;
278
+ /**
279
+ * The role an image plays, sent to Shopwave as the uploader's `prefix` header.
280
+ * The uploader names the file `<prefix>_<hash>.<ext>`, so the role travels with
281
+ * the file wherever a record stores it (a product's `images`). Live, merchant
282
+ * 5644, 4 Nov 2026: all four values answered 201.
283
+ * - `product`: a product gallery image;
284
+ * - `product_thumbnail`: the product's lead image, shown in lists;
285
+ * - `variant` / `variant_thumbnail`: a variant's own image and its lead image
286
+ * (used by the Connect integrations).
287
+ *
288
+ * Values are the ones Connect's `uploadFileToShopwave` sends.
289
+ */
290
+ type UploadPrefix = "product" | "product_thumbnail" | "variant" | "variant_thumbnail";
291
+ /** Every `UploadPrefix`, longest first so a name check never takes `product` for `product_thumbnail`. */
292
+ declare const UPLOAD_PREFIXES: ReadonlyArray<UploadPrefix>;
278
293
  /** How uploads are addressed (app route and Shopwave uploader). */
279
294
  declare const SHOPWAVE_UPLOAD: Readonly<{
280
- /** App route: `POST /api/<route>` (multipart `file` + `kind`). */
295
+ /** App route: `POST /api/<route>` (multipart `file` + `kind`, optional `prefix`). */
281
296
  route: "upload";
282
297
  /** Shopwave path: `PUT {apiUrl}/uploader` (multipart `file`). */
283
298
  upstream: "uploader";
284
299
  /** Header that carries the upload kind upstream. */
285
300
  kindHeader: "contentType";
301
+ /** Header that carries the image role upstream (see `UploadPrefix`). */
302
+ prefixHeader: "prefix";
286
303
  /** Multipart field name for the file, on both sides. */
287
304
  fileField: "file";
288
305
  /** Multipart field name for the kind in the app request. */
289
306
  kindField: "kind";
307
+ /** Multipart field name for the image role in the app request. */
308
+ prefixField: "prefix";
290
309
  }>;
291
310
  /**
292
311
  * Read-only lists that aren't records: the merchant's distinct tags.
@@ -445,9 +464,11 @@ interface UploadOptions {
445
464
  }
446
465
  interface UploadHandlers {
447
466
  /**
448
- * Multipart `file` + `kind` (see `UploadKind`) → `PUT {apiUrl}/uploader`.
449
- * Answers with Shopwave's reply (201 `{ fileName, path, api }`); 400 for a
450
- * missing file or unknown kind, 413 when too large, 415 for other types.
467
+ * Multipart `file` + `kind` (see `UploadKind`), and optionally `prefix`
468
+ * (see `UploadPrefix`) → `PUT {apiUrl}/uploader` with the `contentType` and
469
+ * `prefix` headers. Answers with Shopwave's reply (201 `{ fileName, path, api }`);
470
+ * 400 for a missing file or an unknown kind or prefix, 413 when too large,
471
+ * 415 for other types.
451
472
  */
452
473
  POST: RouteHandler;
453
474
  }
@@ -483,5 +504,5 @@ interface ShopwaveApiHandlers {
483
504
  declare function shopwaveDateTime(date?: Date): string;
484
505
  declare function createShopwaveApiHandlers(config: ShopwaveApiConfig): ShopwaveApiHandlers;
485
506
  //#endregion
486
- export { BLOCKED_EXTRAS, type CollectionHandlers, type DeletableEntityKind, type EntityDefinition, type EntityKind, type ForwardInit, type ItemHandlers, type LookupDefinition, type LookupKind, RequestBodyError, type ResourceDefinition, type ResourceHandlers, type ResourceKind, type RouteContext, type RouteHandler, SHOPWAVE_ENTITIES, SHOPWAVE_LOOKUPS, SHOPWAVE_RESOURCES, SHOPWAVE_TOKEN_EXPIRED_ERROR_ID, SHOPWAVE_UPLOAD, type ShopwaveApiConfig, type ShopwaveApiHandlers, ShopwaveAuthError, type ShopwaveAuthErrorCode, type ShopwaveOAuthClient, type ShopwaveOAuthConfig, type ShopwaveToken, type ShopwaveTokenResponse, UPLOAD_KINDS, type UploadHandlers, type UploadKind, type UploadOptions, type WritableEntityKind, assertOAuthConfig, authorizationHeader, createShopwaveApiHandlers, createShopwaveOAuth, createState, isExpiredTokenResponse, isTokenExpired, normalizeStoredToken, normalizeWriteBody, parseExtras, readRequestToken, safeEqual, sanitizeReturnTo, shopwaveDateTime, tokenFromResponse };
507
+ export { BLOCKED_EXTRAS, type CollectionHandlers, type DeletableEntityKind, type EntityDefinition, type EntityKind, type ForwardInit, type ItemHandlers, type LookupDefinition, type LookupKind, RequestBodyError, type ResourceDefinition, type ResourceHandlers, type ResourceKind, type RouteContext, type RouteHandler, SHOPWAVE_ENTITIES, SHOPWAVE_LOOKUPS, SHOPWAVE_RESOURCES, SHOPWAVE_TOKEN_EXPIRED_ERROR_ID, SHOPWAVE_UPLOAD, type ShopwaveApiConfig, type ShopwaveApiHandlers, ShopwaveAuthError, type ShopwaveAuthErrorCode, type ShopwaveOAuthClient, type ShopwaveOAuthConfig, type ShopwaveToken, type ShopwaveTokenResponse, UPLOAD_KINDS, UPLOAD_PREFIXES, type UploadHandlers, type UploadKind, type UploadOptions, type UploadPrefix, type WritableEntityKind, assertOAuthConfig, authorizationHeader, createShopwaveApiHandlers, createShopwaveOAuth, createState, isExpiredTokenResponse, isTokenExpired, normalizeStoredToken, normalizeWriteBody, parseExtras, readRequestToken, safeEqual, sanitizeReturnTo, shopwaveDateTime, tokenFromResponse };
487
508
  //# sourceMappingURL=index.d.cts.map
@@ -275,18 +275,37 @@ declare const SHOPWAVE_RESOURCES: Readonly<Record<ResourceKind, ResourceDefiniti
275
275
  type UploadKind = "merchant" | "merchantFeature" | "product" | "user" | "applicationLogo" | "applicationImages";
276
276
  /** `UploadKind` → the API's `contentType` value. */
277
277
  declare const UPLOAD_KINDS: Readonly<Record<UploadKind, string>>;
278
+ /**
279
+ * The role an image plays, sent to Shopwave as the uploader's `prefix` header.
280
+ * The uploader names the file `<prefix>_<hash>.<ext>`, so the role travels with
281
+ * the file wherever a record stores it (a product's `images`). Live, merchant
282
+ * 5644, 4 Nov 2026: all four values answered 201.
283
+ * - `product`: a product gallery image;
284
+ * - `product_thumbnail`: the product's lead image, shown in lists;
285
+ * - `variant` / `variant_thumbnail`: a variant's own image and its lead image
286
+ * (used by the Connect integrations).
287
+ *
288
+ * Values are the ones Connect's `uploadFileToShopwave` sends.
289
+ */
290
+ type UploadPrefix = "product" | "product_thumbnail" | "variant" | "variant_thumbnail";
291
+ /** Every `UploadPrefix`, longest first so a name check never takes `product` for `product_thumbnail`. */
292
+ declare const UPLOAD_PREFIXES: ReadonlyArray<UploadPrefix>;
278
293
  /** How uploads are addressed (app route and Shopwave uploader). */
279
294
  declare const SHOPWAVE_UPLOAD: Readonly<{
280
- /** App route: `POST /api/<route>` (multipart `file` + `kind`). */
295
+ /** App route: `POST /api/<route>` (multipart `file` + `kind`, optional `prefix`). */
281
296
  route: "upload";
282
297
  /** Shopwave path: `PUT {apiUrl}/uploader` (multipart `file`). */
283
298
  upstream: "uploader";
284
299
  /** Header that carries the upload kind upstream. */
285
300
  kindHeader: "contentType";
301
+ /** Header that carries the image role upstream (see `UploadPrefix`). */
302
+ prefixHeader: "prefix";
286
303
  /** Multipart field name for the file, on both sides. */
287
304
  fileField: "file";
288
305
  /** Multipart field name for the kind in the app request. */
289
306
  kindField: "kind";
307
+ /** Multipart field name for the image role in the app request. */
308
+ prefixField: "prefix";
290
309
  }>;
291
310
  /**
292
311
  * Read-only lists that aren't records: the merchant's distinct tags.
@@ -445,9 +464,11 @@ interface UploadOptions {
445
464
  }
446
465
  interface UploadHandlers {
447
466
  /**
448
- * Multipart `file` + `kind` (see `UploadKind`) → `PUT {apiUrl}/uploader`.
449
- * Answers with Shopwave's reply (201 `{ fileName, path, api }`); 400 for a
450
- * missing file or unknown kind, 413 when too large, 415 for other types.
467
+ * Multipart `file` + `kind` (see `UploadKind`), and optionally `prefix`
468
+ * (see `UploadPrefix`) → `PUT {apiUrl}/uploader` with the `contentType` and
469
+ * `prefix` headers. Answers with Shopwave's reply (201 `{ fileName, path, api }`);
470
+ * 400 for a missing file or an unknown kind or prefix, 413 when too large,
471
+ * 415 for other types.
451
472
  */
452
473
  POST: RouteHandler;
453
474
  }
@@ -483,5 +504,5 @@ interface ShopwaveApiHandlers {
483
504
  declare function shopwaveDateTime(date?: Date): string;
484
505
  declare function createShopwaveApiHandlers(config: ShopwaveApiConfig): ShopwaveApiHandlers;
485
506
  //#endregion
486
- export { BLOCKED_EXTRAS, type CollectionHandlers, type DeletableEntityKind, type EntityDefinition, type EntityKind, type ForwardInit, type ItemHandlers, type LookupDefinition, type LookupKind, RequestBodyError, type ResourceDefinition, type ResourceHandlers, type ResourceKind, type RouteContext, type RouteHandler, SHOPWAVE_ENTITIES, SHOPWAVE_LOOKUPS, SHOPWAVE_RESOURCES, SHOPWAVE_TOKEN_EXPIRED_ERROR_ID, SHOPWAVE_UPLOAD, type ShopwaveApiConfig, type ShopwaveApiHandlers, ShopwaveAuthError, type ShopwaveAuthErrorCode, type ShopwaveOAuthClient, type ShopwaveOAuthConfig, type ShopwaveToken, type ShopwaveTokenResponse, UPLOAD_KINDS, type UploadHandlers, type UploadKind, type UploadOptions, type WritableEntityKind, assertOAuthConfig, authorizationHeader, createShopwaveApiHandlers, createShopwaveOAuth, createState, isExpiredTokenResponse, isTokenExpired, normalizeStoredToken, normalizeWriteBody, parseExtras, readRequestToken, safeEqual, sanitizeReturnTo, shopwaveDateTime, tokenFromResponse };
507
+ export { BLOCKED_EXTRAS, type CollectionHandlers, type DeletableEntityKind, type EntityDefinition, type EntityKind, type ForwardInit, type ItemHandlers, type LookupDefinition, type LookupKind, RequestBodyError, type ResourceDefinition, type ResourceHandlers, type ResourceKind, type RouteContext, type RouteHandler, SHOPWAVE_ENTITIES, SHOPWAVE_LOOKUPS, SHOPWAVE_RESOURCES, SHOPWAVE_TOKEN_EXPIRED_ERROR_ID, SHOPWAVE_UPLOAD, type ShopwaveApiConfig, type ShopwaveApiHandlers, ShopwaveAuthError, type ShopwaveAuthErrorCode, type ShopwaveOAuthClient, type ShopwaveOAuthConfig, type ShopwaveToken, type ShopwaveTokenResponse, UPLOAD_KINDS, UPLOAD_PREFIXES, type UploadHandlers, type UploadKind, type UploadOptions, type UploadPrefix, type WritableEntityKind, assertOAuthConfig, authorizationHeader, createShopwaveApiHandlers, createShopwaveOAuth, createState, isExpiredTokenResponse, isTokenExpired, normalizeStoredToken, normalizeWriteBody, parseExtras, readRequestToken, safeEqual, sanitizeReturnTo, shopwaveDateTime, tokenFromResponse };
487
508
  //# sourceMappingURL=index.d.ts.map
@@ -244,6 +244,74 @@ function safeEqual(a, b) {
244
244
  return diff === 0;
245
245
  }
246
246
 
247
+ //#endregion
248
+ //#region src/core/resources.ts
249
+ /**
250
+ * - merchant: `GET /merchant`; `POST /merchant` with `{ merchant: { id, … } }`
251
+ * updates it (without an `id` the API would create a second merchant, so the
252
+ * route requires one).
253
+ * - user: `GET /user` (read-only here; the API's `POST /user` invites users and
254
+ * needs the admin scope).
255
+ */
256
+ const SHOPWAVE_RESOURCES = Object.freeze({
257
+ merchant: {
258
+ route: "merchant",
259
+ key: "merchant",
260
+ upstream: "merchant",
261
+ writable: true
262
+ },
263
+ user: {
264
+ route: "user",
265
+ key: "user",
266
+ upstream: "user",
267
+ writable: false
268
+ }
269
+ });
270
+ /** `UploadKind` → the API's `contentType` value. */
271
+ const UPLOAD_KINDS = Object.freeze({
272
+ merchant: "merchant",
273
+ merchantFeature: "merchantFeature",
274
+ product: "product",
275
+ user: "user",
276
+ applicationLogo: "applicaionLogo",
277
+ applicationImages: "applicaionImages"
278
+ });
279
+ /** Every `UploadPrefix`, longest first so a name check never takes `product` for `product_thumbnail`. */
280
+ const UPLOAD_PREFIXES = Object.freeze([
281
+ "product_thumbnail",
282
+ "variant_thumbnail",
283
+ "product",
284
+ "variant"
285
+ ]);
286
+ /** How uploads are addressed (app route and Shopwave uploader). */
287
+ const SHOPWAVE_UPLOAD = Object.freeze({
288
+ route: "upload",
289
+ upstream: "uploader",
290
+ kindHeader: "contentType",
291
+ prefixHeader: "prefix",
292
+ fileField: "file",
293
+ kindField: "kind",
294
+ prefixField: "prefix"
295
+ });
296
+ function isUploadKind(value) {
297
+ return typeof value === "string" && Object.prototype.hasOwnProperty.call(UPLOAD_KINDS, value);
298
+ }
299
+ function isUploadPrefix(value) {
300
+ return typeof value === "string" && UPLOAD_PREFIXES.includes(value);
301
+ }
302
+ const SHOPWAVE_LOOKUPS = Object.freeze({
303
+ productTags: {
304
+ route: "products/tags",
305
+ key: "tags",
306
+ upstream: "product/tags"
307
+ },
308
+ productInstanceTags: {
309
+ route: "products/instance-tags",
310
+ key: "tags",
311
+ upstream: "product/instance/tags"
312
+ }
313
+ });
314
+
247
315
  //#endregion
248
316
  //#region src/core/entities.ts
249
317
  /**
@@ -320,62 +388,6 @@ const SHOPWAVE_ENTITIES = Object.freeze({
320
388
  }
321
389
  });
322
390
 
323
- //#endregion
324
- //#region src/core/resources.ts
325
- /**
326
- * - merchant: `GET /merchant`; `POST /merchant` with `{ merchant: { id, … } }`
327
- * updates it (without an `id` the API would create a second merchant, so the
328
- * route requires one).
329
- * - user: `GET /user` (read-only here; the API's `POST /user` invites users and
330
- * needs the admin scope).
331
- */
332
- const SHOPWAVE_RESOURCES = Object.freeze({
333
- merchant: {
334
- route: "merchant",
335
- key: "merchant",
336
- upstream: "merchant",
337
- writable: true
338
- },
339
- user: {
340
- route: "user",
341
- key: "user",
342
- upstream: "user",
343
- writable: false
344
- }
345
- });
346
- /** `UploadKind` → the API's `contentType` value. */
347
- const UPLOAD_KINDS = Object.freeze({
348
- merchant: "merchant",
349
- merchantFeature: "merchantFeature",
350
- product: "product",
351
- user: "user",
352
- applicationLogo: "applicaionLogo",
353
- applicationImages: "applicaionImages"
354
- });
355
- /** How uploads are addressed (app route and Shopwave uploader). */
356
- const SHOPWAVE_UPLOAD = Object.freeze({
357
- route: "upload",
358
- upstream: "uploader",
359
- kindHeader: "contentType",
360
- fileField: "file",
361
- kindField: "kind"
362
- });
363
- function isUploadKind(value) {
364
- return typeof value === "string" && Object.prototype.hasOwnProperty.call(UPLOAD_KINDS, value);
365
- }
366
- const SHOPWAVE_LOOKUPS = Object.freeze({
367
- productTags: {
368
- route: "products/tags",
369
- key: "tags",
370
- upstream: "product/tags"
371
- },
372
- productInstanceTags: {
373
- route: "products/instance-tags",
374
- key: "tags",
375
- upstream: "product/instance/tags"
376
- }
377
- });
378
-
379
391
  //#endregion
380
392
  //#region src/server/api.ts
381
393
  /**
@@ -704,6 +716,8 @@ function createShopwaveApiHandlers(config) {
704
716
  if (!file || typeof file === "string" || file.size === 0) return jsonError(400, "invalid_body", `Missing "${SHOPWAVE_UPLOAD.fileField}"`);
705
717
  const kind = form.get(SHOPWAVE_UPLOAD.kindField);
706
718
  if (!isUploadKind(kind)) return jsonError(400, "invalid_body", `"${SHOPWAVE_UPLOAD.kindField}" must be one of ${Object.keys(UPLOAD_KINDS).join(", ")}`);
719
+ const prefix = form.get(SHOPWAVE_UPLOAD.prefixField);
720
+ if (prefix !== null && !isUploadPrefix(prefix)) return jsonError(400, "invalid_body", `"${SHOPWAVE_UPLOAD.prefixField}" must be one of ${UPLOAD_PREFIXES.join(", ")}`);
707
721
  if (file.size > maxBytes) return jsonError(413, "too_large", `The file is larger than ${maxBytes} bytes`);
708
722
  if (!acceptsType(file.type || "", accept)) return jsonError(415, "unsupported_type", `Files of type "${file.type || "unknown"}" aren't accepted`);
709
723
  const upstreamForm = new FormData();
@@ -711,7 +725,10 @@ function createShopwaveApiHandlers(config) {
711
725
  return forward(request, {
712
726
  method: "PUT",
713
727
  path: SHOPWAVE_UPLOAD.upstream,
714
- headers: { [SHOPWAVE_UPLOAD.kindHeader]: UPLOAD_KINDS[kind] },
728
+ headers: {
729
+ [SHOPWAVE_UPLOAD.kindHeader]: UPLOAD_KINDS[kind],
730
+ ...prefix !== null ? { [SHOPWAVE_UPLOAD.prefixHeader]: prefix } : {}
731
+ },
715
732
  formData: upstreamForm,
716
733
  forwardExtras: false
717
734
  });
@@ -840,5 +857,5 @@ function createShopwaveApiHandlers(config) {
840
857
  }
841
858
 
842
859
  //#endregion
843
- export { BLOCKED_EXTRAS, RequestBodyError, SHOPWAVE_ENTITIES, SHOPWAVE_LOOKUPS, SHOPWAVE_RESOURCES, SHOPWAVE_TOKEN_EXPIRED_ERROR_ID, SHOPWAVE_UPLOAD, ShopwaveAuthError, UPLOAD_KINDS, assertOAuthConfig, authorizationHeader, createShopwaveApiHandlers, createShopwaveOAuth, createState, isExpiredTokenResponse, isTokenExpired, normalizeStoredToken, normalizeWriteBody, parseExtras, readRequestToken, safeEqual, sanitizeReturnTo, shopwaveDateTime, tokenFromResponse };
860
+ export { BLOCKED_EXTRAS, RequestBodyError, SHOPWAVE_ENTITIES, SHOPWAVE_LOOKUPS, SHOPWAVE_RESOURCES, SHOPWAVE_TOKEN_EXPIRED_ERROR_ID, SHOPWAVE_UPLOAD, ShopwaveAuthError, UPLOAD_KINDS, UPLOAD_PREFIXES, assertOAuthConfig, authorizationHeader, createShopwaveApiHandlers, createShopwaveOAuth, createState, isExpiredTokenResponse, isTokenExpired, normalizeStoredToken, normalizeWriteBody, parseExtras, readRequestToken, safeEqual, sanitizeReturnTo, shopwaveDateTime, tokenFromResponse };
844
861
  //# sourceMappingURL=index.js.map