@plentymarkets/shop-core 1.13.6 → 1.13.8

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.13.6",
4
+ "version": "1.13.8",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  import { defineNuxtModule, createResolver, addImports } from '@nuxt/kit';
2
2
  import { ofetch } from 'ofetch';
3
- import { writeFile } from 'fs/promises';
3
+ import { mkdir, writeFile } from 'fs/promises';
4
4
  import { join } from 'path';
5
+ import { existsSync } from 'fs';
5
6
 
6
7
  const fetchAllTranslations = async (url, configId, securityToken) => {
7
8
  return await ofetch(
@@ -35,18 +36,23 @@ const module$1 = defineNuxtModule({
35
36
  };
36
37
  const overridesDir = resolver.resolve("./runtime/lang/overrides");
37
38
  const allLocalesForOverride = [];
39
+ if (!existsSync(overridesDir)) {
40
+ await mkdir(overridesDir, { recursive: true });
41
+ }
38
42
  if (_options.apiEndpoint && _options.configId && _options.securityToken) {
39
43
  try {
40
44
  const { data } = await fetchAllTranslations(_options.apiEndpoint, _options.configId, _options.securityToken);
41
45
  for (const key of Object.keys(data)) {
42
46
  allLocalesForOverride.push(key);
43
47
  await writeFile(join(overridesDir, `${key}.json`), JSON.stringify({ translated: data[key] }, null, 2));
48
+ console.log(`[shop-core] Wrote language overrides for locale "${key}"`);
44
49
  }
45
50
  } catch (error) {
46
51
  console.warn("Failed to fetch translations: ", error);
47
52
  }
48
53
  }
49
54
  nuxt.hook("i18n:registerModule", (register) => {
55
+ console.log(`[shop-core] Hook(i18n:registerModule) Registering language overrides for locales: "${allLocalesForOverride.join(", ")}"`);
50
56
  if (allLocalesForOverride.length > 0) {
51
57
  register({
52
58
  langDir: resolver.resolve("./runtime/lang/overrides"),
@@ -4,6 +4,7 @@ export declare const useEditorLocalizationKeys: () => {
4
4
  checkHasUnsavedChanges: () => boolean;
5
5
  collectChangedTranslations: () => Record<string, Record<string, string>>;
6
6
  loadKeys: () => Promise<void>;
7
+ filterKeys: (searchTerm: string, activeLocales: string[]) => void;
7
8
  getTranslatedCount: (locale: string) => {
8
9
  translated: number;
9
10
  undeployed: number;
@@ -13,6 +14,7 @@ export declare const useEditorLocalizationKeys: () => {
13
14
  getKeyFromFullKey: (key: string) => string;
14
15
  saveLocalizations: () => Promise<void>;
15
16
  keys: import("vue").Ref<MultilingualKeysState[], MultilingualKeysState[]>;
17
+ filteredKeys: import("vue").Ref<MultilingualKeysState[] | null, MultilingualKeysState[] | null>;
16
18
  drawerOpen: import("vue").Ref<boolean, boolean>;
17
19
  hasChanges: import("vue").Ref<boolean, boolean>;
18
20
  backendLanguages: import("vue").Ref<Set<string>, Set<string>>;
@@ -6,6 +6,7 @@ import { allLanguages } from "./useEditorLocalizationLocales.js";
6
6
  export const useEditorLocalizationKeys = () => {
7
7
  const state = useState("useEditorLocalizationKeys", () => ({
8
8
  keys: [],
9
+ filteredKeys: null,
9
10
  drawerOpen: false,
10
11
  hasChanges: false,
11
12
  backendLanguages: /* @__PURE__ */ new Set(),
@@ -28,6 +29,23 @@ export const useEditorLocalizationKeys = () => {
28
29
  state.value.loading = false;
29
30
  state.value.drawerOpen = true;
30
31
  };
32
+ const filterKeys = (searchTerm, activeLocales) => {
33
+ if (searchTerm.trim().length === 0) {
34
+ state.value.filteredKeys = null;
35
+ return;
36
+ }
37
+ const searchQuery = searchTerm.trim().toLowerCase();
38
+ state.value.filteredKeys = state.value.keys.filter((keyEntry) => {
39
+ if (keyEntry.key.toLowerCase().includes(searchQuery)) {
40
+ return true;
41
+ }
42
+ return activeLocales.some((locale) => {
43
+ const translation = keyEntry.translations[locale];
44
+ if (!translation) return false;
45
+ return translation.input.toLowerCase().includes(searchQuery);
46
+ });
47
+ });
48
+ };
31
49
  const getTranslatedCount = (locale) => {
32
50
  let translatedCount = 0;
33
51
  let undeployedCount = 0;
@@ -65,7 +83,7 @@ export const useEditorLocalizationKeys = () => {
65
83
  for (const locale in keyState.translations) {
66
84
  if (!selectedLocalesSet.has(locale)) continue;
67
85
  const translation = keyState.translations[locale];
68
- if (translation && translation.input && translation.input !== translation.value) {
86
+ if (translation && translation.input !== translation.value) {
69
87
  if (!translationsByLocale[locale]) translationsByLocale[locale] = {};
70
88
  translationsByLocale[locale][keyState.key] = translation.input;
71
89
  }
@@ -81,7 +99,7 @@ export const useEditorLocalizationKeys = () => {
81
99
  for (const locale in keyState.translations) {
82
100
  if (!selectedLocalesSet.has(locale)) continue;
83
101
  const translation = keyState.translations[locale];
84
- if (translation && translation.input && translation.input !== translation.value) {
102
+ if (translation && translation.input !== translation.value) {
85
103
  return true;
86
104
  }
87
105
  }
@@ -168,6 +186,7 @@ export const useEditorLocalizationKeys = () => {
168
186
  checkHasUnsavedChanges,
169
187
  collectChangedTranslations,
170
188
  loadKeys,
189
+ filterKeys,
171
190
  getTranslatedCount,
172
191
  getCategoryFromKey,
173
192
  getKeyFromFullKey,
@@ -1,17 +1,21 @@
1
1
  import { useState } from "nuxt/app";
2
- import { toRefs } from "vue";
2
+ import { toRefs, onUnmounted, getCurrentInstance } from "vue";
3
3
  const maxVisibleNotifications = 5;
4
- const dismissTimeout = 5e3;
5
- export const useNotification = () => {
4
+ export const useNotification = (defaultDismissTimeout = 5e3) => {
6
5
  const state = useState(`useNotification`, () => ({
7
6
  data: []
8
7
  }));
8
+ const timeoutIds = /* @__PURE__ */ new Map();
9
9
  const send = (notification) => {
10
10
  if (import.meta.server) return;
11
11
  const id = Symbol();
12
12
  const dismiss = () => {
13
13
  const index = state.value.data.findIndex((notification2) => notification2.id === id);
14
14
  if (index !== -1) state.value.data.splice(index, 1);
15
+ if (timeoutIds.has(id)) {
16
+ clearTimeout(timeoutIds.get(id));
17
+ timeoutIds.delete(id);
18
+ }
15
19
  };
16
20
  const dismissibleNotification = {
17
21
  ...notification,
@@ -21,12 +25,25 @@ export const useNotification = () => {
21
25
  state.value.data.push(dismissibleNotification);
22
26
  if (state.value.data.length > maxVisibleNotifications) state.value.data.shift();
23
27
  if (!notification.persist && notification.type !== "negative") {
24
- setTimeout(dismiss, notification.dismissTimeout || dismissTimeout);
28
+ const timeoutId = setTimeout(dismiss, notification.dismissTimeout || defaultDismissTimeout);
29
+ timeoutIds.set(id, timeoutId);
25
30
  }
26
31
  };
32
+ const clearTimeouts = () => {
33
+ for (const timeoutId of timeoutIds.values()) {
34
+ clearTimeout(timeoutId);
35
+ }
36
+ timeoutIds.clear();
37
+ };
27
38
  const clear = () => {
39
+ clearTimeouts();
28
40
  state.value.data = [];
29
41
  };
42
+ if (getCurrentInstance()) {
43
+ onUnmounted(() => {
44
+ clearTimeouts();
45
+ });
46
+ }
30
47
  return {
31
48
  send,
32
49
  clear,
@@ -8,15 +8,20 @@ export const useRegisterCookie = () => {
8
8
  );
9
9
  return;
10
10
  }
11
- const runtimeCookies = useRuntimeConfig().public.cookieGroups;
12
- if (runtimeCookies?.groups) {
13
- for (const cookieGroup of runtimeCookies.groups) {
14
- if (cookieGroup.name === group) {
15
- if (!cookieGroup.cookies) cookieGroup.cookies = [];
16
- if (cookieGroup.cookies.some((runtimeCookie) => runtimeCookie.name === newCookie.name)) return;
17
- cookieGroup.cookies.push(newCookie);
18
- return;
19
- }
11
+ const runtimeConfig = useRuntimeConfig().public;
12
+ const runtimeCookies = runtimeConfig.cookieGroups;
13
+ if (!runtimeCookies?.groups) {
14
+ return;
15
+ }
16
+ const groupsMap = new Map(runtimeCookies.groups.map((_group) => [_group.name, _group]));
17
+ const targetGroup = groupsMap.get(group);
18
+ if (targetGroup) {
19
+ if (!targetGroup.cookies) {
20
+ targetGroup.cookies = [];
21
+ }
22
+ const cookieExists = targetGroup.cookies.find((cookie) => cookie.name === newCookie.name);
23
+ if (!cookieExists) {
24
+ targetGroup.cookies.push(newCookie);
20
25
  }
21
26
  }
22
27
  };
@@ -32,4 +32,4 @@ export interface UseNotification {
32
32
  send: SendNotification;
33
33
  clear: ClearNotification;
34
34
  }
35
- export type UseNotificationReturn = () => UseNotification;
35
+ export type UseNotificationReturn = (defaultDismissTimeout?: number) => UseNotification;
@@ -2,18 +2,11 @@ const convertToDays = (daysInString) => {
2
2
  return Number.parseInt(daysInString.split(" ")[0]);
3
3
  };
4
4
  const getMinimumLifeSpan = (cookieJsonFromConfig) => {
5
- let minimum = 999999;
6
- cookieJsonFromConfig.forEach((group) => {
7
- const accepted = group.cookies.filter((cookie) => {
8
- return cookie.accepted;
9
- });
10
- accepted.forEach((cookie) => {
11
- if (cookie.Lifespan && minimum > convertToDays(cookie.Lifespan)) {
12
- minimum = convertToDays(cookie.Lifespan);
13
- }
14
- });
15
- });
16
- return 60 * 60 * 24 * minimum;
5
+ const minimum = cookieJsonFromConfig.flatMap((group) => group.cookies).filter((cookie) => cookie.accepted && cookie.Lifespan).reduce((min, cookie) => {
6
+ const lifespanDays = convertToDays(cookie.Lifespan);
7
+ return Math.min(lifespanDays, min);
8
+ }, 999999);
9
+ return minimum * 24 * 60 * 60;
17
10
  };
18
11
  export const cookieBarHelper = () => {
19
12
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plentymarkets/shop-core",
3
- "version": "1.13.6",
3
+ "version": "1.13.8",
4
4
  "description": "Core module for PlentyONE Shop",
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,8 +49,8 @@
49
49
  "@vue-storefront/sdk": "^3.4.1",
50
50
  "cookie": "^1.0.2",
51
51
  "js-sha256": "^0.11.0",
52
- "resolve": "^1.22.10",
53
- "ofetch": "^1.5.1"
52
+ "ofetch": "^1.5.1",
53
+ "resolve": "^1.22.10"
54
54
  },
55
55
  "overrides": {
56
56
  "prettier": "^3.6.2"
@@ -70,6 +70,7 @@
70
70
  "changelogen": "^0.5.7",
71
71
  "eslint": "^9.24.0",
72
72
  "eslint-config-prettier": "^9.1.0",
73
+ "eslint-plugin-ceviz": "^0.0.4",
73
74
  "eslint-plugin-vuejs-accessibility": "^2.4.1",
74
75
  "happy-dom": "^20.0.2",
75
76
  "nuxi": "3.17.2",