@scayle/storefront-nuxt 7.74.0 → 7.75.1
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 +50 -1
- package/dist/index.d.mts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.mjs +15 -0
- package/dist/module.d.mts +2 -2
- package/dist/module.d.ts +2 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +32 -1
- package/dist/rpc.d.mts +1 -1
- package/dist/rpc.d.ts +1 -1
- package/dist/runtime/composables/core/useIDP.d.ts +5 -5
- package/dist/runtime/composables/core/useIDP.mjs +2 -2
- package/dist/runtime/composables/core/useRpc.d.ts +38 -9
- package/dist/runtime/composables/core/useRpc.mjs +29 -49
- package/dist/runtime/composables/core/useUser.d.ts +21 -6
- package/dist/runtime/composables/core/useUser.mjs +26 -10
- package/dist/runtime/composables/storefront/useBasket.d.ts +69 -8
- package/dist/runtime/composables/storefront/useBasket.mjs +16 -18
- package/dist/runtime/composables/storefront/useBrand.d.ts +4 -9
- package/dist/runtime/composables/storefront/useBrand.mjs +5 -12
- package/dist/runtime/composables/storefront/useBrands.d.ts +4 -9
- package/dist/runtime/composables/storefront/useBrands.mjs +5 -12
- package/dist/runtime/composables/storefront/useCategories.d.ts +23 -13
- package/dist/runtime/composables/storefront/useCategories.mjs +8 -12
- package/dist/runtime/composables/storefront/useCategoryById.d.ts +4 -9
- package/dist/runtime/composables/storefront/useCategoryById.mjs +5 -12
- package/dist/runtime/composables/storefront/useCategoryByPath.d.ts +4 -9
- package/dist/runtime/composables/storefront/useCategoryByPath.mjs +5 -12
- package/dist/runtime/composables/storefront/useCurrentPromotions.d.ts +4 -9
- package/dist/runtime/composables/storefront/useCurrentPromotions.mjs +5 -12
- package/dist/runtime/composables/storefront/useFacet.d.ts +60 -15
- package/dist/runtime/composables/storefront/useFacet.mjs +117 -110
- package/dist/runtime/composables/storefront/useFilters.d.ts +4 -12
- package/dist/runtime/composables/storefront/useFilters.mjs +5 -12
- package/dist/runtime/composables/storefront/useNavigationTree.d.ts +4 -9
- package/dist/runtime/composables/storefront/useNavigationTree.mjs +5 -12
- package/dist/runtime/composables/storefront/useNavigationTrees.d.ts +4 -9
- package/dist/runtime/composables/storefront/useNavigationTrees.mjs +5 -12
- package/dist/runtime/composables/storefront/useOrder.d.ts +6 -5
- package/dist/runtime/composables/storefront/useOrder.mjs +2 -2
- package/dist/runtime/composables/storefront/useOrderConfirmation.d.ts +6 -5
- package/dist/runtime/composables/storefront/useOrderConfirmation.mjs +2 -2
- package/dist/runtime/composables/storefront/useProduct.d.ts +4 -9
- package/dist/runtime/composables/storefront/useProduct.mjs +5 -12
- package/dist/runtime/composables/storefront/useProducts.d.ts +4 -21
- package/dist/runtime/composables/storefront/useProducts.mjs +5 -12
- package/dist/runtime/composables/storefront/useProductsByIds.d.ts +4 -9
- package/dist/runtime/composables/storefront/useProductsByIds.mjs +5 -12
- package/dist/runtime/composables/storefront/useProductsByReferenceKeys.d.ts +4 -9
- package/dist/runtime/composables/storefront/useProductsByReferenceKeys.mjs +5 -12
- package/dist/runtime/composables/storefront/useProductsCount.d.ts +4 -11
- package/dist/runtime/composables/storefront/useProductsCount.mjs +5 -12
- package/dist/runtime/composables/storefront/usePromotions.d.ts +4 -9
- package/dist/runtime/composables/storefront/usePromotions.mjs +5 -12
- package/dist/runtime/composables/storefront/usePromotionsByIds.d.ts +4 -9
- package/dist/runtime/composables/storefront/usePromotionsByIds.mjs +5 -12
- package/dist/runtime/composables/storefront/useShopConfiguration.d.ts +4 -9
- package/dist/runtime/composables/storefront/useShopConfiguration.mjs +5 -12
- package/dist/runtime/composables/storefront/useUserAddresses.d.ts +4 -9
- package/dist/runtime/composables/storefront/useUserAddresses.mjs +5 -12
- package/dist/runtime/composables/storefront/useVariant.d.ts +4 -9
- package/dist/runtime/composables/storefront/useVariant.mjs +5 -12
- package/dist/runtime/composables/storefront/useWishlist.d.ts +42 -4
- package/dist/runtime/composables/storefront/useWishlist.mjs +17 -14
- package/dist/runtime/log.mjs +1 -1
- package/dist/runtime/utils/promise.d.ts +9 -0
- package/dist/runtime/utils/promise.mjs +12 -0
- package/dist/runtime/utils/zodSchema.d.ts +22 -22
- package/dist/runtime/utils/zodSchema.mjs +4 -4
- package/dist/shared/{storefront-nuxt.db7a2f93.d.mts → storefront-nuxt.257df9a6.d.mts} +8 -8
- package/dist/shared/{storefront-nuxt.db7a2f93.d.ts → storefront-nuxt.257df9a6.d.ts} +8 -8
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# @scayle/storefront-nuxt
|
|
2
2
|
|
|
3
|
+
## 7.75.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add `immediate` option to `useUser` and deprecate `autoFetch`
|
|
8
|
+
- Log warning when deprecated `autoFetch` option is used
|
|
9
|
+
|
|
10
|
+
## 7.75.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- Configure `keyedComposables` to automatically create keys for `useRpc` wrapping composables instead of relying on hardcoded defaults
|
|
15
|
+
- Export the `extendPromise` util
|
|
16
|
+
- Restore the `useAsyncData` implementation of `useRpc`
|
|
17
|
+
|
|
18
|
+
Originally, `useRpc` was based on `useAsyncData` but in order to fix an issue with wishlists, we restricted the API and changed it to a rough emulation of `useAsyncData`. Because this emulation was similar, but not the same as `useAsyncData` it caused additional confusion. This change brings back the `useAsyncData` implementation.
|
|
19
|
+
|
|
20
|
+
For developers, this means that `useRpc` will behave in the same manner as `useAsyncData`, be subject to the same restrictions and allow the same options.
|
|
21
|
+
|
|
22
|
+
This also means that `useRpc` is now optionally awaitable. `const { data } = await useRpc()` now works as well as `const { data } = useRpc()`. The difference is that the former will wait for the data to load, while the latter will initially be set to the default value.
|
|
23
|
+
|
|
24
|
+
Composables which are simply wrappers around `useRpc` also inherit this new behavior. They accept the same options as `useAsyncData`, return the same properties (and possibly some additional ones) and are optionally awaitable.
|
|
25
|
+
|
|
26
|
+
This includes the following composables:
|
|
27
|
+
|
|
28
|
+
- `useBrand`
|
|
29
|
+
- `useBrands`
|
|
30
|
+
- `useCategories`
|
|
31
|
+
- `useCategoryById`
|
|
32
|
+
- `useCategoryByPath`
|
|
33
|
+
- `useCurrentPromotions`
|
|
34
|
+
- `useFilters`
|
|
35
|
+
- `useNavigationTree`
|
|
36
|
+
- `useNavigationTrees`
|
|
37
|
+
- `useProduct`
|
|
38
|
+
- `useProducts`
|
|
39
|
+
- `useProductsByIds`
|
|
40
|
+
- `useProductsByReferenceKeys`
|
|
41
|
+
- `useProductsCount`
|
|
42
|
+
- `usePromotions`
|
|
43
|
+
- `usePromotionsByIds`
|
|
44
|
+
- `useShopConfiguration`
|
|
45
|
+
- `useUserAddresses`
|
|
46
|
+
- `useVariant`
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- It is no longer mandatory to `await` calls to `useFacet`, `useUser`, `useWishlist` and `useBasket`
|
|
51
|
+
|
|
3
52
|
## 7.74.0
|
|
4
53
|
|
|
5
54
|
### Minor Changes
|
|
@@ -16,7 +65,7 @@
|
|
|
16
65
|
|
|
17
66
|
### Minor Changes
|
|
18
67
|
|
|
19
|
-
- Renamed ModuleOptions to ModuleBaseOptions to differentiate it from other ModuleOptions used in different modules.
|
|
68
|
+
- Breaking: Renamed ModuleOptions to ModuleBaseOptions to differentiate it from other ModuleOptions used in different modules.
|
|
20
69
|
|
|
21
70
|
### Patch Changes
|
|
22
71
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as AdditionalShopConfig, A as AppKeys, B as BapiConfig, h as CheckoutEvent, C as CheckoutShopConfig, M as ModuleBaseOptions, i as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, a as SessionConfig, e as ShopConfig, f as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, g as StorefrontConfig } from './shared/storefront-nuxt.
|
|
1
|
+
export { d as AdditionalShopConfig, A as AppKeys, B as BapiConfig, h as CheckoutEvent, C as CheckoutShopConfig, M as ModuleBaseOptions, i as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, a as SessionConfig, e as ShopConfig, f as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, g as StorefrontConfig } from './shared/storefront-nuxt.257df9a6.mjs';
|
|
2
2
|
export { rpcCall } from './rpc.mjs';
|
|
3
3
|
export * from '@scayle/storefront-core';
|
|
4
4
|
export { LogLevel } from '@scayle/storefront-core';
|
|
@@ -9,6 +9,16 @@ import 'unstorage';
|
|
|
9
9
|
import 'zod';
|
|
10
10
|
import 'nuxt/app';
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* This function accepts a Promise which has the same interface as its resolved value.
|
|
14
|
+
* It returns a new Promise which extends the original Promise and the original Promise's resolve value
|
|
15
|
+
* with all the properties in source.
|
|
16
|
+
* @param promise
|
|
17
|
+
* @param source
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
declare function extendPromise<T extends object, U>(promise: T & Promise<T>, source: U): T & U & Promise<T & U>;
|
|
21
|
+
|
|
12
22
|
interface RpcMethodsStorefront {
|
|
13
23
|
}
|
|
14
24
|
declare module '@scayle/storefront-core' {
|
|
@@ -16,4 +26,4 @@ declare module '@scayle/storefront-core' {
|
|
|
16
26
|
}
|
|
17
27
|
}
|
|
18
28
|
|
|
19
|
-
export type
|
|
29
|
+
export { type RpcMethodsStorefront, extendPromise };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as AdditionalShopConfig, A as AppKeys, B as BapiConfig, h as CheckoutEvent, C as CheckoutShopConfig, M as ModuleBaseOptions, i as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, a as SessionConfig, e as ShopConfig, f as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, g as StorefrontConfig } from './shared/storefront-nuxt.
|
|
1
|
+
export { d as AdditionalShopConfig, A as AppKeys, B as BapiConfig, h as CheckoutEvent, C as CheckoutShopConfig, M as ModuleBaseOptions, i as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, a as SessionConfig, e as ShopConfig, f as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, g as StorefrontConfig } from './shared/storefront-nuxt.257df9a6.js';
|
|
2
2
|
export { rpcCall } from './rpc.js';
|
|
3
3
|
export * from '@scayle/storefront-core';
|
|
4
4
|
export { LogLevel } from '@scayle/storefront-core';
|
|
@@ -9,6 +9,16 @@ import 'unstorage';
|
|
|
9
9
|
import 'zod';
|
|
10
10
|
import 'nuxt/app';
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* This function accepts a Promise which has the same interface as its resolved value.
|
|
14
|
+
* It returns a new Promise which extends the original Promise and the original Promise's resolve value
|
|
15
|
+
* with all the properties in source.
|
|
16
|
+
* @param promise
|
|
17
|
+
* @param source
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
declare function extendPromise<T extends object, U>(promise: T & Promise<T>, source: U): T & U & Promise<T & U>;
|
|
21
|
+
|
|
12
22
|
interface RpcMethodsStorefront {
|
|
13
23
|
}
|
|
14
24
|
declare module '@scayle/storefront-core' {
|
|
@@ -16,4 +26,4 @@ declare module '@scayle/storefront-core' {
|
|
|
16
26
|
}
|
|
17
27
|
}
|
|
18
28
|
|
|
19
|
-
export type
|
|
29
|
+
export { type RpcMethodsStorefront, extendPromise };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
1
|
export { rpcCall } from './rpc.mjs';
|
|
2
2
|
export * from '@scayle/storefront-core';
|
|
3
3
|
export { unwrap } from '@scayle/storefront-core/dist/utils/response';
|
|
4
|
+
|
|
5
|
+
function extendPromise(promise, source) {
|
|
6
|
+
const newPromise = promise.then(
|
|
7
|
+
(result) => Object.assign(result, source)
|
|
8
|
+
);
|
|
9
|
+
const withoutPromise = Object.assign({}, promise);
|
|
10
|
+
for (const key of Object.getOwnPropertyNames(
|
|
11
|
+
Promise.prototype
|
|
12
|
+
)) {
|
|
13
|
+
delete withoutPromise[key];
|
|
14
|
+
}
|
|
15
|
+
return Object.assign(newPromise, Object.assign(withoutPromise, source));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { extendPromise };
|
package/dist/module.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
import { M as ModuleBaseOptions } from './shared/storefront-nuxt.
|
|
3
|
-
export { d as AdditionalShopConfig, A as AppKeys, B as BapiConfig, h as CheckoutEvent, C as CheckoutShopConfig, i as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, a as SessionConfig, e as ShopConfig, f as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, g as StorefrontConfig } from './shared/storefront-nuxt.
|
|
2
|
+
import { M as ModuleBaseOptions } from './shared/storefront-nuxt.257df9a6.mjs';
|
|
3
|
+
export { d as AdditionalShopConfig, A as AppKeys, B as BapiConfig, h as CheckoutEvent, C as CheckoutShopConfig, i as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, a as SessionConfig, e as ShopConfig, f as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, g as StorefrontConfig } from './shared/storefront-nuxt.257df9a6.mjs';
|
|
4
4
|
export { LogLevel } from '@scayle/storefront-core';
|
|
5
5
|
import '@scayle/unstorage-compression-driver';
|
|
6
6
|
import 'unstorage';
|
package/dist/module.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
import { M as ModuleBaseOptions } from './shared/storefront-nuxt.
|
|
3
|
-
export { d as AdditionalShopConfig, A as AppKeys, B as BapiConfig, h as CheckoutEvent, C as CheckoutShopConfig, i as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, a as SessionConfig, e as ShopConfig, f as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, g as StorefrontConfig } from './shared/storefront-nuxt.
|
|
2
|
+
import { M as ModuleBaseOptions } from './shared/storefront-nuxt.257df9a6.js';
|
|
3
|
+
export { d as AdditionalShopConfig, A as AppKeys, B as BapiConfig, h as CheckoutEvent, C as CheckoutShopConfig, i as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, a as SessionConfig, e as ShopConfig, f as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, g as StorefrontConfig } from './shared/storefront-nuxt.257df9a6.js';
|
|
4
4
|
export { LogLevel } from '@scayle/storefront-core';
|
|
5
5
|
import '@scayle/unstorage-compression-driver';
|
|
6
6
|
import 'unstorage';
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -64,7 +64,7 @@ export default {
|
|
|
64
64
|
}`;
|
|
65
65
|
}
|
|
66
66
|
const PACKAGE_NAME = "@scayle/storefront-nuxt";
|
|
67
|
-
const PACKAGE_VERSION = "7.
|
|
67
|
+
const PACKAGE_VERSION = "7.75.0";
|
|
68
68
|
const logger = createConsola({
|
|
69
69
|
fancy: true,
|
|
70
70
|
formatOptions: {
|
|
@@ -315,6 +315,37 @@ Missing RPC Overrides: ${Array.from(overridenRPCMethodNames).map((name) => `'${n
|
|
|
315
315
|
addImportsDir(resolve("runtime/composables/storefront"));
|
|
316
316
|
addImportsDir(resolve("runtime/composables/core"));
|
|
317
317
|
addImportsDir(resolve("runtime/utils"));
|
|
318
|
+
const keyedComposables = [
|
|
319
|
+
"useBrand",
|
|
320
|
+
"useBrands",
|
|
321
|
+
"useCategories",
|
|
322
|
+
"useCategoryById",
|
|
323
|
+
"useCategoryByPath",
|
|
324
|
+
"useCurrentPromotions",
|
|
325
|
+
"useFacet",
|
|
326
|
+
"useFilters",
|
|
327
|
+
"useIDP",
|
|
328
|
+
"useNavigationTree",
|
|
329
|
+
"useNavigationTrees",
|
|
330
|
+
"useOrder",
|
|
331
|
+
"useOrderConfirmation",
|
|
332
|
+
"useProduct",
|
|
333
|
+
"useProducts",
|
|
334
|
+
"useProductsByIds",
|
|
335
|
+
"useProductsByReferenceKeys",
|
|
336
|
+
"useProductsCount",
|
|
337
|
+
"usePromotions",
|
|
338
|
+
"usePromotionsByIds",
|
|
339
|
+
"useShopConfiguration",
|
|
340
|
+
"useUserAddresses",
|
|
341
|
+
"useVariant"
|
|
342
|
+
];
|
|
343
|
+
nuxt.options.optimization.keyedComposables.push(
|
|
344
|
+
...keyedComposables.map((name) => ({
|
|
345
|
+
name,
|
|
346
|
+
argumentLength: 2
|
|
347
|
+
}))
|
|
348
|
+
);
|
|
318
349
|
nuxt.options.build.transpile = [
|
|
319
350
|
...nuxt.options.build?.transpile || [],
|
|
320
351
|
PACKAGE_NAME,
|
package/dist/rpc.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RpcMethodName, RpcMethodParameters, RpcMethodReturnType, RpcContext } from '@scayle/storefront-core';
|
|
2
2
|
import { NuxtApp } from 'nuxt/app';
|
|
3
|
-
import { P as PublicShopConfig } from './shared/storefront-nuxt.
|
|
3
|
+
import { P as PublicShopConfig } from './shared/storefront-nuxt.257df9a6.mjs';
|
|
4
4
|
import '@nuxt/schema';
|
|
5
5
|
import '@scayle/unstorage-compression-driver';
|
|
6
6
|
import 'unstorage';
|
package/dist/rpc.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RpcMethodName, RpcMethodParameters, RpcMethodReturnType, RpcContext } from '@scayle/storefront-core';
|
|
2
2
|
import { NuxtApp } from 'nuxt/app';
|
|
3
|
-
import { P as PublicShopConfig } from './shared/storefront-nuxt.
|
|
3
|
+
import { P as PublicShopConfig } from './shared/storefront-nuxt.257df9a6.js';
|
|
4
4
|
import '@nuxt/schema';
|
|
5
5
|
import '@scayle/unstorage-compression-driver';
|
|
6
6
|
import 'unstorage';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { type MaybeRefOrGetter } from 'vue';
|
|
2
2
|
import type { RpcMethodParameters } from '@scayle/storefront-core';
|
|
3
|
-
export declare function useIDP(params?: MaybeRefOrGetter<RpcMethodParameters<'getExternalIdpRedirect'
|
|
3
|
+
export declare function useIDP(params?: MaybeRefOrGetter<RpcMethodParameters<'getExternalIdpRedirect'>>, key?: string): Promise<{
|
|
4
4
|
data: import("vue").Ref<{
|
|
5
5
|
[k: string]: string;
|
|
6
|
-
}
|
|
6
|
+
}>;
|
|
7
7
|
fetching: import("vue").Ref<boolean>;
|
|
8
|
-
fetch: () => Promise<void>;
|
|
9
|
-
error: import("vue").Ref<import("nuxt/app").NuxtError<unknown> |
|
|
10
|
-
status: import("vue").Ref<import("
|
|
8
|
+
fetch: (opts?: import("nuxt/dist/app/composables/asyncData").AsyncDataExecuteOptions | undefined) => Promise<void>;
|
|
9
|
+
error: import("vue").Ref<import("nuxt/app").NuxtError<unknown> | null>;
|
|
10
|
+
status: import("vue").Ref<import("nuxt/app").AsyncDataRequestStatus>;
|
|
11
11
|
handleIDPLoginCallback: (params: string | {
|
|
12
12
|
code: string;
|
|
13
13
|
}) => Promise<{
|
|
@@ -3,12 +3,12 @@ import { useRpc } from "../core/useRpc.mjs";
|
|
|
3
3
|
import { rpcCall } from "./../../rpc/rpcCall.mjs";
|
|
4
4
|
import { useCurrentShop } from "./useCurrentShop.mjs";
|
|
5
5
|
import { toValue } from "#imports";
|
|
6
|
-
export async function useIDP(params = {}) {
|
|
6
|
+
export async function useIDP(params = {}, key) {
|
|
7
7
|
const nuxtApp = useNuxtApp();
|
|
8
8
|
const shop = useCurrentShop();
|
|
9
9
|
const { data, fetching, fetch, error, status } = await useRpc(
|
|
10
10
|
"getExternalIdpRedirect",
|
|
11
|
-
|
|
11
|
+
key ?? "useIDP",
|
|
12
12
|
params
|
|
13
13
|
);
|
|
14
14
|
const handleIDPLoginCallback = rpcCall(
|
|
@@ -1,18 +1,47 @@
|
|
|
1
1
|
import type { RpcContext, RpcMethodName, RpcMethodParameters, RpcMethodReturnType } from '@scayle/storefront-core';
|
|
2
|
-
import type { AsyncDataOptions
|
|
3
|
-
import {
|
|
2
|
+
import type { AsyncDataOptions } from 'nuxt/app';
|
|
3
|
+
import { useAsyncData } from 'nuxt/app';
|
|
4
|
+
import type { MaybeRefOrGetter } from '#imports';
|
|
4
5
|
type KeysOf<T> = Array<T extends T ? (keyof T extends string ? keyof T : never) : never>;
|
|
5
6
|
export type RpcAsyncDataOptions<TResult> = AsyncDataOptions<TResult, TResult, KeysOf<TResult>, TResult>;
|
|
6
7
|
export interface RpcOptions {
|
|
8
|
+
/** @deprecated use immediate instead */
|
|
7
9
|
autoFetch?: boolean;
|
|
8
10
|
lazy?: boolean;
|
|
9
11
|
}
|
|
12
|
+
export type UseRpcOptions<N extends RpcMethodName> = RpcOptions & RpcAsyncDataOptions<Exclude<Awaited<RpcMethodReturnType<N>>, Response>>;
|
|
13
|
+
export type UseRpcReturn<N extends RpcMethodName> = ExtendedAsyncData<Exclude<Awaited<RpcMethodReturnType<N>>, Response>>;
|
|
10
14
|
export type Status = 'idle' | 'pending' | 'success' | 'error';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
type AsyncData<T> = ReturnType<typeof useAsyncData<T>>;
|
|
16
|
+
type AwaitedAsyncData<T> = Awaited<AsyncData<T>>;
|
|
17
|
+
type _ExtendedAsyncData<T> = AwaitedAsyncData<T> & {
|
|
18
|
+
fetching: AwaitedAsyncData<T>['pending'];
|
|
19
|
+
fetch: AwaitedAsyncData<T>['refresh'];
|
|
20
|
+
};
|
|
21
|
+
export type ExtendedAsyncData<T> = _ExtendedAsyncData<T> & Promise<_ExtendedAsyncData<T>>;
|
|
22
|
+
/**
|
|
23
|
+
* `useRpc` is a wrapper around `useAsyncData` for registered RPC methods
|
|
24
|
+
*
|
|
25
|
+
* This is slightly different from the useRpc we have in Nuxt2
|
|
26
|
+
* It is built on top of useAsyncData and matches its API more than the Nuxt2 API
|
|
27
|
+
* Notably, fetch is now refresh. The fetching property remains the same.
|
|
28
|
+
* It also doesn't directly use rpcCall, instead calling $fetch directly
|
|
29
|
+
* The main difference regards how params are passed:
|
|
30
|
+
* In Nuxt2 for an RPC with params, the params are passed when calling `fetch`.
|
|
31
|
+
* In Nuxt3 for an RPC with params, the params are passed to `useRpc`.
|
|
32
|
+
* Additionally, in Nuxt3 the params can be `Params`, `Ref<Params>` or `() => Params`
|
|
33
|
+
*
|
|
34
|
+
* @param method - the RPC method name
|
|
35
|
+
* @param key - a unique key for persisting the data between server and client and de-duplicating requests
|
|
36
|
+
* @param params - parameters to pass to the RPC method.
|
|
37
|
+
* This can be specified in three ways: as a raw value, a `Ref` or a function that returns the params
|
|
38
|
+
* - When passed as a raw value, the parameters are set at the point `useRpc` is called. Subsequent `refresh` calls will use the same params.
|
|
39
|
+
* - When passed as a function, the function will be invoked each time `refresh` is called to get the params.
|
|
40
|
+
* - When passed as a Ref, a watcher wil be added that calls `refresh` each time params change.
|
|
41
|
+
* @param options - Override the options passed to `useAsyncData`.
|
|
42
|
+
* By default, `useRpc` will set `immediate` to `false` and will pass `[params]` to `watch` if `params` is a `Ref`.
|
|
43
|
+
* But anything passed here will take precedence.
|
|
44
|
+
* @see {@link https://nuxt.com/docs/api/composables/use-async-data#params}
|
|
45
|
+
*/
|
|
46
|
+
export declare function useRpc<N extends RpcMethodName, P extends RpcMethodParameters<N>, TResult extends Exclude<Awaited<RpcMethodReturnType<N>>, Response>, TParams = P extends RpcContext ? undefined : P>(method: N, key: string, params?: MaybeRefOrGetter<TParams>, options?: RpcAsyncDataOptions<TResult> & RpcOptions): ExtendedAsyncData<TResult>;
|
|
18
47
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { unwrap } from "@scayle/storefront-core/dist/utils/response";
|
|
2
|
-
import { useNuxtApp,
|
|
2
|
+
import { useNuxtApp, useAsyncData } from "nuxt/app";
|
|
3
3
|
import { useCoreLog } from "../useCoreLog.mjs";
|
|
4
|
-
import { resolveError } from "../../error/handler.mjs";
|
|
5
4
|
import { useCurrentShop } from "./useCurrentShop.mjs";
|
|
6
|
-
import {
|
|
5
|
+
import { extendPromise } from "../../utils/promise.mjs";
|
|
6
|
+
import { toValue, computed, isRef } from "#imports";
|
|
7
7
|
function getFetch(nuxtApp, log) {
|
|
8
8
|
const fetch = nuxtApp.ssrContext?.event.$fetch ?? $fetch;
|
|
9
9
|
if (nuxtApp.ssrContext?.event && !nuxtApp.ssrContext?.event.$fetch) {
|
|
@@ -11,36 +11,25 @@ function getFetch(nuxtApp, log) {
|
|
|
11
11
|
}
|
|
12
12
|
return fetch;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
const data = resolveError(error);
|
|
16
|
-
return createError(data);
|
|
17
|
-
};
|
|
18
|
-
export async function useRpc(method, key, params, options = { autoFetch: true, lazy: false }) {
|
|
14
|
+
export function useRpc(method, key, params, options) {
|
|
19
15
|
const currentShop = useCurrentShop();
|
|
20
16
|
const log = useCoreLog("rpc");
|
|
21
17
|
const nuxtApp = useNuxtApp();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
() =>
|
|
33
|
-
);
|
|
34
|
-
const status = useState(`${keyPrefix}-status`, () => "idle");
|
|
35
|
-
const fetch = async () => {
|
|
36
|
-
try {
|
|
37
|
-
status.value = "pending";
|
|
38
|
-
fetching.value = true;
|
|
39
|
-
error.value = void 0;
|
|
18
|
+
if (options && options.autoFetch !== void 0) {
|
|
19
|
+
log.warn("autoFetch is disabled; use immediate instead");
|
|
20
|
+
if (options.immediate === void 0) {
|
|
21
|
+
options.immediate = options.autoFetch;
|
|
22
|
+
} else {
|
|
23
|
+
log.warn("autoFetch will be ignored because immediate was specified");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const asyncData = useAsyncData(
|
|
27
|
+
key,
|
|
28
|
+
async () => {
|
|
40
29
|
const apiBasePath = currentShop.value?.apiBasePath ?? "/api";
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
await
|
|
30
|
+
const fetch = getFetch(nuxtApp, log);
|
|
31
|
+
return await unwrap(
|
|
32
|
+
await fetch(`/rpc/${method}`, {
|
|
44
33
|
// @ts-expect-error Type '"POST"' is not assignable to type 'AvailableRouterMethod<`/rpc/${N}`> | Uppercase<AvailableRouterMethod<`/rpc/${N}`>> | undefined'.ts(2322)
|
|
45
34
|
method: "POST",
|
|
46
35
|
body: {
|
|
@@ -52,25 +41,16 @@ export async function useRpc(method, key, params, options = { autoFetch: true, l
|
|
|
52
41
|
}
|
|
53
42
|
})
|
|
54
43
|
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
status.value = error.value ? "error" : "success";
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
...isRef(params) ? { watch: [params] } : {},
|
|
47
|
+
...options
|
|
60
48
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
data,
|
|
71
|
-
fetching,
|
|
72
|
-
fetch,
|
|
73
|
-
error,
|
|
74
|
-
status
|
|
75
|
-
};
|
|
49
|
+
);
|
|
50
|
+
return extendPromise(asyncData, {
|
|
51
|
+
/** @deprecated - use refresh instead */
|
|
52
|
+
fetch: asyncData.refresh,
|
|
53
|
+
/** @deprecated - use `status.value === 'pending'´ instead */
|
|
54
|
+
fetching: computed(() => asyncData.status.value === "pending")
|
|
55
|
+
});
|
|
76
56
|
}
|
|
@@ -1,16 +1,31 @@
|
|
|
1
|
-
import type { ShopUser, UpdatePasswordParams
|
|
2
|
-
export type ExtendedUseUserParams =
|
|
1
|
+
import type { ShopUser, UpdatePasswordParams } from '@scayle/storefront-core';
|
|
2
|
+
export type ExtendedUseUserParams = {
|
|
3
|
+
key?: string;
|
|
4
|
+
/** @deprecated use immediate instead */
|
|
5
|
+
autoFetch?: boolean;
|
|
6
|
+
immediate?: boolean;
|
|
3
7
|
lazy?: boolean;
|
|
4
8
|
};
|
|
5
|
-
export declare function useUser(
|
|
9
|
+
export declare function useUser(options?: ExtendedUseUserParams): {
|
|
6
10
|
user: import("vue").ComputedRef<ShopUser | undefined>;
|
|
7
11
|
isLoggedIn: import("vue").ComputedRef<boolean>;
|
|
8
12
|
customerType: import("vue").ComputedRef<"guest" | "new" | "existing">;
|
|
9
13
|
fetching: import("vue").Ref<boolean>;
|
|
10
|
-
fetch: () => Promise<void>;
|
|
14
|
+
fetch: (opts?: import("nuxt/dist/app/composables/asyncData").AsyncDataExecuteOptions | undefined) => Promise<void>;
|
|
11
15
|
forceRefresh: () => Promise<void>;
|
|
12
16
|
updateUser: (payload: Partial<ShopUser>) => Promise<void>;
|
|
13
17
|
updatePassword: (payload: UpdatePasswordParams) => Promise<void>;
|
|
14
|
-
error: import("vue").Ref<import("nuxt/app").NuxtError<unknown> |
|
|
15
|
-
status: import("vue").Ref<import("
|
|
18
|
+
error: import("vue").Ref<import("nuxt/app").NuxtError<unknown> | null>;
|
|
19
|
+
status: import("vue").Ref<import("nuxt/app").AsyncDataRequestStatus>;
|
|
20
|
+
} & Promise<{
|
|
21
|
+
user: import("vue").ComputedRef<ShopUser | undefined>;
|
|
22
|
+
isLoggedIn: import("vue").ComputedRef<boolean>;
|
|
23
|
+
customerType: import("vue").ComputedRef<"guest" | "new" | "existing">;
|
|
24
|
+
fetching: import("vue").Ref<boolean>;
|
|
25
|
+
fetch: (opts?: import("nuxt/dist/app/composables/asyncData").AsyncDataExecuteOptions | undefined) => Promise<void>;
|
|
26
|
+
forceRefresh: () => Promise<void>;
|
|
27
|
+
updateUser: (payload: Partial<ShopUser>) => Promise<void>;
|
|
28
|
+
updatePassword: (payload: UpdatePasswordParams) => Promise<void>;
|
|
29
|
+
error: import("vue").Ref<import("nuxt/app").NuxtError<unknown> | null>;
|
|
30
|
+
status: import("vue").Ref<import("nuxt/app").AsyncDataRequestStatus>;
|
|
16
31
|
}>;
|
|
@@ -2,26 +2,42 @@ import { useNuxtApp } from "nuxt/app";
|
|
|
2
2
|
import { computed } from "vue";
|
|
3
3
|
import { rpcCall } from "../../rpc/rpcCall.mjs";
|
|
4
4
|
import { useCoreLog } from "../useCoreLog.mjs";
|
|
5
|
+
import { extendPromise } from "../../utils/promise.mjs";
|
|
5
6
|
import { useRpc } from "./useRpc.mjs";
|
|
6
7
|
import { useCurrentShop } from "./useCurrentShop.mjs";
|
|
7
8
|
import { toValue } from "#imports";
|
|
8
|
-
export
|
|
9
|
-
autoFetch = true,
|
|
10
|
-
lazy = false,
|
|
11
|
-
key = "useUser"
|
|
12
|
-
} = {}) {
|
|
9
|
+
export function useUser(options = {}) {
|
|
13
10
|
const nuxtApp = useNuxtApp();
|
|
14
11
|
const shop = useCurrentShop();
|
|
15
12
|
const log = useCoreLog("useUser");
|
|
16
|
-
|
|
13
|
+
if (options && options.autoFetch !== void 0) {
|
|
14
|
+
log.warn("autoFetch is disabled; use immediate instead");
|
|
15
|
+
if (options.immediate === void 0) {
|
|
16
|
+
options.immediate = options.autoFetch;
|
|
17
|
+
} else {
|
|
18
|
+
log.warn("autoFetch will be ignored because immediate was specified");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const {
|
|
22
|
+
immediate = true,
|
|
23
|
+
lazy = false,
|
|
24
|
+
key = "useUser"
|
|
25
|
+
} = options;
|
|
26
|
+
const asyncDataPromise = useRpc(
|
|
17
27
|
"getUser",
|
|
18
28
|
key,
|
|
19
29
|
void 0,
|
|
20
30
|
{
|
|
21
|
-
|
|
22
|
-
lazy
|
|
31
|
+
immediate,
|
|
32
|
+
lazy,
|
|
33
|
+
server: false,
|
|
34
|
+
dedupe: "defer",
|
|
35
|
+
getCachedData: (key2) => {
|
|
36
|
+
return toValue(nuxtApp._asyncData[key2]?.data) ?? void 0;
|
|
37
|
+
}
|
|
23
38
|
}
|
|
24
39
|
);
|
|
40
|
+
const { data, fetching, fetch, error, status } = asyncDataPromise;
|
|
25
41
|
const updateUser = async (payload) => {
|
|
26
42
|
log.debug("Update user");
|
|
27
43
|
data.value = await rpcCall(
|
|
@@ -53,7 +69,7 @@ export async function useUser({
|
|
|
53
69
|
log.debug("Refresh user");
|
|
54
70
|
data.value = await rpcCall(nuxtApp, "refreshUser", toValue(shop))();
|
|
55
71
|
};
|
|
56
|
-
return {
|
|
72
|
+
return extendPromise(asyncDataPromise.then(() => ({})), {
|
|
57
73
|
user,
|
|
58
74
|
isLoggedIn,
|
|
59
75
|
customerType,
|
|
@@ -64,5 +80,5 @@ export async function useUser({
|
|
|
64
80
|
updatePassword,
|
|
65
81
|
error,
|
|
66
82
|
status
|
|
67
|
-
};
|
|
83
|
+
});
|
|
68
84
|
}
|
|
@@ -5,18 +5,79 @@ type UseBasketOptions = Partial<{
|
|
|
5
5
|
params: MaybeRefOrGetter<RpcMethodParameters<'getBasket'>>;
|
|
6
6
|
key: string;
|
|
7
7
|
}>;
|
|
8
|
-
export declare function useBasket({ params, key, }?: UseBasketOptions):
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
export declare function useBasket({ params, key, }?: UseBasketOptions): import("nuxt/dist/app/composables/asyncData")._AsyncData<BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>, import("nuxt/app").NuxtError<unknown> | null> & {
|
|
9
|
+
fetching: import("vue").Ref<boolean>;
|
|
10
|
+
fetch: (opts?: import("nuxt/dist/app/composables/asyncData").AsyncDataExecuteOptions | undefined) => Promise<void>;
|
|
11
|
+
} & {
|
|
12
|
+
data: import("vue").Ref<BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>>;
|
|
13
|
+
items: import("vue").ComputedRef<import("@scayle/storefront-api").BasketItem<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>[]>;
|
|
14
|
+
cost: import("vue").ComputedRef<import("@scayle/storefront-api").BasketTotalPrice>;
|
|
15
|
+
key: import("vue").ComputedRef<import("@scayle/storefront-api").BasketKey>;
|
|
16
|
+
packages: import("vue").ComputedRef<import("@scayle/storefront-api").BasketPackageInformation[]>;
|
|
17
|
+
shippingDates: import("vue").ComputedRef<(string | null)[] | undefined>;
|
|
18
|
+
isEmpty: import("vue").ComputedRef<boolean>;
|
|
19
|
+
fetching: import("vue").Ref<boolean>;
|
|
20
|
+
fetch: (opts?: import("nuxt/dist/app/composables/asyncData").AsyncDataExecuteOptions | undefined) => Promise<void>;
|
|
21
|
+
count: import("vue").ComputedRef<number>;
|
|
22
|
+
countWithoutSoldOutItems: import("vue").ComputedRef<number>;
|
|
23
|
+
addItem: ({ variantId, promotionId, quantity, existingItemHandling, displayData, customData, itemGroup, }: AddOrUpdateItemType & {
|
|
24
|
+
existingItemHandling?: ExistingItemHandling;
|
|
25
|
+
}) => Promise<void>;
|
|
26
|
+
addItems: (items: AddOrUpdateItemType[], existingItemHandling?: 1) => Promise<void>;
|
|
27
|
+
removeItem: (item: {
|
|
28
|
+
variantId: number;
|
|
29
|
+
}) => Promise<void>;
|
|
30
|
+
clear: () => Promise<void>;
|
|
31
|
+
contains: (item: {
|
|
32
|
+
variantId: number;
|
|
33
|
+
} | {
|
|
34
|
+
productId: number;
|
|
35
|
+
}) => boolean;
|
|
36
|
+
products: import("vue").ComputedRef<import("@scayle/storefront-api").Product[]>;
|
|
37
|
+
findItem: (item: {
|
|
38
|
+
variantId: number;
|
|
39
|
+
} | {
|
|
40
|
+
productId: number;
|
|
41
|
+
}) => import("@scayle/storefront-api").BasketItem<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant> | undefined;
|
|
42
|
+
generateBasketKey: ({ keyTemplate, hashAlgorithm, shopId, userId, log, }: {
|
|
43
|
+
keyTemplate: string;
|
|
44
|
+
hashAlgorithm: import("@scayle/storefront-core").HashAlgorithm;
|
|
45
|
+
shopId: string;
|
|
46
|
+
userId: string;
|
|
47
|
+
log?: import("@scayle/storefront-core").Log | undefined;
|
|
48
|
+
}) => Promise<string>;
|
|
49
|
+
mergeBaskets: (args: {
|
|
50
|
+
fromBasketKey: string;
|
|
51
|
+
toBasketKey: string;
|
|
52
|
+
}) => Promise<{
|
|
53
|
+
type: "failure";
|
|
54
|
+
statusCode: number;
|
|
55
|
+
basket: BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>;
|
|
56
|
+
} | {
|
|
57
|
+
readonly type: "success";
|
|
58
|
+
readonly basket: BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>;
|
|
59
|
+
} | {
|
|
60
|
+
readonly type: "failure";
|
|
61
|
+
readonly basket: BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>;
|
|
62
|
+
readonly errors: import("@scayle/storefront-api").AddOrUpdateItemError[];
|
|
63
|
+
} | undefined>;
|
|
64
|
+
error: import("vue").Ref<import("nuxt/app").NuxtError<unknown> | null>;
|
|
65
|
+
status: import("vue").Ref<import("nuxt/app").AsyncDataRequestStatus>;
|
|
66
|
+
} & Promise<import("nuxt/dist/app/composables/asyncData")._AsyncData<BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>, import("nuxt/app").NuxtError<unknown> | null> & {
|
|
67
|
+
fetching: import("vue").Ref<boolean>;
|
|
68
|
+
fetch: (opts?: import("nuxt/dist/app/composables/asyncData").AsyncDataExecuteOptions | undefined) => Promise<void>;
|
|
69
|
+
} & {
|
|
70
|
+
data: import("vue").Ref<BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>>;
|
|
71
|
+
items: import("vue").ComputedRef<import("@scayle/storefront-api").BasketItem<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>[]>;
|
|
72
|
+
cost: import("vue").ComputedRef<import("@scayle/storefront-api").BasketTotalPrice>;
|
|
73
|
+
key: import("vue").ComputedRef<import("@scayle/storefront-api").BasketKey>;
|
|
74
|
+
packages: import("vue").ComputedRef<import("@scayle/storefront-api").BasketPackageInformation[]>;
|
|
14
75
|
shippingDates: import("vue").ComputedRef<(string | null)[] | undefined>;
|
|
15
76
|
isEmpty: import("vue").ComputedRef<boolean>;
|
|
16
77
|
fetching: import("vue").Ref<boolean>;
|
|
17
78
|
fetch: (opts?: import("nuxt/dist/app/composables/asyncData").AsyncDataExecuteOptions | undefined) => Promise<void>;
|
|
18
|
-
count: import("vue").ComputedRef<number
|
|
19
|
-
countWithoutSoldOutItems: import("vue").ComputedRef<number
|
|
79
|
+
count: import("vue").ComputedRef<number>;
|
|
80
|
+
countWithoutSoldOutItems: import("vue").ComputedRef<number>;
|
|
20
81
|
addItem: ({ variantId, promotionId, quantity, existingItemHandling, displayData, customData, itemGroup, }: AddOrUpdateItemType & {
|
|
21
82
|
existingItemHandling?: ExistingItemHandling;
|
|
22
83
|
}) => Promise<void>;
|