@wix/headless-stores 0.0.4 → 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.
- package/dist/astro/actions/custom-checkout.d.ts +50 -0
- package/dist/astro/actions/custom-checkout.js +52 -0
- package/dist/astro/actions/index.d.ts +1 -0
- package/dist/astro/actions/index.js +1 -0
- package/dist/react/PayNow.d.ts +18 -0
- package/dist/react/PayNow.js +12 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +1 -0
- package/dist/server-actions/custom-checkout-action.d.ts +45 -0
- package/dist/server-actions/custom-checkout-action.js +55 -0
- package/dist/server-actions/index.d.ts +1 -0
- package/dist/server-actions/index.js +1 -0
- package/dist/services/buy-now-service.d.ts +1 -1
- package/dist/services/buy-now-service.js +6 -3
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/pay-now-service.d.ts +72 -0
- package/dist/services/pay-now-service.js +45 -0
- package/package.json +5 -2
- package/dist/react/CurrentCartServiceProvider.d.ts +0 -5
- package/dist/react/CurrentCartServiceProvider.js +0 -12
- package/dist/react/VariantSelectorServiceProvider.d.ts +0 -7
- package/dist/react/VariantSelectorServiceProvider.js +0 -22
- package/dist/services/CurrentCartService.d.ts +0 -18
- package/dist/services/CurrentCartService.js +0 -9
- package/dist/services/VariantSelectorServices.d.ts +0 -8
- package/dist/services/VariantSelectorServices.js +0 -20
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type CustomLineItemCheckoutOptions } from '@wix/headless-stores/server-actions';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an Astro action factory for custom checkout functionality with line items.
|
|
4
|
+
*
|
|
5
|
+
* This factory function generates an Astro action that can be used to create custom
|
|
6
|
+
* checkout URLs with specific line items. It wraps the Wix headless stores server
|
|
7
|
+
* action functionality in an Astro-compatible action format.
|
|
8
|
+
*
|
|
9
|
+
* @param {CustomLineItemCheckoutOptions} factoryOpts - Configuration options for the custom checkout
|
|
10
|
+
* @param {string} factoryOpts.productName - The name of the product for the custom line item
|
|
11
|
+
* @param {string} [factoryOpts.priceDescription] - A description for the price, which will be displayed to the customer
|
|
12
|
+
* @param {Array<{content: string, title: string}>} [factoryOpts.policies] - An array of policies related to this custom item
|
|
13
|
+
* @param {string} [factoryOpts.postFlowUrl] - The URL to redirect the user to after the checkout is successfully completed
|
|
14
|
+
* @param {number} [factoryOpts.quantity=1] - The quantity of the product
|
|
15
|
+
* @param {string} factoryOpts.price - The price of the product
|
|
16
|
+
*
|
|
17
|
+
* @returns {ReturnType<typeof defineAction>} An Astro action that when invoked returns checkout URL
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Define the action with your configuration
|
|
22
|
+
* const customCheckoutAction = customCheckoutActionFactory({
|
|
23
|
+
* productName: "Premium Subscription",
|
|
24
|
+
* price: "29.99",
|
|
25
|
+
* priceDescription: "per month",
|
|
26
|
+
* quantity: 1,
|
|
27
|
+
* postFlowUrl: "https://yoursite.com/thank-you",
|
|
28
|
+
* policies: [
|
|
29
|
+
* {
|
|
30
|
+
* title: "Refund Policy",
|
|
31
|
+
* content: "30-day money back guarantee"
|
|
32
|
+
* }
|
|
33
|
+
* ]
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* export const server = {
|
|
37
|
+
* checkout: customCheckoutAction
|
|
38
|
+
* };
|
|
39
|
+
*
|
|
40
|
+
* // Use in your Astro component or API route
|
|
41
|
+
* import { actions } from "astro:actions";
|
|
42
|
+
* const checkoutUrl = await actions.customCheckoutAction();
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @see {@link https://docs.astro.build/en/guides/actions/} Astro Actions Documentation
|
|
46
|
+
* @see {@link https://dev.wix.com/docs/sdk/headless/api-reference/stores/checkout} Wix Stores Checkout API
|
|
47
|
+
*/
|
|
48
|
+
export declare const customCheckoutActionFactory: (factoryOpts: CustomLineItemCheckoutOptions) => ((input?: any) => Promise<import("astro:actions").SafeResult<never, string>>) & {
|
|
49
|
+
orThrow: (input?: any) => Promise<string>;
|
|
50
|
+
} & string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/// <reference types="astro/client" />
|
|
2
|
+
import { defineAction } from 'astro:actions';
|
|
3
|
+
import { getCustomLineItemCheckoutURLFactory } from '@wix/headless-stores/server-actions';
|
|
4
|
+
/**
|
|
5
|
+
* Creates an Astro action factory for custom checkout functionality with line items.
|
|
6
|
+
*
|
|
7
|
+
* This factory function generates an Astro action that can be used to create custom
|
|
8
|
+
* checkout URLs with specific line items. It wraps the Wix headless stores server
|
|
9
|
+
* action functionality in an Astro-compatible action format.
|
|
10
|
+
*
|
|
11
|
+
* @param {CustomLineItemCheckoutOptions} factoryOpts - Configuration options for the custom checkout
|
|
12
|
+
* @param {string} factoryOpts.productName - The name of the product for the custom line item
|
|
13
|
+
* @param {string} [factoryOpts.priceDescription] - A description for the price, which will be displayed to the customer
|
|
14
|
+
* @param {Array<{content: string, title: string}>} [factoryOpts.policies] - An array of policies related to this custom item
|
|
15
|
+
* @param {string} [factoryOpts.postFlowUrl] - The URL to redirect the user to after the checkout is successfully completed
|
|
16
|
+
* @param {number} [factoryOpts.quantity=1] - The quantity of the product
|
|
17
|
+
* @param {string} factoryOpts.price - The price of the product
|
|
18
|
+
*
|
|
19
|
+
* @returns {ReturnType<typeof defineAction>} An Astro action that when invoked returns checkout URL
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Define the action with your configuration
|
|
24
|
+
* const customCheckoutAction = customCheckoutActionFactory({
|
|
25
|
+
* productName: "Premium Subscription",
|
|
26
|
+
* price: "29.99",
|
|
27
|
+
* priceDescription: "per month",
|
|
28
|
+
* quantity: 1,
|
|
29
|
+
* postFlowUrl: "https://yoursite.com/thank-you",
|
|
30
|
+
* policies: [
|
|
31
|
+
* {
|
|
32
|
+
* title: "Refund Policy",
|
|
33
|
+
* content: "30-day money back guarantee"
|
|
34
|
+
* }
|
|
35
|
+
* ]
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* export const server = {
|
|
39
|
+
* checkout: customCheckoutAction
|
|
40
|
+
* };
|
|
41
|
+
*
|
|
42
|
+
* // Use in your Astro component or API route
|
|
43
|
+
* import { actions } from "astro:actions";
|
|
44
|
+
* const checkoutUrl = await actions.customCheckoutAction();
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @see {@link https://docs.astro.build/en/guides/actions/} Astro Actions Documentation
|
|
48
|
+
* @see {@link https://dev.wix.com/docs/sdk/headless/api-reference/stores/checkout} Wix Stores Checkout API
|
|
49
|
+
*/
|
|
50
|
+
export const customCheckoutActionFactory = (factoryOpts) => defineAction({
|
|
51
|
+
handler: () => getCustomLineItemCheckoutURLFactory(factoryOpts)(),
|
|
52
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./custom-checkout";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./custom-checkout";
|
|
@@ -0,0 +1,18 @@
|
|
|
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;
|
|
17
|
+
}
|
|
18
|
+
export declare function PayNow(props: PayNowProps): import("react").ReactNode;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useService } from "@wix/services-manager-react";
|
|
2
|
+
import { PayNowServiceDefinition } from "../services/pay-now-service";
|
|
3
|
+
;
|
|
4
|
+
;
|
|
5
|
+
export function PayNow(props) {
|
|
6
|
+
const { redirectToCheckout, loadingSignal, errorSignal, } = useService(PayNowServiceDefinition);
|
|
7
|
+
return props.children({
|
|
8
|
+
isLoading: loadingSignal.get(),
|
|
9
|
+
error: errorSignal.get(),
|
|
10
|
+
redirectToCheckout,
|
|
11
|
+
});
|
|
12
|
+
}
|
package/dist/react/index.d.ts
CHANGED
package/dist/react/index.js
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for creating a checkout with a custom line item.
|
|
3
|
+
*/
|
|
4
|
+
export interface CustomLineItemCheckoutOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The name of the product for the custom line item.
|
|
7
|
+
* @example "My Custom Product"
|
|
8
|
+
*/
|
|
9
|
+
productName: string;
|
|
10
|
+
/**
|
|
11
|
+
* A description for the price, which will be displayed to the customer.
|
|
12
|
+
* @example "per month"
|
|
13
|
+
*/
|
|
14
|
+
priceDescription?: string;
|
|
15
|
+
/**
|
|
16
|
+
* An array of policies related to this custom item.
|
|
17
|
+
* Each policy should have a title and content.
|
|
18
|
+
*/
|
|
19
|
+
policies?: {
|
|
20
|
+
content: string;
|
|
21
|
+
title: string;
|
|
22
|
+
}[];
|
|
23
|
+
/**
|
|
24
|
+
* The URL to redirect the user to after the checkout is successfully completed.
|
|
25
|
+
*/
|
|
26
|
+
postFlowUrl?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The quantity of the product.
|
|
29
|
+
* @default 1
|
|
30
|
+
*/
|
|
31
|
+
quantity?: number;
|
|
32
|
+
/**
|
|
33
|
+
* The price of the product.
|
|
34
|
+
*/
|
|
35
|
+
price: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a factory function to generate checkout URLs for custom line items with a fixed price.
|
|
39
|
+
* This is useful when you have a single product or service with a known price,
|
|
40
|
+
* and you want to dynamically create checkout sessions for it.
|
|
41
|
+
*
|
|
42
|
+
* @param factoryOpts - The options for the factory, including the price.
|
|
43
|
+
* @returns A function that takes `CustomLineItemCheckoutOptions` and returns a checkout URL.
|
|
44
|
+
*/
|
|
45
|
+
export declare function getCustomLineItemCheckoutURLFactory(factoryOpts: CustomLineItemCheckoutOptions): () => Promise<string>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { checkout } from "@wix/ecom";
|
|
2
|
+
import { redirects } from "@wix/redirects";
|
|
3
|
+
import { auth } from "@wix/essentials";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a factory function to generate checkout URLs for custom line items with a fixed price.
|
|
6
|
+
* This is useful when you have a single product or service with a known price,
|
|
7
|
+
* and you want to dynamically create checkout sessions for it.
|
|
8
|
+
*
|
|
9
|
+
* @param factoryOpts - The options for the factory, including the price.
|
|
10
|
+
* @returns A function that takes `CustomLineItemCheckoutOptions` and returns a checkout URL.
|
|
11
|
+
*/
|
|
12
|
+
export function getCustomLineItemCheckoutURLFactory(factoryOpts) {
|
|
13
|
+
/**
|
|
14
|
+
* Generates a checkout URL for a custom line item.
|
|
15
|
+
* @param opts - The options for the custom line item checkout.
|
|
16
|
+
* @returns A promise that resolves to the full URL for the redirect session to the checkout.
|
|
17
|
+
* @throws Will throw an error if the checkout creation or redirect session fails.
|
|
18
|
+
*/
|
|
19
|
+
return async function getCustomLineItemCheckoutURL() {
|
|
20
|
+
try {
|
|
21
|
+
const checkoutResult = await auth.elevate(checkout.createCheckout)({
|
|
22
|
+
customLineItems: [
|
|
23
|
+
{
|
|
24
|
+
productName: {
|
|
25
|
+
original: factoryOpts.productName,
|
|
26
|
+
},
|
|
27
|
+
price: factoryOpts.price,
|
|
28
|
+
quantity: factoryOpts.quantity || 1,
|
|
29
|
+
itemType: {
|
|
30
|
+
preset: checkout.ItemTypeItemType.PHYSICAL,
|
|
31
|
+
},
|
|
32
|
+
priceDescription: {
|
|
33
|
+
original: factoryOpts.priceDescription
|
|
34
|
+
},
|
|
35
|
+
policies: factoryOpts.policies || [],
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
channelType: checkout.ChannelType.WEB,
|
|
39
|
+
});
|
|
40
|
+
if (!checkoutResult._id) {
|
|
41
|
+
throw new Error(`Failed to create checkout for custom line item ${factoryOpts.productName}`);
|
|
42
|
+
}
|
|
43
|
+
const { redirectSession } = await redirects.createRedirectSession({
|
|
44
|
+
ecomCheckout: { checkoutId: checkoutResult._id },
|
|
45
|
+
callbacks: {
|
|
46
|
+
...(factoryOpts.postFlowUrl ? { postFlowUrl: factoryOpts.postFlowUrl } : {})
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return redirectSession?.fullUrl;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./custom-checkout-action";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./custom-checkout-action";
|
|
@@ -42,7 +42,7 @@ export declare const loadBuyNowServiceInitialData: (productSlug: string, variant
|
|
|
42
42
|
}>;
|
|
43
43
|
export declare const buyNowServiceBinding: <T extends {
|
|
44
44
|
[key: string]: Awaited<ReturnType<typeof loadBuyNowServiceInitialData>>[typeof BuyNowServiceDefinition];
|
|
45
|
-
}>(servicesConfigs: T) => readonly [string & {
|
|
45
|
+
}>(servicesConfigs: T, additionalConfig?: Partial<ServiceFactoryConfig<typeof BuyNowServiceImplementation>>) => readonly [string & {
|
|
46
46
|
__api: {
|
|
47
47
|
redirectToCheckout: () => Promise<void>;
|
|
48
48
|
loadingSignal: Signal<boolean>;
|
|
@@ -15,7 +15,7 @@ export const BuyNowServiceImplementation = implementService.withConfig()(BuyNowS
|
|
|
15
15
|
window.location.href = checkoutUrl;
|
|
16
16
|
}
|
|
17
17
|
catch (error) {
|
|
18
|
-
errorSignal.set(error);
|
|
18
|
+
errorSignal.set(error.toString());
|
|
19
19
|
loadingSignal.set(false);
|
|
20
20
|
}
|
|
21
21
|
},
|
|
@@ -49,10 +49,13 @@ export const loadBuyNowServiceInitialData = async (productSlug, variantId) => {
|
|
|
49
49
|
},
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
|
-
export const buyNowServiceBinding = (servicesConfigs) => {
|
|
52
|
+
export const buyNowServiceBinding = (servicesConfigs, additionalConfig = {}) => {
|
|
53
53
|
return [
|
|
54
54
|
BuyNowServiceDefinition,
|
|
55
55
|
BuyNowServiceImplementation,
|
|
56
|
-
|
|
56
|
+
{
|
|
57
|
+
...servicesConfigs[BuyNowServiceDefinition],
|
|
58
|
+
...additionalConfig,
|
|
59
|
+
},
|
|
57
60
|
];
|
|
58
61
|
};
|
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ServiceFactoryConfig, Signal } from "@wix/services-definitions";
|
|
2
|
+
export declare const PayNowServiceDefinition: string & {
|
|
3
|
+
__api: {
|
|
4
|
+
redirectToCheckout: () => Promise<void>;
|
|
5
|
+
loadingSignal: Signal<boolean>;
|
|
6
|
+
errorSignal: Signal<string | null>;
|
|
7
|
+
};
|
|
8
|
+
__config: {};
|
|
9
|
+
isServiceDefinition?: boolean;
|
|
10
|
+
} & {
|
|
11
|
+
redirectToCheckout: () => Promise<void>;
|
|
12
|
+
loadingSignal: Signal<boolean>;
|
|
13
|
+
errorSignal: Signal<string | null>;
|
|
14
|
+
};
|
|
15
|
+
export declare const PayNowServiceImplementation: import("@wix/services-definitions").ServiceFactory<string & {
|
|
16
|
+
__api: {
|
|
17
|
+
redirectToCheckout: () => Promise<void>;
|
|
18
|
+
loadingSignal: Signal<boolean>;
|
|
19
|
+
errorSignal: Signal<string | null>;
|
|
20
|
+
};
|
|
21
|
+
__config: {};
|
|
22
|
+
isServiceDefinition?: boolean;
|
|
23
|
+
} & {
|
|
24
|
+
redirectToCheckout: () => Promise<void>;
|
|
25
|
+
loadingSignal: Signal<boolean>;
|
|
26
|
+
errorSignal: Signal<string | null>;
|
|
27
|
+
}, {
|
|
28
|
+
customCheckoutAction?: () => Promise<{
|
|
29
|
+
data: string | undefined;
|
|
30
|
+
error: unknown;
|
|
31
|
+
}>;
|
|
32
|
+
}, import("@wix/services-definitions").ThreadMode.MAIN>;
|
|
33
|
+
export declare const loadPayNowServiceInitialData: () => Promise<{
|
|
34
|
+
[PayNowServiceDefinition]: {};
|
|
35
|
+
}>;
|
|
36
|
+
export declare const payNowServiceBinding: <T extends {
|
|
37
|
+
[key: string]: Awaited<ReturnType<typeof loadPayNowServiceInitialData>>[typeof PayNowServiceDefinition];
|
|
38
|
+
}>(servicesConfigs: T, additionalConfig?: Partial<ServiceFactoryConfig<typeof PayNowServiceImplementation>>) => readonly [string & {
|
|
39
|
+
__api: {
|
|
40
|
+
redirectToCheckout: () => Promise<void>;
|
|
41
|
+
loadingSignal: Signal<boolean>;
|
|
42
|
+
errorSignal: Signal<string | null>;
|
|
43
|
+
};
|
|
44
|
+
__config: {};
|
|
45
|
+
isServiceDefinition?: boolean;
|
|
46
|
+
} & {
|
|
47
|
+
redirectToCheckout: () => Promise<void>;
|
|
48
|
+
loadingSignal: Signal<boolean>;
|
|
49
|
+
errorSignal: Signal<string | null>;
|
|
50
|
+
}, import("@wix/services-definitions").ServiceFactory<string & {
|
|
51
|
+
__api: {
|
|
52
|
+
redirectToCheckout: () => Promise<void>;
|
|
53
|
+
loadingSignal: Signal<boolean>;
|
|
54
|
+
errorSignal: Signal<string | null>;
|
|
55
|
+
};
|
|
56
|
+
__config: {};
|
|
57
|
+
isServiceDefinition?: boolean;
|
|
58
|
+
} & {
|
|
59
|
+
redirectToCheckout: () => Promise<void>;
|
|
60
|
+
loadingSignal: Signal<boolean>;
|
|
61
|
+
errorSignal: Signal<string | null>;
|
|
62
|
+
}, {
|
|
63
|
+
customCheckoutAction?: () => Promise<{
|
|
64
|
+
data: string | undefined;
|
|
65
|
+
error: unknown;
|
|
66
|
+
}>;
|
|
67
|
+
}, import("@wix/services-definitions").ThreadMode.MAIN>, {
|
|
68
|
+
customCheckoutAction?: () => Promise<{
|
|
69
|
+
data: string | undefined;
|
|
70
|
+
error: unknown;
|
|
71
|
+
}>;
|
|
72
|
+
}];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { defineService, implementService, } from "@wix/services-definitions";
|
|
2
|
+
import { SignalsServiceDefinition } from "@wix/services-definitions/core-services/signals";
|
|
3
|
+
export const PayNowServiceDefinition = defineService("PayNow");
|
|
4
|
+
export const PayNowServiceImplementation = implementService.withConfig()(PayNowServiceDefinition, ({ getService, config }) => {
|
|
5
|
+
const signalsService = getService(SignalsServiceDefinition);
|
|
6
|
+
const loadingSignal = signalsService.signal(false);
|
|
7
|
+
const errorSignal = signalsService.signal(null);
|
|
8
|
+
return {
|
|
9
|
+
redirectToCheckout: async () => {
|
|
10
|
+
loadingSignal.set(true);
|
|
11
|
+
try {
|
|
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
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
errorSignal.set(error.toString());
|
|
24
|
+
loadingSignal.set(false);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
loadingSignal,
|
|
28
|
+
errorSignal,
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
export const loadPayNowServiceInitialData = async () => {
|
|
32
|
+
return {
|
|
33
|
+
[PayNowServiceDefinition]: {},
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export const payNowServiceBinding = (servicesConfigs, additionalConfig = {}) => {
|
|
37
|
+
return [
|
|
38
|
+
PayNowServiceDefinition,
|
|
39
|
+
PayNowServiceImplementation,
|
|
40
|
+
{
|
|
41
|
+
...servicesConfigs[PayNowServiceDefinition],
|
|
42
|
+
...additionalConfig,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/headless-stores",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "tsc",
|
|
6
6
|
"test": "vitest"
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
],
|
|
11
11
|
"exports": {
|
|
12
12
|
"./react": "./dist/react/index.js",
|
|
13
|
-
"./services": "./dist/services/index.js"
|
|
13
|
+
"./services": "./dist/services/index.js",
|
|
14
|
+
"./server-actions": "./dist/server-actions/index.js",
|
|
15
|
+
"./astro/actions": "./dist/astro/actions/index.js"
|
|
14
16
|
},
|
|
15
17
|
"devDependencies": {
|
|
16
18
|
"@testing-library/dom": "^10.4.0",
|
|
@@ -24,6 +26,7 @@
|
|
|
24
26
|
},
|
|
25
27
|
"dependencies": {
|
|
26
28
|
"@wix/ecom": "^1.0.1169",
|
|
29
|
+
"@wix/essentials": "^0.1.22",
|
|
27
30
|
"@wix/redirects": "^1.0.79",
|
|
28
31
|
"@wix/services-definitions": "^0.1.2",
|
|
29
32
|
"@wix/services-manager-react": "^0.1.9"
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { CurrentCartService } from "../services/CurrentCartService";
|
|
4
|
-
export const CurrentCartServiceContext = React.createContext(null);
|
|
5
|
-
export function CurrentCartServiceProvider(props) {
|
|
6
|
-
const theService = CurrentCartService({
|
|
7
|
-
// @ts-expect-error
|
|
8
|
-
getService: () => { },
|
|
9
|
-
config: {},
|
|
10
|
-
});
|
|
11
|
-
return (_jsx(CurrentCartServiceContext.Provider, { value: theService, children: props.children }));
|
|
12
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { productsV3 } from "@wix/stores";
|
|
3
|
-
export declare const VariantSelectorContext: React.Context<unknown>;
|
|
4
|
-
export declare function VariantSelectorServiceProvider(props: {
|
|
5
|
-
product: productsV3.V3Product;
|
|
6
|
-
children: React.ReactNode;
|
|
7
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React, { useContext } from "react";
|
|
3
|
-
import { VariantSelectorService } from "../services/VariantSelectorServices";
|
|
4
|
-
import { CurrentCartServiceContext } from "./CurrentCartServiceProvider";
|
|
5
|
-
import { CurrentCartServiceDefinition } from "../services/CurrentCartService";
|
|
6
|
-
export const VariantSelectorContext = React.createContext(null);
|
|
7
|
-
export function VariantSelectorServiceProvider(props) {
|
|
8
|
-
const currentCartService = useContext(CurrentCartServiceContext);
|
|
9
|
-
const theService = VariantSelectorService({
|
|
10
|
-
// @ts-expect-error
|
|
11
|
-
getService: (id) => {
|
|
12
|
-
if (id === CurrentCartServiceDefinition) {
|
|
13
|
-
return currentCartService;
|
|
14
|
-
}
|
|
15
|
-
throw new Error(`Unknown service: ${id}`);
|
|
16
|
-
},
|
|
17
|
-
config: {
|
|
18
|
-
product: props.product,
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
return (_jsx(VariantSelectorContext.Provider, { value: theService, children: props.children }));
|
|
22
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare const CurrentCartServiceDefinition: string & {
|
|
2
|
-
__api: {
|
|
3
|
-
addItem: () => void;
|
|
4
|
-
};
|
|
5
|
-
__config: {};
|
|
6
|
-
isServiceDefinition?: boolean;
|
|
7
|
-
} & {
|
|
8
|
-
addItem: () => void;
|
|
9
|
-
};
|
|
10
|
-
export declare const CurrentCartService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
11
|
-
__api: {
|
|
12
|
-
addItem: () => void;
|
|
13
|
-
};
|
|
14
|
-
__config: {};
|
|
15
|
-
isServiceDefinition?: boolean;
|
|
16
|
-
} & {
|
|
17
|
-
addItem: () => void;
|
|
18
|
-
}, {}, import("@wix/services-definitions").ThreadMode.MAIN>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { defineService, implementService } from "@wix/services-definitions";
|
|
2
|
-
export const CurrentCartServiceDefinition = defineService("kaki2");
|
|
3
|
-
export const CurrentCartService = implementService.withConfig()(CurrentCartServiceDefinition, () => {
|
|
4
|
-
return {
|
|
5
|
-
addItem: () => {
|
|
6
|
-
alert("addItem");
|
|
7
|
-
},
|
|
8
|
-
};
|
|
9
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { productsV3 } from "@wix/stores";
|
|
2
|
-
export declare const VariantSelectorService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
3
|
-
__api: {};
|
|
4
|
-
__config: {};
|
|
5
|
-
isServiceDefinition?: boolean;
|
|
6
|
-
}, {
|
|
7
|
-
product: productsV3.V3Product;
|
|
8
|
-
}, import("@wix/services-definitions").ThreadMode.MAIN>;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { defineService, implementService, } from "@wix/services-definitions";
|
|
2
|
-
import { SignalsServiceDefinition } from "@wix/services-definitions/core-services/signals";
|
|
3
|
-
import { CurrentCartServiceDefinition } from "./CurrentCartService";
|
|
4
|
-
const VariantSelectorServiceDefinition = defineService("kaki");
|
|
5
|
-
export const VariantSelectorService = implementService.withConfig()(VariantSelectorServiceDefinition, ({ getService, config }) => {
|
|
6
|
-
const cartService = getService(CurrentCartServiceDefinition);
|
|
7
|
-
const signalsService = getService(SignalsServiceDefinition);
|
|
8
|
-
const selectedVariant = signalsService.signal((config.product.variantsInfo?.variants ?? []).length > 0
|
|
9
|
-
? config.product.variantsInfo.variants[0]._id
|
|
10
|
-
: null);
|
|
11
|
-
return {
|
|
12
|
-
selectedVariant,
|
|
13
|
-
setSelectedVariant: (variant) => {
|
|
14
|
-
selectedVariant.set(variant);
|
|
15
|
-
},
|
|
16
|
-
addToCart: async () => {
|
|
17
|
-
await cartService.addItem();
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
});
|