@tivio/sdk-react 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -1,8 +1,14 @@
1
1
  # @tivio/sdk-react
2
2
 
3
3
  ## Changelog
4
+
4
5
  * UNRELEASED
5
- *
6
+ * v3.1.0
7
+ * patch: internal refactored `useAd`, `useAdSegment`
8
+ * patch: `useAdSegment()` now returns null if no monetization is configured, ad segments are not managed in that situation
9
+ * patch: internal: fixed refactored `setUser()`
10
+ * minor: enriched `AdSegment` type from `useAdSegment()`
11
+ * minor: Added `setUser()` function for login and logout
6
12
  * v3.0.0
7
13
  * minor: Added hook useWatchWithoutAdsOffer to trigger purchase dialog to "watch without ads", if available
8
14
  * patch: fix peerDependency declaration for react, react-dom
@@ -104,9 +110,24 @@ function App({children}) {
104
110
  }
105
111
  ```
106
112
 
107
- ### Usage with authorization
113
+ ## Authentication
114
+
115
+ A logged-in user can access more features, such as making purchases. In order to authenticate a user with Tivio, use the `setUser()` method.
116
+
117
+ Verification of the user against 3rd party auth servers is implemented per customer.
118
+
119
+ ```typescript
120
+ import { setUser } from '@tivio/sdk-react'
121
+
122
+ // Log in
108
123
 
109
- // TODO
124
+ // Payload is specific per customer
125
+ // A common use-case is sending an auth token inside the payload, which Tivio can use to verify the user
126
+ await setUser('userId', { token: 'xxx'})
127
+
128
+ // Log out
129
+ await setUser('userId', null)
130
+ ```
110
131
 
111
132
  ## Tivio widget
112
133
 
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) 2021, nangu.TV, a.s. All rights reserved.
3
3
  * nangu.TV, a.s PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
4
4
  */
5
- import type { AdSource, UsePlayerEvent } from '../../types/customPlayer.types';
5
+ import type { UsePlayerEvent } from '../../types/customPlayer.types';
6
6
  import type { BetOffer, Marker } from '../../types/types';
7
7
  export declare const usePlayerEvent: UsePlayerEvent;
8
8
  export declare const useMarkers: () => Marker[] | null;
@@ -12,12 +12,17 @@ interface IntroMarker {
12
12
  skip: () => void;
13
13
  }
14
14
  export declare const useIntro: () => IntroMarker | null;
15
- export declare const useAd: () => AdSource | null;
15
+ export declare const useAd: () => import("../../types/customPlayer.types").AdSource | null;
16
16
  export declare const useCurrentMarker: () => Marker | null;
17
17
  export declare const useSeekState: () => boolean | null;
18
- interface AdSegment {
18
+ export declare const useAdSegment: () => {
19
+ id: string;
19
20
  remainingMs: number;
21
+ secondsToEnd: number;
22
+ secondsToSkippable: number | null;
20
23
  canSeek: boolean;
21
- }
22
- export declare const useAdSegment: () => AdSegment | null;
24
+ canSkip: boolean;
25
+ isSkippable: boolean;
26
+ skip: () => any;
27
+ } | null;
23
28
  export {};
@@ -1,4 +1,4 @@
1
1
  import { QerkoTransaction } from '@tivio/common';
2
- import { Voucher } from './useTransactionPayment';
3
- declare const usePurchaseSubscription: (monetizationId: string, voucher?: Voucher | undefined) => QerkoTransaction;
2
+ import { NewVoucher } from './useTransactionPayment';
3
+ declare const usePurchaseSubscription: (monetizationId: string, voucher?: NewVoucher | undefined) => QerkoTransaction;
4
4
  export { usePurchaseSubscription, };
@@ -1,10 +1,10 @@
1
1
  import { QerkoTransaction } from '@tivio/common';
2
- declare type Voucher = {
3
- /**
4
- * Voucher expiration date as a Date object or timestamp in ms.
5
- */
2
+ /**
3
+ * TODO: Duplicate, because we can't import types from core-js.
4
+ */
5
+ declare type NewVoucher = {
6
6
  expirationDate: Date | number;
7
7
  };
8
- declare const useTransactionPayment: (videoId: string, monetizationId: string, voucher?: Voucher | undefined) => QerkoTransaction;
8
+ declare const useTransactionPayment: (videoId: string, monetizationId: string, voucher?: NewVoucher | undefined) => QerkoTransaction;
9
9
  export { useTransactionPayment, };
10
- export type { Voucher, };
10
+ export type { NewVoucher, };
@@ -1,3 +1,6 @@
1
+ /**
2
+ * TODO: Should be in core-js, we can't import types from it, though.
3
+ */
1
4
  declare type Voucher = {
2
5
  activate: () => void;
3
6
  isUsed: boolean;
@@ -6,7 +9,7 @@ declare type Voucher = {
6
9
  voucherInfo: any;
7
10
  };
8
11
  declare const useVoucher: (voucherId: string) => {
9
- activate: (() => void) | null;
12
+ activate: (() => Promise<void>) | null;
10
13
  voucher: Voucher | null;
11
14
  error: Error | null;
12
15
  };
package/dist/index.d.ts CHANGED
@@ -23,3 +23,4 @@ export { TivioGetters } from './types/bundle.types';
23
23
  export { TivioSubscriptions } from './types/bundle.types';
24
24
  export { PlayerCapability } from './types/bundle.types';
25
25
  export { Currency } from './types/bundle.types';
26
+ export { setUser } from './services/login';