@scayle/storefront-nuxt 7.95.4 → 8.0.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 +476 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/module.d.mts +2 -2
- package/dist/module.d.ts +2 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +6 -6
- package/dist/runtime/api/rpcHandler.d.ts +4 -6
- package/dist/runtime/campaignKey.d.ts +1 -2
- package/dist/runtime/campaignKey.js +3 -9
- package/dist/runtime/composables/core/useIDP.d.ts +2 -4
- package/dist/runtime/composables/core/useIDP.js +1 -8
- package/dist/runtime/composables/core/useRpc.d.ts +4 -17
- package/dist/runtime/composables/core/useRpc.js +11 -20
- package/dist/runtime/composables/core/useSession.d.ts +1 -1
- package/dist/runtime/composables/core/useUser.d.ts +2 -4
- package/dist/runtime/composables/core/useUser.js +3 -12
- package/dist/runtime/composables/index.d.ts +0 -3
- package/dist/runtime/composables/index.js +0 -3
- package/dist/runtime/composables/storefront/useBasket.d.ts +6 -4
- package/dist/runtime/composables/storefront/useBasket.js +68 -38
- package/dist/runtime/composables/storefront/useBrand.d.ts +2 -4
- package/dist/runtime/composables/storefront/useBrand.js +3 -4
- package/dist/runtime/composables/storefront/useBrands.d.ts +2 -4
- package/dist/runtime/composables/storefront/useBrands.js +3 -4
- package/dist/runtime/composables/storefront/useCategories.d.ts +3 -5
- package/dist/runtime/composables/storefront/useCategories.js +3 -8
- package/dist/runtime/composables/storefront/useCategoryById.d.ts +2 -4
- package/dist/runtime/composables/storefront/useCategoryById.js +3 -4
- package/dist/runtime/composables/storefront/useCategoryByPath.d.ts +2 -4
- package/dist/runtime/composables/storefront/useCategoryByPath.js +3 -4
- package/dist/runtime/composables/storefront/useCurrentPromotions.d.ts +2 -4
- package/dist/runtime/composables/storefront/useCurrentPromotions.js +3 -4
- package/dist/runtime/composables/storefront/useFilters.d.ts +2 -4
- package/dist/runtime/composables/storefront/useFilters.js +3 -4
- package/dist/runtime/composables/storefront/useNavigationTree.d.ts +3 -11
- package/dist/runtime/composables/storefront/useNavigationTree.js +6 -9
- package/dist/runtime/composables/storefront/useNavigationTrees.d.ts +2 -4
- package/dist/runtime/composables/storefront/useNavigationTrees.js +3 -4
- package/dist/runtime/composables/storefront/useOrder.d.ts +3 -5
- package/dist/runtime/composables/storefront/useOrder.js +3 -5
- package/dist/runtime/composables/storefront/useOrderConfirmation.d.ts +3 -5
- package/dist/runtime/composables/storefront/useOrderConfirmation.js +2 -2
- package/dist/runtime/composables/storefront/useProduct.d.ts +2 -4
- package/dist/runtime/composables/storefront/useProduct.js +3 -4
- package/dist/runtime/composables/storefront/useProducts.d.ts +2 -4
- package/dist/runtime/composables/storefront/useProducts.js +3 -4
- package/dist/runtime/composables/storefront/useProductsByIds.d.ts +2 -4
- package/dist/runtime/composables/storefront/useProductsByIds.js +3 -4
- package/dist/runtime/composables/storefront/useProductsByReferenceKeys.d.ts +2 -4
- package/dist/runtime/composables/storefront/useProductsByReferenceKeys.js +3 -4
- package/dist/runtime/composables/storefront/useProductsCount.d.ts +2 -4
- package/dist/runtime/composables/storefront/useProductsCount.js +3 -4
- package/dist/runtime/composables/storefront/usePromotions.d.ts +2 -4
- package/dist/runtime/composables/storefront/usePromotions.js +3 -4
- package/dist/runtime/composables/storefront/usePromotionsByIds.d.ts +2 -4
- package/dist/runtime/composables/storefront/usePromotionsByIds.js +3 -4
- package/dist/runtime/composables/storefront/useShopConfiguration.d.ts +1 -3
- package/dist/runtime/composables/storefront/useShopConfiguration.js +3 -4
- package/dist/runtime/composables/storefront/useStorefrontSearch.d.ts +5 -3
- package/dist/runtime/composables/storefront/useStorefrontSearch.js +3 -5
- package/dist/runtime/composables/storefront/useUserAddresses.d.ts +1 -3
- package/dist/runtime/composables/storefront/useUserAddresses.js +3 -4
- package/dist/runtime/composables/storefront/useVariant.d.ts +2 -4
- package/dist/runtime/composables/storefront/useVariant.js +3 -4
- package/dist/runtime/composables/storefront/useWishlist.d.ts +2 -3
- package/dist/runtime/composables/storefront/useWishlist.js +12 -21
- package/dist/runtime/context.js +1 -5
- package/dist/runtime/createLog.d.ts +1 -1
- package/dist/runtime/error/handler.d.ts +1 -1
- package/dist/runtime/error/handler.js +1 -28
- package/dist/runtime/nitro/plugins/nitroRuntimeStorageConfig.js +5 -93
- package/dist/runtime/plugin/shop.d.ts +4 -4
- package/dist/runtime/rpc/rpcCall.d.ts +1 -1
- package/dist/runtime/server/middleware/bootstrap-utils.d.ts +1 -5
- package/dist/runtime/server/middleware/bootstrap-utils.js +2 -4
- package/dist/runtime/server/middleware/bootstrap.js +3 -5
- package/dist/runtime/server/utils/cacheStorage.d.ts +1 -1
- package/dist/runtime/server/utils/cacheStorage.js +2 -2
- package/dist/runtime/utils/zodSchema.d.ts +467 -1840
- package/dist/runtime/utils/zodSchema.js +34 -83
- package/dist/shared/{storefront-nuxt.80aa5060.d.ts → storefront-nuxt.a816664e.d.mts} +4 -25
- package/dist/shared/{storefront-nuxt.80aa5060.d.mts → storefront-nuxt.a816664e.d.ts} +4 -25
- package/dist/test/factories.d.mts +1 -1
- package/dist/test/factories.d.ts +1 -1
- package/dist/test/factories.mjs +0 -2
- package/dist/types.d.mts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +8 -8
- package/dist/runtime/composables/storefront/useFacet.d.ts +0 -100
- package/dist/runtime/composables/storefront/useFacet.js +0 -210
- package/dist/runtime/composables/storefront/useQueryFilterState.d.ts +0 -13
- package/dist/runtime/composables/storefront/useQueryFilterState.js +0 -78
- package/dist/runtime/composables/storefront/useSearch.d.ts +0 -14
- package/dist/runtime/composables/storefront/useSearch.js +0 -44
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useRpc } from "../core/useRpc.js";
|
|
2
2
|
import { extendPromise } from "../../utils/promise.js";
|
|
3
|
-
import { useRpcCall } from "../core/useRpcCall.js";
|
|
4
3
|
export function useIDP(params = {}, key) {
|
|
5
4
|
const useRpcPromise = useRpc(
|
|
6
5
|
"getExternalIdpRedirect",
|
|
@@ -9,21 +8,15 @@ export function useIDP(params = {}, key) {
|
|
|
9
8
|
);
|
|
10
9
|
const {
|
|
11
10
|
data,
|
|
12
|
-
fetch,
|
|
13
|
-
fetching,
|
|
14
11
|
error,
|
|
15
12
|
refresh,
|
|
16
13
|
status
|
|
17
14
|
} = useRpcPromise;
|
|
18
|
-
const handleIDPLoginCallback = useRpcCall("handleIDPLoginCallback");
|
|
19
15
|
return extendPromise(useRpcPromise.then(() => ({})), {
|
|
20
16
|
data,
|
|
21
17
|
fetch,
|
|
22
|
-
fetching,
|
|
23
18
|
error,
|
|
24
19
|
refresh,
|
|
25
|
-
status
|
|
26
|
-
// TODO: [Next Major Release] Deprecate the property here and remove it with the next major release
|
|
27
|
-
handleIDPLoginCallback
|
|
20
|
+
status
|
|
28
21
|
});
|
|
29
22
|
}
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import type { RpcContext, RpcMethodName, RpcMethodParameters, RpcMethodReturnType } from '@scayle/storefront-core';
|
|
2
|
-
import type
|
|
3
|
-
import {
|
|
4
|
-
import type { MaybeRefOrGetter } from '#imports';
|
|
2
|
+
import { type AsyncDataOptions, useAsyncData } from 'nuxt/app';
|
|
3
|
+
import { type MaybeRefOrGetter } from 'vue';
|
|
5
4
|
export type KeysOf<T> = Array<T extends T ? (keyof T extends string ? keyof T : never) : never>;
|
|
6
|
-
export type RpcOptions = {
|
|
7
|
-
/** @deprecated use immediate instead */
|
|
8
|
-
autoFetch?: boolean;
|
|
9
|
-
lazy?: boolean;
|
|
10
|
-
};
|
|
11
5
|
/** The normalized return type of an RPC */
|
|
12
6
|
export type NormalizedRpcResponse<N extends RpcMethodName> = Exclude<Awaited<RpcMethodReturnType<N>>, Response>;
|
|
13
|
-
|
|
14
|
-
* Extend AsyncDataOptions with autoFetch (deprecated) and lazy (unused)
|
|
15
|
-
*/
|
|
16
|
-
export type UseRpcOptions<N extends RpcMethodName, DataT = NormalizedRpcResponse<N>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null, ResponseT = NormalizedRpcResponse<N>> = RpcOptions & AsyncDataOptions<ResponseT, DataT, PickKeys, DefaultT>;
|
|
7
|
+
export type UseRpcOptions<N extends RpcMethodName, DataT = NormalizedRpcResponse<N>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null, ResponseT = NormalizedRpcResponse<N>> = AsyncDataOptions<ResponseT, DataT, PickKeys, DefaultT>;
|
|
17
8
|
/**
|
|
18
9
|
* The return type of a composable based on useRpc
|
|
19
10
|
*/
|
|
@@ -21,11 +12,7 @@ export type UseRpcReturn<N extends RpcMethodName, DataT = NormalizedRpcResponse<
|
|
|
21
12
|
export type Status = 'idle' | 'pending' | 'success' | 'error';
|
|
22
13
|
type AsyncData<ResT, ErrorT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null> = ReturnType<typeof useAsyncData<ResT, ErrorT, DataT, PickKeys, DefaultT>>;
|
|
23
14
|
type AwaitedAsyncData<ResT, ErrorT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null> = Awaited<AsyncData<ResT, ErrorT, DataT, PickKeys, DefaultT>>;
|
|
24
|
-
type
|
|
25
|
-
fetching: AwaitedAsyncData<ResT, ErrorT, DataT, PickKeys, DefaultT>['pending'];
|
|
26
|
-
fetch: AwaitedAsyncData<ResT, ErrorT, DataT, PickKeys, DefaultT>['refresh'];
|
|
27
|
-
};
|
|
28
|
-
export type ExtendedAsyncData<ResT, ErrorT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null> = _ExtendedAsyncData<ResT, ErrorT, DataT, PickKeys, DefaultT> & Promise<_ExtendedAsyncData<ResT, ErrorT, DataT, PickKeys, DefaultT>>;
|
|
15
|
+
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>>;
|
|
29
16
|
/**
|
|
30
17
|
* `useRpc` is a wrapper around `useAsyncData` for registered RPC methods
|
|
31
18
|
*
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { unwrap } from "@scayle/storefront-core/dist/utils/response";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
useNuxtApp,
|
|
4
|
+
useAsyncData
|
|
5
|
+
} from "nuxt/app";
|
|
3
6
|
import { useCoreLog } from "../useCoreLog.js";
|
|
4
7
|
import { useCurrentShop } from "./useCurrentShop.js";
|
|
5
|
-
import {
|
|
6
|
-
import { toValue, computed, isRef } from "#imports";
|
|
8
|
+
import { toValue, isRef } from "vue";
|
|
7
9
|
import { useRuntimeConfig } from "#app/nuxt";
|
|
8
10
|
function getFetch(nuxtApp, log) {
|
|
9
11
|
const fetch = nuxtApp.ssrContext?.event.$fetch ?? $fetch;
|
|
@@ -16,15 +18,9 @@ export function useRpc(method, key, params, options) {
|
|
|
16
18
|
const currentShop = useCurrentShop();
|
|
17
19
|
const log = useCoreLog("rpc");
|
|
18
20
|
const nuxtApp = useNuxtApp();
|
|
19
|
-
const {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (options.immediate === void 0) {
|
|
23
|
-
options.immediate = options.autoFetch;
|
|
24
|
-
} else {
|
|
25
|
-
log.warn("autoFetch will be ignored because immediate was specified");
|
|
26
|
-
}
|
|
27
|
-
}
|
|
21
|
+
const {
|
|
22
|
+
public: { storefront }
|
|
23
|
+
} = useRuntimeConfig();
|
|
28
24
|
const asyncData = useAsyncData(
|
|
29
25
|
key,
|
|
30
26
|
async () => {
|
|
@@ -47,17 +43,12 @@ export function useRpc(method, key, params, options) {
|
|
|
47
43
|
{
|
|
48
44
|
// Both refs and getter functions are valid watch sources
|
|
49
45
|
...isRef(params) || typeof params === "function" ? { watch: [params] } : {},
|
|
50
|
-
getCachedData:
|
|
46
|
+
getCachedData: storefront.legacy?.enableDefaultGetCachedDataOverride ? (key2, nuxtApp2) => {
|
|
51
47
|
const hydrationData = nuxtApp2.isHydrating ? nuxtApp2.payload.data[key2] : nuxtApp2.static.data[key2];
|
|
52
48
|
return hydrationData ?? nuxtApp2._asyncData[key2]?.data.value;
|
|
53
|
-
},
|
|
49
|
+
} : void 0,
|
|
54
50
|
...options
|
|
55
51
|
}
|
|
56
52
|
);
|
|
57
|
-
return
|
|
58
|
-
/** @deprecated - use refresh instead */
|
|
59
|
-
fetch: asyncData.refresh,
|
|
60
|
-
/** @deprecated - use `status.value === 'pending'´ instead */
|
|
61
|
-
fetching: computed(() => asyncData.status.value === "pending")
|
|
62
|
-
});
|
|
53
|
+
return asyncData;
|
|
63
54
|
}
|
|
@@ -20,7 +20,7 @@ export declare function useSession(): {
|
|
|
20
20
|
success: false;
|
|
21
21
|
}>;
|
|
22
22
|
resetPasswordByHash: (params: import("utility-types").Optional<import("@scayle/storefront-core").UpdatePasswordByHashRequest, "shop_id">) => Promise<never>;
|
|
23
|
-
loginWithIDP: (params:
|
|
23
|
+
loginWithIDP: (params: {
|
|
24
24
|
code: string;
|
|
25
25
|
}) => Promise<{
|
|
26
26
|
message: string;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import type { ShopUser, UpdatePasswordParams } from '@scayle/storefront-core';
|
|
2
2
|
import { type UseRpcReturn } from './useRpc.js';
|
|
3
|
-
import { type ComputedRef } from '
|
|
3
|
+
import { type ComputedRef } from 'vue';
|
|
4
4
|
export type ExtendedUseUserParams = {
|
|
5
5
|
key?: string;
|
|
6
|
-
/** @deprecated use immediate instead */
|
|
7
|
-
autoFetch?: boolean;
|
|
8
6
|
immediate?: boolean;
|
|
9
7
|
lazy?: boolean;
|
|
10
8
|
};
|
|
11
|
-
type UseUserBaseReturn = Pick<Awaited<UseRpcReturn<'getUser'>>, 'error' | 'status' | '
|
|
9
|
+
type UseUserBaseReturn = Pick<Awaited<UseRpcReturn<'getUser'>>, 'error' | 'status' | 'refresh'> & {
|
|
12
10
|
updateUser: (payload: Partial<ShopUser>) => Promise<void>;
|
|
13
11
|
updatePassword: (payload: UpdatePasswordParams) => Promise<void>;
|
|
14
12
|
user: ComputedRef<ShopUser | undefined>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { useNuxtApp } from "nuxt/app";
|
|
2
|
-
import { computed } from "vue";
|
|
3
2
|
import { useCoreLog } from "../useCoreLog.js";
|
|
4
3
|
import { extendPromise } from "../../utils/promise.js";
|
|
5
4
|
import { useRpc } from "./useRpc.js";
|
|
6
|
-
import { toValue } from "
|
|
5
|
+
import { toValue, computed } from "vue";
|
|
7
6
|
import { useRpcCall } from "../core/useRpcCall.js";
|
|
8
7
|
export function useUser(options = {}) {
|
|
9
8
|
const nuxtApp = useNuxtApp();
|
|
@@ -11,14 +10,6 @@ export function useUser(options = {}) {
|
|
|
11
10
|
const updateUserRpc = useRpcCall("updateShopUser");
|
|
12
11
|
const updatePasswordRpc = useRpcCall("updatePassword");
|
|
13
12
|
const refreshUserRpc = useRpcCall("refreshUser");
|
|
14
|
-
if (options && options.autoFetch !== void 0) {
|
|
15
|
-
log.warn("autoFetch is disabled; use immediate instead");
|
|
16
|
-
if (options.immediate === void 0) {
|
|
17
|
-
options.immediate = options.autoFetch;
|
|
18
|
-
} else {
|
|
19
|
-
log.warn("autoFetch will be ignored because immediate was specified");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
13
|
const {
|
|
23
14
|
immediate = true,
|
|
24
15
|
lazy = false,
|
|
@@ -38,7 +29,7 @@ export function useUser(options = {}) {
|
|
|
38
29
|
}
|
|
39
30
|
}
|
|
40
31
|
);
|
|
41
|
-
const { data,
|
|
32
|
+
const { data, refresh, error, status } = asyncDataPromise;
|
|
42
33
|
const updateUser = async (payload) => {
|
|
43
34
|
log.debug("Update user");
|
|
44
35
|
data.value = await updateUserRpc(payload);
|
|
@@ -66,7 +57,7 @@ export function useUser(options = {}) {
|
|
|
66
57
|
user,
|
|
67
58
|
isLoggedIn,
|
|
68
59
|
customerType,
|
|
69
|
-
|
|
60
|
+
refresh,
|
|
70
61
|
fetch,
|
|
71
62
|
forceRefresh,
|
|
72
63
|
updateUser,
|
|
@@ -14,7 +14,6 @@ export * from './storefront/useCategories.js';
|
|
|
14
14
|
export * from './storefront/useCategoryById.js';
|
|
15
15
|
export * from './storefront/useCategoryByPath.js';
|
|
16
16
|
export * from './storefront/useCurrentPromotions.js';
|
|
17
|
-
export * from './storefront/useFacet.js';
|
|
18
17
|
export * from './storefront/useFilters.js';
|
|
19
18
|
export * from './storefront/useNavigationTree.js';
|
|
20
19
|
export * from './storefront/useNavigationTrees.js';
|
|
@@ -27,8 +26,6 @@ export * from './storefront/useProductsByReferenceKeys.js';
|
|
|
27
26
|
export * from './storefront/useProductsCount.js';
|
|
28
27
|
export * from './storefront/usePromotions.js';
|
|
29
28
|
export * from './storefront/usePromotionsByIds.js';
|
|
30
|
-
export * from './storefront/useQueryFilterState.js';
|
|
31
|
-
export * from './storefront/useSearch.js';
|
|
32
29
|
export * from './storefront/useShopConfiguration.js';
|
|
33
30
|
export * from './storefront/useStorefrontSearch.js';
|
|
34
31
|
export * from './storefront/useUserAddresses.js';
|
|
@@ -14,7 +14,6 @@ export * from "./storefront/useCategories.js";
|
|
|
14
14
|
export * from "./storefront/useCategoryById.js";
|
|
15
15
|
export * from "./storefront/useCategoryByPath.js";
|
|
16
16
|
export * from "./storefront/useCurrentPromotions.js";
|
|
17
|
-
export * from "./storefront/useFacet.js";
|
|
18
17
|
export * from "./storefront/useFilters.js";
|
|
19
18
|
export * from "./storefront/useNavigationTree.js";
|
|
20
19
|
export * from "./storefront/useNavigationTrees.js";
|
|
@@ -27,8 +26,6 @@ export * from "./storefront/useProductsByReferenceKeys.js";
|
|
|
27
26
|
export * from "./storefront/useProductsCount.js";
|
|
28
27
|
export * from "./storefront/usePromotions.js";
|
|
29
28
|
export * from "./storefront/usePromotionsByIds.js";
|
|
30
|
-
export * from "./storefront/useQueryFilterState.js";
|
|
31
|
-
export * from "./storefront/useSearch.js";
|
|
32
29
|
export * from "./storefront/useShopConfiguration.js";
|
|
33
30
|
export * from "./storefront/useStorefrontSearch.js";
|
|
34
31
|
export * from "./storefront/useUserAddresses.js";
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { AddOrUpdateItemType, RpcMethodParameters, RpcMethodReturnType, BasketItem, Product, BasketTotalPrice } from '@scayle/storefront-core';
|
|
2
2
|
import { ExistingItemHandling } from '@scayle/storefront-core';
|
|
3
|
-
import { type UseRpcReturn } from '../core/useRpc.js';
|
|
4
|
-
import { type MaybeRefOrGetter, type ComputedRef } from '
|
|
3
|
+
import { type NormalizedRpcResponse, type UseRpcReturn } from '../core/useRpc.js';
|
|
4
|
+
import { type MaybeRefOrGetter, type ComputedRef, type Ref } from 'vue';
|
|
5
5
|
import type { BasketKey, BasketPackageInformation } from '@scayle/storefront-api';
|
|
6
6
|
type UseBasketOptions = Partial<{
|
|
7
7
|
params: MaybeRefOrGetter<RpcMethodParameters<'getBasket'>>;
|
|
8
8
|
key: string;
|
|
9
9
|
}>;
|
|
10
|
-
type UseBasketBaseReturn = Awaited<UseRpcReturn<'getBasket'
|
|
10
|
+
type UseBasketBaseReturn = Omit<Awaited<UseRpcReturn<'getBasket'>>, 'data'> & {
|
|
11
|
+
data: Ref<NormalizedRpcResponse<'getBasket'>['basket'] | null>;
|
|
12
|
+
} & {
|
|
11
13
|
addItem: (item: AddOrUpdateItemType & {
|
|
12
14
|
existingItemHandling?: ExistingItemHandling;
|
|
13
15
|
}) => Promise<void>;
|
|
@@ -41,5 +43,5 @@ type UseBasketBaseReturn = Awaited<UseRpcReturn<'getBasket'>> & {
|
|
|
41
43
|
packages: ComputedRef<BasketPackageInformation[] | undefined>;
|
|
42
44
|
shippingDates: ComputedRef<(string | null)[] | undefined>;
|
|
43
45
|
};
|
|
44
|
-
export declare function useBasket({ params,
|
|
46
|
+
export declare function useBasket({ params, }?: UseBasketOptions, key?: string): UseBasketBaseReturn & Promise<UseBasketBaseReturn>;
|
|
45
47
|
export {};
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import { generateBasketKey } from "@scayle/storefront-core/dist/utils/keys";
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
AddToBasketFailureKind,
|
|
4
4
|
ExistingItemHandling,
|
|
5
|
-
getShippingDates
|
|
6
|
-
HttpStatusCode,
|
|
7
|
-
HttpStatusMessage
|
|
5
|
+
getShippingDates
|
|
8
6
|
} from "@scayle/storefront-core";
|
|
9
|
-
import {
|
|
10
|
-
|
|
7
|
+
import {
|
|
8
|
+
wasAddedWithReducedQuantity
|
|
9
|
+
} from "@scayle/storefront-core/dist/utils/basket";
|
|
11
10
|
import { extendPromise } from "../../utils/promise.js";
|
|
12
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
useRpc
|
|
13
|
+
} from "../core/useRpc.js";
|
|
13
14
|
import { useRpcCall } from "../core/useRpcCall.js";
|
|
14
15
|
import {
|
|
15
16
|
toValue,
|
|
16
|
-
toRef
|
|
17
|
-
|
|
17
|
+
toRef,
|
|
18
|
+
computed
|
|
19
|
+
} from "vue";
|
|
20
|
+
import { FetchError } from "ofetch";
|
|
18
21
|
export function useBasket({
|
|
19
|
-
params
|
|
20
|
-
|
|
21
|
-
} = {}) {
|
|
22
|
-
const nuxtApp = useNuxtApp();
|
|
22
|
+
params
|
|
23
|
+
} = {}, key = "useBasket") {
|
|
23
24
|
const addItemToBasketRpc = useRpcCall("addItemToBasket");
|
|
24
25
|
const addItemsToBasketRpc = useRpcCall("addItemsToBasket");
|
|
25
26
|
const mergeBasketsRpc = useRpcCall("mergeBaskets");
|
|
@@ -30,13 +31,13 @@ export function useBasket({
|
|
|
30
31
|
// NOTE: In some cases it might be ok to fetch on server
|
|
31
32
|
watch: [toRef(params)],
|
|
32
33
|
dedupe: "defer",
|
|
33
|
-
|
|
34
|
+
transform: (basketResponse) => basketResponse.basket,
|
|
35
|
+
getCachedData: (key2, nuxtApp) => {
|
|
34
36
|
return toValue(nuxtApp._asyncData[key2]?.data) ?? void 0;
|
|
35
37
|
}
|
|
36
38
|
});
|
|
37
39
|
const {
|
|
38
40
|
data,
|
|
39
|
-
pending,
|
|
40
41
|
error,
|
|
41
42
|
refresh,
|
|
42
43
|
status
|
|
@@ -50,24 +51,56 @@ export function useBasket({
|
|
|
50
51
|
customData,
|
|
51
52
|
itemGroup
|
|
52
53
|
}) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
try {
|
|
55
|
+
const { basket, errors: basketErrors } = await addItemToBasketRpc({
|
|
56
|
+
promotionId,
|
|
57
|
+
variantId,
|
|
58
|
+
quantity,
|
|
59
|
+
existingItemHandling,
|
|
60
|
+
displayData,
|
|
61
|
+
customData,
|
|
62
|
+
itemGroup,
|
|
63
|
+
with: toValue(params)
|
|
64
|
+
});
|
|
65
|
+
data.value = basket;
|
|
66
|
+
handleBasketError(basketErrors);
|
|
67
|
+
} catch (error2) {
|
|
68
|
+
handleFetchError(error2);
|
|
69
|
+
}
|
|
63
70
|
};
|
|
64
71
|
const addItems = async (items2, existingItemHandling = ExistingItemHandling.AddQuantityToExisting) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
try {
|
|
73
|
+
const { basket, errors: basketErrors } = await addItemsToBasketRpc({
|
|
74
|
+
items: items2,
|
|
75
|
+
existingItemHandling,
|
|
76
|
+
with: toValue(params)
|
|
77
|
+
});
|
|
78
|
+
data.value = basket;
|
|
79
|
+
handleBasketError(basketErrors);
|
|
80
|
+
} catch (error2) {
|
|
81
|
+
handleFetchError(error2);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const handleBasketError = (basketErrors) => {
|
|
85
|
+
if (wasAddedWithReducedQuantity(basketErrors)) {
|
|
86
|
+
throw new Error("Item was added with reduced quantity", {
|
|
87
|
+
cause: AddToBasketFailureKind.ItemAddedWithReducedQuantity
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const handleFetchError = (error2) => {
|
|
92
|
+
if (error2 instanceof FetchError && isAddOrUpdateItemError(
|
|
93
|
+
error2.data.errors?.[0]
|
|
94
|
+
) && error2.data.errors?.[0].operation !== "delete") {
|
|
95
|
+
throw new Error(error2.message, {
|
|
96
|
+
cause: error2.data.errors?.[0].kind
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
throw error2;
|
|
70
100
|
};
|
|
101
|
+
function isAddOrUpdateItemError(error2) {
|
|
102
|
+
return typeof error2 === "object" && error2 !== null && "operation" in error2 && "kind" in error2;
|
|
103
|
+
}
|
|
71
104
|
const mergeBaskets = async (args) => {
|
|
72
105
|
return await mergeBasketsRpc({
|
|
73
106
|
...args,
|
|
@@ -88,22 +121,22 @@ export function useBasket({
|
|
|
88
121
|
const removeItem = async (item) => {
|
|
89
122
|
const element = findItem(item);
|
|
90
123
|
if (!element) {
|
|
91
|
-
throw new
|
|
92
|
-
HttpStatusMessage.NOT_FOUND,
|
|
93
|
-
HttpStatusCode.NOT_FOUND,
|
|
124
|
+
throw new Error(
|
|
94
125
|
`Could not find basket item by variant-id: ${item.variantId}`
|
|
95
126
|
);
|
|
96
127
|
}
|
|
97
|
-
|
|
128
|
+
const { basket } = await removeItemFromBasketRpc({
|
|
98
129
|
itemKey: element.key,
|
|
99
130
|
with: toValue(params)
|
|
100
131
|
});
|
|
132
|
+
data.value = basket;
|
|
101
133
|
};
|
|
102
134
|
const removeItemByKey = async (itemKey) => {
|
|
103
|
-
|
|
135
|
+
const { basket } = await removeItemFromBasketRpc({
|
|
104
136
|
itemKey,
|
|
105
137
|
with: toValue(params)
|
|
106
138
|
});
|
|
139
|
+
data.value = basket;
|
|
107
140
|
};
|
|
108
141
|
const clear = async () => {
|
|
109
142
|
await clearBasketRpc();
|
|
@@ -163,9 +196,6 @@ export function useBasket({
|
|
|
163
196
|
packages,
|
|
164
197
|
shippingDates,
|
|
165
198
|
isEmpty,
|
|
166
|
-
fetching: pending,
|
|
167
|
-
pending,
|
|
168
|
-
fetch: refresh,
|
|
169
199
|
refresh,
|
|
170
200
|
count,
|
|
171
201
|
countWithoutSoldOutItems,
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { RpcMethodParameters } from '@scayle/storefront-core';
|
|
2
2
|
import type { UseRpcOptions, UseRpcReturn, NormalizedRpcResponse, KeysOf } from '../core/useRpc.js';
|
|
3
|
-
import type { MaybeRefOrGetter } from '
|
|
4
|
-
export declare function useBrand<DataT = NormalizedRpcResponse<'getBrandById'>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null>({ params, options,
|
|
3
|
+
import type { MaybeRefOrGetter } from 'vue';
|
|
4
|
+
export declare function useBrand<DataT = NormalizedRpcResponse<'getBrandById'>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null>({ params, options, }?: Partial<{
|
|
5
5
|
params: MaybeRefOrGetter<RpcMethodParameters<'getBrandById'>>;
|
|
6
6
|
options: UseRpcOptions<'getBrandById', DataT, PickKeys, DefaultT>;
|
|
7
|
-
/** @deprecated use the second argument of the composable to define the key */
|
|
8
|
-
key: string;
|
|
9
7
|
}>, key?: string): UseRpcReturn<'getBrandById', DataT, PickKeys, DefaultT>;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { useRpc } from "../core/useRpc.js";
|
|
2
2
|
export function useBrand({
|
|
3
3
|
params,
|
|
4
|
-
options
|
|
5
|
-
|
|
6
|
-
} = {}, key) {
|
|
4
|
+
options
|
|
5
|
+
} = {}, key = "useBrand") {
|
|
7
6
|
return useRpc(
|
|
8
7
|
"getBrandById",
|
|
9
|
-
|
|
8
|
+
key,
|
|
10
9
|
params,
|
|
11
10
|
options
|
|
12
11
|
);
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { RpcMethodParameters } from '@scayle/storefront-core';
|
|
2
2
|
import type { UseRpcOptions, UseRpcReturn, NormalizedRpcResponse, KeysOf } from '../core/useRpc.js';
|
|
3
|
-
import type { MaybeRefOrGetter } from '
|
|
4
|
-
export declare function useBrands<DataT = NormalizedRpcResponse<'getBrands'>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null>({ params, options,
|
|
3
|
+
import type { MaybeRefOrGetter } from 'vue';
|
|
4
|
+
export declare function useBrands<DataT = NormalizedRpcResponse<'getBrands'>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null>({ params, options, }?: Partial<{
|
|
5
5
|
params: MaybeRefOrGetter<RpcMethodParameters<'getBrands'>>;
|
|
6
6
|
options: UseRpcOptions<'getBrands', DataT, PickKeys, DefaultT>;
|
|
7
|
-
/** @deprecated use the second argument of the composable to define the key */
|
|
8
|
-
key: string;
|
|
9
7
|
}>, key?: string): UseRpcReturn<'getBrands', DataT, PickKeys, DefaultT>;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { useRpc } from "../core/useRpc.js";
|
|
2
2
|
export function useBrands({
|
|
3
3
|
params,
|
|
4
|
-
options
|
|
5
|
-
|
|
6
|
-
} = {}, key) {
|
|
4
|
+
options
|
|
5
|
+
} = {}, key = "useBrands") {
|
|
7
6
|
return useRpc(
|
|
8
7
|
"getBrands",
|
|
9
|
-
|
|
8
|
+
key,
|
|
10
9
|
params,
|
|
11
10
|
options
|
|
12
11
|
);
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { RpcMethodParameters, RpcMethodReturnType } from '@scayle/storefront-core';
|
|
2
2
|
import type { KeysOf, UseRpcOptions, UseRpcReturn, NormalizedRpcResponse } from '../core/useRpc.js';
|
|
3
|
-
import type { MaybeRefOrGetter } from '
|
|
4
|
-
type UseCategoriesBaseReturn<DataT, PickKeys extends KeysOf<DataT>, DefaultT> = Pick<Awaited<UseRpcReturn<'getCategoriesByPath', DataT, PickKeys, DefaultT>>, 'data' | 'error' | 'status' | '
|
|
3
|
+
import type { MaybeRefOrGetter } from 'vue';
|
|
4
|
+
type UseCategoriesBaseReturn<DataT, PickKeys extends KeysOf<DataT>, DefaultT> = Pick<Awaited<UseRpcReturn<'getCategoriesByPath', DataT, PickKeys, DefaultT>>, 'data' | 'error' | 'status' | 'refresh'> & {
|
|
5
5
|
getCategoryById: (id: number, includeHidden?: true) => RpcMethodReturnType<'getCategoryById'>;
|
|
6
6
|
};
|
|
7
|
-
export declare function useCategories<DataT = NormalizedRpcResponse<'getCategoriesByPath'>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null>({ params, options,
|
|
7
|
+
export declare function useCategories<DataT = NormalizedRpcResponse<'getCategoriesByPath'>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null>({ params, options, }?: Partial<{
|
|
8
8
|
params: MaybeRefOrGetter<RpcMethodParameters<'getCategoriesByPath'>>;
|
|
9
9
|
options: UseRpcOptions<'getCategoriesByPath', DataT, PickKeys, DefaultT>;
|
|
10
|
-
/** @deprecated use the second argument of the composable to define the key */
|
|
11
|
-
key: string;
|
|
12
10
|
}>, key?: string): UseCategoriesBaseReturn<DataT, PickKeys, DefaultT> & Promise<UseCategoriesBaseReturn<DataT, PickKeys, DefaultT>>;
|
|
13
11
|
export {};
|
|
@@ -3,12 +3,11 @@ import { extendPromise } from "../../utils/promise.js";
|
|
|
3
3
|
import { useRpcCall } from "../core/useRpcCall.js";
|
|
4
4
|
export function useCategories({
|
|
5
5
|
params,
|
|
6
|
-
options
|
|
7
|
-
|
|
8
|
-
} = {}, key) {
|
|
6
|
+
options
|
|
7
|
+
} = {}, key = "useCategories") {
|
|
9
8
|
const useRpcPromise = useRpc(
|
|
10
9
|
"getCategoriesByPath",
|
|
11
|
-
|
|
10
|
+
key,
|
|
12
11
|
params,
|
|
13
12
|
options
|
|
14
13
|
);
|
|
@@ -17,16 +16,12 @@ export function useCategories({
|
|
|
17
16
|
data,
|
|
18
17
|
error,
|
|
19
18
|
status,
|
|
20
|
-
fetch,
|
|
21
|
-
fetching,
|
|
22
19
|
refresh
|
|
23
20
|
} = useRpcPromise;
|
|
24
21
|
return extendPromise(useRpcPromise.then(() => ({})), {
|
|
25
22
|
data,
|
|
26
23
|
error,
|
|
27
24
|
status,
|
|
28
|
-
fetch,
|
|
29
|
-
fetching,
|
|
30
25
|
refresh,
|
|
31
26
|
getCategoryById: (id, includeHidden) => getCategoryById({ id, includeHidden })
|
|
32
27
|
});
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { RpcMethodParameters } from '@scayle/storefront-core';
|
|
2
2
|
import type { UseRpcOptions, UseRpcReturn, NormalizedRpcResponse, KeysOf } from '../core/useRpc.js';
|
|
3
|
-
import type { MaybeRefOrGetter } from '
|
|
4
|
-
export declare function useCategoryById<DataT = NormalizedRpcResponse<'getCategoryById'>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null>({ params, options,
|
|
3
|
+
import type { MaybeRefOrGetter } from 'vue';
|
|
4
|
+
export declare function useCategoryById<DataT = NormalizedRpcResponse<'getCategoryById'>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null>({ params, options, }?: Partial<{
|
|
5
5
|
params: MaybeRefOrGetter<RpcMethodParameters<'getCategoryById'>>;
|
|
6
6
|
options: UseRpcOptions<'getCategoryById', DataT, PickKeys, DefaultT>;
|
|
7
|
-
/** @deprecated use the second argument of the composable to define the key */
|
|
8
|
-
key: string;
|
|
9
7
|
}>, key?: string): UseRpcReturn<'getCategoryById', DataT, PickKeys, DefaultT>;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { useRpc } from "../core/useRpc.js";
|
|
2
2
|
export function useCategoryById({
|
|
3
3
|
params,
|
|
4
|
-
options
|
|
5
|
-
|
|
6
|
-
} = {}, key) {
|
|
4
|
+
options
|
|
5
|
+
} = {}, key = "useCategoryById") {
|
|
7
6
|
return useRpc(
|
|
8
7
|
"getCategoryById",
|
|
9
|
-
|
|
8
|
+
key,
|
|
10
9
|
params,
|
|
11
10
|
options
|
|
12
11
|
);
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { RpcMethodParameters } from '@scayle/storefront-core';
|
|
2
2
|
import type { UseRpcOptions, UseRpcReturn, NormalizedRpcResponse, KeysOf } from '../core/useRpc.js';
|
|
3
|
-
import type { MaybeRefOrGetter } from '
|
|
4
|
-
export declare function useCategoryByPath<DataT = NormalizedRpcResponse<'getCategoryByPath'>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null>({ params, options,
|
|
3
|
+
import type { MaybeRefOrGetter } from 'vue';
|
|
4
|
+
export declare function useCategoryByPath<DataT = NormalizedRpcResponse<'getCategoryByPath'>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null>({ params, options, }: {
|
|
5
5
|
params: MaybeRefOrGetter<RpcMethodParameters<'getCategoryByPath'>>;
|
|
6
6
|
options?: UseRpcOptions<'getCategoryByPath', DataT, PickKeys, DefaultT>;
|
|
7
|
-
/** @deprecated use the second argument of the composable to define the key */
|
|
8
|
-
key: string;
|
|
9
7
|
}, key?: string): UseRpcReturn<'getCategoryByPath', DataT, PickKeys, DefaultT>;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { useRpc } from "../core/useRpc.js";
|
|
2
2
|
export function useCategoryByPath({
|
|
3
3
|
params,
|
|
4
|
-
options
|
|
5
|
-
|
|
6
|
-
}, key) {
|
|
4
|
+
options
|
|
5
|
+
}, key = "useCategoryByPath") {
|
|
7
6
|
return useRpc(
|
|
8
7
|
"getCategoryByPath",
|
|
9
|
-
|
|
8
|
+
key,
|
|
10
9
|
params,
|
|
11
10
|
options
|
|
12
11
|
);
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { RpcMethodParameters } from '@scayle/storefront-core';
|
|
2
2
|
import type { KeysOf, UseRpcOptions, UseRpcReturn, NormalizedRpcResponse } from '../core/useRpc.js';
|
|
3
|
-
import type { MaybeRefOrGetter } from '
|
|
4
|
-
export declare function useCurrentPromotions<DataT = NormalizedRpcResponse<'getCurrentPromotions'>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null>({ params, options,
|
|
3
|
+
import type { MaybeRefOrGetter } from 'vue';
|
|
4
|
+
export declare function useCurrentPromotions<DataT = NormalizedRpcResponse<'getCurrentPromotions'>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null>({ params, options, }?: Partial<{
|
|
5
5
|
params: MaybeRefOrGetter<RpcMethodParameters<'getCurrentPromotions'>>;
|
|
6
6
|
options: UseRpcOptions<'getCurrentPromotions', DataT, PickKeys, DefaultT>;
|
|
7
|
-
/** @deprecated use the second argument of the composable to define the key */
|
|
8
|
-
key: string;
|
|
9
7
|
}>, key?: string): UseRpcReturn<'getCurrentPromotions', DataT, PickKeys, DefaultT>;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { useRpc } from "../core/useRpc.js";
|
|
2
2
|
export function useCurrentPromotions({
|
|
3
3
|
params,
|
|
4
|
-
options
|
|
5
|
-
|
|
6
|
-
} = {}, key) {
|
|
4
|
+
options
|
|
5
|
+
} = {}, key = "useCurrentPromotions") {
|
|
7
6
|
return useRpc(
|
|
8
7
|
"getCurrentPromotions",
|
|
9
|
-
|
|
8
|
+
key,
|
|
10
9
|
params,
|
|
11
10
|
{
|
|
12
11
|
getCachedData(key2, nuxtApp) {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { RpcMethodParameters } from '@scayle/storefront-core';
|
|
2
2
|
import type { UseRpcOptions, UseRpcReturn, NormalizedRpcResponse, KeysOf } from '../core/useRpc.js';
|
|
3
|
-
import type { MaybeRefOrGetter } from '
|
|
4
|
-
export declare function useFilters<DataT = NormalizedRpcResponse<'getFilters'>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null>({ params, options,
|
|
3
|
+
import type { MaybeRefOrGetter } from 'vue';
|
|
4
|
+
export declare function useFilters<DataT = NormalizedRpcResponse<'getFilters'>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null>({ params, options, }?: Partial<{
|
|
5
5
|
params: MaybeRefOrGetter<RpcMethodParameters<'getFilters'>>;
|
|
6
6
|
options: UseRpcOptions<'getFilters', DataT, PickKeys, DefaultT>;
|
|
7
|
-
/** @deprecated use the second argument of the composable to define the key */
|
|
8
|
-
key: string;
|
|
9
7
|
}>, key?: string): UseRpcReturn<'getFilters', DataT, PickKeys, DefaultT>;
|