@scayle/storefront-core 7.69.3 → 8.1.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 +209 -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/brands.cjs +3 -2
- package/dist/rpc/methods/brands.d.ts +2 -2
- package/dist/rpc/methods/brands.mjs +3 -2
- package/dist/rpc/methods/categories.cjs +3 -2
- package/dist/rpc/methods/categories.d.ts +2 -2
- package/dist/rpc/methods/categories.mjs +13 -6
- 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/products.cjs +4 -3
- package/dist/rpc/methods/products.d.ts +3 -3
- package/dist/rpc/methods/products.mjs +22 -12
- package/dist/rpc/methods/promotion.cjs +4 -3
- package/dist/rpc/methods/promotion.d.ts +3 -3
- package/dist/rpc/methods/promotion.mjs +9 -5
- package/dist/rpc/methods/search.cjs +3 -33
- package/dist/rpc/methods/search.d.ts +1 -11
- package/dist/rpc/methods/search.mjs +2 -23
- package/dist/rpc/methods/shopConfiguration.cjs +2 -1
- package/dist/rpc/methods/shopConfiguration.d.ts +1 -1
- package/dist/rpc/methods/shopConfiguration.mjs +7 -3
- 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/rpc/methods/variants.cjs +2 -1
- package/dist/rpc/methods/variants.d.ts +1 -1
- package/dist/rpc/methods/variants.mjs +7 -3
- package/dist/rpc/methods/wishlist.cjs +3 -2
- package/dist/rpc/methods/wishlist.d.ts +3 -4
- package/dist/rpc/methods/wishlist.mjs +17 -9
- 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/dist/utils/sapi.cjs +19 -0
- package/dist/utils/sapi.d.ts +5 -0
- package/dist/utils/sapi.mjs +13 -0
- 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
|
@@ -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(
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getVariantById = void 0;
|
|
7
|
+
var _sapi = require("../../utils/sapi.cjs");
|
|
7
8
|
const defaultWith = {
|
|
8
9
|
attributes: "all"
|
|
9
10
|
};
|
|
@@ -18,7 +19,7 @@ const getVariantById = exports.getVariantById = async function getVariantById2({
|
|
|
18
19
|
withParams
|
|
19
20
|
}) {
|
|
20
21
|
const resolvedWith = include ?? withParams?.variant ?? defaultWith;
|
|
21
|
-
return await cached(sapiClient.variants.getByIds, {
|
|
22
|
+
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.variants.getByIds), {
|
|
22
23
|
cacheKeyPrefix: "getByIds-variants"
|
|
23
24
|
})(ids, include ? {
|
|
24
25
|
with: resolvedWith,
|
|
@@ -5,4 +5,4 @@ export interface FetchVariantsParams {
|
|
|
5
5
|
include?: ProductWith;
|
|
6
6
|
pricePromotionKey?: string;
|
|
7
7
|
}
|
|
8
|
-
export declare const getVariantById: ({ ids, include, pricePromotionKey }: FetchVariantsParams, { sapiClient, cached, campaignKey, withParams }: RpcContext) => Promise<VariantDetail[]>;
|
|
8
|
+
export declare const getVariantById: ({ ids, include, pricePromotionKey }: FetchVariantsParams, { sapiClient, cached, campaignKey, withParams }: RpcContext) => Promise<Response | VariantDetail[]>;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
1
2
|
const defaultWith = {
|
|
2
3
|
attributes: "all"
|
|
3
4
|
};
|
|
4
5
|
export const getVariantById = async function getVariantById2({ ids, include = defaultWith, pricePromotionKey = "default" }, { sapiClient, cached, campaignKey, withParams }) {
|
|
5
6
|
const resolvedWith = include ?? withParams?.variant ?? defaultWith;
|
|
6
|
-
return await cached(
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
return await cached(
|
|
8
|
+
mapSAPIFetchErrorToResponse(sapiClient.variants.getByIds),
|
|
9
|
+
{
|
|
10
|
+
cacheKeyPrefix: "getByIds-variants"
|
|
11
|
+
}
|
|
12
|
+
)(
|
|
9
13
|
ids,
|
|
10
14
|
include ? { with: resolvedWith, campaignKey, pricePromotionKey } : void 0
|
|
11
15
|
);
|
|
@@ -8,6 +8,7 @@ var _types = require("../../types/index.cjs");
|
|
|
8
8
|
var _constants = require("../../constants/index.cjs");
|
|
9
9
|
var _response = require("../../utils/response.cjs");
|
|
10
10
|
var _errors = require("../../errors/index.cjs");
|
|
11
|
+
var _sapi = require("../../utils/sapi.cjs");
|
|
11
12
|
function getWithParams(params, context) {
|
|
12
13
|
return params.with ?? context.withParams?.wishlist ?? _constants.MIN_WITH_PARAMS_WISHLIST;
|
|
13
14
|
}
|
|
@@ -23,7 +24,7 @@ const getWishlist = exports.getWishlist = async function getWishlist2(options, c
|
|
|
23
24
|
const resolvedWith = getWithParams({
|
|
24
25
|
with: options
|
|
25
26
|
}, context);
|
|
26
|
-
return await sapiClient.wishlist.get(wishlistKey, {
|
|
27
|
+
return await (0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.wishlist.get)(wishlistKey, {
|
|
27
28
|
with: resolvedWith,
|
|
28
29
|
campaignKey,
|
|
29
30
|
pricePromotionKey: resolvedWith?.pricePromotionKey ?? ""
|
|
@@ -83,7 +84,7 @@ const removeItemFromWishlist = exports.removeItemFromWishlist = async function r
|
|
|
83
84
|
wishlistKey
|
|
84
85
|
} = context;
|
|
85
86
|
const resolvedWith = getWithParams(options, context);
|
|
86
|
-
return await sapiClient.wishlist.deleteItem(wishlistKey, options.itemKey, {
|
|
87
|
+
return await (0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.wishlist.deleteItem)(wishlistKey, options.itemKey, {
|
|
87
88
|
with: resolvedWith,
|
|
88
89
|
campaignKey
|
|
89
90
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Wishlist } from '@scayle/storefront-api';
|
|
2
2
|
import type { RpcContext, WishlistWithOptions } from '../../types';
|
|
3
|
-
|
|
4
|
-
export declare const getWishlist: (options: WishlistWithOptions | undefined, context: RpcContext) => Promise<ErrorResponse | Wishlist>;
|
|
3
|
+
export declare const getWishlist: (options: WishlistWithOptions | undefined, context: RpcContext) => Promise<Response | Wishlist>;
|
|
5
4
|
export declare const addItemToWishlist: (options: {
|
|
6
5
|
variantId?: number;
|
|
7
6
|
productId?: number;
|
|
@@ -10,5 +9,5 @@ export declare const addItemToWishlist: (options: {
|
|
|
10
9
|
export declare const removeItemFromWishlist: (options: {
|
|
11
10
|
itemKey: string;
|
|
12
11
|
with?: WishlistWithOptions;
|
|
13
|
-
}, context: RpcContext) => Promise<
|
|
14
|
-
export declare const clearWishlist: (context: RpcContext) => Promise<
|
|
12
|
+
}, context: RpcContext) => Promise<Response | Wishlist>;
|
|
13
|
+
export declare const clearWishlist: (context: RpcContext) => Promise<Response | Wishlist>;
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "../../constants/index.mjs";
|
|
7
7
|
import { unwrap } from "../../utils/response.mjs";
|
|
8
8
|
import { ErrorResponse } from "../../errors/index.mjs";
|
|
9
|
+
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
9
10
|
function getWithParams(params, context) {
|
|
10
11
|
return params.with ?? context.withParams?.wishlist ?? MIN_WITH_PARAMS_WISHLIST;
|
|
11
12
|
}
|
|
@@ -19,11 +20,14 @@ export const getWishlist = async function getWishlist2(options, context) {
|
|
|
19
20
|
}
|
|
20
21
|
const { sapiClient, campaignKey, wishlistKey } = context;
|
|
21
22
|
const resolvedWith = getWithParams({ with: options }, context);
|
|
22
|
-
return await sapiClient.wishlist.get(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
return await mapSAPIFetchErrorToResponse(sapiClient.wishlist.get)(
|
|
24
|
+
wishlistKey,
|
|
25
|
+
{
|
|
26
|
+
with: resolvedWith,
|
|
27
|
+
campaignKey,
|
|
28
|
+
pricePromotionKey: resolvedWith?.pricePromotionKey ?? ""
|
|
29
|
+
}
|
|
30
|
+
);
|
|
27
31
|
};
|
|
28
32
|
export const addItemToWishlist = async function addItemToWishlist2(options, context) {
|
|
29
33
|
if (!hasSession(context)) {
|
|
@@ -71,10 +75,14 @@ export const removeItemFromWishlist = async function removeItemFromWishlist2(opt
|
|
|
71
75
|
}
|
|
72
76
|
const { sapiClient, campaignKey, wishlistKey } = context;
|
|
73
77
|
const resolvedWith = getWithParams(options, context);
|
|
74
|
-
return await sapiClient.wishlist.deleteItem(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
return await mapSAPIFetchErrorToResponse(sapiClient.wishlist.deleteItem)(
|
|
79
|
+
wishlistKey,
|
|
80
|
+
options.itemKey,
|
|
81
|
+
{
|
|
82
|
+
with: resolvedWith,
|
|
83
|
+
campaignKey
|
|
84
|
+
}
|
|
85
|
+
);
|
|
78
86
|
};
|
|
79
87
|
export const clearWishlist = async function clearWishlist2(context) {
|
|
80
88
|
const wishlistResponse = await getWishlist({}, context);
|
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
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.mapSAPIFetchErrorToResponse = mapSAPIFetchErrorToResponse;
|
|
7
|
+
var _storefrontApi = require("@scayle/storefront-api");
|
|
8
|
+
function mapSAPIFetchErrorToResponse(func) {
|
|
9
|
+
return async (...args) => {
|
|
10
|
+
try {
|
|
11
|
+
return await func(...args);
|
|
12
|
+
} catch (e) {
|
|
13
|
+
if (e instanceof _storefrontApi.FetchError) {
|
|
14
|
+
return e.response;
|
|
15
|
+
}
|
|
16
|
+
throw e;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrap a SAPI API function, catching any SAPI FetchErrors thrown
|
|
3
|
+
* and translating them to a Response return
|
|
4
|
+
*/
|
|
5
|
+
export declare function mapSAPIFetchErrorToResponse<T extends (...args: any) => any>(func: T): (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>> | Response>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FetchError } from "@scayle/storefront-api";
|
|
2
|
+
export function mapSAPIFetchErrorToResponse(func) {
|
|
3
|
+
return async (...args) => {
|
|
4
|
+
try {
|
|
5
|
+
return await func(...args);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
if (e instanceof FetchError) {
|
|
8
|
+
return e.response;
|
|
9
|
+
}
|
|
10
|
+
throw e;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.1.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;
|
package/dist/bapi/init.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { StorefrontAPIClient } from '@scayle/storefront-api';
|
|
2
|
-
interface StorefrontAPIConfig {
|
|
3
|
-
host: string;
|
|
4
|
-
shopId: number;
|
|
5
|
-
authentication: 'token';
|
|
6
|
-
token: string;
|
|
7
|
-
additionalHeaders: HeadersInit;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Create a new Storefront API Client.
|
|
11
|
-
*
|
|
12
|
-
* @deprecated
|
|
13
|
-
*/
|
|
14
|
-
export declare const init: (config: StorefrontAPIConfig) => StorefrontAPIClient;
|
|
15
|
-
export {};
|
package/dist/bapi/init.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { StorefrontAPIClient } from "@scayle/storefront-api";
|
|
2
|
-
export const init = (config) => {
|
|
3
|
-
return new StorefrontAPIClient({
|
|
4
|
-
host: config.host,
|
|
5
|
-
shopId: config.shopId,
|
|
6
|
-
auth: {
|
|
7
|
-
type: config.authentication,
|
|
8
|
-
token: config.token
|
|
9
|
-
},
|
|
10
|
-
additionalHeaders: config.additionalHeaders
|
|
11
|
-
});
|
|
12
|
-
};
|