@scayle/storefront-core 8.35.0 → 8.36.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
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @scayle/storefront-core
|
|
2
2
|
|
|
3
|
+
## 8.36.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Created a new RPC method `getCampaign` to retrieve the first active campaign.
|
|
8
|
+
|
|
9
|
+
More details can be found in the official SCAYLE Resource Center under [API Guides / Storefront API / Campaigns / List Campaigns](https://scayle.dev/en/api-guides/storefront-api/resources/campaigns/list-campaigns).
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
**Dependencies**
|
|
14
|
+
|
|
15
|
+
- Updated dependency to @scayle/storefront-api@18.11.0
|
|
16
|
+
|
|
3
17
|
## 8.35.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
import type { Campaign } from '@scayle/storefront-api';
|
|
1
2
|
import type { RpcHandler } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves the active campaign.
|
|
5
|
+
*
|
|
6
|
+
* This RPC method retrieves the active campaign.
|
|
7
|
+
* It then returns the first active campaign.
|
|
8
|
+
*
|
|
9
|
+
* @param context The RPC Context
|
|
10
|
+
* @returns The current active campaign.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getCampaign: RpcHandler<Campaign | undefined>;
|
|
2
13
|
/**
|
|
3
14
|
* Retrieves the active campaign key.
|
|
4
15
|
*
|
|
@@ -6,11 +17,6 @@ import type { RpcHandler } from '../../types';
|
|
|
6
17
|
* for an existing `campaignKey`. If not present, it fetches active campaigns from the SAPI
|
|
7
18
|
* `list-campaigns` endpoint using the `sapiClient`, caching the result for 5 minutes.
|
|
8
19
|
*
|
|
9
|
-
* @see https://scayle.dev/en/api-guides/storefront-api/resources/campaigns/list-campaigns
|
|
10
|
-
*
|
|
11
|
-
* This function uses the Storefront cache (`cached()`) with a `get-campaignKey` key prefix to improve performance.
|
|
12
|
-
* Cached entries are returned if found; otherwise, data is fetched and cached.
|
|
13
|
-
*
|
|
14
20
|
* @param context The RPC Context
|
|
15
21
|
* @returns The current active campaign key.
|
|
16
22
|
*/
|
|
@@ -4,10 +4,7 @@ import {
|
|
|
4
4
|
isCampaignActive
|
|
5
5
|
} from "../../utils/campaign.mjs";
|
|
6
6
|
import { defineRpcHandler } from "../../utils/index.mjs";
|
|
7
|
-
|
|
8
|
-
if (context.campaignKey) {
|
|
9
|
-
return context.campaignKey;
|
|
10
|
-
}
|
|
7
|
+
const getCampaigns = async (context) => {
|
|
11
8
|
const { cached, sapiClient } = context;
|
|
12
9
|
const { campaigns } = await cached(async () => {
|
|
13
10
|
const { entities } = await sapiClient.campaigns.get();
|
|
@@ -17,8 +14,20 @@ export const getCampaignKey = defineRpcHandler(async (context) => {
|
|
|
17
14
|
}).sort(sortCampaignsByDateAscending)
|
|
18
15
|
};
|
|
19
16
|
}, {
|
|
20
|
-
cacheKeyPrefix: "get-
|
|
17
|
+
cacheKeyPrefix: "get-campaigns",
|
|
21
18
|
ttl: 5 * 60
|
|
22
19
|
})();
|
|
23
|
-
return campaigns
|
|
20
|
+
return campaigns;
|
|
21
|
+
};
|
|
22
|
+
export const getCampaign = defineRpcHandler(async (context) => {
|
|
23
|
+
const campaigns = await getCampaigns(context);
|
|
24
|
+
return campaigns.find(isCampaignActive);
|
|
25
|
+
});
|
|
26
|
+
export const getCampaignKey = defineRpcHandler(async (context) => {
|
|
27
|
+
if (context.campaignKey) {
|
|
28
|
+
return context.campaignKey;
|
|
29
|
+
}
|
|
30
|
+
const campaigns = await getCampaigns(context);
|
|
31
|
+
const campaign = campaigns.find(isCampaignActive);
|
|
32
|
+
return campaign?.key;
|
|
24
33
|
});
|
|
@@ -37,7 +37,7 @@ export const getCheckoutToken = defineRpcHandler(async (jwtPayload = {}, context
|
|
|
37
37
|
carrier,
|
|
38
38
|
basketId: context.basketKey,
|
|
39
39
|
campaignKey
|
|
40
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.
|
|
40
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.36.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
|
|
41
41
|
return {
|
|
42
42
|
accessToken: refreshedAccessToken,
|
|
43
43
|
checkoutJwt
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-core",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.36.0",
|
|
4
4
|
"description": "Collection of essential utilities to work with the Storefront API",
|
|
5
5
|
"author": "SCAYLE Commerce Engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
"ufo": "^1.5.3",
|
|
57
57
|
"uncrypto": "^0.1.3",
|
|
58
58
|
"utility-types": "^3.11.0",
|
|
59
|
-
"@scayle/storefront-api": "18.
|
|
59
|
+
"@scayle/storefront-api": "18.11.0",
|
|
60
60
|
"@scayle/unstorage-scayle-kv-driver": "1.0.2"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/crypto-js": "4.2.2",
|
|
64
|
-
"@types/node": "22.16.
|
|
64
|
+
"@types/node": "22.16.5",
|
|
65
65
|
"@types/webpack-env": "1.18.8",
|
|
66
66
|
"@vitest/coverage-v8": "3.2.4",
|
|
67
67
|
"dprint": "0.50.1",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"@scayle/eslint-config-storefront": "4.6.1"
|
|
78
78
|
},
|
|
79
79
|
"volta": {
|
|
80
|
-
"node": "22.17.
|
|
80
|
+
"node": "22.17.1"
|
|
81
81
|
},
|
|
82
82
|
"scripts": {
|
|
83
83
|
"clean": "rimraf ./dist",
|