@scayle/storefront-nuxt 8.61.0 → 8.61.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG-V7.md +3 -11
- package/CHANGELOG.md +240 -255
- package/dist/module.json +1 -1
- package/dist/module.mjs +95 -39
- package/dist/runtime/api/rpcHandler.js +1 -4
- package/dist/runtime/cached.js +1 -6
- package/dist/runtime/campaignKey.js +15 -15
- package/dist/runtime/composables/core/useIDP.js +11 -13
- package/dist/runtime/composables/core/useSession.js +1 -3
- package/dist/runtime/composables/core/useUser.js +24 -30
- package/dist/runtime/composables/storefront/useBasket.d.ts +1 -1
- package/dist/runtime/composables/storefront/useBasket.js +32 -45
- package/dist/runtime/composables/storefront/useBrand.js +1 -6
- package/dist/runtime/composables/storefront/useBrands.js +1 -6
- package/dist/runtime/composables/storefront/useCampaign.js +1 -6
- package/dist/runtime/composables/storefront/useCategories.js +12 -19
- package/dist/runtime/composables/storefront/useCategoryById.js +1 -6
- package/dist/runtime/composables/storefront/useCategoryByPath.js +1 -6
- package/dist/runtime/composables/storefront/useCurrentPromotions.js +7 -12
- package/dist/runtime/composables/storefront/useFilters.js +1 -6
- package/dist/runtime/composables/storefront/useNavigationTree.js +2 -12
- package/dist/runtime/composables/storefront/useNavigationTrees.js +1 -6
- package/dist/runtime/composables/storefront/useProduct.js +1 -6
- package/dist/runtime/composables/storefront/useProducts.js +1 -6
- package/dist/runtime/composables/storefront/useProductsByIds.js +1 -6
- package/dist/runtime/composables/storefront/useProductsByReferenceKeys.js +1 -6
- package/dist/runtime/composables/storefront/useProductsCount.js +1 -6
- package/dist/runtime/composables/storefront/usePromotions.js +1 -6
- package/dist/runtime/composables/storefront/usePromotionsByIds.js +1 -6
- package/dist/runtime/composables/storefront/useShopConfiguration.js +1 -6
- package/dist/runtime/composables/storefront/useUserAddresses.js +1 -6
- package/dist/runtime/composables/storefront/useVariant.js +1 -6
- package/dist/runtime/composables/storefront/useWishlist.d.ts +1 -1
- package/dist/runtime/composables/storefront/useWishlist.js +11 -25
- package/dist/runtime/context.js +2 -10
- package/dist/runtime/nitro/plugins/configValidation.js +6 -4
- package/dist/runtime/nitro/plugins/nitroStorageConfig.js +1 -4
- package/dist/runtime/server/middleware/bootstrap.js +3 -14
- package/dist/runtime/server/middleware/redirects.js +1 -3
- package/dist/runtime/utils/storage.js +1 -4
- package/dist/runtime/utils/zodSchema.js +33 -25
- package/package.json +9 -8
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
|
-
import {
|
|
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.
|
|
60
|
+
const PACKAGE_VERSION = "8.61.2";
|
|
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(
|
|
83
|
+
names.map(
|
|
84
|
+
(name) => `${name}: typeof import('${source}')['${name}'],`
|
|
85
|
+
).join("\n")
|
|
83
86
|
),
|
|
84
87
|
[]
|
|
85
88
|
).join("\n")}
|
|
@@ -105,7 +108,60 @@ function readHttpMethod(handler) {
|
|
|
105
108
|
}
|
|
106
109
|
return DEFAULT_RPC_HTTP_METHOD;
|
|
107
110
|
}
|
|
108
|
-
|
|
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(`Alias chain for ${target} resolved to ${current} but maximum depth of 10 was reached`);
|
|
135
|
+
return current;
|
|
136
|
+
}
|
|
137
|
+
async function buildResolvedNuxtAliasMap(nuxt) {
|
|
138
|
+
return runWithNuxtContext(nuxt, async () => {
|
|
139
|
+
const alias = getNuxtStringAliases(nuxt);
|
|
140
|
+
const resolveOpts = {
|
|
141
|
+
cwd: nuxt.options.rootDir,
|
|
142
|
+
alias,
|
|
143
|
+
virtual: true,
|
|
144
|
+
fallbackToOriginal: true
|
|
145
|
+
};
|
|
146
|
+
const resolved = {};
|
|
147
|
+
for (const [specifier, target] of Object.entries(alias)) {
|
|
148
|
+
try {
|
|
149
|
+
resolved[specifier] = await resolveAliasChain(target, resolveOpts);
|
|
150
|
+
} catch {
|
|
151
|
+
resolved[specifier] = target;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return sortAliasRecordByLongestSpecifierFirst(resolved);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function getJitiParentUrlForNuxtApp(nuxt) {
|
|
158
|
+
const pkg = join(nuxt.options.rootDir, "package.json");
|
|
159
|
+
if (existsSync(pkg)) {
|
|
160
|
+
return pathToFileURL(pkg).href;
|
|
161
|
+
}
|
|
162
|
+
return pathToFileURL(join(nuxt.options.rootDir, ".")).href;
|
|
163
|
+
}
|
|
164
|
+
async function buildRpcHttpMethodManifest(customRpcImports, coreHandlers, nuxt) {
|
|
109
165
|
const manifest = {};
|
|
110
166
|
for (const [name, handler] of Object.entries(coreHandlers)) {
|
|
111
167
|
manifest[name] = readHttpMethod(handler);
|
|
@@ -113,10 +169,13 @@ async function buildRpcHttpMethodManifest(customRpcImports, coreHandlers) {
|
|
|
113
169
|
if (customRpcImports.length === 0) {
|
|
114
170
|
return manifest;
|
|
115
171
|
}
|
|
172
|
+
const jiti = createJiti(getJitiParentUrlForNuxtApp(nuxt), {
|
|
173
|
+
alias: await buildResolvedNuxtAliasMap(nuxt)
|
|
174
|
+
});
|
|
116
175
|
for (const { source, names } of customRpcImports) {
|
|
117
176
|
let loadedModule;
|
|
118
177
|
try {
|
|
119
|
-
loadedModule = await import(source);
|
|
178
|
+
loadedModule = await jiti.import(source);
|
|
120
179
|
} catch (error) {
|
|
121
180
|
logger.warn(
|
|
122
181
|
`Failed to load custom RPC module '${source}' while inferring HTTP methods. Methods from this module will default to '${DEFAULT_RPC_HTTP_METHOD}'.`,
|
|
@@ -134,8 +193,8 @@ function createRpcHttpMethodsSource(manifest) {
|
|
|
134
193
|
export const rpcHttpMethods = ${JSON.stringify(manifest, null, 2)}
|
|
135
194
|
`;
|
|
136
195
|
}
|
|
137
|
-
async function nitroSetup(nitroConfig, config, moduleOptions) {
|
|
138
|
-
const { resolve, resolvePath } = createResolver(import.meta.url);
|
|
196
|
+
async function nitroSetup(nitroConfig, config, moduleOptions, nuxt) {
|
|
197
|
+
const { resolve, resolvePath: resolvePath2 } = createResolver(import.meta.url);
|
|
139
198
|
const {
|
|
140
199
|
apiBasePath,
|
|
141
200
|
customRpcImports,
|
|
@@ -144,33 +203,28 @@ async function nitroSetup(nitroConfig, config, moduleOptions) {
|
|
|
144
203
|
rpcHttpMethodManifest,
|
|
145
204
|
rpcHttpMethodsPath
|
|
146
205
|
} = config;
|
|
206
|
+
const nuxtAliases = await buildResolvedNuxtAliasMap(nuxt);
|
|
147
207
|
nitroConfig.replace = nitroConfig.replace || {};
|
|
148
208
|
nitroConfig.replace["process.env.SFC_OMIT_MD5"] = stringToBoolean(
|
|
149
209
|
process.env.SFC_OMIT_MD5
|
|
150
210
|
);
|
|
151
211
|
nitroConfig.replace.__sfc_version = PACKAGE_VERSION;
|
|
152
212
|
nitroConfig.alias = {
|
|
153
|
-
...
|
|
213
|
+
...nuxtAliases,
|
|
214
|
+
...nitroConfig.alias ?? {},
|
|
154
215
|
"#virtual/rpcHttpMethods": rpcHttpMethodsPath
|
|
155
216
|
};
|
|
156
217
|
nitroConfig.virtual = {
|
|
157
218
|
...nitroConfig.virtual,
|
|
158
|
-
"#virtual/storage-drivers": createVirtualDriverImport(
|
|
159
|
-
|
|
160
|
-
),
|
|
161
|
-
"#virtual/customRpcMethods": createRpcMethodIndex(
|
|
162
|
-
customRpcImports
|
|
163
|
-
)
|
|
219
|
+
"#virtual/storage-drivers": createVirtualDriverImport(usedDrivers),
|
|
220
|
+
"#virtual/customRpcMethods": createRpcMethodIndex(customRpcImports)
|
|
164
221
|
};
|
|
165
222
|
nitroConfig.handlers = nitroConfig.handlers ?? [];
|
|
166
223
|
nitroConfig.handlers.unshift({
|
|
167
224
|
middleware: true,
|
|
168
225
|
handler: resolve("./runtime/server/middleware/bootstrap")
|
|
169
226
|
});
|
|
170
|
-
const allRpcNames = customRpcImports.reduce(
|
|
171
|
-
(acc, { names }) => acc.concat(names),
|
|
172
|
-
[]
|
|
173
|
-
).concat(coreMethodNames);
|
|
227
|
+
const allRpcNames = customRpcImports.reduce((acc, { names }) => acc.concat(names), []).concat(coreMethodNames);
|
|
174
228
|
for (const methodName of allRpcNames) {
|
|
175
229
|
const httpMethod = rpcHttpMethodManifest[methodName] ?? DEFAULT_RPC_HTTP_METHOD;
|
|
176
230
|
nitroConfig.handlers.push({
|
|
@@ -203,9 +257,7 @@ async function nitroSetup(nitroConfig, config, moduleOptions) {
|
|
|
203
257
|
resolve("./runtime/nitro/plugins/nitroLegacyStorageConfig")
|
|
204
258
|
);
|
|
205
259
|
}
|
|
206
|
-
nitroConfig.plugins.push(
|
|
207
|
-
resolve("./runtime/nitro/plugins/internalFetch")
|
|
208
|
-
);
|
|
260
|
+
nitroConfig.plugins.push(resolve("./runtime/nitro/plugins/internalFetch"));
|
|
209
261
|
if (stringToBoolean(process.env.SFC_PLUGIN_CONFIG_VALIDATION_ENABLED, true)) {
|
|
210
262
|
logger.debug("Installing config validation plugin");
|
|
211
263
|
nitroConfig.plugins.push(
|
|
@@ -233,14 +285,12 @@ async function nitroSetup(nitroConfig, config, moduleOptions) {
|
|
|
233
285
|
);
|
|
234
286
|
}
|
|
235
287
|
const base = resolve(`./`);
|
|
236
|
-
const handlerPaths = nitroConfig.handlers.filter(
|
|
237
|
-
(h) => h?.handler && h?.handler.startsWith(base)
|
|
238
|
-
).map((h) => h?.handler);
|
|
288
|
+
const handlerPaths = nitroConfig.handlers.filter((h) => h?.handler && h?.handler.startsWith(base)).map((h) => h?.handler);
|
|
239
289
|
const pluginPaths = nitroConfig.plugins.filter(
|
|
240
290
|
(p) => p && p?.startsWith(base)
|
|
241
291
|
);
|
|
242
292
|
const runtimeEntries = await Promise.all(
|
|
243
|
-
[...handlerPaths, ...pluginPaths].map((p) =>
|
|
293
|
+
[...handlerPaths, ...pluginPaths].map((p) => resolvePath2(p))
|
|
244
294
|
);
|
|
245
295
|
const trace = await nodeFileTrace(runtimeEntries, { base });
|
|
246
296
|
const tracedImports = [...trace.fileList].map((p) => resolve(p));
|
|
@@ -300,7 +350,7 @@ const module$1 = defineNuxtModule({
|
|
|
300
350
|
},
|
|
301
351
|
async setup(options, nuxt) {
|
|
302
352
|
const { resolve } = createResolver(import.meta.url);
|
|
303
|
-
const { resolve: appResolve, resolvePath } = createResolver(
|
|
353
|
+
const { resolve: appResolve, resolvePath: resolvePath2 } = createResolver(
|
|
304
354
|
nuxt.options.rootDir
|
|
305
355
|
);
|
|
306
356
|
addServerTemplate({
|
|
@@ -401,7 +451,7 @@ const module$1 = defineNuxtModule({
|
|
|
401
451
|
(name) => !storefrontRpcMethodNames.includes(name)
|
|
402
452
|
);
|
|
403
453
|
});
|
|
404
|
-
const rpcDir = await
|
|
454
|
+
const rpcDir = await resolvePath2(
|
|
405
455
|
appResolve(options.rpcDir ?? "./rpcMethods")
|
|
406
456
|
);
|
|
407
457
|
if (existsSync(rpcDir)) {
|
|
@@ -420,7 +470,8 @@ const module$1 = defineNuxtModule({
|
|
|
420
470
|
);
|
|
421
471
|
rpcHttpMethodManifest = await buildRpcHttpMethodManifest(
|
|
422
472
|
customRpcImports,
|
|
423
|
-
rpcMethods
|
|
473
|
+
rpcMethods,
|
|
474
|
+
nuxt
|
|
424
475
|
);
|
|
425
476
|
const rpcHttpMethodsSource = createRpcHttpMethodsSource(
|
|
426
477
|
rpcHttpMethodManifest
|
|
@@ -461,14 +512,19 @@ const module$1 = defineNuxtModule({
|
|
|
461
512
|
export {}`
|
|
462
513
|
});
|
|
463
514
|
nuxt.hooks.hook("nitro:config", async (nitroConfig) => {
|
|
464
|
-
await nitroSetup(
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
515
|
+
await nitroSetup(
|
|
516
|
+
nitroConfig,
|
|
517
|
+
{
|
|
518
|
+
apiBasePath,
|
|
519
|
+
customRpcImports,
|
|
520
|
+
coreMethodNames: [...rpcMethodNames],
|
|
521
|
+
usedDrivers: getUsedDrivers(nuxt.options.runtimeConfig.storefront),
|
|
522
|
+
rpcHttpMethodManifest,
|
|
523
|
+
rpcHttpMethodsPath
|
|
524
|
+
},
|
|
525
|
+
nuxt.options.runtimeConfig.storefront,
|
|
526
|
+
nuxt
|
|
527
|
+
);
|
|
472
528
|
});
|
|
473
529
|
nuxt.hooks.hook("nitro:init", async (nitro) => {
|
|
474
530
|
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;
|
package/dist/runtime/cached.js
CHANGED
|
@@ -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(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
() => {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (current.itemGroup.
|
|
184
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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);
|
|
@@ -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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
}
|