@ecomweb/sdk 0.14.1 → 0.16.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/README.md +18 -2
- package/dist/index.d.ts +235 -73
- package/dist/index.js +272 -135
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/core/client-info.ts
|
|
2
|
-
var SDK_VERSION = true ? "0.
|
|
2
|
+
var SDK_VERSION = true ? "0.16.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
|
-
`/
|
|
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
|
-
`/
|
|
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
|
-
`/
|
|
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
|
-
`/
|
|
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
|
-
`/
|
|
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
|
-
`/
|
|
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
|
-
`/
|
|
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(
|
|
3107
|
-
this.
|
|
3108
|
-
this.
|
|
3106
|
+
constructor(privateHttp, shopperHttp) {
|
|
3107
|
+
this.privateHttp = privateHttp;
|
|
3108
|
+
this.shopperHttp = shopperHttp;
|
|
3109
3109
|
}
|
|
3110
3110
|
client(isAuth) {
|
|
3111
|
-
return isAuth ? this.
|
|
3111
|
+
return isAuth ? this.shopperHttp : this.privateHttp;
|
|
3112
3112
|
}
|
|
3113
|
-
|
|
3114
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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.
|
|
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(
|
|
3209
|
-
this.
|
|
3210
|
-
this.
|
|
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.
|
|
3225
|
-
`/
|
|
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.
|
|
3242
|
-
`/
|
|
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.
|
|
3248
|
-
`/
|
|
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.
|
|
3274
|
-
`/
|
|
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.
|
|
3284
|
-
`/
|
|
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.
|
|
3294
|
-
`/
|
|
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
|
-
`/
|
|
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
|
-
`/
|
|
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
|
-
`/
|
|
3350
|
+
`/storefront/stores/${storeRef}/blog/categories${qsStr ? "?" + qsStr : ""}`
|
|
3350
3351
|
);
|
|
3351
3352
|
return unwrap(res);
|
|
3352
3353
|
}
|
|
@@ -3360,36 +3361,71 @@ var BlogApi = class {
|
|
|
3360
3361
|
async getTags(storeRef, query = {}) {
|
|
3361
3362
|
const qsStr = stringify(query);
|
|
3362
3363
|
const res = await this.publicHttp.get(
|
|
3363
|
-
`/
|
|
3364
|
+
`/storefront/stores/${storeRef}/blog/tags${qsStr ? "?" + qsStr : ""}`
|
|
3364
3365
|
);
|
|
3365
3366
|
return unwrap(res);
|
|
3366
3367
|
}
|
|
3367
3368
|
/**
|
|
3368
|
-
* Lists the approved comments of a post, as an anonymous visitor.
|
|
3369
|
+
* Lists the approved comments of a post, as an anonymous visitor. Returns at
|
|
3370
|
+
* most 100 per call, oldest first unless `sort_order` is `desc`; use
|
|
3371
|
+
* {@link BlogApi.getPostCommentsPage} for the total.
|
|
3369
3372
|
*
|
|
3370
3373
|
* @param storeRef - the store's ref or handle
|
|
3371
3374
|
* @param postId - the post id
|
|
3375
|
+
* @param query - `limit` (at most 100), `offset` and `sort_order`
|
|
3372
3376
|
* @returns The comments; throws {@link ApiClientError} when the API answers with an error
|
|
3373
3377
|
*/
|
|
3374
|
-
async getPostComments(storeRef, postId) {
|
|
3375
|
-
|
|
3376
|
-
`/public/stores/${storeRef}/blog/posts/${postId}/comments`
|
|
3377
|
-
);
|
|
3378
|
-
return unwrap(res);
|
|
3378
|
+
async getPostComments(storeRef, postId, query = {}) {
|
|
3379
|
+
return unwrap(await this.fetchComments(this.publicHttp, storeRef, postId, query));
|
|
3379
3380
|
}
|
|
3380
3381
|
/**
|
|
3381
|
-
* Lists the approved comments of a post, sending the signed-in customer's
|
|
3382
|
+
* Lists the approved comments of a post, sending the signed-in customer's
|
|
3383
|
+
* credentials, so that customer's own comments still waiting for approval
|
|
3384
|
+
* are included. Paging as in {@link BlogApi.getPostComments}.
|
|
3382
3385
|
*
|
|
3383
3386
|
* @param storeRef - the store's ref or handle
|
|
3384
3387
|
* @param postId - the post id
|
|
3388
|
+
* @param query - `limit` (at most 100), `offset` and `sort_order`
|
|
3385
3389
|
* @returns The comments; throws {@link ApiClientError} when the API answers with an error
|
|
3386
3390
|
*/
|
|
3387
|
-
async getPostCommentsAuth(storeRef, postId) {
|
|
3388
|
-
|
|
3389
|
-
|
|
3391
|
+
async getPostCommentsAuth(storeRef, postId, query = {}) {
|
|
3392
|
+
return unwrap(await this.fetchComments(this.authHttp, storeRef, postId, query));
|
|
3393
|
+
}
|
|
3394
|
+
/**
|
|
3395
|
+
* One page of a post's comments with the total across all pages, for
|
|
3396
|
+
* "load more" or a comment count. Set `asCustomer` to include the signed-in
|
|
3397
|
+
* customer's own pending comments, as {@link BlogApi.getPostCommentsAuth} does.
|
|
3398
|
+
*
|
|
3399
|
+
* @param storeRef - the store's ref or handle
|
|
3400
|
+
* @param postId - the post id
|
|
3401
|
+
* @param query - `limit` (at most 100), `offset` and `sort_order`
|
|
3402
|
+
* @param options - `asCustomer` sends the signed-in customer's credentials
|
|
3403
|
+
* @returns The page and the total (`null` when the HTTP client does not pass response headers on); throws {@link ApiClientError} when the API answers with an error
|
|
3404
|
+
*/
|
|
3405
|
+
async getPostCommentsPage(storeRef, postId, query = {}, options = {}) {
|
|
3406
|
+
const res = await this.fetchComments(
|
|
3407
|
+
options.asCustomer ? this.authHttp : this.publicHttp,
|
|
3408
|
+
storeRef,
|
|
3409
|
+
postId,
|
|
3410
|
+
query
|
|
3411
|
+
);
|
|
3412
|
+
const items = unwrap(res);
|
|
3413
|
+
const header = res.headers?.["x-total-count"];
|
|
3414
|
+
const total = header != null && header !== "" ? Number(header) : NaN;
|
|
3415
|
+
return { items, total: Number.isFinite(total) ? total : null };
|
|
3416
|
+
}
|
|
3417
|
+
fetchComments(http, storeRef, postId, query) {
|
|
3418
|
+
const qsStr = stringify({
|
|
3419
|
+
limit: query.limit,
|
|
3420
|
+
offset: query.offset,
|
|
3421
|
+
sort_order: query.sort_order
|
|
3422
|
+
});
|
|
3423
|
+
return http.get(
|
|
3424
|
+
`/storefront/stores/${storeRef}/blog/posts/${postId}/comments${qsStr ? "?" + qsStr : ""}`
|
|
3390
3425
|
);
|
|
3391
|
-
return unwrap(res);
|
|
3392
3426
|
}
|
|
3427
|
+
};
|
|
3428
|
+
var BlogServerApi = class extends BlogApi {
|
|
3393
3429
|
/**
|
|
3394
3430
|
* Submits a comment on a post, as the signed-in customer. It may wait for moderation.
|
|
3395
3431
|
*
|
|
@@ -3400,7 +3436,7 @@ var BlogApi = class {
|
|
|
3400
3436
|
*/
|
|
3401
3437
|
async submitComment(storeRef, postId, data) {
|
|
3402
3438
|
const res = await this.authHttp.post(
|
|
3403
|
-
`/
|
|
3439
|
+
`/storefront/stores/${storeRef}/blog/posts/${postId}/comments`,
|
|
3404
3440
|
data
|
|
3405
3441
|
);
|
|
3406
3442
|
return unwrap(res);
|
|
@@ -3427,7 +3463,7 @@ var StoresApi = class {
|
|
|
3427
3463
|
if (options?.includeEmbeddedScripts ?? true)
|
|
3428
3464
|
params.set("include_embedded_scripts", "1");
|
|
3429
3465
|
const qs = params.toString();
|
|
3430
|
-
const url = `/
|
|
3466
|
+
const url = `/storefront/stores/${storeRef}${qs ? `?${qs}` : ""}`;
|
|
3431
3467
|
const res = requestOptions ? await this.http.get(url, requestOptions) : await this.http.get(url);
|
|
3432
3468
|
return unwrapOrNull(res);
|
|
3433
3469
|
}
|
|
@@ -3439,7 +3475,7 @@ var StoresApi = class {
|
|
|
3439
3475
|
*/
|
|
3440
3476
|
async getBySubdomain(subdomain) {
|
|
3441
3477
|
const res = await this.http.get(
|
|
3442
|
-
`/
|
|
3478
|
+
`/storefront/stores/exists/subdomain/${subdomain}`
|
|
3443
3479
|
);
|
|
3444
3480
|
return unwrapOrNull(res);
|
|
3445
3481
|
}
|
|
@@ -3448,7 +3484,7 @@ var StoresApi = class {
|
|
|
3448
3484
|
* which opens a coming soon store) is passed to the client only when given.
|
|
3449
3485
|
*/
|
|
3450
3486
|
async getByDomain(domain, options) {
|
|
3451
|
-
const url = `/
|
|
3487
|
+
const url = `/storefront/stores/domain/${domain}`;
|
|
3452
3488
|
const res = options ? await this.http.get(url, options) : await this.http.get(url);
|
|
3453
3489
|
return unwrapOrNull(res);
|
|
3454
3490
|
}
|
|
@@ -3463,14 +3499,14 @@ var ThemesApi = class {
|
|
|
3463
3499
|
/** The store theme a dashboard preview link points to; null if refused. */
|
|
3464
3500
|
async getPreview(storeRef, token) {
|
|
3465
3501
|
const res = await this.http.get(
|
|
3466
|
-
`/
|
|
3502
|
+
`/storefront/stores/${storeRef}/theme-preview?token=${encodeURIComponent(token)}`
|
|
3467
3503
|
);
|
|
3468
3504
|
return unwrapOrNull(res, NO_PREVIEW);
|
|
3469
3505
|
}
|
|
3470
3506
|
/** The theme on a preview host, p-<slug>, with its saved values. */
|
|
3471
3507
|
async getPreviewBySlug(storeRef, slug) {
|
|
3472
3508
|
const res = await this.http.get(
|
|
3473
|
-
`/
|
|
3509
|
+
`/storefront/stores/${storeRef}/theme-preview?slug=${encodeURIComponent(slug)}`
|
|
3474
3510
|
);
|
|
3475
3511
|
return unwrapOrNull(res, NO_PREVIEW);
|
|
3476
3512
|
}
|
|
@@ -3498,7 +3534,7 @@ var MetaobjectsApi = class {
|
|
|
3498
3534
|
const search = query.toString();
|
|
3499
3535
|
const http = params.as_customer ? this.authHttp : this.publicHttp;
|
|
3500
3536
|
const res = await http.get(
|
|
3501
|
-
`/
|
|
3537
|
+
`/storefront/stores/${storeRef}/metaobjects/${encodeURIComponent(type)}${search ? `?${search}` : ""}`
|
|
3502
3538
|
);
|
|
3503
3539
|
return unwrapOrNull(res, [404]) ?? EMPTY;
|
|
3504
3540
|
}
|
|
@@ -3506,7 +3542,7 @@ var MetaobjectsApi = class {
|
|
|
3506
3542
|
async get(storeRef, type, handle, options = {}) {
|
|
3507
3543
|
const http = options.as_customer ? this.authHttp : this.publicHttp;
|
|
3508
3544
|
const res = await http.get(
|
|
3509
|
-
`/
|
|
3545
|
+
`/storefront/stores/${storeRef}/metaobjects/${encodeURIComponent(type)}/${encodeURIComponent(handle)}`
|
|
3510
3546
|
);
|
|
3511
3547
|
return unwrapOrNull(res, [404]);
|
|
3512
3548
|
}
|
|
@@ -3527,7 +3563,7 @@ var SearchApi = class {
|
|
|
3527
3563
|
async searchCatalog(storeRef, params) {
|
|
3528
3564
|
const queryString = stringify(params);
|
|
3529
3565
|
const res = await this.http.get(
|
|
3530
|
-
`/
|
|
3566
|
+
`/storefront/stores/${storeRef}/search/catalog${queryString ? "?" + queryString : ""}`
|
|
3531
3567
|
);
|
|
3532
3568
|
return unwrap(res);
|
|
3533
3569
|
}
|
|
@@ -3541,7 +3577,7 @@ var SearchApi = class {
|
|
|
3541
3577
|
async autocompleteCatalog(storeRef, params) {
|
|
3542
3578
|
const queryString = stringify(params);
|
|
3543
3579
|
const res = await this.http.get(
|
|
3544
|
-
`/
|
|
3580
|
+
`/storefront/stores/${storeRef}/search/catalog/autocomplete${queryString ? "?" + queryString : ""}`
|
|
3545
3581
|
);
|
|
3546
3582
|
return unwrap(res);
|
|
3547
3583
|
}
|
|
@@ -3555,7 +3591,7 @@ var SearchApi = class {
|
|
|
3555
3591
|
async searchBlog(storeRef, params) {
|
|
3556
3592
|
const queryString = stringify(params);
|
|
3557
3593
|
const res = await this.http.get(
|
|
3558
|
-
`/
|
|
3594
|
+
`/storefront/stores/${storeRef}/search/blog${queryString ? "?" + queryString : ""}`
|
|
3559
3595
|
);
|
|
3560
3596
|
return unwrap(res);
|
|
3561
3597
|
}
|
|
@@ -3563,8 +3599,8 @@ var SearchApi = class {
|
|
|
3563
3599
|
|
|
3564
3600
|
// src/modules/shipping/api.ts
|
|
3565
3601
|
var ShippingApi = class {
|
|
3566
|
-
constructor(
|
|
3567
|
-
this.
|
|
3602
|
+
constructor(publicHttp) {
|
|
3603
|
+
this.publicHttp = publicHttp;
|
|
3568
3604
|
}
|
|
3569
3605
|
/**
|
|
3570
3606
|
* List administrative areas. Pass `level` for one tier or `parent_code`
|
|
@@ -3576,11 +3612,17 @@ var ShippingApi = class {
|
|
|
3576
3612
|
if (query.level !== void 0) params.set("level", String(query.level));
|
|
3577
3613
|
if (query.parent_code) params.set("parent_code", query.parent_code);
|
|
3578
3614
|
const qs = params.toString();
|
|
3579
|
-
const res = await this.
|
|
3580
|
-
`/
|
|
3615
|
+
const res = await this.publicHttp.get(
|
|
3616
|
+
`/storefront/stores/${storeRef}/shipping/locations${qs ? `?${qs}` : ""}`
|
|
3581
3617
|
);
|
|
3582
3618
|
return unwrap(res);
|
|
3583
3619
|
}
|
|
3620
|
+
};
|
|
3621
|
+
var ShippingServerApi = class extends ShippingApi {
|
|
3622
|
+
constructor(publicHttp, privateHttp) {
|
|
3623
|
+
super(publicHttp);
|
|
3624
|
+
this.privateHttp = privateHttp;
|
|
3625
|
+
}
|
|
3584
3626
|
/**
|
|
3585
3627
|
* Works out the shipping options and prices for a cart and a destination.
|
|
3586
3628
|
*
|
|
@@ -3589,8 +3631,8 @@ var ShippingApi = class {
|
|
|
3589
3631
|
* @returns The available shipping options; throws {@link ApiClientError} when the API answers with an error
|
|
3590
3632
|
*/
|
|
3591
3633
|
async calculate(storeRef, data) {
|
|
3592
|
-
const res = await this.
|
|
3593
|
-
`/
|
|
3634
|
+
const res = await this.privateHttp.post(
|
|
3635
|
+
`/storefront/stores/${storeRef}/shipping/calculate`,
|
|
3594
3636
|
data
|
|
3595
3637
|
);
|
|
3596
3638
|
return unwrap(res);
|
|
@@ -3599,35 +3641,41 @@ var ShippingApi = class {
|
|
|
3599
3641
|
|
|
3600
3642
|
// src/modules/promotions/api.ts
|
|
3601
3643
|
var PromotionsApi = class {
|
|
3602
|
-
constructor(
|
|
3603
|
-
this.
|
|
3644
|
+
constructor(publicHttp) {
|
|
3645
|
+
this.publicHttp = publicHttp;
|
|
3604
3646
|
}
|
|
3605
3647
|
/**
|
|
3606
|
-
*
|
|
3648
|
+
* Lists promotions the shopper could use, optionally for a given cart subtotal.
|
|
3607
3649
|
*
|
|
3608
3650
|
* @param storeRef - the store's ref or handle
|
|
3609
|
-
* @param
|
|
3610
|
-
* @returns The
|
|
3651
|
+
* @param subtotal - the cart subtotal in the store's currency
|
|
3652
|
+
* @returns The suggested promotions; throws {@link ApiClientError} when the API answers with an error
|
|
3611
3653
|
*/
|
|
3612
|
-
async
|
|
3613
|
-
const
|
|
3614
|
-
|
|
3615
|
-
|
|
3654
|
+
async getSuggestions(storeRef, subtotal) {
|
|
3655
|
+
const params = new URLSearchParams();
|
|
3656
|
+
if (subtotal !== void 0) params.append("subtotal", subtotal.toString());
|
|
3657
|
+
const res = await this.publicHttp.get(
|
|
3658
|
+
`/storefront/stores/${storeRef}/promotions/suggestions?${params.toString()}`
|
|
3616
3659
|
);
|
|
3617
3660
|
return unwrap(res);
|
|
3618
3661
|
}
|
|
3662
|
+
};
|
|
3663
|
+
var PromotionsServerApi = class extends PromotionsApi {
|
|
3664
|
+
constructor(publicHttp, privateHttp) {
|
|
3665
|
+
super(publicHttp);
|
|
3666
|
+
this.privateHttp = privateHttp;
|
|
3667
|
+
}
|
|
3619
3668
|
/**
|
|
3620
|
-
*
|
|
3669
|
+
* Checks a promotion code against a cart.
|
|
3621
3670
|
*
|
|
3622
3671
|
* @param storeRef - the store's ref or handle
|
|
3623
|
-
* @param
|
|
3624
|
-
* @returns The
|
|
3672
|
+
* @param data - the code and the cart details
|
|
3673
|
+
* @returns The validation result; throws {@link ApiClientError} when the API answers with an error
|
|
3625
3674
|
*/
|
|
3626
|
-
async
|
|
3627
|
-
const
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
`/public/stores/${storeRef}/promotions/suggestions?${params.toString()}`
|
|
3675
|
+
async validate(storeRef, data) {
|
|
3676
|
+
const res = await this.privateHttp.post(
|
|
3677
|
+
`/storefront/stores/${storeRef}/promotions/validate`,
|
|
3678
|
+
data
|
|
3631
3679
|
);
|
|
3632
3680
|
return unwrap(res);
|
|
3633
3681
|
}
|
|
@@ -3646,7 +3694,7 @@ var PaymentMethodsApi = class {
|
|
|
3646
3694
|
*/
|
|
3647
3695
|
async getEnabled(storeRef) {
|
|
3648
3696
|
const res = await this.http.get(
|
|
3649
|
-
`/
|
|
3697
|
+
`/storefront/stores/${storeRef}/payment-methods`
|
|
3650
3698
|
);
|
|
3651
3699
|
return unwrap(res);
|
|
3652
3700
|
}
|
|
@@ -3654,9 +3702,8 @@ var PaymentMethodsApi = class {
|
|
|
3654
3702
|
|
|
3655
3703
|
// src/modules/payments/api.ts
|
|
3656
3704
|
var PaymentsApi = class {
|
|
3657
|
-
constructor(
|
|
3658
|
-
this.
|
|
3659
|
-
this.authHttp = authHttp;
|
|
3705
|
+
constructor(privateHttp) {
|
|
3706
|
+
this.privateHttp = privateHttp;
|
|
3660
3707
|
}
|
|
3661
3708
|
/**
|
|
3662
3709
|
* Start a gateway charge attempt for an order. Keyed by `order_code`,
|
|
@@ -3666,8 +3713,8 @@ var PaymentsApi = class {
|
|
|
3666
3713
|
* store's orders.
|
|
3667
3714
|
*/
|
|
3668
3715
|
async initiate(storeRef, input) {
|
|
3669
|
-
const res = await this.
|
|
3670
|
-
`/
|
|
3716
|
+
const res = await this.privateHttp.post(
|
|
3717
|
+
`/storefront/stores/${encodeURIComponent(storeRef)}/payments/initiate`,
|
|
3671
3718
|
{ order_code: input.order_code, provider_code: input.provider_code }
|
|
3672
3719
|
);
|
|
3673
3720
|
return unwrap(res);
|
|
@@ -3678,8 +3725,8 @@ var PaymentsApi = class {
|
|
|
3678
3725
|
* `#` by default in this system, and an unencoded `#` truncates the URL.
|
|
3679
3726
|
*/
|
|
3680
3727
|
async getPaymentState(storeRef, order_code) {
|
|
3681
|
-
const res = await this.
|
|
3682
|
-
`/
|
|
3728
|
+
const res = await this.privateHttp.get(
|
|
3729
|
+
`/storefront/stores/${encodeURIComponent(storeRef)}/orders/${encodeURIComponent(order_code)}/payment-state`
|
|
3683
3730
|
);
|
|
3684
3731
|
return unwrap(res);
|
|
3685
3732
|
}
|
|
@@ -3687,8 +3734,8 @@ var PaymentsApi = class {
|
|
|
3687
3734
|
|
|
3688
3735
|
// src/modules/reviews/api.ts
|
|
3689
3736
|
var ReviewsApi = class {
|
|
3690
|
-
constructor(
|
|
3691
|
-
this.
|
|
3737
|
+
constructor(publicHttp) {
|
|
3738
|
+
this.publicHttp = publicHttp;
|
|
3692
3739
|
}
|
|
3693
3740
|
/**
|
|
3694
3741
|
* Lists the published reviews of a product.
|
|
@@ -3700,11 +3747,17 @@ var ReviewsApi = class {
|
|
|
3700
3747
|
*/
|
|
3701
3748
|
async getProductReviews(storeRef, productId, query) {
|
|
3702
3749
|
const queryString = stringify(query ?? {});
|
|
3703
|
-
const res = await this.
|
|
3704
|
-
|
|
3750
|
+
const res = await this.publicHttp.get(
|
|
3751
|
+
`/storefront/stores/${storeRef}/products/${productId}/reviews${queryString ? `?${queryString}` : ""}`
|
|
3705
3752
|
);
|
|
3706
3753
|
return unwrap(res);
|
|
3707
3754
|
}
|
|
3755
|
+
};
|
|
3756
|
+
var ReviewsServerApi = class extends ReviewsApi {
|
|
3757
|
+
constructor(publicHttp, privateHttp) {
|
|
3758
|
+
super(publicHttp);
|
|
3759
|
+
this.privateHttp = privateHttp;
|
|
3760
|
+
}
|
|
3708
3761
|
/**
|
|
3709
3762
|
* Gets the public details behind a review invitation link.
|
|
3710
3763
|
*
|
|
@@ -3713,8 +3766,8 @@ var ReviewsApi = class {
|
|
|
3713
3766
|
* @returns The invitation details; throws {@link ApiClientError} when the API answers with an error
|
|
3714
3767
|
*/
|
|
3715
3768
|
async getReviewInvitation(storeRef, token) {
|
|
3716
|
-
const res = await this.
|
|
3717
|
-
|
|
3769
|
+
const res = await this.privateHttp.get(
|
|
3770
|
+
`/storefront/stores/${storeRef}/review-invitations/${token}`
|
|
3718
3771
|
);
|
|
3719
3772
|
return unwrap(res);
|
|
3720
3773
|
}
|
|
@@ -3728,8 +3781,8 @@ var ReviewsApi = class {
|
|
|
3728
3781
|
*/
|
|
3729
3782
|
async getOrderReviewInvitations(storeRef, orderNumber, email) {
|
|
3730
3783
|
const queryString = stringify({ order_number: orderNumber, email });
|
|
3731
|
-
const res = await this.
|
|
3732
|
-
|
|
3784
|
+
const res = await this.privateHttp.get(
|
|
3785
|
+
`/storefront/stores/${storeRef}/review-invitations/by-order?${queryString}`
|
|
3733
3786
|
);
|
|
3734
3787
|
return unwrap(res);
|
|
3735
3788
|
}
|
|
@@ -3743,8 +3796,8 @@ var ReviewsApi = class {
|
|
|
3743
3796
|
*/
|
|
3744
3797
|
async getBatchOrderReviewInvitations(storeRef, orderNumbers, email) {
|
|
3745
3798
|
const queryString = stringify({ order_numbers: orderNumbers.join(","), email });
|
|
3746
|
-
const res = await this.
|
|
3747
|
-
|
|
3799
|
+
const res = await this.privateHttp.get(
|
|
3800
|
+
`/storefront/stores/${storeRef}/review-invitations/by-orders?${queryString}`
|
|
3748
3801
|
);
|
|
3749
3802
|
return unwrap(res);
|
|
3750
3803
|
}
|
|
@@ -3757,8 +3810,8 @@ var ReviewsApi = class {
|
|
|
3757
3810
|
* @returns The API's answer; throws {@link ApiClientError} when the API answers with an error
|
|
3758
3811
|
*/
|
|
3759
3812
|
async submitReviewInvitation(storeRef, token, payload) {
|
|
3760
|
-
const res = await this.
|
|
3761
|
-
|
|
3813
|
+
const res = await this.privateHttp.post(
|
|
3814
|
+
`/storefront/stores/${storeRef}/review-invitations/${token}/submit`,
|
|
3762
3815
|
payload
|
|
3763
3816
|
);
|
|
3764
3817
|
return unwrap(res);
|
|
@@ -3779,14 +3832,14 @@ var CustomersApi = class {
|
|
|
3779
3832
|
*/
|
|
3780
3833
|
async upsertForAuth(storeRef, payload) {
|
|
3781
3834
|
return this.http.post(
|
|
3782
|
-
`/stores/${storeRef}/customers/auth/upsert`,
|
|
3835
|
+
`/storefront/stores/${storeRef}/customers/auth/upsert`,
|
|
3783
3836
|
payload
|
|
3784
3837
|
);
|
|
3785
3838
|
}
|
|
3786
3839
|
/** The signed-in customer's metafields with customer access (spec §6.6). */
|
|
3787
3840
|
async getMetafields(storeRef) {
|
|
3788
3841
|
const res = await this.http.get(
|
|
3789
|
-
`/
|
|
3842
|
+
`/storefront/stores/${storeRef}/customers/metafields`
|
|
3790
3843
|
);
|
|
3791
3844
|
return unwrap(res);
|
|
3792
3845
|
}
|
|
@@ -3796,7 +3849,7 @@ var CustomersApi = class {
|
|
|
3796
3849
|
*/
|
|
3797
3850
|
async updateMetafields(storeRef, values) {
|
|
3798
3851
|
const res = await this.http.put(
|
|
3799
|
-
`/
|
|
3852
|
+
`/storefront/stores/${storeRef}/customers/metafields`,
|
|
3800
3853
|
{ values }
|
|
3801
3854
|
);
|
|
3802
3855
|
return unwrap(res);
|
|
@@ -3816,7 +3869,7 @@ var AddressesApi = class {
|
|
|
3816
3869
|
*/
|
|
3817
3870
|
async list(storeRef) {
|
|
3818
3871
|
const res = await this.http.get(
|
|
3819
|
-
`/
|
|
3872
|
+
`/storefront/stores/${storeRef}/customers/address`
|
|
3820
3873
|
);
|
|
3821
3874
|
return unwrapOrNull(res);
|
|
3822
3875
|
}
|
|
@@ -3829,7 +3882,7 @@ var AddressesApi = class {
|
|
|
3829
3882
|
*/
|
|
3830
3883
|
async getById(storeRef, addressId) {
|
|
3831
3884
|
const res = await this.http.get(
|
|
3832
|
-
`/
|
|
3885
|
+
`/storefront/stores/${storeRef}/customers/address/${addressId}`
|
|
3833
3886
|
);
|
|
3834
3887
|
return unwrapOrNull(res);
|
|
3835
3888
|
}
|
|
@@ -3842,7 +3895,7 @@ var AddressesApi = class {
|
|
|
3842
3895
|
*/
|
|
3843
3896
|
async create(storeRef, data) {
|
|
3844
3897
|
const res = await this.http.post(
|
|
3845
|
-
`/
|
|
3898
|
+
`/storefront/stores/${storeRef}/customers/address`,
|
|
3846
3899
|
data
|
|
3847
3900
|
);
|
|
3848
3901
|
return unwrapOrNull(res);
|
|
@@ -3857,7 +3910,7 @@ var AddressesApi = class {
|
|
|
3857
3910
|
*/
|
|
3858
3911
|
async update(storeRef, addressId, data) {
|
|
3859
3912
|
const res = await this.http.patch(
|
|
3860
|
-
`/
|
|
3913
|
+
`/storefront/stores/${storeRef}/customers/address/${addressId}`,
|
|
3861
3914
|
data
|
|
3862
3915
|
);
|
|
3863
3916
|
return unwrapOrNull(res);
|
|
@@ -3871,7 +3924,7 @@ var AddressesApi = class {
|
|
|
3871
3924
|
*/
|
|
3872
3925
|
async delete(storeRef, addressId) {
|
|
3873
3926
|
const res = await this.http.delete(
|
|
3874
|
-
`/
|
|
3927
|
+
`/storefront/stores/${storeRef}/customers/address/${addressId}`
|
|
3875
3928
|
);
|
|
3876
3929
|
return res.success;
|
|
3877
3930
|
}
|
|
@@ -3884,7 +3937,7 @@ var AddressesApi = class {
|
|
|
3884
3937
|
*/
|
|
3885
3938
|
async setDefault(storeRef, addressId) {
|
|
3886
3939
|
const res = await this.http.patch(
|
|
3887
|
-
`/
|
|
3940
|
+
`/storefront/stores/${storeRef}/customers/address/${addressId}/set-default`
|
|
3888
3941
|
);
|
|
3889
3942
|
return unwrapOrNull(res);
|
|
3890
3943
|
}
|
|
@@ -3903,7 +3956,7 @@ var ContentPagesApi = class {
|
|
|
3903
3956
|
*/
|
|
3904
3957
|
async getPublished(storeRef) {
|
|
3905
3958
|
const res = await this.http.get(
|
|
3906
|
-
`/
|
|
3959
|
+
`/storefront/stores/${storeRef}/content-pages`
|
|
3907
3960
|
);
|
|
3908
3961
|
return unwrap(res);
|
|
3909
3962
|
}
|
|
@@ -3918,7 +3971,7 @@ var ContentPagesApi = class {
|
|
|
3918
3971
|
async getBySlug(storeRef, slug, query) {
|
|
3919
3972
|
const queryString = query ? stringify(query) : "";
|
|
3920
3973
|
const res = await this.http.get(
|
|
3921
|
-
`/
|
|
3974
|
+
`/storefront/stores/${storeRef}/content-pages/${encodeURIComponent(slug)}${queryString ? "?" + queryString : ""}`
|
|
3922
3975
|
);
|
|
3923
3976
|
return unwrap(res);
|
|
3924
3977
|
}
|
|
@@ -3940,7 +3993,7 @@ var MenusApi = class {
|
|
|
3940
3993
|
async getByRef(storeRef, ref, includeItems = true) {
|
|
3941
3994
|
const query = includeItems ? "?include_items=true" : "";
|
|
3942
3995
|
const res = await this.http.get(
|
|
3943
|
-
`/
|
|
3996
|
+
`/storefront/stores/${storeRef}/menus/ref/${encodeURIComponent(ref)}${query}`
|
|
3944
3997
|
);
|
|
3945
3998
|
return unwrapOrNull(res);
|
|
3946
3999
|
}
|
|
@@ -3955,7 +4008,7 @@ var RedirectsApi = class {
|
|
|
3955
4008
|
async lookup(storeRef, path, options) {
|
|
3956
4009
|
const params = new URLSearchParams();
|
|
3957
4010
|
params.set("path", path);
|
|
3958
|
-
const url = `/
|
|
4011
|
+
const url = `/storefront/stores/${storeRef}/url-redirects/lookup?${params.toString()}`;
|
|
3959
4012
|
const res = options ? await this.http.get(url, options) : await this.http.get(url);
|
|
3960
4013
|
const result = unwrapOrNull(res);
|
|
3961
4014
|
return result?.data ?? null;
|
|
@@ -3969,10 +4022,10 @@ var AuthApi = class {
|
|
|
3969
4022
|
this.storeRef = storeRef;
|
|
3970
4023
|
}
|
|
3971
4024
|
publicPath(suffix) {
|
|
3972
|
-
return `/
|
|
4025
|
+
return `/storefront/stores/${encodeURIComponent(this.storeRef)}/auth/${suffix}`;
|
|
3973
4026
|
}
|
|
3974
4027
|
tenantPath(suffix) {
|
|
3975
|
-
return `/
|
|
4028
|
+
return `/storefront/stores/${encodeURIComponent(this.storeRef)}/auth/${suffix}`;
|
|
3976
4029
|
}
|
|
3977
4030
|
auth(access_token) {
|
|
3978
4031
|
return { headers: { Authorization: `Bearer ${access_token}` } };
|
|
@@ -4421,33 +4474,111 @@ var SHIPPING_ERROR_CODES = {
|
|
|
4421
4474
|
RATE_UNAVAILABLE: "ORDER_SHIPPING_RATE_UNAVAILABLE"
|
|
4422
4475
|
};
|
|
4423
4476
|
|
|
4424
|
-
// src/
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
const
|
|
4477
|
+
// src/core/storefront-key.ts
|
|
4478
|
+
var KEY_HEADER = "x-storefront-api-key";
|
|
4479
|
+
function withKey(options, key) {
|
|
4480
|
+
const headers = {};
|
|
4481
|
+
for (const [name, value] of Object.entries(options?.headers ?? {})) {
|
|
4482
|
+
if (name.toLowerCase() !== KEY_HEADER) headers[name] = value;
|
|
4483
|
+
}
|
|
4484
|
+
headers[KEY_HEADER] = key;
|
|
4485
|
+
return { ...options, headers };
|
|
4486
|
+
}
|
|
4487
|
+
function withStorefrontKey(http, key) {
|
|
4488
|
+
return {
|
|
4489
|
+
get: (url, options) => http.get(url, withKey(options, key)),
|
|
4490
|
+
post: (url, data, options) => http.post(url, data, withKey(options, key)),
|
|
4491
|
+
put: (url, data, options) => http.put(url, data, withKey(options, key)),
|
|
4492
|
+
patch: (url, data, options) => http.patch(url, data, withKey(options, key)),
|
|
4493
|
+
delete: (url, options) => http.delete(url, withKey(options, key))
|
|
4494
|
+
};
|
|
4495
|
+
}
|
|
4496
|
+
|
|
4497
|
+
// src/factory.ts
|
|
4498
|
+
function buildAllModules({
|
|
4499
|
+
publicHttp,
|
|
4500
|
+
privateHttp,
|
|
4501
|
+
shopperHttp
|
|
4502
|
+
}) {
|
|
4428
4503
|
return {
|
|
4429
4504
|
products: new ProductsApi(publicHttp),
|
|
4430
4505
|
collections: new CollectionsApi(publicHttp),
|
|
4431
4506
|
categories: new CategoriesApi(publicHttp),
|
|
4432
|
-
|
|
4433
|
-
orders: new OrdersApi(publicHttp, authHttp),
|
|
4434
|
-
blog: new BlogApi(publicHttp, authHttp),
|
|
4507
|
+
blog: new BlogServerApi(publicHttp, shopperHttp),
|
|
4435
4508
|
stores: new StoresApi(publicHttp),
|
|
4436
4509
|
themes: new ThemesApi(publicHttp),
|
|
4437
|
-
metaobjects: new MetaobjectsApi(publicHttp,
|
|
4510
|
+
metaobjects: new MetaobjectsApi(publicHttp, shopperHttp),
|
|
4438
4511
|
search: new SearchApi(publicHttp),
|
|
4439
|
-
shipping: new
|
|
4440
|
-
promotions: new
|
|
4512
|
+
shipping: new ShippingServerApi(publicHttp, privateHttp),
|
|
4513
|
+
promotions: new PromotionsServerApi(publicHttp, privateHttp),
|
|
4441
4514
|
paymentMethods: new PaymentMethodsApi(publicHttp),
|
|
4442
|
-
|
|
4443
|
-
reviews: new ReviewsApi(publicHttp),
|
|
4444
|
-
customers: new CustomersApi(authHttp),
|
|
4445
|
-
addresses: new AddressesApi(authHttp),
|
|
4515
|
+
reviews: new ReviewsServerApi(publicHttp, privateHttp),
|
|
4446
4516
|
contentPages: new ContentPagesApi(publicHttp),
|
|
4447
4517
|
menus: new MenusApi(publicHttp),
|
|
4448
|
-
redirects: new RedirectsApi(publicHttp)
|
|
4518
|
+
redirects: new RedirectsApi(publicHttp),
|
|
4519
|
+
cart: new CartApi(privateHttp, shopperHttp),
|
|
4520
|
+
orders: new OrdersApi(privateHttp, shopperHttp),
|
|
4521
|
+
payments: new PaymentsApi(privateHttp),
|
|
4522
|
+
customers: new CustomersApi(shopperHttp),
|
|
4523
|
+
addresses: new AddressesApi(shopperHttp)
|
|
4449
4524
|
};
|
|
4450
4525
|
}
|
|
4526
|
+
function createEcomwebSdk(options) {
|
|
4527
|
+
const publicHttp = withClientHeader(options.publicHttp, options.clientInfo);
|
|
4528
|
+
const shopperHttp = withClientHeader(options.authHttp, options.clientInfo);
|
|
4529
|
+
const all = buildAllModules({ publicHttp, privateHttp: publicHttp, shopperHttp });
|
|
4530
|
+
return {
|
|
4531
|
+
products: all.products,
|
|
4532
|
+
collections: all.collections,
|
|
4533
|
+
categories: all.categories,
|
|
4534
|
+
blog: new BlogApi(publicHttp, shopperHttp),
|
|
4535
|
+
stores: all.stores,
|
|
4536
|
+
themes: all.themes,
|
|
4537
|
+
metaobjects: all.metaobjects,
|
|
4538
|
+
search: all.search,
|
|
4539
|
+
shipping: new ShippingApi(publicHttp),
|
|
4540
|
+
promotions: new PromotionsApi(publicHttp),
|
|
4541
|
+
paymentMethods: all.paymentMethods,
|
|
4542
|
+
reviews: new ReviewsApi(publicHttp),
|
|
4543
|
+
contentPages: all.contentPages,
|
|
4544
|
+
menus: all.menus,
|
|
4545
|
+
redirects: all.redirects
|
|
4546
|
+
};
|
|
4547
|
+
}
|
|
4548
|
+
function createEcomwebServerSdk(options) {
|
|
4549
|
+
const secretKey = options.secretKey?.trim() ?? "";
|
|
4550
|
+
if (!secretKey) {
|
|
4551
|
+
throw new Error("createEcomwebServerSdk: secretKey is required");
|
|
4552
|
+
}
|
|
4553
|
+
if (secretKey.startsWith("pk_")) {
|
|
4554
|
+
throw new Error(
|
|
4555
|
+
"createEcomwebServerSdk: secretKey is a publishable key; pass the secret key (sk_...)"
|
|
4556
|
+
);
|
|
4557
|
+
}
|
|
4558
|
+
if (typeof window !== "undefined") {
|
|
4559
|
+
throw new Error(
|
|
4560
|
+
"createEcomwebServerSdk runs on a server only; in the browser use createEcomwebProxiedSdk"
|
|
4561
|
+
);
|
|
4562
|
+
}
|
|
4563
|
+
const publicHttp = withClientHeader(
|
|
4564
|
+
withStorefrontKey(options.publicHttp, secretKey),
|
|
4565
|
+
options.clientInfo
|
|
4566
|
+
);
|
|
4567
|
+
const shopperHttp = withClientHeader(
|
|
4568
|
+
withStorefrontKey(options.authHttp, secretKey),
|
|
4569
|
+
options.clientInfo
|
|
4570
|
+
);
|
|
4571
|
+
return buildAllModules({ publicHttp, privateHttp: publicHttp, shopperHttp });
|
|
4572
|
+
}
|
|
4573
|
+
function createEcomwebProxiedSdk(options) {
|
|
4574
|
+
const publicHttp = withClientHeader(options.publicHttp, options.clientInfo);
|
|
4575
|
+
const proxyHttp = withClientHeader(options.proxyHttp, options.clientInfo);
|
|
4576
|
+
return buildAllModules({
|
|
4577
|
+
publicHttp,
|
|
4578
|
+
privateHttp: proxyHttp,
|
|
4579
|
+
shopperHttp: proxyHttp
|
|
4580
|
+
});
|
|
4581
|
+
}
|
|
4451
4582
|
export {
|
|
4452
4583
|
ADJUSTABLE_STATES,
|
|
4453
4584
|
ADMIN_ORDER_SOURCES,
|
|
@@ -4455,6 +4586,7 @@ export {
|
|
|
4455
4586
|
ApiClientError,
|
|
4456
4587
|
AuthApi,
|
|
4457
4588
|
BlogApi,
|
|
4589
|
+
BlogServerApi,
|
|
4458
4590
|
CLIENT_HEADER,
|
|
4459
4591
|
COLLECTION_RULE_MATRIX,
|
|
4460
4592
|
CONDITION_TYPE_LABELS,
|
|
@@ -4530,11 +4662,13 @@ export {
|
|
|
4530
4662
|
PromotionTypeSchema,
|
|
4531
4663
|
PromotionWithDiscountSchema,
|
|
4532
4664
|
PromotionsApi,
|
|
4665
|
+
PromotionsServerApi,
|
|
4533
4666
|
RENDER_PREFIX,
|
|
4534
4667
|
RESOURCE_REFERENCE_TYPES,
|
|
4535
4668
|
RULE_FIELDS,
|
|
4536
4669
|
RedirectsApi,
|
|
4537
4670
|
ReviewsApi,
|
|
4671
|
+
ReviewsServerApi,
|
|
4538
4672
|
SDK_CLIENT_TOKEN,
|
|
4539
4673
|
SDK_VERSION,
|
|
4540
4674
|
SHIPMENT_STATUSES,
|
|
@@ -4544,6 +4678,7 @@ export {
|
|
|
4544
4678
|
SHIPPING_RATE_TYPES,
|
|
4545
4679
|
SearchApi,
|
|
4546
4680
|
ShippingApi,
|
|
4681
|
+
ShippingServerApi,
|
|
4547
4682
|
StoresApi,
|
|
4548
4683
|
THEME_HEX_COLOR,
|
|
4549
4684
|
ThemesApi,
|
|
@@ -4589,7 +4724,9 @@ export {
|
|
|
4589
4724
|
createBlogTagSchema,
|
|
4590
4725
|
createCategorySchema,
|
|
4591
4726
|
createContentPageSchema,
|
|
4727
|
+
createEcomwebProxiedSdk,
|
|
4592
4728
|
createEcomwebSdk,
|
|
4729
|
+
createEcomwebServerSdk,
|
|
4593
4730
|
createEmbeddedScriptSchema,
|
|
4594
4731
|
createOrderItemSchema,
|
|
4595
4732
|
createOrderSchema,
|