@ecomweb/sdk 0.14.0 → 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/README.md +18 -2
- package/dist/index.d.ts +786 -35
- package/dist/index.js +675 -120
- 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.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) {
|
|
@@ -2956,19 +2956,35 @@ var ProductsApi = class {
|
|
|
2956
2956
|
constructor(http) {
|
|
2957
2957
|
this.http = http;
|
|
2958
2958
|
}
|
|
2959
|
+
/**
|
|
2960
|
+
* Gets one product by id.
|
|
2961
|
+
*
|
|
2962
|
+
* @param storeRef - the store's ref or handle
|
|
2963
|
+
* @param productId - the product id
|
|
2964
|
+
* @param query - optional fields to include
|
|
2965
|
+
* @returns The product, or `null` when it is not found; throws {@link ApiClientError} on any other API error
|
|
2966
|
+
*/
|
|
2959
2967
|
async getById(storeRef, productId, query) {
|
|
2960
2968
|
const queryString = stringify(query ?? {});
|
|
2961
2969
|
const res = await this.http.get(
|
|
2962
|
-
`/
|
|
2970
|
+
`/storefront/stores/${storeRef}/products/${productId}${queryString ? "?" + queryString : ""}`
|
|
2963
2971
|
);
|
|
2964
2972
|
return unwrapOrNull(res);
|
|
2965
2973
|
}
|
|
2974
|
+
/**
|
|
2975
|
+
* Gets one product by slug.
|
|
2976
|
+
*
|
|
2977
|
+
* @param storeRef - the store's ref or handle
|
|
2978
|
+
* @param slug - the product slug
|
|
2979
|
+
* @param query - optional fields to include
|
|
2980
|
+
* @returns The product, or `null` when it is not found; throws {@link ApiClientError} on any other API error
|
|
2981
|
+
*/
|
|
2966
2982
|
async getBySlug(storeRef, slug, query) {
|
|
2967
2983
|
const normalizedSlug = slug.normalize("NFC");
|
|
2968
2984
|
const encodedSlug = encodeURIComponent(normalizedSlug);
|
|
2969
2985
|
const queryString = stringify(query ?? {});
|
|
2970
2986
|
const res = await this.http.get(
|
|
2971
|
-
`/
|
|
2987
|
+
`/storefront/stores/${storeRef}/products/slug/${encodedSlug}${queryString ? "?" + queryString : ""}`
|
|
2972
2988
|
);
|
|
2973
2989
|
return unwrapOrNull(res);
|
|
2974
2990
|
}
|
|
@@ -2979,13 +2995,27 @@ var CollectionsApi = class {
|
|
|
2979
2995
|
constructor(http) {
|
|
2980
2996
|
this.http = http;
|
|
2981
2997
|
}
|
|
2998
|
+
/**
|
|
2999
|
+
* Lists collections, one page at a time.
|
|
3000
|
+
*
|
|
3001
|
+
* @param storeRef - the store's ref or handle
|
|
3002
|
+
* @param params - filters, sorting and paging
|
|
3003
|
+
* @returns A page of collections; throws {@link ApiClientError} when the API answers with an error
|
|
3004
|
+
*/
|
|
2982
3005
|
async getAllPaginated(storeRef, params) {
|
|
2983
3006
|
const queryString = stringify(params ?? {});
|
|
2984
3007
|
const res = await this.http.get(
|
|
2985
|
-
`/
|
|
3008
|
+
`/storefront/stores/${storeRef}/collections${queryString ? "?" + queryString : ""}`
|
|
2986
3009
|
);
|
|
2987
3010
|
return unwrap(res);
|
|
2988
3011
|
}
|
|
3012
|
+
/**
|
|
3013
|
+
* Lists up to 100 collections in one call.
|
|
3014
|
+
*
|
|
3015
|
+
* @param storeRef - the store's ref or handle
|
|
3016
|
+
* @param ids - limit the result to these collection ids
|
|
3017
|
+
* @returns The collections; throws {@link ApiClientError} when the API answers with an error
|
|
3018
|
+
*/
|
|
2989
3019
|
async getAll(storeRef, ids) {
|
|
2990
3020
|
const result = await this.getAllPaginated(storeRef, {
|
|
2991
3021
|
ids,
|
|
@@ -2993,10 +3023,18 @@ var CollectionsApi = class {
|
|
|
2993
3023
|
});
|
|
2994
3024
|
return result.data;
|
|
2995
3025
|
}
|
|
3026
|
+
/**
|
|
3027
|
+
* Gets one collection by slug.
|
|
3028
|
+
*
|
|
3029
|
+
* @param storeRef - the store's ref or handle
|
|
3030
|
+
* @param slug - the collection slug
|
|
3031
|
+
* @param query - `include_seo_metadata` adds the SEO fields
|
|
3032
|
+
* @returns The collection, or `null` when it is not found; throws {@link ApiClientError} on any other API error
|
|
3033
|
+
*/
|
|
2996
3034
|
async getBySlug(storeRef, slug, query) {
|
|
2997
3035
|
const queryString = query ? stringify(query) : "";
|
|
2998
3036
|
const res = await this.http.get(
|
|
2999
|
-
`/
|
|
3037
|
+
`/storefront/stores/${storeRef}/collections/slug/${slug}${queryString ? "?" + queryString : ""}`
|
|
3000
3038
|
);
|
|
3001
3039
|
return unwrapOrNull(res);
|
|
3002
3040
|
}
|
|
@@ -3007,13 +3045,27 @@ var CategoriesApi = class {
|
|
|
3007
3045
|
constructor(http) {
|
|
3008
3046
|
this.http = http;
|
|
3009
3047
|
}
|
|
3048
|
+
/**
|
|
3049
|
+
* Lists categories, one page at a time.
|
|
3050
|
+
*
|
|
3051
|
+
* @param storeRef - the store's ref or handle
|
|
3052
|
+
* @param params - filters, sorting and paging
|
|
3053
|
+
* @returns A page of categories; throws {@link ApiClientError} when the API answers with an error
|
|
3054
|
+
*/
|
|
3010
3055
|
async getAllPaginated(storeRef, params) {
|
|
3011
3056
|
const queryString = stringify(params ?? {});
|
|
3012
3057
|
const res = await this.http.get(
|
|
3013
|
-
`/
|
|
3058
|
+
`/storefront/stores/${storeRef}/categories${queryString ? "?" + queryString : ""}`
|
|
3014
3059
|
);
|
|
3015
3060
|
return unwrap(res);
|
|
3016
3061
|
}
|
|
3062
|
+
/**
|
|
3063
|
+
* Lists up to 1,000 categories in one call.
|
|
3064
|
+
*
|
|
3065
|
+
* @param storeRef - the store's ref or handle
|
|
3066
|
+
* @param activeOnly - `true` (the default) returns only active categories
|
|
3067
|
+
* @returns The categories; throws {@link ApiClientError} when the API answers with an error
|
|
3068
|
+
*/
|
|
3017
3069
|
async getAll(storeRef, activeOnly = true) {
|
|
3018
3070
|
const result = await this.getAllPaginated(storeRef, {
|
|
3019
3071
|
is_active: activeOnly,
|
|
@@ -3021,15 +3073,29 @@ var CategoriesApi = class {
|
|
|
3021
3073
|
});
|
|
3022
3074
|
return result.data;
|
|
3023
3075
|
}
|
|
3076
|
+
/**
|
|
3077
|
+
* Gets one category by id.
|
|
3078
|
+
*
|
|
3079
|
+
* @param storeRef - the store's ref or handle
|
|
3080
|
+
* @param categoryId - the category id
|
|
3081
|
+
* @returns The category, or `null` when it is not found; throws {@link ApiClientError} on any other API error
|
|
3082
|
+
*/
|
|
3024
3083
|
async getById(storeRef, categoryId) {
|
|
3025
3084
|
const res = await this.http.get(
|
|
3026
|
-
`/
|
|
3085
|
+
`/storefront/stores/${storeRef}/categories/${categoryId}`
|
|
3027
3086
|
);
|
|
3028
3087
|
return unwrapOrNull(res);
|
|
3029
3088
|
}
|
|
3089
|
+
/**
|
|
3090
|
+
* Gets one category by slug.
|
|
3091
|
+
*
|
|
3092
|
+
* @param storeRef - the store's ref or handle
|
|
3093
|
+
* @param slug - the category slug
|
|
3094
|
+
* @returns The category, or `null` when it is not found; throws {@link ApiClientError} on any other API error
|
|
3095
|
+
*/
|
|
3030
3096
|
async getBySlug(storeRef, slug) {
|
|
3031
3097
|
const res = await this.http.get(
|
|
3032
|
-
`/
|
|
3098
|
+
`/storefront/stores/${storeRef}/categories/${encodeURIComponent(slug)}`
|
|
3033
3099
|
);
|
|
3034
3100
|
return unwrapOrNull(res);
|
|
3035
3101
|
}
|
|
@@ -3037,44 +3103,89 @@ var CategoriesApi = class {
|
|
|
3037
3103
|
|
|
3038
3104
|
// src/modules/cart/api.ts
|
|
3039
3105
|
var CartApi = class {
|
|
3040
|
-
constructor(
|
|
3041
|
-
this.
|
|
3042
|
-
this.
|
|
3106
|
+
constructor(privateHttp, shopperHttp) {
|
|
3107
|
+
this.privateHttp = privateHttp;
|
|
3108
|
+
this.shopperHttp = shopperHttp;
|
|
3043
3109
|
}
|
|
3044
3110
|
client(isAuth) {
|
|
3045
|
-
return isAuth ? this.
|
|
3111
|
+
return isAuth ? this.shopperHttp : this.privateHttp;
|
|
3046
3112
|
}
|
|
3047
|
-
|
|
3048
|
-
|
|
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`;
|
|
3049
3116
|
}
|
|
3117
|
+
/**
|
|
3118
|
+
* Gets the shopper's cart.
|
|
3119
|
+
*
|
|
3120
|
+
* @param storeRef - the store's ref or handle
|
|
3121
|
+
* @param sessionId - the guest cart session id
|
|
3122
|
+
* @param isAuth - `true` for the signed-in customer's cart, `false` for the guest cart
|
|
3123
|
+
* @returns The cart, or `null` when it is not found; throws {@link ApiClientError} on any other API error
|
|
3124
|
+
*/
|
|
3050
3125
|
async getCart(storeRef, sessionId, isAuth) {
|
|
3051
3126
|
const res = await this.client(isAuth).get(
|
|
3052
|
-
|
|
3127
|
+
this.cartPath(isAuth, storeRef),
|
|
3053
3128
|
{ headers: { "x-session-id": sessionId } }
|
|
3054
3129
|
);
|
|
3055
3130
|
return unwrapOrNull(res);
|
|
3056
3131
|
}
|
|
3132
|
+
/**
|
|
3133
|
+
* Adds a product variant to the cart.
|
|
3134
|
+
*
|
|
3135
|
+
* @param storeRef - the store's ref or handle
|
|
3136
|
+
* @param data - the variant and the quantity
|
|
3137
|
+
* @param sessionId - the guest cart session id
|
|
3138
|
+
* @param isAuth - `true` for the signed-in customer's cart, `false` for the guest cart
|
|
3139
|
+
* @returns The cart id and the added item; throws {@link ApiClientError} when the API answers with an error
|
|
3140
|
+
*/
|
|
3057
3141
|
async addItem(storeRef, data, sessionId, isAuth) {
|
|
3058
|
-
const res = await this.client(isAuth).post(
|
|
3142
|
+
const res = await this.client(isAuth).post(`${this.cartPath(isAuth, storeRef)}/items`, data, {
|
|
3059
3143
|
headers: { "x-session-id": sessionId }
|
|
3060
3144
|
});
|
|
3061
3145
|
return unwrap(res);
|
|
3062
3146
|
}
|
|
3147
|
+
/**
|
|
3148
|
+
* Changes the quantity of a cart line.
|
|
3149
|
+
*
|
|
3150
|
+
* @param storeRef - the store's ref or handle
|
|
3151
|
+
* @param itemId - the cart line id
|
|
3152
|
+
* @param data - the new quantity
|
|
3153
|
+
* @param sessionId - the guest cart session id
|
|
3154
|
+
* @param isAuth - `true` for the signed-in customer's cart, `false` for the guest cart
|
|
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
|
|
3156
|
+
*/
|
|
3063
3157
|
async updateItem(storeRef, itemId, data, sessionId, isAuth) {
|
|
3064
|
-
const res = await this.client(isAuth).put(
|
|
3158
|
+
const res = await this.client(isAuth).put(`${this.cartPath(isAuth, storeRef)}/items/${itemId}`, data, {
|
|
3065
3159
|
headers: { "x-session-id": sessionId }
|
|
3066
3160
|
});
|
|
3067
3161
|
return unwrap(res);
|
|
3068
3162
|
}
|
|
3163
|
+
/**
|
|
3164
|
+
* Removes a line from the cart.
|
|
3165
|
+
*
|
|
3166
|
+
* @param storeRef - the store's ref or handle
|
|
3167
|
+
* @param itemId - the cart line id
|
|
3168
|
+
* @param sessionId - the guest cart session id
|
|
3169
|
+
* @param isAuth - `true` for the signed-in customer's cart, `false` for the guest cart
|
|
3170
|
+
* @returns The cart id and the removed line's id; throws {@link ApiClientError} when the API answers with an error
|
|
3171
|
+
*/
|
|
3069
3172
|
async removeItem(storeRef, itemId, sessionId, isAuth) {
|
|
3070
|
-
const res = await this.client(isAuth).delete(
|
|
3173
|
+
const res = await this.client(isAuth).delete(`${this.cartPath(isAuth, storeRef)}/items/${itemId}`, {
|
|
3071
3174
|
headers: { "x-session-id": sessionId }
|
|
3072
3175
|
});
|
|
3073
3176
|
return unwrap(res);
|
|
3074
3177
|
}
|
|
3178
|
+
/**
|
|
3179
|
+
* Empties the cart.
|
|
3180
|
+
*
|
|
3181
|
+
* @param storeRef - the store's ref or handle
|
|
3182
|
+
* @param sessionId - the guest cart session id
|
|
3183
|
+
* @param isAuth - `true` for the signed-in customer's cart, `false` for the guest cart
|
|
3184
|
+
* @returns The cart id; throws {@link ApiClientError} when the API answers with an error
|
|
3185
|
+
*/
|
|
3075
3186
|
async clear(storeRef, sessionId, isAuth) {
|
|
3076
3187
|
const res = await this.client(isAuth).delete(
|
|
3077
|
-
|
|
3188
|
+
this.cartPath(isAuth, storeRef),
|
|
3078
3189
|
{ headers: { "x-session-id": sessionId } }
|
|
3079
3190
|
);
|
|
3080
3191
|
return unwrap(res);
|
|
@@ -3084,8 +3195,8 @@ var CartApi = class {
|
|
|
3084
3195
|
* `{ merged: false }` when neither cart exists.
|
|
3085
3196
|
*/
|
|
3086
3197
|
async merge(storeRef, sessionId) {
|
|
3087
|
-
const res = await this.
|
|
3088
|
-
`/stores/${storeRef}/cart/merge`,
|
|
3198
|
+
const res = await this.shopperHttp.post(
|
|
3199
|
+
`/storefront/stores/${storeRef}/customers/cart/merge`,
|
|
3089
3200
|
{},
|
|
3090
3201
|
{ headers: { "x-session-id": sessionId } }
|
|
3091
3202
|
);
|
|
@@ -3095,9 +3206,9 @@ var CartApi = class {
|
|
|
3095
3206
|
|
|
3096
3207
|
// src/modules/orders/api.ts
|
|
3097
3208
|
var OrdersApi = class {
|
|
3098
|
-
constructor(
|
|
3099
|
-
this.
|
|
3100
|
-
this.
|
|
3209
|
+
constructor(privateHttp, shopperHttp) {
|
|
3210
|
+
this.privateHttp = privateHttp;
|
|
3211
|
+
this.shopperHttp = shopperHttp;
|
|
3101
3212
|
}
|
|
3102
3213
|
/**
|
|
3103
3214
|
* Look up a guest order. The API answers with the bare order when it
|
|
@@ -3111,27 +3222,42 @@ var OrdersApi = class {
|
|
|
3111
3222
|
customer_email: params.customer_email,
|
|
3112
3223
|
customer_phone: params.customer_phone
|
|
3113
3224
|
});
|
|
3114
|
-
const res = await this.
|
|
3115
|
-
`/
|
|
3225
|
+
const res = await this.privateHttp.get(
|
|
3226
|
+
`/storefront/stores/${storeRef}/orders/lookup?${query}`
|
|
3116
3227
|
);
|
|
3117
3228
|
const data = unwrapOrNull(res);
|
|
3118
3229
|
if (!data || !("id" in data) || data.id == null) return null;
|
|
3119
3230
|
return data;
|
|
3120
3231
|
}
|
|
3232
|
+
/**
|
|
3233
|
+
* Places an order.
|
|
3234
|
+
*
|
|
3235
|
+
* @param storeRef - the store's ref or handle
|
|
3236
|
+
* @param data - the order details
|
|
3237
|
+
* @param isAuth - `true` to place it as the signed-in customer, `false` as a guest
|
|
3238
|
+
* @returns The created order with its items; throws {@link ApiClientError} when the API answers with an error
|
|
3239
|
+
*/
|
|
3121
3240
|
async create(storeRef, data, isAuth) {
|
|
3122
3241
|
if (isAuth) {
|
|
3123
|
-
const res2 = await this.
|
|
3124
|
-
`/
|
|
3242
|
+
const res2 = await this.shopperHttp.post(
|
|
3243
|
+
`/storefront/stores/${storeRef}/customers/orders`,
|
|
3125
3244
|
data
|
|
3126
3245
|
);
|
|
3127
3246
|
return unwrap(res2);
|
|
3128
3247
|
}
|
|
3129
|
-
const res = await this.
|
|
3130
|
-
`/
|
|
3248
|
+
const res = await this.privateHttp.post(
|
|
3249
|
+
`/storefront/stores/${storeRef}/orders`,
|
|
3131
3250
|
data
|
|
3132
3251
|
);
|
|
3133
3252
|
return unwrap(res);
|
|
3134
3253
|
}
|
|
3254
|
+
/**
|
|
3255
|
+
* Lists the signed-in customer's orders, newest first by default.
|
|
3256
|
+
*
|
|
3257
|
+
* @param storeRef - the store's ref or handle
|
|
3258
|
+
* @param params - search, status filter, sorting and paging (`page`, or `limit` and `offset`)
|
|
3259
|
+
* @returns A page of orders; throws {@link ApiClientError} when the API answers with an error
|
|
3260
|
+
*/
|
|
3135
3261
|
async listCustomerOrders(storeRef, params = {}) {
|
|
3136
3262
|
const limit = params.limit ?? 10;
|
|
3137
3263
|
const page = params.page ?? (params.offset ? Math.floor(params.offset / limit) + 1 : 1);
|
|
@@ -3145,8 +3271,8 @@ var OrdersApi = class {
|
|
|
3145
3271
|
sort_by: params.sort_by ?? "created_at",
|
|
3146
3272
|
sort_order: params.sort_order ?? "desc"
|
|
3147
3273
|
});
|
|
3148
|
-
const res = await this.
|
|
3149
|
-
`/
|
|
3274
|
+
const res = await this.shopperHttp.get(
|
|
3275
|
+
`/storefront/stores/${storeRef}/customers/orders${query ? `?${query}` : ""}`
|
|
3150
3276
|
);
|
|
3151
3277
|
return unwrap(res);
|
|
3152
3278
|
}
|
|
@@ -3155,8 +3281,8 @@ var OrdersApi = class {
|
|
|
3155
3281
|
* verifies ownership and returns 404 — not 403 — for someone else's order.
|
|
3156
3282
|
*/
|
|
3157
3283
|
async getCustomerOrder(storeRef, orderId) {
|
|
3158
|
-
const res = await this.
|
|
3159
|
-
`/
|
|
3284
|
+
const res = await this.shopperHttp.get(
|
|
3285
|
+
`/storefront/stores/${storeRef}/customers/orders/${orderId}`
|
|
3160
3286
|
);
|
|
3161
3287
|
return unwrap(res);
|
|
3162
3288
|
}
|
|
@@ -3165,8 +3291,8 @@ var OrdersApi = class {
|
|
|
3165
3291
|
* processing; the API rejects anything else with ORDER_NOT_CANCELLABLE.
|
|
3166
3292
|
*/
|
|
3167
3293
|
async cancelCustomerOrder(storeRef, orderId) {
|
|
3168
|
-
const res = await this.
|
|
3169
|
-
`/
|
|
3294
|
+
const res = await this.shopperHttp.delete(
|
|
3295
|
+
`/storefront/stores/${storeRef}/customers/orders/${orderId}`
|
|
3170
3296
|
);
|
|
3171
3297
|
return unwrap(res);
|
|
3172
3298
|
}
|
|
@@ -3178,13 +3304,28 @@ var BlogApi = class {
|
|
|
3178
3304
|
this.publicHttp = publicHttp;
|
|
3179
3305
|
this.authHttp = authHttp;
|
|
3180
3306
|
}
|
|
3307
|
+
/**
|
|
3308
|
+
* Lists published blog posts.
|
|
3309
|
+
*
|
|
3310
|
+
* @param storeRef - the store's ref or handle
|
|
3311
|
+
* @param query - filters, sorting and paging
|
|
3312
|
+
* @returns A page of posts; throws {@link ApiClientError} when the API answers with an error
|
|
3313
|
+
*/
|
|
3181
3314
|
async getPosts(storeRef, query = {}) {
|
|
3182
3315
|
const qsStr = stringify(query);
|
|
3183
3316
|
const res = await this.publicHttp.get(
|
|
3184
|
-
`/
|
|
3317
|
+
`/storefront/stores/${storeRef}/blog/posts${qsStr ? "?" + qsStr : ""}`
|
|
3185
3318
|
);
|
|
3186
3319
|
return unwrap(res);
|
|
3187
3320
|
}
|
|
3321
|
+
/**
|
|
3322
|
+
* Gets one published blog post by its slug.
|
|
3323
|
+
*
|
|
3324
|
+
* @param storeRef - the store's ref or handle
|
|
3325
|
+
* @param slug - the post slug
|
|
3326
|
+
* @param options - `incrementView` counts a view; `include_seo_metadata` and `include_products` add those fields
|
|
3327
|
+
* @returns The post, or `null` when it is not found; throws {@link ApiClientError} on any other API error
|
|
3328
|
+
*/
|
|
3188
3329
|
async getPostBySlug(storeRef, slug, options = {}) {
|
|
3189
3330
|
const query = stringify({
|
|
3190
3331
|
increment_view: options.incrementView,
|
|
@@ -3192,39 +3333,77 @@ var BlogApi = class {
|
|
|
3192
3333
|
include_products: options.include_products
|
|
3193
3334
|
});
|
|
3194
3335
|
const res = await this.publicHttp.get(
|
|
3195
|
-
`/
|
|
3336
|
+
`/storefront/stores/${storeRef}/blog/posts/slug/${encodeURIComponent(slug)}${query ? `?${query}` : ""}`
|
|
3196
3337
|
);
|
|
3197
3338
|
return unwrapOrNull(res);
|
|
3198
3339
|
}
|
|
3340
|
+
/**
|
|
3341
|
+
* Lists blog categories.
|
|
3342
|
+
*
|
|
3343
|
+
* @param storeRef - the store's ref or handle
|
|
3344
|
+
* @param query - filters and paging
|
|
3345
|
+
* @returns A page of categories; throws {@link ApiClientError} when the API answers with an error
|
|
3346
|
+
*/
|
|
3199
3347
|
async getCategories(storeRef, query = {}) {
|
|
3200
3348
|
const qsStr = stringify(query);
|
|
3201
3349
|
const res = await this.publicHttp.get(
|
|
3202
|
-
`/
|
|
3350
|
+
`/storefront/stores/${storeRef}/blog/categories${qsStr ? "?" + qsStr : ""}`
|
|
3203
3351
|
);
|
|
3204
3352
|
return unwrap(res);
|
|
3205
3353
|
}
|
|
3354
|
+
/**
|
|
3355
|
+
* Lists blog tags.
|
|
3356
|
+
*
|
|
3357
|
+
* @param storeRef - the store's ref or handle
|
|
3358
|
+
* @param query - filters and paging
|
|
3359
|
+
* @returns A page of tags; throws {@link ApiClientError} when the API answers with an error
|
|
3360
|
+
*/
|
|
3206
3361
|
async getTags(storeRef, query = {}) {
|
|
3207
3362
|
const qsStr = stringify(query);
|
|
3208
3363
|
const res = await this.publicHttp.get(
|
|
3209
|
-
`/
|
|
3364
|
+
`/storefront/stores/${storeRef}/blog/tags${qsStr ? "?" + qsStr : ""}`
|
|
3210
3365
|
);
|
|
3211
3366
|
return unwrap(res);
|
|
3212
3367
|
}
|
|
3368
|
+
/**
|
|
3369
|
+
* Lists the approved comments of a post, as an anonymous visitor.
|
|
3370
|
+
*
|
|
3371
|
+
* @param storeRef - the store's ref or handle
|
|
3372
|
+
* @param postId - the post id
|
|
3373
|
+
* @returns The comments; throws {@link ApiClientError} when the API answers with an error
|
|
3374
|
+
*/
|
|
3213
3375
|
async getPostComments(storeRef, postId) {
|
|
3214
3376
|
const res = await this.publicHttp.get(
|
|
3215
|
-
`/
|
|
3377
|
+
`/storefront/stores/${storeRef}/blog/posts/${postId}/comments`
|
|
3216
3378
|
);
|
|
3217
3379
|
return unwrap(res);
|
|
3218
3380
|
}
|
|
3381
|
+
/**
|
|
3382
|
+
* Lists the approved comments of a post, sending the signed-in customer's credentials.
|
|
3383
|
+
*
|
|
3384
|
+
* @param storeRef - the store's ref or handle
|
|
3385
|
+
* @param postId - the post id
|
|
3386
|
+
* @returns The comments; throws {@link ApiClientError} when the API answers with an error
|
|
3387
|
+
*/
|
|
3219
3388
|
async getPostCommentsAuth(storeRef, postId) {
|
|
3220
3389
|
const res = await this.authHttp.get(
|
|
3221
|
-
`/
|
|
3390
|
+
`/storefront/stores/${storeRef}/blog/posts/${postId}/comments`
|
|
3222
3391
|
);
|
|
3223
3392
|
return unwrap(res);
|
|
3224
3393
|
}
|
|
3394
|
+
};
|
|
3395
|
+
var BlogServerApi = class extends BlogApi {
|
|
3396
|
+
/**
|
|
3397
|
+
* Submits a comment on a post, as the signed-in customer. It may wait for moderation.
|
|
3398
|
+
*
|
|
3399
|
+
* @param storeRef - the store's ref or handle
|
|
3400
|
+
* @param postId - the post id
|
|
3401
|
+
* @param data - the author name, the text, and optionally a website and the parent comment id
|
|
3402
|
+
* @returns The created comment; throws {@link ApiClientError} when the API answers with an error
|
|
3403
|
+
*/
|
|
3225
3404
|
async submitComment(storeRef, postId, data) {
|
|
3226
3405
|
const res = await this.authHttp.post(
|
|
3227
|
-
`/
|
|
3406
|
+
`/storefront/stores/${storeRef}/blog/posts/${postId}/comments`,
|
|
3228
3407
|
data
|
|
3229
3408
|
);
|
|
3230
3409
|
return unwrap(res);
|
|
@@ -3236,6 +3415,14 @@ var StoresApi = class {
|
|
|
3236
3415
|
constructor(http) {
|
|
3237
3416
|
this.http = http;
|
|
3238
3417
|
}
|
|
3418
|
+
/**
|
|
3419
|
+
* Gets a store's public information, by default with its configuration, settings and embedded scripts.
|
|
3420
|
+
*
|
|
3421
|
+
* @param storeRef - the store's ref or handle
|
|
3422
|
+
* @param options - set `includeConfig`, `includeSettings` or `includeEmbeddedScripts` to `false` to leave that part out
|
|
3423
|
+
* @param requestOptions - extra request options, passed to the HTTP client only when given
|
|
3424
|
+
* @returns The store information, or `null` when it is not found; throws {@link ApiClientError} on any other API error
|
|
3425
|
+
*/
|
|
3239
3426
|
async getById(storeRef, options, requestOptions) {
|
|
3240
3427
|
const params = new URLSearchParams();
|
|
3241
3428
|
if (options?.includeConfig ?? true) params.set("include_config", "1");
|
|
@@ -3243,13 +3430,19 @@ var StoresApi = class {
|
|
|
3243
3430
|
if (options?.includeEmbeddedScripts ?? true)
|
|
3244
3431
|
params.set("include_embedded_scripts", "1");
|
|
3245
3432
|
const qs = params.toString();
|
|
3246
|
-
const url = `/
|
|
3433
|
+
const url = `/storefront/stores/${storeRef}${qs ? `?${qs}` : ""}`;
|
|
3247
3434
|
const res = requestOptions ? await this.http.get(url, requestOptions) : await this.http.get(url);
|
|
3248
3435
|
return unwrapOrNull(res);
|
|
3249
3436
|
}
|
|
3437
|
+
/**
|
|
3438
|
+
* Gets a store by its subdomain.
|
|
3439
|
+
*
|
|
3440
|
+
* @param subdomain - the store's subdomain
|
|
3441
|
+
* @returns The store, or `null` when it is not found; throws {@link ApiClientError} on any other API error
|
|
3442
|
+
*/
|
|
3250
3443
|
async getBySubdomain(subdomain) {
|
|
3251
3444
|
const res = await this.http.get(
|
|
3252
|
-
`/
|
|
3445
|
+
`/storefront/stores/exists/subdomain/${subdomain}`
|
|
3253
3446
|
);
|
|
3254
3447
|
return unwrapOrNull(res);
|
|
3255
3448
|
}
|
|
@@ -3258,7 +3451,7 @@ var StoresApi = class {
|
|
|
3258
3451
|
* which opens a coming soon store) is passed to the client only when given.
|
|
3259
3452
|
*/
|
|
3260
3453
|
async getByDomain(domain, options) {
|
|
3261
|
-
const url = `/
|
|
3454
|
+
const url = `/storefront/stores/domain/${domain}`;
|
|
3262
3455
|
const res = options ? await this.http.get(url, options) : await this.http.get(url);
|
|
3263
3456
|
return unwrapOrNull(res);
|
|
3264
3457
|
}
|
|
@@ -3273,14 +3466,14 @@ var ThemesApi = class {
|
|
|
3273
3466
|
/** The store theme a dashboard preview link points to; null if refused. */
|
|
3274
3467
|
async getPreview(storeRef, token) {
|
|
3275
3468
|
const res = await this.http.get(
|
|
3276
|
-
`/
|
|
3469
|
+
`/storefront/stores/${storeRef}/theme-preview?token=${encodeURIComponent(token)}`
|
|
3277
3470
|
);
|
|
3278
3471
|
return unwrapOrNull(res, NO_PREVIEW);
|
|
3279
3472
|
}
|
|
3280
3473
|
/** The theme on a preview host, p-<slug>, with its saved values. */
|
|
3281
3474
|
async getPreviewBySlug(storeRef, slug) {
|
|
3282
3475
|
const res = await this.http.get(
|
|
3283
|
-
`/
|
|
3476
|
+
`/storefront/stores/${storeRef}/theme-preview?slug=${encodeURIComponent(slug)}`
|
|
3284
3477
|
);
|
|
3285
3478
|
return unwrapOrNull(res, NO_PREVIEW);
|
|
3286
3479
|
}
|
|
@@ -3308,7 +3501,7 @@ var MetaobjectsApi = class {
|
|
|
3308
3501
|
const search = query.toString();
|
|
3309
3502
|
const http = params.as_customer ? this.authHttp : this.publicHttp;
|
|
3310
3503
|
const res = await http.get(
|
|
3311
|
-
`/
|
|
3504
|
+
`/storefront/stores/${storeRef}/metaobjects/${encodeURIComponent(type)}${search ? `?${search}` : ""}`
|
|
3312
3505
|
);
|
|
3313
3506
|
return unwrapOrNull(res, [404]) ?? EMPTY;
|
|
3314
3507
|
}
|
|
@@ -3316,7 +3509,7 @@ var MetaobjectsApi = class {
|
|
|
3316
3509
|
async get(storeRef, type, handle, options = {}) {
|
|
3317
3510
|
const http = options.as_customer ? this.authHttp : this.publicHttp;
|
|
3318
3511
|
const res = await http.get(
|
|
3319
|
-
`/
|
|
3512
|
+
`/storefront/stores/${storeRef}/metaobjects/${encodeURIComponent(type)}/${encodeURIComponent(handle)}`
|
|
3320
3513
|
);
|
|
3321
3514
|
return unwrapOrNull(res, [404]);
|
|
3322
3515
|
}
|
|
@@ -3327,24 +3520,45 @@ var SearchApi = class {
|
|
|
3327
3520
|
constructor(http) {
|
|
3328
3521
|
this.http = http;
|
|
3329
3522
|
}
|
|
3523
|
+
/**
|
|
3524
|
+
* Searches products.
|
|
3525
|
+
*
|
|
3526
|
+
* @param storeRef - the store's ref or handle
|
|
3527
|
+
* @param params - the query, filters and paging
|
|
3528
|
+
* @returns The matching products; throws {@link ApiClientError} when the API answers with an error
|
|
3529
|
+
*/
|
|
3330
3530
|
async searchCatalog(storeRef, params) {
|
|
3331
3531
|
const queryString = stringify(params);
|
|
3332
3532
|
const res = await this.http.get(
|
|
3333
|
-
`/
|
|
3533
|
+
`/storefront/stores/${storeRef}/search/catalog${queryString ? "?" + queryString : ""}`
|
|
3334
3534
|
);
|
|
3335
3535
|
return unwrap(res);
|
|
3336
3536
|
}
|
|
3537
|
+
/**
|
|
3538
|
+
* Suggests product matches while the shopper is typing.
|
|
3539
|
+
*
|
|
3540
|
+
* @param storeRef - the store's ref or handle
|
|
3541
|
+
* @param params - the partial query and the suggestion limit
|
|
3542
|
+
* @returns The suggestions; throws {@link ApiClientError} when the API answers with an error
|
|
3543
|
+
*/
|
|
3337
3544
|
async autocompleteCatalog(storeRef, params) {
|
|
3338
3545
|
const queryString = stringify(params);
|
|
3339
3546
|
const res = await this.http.get(
|
|
3340
|
-
`/
|
|
3547
|
+
`/storefront/stores/${storeRef}/search/catalog/autocomplete${queryString ? "?" + queryString : ""}`
|
|
3341
3548
|
);
|
|
3342
3549
|
return unwrap(res);
|
|
3343
3550
|
}
|
|
3551
|
+
/**
|
|
3552
|
+
* Searches published blog posts.
|
|
3553
|
+
*
|
|
3554
|
+
* @param storeRef - the store's ref or handle
|
|
3555
|
+
* @param params - the query and paging
|
|
3556
|
+
* @returns The matching posts; throws {@link ApiClientError} when the API answers with an error
|
|
3557
|
+
*/
|
|
3344
3558
|
async searchBlog(storeRef, params) {
|
|
3345
3559
|
const queryString = stringify(params);
|
|
3346
3560
|
const res = await this.http.get(
|
|
3347
|
-
`/
|
|
3561
|
+
`/storefront/stores/${storeRef}/search/blog${queryString ? "?" + queryString : ""}`
|
|
3348
3562
|
);
|
|
3349
3563
|
return unwrap(res);
|
|
3350
3564
|
}
|
|
@@ -3352,8 +3566,8 @@ var SearchApi = class {
|
|
|
3352
3566
|
|
|
3353
3567
|
// src/modules/shipping/api.ts
|
|
3354
3568
|
var ShippingApi = class {
|
|
3355
|
-
constructor(
|
|
3356
|
-
this.
|
|
3569
|
+
constructor(publicHttp) {
|
|
3570
|
+
this.publicHttp = publicHttp;
|
|
3357
3571
|
}
|
|
3358
3572
|
/**
|
|
3359
3573
|
* List administrative areas. Pass `level` for one tier or `parent_code`
|
|
@@ -3365,14 +3579,27 @@ var ShippingApi = class {
|
|
|
3365
3579
|
if (query.level !== void 0) params.set("level", String(query.level));
|
|
3366
3580
|
if (query.parent_code) params.set("parent_code", query.parent_code);
|
|
3367
3581
|
const qs = params.toString();
|
|
3368
|
-
const res = await this.
|
|
3369
|
-
`/
|
|
3582
|
+
const res = await this.publicHttp.get(
|
|
3583
|
+
`/storefront/stores/${storeRef}/shipping/locations${qs ? `?${qs}` : ""}`
|
|
3370
3584
|
);
|
|
3371
3585
|
return unwrap(res);
|
|
3372
3586
|
}
|
|
3587
|
+
};
|
|
3588
|
+
var ShippingServerApi = class extends ShippingApi {
|
|
3589
|
+
constructor(publicHttp, privateHttp) {
|
|
3590
|
+
super(publicHttp);
|
|
3591
|
+
this.privateHttp = privateHttp;
|
|
3592
|
+
}
|
|
3593
|
+
/**
|
|
3594
|
+
* Works out the shipping options and prices for a cart and a destination.
|
|
3595
|
+
*
|
|
3596
|
+
* @param storeRef - the store's ref or handle
|
|
3597
|
+
* @param data - the destination and the cart contents
|
|
3598
|
+
* @returns The available shipping options; throws {@link ApiClientError} when the API answers with an error
|
|
3599
|
+
*/
|
|
3373
3600
|
async calculate(storeRef, data) {
|
|
3374
|
-
const res = await this.
|
|
3375
|
-
`/
|
|
3601
|
+
const res = await this.privateHttp.post(
|
|
3602
|
+
`/storefront/stores/${storeRef}/shipping/calculate`,
|
|
3376
3603
|
data
|
|
3377
3604
|
);
|
|
3378
3605
|
return unwrap(res);
|
|
@@ -3381,21 +3608,41 @@ var ShippingApi = class {
|
|
|
3381
3608
|
|
|
3382
3609
|
// src/modules/promotions/api.ts
|
|
3383
3610
|
var PromotionsApi = class {
|
|
3384
|
-
constructor(
|
|
3385
|
-
this.
|
|
3386
|
-
}
|
|
3387
|
-
async validate(storeRef, data) {
|
|
3388
|
-
const res = await this.http.post(
|
|
3389
|
-
`/public/stores/${storeRef}/promotions/validate`,
|
|
3390
|
-
data
|
|
3391
|
-
);
|
|
3392
|
-
return unwrap(res);
|
|
3611
|
+
constructor(publicHttp) {
|
|
3612
|
+
this.publicHttp = publicHttp;
|
|
3393
3613
|
}
|
|
3614
|
+
/**
|
|
3615
|
+
* Lists promotions the shopper could use, optionally for a given cart subtotal.
|
|
3616
|
+
*
|
|
3617
|
+
* @param storeRef - the store's ref or handle
|
|
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
|
|
3620
|
+
*/
|
|
3394
3621
|
async getSuggestions(storeRef, subtotal) {
|
|
3395
3622
|
const params = new URLSearchParams();
|
|
3396
3623
|
if (subtotal !== void 0) params.append("subtotal", subtotal.toString());
|
|
3397
|
-
const res = await this.
|
|
3398
|
-
`/
|
|
3624
|
+
const res = await this.publicHttp.get(
|
|
3625
|
+
`/storefront/stores/${storeRef}/promotions/suggestions?${params.toString()}`
|
|
3626
|
+
);
|
|
3627
|
+
return unwrap(res);
|
|
3628
|
+
}
|
|
3629
|
+
};
|
|
3630
|
+
var PromotionsServerApi = class extends PromotionsApi {
|
|
3631
|
+
constructor(publicHttp, privateHttp) {
|
|
3632
|
+
super(publicHttp);
|
|
3633
|
+
this.privateHttp = privateHttp;
|
|
3634
|
+
}
|
|
3635
|
+
/**
|
|
3636
|
+
* Checks a promotion code against a cart.
|
|
3637
|
+
*
|
|
3638
|
+
* @param storeRef - the store's ref or handle
|
|
3639
|
+
* @param data - the code and the cart details
|
|
3640
|
+
* @returns The validation result; throws {@link ApiClientError} when the API answers with an error
|
|
3641
|
+
*/
|
|
3642
|
+
async validate(storeRef, data) {
|
|
3643
|
+
const res = await this.privateHttp.post(
|
|
3644
|
+
`/storefront/stores/${storeRef}/promotions/validate`,
|
|
3645
|
+
data
|
|
3399
3646
|
);
|
|
3400
3647
|
return unwrap(res);
|
|
3401
3648
|
}
|
|
@@ -3406,9 +3653,15 @@ var PaymentMethodsApi = class {
|
|
|
3406
3653
|
constructor(http) {
|
|
3407
3654
|
this.http = http;
|
|
3408
3655
|
}
|
|
3656
|
+
/**
|
|
3657
|
+
* Lists the payment methods the store has turned on.
|
|
3658
|
+
*
|
|
3659
|
+
* @param storeRef - the store's ref or handle
|
|
3660
|
+
* @returns The enabled payment methods; throws {@link ApiClientError} when the API answers with an error
|
|
3661
|
+
*/
|
|
3409
3662
|
async getEnabled(storeRef) {
|
|
3410
3663
|
const res = await this.http.get(
|
|
3411
|
-
`/
|
|
3664
|
+
`/storefront/stores/${storeRef}/payment-methods`
|
|
3412
3665
|
);
|
|
3413
3666
|
return unwrap(res);
|
|
3414
3667
|
}
|
|
@@ -3416,9 +3669,8 @@ var PaymentMethodsApi = class {
|
|
|
3416
3669
|
|
|
3417
3670
|
// src/modules/payments/api.ts
|
|
3418
3671
|
var PaymentsApi = class {
|
|
3419
|
-
constructor(
|
|
3420
|
-
this.
|
|
3421
|
-
this.authHttp = authHttp;
|
|
3672
|
+
constructor(privateHttp) {
|
|
3673
|
+
this.privateHttp = privateHttp;
|
|
3422
3674
|
}
|
|
3423
3675
|
/**
|
|
3424
3676
|
* Start a gateway charge attempt for an order. Keyed by `order_code`,
|
|
@@ -3428,8 +3680,8 @@ var PaymentsApi = class {
|
|
|
3428
3680
|
* store's orders.
|
|
3429
3681
|
*/
|
|
3430
3682
|
async initiate(storeRef, input) {
|
|
3431
|
-
const res = await this.
|
|
3432
|
-
`/
|
|
3683
|
+
const res = await this.privateHttp.post(
|
|
3684
|
+
`/storefront/stores/${encodeURIComponent(storeRef)}/payments/initiate`,
|
|
3433
3685
|
{ order_code: input.order_code, provider_code: input.provider_code }
|
|
3434
3686
|
);
|
|
3435
3687
|
return unwrap(res);
|
|
@@ -3440,8 +3692,8 @@ var PaymentsApi = class {
|
|
|
3440
3692
|
* `#` by default in this system, and an unencoded `#` truncates the URL.
|
|
3441
3693
|
*/
|
|
3442
3694
|
async getPaymentState(storeRef, order_code) {
|
|
3443
|
-
const res = await this.
|
|
3444
|
-
`/
|
|
3695
|
+
const res = await this.privateHttp.get(
|
|
3696
|
+
`/storefront/stores/${encodeURIComponent(storeRef)}/orders/${encodeURIComponent(order_code)}/payment-state`
|
|
3445
3697
|
);
|
|
3446
3698
|
return unwrap(res);
|
|
3447
3699
|
}
|
|
@@ -3449,39 +3701,84 @@ var PaymentsApi = class {
|
|
|
3449
3701
|
|
|
3450
3702
|
// src/modules/reviews/api.ts
|
|
3451
3703
|
var ReviewsApi = class {
|
|
3452
|
-
constructor(
|
|
3453
|
-
this.
|
|
3704
|
+
constructor(publicHttp) {
|
|
3705
|
+
this.publicHttp = publicHttp;
|
|
3454
3706
|
}
|
|
3707
|
+
/**
|
|
3708
|
+
* Lists the published reviews of a product.
|
|
3709
|
+
*
|
|
3710
|
+
* @param storeRef - the store's ref or handle
|
|
3711
|
+
* @param productId - the product id
|
|
3712
|
+
* @param query - filters and paging
|
|
3713
|
+
* @returns A page of reviews; throws {@link ApiClientError} when the API answers with an error
|
|
3714
|
+
*/
|
|
3455
3715
|
async getProductReviews(storeRef, productId, query) {
|
|
3456
3716
|
const queryString = stringify(query ?? {});
|
|
3457
|
-
const res = await this.
|
|
3458
|
-
|
|
3717
|
+
const res = await this.publicHttp.get(
|
|
3718
|
+
`/storefront/stores/${storeRef}/products/${productId}/reviews${queryString ? `?${queryString}` : ""}`
|
|
3459
3719
|
);
|
|
3460
3720
|
return unwrap(res);
|
|
3461
3721
|
}
|
|
3722
|
+
};
|
|
3723
|
+
var ReviewsServerApi = class extends ReviewsApi {
|
|
3724
|
+
constructor(publicHttp, privateHttp) {
|
|
3725
|
+
super(publicHttp);
|
|
3726
|
+
this.privateHttp = privateHttp;
|
|
3727
|
+
}
|
|
3728
|
+
/**
|
|
3729
|
+
* Gets the public details behind a review invitation link.
|
|
3730
|
+
*
|
|
3731
|
+
* @param storeRef - the store's ref or handle
|
|
3732
|
+
* @param token - the token from the invitation link
|
|
3733
|
+
* @returns The invitation details; throws {@link ApiClientError} when the API answers with an error
|
|
3734
|
+
*/
|
|
3462
3735
|
async getReviewInvitation(storeRef, token) {
|
|
3463
|
-
const res = await this.
|
|
3464
|
-
|
|
3736
|
+
const res = await this.privateHttp.get(
|
|
3737
|
+
`/storefront/stores/${storeRef}/review-invitations/${token}`
|
|
3465
3738
|
);
|
|
3466
3739
|
return unwrap(res);
|
|
3467
3740
|
}
|
|
3741
|
+
/**
|
|
3742
|
+
* Lists the review invitations for one order.
|
|
3743
|
+
*
|
|
3744
|
+
* @param storeRef - the store's ref or handle
|
|
3745
|
+
* @param orderNumber - the order number
|
|
3746
|
+
* @param email - the email address on the order
|
|
3747
|
+
* @returns The invitation summaries; throws {@link ApiClientError} when the API answers with an error
|
|
3748
|
+
*/
|
|
3468
3749
|
async getOrderReviewInvitations(storeRef, orderNumber, email) {
|
|
3469
3750
|
const queryString = stringify({ order_number: orderNumber, email });
|
|
3470
|
-
const res = await this.
|
|
3471
|
-
|
|
3751
|
+
const res = await this.privateHttp.get(
|
|
3752
|
+
`/storefront/stores/${storeRef}/review-invitations/by-order?${queryString}`
|
|
3472
3753
|
);
|
|
3473
3754
|
return unwrap(res);
|
|
3474
3755
|
}
|
|
3756
|
+
/**
|
|
3757
|
+
* Lists the review invitations for several orders at once.
|
|
3758
|
+
*
|
|
3759
|
+
* @param storeRef - the store's ref or handle
|
|
3760
|
+
* @param orderNumbers - the order numbers
|
|
3761
|
+
* @param email - the email address on the orders
|
|
3762
|
+
* @returns The invitations grouped by order; throws {@link ApiClientError} when the API answers with an error
|
|
3763
|
+
*/
|
|
3475
3764
|
async getBatchOrderReviewInvitations(storeRef, orderNumbers, email) {
|
|
3476
3765
|
const queryString = stringify({ order_numbers: orderNumbers.join(","), email });
|
|
3477
|
-
const res = await this.
|
|
3478
|
-
|
|
3766
|
+
const res = await this.privateHttp.get(
|
|
3767
|
+
`/storefront/stores/${storeRef}/review-invitations/by-orders?${queryString}`
|
|
3479
3768
|
);
|
|
3480
3769
|
return unwrap(res);
|
|
3481
3770
|
}
|
|
3771
|
+
/**
|
|
3772
|
+
* Submits a review through an invitation link.
|
|
3773
|
+
*
|
|
3774
|
+
* @param storeRef - the store's ref or handle
|
|
3775
|
+
* @param token - the token from the invitation link
|
|
3776
|
+
* @param payload - the rating and review text
|
|
3777
|
+
* @returns The API's answer; throws {@link ApiClientError} when the API answers with an error
|
|
3778
|
+
*/
|
|
3482
3779
|
async submitReviewInvitation(storeRef, token, payload) {
|
|
3483
|
-
const res = await this.
|
|
3484
|
-
|
|
3780
|
+
const res = await this.privateHttp.post(
|
|
3781
|
+
`/storefront/stores/${storeRef}/review-invitations/${token}/submit`,
|
|
3485
3782
|
payload
|
|
3486
3783
|
);
|
|
3487
3784
|
return unwrap(res);
|
|
@@ -3493,16 +3790,23 @@ var CustomersApi = class {
|
|
|
3493
3790
|
constructor(http) {
|
|
3494
3791
|
this.http = http;
|
|
3495
3792
|
}
|
|
3793
|
+
/**
|
|
3794
|
+
* Creates the customer record for a newly signed-in user, or updates it when it exists.
|
|
3795
|
+
*
|
|
3796
|
+
* @param storeRef - the store's ref or handle
|
|
3797
|
+
* @param payload - the identity fields to store
|
|
3798
|
+
* @returns The customer, as the raw {@link ApiResponse}; it does not throw, so check `success`
|
|
3799
|
+
*/
|
|
3496
3800
|
async upsertForAuth(storeRef, payload) {
|
|
3497
3801
|
return this.http.post(
|
|
3498
|
-
`/stores/${storeRef}/customers/auth/upsert`,
|
|
3802
|
+
`/storefront/stores/${storeRef}/customers/auth/upsert`,
|
|
3499
3803
|
payload
|
|
3500
3804
|
);
|
|
3501
3805
|
}
|
|
3502
3806
|
/** The signed-in customer's metafields with customer access (spec §6.6). */
|
|
3503
3807
|
async getMetafields(storeRef) {
|
|
3504
3808
|
const res = await this.http.get(
|
|
3505
|
-
`/
|
|
3809
|
+
`/storefront/stores/${storeRef}/customers/metafields`
|
|
3506
3810
|
);
|
|
3507
3811
|
return unwrap(res);
|
|
3508
3812
|
}
|
|
@@ -3512,7 +3816,7 @@ var CustomersApi = class {
|
|
|
3512
3816
|
*/
|
|
3513
3817
|
async updateMetafields(storeRef, values) {
|
|
3514
3818
|
const res = await this.http.put(
|
|
3515
|
-
`/
|
|
3819
|
+
`/storefront/stores/${storeRef}/customers/metafields`,
|
|
3516
3820
|
{ values }
|
|
3517
3821
|
);
|
|
3518
3822
|
return unwrap(res);
|
|
@@ -3524,41 +3828,83 @@ var AddressesApi = class {
|
|
|
3524
3828
|
constructor(http) {
|
|
3525
3829
|
this.http = http;
|
|
3526
3830
|
}
|
|
3831
|
+
/**
|
|
3832
|
+
* Lists the signed-in customer's saved addresses.
|
|
3833
|
+
*
|
|
3834
|
+
* @param storeRef - the store's ref or handle
|
|
3835
|
+
* @returns The addresses, or `null` when it is not found; throws {@link ApiClientError} on any other API error
|
|
3836
|
+
*/
|
|
3527
3837
|
async list(storeRef) {
|
|
3528
3838
|
const res = await this.http.get(
|
|
3529
|
-
`/
|
|
3839
|
+
`/storefront/stores/${storeRef}/customers/address`
|
|
3530
3840
|
);
|
|
3531
3841
|
return unwrapOrNull(res);
|
|
3532
3842
|
}
|
|
3843
|
+
/**
|
|
3844
|
+
* Gets one of the signed-in customer's saved addresses.
|
|
3845
|
+
*
|
|
3846
|
+
* @param storeRef - the store's ref or handle
|
|
3847
|
+
* @param addressId - the address id
|
|
3848
|
+
* @returns The address, or `null` when it is not found; throws {@link ApiClientError} on any other API error
|
|
3849
|
+
*/
|
|
3533
3850
|
async getById(storeRef, addressId) {
|
|
3534
3851
|
const res = await this.http.get(
|
|
3535
|
-
`/
|
|
3852
|
+
`/storefront/stores/${storeRef}/customers/address/${addressId}`
|
|
3536
3853
|
);
|
|
3537
3854
|
return unwrapOrNull(res);
|
|
3538
3855
|
}
|
|
3856
|
+
/**
|
|
3857
|
+
* Saves a new address for the signed-in customer.
|
|
3858
|
+
*
|
|
3859
|
+
* @param storeRef - the store's ref or handle
|
|
3860
|
+
* @param data - the address fields
|
|
3861
|
+
* @returns The created address, or `null` when it is not found; throws {@link ApiClientError} on any other API error
|
|
3862
|
+
*/
|
|
3539
3863
|
async create(storeRef, data) {
|
|
3540
3864
|
const res = await this.http.post(
|
|
3541
|
-
`/
|
|
3865
|
+
`/storefront/stores/${storeRef}/customers/address`,
|
|
3542
3866
|
data
|
|
3543
3867
|
);
|
|
3544
3868
|
return unwrapOrNull(res);
|
|
3545
3869
|
}
|
|
3870
|
+
/**
|
|
3871
|
+
* Updates one of the signed-in customer's saved addresses.
|
|
3872
|
+
*
|
|
3873
|
+
* @param storeRef - the store's ref or handle
|
|
3874
|
+
* @param addressId - the address id
|
|
3875
|
+
* @param data - the fields to change
|
|
3876
|
+
* @returns The updated address, or `null` when it is not found; throws {@link ApiClientError} on any other API error
|
|
3877
|
+
*/
|
|
3546
3878
|
async update(storeRef, addressId, data) {
|
|
3547
3879
|
const res = await this.http.patch(
|
|
3548
|
-
`/
|
|
3880
|
+
`/storefront/stores/${storeRef}/customers/address/${addressId}`,
|
|
3549
3881
|
data
|
|
3550
3882
|
);
|
|
3551
3883
|
return unwrapOrNull(res);
|
|
3552
3884
|
}
|
|
3885
|
+
/**
|
|
3886
|
+
* Deletes one of the signed-in customer's saved addresses.
|
|
3887
|
+
*
|
|
3888
|
+
* @param storeRef - the store's ref or handle
|
|
3889
|
+
* @param addressId - the address id
|
|
3890
|
+
* @returns `true` when the API accepted the deletion, `false` otherwise; it does not throw
|
|
3891
|
+
*/
|
|
3553
3892
|
async delete(storeRef, addressId) {
|
|
3554
3893
|
const res = await this.http.delete(
|
|
3555
|
-
`/
|
|
3894
|
+
`/storefront/stores/${storeRef}/customers/address/${addressId}`
|
|
3556
3895
|
);
|
|
3557
3896
|
return res.success;
|
|
3558
3897
|
}
|
|
3898
|
+
/**
|
|
3899
|
+
* Makes a saved address the customer's default.
|
|
3900
|
+
*
|
|
3901
|
+
* @param storeRef - the store's ref or handle
|
|
3902
|
+
* @param addressId - the address id
|
|
3903
|
+
* @returns The updated address, or `null` when it is not found; throws {@link ApiClientError} on any other API error
|
|
3904
|
+
*/
|
|
3559
3905
|
async setDefault(storeRef, addressId) {
|
|
3560
3906
|
const res = await this.http.patch(
|
|
3561
|
-
`/
|
|
3907
|
+
`/storefront/stores/${storeRef}/customers/address/${addressId}/set-default`
|
|
3562
3908
|
);
|
|
3563
3909
|
return unwrapOrNull(res);
|
|
3564
3910
|
}
|
|
@@ -3569,16 +3915,30 @@ var ContentPagesApi = class {
|
|
|
3569
3915
|
constructor(http) {
|
|
3570
3916
|
this.http = http;
|
|
3571
3917
|
}
|
|
3918
|
+
/**
|
|
3919
|
+
* Lists the published content pages.
|
|
3920
|
+
*
|
|
3921
|
+
* @param storeRef - the store's ref or handle
|
|
3922
|
+
* @returns A page of content pages; throws {@link ApiClientError} when the API answers with an error
|
|
3923
|
+
*/
|
|
3572
3924
|
async getPublished(storeRef) {
|
|
3573
3925
|
const res = await this.http.get(
|
|
3574
|
-
`/
|
|
3926
|
+
`/storefront/stores/${storeRef}/content-pages`
|
|
3575
3927
|
);
|
|
3576
3928
|
return unwrap(res);
|
|
3577
3929
|
}
|
|
3930
|
+
/**
|
|
3931
|
+
* Gets one published content page by slug.
|
|
3932
|
+
*
|
|
3933
|
+
* @param storeRef - the store's ref or handle
|
|
3934
|
+
* @param slug - the page slug
|
|
3935
|
+
* @param query - `include_seo_metadata` adds the SEO fields
|
|
3936
|
+
* @returns The page; throws {@link ApiClientError} when the API answers with an error
|
|
3937
|
+
*/
|
|
3578
3938
|
async getBySlug(storeRef, slug, query) {
|
|
3579
3939
|
const queryString = query ? stringify(query) : "";
|
|
3580
3940
|
const res = await this.http.get(
|
|
3581
|
-
`/
|
|
3941
|
+
`/storefront/stores/${storeRef}/content-pages/${encodeURIComponent(slug)}${queryString ? "?" + queryString : ""}`
|
|
3582
3942
|
);
|
|
3583
3943
|
return unwrap(res);
|
|
3584
3944
|
}
|
|
@@ -3589,10 +3949,18 @@ var MenusApi = class {
|
|
|
3589
3949
|
constructor(http) {
|
|
3590
3950
|
this.http = http;
|
|
3591
3951
|
}
|
|
3952
|
+
/**
|
|
3953
|
+
* Gets a navigation menu by its ref.
|
|
3954
|
+
*
|
|
3955
|
+
* @param storeRef - the store's ref or handle
|
|
3956
|
+
* @param ref - the menu ref
|
|
3957
|
+
* @param includeItems - `true` (the default) includes the menu items
|
|
3958
|
+
* @returns The menu, or `null` when it is not found; throws {@link ApiClientError} on any other API error
|
|
3959
|
+
*/
|
|
3592
3960
|
async getByRef(storeRef, ref, includeItems = true) {
|
|
3593
3961
|
const query = includeItems ? "?include_items=true" : "";
|
|
3594
3962
|
const res = await this.http.get(
|
|
3595
|
-
`/
|
|
3963
|
+
`/storefront/stores/${storeRef}/menus/ref/${encodeURIComponent(ref)}${query}`
|
|
3596
3964
|
);
|
|
3597
3965
|
return unwrapOrNull(res);
|
|
3598
3966
|
}
|
|
@@ -3607,7 +3975,7 @@ var RedirectsApi = class {
|
|
|
3607
3975
|
async lookup(storeRef, path, options) {
|
|
3608
3976
|
const params = new URLSearchParams();
|
|
3609
3977
|
params.set("path", path);
|
|
3610
|
-
const url = `/
|
|
3978
|
+
const url = `/storefront/stores/${storeRef}/url-redirects/lookup?${params.toString()}`;
|
|
3611
3979
|
const res = options ? await this.http.get(url, options) : await this.http.get(url);
|
|
3612
3980
|
const result = unwrapOrNull(res);
|
|
3613
3981
|
return result?.data ?? null;
|
|
@@ -3621,10 +3989,10 @@ var AuthApi = class {
|
|
|
3621
3989
|
this.storeRef = storeRef;
|
|
3622
3990
|
}
|
|
3623
3991
|
publicPath(suffix) {
|
|
3624
|
-
return `/
|
|
3992
|
+
return `/storefront/stores/${encodeURIComponent(this.storeRef)}/auth/${suffix}`;
|
|
3625
3993
|
}
|
|
3626
3994
|
tenantPath(suffix) {
|
|
3627
|
-
return `/
|
|
3995
|
+
return `/storefront/stores/${encodeURIComponent(this.storeRef)}/auth/${suffix}`;
|
|
3628
3996
|
}
|
|
3629
3997
|
auth(access_token) {
|
|
3630
3998
|
return { headers: { Authorization: `Bearer ${access_token}` } };
|
|
@@ -3634,9 +4002,21 @@ var AuthApi = class {
|
|
|
3634
4002
|
async register(payload) {
|
|
3635
4003
|
return this.http.post(this.publicPath("register"), payload, void 0);
|
|
3636
4004
|
}
|
|
4005
|
+
/**
|
|
4006
|
+
* Signs a customer in with email and password.
|
|
4007
|
+
*
|
|
4008
|
+
* @param payload - the login credentials
|
|
4009
|
+
* @returns The auth result with the token pair, as the raw {@link ApiResponse}; it does not throw, so check `success`
|
|
4010
|
+
*/
|
|
3637
4011
|
async login(payload) {
|
|
3638
4012
|
return this.http.post(this.publicPath("login"), payload, void 0);
|
|
3639
4013
|
}
|
|
4014
|
+
/**
|
|
4015
|
+
* Exchanges a refresh token for a new token pair. The old refresh token stops working.
|
|
4016
|
+
*
|
|
4017
|
+
* @param refresh_token - the customer's current refresh token
|
|
4018
|
+
* @returns The new token pair, as the raw {@link ApiResponse}; it does not throw, so check `success`
|
|
4019
|
+
*/
|
|
3640
4020
|
async refresh(refresh_token) {
|
|
3641
4021
|
return this.http.post(
|
|
3642
4022
|
this.publicPath("refresh"),
|
|
@@ -3656,6 +4036,12 @@ var AuthApi = class {
|
|
|
3656
4036
|
void 0
|
|
3657
4037
|
);
|
|
3658
4038
|
}
|
|
4039
|
+
/**
|
|
4040
|
+
* Sends the email-verification message again.
|
|
4041
|
+
*
|
|
4042
|
+
* @param email - the address to verify
|
|
4043
|
+
* @returns The send result, as the raw {@link ApiResponse}; it does not throw, so check `success`
|
|
4044
|
+
*/
|
|
3659
4045
|
async resendVerification(email) {
|
|
3660
4046
|
return this.http.post(
|
|
3661
4047
|
this.publicPath("resend-verification"),
|
|
@@ -3663,6 +4049,12 @@ var AuthApi = class {
|
|
|
3663
4049
|
void 0
|
|
3664
4050
|
);
|
|
3665
4051
|
}
|
|
4052
|
+
/**
|
|
4053
|
+
* Starts a password reset by emailing a reset link.
|
|
4054
|
+
*
|
|
4055
|
+
* @param email - the account's email address
|
|
4056
|
+
* @returns The send result, as the raw {@link ApiResponse}; it does not throw, so check `success`
|
|
4057
|
+
*/
|
|
3666
4058
|
async forgotPassword(email) {
|
|
3667
4059
|
return this.http.post(
|
|
3668
4060
|
this.publicPath("forgot-password"),
|
|
@@ -3670,6 +4062,12 @@ var AuthApi = class {
|
|
|
3670
4062
|
void 0
|
|
3671
4063
|
);
|
|
3672
4064
|
}
|
|
4065
|
+
/**
|
|
4066
|
+
* Sets a new password using the token from the reset email.
|
|
4067
|
+
*
|
|
4068
|
+
* @param payload - the reset token and the new password
|
|
4069
|
+
* @returns The reset result, as the raw {@link ApiResponse}; it does not throw, so check `success`
|
|
4070
|
+
*/
|
|
3673
4071
|
async resetPassword(payload) {
|
|
3674
4072
|
return this.http.post(
|
|
3675
4073
|
this.publicPath("reset-password"),
|
|
@@ -3685,6 +4083,12 @@ var AuthApi = class {
|
|
|
3685
4083
|
void 0
|
|
3686
4084
|
);
|
|
3687
4085
|
}
|
|
4086
|
+
/**
|
|
4087
|
+
* Emails a one-time sign-in code.
|
|
4088
|
+
*
|
|
4089
|
+
* @param email - the account's email address
|
|
4090
|
+
* @returns The send result, as the raw {@link ApiResponse}; it does not throw, so check `success`
|
|
4091
|
+
*/
|
|
3688
4092
|
async requestOtp(email) {
|
|
3689
4093
|
return this.http.post(
|
|
3690
4094
|
this.publicPath("otp/request"),
|
|
@@ -3692,6 +4096,12 @@ var AuthApi = class {
|
|
|
3692
4096
|
void 0
|
|
3693
4097
|
);
|
|
3694
4098
|
}
|
|
4099
|
+
/**
|
|
4100
|
+
* Signs a customer in with the one-time code from the email.
|
|
4101
|
+
*
|
|
4102
|
+
* @param payload - the email and the code
|
|
4103
|
+
* @returns The auth result with the token pair, as the raw {@link ApiResponse}; it does not throw, so check `success`
|
|
4104
|
+
*/
|
|
3695
4105
|
async verifyOtp(payload) {
|
|
3696
4106
|
return this.http.post(
|
|
3697
4107
|
this.publicPath("otp/verify"),
|
|
@@ -3699,9 +4109,20 @@ var AuthApi = class {
|
|
|
3699
4109
|
void 0
|
|
3700
4110
|
);
|
|
3701
4111
|
}
|
|
4112
|
+
/**
|
|
4113
|
+
* Starts an anonymous (guest) session.
|
|
4114
|
+
*
|
|
4115
|
+
* @returns The auth result with the token pair, as the raw {@link ApiResponse}; it does not throw, so check `success`
|
|
4116
|
+
*/
|
|
3702
4117
|
async anonymous() {
|
|
3703
4118
|
return this.http.post(this.publicPath("anonymous"), void 0, void 0);
|
|
3704
4119
|
}
|
|
4120
|
+
/**
|
|
4121
|
+
* Gets the URL that starts Google sign-in.
|
|
4122
|
+
*
|
|
4123
|
+
* @param redirect_to - where to send the customer after sign-in, `/` by default
|
|
4124
|
+
* @returns The Google sign-in URL, as the raw {@link ApiResponse}; it does not throw, so check `success`
|
|
4125
|
+
*/
|
|
3705
4126
|
async getGoogleUrl(redirect_to = "/") {
|
|
3706
4127
|
const query = `?redirect_to=${encodeURIComponent(redirect_to)}`;
|
|
3707
4128
|
return this.http.get(
|
|
@@ -3709,6 +4130,12 @@ var AuthApi = class {
|
|
|
3709
4130
|
void 0
|
|
3710
4131
|
);
|
|
3711
4132
|
}
|
|
4133
|
+
/**
|
|
4134
|
+
* Completes Google sign-in by exchanging the authorization code.
|
|
4135
|
+
*
|
|
4136
|
+
* @param code - the authorization code Google returned
|
|
4137
|
+
* @returns The auth result with the token pair, as the raw {@link ApiResponse}; it does not throw, so check `success`
|
|
4138
|
+
*/
|
|
3712
4139
|
async exchangeGoogleCode(code) {
|
|
3713
4140
|
return this.http.post(
|
|
3714
4141
|
this.publicPath("google/exchange"),
|
|
@@ -3716,10 +4143,21 @@ var AuthApi = class {
|
|
|
3716
4143
|
void 0
|
|
3717
4144
|
);
|
|
3718
4145
|
}
|
|
4146
|
+
/**
|
|
4147
|
+
* Reads which sign-in methods this store has turned on.
|
|
4148
|
+
*
|
|
4149
|
+
* @returns The public auth configuration, as the raw {@link ApiResponse}; it does not throw, so check `success`
|
|
4150
|
+
*/
|
|
3719
4151
|
async getAuthConfig() {
|
|
3720
4152
|
return this.http.get(this.publicPath("config"), void 0);
|
|
3721
4153
|
}
|
|
3722
4154
|
// ---- access token required -------------------------------------------
|
|
4155
|
+
/**
|
|
4156
|
+
* Reads the signed-in customer's identity.
|
|
4157
|
+
*
|
|
4158
|
+
* @param access_token - the signed-in customer's access token
|
|
4159
|
+
* @returns The current identity, as the raw {@link ApiResponse}; it does not throw, so check `success`
|
|
4160
|
+
*/
|
|
3723
4161
|
async me(access_token) {
|
|
3724
4162
|
return this.http.get(
|
|
3725
4163
|
this.tenantPath("me"),
|
|
@@ -3734,6 +4172,12 @@ var AuthApi = class {
|
|
|
3734
4172
|
this.auth(access_token)
|
|
3735
4173
|
);
|
|
3736
4174
|
}
|
|
4175
|
+
/**
|
|
4176
|
+
* Signs the customer out of every session.
|
|
4177
|
+
*
|
|
4178
|
+
* @param access_token - the signed-in customer's access token
|
|
4179
|
+
* @returns The API's answer, as the raw {@link ApiResponse}; it does not throw, so check `success`
|
|
4180
|
+
*/
|
|
3737
4181
|
async logoutAll(access_token) {
|
|
3738
4182
|
return this.http.post(
|
|
3739
4183
|
this.tenantPath("logout-all"),
|
|
@@ -3741,6 +4185,13 @@ var AuthApi = class {
|
|
|
3741
4185
|
this.auth(access_token)
|
|
3742
4186
|
);
|
|
3743
4187
|
}
|
|
4188
|
+
/**
|
|
4189
|
+
* Changes the signed-in customer's password.
|
|
4190
|
+
*
|
|
4191
|
+
* @param access_token - the signed-in customer's access token
|
|
4192
|
+
* @param payload - the current and the new password
|
|
4193
|
+
* @returns The API's answer, as the raw {@link ApiResponse}; it does not throw, so check `success`
|
|
4194
|
+
*/
|
|
3744
4195
|
async changePassword(access_token, payload) {
|
|
3745
4196
|
return this.http.post(
|
|
3746
4197
|
this.tenantPath("change-password"),
|
|
@@ -3748,6 +4199,13 @@ var AuthApi = class {
|
|
|
3748
4199
|
this.auth(access_token)
|
|
3749
4200
|
);
|
|
3750
4201
|
}
|
|
4202
|
+
/**
|
|
4203
|
+
* Starts an email change; the new address must be confirmed from the message sent to it.
|
|
4204
|
+
*
|
|
4205
|
+
* @param access_token - the signed-in customer's access token
|
|
4206
|
+
* @param payload - the new email address and the current password
|
|
4207
|
+
* @returns The change-email result, as the raw {@link ApiResponse}; it does not throw, so check `success`
|
|
4208
|
+
*/
|
|
3751
4209
|
async changeEmail(access_token, payload) {
|
|
3752
4210
|
return this.http.post(
|
|
3753
4211
|
this.tenantPath("change-email"),
|
|
@@ -3762,12 +4220,25 @@ var MemoryTokenStorage = class {
|
|
|
3762
4220
|
constructor(initial = null) {
|
|
3763
4221
|
this.tokens = initial;
|
|
3764
4222
|
}
|
|
4223
|
+
/**
|
|
4224
|
+
* Reads the stored token pair.
|
|
4225
|
+
*
|
|
4226
|
+
* @returns The stored tokens, or `null` when none are stored
|
|
4227
|
+
*/
|
|
3765
4228
|
async get() {
|
|
3766
4229
|
return this.tokens;
|
|
3767
4230
|
}
|
|
4231
|
+
/**
|
|
4232
|
+
* Stores a token pair, replacing any earlier one.
|
|
4233
|
+
*
|
|
4234
|
+
* @param tokens - the access and refresh tokens
|
|
4235
|
+
*/
|
|
3768
4236
|
async set(tokens) {
|
|
3769
4237
|
this.tokens = tokens;
|
|
3770
4238
|
}
|
|
4239
|
+
/**
|
|
4240
|
+
* Forgets the stored token pair.
|
|
4241
|
+
*/
|
|
3771
4242
|
async clear() {
|
|
3772
4243
|
this.tokens = null;
|
|
3773
4244
|
}
|
|
@@ -3970,33 +4441,111 @@ var SHIPPING_ERROR_CODES = {
|
|
|
3970
4441
|
RATE_UNAVAILABLE: "ORDER_SHIPPING_RATE_UNAVAILABLE"
|
|
3971
4442
|
};
|
|
3972
4443
|
|
|
3973
|
-
// src/
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
const
|
|
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
|
+
}) {
|
|
3977
4470
|
return {
|
|
3978
4471
|
products: new ProductsApi(publicHttp),
|
|
3979
4472
|
collections: new CollectionsApi(publicHttp),
|
|
3980
4473
|
categories: new CategoriesApi(publicHttp),
|
|
3981
|
-
|
|
3982
|
-
orders: new OrdersApi(publicHttp, authHttp),
|
|
3983
|
-
blog: new BlogApi(publicHttp, authHttp),
|
|
4474
|
+
blog: new BlogServerApi(publicHttp, shopperHttp),
|
|
3984
4475
|
stores: new StoresApi(publicHttp),
|
|
3985
4476
|
themes: new ThemesApi(publicHttp),
|
|
3986
|
-
metaobjects: new MetaobjectsApi(publicHttp,
|
|
4477
|
+
metaobjects: new MetaobjectsApi(publicHttp, shopperHttp),
|
|
3987
4478
|
search: new SearchApi(publicHttp),
|
|
3988
|
-
shipping: new
|
|
3989
|
-
promotions: new
|
|
4479
|
+
shipping: new ShippingServerApi(publicHttp, privateHttp),
|
|
4480
|
+
promotions: new PromotionsServerApi(publicHttp, privateHttp),
|
|
3990
4481
|
paymentMethods: new PaymentMethodsApi(publicHttp),
|
|
3991
|
-
|
|
3992
|
-
reviews: new ReviewsApi(publicHttp),
|
|
3993
|
-
customers: new CustomersApi(authHttp),
|
|
3994
|
-
addresses: new AddressesApi(authHttp),
|
|
4482
|
+
reviews: new ReviewsServerApi(publicHttp, privateHttp),
|
|
3995
4483
|
contentPages: new ContentPagesApi(publicHttp),
|
|
3996
4484
|
menus: new MenusApi(publicHttp),
|
|
3997
|
-
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)
|
|
4491
|
+
};
|
|
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
|
|
3998
4513
|
};
|
|
3999
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
|
+
}
|
|
4000
4549
|
export {
|
|
4001
4550
|
ADJUSTABLE_STATES,
|
|
4002
4551
|
ADMIN_ORDER_SOURCES,
|
|
@@ -4004,6 +4553,7 @@ export {
|
|
|
4004
4553
|
ApiClientError,
|
|
4005
4554
|
AuthApi,
|
|
4006
4555
|
BlogApi,
|
|
4556
|
+
BlogServerApi,
|
|
4007
4557
|
CLIENT_HEADER,
|
|
4008
4558
|
COLLECTION_RULE_MATRIX,
|
|
4009
4559
|
CONDITION_TYPE_LABELS,
|
|
@@ -4079,11 +4629,13 @@ export {
|
|
|
4079
4629
|
PromotionTypeSchema,
|
|
4080
4630
|
PromotionWithDiscountSchema,
|
|
4081
4631
|
PromotionsApi,
|
|
4632
|
+
PromotionsServerApi,
|
|
4082
4633
|
RENDER_PREFIX,
|
|
4083
4634
|
RESOURCE_REFERENCE_TYPES,
|
|
4084
4635
|
RULE_FIELDS,
|
|
4085
4636
|
RedirectsApi,
|
|
4086
4637
|
ReviewsApi,
|
|
4638
|
+
ReviewsServerApi,
|
|
4087
4639
|
SDK_CLIENT_TOKEN,
|
|
4088
4640
|
SDK_VERSION,
|
|
4089
4641
|
SHIPMENT_STATUSES,
|
|
@@ -4093,6 +4645,7 @@ export {
|
|
|
4093
4645
|
SHIPPING_RATE_TYPES,
|
|
4094
4646
|
SearchApi,
|
|
4095
4647
|
ShippingApi,
|
|
4648
|
+
ShippingServerApi,
|
|
4096
4649
|
StoresApi,
|
|
4097
4650
|
THEME_HEX_COLOR,
|
|
4098
4651
|
ThemesApi,
|
|
@@ -4138,7 +4691,9 @@ export {
|
|
|
4138
4691
|
createBlogTagSchema,
|
|
4139
4692
|
createCategorySchema,
|
|
4140
4693
|
createContentPageSchema,
|
|
4694
|
+
createEcomwebProxiedSdk,
|
|
4141
4695
|
createEcomwebSdk,
|
|
4696
|
+
createEcomwebServerSdk,
|
|
4142
4697
|
createEmbeddedScriptSchema,
|
|
4143
4698
|
createOrderItemSchema,
|
|
4144
4699
|
createOrderSchema,
|