@scayle/storefront-core 8.8.0 → 8.9.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 +24 -0
- package/dist/index.d.ts +2 -0
- package/dist/rpc/methods/basket/basket.mjs +4 -5
- package/dist/rpc/methods/checkout/checkout.d.ts +2 -3
- package/dist/rpc/methods/checkout/checkout.mjs +2 -3
- package/dist/rpc/methods/products.d.ts +9 -28
- package/dist/rpc/methods/products.mjs +7 -8
- package/dist/rpc/methods/variants.d.ts +2 -2
- package/dist/rpc/methods/variants.mjs +1 -2
- package/dist/rpc/methods/wishlist.d.ts +7 -7
- package/dist/rpc/methods/wishlist.mjs +3 -4
- package/dist/types/api/context.d.ts +21 -1
- package/dist/utils/campaign.d.ts +25 -10
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
# @scayle/storefront-core
|
|
2
2
|
|
|
3
|
+
## 8.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Extend `RpcContext` with an `rpcCall` property. This is a utility function that can be used within RPC methods to invoke another RPC method.
|
|
8
|
+
|
|
3
9
|
## 8.8.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
6
12
|
|
|
7
13
|
- Deprecate `RpcContext.campaignKey`. The `getCampaignKey` RPC should be used instead.
|
|
8
14
|
|
|
15
|
+
To get the default campaign key, you can call the RPC method:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
// Before
|
|
19
|
+
async function rpcMethod(context) {
|
|
20
|
+
const campaignKey = { context }
|
|
21
|
+
// ...
|
|
22
|
+
}
|
|
23
|
+
// After
|
|
24
|
+
async function rpcMethod(context) {
|
|
25
|
+
const campaignKey = await context.callRpc?.('getCampaignKey')
|
|
26
|
+
// ...
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
To override the default campaign key, override the getCampaignKey RPC with your own implementation.
|
|
31
|
+
See [Overriding core RPC Methods](https://scayle.dev/en/storefront-guide/developer-guide/basic-setup/rpc-methods#overriding-core-rpc-methods) for more.
|
|
32
|
+
|
|
9
33
|
## 8.7.1
|
|
10
34
|
|
|
11
35
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as rpcMethods from './rpc/methods';
|
|
2
|
+
import type { RpcContext } from './types';
|
|
2
3
|
export { rpcMethods };
|
|
3
4
|
export * from './errors';
|
|
4
5
|
export * from './utils';
|
|
@@ -65,4 +66,5 @@ export type RpcMethodParameters<N extends RpcMethodName> = Parameters<RpcMethod<
|
|
|
65
66
|
* @template N The name of the RPC method.
|
|
66
67
|
*/
|
|
67
68
|
export type RpcMethodReturnType<N extends RpcMethodName> = ReturnType<RpcMethod<N>>;
|
|
69
|
+
export type RpcMethodCall = <N extends RpcMethodName, P extends RpcMethodParameters<N>, TResult extends Exclude<Awaited<RpcMethodReturnType<N>>, Response>>(...args: P extends RpcContext ? [N] : [N, P]) => TResult;
|
|
68
70
|
export { ExistingItemHandling, AddToBasketFailureKind, UpdateBasketItemFailureKind, AddToWishlistFailureKind, PromotionEffectType, FilterTypes, APISortOption, APISortOrder, type ProductSortConfig, } from '@scayle/storefront-api';
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
import { mergeBaskets as mergeBasketFunction } from "../../../utils/user.mjs";
|
|
10
10
|
import { unwrap } from "../../../utils/response.mjs";
|
|
11
11
|
import { wasAddedWithReducedQuantity } from "../../../utils/index.mjs";
|
|
12
|
-
import { getCampaignKey } from "../campaign.mjs";
|
|
13
12
|
const SAPI_ERROR_NAME = "SAPI ERROR";
|
|
14
13
|
function getWithParams(params, context) {
|
|
15
14
|
return params.with ?? context.withParams?.basket ?? MIN_WITH_PARAMS_BASKET;
|
|
@@ -33,7 +32,7 @@ export const addItemToBasket = async function addItemToBasket2({
|
|
|
33
32
|
);
|
|
34
33
|
}
|
|
35
34
|
const { sapiClient, basketKey } = context;
|
|
36
|
-
const campaignKey = await getCampaignKey
|
|
35
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
37
36
|
const resolvedWith = getWithParams(
|
|
38
37
|
{ with: _with },
|
|
39
38
|
context
|
|
@@ -94,7 +93,7 @@ export const addItemsToBasket = async function addItemsToBasket2(params, context
|
|
|
94
93
|
);
|
|
95
94
|
}
|
|
96
95
|
const { sapiClient, basketKey } = context;
|
|
97
|
-
const campaignKey = await getCampaignKey
|
|
96
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
98
97
|
const resolvedWith = getWithParams(params, context);
|
|
99
98
|
const itemsToBeAddedOrUpdated = params.items.map((item) => ({
|
|
100
99
|
variantId: item.variantId,
|
|
@@ -155,7 +154,7 @@ export const getBasket = async function getBasket2(options, context) {
|
|
|
155
154
|
);
|
|
156
155
|
}
|
|
157
156
|
const { sapiClient, basketKey } = context;
|
|
158
|
-
const campaignKey = await getCampaignKey
|
|
157
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
159
158
|
const resolvedWith = getWithParams(
|
|
160
159
|
{ with: options },
|
|
161
160
|
context
|
|
@@ -188,7 +187,7 @@ export const removeItemFromBasket = async function removeItemFromBasket2(options
|
|
|
188
187
|
);
|
|
189
188
|
}
|
|
190
189
|
const { sapiClient, basketKey } = context;
|
|
191
|
-
const campaignKey = await getCampaignKey
|
|
190
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
192
191
|
const resolvedWith = getWithParams(options, context);
|
|
193
192
|
const basket = await sapiClient.basket.deleteItem(
|
|
194
193
|
basketKey,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { RpcContext } from '../../../types';
|
|
1
|
+
import type { RpcHandler } from '../../../types';
|
|
3
2
|
interface CheckoutJwtPayload {
|
|
4
3
|
voucher?: string;
|
|
5
4
|
customData?: Record<string, unknown>;
|
|
@@ -9,7 +8,7 @@ interface CheckoutJwtPayload {
|
|
|
9
8
|
};
|
|
10
9
|
carrier?: string;
|
|
11
10
|
}
|
|
12
|
-
export declare const getCheckoutToken:
|
|
11
|
+
export declare const getCheckoutToken: RpcHandler<CheckoutJwtPayload | undefined, {
|
|
13
12
|
accessToken: string;
|
|
14
13
|
checkoutJwt: string;
|
|
15
14
|
}>;
|
|
@@ -3,7 +3,6 @@ import { hasSession } from "../../../types/index.mjs";
|
|
|
3
3
|
import { ErrorResponse } from "../../../errors/index.mjs";
|
|
4
4
|
import { HttpStatusCode, HttpStatusMessage } from "../../../constants/index.mjs";
|
|
5
5
|
import { getAccessToken } from "../user.mjs";
|
|
6
|
-
import { getCampaignKey } from "../campaign.mjs";
|
|
7
6
|
export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}, context) {
|
|
8
7
|
if (!hasSession(context)) {
|
|
9
8
|
return new ErrorResponse(
|
|
@@ -29,7 +28,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
|
|
|
29
28
|
const secret = new TextEncoder().encode(context.checkout.secret);
|
|
30
29
|
const now = /* @__PURE__ */ new Date();
|
|
31
30
|
const { voucher, customData, preferredCollectionPoint, carrier } = jwtPayload;
|
|
32
|
-
const campaignKey = await getCampaignKey
|
|
31
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
33
32
|
const checkoutJwt = await new SignJWT({
|
|
34
33
|
voucher,
|
|
35
34
|
customData,
|
|
@@ -37,7 +36,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
|
|
|
37
36
|
carrier,
|
|
38
37
|
basketId: context.basketKey,
|
|
39
38
|
campaignKey
|
|
40
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.
|
|
39
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.9.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
|
|
41
40
|
return {
|
|
42
41
|
accessToken: refreshedAccessToken,
|
|
43
42
|
checkoutJwt
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { FetchFiltersParams, FetchProductParams, FetchProductsByCategoryParams, FetchProductsByIdsParams, FetchProductsByReferenceKeysParams, FetchProductsCountParams, Product, RpcContext } from '../../types';
|
|
3
|
-
import { ErrorResponse } from '../../errors';
|
|
1
|
+
import type { FetchFiltersParams, FetchFiltersResponse, FetchProductParams, FetchProductsByCategoryParams, FetchProductsByCategoryResponse, FetchProductsByIdsParams, FetchProductsByReferenceKeysParams, FetchProductsCountParams, FetchProductsCountResponse, Product, RpcContext, RpcHandler } from '../../types';
|
|
4
2
|
/**
|
|
5
3
|
* For functions which accept either a category path or category ID,
|
|
6
4
|
* this function can resolve the ID which is necessary for the calling
|
|
@@ -20,32 +18,15 @@ export declare function resolveCategoryIdFromParams(context: RpcContext, params:
|
|
|
20
18
|
category: string | undefined;
|
|
21
19
|
categoryId: number | undefined;
|
|
22
20
|
}>;
|
|
23
|
-
export declare const getProductById:
|
|
24
|
-
export declare const getProductsByIds:
|
|
25
|
-
export declare const getProductsByReferenceKeys:
|
|
26
|
-
export declare const getProductsCount:
|
|
27
|
-
|
|
28
|
-
}>;
|
|
29
|
-
export declare const fetchAllFiltersForCategory: ({ includedFilters, category }: {
|
|
21
|
+
export declare const getProductById: RpcHandler<FetchProductParams, Product>;
|
|
22
|
+
export declare const getProductsByIds: RpcHandler<FetchProductsByIdsParams, Product[]>;
|
|
23
|
+
export declare const getProductsByReferenceKeys: RpcHandler<FetchProductsByReferenceKeysParams, Product[]>;
|
|
24
|
+
export declare const getProductsCount: RpcHandler<FetchProductsCountParams, FetchProductsCountResponse>;
|
|
25
|
+
export declare const fetchAllFiltersForCategory: RpcHandler<{
|
|
30
26
|
includedFilters?: string[];
|
|
31
27
|
category: {
|
|
32
28
|
id?: number;
|
|
33
29
|
};
|
|
34
|
-
},
|
|
35
|
-
export declare const getFilters:
|
|
36
|
-
|
|
37
|
-
unfilteredCount: number;
|
|
38
|
-
}>;
|
|
39
|
-
export declare const getProductsByCategory: (params: FetchProductsByCategoryParams, context: RpcContext) => Promise<(string[] & ErrorResponse) | {
|
|
40
|
-
products: Product[];
|
|
41
|
-
pagination: {
|
|
42
|
-
current: number;
|
|
43
|
-
total: number;
|
|
44
|
-
perPage: number;
|
|
45
|
-
page: number;
|
|
46
|
-
first: number;
|
|
47
|
-
prev: number;
|
|
48
|
-
next: number;
|
|
49
|
-
last: number;
|
|
50
|
-
};
|
|
51
|
-
}>;
|
|
30
|
+
}, string[]>;
|
|
31
|
+
export declare const getFilters: RpcHandler<FetchFiltersParams, FetchFiltersResponse>;
|
|
32
|
+
export declare const getProductsByCategory: RpcHandler<FetchProductsByCategoryParams, FetchProductsByCategoryResponse>;
|
|
@@ -4,7 +4,6 @@ import { MINUTE } from "../../cache/index.mjs";
|
|
|
4
4
|
import { unwrap } from "../../utils/response.mjs";
|
|
5
5
|
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
6
6
|
import { ErrorResponse } from "../../errors/index.mjs";
|
|
7
|
-
import { getCampaignKey } from "./campaign.mjs";
|
|
8
7
|
const MAX_PER_PAGE = 100;
|
|
9
8
|
const sanitizeAttributesForSAPI = ({
|
|
10
9
|
attributes,
|
|
@@ -37,7 +36,7 @@ export async function resolveCategoryIdFromParams(context, params) {
|
|
|
37
36
|
}
|
|
38
37
|
export const getProductById = async function getProductById2(options, context) {
|
|
39
38
|
const { sapiClient, cached, withParams } = context;
|
|
40
|
-
const campaignKey = await getCampaignKey
|
|
39
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
41
40
|
return await cached(
|
|
42
41
|
mapSAPIFetchErrorToResponse(sapiClient.products.getById),
|
|
43
42
|
{
|
|
@@ -53,7 +52,7 @@ export const getProductById = async function getProductById2(options, context) {
|
|
|
53
52
|
};
|
|
54
53
|
export const getProductsByIds = async function getProductsByIds2(options, context) {
|
|
55
54
|
const { sapiClient, cached, withParams } = context;
|
|
56
|
-
const campaignKey = await getCampaignKey
|
|
55
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
57
56
|
return await cached(
|
|
58
57
|
mapSAPIFetchErrorToResponse(sapiClient.products.getByIds),
|
|
59
58
|
{
|
|
@@ -68,7 +67,7 @@ export const getProductsByIds = async function getProductsByIds2(options, contex
|
|
|
68
67
|
};
|
|
69
68
|
export const getProductsByReferenceKeys = async function getProductsByReferenceKeys2(options, context) {
|
|
70
69
|
const { sapiClient, cached, withParams } = context;
|
|
71
|
-
const campaignKey = await getCampaignKey
|
|
70
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
72
71
|
return await cached(
|
|
73
72
|
mapSAPIFetchErrorToResponse(sapiClient.products.getByReferenceKeys),
|
|
74
73
|
{
|
|
@@ -90,7 +89,7 @@ export const getProductsCount = async function getProductsCount2(params, context
|
|
|
90
89
|
orFiltersOperator = void 0
|
|
91
90
|
} = params;
|
|
92
91
|
const { cached, sapiClient } = context;
|
|
93
|
-
const campaignKey = await getCampaignKey
|
|
92
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
94
93
|
const { categoryId } = await resolveCategoryIdFromParams(context, params);
|
|
95
94
|
const response = await getSanitizedAttributes(
|
|
96
95
|
context,
|
|
@@ -131,7 +130,7 @@ export const getProductsCount = async function getProductsCount2(params, context
|
|
|
131
130
|
};
|
|
132
131
|
export const fetchAllFiltersForCategory = async function fetchAllFiltersForCategory2({ includedFilters = [], category }, context) {
|
|
133
132
|
const { cached, sapiClient } = context;
|
|
134
|
-
const campaignKey = await getCampaignKey
|
|
133
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
135
134
|
const fetchAndMapFiltersToSlugs = async () => {
|
|
136
135
|
const filtersFromSAPI = await cached(sapiClient.filters.get)({
|
|
137
136
|
where: { categoryId: category.id },
|
|
@@ -173,7 +172,7 @@ export const getFilters = async function getFilters2(params, context) {
|
|
|
173
172
|
orFiltersOperator
|
|
174
173
|
} = params;
|
|
175
174
|
const { cached, sapiClient } = context;
|
|
176
|
-
const campaignKey = await getCampaignKey
|
|
175
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
177
176
|
const { category, categoryId } = await resolveCategoryIdFromParams(
|
|
178
177
|
context,
|
|
179
178
|
params
|
|
@@ -253,7 +252,7 @@ export const getProductsByCategory = async function getProductsByCategory2(param
|
|
|
253
252
|
trackSearchAnalyticsEvent = void 0
|
|
254
253
|
} = params;
|
|
255
254
|
const { cached, sapiClient } = context;
|
|
256
|
-
const campaignKey = await getCampaignKey
|
|
255
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
257
256
|
const { category, categoryId } = await resolveCategoryIdFromParams(
|
|
258
257
|
context,
|
|
259
258
|
params
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ProductWith, VariantDetail } from '@scayle/storefront-api';
|
|
2
|
-
import type {
|
|
2
|
+
import type { RpcHandler } from '../../types';
|
|
3
3
|
export interface FetchVariantsParams {
|
|
4
4
|
ids: number[];
|
|
5
5
|
include?: ProductWith;
|
|
6
6
|
pricePromotionKey?: string;
|
|
7
7
|
}
|
|
8
|
-
export declare const getVariantById:
|
|
8
|
+
export declare const getVariantById: RpcHandler<FetchVariantsParams, VariantDetail[]>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
2
|
-
import { getCampaignKey } from "./campaign.mjs";
|
|
3
2
|
const defaultWith = {
|
|
4
3
|
attributes: "all"
|
|
5
4
|
};
|
|
6
5
|
export const getVariantById = async function getVariantById2({ ids, include = defaultWith, pricePromotionKey = "default" }, context) {
|
|
7
6
|
const { sapiClient, cached, withParams } = context;
|
|
8
|
-
const campaignKey = await getCampaignKey
|
|
7
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
9
8
|
const resolvedWith = include ?? withParams?.variant ?? defaultWith;
|
|
10
9
|
return await cached(
|
|
11
10
|
mapSAPIFetchErrorToResponse(sapiClient.variants.getByIds),
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Wishlist } from '@scayle/storefront-api';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const getWishlist:
|
|
4
|
-
export declare const addItemToWishlist:
|
|
2
|
+
import type { ParamRpcHandler, RpcHandler, WishlistWithOptions } from '../../types';
|
|
3
|
+
export declare const getWishlist: RpcHandler<WishlistWithOptions | undefined, Wishlist>;
|
|
4
|
+
export declare const addItemToWishlist: ParamRpcHandler<{
|
|
5
5
|
variantId?: number;
|
|
6
6
|
productId?: number;
|
|
7
7
|
with?: WishlistWithOptions;
|
|
8
|
-
},
|
|
9
|
-
export declare const removeItemFromWishlist:
|
|
8
|
+
}, Wishlist | Response>;
|
|
9
|
+
export declare const removeItemFromWishlist: RpcHandler<{
|
|
10
10
|
itemKey: string;
|
|
11
11
|
with?: WishlistWithOptions;
|
|
12
|
-
},
|
|
13
|
-
export declare const clearWishlist:
|
|
12
|
+
}, Wishlist>;
|
|
13
|
+
export declare const clearWishlist: RpcHandler<Wishlist>;
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
import { unwrap } from "../../utils/response.mjs";
|
|
8
8
|
import { ErrorResponse } from "../../errors/index.mjs";
|
|
9
9
|
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
10
|
-
import { getCampaignKey } from "./campaign.mjs";
|
|
11
10
|
function getWithParams(params, context) {
|
|
12
11
|
return params.with ?? context.withParams?.wishlist ?? MIN_WITH_PARAMS_WISHLIST;
|
|
13
12
|
}
|
|
@@ -20,7 +19,7 @@ export const getWishlist = async function getWishlist2(options, context) {
|
|
|
20
19
|
);
|
|
21
20
|
}
|
|
22
21
|
const { sapiClient, wishlistKey } = context;
|
|
23
|
-
const campaignKey = await getCampaignKey
|
|
22
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
24
23
|
const resolvedWith = getWithParams({ with: options }, context);
|
|
25
24
|
return await mapSAPIFetchErrorToResponse(sapiClient.wishlist.get)(
|
|
26
25
|
wishlistKey,
|
|
@@ -40,7 +39,7 @@ export const addItemToWishlist = async function addItemToWishlist2(options, cont
|
|
|
40
39
|
);
|
|
41
40
|
}
|
|
42
41
|
const { sapiClient, wishlistKey } = context;
|
|
43
|
-
const campaignKey = await getCampaignKey
|
|
42
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
44
43
|
const { productId, variantId } = options;
|
|
45
44
|
const resolvedWith = getWithParams(options, context);
|
|
46
45
|
const pricePromotionKey = resolvedWith?.pricePromotionKey ?? "";
|
|
@@ -77,7 +76,7 @@ export const removeItemFromWishlist = async function removeItemFromWishlist2(opt
|
|
|
77
76
|
);
|
|
78
77
|
}
|
|
79
78
|
const { sapiClient, wishlistKey } = context;
|
|
80
|
-
const campaignKey = await getCampaignKey
|
|
79
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
81
80
|
const resolvedWith = getWithParams(options, context);
|
|
82
81
|
return await mapSAPIFetchErrorToResponse(sapiClient.wishlist.deleteItem)(
|
|
83
82
|
wishlistKey,
|
|
@@ -5,6 +5,7 @@ import type { CachedType } from '../../cache/cached';
|
|
|
5
5
|
import type { AuthenticationType, ShopUser } from '../user';
|
|
6
6
|
import type { BasketWithOptions, CategoryWith, ProductCategoryWith, ProductWith, SearchV2With, SearchWith, VariantWith, WishlistWithOptions } from '../';
|
|
7
7
|
import type { IDPConfig, OAuthTokens } from './auth';
|
|
8
|
+
import type { RpcMethodCall } from '../..';
|
|
8
9
|
export type WithParams = Partial<{
|
|
9
10
|
basket: BasketWithOptions;
|
|
10
11
|
wishlist: WishlistWithOptions;
|
|
@@ -78,7 +79,25 @@ export type RpcContext = {
|
|
|
78
79
|
domain?: string;
|
|
79
80
|
withParams?: WithParams;
|
|
80
81
|
/**
|
|
81
|
-
* @deprecated
|
|
82
|
+
* @deprecated The `getCampaignKey` RPC method should be used instead to retrieve the default campaign key.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
*
|
|
86
|
+
* ```typescript
|
|
87
|
+
* // Before
|
|
88
|
+
* async function rpcMethod(context) {
|
|
89
|
+
* const campaignKey = { context }
|
|
90
|
+
* // ...
|
|
91
|
+
* }
|
|
92
|
+
* // After
|
|
93
|
+
* async function rpcMethod(context) {
|
|
94
|
+
* const campaignKey = await context.callRpc?.('getCampaignKey')
|
|
95
|
+
* // ...
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* To override the default campaign key, override the getCampaignKey RPC with your own implementation
|
|
100
|
+
* @see https://scayle.dev/en/storefront-guide/developer-guide/basic-setup/rpc-methods#overriding-core-rpc-methods
|
|
82
101
|
*/
|
|
83
102
|
campaignKey?: string;
|
|
84
103
|
destroySessionsForUserId: (userId: number, sessionsToKeep?: string[]) => Promise<void>;
|
|
@@ -102,6 +121,7 @@ export type RpcContext = {
|
|
|
102
121
|
callHook?: Hookable<StorefrontHooks>['callHook'];
|
|
103
122
|
callHookParallel?: Hookable<StorefrontHooks>['callHookParallel'];
|
|
104
123
|
callHookWith?: Hookable<StorefrontHooks>['callHookWith'];
|
|
124
|
+
callRpc?: RpcMethodCall;
|
|
105
125
|
} & AdditionalRpcContext & (ContextWithoutSession | ContextWithSession);
|
|
106
126
|
export type RpcContextWithSession = RpcContext & ContextWithSession;
|
|
107
127
|
export declare function assertSession(context: RpcContext): asserts context is RpcContextWithSession;
|
package/dist/utils/campaign.d.ts
CHANGED
|
@@ -1,23 +1,38 @@
|
|
|
1
1
|
import type { Campaign } from '@scayle/storefront-api';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Checks if a given campaign is currently active.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Determines if the current time falls within the campaign's start and end dates.
|
|
6
|
+
*
|
|
7
|
+
* @see https://scayle.dev/en/user-guide/shops/promotions/discounts-and-offers/price-campaigns
|
|
8
|
+
*
|
|
9
|
+
* @param campaign The campaign to check.
|
|
10
|
+
*
|
|
11
|
+
* @returns True if the campaign is active, false otherwise.
|
|
7
12
|
*/
|
|
8
13
|
export declare const isCampaignActive: (campaign?: Campaign) => boolean;
|
|
9
14
|
/**
|
|
10
|
-
*
|
|
15
|
+
* Checks if a given campaign has not yet ended.
|
|
16
|
+
*
|
|
17
|
+
* Compares the campaign's end date with the current time.
|
|
18
|
+
*
|
|
19
|
+
* @see https://scayle.dev/en/user-guide/shops/promotions/discounts-and-offers/price-campaigns
|
|
11
20
|
*
|
|
12
|
-
* @param campaign
|
|
13
|
-
*
|
|
21
|
+
* @param campaign The campaign to check.
|
|
22
|
+
*
|
|
23
|
+
* @returns True if the campaign has not ended, false otherwise.
|
|
14
24
|
*/
|
|
15
25
|
export declare const campaignHasNotEnded: (campaign: Campaign) => boolean;
|
|
16
26
|
/**
|
|
17
|
-
*
|
|
27
|
+
* Sorts campaigns by their start date in ascending order.
|
|
28
|
+
*
|
|
29
|
+
* Uses the difference between start times to determine order.
|
|
30
|
+
*
|
|
31
|
+
* @see https://scayle.dev/en/user-guide/shops/promotions/discounts-and-offers/price-campaigns
|
|
32
|
+
*
|
|
33
|
+
* @param a The first campaign to compare.
|
|
34
|
+
* @param b The second campaign to compare.
|
|
18
35
|
*
|
|
19
|
-
* @
|
|
20
|
-
* @param b The second campaign for comparison
|
|
21
|
-
* @returns A positive value when a should come before b, negative value when b should come before a, or 0 when they are considered equal
|
|
36
|
+
* @returns A negative number if `a` starts before `b`, a positive number if `a` starts after `b`, and 0 if they start at the same time.
|
|
22
37
|
*/
|
|
23
38
|
export declare const sortCampaignsByDateAscending: (a: Campaign, b: Campaign) => number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-core",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.9.0",
|
|
4
4
|
"description": "Collection of essential utilities to work with the Storefront API",
|
|
5
5
|
"author": "SCAYLE Commerce Engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -68,17 +68,17 @@
|
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@scayle/eslint-config-storefront": "4.4.1",
|
|
70
70
|
"@types/crypto-js": "4.2.2",
|
|
71
|
-
"@types/node": "22.13.
|
|
71
|
+
"@types/node": "22.13.5",
|
|
72
72
|
"@types/webpack-env": "1.18.8",
|
|
73
73
|
"@vitest/coverage-v8": "2.1.9",
|
|
74
74
|
"dprint": "0.49.0",
|
|
75
|
-
"eslint": "9.
|
|
75
|
+
"eslint": "9.21.0",
|
|
76
76
|
"eslint-formatter-gitlab": "5.1.0",
|
|
77
77
|
"publint": "0.2.12",
|
|
78
78
|
"rimraf": "6.0.1",
|
|
79
79
|
"typescript": "5.7.3",
|
|
80
80
|
"unbuild": "3.3.1",
|
|
81
|
-
"unstorage": "1.
|
|
81
|
+
"unstorage": "1.15.0",
|
|
82
82
|
"vitest": "2.1.9"
|
|
83
83
|
}
|
|
84
84
|
}
|