@nizza/core 0.5.0-beta.14 → 0.5.0-beta.16
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/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +2029 -1880
- package/dist/index.mjs.map +1 -1
- package/dist/lib/add-to-cart/hooks.d.ts +19 -0
- package/dist/lib/add-to-cart/index.d.ts +1 -0
- package/dist/lib/constants/eventBus.d.ts +3 -0
- package/dist/lib/constants/products.d.ts +2 -1
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/types/add-to-cart-hooks.d.ts +122 -0
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/nizza/main.d.ts +1 -1
- package/dist/locales/index.d.ts +1 -0
- package/dist/package.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AddToCartActionFactory, HooksInitConfig, HookState } from '../types';
|
|
2
|
+
export declare const addToCartMessages: {
|
|
3
|
+
errorAddingToCart: string;
|
|
4
|
+
errorOpeningVariationSelector: string;
|
|
5
|
+
errorOpeningNewTab: string;
|
|
6
|
+
successAddingToCart: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Executes the add to cart hooks.
|
|
10
|
+
* @async
|
|
11
|
+
* @param {HooksInitConfig} config - The initial configuration for the add to cart operation.
|
|
12
|
+
*/
|
|
13
|
+
export declare function runAddToCartHooks<ContextData extends Record<string, any>>(config: HooksInitConfig<ContextData>): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates an action factory based on the current state.
|
|
16
|
+
* @param {HookState} state - The current state of the add to cart operation.
|
|
17
|
+
* @returns {AddToCartActionFactory} The created action factory.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createActionFactory(state: HookState): AddToCartActionFactory;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hooks';
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
export declare const EventBusWildcards: {
|
|
11
11
|
readonly ALL: "*";
|
|
12
12
|
readonly CORE: "core:**";
|
|
13
|
+
readonly ADD_TO_CART_HOOKS: "core:addToCartHooks:**";
|
|
13
14
|
readonly LIVE_STREAMING_EVENT: "event:**";
|
|
14
15
|
readonly EVENT_CHAT: "event:chat:**";
|
|
15
16
|
readonly EVENT_PRODUCTS: "event:products:**";
|
|
@@ -31,4 +32,6 @@ export declare const EventBusWildcards: {
|
|
|
31
32
|
*/
|
|
32
33
|
export declare const EventNames: {
|
|
33
34
|
readonly EVENT_STATUS_CHANGED: "event:statusChanged";
|
|
35
|
+
/** AddToCartHook events */
|
|
36
|
+
readonly ATCH_ACTION_EXECUTED: "core:addToCartHooks:actionExecuted";
|
|
34
37
|
};
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { NizzaProduct } from './nizza';
|
|
2
|
+
export type HookName = 'transform' | 'validate' | 'end';
|
|
3
|
+
/**
|
|
4
|
+
* ============ Action types ============
|
|
5
|
+
*/
|
|
6
|
+
export declare enum AddToCartActionTypes {
|
|
7
|
+
OPEN_TAB = "openTab",
|
|
8
|
+
OPEN_VARIATION_SELECTOR = "openVariationSelector",
|
|
9
|
+
ADD_TO_CART = "addToCart"
|
|
10
|
+
}
|
|
11
|
+
export type AddToCartCreateAction<T> = (data: T) => AddToCartAction;
|
|
12
|
+
export type AddToCartCreateActionExec<T> = (data: T) => any;
|
|
13
|
+
export type AddToCartAction = {
|
|
14
|
+
type: AddToCartActionTypes;
|
|
15
|
+
exec: () => any;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* ============ Factory types ============
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* The keys must be coincide with "AddToCartHookActionTypes" enum values
|
|
22
|
+
*/
|
|
23
|
+
export type AddToCartActionFactory = {
|
|
24
|
+
openTab: AddToCartCreateAction<string>;
|
|
25
|
+
openVariationSelector: AddToCartCreateAction<boolean>;
|
|
26
|
+
addToCart: AddToCartCreateAction<{
|
|
27
|
+
product: NizzaProduct;
|
|
28
|
+
quantity?: number;
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
export type AddToCartActionFactoryMap = {
|
|
32
|
+
openTab: AddToCartCreateActionExec<string>;
|
|
33
|
+
openVariationSelector: AddToCartCreateActionExec<boolean>;
|
|
34
|
+
addToCart: AddToCartCreateActionExec<{
|
|
35
|
+
product: NizzaProduct;
|
|
36
|
+
quantity?: number;
|
|
37
|
+
}>;
|
|
38
|
+
};
|
|
39
|
+
type AddToCartCreateNotify = (message: string) => void;
|
|
40
|
+
export type AddToCartNotifyFactory = {
|
|
41
|
+
error: AddToCartCreateNotify;
|
|
42
|
+
success: AddToCartCreateNotify;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* ============ Context types ============
|
|
46
|
+
*/
|
|
47
|
+
type TransformHookContext<T = Record<string, any>> = {
|
|
48
|
+
product: NizzaProduct;
|
|
49
|
+
data: T;
|
|
50
|
+
};
|
|
51
|
+
type ValidateHookContext<T = Record<string, any>> = {
|
|
52
|
+
product: NizzaProduct;
|
|
53
|
+
defaultAction: AddToCartAction;
|
|
54
|
+
action: AddToCartActionFactory;
|
|
55
|
+
data: T;
|
|
56
|
+
};
|
|
57
|
+
type EndHookContext<T = Record<string, any>> = {
|
|
58
|
+
error: Error | string | null | unknown;
|
|
59
|
+
notify: AddToCartNotifyFactory;
|
|
60
|
+
actionExecuted: AddToCartAction;
|
|
61
|
+
data: T;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* ============ Execution types ============
|
|
65
|
+
*/
|
|
66
|
+
/**
|
|
67
|
+
* Context for the add to cart operation.
|
|
68
|
+
*/
|
|
69
|
+
export type HookContext<T = Record<string, any>> = {
|
|
70
|
+
/** Indicates if the variation selector is open. */
|
|
71
|
+
isVariationSelectorOpen: boolean;
|
|
72
|
+
/** The quantity of the product to add to cart. */
|
|
73
|
+
quantity?: number;
|
|
74
|
+
data?: T;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Represents the combined state of the add to cart operation.
|
|
78
|
+
*/
|
|
79
|
+
export type HookState<ContextData = Record<string, any>> = HooksInitConfig<ContextData> & {
|
|
80
|
+
action: AddToCartAction;
|
|
81
|
+
};
|
|
82
|
+
export type AddToCartHookStrategy<ContextData = Record<string, any>> = {
|
|
83
|
+
validate: (state: HookState<ContextData>) => AddToCartAction;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Initial configuration for the add to cart operation.
|
|
87
|
+
*/
|
|
88
|
+
export type HooksInitConfig<ContextData = Record<string, any>> = {
|
|
89
|
+
/** The product to be added to the cart. */
|
|
90
|
+
product: NizzaProduct;
|
|
91
|
+
hookStrategy: AddToCartHookStrategy<ContextData>;
|
|
92
|
+
/** A map of action factories for different add to cart actions. */
|
|
93
|
+
actionFactory: AddToCartActionFactoryMap;
|
|
94
|
+
/** Factory for creating notification actions. */
|
|
95
|
+
notifyFactory: AddToCartNotifyFactory;
|
|
96
|
+
/** Context for the add to cart operation. */
|
|
97
|
+
context: HookContext<ContextData>;
|
|
98
|
+
/** User-defined configuration for add to cart behavior. */
|
|
99
|
+
userAddToCartConfig?: AddToCartConfig;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* ============ Event types ============
|
|
103
|
+
*/
|
|
104
|
+
export type ActionExecutedPayload = {
|
|
105
|
+
actionType: AddToCartActionTypes;
|
|
106
|
+
product: NizzaProduct;
|
|
107
|
+
success: boolean;
|
|
108
|
+
error: Error | string | null | unknown;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* ============ Main types ============
|
|
112
|
+
*/
|
|
113
|
+
interface AddToCartHooks<ContextData = Record<string, any>> {
|
|
114
|
+
transform: (context: TransformHookContext<ContextData>) => NizzaProduct | Promise<NizzaProduct>;
|
|
115
|
+
validate: (context: ValidateHookContext<ContextData>) => AddToCartAction | Promise<AddToCartAction>;
|
|
116
|
+
end: (context: EndHookContext<ContextData>) => void | boolean | Promise<void | boolean>;
|
|
117
|
+
}
|
|
118
|
+
export interface AddToCartConfig {
|
|
119
|
+
hooks?: Partial<AddToCartHooks>;
|
|
120
|
+
actionFactory?: Partial<AddToCartActionFactoryMap>;
|
|
121
|
+
}
|
|
122
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NizzaProduct } from './product';
|
|
2
2
|
export type NizzaAddToCartHandlerParams = {
|
|
3
3
|
product: NizzaProduct;
|
|
4
|
-
quantity
|
|
4
|
+
quantity?: number;
|
|
5
5
|
};
|
|
6
6
|
export type NizzaAddToCartHandler = (params: NizzaAddToCartHandlerParams) => Promise<void>;
|
|
7
7
|
export type NizzaSetUTMHandler = (utm: string) => Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/package.json
CHANGED