@inappstory/react-sdk 1.8.0-rc.2 → 1.8.0-rc.4

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,212 @@
1
+ /**
2
+ * Base StoryReader event.
3
+ * Used as a foundation for most story-related events.
4
+ */
5
+ export interface StoryReaderEvent {
6
+ /** Unique story identifier */
7
+ id: number;
8
+ /** Story title (optional) */
9
+ title?: string;
10
+ /** Number of slides in the story */
11
+ slidesCount?: number;
12
+ /** Feed name where the story was loaded from */
13
+ feed?: string;
14
+ /** Source of story launch (e.g., deeplink, banner) */
15
+ source?: string;
16
+ /** Filters applied to the story list */
17
+ filter: Record<string, unknown>;
18
+ /** User-generated payload (e.g., UGC data) */
19
+ ugcPayload: Record<string, unknown>;
20
+ /** Number of items in the default list */
21
+ defaultListLength: number;
22
+ /** Number of items in the favorites list */
23
+ favoriteListLength: number;
24
+ }
25
+
26
+ /**
27
+ * Possible reasons for closing StoryReader.
28
+ */
29
+ export enum CloseAction {
30
+ /** Closed via the close (X) button in UI */
31
+ closeReaderByCloseBtn = "closeReaderByCloseBtn",
32
+ /** Closed via ESC key (desktop only) */
33
+ closeReaderByEscBtn = "closeReaderByEscBtn",
34
+ /** Closed by swipe down (mobile only) */
35
+ swipeDown = "swipeDown",
36
+ /** Closed by swipe to next story (mobile only) */
37
+ swipe = "swipe",
38
+ /** Closed by clicking the first (backward) or last (forward) slide */
39
+ lastSlideClick = "lastSlideClick",
40
+ /** Closed automatically by timer transition to next story */
41
+ auto = "auto",
42
+ /** Closed using public API: StoryManager.closeStoryReader */
43
+ externalCloseReader = "externalCloseReader"
44
+ }
45
+
46
+ /** Event: story was shown */
47
+ export interface ShowStoryEvent extends StoryReaderEvent {}
48
+
49
+ /** Event: story was closed */
50
+ export interface CloseStoryEvent extends StoryReaderEvent {
51
+ /** Close reason */
52
+ action: CloseAction;
53
+ }
54
+
55
+ /** Event: user clicked on a story */
56
+ export interface ClickOnStoryEvent extends StoryReaderEvent {
57
+ /** Story index inside feed */
58
+ index: number;
59
+ /** Whether the click was triggered by deeplink */
60
+ isDeeplink: boolean;
61
+ /** URL if click leads externally */
62
+ url?: string;
63
+ }
64
+
65
+ /** Event: specific slide was shown */
66
+ export interface ShowSlideEvent extends StoryReaderEvent {
67
+ /** Index of the current slide */
68
+ index: number;
69
+ /** Slide payload (e.g., JSON data) */
70
+ payload: string;
71
+ }
72
+
73
+ /** Event: story was liked */
74
+ export interface LikeStoryEvent extends StoryReaderEvent {
75
+ /** true — liked, false — unliked */
76
+ value: boolean;
77
+ }
78
+
79
+ /** Event: story was disliked */
80
+ export interface DislikeStoryEvent extends StoryReaderEvent {
81
+ /** true — disliked, false — undisliked */
82
+ value: boolean;
83
+ }
84
+
85
+ /** Event: story was added/removed from favorites */
86
+ export interface FavoriteStoryEvent extends StoryReaderEvent {
87
+ /** true — added, false — removed */
88
+ value: boolean;
89
+ }
90
+
91
+ /** Event: story was shared */
92
+ export interface ShareStoryEvent extends StoryReaderEvent {}
93
+
94
+ /** Event: story was shared with a given URL */
95
+ export interface ShareStoryWithPathEvent extends StoryReaderEvent {
96
+ /** URL used for sharing */
97
+ url: string;
98
+ }
99
+
100
+ /** Event: user clicked on the "favorites" cell */
101
+ export interface ClickOnFavoriteCellEvent {
102
+ /** Feed name where the click happened */
103
+ feed: string;
104
+ }
105
+
106
+ /** Event: feed was loaded */
107
+ export interface FeedLoadEvent {
108
+ /** Feed name */
109
+ feed: string;
110
+ /** List of stories in the feed */
111
+ stories: Array<{ id: number; title: string; slidesCount: number }>;
112
+ }
113
+
114
+ /** Event: feed impression (visible stories) */
115
+ export interface FeedImpressionEvent {
116
+ /** Feed name */
117
+ feed: string;
118
+ /** Stories that entered visible area */
119
+ stories: Array<{ id: number; title: string; slidesCount: number }>;
120
+ }
121
+
122
+ /** Event: visible area with stories was updated */
123
+ export interface VisibleAreaUpdatedEvent {
124
+ /** Feed name */
125
+ feed: string;
126
+ /** Stories that became visible */
127
+ stories: Array<{ id: number; title: string; slidesCount: number }>;
128
+ }
129
+
130
+ /** Generic widget event */
131
+ export interface WidgetEvent {
132
+ /** Event name */
133
+ name: string;
134
+ /** Event data */
135
+ data: any;
136
+ }
137
+
138
+ /** Event: mini-game started */
139
+ export interface StartGameEvent {
140
+ /** Game ID */
141
+ id: string;
142
+ }
143
+
144
+ /** Event: mini-game closed */
145
+ export interface CloseGameEvent {
146
+ /** Game ID */
147
+ id: string;
148
+ }
149
+
150
+ /** Event: mini-game finished */
151
+ export interface FinishGameEvent {
152
+ /** Game ID */
153
+ id: string;
154
+ /** Game result */
155
+ result: Record<string, any>;
156
+ }
157
+
158
+ /** Generic game event */
159
+ export interface EventGameEvent {
160
+ /** Event name */
161
+ name: string;
162
+ /** Event payload */
163
+ payload: Record<string, any>;
164
+ }
165
+ /**
166
+ * All StoryManager events that can be emitted externally.
167
+ */
168
+ export interface StoryManagerEvents {
169
+ /** Story preview card is clicked */
170
+ clickOnStory: ClickOnStoryEvent;
171
+ /** Story is shown */
172
+ showStory: ShowSlideEvent;
173
+ /** Story is closed */
174
+ closeStory: CloseStoryEvent;
175
+ /** Slide is shown */
176
+ showSlide: ShowSlideEvent;
177
+ /** Story was liked */
178
+ likeStory: LikeStoryEvent;
179
+ /** Story was disliked */
180
+ dislikeStory: DislikeStoryEvent;
181
+ /** Story added/removed from favorites */
182
+ favoriteStory: FavoriteStoryEvent;
183
+ /** Story was shared */
184
+ shareStory: ShareStoryEvent;
185
+ /** Story shared with a given URL */
186
+ shareStoryWithPath: ShareStoryWithPathEvent;
187
+ /** Feed impression */
188
+ feedImpression: FeedImpressionEvent;
189
+ /** Visible area with stories was updated */
190
+ visibleAreaUpdated: VisibleAreaUpdatedEvent;
191
+ /** Widget event */
192
+ widgetEvent: WidgetEvent;
193
+ /** Game started */
194
+ startGame: StartGameEvent;
195
+ /** Game closed */
196
+ closeGame: CloseGameEvent;
197
+ /** Game finished */
198
+ finishGame: FinishGameEvent;
199
+ /** Custom game event */
200
+ eventGame: EventGameEvent;
201
+ /**
202
+ * @deprecated
203
+ * See https://docs.inappstory.com/sdk-guides/react-sdk/link-handling.html
204
+ */
205
+ clickOnButton: any;
206
+ }
207
+
208
+ /**
209
+ * @deprecated
210
+ * Use StoryManagerEvents instead
211
+ */
212
+ export type PublicEvents = StoryManagerEvents;
@@ -1,2 +1 @@
1
- export { IASContainer } from './IasContainer';
2
- export * from "./publicEvents"
1
+ export { IASContainer } from './IasContainer';
@@ -10,8 +10,12 @@ import {
10
10
  ShowSlideEvent,
11
11
  ShowStoryEvent,
12
12
  VisibleAreaUpdatedEvent,
13
- WidgetEvent
14
- } from "./publicEvents";
13
+ WidgetEvent,
14
+ StartGameEvent,
15
+ FinishGameEvent,
16
+ CloseGameEvent,
17
+ EventGameEvent
18
+ } from "../events";
15
19
 
16
20
  /**
17
21
  * Interface for `StoryManager` event handlers.
@@ -64,13 +68,6 @@ export interface StoryManagerEventsProps {
64
68
  */
65
69
  onDislikeStory?: (event: DislikeStoryEvent) => void;
66
70
 
67
- /**
68
- * Called when a user clicks on an interactive button in the story
69
- * @param event - Contains URL
70
- * @deprecated Use `onWidgetEvent` instead
71
- */
72
- onClickOnButton?: (event: ClickOnButtonEvent) => void;
73
-
74
71
  /**
75
72
  * Called when a user favorites a story
76
73
  * @param event - Contains story ID and favorite status
@@ -106,4 +103,35 @@ export interface StoryManagerEventsProps {
106
103
  * @param event - Contains widget type and event-specific data
107
104
  */
108
105
  onWidgetEvent?: (event: WidgetEvent) => void;
106
+
107
+ /**
108
+ * Called when a game is started inside the story
109
+ * @param event - Contains game identifier
110
+ */
111
+ onStartGame?: (event: StartGameEvent) => void;
112
+
113
+ /**
114
+ * Called when a game is closed by user or system
115
+ * @param event - Contains game identifier
116
+ */
117
+ onCloseGame?: (event: CloseGameEvent) => void;
118
+
119
+ /**
120
+ * Called when a game finishes
121
+ * @param event - Contains game identifier and result payload
122
+ */
123
+ onFinishGame?: (event: FinishGameEvent) => void;
124
+
125
+ /**
126
+ * Called on custom in-game events
127
+ * @param event - Contains event name and custom payload
128
+ */
129
+ onEventGame?: (event: EventGameEvent) => void;
130
+
131
+ /**
132
+ *
133
+ * @deprecated
134
+ * See https://docs.inappstory.com/sdk-guides/react-sdk/link-handling.html
135
+ */
136
+ onClickOnButton?: (event: any) => void;
109
137
  }
@@ -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"
@@ -1,3 +1,4 @@
1
+ import { StoryManagerEvents } from "./events";
1
2
  import { PublicEventHandler, PublicEvents } from "./ias-container";
2
3
  import { InAppMessaging } from "./in-app-messaging/inAppMessaging";
3
4
 
@@ -38,7 +39,7 @@ export type StoryManagerConfig = {
38
39
  placeholders?: Record<string, string>;
39
40
  /** Image placeholders to be replaced in stories (optional)
40
41
  * @see https://docs.inappstory.com/sdk-guides/js-sdk/placeholders.html
41
- * @example
42
+ * @example
42
43
  * imagePlaceholders: {
43
44
  * "your-image-placeholder-key": "value"
44
45
  * }
@@ -146,10 +147,10 @@ export declare class StoryManager {
146
147
  };
147
148
 
148
149
  */
149
- showOnboardingStories(options?: { feed?: string; customTags?: Array<string>; limit?: number }): Promise<{
150
+ showOnboardingStories(options?: { feed?: string; customTags?: string[]; limit?: number }): Promise<{
150
151
  stories: {
151
152
  title: Option<string>;
152
- tags: Array<string>;
153
+ tags: string[];
153
154
  slidesCount: Option<number>;
154
155
  ugcPayload?: Record<string, unknown>;
155
156
  id: number;
@@ -218,7 +219,10 @@ export declare class StoryManager {
218
219
  * @param listener The event handler
219
220
  * @see https://docs.inappstory.com/sdk-guides/react-sdk/events.html
220
221
  */
221
- on(eventName: string, listener: (...args: any[]) => void): this;
222
+ on<EventName extends keyof StoryManagerEvents>(
223
+ eventName: EventName,
224
+ listener: (event: StoryManagerEvents[EventName]) => void
225
+ ): this;
222
226
 
223
227
  /**
224
228
  * Subscribes to a one-time SDK event.
@@ -226,7 +230,10 @@ export declare class StoryManager {
226
230
  * @param listener The event handler
227
231
  * @see https://docs.inappstory.com/sdk-guides/react-sdk/events.html
228
232
  */
229
- once(eventName: string, listener: (...args: any[]) => void): this;
233
+ once<EventName extends keyof StoryManagerEvents>(
234
+ eventName: EventName,
235
+ listener: (event: StoryManagerEvents[EventName]) => void
236
+ ): this;
230
237
 
231
238
  /**
232
239
  * Unsubscribes from an SDK event.
@@ -234,7 +241,10 @@ export declare class StoryManager {
234
241
  * @param listener The event handler
235
242
  * @see https://docs.inappstory.com/sdk-guides/react-sdk/events.html
236
243
  */
237
- off(eventName: string, listener: (...args: any[]) => void): this;
244
+ off<EventName extends keyof StoryManagerEvents>(
245
+ eventName: EventName,
246
+ listener: (event: StoryManagerEvents[EventName]) => void
247
+ ): this;
238
248
 
239
249
  /**
240
250
  * Installs a plugin at the class level.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inappstory/react-sdk",
3
- "version": "1.8.0-rc.2",
3
+ "version": "1.8.0-rc.4",
4
4
  "description": "React SDK",
5
5
  "keywords": [
6
6
  "stories",