@scayle/storefront-core 7.69.3 → 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 +187 -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 +6 -9
- 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
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from "../../../constants/index.mjs";
|
|
9
9
|
import { mergeBaskets as mergeBasketFunction } from "../../../utils/user.mjs";
|
|
10
10
|
import { unwrap } from "../../../utils/response.mjs";
|
|
11
|
+
import { wasAddedWithReducedQuantity } from "../../../utils/index.mjs";
|
|
11
12
|
const SAPI_ERROR_NAME = "SAPI ERROR";
|
|
12
13
|
function getWithParams(params, context) {
|
|
13
14
|
return params.with ?? context.withParams?.basket ?? MIN_WITH_PARAMS_BASKET;
|
|
@@ -62,16 +63,22 @@ export const addItemToBasket = async function addItemToBasket2({
|
|
|
62
63
|
}
|
|
63
64
|
);
|
|
64
65
|
if (result.type === "success") {
|
|
65
|
-
return result.basket;
|
|
66
|
+
return { basket: result.basket };
|
|
67
|
+
} else if (result.type === "failure" && wasAddedWithReducedQuantity(result.errors)) {
|
|
68
|
+
return {
|
|
69
|
+
basket: result.basket,
|
|
70
|
+
errors: result.errors
|
|
71
|
+
};
|
|
66
72
|
} else {
|
|
67
73
|
const { message, statusCode } = parseBasketError(result);
|
|
68
74
|
context.log.error("Adding item to basket failed", { message, statusCode });
|
|
69
75
|
return new ErrorResponse(
|
|
70
|
-
|
|
76
|
+
HttpStatusCode.BAD_REQUEST,
|
|
71
77
|
SAPI_ERROR_NAME,
|
|
72
78
|
"Adding item to basket failed",
|
|
73
79
|
{
|
|
74
|
-
detail: message
|
|
80
|
+
detail: message,
|
|
81
|
+
errors: result.errors
|
|
75
82
|
}
|
|
76
83
|
);
|
|
77
84
|
}
|
|
@@ -113,7 +120,12 @@ export const addItemsToBasket = async function addItemsToBasket2(params, context
|
|
|
113
120
|
}
|
|
114
121
|
);
|
|
115
122
|
if (result.type === "success") {
|
|
116
|
-
return result.basket;
|
|
123
|
+
return { basket: result.basket };
|
|
124
|
+
} else if (result.type === "failure" && wasAddedWithReducedQuantity(result.errors)) {
|
|
125
|
+
return {
|
|
126
|
+
basket: result.basket,
|
|
127
|
+
errors: result.errors
|
|
128
|
+
};
|
|
117
129
|
} else {
|
|
118
130
|
const { statusCode, message } = parseBasketError(result);
|
|
119
131
|
context.log.error("Adding one or more items to basket failed", {
|
|
@@ -121,11 +133,12 @@ export const addItemsToBasket = async function addItemsToBasket2(params, context
|
|
|
121
133
|
message
|
|
122
134
|
});
|
|
123
135
|
return new ErrorResponse(
|
|
124
|
-
|
|
136
|
+
HttpStatusCode.BAD_REQUEST,
|
|
125
137
|
SAPI_ERROR_NAME,
|
|
126
138
|
"Adding one or more items to basket failed",
|
|
127
139
|
{
|
|
128
|
-
detail: message
|
|
140
|
+
detail: message,
|
|
141
|
+
errors: result.errors
|
|
129
142
|
}
|
|
130
143
|
);
|
|
131
144
|
}
|
|
@@ -160,7 +173,7 @@ export const getBasket = async function getBasket2(options, context) {
|
|
|
160
173
|
}
|
|
161
174
|
);
|
|
162
175
|
}
|
|
163
|
-
return response.basket;
|
|
176
|
+
return { basket: response.basket };
|
|
164
177
|
};
|
|
165
178
|
export const removeItemFromBasket = async function removeItemFromBasket2(options, context) {
|
|
166
179
|
if (!hasSession(context)) {
|
|
@@ -172,19 +185,24 @@ export const removeItemFromBasket = async function removeItemFromBasket2(options
|
|
|
172
185
|
}
|
|
173
186
|
const { sapiClient, campaignKey, basketKey } = context;
|
|
174
187
|
const resolvedWith = getWithParams(options, context);
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
188
|
+
const basket = await sapiClient.basket.deleteItem(
|
|
189
|
+
basketKey,
|
|
190
|
+
options.itemKey,
|
|
191
|
+
{
|
|
192
|
+
with: resolvedWith,
|
|
193
|
+
campaignKey,
|
|
194
|
+
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData,
|
|
195
|
+
orderCustomData: options.orderCustomData
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
return { basket };
|
|
181
199
|
};
|
|
182
200
|
export const clearBasket = async function clearBasket2(context) {
|
|
183
201
|
const getBasketResponse = await getBasket({}, context);
|
|
184
202
|
if (getBasketResponse instanceof ErrorResponse) {
|
|
185
203
|
return getBasketResponse;
|
|
186
204
|
}
|
|
187
|
-
const basket = await unwrap(getBasketResponse);
|
|
205
|
+
const { basket } = await unwrap(getBasketResponse);
|
|
188
206
|
await Promise.all(
|
|
189
207
|
basket.items.map(async (item) => {
|
|
190
208
|
await removeItemFromBasket({ itemKey: item.key }, context);
|
|
@@ -2,4 +2,4 @@ import { ErrorResponse } from '../../errors';
|
|
|
2
2
|
import type { Order, RpcContext } from '../../types';
|
|
3
3
|
export declare const getOrderDataByCbd: ({ cbdToken }: {
|
|
4
4
|
cbdToken: string;
|
|
5
|
-
}, context: RpcContext) => Promise<
|
|
5
|
+
}, context: RpcContext) => Promise<ErrorResponse | Order>;
|
|
@@ -37,7 +37,7 @@ const getCheckoutToken = exports.getCheckoutToken = async function getCheckoutTo
|
|
|
37
37
|
carrier,
|
|
38
38
|
basketId: context.basketKey,
|
|
39
39
|
campaignKey: context.campaignKey
|
|
40
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"
|
|
40
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.0.0"}`).setProtectedHeader({
|
|
41
41
|
alg: "HS256",
|
|
42
42
|
typ: "JWT"
|
|
43
43
|
}).sign(secret);
|
|
@@ -35,7 +35,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
|
|
|
35
35
|
carrier,
|
|
36
36
|
basketId: context.basketKey,
|
|
37
37
|
campaignKey: context.campaignKey
|
|
38
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"
|
|
38
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.0.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
|
|
39
39
|
return {
|
|
40
40
|
accessToken: refreshedAccessToken,
|
|
41
41
|
checkoutJwt
|
|
@@ -2,4 +2,4 @@ import { ErrorResponse } from '../../../errors';
|
|
|
2
2
|
import type { Order } from '../../../types';
|
|
3
3
|
export declare const getOrderById: ({ orderId }: {
|
|
4
4
|
orderId: number;
|
|
5
|
-
}, context: import("../../../types").RpcContext) => Promise<
|
|
5
|
+
}, context: import("../../../types").RpcContext) => Promise<ErrorResponse | Order>;
|
|
@@ -51,8 +51,7 @@ const handleIDPLoginCallback = exports.handleIDPLoginCallback = async function h
|
|
|
51
51
|
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
52
52
|
}
|
|
53
53
|
const OAuthClient = (0, _oauth.getOAuthClient)(context);
|
|
54
|
-
const
|
|
55
|
-
const tokens = await OAuthClient.generateToken(code);
|
|
54
|
+
const tokens = await OAuthClient.generateToken(payload.code);
|
|
56
55
|
await (0, _session.postLogin)(context, tokens);
|
|
57
56
|
return {
|
|
58
57
|
message: "success"
|
|
@@ -7,6 +7,6 @@ export declare const getExternalIdpRedirect: ({ queryParams }: {
|
|
|
7
7
|
}>;
|
|
8
8
|
export declare const handleIDPLoginCallback: (payload: {
|
|
9
9
|
code: string;
|
|
10
|
-
}
|
|
10
|
+
}, context: RpcContext) => Promise<ErrorResponse | {
|
|
11
11
|
message: string;
|
|
12
12
|
}>;
|
|
@@ -54,8 +54,7 @@ export const handleIDPLoginCallback = async function handleIDPLoginCallback2(pay
|
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
56
|
const OAuthClient = getOAuthClient(context);
|
|
57
|
-
const
|
|
58
|
-
const tokens = await OAuthClient.generateToken(code);
|
|
57
|
+
const tokens = await OAuthClient.generateToken(payload.code);
|
|
59
58
|
await postLogin(context, tokens);
|
|
60
59
|
return {
|
|
61
60
|
message: "success"
|
|
@@ -3,38 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
var _constants = require("../../constants/index.cjs");
|
|
8
|
-
var _stringHelpers = require("../../helpers/stringHelpers.cjs");
|
|
9
|
-
const getCategoryId = async (cached, sapiClient, slug) => {
|
|
10
|
-
if (!slug) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const sanitizedPath = (0, _stringHelpers.splitAndRemoveEmpty)(slug);
|
|
14
|
-
const result = await cached(sapiClient.categories.getByPath, {
|
|
15
|
-
cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
|
|
16
|
-
})(sanitizedPath);
|
|
17
|
-
return result.id;
|
|
18
|
-
};
|
|
19
|
-
const searchProducts = exports.searchProducts = async function searchProducts2({
|
|
20
|
-
term,
|
|
21
|
-
slug,
|
|
22
|
-
with: _with,
|
|
23
|
-
productLimit
|
|
24
|
-
}, {
|
|
25
|
-
cached,
|
|
26
|
-
sapiClient,
|
|
27
|
-
withParams
|
|
28
|
-
}) {
|
|
29
|
-
const categoryId = await getCategoryId(cached, sapiClient, slug);
|
|
30
|
-
return await cached(sapiClient.typeahead.suggestions, {
|
|
31
|
-
cacheKeyPrefix: `typeahead-suggestions-${term}`
|
|
32
|
-
})(term, {
|
|
33
|
-
productLimit,
|
|
34
|
-
categoryId,
|
|
35
|
-
with: _with ?? withParams?.search ?? _constants.MIN_WITH_PARAMS_SEARCH
|
|
36
|
-
});
|
|
37
|
-
};
|
|
6
|
+
exports.resolveSearch = exports.getSearchSuggestions = void 0;
|
|
38
7
|
const getSearchSuggestions = exports.getSearchSuggestions = async function getSearchSuggestions2({
|
|
39
8
|
term,
|
|
40
9
|
with: _with,
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import type { TypeaheadSuggestionsEndpointRequestParameters, TypeaheadSuggestionsEndpointResponseData } from '@scayle/storefront-api';
|
|
2
1
|
import type { SearchV2ResolveEndpointParameters, SearchV2SuggestionsEndpointParameters, SearchV2SuggestionsEndpointResponseData } from '../../types/sapi/search';
|
|
3
|
-
type SearchWith = TypeaheadSuggestionsEndpointRequestParameters['with'];
|
|
4
|
-
/** @deprecated `searchProducts` is deprecated. Please, use `getSuggestions` or `resolve` RPC methods */
|
|
5
|
-
export declare const searchProducts: ({ term, slug, with: _with, productLimit }: {
|
|
6
|
-
term: string;
|
|
7
|
-
slug?: string;
|
|
8
|
-
with?: SearchWith;
|
|
9
|
-
productLimit?: number;
|
|
10
|
-
}, { cached, sapiClient, withParams }: import("../../types").RpcContext) => Promise<TypeaheadSuggestionsEndpointResponseData>;
|
|
11
2
|
export declare const getSearchSuggestions: ({ term, with: _with, categoryId }: SearchV2SuggestionsEndpointParameters, { sapiClient, withParams }: import("../../types").RpcContext) => Promise<SearchV2SuggestionsEndpointResponseData>;
|
|
12
3
|
export declare const resolveSearch: ({ term, with: _with, categoryId }: SearchV2ResolveEndpointParameters, { cached, sapiClient, withParams }: import("../../types").RpcContext) => Promise<import("@scayle/storefront-api").SearchEntity | null>;
|
|
13
|
-
export {};
|
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
import { MIN_WITH_PARAMS_SEARCH } from "../../constants/index.mjs";
|
|
2
|
-
import { splitAndRemoveEmpty } from "../../helpers/stringHelpers.mjs";
|
|
3
|
-
const getCategoryId = async (cached, sapiClient, slug) => {
|
|
4
|
-
if (!slug) {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
const sanitizedPath = splitAndRemoveEmpty(slug);
|
|
8
|
-
const result = await cached(sapiClient.categories.getByPath, {
|
|
9
|
-
cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
|
|
10
|
-
})(sanitizedPath);
|
|
11
|
-
return result.id;
|
|
12
|
-
};
|
|
13
|
-
export const searchProducts = async function searchProducts2({ term, slug, with: _with, productLimit }, { cached, sapiClient, withParams }) {
|
|
14
|
-
const categoryId = await getCategoryId(cached, sapiClient, slug);
|
|
15
|
-
return await cached(sapiClient.typeahead.suggestions, {
|
|
16
|
-
cacheKeyPrefix: `typeahead-suggestions-${term}`
|
|
17
|
-
})(term, {
|
|
18
|
-
productLimit,
|
|
19
|
-
categoryId,
|
|
20
|
-
with: _with ?? withParams?.search ?? MIN_WITH_PARAMS_SEARCH
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
1
|
export const getSearchSuggestions = async function getSearchSuggestions2({ term, with: _with, categoryId }, { sapiClient, withParams }) {
|
|
24
2
|
return await sapiClient.searchv2.suggestions(
|
|
25
3
|
term,
|
|
@@ -12,16 +12,12 @@ var _errors = require("../../errors/index.cjs");
|
|
|
12
12
|
var _fetch = require("../../utils/fetch.cjs");
|
|
13
13
|
const getUser = exports.getUser = function getUser2(context) {
|
|
14
14
|
const {
|
|
15
|
-
user
|
|
16
|
-
accessToken,
|
|
17
|
-
shopId
|
|
15
|
+
user
|
|
18
16
|
} = context;
|
|
19
17
|
if (user) {
|
|
20
18
|
user.authentication = user.authentication ?? {
|
|
21
19
|
type: "idp"
|
|
22
20
|
};
|
|
23
|
-
user.authentication.storefrontAccessToken = accessToken;
|
|
24
|
-
user.loginShopId = shopId;
|
|
25
21
|
}
|
|
26
22
|
return {
|
|
27
23
|
user
|
|
@@ -40,8 +36,6 @@ const fetchUser = exports.fetchUser = async function fetchUser2({
|
|
|
40
36
|
type: "idp"
|
|
41
37
|
};
|
|
42
38
|
}
|
|
43
|
-
user.authentication.storefrontAccessToken = accessToken;
|
|
44
|
-
user.loginShopId = shopId;
|
|
45
39
|
return user;
|
|
46
40
|
};
|
|
47
41
|
const refreshUser = exports.refreshUser = async function refreshUser2(context) {
|
|
@@ -73,6 +67,8 @@ const refreshUser = exports.refreshUser = async function refreshUser2(context) {
|
|
|
73
67
|
};
|
|
74
68
|
const getAccessToken = exports.getAccessToken = async function getAccessToken2({
|
|
75
69
|
forceTokenRefresh = false
|
|
70
|
+
} = {
|
|
71
|
+
forceTokenRefresh: false
|
|
76
72
|
}, context) {
|
|
77
73
|
if (!(0, _types.hasSession)(context)) {
|
|
78
74
|
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
@@ -94,14 +90,6 @@ const getAccessToken = exports.getAccessToken = async function getAccessToken2({
|
|
|
94
90
|
accessToken: tokens.access_token,
|
|
95
91
|
refreshToken: tokens.refresh_token
|
|
96
92
|
});
|
|
97
|
-
try {
|
|
98
|
-
const user = await fetchUser({
|
|
99
|
-
accessToken: tokens.access_token
|
|
100
|
-
}, context);
|
|
101
|
-
context.updateUser(user);
|
|
102
|
-
} catch {
|
|
103
|
-
context.log.debug("Failed to update user");
|
|
104
|
-
}
|
|
105
93
|
} catch (e) {
|
|
106
94
|
if (e instanceof _fetch.FetchError && e.response.status === _constants.HttpStatusCode.UNAUTHORIZED) {
|
|
107
95
|
context.log.debug("Failed to refresh Checkout Token due to invalid refresh token. Deleting session");
|
|
@@ -19,5 +19,5 @@ declare const refreshUser: (context: RpcContext) => Promise<ErrorResponse | {
|
|
|
19
19
|
}>;
|
|
20
20
|
declare const getAccessToken: ({ forceTokenRefresh }: {
|
|
21
21
|
forceTokenRefresh?: boolean;
|
|
22
|
-
}, context: RpcContext) => Promise<string | ErrorResponse>;
|
|
22
|
+
} | undefined, context: RpcContext) => Promise<string | ErrorResponse>;
|
|
23
23
|
export { getUser, fetchUser, refreshUser, getAccessToken };
|
|
@@ -5,13 +5,11 @@ import { HttpStatusCode, HttpStatusMessage } from "../../constants/index.mjs";
|
|
|
5
5
|
import { ErrorResponse } from "../../errors/index.mjs";
|
|
6
6
|
import { FetchError } from "../../utils/fetch.mjs";
|
|
7
7
|
const getUser = function getUser2(context) {
|
|
8
|
-
const { user
|
|
8
|
+
const { user } = context;
|
|
9
9
|
if (user) {
|
|
10
10
|
user.authentication = user.authentication ?? {
|
|
11
11
|
type: "idp"
|
|
12
12
|
};
|
|
13
|
-
user.authentication.storefrontAccessToken = accessToken;
|
|
14
|
-
user.loginShopId = shopId;
|
|
15
13
|
}
|
|
16
14
|
return {
|
|
17
15
|
user
|
|
@@ -26,8 +24,6 @@ const fetchUser = async function fetchUser2({ accessToken }, context) {
|
|
|
26
24
|
type: "idp"
|
|
27
25
|
};
|
|
28
26
|
}
|
|
29
|
-
user.authentication.storefrontAccessToken = accessToken;
|
|
30
|
-
user.loginShopId = shopId;
|
|
31
27
|
return user;
|
|
32
28
|
};
|
|
33
29
|
const refreshUser = async function refreshUser2(context) {
|
|
@@ -51,7 +47,7 @@ const refreshUser = async function refreshUser2(context) {
|
|
|
51
47
|
return { user: void 0 };
|
|
52
48
|
}
|
|
53
49
|
};
|
|
54
|
-
const getAccessToken = async function getAccessToken2({ forceTokenRefresh = false }, context) {
|
|
50
|
+
const getAccessToken = async function getAccessToken2({ forceTokenRefresh = false } = { forceTokenRefresh: false }, context) {
|
|
55
51
|
if (!hasSession(context)) {
|
|
56
52
|
return new ErrorResponse(
|
|
57
53
|
HttpStatusCode.BAD_REQUEST,
|
|
@@ -84,15 +80,6 @@ const getAccessToken = async function getAccessToken2({ forceTokenRefresh = fals
|
|
|
84
80
|
accessToken: tokens.access_token,
|
|
85
81
|
refreshToken: tokens.refresh_token
|
|
86
82
|
});
|
|
87
|
-
try {
|
|
88
|
-
const user = await fetchUser(
|
|
89
|
-
{ accessToken: tokens.access_token },
|
|
90
|
-
context
|
|
91
|
-
);
|
|
92
|
-
context.updateUser(user);
|
|
93
|
-
} catch {
|
|
94
|
-
context.log.debug("Failed to update user");
|
|
95
|
-
}
|
|
96
83
|
} catch (e) {
|
|
97
84
|
if (e instanceof FetchError && e.response.status === HttpStatusCode.UNAUTHORIZED) {
|
|
98
85
|
context.log.debug(
|
package/dist/server.cjs
CHANGED
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
|
-
createClient: true,
|
|
8
|
-
RedisCache: true,
|
|
9
7
|
UnstorageCache: true,
|
|
10
|
-
CACHE_TIMEOUT: true
|
|
11
|
-
initBapi: true
|
|
8
|
+
CACHE_TIMEOUT: true
|
|
12
9
|
};
|
|
13
10
|
Object.defineProperty(exports, "CACHE_TIMEOUT", {
|
|
14
11
|
enumerable: true,
|
|
@@ -16,34 +13,14 @@ Object.defineProperty(exports, "CACHE_TIMEOUT", {
|
|
|
16
13
|
return _cache.CACHE_TIMEOUT;
|
|
17
14
|
}
|
|
18
15
|
});
|
|
19
|
-
Object.defineProperty(exports, "RedisCache", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () {
|
|
22
|
-
return _redis.RedisCache;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
16
|
Object.defineProperty(exports, "UnstorageCache", {
|
|
26
17
|
enumerable: true,
|
|
27
18
|
get: function () {
|
|
28
19
|
return _unstorage.UnstorageCache;
|
|
29
20
|
}
|
|
30
21
|
});
|
|
31
|
-
Object.defineProperty(exports, "createClient", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: function () {
|
|
34
|
-
return _redis.createClient;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
Object.defineProperty(exports, "initBapi", {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
get: function () {
|
|
40
|
-
return _init.init;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
var _redis = require("./cache/providers/redis.cjs");
|
|
44
22
|
var _unstorage = require("./cache/providers/unstorage.cjs");
|
|
45
23
|
var _cache = require("./constants/cache.cjs");
|
|
46
|
-
var _init = require("./bapi/init.cjs");
|
|
47
24
|
var _customer = require("./api/customer.cjs");
|
|
48
25
|
Object.keys(_customer).forEach(function (key) {
|
|
49
26
|
if (key === "default" || key === "__esModule") return;
|
package/dist/server.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export { createClient, RedisCache } from './cache/providers/redis';
|
|
2
1
|
export { UnstorageCache } from './cache/providers/unstorage';
|
|
3
2
|
export { CACHE_TIMEOUT } from './constants/cache';
|
|
4
|
-
export type { RedisOptions } from './cache/providers/redis';
|
|
5
|
-
export { init as initBapi } from './bapi/init';
|
|
6
3
|
export * from './api/customer';
|
|
7
4
|
export * from './api/oauth';
|
package/dist/server.mjs
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export { createClient, RedisCache } from "./cache/providers/redis.mjs";
|
|
2
1
|
export { UnstorageCache } from "./cache/providers/unstorage.mjs";
|
|
3
2
|
export { CACHE_TIMEOUT } from "./constants/cache.mjs";
|
|
4
|
-
export { init as initBapi } from "./bapi/init.mjs";
|
|
5
3
|
export * from "./api/customer.mjs";
|
|
6
4
|
export * from "./api/oauth.mjs";
|
package/dist/types/api/auth.d.ts
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
import type { Gender } from '../user';
|
|
2
|
-
/**
|
|
3
|
-
* @deprecated
|
|
4
|
-
*/
|
|
5
|
-
export interface AuthConfig {
|
|
6
|
-
callback: string;
|
|
7
|
-
scopes?: string[];
|
|
8
|
-
accessToken?: string;
|
|
9
|
-
customData?: unknown;
|
|
10
|
-
}
|
|
11
2
|
export interface OAuthTokens {
|
|
12
3
|
accessToken: string;
|
|
13
4
|
refreshToken: string;
|
|
@@ -72,16 +72,8 @@ export type RpcContext = {
|
|
|
72
72
|
*/
|
|
73
73
|
cbdExpiration?: number;
|
|
74
74
|
};
|
|
75
|
-
/**
|
|
76
|
-
* @deprecated bapiClient got renamed. Use {@link RpcContext.sapiClient} from now on.
|
|
77
|
-
*/
|
|
78
|
-
bapiClient: StorefrontAPIClient;
|
|
79
75
|
sapiClient: StorefrontAPIClient;
|
|
80
76
|
cached: CachedType;
|
|
81
|
-
/**
|
|
82
|
-
* @deprecated this flag will be removed in a future release.
|
|
83
|
-
*/
|
|
84
|
-
isCmsPreview: boolean;
|
|
85
77
|
shopId: number;
|
|
86
78
|
domain: string;
|
|
87
79
|
withParams?: WithParams;
|
|
@@ -89,10 +81,6 @@ export type RpcContext = {
|
|
|
89
81
|
destroySessionsForUserId: (userId: number, sessionsToKeep?: string[]) => Promise<void>;
|
|
90
82
|
generateBasketKeyForUserId: (userId: string) => Promise<string>;
|
|
91
83
|
generateWishlistKeyForUserId: (userId: string) => Promise<string>;
|
|
92
|
-
/**
|
|
93
|
-
* @deprecated storeCampaignKeyword will be removed in a future release.
|
|
94
|
-
*/
|
|
95
|
-
storeCampaignKeyword?: string;
|
|
96
84
|
routerBasePath?: string;
|
|
97
85
|
ip?: string | undefined;
|
|
98
86
|
log: Log;
|
package/dist/types/user.d.ts
CHANGED
|
@@ -20,8 +20,6 @@ interface UserAuthentication {
|
|
|
20
20
|
accessToken?: string;
|
|
21
21
|
userId?: string;
|
|
22
22
|
};
|
|
23
|
-
/** @deprecated use `getAccessToken` RPC instead */
|
|
24
|
-
storefrontAccessToken?: string;
|
|
25
23
|
type: AuthenticationType;
|
|
26
24
|
}
|
|
27
25
|
export interface OrderSummary {
|
|
@@ -91,8 +89,6 @@ export interface ShopUser {
|
|
|
91
89
|
customData?: {
|
|
92
90
|
memberRoles?: MemberRole[];
|
|
93
91
|
};
|
|
94
|
-
/** @deprecated `loginShopId` is no longer needed, because each shop now has it's own session cookie */
|
|
95
|
-
loginShopId?: number;
|
|
96
92
|
}
|
|
97
93
|
export interface UseUserFacetParams {
|
|
98
94
|
userParams: UseUserParams;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.wasAddedWithReducedQuantity = void 0;
|
|
7
|
+
var _constants = require("../constants/index.cjs");
|
|
8
|
+
const wasAddedWithReducedQuantity = errors => {
|
|
9
|
+
if (!errors) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return errors.every(error => error.operation === "add" && error.kind === _constants.AddToBasketFailureKind.ItemAddedWithReducedQuantity || error.operation === "update" && error.kind === _constants.UpdateBasketItemFailureKind.ItemAddedWithReducedQuantity);
|
|
13
|
+
};
|
|
14
|
+
exports.wasAddedWithReducedQuantity = wasAddedWithReducedQuantity;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AddToBasketFailureKind,
|
|
3
|
+
UpdateBasketItemFailureKind
|
|
4
|
+
} from "../constants/index.mjs";
|
|
5
|
+
export const wasAddedWithReducedQuantity = (errors) => {
|
|
6
|
+
if (!errors) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
return errors.every(
|
|
10
|
+
(error) => error.operation === "add" && error.kind === AddToBasketFailureKind.ItemAddedWithReducedQuantity || error.operation === "update" && error.kind === UpdateBasketItemFailureKind.ItemAddedWithReducedQuantity
|
|
11
|
+
);
|
|
12
|
+
};
|
package/dist/utils/index.cjs
CHANGED
|
@@ -35,4 +35,15 @@ Object.keys(_fetch).forEach(function (key) {
|
|
|
35
35
|
return _fetch[key];
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
|
+
});
|
|
39
|
+
var _basket = require("./basket.cjs");
|
|
40
|
+
Object.keys(_basket).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _basket[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _basket[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
38
49
|
});
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.mjs
CHANGED
package/dist/utils/keys.cjs
CHANGED
|
@@ -8,7 +8,7 @@ var _hash = require("../constants/hash.cjs");
|
|
|
8
8
|
var _hash2 = require("./hash.cjs");
|
|
9
9
|
const generateKey = async ({
|
|
10
10
|
keyTemplate,
|
|
11
|
-
hashAlgorithm = _hash.HashAlgorithm.
|
|
11
|
+
hashAlgorithm = _hash.HashAlgorithm.SHA256,
|
|
12
12
|
shopId,
|
|
13
13
|
userId,
|
|
14
14
|
log
|
|
@@ -35,7 +35,7 @@ const generateKey = async ({
|
|
|
35
35
|
exports.generateKey = generateKey;
|
|
36
36
|
const generateWishlistKey = async ({
|
|
37
37
|
keyTemplate,
|
|
38
|
-
hashAlgorithm = _hash.HashAlgorithm.
|
|
38
|
+
hashAlgorithm = _hash.HashAlgorithm.SHA256,
|
|
39
39
|
shopId,
|
|
40
40
|
userId,
|
|
41
41
|
log
|
|
@@ -51,7 +51,7 @@ const generateWishlistKey = async ({
|
|
|
51
51
|
exports.generateWishlistKey = generateWishlistKey;
|
|
52
52
|
const generateBasketKey = async ({
|
|
53
53
|
keyTemplate,
|
|
54
|
-
hashAlgorithm = _hash.HashAlgorithm.
|
|
54
|
+
hashAlgorithm = _hash.HashAlgorithm.SHA256,
|
|
55
55
|
shopId,
|
|
56
56
|
userId,
|
|
57
57
|
log
|
package/dist/utils/keys.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { HashAlgorithm } from "../constants/hash.mjs";
|
|
|
2
2
|
import { md5, sha256 } from "./hash.mjs";
|
|
3
3
|
export const generateKey = async ({
|
|
4
4
|
keyTemplate,
|
|
5
|
-
hashAlgorithm = HashAlgorithm.
|
|
5
|
+
hashAlgorithm = HashAlgorithm.SHA256,
|
|
6
6
|
shopId,
|
|
7
7
|
userId,
|
|
8
8
|
log
|
|
@@ -26,7 +26,7 @@ export const generateKey = async ({
|
|
|
26
26
|
};
|
|
27
27
|
export const generateWishlistKey = async ({
|
|
28
28
|
keyTemplate,
|
|
29
|
-
hashAlgorithm = HashAlgorithm.
|
|
29
|
+
hashAlgorithm = HashAlgorithm.SHA256,
|
|
30
30
|
shopId,
|
|
31
31
|
userId,
|
|
32
32
|
log
|
|
@@ -41,7 +41,7 @@ export const generateWishlistKey = async ({
|
|
|
41
41
|
};
|
|
42
42
|
export const generateBasketKey = async ({
|
|
43
43
|
keyTemplate,
|
|
44
|
-
hashAlgorithm = HashAlgorithm.
|
|
44
|
+
hashAlgorithm = HashAlgorithm.SHA256,
|
|
45
45
|
shopId,
|
|
46
46
|
userId,
|
|
47
47
|
log
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Collection of essential utilities to work with the Storefront API",
|
|
5
5
|
"author": "SCAYLE Commerce Engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -83,20 +83,17 @@
|
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@scayle/eslint-config-storefront": "4.3.2",
|
|
85
85
|
"@types/crypto-js": "4.2.2",
|
|
86
|
-
"@types/node": "22.10.
|
|
86
|
+
"@types/node": "22.10.1",
|
|
87
87
|
"@types/webpack-env": "1.18.5",
|
|
88
|
-
"@vitest/coverage-v8": "2.1.
|
|
89
|
-
"dprint": "0.47.
|
|
90
|
-
"eslint": "9.
|
|
88
|
+
"@vitest/coverage-v8": "2.1.8",
|
|
89
|
+
"dprint": "0.47.6",
|
|
90
|
+
"eslint": "9.16.0",
|
|
91
91
|
"eslint-formatter-gitlab": "5.1.0",
|
|
92
92
|
"publint": "0.2.12",
|
|
93
93
|
"rimraf": "6.0.1",
|
|
94
94
|
"typescript": "5.6.3",
|
|
95
95
|
"unbuild": "2.0.0",
|
|
96
96
|
"unstorage": "1.13.1",
|
|
97
|
-
"vitest": "2.1.
|
|
98
|
-
},
|
|
99
|
-
"optionalDependencies": {
|
|
100
|
-
"redis": "4"
|
|
97
|
+
"vitest": "2.1.8"
|
|
101
98
|
}
|
|
102
99
|
}
|
package/dist/bapi/init.cjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.init = void 0;
|
|
7
|
-
var _storefrontApi = require("@scayle/storefront-api");
|
|
8
|
-
const init = config => {
|
|
9
|
-
return new _storefrontApi.StorefrontAPIClient({
|
|
10
|
-
host: config.host,
|
|
11
|
-
shopId: config.shopId,
|
|
12
|
-
auth: {
|
|
13
|
-
type: config.authentication,
|
|
14
|
-
token: config.token
|
|
15
|
-
},
|
|
16
|
-
additionalHeaders: config.additionalHeaders
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
exports.init = init;
|