@tivio/sdk-react 9.2.0 → 9.3.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.
package/README.md CHANGED
@@ -52,6 +52,301 @@ await setUser('userId', { token: 'xxx'})
52
52
  await setUser(null)
53
53
  ```
54
54
 
55
+ ### Create user with email and password
56
+
57
+ Returns user's firebase uid or null if error occurs
58
+
59
+ ```typescript
60
+ tivio.createUserWithEmailAndPassword(email: string, password: string, username: string, phoneNumber?: string | undefined): Promise<string | null>
61
+ ```
62
+ **Example**
63
+ ```typescript
64
+ await tivio.createUserWithEmailAndPassword('test@example.com', 'password', 'Fist & Last Name', '+420777123456')
65
+ ```
66
+
67
+ ### Sign in with email and password
68
+
69
+ Returns user's firebase uid or null if error occurs
70
+
71
+ ```typescript
72
+ tivio.signInWithEmailAndPassword(email: string, password: string): Promise<string | null>
73
+ ```
74
+ **Example**
75
+ ```typescript
76
+ await tivio.signInWithEmailAndPassword('test@example.com', 'password')
77
+ ```
78
+
79
+ ### Sign out
80
+
81
+ ```typescript
82
+ tivio.signOut(): Promise<void>
83
+ ```
84
+
85
+ ### Reset password
86
+
87
+ Send email with password reset link to the user with given email address
88
+
89
+ ```typescript
90
+ tivio.resetPassword(email: string): Promise<void>
91
+ ```
92
+
93
+ ## User entity
94
+
95
+ ### Get user
96
+
97
+ Returns user object or null if user is not authenticated
98
+
99
+ ```typescript
100
+ tivio.getUser(): Promise<User | null>
101
+ ```
102
+
103
+ ### Essential Properties
104
+
105
+ #### Basic Information
106
+ - `id: string` - Unique Tivio user ID
107
+ - `email?: string` - Email address
108
+ - `name?: string` - Display name - could be nickname, first name and last name, etc.
109
+
110
+ #### Authentication Status
111
+ - `isSignedIn: boolean` - Whether the user is currently signed in
112
+ - `isReady: boolean` - Whether user data is fully loaded
113
+ - `isAnonymous: boolean` - Whether this is an anonymous user
114
+
115
+ #### Content & Preferences
116
+ - `purchases: Purchase[]` - Active purchases (excluding vouchers)
117
+
118
+ #### User Profiles
119
+ - `profiles: UserProfile[]` - Available user profiles (e.g. multiple people can use the same user account with different preferences)
120
+ - `activeUserProfileId: string | null` - Currently active profile
121
+
122
+ ### Essential Methods
123
+
124
+ #### Authentication
125
+ ```typescript
126
+ changePassword(oldPassword: string, newPassword: string): Promise<void>
127
+ ```
128
+
129
+ #### Profile Management
130
+
131
+ #### Create user profile
132
+
133
+ ```typescript
134
+ interface CreateUserProfileRequest {
135
+ /**
136
+ * Profile name - typically first name and last name, but users can fill in whatever they want.
137
+ */
138
+ name: string
139
+ /**
140
+ * Filled in values for user profile survey. See {@link OrganizationDocument} its configuration.
141
+ */
142
+ survey?: ProfileSurvey
143
+ }
144
+ interface ProfileSurvey {
145
+ gender?: Translation
146
+ age?: AgeRange
147
+ }
148
+ interface AgeRange {
149
+ from: number
150
+ /**
151
+ * If not set, we assume the range is not closed and {@property to} is set to infinity
152
+ * (there are no values to represent {@link Infinity} in firestore, so we use undefined instead).
153
+ */
154
+ to?: number
155
+ /**
156
+ * If set, we assume that this is a profile for kids only (e.g. 0-12).
157
+ * This value can only be `true` or not specified (undefined).
158
+ */
159
+ kidsOnly?: true
160
+ }
161
+ createUserProfile(request: CreateUserProfileRequest): Promise<void>
162
+ ```
163
+ **Example**
164
+ ```typescript
165
+ await user.createUserProfile({
166
+ name: 'John Doe',
167
+ survey: {
168
+ gender: {
169
+ cs: "Žena",
170
+ en: "Female",
171
+ sk: "Žena"
172
+ },
173
+ age: {
174
+ from: 18,
175
+ to: 24
176
+ }
177
+ }
178
+ })
179
+ ```
180
+
181
+ #### Set active user profile
182
+
183
+ ```typescript
184
+ user.setActiveUserProfileId(profileId: string): void
185
+ ```
186
+
187
+ #### Delete user profile
188
+
189
+ ```typescript
190
+ user.deleteUserProfile(profileId: string): Promise<void>
191
+ ```
192
+
193
+ ## Content
194
+
195
+ ### Assets
196
+
197
+ In order to obtain assets (images) from a Video or Tag, you can use these methods:
198
+
199
+ #### Video or Tag
200
+ - `video.cover` - cover image (landscape)
201
+ - `video.banner` - banner image
202
+ - `video.circled` - circled image
203
+ - `video.detailBanner` - detail banner image (landscape)
204
+ - `video.portrait` - portrait image (portrait)
205
+
206
+ #### Tag only
207
+ - `tag.bannerMobile` - banner image mobile
208
+
209
+ __All of the assets fallback to type cover or empty string if cover is not available__
210
+
211
+ ### Get content based on user profile
212
+
213
+ ```typescript
214
+ interface GetUserProfileDataOptions {
215
+ /**
216
+ * If true, the data will be returned for all user profiles.
217
+ * If false, the data will be returned only for the active user profile.
218
+ */
219
+ ignoreActiveUserProfile?: boolean
220
+ }
221
+
222
+ getFavorites(options?: GetUserProfileDataOptions): Promise<FavoriteWithData[]>
223
+ getWatchPositions(options?: GetUserProfileDataOptions): Promise<WatchPositionWithData[]>
224
+ getWatchHistory(options?: GetUserProfileDataOptions): Promise<WatchPositionWithData[]>
225
+ ```
226
+
227
+ ### Get user favorites
228
+
229
+ ```typescript
230
+ interface FavoriteWithData {
231
+ content: Video | Tag
232
+ type: 'video' | 'tag' // Filtering by this type will set the content type to be Video or Tag
233
+ profileId?: string
234
+ }
235
+
236
+ getFavorites(options?: GetUserProfileDataOptions): Promise<FavoriteWithData[]>
237
+ ```
238
+ **Example**
239
+ ```typescript
240
+ const favorites = await user.getFavorites()
241
+ favorites.forEach(favorite => {
242
+ console.log({
243
+ name: favorite.name,
244
+ cover: favorite.cover, // cover image (landscape)
245
+ portrait: favorite.portrait, // portrait image (portrait)
246
+ })
247
+ })
248
+ ```
249
+
250
+ ### Get user watch positions
251
+
252
+ ```typescript
253
+ interface WatchPositionWithData {
254
+ position: number
255
+ video: Video
256
+ tag?: Tag
257
+ episodeNumber?: number
258
+ seasonNumber?: number
259
+ videoDuration?: number
260
+ }
261
+
262
+ getWatchPositions(options?: GetUserProfileDataOptions): Promise<WatchPositionWithData[]>
263
+ ```
264
+ **Example**
265
+ ```typescript
266
+ const watchPositions = await user.getWatchPositions()
267
+ watchPositions.forEach(watchPosition => {
268
+ console.log({
269
+ position: watchPosition.position, // watch position in milliseconds
270
+ videoName: watchPosition.video.name,
271
+ videoCover: watchPosition.video.cover,
272
+ tagName: watchPosition.tag?.name, // optional tag for series
273
+ episodeNumber: watchPosition.episodeNumber, // optional episode number
274
+ seasonNumber: watchPosition.seasonNumber, // optional season number
275
+ videoDuration: watchPosition.videoDuration, // optional video duration
276
+ })
277
+ })
278
+ ```
279
+
280
+ ### Get user watch history
281
+
282
+ ```typescript
283
+ getWatchHistory(options?: GetUserProfileDataOptions): Promise<WatchPositionWithData[]>
284
+ ```
285
+ **Example**
286
+ ```typescript
287
+ const watchHistory = await user.getWatchHistory()
288
+ watchHistory.forEach(watchPosition => {
289
+ console.log({
290
+ position: watchPosition.position, // watch position in milliseconds
291
+ videoName: watchPosition.video.name,
292
+ videoCover: watchPosition.video.cover,
293
+ tagName: watchPosition.tag?.name, // optional tag for series
294
+ episodeNumber: watchPosition.episodeNumber, // optional episode number
295
+ seasonNumber: watchPosition.seasonNumber, // optional season number
296
+ videoDuration: watchPosition.videoDuration, // optional video duration
297
+ })
298
+ })
299
+ ```
300
+
301
+ ### Add to/remove from favorites
302
+
303
+ Simply call addToFavorites or removeFromFavorites on the Video or Tag.
304
+ ```typescript
305
+ const video = await tivio.getVideoById('videoId')
306
+ await video.addToFavorites()
307
+ await video.removeFromFavorites()
308
+
309
+ const tag = await tivio.getTagById('tagId')
310
+ await tag.addToFavorites()
311
+ await tag.removeFromFavorites()
312
+
313
+ // Remove a favorite from favorites
314
+ const favorites = await tivio.getUser()?.favorites
315
+ favorites[0]?.removeFromFavorites()
316
+ ```
317
+
318
+ > Note: When user saves favorite without profileId, it will only be shown if the app doesn't have any active user profile.
319
+
320
+ ### Get screen by ID
321
+
322
+ ```typescript
323
+ getScreenById(screenId: string): Promise<Screen | null>
324
+ ```
325
+
326
+ ### Get row by ID
327
+
328
+ ```typescript
329
+ getRowById(rowId: string): Promise<Row | null>
330
+ ```
331
+
332
+ ### Get video by ID
333
+
334
+ ```typescript
335
+ getVideoById(videoId: string): Promise<Video | null>
336
+ ```
337
+
338
+ ### Get tag by ID
339
+
340
+ ```typescript
341
+ getTagById(tagId: string): Promise<Tag | null>
342
+ ```
343
+
344
+ ### Get TV Channel by ID
345
+
346
+ ```typescript
347
+ getTvChannelById(tvChannelId: string): Promise<TvChannel | null>
348
+ ```
349
+
55
350
  ## Player
56
351
 
57
352
  You can choose whether you will use complete player component provided by Tivio or you will wrap your existing player
package/README.md.bak CHANGED
@@ -52,6 +52,301 @@ await setUser('userId', { token: 'xxx'})
52
52
  await setUser(null)
53
53
  ```
54
54
 
55
+ ### Create user with email and password
56
+
57
+ Returns user's firebase uid or null if error occurs
58
+
59
+ ```typescript
60
+ tivio.createUserWithEmailAndPassword(email: string, password: string, username: string, phoneNumber?: string | undefined): Promise<string | null>
61
+ ```
62
+ **Example**
63
+ ```typescript
64
+ await tivio.createUserWithEmailAndPassword('test@example.com', 'password', 'Fist & Last Name', '+420777123456')
65
+ ```
66
+
67
+ ### Sign in with email and password
68
+
69
+ Returns user's firebase uid or null if error occurs
70
+
71
+ ```typescript
72
+ tivio.signInWithEmailAndPassword(email: string, password: string): Promise<string | null>
73
+ ```
74
+ **Example**
75
+ ```typescript
76
+ await tivio.signInWithEmailAndPassword('test@example.com', 'password')
77
+ ```
78
+
79
+ ### Sign out
80
+
81
+ ```typescript
82
+ tivio.signOut(): Promise<void>
83
+ ```
84
+
85
+ ### Reset password
86
+
87
+ Send email with password reset link to the user with given email address
88
+
89
+ ```typescript
90
+ tivio.resetPassword(email: string): Promise<void>
91
+ ```
92
+
93
+ ## User entity
94
+
95
+ ### Get user
96
+
97
+ Returns user object or null if user is not authenticated
98
+
99
+ ```typescript
100
+ tivio.getUser(): Promise<User | null>
101
+ ```
102
+
103
+ ### Essential Properties
104
+
105
+ #### Basic Information
106
+ - `id: string` - Unique Tivio user ID
107
+ - `email?: string` - Email address
108
+ - `name?: string` - Display name - could be nickname, first name and last name, etc.
109
+
110
+ #### Authentication Status
111
+ - `isSignedIn: boolean` - Whether the user is currently signed in
112
+ - `isReady: boolean` - Whether user data is fully loaded
113
+ - `isAnonymous: boolean` - Whether this is an anonymous user
114
+
115
+ #### Content & Preferences
116
+ - `purchases: Purchase[]` - Active purchases (excluding vouchers)
117
+
118
+ #### User Profiles
119
+ - `profiles: UserProfile[]` - Available user profiles (e.g. multiple people can use the same user account with different preferences)
120
+ - `activeUserProfileId: string | null` - Currently active profile
121
+
122
+ ### Essential Methods
123
+
124
+ #### Authentication
125
+ ```typescript
126
+ changePassword(oldPassword: string, newPassword: string): Promise<void>
127
+ ```
128
+
129
+ #### Profile Management
130
+
131
+ #### Create user profile
132
+
133
+ ```typescript
134
+ interface CreateUserProfileRequest {
135
+ /**
136
+ * Profile name - typically first name and last name, but users can fill in whatever they want.
137
+ */
138
+ name: string
139
+ /**
140
+ * Filled in values for user profile survey. See {@link OrganizationDocument} its configuration.
141
+ */
142
+ survey?: ProfileSurvey
143
+ }
144
+ interface ProfileSurvey {
145
+ gender?: Translation
146
+ age?: AgeRange
147
+ }
148
+ interface AgeRange {
149
+ from: number
150
+ /**
151
+ * If not set, we assume the range is not closed and {@property to} is set to infinity
152
+ * (there are no values to represent {@link Infinity} in firestore, so we use undefined instead).
153
+ */
154
+ to?: number
155
+ /**
156
+ * If set, we assume that this is a profile for kids only (e.g. 0-12).
157
+ * This value can only be `true` or not specified (undefined).
158
+ */
159
+ kidsOnly?: true
160
+ }
161
+ createUserProfile(request: CreateUserProfileRequest): Promise<void>
162
+ ```
163
+ **Example**
164
+ ```typescript
165
+ await user.createUserProfile({
166
+ name: 'John Doe',
167
+ survey: {
168
+ gender: {
169
+ cs: "Žena",
170
+ en: "Female",
171
+ sk: "Žena"
172
+ },
173
+ age: {
174
+ from: 18,
175
+ to: 24
176
+ }
177
+ }
178
+ })
179
+ ```
180
+
181
+ #### Set active user profile
182
+
183
+ ```typescript
184
+ user.setActiveUserProfileId(profileId: string): void
185
+ ```
186
+
187
+ #### Delete user profile
188
+
189
+ ```typescript
190
+ user.deleteUserProfile(profileId: string): Promise<void>
191
+ ```
192
+
193
+ ## Content
194
+
195
+ ### Assets
196
+
197
+ In order to obtain assets (images) from a Video or Tag, you can use these methods:
198
+
199
+ #### Video or Tag
200
+ - `video.cover` - cover image (landscape)
201
+ - `video.banner` - banner image
202
+ - `video.circled` - circled image
203
+ - `video.detailBanner` - detail banner image (landscape)
204
+ - `video.portrait` - portrait image (portrait)
205
+
206
+ #### Tag only
207
+ - `tag.bannerMobile` - banner image mobile
208
+
209
+ __All of the assets fallback to type cover or empty string if cover is not available__
210
+
211
+ ### Get content based on user profile
212
+
213
+ ```typescript
214
+ interface GetUserProfileDataOptions {
215
+ /**
216
+ * If true, the data will be returned for all user profiles.
217
+ * If false, the data will be returned only for the active user profile.
218
+ */
219
+ ignoreActiveUserProfile?: boolean
220
+ }
221
+
222
+ getFavorites(options?: GetUserProfileDataOptions): Promise<FavoriteWithData[]>
223
+ getWatchPositions(options?: GetUserProfileDataOptions): Promise<WatchPositionWithData[]>
224
+ getWatchHistory(options?: GetUserProfileDataOptions): Promise<WatchPositionWithData[]>
225
+ ```
226
+
227
+ ### Get user favorites
228
+
229
+ ```typescript
230
+ interface FavoriteWithData {
231
+ content: Video | Tag
232
+ type: 'video' | 'tag' // Filtering by this type will set the content type to be Video or Tag
233
+ profileId?: string
234
+ }
235
+
236
+ getFavorites(options?: GetUserProfileDataOptions): Promise<FavoriteWithData[]>
237
+ ```
238
+ **Example**
239
+ ```typescript
240
+ const favorites = await user.getFavorites()
241
+ favorites.forEach(favorite => {
242
+ console.log({
243
+ name: favorite.name,
244
+ cover: favorite.cover, // cover image (landscape)
245
+ portrait: favorite.portrait, // portrait image (portrait)
246
+ })
247
+ })
248
+ ```
249
+
250
+ ### Get user watch positions
251
+
252
+ ```typescript
253
+ interface WatchPositionWithData {
254
+ position: number
255
+ video: Video
256
+ tag?: Tag
257
+ episodeNumber?: number
258
+ seasonNumber?: number
259
+ videoDuration?: number
260
+ }
261
+
262
+ getWatchPositions(options?: GetUserProfileDataOptions): Promise<WatchPositionWithData[]>
263
+ ```
264
+ **Example**
265
+ ```typescript
266
+ const watchPositions = await user.getWatchPositions()
267
+ watchPositions.forEach(watchPosition => {
268
+ console.log({
269
+ position: watchPosition.position, // watch position in milliseconds
270
+ videoName: watchPosition.video.name,
271
+ videoCover: watchPosition.video.cover,
272
+ tagName: watchPosition.tag?.name, // optional tag for series
273
+ episodeNumber: watchPosition.episodeNumber, // optional episode number
274
+ seasonNumber: watchPosition.seasonNumber, // optional season number
275
+ videoDuration: watchPosition.videoDuration, // optional video duration
276
+ })
277
+ })
278
+ ```
279
+
280
+ ### Get user watch history
281
+
282
+ ```typescript
283
+ getWatchHistory(options?: GetUserProfileDataOptions): Promise<WatchPositionWithData[]>
284
+ ```
285
+ **Example**
286
+ ```typescript
287
+ const watchHistory = await user.getWatchHistory()
288
+ watchHistory.forEach(watchPosition => {
289
+ console.log({
290
+ position: watchPosition.position, // watch position in milliseconds
291
+ videoName: watchPosition.video.name,
292
+ videoCover: watchPosition.video.cover,
293
+ tagName: watchPosition.tag?.name, // optional tag for series
294
+ episodeNumber: watchPosition.episodeNumber, // optional episode number
295
+ seasonNumber: watchPosition.seasonNumber, // optional season number
296
+ videoDuration: watchPosition.videoDuration, // optional video duration
297
+ })
298
+ })
299
+ ```
300
+
301
+ ### Add to/remove from favorites
302
+
303
+ Simply call addToFavorites or removeFromFavorites on the Video or Tag.
304
+ ```typescript
305
+ const video = await tivio.getVideoById('videoId')
306
+ await video.addToFavorites()
307
+ await video.removeFromFavorites()
308
+
309
+ const tag = await tivio.getTagById('tagId')
310
+ await tag.addToFavorites()
311
+ await tag.removeFromFavorites()
312
+
313
+ // Remove a favorite from favorites
314
+ const favorites = await tivio.getUser()?.favorites
315
+ favorites[0]?.removeFromFavorites()
316
+ ```
317
+
318
+ > Note: When user saves favorite without profileId, it will only be shown if the app doesn't have any active user profile.
319
+
320
+ ### Get screen by ID
321
+
322
+ ```typescript
323
+ getScreenById(screenId: string): Promise<Screen | null>
324
+ ```
325
+
326
+ ### Get row by ID
327
+
328
+ ```typescript
329
+ getRowById(rowId: string): Promise<Row | null>
330
+ ```
331
+
332
+ ### Get video by ID
333
+
334
+ ```typescript
335
+ getVideoById(videoId: string): Promise<Video | null>
336
+ ```
337
+
338
+ ### Get tag by ID
339
+
340
+ ```typescript
341
+ getTagById(tagId: string): Promise<Tag | null>
342
+ ```
343
+
344
+ ### Get TV Channel by ID
345
+
346
+ ```typescript
347
+ getTvChannelById(tvChannelId: string): Promise<TvChannel | null>
348
+ ```
349
+
55
350
  ## Player
56
351
 
57
352
  You can choose whether you will use complete player component provided by Tivio or you will wrap your existing player