@wix/headless-stores 0.0.5 → 0.0.6

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.
@@ -1,10 +1,18 @@
1
- interface PayNowProps {
2
- children: (props: {
3
- isLoading: boolean;
4
- error: string | null;
5
- productName: string;
6
- redirectToCheckout: () => Promise<void>;
7
- }) => React.ReactNode;
1
+ export type PayNowRedirectToCheckout = () => void;
2
+ /**
3
+ * Props passed to the render function of the PayNow component
4
+ */
5
+ export interface PayNowRenderProps {
6
+ /** Whether the buy now operation is currently loading */
7
+ isLoading: boolean;
8
+ /** Function to redirect the user to the checkout page */
9
+ redirectToCheckout: PayNowRedirectToCheckout;
10
+ /** The error message if the buy now operation fails */
11
+ error: string | null;
12
+ }
13
+ export type PayNowChildren = (props: PayNowRenderProps) => React.ReactNode;
14
+ export interface PayNowProps {
15
+ /** Render function that receives buy now state and actions */
16
+ children: PayNowChildren;
8
17
  }
9
18
  export declare function PayNow(props: PayNowProps): import("react").ReactNode;
10
- export {};
@@ -1,11 +1,12 @@
1
1
  import { useService } from "@wix/services-manager-react";
2
2
  import { PayNowServiceDefinition } from "../services/pay-now-service";
3
+ ;
4
+ ;
3
5
  export function PayNow(props) {
4
- const { redirectToCheckout, loadingSignal, productName, errorSignal, } = useService(PayNowServiceDefinition);
6
+ const { redirectToCheckout, loadingSignal, errorSignal, } = useService(PayNowServiceDefinition);
5
7
  return props.children({
6
8
  isLoading: loadingSignal.get(),
7
9
  error: errorSignal.get(),
8
- productName: productName,
9
10
  redirectToCheckout,
10
11
  });
11
12
  }
@@ -1 +1,2 @@
1
1
  export * from "./BuyNow";
2
+ export * from "./PayNow";
@@ -1 +1,2 @@
1
1
  export * from "./BuyNow";
2
+ export * from "./PayNow";
@@ -30,10 +30,6 @@ export declare const BuyNowServiceImplementation: import("@wix/services-definiti
30
30
  productName: string;
31
31
  price: string;
32
32
  currency: string;
33
- customCheckoutAction?: () => Promise<{
34
- data: string;
35
- error: unknown;
36
- }>;
37
33
  }, import("@wix/services-definitions").ThreadMode.MAIN>;
38
34
  export declare const loadBuyNowServiceInitialData: (productSlug: string, variantId?: string) => Promise<{
39
35
  [BuyNowServiceDefinition]: {
@@ -46,7 +42,7 @@ export declare const loadBuyNowServiceInitialData: (productSlug: string, variant
46
42
  }>;
47
43
  export declare const buyNowServiceBinding: <T extends {
48
44
  [key: string]: Awaited<ReturnType<typeof loadBuyNowServiceInitialData>>[typeof BuyNowServiceDefinition];
49
- }>(servicesConfigs: T, additionalConfig: Partial<ServiceFactoryConfig<typeof BuyNowServiceImplementation>>) => readonly [string & {
45
+ }>(servicesConfigs: T, additionalConfig?: Partial<ServiceFactoryConfig<typeof BuyNowServiceImplementation>>) => readonly [string & {
50
46
  __api: {
51
47
  redirectToCheckout: () => Promise<void>;
52
48
  loadingSignal: Signal<boolean>;
@@ -76,18 +72,10 @@ export declare const buyNowServiceBinding: <T extends {
76
72
  productName: string;
77
73
  price: string;
78
74
  currency: string;
79
- customCheckoutAction?: () => Promise<{
80
- data: string;
81
- error: unknown;
82
- }>;
83
75
  }, import("@wix/services-definitions").ThreadMode.MAIN>, {
84
76
  productId: string;
85
77
  variantId?: string;
86
78
  productName: string;
87
79
  price: string;
88
80
  currency: string;
89
- customCheckoutAction?: () => Promise<{
90
- data: string;
91
- error: unknown;
92
- }>;
93
81
  }];
@@ -11,16 +11,6 @@ export const BuyNowServiceImplementation = implementService.withConfig()(BuyNowS
11
11
  redirectToCheckout: async () => {
12
12
  loadingSignal.set(true);
13
13
  try {
14
- if (config.customCheckoutAction) {
15
- const result = await config.customCheckoutAction();
16
- if (result && result.data) {
17
- window.location.href = result.data;
18
- }
19
- else {
20
- throw new Error("Failed to create checkout" + result?.error);
21
- }
22
- return;
23
- }
24
14
  const checkoutUrl = await getCheckoutUrlForProduct(config.productId, config.variantId);
25
15
  window.location.href = checkoutUrl;
26
16
  }
@@ -59,7 +49,7 @@ export const loadBuyNowServiceInitialData = async (productSlug, variantId) => {
59
49
  },
60
50
  };
61
51
  };
62
- export const buyNowServiceBinding = (servicesConfigs, additionalConfig) => {
52
+ export const buyNowServiceBinding = (servicesConfigs, additionalConfig = {}) => {
63
53
  return [
64
54
  BuyNowServiceDefinition,
65
55
  BuyNowServiceImplementation,
@@ -1 +1,2 @@
1
1
  export { buyNowServiceBinding, loadBuyNowServiceInitialData, } from "./buy-now-service";
2
+ export { payNowServiceBinding, loadPayNowServiceInitialData, } from "./pay-now-service";
@@ -1 +1,2 @@
1
1
  export { buyNowServiceBinding, loadBuyNowServiceInitialData, } from "./buy-now-service";
2
+ export { payNowServiceBinding, loadPayNowServiceInitialData, } from "./pay-now-service";
@@ -25,27 +25,17 @@ export declare const PayNowServiceImplementation: import("@wix/services-definiti
25
25
  loadingSignal: Signal<boolean>;
26
26
  errorSignal: Signal<string | null>;
27
27
  }, {
28
- productName: string;
29
- price: string;
30
- payNowServiceActions: {
31
- customLineItemCheckout: (input: {
32
- productName: string;
33
- price: string;
34
- }) => Promise<{
35
- data: string;
36
- error: unknown;
37
- }>;
38
- };
28
+ customCheckoutAction?: () => Promise<{
29
+ data: string | undefined;
30
+ error: unknown;
31
+ }>;
39
32
  }, import("@wix/services-definitions").ThreadMode.MAIN>;
40
- export declare const loadPayNowServiceInitialData: (productName: string, price: string) => Promise<{
41
- [PayNowServiceDefinition]: {
42
- productName: string;
43
- price: string;
44
- };
33
+ export declare const loadPayNowServiceInitialData: () => Promise<{
34
+ [PayNowServiceDefinition]: {};
45
35
  }>;
46
36
  export declare const payNowServiceBinding: <T extends {
47
37
  [key: string]: Awaited<ReturnType<typeof loadPayNowServiceInitialData>>[typeof PayNowServiceDefinition];
48
- }>(servicesConfigs: T) => readonly [string & {
38
+ }>(servicesConfigs: T, additionalConfig?: Partial<ServiceFactoryConfig<typeof PayNowServiceImplementation>>) => readonly [string & {
49
39
  __api: {
50
40
  redirectToCheckout: () => Promise<void>;
51
41
  loadingSignal: Signal<boolean>;
@@ -70,27 +60,13 @@ export declare const payNowServiceBinding: <T extends {
70
60
  loadingSignal: Signal<boolean>;
71
61
  errorSignal: Signal<string | null>;
72
62
  }, {
73
- productName: string;
74
- price: string;
75
- payNowServiceActions: {
76
- customLineItemCheckout: (input: {
77
- productName: string;
78
- price: string;
79
- }) => Promise<{
80
- data: string;
81
- error: unknown;
82
- }>;
83
- };
63
+ customCheckoutAction?: () => Promise<{
64
+ data: string | undefined;
65
+ error: unknown;
66
+ }>;
84
67
  }, import("@wix/services-definitions").ThreadMode.MAIN>, {
85
- productName: string;
86
- price: string;
87
- payNowServiceActions: {
88
- customLineItemCheckout: (input: {
89
- productName: string;
90
- price: string;
91
- }) => Promise<{
92
- data: string;
93
- error: unknown;
94
- }>;
95
- };
68
+ customCheckoutAction?: () => Promise<{
69
+ data: string | undefined;
70
+ error: unknown;
71
+ }>;
96
72
  }];
@@ -9,33 +9,37 @@ export const PayNowServiceImplementation = implementService.withConfig()(PayNowS
9
9
  redirectToCheckout: async () => {
10
10
  loadingSignal.set(true);
11
11
  try {
12
- const result = await config.payNowServiceActions.customLineItemCheckout({ productName: config.productName, price: config.price });
13
- console.log('from server action', result);
14
- window.location.href = result.data;
12
+ if (config.customCheckoutAction) {
13
+ const result = await config.customCheckoutAction();
14
+ if (result && result.data) {
15
+ window.location.href = result.data;
16
+ }
17
+ else {
18
+ throw new Error("Failed to create checkout" + result?.error);
19
+ }
20
+ }
15
21
  }
16
22
  catch (error) {
17
- errorSignal.set(error);
23
+ errorSignal.set(error.toString());
18
24
  loadingSignal.set(false);
19
25
  }
20
26
  },
21
27
  loadingSignal,
22
28
  errorSignal,
23
- productName: config.productName,
24
- price: config.price,
25
29
  };
26
30
  });
27
- export const loadPayNowServiceInitialData = async (productName, price) => {
31
+ export const loadPayNowServiceInitialData = async () => {
28
32
  return {
29
- [PayNowServiceDefinition]: {
30
- productName,
31
- price,
32
- },
33
+ [PayNowServiceDefinition]: {},
33
34
  };
34
35
  };
35
- export const payNowServiceBinding = (servicesConfigs) => {
36
+ export const payNowServiceBinding = (servicesConfigs, additionalConfig = {}) => {
36
37
  return [
37
38
  PayNowServiceDefinition,
38
39
  PayNowServiceImplementation,
39
- servicesConfigs[PayNowServiceDefinition],
40
+ {
41
+ ...servicesConfigs[PayNowServiceDefinition],
42
+ ...additionalConfig,
43
+ },
40
44
  ];
41
45
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-stores",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "scripts": {
5
5
  "build": "tsc",
6
6
  "test": "vitest"