@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 +1 -1
- package/dist/module.mjs +8 -1
- package/dist/runtime/composables/usePlentyLogs.d.ts +2 -0
- package/dist/runtime/composables/usePlentyLogs.js +6 -0
- package/dist/runtime/plugins/logs.client.d.ts +11 -0
- package/dist/runtime/plugins/logs.client.js +30 -0
- package/dist/runtime/types/index.d.ts +1 -0
- package/dist/runtime/types/index.js +1 -0
- package/dist/runtime/types/log-events.d.ts +5 -0
- package/dist/runtime/types/log-events.js +5 -0
- package/dist/runtime/types/module.d.ts +1 -0
- package/dist/runtime/utils/logTracker.d.ts +17 -0
- package/dist/runtime/utils/logTracker.js +28 -0
- package/package.json +2 -2
package/dist/module.json
CHANGED
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,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
|
+
});
|
|
@@ -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.
|
|
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.
|
|
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",
|