react-native-purchases-ui 11.0.0 → 11.0.2
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/Package.swift +1 -1
- package/README.md +85 -0
- package/RNPaywalls.podspec +1 -1
- package/android/build.gradle +3 -3
- package/android/src/main/java/com/revenuecat/purchases/react/ui/RNCheckpointsModule.kt +82 -9
- package/ios/RNCheckpoints.m +81 -9
- package/lib/commonjs/checkpoints.js +162 -9
- package/lib/commonjs/checkpoints.js.map +1 -1
- package/lib/commonjs/index.js +1 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/checkpoints.js +167 -9
- package/lib/module/checkpoints.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/checkpoints.d.ts +61 -2
- package/lib/typescript/src/checkpoints.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/checkpoints.ts +193 -9
- package/src/index.tsx +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,SAAS,EAGd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,cAAc,EAAE,KAAK,cAAc,EACnC,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAC7C,KAAK,yBAAyB,EAC9B,qBAAqB,EAEtB,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAInE,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"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AK,CAAC,EAAE,CAAC,sBAAsB,CAAC,CAChB;IAE1D,OAAO,CAAC,MAAM,CAAC,0BAA0B;CAM1C"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-purchases-ui",
|
|
3
3
|
"title": "React Native Purchases UI",
|
|
4
|
-
"version": "11.0.
|
|
4
|
+
"version": "11.0.2",
|
|
5
5
|
"description": "React Native in-app purchases and subscriptions made easy. Supports iOS and Android.",
|
|
6
6
|
"main": "lib/commonjs/index",
|
|
7
7
|
"module": "lib/module/index",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"peerDependencies": {
|
|
82
82
|
"react": "*",
|
|
83
83
|
"react-native": ">= 0.80.0",
|
|
84
|
-
"react-native-purchases": "11.0.
|
|
84
|
+
"react-native-purchases": "11.0.2",
|
|
85
85
|
"react-native-web": "*"
|
|
86
86
|
},
|
|
87
87
|
"peerDependenciesMeta": {
|
|
@@ -128,6 +128,6 @@
|
|
|
128
128
|
]
|
|
129
129
|
},
|
|
130
130
|
"dependencies": {
|
|
131
|
-
"@revenuecat/purchases-typescript-internal": "20.
|
|
131
|
+
"@revenuecat/purchases-typescript-internal": "20.7.0"
|
|
132
132
|
}
|
|
133
133
|
}
|
package/src/checkpoints.ts
CHANGED
|
@@ -2,9 +2,10 @@ import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
|
|
|
2
2
|
import {
|
|
3
3
|
type CustomerInfo,
|
|
4
4
|
type PurchasesEntitlementInfo,
|
|
5
|
+
type PurchasesOffering,
|
|
5
6
|
type PurchasesStoreProduct,
|
|
6
7
|
} from '@revenuecat/purchases-typescript-internal';
|
|
7
|
-
import { convertCustomVariablesToNativeMap, type CustomVariables } from './customVariables';
|
|
8
|
+
import { CustomVariableValue, convertCustomVariablesToNativeMap, type CustomVariables } from './customVariables';
|
|
8
9
|
import { shouldUsePreviewAPIMode } from './utils/environment';
|
|
9
10
|
|
|
10
11
|
/** How the SDK presents the flow selected by a checkpoint. */
|
|
@@ -34,14 +35,80 @@ export interface CheckpointResult {
|
|
|
34
35
|
customer: CustomerInfo;
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
/** What kind of failure the native SDK needs an error dialog for. */
|
|
39
|
+
export type CheckpointErrorKind = 'flowCouldNotBeShown' | 'flowActionFailed' | 'flowResultSyncFailed';
|
|
40
|
+
|
|
41
|
+
export interface CheckpointError {
|
|
42
|
+
kind: CheckpointErrorKind;
|
|
43
|
+
code: number;
|
|
44
|
+
message: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The content of the native error dialog. */
|
|
48
|
+
export interface CheckpointErrorDialog {
|
|
49
|
+
message: string;
|
|
50
|
+
primaryButtonTitle: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** What to do with a checkpoint error. The SDK owns dialog presentation and acknowledgement. */
|
|
54
|
+
export type CheckpointErrorDialogOutcome =
|
|
55
|
+
| { type: 'show'; dialog: CheckpointErrorDialog }
|
|
56
|
+
| { type: 'useDefault' }
|
|
57
|
+
| { type: 'suppress' };
|
|
58
|
+
|
|
59
|
+
/** How an app-owned checkpoint paywall presentation ended. */
|
|
60
|
+
export enum PAYWALL_PRESENTATION_RESULT {
|
|
61
|
+
/** The user continued. Permit checkpoint continuation after purchase synchronization. */
|
|
62
|
+
CONTINUED = 'CONTINUED',
|
|
63
|
+
/** The user closed the paywall. Permit checkpoint continuation after purchase synchronization. */
|
|
64
|
+
CLOSED = 'CLOSED',
|
|
65
|
+
/** The user navigated back. Stop the checkpoint without calling `onPassed`. */
|
|
66
|
+
NAVIGATED_BACK = 'NAVIGATED_BACK',
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface PaywallPresentationParams {
|
|
70
|
+
checkpointIdentifier: string;
|
|
71
|
+
customVariables: CustomVariables;
|
|
72
|
+
presentationMode: FLOW_PRESENTATION_MODE;
|
|
73
|
+
offering: PurchasesOffering;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Presents a checkpoint-selected offering. Dismiss the app-owned UI, then call completion.
|
|
78
|
+
* Throwing or rejecting a returned promise reports NAVIGATED_BACK. Resolving a promise alone
|
|
79
|
+
* does not complete presentation; the completion callback determines the outcome.
|
|
80
|
+
*/
|
|
81
|
+
export type PaywallPresenter = (
|
|
82
|
+
params: PaywallPresentationParams,
|
|
83
|
+
completion: (result: PAYWALL_PRESENTATION_RESULT) => void,
|
|
84
|
+
) => void | Promise<void>;
|
|
85
|
+
|
|
86
|
+
type NativeCheckpointErrorDialogOutcome =
|
|
87
|
+
| { type: 'show'; dialog: { message: string; buttonTitle: string } }
|
|
88
|
+
| { type: 'useDefault' }
|
|
89
|
+
| { type: 'suppress' };
|
|
90
|
+
|
|
37
91
|
export interface CheckpointParams {
|
|
38
92
|
customVariables?: CustomVariables;
|
|
39
93
|
presentationMode?: FLOW_PRESENTATION_MODE;
|
|
94
|
+
/**
|
|
95
|
+
* Chooses custom dialog content, the SDK's default dialog, or no dialog for each error,
|
|
96
|
+
* including synchronization errors after a custom paywall presenter completes.
|
|
97
|
+
* May return a promise. The SDK waits for the result; a pending promise delays error handling.
|
|
98
|
+
* Throwing, rejecting, or returning an invalid outcome uses the SDK's default dialog.
|
|
99
|
+
*/
|
|
100
|
+
errorDialogFactory?: (error: CheckpointError) => CheckpointErrorDialogOutcome | Promise<CheckpointErrorDialogOutcome>;
|
|
101
|
+
/** Overrides the global presenter. Use `undefined` for the global default or `null` for the SDK presenter. */
|
|
102
|
+
paywallPresenter?: PaywallPresenter | null;
|
|
40
103
|
}
|
|
41
104
|
|
|
42
105
|
const PASSED_EVENT = 'Checkpoints-onPassed';
|
|
106
|
+
const ERROR_DIALOG_REQUESTED_EVENT = 'Checkpoints-onErrorDialogRequested';
|
|
107
|
+
const ERROR_EVENT = 'Checkpoints-onError';
|
|
108
|
+
const PRESENT_PAYWALL_EVENT = 'Checkpoints-onPaywallPresentation';
|
|
43
109
|
let nextCallId = 0;
|
|
44
110
|
const callIdPrefix = `${Date.now()}-${Math.random()}`;
|
|
111
|
+
let globalPaywallPresenter: PaywallPresenter | null = null;
|
|
45
112
|
|
|
46
113
|
function nativeCheckpoints() {
|
|
47
114
|
if (shouldUsePreviewAPIMode() || (Platform.OS !== 'ios' && Platform.OS !== 'android')) {
|
|
@@ -57,13 +124,41 @@ function nativeCheckpoints() {
|
|
|
57
124
|
return native;
|
|
58
125
|
}
|
|
59
126
|
|
|
127
|
+
function toErrorDialogOutcome(value: unknown): CheckpointErrorDialogOutcome {
|
|
128
|
+
if (typeof value === 'object' && value !== null) {
|
|
129
|
+
const outcome = value as { type?: unknown; dialog?: unknown };
|
|
130
|
+
if (outcome.type === 'useDefault' || outcome.type === 'suppress') {
|
|
131
|
+
return { type: outcome.type };
|
|
132
|
+
}
|
|
133
|
+
if (outcome.type === 'show' && typeof outcome.dialog === 'object' && outcome.dialog !== null) {
|
|
134
|
+
const { message, primaryButtonTitle } = outcome.dialog as Partial<CheckpointErrorDialog>;
|
|
135
|
+
if (typeof message === 'string' && message.length > 0 &&
|
|
136
|
+
typeof primaryButtonTitle === 'string' && primaryButtonTitle.length > 0) {
|
|
137
|
+
return { type: 'show', dialog: { message, primaryButtonTitle } };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
throw new Error('errorDialogFactory must return a show outcome with non-empty message and primaryButtonTitle, useDefault, or suppress.');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function toNativeErrorDialogOutcome(outcome: CheckpointErrorDialogOutcome): NativeCheckpointErrorDialogOutcome {
|
|
145
|
+
if (outcome.type !== 'show') {
|
|
146
|
+
return outcome;
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
type: 'show',
|
|
150
|
+
dialog: { message: outcome.dialog.message, buttonTitle: outcome.dialog.primaryButtonTitle },
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
60
154
|
/**
|
|
61
155
|
* Calls onPassed only when the app can continue past the checkpoint. It is not called when
|
|
62
156
|
* the user backs out, a blocking error occurs, or another checkpoint owns presentation.
|
|
63
157
|
* Requires iOS 15+ or Android. Checkpoints are an invite-only API.
|
|
64
158
|
*
|
|
65
159
|
* Returns a function that removes the callback. Call it when the owning screen unmounts;
|
|
66
|
-
*
|
|
160
|
+
* cleanup cancels custom presentation if its handler has not run yet. Already shown UI stays
|
|
161
|
+
* open; dismiss it and call its presentation completion as usual.
|
|
67
162
|
*/
|
|
68
163
|
export function checkpoint(
|
|
69
164
|
identifier: string,
|
|
@@ -72,20 +167,109 @@ export function checkpoint(
|
|
|
72
167
|
): () => void {
|
|
73
168
|
const native = nativeCheckpoints();
|
|
74
169
|
const callId = `${callIdPrefix}-${++nextCallId}`;
|
|
170
|
+
const paywallPresenter = params.paywallPresenter === undefined ? globalPaywallPresenter : params.paywallPresenter;
|
|
75
171
|
const emitter = new NativeEventEmitter(native);
|
|
76
|
-
const
|
|
172
|
+
const errorDialogFactory = params.errorDialogFactory;
|
|
173
|
+
let isCallbackActive = true;
|
|
174
|
+
let detached = false;
|
|
175
|
+
let activePaywallRequestId: string | null = null;
|
|
176
|
+
const subscriptions: Array<{ remove: () => void }> = [];
|
|
177
|
+
const removeSubscriptions = () => subscriptions.splice(0).forEach(subscription => subscription.remove());
|
|
178
|
+
|
|
179
|
+
subscriptions.push(emitter.addListener(PASSED_EVENT, event => {
|
|
77
180
|
if (event.callId !== callId) {
|
|
78
181
|
return;
|
|
79
182
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
183
|
+
removeSubscriptions();
|
|
184
|
+
if (isCallbackActive) {
|
|
185
|
+
onPassed(event.result);
|
|
186
|
+
}
|
|
187
|
+
}));
|
|
188
|
+
subscriptions.push(emitter.addListener(ERROR_EVENT, event => {
|
|
189
|
+
if (event.callId === callId) {
|
|
190
|
+
removeSubscriptions();
|
|
191
|
+
}
|
|
192
|
+
}));
|
|
193
|
+
if (errorDialogFactory) {
|
|
194
|
+
subscriptions.push(emitter.addListener(ERROR_DIALOG_REQUESTED_EVENT, async event => {
|
|
195
|
+
if (event.callId !== callId) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
let outcome: CheckpointErrorDialogOutcome = { type: 'useDefault' };
|
|
199
|
+
try {
|
|
200
|
+
outcome = toErrorDialogOutcome(await errorDialogFactory(event.error));
|
|
201
|
+
} catch (error) {
|
|
202
|
+
// tslint:disable-next-line:no-console
|
|
203
|
+
console.warn('[RevenueCatUI] Using the default checkpoint error dialog because errorDialogFactory failed:', error);
|
|
204
|
+
}
|
|
205
|
+
if (!detached) {
|
|
206
|
+
native.resolveErrorDialog(event.requestId, toNativeErrorDialogOutcome(outcome));
|
|
207
|
+
}
|
|
208
|
+
}));
|
|
209
|
+
}
|
|
210
|
+
if (paywallPresenter) {
|
|
211
|
+
subscriptions.push(emitter.addListener(PRESENT_PAYWALL_EVENT, event => {
|
|
212
|
+
if (event.callId !== callId) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
activePaywallRequestId = event.requestId;
|
|
216
|
+
let didComplete = false;
|
|
217
|
+
const customVariables: CustomVariables = {};
|
|
218
|
+
Object.entries(event.params.customVariables ?? {}).forEach(([key, value]) => {
|
|
219
|
+
if (typeof value === 'string') {
|
|
220
|
+
customVariables[key] = CustomVariableValue.string(value);
|
|
221
|
+
} else if (typeof value === 'number') {
|
|
222
|
+
customVariables[key] = CustomVariableValue.number(value);
|
|
223
|
+
} else if (typeof value === 'boolean') {
|
|
224
|
+
customVariables[key] = CustomVariableValue.boolean(value);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
const complete = (result: PAYWALL_PRESENTATION_RESULT) => {
|
|
228
|
+
if (didComplete) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
didComplete = true;
|
|
232
|
+
activePaywallRequestId = null;
|
|
233
|
+
native.completePaywallPresentation(event.requestId, result);
|
|
234
|
+
if (result === PAYWALL_PRESENTATION_RESULT.NAVIGATED_BACK) {
|
|
235
|
+
removeSubscriptions();
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
try {
|
|
239
|
+
Promise.resolve(paywallPresenter({ ...event.params, customVariables }, complete))
|
|
240
|
+
.catch(() => complete(PAYWALL_PRESENTATION_RESULT.NAVIGATED_BACK));
|
|
241
|
+
} catch {
|
|
242
|
+
complete(PAYWALL_PRESENTATION_RESULT.NAVIGATED_BACK);
|
|
243
|
+
}
|
|
244
|
+
}));
|
|
245
|
+
}
|
|
83
246
|
try {
|
|
84
247
|
native.checkpoint(identifier, convertCustomVariablesToNativeMap(params.customVariables),
|
|
85
|
-
params.presentationMode ?? FLOW_PRESENTATION_MODE.DEFAULT, callId
|
|
248
|
+
params.presentationMode ?? FLOW_PRESENTATION_MODE.DEFAULT, callId,
|
|
249
|
+
errorDialogFactory !== undefined, paywallPresenter != null);
|
|
86
250
|
} catch (error) {
|
|
87
|
-
|
|
251
|
+
removeSubscriptions();
|
|
88
252
|
throw error;
|
|
89
253
|
}
|
|
90
|
-
return () =>
|
|
254
|
+
return () => {
|
|
255
|
+
isCallbackActive = false;
|
|
256
|
+
removeSubscriptions();
|
|
257
|
+
if (paywallPresenter && !detached) {
|
|
258
|
+
native.detachPaywallPresenter(callId, activePaywallRequestId);
|
|
259
|
+
}
|
|
260
|
+
if (errorDialogFactory && !detached) {
|
|
261
|
+
native.detachErrorDialogFactory(callId);
|
|
262
|
+
}
|
|
263
|
+
detached = true;
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Sets the default app-owned presenter for checkpoint-selected offerings. A per-checkpoint
|
|
269
|
+
* `paywallPresenter` overrides this handler. Pass `null` to restore the SDK presenter.
|
|
270
|
+
* Changes affect future checkpoint calls. Each call captures its presenter when `checkpoint` is called,
|
|
271
|
+
* even if presentation starts after the global presenter changes.
|
|
272
|
+
*/
|
|
273
|
+
export function setPaywallPresenter(presenter: PaywallPresenter | null): void {
|
|
274
|
+
globalPaywallPresenter = presenter;
|
|
91
275
|
}
|
package/src/index.tsx
CHANGED
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
convertCustomVariablesToNativeMap,
|
|
29
29
|
transformOptionsForNative,
|
|
30
30
|
} from "./customVariables";
|
|
31
|
-
import { checkpoint } from "./checkpoints";
|
|
31
|
+
import { checkpoint, setPaywallPresenter } from "./checkpoints";
|
|
32
32
|
|
|
33
33
|
export * from "./checkpoints";
|
|
34
34
|
|
|
@@ -588,6 +588,7 @@ export interface PresentCustomerCenterParams {
|
|
|
588
588
|
|
|
589
589
|
export default class RevenueCatUI {
|
|
590
590
|
public static checkpoint = checkpoint;
|
|
591
|
+
public static setPaywallPresenter = setPaywallPresenter;
|
|
591
592
|
|
|
592
593
|
|
|
593
594
|
private static Defaults = {
|