@tivio/sdk-react 10.1.0 → 10.2.0

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
@@ -535,3 +535,87 @@ useTaggedVideos: (tagIds: string[], options?: SubscribeToItemsInRowOptions) => {
535
535
  error: Error | null
536
536
  }
537
537
  ```
538
+
539
+ ### useVoucher hook
540
+
541
+ Activates a voucher for the current user. Reading vouchers directly from the client is
542
+ forbidden, so the hook does not fetch the voucher — calling `activate()` invokes the
543
+ `activateVoucher` cloud function, which detects on its own whether the code is a single-use
544
+ or a multi-use voucher.
545
+
546
+ After a successful activation the `voucher` object exposes server-provided metadata
547
+ (`voucherInfo`, `videoId`, `subscriptionsToShow`) as flat attributes. Until the voucher is
548
+ initialized, `voucher` is `null`.
549
+
550
+ ```ts
551
+ /**
552
+ * Use voucher
553
+ * @param voucherId - voucher code entered by the user
554
+ */
555
+ useVoucher: (voucherId: string) => {
556
+ /**
557
+ * Triggers the `activateVoucher` cloud function for the current user.
558
+ * On success, `activationSuccess` becomes `true` and `voucher` is populated
559
+ * with the activation metadata.
560
+ */
561
+ activate: () => Promise<void>
562
+ voucher: {
563
+ organizationId: string | null
564
+ isInitialized: boolean
565
+ /** Public, server-safe metadata about the activated voucher. */
566
+ voucherInfo: VoucherInfoPublic | null
567
+ /** Set for transaction (PPV) vouchers — the unlocked video. */
568
+ videoId?: string
569
+ /** Monetizations to offer when the voucher does not fully cover the content. */
570
+ subscriptionsToShow: PurchasableMonetization[]
571
+ } | null
572
+ error: Error | BadRequestError | null
573
+ activationSuccess: boolean
574
+ }
575
+ ```
576
+
577
+ `voucherInfo` is a discriminated union by `type`:
578
+
579
+ ```ts
580
+ type VoucherInfoPublic = VoucherInfoSubscriptionPublic | VoucherInfoTransactionPublic
581
+
582
+ interface VoucherInfoBasePublic {
583
+ id: string
584
+ isExpired: boolean
585
+ status: 'NEW' | 'USED' | 'FULFILLED'
586
+ /** True when the voucher fully covers the content (no further payment needed). */
587
+ fullDiscount?: boolean
588
+ }
589
+
590
+ interface VoucherInfoSubscriptionPublic extends VoucherInfoBasePublic {
591
+ type: 'subscription'
592
+ name: string
593
+ benefits: string[]
594
+ frequency?: MONETIZATION_FREQUENCY
595
+ }
596
+
597
+ interface VoucherInfoTransactionPublic extends VoucherInfoBasePublic {
598
+ type: 'transaction'
599
+ name: string
600
+ videoId: string
601
+ cover: string
602
+ description: string
603
+ }
604
+ ```
605
+
606
+ When activation fails, `error` may be a `BadRequestError` whose `details.reason` explains why:
607
+
608
+ ```ts
609
+ type BadRequestError = Error & {
610
+ details?: {
611
+ reason?:
612
+ | 'DOES_NOT_EXIST'
613
+ | 'EXPIRED'
614
+ | 'ALREADY_USED'
615
+ | 'ALREADY_USED_BY_CURRENT_USER'
616
+ | 'LIMIT_REACHED'
617
+ | 'FULFILLED'
618
+ | 'INVALID_VOUCHER_TYPE'
619
+ }
620
+ }
621
+ ```
package/README.md.bak CHANGED
@@ -535,3 +535,87 @@ useTaggedVideos: (tagIds: string[], options?: SubscribeToItemsInRowOptions) => {
535
535
  error: Error | null
536
536
  }
537
537
  ```
538
+
539
+ ### useVoucher hook
540
+
541
+ Activates a voucher for the current user. Reading vouchers directly from the client is
542
+ forbidden, so the hook does not fetch the voucher — calling `activate()` invokes the
543
+ `activateVoucher` cloud function, which detects on its own whether the code is a single-use
544
+ or a multi-use voucher.
545
+
546
+ After a successful activation the `voucher` object exposes server-provided metadata
547
+ (`voucherInfo`, `videoId`, `subscriptionsToShow`) as flat attributes. Until the voucher is
548
+ initialized, `voucher` is `null`.
549
+
550
+ ```ts
551
+ /**
552
+ * Use voucher
553
+ * @param voucherId - voucher code entered by the user
554
+ */
555
+ useVoucher: (voucherId: string) => {
556
+ /**
557
+ * Triggers the `activateVoucher` cloud function for the current user.
558
+ * On success, `activationSuccess` becomes `true` and `voucher` is populated
559
+ * with the activation metadata.
560
+ */
561
+ activate: () => Promise<void>
562
+ voucher: {
563
+ organizationId: string | null
564
+ isInitialized: boolean
565
+ /** Public, server-safe metadata about the activated voucher. */
566
+ voucherInfo: VoucherInfoPublic | null
567
+ /** Set for transaction (PPV) vouchers — the unlocked video. */
568
+ videoId?: string
569
+ /** Monetizations to offer when the voucher does not fully cover the content. */
570
+ subscriptionsToShow: PurchasableMonetization[]
571
+ } | null
572
+ error: Error | BadRequestError | null
573
+ activationSuccess: boolean
574
+ }
575
+ ```
576
+
577
+ `voucherInfo` is a discriminated union by `type`:
578
+
579
+ ```ts
580
+ type VoucherInfoPublic = VoucherInfoSubscriptionPublic | VoucherInfoTransactionPublic
581
+
582
+ interface VoucherInfoBasePublic {
583
+ id: string
584
+ isExpired: boolean
585
+ status: 'NEW' | 'USED' | 'FULFILLED'
586
+ /** True when the voucher fully covers the content (no further payment needed). */
587
+ fullDiscount?: boolean
588
+ }
589
+
590
+ interface VoucherInfoSubscriptionPublic extends VoucherInfoBasePublic {
591
+ type: 'subscription'
592
+ name: string
593
+ benefits: string[]
594
+ frequency?: MONETIZATION_FREQUENCY
595
+ }
596
+
597
+ interface VoucherInfoTransactionPublic extends VoucherInfoBasePublic {
598
+ type: 'transaction'
599
+ name: string
600
+ videoId: string
601
+ cover: string
602
+ description: string
603
+ }
604
+ ```
605
+
606
+ When activation fails, `error` may be a `BadRequestError` whose `details.reason` explains why:
607
+
608
+ ```ts
609
+ type BadRequestError = Error & {
610
+ details?: {
611
+ reason?:
612
+ | 'DOES_NOT_EXIST'
613
+ | 'EXPIRED'
614
+ | 'ALREADY_USED'
615
+ | 'ALREADY_USED_BY_CURRENT_USER'
616
+ | 'LIMIT_REACHED'
617
+ | 'FULFILLED'
618
+ | 'INVALID_VOUCHER_TYPE'
619
+ }
620
+ }
621
+ ```
package/dist/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import type { ComponentType } from 'react';
2
2
  import { DocumentReference } from '@firebase/firestore-types';
3
3
  import type duration from 'dayjs/plugin/duration';
4
- import type { default as firebase_2 } from '@firebase/app-types';
5
- import type { default as firebase_3 } from 'firebase';
4
+ import type firebase from '@firebase/app-types';
6
5
  import { FunctionComponentElement } from 'react';
7
6
  import type { GeoPoint } from '@firebase/firestore-types';
8
7
  import { OperatingSystem } from 'detect-browser';
@@ -26,7 +25,22 @@ export declare interface ActivatedPromotionsWithIdsResponse {
26
25
  activatedPromotionsIds: string[];
27
26
  }
28
27
 
29
- export declare type ActivateVoucherResponse = string | ActivatedPromotionsResponse | ActivatedPromotionsWithIdsResponse;
28
+ /**
29
+ * Response returned when `activateVoucher` is called with `responseFormat: 'extended'`.
30
+ *
31
+ * It always carries `voucherInfo` (safe server-side metadata) and, depending on the
32
+ * voucher type, either a `purchaseId` (transaction / subscription) or the list of
33
+ * `activatedPromotions` (promotion voucher).
34
+ */
35
+ export declare interface ActivateVoucherExtendedResponse {
36
+ voucherInfo: VoucherInfoPublic;
37
+ purchaseId?: string;
38
+ activatedPromotions?: ActivatedPromotion[];
39
+ }
40
+
41
+ export declare type ActivateVoucherResponse = string | ActivatedPromotionsResponse | ActivatedPromotionsWithIdsResponse | ActivateVoucherExtendedResponse;
42
+
43
+ export declare type ActivateVoucherResponseFormat = 'legacy' | 'extended';
30
44
 
31
45
  declare interface actualPriceDetails {
32
46
  amountCents: number;
@@ -599,7 +613,7 @@ export declare interface AvatarProps {
599
613
  */
600
614
  export declare type BadRequestError = Error & {
601
615
  details?: {
602
- reason?: 'DOES_NOT_EXIST' | 'EXPIRED' | 'ALREADY_USED' | 'ALREADY_USED_BY_CURRENT_USER';
616
+ reason?: 'DOES_NOT_EXIST' | 'EXPIRED' | 'ALREADY_USED' | 'ALREADY_USED_BY_CURRENT_USER' | 'LIMIT_REACHED' | 'FULFILLED' | 'INVALID_VOUCHER_TYPE';
603
617
  };
604
618
  };
605
619
 
@@ -1456,7 +1470,9 @@ export declare enum CustomerId {
1456
1470
  THE_JOHNY = "THE_JOHNY",
1457
1471
  GOOD_MOVE = "GOOD_MOVE",
1458
1472
  JANA_HANZ = "JANA_HANZ",
1459
- MYSTICO = "MYSTICO"
1473
+ MYSTICO = "MYSTICO",
1474
+ MORAVEC = "MORAVEC",
1475
+ JAN_TUNA = "JAN_TUNA"
1460
1476
  }
1461
1477
 
1462
1478
  export declare interface CustomScript {
@@ -3227,6 +3243,16 @@ export declare interface MonetizationCardProps {
3227
3243
  focused?: boolean;
3228
3244
  }
3229
3245
 
3246
+ /**
3247
+ * @public
3248
+ */
3249
+ export declare type MonetizationCta = {
3250
+ type: 'email';
3251
+ payload: {
3252
+ email: string;
3253
+ };
3254
+ };
3255
+
3230
3256
  export declare interface MonetizationsCountsSummaryItem {
3231
3257
  /**
3232
3258
  * Unix timestamp at which the data is aggregated
@@ -4617,6 +4643,11 @@ export declare interface PubSub {
4617
4643
  * @public
4618
4644
  */
4619
4645
  export declare interface PurchasableMonetization extends Monetization {
4646
+ /**
4647
+ * If CTA is configured, the monetization should not be directly purchasable in clients.
4648
+ * Client apps should render CTA action instead of purchase button.
4649
+ */
4650
+ cta?: MonetizationCta;
4620
4651
  /**
4621
4652
  * Price before any discounts (e.g. promotions).
4622
4653
  */
@@ -6594,14 +6625,6 @@ export declare type SubscribeToTaggedVideosOptions = Omit<SubscribeToItemsInRowO
6594
6625
  orderBy?: OrderBy<TaggedVideosOrderByField>[];
6595
6626
  };
6596
6627
 
6597
- declare interface SubscriptionInfo {
6598
- id: string;
6599
- type: 'subscription';
6600
- name: string;
6601
- benefits: string[];
6602
- frequency: string;
6603
- }
6604
-
6605
6628
  /**
6606
6629
  * Extended language codes for subtitle tracks.
6607
6630
  * Includes all LangCode values plus additional languages only needed for subtitles.
@@ -6984,7 +7007,7 @@ export declare interface TivioConfig {
6984
7007
  debug?: boolean;
6985
7008
  verbose?: boolean;
6986
7009
  firebaseApp?: any | null;
6987
- firebaseFactory?: (config: object, appName?: string) => firebase_2.FirebaseApp;
7010
+ firebaseFactory?: (config: object, appName?: string) => firebase.FirebaseApp;
6988
7011
  authDomainOverride?: string;
6989
7012
  /**
6990
7013
  * @deprecated this field is no longer in use and has no impact when set.
@@ -7113,7 +7136,7 @@ export declare type TivioHooks = {
7113
7136
  data: Video | null;
7114
7137
  error: string | null;
7115
7138
  };
7116
- useVoucher: (voucherId: string) => any;
7139
+ useVoucher: (voucherId: string) => UseVoucherReturn;
7117
7140
  useApplyInviteCode: () => {
7118
7141
  applyInviteCodeResult?: boolean;
7119
7142
  loading: boolean;
@@ -7356,7 +7379,7 @@ export declare type TivioReactBundle = {
7356
7379
  }, email?: string) => Promise<QerkoPaymentInfo>;
7357
7380
  purchaseSubscriptionWithQerko: (monetizationId: string, voucher?: {
7358
7381
  expirationDate: Date;
7359
- }) => Promise<QerkoPaymentInfo>;
7382
+ }, email?: string, quantity?: number) => Promise<QerkoPaymentInfo>;
7360
7383
  cancelSubscriptionWithQerko: (subscriptionId: string) => Promise<QerkoCancellationInfo>;
7361
7384
  showConsentPreferences: () => void;
7362
7385
  /**
@@ -7465,17 +7488,6 @@ export declare interface Track {
7465
7488
  language: LangCode;
7466
7489
  }
7467
7490
 
7468
- declare interface TransactionInfo {
7469
- id: string;
7470
- type: 'transaction';
7471
- name: string;
7472
- videoId: string;
7473
- cover: string;
7474
- description: string;
7475
- promotions?: firebase_3.firestore.DocumentReference<Promotion>[];
7476
- fullDiscount?: boolean;
7477
- }
7478
-
7479
7491
  /**
7480
7492
  * Represents one string in every supported language mutation.
7481
7493
  * @public
@@ -8324,19 +8336,28 @@ export declare const useVideo: (videoIdOrUrlName?: string) => {
8324
8336
  /**
8325
8337
  * @public
8326
8338
  */
8327
- export declare const useVoucher: (voucherId: string) => {
8328
- activate: (() => Promise<void>) | null;
8329
- voucher: Voucher | null;
8330
- /**
8331
- * You can check error.details if you need to know error type when you want your own error messages
8332
- * (can be one of "DOES_NOT_EXIST", "EXPIRED", "ALREADY_USED_BY_CURRENT_USER" and "ALREADY_USED").
8333
- */
8334
- error: Error | BadRequestError | null;
8335
- /**
8336
- * True if voucher has been successfully activated in current session.
8337
- */
8339
+ export declare const useVoucher: (voucherId: string) => UseVoucherReturn;
8340
+
8341
+ /**
8342
+ * Return type of `useVoucher` hook (core-react / sdk-react).
8343
+ *
8344
+ * Activation is triggered via the top-level `activate`. After a successful activation
8345
+ * `voucher` carries the server-provided metadata (`voucherInfo`, `videoId`,
8346
+ * `subscriptionsToShow`) as flat attributes. While the voucher is still initializing,
8347
+ * `voucher` is `null`.
8348
+ */
8349
+ export declare interface UseVoucherReturn {
8350
+ activate: () => Promise<void>;
8351
+ voucher: {
8352
+ organizationId: string | null;
8353
+ isInitialized: boolean;
8354
+ voucherInfo: VoucherInfoPublic | null;
8355
+ videoId?: string;
8356
+ subscriptionsToShow: PurchasableMonetization[];
8357
+ } | null;
8358
+ error: Error | null;
8338
8359
  activationSuccess: boolean;
8339
- };
8360
+ }
8340
8361
 
8341
8362
  /**
8342
8363
  * @public
@@ -8970,15 +8991,30 @@ export declare interface VodTivioSourceParams extends PlayerSourceParams<SourceT
8970
8991
  sessionId?: string;
8971
8992
  }
8972
8993
 
8973
- /**
8974
- * TODO: Should be in core-js, we can't import types from it, though.
8975
- */
8976
- declare interface Voucher {
8977
- activate: () => void;
8978
- isUsed: boolean;
8994
+ export declare interface VoucherInfoBasePublic {
8995
+ id: string;
8979
8996
  isExpired: boolean;
8980
- status: 'NEW' | 'USED';
8981
- voucherInfo: SubscriptionInfo | TransactionInfo;
8997
+ status: VoucherInfoPublicStatus;
8998
+ fullDiscount?: boolean;
8999
+ }
9000
+
9001
+ export declare type VoucherInfoPublic = VoucherInfoSubscriptionPublic | VoucherInfoTransactionPublic;
9002
+
9003
+ export declare type VoucherInfoPublicStatus = 'NEW' | 'USED' | 'FULFILLED';
9004
+
9005
+ export declare interface VoucherInfoSubscriptionPublic extends VoucherInfoBasePublic {
9006
+ type: 'subscription';
9007
+ name: string;
9008
+ benefits: string[];
9009
+ frequency?: MONETIZATION_FREQUENCY;
9010
+ }
9011
+
9012
+ export declare interface VoucherInfoTransactionPublic extends VoucherInfoBasePublic {
9013
+ type: 'transaction';
9014
+ name: string;
9015
+ videoId: string;
9016
+ cover: string;
9017
+ description: string;
8982
9018
  }
8983
9019
 
8984
9020
  declare interface VoucherPageConfiguration {