@scayle/storefront-nuxt 8.18.0 → 8.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @scayle/storefront-nuxt
2
2
 
3
+ ## 8.19.1
4
+
5
+ ### Patch Changes
6
+
7
+ **Dependencies**
8
+
9
+ **@scayle/storefront-core v8.19.1**
10
+
11
+ - Patch
12
+ - Fix `getCategoriesByPath` RPC to return 404 for non-existing categories.
13
+
14
+ ## 8.19.0
15
+
16
+ ### Minor Changes
17
+
18
+ - Add a new `output` option to the log config. It controls where server-side logs are sent and can be set to `stderr`, `stdout` or `auto`. `stderr` and `stdout` will send all logs to the configured steam, while `auto` will send error logs `stderr` and other logs to `stdout`. `auto` is the default value.
19
+ - Add a new `json` option to the log config. When this is enabled via the nuxt.config or setting `NUXT_PUBLIC_STOREFRONT_LOG_JSON=true` in the `.env`, logs will be output in a JSON format.
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependency `@vueuse/core@13.0.0` to `@vueuse/core@13.1.0`
24
+
25
+ **@scayle/storefront-core v8.19.0**
26
+
27
+ **Dependencies**
28
+
3
29
  ## 8.18.0
4
30
 
5
31
  ### Patch Changes
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
- "version": "8.18.0",
3
+ "version": "8.19.1",
4
4
  "configKey": "storefront",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.9.0"
package/dist/module.mjs CHANGED
@@ -53,7 +53,7 @@ export default {
53
53
  }`;
54
54
  }
55
55
  const PACKAGE_NAME = "@scayle/storefront-nuxt";
56
- const PACKAGE_VERSION = "8.18.0";
56
+ const PACKAGE_VERSION = "8.19.1";
57
57
  const logger = createConsola({
58
58
  fancy: true,
59
59
  formatOptions: {
@@ -257,7 +257,9 @@ const module = defineNuxtModule({
257
257
  nuxt.options.runtimeConfig.public.storefront = defu(nuxt.options.runtimeConfig.public.storefront, {
258
258
  log: {
259
259
  name: "storefront-nuxt",
260
- level: "info"
260
+ level: "info",
261
+ json: false,
262
+ output: "auto"
261
263
  }
262
264
  });
263
265
  extendViteConfig((config) => {
@@ -0,0 +1,17 @@
1
+ import type { LogObject, ConsolaReporter, FormatOptions, ConsolaOptions } from 'consola';
2
+ /**
3
+ * This custom Consola reporter formats log objects in a JSON string.
4
+ * It is a modified version of the built-in BasicReporter
5
+ * https://github.com/unjs/consola/blob/main/src/reporters/basic.ts
6
+ */
7
+ export declare class JSONReporter implements ConsolaReporter {
8
+ formatStack(stack: string, message: string, opts: FormatOptions): string;
9
+ formatError(err: object, opts: FormatOptions): string;
10
+ formatArgs(args: unknown[], opts: FormatOptions): string;
11
+ formatDate(date: Date, opts: FormatOptions): string;
12
+ filterAndJoin(arr: (string | undefined | null)[]): string;
13
+ formatLogObj(logObj: LogObject, opts: FormatOptions): string;
14
+ log(logObj: LogObject, ctx: {
15
+ options: ConsolaOptions;
16
+ }): boolean;
17
+ }
@@ -0,0 +1,55 @@
1
+ import { formatWithOptions } from "node:util";
2
+ import { sep } from "node:path";
3
+ function parseStack(stack, message) {
4
+ const cwd = process.cwd() + sep;
5
+ const lines = stack.split("\n").splice(message.split("\n").length).map((l) => l.trim().replace("file://", "").replace(cwd, ""));
6
+ return lines;
7
+ }
8
+ export class JSONReporter {
9
+ formatStack(stack, message, opts) {
10
+ const indent = " ".repeat((opts?.errorLevel || 0) + 1);
11
+ return indent + parseStack(stack, message).join(`
12
+ ${indent}`);
13
+ }
14
+ formatError(err, opts) {
15
+ const message = "message" in err && err.message && typeof err.message === "string" ? err.message : formatWithOptions(opts, err);
16
+ const stack = "stack" in err && err.stack && typeof err.stack === "string" ? this.formatStack(err.stack, message, opts) : "";
17
+ const level = opts?.errorLevel || 0;
18
+ const causedPrefix = level > 0 ? `${" ".repeat(level)}[cause]: ` : "";
19
+ const causedError = "cause" in err && err.cause ? "\n\n" + this.formatError(err.cause, { ...opts, errorLevel: level + 1 }) : "";
20
+ return causedPrefix + message + "\n" + stack + causedError;
21
+ }
22
+ formatArgs(args, opts) {
23
+ const _args = args.map((arg) => {
24
+ if (arg && arg instanceof Error) {
25
+ return this.formatError(arg, opts);
26
+ }
27
+ return arg;
28
+ });
29
+ return formatWithOptions(opts, ..._args);
30
+ }
31
+ formatDate(date, opts) {
32
+ return opts.date ? date.toLocaleTimeString() : "";
33
+ }
34
+ filterAndJoin(arr) {
35
+ return arr.filter(Boolean).join(" ");
36
+ }
37
+ formatLogObj(logObj, opts) {
38
+ const message = this.formatArgs(logObj.args, opts);
39
+ return JSON.stringify({
40
+ timestamp: logObj.date.toISOString(),
41
+ message,
42
+ severity: logObj.type
43
+ });
44
+ }
45
+ log(logObj, ctx) {
46
+ const line = this.formatLogObj(logObj, {
47
+ columns: ctx.options.stdout?.columns || 0,
48
+ ...ctx.options.formatOptions,
49
+ colors: false,
50
+ compact: true
51
+ });
52
+ const stream = logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout;
53
+ return stream.write(line + "\n");
54
+ }
55
+ }
@@ -2,10 +2,20 @@ import { createConsola } from "consola";
2
2
  import { defineNitroPlugin } from "nitropack/runtime/plugin";
3
3
  import { useRuntimeConfig } from "#imports";
4
4
  import createLog from "../../createLog.js";
5
+ import { JSONReporter } from "../../JSONReporter.js";
5
6
  export default defineNitroPlugin((nitroApp) => {
6
7
  const config = useRuntimeConfig();
7
8
  const logConfig = config.public.storefront.log;
8
- const log = createLog(createConsola, logConfig.name, logConfig.level);
9
+ const log = createLog(
10
+ (opts) => createConsola({
11
+ ...logConfig.json ? { reporters: [new JSONReporter()] } : void 0,
12
+ stderr: logConfig.output === "stdout" ? process.stdout : process.stderr,
13
+ stdout: logConfig.output === "stderr" ? process.stderr : process.stdout,
14
+ ...opts
15
+ }),
16
+ logConfig.name,
17
+ logConfig.level
18
+ );
9
19
  log.info(`Logger instance created. Level: ${logConfig.level}`);
10
20
  nitroApp.hooks.hook("request", (event) => {
11
21
  event.context.$log = log;
@@ -4,6 +4,7 @@ import {
4
4
  STORAGE_MOUNT_SESSION
5
5
  } from "../../server/utils/cacheStorage.js";
6
6
  import createLog from "../../createLog.js";
7
+ import { JSONReporter } from "../../JSONReporter.js";
7
8
  import drivers from "#virtual/storage-drivers";
8
9
  import { defineNitroPlugin } from "nitropack/runtime/plugin";
9
10
  import { useStorage } from "nitropack/runtime/storage";
@@ -38,7 +39,16 @@ export default defineNitroPlugin(() => {
38
39
  const config = useRuntimeConfig();
39
40
  const { shops } = config.storefront;
40
41
  const logConfig = config.public.storefront.log;
41
- const log = createLog(createConsola, logConfig.name, logConfig.level);
42
+ const log = createLog(
43
+ (opts) => createConsola({
44
+ ...logConfig.json ? { reporters: [new JSONReporter()] } : void 0,
45
+ stderr: logConfig.output === "stdout" ? process.stdout : process.stderr,
46
+ stdout: logConfig.output === "stderr" ? process.stderr : process.stdout,
47
+ ...opts
48
+ }),
49
+ logConfig.name,
50
+ logConfig.level
51
+ );
42
52
  try {
43
53
  const globalCacheConfig = config.storefront.storage?.cache;
44
54
  mountStorage(storage, {
@@ -1028,12 +1028,18 @@ declare const PublicRuntimeConfigSchema: z.ZodObject<{
1028
1028
  log: z.ZodObject<{
1029
1029
  name: z.ZodString;
1030
1030
  level: z.ZodType<LogLevel, z.ZodTypeDef, LogLevel>;
1031
+ json: z.ZodOptional<z.ZodBoolean>;
1032
+ output: z.ZodDefault<z.ZodEnum<["stdout", "stderr", "auto"]>>;
1031
1033
  }, "strip", z.ZodTypeAny, {
1032
1034
  name: string;
1033
1035
  level: LogLevel;
1036
+ output: "stdout" | "stderr" | "auto";
1037
+ json?: boolean | undefined;
1034
1038
  }, {
1035
1039
  name: string;
1036
1040
  level: LogLevel;
1041
+ json?: boolean | undefined;
1042
+ output?: "stdout" | "stderr" | "auto" | undefined;
1037
1043
  }>;
1038
1044
  /** Collection of feature flags regarding legacy features and functionalities */
1039
1045
  legacy: z.ZodOptional<z.ZodObject<{
@@ -1047,6 +1053,8 @@ declare const PublicRuntimeConfigSchema: z.ZodObject<{
1047
1053
  log: {
1048
1054
  name: string;
1049
1055
  level: LogLevel;
1056
+ output: "stdout" | "stderr" | "auto";
1057
+ json?: boolean | undefined;
1050
1058
  };
1051
1059
  legacy?: {
1052
1060
  enableDefaultGetCachedDataOverride?: boolean | undefined;
@@ -1055,6 +1063,8 @@ declare const PublicRuntimeConfigSchema: z.ZodObject<{
1055
1063
  log: {
1056
1064
  name: string;
1057
1065
  level: LogLevel;
1066
+ json?: boolean | undefined;
1067
+ output?: "stdout" | "stderr" | "auto" | undefined;
1058
1068
  };
1059
1069
  legacy?: {
1060
1070
  enableDefaultGetCachedDataOverride?: boolean | undefined;
@@ -2130,12 +2140,18 @@ export declare const RuntimeConfigSchema: z.ZodObject<{
2130
2140
  log: z.ZodObject<{
2131
2141
  name: z.ZodString;
2132
2142
  level: z.ZodType<LogLevel, z.ZodTypeDef, LogLevel>;
2143
+ json: z.ZodOptional<z.ZodBoolean>;
2144
+ output: z.ZodDefault<z.ZodEnum<["stdout", "stderr", "auto"]>>;
2133
2145
  }, "strip", z.ZodTypeAny, {
2134
2146
  name: string;
2135
2147
  level: LogLevel;
2148
+ output: "stdout" | "stderr" | "auto";
2149
+ json?: boolean | undefined;
2136
2150
  }, {
2137
2151
  name: string;
2138
2152
  level: LogLevel;
2153
+ json?: boolean | undefined;
2154
+ output?: "stdout" | "stderr" | "auto" | undefined;
2139
2155
  }>;
2140
2156
  /** Collection of feature flags regarding legacy features and functionalities */
2141
2157
  legacy: z.ZodOptional<z.ZodObject<{
@@ -2149,6 +2165,8 @@ export declare const RuntimeConfigSchema: z.ZodObject<{
2149
2165
  log: {
2150
2166
  name: string;
2151
2167
  level: LogLevel;
2168
+ output: "stdout" | "stderr" | "auto";
2169
+ json?: boolean | undefined;
2152
2170
  };
2153
2171
  legacy?: {
2154
2172
  enableDefaultGetCachedDataOverride?: boolean | undefined;
@@ -2157,6 +2175,8 @@ export declare const RuntimeConfigSchema: z.ZodObject<{
2157
2175
  log: {
2158
2176
  name: string;
2159
2177
  level: LogLevel;
2178
+ json?: boolean | undefined;
2179
+ output?: "stdout" | "stderr" | "auto" | undefined;
2160
2180
  };
2161
2181
  legacy?: {
2162
2182
  enableDefaultGetCachedDataOverride?: boolean | undefined;
@@ -2167,6 +2187,8 @@ export declare const RuntimeConfigSchema: z.ZodObject<{
2167
2187
  log: {
2168
2188
  name: string;
2169
2189
  level: LogLevel;
2190
+ output: "stdout" | "stderr" | "auto";
2191
+ json?: boolean | undefined;
2170
2192
  };
2171
2193
  legacy?: {
2172
2194
  enableDefaultGetCachedDataOverride?: boolean | undefined;
@@ -2177,6 +2199,8 @@ export declare const RuntimeConfigSchema: z.ZodObject<{
2177
2199
  log: {
2178
2200
  name: string;
2179
2201
  level: LogLevel;
2202
+ json?: boolean | undefined;
2203
+ output?: "stdout" | "stderr" | "auto" | undefined;
2180
2204
  };
2181
2205
  legacy?: {
2182
2206
  enableDefaultGetCachedDataOverride?: boolean | undefined;
@@ -2351,6 +2375,8 @@ export declare const RuntimeConfigSchema: z.ZodObject<{
2351
2375
  log: {
2352
2376
  name: string;
2353
2377
  level: LogLevel;
2378
+ output: "stdout" | "stderr" | "auto";
2379
+ json?: boolean | undefined;
2354
2380
  };
2355
2381
  legacy?: {
2356
2382
  enableDefaultGetCachedDataOverride?: boolean | undefined;
@@ -2525,6 +2551,8 @@ export declare const RuntimeConfigSchema: z.ZodObject<{
2525
2551
  log: {
2526
2552
  name: string;
2527
2553
  level: LogLevel;
2554
+ json?: boolean | undefined;
2555
+ output?: "stdout" | "stderr" | "auto" | undefined;
2528
2556
  };
2529
2557
  legacy?: {
2530
2558
  enableDefaultGetCachedDataOverride?: boolean | undefined;
@@ -145,7 +145,9 @@ const logLevel = z.enum(["debug", "info", "warn", "error"]);
145
145
  const PublicRuntimeConfigSchema = z.object({
146
146
  log: z.object({
147
147
  name: z.string(),
148
- level: logLevel
148
+ level: logLevel,
149
+ json: z.boolean().optional(),
150
+ output: z.enum(["stdout", "stderr", "auto"]).default("auto")
149
151
  }),
150
152
  /** Collection of feature flags regarding legacy features and functionalities */
151
153
  legacy: z.object({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
3
  "type": "module",
4
- "version": "8.18.0",
4
+ "version": "8.19.1",
5
5
  "description": "Nuxt integration for the SCAYLE Commerce Engine and Storefront API",
6
6
  "author": "SCAYLE Commerce Engine",
7
7
  "license": "MIT",
@@ -81,10 +81,10 @@
81
81
  "dependencies": {
82
82
  "@opentelemetry/api": "^1.9.0",
83
83
  "@scayle/h3-session": "0.6.0",
84
- "@scayle/storefront-core": "8.18.0",
84
+ "@scayle/storefront-core": "8.19.1",
85
85
  "@scayle/unstorage-compression-driver": "^0.2.6",
86
86
  "@vercel/nft": "0.29.2",
87
- "@vueuse/core": "13.0.0",
87
+ "@vueuse/core": "13.1.0",
88
88
  "consola": "^3.2.3",
89
89
  "core-js": "^3.37.1",
90
90
  "defu": "^6.1.4",