@plentymarkets/shop-core 1.3.1 → 1.3.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/dist/module.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- export { Cookie, CookieGroup, CookieGroupFromNuxtConfig } from '../dist/runtime/types/index.js';
2
+ export { Cookie, CookieGroup, CookieGroupFromNuxtConfig, Events, JsonCookie, Notification, PaymentButtonComponent, PaymentButtonComponentProps } from '../dist/runtime/types/index.js';
3
3
 
4
4
  interface ModuleOptions {
5
5
  apiUrl: string;
package/dist/module.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- export { Cookie, CookieGroup, CookieGroupFromNuxtConfig } from '../dist/runtime/types/index.js';
2
+ export { Cookie, CookieGroup, CookieGroupFromNuxtConfig, Events, JsonCookie, Notification, PaymentButtonComponent, PaymentButtonComponentProps } from '../dist/runtime/types/index.js';
3
3
 
4
4
  interface ModuleOptions {
5
5
  apiUrl: string;
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shop-core",
3
3
  "configKey": "shopCore",
4
- "version": "1.3.1",
4
+ "version": "1.3.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -15,6 +15,16 @@ const module = defineNuxtModule({
15
15
  as: "useSdk",
16
16
  from: resolver.resolve("./runtime/composables/useSdk")
17
17
  });
18
+ addImports({
19
+ name: "useNotification",
20
+ as: "useNotification",
21
+ from: resolver.resolve("./runtime/composables/useNotification")
22
+ });
23
+ addImports({
24
+ name: "useHandleError",
25
+ as: "useHandleError",
26
+ from: resolver.resolve("./runtime/composables/useHandleError")
27
+ });
18
28
  addImports({
19
29
  name: "usePlentyEvent",
20
30
  as: "usePlentyEvent",
@@ -35,6 +45,11 @@ const module = defineNuxtModule({
35
45
  as: "useRegisterCookie",
36
46
  from: resolver.resolve("./runtime/composables/useRegisterCookie")
37
47
  });
48
+ addImports({
49
+ name: "useDynamicPaymentButtons",
50
+ as: "useDynamicPaymentButtons",
51
+ from: resolver.resolve("./runtime/composables/useDynamicPaymentButtons")
52
+ });
38
53
  }
39
54
  });
40
55
 
@@ -1,5 +1,5 @@
1
1
  import { useRuntimeConfig } from "nuxt/app";
2
- import { describe, it, expect } from "vitest";
2
+ import { describe, it, expect, vi, beforeEach } from "vitest";
3
3
  import { mockNuxtImport } from "@nuxt/test-utils/runtime";
4
4
  import { useCookieBar } from "../useCookieBar.js";
5
5
  import { useCookieConsent } from "../useCookieConsent.js";
@@ -88,6 +88,10 @@ describe("useCookieBar", () => {
88
88
  document.cookie = "testCookie=testValue";
89
89
  const cookie = {
90
90
  name: "testCookie",
91
+ Lifespan: "Session",
92
+ Provider: "testProvider",
93
+ Status: "testStatus",
94
+ PrivacyPolicy: "https://example.com/privacy",
91
95
  cookieNames: ["testCookie"]
92
96
  };
93
97
  const { removeCookies } = useCookieBar();
@@ -1,5 +1,5 @@
1
1
  import { useRuntimeConfig } from "nuxt/app";
2
- import { describe, it, vi } from "vitest";
2
+ import { describe, it, vi, expect } from "vitest";
3
3
  import { useRegisterCookie } from "../useRegisterCookie.js";
4
4
  vi.mock("nuxt/app", () => ({
5
5
  useRuntimeConfig: vi.fn()
@@ -103,7 +103,8 @@ describe("useRegisterCookie", () => {
103
103
  cookieGroups: {
104
104
  groups: [
105
105
  {
106
- name: "marketing"
106
+ name: "marketing",
107
+ cookies: []
107
108
  }
108
109
  ]
109
110
  }
@@ -1,3 +1,4 @@
1
+ import type { Ref } from 'vue';
1
2
  import type { Cookie, CookieGroupFromNuxtConfig } from '../types/index.js';
2
3
  /**
3
4
  * @description Composable for managing cookie consent bar.
@@ -15,8 +16,8 @@ export declare const useCookieBar: () => {
15
16
  setAllCookiesState: (accepted: boolean) => void;
16
17
  removeCookies: (cookie: Cookie) => void;
17
18
  accept: (name: string) => void;
18
- data: import("vue").Ref<CookieGroupFromNuxtConfig, CookieGroupFromNuxtConfig>;
19
- visible: import("vue").Ref<boolean, boolean>;
20
- loading: import("vue").Ref<boolean, boolean>;
19
+ data: Ref<CookieGroupFromNuxtConfig, CookieGroupFromNuxtConfig>;
20
+ visible: Ref<boolean, boolean>;
21
+ loading: Ref<boolean, boolean>;
21
22
  };
22
23
  export declare const fetchScripts: (scripts: string[]) => void;
@@ -0,0 +1,5 @@
1
+ import type { PaymentButtonComponent } from '../types/index.js';
2
+ export declare const useDynamicPaymentButtons: () => {
3
+ components: import("vue").Ref<PaymentButtonComponent[], PaymentButtonComponent[]>;
4
+ addComponent: (component: PaymentButtonComponent) => void;
5
+ };
@@ -0,0 +1,17 @@
1
+ import { useState } from "nuxt/app";
2
+ import { toRefs } from "vue";
3
+ export const useDynamicPaymentButtons = () => {
4
+ const state = useState("useDynamicPaymentButtons", () => ({
5
+ components: []
6
+ }));
7
+ const addComponent = (component) => {
8
+ if (state.value.components.some((stateComponent) => stateComponent.componentName === component.componentName)) {
9
+ return;
10
+ }
11
+ state.value.components.push(component);
12
+ };
13
+ return {
14
+ addComponent,
15
+ ...toRefs(state.value)
16
+ };
17
+ };
@@ -0,0 +1,13 @@
1
+ import type { UseHandleError } from '../types/index.js';
2
+ /**
3
+ * @description Composable for handling errors.
4
+ * @param error
5
+ * @example
6
+ * ``` ts
7
+ * const { data, error } = useHandleError({
8
+ * statusCode: ''
9
+ * message: ''
10
+ * });
11
+ * ```
12
+ */
13
+ export declare const useHandleError: UseHandleError;
@@ -0,0 +1,27 @@
1
+ import { useNuxtApp } from "nuxt/app";
2
+ import { ApiError } from "@plentymarkets/shop-api";
3
+ import { useNotification } from "../composables/useNotification.js";
4
+ export const useHandleError = (error) => {
5
+ if (error && import.meta.client) {
6
+ const $i18n = useNuxtApp().$i18n;
7
+ const { send } = useNotification();
8
+ const type = "negative";
9
+ const persist = true;
10
+ if (error instanceof ApiError) {
11
+ const translationKey = `storefrontError.${error.key}`;
12
+ const message = error.key && $i18n.te(translationKey) ? $i18n.t(translationKey) : error.message + " _ " + translationKey;
13
+ send({
14
+ type,
15
+ message,
16
+ persist
17
+ });
18
+ } else {
19
+ const message = $i18n.t("storefrontError.unknownError");
20
+ send({
21
+ type,
22
+ message,
23
+ persist
24
+ });
25
+ }
26
+ }
27
+ };
@@ -0,0 +1,10 @@
1
+ import type { UseNotificationReturn } from '../types/index.js';
2
+ /**
3
+ * @description Composable to display ui notifications
4
+ * @return UseNotificationReturn
5
+ * @example
6
+ * ``` ts
7
+ * const { data, send } = useNotification();
8
+ * ```
9
+ */
10
+ export declare const useNotification: UseNotificationReturn;
@@ -0,0 +1,34 @@
1
+ import { useState } from "nuxt/app";
2
+ import { toRefs } from "vue";
3
+ const maxVisibleNotifications = 5;
4
+ const dismissTimeout = 5e3;
5
+ export const useNotification = () => {
6
+ const state = useState(`useNotification`, () => ({
7
+ data: []
8
+ }));
9
+ const send = (notification) => {
10
+ const id = Symbol();
11
+ const dismiss = () => {
12
+ const index = state.value.data.findIndex((notification2) => notification2.id === id);
13
+ if (index !== -1) state.value.data.splice(index, 1);
14
+ };
15
+ const dismissibleNotification = {
16
+ ...notification,
17
+ id,
18
+ dismiss
19
+ };
20
+ state.value.data.push(dismissibleNotification);
21
+ if (state.value.data.length > maxVisibleNotifications) state.value.data.shift();
22
+ if (!notification.persist && notification.type !== "negative") {
23
+ setTimeout(dismiss, notification.dismissTimeout || dismissTimeout);
24
+ }
25
+ };
26
+ const clear = () => {
27
+ state.value.data = [];
28
+ };
29
+ return {
30
+ send,
31
+ clear,
32
+ ...toRefs(state.value)
33
+ };
34
+ };
@@ -27,4 +27,5 @@ export type Events = {
27
27
  'backend:CheckoutChanged': CheckoutChanged;
28
28
  'backend:AfterAccountAuthentication': AfterAccountAuthentication;
29
29
  'backend:FrontendUpdateCustomerSettings': FrontendUpdateCustomerSettings;
30
+ 'module:clearCart': null;
30
31
  };
@@ -1,2 +1,4 @@
1
1
  export * from './cookies.js';
2
2
  export * from './events.js';
3
+ export * from './render.js';
4
+ export * from './notification.js';
@@ -1,2 +1,4 @@
1
1
  export * from "./cookies.js";
2
2
  export * from "./events.js";
3
+ export * from "./render.js";
4
+ export * from "./notification.js";
@@ -0,0 +1,35 @@
1
+ import type { ApiError } from '@plentymarkets/shop-api';
2
+ import type { NuxtError } from 'nuxt/app';
3
+ import type { Ref } from 'vue';
4
+ export type ErrorParams = {
5
+ /** The error message. */
6
+ message: string;
7
+ /** The HTTP status code associated with this error. */
8
+ statusCode?: number;
9
+ /** An optional cause for the error, providing more context or the underlying error that led to this error. */
10
+ cause?: unknown;
11
+ };
12
+ export type UseHandleError = (error: ApiError | NuxtError<unknown> | null) => void;
13
+ export interface Notification {
14
+ message: string | string[];
15
+ action?: {
16
+ text: string;
17
+ onClick: (...arguments_: Array<unknown>) => void;
18
+ };
19
+ type: 'neutral' | 'positive' | 'secondary' | 'warning' | 'negative';
20
+ persist?: boolean;
21
+ id?: symbol;
22
+ dismiss?: () => void;
23
+ dismissTimeout?: number;
24
+ }
25
+ export type SendNotification = (notification: Notification) => void;
26
+ export type ClearNotification = () => void;
27
+ export interface UseNotificationState {
28
+ data: Notification[];
29
+ }
30
+ export interface UseNotification {
31
+ data: Readonly<Ref<UseNotificationState['data']>>;
32
+ send: SendNotification;
33
+ clear: ClearNotification;
34
+ }
35
+ export type UseNotificationReturn = () => UseNotification;
File without changes
@@ -0,0 +1,10 @@
1
+ export type PaymentButtonComponent = {
2
+ componentName: string;
3
+ key?: string;
4
+ paymentKey?: string;
5
+ excludeKeys?: string[];
6
+ excludePaymentKeys?: string[];
7
+ };
8
+ export type PaymentButtonComponentProps = {
9
+ disabled: boolean;
10
+ };
File without changes
package/dist/types.d.mts CHANGED
@@ -1 +1 @@
1
- export { type Cookie, type CookieGroup, type CookieGroupFromNuxtConfig } from './module.js'
1
+ export { type Cookie, type CookieGroup, type CookieGroupFromNuxtConfig, type Events, type JsonCookie, type Notification, type PaymentButtonComponent, type PaymentButtonComponentProps } from './module.js'
package/dist/types.d.ts CHANGED
@@ -1 +1 @@
1
- export { type Cookie, type CookieGroup, type CookieGroupFromNuxtConfig } from './module'
1
+ export { type Cookie, type CookieGroup, type CookieGroupFromNuxtConfig, type Events, type JsonCookie, type Notification, type PaymentButtonComponent, type PaymentButtonComponentProps } from './module'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plentymarkets/shop-core",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Core module for PlentyONE Shop",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,6 +26,7 @@
26
26
  "dist"
27
27
  ],
28
28
  "scripts": {
29
+ "go": "bun dev:prepare && bun prepack",
29
30
  "prepack": "nuxt-module-build build",
30
31
  "dev": "nuxi dev playground",
31
32
  "dev:build": "nuxi build playground",
@@ -1,44 +0,0 @@
1
- import { describe, expect, it, beforeEach, vi } from "vitest";
2
- import { usePlentyEvent } from "../usePlentyEvent.js";
3
- describe("usePlentyEvent", () => {
4
- beforeEach(() => {
5
- usePlentyEvent().all.clear();
6
- });
7
- it("should register event listener", () => {
8
- const { on, all } = usePlentyEvent();
9
- on("userLogin", () => {
10
- });
11
- expect(all.get("userLogin")).toHaveLength(1);
12
- });
13
- it("should register multiple event listeners", () => {
14
- const { on, all } = usePlentyEvent();
15
- on("userLogin", () => {
16
- });
17
- on("userLogin", () => {
18
- });
19
- expect(all.get("userLogin")).toHaveLength(2);
20
- });
21
- it("should emit and listen to event", () => {
22
- const { on, emit } = usePlentyEvent();
23
- const mock = vi.fn();
24
- on("userLogin", mock);
25
- emit("userLogin", { id: 1, firstName: "John Doe" });
26
- expect(mock).toHaveBeenCalled();
27
- });
28
- it("should clear all event listeners", () => {
29
- const { on, all } = usePlentyEvent();
30
- on("userLogin", () => {
31
- });
32
- on("userLogout", () => {
33
- });
34
- all.clear();
35
- expect(all.size).toBe(0);
36
- });
37
- it("should turn off event listener", () => {
38
- const { on, off, all } = usePlentyEvent();
39
- const mock = vi.fn();
40
- on("userLogin", mock);
41
- off("userLogin", mock);
42
- expect(all.get("userLogin")).toHaveLength(0);
43
- });
44
- });