@rovenue/react-native-sdk 0.23.1 → 0.26.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/android/src/main/java/dev/rovenue/sdkrn/RovenueModule.kt +97 -3
- package/dist/chunk-BORMJJTI.js +7 -0
- package/dist/{chunk-GQB7N5CJ.js.map → chunk-BORMJJTI.js.map} +1 -1
- package/dist/index.cjs +82 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +122 -15
- package/dist/index.d.ts +122 -15
- package/dist/index.js +81 -3
- package/dist/index.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.mts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/ios/PrivacyInfo.xcprivacy +17 -0
- package/ios/RovenueModule.swift +111 -3
- package/package.json +1 -1
- package/dist/chunk-GQB7N5CJ.js +0 -7
package/dist/index.d.mts
CHANGED
|
@@ -236,7 +236,7 @@ interface TrackParams {
|
|
|
236
236
|
*/
|
|
237
237
|
declare function track(eventType: string, params?: TrackParams): Promise<void>;
|
|
238
238
|
|
|
239
|
-
declare const ERROR_KINDS: readonly ["NetworkUnavailable", "Timeout", "RateLimited", "ServerError", "InvalidApiKey", "Forbidden", "NotFound", "InvalidRequest", "Conflict", "InvalidArgument", "SandboxKeyInRelease", "InsufficientCredits", "FunnelTokenNotFound", "FunnelTokenExpired", "FunnelTokenAlreadyClaimed", "FunnelConfigUnsupported", "FunnelInvalid", "SubscriberUnresolvable", "PurchaseCanceled", "ProductNotAvailable", "AlreadyOwned", "PaymentDeclined", "StoreServiceUnavailable", "Ineligible", "ReceiptInvalid", "StoreProblem", "Storage", "Internal"];
|
|
239
|
+
declare const ERROR_KINDS: readonly ["NetworkUnavailable", "Timeout", "RateLimited", "ServerError", "InvalidApiKey", "Forbidden", "NotFound", "InvalidRequest", "Conflict", "InvalidArgument", "SandboxKeyInRelease", "InsufficientCredits", "FunnelTokenNotFound", "FunnelTokenExpired", "FunnelTokenAlreadyClaimed", "FunnelConfigUnsupported", "FunnelInvalid", "SubscriberUnresolvable", "IdentityTokenInvalid", "PurchaseCanceled", "ProductNotAvailable", "AlreadyOwned", "PaymentDeclined", "StoreServiceUnavailable", "Ineligible", "ReceiptInvalid", "StoreProblem", "Storage", "Internal"];
|
|
240
240
|
type ErrorKind = (typeof ERROR_KINDS)[number];
|
|
241
241
|
interface ErrorExtras {
|
|
242
242
|
serverCode?: string;
|
|
@@ -370,20 +370,29 @@ declare function configure(opts: RovenueConfig): void;
|
|
|
370
370
|
*/
|
|
371
371
|
declare function currentUser(): Promise<User>;
|
|
372
372
|
/**
|
|
373
|
-
* Link the anonymous device identity to `appUserId`.
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
373
|
+
* Link the anonymous device identity to `appUserId`.
|
|
374
|
+
*
|
|
375
|
+
* `identityToken` vouches for `appUserId`: your backend mints it with the
|
|
376
|
+
* secret key (`POST /v1/identity-tokens`) for the signed-in user and hands
|
|
377
|
+
* it to the app. It is valid for 15 minutes; fetch a fresh one for each
|
|
378
|
+
* identify.
|
|
379
|
+
*
|
|
380
|
+
* The local write always succeeds; the `POST /v1/identify` to the server is
|
|
381
|
+
* best-effort — if it fails (offline/5xx) the link is retried automatically
|
|
382
|
+
* later with the same token, not surfaced as an error here. `IDENTITY_CHANGED` fires after the bind and
|
|
377
383
|
* an entitlements refresh attempt: after a delivered bind the native core
|
|
378
384
|
* fetches entitlements once (firing `ENTITLEMENTS_CHANGED` when it lands)
|
|
379
385
|
* and this promise resolves after that fetch. When the bind is not
|
|
380
386
|
* delivered (offline, server error, refused) it fires right after the
|
|
381
387
|
* local link. Rejects on
|
|
382
|
-
* validation failure (
|
|
383
|
-
*
|
|
384
|
-
*
|
|
388
|
+
* validation failure (a blank id or token), with `IdentityTokenInvalid` when
|
|
389
|
+
* the server refuses the token (expired, or minted for another user, project
|
|
390
|
+
* or environment: the bind is dropped, so identify again with a fresh
|
|
391
|
+
* token), and with `SubscriberUnresolvable` when the server cannot resolve
|
|
392
|
+
* this install's subscriber (corrupt merge history) — the local link stands,
|
|
393
|
+
* unsynced, until the data is repaired.
|
|
385
394
|
*/
|
|
386
|
-
declare function identify(appUserId: string): Promise<void>;
|
|
395
|
+
declare function identify(appUserId: string, identityToken: string): Promise<void>;
|
|
387
396
|
/**
|
|
388
397
|
* Log out the current user: mints a fresh anonymous `rovenueId` and drops
|
|
389
398
|
* `appUserId`, so the next identity starts clean — including a new Apple
|
|
@@ -478,8 +487,105 @@ declare function restorePurchases(): Promise<PurchaseResult>;
|
|
|
478
487
|
* `1` — an integrator who bundles a stale/mismatched export must see this
|
|
479
488
|
* loudly, at call time.
|
|
480
489
|
*/
|
|
490
|
+
/**
|
|
491
|
+
* Fetch a placement and warm everything its first screen draws — the
|
|
492
|
+
* placement response, the first screen's images and video posters, the
|
|
493
|
+
* store prices of its packages and its fonts — so even the first open of
|
|
494
|
+
* `<RovenueFunnelView placementId=…>` draws complete and at once. Call it at
|
|
495
|
+
* app start for the placement that shows your paywall.
|
|
496
|
+
*
|
|
497
|
+
* Never rejects: an unavailable placement or a network failure is logged
|
|
498
|
+
* natively and the open loads as it would have without it. Nothing is
|
|
499
|
+
* presented, so no funnel event is sent.
|
|
500
|
+
*
|
|
501
|
+
* @param placementId the placement identifier.
|
|
502
|
+
* @param locale the locale the funnel will open in; the device's when omitted.
|
|
503
|
+
*/
|
|
504
|
+
declare function preloadPlacement(placementId: string, locale?: string): Promise<void>;
|
|
481
505
|
declare function setFallbackPlacements(json: string): Promise<number>;
|
|
482
506
|
|
|
507
|
+
/** How a presented funnel covers the app. */
|
|
508
|
+
type FunnelPresentationStyle = "fullScreen" | "modal" | "sheet";
|
|
509
|
+
/** How a full-screen funnel enters; Reduce Motion / animations off make each a fade. */
|
|
510
|
+
type FunnelPresentationEnter = "bottom" | "side" | "fade" | "none";
|
|
511
|
+
/** A sheet height: the first page's content (`fit`, capped at `large`), half the screen, or nearly all of it. */
|
|
512
|
+
type FunnelSheetDetent = "fit" | "medium" | "large";
|
|
513
|
+
/**
|
|
514
|
+
* A present call's partial override of how the funnel's editor settings
|
|
515
|
+
* present it. A field left out keeps the funnel's own; a style changed here
|
|
516
|
+
* with no `dismissible` takes that style's default.
|
|
517
|
+
*/
|
|
518
|
+
interface FunnelPresentationOverride {
|
|
519
|
+
style?: FunnelPresentationStyle;
|
|
520
|
+
enter?: FunnelPresentationEnter;
|
|
521
|
+
detents?: FunnelSheetDetent[];
|
|
522
|
+
dismissible?: boolean;
|
|
523
|
+
closeOnPurchase?: boolean;
|
|
524
|
+
}
|
|
525
|
+
/** What `presentFunnel` takes. Every callback is optional. */
|
|
526
|
+
interface PresentFunnelOptions {
|
|
527
|
+
/** The placement identifier. */
|
|
528
|
+
placement: string;
|
|
529
|
+
/** The locale to resolve text in; the device's when omitted. */
|
|
530
|
+
locale?: string;
|
|
531
|
+
/** Overrides the funnel's own presentation, field by field. */
|
|
532
|
+
style?: FunnelPresentationOverride;
|
|
533
|
+
/**
|
|
534
|
+
* Perform the purchase of this package yourself; resolve whether it went
|
|
535
|
+
* through. Without it the SDK purchases. While it runs the funnel cannot
|
|
536
|
+
* be swiped or backed away.
|
|
537
|
+
*/
|
|
538
|
+
onPurchase?: (packageId: string) => Promise<{
|
|
539
|
+
purchased: boolean;
|
|
540
|
+
}>;
|
|
541
|
+
/** Perform a restore yourself; resolve whether it restored anything. */
|
|
542
|
+
onRestore?: () => Promise<{
|
|
543
|
+
purchased: boolean;
|
|
544
|
+
}>;
|
|
545
|
+
/**
|
|
546
|
+
* Observe a failed purchase or restore the SDK performed. The funnel stays
|
|
547
|
+
* open; a cancelled store sheet is not reported, nor is a failure of your
|
|
548
|
+
* own `onPurchase` / `onRestore`.
|
|
549
|
+
*/
|
|
550
|
+
onPurchaseError?: (error: RovenueError) => void;
|
|
551
|
+
/** A URL the funnel opens; without it, an http(s) URL opens in the browser. */
|
|
552
|
+
onUrl?: (url: string) => void;
|
|
553
|
+
/** A custom action the funnel runs: its id and its params as JSON. */
|
|
554
|
+
onCustomAction?: (action: {
|
|
555
|
+
actionId: string;
|
|
556
|
+
paramsJson: string;
|
|
557
|
+
}) => void;
|
|
558
|
+
}
|
|
559
|
+
/** What `presentFunnel` resolves with. */
|
|
560
|
+
interface FunnelPresentResult {
|
|
561
|
+
/** How it ended: finished (or closed after a purchase), closed by the visitor, or never presented. */
|
|
562
|
+
result: "completed" | "dismissed" | "unavailable";
|
|
563
|
+
/** Whether a purchase or restore succeeded while it was presented. */
|
|
564
|
+
purchased: boolean;
|
|
565
|
+
/** The entitlements and balances after the purchase; set whenever `purchased` is true. */
|
|
566
|
+
customerInfo?: PurchaseResult;
|
|
567
|
+
/** The last purchase or restore failure the SDK saw. */
|
|
568
|
+
lastError?: RovenueError;
|
|
569
|
+
/** Why nothing was presented: `alreadyPresented`, `noPresenter`, or the placement's unavailable reason. */
|
|
570
|
+
reason?: string;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Present the funnel a placement serves — natively, the way the funnel's
|
|
574
|
+
* editor settings say (full screen, modal or sheet) — and resolve when it
|
|
575
|
+
* ends. The placement is resolved first (instantly after
|
|
576
|
+
* `preloadPlacement`); nothing is presented when it serves no funnel.
|
|
577
|
+
*
|
|
578
|
+
* The SDK performs purchases and restores itself unless you pass
|
|
579
|
+
* `onPurchase` / `onRestore`, and closes after a successful one when the
|
|
580
|
+
* funnel is set to "Close after purchase". Only one funnel is presented at
|
|
581
|
+
* a time: a second call while one is up resolves `unavailable` with reason
|
|
582
|
+
* `alreadyPresented`.
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* const { result, purchased } = await presentFunnel({ placement: "paywall" });
|
|
586
|
+
*/
|
|
587
|
+
declare function presentFunnel(options: PresentFunnelOptions): Promise<FunnelPresentResult>;
|
|
588
|
+
|
|
483
589
|
/** Force an immediate fetch of the latest Remote Config from the server. */
|
|
484
590
|
declare function refreshRemoteConfig(): Promise<void>;
|
|
485
591
|
/** The whole `{ flags, experiments }` bundle, fetched from the local cache. */
|
|
@@ -496,11 +602,10 @@ declare function getExperiment(key: string): Promise<ExperimentAssignment | null
|
|
|
496
602
|
declare function getExperiments(): Promise<ExperimentAssignment[]>;
|
|
497
603
|
|
|
498
604
|
/**
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
* `AppState` changes, so most apps never need to call it directly.
|
|
605
|
+
* Override the SDK's foreground state. Not needed: the native SDK observes
|
|
606
|
+
* the app lifecycle itself — polling and the attribute/session flush run
|
|
607
|
+
* while the app is in front and pause in the background. A manual call is
|
|
608
|
+
* honoured until the next lifecycle transition.
|
|
504
609
|
*/
|
|
505
610
|
declare function setForeground(foreground: boolean): void;
|
|
506
611
|
/**
|
|
@@ -753,6 +858,8 @@ declare const Rovenue: {
|
|
|
753
858
|
readonly purchase: typeof purchase;
|
|
754
859
|
readonly restorePurchases: typeof restorePurchases;
|
|
755
860
|
readonly setFallbackPlacements: typeof setFallbackPlacements;
|
|
861
|
+
readonly preloadPlacement: typeof preloadPlacement;
|
|
862
|
+
readonly presentFunnel: typeof presentFunnel;
|
|
756
863
|
readonly track: typeof track;
|
|
757
864
|
readonly refreshRemoteConfig: typeof refreshRemoteConfig;
|
|
758
865
|
readonly getRemoteConfig: typeof getRemoteConfig;
|
|
@@ -792,4 +899,4 @@ declare const Rovenue: {
|
|
|
792
899
|
readonly addChangeListener: (cb: (event: ChangeEvent) => void) => (() => void);
|
|
793
900
|
};
|
|
794
901
|
|
|
795
|
-
export { type AttributionProvider, type ChangeEvent, type ClaimInstallParams, ERROR_KINDS, EVENT_WIRE_VERSION, type Entitlement, type ErrorExtras, type ErrorKind, type EventEnvelope, type ExperimentAssignment, type FunnelClaimResult, type FunnelCustomAction, type FunnelDraftIssue, type FunnelLoadedEvent, type FunnelScreenEvent, type FunnelUnavailableEvent, type FunnelUnavailableReason, type IdentityContext, type LogEntry, type Offering, type Offerings, type Package, type ProductType, type PurchaseResult, type RemoteConfig, Rovenue, type RovenueConfig, RovenueError, RovenueFunnelView, type RovenueFunnelViewProps, type StoreProduct, type TrackParams, type User, type VirtualCurrencyGrant, extractFunnelToken, mapNativeError, serializeEnvelope, stripUndefined, useCurrentUser, useEntitlement, useEntitlements, useExperiment, useFlag, useRemoteConfig, useVirtualCurrencies, useVirtualCurrency };
|
|
902
|
+
export { type AttributionProvider, type ChangeEvent, type ClaimInstallParams, ERROR_KINDS, EVENT_WIRE_VERSION, type Entitlement, type ErrorExtras, type ErrorKind, type EventEnvelope, type ExperimentAssignment, type FunnelClaimResult, type FunnelCustomAction, type FunnelDraftIssue, type FunnelLoadedEvent, type FunnelPresentResult, type FunnelPresentationEnter, type FunnelPresentationOverride, type FunnelPresentationStyle, type FunnelScreenEvent, type FunnelSheetDetent, type FunnelUnavailableEvent, type FunnelUnavailableReason, type IdentityContext, type LogEntry, type Offering, type Offerings, type Package, type PresentFunnelOptions, type ProductType, type PurchaseResult, type RemoteConfig, Rovenue, type RovenueConfig, RovenueError, RovenueFunnelView, type RovenueFunnelViewProps, type StoreProduct, type TrackParams, type User, type VirtualCurrencyGrant, extractFunnelToken, mapNativeError, presentFunnel, serializeEnvelope, stripUndefined, useCurrentUser, useEntitlement, useEntitlements, useExperiment, useFlag, useRemoteConfig, useVirtualCurrencies, useVirtualCurrency };
|
package/dist/index.d.ts
CHANGED
|
@@ -236,7 +236,7 @@ interface TrackParams {
|
|
|
236
236
|
*/
|
|
237
237
|
declare function track(eventType: string, params?: TrackParams): Promise<void>;
|
|
238
238
|
|
|
239
|
-
declare const ERROR_KINDS: readonly ["NetworkUnavailable", "Timeout", "RateLimited", "ServerError", "InvalidApiKey", "Forbidden", "NotFound", "InvalidRequest", "Conflict", "InvalidArgument", "SandboxKeyInRelease", "InsufficientCredits", "FunnelTokenNotFound", "FunnelTokenExpired", "FunnelTokenAlreadyClaimed", "FunnelConfigUnsupported", "FunnelInvalid", "SubscriberUnresolvable", "PurchaseCanceled", "ProductNotAvailable", "AlreadyOwned", "PaymentDeclined", "StoreServiceUnavailable", "Ineligible", "ReceiptInvalid", "StoreProblem", "Storage", "Internal"];
|
|
239
|
+
declare const ERROR_KINDS: readonly ["NetworkUnavailable", "Timeout", "RateLimited", "ServerError", "InvalidApiKey", "Forbidden", "NotFound", "InvalidRequest", "Conflict", "InvalidArgument", "SandboxKeyInRelease", "InsufficientCredits", "FunnelTokenNotFound", "FunnelTokenExpired", "FunnelTokenAlreadyClaimed", "FunnelConfigUnsupported", "FunnelInvalid", "SubscriberUnresolvable", "IdentityTokenInvalid", "PurchaseCanceled", "ProductNotAvailable", "AlreadyOwned", "PaymentDeclined", "StoreServiceUnavailable", "Ineligible", "ReceiptInvalid", "StoreProblem", "Storage", "Internal"];
|
|
240
240
|
type ErrorKind = (typeof ERROR_KINDS)[number];
|
|
241
241
|
interface ErrorExtras {
|
|
242
242
|
serverCode?: string;
|
|
@@ -370,20 +370,29 @@ declare function configure(opts: RovenueConfig): void;
|
|
|
370
370
|
*/
|
|
371
371
|
declare function currentUser(): Promise<User>;
|
|
372
372
|
/**
|
|
373
|
-
* Link the anonymous device identity to `appUserId`.
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
373
|
+
* Link the anonymous device identity to `appUserId`.
|
|
374
|
+
*
|
|
375
|
+
* `identityToken` vouches for `appUserId`: your backend mints it with the
|
|
376
|
+
* secret key (`POST /v1/identity-tokens`) for the signed-in user and hands
|
|
377
|
+
* it to the app. It is valid for 15 minutes; fetch a fresh one for each
|
|
378
|
+
* identify.
|
|
379
|
+
*
|
|
380
|
+
* The local write always succeeds; the `POST /v1/identify` to the server is
|
|
381
|
+
* best-effort — if it fails (offline/5xx) the link is retried automatically
|
|
382
|
+
* later with the same token, not surfaced as an error here. `IDENTITY_CHANGED` fires after the bind and
|
|
377
383
|
* an entitlements refresh attempt: after a delivered bind the native core
|
|
378
384
|
* fetches entitlements once (firing `ENTITLEMENTS_CHANGED` when it lands)
|
|
379
385
|
* and this promise resolves after that fetch. When the bind is not
|
|
380
386
|
* delivered (offline, server error, refused) it fires right after the
|
|
381
387
|
* local link. Rejects on
|
|
382
|
-
* validation failure (
|
|
383
|
-
*
|
|
384
|
-
*
|
|
388
|
+
* validation failure (a blank id or token), with `IdentityTokenInvalid` when
|
|
389
|
+
* the server refuses the token (expired, or minted for another user, project
|
|
390
|
+
* or environment: the bind is dropped, so identify again with a fresh
|
|
391
|
+
* token), and with `SubscriberUnresolvable` when the server cannot resolve
|
|
392
|
+
* this install's subscriber (corrupt merge history) — the local link stands,
|
|
393
|
+
* unsynced, until the data is repaired.
|
|
385
394
|
*/
|
|
386
|
-
declare function identify(appUserId: string): Promise<void>;
|
|
395
|
+
declare function identify(appUserId: string, identityToken: string): Promise<void>;
|
|
387
396
|
/**
|
|
388
397
|
* Log out the current user: mints a fresh anonymous `rovenueId` and drops
|
|
389
398
|
* `appUserId`, so the next identity starts clean — including a new Apple
|
|
@@ -478,8 +487,105 @@ declare function restorePurchases(): Promise<PurchaseResult>;
|
|
|
478
487
|
* `1` — an integrator who bundles a stale/mismatched export must see this
|
|
479
488
|
* loudly, at call time.
|
|
480
489
|
*/
|
|
490
|
+
/**
|
|
491
|
+
* Fetch a placement and warm everything its first screen draws — the
|
|
492
|
+
* placement response, the first screen's images and video posters, the
|
|
493
|
+
* store prices of its packages and its fonts — so even the first open of
|
|
494
|
+
* `<RovenueFunnelView placementId=…>` draws complete and at once. Call it at
|
|
495
|
+
* app start for the placement that shows your paywall.
|
|
496
|
+
*
|
|
497
|
+
* Never rejects: an unavailable placement or a network failure is logged
|
|
498
|
+
* natively and the open loads as it would have without it. Nothing is
|
|
499
|
+
* presented, so no funnel event is sent.
|
|
500
|
+
*
|
|
501
|
+
* @param placementId the placement identifier.
|
|
502
|
+
* @param locale the locale the funnel will open in; the device's when omitted.
|
|
503
|
+
*/
|
|
504
|
+
declare function preloadPlacement(placementId: string, locale?: string): Promise<void>;
|
|
481
505
|
declare function setFallbackPlacements(json: string): Promise<number>;
|
|
482
506
|
|
|
507
|
+
/** How a presented funnel covers the app. */
|
|
508
|
+
type FunnelPresentationStyle = "fullScreen" | "modal" | "sheet";
|
|
509
|
+
/** How a full-screen funnel enters; Reduce Motion / animations off make each a fade. */
|
|
510
|
+
type FunnelPresentationEnter = "bottom" | "side" | "fade" | "none";
|
|
511
|
+
/** A sheet height: the first page's content (`fit`, capped at `large`), half the screen, or nearly all of it. */
|
|
512
|
+
type FunnelSheetDetent = "fit" | "medium" | "large";
|
|
513
|
+
/**
|
|
514
|
+
* A present call's partial override of how the funnel's editor settings
|
|
515
|
+
* present it. A field left out keeps the funnel's own; a style changed here
|
|
516
|
+
* with no `dismissible` takes that style's default.
|
|
517
|
+
*/
|
|
518
|
+
interface FunnelPresentationOverride {
|
|
519
|
+
style?: FunnelPresentationStyle;
|
|
520
|
+
enter?: FunnelPresentationEnter;
|
|
521
|
+
detents?: FunnelSheetDetent[];
|
|
522
|
+
dismissible?: boolean;
|
|
523
|
+
closeOnPurchase?: boolean;
|
|
524
|
+
}
|
|
525
|
+
/** What `presentFunnel` takes. Every callback is optional. */
|
|
526
|
+
interface PresentFunnelOptions {
|
|
527
|
+
/** The placement identifier. */
|
|
528
|
+
placement: string;
|
|
529
|
+
/** The locale to resolve text in; the device's when omitted. */
|
|
530
|
+
locale?: string;
|
|
531
|
+
/** Overrides the funnel's own presentation, field by field. */
|
|
532
|
+
style?: FunnelPresentationOverride;
|
|
533
|
+
/**
|
|
534
|
+
* Perform the purchase of this package yourself; resolve whether it went
|
|
535
|
+
* through. Without it the SDK purchases. While it runs the funnel cannot
|
|
536
|
+
* be swiped or backed away.
|
|
537
|
+
*/
|
|
538
|
+
onPurchase?: (packageId: string) => Promise<{
|
|
539
|
+
purchased: boolean;
|
|
540
|
+
}>;
|
|
541
|
+
/** Perform a restore yourself; resolve whether it restored anything. */
|
|
542
|
+
onRestore?: () => Promise<{
|
|
543
|
+
purchased: boolean;
|
|
544
|
+
}>;
|
|
545
|
+
/**
|
|
546
|
+
* Observe a failed purchase or restore the SDK performed. The funnel stays
|
|
547
|
+
* open; a cancelled store sheet is not reported, nor is a failure of your
|
|
548
|
+
* own `onPurchase` / `onRestore`.
|
|
549
|
+
*/
|
|
550
|
+
onPurchaseError?: (error: RovenueError) => void;
|
|
551
|
+
/** A URL the funnel opens; without it, an http(s) URL opens in the browser. */
|
|
552
|
+
onUrl?: (url: string) => void;
|
|
553
|
+
/** A custom action the funnel runs: its id and its params as JSON. */
|
|
554
|
+
onCustomAction?: (action: {
|
|
555
|
+
actionId: string;
|
|
556
|
+
paramsJson: string;
|
|
557
|
+
}) => void;
|
|
558
|
+
}
|
|
559
|
+
/** What `presentFunnel` resolves with. */
|
|
560
|
+
interface FunnelPresentResult {
|
|
561
|
+
/** How it ended: finished (or closed after a purchase), closed by the visitor, or never presented. */
|
|
562
|
+
result: "completed" | "dismissed" | "unavailable";
|
|
563
|
+
/** Whether a purchase or restore succeeded while it was presented. */
|
|
564
|
+
purchased: boolean;
|
|
565
|
+
/** The entitlements and balances after the purchase; set whenever `purchased` is true. */
|
|
566
|
+
customerInfo?: PurchaseResult;
|
|
567
|
+
/** The last purchase or restore failure the SDK saw. */
|
|
568
|
+
lastError?: RovenueError;
|
|
569
|
+
/** Why nothing was presented: `alreadyPresented`, `noPresenter`, or the placement's unavailable reason. */
|
|
570
|
+
reason?: string;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Present the funnel a placement serves — natively, the way the funnel's
|
|
574
|
+
* editor settings say (full screen, modal or sheet) — and resolve when it
|
|
575
|
+
* ends. The placement is resolved first (instantly after
|
|
576
|
+
* `preloadPlacement`); nothing is presented when it serves no funnel.
|
|
577
|
+
*
|
|
578
|
+
* The SDK performs purchases and restores itself unless you pass
|
|
579
|
+
* `onPurchase` / `onRestore`, and closes after a successful one when the
|
|
580
|
+
* funnel is set to "Close after purchase". Only one funnel is presented at
|
|
581
|
+
* a time: a second call while one is up resolves `unavailable` with reason
|
|
582
|
+
* `alreadyPresented`.
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* const { result, purchased } = await presentFunnel({ placement: "paywall" });
|
|
586
|
+
*/
|
|
587
|
+
declare function presentFunnel(options: PresentFunnelOptions): Promise<FunnelPresentResult>;
|
|
588
|
+
|
|
483
589
|
/** Force an immediate fetch of the latest Remote Config from the server. */
|
|
484
590
|
declare function refreshRemoteConfig(): Promise<void>;
|
|
485
591
|
/** The whole `{ flags, experiments }` bundle, fetched from the local cache. */
|
|
@@ -496,11 +602,10 @@ declare function getExperiment(key: string): Promise<ExperimentAssignment | null
|
|
|
496
602
|
declare function getExperiments(): Promise<ExperimentAssignment[]>;
|
|
497
603
|
|
|
498
604
|
/**
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
* `AppState` changes, so most apps never need to call it directly.
|
|
605
|
+
* Override the SDK's foreground state. Not needed: the native SDK observes
|
|
606
|
+
* the app lifecycle itself — polling and the attribute/session flush run
|
|
607
|
+
* while the app is in front and pause in the background. A manual call is
|
|
608
|
+
* honoured until the next lifecycle transition.
|
|
504
609
|
*/
|
|
505
610
|
declare function setForeground(foreground: boolean): void;
|
|
506
611
|
/**
|
|
@@ -753,6 +858,8 @@ declare const Rovenue: {
|
|
|
753
858
|
readonly purchase: typeof purchase;
|
|
754
859
|
readonly restorePurchases: typeof restorePurchases;
|
|
755
860
|
readonly setFallbackPlacements: typeof setFallbackPlacements;
|
|
861
|
+
readonly preloadPlacement: typeof preloadPlacement;
|
|
862
|
+
readonly presentFunnel: typeof presentFunnel;
|
|
756
863
|
readonly track: typeof track;
|
|
757
864
|
readonly refreshRemoteConfig: typeof refreshRemoteConfig;
|
|
758
865
|
readonly getRemoteConfig: typeof getRemoteConfig;
|
|
@@ -792,4 +899,4 @@ declare const Rovenue: {
|
|
|
792
899
|
readonly addChangeListener: (cb: (event: ChangeEvent) => void) => (() => void);
|
|
793
900
|
};
|
|
794
901
|
|
|
795
|
-
export { type AttributionProvider, type ChangeEvent, type ClaimInstallParams, ERROR_KINDS, EVENT_WIRE_VERSION, type Entitlement, type ErrorExtras, type ErrorKind, type EventEnvelope, type ExperimentAssignment, type FunnelClaimResult, type FunnelCustomAction, type FunnelDraftIssue, type FunnelLoadedEvent, type FunnelScreenEvent, type FunnelUnavailableEvent, type FunnelUnavailableReason, type IdentityContext, type LogEntry, type Offering, type Offerings, type Package, type ProductType, type PurchaseResult, type RemoteConfig, Rovenue, type RovenueConfig, RovenueError, RovenueFunnelView, type RovenueFunnelViewProps, type StoreProduct, type TrackParams, type User, type VirtualCurrencyGrant, extractFunnelToken, mapNativeError, serializeEnvelope, stripUndefined, useCurrentUser, useEntitlement, useEntitlements, useExperiment, useFlag, useRemoteConfig, useVirtualCurrencies, useVirtualCurrency };
|
|
902
|
+
export { type AttributionProvider, type ChangeEvent, type ClaimInstallParams, ERROR_KINDS, EVENT_WIRE_VERSION, type Entitlement, type ErrorExtras, type ErrorKind, type EventEnvelope, type ExperimentAssignment, type FunnelClaimResult, type FunnelCustomAction, type FunnelDraftIssue, type FunnelLoadedEvent, type FunnelPresentResult, type FunnelPresentationEnter, type FunnelPresentationOverride, type FunnelPresentationStyle, type FunnelScreenEvent, type FunnelSheetDetent, type FunnelUnavailableEvent, type FunnelUnavailableReason, type IdentityContext, type LogEntry, type Offering, type Offerings, type Package, type PresentFunnelOptions, type ProductType, type PurchaseResult, type RemoteConfig, Rovenue, type RovenueConfig, RovenueError, RovenueFunnelView, type RovenueFunnelViewProps, type StoreProduct, type TrackParams, type User, type VirtualCurrencyGrant, extractFunnelToken, mapNativeError, presentFunnel, serializeEnvelope, stripUndefined, useCurrentUser, useEntitlement, useEntitlements, useExperiment, useFlag, useRemoteConfig, useVirtualCurrencies, useVirtualCurrency };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SDK_VERSION
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-BORMJJTI.js";
|
|
4
4
|
|
|
5
5
|
// src/events.ts
|
|
6
6
|
var EVENT_WIRE_VERSION = 1;
|
|
@@ -51,6 +51,10 @@ var ERROR_KINDS = [
|
|
|
51
51
|
// The server cannot resolve this device's subscriber (corrupt merge
|
|
52
52
|
// chain, backend SUBSCRIBER_UNRESOLVABLE). Terminal: not retryable.
|
|
53
53
|
"SubscriberUnresolvable",
|
|
54
|
+
// The server refused the identity token identify() sent (backend
|
|
55
|
+
// IDENTITY_TOKEN_INVALID, 401): expired, or minted for another user,
|
|
56
|
+
// project or environment. Not retryable: identify again with a fresh token.
|
|
57
|
+
"IdentityTokenInvalid",
|
|
54
58
|
"PurchaseCanceled",
|
|
55
59
|
"ProductNotAvailable",
|
|
56
60
|
"AlreadyOwned",
|
|
@@ -523,8 +527,8 @@ async function call2(fn) {
|
|
|
523
527
|
async function currentUser() {
|
|
524
528
|
return call2(() => getNative().currentUser());
|
|
525
529
|
}
|
|
526
|
-
async function identify(appUserId) {
|
|
527
|
-
return call2(() => getNative().identify(appUserId));
|
|
530
|
+
async function identify(appUserId, identityToken) {
|
|
531
|
+
return call2(() => getNative().identify(appUserId, identityToken));
|
|
528
532
|
}
|
|
529
533
|
async function logOut() {
|
|
530
534
|
return call2(() => getNative().logOut());
|
|
@@ -667,10 +671,81 @@ async function call6(fn) {
|
|
|
667
671
|
throw fromNativeError(e);
|
|
668
672
|
}
|
|
669
673
|
}
|
|
674
|
+
async function preloadPlacement(placementId, locale) {
|
|
675
|
+
try {
|
|
676
|
+
await getNative().preloadPlacement(placementId, locale ?? null);
|
|
677
|
+
} catch {
|
|
678
|
+
}
|
|
679
|
+
}
|
|
670
680
|
async function setFallbackPlacements(json) {
|
|
671
681
|
return call6(() => getNative().setFallbackPlacements(json));
|
|
672
682
|
}
|
|
673
683
|
|
|
684
|
+
// src/api/present-funnel.ts
|
|
685
|
+
var FUNNEL_PRESENT_EVENT = "onFunnelPresentEvent";
|
|
686
|
+
var presentationSerial = 0;
|
|
687
|
+
function toError(dto) {
|
|
688
|
+
const mapped = fromNativeError(Object.assign(new Error(dto.message), { code: dto.kind }));
|
|
689
|
+
if (mapped instanceof RovenueError) {
|
|
690
|
+
return new RovenueError(mapped.kind, dto.message, {
|
|
691
|
+
serverCode: dto.serverCode ?? void 0,
|
|
692
|
+
httpStatus: dto.httpStatus ?? void 0,
|
|
693
|
+
retryable: dto.retryable
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
return new RovenueError("Internal", dto.message);
|
|
697
|
+
}
|
|
698
|
+
async function presentFunnel(options) {
|
|
699
|
+
const native = getNative();
|
|
700
|
+
presentationSerial += 1;
|
|
701
|
+
const presentationId = `p${Date.now().toString(36)}${presentationSerial}`;
|
|
702
|
+
const subscription3 = getEmitter().addListener(FUNNEL_PRESENT_EVENT, (event) => {
|
|
703
|
+
if (event.presentationId !== presentationId) return;
|
|
704
|
+
switch (event.type) {
|
|
705
|
+
case "purchaseRequest":
|
|
706
|
+
case "restoreRequest": {
|
|
707
|
+
const run = event.type === "purchaseRequest" ? options.onPurchase?.(event.packageId) : options.onRestore?.();
|
|
708
|
+
Promise.resolve(run).then((answer) => native.resolveFunnelPurchaseRequest(event.requestId, Boolean(answer?.purchased))).catch(() => native.resolveFunnelPurchaseRequest(event.requestId, false));
|
|
709
|
+
break;
|
|
710
|
+
}
|
|
711
|
+
case "purchaseError":
|
|
712
|
+
options.onPurchaseError?.(toError(event.error));
|
|
713
|
+
break;
|
|
714
|
+
case "url":
|
|
715
|
+
options.onUrl?.(event.url);
|
|
716
|
+
break;
|
|
717
|
+
case "customAction":
|
|
718
|
+
options.onCustomAction?.({ actionId: event.actionId, paramsJson: event.paramsJson });
|
|
719
|
+
break;
|
|
720
|
+
}
|
|
721
|
+
});
|
|
722
|
+
try {
|
|
723
|
+
const dto = await native.presentFunnel(
|
|
724
|
+
presentationId,
|
|
725
|
+
options.placement,
|
|
726
|
+
options.locale ?? null,
|
|
727
|
+
options.style ? JSON.stringify(options.style) : null,
|
|
728
|
+
{
|
|
729
|
+
onPurchase: Boolean(options.onPurchase),
|
|
730
|
+
onRestore: Boolean(options.onRestore),
|
|
731
|
+
onUrl: Boolean(options.onUrl),
|
|
732
|
+
onCustomAction: Boolean(options.onCustomAction)
|
|
733
|
+
}
|
|
734
|
+
);
|
|
735
|
+
return {
|
|
736
|
+
result: dto.result,
|
|
737
|
+
purchased: dto.purchased,
|
|
738
|
+
...dto.customerInfo ? { customerInfo: dto.customerInfo } : {},
|
|
739
|
+
...dto.lastError ? { lastError: toError(dto.lastError) } : {},
|
|
740
|
+
...dto.reason ? { reason: dto.reason } : {}
|
|
741
|
+
};
|
|
742
|
+
} catch (e) {
|
|
743
|
+
throw fromNativeError(e);
|
|
744
|
+
} finally {
|
|
745
|
+
subscription3.remove();
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
674
749
|
// src/api/events.ts
|
|
675
750
|
function isoNow2() {
|
|
676
751
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -969,6 +1044,8 @@ var Rovenue = {
|
|
|
969
1044
|
purchase,
|
|
970
1045
|
restorePurchases,
|
|
971
1046
|
setFallbackPlacements,
|
|
1047
|
+
preloadPlacement,
|
|
1048
|
+
presentFunnel,
|
|
972
1049
|
track,
|
|
973
1050
|
refreshRemoteConfig,
|
|
974
1051
|
getRemoteConfig,
|
|
@@ -1021,6 +1098,7 @@ export {
|
|
|
1021
1098
|
SDK_VERSION,
|
|
1022
1099
|
extractFunnelToken,
|
|
1023
1100
|
mapNativeError,
|
|
1101
|
+
presentFunnel,
|
|
1024
1102
|
serializeEnvelope,
|
|
1025
1103
|
stripUndefined,
|
|
1026
1104
|
useCurrentUser,
|