@webround/commerce 0.0.0-stage → 0.3.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 +192 -2
- package/dist/account/account.d.ts +54 -0
- package/dist/account/account.js +40 -0
- package/dist/account/index.d.ts +3 -0
- package/dist/account/index.js +2 -0
- package/dist/addresses/api.d.ts +16 -0
- package/dist/addresses/api.js +13 -0
- package/dist/addresses/book.d.ts +40 -0
- package/dist/addresses/book.js +144 -0
- package/dist/addresses/index.d.ts +8 -0
- package/dist/addresses/index.js +5 -0
- package/dist/addresses/rules.d.ts +4 -0
- package/dist/addresses/rules.js +9 -0
- package/dist/addresses/types.d.ts +48 -0
- package/dist/addresses/types.js +6 -0
- package/dist/auth/api.d.ts +43 -0
- package/dist/auth/api.js +22 -0
- package/dist/auth/auth.d.ts +32 -0
- package/dist/auth/auth.js +23 -0
- package/dist/auth/cookies.d.ts +46 -0
- package/dist/auth/cookies.js +156 -0
- package/dist/auth/index.d.ts +14 -0
- package/dist/auth/index.js +8 -0
- package/dist/auth/renewal.d.ts +4 -0
- package/dist/auth/renewal.js +37 -0
- package/dist/auth/store.d.ts +70 -0
- package/dist/auth/store.js +284 -0
- package/dist/auth/types.d.ts +105 -0
- package/dist/auth/types.js +5 -0
- package/dist/auth/wake.d.ts +18 -0
- package/dist/auth/wake.js +23 -0
- package/dist/cache.d.ts +49 -0
- package/dist/cache.js +144 -0
- package/dist/canonical.d.ts +7 -0
- package/dist/canonical.js +32 -0
- package/dist/cart/api.d.ts +25 -0
- package/dist/cart/api.js +16 -0
- package/dist/cart/index.d.ts +10 -0
- package/dist/cart/index.js +6 -0
- package/dist/cart/lines.d.ts +15 -0
- package/dist/cart/lines.js +23 -0
- package/dist/cart/storage.d.ts +30 -0
- package/dist/cart/storage.js +82 -0
- package/dist/cart/store.d.ts +58 -0
- package/dist/cart/store.js +218 -0
- package/dist/cart/types.d.ts +194 -0
- package/dist/cart/types.js +11 -0
- package/dist/catalog/cached.d.ts +47 -0
- package/dist/catalog/cached.js +52 -0
- package/dist/catalog/catalog.d.ts +10 -0
- package/dist/catalog/catalog.js +7 -0
- package/dist/catalog/named.d.ts +3 -0
- package/dist/catalog/named.js +7 -0
- package/dist/catalog/products.d.ts +28 -0
- package/dist/catalog/products.js +12 -0
- package/dist/catalog/store-data.d.ts +13 -0
- package/dist/catalog/store-data.js +6 -0
- package/dist/catalog/types.d.ts +430 -0
- package/dist/catalog/types.js +4 -0
- package/dist/checkout/api.d.ts +14 -0
- package/dist/checkout/api.js +7 -0
- package/dist/checkout/errors.d.ts +23 -0
- package/dist/checkout/errors.js +18 -0
- package/dist/checkout/index.d.ts +10 -0
- package/dist/checkout/index.js +6 -0
- package/dist/checkout/return-urls.d.ts +7 -0
- package/dist/checkout/return-urls.js +11 -0
- package/dist/checkout/store.d.ts +98 -0
- package/dist/checkout/store.js +179 -0
- package/dist/checkout/types.d.ts +225 -0
- package/dist/checkout/types.js +28 -0
- package/dist/commerce.d.ts +55 -0
- package/dist/commerce.js +55 -0
- package/dist/customer-resources.d.ts +18 -0
- package/dist/customer-resources.js +40 -0
- package/dist/errors.d.ts +65 -0
- package/dist/errors.js +96 -0
- package/dist/http.d.ts +49 -0
- package/dist/http.js +94 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +22 -0
- package/dist/orders/api.d.ts +16 -0
- package/dist/orders/api.js +13 -0
- package/dist/orders/index.d.ts +6 -0
- package/dist/orders/index.js +3 -0
- package/dist/orders/orders.d.ts +19 -0
- package/dist/orders/orders.js +18 -0
- package/dist/orders/types.d.ts +88 -0
- package/dist/orders/types.js +4 -0
- package/dist/resource.d.ts +19 -0
- package/dist/resource.js +15 -0
- package/dist/returns/api.d.ts +27 -0
- package/dist/returns/api.js +19 -0
- package/dist/returns/index.d.ts +6 -0
- package/dist/returns/index.js +3 -0
- package/dist/returns/returns.d.ts +30 -0
- package/dist/returns/returns.js +31 -0
- package/dist/returns/types.d.ts +99 -0
- package/dist/returns/types.js +2 -0
- package/dist/reviews/api.d.ts +19 -0
- package/dist/reviews/api.js +15 -0
- package/dist/reviews/index.d.ts +9 -0
- package/dist/reviews/index.js +5 -0
- package/dist/reviews/reviews.d.ts +23 -0
- package/dist/reviews/reviews.js +37 -0
- package/dist/reviews/rules.d.ts +8 -0
- package/dist/reviews/rules.js +7 -0
- package/dist/reviews/types.d.ts +54 -0
- package/dist/reviews/types.js +10 -0
- package/dist/shop/address-store.d.ts +14 -0
- package/dist/shop/address-store.js +28 -0
- package/dist/shop/address.d.ts +12 -0
- package/dist/shop/address.js +95 -0
- package/dist/shop/index.d.ts +16 -0
- package/dist/shop/index.js +9 -0
- package/dist/shop/question.d.ts +15 -0
- package/dist/shop/question.js +12 -0
- package/dist/shop/range.d.ts +7 -0
- package/dist/shop/range.js +38 -0
- package/dist/shop/sort.d.ts +19 -0
- package/dist/shop/sort.js +18 -0
- package/dist/shop/state.d.ts +47 -0
- package/dist/shop/state.js +51 -0
- package/dist/shop/store.d.ts +26 -0
- package/dist/shop/store.js +47 -0
- package/dist/shop/to-search.d.ts +14 -0
- package/dist/shop/to-search.js +53 -0
- package/dist/store-kit.d.ts +39 -0
- package/dist/store-kit.js +81 -0
- package/dist/wishlist/api.d.ts +12 -0
- package/dist/wishlist/api.js +10 -0
- package/dist/wishlist/index.d.ts +7 -0
- package/dist/wishlist/index.js +4 -0
- package/dist/wishlist/types.d.ts +30 -0
- package/dist/wishlist/types.js +4 -0
- package/dist/wishlist/wishlist.d.ts +45 -0
- package/dist/wishlist/wishlist.js +84 -0
- package/package.json +39 -5
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/** One line of a cart: which variant, at which of its prices, how many. */
|
|
2
|
+
export interface CartLineInput {
|
|
3
|
+
variantId: string;
|
|
4
|
+
priceId: string;
|
|
5
|
+
quantity: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* An option of a line (size, colour…), in one of two shapes, because the store makes it in two places. What `total` answers for a guest's lines is read from the catalog in the language asked:
|
|
9
|
+
* `tagValue` is the value in that language (`tagValueAlias` is `null` there). What a customer's cart (`get`) answers is what was SAVED when the line was added: `optionValue`, the value as the
|
|
10
|
+
* store keeps it (in its default language), and no alias. They are not the same thing; which one a line has is told by the key it has.
|
|
11
|
+
*/
|
|
12
|
+
export type CartItemOption = {
|
|
13
|
+
optionName: string;
|
|
14
|
+
tagValue: string;
|
|
15
|
+
tagValueAlias: string | null;
|
|
16
|
+
} | {
|
|
17
|
+
optionName: string;
|
|
18
|
+
optionValue: string;
|
|
19
|
+
};
|
|
20
|
+
/** `pricing` of a zone or a method: by currency, as the store writes it (what a checkout reads). */
|
|
21
|
+
type ByCurrency = Record<string, unknown>;
|
|
22
|
+
export interface CartShippingZone {
|
|
23
|
+
id: string;
|
|
24
|
+
label: string;
|
|
25
|
+
countryCode: string;
|
|
26
|
+
surchargePricing: ByCurrency;
|
|
27
|
+
taxRate: number;
|
|
28
|
+
/** Seen absent in a real cart: the store leaves these out of the zones it puts in a cart. */
|
|
29
|
+
stripeTaxRateId?: string | null;
|
|
30
|
+
createdAt?: string;
|
|
31
|
+
updatedAt?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface CartShippingMethod {
|
|
34
|
+
id: string;
|
|
35
|
+
/** Seen in a real cart, undocumented: which method this is. */
|
|
36
|
+
methodId?: string;
|
|
37
|
+
assetUrl?: string | null;
|
|
38
|
+
label: string;
|
|
39
|
+
provider: string | null;
|
|
40
|
+
availableCountries?: string[] | null;
|
|
41
|
+
etaMin: number | null;
|
|
42
|
+
etaMax: number | null;
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
pricing: ByCurrency;
|
|
45
|
+
maxWeight: number | null;
|
|
46
|
+
maxVolume: number | null;
|
|
47
|
+
assetId: string | null;
|
|
48
|
+
createdAt?: string | null;
|
|
49
|
+
updatedAt?: string | null;
|
|
50
|
+
}
|
|
51
|
+
export interface CartTaxZone {
|
|
52
|
+
id: string;
|
|
53
|
+
label: string;
|
|
54
|
+
rate: number;
|
|
55
|
+
countryCode: string;
|
|
56
|
+
isDefault: boolean;
|
|
57
|
+
stripeTaxRateId?: string | null;
|
|
58
|
+
createdAt?: string | null;
|
|
59
|
+
updatedAt?: string | null;
|
|
60
|
+
}
|
|
61
|
+
/** A line of a priced cart. `id` is the line's own (a customer's cart has it; what `total` answers for a guest does not). */
|
|
62
|
+
export interface CartItem {
|
|
63
|
+
id?: string;
|
|
64
|
+
variantId: string;
|
|
65
|
+
priceId: string;
|
|
66
|
+
productId: string;
|
|
67
|
+
variantName: string | null;
|
|
68
|
+
productName: string | null;
|
|
69
|
+
variantSlug: string;
|
|
70
|
+
skuCode: string | null;
|
|
71
|
+
coverUrl: string | null;
|
|
72
|
+
quantity: number;
|
|
73
|
+
originalPrice: number;
|
|
74
|
+
comparePrice: number;
|
|
75
|
+
netAmount: number;
|
|
76
|
+
totalAmount: number;
|
|
77
|
+
grossAmount: number;
|
|
78
|
+
totalGrossAmount: number;
|
|
79
|
+
taxRate: number;
|
|
80
|
+
defaultTaxRate: number;
|
|
81
|
+
currencyCode: string;
|
|
82
|
+
cadence: string | null;
|
|
83
|
+
isAvailable: boolean;
|
|
84
|
+
available: number;
|
|
85
|
+
options: CartItemOption[];
|
|
86
|
+
shippingZones: CartShippingZone[];
|
|
87
|
+
shippingMethods: CartShippingMethod[];
|
|
88
|
+
taxZones: CartTaxZone[];
|
|
89
|
+
resolvedZone: CartTaxZone | null;
|
|
90
|
+
deliveryMethods: string[];
|
|
91
|
+
allowBackorder: boolean;
|
|
92
|
+
purchaseRestock: boolean;
|
|
93
|
+
allowFreeShipping: boolean;
|
|
94
|
+
forceFreeShipping: boolean;
|
|
95
|
+
packageWeight?: number;
|
|
96
|
+
packageLength?: number;
|
|
97
|
+
packageWidth?: number;
|
|
98
|
+
packageHeight?: number;
|
|
99
|
+
packageVolume?: number;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* A priced cart: the customer's (`get`) or the one the lines of a guest make (`total`). The two totals count ONLY the lines that are available (`isAvailable`): a cart of lines that are all out of stock
|
|
103
|
+
* has the total 0 though each line has its own price. A variant the store does not have is left out of `total`'s answer, not refused.
|
|
104
|
+
*/
|
|
105
|
+
export interface Cart {
|
|
106
|
+
items: CartItem[];
|
|
107
|
+
totalAmount: number;
|
|
108
|
+
totalGrossAmount: number;
|
|
109
|
+
}
|
|
110
|
+
export interface GetCartInput {
|
|
111
|
+
langCode?: string;
|
|
112
|
+
/** Identifies this cart for the store's analytics (an abandoned cart): made and kept by the client. */
|
|
113
|
+
cartTrackingId?: string;
|
|
114
|
+
}
|
|
115
|
+
export interface CartTotalInput {
|
|
116
|
+
langCode?: string;
|
|
117
|
+
/** Up to 100 lines. */
|
|
118
|
+
items: CartLineInput[];
|
|
119
|
+
cartTrackingId?: string;
|
|
120
|
+
}
|
|
121
|
+
export interface MergeCartInput {
|
|
122
|
+
langCode?: string;
|
|
123
|
+
/** Up to 100 lines. A variant the customer's cart already has is added to. */
|
|
124
|
+
items: CartLineInput[];
|
|
125
|
+
}
|
|
126
|
+
export interface UpdateCartItemInput {
|
|
127
|
+
quantity: number;
|
|
128
|
+
}
|
|
129
|
+
/** What adding a line answers: the line was made (`created`) or was already there and its quantity grew (`updated`, with the quantity it has now). */
|
|
130
|
+
export interface CartItemAction {
|
|
131
|
+
created?: boolean;
|
|
132
|
+
updated?: boolean;
|
|
133
|
+
deleted?: boolean;
|
|
134
|
+
quantity?: number;
|
|
135
|
+
}
|
|
136
|
+
/** `fallbackApplied`: the lines had more than one currency or billing cadence, and the store had to fall back to one. */
|
|
137
|
+
export interface CartMergeAnswer {
|
|
138
|
+
merged: boolean;
|
|
139
|
+
fallbackApplied: boolean;
|
|
140
|
+
}
|
|
141
|
+
export interface VerifyPromotionsInput {
|
|
142
|
+
/** 1 to 10 codes: none, or one the store does not know, is 404 `PROMOTION_INVALID`. */
|
|
143
|
+
codes: string[];
|
|
144
|
+
/** The cart's gross total as a TEXT of digits with up to 8 decimals (`"123.45"`): that is how the store wants it. */
|
|
145
|
+
cartTotal: string;
|
|
146
|
+
cartCurrency: string;
|
|
147
|
+
variantIds: string[];
|
|
148
|
+
langCode?: string;
|
|
149
|
+
}
|
|
150
|
+
export interface Promotion {
|
|
151
|
+
id: string;
|
|
152
|
+
name: string;
|
|
153
|
+
/** Not in what the cart's promotion check answers (the store selects fewer columns than it declares). */
|
|
154
|
+
description?: string | null;
|
|
155
|
+
active?: boolean;
|
|
156
|
+
target: string;
|
|
157
|
+
code: string | null;
|
|
158
|
+
position: number;
|
|
159
|
+
discountType: string;
|
|
160
|
+
/** `{ base }` for a percentage; by currency (`{ EUR: { base } }`) for a fixed amount. */
|
|
161
|
+
discountValue: {
|
|
162
|
+
base: number;
|
|
163
|
+
} | Record<string, {
|
|
164
|
+
base: number;
|
|
165
|
+
}> | null;
|
|
166
|
+
limitUsageGlobal: boolean;
|
|
167
|
+
limitUsageCustomer: boolean;
|
|
168
|
+
maxUsesGlobal: number | null;
|
|
169
|
+
maxUsesPerCustomer: number | null;
|
|
170
|
+
minOrderAmount: Record<string, {
|
|
171
|
+
base: number;
|
|
172
|
+
}> | null;
|
|
173
|
+
exclusive: boolean;
|
|
174
|
+
reserved: boolean;
|
|
175
|
+
filterMode: string;
|
|
176
|
+
startsAt: string | null;
|
|
177
|
+
endsAt: string | null;
|
|
178
|
+
createdAt: string;
|
|
179
|
+
updatedAt?: string | null;
|
|
180
|
+
}
|
|
181
|
+
export interface VerifyPromotionsAnswer {
|
|
182
|
+
data: Promotion[];
|
|
183
|
+
valid: boolean;
|
|
184
|
+
}
|
|
185
|
+
/** The `code` the store gives to what the cart refuses (`CommerceError.code`). */
|
|
186
|
+
export declare const CART_ERROR_CODES: {
|
|
187
|
+
/** A cart has one currency and one billing cadence. */
|
|
188
|
+
readonly currencyMismatch: "CART_CURRENCY_MISMATCH";
|
|
189
|
+
/** A cart has a limited number of different variants (99 by default). */
|
|
190
|
+
readonly limitReached: "CART_LIMIT_REACHED";
|
|
191
|
+
readonly invalidItems: "CART_INVALID_ITEMS";
|
|
192
|
+
};
|
|
193
|
+
export {};
|
|
194
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// What the cart's calls of commerce-core take and give, as the store says it (the shapes are its own: nothing is renamed, reshaped or completed). Dates come as text, as JSON has them. What a customer's cart is made
|
|
2
|
+
// of (a variant, one of its prices, how many) is the same for a customer's and a guest's: a guest's lives in the page and is priced by `total`.
|
|
3
|
+
/** The `code` the store gives to what the cart refuses (`CommerceError.code`). */
|
|
4
|
+
export const CART_ERROR_CODES = {
|
|
5
|
+
/** A cart has one currency and one billing cadence. */
|
|
6
|
+
currencyMismatch: 'CART_CURRENCY_MISMATCH',
|
|
7
|
+
/** A cart has a limited number of different variants (99 by default). */
|
|
8
|
+
limitReached: 'CART_LIMIT_REACHED',
|
|
9
|
+
invalidItems: 'CART_INVALID_ITEMS',
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Cache } from '../cache.js';
|
|
2
|
+
import { type Resource } from '../resource.js';
|
|
3
|
+
import type { HttpClient } from '../http.js';
|
|
4
|
+
import { type Catalog } from './catalog.js';
|
|
5
|
+
import type { ProductByIdInput, ProductBySlugInput, ProductDetailResponse, ProductPage, ProductRelatedInput, ProductReviewsInput, ProductSearch, ReviewPage, StoreDataResponse } from './types.js';
|
|
6
|
+
/** What can be forgotten from the cache: one of the catalog's calls. */
|
|
7
|
+
export type CatalogCall = 'products.search' | 'products.getBySlug' | 'products.getById' | 'products.getReviews' | 'products.getRelated' | 'storeData.get';
|
|
8
|
+
export type { Resource };
|
|
9
|
+
export interface CatalogResources {
|
|
10
|
+
products: {
|
|
11
|
+
search(input: ProductSearch): Resource<ProductPage>;
|
|
12
|
+
getBySlug(variantSlug: string, input: ProductBySlugInput): Resource<ProductDetailResponse>;
|
|
13
|
+
getById(id: string, input: ProductByIdInput): Resource<ProductDetailResponse>;
|
|
14
|
+
getReviews(id: string, input?: ProductReviewsInput): Resource<ReviewPage>;
|
|
15
|
+
getRelated(id: string, input: ProductRelatedInput): Resource<ProductPage>;
|
|
16
|
+
};
|
|
17
|
+
storeData: {
|
|
18
|
+
get(input?: {
|
|
19
|
+
langCode?: string;
|
|
20
|
+
}): Resource<StoreDataResponse>;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* What to forget. `call` alone: everything that was asked of that call. With `subject`: only what it was asked about (the product's id for `getById`, `getReviews`, `getRelated`; the VARIANT's slug
|
|
25
|
+
* for `getBySlug`). The search and the store data are about nothing in particular, so they take no subject.
|
|
26
|
+
*/
|
|
27
|
+
export type CatalogForget = {
|
|
28
|
+
call: 'products.search' | 'storeData.get';
|
|
29
|
+
} | {
|
|
30
|
+
call: 'products.getBySlug' | 'products.getById' | 'products.getReviews' | 'products.getRelated';
|
|
31
|
+
subject?: string;
|
|
32
|
+
};
|
|
33
|
+
export interface CachedCatalog extends Catalog {
|
|
34
|
+
resource: CatalogResources;
|
|
35
|
+
/** Forgets what was asked of the catalog, so that the next question is asked again: of one call, of one call about one subject, or (with nothing said) all that this store has in the cache. */
|
|
36
|
+
invalidate(target?: CatalogForget): void;
|
|
37
|
+
}
|
|
38
|
+
/** What tells one store's questions from another's in the cache: where the backend is, and which store. A client has them (`HttpClient`); a catalog that does not use one says them itself. */
|
|
39
|
+
export type CatalogIdentity = Pick<HttpClient, 'baseUrl' | 'storeId'>;
|
|
40
|
+
/**
|
|
41
|
+
* The catalog, remembered. With a client (`createCachedCatalog(http, cache)`) it asks the REST catalog. With an `identity` and a `catalog` of its own
|
|
42
|
+
* (`createCachedCatalog({ baseUrl, storeId }, cache, catalog)`) it remembers whatever answers the `Catalog` interface (a GraphQL one, one for tests): the cache,
|
|
43
|
+
* the resources and what a framework binds to them are the same, for they depend on the interface and on who is asking, never on how it is asked.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createCachedCatalog(http: HttpClient, cache: Cache): CachedCatalog;
|
|
46
|
+
export declare function createCachedCatalog(identity: CatalogIdentity, cache: Cache, catalog: Catalog): CachedCatalog;
|
|
47
|
+
//# sourceMappingURL=cached.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { cachePrefix } from '../cache.js';
|
|
2
|
+
import { createResourceFactory } from '../resource.js';
|
|
3
|
+
import { createCatalog } from './catalog.js';
|
|
4
|
+
import { named } from './named.js';
|
|
5
|
+
export function createCachedCatalog(identity, cache, catalog) {
|
|
6
|
+
const plain = catalog ?? createCatalog(identity);
|
|
7
|
+
const http = identity;
|
|
8
|
+
const resource = createResourceFactory(cache, http);
|
|
9
|
+
const resources = {
|
|
10
|
+
products: {
|
|
11
|
+
search: (input) => resource('products.search', undefined, input, (o) => plain.products.search(input, o)),
|
|
12
|
+
getBySlug: (variantSlug, input) => {
|
|
13
|
+
named('a variant slug', variantSlug);
|
|
14
|
+
return resource('products.getBySlug', variantSlug, input, (o) => plain.products.getBySlug(variantSlug, input, o));
|
|
15
|
+
},
|
|
16
|
+
getById: (id, input) => {
|
|
17
|
+
named('an id', id);
|
|
18
|
+
return resource('products.getById', id, input, (o) => plain.products.getById(id, input, o));
|
|
19
|
+
},
|
|
20
|
+
getReviews: (id, input) => {
|
|
21
|
+
named('an id', id);
|
|
22
|
+
// Nothing asked and an empty ask are the same question
|
|
23
|
+
return resource('products.getReviews', id, input ?? {}, (o) => plain.products.getReviews(id, input, o));
|
|
24
|
+
},
|
|
25
|
+
getRelated: (id, input) => {
|
|
26
|
+
named('an id', id);
|
|
27
|
+
return resource('products.getRelated', id, input, (o) => plain.products.getRelated(id, input, o));
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
storeData: {
|
|
31
|
+
get: (input) => resource('storeData.get', undefined, input ?? {}, (o) => plain.storeData.get(input, o)),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
resource: resources,
|
|
36
|
+
products: {
|
|
37
|
+
search: (input, options) => resources.products.search(input).load(options),
|
|
38
|
+
getBySlug: (variantSlug, input, options) => resources.products.getBySlug(variantSlug, input).load(options),
|
|
39
|
+
getById: (id, input, options) => resources.products.getById(id, input).load(options),
|
|
40
|
+
getReviews: (id, input, options) => resources.products.getReviews(id, input).load(options),
|
|
41
|
+
getRelated: (id, input, options) => resources.products.getRelated(id, input).load(options),
|
|
42
|
+
},
|
|
43
|
+
storeData: {
|
|
44
|
+
get: (input, options) => resources.storeData.get(input).load(options),
|
|
45
|
+
},
|
|
46
|
+
invalidate(target) {
|
|
47
|
+
const store = { base: http.baseUrl, storeId: http.storeId };
|
|
48
|
+
cache.invalidate(target ? cachePrefix({ ...store, call: target.call, subject: 'subject' in target ? target.subject : undefined }) : cachePrefix(store));
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=cached.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import { type ProductsApi } from './products.js';
|
|
3
|
+
import { type StoreDataApi } from './store-data.js';
|
|
4
|
+
export interface Catalog {
|
|
5
|
+
products: ProductsApi;
|
|
6
|
+
storeData: StoreDataApi;
|
|
7
|
+
}
|
|
8
|
+
/** The catalog's calls, over a client made for the catalog's address (`createHttpClient`). Each call answers what the catalog answers. */
|
|
9
|
+
export declare function createCatalog(http: HttpClient): Catalog;
|
|
10
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createProductsApi } from './products.js';
|
|
2
|
+
import { createStoreDataApi } from './store-data.js';
|
|
3
|
+
/** The catalog's calls, over a client made for the catalog's address (`createHttpClient`). Each call answers what the catalog answers. */
|
|
4
|
+
export function createCatalog(http) {
|
|
5
|
+
return { products: createProductsApi(http), storeData: createStoreDataApi(http) };
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** What names one thing in an address (a product's id, a variant's slug) must be something: an empty one would be the address of the list, and ask for a search with the wrong body. */
|
|
2
|
+
export declare function named(what: string, value: string): string;
|
|
3
|
+
//# sourceMappingURL=named.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** What names one thing in an address (a product's id, a variant's slug) must be something: an empty one would be the address of the list, and ask for a search with the wrong body. */
|
|
2
|
+
export function named(what, value) {
|
|
3
|
+
if (typeof value !== 'string' || value === '')
|
|
4
|
+
throw new TypeError(`${what} is needed to ask for a product`);
|
|
5
|
+
return encodeURIComponent(value);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=named.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import type { CallOptions, ProductByIdInput, ProductBySlugInput, ProductDetailResponse, ProductPage, ProductRelatedInput, ProductReviewsInput, ProductSearch, ReviewPage } from './types.js';
|
|
3
|
+
export interface ProductsApi {
|
|
4
|
+
/**
|
|
5
|
+
* `POST /public/products`: the store's products, filtered, sorted and paginated as asked. Nothing is added to what is asked (no page, no limit, no sorting): the server's own
|
|
6
|
+
* defaults apply to what is left out. The body goes out in its canonical form (keys and lists in order), so the same search is always the same request.
|
|
7
|
+
*/
|
|
8
|
+
search(input: ProductSearch, options?: CallOptions): Promise<ProductPage>;
|
|
9
|
+
/**
|
|
10
|
+
* `POST /public/products/by-slug/{variantSlug}`: the product that has a variant with this slug, with all it has. A product has no slug: it is the VARIANT's. What is loaded with it is for
|
|
11
|
+
* `input`'s `include*` to say.
|
|
12
|
+
*/
|
|
13
|
+
getBySlug(variantSlug: string, input: ProductBySlugInput, options?: CallOptions): Promise<ProductDetailResponse>;
|
|
14
|
+
/** `POST /public/products/{id}`: the product with this id, with all it has. */
|
|
15
|
+
getById(id: string, input: ProductByIdInput, options?: CallOptions): Promise<ProductDetailResponse>;
|
|
16
|
+
/**
|
|
17
|
+
* `POST /public/products/{id}/reviews`: the product's reviews, a page of them, with how many there are for each grade. The id is the product's (a UUID: the catalog refuses anything else with a 400).
|
|
18
|
+
* A product with no reviews is an empty page, not an error.
|
|
19
|
+
*/
|
|
20
|
+
getReviews(id: string, input?: ProductReviewsInput, options?: CallOptions): Promise<ReviewPage>;
|
|
21
|
+
/**
|
|
22
|
+
* `POST /public/products/{id}/related`: the products related to this one (up to ten, the most relevant first), in the same shape as a search's. The id is the product's (a UUID).
|
|
23
|
+
* A product with nothing related is an empty page, not an error.
|
|
24
|
+
*/
|
|
25
|
+
getRelated(id: string, input: ProductRelatedInput, options?: CallOptions): Promise<ProductPage>;
|
|
26
|
+
}
|
|
27
|
+
export declare function createProductsApi(http: HttpClient): ProductsApi;
|
|
28
|
+
//# sourceMappingURL=products.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { canonicalize } from '../canonical.js';
|
|
2
|
+
import { named } from './named.js';
|
|
3
|
+
export function createProductsApi(http) {
|
|
4
|
+
return {
|
|
5
|
+
search: (input, options) => http.request({ method: 'POST', path: '/public/products', body: canonicalize(input), signal: options?.signal }),
|
|
6
|
+
getBySlug: (variantSlug, input, options) => http.request({ method: 'POST', path: `/public/products/by-slug/${named('a variant slug', variantSlug)}`, body: canonicalize(input), signal: options?.signal }),
|
|
7
|
+
getById: (id, input, options) => http.request({ method: 'POST', path: `/public/products/${named('an id', id)}`, body: canonicalize(input), signal: options?.signal }),
|
|
8
|
+
getRelated: (id, input, options) => http.request({ method: 'POST', path: `/public/products/${named('an id', id)}/related`, body: canonicalize(input), signal: options?.signal }),
|
|
9
|
+
getReviews: (id, input, options) => http.request({ method: 'POST', path: `/public/products/${named('an id', id)}/reviews`, body: canonicalize(input ?? {}), signal: options?.signal }),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=products.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import type { CallOptions, StoreDataResponse } from './types.js';
|
|
3
|
+
export interface StoreDataApi {
|
|
4
|
+
/**
|
|
5
|
+
* `GET /public/store_data`: what the store is made of for a customer: its settings, the collections, the filters, the tags and the attributes to filter and sort by. The answer is
|
|
6
|
+
* the catalog's own (`{ data: … }`), unchanged. `langCode` is the language the names come in: `default` (or none) is the store's default language, and one the store does not use gets it too.
|
|
7
|
+
*/
|
|
8
|
+
get(input?: {
|
|
9
|
+
langCode?: string;
|
|
10
|
+
}, options?: CallOptions): Promise<StoreDataResponse>;
|
|
11
|
+
}
|
|
12
|
+
export declare function createStoreDataApi(http: HttpClient): StoreDataApi;
|
|
13
|
+
//# sourceMappingURL=store-data.d.ts.map
|