@inappstory/react-sdk 1.7.4 → 1.7.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.
Files changed (30) hide show
  1. package/dist/index.esm.mjs +3113 -3593
  2. package/dist/index.esm.mjs.map +1 -1
  3. package/dist/index.umd.js +2 -2
  4. package/dist/types/appearance-manager/appearanceCommon.d.ts +69 -3
  5. package/dist/types/appearance-manager/gameReader.d.ts +83 -4
  6. package/dist/types/appearance-manager/goodsWidget.d.ts +84 -1
  7. package/dist/types/appearance-manager/sharePanel.d.ts +133 -7
  8. package/dist/types/appearance-manager/storiesList.d.ts +303 -5
  9. package/dist/types/appearance-manager/storyReader.d.ts +260 -0
  10. package/dist/types/events.d.ts +212 -0
  11. package/dist/types/ias-container/IasContainer.d.ts +24 -0
  12. package/dist/types/ias-container/appearanceOptionsProps.d.ts +20 -1
  13. package/dist/types/ias-container/index.d.ts +1 -2
  14. package/dist/types/ias-container/storyManagerEventsProps.d.ts +110 -4
  15. package/dist/types/in-app-messaging/iamErrors.d.ts +49 -45
  16. package/dist/types/in-app-messaging/inAppMessaging.d.ts +166 -0
  17. package/dist/types/index.d.ts +2 -1
  18. package/dist/types/story-list/FavoriteStoryList.d.ts +51 -1
  19. package/dist/types/story-list/StoryList.d.ts +169 -0
  20. package/dist/types/story-list/UGCStoryList.d.ts +61 -0
  21. package/dist/types/story-list/navigationViewModel.d.ts +43 -0
  22. package/dist/types/story-list/storyCardViewModel.d.ts +87 -3
  23. package/dist/types/story-list/storyListApi.d.ts +3 -2
  24. package/dist/types/story-list/storyListLoadStatus.ts +47 -10
  25. package/dist/types/storyManager.d.ts +205 -6
  26. package/package.json +6 -2
  27. package/plugins/dotLottie/iasDotLottiePlugin.umd.js +1 -1
  28. package/plugins/videoOnDemand/iasVideoOnDemandPlugin.umd.js +1 -1
  29. package/dist/types/appearance-manager/storyReader.ts +0 -125
  30. package/dist/types/ias-container/publicEvents.d.ts +0 -104
@@ -1,48 +1,214 @@
1
+ import {
2
+ IamNotFoundByEventError,
3
+ IamMessageOpenError,
4
+ IamOtherReaderIsOpenError,
5
+ IamShowOnlyIfLoadedError,
6
+ IamMessageLimitExceededError,
7
+ IamNotFoundByIdError,
8
+ IamFrequencyLimitError,
9
+ IamCheckDisplayTimeRangeError
10
+ } from "./iamErrors";
11
+
12
+ /**
13
+ * Enum representing different types of in-app messages
14
+ */
1
15
  export declare enum IamMessageType {
16
+ /**
17
+ * Message appears as a bottom sheet (slides up from bottom of screen)
18
+ */
2
19
  BottomSheet = 1,
20
+
21
+ /**
22
+ * Message appears as a modal dialog (centered on screen)
23
+ */
3
24
  Modal = 2,
25
+
26
+ /**
27
+ * Message takes up the full screen
28
+ */
4
29
  Fullscreen = 3
5
30
  }
6
31
 
32
+ /**
33
+ * Interface representing an in-app message
34
+ */
7
35
  export interface IamMessage {
36
+ /**
37
+ * Unique identifier for the message
38
+ */
8
39
  id: number;
40
+
41
+ /**
42
+ * Name of the campaign this message belongs to
43
+ */
9
44
  campaignName: string;
45
+
46
+ /**
47
+ * Visual presentation type of the message
48
+ */
10
49
  type: IamMessageType;
11
50
  }
12
51
 
52
+ /**
53
+ * Type mapping of all possible IAM events and their payload structures
54
+ */
13
55
  export type IamEvents = {
56
+ /**
57
+ * Triggered when a message is closed
58
+ */
14
59
  close: {
60
+ /**
61
+ * The message that was closed
62
+ */
15
63
  message: IamMessage;
16
64
  };
65
+
66
+ /**
67
+ * Triggered when a widget within a message fires an event
68
+ */
17
69
  widgetEvent: {
70
+ /**
71
+ * The message containing the widget
72
+ */
18
73
  message: IamMessage;
74
+
75
+ /**
76
+ * Name/type of the widget event
77
+ */
19
78
  name: string;
79
+
80
+ /**
81
+ * Additional data associated with the event
82
+ */
20
83
  data: Record<string, any>;
21
84
  };
85
+
86
+ /**
87
+ * Triggered when a button is clicked within a message
88
+ */
22
89
  clickOnButton: {
90
+ /**
91
+ * Unique identifier of the clicked button
92
+ */
23
93
  id: number;
94
+
95
+ /**
96
+ * Index position of the button
97
+ */
24
98
  index: number;
99
+
100
+ /**
101
+ * URL associated with the button (if any)
102
+ */
25
103
  url: string;
104
+
105
+ /**
106
+ * ID of the HTML element that was clicked
107
+ */
26
108
  elementId: string;
27
109
  };
28
110
  };
29
111
 
112
+ /**
113
+ * Type definition for IAM event handlers
114
+ * @template Event - The event name (keyof IamEvents)
115
+ */
30
116
  export type IamEventHandler<Event extends keyof IamEvents> = (event: IamEvents[Event]) => void;
31
117
 
118
+ /**
119
+ * Interface for the In-App Messaging service
120
+ */
32
121
  export interface InAppMessaging {
122
+ /**
123
+ * Gets the currently active/open message
124
+ */
33
125
  get activeMessage(): IamMessage | null;
126
+
127
+ /**
128
+ * Indicates whether messages have been loaded
129
+ */
34
130
  get isLoaded(): boolean;
131
+
132
+ /**
133
+ * Indicates whether messages are currently loading
134
+ */
35
135
  get isLoading(): boolean;
136
+
137
+ /**
138
+ * Indicates whether a message is currently open/visible
139
+ */
36
140
  get isOpened(): boolean;
37
141
 
142
+ /**
143
+ * Preloads messages for faster display later
144
+ * @param options - Optional configuration
145
+ * @param options.tags - Filter messages by tags
146
+ * @returns Promise resolving to array of loaded messages
147
+ */
38
148
  preload(options?: { tags?: string[] }): Promise<IamMessage[]>;
149
+
150
+ /**
151
+ * Displays a message by its ID
152
+ * @param messageId - The ID of the message to show
153
+ * @param options - Optional display configuration
154
+ * @param options.showOnlyIfLoaded - If true, only shows messages that were preloaded
155
+ * @returns Promise resolving to the displayed message
156
+ * @throws {IamNotFoundByIdError} If no message exists with this ID
157
+ * @throws {IamMessageOpenError} If this message is already open
158
+ * @throws {IamOtherReaderIsOpenError} If another reader is active
159
+ * @throws {IamShowOnlyIfLoadedError} If showOnlyIfLoaded=true but message wasn't preloaded
160
+ * @throws {IamMessageLimitExceededError} If message display limit was reached
161
+ */
39
162
  showMessageById(messageId: number | string, options?: { showOnlyIfLoaded?: boolean }): Promise<IamMessage>;
163
+
164
+ /**
165
+ * Displays a message associated with an event name
166
+ * @param eventName - The event name triggering the message
167
+ * @param options - Optional display configuration
168
+ * @param options.showOnlyIfLoaded - If true, only shows messages that were preloaded
169
+ * @param options.tags - Filter messages by tags
170
+ * @returns Promise resolving to the displayed message
171
+ * @throws {IamNotFoundByEventError} If no message exists for this event
172
+ * @throws {IamFrequencyLimitError} If message frequency limit was exceeded
173
+ * @throws {IamCheckDisplayTimeRangeError} If current time is outside allowed display period
174
+ * @throws {IamOtherReaderIsOpenError} If another reader is active
175
+ * @throws {IamShowOnlyIfLoadedError} If showOnlyIfLoaded=true but message wasn't preloaded
176
+ */
40
177
  showMessageByEvent(
41
178
  eventName: string,
42
179
  options?: { showOnlyIfLoaded?: boolean; tags?: string[] }
43
180
  ): Promise<IamMessage>;
181
+
182
+ /**
183
+ * Closes the currently open message
184
+ * @returns Promise that resolves when the message is closed
185
+ */
44
186
  close(): Promise<void>;
187
+
188
+ /**
189
+ * Registers an event listener
190
+ * @template Event - The event name to listen for
191
+ * @param eventName - Name of the event to listen for
192
+ * @param listener - Callback function to handle the event
193
+ * @returns The InAppMessaging instance for chaining
194
+ */
45
195
  on<Event extends keyof IamEvents>(eventName: Event, listener: IamEventHandler<Event>): this;
196
+
197
+ /**
198
+ * Registers a one-time event listener
199
+ * @template Event - The event name to listen for
200
+ * @param eventName - Name of the event to listen for
201
+ * @param listener - Callback function to handle the event
202
+ * @returns The InAppMessaging instance for chaining
203
+ */
46
204
  once<Event extends keyof IamEvents>(eventName: Event, listener: IamEventHandler<Event>): this;
205
+
206
+ /**
207
+ * Removes an event listener
208
+ * @template Event - The event name to remove listener for
209
+ * @param eventName - Name of the event
210
+ * @param listener - Callback function to remove
211
+ * @returns The InAppMessaging instance for chaining
212
+ */
47
213
  off<Event extends keyof IamEvents>(eventName: Event, listener: IamEventHandler<Event>): this;
48
214
  }
@@ -2,4 +2,5 @@ export * from "./appearance-manager";
2
2
  export * from "./story-list";
3
3
  export * from "./storyManager";
4
4
  export * from "./ias-container";
5
- export * from "./in-app-messaging"
5
+ export * from "./in-app-messaging"
6
+ export * from "./events"
@@ -2,10 +2,60 @@ import { StoriesListOptions, NavigationViewModel } from "..";
2
2
  import { StoryCardViewModel } from "./storyCardViewModel";
3
3
  import { OverrideByMediaQuery } from "../appearance-manager/overrideByMediaQuery";
4
4
 
5
+ /**
6
+ * Props for the FavoriteStoryList component that displays a user's favorite stories
7
+ */
5
8
  interface FavoriteStoryListProps {
9
+ /**
10
+ * Configuration options for customizing the appearance and behavior of the list
11
+ */
6
12
  options?: StoriesListOptions;
7
- optionsOverrideByMediaQuery?: OverrideByMediaQuery<StoriesListOptions>[]
13
+
14
+ /**
15
+ * Custom render function for story cards
16
+ *
17
+ * @param storyCard - Data object containing card content and metadata
18
+ * @returns React node to render for the card
19
+ *
20
+ * @example
21
+ * (storyCard) => (
22
+ * <CustomCard
23
+ * title={storyCard.title}
24
+ * image={storyCard.getImageSrcByCoverQuality('high')}
25
+ * />
26
+ * )
27
+ */
8
28
  storyCardView?: (storyCard: StoryCardViewModel) => React.ReactNode;
29
+
30
+ /**
31
+ * Custom render function for navigation controls
32
+ *
33
+ * @param navigation - Data object containing navigation state and methods
34
+ * @returns React node to render for navigation
35
+ *
36
+ * @example
37
+ * (navigation) => (
38
+ * <div className="custom-nav">
39
+ * <button onClick={navigation.onPrev} disabled={navigation.reachStart}>
40
+ * Previous
41
+ * </button>
42
+ * <button onClick={navigation.onNext} disabled={navigation.reachEnd}>
43
+ * Next
44
+ * </button>
45
+ * </div>
46
+ * )
47
+ */
9
48
  navigationView?: (navigation: NavigationViewModel) => React.ReactNode;
10
49
  }
50
+
51
+ /**
52
+ * Component that displays a scrollable list of a user's favorite stories
53
+ * with support for custom rendering and responsive configuration
54
+ *
55
+ * @param props - Configuration properties for the component
56
+ * @returns React element representing the favorite stories list
57
+ *
58
+ * @example
59
+ * <FavoriteStoryList />
60
+ */
11
61
  export declare const FavoriteStoryList: (props: FavoriteStoryListProps) => JSX.Element;
@@ -6,19 +6,188 @@ import { FavoriteCardCompositeViewModel } from "./favoriteCardCompositeViewModel
6
6
  import { StoryListApi } from "./storyListApi";
7
7
  import { StoriesListOptions } from "../appearance-manager";
8
8
 
9
+ /**
10
+ * Props for the StoryList component that displays a list of stories previews
11
+ * @see https://docs.inappstory.com/sdk-guides/react-sdk/story-list.html
12
+ */
9
13
  interface StoryListProps {
14
+ /**
15
+ * Ref for accessing the StoryList component API
16
+ */
10
17
  ref?: React.Ref<StoryListApi | null>;
18
+
19
+ /**
20
+ * Appearance settings for the stories list
21
+ */
11
22
  options?: StoriesListOptions;
23
+
24
+ /**
25
+ * Feed identifier for loading stories
26
+ * @default default
27
+ */
12
28
  feedSlug?: string;
29
+
30
+ /**
31
+ * Use the testKey to see stories with status `Moderation`.
32
+ */
13
33
  testKey?: string;
34
+
35
+ /**
36
+ * Callback when UGC card is clicked
37
+ */
14
38
  onUgcCardClick?: () => void;
39
+
40
+ /**
41
+ * Callback when favorite card is clicked
42
+ */
15
43
  onFavoriteCardClick?: () => void;
44
+
45
+ /**
46
+ * Flag indicating whether to use UGC cards
47
+ */
16
48
  useUgcCard?: boolean;
49
+
50
+ /**
51
+ * Flag indicating whether favorite cards are present
52
+ */
17
53
  hasFavorite?: boolean;
54
+
55
+ /**
56
+ * Callback triggered when story list loading starts
57
+ */
18
58
  onLoadStart?: () => void;
59
+
60
+ /**
61
+ * Callback triggered when story list loading completes
62
+ * @param storyListLoadStatus - Status of the story list loading
63
+ */
19
64
  onLoadEnd?: (storyListLoadStatus: StoryListLoadStatus) => void;
65
+
66
+ /**
67
+ * Custom render for story cards
68
+ * @param storyCard - Data for rendering a story card
69
+ * @returns React element for the story card
70
+ * @example
71
+ * // Custom card with gradient overlay
72
+ * storyCardView={(card) => (
73
+ * <div style={{
74
+ * position: 'relative',
75
+ * borderRadius: 8,
76
+ * overflow: 'hidden',
77
+ * aspectRatio: card.getAspectRatio('grid')
78
+ * }}>
79
+ * <img
80
+ * src={card.getImageSrcByCoverQuality('medium')}
81
+ * alt={card.title}
82
+ * style={{ width: '100%', height: '100%', objectFit: 'cover' }}
83
+ * />
84
+ * <div style={{
85
+ * position: 'absolute',
86
+ * bottom: 0,
87
+ * left: 0,
88
+ * right: 0,
89
+ * padding: 16,
90
+ * background: 'linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 100%)'
91
+ * }}>
92
+ * <h3 style={{ color: '#fff', margin: 0 }}>{card.title}</h3>
93
+ * </div>
94
+ * </div>
95
+ * )}
96
+ */
20
97
  storyCardView?: (storyCard: StoryCardViewModel) => React.ReactNode;
98
+
99
+ /**
100
+ * Custom render for navigation
101
+ * @param navigation - Data for rendering navigation
102
+ * @returns React element for navigation
103
+ * @example
104
+ * // Custom navigation arrows with disabled states
105
+ * navigationView={(nav) => (
106
+ * <div style={{
107
+ * display: 'flex',
108
+ * justifyContent: 'center',
109
+ * gap: 16,
110
+ * padding: '16px 0'
111
+ * }}>
112
+ * <button
113
+ * onClick={nav.onPrev}
114
+ * disabled={nav.reachStart}
115
+ * style={{
116
+ * padding: '8px 16px',
117
+ * opacity: nav.reachStart ? 0.5 : 1,
118
+ * cursor: nav.reachStart ? 'not-allowed' : 'pointer'
119
+ * }}
120
+ * >
121
+ * ← Previous
122
+ * </button>
123
+ * <button
124
+ * onClick={nav.onNext}
125
+ * disabled={nav.reachEnd}
126
+ * style={{
127
+ * padding: '8px 16px',
128
+ * opacity: nav.reachEnd ? 0.5 : 1,
129
+ * cursor: nav.reachEnd ? 'not-allowed' : 'pointer'
130
+ * }}
131
+ * >
132
+ * Next →
133
+ * </button>
134
+ * </div>
135
+ * )}
136
+ */
21
137
  navigationView?: (navigation: NavigationViewModel) => React.ReactNode;
138
+
139
+ /**
140
+ * Custom render function for favorite cards
141
+ * @param favoriteCardCompositeViewModel - Data for rendering a favorite card
142
+ * @returns React element for the favorite card
143
+ * @example
144
+ * // Favorite card with special badge
145
+ * favoriteCardView={(favoriteCard) => (
146
+ * <div style={{
147
+ * border: '2px dashed gold',
148
+ * borderRadius: 12,
149
+ * padding: 16,
150
+ * position: 'relative'
151
+ * }}>
152
+ * <h3 style={{ marginTop: 0, color: 'gold' }}>
153
+ * Favorites Collection ({favoriteCard.favoriteStories.length})
154
+ * </h3>
155
+ * <div style={{
156
+ * display: 'grid',
157
+ * gridTemplateColumns: 'repeat(auto-fill, minmax(80px, 1fr))',
158
+ * gap: 8
159
+ * }}>
160
+ * {favoriteCard.favoriteStories.map(story => (
161
+ * <img
162
+ * key={story.id}
163
+ * src={story.getImageSrcByCoverQuality('medium')}
164
+ * alt={story.title}
165
+ * style={{
166
+ * width: '100%',
167
+ * aspectRatio: '1',
168
+ * objectFit: 'cover',
169
+ * borderRadius: 4
170
+ * }}
171
+ * />
172
+ * ))}
173
+ * </div>
174
+ * </div>
175
+ * )}
176
+ */
22
177
  favoriteCardView?: (favoriteCardCompositeViewModel: FavoriteCardCompositeViewModel) => React.ReactNode;
23
178
  }
179
+
180
+ /**
181
+ * Component for displaying a list of stories previews
182
+ * @param props - Component props
183
+ * @returns React story list component
184
+ * @example
185
+ * // Basic usage with custom card and navigation
186
+ * <StoryList
187
+ * feedSlug="default"
188
+ * storyCardView={(card) => <CustomStoryCard card={card} />}
189
+ * navigationView={(nav) => <CustomNavigation {...nav} />}
190
+ * onLoadEnd={(status) => console.log('Loaded', status.defaultListLength, 'stories')}
191
+ * />
192
+ */
24
193
  export declare const StoryList: (props: StoryListProps) => JSX.Element;
@@ -5,17 +5,78 @@ import { StoryCardViewModel } from "./storyCardViewModel";
5
5
  import { StoryListApi } from "./storyListApi";
6
6
  import { StoryListLoadStatus } from "./storyListLoadStatus";
7
7
 
8
+ /**
9
+ * Props for the UGCStoryList component that displays user-generated content stories
10
+ */
8
11
  interface UGCStoryListProps {
12
+ /**
13
+ * Ref object to access the StoryList API methods imperatively
14
+ */
9
15
  ref?: React.Ref<StoryListApi | null>;
16
+
17
+ /**
18
+ * Appearance settings for the stories list
19
+ */
10
20
  options?: StoriesListOptions;
21
+
22
+ /**
23
+ * Use the testKey to see stories with status `Moderation`.
24
+ */
11
25
  testKey?: string;
26
+
27
+ /**
28
+ * Callback triggered when a UGC story card is clicked
29
+ */
12
30
  onUgcCardClick?: () => void;
31
+
32
+ /**
33
+ * Flag to enable/disable UGC card functionality
34
+ * @default false
35
+ */
13
36
  useUgcCard?: boolean;
37
+
38
+ /**
39
+ * Flag indicating whether favorites functionality should be enabled
40
+ * @default false
41
+ */
14
42
  hasFavorite?: boolean;
43
+
44
+ /**
45
+ * Filter criteria to apply when loading stories
46
+ */
15
47
  filter?: Record<string, any>;
48
+
49
+ /**
50
+ * Callback triggered when story list loading begins
51
+ */
16
52
  onLoadStart?: () => void;
53
+
54
+ /**
55
+ * Callback triggered when story list loading completes
56
+ * @param storyListLoadStatus - Contains loading results and metadata
57
+ */
17
58
  onLoadEnd?: (storyListLoadStatus: StoryListLoadStatus) => void;
59
+
60
+ /**
61
+ * Custom render function for story cards
62
+ * @param storyCard - Data object containing card content and metadata
63
+ * @returns React node to render for the card
64
+ */
18
65
  storyCardView?: (storyCard: StoryCardViewModel) => React.ReactNode;
66
+
67
+ /**
68
+ * Custom render function for navigation controls
69
+ * @param navigation - Data object containing navigation state
70
+ * @returns React node to render for navigation
71
+ */
19
72
  navigationView?: (navigation: NavigationViewModel) => React.ReactNode;
20
73
  }
74
+
75
+ /**
76
+ * Component that displays a scrollable list of user-generated content stories
77
+ * with support for custom rendering and interaction callbacks
78
+ *
79
+ * @param props - Configuration properties for the component
80
+ * @returns React element representing the story list
81
+ */
21
82
  export declare const UGCStoryList: (props: UGCStoryListProps) => JSX.Element;
@@ -1,12 +1,55 @@
1
+ /**
2
+ * Represents the view model for navigation controls in a stories list or carousel
3
+ */
1
4
  export interface NavigationViewModel {
5
+ /**
6
+ * CSS styles to be applied to navigation elements by default
7
+ */
2
8
  defaultStyles: Record<string, string>;
9
+
10
+ /**
11
+ * Indicates whether the beginning of the list has been reached
12
+ * (disabled state for previous/back navigation)
13
+ */
3
14
  reachStart: boolean;
15
+
16
+ /**
17
+ * Indicates whether the end of the list has been reached
18
+ * (disabled state for next/forward navigation)
19
+ */
4
20
  reachEnd: boolean;
21
+
22
+ /**
23
+ * Handler for previous/back navigation action
24
+ * Scrolls to the previous item or page
25
+ */
5
26
  onPrev(): void;
27
+
28
+ /**
29
+ * Handler for next/forward navigation action
30
+ * Scrolls to the next item or page
31
+ */
6
32
  onNext(): void;
33
+
34
+ /**
35
+ * Slider state and properties
36
+ */
7
37
  slider: {
38
+ /**
39
+ * Current scroll position of the slider in pixels
40
+ */
8
41
  currentPosition: number;
42
+
43
+ /**
44
+ * Scroll direction of the slider
45
+ * @default "horizontal"
46
+ */
9
47
  direction: "horizontal" | "vertical";
48
+
49
+ /**
50
+ * Dimensions and position of the visible viewport area
51
+ * @description Uses DOMRect with properties: x, y, width, height, top, right, bottom, left
52
+ */
10
53
  viewport: DOMRect;
11
54
  };
12
55
  }