@scayle/storefront-core 7.69.2 → 8.0.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/CHANGELOG.md +195 -0
- package/dist/cache/cached.cjs +1 -1
- package/dist/cache/cached.d.ts +1 -1
- package/dist/cache/cached.mjs +1 -1
- package/dist/constants/basket.cjs +15 -1
- package/dist/constants/basket.d.ts +16 -0
- package/dist/constants/basket.mjs +14 -0
- package/dist/errors/errorResponse.d.ts +1 -1
- package/dist/errors/index.cjs +0 -22
- package/dist/errors/index.d.ts +0 -2
- package/dist/errors/index.mjs +0 -2
- package/dist/helpers/productHelpers.cjs +1 -35
- package/dist/helpers/productHelpers.d.ts +0 -8
- package/dist/helpers/productHelpers.mjs +0 -27
- package/dist/rpc/methods/basket/basket.cjs +33 -9
- package/dist/rpc/methods/basket/basket.d.ts +20 -4
- package/dist/rpc/methods/basket/basket.mjs +32 -14
- package/dist/rpc/methods/cbd.d.ts +1 -1
- package/dist/rpc/methods/checkout/checkout.cjs +1 -1
- package/dist/rpc/methods/checkout/checkout.mjs +1 -1
- package/dist/rpc/methods/checkout/order.d.ts +1 -1
- package/dist/rpc/methods/oauth/idp.cjs +1 -2
- package/dist/rpc/methods/oauth/idp.d.ts +1 -1
- package/dist/rpc/methods/oauth/idp.mjs +1 -2
- package/dist/rpc/methods/search.cjs +1 -32
- package/dist/rpc/methods/search.d.ts +0 -10
- package/dist/rpc/methods/search.mjs +0 -22
- package/dist/rpc/methods/user.cjs +3 -15
- package/dist/rpc/methods/user.d.ts +1 -1
- package/dist/rpc/methods/user.mjs +2 -15
- package/dist/server.cjs +1 -24
- package/dist/server.d.ts +0 -3
- package/dist/server.mjs +0 -2
- package/dist/types/api/auth.d.ts +0 -9
- package/dist/types/api/context.d.ts +0 -12
- package/dist/types/user.d.ts +0 -4
- package/dist/utils/basket.cjs +14 -0
- package/dist/utils/basket.d.ts +2 -0
- package/dist/utils/basket.mjs +12 -0
- package/dist/utils/index.cjs +11 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.mjs +1 -0
- package/dist/utils/keys.cjs +3 -3
- package/dist/utils/keys.mjs +3 -3
- package/package.json +7 -10
- package/dist/bapi/init.cjs +0 -19
- package/dist/bapi/init.d.ts +0 -15
- package/dist/bapi/init.mjs +0 -12
- package/dist/cache/providers/redis.cjs +0 -94
- package/dist/cache/providers/redis.d.ts +0 -28
- package/dist/cache/providers/redis.mjs +0 -86
- package/dist/errors/BAPIError.cjs +0 -18
- package/dist/errors/BAPIError.d.ts +0 -8
- package/dist/errors/BAPIError.mjs +0 -11
- package/dist/errors/baseError.cjs +0 -17
- package/dist/errors/baseError.d.ts +0 -5
- package/dist/errors/baseError.mjs +0 -10
- package/dist/utils/compression.cjs +0 -25
- package/dist/utils/compression.d.ts +0 -2
- package/dist/utils/compression.mjs +0 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,200 @@
|
|
|
1
1
|
# @scayle/storefront-core
|
|
2
2
|
|
|
3
|
+
## 8.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- **\[💥 BREAKING\]** The `getBadgeLabel` helper function has been removed, giving you more control over badge label display.
|
|
8
|
+
|
|
9
|
+
- **Note:** This change doesn't affect projects using SCAYLE Storefront Boilerplate v1.0 or later.
|
|
10
|
+
- For applications based on older versions or using `getBadgeLabel`, you can refer to the previous implementation below:
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
const BadgeLabel = {
|
|
14
|
+
NEW: 'new',
|
|
15
|
+
SOLD_OUT: 'sold_out',
|
|
16
|
+
ONLINE_EXCLUSIVE: 'online_exclusive',
|
|
17
|
+
SUSTAINABLE: 'sustainable',
|
|
18
|
+
PREMIUM: 'premium',
|
|
19
|
+
DEFAULT: '',
|
|
20
|
+
} as const
|
|
21
|
+
|
|
22
|
+
type BadgeLabelParamsKeys =
|
|
23
|
+
| 'isNew'
|
|
24
|
+
| 'isSoldOut'
|
|
25
|
+
| 'isOnlineOnly'
|
|
26
|
+
| 'isSustainable'
|
|
27
|
+
| 'isPremium'
|
|
28
|
+
type BadgeLabelParams = Partial<Record<BadgeLabelParamsKeys, boolean>>
|
|
29
|
+
|
|
30
|
+
const getBadgeLabel = (params: BadgeLabelParams = {}): string => {
|
|
31
|
+
if (!params) {
|
|
32
|
+
return BadgeLabel.DEFAULT
|
|
33
|
+
}
|
|
34
|
+
const { isNew, isSoldOut, isOnlineOnly, isSustainable, isPremium } =
|
|
35
|
+
params
|
|
36
|
+
|
|
37
|
+
if (isNew) {
|
|
38
|
+
return BadgeLabel.NEW
|
|
39
|
+
} else if (isSoldOut) {
|
|
40
|
+
return BadgeLabel.SOLD_OUT
|
|
41
|
+
} else if (isOnlineOnly) {
|
|
42
|
+
return BadgeLabel.ONLINE_EXCLUSIVE
|
|
43
|
+
} else if (isSustainable) {
|
|
44
|
+
return BadgeLabel.SUSTAINABLE
|
|
45
|
+
} else if (isPremium) {
|
|
46
|
+
return BadgeLabel.PREMIUM
|
|
47
|
+
} else {
|
|
48
|
+
return BadgeLabel.DEFAULT
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- **\[💥 BREAKING\]** We've standardized our configuration to use `sapi` (Storefront API) throughout the codebase, replacing the deprecated `bapi` keyword. This change improves clarity and consistency by removing the `initBapi` function, replacing the `bapiClient` property with `sapiClient` within the `RPCContext`, and updating all code references accordingly. `BapiConfig` is not exported anymore and has been superseded by `SapiConfig`.
|
|
54
|
+
|
|
55
|
+
- **NOTE:** These changes impact your environment variables used for deployments. Please check your infrastructure and deployment setup and adapt accordingly!
|
|
56
|
+
- _Previous `bapi` Configuration in `nuxt.config.ts`_
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
export default {
|
|
60
|
+
// ...
|
|
61
|
+
runtimeConfig: {
|
|
62
|
+
// ...
|
|
63
|
+
storefront: {
|
|
64
|
+
// ...
|
|
65
|
+
bapi: {
|
|
66
|
+
host: '...',
|
|
67
|
+
token: '...',
|
|
68
|
+
},
|
|
69
|
+
// ...
|
|
70
|
+
},
|
|
71
|
+
// ...
|
|
72
|
+
},
|
|
73
|
+
// ...
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
- _Legacy Environment Variables:_
|
|
78
|
+
|
|
79
|
+
```env
|
|
80
|
+
NUXT_STOREFRONT_BAPI_HOST='...'
|
|
81
|
+
NUXT_STOREFRONT_BAPI_TOKEN='...'
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- _Current `sapi` Configuration in `nuxt.config.ts`_
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
export default {
|
|
88
|
+
// ...
|
|
89
|
+
runtimeConfig: {
|
|
90
|
+
// ...
|
|
91
|
+
storefront: {
|
|
92
|
+
// ...
|
|
93
|
+
sapi: {
|
|
94
|
+
host: '...',
|
|
95
|
+
token: '...',
|
|
96
|
+
},
|
|
97
|
+
// ...
|
|
98
|
+
},
|
|
99
|
+
// ...
|
|
100
|
+
},
|
|
101
|
+
// ...
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
- _New Environment Variables:_
|
|
106
|
+
|
|
107
|
+
```env
|
|
108
|
+
NUXT_STOREFRONT_SAPI_HOST='...'
|
|
109
|
+
NUXT_STOREFRONT_SAPI_TOKEN='...'
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
- **\[💥 BREAKING\]** We've streamlined cache management by replacing the outdated `AY_CACHE_DISABLED` environment variable. Now, you can effortlessly control caching using either the `NUXT_STOREFRONT_CACHE_ENABLED` environment variable or the `storefront.cache.enabled` option within your `nuxt.config.ts` file, providing a more user-friendly experience.
|
|
113
|
+
- **\[💥 BREAKING\]** This release removes the `RedisCache` provider. We now use `UnstorageCache` which also supports Redis as a backing store.
|
|
114
|
+
- **\[💥 BREAKING\]** To improve security and streamline token management, we've updated how you access user `accessToken`. Instead of directly accessing the `storefrontAccessToken` field on the `UserAuthentication` interface, you'll now use the dedicated `getAccessToken` RPC. This change ensures a more secure and controlled method for handling sensitive user data within your application.
|
|
115
|
+
|
|
116
|
+
- _Previous Usage of `user.authentication.storefrontAccessToken`:_
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
const { data, fetching, fetch, error, status } = useUser(
|
|
120
|
+
'getUser',
|
|
121
|
+
// ...
|
|
122
|
+
)
|
|
123
|
+
data.value.user.authentication.storefrontAccessToken
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- _Current Usage of dedicated `getAccessToken` RPC method:_
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
const { data: accessToken } = useRpc(
|
|
130
|
+
'getAccessToken',
|
|
131
|
+
// ...
|
|
132
|
+
)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
- **\[💥 BREAKING\]** We've enhanced security for basket and wishlist keys by switching the default hashing algorithm from MD5 to the more robust SHA256.
|
|
136
|
+
|
|
137
|
+
- _Overriding default `hashAlgorithm` in `nuxt.config.ts`:_
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
export default defineNuxtConfig({
|
|
141
|
+
// ...
|
|
142
|
+
runtimeConfig: {
|
|
143
|
+
// ...
|
|
144
|
+
storefront: {
|
|
145
|
+
// ...
|
|
146
|
+
appKeys: {
|
|
147
|
+
// ...
|
|
148
|
+
hashAlgorithm: HashAlgorithm.MD5, // HashAlgorithm.SHA256
|
|
149
|
+
},
|
|
150
|
+
// ...
|
|
151
|
+
},
|
|
152
|
+
// ...
|
|
153
|
+
},
|
|
154
|
+
// ...
|
|
155
|
+
})
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
- **\[💥 BREAKING\]** The attribute `loginShopId` is removed from the `ShopUser` interface as the shop now uses session cookies.
|
|
159
|
+
- **\[💥 BREAKING\]** We're streamlining the search experience as we transition to SCAYLE Search v2, focusing on a category-centric approach. To achieve this, we're consolidating search functionality. This means we're replacing the `searchProducts` RPC method with `getSearchSuggestions`, which provides both product suggestions (triggered by product IDs) and category suggestions (triggered by category-like terms, leading to filtered category pages).
|
|
160
|
+
|
|
161
|
+
- _Previous Usage of `searchProducts` RPC method:_
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
const getSearchSuggestionsRpc = useRpcCall('searchProducts')
|
|
165
|
+
|
|
166
|
+
data.value = await searchProducts({
|
|
167
|
+
term: String(searchQuery.value),
|
|
168
|
+
...params,
|
|
169
|
+
})
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
- _Current Usage of `getSearchSuggestions` RPC method:_
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
const getSearchSuggestionsRpc = useRpcCall('getSearchSuggestions')
|
|
176
|
+
|
|
177
|
+
data.value = await getSearchSuggestionsRpc({
|
|
178
|
+
term: String(searchQuery.value),
|
|
179
|
+
...params,
|
|
180
|
+
})
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
- **\[💥 BREAKING\]** Improved basket updating: Adding an item to your basket with a reduced quantity will now correctly update the basket contents.
|
|
184
|
+
- **\[💥 BREAKING\]** The methods `getBasket`, `removeItemFromBasket`, `addItemsToBasket`, and `addItemToBasket` have been updated. Instead of returning the basket object directly, the basket will now be accessible as a property within the response body. Furthermore, errors occurring during`addItemToBasket` and `addItemsToBasket` will from now on return HTTP 400. The error kind can be identified by checking the `error` property of the response.
|
|
185
|
+
|
|
186
|
+
### Patch Changes
|
|
187
|
+
|
|
188
|
+
- Default `forceTokenRefresh` to `false` when no payload is passed to `getAccessToken`
|
|
189
|
+
|
|
190
|
+
## 7.69.3
|
|
191
|
+
|
|
192
|
+
### Patch Changes
|
|
193
|
+
|
|
194
|
+
**Dependencies**
|
|
195
|
+
|
|
196
|
+
- Updated dependency to @scayle/storefront-api@17.13.0
|
|
197
|
+
|
|
3
198
|
## 7.69.2
|
|
4
199
|
|
|
5
200
|
### Patch Changes
|
package/dist/cache/cached.cjs
CHANGED
|
@@ -15,7 +15,7 @@ class Cached {
|
|
|
15
15
|
log;
|
|
16
16
|
prefix;
|
|
17
17
|
enabled;
|
|
18
|
-
constructor(cache, log, prefix = "", enabled
|
|
18
|
+
constructor(cache, log, prefix = "", enabled) {
|
|
19
19
|
if (!cache) {
|
|
20
20
|
log.error(CACHE_NOT_INITIALIZED_MSG);
|
|
21
21
|
throw new Error(CACHE_NOT_INITIALIZED_MSG);
|
package/dist/cache/cached.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare class Cached {
|
|
|
13
13
|
private log;
|
|
14
14
|
private prefix;
|
|
15
15
|
private enabled;
|
|
16
|
-
constructor(cache: CacheInterface, log: Log, prefix
|
|
16
|
+
constructor(cache: CacheInterface, log: Log, prefix: (string | number) | undefined, enabled: boolean);
|
|
17
17
|
get isCacheEnabled(): boolean | undefined;
|
|
18
18
|
execute<TArgs extends unknown[], TResult>(fn: Fn<TArgs, TResult>, options?: CacheOptions): Awaited<Fn<TArgs, TResult>>;
|
|
19
19
|
private getCacheValue;
|
package/dist/cache/cached.mjs
CHANGED
|
@@ -9,7 +9,7 @@ export class Cached {
|
|
|
9
9
|
log;
|
|
10
10
|
prefix;
|
|
11
11
|
enabled;
|
|
12
|
-
constructor(cache, log, prefix = "", enabled
|
|
12
|
+
constructor(cache, log, prefix = "", enabled) {
|
|
13
13
|
if (!cache) {
|
|
14
14
|
log.error(CACHE_NOT_INITIALIZED_MSG);
|
|
15
15
|
throw new Error(CACHE_NOT_INITIALIZED_MSG);
|
|
@@ -3,10 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.ExistingItemHandling = void 0;
|
|
6
|
+
exports.UpdateBasketItemFailureKind = exports.ExistingItemHandling = exports.AddToBasketFailureKind = void 0;
|
|
7
7
|
const ExistingItemHandling = exports.ExistingItemHandling = {
|
|
8
8
|
KeepExisting: 0,
|
|
9
9
|
AddQuantityToExisting: 1,
|
|
10
10
|
ReplaceExisting: 2,
|
|
11
11
|
ReplaceExistingWithCombinedQuantity: 3
|
|
12
|
+
};
|
|
13
|
+
const AddToBasketFailureKind = exports.AddToBasketFailureKind = {
|
|
14
|
+
VariantAlreadyPresent: "VariantAlreadyPresent",
|
|
15
|
+
ItemUnvailable: "ItemUnvailable",
|
|
16
|
+
MaximumItemCountReached: "MaximumItemCountReached",
|
|
17
|
+
ItemDataNotFound: "ItemDataNotFound",
|
|
18
|
+
ItemAddedWithReducedQuantity: "ItemAddedWithReducedQuantity",
|
|
19
|
+
Unknown: "Unknown"
|
|
20
|
+
};
|
|
21
|
+
const UpdateBasketItemFailureKind = exports.UpdateBasketItemFailureKind = {
|
|
22
|
+
ItemUnvailable: "ItemUnvailable",
|
|
23
|
+
BasketItemNotFound: "BasketItemNotFound",
|
|
24
|
+
ItemAddedWithReducedQuantity: "ItemAddedWithReducedQuantity",
|
|
25
|
+
Unknown: "Unknown"
|
|
12
26
|
};
|
|
@@ -6,3 +6,19 @@ export declare const ExistingItemHandling: {
|
|
|
6
6
|
readonly ReplaceExistingWithCombinedQuantity: 3;
|
|
7
7
|
};
|
|
8
8
|
export type ExistingItemHandling = ValuesType<typeof ExistingItemHandling>;
|
|
9
|
+
export declare const AddToBasketFailureKind: {
|
|
10
|
+
readonly VariantAlreadyPresent: "VariantAlreadyPresent";
|
|
11
|
+
readonly ItemUnvailable: "ItemUnvailable";
|
|
12
|
+
readonly MaximumItemCountReached: "MaximumItemCountReached";
|
|
13
|
+
readonly ItemDataNotFound: "ItemDataNotFound";
|
|
14
|
+
readonly ItemAddedWithReducedQuantity: "ItemAddedWithReducedQuantity";
|
|
15
|
+
readonly Unknown: "Unknown";
|
|
16
|
+
};
|
|
17
|
+
export type AddToBasketFailureKind = ValuesType<typeof AddToBasketFailureKind>;
|
|
18
|
+
export declare const UpdateBasketItemFailureKind: {
|
|
19
|
+
readonly ItemUnvailable: "ItemUnvailable";
|
|
20
|
+
readonly BasketItemNotFound: "BasketItemNotFound";
|
|
21
|
+
readonly ItemAddedWithReducedQuantity: "ItemAddedWithReducedQuantity";
|
|
22
|
+
readonly Unknown: "Unknown";
|
|
23
|
+
};
|
|
24
|
+
export type UpdateBasketItemFailureKind = ValuesType<typeof UpdateBasketItemFailureKind>;
|
|
@@ -4,3 +4,17 @@ export const ExistingItemHandling = {
|
|
|
4
4
|
ReplaceExisting: 2,
|
|
5
5
|
ReplaceExistingWithCombinedQuantity: 3
|
|
6
6
|
};
|
|
7
|
+
export const AddToBasketFailureKind = {
|
|
8
|
+
VariantAlreadyPresent: "VariantAlreadyPresent",
|
|
9
|
+
ItemUnvailable: "ItemUnvailable",
|
|
10
|
+
MaximumItemCountReached: "MaximumItemCountReached",
|
|
11
|
+
ItemDataNotFound: "ItemDataNotFound",
|
|
12
|
+
ItemAddedWithReducedQuantity: "ItemAddedWithReducedQuantity",
|
|
13
|
+
Unknown: "Unknown"
|
|
14
|
+
};
|
|
15
|
+
export const UpdateBasketItemFailureKind = {
|
|
16
|
+
ItemUnvailable: "ItemUnvailable",
|
|
17
|
+
BasketItemNotFound: "BasketItemNotFound",
|
|
18
|
+
ItemAddedWithReducedQuantity: "ItemAddedWithReducedQuantity",
|
|
19
|
+
Unknown: "Unknown"
|
|
20
|
+
};
|
package/dist/errors/index.cjs
CHANGED
|
@@ -3,28 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var _BAPIError = require("./BAPIError.cjs");
|
|
7
|
-
Object.keys(_BAPIError).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _BAPIError[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _BAPIError[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _baseError = require("./baseError.cjs");
|
|
18
|
-
Object.keys(_baseError).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _baseError[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _baseError[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
6
|
var _errorResponse = require("./errorResponse.cjs");
|
|
29
7
|
Object.keys(_errorResponse).forEach(function (key) {
|
|
30
8
|
if (key === "default" || key === "__esModule") return;
|
package/dist/errors/index.d.ts
CHANGED
package/dist/errors/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.slugify = exports.isVariantInStock = exports.isInStock = exports.getVariantCrosssellingValues = exports.getVariantBySize = exports.getVariant = exports.getTotalAppliedReductions = exports.getSizeFromVariant = exports.getSizeFromSpecificVariant = exports.getProductSiblings = exports.getProductPath = exports.getProductColors = exports.getProductAndSiblingsColors = exports.getPrice = exports.getOriginalPrice = exports.getLowestPrice = exports.getLatestCategory = exports.getCategoriesByRoute = exports.
|
|
6
|
+
exports.slugify = exports.isVariantInStock = exports.isInStock = exports.getVariantCrosssellingValues = exports.getVariantBySize = exports.getVariant = exports.getTotalAppliedReductions = exports.getSizeFromVariant = exports.getSizeFromSpecificVariant = exports.getProductSiblings = exports.getProductPath = exports.getProductColors = exports.getProductAndSiblingsColors = exports.getPrice = exports.getOriginalPrice = exports.getLowestPrice = exports.getLatestCategory = exports.getCategoriesByRoute = exports.getAttribute = exports.getAppliedReductionsByCategory = exports.getAllSizesFromVariants = void 0;
|
|
7
7
|
var _storefrontApi = require("@scayle/storefront-api");
|
|
8
8
|
var _slugify = _interopRequireDefault(require("slugify"));
|
|
9
9
|
var _product = require("../constants/product.cjs");
|
|
@@ -18,42 +18,8 @@ const slugify = url => {
|
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
exports.slugify = slugify;
|
|
21
|
-
const BadgeLabel = {
|
|
22
|
-
NEW: "new",
|
|
23
|
-
SOLD_OUT: "sold_out",
|
|
24
|
-
ONLINE_EXCLUSIVE: "online_exclusive",
|
|
25
|
-
SUSTAINABLE: "sustainable",
|
|
26
|
-
PREMIUM: "premium",
|
|
27
|
-
DEFAULT: ""
|
|
28
|
-
};
|
|
29
21
|
const getPrice = variant => variant.price;
|
|
30
22
|
exports.getPrice = getPrice;
|
|
31
|
-
const getBadgeLabel = (params = {}) => {
|
|
32
|
-
if (!params) {
|
|
33
|
-
return BadgeLabel.DEFAULT;
|
|
34
|
-
}
|
|
35
|
-
const {
|
|
36
|
-
isNew,
|
|
37
|
-
isSoldOut,
|
|
38
|
-
isOnlineOnly,
|
|
39
|
-
isSustainable,
|
|
40
|
-
isPremium
|
|
41
|
-
} = params;
|
|
42
|
-
if (isNew) {
|
|
43
|
-
return BadgeLabel.NEW;
|
|
44
|
-
} else if (isSoldOut) {
|
|
45
|
-
return BadgeLabel.SOLD_OUT;
|
|
46
|
-
} else if (isOnlineOnly) {
|
|
47
|
-
return BadgeLabel.ONLINE_EXCLUSIVE;
|
|
48
|
-
} else if (isSustainable) {
|
|
49
|
-
return BadgeLabel.SUSTAINABLE;
|
|
50
|
-
} else if (isPremium) {
|
|
51
|
-
return BadgeLabel.PREMIUM;
|
|
52
|
-
} else {
|
|
53
|
-
return BadgeLabel.DEFAULT;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
exports.getBadgeLabel = getBadgeLabel;
|
|
57
23
|
const getOriginalPrice = price => {
|
|
58
24
|
return price.appliedReductions.length > 0 ? price.appliedReductions[0].amount.absoluteWithTax + price.withTax : price.withTax;
|
|
59
25
|
};
|
|
@@ -5,14 +5,6 @@ interface Route {
|
|
|
5
5
|
}
|
|
6
6
|
export declare const slugify: (url: string | undefined) => string;
|
|
7
7
|
export declare const getPrice: (variant: Variant) => VariantPrice;
|
|
8
|
-
type BadgeLabelParamsKeys = 'isNew' | 'isSoldOut' | 'isOnlineOnly' | 'isSustainable' | 'isPremium';
|
|
9
|
-
type BadgeLabelParams = Partial<Record<BadgeLabelParamsKeys, boolean>>;
|
|
10
|
-
/**
|
|
11
|
-
* getBadgeLabel is deprecated as this is application logic and should be handled per project.
|
|
12
|
-
*
|
|
13
|
-
* @deprecated
|
|
14
|
-
*/
|
|
15
|
-
export declare const getBadgeLabel: (params?: BadgeLabelParams) => string;
|
|
16
8
|
export declare const getOriginalPrice: (price: VariantPrice) => number;
|
|
17
9
|
export declare const getTotalAppliedReductions: (price: {
|
|
18
10
|
appliedReductions: {
|
|
@@ -10,34 +10,7 @@ export const slugify = (url) => {
|
|
|
10
10
|
remove: /[*+~.()'"!:@/#?]/g
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
|
-
const BadgeLabel = {
|
|
14
|
-
NEW: "new",
|
|
15
|
-
SOLD_OUT: "sold_out",
|
|
16
|
-
ONLINE_EXCLUSIVE: "online_exclusive",
|
|
17
|
-
SUSTAINABLE: "sustainable",
|
|
18
|
-
PREMIUM: "premium",
|
|
19
|
-
DEFAULT: ""
|
|
20
|
-
};
|
|
21
13
|
export const getPrice = (variant) => variant.price;
|
|
22
|
-
export const getBadgeLabel = (params = {}) => {
|
|
23
|
-
if (!params) {
|
|
24
|
-
return BadgeLabel.DEFAULT;
|
|
25
|
-
}
|
|
26
|
-
const { isNew, isSoldOut, isOnlineOnly, isSustainable, isPremium } = params;
|
|
27
|
-
if (isNew) {
|
|
28
|
-
return BadgeLabel.NEW;
|
|
29
|
-
} else if (isSoldOut) {
|
|
30
|
-
return BadgeLabel.SOLD_OUT;
|
|
31
|
-
} else if (isOnlineOnly) {
|
|
32
|
-
return BadgeLabel.ONLINE_EXCLUSIVE;
|
|
33
|
-
} else if (isSustainable) {
|
|
34
|
-
return BadgeLabel.SUSTAINABLE;
|
|
35
|
-
} else if (isPremium) {
|
|
36
|
-
return BadgeLabel.PREMIUM;
|
|
37
|
-
} else {
|
|
38
|
-
return BadgeLabel.DEFAULT;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
14
|
export const getOriginalPrice = (price) => {
|
|
42
15
|
return price.appliedReductions.length > 0 ? price.appliedReductions[0].amount.absoluteWithTax + price.withTax : price.withTax;
|
|
43
16
|
};
|
|
@@ -9,6 +9,7 @@ var _types = require("../../../types/index.cjs");
|
|
|
9
9
|
var _constants = require("../../../constants/index.cjs");
|
|
10
10
|
var _user = require("../../../utils/user.cjs");
|
|
11
11
|
var _response = require("../../../utils/response.cjs");
|
|
12
|
+
var _utils = require("../../../utils/index.cjs");
|
|
12
13
|
const SAPI_ERROR_NAME = "SAPI ERROR";
|
|
13
14
|
function getWithParams(params, context) {
|
|
14
15
|
return params.with ?? context.withParams?.basket ?? _constants.MIN_WITH_PARAMS_BASKET;
|
|
@@ -55,7 +56,14 @@ const addItemToBasket = exports.addItemToBasket = async function addItemToBasket
|
|
|
55
56
|
existingItemHandling
|
|
56
57
|
});
|
|
57
58
|
if (result.type === "success") {
|
|
58
|
-
return
|
|
59
|
+
return {
|
|
60
|
+
basket: result.basket
|
|
61
|
+
};
|
|
62
|
+
} else if (result.type === "failure" && (0, _utils.wasAddedWithReducedQuantity)(result.errors)) {
|
|
63
|
+
return {
|
|
64
|
+
basket: result.basket,
|
|
65
|
+
errors: result.errors
|
|
66
|
+
};
|
|
59
67
|
} else {
|
|
60
68
|
const {
|
|
61
69
|
message,
|
|
@@ -65,8 +73,9 @@ const addItemToBasket = exports.addItemToBasket = async function addItemToBasket
|
|
|
65
73
|
message,
|
|
66
74
|
statusCode
|
|
67
75
|
});
|
|
68
|
-
return new _errors.ErrorResponse(
|
|
69
|
-
detail: message
|
|
76
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, SAPI_ERROR_NAME, "Adding item to basket failed", {
|
|
77
|
+
detail: message,
|
|
78
|
+
errors: result.errors
|
|
70
79
|
});
|
|
71
80
|
}
|
|
72
81
|
};
|
|
@@ -102,7 +111,14 @@ const addItemsToBasket = exports.addItemsToBasket = async function addItemsToBas
|
|
|
102
111
|
existingItemHandling: params.existingItemHandling || _constants.ExistingItemHandling.AddQuantityToExisting
|
|
103
112
|
});
|
|
104
113
|
if (result.type === "success") {
|
|
105
|
-
return
|
|
114
|
+
return {
|
|
115
|
+
basket: result.basket
|
|
116
|
+
};
|
|
117
|
+
} else if (result.type === "failure" && (0, _utils.wasAddedWithReducedQuantity)(result.errors)) {
|
|
118
|
+
return {
|
|
119
|
+
basket: result.basket,
|
|
120
|
+
errors: result.errors
|
|
121
|
+
};
|
|
106
122
|
} else {
|
|
107
123
|
const {
|
|
108
124
|
statusCode,
|
|
@@ -112,8 +128,9 @@ const addItemsToBasket = exports.addItemsToBasket = async function addItemsToBas
|
|
|
112
128
|
statusCode,
|
|
113
129
|
message
|
|
114
130
|
});
|
|
115
|
-
return new _errors.ErrorResponse(
|
|
116
|
-
detail: message
|
|
131
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, SAPI_ERROR_NAME, "Adding one or more items to basket failed", {
|
|
132
|
+
detail: message,
|
|
133
|
+
errors: result.errors
|
|
117
134
|
});
|
|
118
135
|
}
|
|
119
136
|
};
|
|
@@ -144,7 +161,9 @@ const getBasket = exports.getBasket = async function getBasket2(options, context
|
|
|
144
161
|
detail: message
|
|
145
162
|
});
|
|
146
163
|
}
|
|
147
|
-
return
|
|
164
|
+
return {
|
|
165
|
+
basket: response.basket
|
|
166
|
+
};
|
|
148
167
|
};
|
|
149
168
|
const removeItemFromBasket = exports.removeItemFromBasket = async function removeItemFromBasket2(options, context) {
|
|
150
169
|
if (!(0, _types.hasSession)(context)) {
|
|
@@ -156,19 +175,24 @@ const removeItemFromBasket = exports.removeItemFromBasket = async function remov
|
|
|
156
175
|
basketKey
|
|
157
176
|
} = context;
|
|
158
177
|
const resolvedWith = getWithParams(options, context);
|
|
159
|
-
|
|
178
|
+
const basket = await sapiClient.basket.deleteItem(basketKey, options.itemKey, {
|
|
160
179
|
with: resolvedWith,
|
|
161
180
|
campaignKey,
|
|
162
181
|
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData,
|
|
163
182
|
orderCustomData: options.orderCustomData
|
|
164
183
|
});
|
|
184
|
+
return {
|
|
185
|
+
basket
|
|
186
|
+
};
|
|
165
187
|
};
|
|
166
188
|
const clearBasket = exports.clearBasket = async function clearBasket2(context) {
|
|
167
189
|
const getBasketResponse = await getBasket({}, context);
|
|
168
190
|
if (getBasketResponse instanceof _errors.ErrorResponse) {
|
|
169
191
|
return getBasketResponse;
|
|
170
192
|
}
|
|
171
|
-
const
|
|
193
|
+
const {
|
|
194
|
+
basket
|
|
195
|
+
} = await (0, _response.unwrap)(getBasketResponse);
|
|
172
196
|
await Promise.all(basket.items.map(async item => {
|
|
173
197
|
await removeItemFromBasket({
|
|
174
198
|
itemKey: item.key
|
|
@@ -6,21 +6,37 @@ export declare const addItemToBasket: ({ variantId, promotionId, quantity, displ
|
|
|
6
6
|
existingItemHandling?: ExistingItemHandling;
|
|
7
7
|
with?: BasketWithOptions;
|
|
8
8
|
orderCustomData?: Record<string, unknown>;
|
|
9
|
-
}, context: RpcContext) => Promise<ErrorResponse |
|
|
9
|
+
}, context: RpcContext) => Promise<ErrorResponse | {
|
|
10
|
+
basket: BasketResponseData<Product, Variant>;
|
|
11
|
+
errors?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
basket: BasketResponseData<Product, Variant>;
|
|
14
|
+
errors: AddOrUpdateItemError[];
|
|
15
|
+
}>;
|
|
10
16
|
export declare const addItemsToBasket: (params: {
|
|
11
17
|
items: AddOrUpdateItemType[];
|
|
12
18
|
existingItemHandling: ExistingItemHandling;
|
|
13
19
|
with?: BasketWithOptions;
|
|
14
20
|
orderCustomData?: Record<string, unknown>;
|
|
15
|
-
}, context: RpcContext) => Promise<ErrorResponse |
|
|
21
|
+
}, context: RpcContext) => Promise<ErrorResponse | {
|
|
22
|
+
basket: BasketResponseData<Product, Variant>;
|
|
23
|
+
errors?: undefined;
|
|
24
|
+
} | {
|
|
25
|
+
basket: BasketResponseData<Product, Variant>;
|
|
26
|
+
errors: AddOrUpdateItemError[];
|
|
27
|
+
}>;
|
|
16
28
|
export declare const getBasket: (options: (BasketWithOptions & {
|
|
17
29
|
orderCustomData?: Record<string, unknown>;
|
|
18
|
-
}) | undefined, context: RpcContext) => Promise<ErrorResponse |
|
|
30
|
+
}) | undefined, context: RpcContext) => Promise<ErrorResponse | {
|
|
31
|
+
basket: BasketResponseData<Product, Variant>;
|
|
32
|
+
}>;
|
|
19
33
|
export declare const removeItemFromBasket: (options: {
|
|
20
34
|
itemKey: string;
|
|
21
35
|
with?: BasketWithOptions;
|
|
22
36
|
orderCustomData?: Record<string, unknown>;
|
|
23
|
-
}, context: RpcContext) => Promise<ErrorResponse |
|
|
37
|
+
}, context: RpcContext) => Promise<ErrorResponse | {
|
|
38
|
+
basket: BasketResponseData<Product, Variant>;
|
|
39
|
+
}>;
|
|
24
40
|
export declare const clearBasket: (context: RpcContext) => Promise<true | ErrorResponse>;
|
|
25
41
|
export declare const mergeBaskets: ({ fromBasketKey, toBasketKey, with: _with, orderCustomData }: {
|
|
26
42
|
fromBasketKey: string;
|