@scayle/storefront-nuxt 8.61.1 → 8.61.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 (42) hide show
  1. package/CHANGELOG-V7.md +3 -11
  2. package/CHANGELOG.md +241 -255
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +97 -39
  5. package/dist/runtime/api/rpcHandler.js +1 -4
  6. package/dist/runtime/cached.js +1 -6
  7. package/dist/runtime/campaignKey.js +15 -15
  8. package/dist/runtime/composables/core/useIDP.js +11 -13
  9. package/dist/runtime/composables/core/useSession.js +1 -3
  10. package/dist/runtime/composables/core/useUser.js +24 -30
  11. package/dist/runtime/composables/storefront/useBasket.d.ts +1 -1
  12. package/dist/runtime/composables/storefront/useBasket.js +32 -45
  13. package/dist/runtime/composables/storefront/useBrand.js +1 -6
  14. package/dist/runtime/composables/storefront/useBrands.js +1 -6
  15. package/dist/runtime/composables/storefront/useCampaign.js +1 -6
  16. package/dist/runtime/composables/storefront/useCategories.js +12 -19
  17. package/dist/runtime/composables/storefront/useCategoryById.js +1 -6
  18. package/dist/runtime/composables/storefront/useCategoryByPath.js +1 -6
  19. package/dist/runtime/composables/storefront/useCurrentPromotions.js +7 -12
  20. package/dist/runtime/composables/storefront/useFilters.js +1 -6
  21. package/dist/runtime/composables/storefront/useNavigationTree.js +2 -12
  22. package/dist/runtime/composables/storefront/useNavigationTrees.js +1 -6
  23. package/dist/runtime/composables/storefront/useProduct.js +1 -6
  24. package/dist/runtime/composables/storefront/useProducts.js +1 -6
  25. package/dist/runtime/composables/storefront/useProductsByIds.js +1 -6
  26. package/dist/runtime/composables/storefront/useProductsByReferenceKeys.js +1 -6
  27. package/dist/runtime/composables/storefront/useProductsCount.js +1 -6
  28. package/dist/runtime/composables/storefront/usePromotions.js +1 -6
  29. package/dist/runtime/composables/storefront/usePromotionsByIds.js +1 -6
  30. package/dist/runtime/composables/storefront/useShopConfiguration.js +1 -6
  31. package/dist/runtime/composables/storefront/useUserAddresses.js +1 -6
  32. package/dist/runtime/composables/storefront/useVariant.js +1 -6
  33. package/dist/runtime/composables/storefront/useWishlist.d.ts +1 -1
  34. package/dist/runtime/composables/storefront/useWishlist.js +11 -25
  35. package/dist/runtime/context.js +2 -10
  36. package/dist/runtime/nitro/plugins/configValidation.js +6 -4
  37. package/dist/runtime/nitro/plugins/nitroStorageConfig.js +1 -4
  38. package/dist/runtime/server/middleware/bootstrap.js +3 -14
  39. package/dist/runtime/server/middleware/redirects.js +1 -3
  40. package/dist/runtime/utils/storage.js +1 -4
  41. package/dist/runtime/utils/zodSchema.js +33 -25
  42. package/package.json +13 -12
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
- "version": "8.61.1",
3
+ "version": "8.61.3",
4
4
  "configKey": "storefront",
5
5
  "compatibility": {
6
6
  "nuxt": ">=3.13"
package/dist/module.mjs CHANGED
@@ -1,11 +1,14 @@
1
1
  import { existsSync } from 'node:fs';
2
- import { defineNuxtModule, createResolver, addServerTemplate, addTypeTemplate, extendViteConfig, addTemplate, updateTemplates, addPlugin, addImportsDir } from '@nuxt/kit';
2
+ import { join } from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { defineNuxtModule, createResolver, addServerTemplate, addTypeTemplate, extendViteConfig, addTemplate, updateTemplates, addPlugin, addImportsDir, runWithNuxtContext, resolvePath } from '@nuxt/kit';
3
5
  import { rpcMethods } from '@scayle/storefront-core';
4
6
  import { defu } from 'defu';
5
7
  import { genExport, genImport, genSafeVariableName } from 'knitwork';
6
8
  import { builtinDrivers } from 'unstorage';
7
9
  import { createConsola } from 'consola';
8
10
  import { nodeFileTrace } from '@vercel/nft';
11
+ import { createJiti } from 'jiti';
9
12
  import { getApiBasePath } from '../dist/runtime/server/middleware/bootstrap-utils.js';
10
13
  export * from '../dist/runtime/types/module.js';
11
14
 
@@ -54,7 +57,7 @@ export default {
54
57
  }`;
55
58
  }
56
59
  const PACKAGE_NAME = "@scayle/storefront-nuxt";
57
- const PACKAGE_VERSION = "8.61.1";
60
+ const PACKAGE_VERSION = "8.61.3";
58
61
  const logger = createConsola({
59
62
  fancy: true,
60
63
  formatOptions: {
@@ -69,9 +72,7 @@ const logger = createConsola({
69
72
  // This assertion avoids the typescript error
70
73
  });
71
74
  function createRpcMethodIndex(customRpcImports) {
72
- return `${customRpcImports.map(({ source, names }) => genExport(source, names)).join(
73
- "\n"
74
- )}
75
+ return `${customRpcImports.map(({ source, names }) => genExport(source, names)).join("\n")}
75
76
  export {}`;
76
77
  }
77
78
  function createRpcMethodTypeDeclaration(customRpcImports) {
@@ -79,7 +80,9 @@ function createRpcMethodTypeDeclaration(customRpcImports) {
79
80
  type RpcMethodsCustomType = {
80
81
  ${customRpcImports.reduce(
81
82
  (lines, { source, names }) => lines.concat(
82
- names.map((name) => `${name}: typeof import('${source}')['${name}'],`).join("\n")
83
+ names.map(
84
+ (name) => `${name}: typeof import('${source}')['${name}'],`
85
+ ).join("\n")
83
86
  ),
84
87
  []
85
88
  ).join("\n")}
@@ -105,7 +108,62 @@ function readHttpMethod(handler) {
105
108
  }
106
109
  return DEFAULT_RPC_HTTP_METHOD;
107
110
  }
108
- async function buildRpcHttpMethodManifest(customRpcImports, coreHandlers) {
111
+ function getNuxtStringAliases(nuxt) {
112
+ const out = {};
113
+ for (const [specifier, target] of Object.entries(nuxt.options.alias)) {
114
+ if (typeof target === "string") {
115
+ out[specifier] = target;
116
+ }
117
+ }
118
+ return out;
119
+ }
120
+ function sortAliasRecordByLongestSpecifierFirst(map) {
121
+ return Object.fromEntries(
122
+ Object.entries(map).sort((a, b) => b[0].length - a[0].length)
123
+ );
124
+ }
125
+ async function resolveAliasChain(target, resolveOpts) {
126
+ let current = target;
127
+ for (let i = 0; i < 10; i++) {
128
+ const next = await resolvePath(current, resolveOpts);
129
+ if (next === current) {
130
+ return next;
131
+ }
132
+ current = next;
133
+ }
134
+ logger.warn(
135
+ `Alias chain for ${target} resolved to ${current} but maximum depth of 10 was reached`
136
+ );
137
+ return current;
138
+ }
139
+ async function buildResolvedNuxtAliasMap(nuxt) {
140
+ return runWithNuxtContext(nuxt, async () => {
141
+ const alias = getNuxtStringAliases(nuxt);
142
+ const resolveOpts = {
143
+ cwd: nuxt.options.rootDir,
144
+ alias,
145
+ virtual: true,
146
+ fallbackToOriginal: true
147
+ };
148
+ const resolved = {};
149
+ for (const [specifier, target] of Object.entries(alias)) {
150
+ try {
151
+ resolved[specifier] = await resolveAliasChain(target, resolveOpts);
152
+ } catch {
153
+ resolved[specifier] = target;
154
+ }
155
+ }
156
+ return sortAliasRecordByLongestSpecifierFirst(resolved);
157
+ });
158
+ }
159
+ function getJitiParentUrlForNuxtApp(nuxt) {
160
+ const pkg = join(nuxt.options.rootDir, "package.json");
161
+ if (existsSync(pkg)) {
162
+ return pathToFileURL(pkg).href;
163
+ }
164
+ return pathToFileURL(join(nuxt.options.rootDir, ".")).href;
165
+ }
166
+ async function buildRpcHttpMethodManifest(customRpcImports, coreHandlers, nuxt) {
109
167
  const manifest = {};
110
168
  for (const [name, handler] of Object.entries(coreHandlers)) {
111
169
  manifest[name] = readHttpMethod(handler);
@@ -113,10 +171,13 @@ async function buildRpcHttpMethodManifest(customRpcImports, coreHandlers) {
113
171
  if (customRpcImports.length === 0) {
114
172
  return manifest;
115
173
  }
174
+ const jiti = createJiti(getJitiParentUrlForNuxtApp(nuxt), {
175
+ alias: await buildResolvedNuxtAliasMap(nuxt)
176
+ });
116
177
  for (const { source, names } of customRpcImports) {
117
178
  let loadedModule;
118
179
  try {
119
- loadedModule = await import(source);
180
+ loadedModule = await jiti.import(source);
120
181
  } catch (error) {
121
182
  logger.warn(
122
183
  `Failed to load custom RPC module '${source}' while inferring HTTP methods. Methods from this module will default to '${DEFAULT_RPC_HTTP_METHOD}'.`,
@@ -134,8 +195,8 @@ function createRpcHttpMethodsSource(manifest) {
134
195
  export const rpcHttpMethods = ${JSON.stringify(manifest, null, 2)}
135
196
  `;
136
197
  }
137
- async function nitroSetup(nitroConfig, config, moduleOptions) {
138
- const { resolve, resolvePath } = createResolver(import.meta.url);
198
+ async function nitroSetup(nitroConfig, config, moduleOptions, nuxt) {
199
+ const { resolve, resolvePath: resolvePath2 } = createResolver(import.meta.url);
139
200
  const {
140
201
  apiBasePath,
141
202
  customRpcImports,
@@ -144,33 +205,28 @@ async function nitroSetup(nitroConfig, config, moduleOptions) {
144
205
  rpcHttpMethodManifest,
145
206
  rpcHttpMethodsPath
146
207
  } = config;
208
+ const nuxtAliases = await buildResolvedNuxtAliasMap(nuxt);
147
209
  nitroConfig.replace = nitroConfig.replace || {};
148
210
  nitroConfig.replace["process.env.SFC_OMIT_MD5"] = stringToBoolean(
149
211
  process.env.SFC_OMIT_MD5
150
212
  );
151
213
  nitroConfig.replace.__sfc_version = PACKAGE_VERSION;
152
214
  nitroConfig.alias = {
153
- ...nitroConfig.alias,
215
+ ...nuxtAliases,
216
+ ...nitroConfig.alias ?? {},
154
217
  "#virtual/rpcHttpMethods": rpcHttpMethodsPath
155
218
  };
156
219
  nitroConfig.virtual = {
157
220
  ...nitroConfig.virtual,
158
- "#virtual/storage-drivers": createVirtualDriverImport(
159
- usedDrivers
160
- ),
161
- "#virtual/customRpcMethods": createRpcMethodIndex(
162
- customRpcImports
163
- )
221
+ "#virtual/storage-drivers": createVirtualDriverImport(usedDrivers),
222
+ "#virtual/customRpcMethods": createRpcMethodIndex(customRpcImports)
164
223
  };
165
224
  nitroConfig.handlers = nitroConfig.handlers ?? [];
166
225
  nitroConfig.handlers.unshift({
167
226
  middleware: true,
168
227
  handler: resolve("./runtime/server/middleware/bootstrap")
169
228
  });
170
- const allRpcNames = customRpcImports.reduce(
171
- (acc, { names }) => acc.concat(names),
172
- []
173
- ).concat(coreMethodNames);
229
+ const allRpcNames = customRpcImports.reduce((acc, { names }) => acc.concat(names), []).concat(coreMethodNames);
174
230
  for (const methodName of allRpcNames) {
175
231
  const httpMethod = rpcHttpMethodManifest[methodName] ?? DEFAULT_RPC_HTTP_METHOD;
176
232
  nitroConfig.handlers.push({
@@ -203,9 +259,7 @@ async function nitroSetup(nitroConfig, config, moduleOptions) {
203
259
  resolve("./runtime/nitro/plugins/nitroLegacyStorageConfig")
204
260
  );
205
261
  }
206
- nitroConfig.plugins.push(
207
- resolve("./runtime/nitro/plugins/internalFetch")
208
- );
262
+ nitroConfig.plugins.push(resolve("./runtime/nitro/plugins/internalFetch"));
209
263
  if (stringToBoolean(process.env.SFC_PLUGIN_CONFIG_VALIDATION_ENABLED, true)) {
210
264
  logger.debug("Installing config validation plugin");
211
265
  nitroConfig.plugins.push(
@@ -233,14 +287,12 @@ async function nitroSetup(nitroConfig, config, moduleOptions) {
233
287
  );
234
288
  }
235
289
  const base = resolve(`./`);
236
- const handlerPaths = nitroConfig.handlers.filter(
237
- (h) => h?.handler && h?.handler.startsWith(base)
238
- ).map((h) => h?.handler);
290
+ const handlerPaths = nitroConfig.handlers.filter((h) => h?.handler && h?.handler.startsWith(base)).map((h) => h?.handler);
239
291
  const pluginPaths = nitroConfig.plugins.filter(
240
292
  (p) => p && p?.startsWith(base)
241
293
  );
242
294
  const runtimeEntries = await Promise.all(
243
- [...handlerPaths, ...pluginPaths].map((p) => resolvePath(p))
295
+ [...handlerPaths, ...pluginPaths].map((p) => resolvePath2(p))
244
296
  );
245
297
  const trace = await nodeFileTrace(runtimeEntries, { base });
246
298
  const tracedImports = [...trace.fileList].map((p) => resolve(p));
@@ -300,7 +352,7 @@ const module$1 = defineNuxtModule({
300
352
  },
301
353
  async setup(options, nuxt) {
302
354
  const { resolve } = createResolver(import.meta.url);
303
- const { resolve: appResolve, resolvePath } = createResolver(
355
+ const { resolve: appResolve, resolvePath: resolvePath2 } = createResolver(
304
356
  nuxt.options.rootDir
305
357
  );
306
358
  addServerTemplate({
@@ -401,7 +453,7 @@ const module$1 = defineNuxtModule({
401
453
  (name) => !storefrontRpcMethodNames.includes(name)
402
454
  );
403
455
  });
404
- const rpcDir = await resolvePath(
456
+ const rpcDir = await resolvePath2(
405
457
  appResolve(options.rpcDir ?? "./rpcMethods")
406
458
  );
407
459
  if (existsSync(rpcDir)) {
@@ -420,7 +472,8 @@ const module$1 = defineNuxtModule({
420
472
  );
421
473
  rpcHttpMethodManifest = await buildRpcHttpMethodManifest(
422
474
  customRpcImports,
423
- rpcMethods
475
+ rpcMethods,
476
+ nuxt
424
477
  );
425
478
  const rpcHttpMethodsSource = createRpcHttpMethodsSource(
426
479
  rpcHttpMethodManifest
@@ -461,14 +514,19 @@ const module$1 = defineNuxtModule({
461
514
  export {}`
462
515
  });
463
516
  nuxt.hooks.hook("nitro:config", async (nitroConfig) => {
464
- await nitroSetup(nitroConfig, {
465
- apiBasePath,
466
- customRpcImports,
467
- coreMethodNames: [...rpcMethodNames],
468
- usedDrivers: getUsedDrivers(nuxt.options.runtimeConfig.storefront),
469
- rpcHttpMethodManifest,
470
- rpcHttpMethodsPath
471
- }, nuxt.options.runtimeConfig.storefront);
517
+ await nitroSetup(
518
+ nitroConfig,
519
+ {
520
+ apiBasePath,
521
+ customRpcImports,
522
+ coreMethodNames: [...rpcMethodNames],
523
+ usedDrivers: getUsedDrivers(nuxt.options.runtimeConfig.storefront),
524
+ rpcHttpMethodManifest,
525
+ rpcHttpMethodsPath
526
+ },
527
+ nuxt.options.runtimeConfig.storefront,
528
+ nuxt
529
+ );
472
530
  });
473
531
  nuxt.hooks.hook("nitro:init", async (nitro) => {
474
532
  await nitroPostInit(nuxt.options.runtimeConfig.storefront, nitro);
@@ -23,10 +23,7 @@ export default defineEventHandler(async (event) => {
23
23
  status: HttpStatusCode.INTERNAL_SERVER_ERROR
24
24
  });
25
25
  }
26
- const tracer = trace.getTracer(
27
- "storefront-nuxt",
28
- "__sfc_version"
29
- );
26
+ const tracer = trace.getTracer("storefront-nuxt", "__sfc_version");
30
27
  const pathComponents = event.path.split("?")[0].split("/");
31
28
  const method = pathComponents[pathComponents.length - 1];
32
29
  const httpMethod = rpcHttpMethods[method] ?? DEFAULT_RPC_HTTP_METHOD;
@@ -1,10 +1,5 @@
1
1
  import { Cached } from "@scayle/storefront-core";
2
2
  export function getCachedFunction($cache, $log, enabled) {
3
- const cached = new Cached(
4
- $cache,
5
- $log,
6
- "",
7
- enabled ?? true
8
- );
3
+ const cached = new Cached($cache, $log, "", enabled ?? true);
9
4
  return cached.execute.bind(cached);
10
5
  }
@@ -5,22 +5,22 @@ import {
5
5
  } from "@scayle/storefront-core";
6
6
  export const fetchCampaignKey = async (sapiClient, cached, log) => {
7
7
  try {
8
- const { campaigns } = await cached(async () => {
9
- const { entities } = await sapiClient.campaigns.get();
10
- return {
11
- campaigns: entities.filter((campaign) => {
12
- return campaignHasNotEnded(campaign);
13
- }).sort(sortCampaignsByDateAscending)
14
- };
15
- }, {
16
- cacheKeyPrefix: "fetch-campaignKey",
17
- ttl: 5 * 60
18
- })();
8
+ const { campaigns } = await cached(
9
+ async () => {
10
+ const { entities } = await sapiClient.campaigns.get();
11
+ return {
12
+ campaigns: entities.filter((campaign) => {
13
+ return campaignHasNotEnded(campaign);
14
+ }).sort(sortCampaignsByDateAscending)
15
+ };
16
+ },
17
+ {
18
+ cacheKeyPrefix: "fetch-campaignKey",
19
+ ttl: 5 * 60
20
+ }
21
+ )();
19
22
  return campaigns.find(isCampaignActive)?.key;
20
23
  } catch (error) {
21
- log.error(
22
- "Failed to get or process the campaigns from SAPI.",
23
- error
24
- );
24
+ log.error("Failed to get or process the campaigns from SAPI.", error);
25
25
  }
26
26
  };
@@ -6,17 +6,15 @@ export function useIDP(params = {}, key) {
6
6
  key ?? "useIDP",
7
7
  params
8
8
  );
9
- const {
10
- data,
11
- error,
12
- refresh,
13
- status
14
- } = useRpcPromise;
15
- return extendPromise(useRpcPromise.then(() => ({})), {
16
- data,
17
- fetch,
18
- error,
19
- refresh,
20
- status
21
- });
9
+ const { data, error, refresh, status } = useRpcPromise;
10
+ return extendPromise(
11
+ useRpcPromise.then(() => ({})),
12
+ {
13
+ data,
14
+ fetch,
15
+ error,
16
+ refresh,
17
+ status
18
+ }
19
+ );
22
20
  }
@@ -7,9 +7,7 @@ export function useSession() {
7
7
  refreshToken: useRpcCall("refreshAccessToken"),
8
8
  revokeToken: useRpcCall("oauthRevokeToken"),
9
9
  forgetPassword: useRpcCall("oauthForgetPassword"),
10
- resetPasswordByHash: useRpcCall(
11
- "updatePasswordByHash"
12
- ),
10
+ resetPasswordByHash: useRpcCall("updatePasswordByHash"),
13
11
  loginWithIDP: useRpcCall("handleIDPLoginCallback")
14
12
  };
15
13
  }
@@ -10,25 +10,16 @@ export function useUser(options = {}) {
10
10
  const updateUserRpc = useRpcCall("updateShopUser");
11
11
  const updatePasswordRpc = useRpcCall("updatePassword");
12
12
  const refreshUserRpc = useRpcCall("refreshUser");
13
- const {
14
- immediate = true,
15
- lazy = false,
16
- key = "useUser"
17
- } = options;
18
- const asyncDataPromise = useRpc(
19
- "getUser",
20
- key,
21
- void 0,
22
- {
23
- immediate,
24
- lazy,
25
- server: false,
26
- dedupe: "defer",
27
- getCachedData: (cacheKey) => {
28
- return toValue(nuxtApp._asyncData[cacheKey]?.data) ?? void 0;
29
- }
13
+ const { immediate = true, lazy = false, key = "useUser" } = options;
14
+ const asyncDataPromise = useRpc("getUser", key, void 0, {
15
+ immediate,
16
+ lazy,
17
+ server: false,
18
+ dedupe: "defer",
19
+ getCachedData: (cacheKey) => {
20
+ return toValue(nuxtApp._asyncData[cacheKey]?.data) ?? void 0;
30
21
  }
31
- );
22
+ });
32
23
  const { data, refresh, error, status } = asyncDataPromise;
33
24
  const updateUser = async (payload) => {
34
25
  log.debug("Update user");
@@ -53,16 +44,19 @@ export function useUser(options = {}) {
53
44
  log.debug("Refresh user");
54
45
  data.value = await refreshUserRpc();
55
46
  };
56
- return extendPromise(asyncDataPromise.then(() => ({})), {
57
- user,
58
- isLoggedIn,
59
- customerType,
60
- refresh,
61
- fetch,
62
- forceRefresh,
63
- updateUser,
64
- updatePassword,
65
- error,
66
- status
67
- });
47
+ return extendPromise(
48
+ asyncDataPromise.then(() => ({})),
49
+ {
50
+ user,
51
+ isLoggedIn,
52
+ customerType,
53
+ refresh,
54
+ fetch,
55
+ forceRefresh,
56
+ updateUser,
57
+ updatePassword,
58
+ error,
59
+ status
60
+ }
61
+ );
68
62
  }
@@ -80,5 +80,5 @@ type UseBasketBaseReturn = Omit<Awaited<UseRpcReturn<'getBasket'>>, 'data'> & {
80
80
  *
81
81
  * @throws {Error} If an item cannot be found during removal or if an item is added with a reduced quantity. Also throws FetchError if RPC calls fail.
82
82
  */
83
- export declare function useBasket({ params, }?: UseBasketOptions, key?: UseRpcCacheKey): UseBasketBaseReturn & Promise<UseBasketBaseReturn>;
83
+ export declare function useBasket({ params }?: UseBasketOptions, key?: UseRpcCacheKey): UseBasketBaseReturn & Promise<UseBasketBaseReturn>;
84
84
  export {};
@@ -10,9 +10,7 @@ import { useRpc } from "../core/useRpc.js";
10
10
  import { useRpcCall } from "../core/useRpcCall.js";
11
11
  import { toValue, computed } from "vue";
12
12
  import { FetchError } from "ofetch";
13
- export function useBasket({
14
- params
15
- } = {}, key = "useBasket") {
13
+ export function useBasket({ params } = {}, key = "useBasket") {
16
14
  const addItemToBasketRpc = useRpcCall("addItemToBasket");
17
15
  const addItemsToBasketRpc = useRpcCall("addItemsToBasket");
18
16
  const updateBasketItemRpc = useRpcCall("updateBasketItem");
@@ -40,12 +38,7 @@ export function useBasket({
40
38
  return toValue(nuxtApp._asyncData[cacheKey]?.data) ?? void 0;
41
39
  }
42
40
  });
43
- const {
44
- data,
45
- error,
46
- refresh,
47
- status
48
- } = asyncData;
41
+ const { data, error, refresh, status } = asyncData;
49
42
  const handleBasketError = (basketErrors) => {
50
43
  if (wasAddedWithReducedQuantity(basketErrors)) {
51
44
  throw new Error("Item was added with reduced quantity", {
@@ -54,9 +47,7 @@ export function useBasket({
54
47
  }
55
48
  };
56
49
  const handleFetchError = (error2) => {
57
- if (error2 instanceof FetchError && isAddOrUpdateItemError(
58
- error2.data.errors?.[0]
59
- ) && error2.data.errors?.[0].operation !== "delete") {
50
+ if (error2 instanceof FetchError && isAddOrUpdateItemError(error2.data.errors?.[0]) && error2.data.errors?.[0].operation !== "delete") {
60
51
  throw new Error(error2.message, {
61
52
  cause: error2.data.errors?.[0].kind
62
53
  });
@@ -164,42 +155,38 @@ export function useBasket({
164
155
  const products = computed(
165
156
  () => data.value?.items.map((item) => item.product) || []
166
157
  );
167
- const count = computed(
168
- () => {
169
- return data.value?.items?.reduce((prev, current) => {
170
- if (current.itemGroup?.id && !current.itemGroup.isMainItem) {
171
- return prev;
172
- }
173
- return prev + current.quantity;
174
- }, 0);
175
- }
176
- );
177
- const countWithoutSoldOutItems = computed(
178
- () => {
179
- const mainItemQuantities = /* @__PURE__ */ new Map();
180
- const soldOutItemGroups = /* @__PURE__ */ new Set();
181
- let count2 = (data.value?.items ?? []).reduce((prev, current) => {
182
- if (current.itemGroup?.id) {
183
- if (current.itemGroup.isMainItem) {
184
- mainItemQuantities.set(current.itemGroup.id, current.quantity);
185
- } else {
186
- if (current.product.isSoldOut && current.itemGroup.isRequired) {
187
- soldOutItemGroups.add(current.itemGroup.id);
188
- }
189
- return prev;
158
+ const count = computed(() => {
159
+ return data.value?.items?.reduce((prev, current) => {
160
+ if (current.itemGroup?.id && !current.itemGroup.isMainItem) {
161
+ return prev;
162
+ }
163
+ return prev + current.quantity;
164
+ }, 0);
165
+ });
166
+ const countWithoutSoldOutItems = computed(() => {
167
+ const mainItemQuantities = /* @__PURE__ */ new Map();
168
+ const soldOutItemGroups = /* @__PURE__ */ new Set();
169
+ let count2 = (data.value?.items ?? []).reduce((prev, current) => {
170
+ if (current.itemGroup?.id) {
171
+ if (current.itemGroup.isMainItem) {
172
+ mainItemQuantities.set(current.itemGroup.id, current.quantity);
173
+ } else {
174
+ if (current.product.isSoldOut && current.itemGroup.isRequired) {
175
+ soldOutItemGroups.add(current.itemGroup.id);
190
176
  }
191
- }
192
- if (current.product.isSoldOut) {
193
177
  return prev;
194
178
  }
195
- return prev + current.quantity;
196
- }, 0);
197
- soldOutItemGroups.forEach((itemGroupId) => {
198
- count2 -= mainItemQuantities.get(itemGroupId) || 0;
199
- });
200
- return count2;
201
- }
202
- );
179
+ }
180
+ if (current.product.isSoldOut) {
181
+ return prev;
182
+ }
183
+ return prev + current.quantity;
184
+ }, 0);
185
+ soldOutItemGroups.forEach((itemGroupId) => {
186
+ count2 -= mainItemQuantities.get(itemGroupId) || 0;
187
+ });
188
+ return count2;
189
+ });
203
190
  const items = computed(() => data.value?.items);
204
191
  const cost = computed(() => data.value?.cost);
205
192
  const basketKey = computed(() => data.value?.key);
@@ -3,10 +3,5 @@ export function useBrand({
3
3
  params,
4
4
  options
5
5
  } = {}, key = "useBrand") {
6
- return useRpc(
7
- "getBrandById",
8
- key,
9
- params,
10
- options
11
- );
6
+ return useRpc("getBrandById", key, params, options);
12
7
  }
@@ -3,10 +3,5 @@ export function useBrands({
3
3
  params,
4
4
  options
5
5
  } = {}, key = "useBrands") {
6
- return useRpc(
7
- "getBrands",
8
- key,
9
- params,
10
- options
11
- );
6
+ return useRpc("getBrands", key, params, options);
12
7
  }
@@ -2,10 +2,5 @@ import { useRpc } from "../core/useRpc.js";
2
2
  export function useCampaign({
3
3
  options
4
4
  } = {}, key = "useCampaign") {
5
- return useRpc(
6
- "getCampaign",
7
- key,
8
- void 0,
9
- options
10
- );
5
+ return useRpc("getCampaign", key, void 0, options);
11
6
  }
@@ -5,24 +5,17 @@ export function useCategories({
5
5
  params,
6
6
  options
7
7
  } = {}, key = "useCategories") {
8
- const useRpcPromise = useRpc(
9
- "getCategoriesByPath",
10
- key,
11
- params,
12
- options
13
- );
8
+ const useRpcPromise = useRpc("getCategoriesByPath", key, params, options);
14
9
  const getCategoryById = useRpcCall("getCategoryById");
15
- const {
16
- data,
17
- error,
18
- status,
19
- refresh
20
- } = useRpcPromise;
21
- return extendPromise(useRpcPromise.then(() => ({})), {
22
- data,
23
- error,
24
- status,
25
- refresh,
26
- getCategoryById: (id, includeHidden) => getCategoryById({ id, includeHidden })
27
- });
10
+ const { data, error, status, refresh } = useRpcPromise;
11
+ return extendPromise(
12
+ useRpcPromise.then(() => ({})),
13
+ {
14
+ data,
15
+ error,
16
+ status,
17
+ refresh,
18
+ getCategoryById: (id, includeHidden) => getCategoryById({ id, includeHidden })
19
+ }
20
+ );
28
21
  }
@@ -3,10 +3,5 @@ export function useCategoryById({
3
3
  params,
4
4
  options
5
5
  } = {}, key = "useCategoryById") {
6
- return useRpc(
7
- "getCategoryById",
8
- key,
9
- params,
10
- options
11
- );
6
+ return useRpc("getCategoryById", key, params, options);
12
7
  }
@@ -3,10 +3,5 @@ export function useCategoryByPath({
3
3
  params,
4
4
  options
5
5
  }, key = "useCategoryByPath") {
6
- return useRpc(
7
- "getCategoryByPath",
8
- key,
9
- params,
10
- options
11
- );
6
+ return useRpc("getCategoryByPath", key, params, options);
12
7
  }