@scayle/storefront-nuxt 7.51.1 → 7.52.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 +29 -0
- package/dist/module.json +1 -1
- package/dist/runtime/composables/core/useRpc.mjs +1 -0
- package/dist/runtime/composables/storefront/useBasket.d.ts +1 -1
- package/dist/runtime/context.d.ts +2 -2
- package/dist/runtime/context.mjs +66 -40
- package/dist/runtime/server/middleware/bootstrap.mjs +6 -2
- package/package.json +17 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @scayle/storefront-nuxt
|
|
2
2
|
|
|
3
|
+
## 7.52.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Allow the session of an `RpcContext` to be undefined
|
|
8
|
+
|
|
9
|
+
BREAKING: This changes the structure of the `RpcContext`, so it may be a breaking change if you have written custom RPC methods.
|
|
10
|
+
|
|
11
|
+
The affected properties on the `RpcContext` are `sessionId`, `wishlistKey` and `basketKey` and the affected methods are `destroySession`, `createUserBoundSession`, `updateUser`, and `updateTokens`. If you use these methods or properties in a custom RPC method, make sure that you handle the case where they might be undefined. TypeScript will also catch these cases if you have `strictNullChecks` enabled.
|
|
12
|
+
|
|
13
|
+
You can check `context.sessionId` (or another session-dependent property) to determine if the session is present. If one of these properties is present, all will be. Alternatively, you can call `assertSession(context)` before referencing any properties on the context. If the session is not present, an error will be thrown. For any usage of `context` after `assertSession` is called, TypeScript will understand that the session properties are present.
|
|
14
|
+
|
|
15
|
+
- Do not attach session for cached request
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
- @scayle/storefront-core@7.38.0
|
|
21
|
+
|
|
22
|
+
## 7.51.2
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Updated to `nuxt@3.9.3` and `vue@3.4.15` (\__For more details check the [Nuxt 3.9.3 Release Notes](https://github.com/nuxt/nuxt/releases/tag/v3.9.3) and [Vue 3.4.15 Changelogs](https://github.com/vuejs/core/blob/main/CHANGELOG.md#3415-2024-01-18)_)
|
|
27
|
+
|
|
28
|
+
**NOTE: The minimum supported versions of the `@scayle/storefront-nuxt` package are `nuxt >=3.9.0` and `vue >=3.4.0`. Please update your application stack accordingly.**
|
|
29
|
+
|
|
30
|
+
- useRpc - clear error state when re-fetching
|
|
31
|
+
|
|
3
32
|
## 7.51.1
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
package/dist/module.json
CHANGED
|
@@ -32,6 +32,7 @@ export const useRpc = async (method, key, params, options = { autoFetch: true, l
|
|
|
32
32
|
try {
|
|
33
33
|
status.value = "pending";
|
|
34
34
|
fetching.value = true;
|
|
35
|
+
error.value = void 0;
|
|
35
36
|
const apiBasePath = currentShop.value?.apiBasePath ?? "/api";
|
|
36
37
|
const fetch2 = getFetch(nuxtApp, log);
|
|
37
38
|
data.value = await unwrap(
|
|
@@ -44,7 +44,7 @@ export declare function useBasket({ params, options, key, }?: UseBasketOptions):
|
|
|
44
44
|
shopId: string;
|
|
45
45
|
userId: string;
|
|
46
46
|
log?: import("@scayle/storefront-core").Log | undefined;
|
|
47
|
-
}) => Promise<
|
|
47
|
+
}) => Promise<string>;
|
|
48
48
|
mergeBaskets: (args: {
|
|
49
49
|
fromBasketKey: string;
|
|
50
50
|
toBasketKey: string;
|
|
@@ -7,8 +7,8 @@ export interface ContextBuilderOptions {
|
|
|
7
7
|
$shopConfig: ShopConfig;
|
|
8
8
|
$storefront: StorefrontConfig;
|
|
9
9
|
$log: Log;
|
|
10
|
-
sessionId
|
|
11
|
-
session
|
|
10
|
+
sessionId?: string;
|
|
11
|
+
session?: Session;
|
|
12
12
|
config: RuntimeConfig;
|
|
13
13
|
}
|
|
14
14
|
export declare const buildContext: (context: ContextBuilderOptions) => Promise<RpcContext>;
|
package/dist/runtime/context.mjs
CHANGED
|
@@ -4,8 +4,72 @@ import {
|
|
|
4
4
|
generateBasketKey,
|
|
5
5
|
generateWishlistKey
|
|
6
6
|
} from "@scayle/storefront-core/dist/utils/keys";
|
|
7
|
+
async function getWishlistKey(appKeys, session, $log, $shopConfig) {
|
|
8
|
+
return session.data.user ? await generateWishlistKey({
|
|
9
|
+
keyTemplate: appKeys.wishlistKey,
|
|
10
|
+
userId: String(session.data.user.id),
|
|
11
|
+
shopId: String($shopConfig.shopId),
|
|
12
|
+
hashAlgorithm: appKeys.hashAlgorithm,
|
|
13
|
+
log: $log
|
|
14
|
+
}) : session.id;
|
|
15
|
+
}
|
|
16
|
+
async function getBasketKey(appKeys, session, $log, $shopConfig) {
|
|
17
|
+
return session.data.user ? await generateBasketKey({
|
|
18
|
+
keyTemplate: appKeys.basketKey,
|
|
19
|
+
userId: String(session.data.user.id),
|
|
20
|
+
shopId: String($shopConfig.shopId),
|
|
21
|
+
hashAlgorithm: appKeys.hashAlgorithm,
|
|
22
|
+
log: $log
|
|
23
|
+
}) : session?.id;
|
|
24
|
+
}
|
|
25
|
+
async function sessionProperties(context) {
|
|
26
|
+
const { $shopConfig, $storefront, $log, session } = context;
|
|
27
|
+
const appKeys = $shopConfig.appKeys ?? $storefront.appKeys;
|
|
28
|
+
if (session) {
|
|
29
|
+
return {
|
|
30
|
+
wishlistKey: await getWishlistKey(appKeys, session, $log, $shopConfig),
|
|
31
|
+
basketKey: await getBasketKey(appKeys, session, $log, $shopConfig),
|
|
32
|
+
sessionId: session.id,
|
|
33
|
+
get user() {
|
|
34
|
+
return session.data?.user ?? void 0;
|
|
35
|
+
},
|
|
36
|
+
get accessToken() {
|
|
37
|
+
return session.data?.accessToken ?? void 0;
|
|
38
|
+
},
|
|
39
|
+
destroySession: async () => {
|
|
40
|
+
await session.destroy();
|
|
41
|
+
},
|
|
42
|
+
createUserBoundSession: async () => {
|
|
43
|
+
$log.debug("creating user bound session");
|
|
44
|
+
const data = session.data;
|
|
45
|
+
await session.regenerate();
|
|
46
|
+
session.data = data;
|
|
47
|
+
await session.save();
|
|
48
|
+
},
|
|
49
|
+
updateUser: async (user) => {
|
|
50
|
+
session.data.user = user;
|
|
51
|
+
await session.save();
|
|
52
|
+
},
|
|
53
|
+
updateTokens: async (tokens) => {
|
|
54
|
+
Object.assign(session.data, tokens);
|
|
55
|
+
await session.save();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
wishlistKey: void 0,
|
|
61
|
+
basketKey: void 0,
|
|
62
|
+
sessionId: void 0,
|
|
63
|
+
user: void 0,
|
|
64
|
+
accessToken: void 0,
|
|
65
|
+
destroySession: void 0,
|
|
66
|
+
createUserBoundSession: void 0,
|
|
67
|
+
updateUser: void 0,
|
|
68
|
+
updateTokens: void 0
|
|
69
|
+
};
|
|
70
|
+
}
|
|
7
71
|
export const buildContext = async (context) => {
|
|
8
|
-
const { $cache, $shopConfig, $storefront, $log,
|
|
72
|
+
const { $cache, $shopConfig, $storefront, $log, config } = context;
|
|
9
73
|
const bapiConfig = $shopConfig.bapi ?? $storefront.bapi;
|
|
10
74
|
const appKeys = $shopConfig.appKeys ?? $storefront.appKeys;
|
|
11
75
|
const idpConfig = $shopConfig.idp ?? $storefront.idp;
|
|
@@ -17,20 +81,7 @@ export const buildContext = async (context) => {
|
|
|
17
81
|
authentication: "token",
|
|
18
82
|
token: bapiConfig.token
|
|
19
83
|
}),
|
|
20
|
-
|
|
21
|
-
keyTemplate: appKeys.wishlistKey,
|
|
22
|
-
userId: String(session.data.user.id),
|
|
23
|
-
shopId: String($shopConfig.shopId),
|
|
24
|
-
hashAlgorithm: appKeys.hashAlgorithm,
|
|
25
|
-
log: $log
|
|
26
|
-
}) : session.id,
|
|
27
|
-
basketKey: session.data.user ? await generateBasketKey({
|
|
28
|
-
keyTemplate: appKeys.basketKey,
|
|
29
|
-
userId: String(session.data.user.id),
|
|
30
|
-
shopId: String($shopConfig.shopId),
|
|
31
|
-
hashAlgorithm: appKeys.hashAlgorithm,
|
|
32
|
-
log: $log
|
|
33
|
-
}) : session.id,
|
|
84
|
+
...await sessionProperties(context),
|
|
34
85
|
auth: {
|
|
35
86
|
resetPasswordUrl: $shopConfig.auth?.resetPasswordUrl
|
|
36
87
|
},
|
|
@@ -48,21 +99,8 @@ export const buildContext = async (context) => {
|
|
|
48
99
|
},
|
|
49
100
|
idp: idpConfig,
|
|
50
101
|
log: $log,
|
|
51
|
-
get user() {
|
|
52
|
-
return session.data?.user ?? void 0;
|
|
53
|
-
},
|
|
54
|
-
destroySession: async () => {
|
|
55
|
-
await session.destroy();
|
|
56
|
-
},
|
|
57
102
|
destroySessionsForUserId: async () => {
|
|
58
103
|
},
|
|
59
|
-
createUserBoundSession: async () => {
|
|
60
|
-
$log.debug("creating user bound session");
|
|
61
|
-
const data = session.data;
|
|
62
|
-
await session.regenerate();
|
|
63
|
-
session.data = data;
|
|
64
|
-
await session.save();
|
|
65
|
-
},
|
|
66
104
|
generateBasketKeyForUserId: (userId) => generateBasketKey({
|
|
67
105
|
keyTemplate: appKeys.basketKey,
|
|
68
106
|
userId,
|
|
@@ -83,18 +121,6 @@ export const buildContext = async (context) => {
|
|
|
83
121
|
domain: $shopConfig.domain,
|
|
84
122
|
withParams: $storefront.withParams,
|
|
85
123
|
campaignKey: $shopConfig.storeCampaignKeyword,
|
|
86
|
-
updateUser: async (user) => {
|
|
87
|
-
session.data.user = user;
|
|
88
|
-
await session.save();
|
|
89
|
-
},
|
|
90
|
-
sessionId: context.sessionId,
|
|
91
|
-
get accessToken() {
|
|
92
|
-
return session.data?.accessToken ?? void 0;
|
|
93
|
-
},
|
|
94
|
-
updateTokens: async (tokens) => {
|
|
95
|
-
Object.assign(session.data, tokens);
|
|
96
|
-
await session.save();
|
|
97
|
-
},
|
|
98
124
|
runtimeConfiguration: config
|
|
99
125
|
};
|
|
100
126
|
};
|
|
@@ -85,13 +85,17 @@ async function bootstrap(event, url, $shopConfig, $storefrontConfig, apiBasePath
|
|
|
85
85
|
);
|
|
86
86
|
event.context.$cache = $cache;
|
|
87
87
|
bootstrapLog.debug("Building context for request");
|
|
88
|
+
const cacheableRoute = !!event.context._nitro.routeRules.cache;
|
|
89
|
+
if (cacheableRoute) {
|
|
90
|
+
bootstrapLog.debug("Skipping session for cached request");
|
|
91
|
+
}
|
|
88
92
|
event.context.$rpcContext = await buildContext({
|
|
89
93
|
$cache,
|
|
90
94
|
$shopConfig,
|
|
91
95
|
$storefront: $storefrontConfig,
|
|
92
96
|
$log: log,
|
|
93
|
-
sessionId: event.context.sessionId,
|
|
94
|
-
session: event.context.session,
|
|
97
|
+
sessionId: cacheableRoute ? void 0 : event.context.sessionId,
|
|
98
|
+
session: cacheableRoute ? void 0 : event.context.session,
|
|
95
99
|
config
|
|
96
100
|
});
|
|
97
101
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.
|
|
4
|
+
"version": "7.52.0",
|
|
5
5
|
"description": "Nuxt integration for the SCAYLE Commerce Engine and Storefront API",
|
|
6
6
|
"author": "SCAYLE Commerce Engine",
|
|
7
7
|
"license": "MIT",
|
|
@@ -60,13 +60,13 @@
|
|
|
60
60
|
"test:watch": "vitest watch"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@nuxt/kit": "3.9.
|
|
63
|
+
"@nuxt/kit": "3.9.3",
|
|
64
64
|
"@scayle/h3-session": "0.3.5",
|
|
65
|
-
"@scayle/storefront-core": "7.
|
|
65
|
+
"@scayle/storefront-core": "7.38.0",
|
|
66
66
|
"@scayle/unstorage-compression-driver": "0.1.1",
|
|
67
67
|
"@vueuse/core": "10.7.2",
|
|
68
68
|
"consola": "3.2.3",
|
|
69
|
-
"core-js": "3.35.
|
|
69
|
+
"core-js": "3.35.1",
|
|
70
70
|
"defu": "6.1.4",
|
|
71
71
|
"h3": "1.10.0",
|
|
72
72
|
"jose": "^5.2.0",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
83
|
"@nuxt/module-builder": "0.5.5",
|
|
84
|
-
"@nuxt/schema": "3.9.
|
|
84
|
+
"@nuxt/schema": "3.9.3",
|
|
85
85
|
"@nuxt/test-utils": "3.10.0",
|
|
86
86
|
"@scayle/eslint-config-storefront": "3.2.6",
|
|
87
87
|
"@scayle/prettier-config-storefront": "2.0.2",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"eslint": "8.56.0",
|
|
90
90
|
"eslint-formatter-gitlab": "5.1.0",
|
|
91
91
|
"node-mocks-http": "1.14.1",
|
|
92
|
-
"nuxt": "3.9.
|
|
92
|
+
"nuxt": "3.9.3",
|
|
93
93
|
"prettier": "3.0.0",
|
|
94
94
|
"publint": "0.2.7",
|
|
95
95
|
"vitest": "1.2.1",
|
|
@@ -102,17 +102,17 @@
|
|
|
102
102
|
},
|
|
103
103
|
"resolutions": {
|
|
104
104
|
"h3": "1.10.1",
|
|
105
|
-
"@vue/compiler-core": "3.4.
|
|
106
|
-
"@vue/shared": "3.4.
|
|
107
|
-
"@vue/compiler-dom": "3.4.
|
|
108
|
-
"@vue/compiler-sfc": "3.4.
|
|
109
|
-
"@vue/compiler-ssr": "3.4.
|
|
110
|
-
"@vue/reactivity": "3.4.
|
|
111
|
-
"@vue/runtime-core": "3.4.
|
|
112
|
-
"@vue/runtime-dom": "3.4.
|
|
113
|
-
"@vue/server-renderer": "3.4.
|
|
114
|
-
"@nuxt/kit": "3.9.
|
|
115
|
-
"@nuxt/schema": "3.9.
|
|
105
|
+
"@vue/compiler-core": "3.4.15",
|
|
106
|
+
"@vue/shared": "3.4.15",
|
|
107
|
+
"@vue/compiler-dom": "3.4.15",
|
|
108
|
+
"@vue/compiler-sfc": "3.4.15",
|
|
109
|
+
"@vue/compiler-ssr": "3.4.15",
|
|
110
|
+
"@vue/reactivity": "3.4.15",
|
|
111
|
+
"@vue/runtime-core": "3.4.15",
|
|
112
|
+
"@vue/runtime-dom": "3.4.15",
|
|
113
|
+
"@vue/server-renderer": "3.4.15",
|
|
114
|
+
"@nuxt/kit": "3.9.3",
|
|
115
|
+
"@nuxt/schema": "3.9.3"
|
|
116
116
|
},
|
|
117
117
|
"volta": {
|
|
118
118
|
"node": "20.11.0"
|