@nizza/core 0.5.0-beta.9 → 0.5.1

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.
@@ -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
  };
@@ -1,5 +1,6 @@
1
1
  export declare enum NizzaVariationTypes {
2
- COMBO = "Combo"
2
+ COMBO = "Combo",
3
+ BADGE = "Badged"
3
4
  }
4
5
  export declare enum NizzaProductRequestOriginTypes {
5
6
  VTEX = "VTEX",
@@ -1,4 +1,5 @@
1
1
  export * from './accounts';
2
+ export * from './add-to-cart';
2
3
  export * from './constants';
3
4
  export * from './domain';
4
5
  export * from './errors';
@@ -1,8 +1,27 @@
1
- import { StoreApi, UseBoundStore } from 'zustand';
2
- import { NizzaConfig, NizzaProductDataSource, NizzaState, NizzaStore } from '../types';
3
- export declare let nizza: NizzaStore;
4
- export declare let useNizza: UseBoundStore<StoreApi<NizzaState>>;
5
- export declare function nizzaInit(): NizzaStore;
6
- export declare function getInstance(): NizzaStore;
7
- export declare function configure(config: NizzaConfig): Promise<void>;
8
- export declare function setProductDataSource(dataSource: NizzaProductDataSource): void;
1
+ import { NizzaAccount } from '../accounts';
2
+ import { BroadcastChannelEventBus } from '../event-buses';
3
+ import { NizzaStore as INizzaStore, NizzaConfig, NizzaProductDataSource } from '../types';
4
+ import { Logger } from '../utils/logger';
5
+ export declare class NizzaStore implements INizzaStore {
6
+ private static _instance;
7
+ readonly version = "1";
8
+ readonly instanceId: string;
9
+ private _config;
10
+ private _account?;
11
+ private _productDataSource;
12
+ private _eventBus;
13
+ readonly log: Logger;
14
+ private constructor();
15
+ static instance(): NizzaStore;
16
+ configure(config: NizzaConfig): Promise<void>;
17
+ private setAccount;
18
+ setProductDataSource(dataSource: NizzaProductDataSource): void;
19
+ get config(): NizzaConfig | null;
20
+ get account(): NizzaAccount | undefined;
21
+ get accountName(): string | undefined;
22
+ get productDataSource(): NizzaProductDataSource | undefined;
23
+ get eventBus(): BroadcastChannelEventBus;
24
+ }
25
+ export declare const nizza: NizzaStore;
26
+ export declare const logger: import("loglevel").Logger;
27
+ export declare const coreLogger: import("loglevel").Logger;
@@ -1,2 +1,4 @@
1
1
  import { NizzaStore } from '../types';
2
- export declare const nizza: NizzaStore;
2
+ export declare const nizza: import("./NizzaStore").NizzaStore | NizzaStore;
3
+ export declare const logger: import("loglevel").Logger;
4
+ export declare const coreLogger: import("loglevel").Logger;
@@ -0,0 +1,7 @@
1
+ import { NizzaConfig, NizzaProductDataSource, NizzaStore } from '../types';
2
+ export declare const configure: (config: NizzaConfig) => Promise<void>;
3
+ export declare const setProductDataSource: (dataSource: NizzaProductDataSource) => void;
4
+ export declare const nizza: import("./NizzaStore").NizzaStore | NizzaStore;
5
+ export declare const useNizza: any;
6
+ export declare const logger: import("loglevel").Logger;
7
+ export declare const coreLogger: import("loglevel").Logger;
@@ -1,2 +1,3 @@
1
1
  export * from './NizzaStore';
2
2
  export * from './helpers';
3
+ export * from './useNizza';
@@ -0,0 +1,11 @@
1
+ import { NizzaStore } from './NizzaStore';
2
+ /**
3
+ * Custom hook for selecting and observing specific properties from NizzaStore.
4
+ *
5
+ * @param selector - A function that receives the NizzaStore instance and returns the selected part.
6
+ * @returns The selected store part, being observed for changes.
7
+ *
8
+ * @example
9
+ * const accountName = useNizza(store => store.accountName);
10
+ */
11
+ export declare function useNizza<T>(selector: (store: NizzaStore) => T): T;
@@ -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 {};
@@ -254,6 +254,10 @@ export type FindManySnackVideoInput = {
254
254
  ids: Array<Scalars['String']>;
255
255
  };
256
256
  export type FindManySnackVideoResult = ErrorGeneral | SnackVideoArray;
257
+ export type GetPlayListInput = {
258
+ account: Scalars['String'];
259
+ };
260
+ export type GetPlayListResult = ErrorGeneral | PlayListArray;
257
261
  export type GetAllChatMessageInput = {
258
262
  account: Scalars['String'];
259
263
  idEvent: Scalars['String'];
@@ -539,7 +543,7 @@ export type SearchInput = {
539
543
  includeTotal?: InputMaybe<Scalars['Boolean']>;
540
544
  limit?: InputMaybe<Scalars['Float']>;
541
545
  page?: InputMaybe<Scalars['Float']>;
542
- search: Scalars['String'];
546
+ search?: Scalars['String'];
543
547
  };
544
548
  export type SnackVideo = {
545
549
  __typename?: 'SnackVideo';
@@ -578,6 +582,40 @@ export type SnackVideoCreatedWithCursor = {
578
582
  totalItems?: Maybe<Scalars['Float']>;
579
583
  };
580
584
  export type SnackVideoGetAll = ErrorGeneral | SnackVideoCreatedArray;
585
+ export type PlayList = {
586
+ __typename?: 'PlayList';
587
+ account: Scalars['String'];
588
+ created: Maybe<Scalars['String']>;
589
+ description: Scalars['String'];
590
+ updated: Scalars['String'];
591
+ videoAmount: Scalars['Float'];
592
+ id: Scalars['String'];
593
+ name: Scalars['String'];
594
+ productAmount: Scalars['Float'];
595
+ videos: Maybe<Array<PlayList>>;
596
+ };
597
+ export type PlayListVideo = {
598
+ __typename?: 'PlayListVideo';
599
+ account: Scalars['String'];
600
+ id: Scalars['String'];
601
+ name: Scalars['String'];
602
+ url: Scalars['String'];
603
+ thumbnailUrl: Scalars['String'];
604
+ duration: Scalars['Float'];
605
+ eventId: Scalars['String'];
606
+ eventName: Scalars['String'];
607
+ transmitionType: Scalars['String'];
608
+ order: Scalars['Float'];
609
+ idPlayList: Scalars['String'];
610
+ };
611
+ export type PlayListArray = {
612
+ __typename?: 'PlayListArray';
613
+ data?: Maybe<Array<PlayList>>;
614
+ duration?: Maybe<Scalars['String']>;
615
+ isArray?: Maybe<Scalars['Boolean']>;
616
+ method?: Maybe<Scalars['String']>;
617
+ path?: Maybe<Scalars['String']>;
618
+ };
581
619
  export type SnackVideoRelationshipInput = {
582
620
  account: Scalars['String'];
583
621
  snackVideoId: Scalars['String'];
@@ -1127,6 +1165,32 @@ export type FindManySnackVideosQuery = {
1127
1165
  }> | null;
1128
1166
  };
1129
1167
  };
1168
+ export type GetPlayListsQueryVariables = Exact<{
1169
+ data: GetPlayListInput;
1170
+ }>;
1171
+ export type GetPlayListQuery = {
1172
+ __typename?: 'Query';
1173
+ getPlayLists: {
1174
+ __typename: 'ErrorGeneral';
1175
+ message: string;
1176
+ statusCode: string;
1177
+ timestamp: string;
1178
+ } | {
1179
+ __typename: 'PlayListArray';
1180
+ data?: Array<{
1181
+ __typename?: 'PlayList';
1182
+ id: string;
1183
+ name: string;
1184
+ url: string;
1185
+ thumbnailUrl: string;
1186
+ uploadProgress: number;
1187
+ duration: number;
1188
+ eventId: string;
1189
+ eventName: string;
1190
+ transmitionType?: string | null;
1191
+ }> | null;
1192
+ };
1193
+ };
1130
1194
  export type GetAllSnackVideosQueryVariables = Exact<{
1131
1195
  data: QueryInput;
1132
1196
  }>;
@@ -1301,6 +1365,9 @@ export declare const DeleteSnackVideoDocument: DocumentNode<DeleteSnackVideoMuta
1301
1365
  export declare const FindManySnackVideosDocument: DocumentNode<FindManySnackVideosQuery, Exact<{
1302
1366
  data: FindManySnackVideoInput;
1303
1367
  }>>;
1368
+ export declare const GetPlayListsDocument: DocumentNode<GetPlayListQuery, Exact<{
1369
+ data: GetPlayListInput;
1370
+ }>>;
1304
1371
  export declare const GetAllSnackVideosDocument: DocumentNode<GetAllSnackVideosQuery, Exact<{
1305
1372
  data: QueryInput;
1306
1373
  }>>;
@@ -1,4 +1,5 @@
1
1
  import * as ApiGraphqlTypes from './api-graphql-types';
2
+ export * from './add-to-cart-hooks';
2
3
  export * from './api';
3
4
  export * from './appModule';
4
5
  export * from './i18n';
@@ -1,4 +1,3 @@
1
- import { StoreApi, UseBoundStore } from 'zustand';
2
1
  import { NizzaAccount } from '../../accounts';
3
2
  import { BroadcastChannelEventBus } from '../../event-buses';
4
3
  import { Logger } from '../../utils';
@@ -7,18 +6,14 @@ export interface GlobalStoreConfig {
7
6
  account: string;
8
7
  getProductDataSource?: () => Promise<any> | any;
9
8
  }
10
- export interface GlobalState {
11
- config: GlobalStoreConfig | null;
12
- account?: any;
13
- productDataSource?: any;
14
- }
15
9
  export interface GlobalStore {
16
10
  version: string;
17
- store: UseBoundStore<StoreApi<any>>;
18
11
  instanceId: string;
12
+ config: GlobalStoreConfig | null;
13
+ account?: any;
14
+ productDataSource?: any;
19
15
  log: Logger;
20
16
  eventBus: BroadcastChannelEventBus;
21
- state: GlobalState;
22
17
  configure: (config: GlobalStoreConfig) => Promise<void>;
23
18
  setProductDataSource: (dataSource: any) => void;
24
19
  }
@@ -26,14 +21,11 @@ export interface NizzaConfig extends GlobalStoreConfig {
26
21
  account: string;
27
22
  getProductDataSource?: () => Promise<NizzaProductDataSource> | NizzaProductDataSource;
28
23
  }
29
- export interface NizzaState extends GlobalState {
24
+ export interface NizzaStore extends GlobalStore {
30
25
  config: NizzaConfig | null;
31
26
  account?: NizzaAccount;
27
+ accountName?: string;
32
28
  productDataSource?: NizzaProductDataSource;
33
- }
34
- export interface NizzaStore extends GlobalStore {
35
- store: UseBoundStore<StoreApi<NizzaState>>;
36
- state: NizzaState;
37
29
  configure: (config: NizzaConfig) => Promise<void>;
38
30
  setProductDataSource: (dataSource: NizzaProductDataSource) => void;
39
31
  }
@@ -1,7 +1,7 @@
1
1
  import { NizzaProduct } from './product';
2
2
  export type NizzaAddToCartHandlerParams = {
3
3
  product: NizzaProduct;
4
- quantity: number;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nizza/core",
3
- "version": "0.5.0-beta.9",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.cjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nizza/core",
3
- "version": "0.5.0-beta.9",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.cjs",