@scayle/storefront-nuxt 8.53.1 → 8.53.2
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/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/composables/core/useRpc.d.ts +2 -1
- package/dist/runtime/composables/core/useRpc.js +8 -6
- package/dist/runtime/composables/index.d.ts +1 -1
- package/dist/runtime/composables/index.js +3 -1
- package/dist/runtime/utils/zodSchema.d.ts +14 -0
- package/dist/runtime/utils/zodSchema.js +8 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @scayle/storefront-nuxt
|
|
2
2
|
|
|
3
|
+
## 8.53.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Introduced the `rpcDefaultLazy` configuration flag to streamline data fetching. When enabled via the `NUXT_PUBLIC_STOREFRONT_RPC_DEFAULT_LAZY` environment variable or by setting `rpcDefaultLazy` in your `nuxt.config.ts`, `useRpc` and derived composables like `useProducts` or `useBasket` will behave lazily by default. This eliminates the need to repeatedly pass `{ lazy: true }` in your component logic.
|
|
8
|
+
|
|
9
|
+
**Examples:**
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
// Before (or when `rpcDefaultLazy: false`)
|
|
13
|
+
// You had to explicitly opt-in to lazy behavior
|
|
14
|
+
const { data } = useRpc('someMethod', { some: 'param' }, { lazy: true })
|
|
15
|
+
|
|
16
|
+
// After (when `rpcDefaultLazy: true`)
|
|
17
|
+
// Lazy behavior is now the default
|
|
18
|
+
const { data } = useRpc('someMethod', { some: 'param' })
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Dependencies**
|
|
22
|
+
|
|
23
|
+
**@scayle/storefront-core v8.53.2**
|
|
24
|
+
|
|
25
|
+
- No changes in this release.
|
|
26
|
+
|
|
3
27
|
## 8.53.1
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RpcContext, RpcMethodName, RpcMethodParameters, RpcMethodReturnType } from '@scayle/storefront-core';
|
|
2
2
|
import { useAsyncData } from 'nuxt/app';
|
|
3
|
-
import type { AsyncDataOptions } from 'nuxt/app';
|
|
3
|
+
import type { AsyncDataOptions, NuxtApp } from 'nuxt/app';
|
|
4
4
|
import type { MaybeRefOrGetter } from 'vue';
|
|
5
5
|
/**
|
|
6
6
|
* Extracts keys from a type `T` as an array of strings.
|
|
@@ -47,6 +47,7 @@ type AwaitedAsyncData<ResT, ErrorT = unknown, DataT = ResT, PickKeys extends Key
|
|
|
47
47
|
* @template DefaultT The default value type. Defaults to `null`.
|
|
48
48
|
*/
|
|
49
49
|
export type ExtendedAsyncData<ResT, ErrorT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null> = AwaitedAsyncData<ResT, ErrorT, DataT, PickKeys, DefaultT> & Promise<AwaitedAsyncData<ResT, ErrorT, DataT, PickKeys, DefaultT>>;
|
|
50
|
+
export declare const defaultCachedData: <ResponseT>(key: string, nuxtApp: NuxtApp) => ResponseT | undefined;
|
|
50
51
|
/**
|
|
51
52
|
* `useRpc` is a wrapper around `useAsyncData` for registered RPC methods.
|
|
52
53
|
*
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { unwrap } from "@scayle/storefront-core";
|
|
2
|
-
import {
|
|
2
|
+
import { useAsyncData, useRuntimeConfig, useNuxtApp } from "nuxt/app";
|
|
3
3
|
import { useCoreLog } from "../useCoreLog.js";
|
|
4
4
|
import { useCurrentShop } from "./useCurrentShop.js";
|
|
5
5
|
import { toValue, isRef } from "vue";
|
|
6
|
-
import { useRuntimeConfig } from "#app/nuxt";
|
|
7
6
|
function getFetch(nuxtApp, log) {
|
|
8
7
|
const fetch = nuxtApp.ssrContext?.event.context.$fetchWithContext ?? $fetch;
|
|
9
8
|
if (nuxtApp.ssrContext?.event && !nuxtApp.ssrContext?.event.context.$fetchWithContext) {
|
|
@@ -11,6 +10,10 @@ function getFetch(nuxtApp, log) {
|
|
|
11
10
|
}
|
|
12
11
|
return fetch;
|
|
13
12
|
}
|
|
13
|
+
export const defaultCachedData = (key, nuxtApp) => {
|
|
14
|
+
const hydrationData = nuxtApp.isHydrating ? nuxtApp.payload.data[key] : nuxtApp.static.data[key];
|
|
15
|
+
return hydrationData ?? nuxtApp._asyncData[key]?.data.value;
|
|
16
|
+
};
|
|
14
17
|
export function useRpc(method, key, params, options) {
|
|
15
18
|
const currentShop = useCurrentShop();
|
|
16
19
|
const log = useCoreLog("rpc");
|
|
@@ -18,6 +21,8 @@ export function useRpc(method, key, params, options) {
|
|
|
18
21
|
const {
|
|
19
22
|
public: { storefront }
|
|
20
23
|
} = useRuntimeConfig();
|
|
24
|
+
options ??= {};
|
|
25
|
+
options.lazy ??= storefront.rpcDefaultLazy;
|
|
21
26
|
const asyncData = useAsyncData(
|
|
22
27
|
key,
|
|
23
28
|
async () => {
|
|
@@ -40,10 +45,7 @@ export function useRpc(method, key, params, options) {
|
|
|
40
45
|
{
|
|
41
46
|
// Both refs and getter functions are valid watch sources
|
|
42
47
|
...isRef(params) || typeof params === "function" ? { watch: [params] } : {},
|
|
43
|
-
getCachedData: storefront.legacy?.enableDefaultGetCachedDataOverride ?
|
|
44
|
-
const hydrationData = nuxtApp2.isHydrating ? nuxtApp2.payload.data[key2] : nuxtApp2.static.data[key2];
|
|
45
|
-
return hydrationData ?? nuxtApp2._asyncData[key2]?.data.value;
|
|
46
|
-
} : void 0,
|
|
48
|
+
getCachedData: storefront.legacy?.enableDefaultGetCachedDataOverride ? defaultCachedData : void 0,
|
|
47
49
|
...options
|
|
48
50
|
}
|
|
49
51
|
);
|
|
@@ -3,7 +3,7 @@ export * from './core/useCurrentShop.js';
|
|
|
3
3
|
export * from './core/useFormatHelpers.js';
|
|
4
4
|
export * from './core/useIDP.js';
|
|
5
5
|
export * from './core/useLog.js';
|
|
6
|
-
export
|
|
6
|
+
export { useRpc, type KeysOf, type NormalizedRpcResponse, type UseRpcOptions, type UseRpcReturn, type Status, type ExtendedAsyncData, } from './core/useRpc.js';
|
|
7
7
|
export * from './core/useRpcCall.js';
|
|
8
8
|
export * from './core/useSession.js';
|
|
9
9
|
export * from './core/useUser.js';
|
|
@@ -3,7 +3,9 @@ export * from "./core/useCurrentShop.js";
|
|
|
3
3
|
export * from "./core/useFormatHelpers.js";
|
|
4
4
|
export * from "./core/useIDP.js";
|
|
5
5
|
export * from "./core/useLog.js";
|
|
6
|
-
export
|
|
6
|
+
export {
|
|
7
|
+
useRpc
|
|
8
|
+
} from "./core/useRpc.js";
|
|
7
9
|
export * from "./core/useRpcCall.js";
|
|
8
10
|
export * from "./core/useSession.js";
|
|
9
11
|
export * from "./core/useUser.js";
|
|
@@ -879,6 +879,13 @@ declare const StorefrontPublicRuntimeConfigSchema: z.ZodMiniObject<{
|
|
|
879
879
|
legacy: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
880
880
|
enableDefaultGetCachedDataOverride: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
881
881
|
}, z.core.$strip>>;
|
|
882
|
+
/**
|
|
883
|
+
* Controls the default lazy loading behavior for useRpc.
|
|
884
|
+
* If set to true,the useRpc composable will not block during data fetching.
|
|
885
|
+
*
|
|
886
|
+
* @default false
|
|
887
|
+
*/
|
|
888
|
+
rpcDefaultLazy: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
882
889
|
}, z.core.$strip>;
|
|
883
890
|
export declare const RuntimeConfigSchema: z.ZodMiniObject<{
|
|
884
891
|
storefront: z.ZodMiniObject<{
|
|
@@ -1395,6 +1402,13 @@ export declare const RuntimeConfigSchema: z.ZodMiniObject<{
|
|
|
1395
1402
|
legacy: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1396
1403
|
enableDefaultGetCachedDataOverride: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
1397
1404
|
}, z.core.$strip>>;
|
|
1405
|
+
/**
|
|
1406
|
+
* Controls the default lazy loading behavior for useRpc.
|
|
1407
|
+
* If set to true,the useRpc composable will not block during data fetching.
|
|
1408
|
+
*
|
|
1409
|
+
* @default false
|
|
1410
|
+
*/
|
|
1411
|
+
rpcDefaultLazy: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
1398
1412
|
}, z.core.$strip>;
|
|
1399
1413
|
}, z.core.$strip>;
|
|
1400
1414
|
}, z.core.$strip>;
|
|
@@ -190,7 +190,14 @@ const StorefrontPublicRuntimeConfigSchema = z.object({
|
|
|
190
190
|
/** Collection of feature flags regarding legacy features and functionalities */
|
|
191
191
|
legacy: z.optional(z.object({
|
|
192
192
|
enableDefaultGetCachedDataOverride: z.optional(z.boolean())
|
|
193
|
-
}))
|
|
193
|
+
})),
|
|
194
|
+
/**
|
|
195
|
+
* Controls the default lazy loading behavior for useRpc.
|
|
196
|
+
* If set to true,the useRpc composable will not block during data fetching.
|
|
197
|
+
*
|
|
198
|
+
* @default false
|
|
199
|
+
*/
|
|
200
|
+
rpcDefaultLazy: z.optional(z.boolean())
|
|
194
201
|
});
|
|
195
202
|
export const RuntimeConfigSchema = z.object({
|
|
196
203
|
storefront: StorefrontRuntimeConfigSchema,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "8.53.
|
|
4
|
+
"version": "8.53.2",
|
|
5
5
|
"description": "Nuxt integration for the SCAYLE Commerce Engine and Storefront API",
|
|
6
6
|
"author": "SCAYLE Commerce Engine",
|
|
7
7
|
"license": "MIT",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"utility-types": "^3.11.0",
|
|
91
91
|
"vue-router": "^4.4.0",
|
|
92
92
|
"zod": "^4.0.0",
|
|
93
|
-
"@scayle/storefront-core": "8.53.
|
|
93
|
+
"@scayle/storefront-core": "8.53.2",
|
|
94
94
|
"@scayle/unstorage-compression-driver": "1.2.4"
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
@@ -117,11 +117,11 @@
|
|
|
117
117
|
"typescript": "5.9.3",
|
|
118
118
|
"unbuild": "3.6.1",
|
|
119
119
|
"vitest": "4.0.13",
|
|
120
|
-
"vue-tsc": "3.1.
|
|
120
|
+
"vue-tsc": "3.1.5",
|
|
121
121
|
"happy-dom": "20.0.10",
|
|
122
|
+
"@scayle/eslint-config-storefront": "4.7.14",
|
|
122
123
|
"@scayle/eslint-plugin-vue-composable": "0.2.2",
|
|
123
124
|
"@scayle/vitest-config-storefront": "1.0.0",
|
|
124
|
-
"@scayle/eslint-config-storefront": "4.7.14",
|
|
125
125
|
"@scayle/unstorage-scayle-kv-driver": "2.0.9"
|
|
126
126
|
},
|
|
127
127
|
"volta": {
|