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.
@@ -182,6 +182,21 @@ declare const SHOPWAVE_RESOURCES: Readonly<Record<ResourceKind, ResourceDefiniti
182
182
  type UploadKind = "merchant" | "merchantFeature" | "product" | "user" | "applicationLogo" | "applicationImages";
183
183
  /** `UploadKind` → the API's `contentType` value. */
184
184
  declare const UPLOAD_KINDS: Readonly<Record<UploadKind, string>>;
185
+ /**
186
+ * The role an image plays, sent to Shopwave as the uploader's `prefix` header.
187
+ * The uploader names the file `<prefix>_<hash>.<ext>`, so the role travels with
188
+ * the file wherever a record stores it (a product's `images`). Live, merchant
189
+ * 5644, 4 Nov 2026: all four values answered 201.
190
+ * - `product`: a product gallery image;
191
+ * - `product_thumbnail`: the product's lead image, shown in lists;
192
+ * - `variant` / `variant_thumbnail`: a variant's own image and its lead image
193
+ * (used by the Connect integrations).
194
+ *
195
+ * Values are the ones Connect's `uploadFileToShopwave` sends.
196
+ */
197
+ type UploadPrefix = "product" | "product_thumbnail" | "variant" | "variant_thumbnail";
198
+ /** Every `UploadPrefix`, longest first so a name check never takes `product` for `product_thumbnail`. */
199
+ declare const UPLOAD_PREFIXES: ReadonlyArray<UploadPrefix>;
185
200
  /**
186
201
  * Read-only lists that aren't records: the merchant's distinct tags.
187
202
  *
@@ -314,9 +329,11 @@ interface UploadOptions {
314
329
  }
315
330
  interface UploadHandlers {
316
331
  /**
317
- * Multipart `file` + `kind` (see `UploadKind`) → `PUT {apiUrl}/uploader`.
318
- * Answers with Shopwave's reply (201 `{ fileName, path, api }`); 400 for a
319
- * missing file or unknown kind, 413 when too large, 415 for other types.
332
+ * Multipart `file` + `kind` (see `UploadKind`), and optionally `prefix`
333
+ * (see `UploadPrefix`) → `PUT {apiUrl}/uploader` with the `contentType` and
334
+ * `prefix` headers. Answers with Shopwave's reply (201 `{ fileName, path, api }`);
335
+ * 400 for a missing file or an unknown kind or prefix, 413 when too large,
336
+ * 415 for other types.
320
337
  */
321
338
  POST: RouteHandler;
322
339
  }
@@ -555,5 +572,5 @@ interface ShopwaveNextApiConfig extends Omit<ShopwaveApiConfig, "getAuthorizatio
555
572
  */
556
573
  declare function createShopwaveApi(config: ShopwaveNextApiConfig): ShopwaveApiHandlers;
557
574
  //#endregion
558
- export { AuthContext, type CollectionHandlers, type EntityDefinition, type EntityKind, type ForwardInit, type ItemHandlers, type LookupKind, ProtectOptions, type ResourceHandlers, type ResourceKind, type RouteContext, type RouteHandler, SHOPWAVE_ENTITIES, SHOPWAVE_LOOKUPS, SHOPWAVE_RESOURCES, type SessionStatus, type ShopwaveApiHandlers, ShopwaveAuth, ShopwaveAuthConfig, ShopwaveAuthError, ShopwaveNextApiConfig, ShopwaveSessionConfig, ShopwaveSessionData, type ShopwaveToken, UPLOAD_KINDS, type UploadHandlers, type UploadKind, type UploadOptions, authorizationHeader, createShopwaveApi, createShopwaveAuth, isExpiredTokenResponse, readRequestToken };
575
+ export { AuthContext, type CollectionHandlers, type EntityDefinition, type EntityKind, type ForwardInit, type ItemHandlers, type LookupKind, ProtectOptions, type ResourceHandlers, type ResourceKind, type RouteContext, type RouteHandler, SHOPWAVE_ENTITIES, SHOPWAVE_LOOKUPS, SHOPWAVE_RESOURCES, type SessionStatus, type ShopwaveApiHandlers, ShopwaveAuth, ShopwaveAuthConfig, ShopwaveAuthError, ShopwaveNextApiConfig, ShopwaveSessionConfig, ShopwaveSessionData, type ShopwaveToken, UPLOAD_KINDS, UPLOAD_PREFIXES, type UploadHandlers, type UploadKind, type UploadOptions, type UploadPrefix, authorizationHeader, createShopwaveApi, createShopwaveAuth, isExpiredTokenResponse, readRequestToken };
559
576
  //# sourceMappingURL=index.d.cts.map
@@ -182,6 +182,21 @@ declare const SHOPWAVE_RESOURCES: Readonly<Record<ResourceKind, ResourceDefiniti
182
182
  type UploadKind = "merchant" | "merchantFeature" | "product" | "user" | "applicationLogo" | "applicationImages";
183
183
  /** `UploadKind` → the API's `contentType` value. */
184
184
  declare const UPLOAD_KINDS: Readonly<Record<UploadKind, string>>;
185
+ /**
186
+ * The role an image plays, sent to Shopwave as the uploader's `prefix` header.
187
+ * The uploader names the file `<prefix>_<hash>.<ext>`, so the role travels with
188
+ * the file wherever a record stores it (a product's `images`). Live, merchant
189
+ * 5644, 4 Nov 2026: all four values answered 201.
190
+ * - `product`: a product gallery image;
191
+ * - `product_thumbnail`: the product's lead image, shown in lists;
192
+ * - `variant` / `variant_thumbnail`: a variant's own image and its lead image
193
+ * (used by the Connect integrations).
194
+ *
195
+ * Values are the ones Connect's `uploadFileToShopwave` sends.
196
+ */
197
+ type UploadPrefix = "product" | "product_thumbnail" | "variant" | "variant_thumbnail";
198
+ /** Every `UploadPrefix`, longest first so a name check never takes `product` for `product_thumbnail`. */
199
+ declare const UPLOAD_PREFIXES: ReadonlyArray<UploadPrefix>;
185
200
  /**
186
201
  * Read-only lists that aren't records: the merchant's distinct tags.
187
202
  *
@@ -314,9 +329,11 @@ interface UploadOptions {
314
329
  }
315
330
  interface UploadHandlers {
316
331
  /**
317
- * Multipart `file` + `kind` (see `UploadKind`) → `PUT {apiUrl}/uploader`.
318
- * Answers with Shopwave's reply (201 `{ fileName, path, api }`); 400 for a
319
- * missing file or unknown kind, 413 when too large, 415 for other types.
332
+ * Multipart `file` + `kind` (see `UploadKind`), and optionally `prefix`
333
+ * (see `UploadPrefix`) → `PUT {apiUrl}/uploader` with the `contentType` and
334
+ * `prefix` headers. Answers with Shopwave's reply (201 `{ fileName, path, api }`);
335
+ * 400 for a missing file or an unknown kind or prefix, 413 when too large,
336
+ * 415 for other types.
320
337
  */
321
338
  POST: RouteHandler;
322
339
  }
@@ -555,5 +572,5 @@ interface ShopwaveNextApiConfig extends Omit<ShopwaveApiConfig, "getAuthorizatio
555
572
  */
556
573
  declare function createShopwaveApi(config: ShopwaveNextApiConfig): ShopwaveApiHandlers;
557
574
  //#endregion
558
- export { AuthContext, type CollectionHandlers, type EntityDefinition, type EntityKind, type ForwardInit, type ItemHandlers, type LookupKind, ProtectOptions, type ResourceHandlers, type ResourceKind, type RouteContext, type RouteHandler, SHOPWAVE_ENTITIES, SHOPWAVE_LOOKUPS, SHOPWAVE_RESOURCES, type SessionStatus, type ShopwaveApiHandlers, ShopwaveAuth, ShopwaveAuthConfig, ShopwaveAuthError, ShopwaveNextApiConfig, ShopwaveSessionConfig, ShopwaveSessionData, type ShopwaveToken, UPLOAD_KINDS, type UploadHandlers, type UploadKind, type UploadOptions, authorizationHeader, createShopwaveApi, createShopwaveAuth, isExpiredTokenResponse, readRequestToken };
575
+ export { AuthContext, type CollectionHandlers, type EntityDefinition, type EntityKind, type ForwardInit, type ItemHandlers, type LookupKind, ProtectOptions, type ResourceHandlers, type ResourceKind, type RouteContext, type RouteHandler, SHOPWAVE_ENTITIES, SHOPWAVE_LOOKUPS, SHOPWAVE_RESOURCES, type SessionStatus, type ShopwaveApiHandlers, ShopwaveAuth, ShopwaveAuthConfig, ShopwaveAuthError, ShopwaveNextApiConfig, ShopwaveSessionConfig, ShopwaveSessionData, type ShopwaveToken, UPLOAD_KINDS, UPLOAD_PREFIXES, type UploadHandlers, type UploadKind, type UploadOptions, type UploadPrefix, authorizationHeader, createShopwaveApi, createShopwaveAuth, isExpiredTokenResponse, readRequestToken };
559
576
  //# sourceMappingURL=index.d.ts.map
@@ -248,6 +248,74 @@ function safeEqual(a, b) {
248
248
  return diff === 0;
249
249
  }
250
250
 
251
+ //#endregion
252
+ //#region src/core/resources.ts
253
+ /**
254
+ * - merchant: `GET /merchant`; `POST /merchant` with `{ merchant: { id, … } }`
255
+ * updates it (without an `id` the API would create a second merchant, so the
256
+ * route requires one).
257
+ * - user: `GET /user` (read-only here; the API's `POST /user` invites users and
258
+ * needs the admin scope).
259
+ */
260
+ const SHOPWAVE_RESOURCES = Object.freeze({
261
+ merchant: {
262
+ route: "merchant",
263
+ key: "merchant",
264
+ upstream: "merchant",
265
+ writable: true
266
+ },
267
+ user: {
268
+ route: "user",
269
+ key: "user",
270
+ upstream: "user",
271
+ writable: false
272
+ }
273
+ });
274
+ /** `UploadKind` → the API's `contentType` value. */
275
+ const UPLOAD_KINDS = Object.freeze({
276
+ merchant: "merchant",
277
+ merchantFeature: "merchantFeature",
278
+ product: "product",
279
+ user: "user",
280
+ applicationLogo: "applicaionLogo",
281
+ applicationImages: "applicaionImages"
282
+ });
283
+ /** Every `UploadPrefix`, longest first so a name check never takes `product` for `product_thumbnail`. */
284
+ const UPLOAD_PREFIXES = Object.freeze([
285
+ "product_thumbnail",
286
+ "variant_thumbnail",
287
+ "product",
288
+ "variant"
289
+ ]);
290
+ /** How uploads are addressed (app route and Shopwave uploader). */
291
+ const SHOPWAVE_UPLOAD = Object.freeze({
292
+ route: "upload",
293
+ upstream: "uploader",
294
+ kindHeader: "contentType",
295
+ prefixHeader: "prefix",
296
+ fileField: "file",
297
+ kindField: "kind",
298
+ prefixField: "prefix"
299
+ });
300
+ function isUploadKind(value) {
301
+ return typeof value === "string" && Object.prototype.hasOwnProperty.call(UPLOAD_KINDS, value);
302
+ }
303
+ function isUploadPrefix(value) {
304
+ return typeof value === "string" && UPLOAD_PREFIXES.includes(value);
305
+ }
306
+ const SHOPWAVE_LOOKUPS = Object.freeze({
307
+ productTags: {
308
+ route: "products/tags",
309
+ key: "tags",
310
+ upstream: "product/tags"
311
+ },
312
+ productInstanceTags: {
313
+ route: "products/instance-tags",
314
+ key: "tags",
315
+ upstream: "product/instance/tags"
316
+ }
317
+ });
318
+
251
319
  //#endregion
252
320
  //#region src/core/entities.ts
253
321
  /**
@@ -324,62 +392,6 @@ const SHOPWAVE_ENTITIES = Object.freeze({
324
392
  }
325
393
  });
326
394
 
327
- //#endregion
328
- //#region src/core/resources.ts
329
- /**
330
- * - merchant: `GET /merchant`; `POST /merchant` with `{ merchant: { id, … } }`
331
- * updates it (without an `id` the API would create a second merchant, so the
332
- * route requires one).
333
- * - user: `GET /user` (read-only here; the API's `POST /user` invites users and
334
- * needs the admin scope).
335
- */
336
- const SHOPWAVE_RESOURCES = Object.freeze({
337
- merchant: {
338
- route: "merchant",
339
- key: "merchant",
340
- upstream: "merchant",
341
- writable: true
342
- },
343
- user: {
344
- route: "user",
345
- key: "user",
346
- upstream: "user",
347
- writable: false
348
- }
349
- });
350
- /** `UploadKind` → the API's `contentType` value. */
351
- const UPLOAD_KINDS = Object.freeze({
352
- merchant: "merchant",
353
- merchantFeature: "merchantFeature",
354
- product: "product",
355
- user: "user",
356
- applicationLogo: "applicaionLogo",
357
- applicationImages: "applicaionImages"
358
- });
359
- /** How uploads are addressed (app route and Shopwave uploader). */
360
- const SHOPWAVE_UPLOAD = Object.freeze({
361
- route: "upload",
362
- upstream: "uploader",
363
- kindHeader: "contentType",
364
- fileField: "file",
365
- kindField: "kind"
366
- });
367
- function isUploadKind(value) {
368
- return typeof value === "string" && Object.prototype.hasOwnProperty.call(UPLOAD_KINDS, value);
369
- }
370
- const SHOPWAVE_LOOKUPS = Object.freeze({
371
- productTags: {
372
- route: "products/tags",
373
- key: "tags",
374
- upstream: "product/tags"
375
- },
376
- productInstanceTags: {
377
- route: "products/instance-tags",
378
- key: "tags",
379
- upstream: "product/instance/tags"
380
- }
381
- });
382
-
383
395
  //#endregion
384
396
  //#region src/server/api.ts
385
397
  /**
@@ -708,6 +720,8 @@ function createShopwaveApiHandlers(config) {
708
720
  if (!file || typeof file === "string" || file.size === 0) return jsonError(400, "invalid_body", `Missing "${SHOPWAVE_UPLOAD.fileField}"`);
709
721
  const kind = form.get(SHOPWAVE_UPLOAD.kindField);
710
722
  if (!isUploadKind(kind)) return jsonError(400, "invalid_body", `"${SHOPWAVE_UPLOAD.kindField}" must be one of ${Object.keys(UPLOAD_KINDS).join(", ")}`);
723
+ const prefix = form.get(SHOPWAVE_UPLOAD.prefixField);
724
+ if (prefix !== null && !isUploadPrefix(prefix)) return jsonError(400, "invalid_body", `"${SHOPWAVE_UPLOAD.prefixField}" must be one of ${UPLOAD_PREFIXES.join(", ")}`);
711
725
  if (file.size > maxBytes) return jsonError(413, "too_large", `The file is larger than ${maxBytes} bytes`);
712
726
  if (!acceptsType(file.type || "", accept)) return jsonError(415, "unsupported_type", `Files of type "${file.type || "unknown"}" aren't accepted`);
713
727
  const upstreamForm = new FormData();
@@ -715,7 +729,10 @@ function createShopwaveApiHandlers(config) {
715
729
  return forward(request, {
716
730
  method: "PUT",
717
731
  path: SHOPWAVE_UPLOAD.upstream,
718
- headers: { [SHOPWAVE_UPLOAD.kindHeader]: UPLOAD_KINDS[kind] },
732
+ headers: {
733
+ [SHOPWAVE_UPLOAD.kindHeader]: UPLOAD_KINDS[kind],
734
+ ...prefix !== null ? { [SHOPWAVE_UPLOAD.prefixHeader]: prefix } : {}
735
+ },
719
736
  formData: upstreamForm,
720
737
  forwardExtras: false
721
738
  });
@@ -1185,5 +1202,5 @@ function createShopwaveApi(config) {
1185
1202
  }
1186
1203
 
1187
1204
  //#endregion
1188
- export { SHOPWAVE_ENTITIES, SHOPWAVE_LOOKUPS, SHOPWAVE_RESOURCES, ShopwaveAuthError, UPLOAD_KINDS, authorizationHeader, createShopwaveApi, createShopwaveAuth, isExpiredTokenResponse, readRequestToken };
1205
+ export { SHOPWAVE_ENTITIES, SHOPWAVE_LOOKUPS, SHOPWAVE_RESOURCES, ShopwaveAuthError, UPLOAD_KINDS, UPLOAD_PREFIXES, authorizationHeader, createShopwaveApi, createShopwaveAuth, isExpiredTokenResponse, readRequestToken };
1189
1206
  //# sourceMappingURL=index.js.map