@ecomweb/sdk 0.14.1 → 0.15.0

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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/core/client-info.ts
2
- var SDK_VERSION = true ? "0.14.1" : "dev";
2
+ var SDK_VERSION = true ? "0.15.0" : "dev";
3
3
  var CLIENT_HEADER = "X-Ecomweb-Client";
4
4
  var SDK_CLIENT_TOKEN = `@ecomweb/sdk/${SDK_VERSION}`;
5
5
  function clientHeaderValue(clientInfo) {
@@ -2967,7 +2967,7 @@ var ProductsApi = class {
2967
2967
  async getById(storeRef, productId, query) {
2968
2968
  const queryString = stringify(query ?? {});
2969
2969
  const res = await this.http.get(
2970
- `/public/stores/${storeRef}/products/${productId}${queryString ? "?" + queryString : ""}`
2970
+ `/storefront/stores/${storeRef}/products/${productId}${queryString ? "?" + queryString : ""}`
2971
2971
  );
2972
2972
  return unwrapOrNull(res);
2973
2973
  }
@@ -2984,7 +2984,7 @@ var ProductsApi = class {
2984
2984
  const encodedSlug = encodeURIComponent(normalizedSlug);
2985
2985
  const queryString = stringify(query ?? {});
2986
2986
  const res = await this.http.get(
2987
- `/public/stores/${storeRef}/products/slug/${encodedSlug}${queryString ? "?" + queryString : ""}`
2987
+ `/storefront/stores/${storeRef}/products/slug/${encodedSlug}${queryString ? "?" + queryString : ""}`
2988
2988
  );
2989
2989
  return unwrapOrNull(res);
2990
2990
  }
@@ -3005,7 +3005,7 @@ var CollectionsApi = class {
3005
3005
  async getAllPaginated(storeRef, params) {
3006
3006
  const queryString = stringify(params ?? {});
3007
3007
  const res = await this.http.get(
3008
- `/public/stores/${storeRef}/collections${queryString ? "?" + queryString : ""}`
3008
+ `/storefront/stores/${storeRef}/collections${queryString ? "?" + queryString : ""}`
3009
3009
  );
3010
3010
  return unwrap(res);
3011
3011
  }
@@ -3034,7 +3034,7 @@ var CollectionsApi = class {
3034
3034
  async getBySlug(storeRef, slug, query) {
3035
3035
  const queryString = query ? stringify(query) : "";
3036
3036
  const res = await this.http.get(
3037
- `/public/stores/${storeRef}/collections/slug/${slug}${queryString ? "?" + queryString : ""}`
3037
+ `/storefront/stores/${storeRef}/collections/slug/${slug}${queryString ? "?" + queryString : ""}`
3038
3038
  );
3039
3039
  return unwrapOrNull(res);
3040
3040
  }
@@ -3055,7 +3055,7 @@ var CategoriesApi = class {
3055
3055
  async getAllPaginated(storeRef, params) {
3056
3056
  const queryString = stringify(params ?? {});
3057
3057
  const res = await this.http.get(
3058
- `/public/stores/${storeRef}/categories${queryString ? "?" + queryString : ""}`
3058
+ `/storefront/stores/${storeRef}/categories${queryString ? "?" + queryString : ""}`
3059
3059
  );
3060
3060
  return unwrap(res);
3061
3061
  }
@@ -3082,7 +3082,7 @@ var CategoriesApi = class {
3082
3082
  */
3083
3083
  async getById(storeRef, categoryId) {
3084
3084
  const res = await this.http.get(
3085
- `/public/stores/${storeRef}/categories/${categoryId}`
3085
+ `/storefront/stores/${storeRef}/categories/${categoryId}`
3086
3086
  );
3087
3087
  return unwrapOrNull(res);
3088
3088
  }
@@ -3095,7 +3095,7 @@ var CategoriesApi = class {
3095
3095
  */
3096
3096
  async getBySlug(storeRef, slug) {
3097
3097
  const res = await this.http.get(
3098
- `/public/stores/${storeRef}/categories/${encodeURIComponent(slug)}`
3098
+ `/storefront/stores/${storeRef}/categories/${encodeURIComponent(slug)}`
3099
3099
  );
3100
3100
  return unwrapOrNull(res);
3101
3101
  }
@@ -3103,15 +3103,16 @@ var CategoriesApi = class {
3103
3103
 
3104
3104
  // src/modules/cart/api.ts
3105
3105
  var CartApi = class {
3106
- constructor(publicHttp, authHttp) {
3107
- this.publicHttp = publicHttp;
3108
- this.authHttp = authHttp;
3106
+ constructor(privateHttp, shopperHttp) {
3107
+ this.privateHttp = privateHttp;
3108
+ this.shopperHttp = shopperHttp;
3109
3109
  }
3110
3110
  client(isAuth) {
3111
- return isAuth ? this.authHttp : this.publicHttp;
3111
+ return isAuth ? this.shopperHttp : this.privateHttp;
3112
3112
  }
3113
- basePath(isAuth) {
3114
- return isAuth ? "stores" : "public/stores";
3113
+ /** Guest cart: `/storefront/stores/:ref/cart`; signed-in: `.../customers/cart`. */
3114
+ cartPath(isAuth, storeRef) {
3115
+ return isAuth ? `/storefront/stores/${storeRef}/customers/cart` : `/storefront/stores/${storeRef}/cart`;
3115
3116
  }
3116
3117
  /**
3117
3118
  * Gets the shopper's cart.
@@ -3123,7 +3124,7 @@ var CartApi = class {
3123
3124
  */
3124
3125
  async getCart(storeRef, sessionId, isAuth) {
3125
3126
  const res = await this.client(isAuth).get(
3126
- `/${this.basePath(isAuth)}/${storeRef}/cart`,
3127
+ this.cartPath(isAuth, storeRef),
3127
3128
  { headers: { "x-session-id": sessionId } }
3128
3129
  );
3129
3130
  return unwrapOrNull(res);
@@ -3138,7 +3139,7 @@ var CartApi = class {
3138
3139
  * @returns The cart id and the added item; throws {@link ApiClientError} when the API answers with an error
3139
3140
  */
3140
3141
  async addItem(storeRef, data, sessionId, isAuth) {
3141
- const res = await this.client(isAuth).post(`/${this.basePath(isAuth)}/${storeRef}/cart/items`, data, {
3142
+ const res = await this.client(isAuth).post(`${this.cartPath(isAuth, storeRef)}/items`, data, {
3142
3143
  headers: { "x-session-id": sessionId }
3143
3144
  });
3144
3145
  return unwrap(res);
@@ -3154,7 +3155,7 @@ var CartApi = class {
3154
3155
  * @returns The cart id and the updated item (`null` when the line was removed); throws {@link ApiClientError} when the API answers with an error
3155
3156
  */
3156
3157
  async updateItem(storeRef, itemId, data, sessionId, isAuth) {
3157
- const res = await this.client(isAuth).put(`/${this.basePath(isAuth)}/${storeRef}/cart/items/${itemId}`, data, {
3158
+ const res = await this.client(isAuth).put(`${this.cartPath(isAuth, storeRef)}/items/${itemId}`, data, {
3158
3159
  headers: { "x-session-id": sessionId }
3159
3160
  });
3160
3161
  return unwrap(res);
@@ -3169,7 +3170,7 @@ var CartApi = class {
3169
3170
  * @returns The cart id and the removed line's id; throws {@link ApiClientError} when the API answers with an error
3170
3171
  */
3171
3172
  async removeItem(storeRef, itemId, sessionId, isAuth) {
3172
- const res = await this.client(isAuth).delete(`/${this.basePath(isAuth)}/${storeRef}/cart/items/${itemId}`, {
3173
+ const res = await this.client(isAuth).delete(`${this.cartPath(isAuth, storeRef)}/items/${itemId}`, {
3173
3174
  headers: { "x-session-id": sessionId }
3174
3175
  });
3175
3176
  return unwrap(res);
@@ -3184,7 +3185,7 @@ var CartApi = class {
3184
3185
  */
3185
3186
  async clear(storeRef, sessionId, isAuth) {
3186
3187
  const res = await this.client(isAuth).delete(
3187
- `/${this.basePath(isAuth)}/${storeRef}/cart`,
3188
+ this.cartPath(isAuth, storeRef),
3188
3189
  { headers: { "x-session-id": sessionId } }
3189
3190
  );
3190
3191
  return unwrap(res);
@@ -3194,8 +3195,8 @@ var CartApi = class {
3194
3195
  * `{ merged: false }` when neither cart exists.
3195
3196
  */
3196
3197
  async merge(storeRef, sessionId) {
3197
- const res = await this.authHttp.post(
3198
- `/stores/${storeRef}/cart/merge`,
3198
+ const res = await this.shopperHttp.post(
3199
+ `/storefront/stores/${storeRef}/customers/cart/merge`,
3199
3200
  {},
3200
3201
  { headers: { "x-session-id": sessionId } }
3201
3202
  );
@@ -3205,9 +3206,9 @@ var CartApi = class {
3205
3206
 
3206
3207
  // src/modules/orders/api.ts
3207
3208
  var OrdersApi = class {
3208
- constructor(publicHttp, authHttp) {
3209
- this.publicHttp = publicHttp;
3210
- this.authHttp = authHttp;
3209
+ constructor(privateHttp, shopperHttp) {
3210
+ this.privateHttp = privateHttp;
3211
+ this.shopperHttp = shopperHttp;
3211
3212
  }
3212
3213
  /**
3213
3214
  * Look up a guest order. The API answers with the bare order when it
@@ -3221,8 +3222,8 @@ var OrdersApi = class {
3221
3222
  customer_email: params.customer_email,
3222
3223
  customer_phone: params.customer_phone
3223
3224
  });
3224
- const res = await this.publicHttp.get(
3225
- `/public/stores/${storeRef}/orders/lookup?${query}`
3225
+ const res = await this.privateHttp.get(
3226
+ `/storefront/stores/${storeRef}/orders/lookup?${query}`
3226
3227
  );
3227
3228
  const data = unwrapOrNull(res);
3228
3229
  if (!data || !("id" in data) || data.id == null) return null;
@@ -3238,14 +3239,14 @@ var OrdersApi = class {
3238
3239
  */
3239
3240
  async create(storeRef, data, isAuth) {
3240
3241
  if (isAuth) {
3241
- const res2 = await this.authHttp.post(
3242
- `/tenant/stores/${storeRef}/customers/orders`,
3242
+ const res2 = await this.shopperHttp.post(
3243
+ `/storefront/stores/${storeRef}/customers/orders`,
3243
3244
  data
3244
3245
  );
3245
3246
  return unwrap(res2);
3246
3247
  }
3247
- const res = await this.publicHttp.post(
3248
- `/public/stores/${storeRef}/orders`,
3248
+ const res = await this.privateHttp.post(
3249
+ `/storefront/stores/${storeRef}/orders`,
3249
3250
  data
3250
3251
  );
3251
3252
  return unwrap(res);
@@ -3270,8 +3271,8 @@ var OrdersApi = class {
3270
3271
  sort_by: params.sort_by ?? "created_at",
3271
3272
  sort_order: params.sort_order ?? "desc"
3272
3273
  });
3273
- const res = await this.authHttp.get(
3274
- `/tenant/stores/${storeRef}/customers/orders${query ? `?${query}` : ""}`
3274
+ const res = await this.shopperHttp.get(
3275
+ `/storefront/stores/${storeRef}/customers/orders${query ? `?${query}` : ""}`
3275
3276
  );
3276
3277
  return unwrap(res);
3277
3278
  }
@@ -3280,8 +3281,8 @@ var OrdersApi = class {
3280
3281
  * verifies ownership and returns 404 — not 403 — for someone else's order.
3281
3282
  */
3282
3283
  async getCustomerOrder(storeRef, orderId) {
3283
- const res = await this.authHttp.get(
3284
- `/tenant/stores/${storeRef}/customers/orders/${orderId}`
3284
+ const res = await this.shopperHttp.get(
3285
+ `/storefront/stores/${storeRef}/customers/orders/${orderId}`
3285
3286
  );
3286
3287
  return unwrap(res);
3287
3288
  }
@@ -3290,8 +3291,8 @@ var OrdersApi = class {
3290
3291
  * processing; the API rejects anything else with ORDER_NOT_CANCELLABLE.
3291
3292
  */
3292
3293
  async cancelCustomerOrder(storeRef, orderId) {
3293
- const res = await this.authHttp.delete(
3294
- `/tenant/stores/${storeRef}/customers/orders/${orderId}`
3294
+ const res = await this.shopperHttp.delete(
3295
+ `/storefront/stores/${storeRef}/customers/orders/${orderId}`
3295
3296
  );
3296
3297
  return unwrap(res);
3297
3298
  }
@@ -3313,7 +3314,7 @@ var BlogApi = class {
3313
3314
  async getPosts(storeRef, query = {}) {
3314
3315
  const qsStr = stringify(query);
3315
3316
  const res = await this.publicHttp.get(
3316
- `/public/stores/${storeRef}/blog/posts${qsStr ? "?" + qsStr : ""}`
3317
+ `/storefront/stores/${storeRef}/blog/posts${qsStr ? "?" + qsStr : ""}`
3317
3318
  );
3318
3319
  return unwrap(res);
3319
3320
  }
@@ -3332,7 +3333,7 @@ var BlogApi = class {
3332
3333
  include_products: options.include_products
3333
3334
  });
3334
3335
  const res = await this.publicHttp.get(
3335
- `/public/stores/${storeRef}/blog/posts/slug/${encodeURIComponent(slug)}${query ? `?${query}` : ""}`
3336
+ `/storefront/stores/${storeRef}/blog/posts/slug/${encodeURIComponent(slug)}${query ? `?${query}` : ""}`
3336
3337
  );
3337
3338
  return unwrapOrNull(res);
3338
3339
  }
@@ -3346,7 +3347,7 @@ var BlogApi = class {
3346
3347
  async getCategories(storeRef, query = {}) {
3347
3348
  const qsStr = stringify(query);
3348
3349
  const res = await this.publicHttp.get(
3349
- `/public/stores/${storeRef}/blog/categories${qsStr ? "?" + qsStr : ""}`
3350
+ `/storefront/stores/${storeRef}/blog/categories${qsStr ? "?" + qsStr : ""}`
3350
3351
  );
3351
3352
  return unwrap(res);
3352
3353
  }
@@ -3360,7 +3361,7 @@ var BlogApi = class {
3360
3361
  async getTags(storeRef, query = {}) {
3361
3362
  const qsStr = stringify(query);
3362
3363
  const res = await this.publicHttp.get(
3363
- `/public/stores/${storeRef}/blog/tags${qsStr ? "?" + qsStr : ""}`
3364
+ `/storefront/stores/${storeRef}/blog/tags${qsStr ? "?" + qsStr : ""}`
3364
3365
  );
3365
3366
  return unwrap(res);
3366
3367
  }
@@ -3373,7 +3374,7 @@ var BlogApi = class {
3373
3374
  */
3374
3375
  async getPostComments(storeRef, postId) {
3375
3376
  const res = await this.publicHttp.get(
3376
- `/public/stores/${storeRef}/blog/posts/${postId}/comments`
3377
+ `/storefront/stores/${storeRef}/blog/posts/${postId}/comments`
3377
3378
  );
3378
3379
  return unwrap(res);
3379
3380
  }
@@ -3386,10 +3387,12 @@ var BlogApi = class {
3386
3387
  */
3387
3388
  async getPostCommentsAuth(storeRef, postId) {
3388
3389
  const res = await this.authHttp.get(
3389
- `/public/stores/${storeRef}/blog/posts/${postId}/comments`
3390
+ `/storefront/stores/${storeRef}/blog/posts/${postId}/comments`
3390
3391
  );
3391
3392
  return unwrap(res);
3392
3393
  }
3394
+ };
3395
+ var BlogServerApi = class extends BlogApi {
3393
3396
  /**
3394
3397
  * Submits a comment on a post, as the signed-in customer. It may wait for moderation.
3395
3398
  *
@@ -3400,7 +3403,7 @@ var BlogApi = class {
3400
3403
  */
3401
3404
  async submitComment(storeRef, postId, data) {
3402
3405
  const res = await this.authHttp.post(
3403
- `/public/stores/${storeRef}/blog/posts/${postId}/comments`,
3406
+ `/storefront/stores/${storeRef}/blog/posts/${postId}/comments`,
3404
3407
  data
3405
3408
  );
3406
3409
  return unwrap(res);
@@ -3427,7 +3430,7 @@ var StoresApi = class {
3427
3430
  if (options?.includeEmbeddedScripts ?? true)
3428
3431
  params.set("include_embedded_scripts", "1");
3429
3432
  const qs = params.toString();
3430
- const url = `/public/stores/${storeRef}${qs ? `?${qs}` : ""}`;
3433
+ const url = `/storefront/stores/${storeRef}${qs ? `?${qs}` : ""}`;
3431
3434
  const res = requestOptions ? await this.http.get(url, requestOptions) : await this.http.get(url);
3432
3435
  return unwrapOrNull(res);
3433
3436
  }
@@ -3439,7 +3442,7 @@ var StoresApi = class {
3439
3442
  */
3440
3443
  async getBySubdomain(subdomain) {
3441
3444
  const res = await this.http.get(
3442
- `/public/stores/exists/subdomain/${subdomain}`
3445
+ `/storefront/stores/exists/subdomain/${subdomain}`
3443
3446
  );
3444
3447
  return unwrapOrNull(res);
3445
3448
  }
@@ -3448,7 +3451,7 @@ var StoresApi = class {
3448
3451
  * which opens a coming soon store) is passed to the client only when given.
3449
3452
  */
3450
3453
  async getByDomain(domain, options) {
3451
- const url = `/public/stores/domain/${domain}`;
3454
+ const url = `/storefront/stores/domain/${domain}`;
3452
3455
  const res = options ? await this.http.get(url, options) : await this.http.get(url);
3453
3456
  return unwrapOrNull(res);
3454
3457
  }
@@ -3463,14 +3466,14 @@ var ThemesApi = class {
3463
3466
  /** The store theme a dashboard preview link points to; null if refused. */
3464
3467
  async getPreview(storeRef, token) {
3465
3468
  const res = await this.http.get(
3466
- `/public/stores/${storeRef}/theme-preview?token=${encodeURIComponent(token)}`
3469
+ `/storefront/stores/${storeRef}/theme-preview?token=${encodeURIComponent(token)}`
3467
3470
  );
3468
3471
  return unwrapOrNull(res, NO_PREVIEW);
3469
3472
  }
3470
3473
  /** The theme on a preview host, p-<slug>, with its saved values. */
3471
3474
  async getPreviewBySlug(storeRef, slug) {
3472
3475
  const res = await this.http.get(
3473
- `/public/stores/${storeRef}/theme-preview?slug=${encodeURIComponent(slug)}`
3476
+ `/storefront/stores/${storeRef}/theme-preview?slug=${encodeURIComponent(slug)}`
3474
3477
  );
3475
3478
  return unwrapOrNull(res, NO_PREVIEW);
3476
3479
  }
@@ -3498,7 +3501,7 @@ var MetaobjectsApi = class {
3498
3501
  const search = query.toString();
3499
3502
  const http = params.as_customer ? this.authHttp : this.publicHttp;
3500
3503
  const res = await http.get(
3501
- `/public/stores/${storeRef}/metaobjects/${encodeURIComponent(type)}${search ? `?${search}` : ""}`
3504
+ `/storefront/stores/${storeRef}/metaobjects/${encodeURIComponent(type)}${search ? `?${search}` : ""}`
3502
3505
  );
3503
3506
  return unwrapOrNull(res, [404]) ?? EMPTY;
3504
3507
  }
@@ -3506,7 +3509,7 @@ var MetaobjectsApi = class {
3506
3509
  async get(storeRef, type, handle, options = {}) {
3507
3510
  const http = options.as_customer ? this.authHttp : this.publicHttp;
3508
3511
  const res = await http.get(
3509
- `/public/stores/${storeRef}/metaobjects/${encodeURIComponent(type)}/${encodeURIComponent(handle)}`
3512
+ `/storefront/stores/${storeRef}/metaobjects/${encodeURIComponent(type)}/${encodeURIComponent(handle)}`
3510
3513
  );
3511
3514
  return unwrapOrNull(res, [404]);
3512
3515
  }
@@ -3527,7 +3530,7 @@ var SearchApi = class {
3527
3530
  async searchCatalog(storeRef, params) {
3528
3531
  const queryString = stringify(params);
3529
3532
  const res = await this.http.get(
3530
- `/public/stores/${storeRef}/search/catalog${queryString ? "?" + queryString : ""}`
3533
+ `/storefront/stores/${storeRef}/search/catalog${queryString ? "?" + queryString : ""}`
3531
3534
  );
3532
3535
  return unwrap(res);
3533
3536
  }
@@ -3541,7 +3544,7 @@ var SearchApi = class {
3541
3544
  async autocompleteCatalog(storeRef, params) {
3542
3545
  const queryString = stringify(params);
3543
3546
  const res = await this.http.get(
3544
- `/public/stores/${storeRef}/search/catalog/autocomplete${queryString ? "?" + queryString : ""}`
3547
+ `/storefront/stores/${storeRef}/search/catalog/autocomplete${queryString ? "?" + queryString : ""}`
3545
3548
  );
3546
3549
  return unwrap(res);
3547
3550
  }
@@ -3555,7 +3558,7 @@ var SearchApi = class {
3555
3558
  async searchBlog(storeRef, params) {
3556
3559
  const queryString = stringify(params);
3557
3560
  const res = await this.http.get(
3558
- `/public/stores/${storeRef}/search/blog${queryString ? "?" + queryString : ""}`
3561
+ `/storefront/stores/${storeRef}/search/blog${queryString ? "?" + queryString : ""}`
3559
3562
  );
3560
3563
  return unwrap(res);
3561
3564
  }
@@ -3563,8 +3566,8 @@ var SearchApi = class {
3563
3566
 
3564
3567
  // src/modules/shipping/api.ts
3565
3568
  var ShippingApi = class {
3566
- constructor(http) {
3567
- this.http = http;
3569
+ constructor(publicHttp) {
3570
+ this.publicHttp = publicHttp;
3568
3571
  }
3569
3572
  /**
3570
3573
  * List administrative areas. Pass `level` for one tier or `parent_code`
@@ -3576,11 +3579,17 @@ var ShippingApi = class {
3576
3579
  if (query.level !== void 0) params.set("level", String(query.level));
3577
3580
  if (query.parent_code) params.set("parent_code", query.parent_code);
3578
3581
  const qs = params.toString();
3579
- const res = await this.http.get(
3580
- `/public/stores/${storeRef}/shipping/locations${qs ? `?${qs}` : ""}`
3582
+ const res = await this.publicHttp.get(
3583
+ `/storefront/stores/${storeRef}/shipping/locations${qs ? `?${qs}` : ""}`
3581
3584
  );
3582
3585
  return unwrap(res);
3583
3586
  }
3587
+ };
3588
+ var ShippingServerApi = class extends ShippingApi {
3589
+ constructor(publicHttp, privateHttp) {
3590
+ super(publicHttp);
3591
+ this.privateHttp = privateHttp;
3592
+ }
3584
3593
  /**
3585
3594
  * Works out the shipping options and prices for a cart and a destination.
3586
3595
  *
@@ -3589,8 +3598,8 @@ var ShippingApi = class {
3589
3598
  * @returns The available shipping options; throws {@link ApiClientError} when the API answers with an error
3590
3599
  */
3591
3600
  async calculate(storeRef, data) {
3592
- const res = await this.http.post(
3593
- `/public/stores/${storeRef}/shipping/calculate`,
3601
+ const res = await this.privateHttp.post(
3602
+ `/storefront/stores/${storeRef}/shipping/calculate`,
3594
3603
  data
3595
3604
  );
3596
3605
  return unwrap(res);
@@ -3599,35 +3608,41 @@ var ShippingApi = class {
3599
3608
 
3600
3609
  // src/modules/promotions/api.ts
3601
3610
  var PromotionsApi = class {
3602
- constructor(http) {
3603
- this.http = http;
3611
+ constructor(publicHttp) {
3612
+ this.publicHttp = publicHttp;
3604
3613
  }
3605
3614
  /**
3606
- * Checks a promotion code against a cart.
3615
+ * Lists promotions the shopper could use, optionally for a given cart subtotal.
3607
3616
  *
3608
3617
  * @param storeRef - the store's ref or handle
3609
- * @param data - the code and the cart details
3610
- * @returns The validation result; throws {@link ApiClientError} when the API answers with an error
3618
+ * @param subtotal - the cart subtotal in the store's currency
3619
+ * @returns The suggested promotions; throws {@link ApiClientError} when the API answers with an error
3611
3620
  */
3612
- async validate(storeRef, data) {
3613
- const res = await this.http.post(
3614
- `/public/stores/${storeRef}/promotions/validate`,
3615
- data
3621
+ async getSuggestions(storeRef, subtotal) {
3622
+ const params = new URLSearchParams();
3623
+ if (subtotal !== void 0) params.append("subtotal", subtotal.toString());
3624
+ const res = await this.publicHttp.get(
3625
+ `/storefront/stores/${storeRef}/promotions/suggestions?${params.toString()}`
3616
3626
  );
3617
3627
  return unwrap(res);
3618
3628
  }
3629
+ };
3630
+ var PromotionsServerApi = class extends PromotionsApi {
3631
+ constructor(publicHttp, privateHttp) {
3632
+ super(publicHttp);
3633
+ this.privateHttp = privateHttp;
3634
+ }
3619
3635
  /**
3620
- * Lists promotions the shopper could use, optionally for a given cart subtotal.
3636
+ * Checks a promotion code against a cart.
3621
3637
  *
3622
3638
  * @param storeRef - the store's ref or handle
3623
- * @param subtotal - the cart subtotal in the store's currency
3624
- * @returns The suggested promotions; throws {@link ApiClientError} when the API answers with an error
3639
+ * @param data - the code and the cart details
3640
+ * @returns The validation result; throws {@link ApiClientError} when the API answers with an error
3625
3641
  */
3626
- async getSuggestions(storeRef, subtotal) {
3627
- const params = new URLSearchParams();
3628
- if (subtotal !== void 0) params.append("subtotal", subtotal.toString());
3629
- const res = await this.http.get(
3630
- `/public/stores/${storeRef}/promotions/suggestions?${params.toString()}`
3642
+ async validate(storeRef, data) {
3643
+ const res = await this.privateHttp.post(
3644
+ `/storefront/stores/${storeRef}/promotions/validate`,
3645
+ data
3631
3646
  );
3632
3647
  return unwrap(res);
3633
3648
  }
@@ -3646,7 +3661,7 @@ var PaymentMethodsApi = class {
3646
3661
  */
3647
3662
  async getEnabled(storeRef) {
3648
3663
  const res = await this.http.get(
3649
- `/public/stores/${storeRef}/payment-methods`
3664
+ `/storefront/stores/${storeRef}/payment-methods`
3650
3665
  );
3651
3666
  return unwrap(res);
3652
3667
  }
@@ -3654,9 +3669,8 @@ var PaymentMethodsApi = class {
3654
3669
 
3655
3670
  // src/modules/payments/api.ts
3656
3671
  var PaymentsApi = class {
3657
- constructor(publicHttp, authHttp) {
3658
- this.publicHttp = publicHttp;
3659
- this.authHttp = authHttp;
3672
+ constructor(privateHttp) {
3673
+ this.privateHttp = privateHttp;
3660
3674
  }
3661
3675
  /**
3662
3676
  * Start a gateway charge attempt for an order. Keyed by `order_code`,
@@ -3666,8 +3680,8 @@ var PaymentsApi = class {
3666
3680
  * store's orders.
3667
3681
  */
3668
3682
  async initiate(storeRef, input) {
3669
- const res = await this.publicHttp.post(
3670
- `/public/stores/${encodeURIComponent(storeRef)}/payments/initiate`,
3683
+ const res = await this.privateHttp.post(
3684
+ `/storefront/stores/${encodeURIComponent(storeRef)}/payments/initiate`,
3671
3685
  { order_code: input.order_code, provider_code: input.provider_code }
3672
3686
  );
3673
3687
  return unwrap(res);
@@ -3678,8 +3692,8 @@ var PaymentsApi = class {
3678
3692
  * `#` by default in this system, and an unencoded `#` truncates the URL.
3679
3693
  */
3680
3694
  async getPaymentState(storeRef, order_code) {
3681
- const res = await this.publicHttp.get(
3682
- `/public/stores/${encodeURIComponent(storeRef)}/orders/${encodeURIComponent(order_code)}/payment-state`
3695
+ const res = await this.privateHttp.get(
3696
+ `/storefront/stores/${encodeURIComponent(storeRef)}/orders/${encodeURIComponent(order_code)}/payment-state`
3683
3697
  );
3684
3698
  return unwrap(res);
3685
3699
  }
@@ -3687,8 +3701,8 @@ var PaymentsApi = class {
3687
3701
 
3688
3702
  // src/modules/reviews/api.ts
3689
3703
  var ReviewsApi = class {
3690
- constructor(http) {
3691
- this.http = http;
3704
+ constructor(publicHttp) {
3705
+ this.publicHttp = publicHttp;
3692
3706
  }
3693
3707
  /**
3694
3708
  * Lists the published reviews of a product.
@@ -3700,11 +3714,17 @@ var ReviewsApi = class {
3700
3714
  */
3701
3715
  async getProductReviews(storeRef, productId, query) {
3702
3716
  const queryString = stringify(query ?? {});
3703
- const res = await this.http.get(
3704
- `public/stores/${storeRef}/products/${productId}/reviews${queryString ? `?${queryString}` : ""}`
3717
+ const res = await this.publicHttp.get(
3718
+ `/storefront/stores/${storeRef}/products/${productId}/reviews${queryString ? `?${queryString}` : ""}`
3705
3719
  );
3706
3720
  return unwrap(res);
3707
3721
  }
3722
+ };
3723
+ var ReviewsServerApi = class extends ReviewsApi {
3724
+ constructor(publicHttp, privateHttp) {
3725
+ super(publicHttp);
3726
+ this.privateHttp = privateHttp;
3727
+ }
3708
3728
  /**
3709
3729
  * Gets the public details behind a review invitation link.
3710
3730
  *
@@ -3713,8 +3733,8 @@ var ReviewsApi = class {
3713
3733
  * @returns The invitation details; throws {@link ApiClientError} when the API answers with an error
3714
3734
  */
3715
3735
  async getReviewInvitation(storeRef, token) {
3716
- const res = await this.http.get(
3717
- `public/stores/${storeRef}/review-invitations/${token}`
3736
+ const res = await this.privateHttp.get(
3737
+ `/storefront/stores/${storeRef}/review-invitations/${token}`
3718
3738
  );
3719
3739
  return unwrap(res);
3720
3740
  }
@@ -3728,8 +3748,8 @@ var ReviewsApi = class {
3728
3748
  */
3729
3749
  async getOrderReviewInvitations(storeRef, orderNumber, email) {
3730
3750
  const queryString = stringify({ order_number: orderNumber, email });
3731
- const res = await this.http.get(
3732
- `public/stores/${storeRef}/review-invitations/by-order?${queryString}`
3751
+ const res = await this.privateHttp.get(
3752
+ `/storefront/stores/${storeRef}/review-invitations/by-order?${queryString}`
3733
3753
  );
3734
3754
  return unwrap(res);
3735
3755
  }
@@ -3743,8 +3763,8 @@ var ReviewsApi = class {
3743
3763
  */
3744
3764
  async getBatchOrderReviewInvitations(storeRef, orderNumbers, email) {
3745
3765
  const queryString = stringify({ order_numbers: orderNumbers.join(","), email });
3746
- const res = await this.http.get(
3747
- `public/stores/${storeRef}/review-invitations/by-orders?${queryString}`
3766
+ const res = await this.privateHttp.get(
3767
+ `/storefront/stores/${storeRef}/review-invitations/by-orders?${queryString}`
3748
3768
  );
3749
3769
  return unwrap(res);
3750
3770
  }
@@ -3757,8 +3777,8 @@ var ReviewsApi = class {
3757
3777
  * @returns The API's answer; throws {@link ApiClientError} when the API answers with an error
3758
3778
  */
3759
3779
  async submitReviewInvitation(storeRef, token, payload) {
3760
- const res = await this.http.post(
3761
- `public/stores/${storeRef}/review-invitations/${token}/submit`,
3780
+ const res = await this.privateHttp.post(
3781
+ `/storefront/stores/${storeRef}/review-invitations/${token}/submit`,
3762
3782
  payload
3763
3783
  );
3764
3784
  return unwrap(res);
@@ -3779,14 +3799,14 @@ var CustomersApi = class {
3779
3799
  */
3780
3800
  async upsertForAuth(storeRef, payload) {
3781
3801
  return this.http.post(
3782
- `/stores/${storeRef}/customers/auth/upsert`,
3802
+ `/storefront/stores/${storeRef}/customers/auth/upsert`,
3783
3803
  payload
3784
3804
  );
3785
3805
  }
3786
3806
  /** The signed-in customer's metafields with customer access (spec §6.6). */
3787
3807
  async getMetafields(storeRef) {
3788
3808
  const res = await this.http.get(
3789
- `/tenant/stores/${storeRef}/customers/metafields`
3809
+ `/storefront/stores/${storeRef}/customers/metafields`
3790
3810
  );
3791
3811
  return unwrap(res);
3792
3812
  }
@@ -3796,7 +3816,7 @@ var CustomersApi = class {
3796
3816
  */
3797
3817
  async updateMetafields(storeRef, values) {
3798
3818
  const res = await this.http.put(
3799
- `/tenant/stores/${storeRef}/customers/metafields`,
3819
+ `/storefront/stores/${storeRef}/customers/metafields`,
3800
3820
  { values }
3801
3821
  );
3802
3822
  return unwrap(res);
@@ -3816,7 +3836,7 @@ var AddressesApi = class {
3816
3836
  */
3817
3837
  async list(storeRef) {
3818
3838
  const res = await this.http.get(
3819
- `/tenant/stores/${storeRef}/customers/address`
3839
+ `/storefront/stores/${storeRef}/customers/address`
3820
3840
  );
3821
3841
  return unwrapOrNull(res);
3822
3842
  }
@@ -3829,7 +3849,7 @@ var AddressesApi = class {
3829
3849
  */
3830
3850
  async getById(storeRef, addressId) {
3831
3851
  const res = await this.http.get(
3832
- `/tenant/stores/${storeRef}/customers/address/${addressId}`
3852
+ `/storefront/stores/${storeRef}/customers/address/${addressId}`
3833
3853
  );
3834
3854
  return unwrapOrNull(res);
3835
3855
  }
@@ -3842,7 +3862,7 @@ var AddressesApi = class {
3842
3862
  */
3843
3863
  async create(storeRef, data) {
3844
3864
  const res = await this.http.post(
3845
- `/tenant/stores/${storeRef}/customers/address`,
3865
+ `/storefront/stores/${storeRef}/customers/address`,
3846
3866
  data
3847
3867
  );
3848
3868
  return unwrapOrNull(res);
@@ -3857,7 +3877,7 @@ var AddressesApi = class {
3857
3877
  */
3858
3878
  async update(storeRef, addressId, data) {
3859
3879
  const res = await this.http.patch(
3860
- `/tenant/stores/${storeRef}/customers/address/${addressId}`,
3880
+ `/storefront/stores/${storeRef}/customers/address/${addressId}`,
3861
3881
  data
3862
3882
  );
3863
3883
  return unwrapOrNull(res);
@@ -3871,7 +3891,7 @@ var AddressesApi = class {
3871
3891
  */
3872
3892
  async delete(storeRef, addressId) {
3873
3893
  const res = await this.http.delete(
3874
- `/tenant/stores/${storeRef}/customers/address/${addressId}`
3894
+ `/storefront/stores/${storeRef}/customers/address/${addressId}`
3875
3895
  );
3876
3896
  return res.success;
3877
3897
  }
@@ -3884,7 +3904,7 @@ var AddressesApi = class {
3884
3904
  */
3885
3905
  async setDefault(storeRef, addressId) {
3886
3906
  const res = await this.http.patch(
3887
- `/tenant/stores/${storeRef}/customers/address/${addressId}/set-default`
3907
+ `/storefront/stores/${storeRef}/customers/address/${addressId}/set-default`
3888
3908
  );
3889
3909
  return unwrapOrNull(res);
3890
3910
  }
@@ -3903,7 +3923,7 @@ var ContentPagesApi = class {
3903
3923
  */
3904
3924
  async getPublished(storeRef) {
3905
3925
  const res = await this.http.get(
3906
- `/public/stores/${storeRef}/content-pages`
3926
+ `/storefront/stores/${storeRef}/content-pages`
3907
3927
  );
3908
3928
  return unwrap(res);
3909
3929
  }
@@ -3918,7 +3938,7 @@ var ContentPagesApi = class {
3918
3938
  async getBySlug(storeRef, slug, query) {
3919
3939
  const queryString = query ? stringify(query) : "";
3920
3940
  const res = await this.http.get(
3921
- `/public/stores/${storeRef}/content-pages/${encodeURIComponent(slug)}${queryString ? "?" + queryString : ""}`
3941
+ `/storefront/stores/${storeRef}/content-pages/${encodeURIComponent(slug)}${queryString ? "?" + queryString : ""}`
3922
3942
  );
3923
3943
  return unwrap(res);
3924
3944
  }
@@ -3940,7 +3960,7 @@ var MenusApi = class {
3940
3960
  async getByRef(storeRef, ref, includeItems = true) {
3941
3961
  const query = includeItems ? "?include_items=true" : "";
3942
3962
  const res = await this.http.get(
3943
- `/public/stores/${storeRef}/menus/ref/${encodeURIComponent(ref)}${query}`
3963
+ `/storefront/stores/${storeRef}/menus/ref/${encodeURIComponent(ref)}${query}`
3944
3964
  );
3945
3965
  return unwrapOrNull(res);
3946
3966
  }
@@ -3955,7 +3975,7 @@ var RedirectsApi = class {
3955
3975
  async lookup(storeRef, path, options) {
3956
3976
  const params = new URLSearchParams();
3957
3977
  params.set("path", path);
3958
- const url = `/public/stores/${storeRef}/url-redirects/lookup?${params.toString()}`;
3978
+ const url = `/storefront/stores/${storeRef}/url-redirects/lookup?${params.toString()}`;
3959
3979
  const res = options ? await this.http.get(url, options) : await this.http.get(url);
3960
3980
  const result = unwrapOrNull(res);
3961
3981
  return result?.data ?? null;
@@ -3969,10 +3989,10 @@ var AuthApi = class {
3969
3989
  this.storeRef = storeRef;
3970
3990
  }
3971
3991
  publicPath(suffix) {
3972
- return `/public/stores/${encodeURIComponent(this.storeRef)}/auth/${suffix}`;
3992
+ return `/storefront/stores/${encodeURIComponent(this.storeRef)}/auth/${suffix}`;
3973
3993
  }
3974
3994
  tenantPath(suffix) {
3975
- return `/tenant/stores/${encodeURIComponent(this.storeRef)}/auth/${suffix}`;
3995
+ return `/storefront/stores/${encodeURIComponent(this.storeRef)}/auth/${suffix}`;
3976
3996
  }
3977
3997
  auth(access_token) {
3978
3998
  return { headers: { Authorization: `Bearer ${access_token}` } };
@@ -4421,33 +4441,111 @@ var SHIPPING_ERROR_CODES = {
4421
4441
  RATE_UNAVAILABLE: "ORDER_SHIPPING_RATE_UNAVAILABLE"
4422
4442
  };
4423
4443
 
4424
- // src/index.ts
4425
- function createEcomwebSdk(options) {
4426
- const publicHttp = withClientHeader(options.publicHttp, options.clientInfo);
4427
- const authHttp = withClientHeader(options.authHttp, options.clientInfo);
4444
+ // src/core/storefront-key.ts
4445
+ var KEY_HEADER = "x-storefront-api-key";
4446
+ function withKey(options, key) {
4447
+ const headers = {};
4448
+ for (const [name, value] of Object.entries(options?.headers ?? {})) {
4449
+ if (name.toLowerCase() !== KEY_HEADER) headers[name] = value;
4450
+ }
4451
+ headers[KEY_HEADER] = key;
4452
+ return { ...options, headers };
4453
+ }
4454
+ function withStorefrontKey(http, key) {
4455
+ return {
4456
+ get: (url, options) => http.get(url, withKey(options, key)),
4457
+ post: (url, data, options) => http.post(url, data, withKey(options, key)),
4458
+ put: (url, data, options) => http.put(url, data, withKey(options, key)),
4459
+ patch: (url, data, options) => http.patch(url, data, withKey(options, key)),
4460
+ delete: (url, options) => http.delete(url, withKey(options, key))
4461
+ };
4462
+ }
4463
+
4464
+ // src/factory.ts
4465
+ function buildAllModules({
4466
+ publicHttp,
4467
+ privateHttp,
4468
+ shopperHttp
4469
+ }) {
4428
4470
  return {
4429
4471
  products: new ProductsApi(publicHttp),
4430
4472
  collections: new CollectionsApi(publicHttp),
4431
4473
  categories: new CategoriesApi(publicHttp),
4432
- cart: new CartApi(publicHttp, authHttp),
4433
- orders: new OrdersApi(publicHttp, authHttp),
4434
- blog: new BlogApi(publicHttp, authHttp),
4474
+ blog: new BlogServerApi(publicHttp, shopperHttp),
4435
4475
  stores: new StoresApi(publicHttp),
4436
4476
  themes: new ThemesApi(publicHttp),
4437
- metaobjects: new MetaobjectsApi(publicHttp, authHttp),
4477
+ metaobjects: new MetaobjectsApi(publicHttp, shopperHttp),
4438
4478
  search: new SearchApi(publicHttp),
4439
- shipping: new ShippingApi(publicHttp),
4440
- promotions: new PromotionsApi(publicHttp),
4479
+ shipping: new ShippingServerApi(publicHttp, privateHttp),
4480
+ promotions: new PromotionsServerApi(publicHttp, privateHttp),
4441
4481
  paymentMethods: new PaymentMethodsApi(publicHttp),
4442
- payments: new PaymentsApi(publicHttp, authHttp),
4443
- reviews: new ReviewsApi(publicHttp),
4444
- customers: new CustomersApi(authHttp),
4445
- addresses: new AddressesApi(authHttp),
4482
+ reviews: new ReviewsServerApi(publicHttp, privateHttp),
4446
4483
  contentPages: new ContentPagesApi(publicHttp),
4447
4484
  menus: new MenusApi(publicHttp),
4448
- redirects: new RedirectsApi(publicHttp)
4485
+ redirects: new RedirectsApi(publicHttp),
4486
+ cart: new CartApi(privateHttp, shopperHttp),
4487
+ orders: new OrdersApi(privateHttp, shopperHttp),
4488
+ payments: new PaymentsApi(privateHttp),
4489
+ customers: new CustomersApi(shopperHttp),
4490
+ addresses: new AddressesApi(shopperHttp)
4449
4491
  };
4450
4492
  }
4493
+ function createEcomwebSdk(options) {
4494
+ const publicHttp = withClientHeader(options.publicHttp, options.clientInfo);
4495
+ const shopperHttp = withClientHeader(options.authHttp, options.clientInfo);
4496
+ const all = buildAllModules({ publicHttp, privateHttp: publicHttp, shopperHttp });
4497
+ return {
4498
+ products: all.products,
4499
+ collections: all.collections,
4500
+ categories: all.categories,
4501
+ blog: new BlogApi(publicHttp, shopperHttp),
4502
+ stores: all.stores,
4503
+ themes: all.themes,
4504
+ metaobjects: all.metaobjects,
4505
+ search: all.search,
4506
+ shipping: new ShippingApi(publicHttp),
4507
+ promotions: new PromotionsApi(publicHttp),
4508
+ paymentMethods: all.paymentMethods,
4509
+ reviews: new ReviewsApi(publicHttp),
4510
+ contentPages: all.contentPages,
4511
+ menus: all.menus,
4512
+ redirects: all.redirects
4513
+ };
4514
+ }
4515
+ function createEcomwebServerSdk(options) {
4516
+ const secretKey = options.secretKey?.trim() ?? "";
4517
+ if (!secretKey) {
4518
+ throw new Error("createEcomwebServerSdk: secretKey is required");
4519
+ }
4520
+ if (secretKey.startsWith("pk_")) {
4521
+ throw new Error(
4522
+ "createEcomwebServerSdk: secretKey is a publishable key; pass the secret key (sk_...)"
4523
+ );
4524
+ }
4525
+ if (typeof window !== "undefined") {
4526
+ throw new Error(
4527
+ "createEcomwebServerSdk runs on a server only; in the browser use createEcomwebProxiedSdk"
4528
+ );
4529
+ }
4530
+ const publicHttp = withClientHeader(
4531
+ withStorefrontKey(options.publicHttp, secretKey),
4532
+ options.clientInfo
4533
+ );
4534
+ const shopperHttp = withClientHeader(
4535
+ withStorefrontKey(options.authHttp, secretKey),
4536
+ options.clientInfo
4537
+ );
4538
+ return buildAllModules({ publicHttp, privateHttp: publicHttp, shopperHttp });
4539
+ }
4540
+ function createEcomwebProxiedSdk(options) {
4541
+ const publicHttp = withClientHeader(options.publicHttp, options.clientInfo);
4542
+ const proxyHttp = withClientHeader(options.proxyHttp, options.clientInfo);
4543
+ return buildAllModules({
4544
+ publicHttp,
4545
+ privateHttp: proxyHttp,
4546
+ shopperHttp: proxyHttp
4547
+ });
4548
+ }
4451
4549
  export {
4452
4550
  ADJUSTABLE_STATES,
4453
4551
  ADMIN_ORDER_SOURCES,
@@ -4455,6 +4553,7 @@ export {
4455
4553
  ApiClientError,
4456
4554
  AuthApi,
4457
4555
  BlogApi,
4556
+ BlogServerApi,
4458
4557
  CLIENT_HEADER,
4459
4558
  COLLECTION_RULE_MATRIX,
4460
4559
  CONDITION_TYPE_LABELS,
@@ -4530,11 +4629,13 @@ export {
4530
4629
  PromotionTypeSchema,
4531
4630
  PromotionWithDiscountSchema,
4532
4631
  PromotionsApi,
4632
+ PromotionsServerApi,
4533
4633
  RENDER_PREFIX,
4534
4634
  RESOURCE_REFERENCE_TYPES,
4535
4635
  RULE_FIELDS,
4536
4636
  RedirectsApi,
4537
4637
  ReviewsApi,
4638
+ ReviewsServerApi,
4538
4639
  SDK_CLIENT_TOKEN,
4539
4640
  SDK_VERSION,
4540
4641
  SHIPMENT_STATUSES,
@@ -4544,6 +4645,7 @@ export {
4544
4645
  SHIPPING_RATE_TYPES,
4545
4646
  SearchApi,
4546
4647
  ShippingApi,
4648
+ ShippingServerApi,
4547
4649
  StoresApi,
4548
4650
  THEME_HEX_COLOR,
4549
4651
  ThemesApi,
@@ -4589,7 +4691,9 @@ export {
4589
4691
  createBlogTagSchema,
4590
4692
  createCategorySchema,
4591
4693
  createContentPageSchema,
4694
+ createEcomwebProxiedSdk,
4592
4695
  createEcomwebSdk,
4696
+ createEcomwebServerSdk,
4593
4697
  createEmbeddedScriptSchema,
4594
4698
  createOrderItemSchema,
4595
4699
  createOrderSchema,