@scayle/storefront-nuxt 7.36.3

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.
Files changed (135) hide show
  1. package/CHANGELOG.md +598 -0
  2. package/LICENSE +21 -0
  3. package/README.md +67 -0
  4. package/dist/index.d.mts +13 -0
  5. package/dist/index.d.ts +13 -0
  6. package/dist/index.mjs +2 -0
  7. package/dist/module.cjs +5 -0
  8. package/dist/module.d.mts +8 -0
  9. package/dist/module.d.ts +8 -0
  10. package/dist/module.json +8 -0
  11. package/dist/module.mjs +173 -0
  12. package/dist/rpc.d.mts +12 -0
  13. package/dist/rpc.d.ts +12 -0
  14. package/dist/rpc.mjs +18 -0
  15. package/dist/runtime/api/cacheAuth.d.ts +12 -0
  16. package/dist/runtime/api/cacheAuth.mjs +40 -0
  17. package/dist/runtime/api/purgeAll.d.ts +2 -0
  18. package/dist/runtime/api/purgeAll.mjs +14 -0
  19. package/dist/runtime/api/purgeTags.d.ts +2 -0
  20. package/dist/runtime/api/purgeTags.mjs +19 -0
  21. package/dist/runtime/api/rpcHandler.d.ts +2 -0
  22. package/dist/runtime/api/rpcHandler.mjs +15 -0
  23. package/dist/runtime/api/up.d.ts +4 -0
  24. package/dist/runtime/api/up.mjs +4 -0
  25. package/dist/runtime/composables/core/useAvailableShops.d.ts +2 -0
  26. package/dist/runtime/composables/core/useAvailableShops.mjs +4 -0
  27. package/dist/runtime/composables/core/useCurrentShop.d.ts +3 -0
  28. package/dist/runtime/composables/core/useCurrentShop.mjs +8 -0
  29. package/dist/runtime/composables/core/useEventListener.d.ts +2 -0
  30. package/dist/runtime/composables/core/useEventListener.mjs +2 -0
  31. package/dist/runtime/composables/core/useLog.d.ts +1 -0
  32. package/dist/runtime/composables/core/useLog.mjs +8 -0
  33. package/dist/runtime/composables/core/useRpc.d.ts +17 -0
  34. package/dist/runtime/composables/core/useRpc.mjs +56 -0
  35. package/dist/runtime/composables/core/useSession.d.ts +21 -0
  36. package/dist/runtime/composables/core/useSession.mjs +21 -0
  37. package/dist/runtime/composables/core/useUser.d.ts +16 -0
  38. package/dist/runtime/composables/core/useUser.mjs +68 -0
  39. package/dist/runtime/composables/storefront/useBasket.d.ts +54 -0
  40. package/dist/runtime/composables/storefront/useBasket.mjs +165 -0
  41. package/dist/runtime/composables/storefront/useBrand.d.ts +16 -0
  42. package/dist/runtime/composables/storefront/useBrand.mjs +20 -0
  43. package/dist/runtime/composables/storefront/useBrands.d.ts +16 -0
  44. package/dist/runtime/composables/storefront/useBrands.mjs +20 -0
  45. package/dist/runtime/composables/storefront/useCategories.d.ts +20 -0
  46. package/dist/runtime/composables/storefront/useCategories.mjs +30 -0
  47. package/dist/runtime/composables/storefront/useCurrentPromotions.d.ts +16 -0
  48. package/dist/runtime/composables/storefront/useCurrentPromotions.mjs +20 -0
  49. package/dist/runtime/composables/storefront/useFacet.d.ts +48 -0
  50. package/dist/runtime/composables/storefront/useFacet.mjs +193 -0
  51. package/dist/runtime/composables/storefront/useFilters.d.ts +16 -0
  52. package/dist/runtime/composables/storefront/useFilters.mjs +20 -0
  53. package/dist/runtime/composables/storefront/useNavigationTree.d.ts +16 -0
  54. package/dist/runtime/composables/storefront/useNavigationTree.mjs +20 -0
  55. package/dist/runtime/composables/storefront/useNavigationTrees.d.ts +16 -0
  56. package/dist/runtime/composables/storefront/useNavigationTrees.mjs +20 -0
  57. package/dist/runtime/composables/storefront/useOrder.d.ts +89 -0
  58. package/dist/runtime/composables/storefront/useOrder.mjs +17 -0
  59. package/dist/runtime/composables/storefront/useOrderConfirmation.d.ts +89 -0
  60. package/dist/runtime/composables/storefront/useOrderConfirmation.mjs +17 -0
  61. package/dist/runtime/composables/storefront/useProduct.d.ts +16 -0
  62. package/dist/runtime/composables/storefront/useProduct.mjs +20 -0
  63. package/dist/runtime/composables/storefront/useProducts.d.ts +20 -0
  64. package/dist/runtime/composables/storefront/useProducts.mjs +20 -0
  65. package/dist/runtime/composables/storefront/useProductsByIds.d.ts +16 -0
  66. package/dist/runtime/composables/storefront/useProductsByIds.mjs +20 -0
  67. package/dist/runtime/composables/storefront/useProductsCount.d.ts +16 -0
  68. package/dist/runtime/composables/storefront/useProductsCount.mjs +20 -0
  69. package/dist/runtime/composables/storefront/usePromotions.d.ts +16 -0
  70. package/dist/runtime/composables/storefront/usePromotions.mjs +20 -0
  71. package/dist/runtime/composables/storefront/usePromotionsByIds.d.ts +16 -0
  72. package/dist/runtime/composables/storefront/usePromotionsByIds.mjs +20 -0
  73. package/dist/runtime/composables/storefront/useQueryFilterState.d.ts +12 -0
  74. package/dist/runtime/composables/storefront/useQueryFilterState.mjs +66 -0
  75. package/dist/runtime/composables/storefront/useSearch.d.ts +13 -0
  76. package/dist/runtime/composables/storefront/useSearch.mjs +49 -0
  77. package/dist/runtime/composables/storefront/useShopConfiguration.d.ts +13 -0
  78. package/dist/runtime/composables/storefront/useShopConfiguration.mjs +19 -0
  79. package/dist/runtime/composables/storefront/useUserAddresses.d.ts +13 -0
  80. package/dist/runtime/composables/storefront/useUserAddresses.mjs +19 -0
  81. package/dist/runtime/composables/storefront/useVariant.d.ts +16 -0
  82. package/dist/runtime/composables/storefront/useVariant.mjs +20 -0
  83. package/dist/runtime/composables/storefront/useWishlist.d.ts +48 -0
  84. package/dist/runtime/composables/storefront/useWishlist.mjs +119 -0
  85. package/dist/runtime/composables/useCoreLog.d.ts +1 -0
  86. package/dist/runtime/composables/useCoreLog.mjs +4 -0
  87. package/dist/runtime/context.d.ts +12 -0
  88. package/dist/runtime/context.mjs +98 -0
  89. package/dist/runtime/createLog.d.ts +3 -0
  90. package/dist/runtime/createLog.mjs +39 -0
  91. package/dist/runtime/error/handler.d.ts +14 -0
  92. package/dist/runtime/error/handler.mjs +53 -0
  93. package/dist/runtime/handler.d.ts +8 -0
  94. package/dist/runtime/handler.mjs +26 -0
  95. package/dist/runtime/log.d.ts +38 -0
  96. package/dist/runtime/log.mjs +68 -0
  97. package/dist/runtime/plugin/log.client.d.ts +8 -0
  98. package/dist/runtime/plugin/log.client.mjs +24 -0
  99. package/dist/runtime/plugin/log.server.d.ts +2 -0
  100. package/dist/runtime/plugin/log.server.mjs +11 -0
  101. package/dist/runtime/plugin/shop.d.ts +8 -0
  102. package/dist/runtime/plugin/shop.mjs +17 -0
  103. package/dist/runtime/rpc/rpcCall.d.ts +9 -0
  104. package/dist/runtime/rpc/rpcCall.mjs +16 -0
  105. package/dist/runtime/server/middleware/bootstrap.d.ts +12 -0
  106. package/dist/runtime/server/middleware/bootstrap.mjs +188 -0
  107. package/dist/runtime/server/middleware/bootstrap.test.d.ts +6 -0
  108. package/dist/runtime/server/middleware/bootstrap.test.mjs +277 -0
  109. package/dist/runtime/server/middleware/bootstrap.utils.d.ts +7 -0
  110. package/dist/runtime/server/middleware/bootstrap.utils.mjs +59 -0
  111. package/dist/runtime/server/middleware/cache.d.ts +12 -0
  112. package/dist/runtime/server/middleware/cache.mjs +44 -0
  113. package/dist/runtime/server/middleware/oauth.d.ts +3 -0
  114. package/dist/runtime/server/middleware/oauth.mjs +123 -0
  115. package/dist/runtime/server/middleware/redirects.d.ts +2 -0
  116. package/dist/runtime/server/middleware/redirects.mjs +86 -0
  117. package/dist/runtime/server/middleware/redirects.test.d.ts +1 -0
  118. package/dist/runtime/server/middleware/redirects.test.mjs +66 -0
  119. package/dist/runtime/server/middleware/redirects.utils.d.ts +18 -0
  120. package/dist/runtime/server/middleware/redirects.utils.mjs +28 -0
  121. package/dist/runtime/utils/error.d.ts +5 -0
  122. package/dist/runtime/utils/error.mjs +7 -0
  123. package/dist/runtime/utils/price.d.ts +11 -0
  124. package/dist/runtime/utils/price.mjs +32 -0
  125. package/dist/runtime/utils/price.test.d.ts +1 -0
  126. package/dist/runtime/utils/price.test.mjs +83 -0
  127. package/dist/runtime/utils/route.d.ts +2 -0
  128. package/dist/runtime/utils/route.mjs +3 -0
  129. package/dist/runtime/utils/route.test.d.ts +1 -0
  130. package/dist/runtime/utils/route.test.mjs +15 -0
  131. package/dist/shared/storefront-nuxt.9548700f.d.mts +161 -0
  132. package/dist/shared/storefront-nuxt.9548700f.d.ts +161 -0
  133. package/dist/types.d.mts +15 -0
  134. package/dist/types.d.ts +15 -0
  135. package/package.json +103 -0
@@ -0,0 +1,19 @@
1
+ import { useRpc } from "../core/useRpc.mjs";
2
+ export async function useShopConfiguration({
3
+ options,
4
+ key = "useShopConfiguration"
5
+ } = {}) {
6
+ const { data, fetching, fetch, error, status } = await useRpc(
7
+ "getShopConfiguration",
8
+ key,
9
+ void 0,
10
+ options
11
+ );
12
+ return {
13
+ data,
14
+ fetching,
15
+ fetch,
16
+ error,
17
+ status
18
+ };
19
+ }
@@ -0,0 +1,13 @@
1
+ import { RpcOptions } from '../core/useRpc';
2
+ type Options = Partial<{
3
+ options: RpcOptions;
4
+ key: string;
5
+ }>;
6
+ export declare function useUserAddresses({ options, key, }?: Options): Promise<{
7
+ data: import("vue").Ref<import("@scayle/storefront-core").ShopUserAddress[]>;
8
+ fetching: import("vue").Ref<boolean>;
9
+ fetch: () => Promise<void>;
10
+ error: import("vue").Ref<import("nuxt/app").NuxtError | undefined>;
11
+ status: import("vue").Ref<import("../core/useRpc").Status>;
12
+ }>;
13
+ export {};
@@ -0,0 +1,19 @@
1
+ import { useRpc } from "../core/useRpc.mjs";
2
+ export async function useUserAddresses({
3
+ options,
4
+ key = "useUserAddresses"
5
+ } = {}) {
6
+ const { data, fetching, fetch, error, status } = await useRpc(
7
+ "getShopUserAddresses",
8
+ key,
9
+ void 0,
10
+ options
11
+ );
12
+ return {
13
+ data,
14
+ fetching,
15
+ fetch,
16
+ error,
17
+ status
18
+ };
19
+ }
@@ -0,0 +1,16 @@
1
+ import { type RpcMethodParameters } from '@scayle/storefront-core';
2
+ import { type RpcOptions } from '../core/useRpc';
3
+ import { type MaybeRefOrGetter } from '#imports';
4
+ type Options = Partial<{
5
+ params: MaybeRefOrGetter<RpcMethodParameters<'getVariantById'>>;
6
+ options: RpcOptions;
7
+ key: string;
8
+ }>;
9
+ export declare function useVariant({ params, options, key, }?: Options): Promise<{
10
+ data: import("vue").Ref<VariantDetail[]>;
11
+ fetching: import("vue").Ref<boolean>;
12
+ fetch: () => Promise<void>;
13
+ error: import("vue").Ref<import("nuxt/app").NuxtError | undefined>;
14
+ status: import("vue").Ref<import("../core/useRpc").Status>;
15
+ }>;
16
+ export {};
@@ -0,0 +1,20 @@
1
+ import { useRpc } from "../core/useRpc.mjs";
2
+ export async function useVariant({
3
+ params,
4
+ options,
5
+ key = "useVariant"
6
+ } = {}) {
7
+ const { data, fetching, fetch, error, status } = await useRpc(
8
+ "getVariantById",
9
+ key,
10
+ params,
11
+ options
12
+ );
13
+ return {
14
+ data,
15
+ fetching,
16
+ fetch,
17
+ error,
18
+ status
19
+ };
20
+ }
@@ -0,0 +1,48 @@
1
+ import { Product, WishlistItem, RpcMethodParameters } from '@scayle/storefront-core';
2
+ import { RpcOptions } from '../core/useRpc';
3
+ import { type MaybeRefOrGetter } from '#imports';
4
+ type Options = Partial<{
5
+ params: MaybeRefOrGetter<RpcMethodParameters<'getWishlist'>>;
6
+ options: RpcOptions;
7
+ key: string;
8
+ }>;
9
+ export declare function useWishlist({ params, options, key, }?: Options): Promise<{
10
+ data: import("vue").Ref<import("@scayle/storefront-core").WishlistResponseData>;
11
+ count: import("vue").ComputedRef<number>;
12
+ items: import("vue").ComputedRef<WishlistItem[]>;
13
+ products: import("vue").ComputedRef<Product[]>;
14
+ addItem: (item: {
15
+ variantId?: number;
16
+ productId?: number;
17
+ }) => Promise<void>;
18
+ removeItem: (item: {
19
+ variantId?: number;
20
+ productId?: number;
21
+ }) => Promise<void>;
22
+ replaceItem: (item: {
23
+ variantId?: number;
24
+ productId?: number;
25
+ }, newItem: {
26
+ variantId?: number;
27
+ productId?: number;
28
+ }) => Promise<void>;
29
+ clear: () => Promise<void>;
30
+ fetching: import("vue").Ref<boolean>;
31
+ fetch: () => Promise<void>;
32
+ toggleItem: (item: {
33
+ variantId?: number;
34
+ productId?: number;
35
+ }) => Promise<void>;
36
+ findItem: (item: {
37
+ variantId?: number;
38
+ productId?: number;
39
+ }) => WishlistItem | undefined;
40
+ contains: (item: {
41
+ variantId: number;
42
+ } | {
43
+ productId: number;
44
+ }) => boolean;
45
+ error: import("vue").Ref<import("nuxt/app").NuxtError | undefined>;
46
+ status: import("vue").Ref<import("../core/useRpc").Status>;
47
+ }>;
48
+ export {};
@@ -0,0 +1,119 @@
1
+ import {
2
+ BaseError,
3
+ HttpStatusMessage,
4
+ HttpStatusCode
5
+ } from "@scayle/storefront-core";
6
+ import { useNuxtApp } from "nuxt/app";
7
+ import { computed } from "vue";
8
+ import { rpcCall } from "../../rpc/rpcCall.mjs";
9
+ import { useCurrentShop } from "../core/useCurrentShop.mjs";
10
+ import { useRpc } from "../core/useRpc.mjs";
11
+ import { toValue } from "#imports";
12
+ export async function useWishlist({
13
+ params,
14
+ options,
15
+ key = "useWishlist"
16
+ } = {}) {
17
+ const nuxtApp = useNuxtApp();
18
+ const shop = useCurrentShop();
19
+ const { data, fetching, fetch, error, status } = await useRpc(
20
+ "getWishlist",
21
+ key,
22
+ params,
23
+ options
24
+ );
25
+ const addItem = async (item) => {
26
+ data.value = await rpcCall(
27
+ nuxtApp,
28
+ "addItemToWishlist",
29
+ toValue(shop)
30
+ )({
31
+ ...item,
32
+ with: toValue(params)
33
+ });
34
+ };
35
+ const removeItem = async (item) => {
36
+ const element = findItem(item);
37
+ if (!element) {
38
+ throw new BaseError(
39
+ HttpStatusMessage.NOT_FOUND,
40
+ HttpStatusCode.NOT_FOUND,
41
+ "Could not find wishlist item."
42
+ );
43
+ }
44
+ data.value = await rpcCall(
45
+ nuxtApp,
46
+ "removeItemFromWishlist",
47
+ toValue(shop)
48
+ )({
49
+ itemKey: element.key,
50
+ with: toValue(params)
51
+ });
52
+ };
53
+ const replaceItem = async (item, newItem) => {
54
+ const element = findItem(item);
55
+ if (!element) {
56
+ throw new BaseError(
57
+ HttpStatusMessage.NOT_FOUND,
58
+ HttpStatusCode.NOT_FOUND,
59
+ `Could not find wishlist item by: ${JSON.stringify(item)}`
60
+ );
61
+ }
62
+ await rpcCall(
63
+ nuxtApp,
64
+ "removeItemFromWishlist",
65
+ toValue(shop)
66
+ )({
67
+ with: toValue(params),
68
+ itemKey: element.key
69
+ });
70
+ data.value = await rpcCall(
71
+ nuxtApp,
72
+ "addItemToWishlist",
73
+ toValue(shop)
74
+ )({
75
+ ...newItem,
76
+ with: toValue(params)
77
+ });
78
+ };
79
+ const clear = async () => {
80
+ data.value = await rpcCall(nuxtApp, "clearWishlist", toValue(shop))();
81
+ };
82
+ const findItem = (item) => {
83
+ return data.value?.items?.find((entry) => {
84
+ if ("variantId" in item) {
85
+ return entry.variant?.id === item.variantId;
86
+ }
87
+ return entry.product?.id === item.productId;
88
+ });
89
+ };
90
+ const contains = (item) => {
91
+ return findItem(item) !== void 0;
92
+ };
93
+ const toggleItem = async (item) => {
94
+ const element = findItem(item);
95
+ await (element ? removeItem(item) : addItem(item));
96
+ };
97
+ const count = computed(() => data.value?.items.length);
98
+ const items = computed(() => data.value?.items);
99
+ const products = computed(() => {
100
+ return items.value?.map((item) => item.product) || [];
101
+ });
102
+ return {
103
+ data,
104
+ count,
105
+ items,
106
+ products,
107
+ addItem,
108
+ removeItem,
109
+ replaceItem,
110
+ clear,
111
+ fetching,
112
+ fetch,
113
+ toggleItem,
114
+ findItem,
115
+ contains,
116
+ error,
117
+ status
118
+ };
119
+ }
@@ -0,0 +1 @@
1
+ export declare function useCoreLog(subSpace: string): any;
@@ -0,0 +1,4 @@
1
+ import { useLog } from "./core/useLog.mjs";
2
+ export function useCoreLog(subSpace) {
3
+ return useLog(subSpace ? `sfc.${subSpace}` : "sfc");
4
+ }
@@ -0,0 +1,12 @@
1
+ import { Log, RpcContext, Cache as CacheInterface } from '@scayle/storefront-core';
2
+ import type { Session } from '@scayle/h3-session';
3
+ import { ShopConfig, StorefrontConfig } from '../module';
4
+ export interface ContextBuilderOptions {
5
+ $cache: CacheInterface;
6
+ $shopConfig: ShopConfig;
7
+ $storefront: StorefrontConfig;
8
+ $log: Log;
9
+ sessionId: string;
10
+ session: Session;
11
+ }
12
+ export declare const buildContext: (context: ContextBuilderOptions) => Promise<RpcContext>;
@@ -0,0 +1,98 @@
1
+ import {
2
+ Cached
3
+ } from "@scayle/storefront-core";
4
+ import { init as initBapi } from "@scayle/storefront-core/dist/bapi/init";
5
+ import {
6
+ generateBasketKey,
7
+ generateWishlistKey
8
+ } from "@scayle/storefront-core/dist/utils/keys";
9
+ export const buildContext = async (context) => {
10
+ const { $cache, $shopConfig, $storefront, $log, session } = context;
11
+ const bapiConfig = $shopConfig.bapi ?? $storefront.bapi;
12
+ const appKeys = $shopConfig.appKeys ?? $storefront.appKeys;
13
+ return {
14
+ cached: new Cached($cache, $log, "", $storefront.cache?.enabled ?? true).execute,
15
+ bapiClient: initBapi({
16
+ host: bapiConfig.host,
17
+ shopId: $shopConfig.shopId,
18
+ authentication: "token",
19
+ token: bapiConfig.token
20
+ }),
21
+ wishlistKey: session.data.user ? await generateWishlistKey({
22
+ keyTemplate: appKeys.wishlistKey,
23
+ userId: String(session.data.user.id),
24
+ shopId: String($shopConfig.shopId),
25
+ hashAlgorithm: appKeys.hashAlgorithm,
26
+ log: $log
27
+ }) : session.id,
28
+ basketKey: session.data.user ? await generateBasketKey({
29
+ keyTemplate: appKeys.basketKey,
30
+ userId: String(session.data.user.id),
31
+ shopId: String($shopConfig.shopId),
32
+ hashAlgorithm: appKeys.hashAlgorithm,
33
+ log: $log
34
+ }) : session.id,
35
+ auth: {
36
+ resetPasswordUrl: $shopConfig.auth?.resetPasswordUrl
37
+ },
38
+ checkout: {
39
+ url: $shopConfig.checkout.host,
40
+ secret: $shopConfig.checkout.secret,
41
+ token: $shopConfig.checkout.token,
42
+ user: $shopConfig.checkout.user,
43
+ cbdExpiration: $shopConfig.checkout.cbdExpiration
44
+ },
45
+ oauth: {
46
+ clientId: $storefront.oauth.clientId,
47
+ clientSecret: $storefront.oauth.clientSecret,
48
+ apiHost: $storefront.oauth.apiHost
49
+ },
50
+ log: $log,
51
+ get user() {
52
+ return session.data?.user ?? void 0;
53
+ },
54
+ destroySession: async () => {
55
+ await session.destroy();
56
+ },
57
+ destroySessionsForUserId: async () => {
58
+ },
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
+ generateBasketKeyForUserId: (userId) => generateBasketKey({
67
+ keyTemplate: appKeys.basketKey,
68
+ userId,
69
+ shopId: String($shopConfig.shopId),
70
+ hashAlgorithm: appKeys.hashAlgorithm,
71
+ log: $log
72
+ }),
73
+ generateWishlistKeyForUserId: (userId) => generateWishlistKey({
74
+ keyTemplate: appKeys.wishlistKey,
75
+ userId,
76
+ shopId: String($shopConfig.shopId),
77
+ hashAlgorithm: appKeys.hashAlgorithm,
78
+ log: $log
79
+ }),
80
+ isCmsPreview: false,
81
+ locale: $shopConfig.locale,
82
+ shopId: $shopConfig.shopId,
83
+ domain: $shopConfig.domain,
84
+ withParams: $storefront.withParams,
85
+ updateUser: async (user) => {
86
+ session.data.user = user;
87
+ await session.save();
88
+ },
89
+ sessionId: context.sessionId,
90
+ get accessToken() {
91
+ return session.data?.accessToken ?? void 0;
92
+ },
93
+ updateTokens: async (tokens) => {
94
+ Object.assign(session.data, tokens);
95
+ await session.save();
96
+ }
97
+ };
98
+ };
@@ -0,0 +1,3 @@
1
+ import type { ConsolaInstance, ConsolaOptions } from 'consola';
2
+ import { Log } from './log';
3
+ export default function createLog(createConsola: (options?: Partial<ConsolaOptions>) => ConsolaInstance, space?: string): Log;
@@ -0,0 +1,39 @@
1
+ import { Log } from "./log.mjs";
2
+ const isProd = process.env.APP_ENV === "production";
3
+ function prepareData(data) {
4
+ if (!data) {
5
+ return data;
6
+ }
7
+ if (data.response) {
8
+ const { response, message, name, code, ...other } = data;
9
+ return {
10
+ message,
11
+ name,
12
+ code,
13
+ status: response?.status,
14
+ statusText: response?.statusText,
15
+ ...other
16
+ };
17
+ }
18
+ return data;
19
+ }
20
+ export default function createLog(createConsola, space = "default-storefront") {
21
+ const logger = createConsola({
22
+ level: 4
23
+ // set to 3 to skip debug messages
24
+ });
25
+ const handler = (entry) => {
26
+ if (isProd && entry.level === "debug") {
27
+ return;
28
+ }
29
+ const data = prepareData(entry.data);
30
+ const log = logger[entry.level] || logger.info;
31
+ const message = `[${entry.space}] ${entry.message}`;
32
+ const args = data ? [message, data] : [message];
33
+ log.apply(log, args);
34
+ };
35
+ return new Log({
36
+ space,
37
+ handler
38
+ });
39
+ }
@@ -0,0 +1,14 @@
1
+ import { HttpStatusCode } from '@scayle/storefront-core';
2
+ import { FetchError } from 'ofetch';
3
+ declare const parseErrorData: (error: unknown) => {
4
+ statusCode: HttpStatusCode;
5
+ statusMessage: string;
6
+ url?: string;
7
+ };
8
+ declare const resolveError: (error: FetchError | Error | unknown, additionalData?: unknown) => {
9
+ statusCode: 401 | 500 | 400 | 100 | 101 | 102 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 426 | 428 | 429 | 431 | 451 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
10
+ statusMessage: string;
11
+ name: string;
12
+ data: unknown;
13
+ };
14
+ export { resolveError, parseErrorData };
@@ -0,0 +1,53 @@
1
+ import {
2
+ BAPIError,
3
+ BaseError,
4
+ HttpStatusCode,
5
+ HttpStatusMessage
6
+ } from "@scayle/storefront-core";
7
+ import { FetchError } from "ofetch";
8
+ const parseErrorData = (error) => {
9
+ if (error.isAxiosError) {
10
+ const err = error;
11
+ return {
12
+ statusCode: err.response?.data.code || HttpStatusCode.INTERNAL_SERVER_ERROR,
13
+ statusMessage: err.response?.data.message || HttpStatusMessage.INTERNAL_SERVER_ERROR,
14
+ url: err.config.url
15
+ };
16
+ }
17
+ if (error instanceof FetchError) {
18
+ const url = error.request?.url || String(error.request) || "/";
19
+ return {
20
+ statusCode: error.status || HttpStatusCode.INTERNAL_SERVER_ERROR,
21
+ statusMessage: error.statusText || HttpStatusMessage.INTERNAL_SERVER_ERROR,
22
+ url
23
+ };
24
+ } else if (error instanceof BAPIError) {
25
+ return {
26
+ statusCode: error.statusCode || HttpStatusCode.INTERNAL_SERVER_ERROR,
27
+ statusMessage: error.message || HttpStatusMessage.INTERNAL_SERVER_ERROR,
28
+ url: error.url
29
+ };
30
+ } else if (error instanceof BaseError) {
31
+ return {
32
+ statusCode: error.statusCode || HttpStatusCode.INTERNAL_SERVER_ERROR,
33
+ statusMessage: error.message || HttpStatusMessage.INTERNAL_SERVER_ERROR
34
+ };
35
+ } else if (error instanceof Error) {
36
+ return {
37
+ statusCode: HttpStatusCode.INTERNAL_SERVER_ERROR,
38
+ statusMessage: error.message || HttpStatusMessage.INTERNAL_SERVER_ERROR
39
+ };
40
+ }
41
+ return {
42
+ statusCode: HttpStatusCode.INTERNAL_SERVER_ERROR,
43
+ statusMessage: HttpStatusMessage.INTERNAL_SERVER_ERROR
44
+ };
45
+ };
46
+ const resolveError = (error, additionalData) => {
47
+ const { statusCode, statusMessage } = parseErrorData(error);
48
+ const [key] = Object.entries(HttpStatusCode).find(([_, code]) => code === statusCode) || [];
49
+ const statusCodeKey = key;
50
+ const name = statusCodeKey ? HttpStatusMessage[statusCodeKey] : HttpStatusMessage.INTERNAL_SERVER_ERROR;
51
+ return { statusCode, statusMessage, name, data: additionalData };
52
+ };
53
+ export { resolveError, parseErrorData };
@@ -0,0 +1,8 @@
1
+ import { RpcContext, RpcMethodName, RpcMethodParameters, RpcMethodReturnType } from '@scayle/storefront-core';
2
+ /**
3
+ * Handler for RPC methods
4
+ * @param method
5
+ * @param payload
6
+ * @param rpcContext
7
+ */
8
+ export declare const handler: <N extends RpcMethodName, P extends RpcMethodParameters<N>, TResult extends Awaited<RpcMethodReturnType<N>>, TakesParameters = P extends RpcContext ? undefined : boolean, TParams = TakesParameters extends undefined ? null : P>(method: N, payload: TParams, rpcContext: RpcContext) => Promise<TResult>;
@@ -0,0 +1,26 @@
1
+ import {
2
+ rpcMethods as coreRpcMethods
3
+ } from "@scayle/storefront-core";
4
+ import * as storefrontRpcMethods from "#rpcMethods";
5
+ export const handler = async (method, payload, rpcContext) => {
6
+ const rpcMethods = {
7
+ ...coreRpcMethods,
8
+ ...storefrontRpcMethods
9
+ };
10
+ if (!Object.hasOwn(rpcMethods, method)) {
11
+ throw new Error(`RPC Method [${method}] was not found`);
12
+ }
13
+ const log = rpcContext.log.space("sfc").space("rpc");
14
+ return await log.time(`Calling RPC method: ${method}`, async () => {
15
+ const fun = rpcMethods[method];
16
+ if (fun.length === 1) {
17
+ return await fun(
18
+ rpcContext
19
+ );
20
+ }
21
+ return await fun(
22
+ payload,
23
+ rpcContext
24
+ );
25
+ });
26
+ };
@@ -0,0 +1,38 @@
1
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
2
+ export interface LogEntry {
3
+ level: LogLevel;
4
+ space: string;
5
+ message: string;
6
+ data?: Object;
7
+ }
8
+ export type LogHandler = (entry: LogEntry) => void;
9
+ export interface LogOptions {
10
+ handler?: LogHandler;
11
+ space: string;
12
+ }
13
+ /**
14
+ * This log provides a way to log messages to a custom log handler (in a serial manner).
15
+ * If no handler is provided, it will log to the console.
16
+ */
17
+ export declare class Log {
18
+ static default: Log;
19
+ _handler?: LogHandler;
20
+ _space: string;
21
+ _type: string;
22
+ constructor(options?: LogOptions);
23
+ debug(message: string, data?: any): void;
24
+ info(message: string, data?: any): void;
25
+ warn(message: string, data?: any): void;
26
+ error(message: string | Error, data?: any): void;
27
+ write(level: LogLevel, message: string, data?: any): void;
28
+ /**
29
+ * Create a new sub-space.
30
+ * All spaces are being separated by a dot. E.g. `global.api` and `global.api.getUser`
31
+ * @param subSpace The name of the sub-space in camel-case (e.g. `api` and `api.getUser`)
32
+ */
33
+ space(subSpace: string): Log;
34
+ /**
35
+ * Measure the time of a function.
36
+ */
37
+ time<T>(message: string, func: () => T): Promise<T>;
38
+ }
@@ -0,0 +1,68 @@
1
+ export class Log {
2
+ static default = new this({
3
+ space: "global",
4
+ handler: consoleLogHandler
5
+ });
6
+ _handler;
7
+ _space;
8
+ _type = "log";
9
+ constructor(options) {
10
+ this._handler = options?.handler || Log.default._handler;
11
+ this._space = options?.space || Log.default._space;
12
+ }
13
+ debug(message, data) {
14
+ this.write("debug", message, data);
15
+ }
16
+ info(message, data) {
17
+ this.write("info", message, data);
18
+ }
19
+ warn(message, data) {
20
+ this.write("warn", message, data);
21
+ }
22
+ error(message, data) {
23
+ const error = message instanceof Error ? message : null;
24
+ if (error) {
25
+ data = {
26
+ error: message,
27
+ ...data
28
+ };
29
+ }
30
+ this.write("error", error?.message ?? message, data);
31
+ }
32
+ write(level, message, data) {
33
+ if (typeof data !== "undefined") {
34
+ data = typeof data !== "object" ? { data } : data;
35
+ }
36
+ if (this._handler) {
37
+ this._handler({ level, message, data, space: this._space });
38
+ } else {
39
+ const logFunc = console[level] || console.log;
40
+ logFunc.apply(console, data ? [message, data] : [message]);
41
+ }
42
+ }
43
+ /**
44
+ * Create a new sub-space.
45
+ * All spaces are being separated by a dot. E.g. `global.api` and `global.api.getUser`
46
+ * @param subSpace The name of the sub-space in camel-case (e.g. `api` and `api.getUser`)
47
+ */
48
+ space(subSpace) {
49
+ return new Log({
50
+ space: `${this._space}.${subSpace}`,
51
+ handler: this._handler
52
+ });
53
+ }
54
+ /**
55
+ * Measure the time of a function.
56
+ */
57
+ async time(message, func) {
58
+ const start = Date.now();
59
+ const result = await func();
60
+ const end = Date.now();
61
+ this.debug(`${message} took ${end - start}ms`);
62
+ return result;
63
+ }
64
+ }
65
+ function consoleLogHandler({ level, message, data }) {
66
+ const logFunc = console[level] || console.log;
67
+ logFunc.apply(console, data ? [message, data] : [message]);
68
+ }
@@ -0,0 +1,8 @@
1
+ declare const _default: import("nuxt/app").Plugin<{
2
+ log: import("../log").Log;
3
+ coreLog: import("../log").Log;
4
+ }> & import("nuxt/app").ObjectPlugin<{
5
+ log: import("../log").Log;
6
+ coreLog: import("../log").Log;
7
+ }>;
8
+ export default _default;
@@ -0,0 +1,24 @@
1
+ import { defineNuxtPlugin, useRuntimeConfig } from "nuxt/app";
2
+ import { createConsola } from "consola/browser";
3
+ import createLog from "../createLog.mjs";
4
+ export default defineNuxtPlugin((nuxtApp) => {
5
+ const config = useRuntimeConfig().public;
6
+ const log = createLog(createConsola, config.log.name);
7
+ const coreLog = log.space("sfc");
8
+ coreLog.debug("Attached client-side logger");
9
+ addClientSideErrorHandling(log, nuxtApp.vueApp);
10
+ return {
11
+ provide: {
12
+ log,
13
+ coreLog
14
+ }
15
+ };
16
+ });
17
+ function addClientSideErrorHandling(log, app) {
18
+ app.config.warnHandler = (msg, vm, trace) => {
19
+ log.space("warnHandler").warn(msg, { vm, trace });
20
+ };
21
+ app.config.errorHandler = (error, vm, info) => {
22
+ log.space("errorHandler").error(error, { vm, info, component: vm?.$options.__name });
23
+ };
24
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;