@nizza/core 0.5.0-beta.14 → 0.5.0-beta.15
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 +4832 -1408
- package/dist/index.mjs.map +1 -1
- package/dist/lib/add-to-cart/hooks.d.ts +13 -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/api-graphql-types.d.ts +26 -26
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/locales/index.d.ts +1 -0
- package/dist/package.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { HooksInitConfig } 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>;
|
|
@@ -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 {};
|
|
@@ -1017,6 +1017,29 @@ export type UpdateCustomizationMutation = {
|
|
|
1017
1017
|
timestamp: string;
|
|
1018
1018
|
};
|
|
1019
1019
|
};
|
|
1020
|
+
export type FindByProductSnackVideoQueryVariables = Exact<{
|
|
1021
|
+
data: FindByProductSnackVideoInput;
|
|
1022
|
+
}>;
|
|
1023
|
+
export type FindByProductSnackVideoQuery = {
|
|
1024
|
+
__typename?: 'Query';
|
|
1025
|
+
findByProductSnackVideo: {
|
|
1026
|
+
__typename: 'ErrorGeneral';
|
|
1027
|
+
message: string;
|
|
1028
|
+
statusCode: string;
|
|
1029
|
+
timestamp: string;
|
|
1030
|
+
} | {
|
|
1031
|
+
__typename: 'SnackVideoArray';
|
|
1032
|
+
data?: Array<{
|
|
1033
|
+
__typename?: 'SnackVideo';
|
|
1034
|
+
id: string;
|
|
1035
|
+
name: string;
|
|
1036
|
+
url: string;
|
|
1037
|
+
thumbnailUrl: string;
|
|
1038
|
+
duration: number;
|
|
1039
|
+
transmitionType?: string | null;
|
|
1040
|
+
}> | null;
|
|
1041
|
+
};
|
|
1042
|
+
};
|
|
1020
1043
|
export type GetTimeLineQueryVariables = Exact<{
|
|
1021
1044
|
data: GetTimeLineInput;
|
|
1022
1045
|
}>;
|
|
@@ -1206,29 +1229,6 @@ export type SearchSnackVideosQuery = {
|
|
|
1206
1229
|
} | null;
|
|
1207
1230
|
};
|
|
1208
1231
|
};
|
|
1209
|
-
export type FindByProductSnackVideoQueryVariables = Exact<{
|
|
1210
|
-
data: FindByProductSnackVideoInput;
|
|
1211
|
-
}>;
|
|
1212
|
-
export type FindByProductSnackVideoQuery = {
|
|
1213
|
-
__typename?: 'Query';
|
|
1214
|
-
findByProductSnackVideo: {
|
|
1215
|
-
__typename: 'ErrorGeneral';
|
|
1216
|
-
message: string;
|
|
1217
|
-
statusCode: string;
|
|
1218
|
-
timestamp: string;
|
|
1219
|
-
} | {
|
|
1220
|
-
__typename: 'SnackVideoArray';
|
|
1221
|
-
data?: Array<{
|
|
1222
|
-
__typename?: 'SnackVideo';
|
|
1223
|
-
id: string;
|
|
1224
|
-
name: string;
|
|
1225
|
-
url: string;
|
|
1226
|
-
thumbnailUrl: string;
|
|
1227
|
-
duration: number;
|
|
1228
|
-
transmitionType?: string | null;
|
|
1229
|
-
}> | null;
|
|
1230
|
-
};
|
|
1231
|
-
};
|
|
1232
1232
|
export declare const AddCollectionDocument: DocumentNode<AddCollectionMutation, Exact<{
|
|
1233
1233
|
data: CreateCollectionInput;
|
|
1234
1234
|
}>>;
|
|
@@ -1283,6 +1283,9 @@ export declare const GetAllCustomizationDocument: DocumentNode<GetAllCustomizati
|
|
|
1283
1283
|
export declare const UpdateCustomizationDocument: DocumentNode<UpdateCustomizationMutation, Exact<{
|
|
1284
1284
|
data: CustomPlayerInput;
|
|
1285
1285
|
}>>;
|
|
1286
|
+
export declare const FindByProductSnackVideoDocument: DocumentNode<FindByProductSnackVideoQuery, Exact<{
|
|
1287
|
+
data: FindByProductSnackVideoInput;
|
|
1288
|
+
}>>;
|
|
1286
1289
|
export declare const GetTimeLineDocument: DocumentNode<GetTimeLineQuery, Exact<{
|
|
1287
1290
|
data: GetTimeLineInput;
|
|
1288
1291
|
}>>;
|
|
@@ -1310,6 +1313,3 @@ export declare const GetSnackVideoRelationshipsDocument: DocumentNode<GetSnackVi
|
|
|
1310
1313
|
export declare const SearchSnackVideosDocument: DocumentNode<SearchSnackVideosQuery, Exact<{
|
|
1311
1314
|
data: SearchInput;
|
|
1312
1315
|
}>>;
|
|
1313
|
-
export declare const FindByProductSnackVideoDocument: DocumentNode<FindByProductSnackVideoQuery, Exact<{
|
|
1314
|
-
data: FindByProductSnackVideoInput;
|
|
1315
|
-
}>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/package.json
CHANGED