@plentymarkets/shop-core 1.23.9 → 1.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@plentymarkets/shop-core",
3
3
  "configKey": "shopCore",
4
- "version": "1.23.9",
4
+ "version": "1.25.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -167,7 +167,8 @@ const module$1 = defineNuxtModule({
167
167
  apiUrl: _options.apiUrl,
168
168
  configId: _options.configId,
169
169
  experimental: {
170
- enableSSRMetrics: _options.experimental?.enableSSRMetrics ?? false
170
+ enableSSRMetrics: _options.experimental?.enableSSRMetrics ?? false,
171
+ enablePlentyLogs: _options.experimental?.enablePlentyLogs ?? true
171
172
  },
172
173
  middlewareSSRUrl: _options.middlewareSSRUrl,
173
174
  logger: {
@@ -244,6 +245,7 @@ export type ShopCoreConfig = ${genInlineTypeImport(projectRootResolver.resolve("
244
245
  });
245
246
  addPlugin(resolver.resolve("./runtime/plugins/sdk"));
246
247
  addPlugin(resolver.resolve("./runtime/plugins/cache-control.server"));
248
+ addPlugin(resolver.resolve("./runtime/plugins/logs.client"));
247
249
  addImports({
248
250
  name: "useSdk",
249
251
  as: "useSdk",
@@ -309,6 +311,11 @@ export type ShopCoreConfig = ${genInlineTypeImport(projectRootResolver.resolve("
309
311
  as: "t",
310
312
  from: resolver.resolve("./runtime/composables/useT")
311
313
  });
314
+ addImports({
315
+ name: "usePlentyLogs",
316
+ as: "usePlentyLogs",
317
+ from: resolver.resolve("./runtime/composables/usePlentyLogs")
318
+ });
312
319
  addImports({
313
320
  name: "getSSRMetrics",
314
321
  as: "getSSRMetrics",
@@ -0,0 +1,2 @@
1
+ import type { ShopLogEventInput } from '../types/log-events.js';
2
+ export declare const usePlentyLogs: (event: ShopLogEventInput) => void;
@@ -0,0 +1,6 @@
1
+ import { useNuxtApp } from "#app";
2
+ export const usePlentyLogs = (event) => {
3
+ if (!import.meta.client) return;
4
+ const { $trackEvent } = useNuxtApp();
5
+ $trackEvent(event);
6
+ };
@@ -0,0 +1,11 @@
1
+ import type { ShopLogEventInput } from '../types/log-events.js';
2
+ declare const _default: import("#app").Plugin<{
3
+ trackEvent: (_event: ShopLogEventInput) => void;
4
+ collectEvents: () => Promise<void>;
5
+ stopCollectInterval: () => void;
6
+ }> & import("#app").ObjectPlugin<{
7
+ trackEvent: (_event: ShopLogEventInput) => void;
8
+ collectEvents: () => Promise<void>;
9
+ stopCollectInterval: () => void;
10
+ }>;
11
+ export default _default;
@@ -0,0 +1,30 @@
1
+ import { defineNuxtPlugin, useRuntimeConfig, useState } from "#app";
2
+ import { createLogsTracker } from "../utils/logTracker.js";
3
+ import { useSdk } from "../composables/useSdk.js";
4
+ export default defineNuxtPlugin(() => {
5
+ const config = useRuntimeConfig();
6
+ let trackEvent = (_event) => {
7
+ };
8
+ let collectEvents = async () => {
9
+ };
10
+ let stopCollectInterval = () => {
11
+ };
12
+ if (config.public.shopCore.experimental.enablePlentyLogs) {
13
+ const queue = useState("plenty-log-event-queue", () => []);
14
+ const sendLogs = async (payload) => {
15
+ return useSdk().plentysystems.doAddShopLogs(payload);
16
+ };
17
+ const tracker = createLogsTracker({ queue, fetcher: sendLogs });
18
+ trackEvent = tracker.trackEvent;
19
+ collectEvents = tracker.collectEvents;
20
+ stopCollectInterval = tracker.stopCollectInterval;
21
+ tracker.startCollectInterval();
22
+ }
23
+ return {
24
+ provide: {
25
+ trackEvent,
26
+ collectEvents,
27
+ stopCollectInterval
28
+ }
29
+ };
30
+ });
@@ -6,3 +6,4 @@ export * from './notification.js';
6
6
  export * from './localization.js';
7
7
  export * from './module.js';
8
8
  export * from './ssr-metrics.js';
9
+ export * from './log-events.js';
@@ -6,3 +6,4 @@ export * from "./notification.js";
6
6
  export * from "./localization.js";
7
7
  export * from "./module.js";
8
8
  export * from "./ssr-metrics.js";
9
+ export * from "./log-events.js";
@@ -0,0 +1,5 @@
1
+ import type { ISODateString, ShopLogEvent } from "@plentymarkets/shop-api";
2
+ export declare const toISODateString: (value: Date | string) => ISODateString;
3
+ export type ShopLogEventInput = Omit<ShopLogEvent, 'triggeredAt'> & {
4
+ triggeredAt?: ISODateString;
5
+ };
@@ -0,0 +1,5 @@
1
+ export const toISODateString = (value) => {
2
+ const d = value instanceof Date ? value : new Date(value);
3
+ if (Number.isNaN(d.getTime())) throw new Error(`Invalid date: ${String(value)}`);
4
+ return d.toISOString();
5
+ };
@@ -4,6 +4,7 @@ export interface ModuleOptions {
4
4
  configId: number;
5
5
  experimental?: {
6
6
  enableSSRMetrics?: boolean;
7
+ enablePlentyLogs?: boolean;
7
8
  };
8
9
  middlewareSSRUrl?: string;
9
10
  logger?: {
@@ -0,0 +1,17 @@
1
+ import type { ShopLogEvent } from '@plentymarkets/shop-api';
2
+ import type { ShopLogEventInput } from '../types/log-events.js';
3
+ interface QueueRef {
4
+ value: ShopLogEvent[];
5
+ }
6
+ interface LogsTrackerDeps {
7
+ queue: QueueRef;
8
+ fetcher: (payload: ShopLogEvent[]) => Promise<unknown>;
9
+ intervalMs?: number;
10
+ }
11
+ export declare const createLogsTracker: (deps: LogsTrackerDeps) => {
12
+ trackEvent: (event: ShopLogEventInput) => void;
13
+ collectEvents: () => Promise<void>;
14
+ startCollectInterval: () => void;
15
+ stopCollectInterval: () => void;
16
+ };
17
+ export {};
@@ -0,0 +1,28 @@
1
+ export const createLogsTracker = (deps) => {
2
+ const { queue, fetcher, intervalMs = 1e4 } = deps;
3
+ let flushInterval = null;
4
+ const trackEvent = (event) => {
5
+ queue.value.push({ ...event, triggeredAt: event.triggeredAt ?? (/* @__PURE__ */ new Date()).toISOString() });
6
+ };
7
+ const collectEvents = async () => {
8
+ if (queue.value.length === 0) return;
9
+ const eventsToSend = [...queue.value];
10
+ queue.value.length = 0;
11
+ try {
12
+ await fetcher(eventsToSend);
13
+ } catch (error) {
14
+ console.error("Failed to send events:", error);
15
+ queue.value.unshift(...eventsToSend);
16
+ }
17
+ };
18
+ const startCollectInterval = () => {
19
+ flushInterval ??= setInterval(collectEvents, intervalMs);
20
+ };
21
+ const stopCollectInterval = () => {
22
+ if (flushInterval) {
23
+ clearInterval(flushInterval);
24
+ flushInterval = null;
25
+ }
26
+ };
27
+ return { trackEvent, collectEvents, startCollectInterval, stopCollectInterval };
28
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plentymarkets/shop-core",
3
- "version": "1.23.9",
3
+ "version": "1.25.0",
4
4
  "description": "Core module for PlentyONE Shop",
5
5
  "repository": {
6
6
  "type": "git",
@@ -50,7 +50,7 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@noble/hashes": "^2.0.1",
53
- "@plentymarkets/shop-api": "^0.168.0",
53
+ "@plentymarkets/shop-api": "^0.170.0",
54
54
  "@vue-storefront/sdk": "^3.4.1",
55
55
  "cookie-es": "^2.0.0",
56
56
  "knitwork": "^1.3.0",