@adapty/capacitor 3.11.1-beta.0 → 3.15.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/AdaptyCapacitor.podspec +3 -3
- package/Package.swift +1 -1
- package/README.md +45 -29
- package/android/build.gradle +4 -3
- package/android/src/main/kotlin/com/adapty/plugin/capacitor/AdaptyCapacitorImplementation.kt +2 -0
- package/dist/esm/adapty.d.ts +752 -6
- package/dist/esm/adapty.js +755 -8
- package/dist/esm/adapty.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/shared/coders/adapty-configuration.js +25 -14
- package/dist/esm/shared/coders/adapty-configuration.js.map +1 -1
- package/dist/esm/shared/coders/adapty-identify-params.d.ts +11 -0
- package/dist/esm/shared/coders/adapty-identify-params.js +19 -0
- package/dist/esm/shared/coders/adapty-identify-params.js.map +1 -0
- package/dist/esm/shared/coders/adapty-paywall-product.d.ts +1 -1
- package/dist/esm/shared/coders/adapty-paywall-product.js +12 -0
- package/dist/esm/shared/coders/adapty-paywall-product.js.map +1 -1
- package/dist/esm/shared/coders/adapty-purchase-params.js +0 -8
- package/dist/esm/shared/coders/adapty-purchase-params.js.map +1 -1
- package/dist/esm/shared/coders/adapty-purchase-result.js +18 -2
- package/dist/esm/shared/coders/adapty-purchase-result.js.map +1 -1
- package/dist/esm/shared/coders/adapty-ui-create-onboarding-view-params.d.ts +8 -0
- package/dist/esm/shared/coders/adapty-ui-create-onboarding-view-params.js +10 -0
- package/dist/esm/shared/coders/adapty-ui-create-onboarding-view-params.js.map +1 -0
- package/dist/esm/shared/coders/adapty-ui-create-paywall-view-params.d.ts +18 -0
- package/dist/esm/shared/coders/adapty-ui-create-paywall-view-params.js +142 -0
- package/dist/esm/shared/coders/adapty-ui-create-paywall-view-params.js.map +1 -0
- package/dist/esm/shared/coders/parse-onboarding.d.ts +3 -0
- package/dist/esm/shared/coders/parse-onboarding.js +86 -0
- package/dist/esm/shared/coders/parse-onboarding.js.map +1 -0
- package/dist/esm/shared/coders/parse-paywall.d.ts +4 -0
- package/dist/esm/shared/coders/parse-paywall.js +141 -0
- package/dist/esm/shared/coders/parse-paywall.js.map +1 -0
- package/dist/esm/shared/coders/parse.d.ts +0 -2
- package/dist/esm/shared/coders/parse.js +0 -75
- package/dist/esm/shared/coders/parse.js.map +1 -1
- package/dist/esm/shared/coders/product-reference.js +10 -0
- package/dist/esm/shared/coders/product-reference.js.map +1 -1
- package/dist/esm/shared/coders/utils.d.ts +18 -0
- package/dist/esm/shared/coders/utils.js +50 -0
- package/dist/esm/shared/coders/utils.js.map +1 -0
- package/dist/esm/shared/types/index.d.ts +16 -0
- package/dist/esm/shared/types/index.js +5 -0
- package/dist/esm/shared/types/index.js.map +1 -1
- package/dist/esm/shared/types/inputs.d.ts +47 -14
- package/dist/esm/shared/types/inputs.js.map +1 -1
- package/dist/esm/shared/types/onboarding-events.d.ts +60 -0
- package/dist/esm/shared/types/onboarding-events.js +11 -0
- package/dist/esm/shared/types/onboarding-events.js.map +1 -0
- package/dist/esm/shared/types/paywall-events.d.ts +84 -0
- package/dist/esm/shared/types/paywall-events.js +16 -0
- package/dist/esm/shared/types/paywall-events.js.map +1 -0
- package/dist/esm/shared/utils/platform.d.ts +2 -0
- package/dist/esm/shared/utils/platform.js +5 -0
- package/dist/esm/shared/utils/platform.js.map +1 -0
- package/dist/esm/types/adapty-plugin.d.ts +2 -1
- package/dist/esm/types/adapty-plugin.js.map +1 -1
- package/dist/esm/ui-builder/base-view-emitter.d.ts +14 -20
- package/dist/esm/ui-builder/base-view-emitter.js +95 -73
- package/dist/esm/ui-builder/base-view-emitter.js.map +1 -1
- package/dist/esm/ui-builder/create-onboarding-view.d.ts +32 -0
- package/dist/esm/ui-builder/create-onboarding-view.js +36 -0
- package/dist/esm/ui-builder/create-onboarding-view.js.map +1 -0
- package/dist/esm/ui-builder/create-paywall-view.d.ts +25 -0
- package/dist/esm/ui-builder/create-paywall-view.js +29 -0
- package/dist/esm/ui-builder/create-paywall-view.js.map +1 -0
- package/dist/esm/ui-builder/index.d.ts +6 -37
- package/dist/esm/ui-builder/index.js +4 -41
- package/dist/esm/ui-builder/index.js.map +1 -1
- package/dist/esm/ui-builder/onboarding-view-controller.d.ts +103 -17
- package/dist/esm/ui-builder/onboarding-view-controller.js +112 -22
- package/dist/esm/ui-builder/onboarding-view-controller.js.map +1 -1
- package/dist/esm/ui-builder/onboarding-view-emitter.d.ts +10 -24
- package/dist/esm/ui-builder/onboarding-view-emitter.js +49 -56
- package/dist/esm/ui-builder/onboarding-view-emitter.js.map +1 -1
- package/dist/esm/ui-builder/paywall-view-controller.d.ts +130 -30
- package/dist/esm/ui-builder/paywall-view-controller.js +141 -71
- package/dist/esm/ui-builder/paywall-view-controller.js.map +1 -1
- package/dist/esm/ui-builder/paywall-view-emitter.d.ts +8 -28
- package/dist/esm/ui-builder/paywall-view-emitter.js +86 -118
- package/dist/esm/ui-builder/paywall-view-emitter.js.map +1 -1
- package/dist/esm/ui-builder/types.d.ts +89 -4
- package/dist/esm/ui-builder/types.js +3 -3
- package/dist/esm/ui-builder/types.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/plugin.cjs.js +1896 -556
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1896 -556
- package/dist/plugin.js.map +1 -1
- package/package.json +2 -2
package/dist/esm/adapty.js
CHANGED
|
@@ -5,6 +5,7 @@ import { AdaptyCapacitorPlugin } from './bridge/plugin';
|
|
|
5
5
|
import { getCoder } from './coder-registry';
|
|
6
6
|
import { defaultAdaptyOptions } from './default-configs';
|
|
7
7
|
import { AdaptyConfigurationCoder } from './shared/coders/adapty-configuration';
|
|
8
|
+
import { AdaptyIdentifyParamsCoder } from './shared/coders/adapty-identify-params';
|
|
8
9
|
import { AdaptyPaywallCoder } from './shared/coders/adapty-paywall';
|
|
9
10
|
import { AdaptyPaywallProductCoder } from './shared/coders/adapty-paywall-product';
|
|
10
11
|
import { AdaptyProfileParametersCoder } from './shared/coders/adapty-profile-parameters';
|
|
@@ -14,6 +15,14 @@ import { isErrorResponse, isSuccessResponse, } from './shared/types/method-types
|
|
|
14
15
|
import { filterUndefined } from './shared/utils/compact-object';
|
|
15
16
|
import { mergeOptions } from './shared/utils/merge-options';
|
|
16
17
|
import { withErrorContext } from './shared/utils/with-error-context';
|
|
18
|
+
/**
|
|
19
|
+
* Entry point for the Adapty SDK.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* This is the main Adapty class, excluding UI rendering functionality.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
17
26
|
export class Adapty {
|
|
18
27
|
constructor() {
|
|
19
28
|
this.activating = null;
|
|
@@ -28,6 +37,34 @@ export class Adapty {
|
|
|
28
37
|
'set_fallback',
|
|
29
38
|
];
|
|
30
39
|
this.options = defaultAdaptyOptions;
|
|
40
|
+
/**
|
|
41
|
+
* Adds an event listener for SDK events.
|
|
42
|
+
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* You can listen to various events from the Adapty SDK such as profile updates.
|
|
45
|
+
* The listener will be called whenever the corresponding event occurs.
|
|
46
|
+
*
|
|
47
|
+
* @param eventName - The name of the event to listen to.
|
|
48
|
+
* @param listenerFunc - The function to call when the event occurs.
|
|
49
|
+
* @returns A listener handle that can be used to remove the listener.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* Listen to profile updates
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { adapty } from '@adapty/capacitor';
|
|
55
|
+
*
|
|
56
|
+
* const listener = adapty.addListener('onLatestProfileLoad', (profile) => {
|
|
57
|
+
* console.log('Profile updated:', profile);
|
|
58
|
+
* const isSubscribed = profile.accessLevels['YOUR_ACCESS_LEVEL']?.isActive;
|
|
59
|
+
* if (isSubscribed) {
|
|
60
|
+
* console.log('User has premium access');
|
|
61
|
+
* }
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* // Later, remove the listener
|
|
65
|
+
* listener.remove();
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
31
68
|
this.addListener = (eventName, listenerFunc) => {
|
|
32
69
|
const wrappedListener = withErrorContext(listenerFunc, eventName, 'Adapty');
|
|
33
70
|
return this.emitter.addListener(eventName, wrappedListener);
|
|
@@ -54,6 +91,7 @@ export class Adapty {
|
|
|
54
91
|
}
|
|
55
92
|
/**
|
|
56
93
|
* Handle method calls through crossplatform bridge with type safety
|
|
94
|
+
* @internal
|
|
57
95
|
*/
|
|
58
96
|
async handleMethodCall(methodName, args, ctx, log) {
|
|
59
97
|
// Hold on deferred activation first
|
|
@@ -137,11 +175,29 @@ export class Adapty {
|
|
|
137
175
|
/**
|
|
138
176
|
* Initializes the Adapty SDK.
|
|
139
177
|
*
|
|
178
|
+
* @remarks
|
|
179
|
+
* This method must be called in order for the SDK to work.
|
|
180
|
+
* It is preferred to call it as early as possible in the app lifecycle,
|
|
181
|
+
* so background activities can be performed and cache can be updated.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* Usage with your user identifier from your system
|
|
187
|
+
* ```typescript
|
|
188
|
+
* await adapty.activate({
|
|
189
|
+
* apiKey: 'YOUR_PUBLIC_SDK_KEY',
|
|
190
|
+
* params: {
|
|
191
|
+
* customerUserId: 'YOUR_USER_ID'
|
|
192
|
+
* }
|
|
193
|
+
* });
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
140
196
|
* @param options - The activation options
|
|
141
|
-
* @param options.apiKey -
|
|
142
|
-
* @param options.params - Optional activation parameters
|
|
143
|
-
* @returns
|
|
144
|
-
* @throws Error if the API key is invalid
|
|
197
|
+
* @param options.apiKey - You can find it in your app settings in Adapty Dashboard App settings > General.
|
|
198
|
+
* @param options.params - Optional activation parameters of type {@link ActivateParamsInput}.
|
|
199
|
+
* @returns A promise that resolves when the SDK is activated.
|
|
200
|
+
* @throws Error if the SDK is already activated or if the API key is invalid.
|
|
145
201
|
*/
|
|
146
202
|
async activate(options) {
|
|
147
203
|
const { apiKey, params = {} } = options;
|
|
@@ -204,6 +260,12 @@ export class Adapty {
|
|
|
204
260
|
const activateRequest = filterUndefined(activateRequestWithUndefined);
|
|
205
261
|
await this.handleMethodCall(method, JSON.stringify(activateRequest), ctx, log);
|
|
206
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* Checks if the Adapty SDK is activated.
|
|
265
|
+
*
|
|
266
|
+
* @returns A promise that resolves to `true` if the SDK is activated, `false` otherwise.
|
|
267
|
+
* @throws Error if an error occurs while checking activation status.
|
|
268
|
+
*/
|
|
207
269
|
async isActivated() {
|
|
208
270
|
const method = 'is_activated';
|
|
209
271
|
const ctx = new LogContext();
|
|
@@ -215,6 +277,32 @@ export class Adapty {
|
|
|
215
277
|
const args = filterUndefined(argsWithUndefined);
|
|
216
278
|
return await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
217
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* Gets the current installation status.
|
|
282
|
+
*
|
|
283
|
+
* @remarks
|
|
284
|
+
* Installation status provides information about when the app was installed,
|
|
285
|
+
* how many times it has been launched, and other installation-related details.
|
|
286
|
+
* The status can be "not_available", "not_determined", or "determined" with details.
|
|
287
|
+
*
|
|
288
|
+
* @returns A promise that resolves with the installation status.
|
|
289
|
+
* @throws Error if an error occurs while retrieving the installation status.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```typescript
|
|
293
|
+
* import { adapty } from '@adapty/capacitor';
|
|
294
|
+
*
|
|
295
|
+
* try {
|
|
296
|
+
* const status = await adapty.getCurrentInstallationStatus();
|
|
297
|
+
* if (status.status === 'determined') {
|
|
298
|
+
* console.log('Install time:', status.details.installTime);
|
|
299
|
+
* console.log('Launch count:', status.details.appLaunchCount);
|
|
300
|
+
* }
|
|
301
|
+
* } catch (error) {
|
|
302
|
+
* console.error('Failed to get installation status:', error);
|
|
303
|
+
* }
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
218
306
|
async getCurrentInstallationStatus() {
|
|
219
307
|
const method = 'get_current_installation_status';
|
|
220
308
|
const ctx = new LogContext();
|
|
@@ -226,6 +314,38 @@ export class Adapty {
|
|
|
226
314
|
const args = filterUndefined(argsWithUndefined);
|
|
227
315
|
return await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
228
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Fetches the paywall by the specified placement.
|
|
319
|
+
*
|
|
320
|
+
* @remarks
|
|
321
|
+
* With Adapty, you can remotely configure the products and offers in your app
|
|
322
|
+
* by simply adding them to paywalls – no need for hardcoding them.
|
|
323
|
+
* The only thing you hardcode is the placement ID.
|
|
324
|
+
* This flexibility allows you to easily update paywalls, products, and offers,
|
|
325
|
+
* or run A/B tests, all without the need for a new app release.
|
|
326
|
+
*
|
|
327
|
+
* @param options - The options for fetching the paywall
|
|
328
|
+
* @param options.placementId - The identifier of the desired placement. This is the value you specified when creating a placement in the Adapty Dashboard.
|
|
329
|
+
* @param options.locale - Optional. The identifier of the paywall localization. Default: `'en'`. See {@link https://docs.adapty.io/docs/localizations-and-locale-codes | Localizations and locale codes} for more information.
|
|
330
|
+
* @param options.params - Optional. Additional parameters for fetching the paywall, including fetch policy and load timeout.
|
|
331
|
+
* @returns A promise that resolves with the requested {@link AdaptyPaywall}.
|
|
332
|
+
* @throws Error if the paywall with the specified ID is not found or if your bundle ID does not match with your Adapty Dashboard setup.
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* import { adapty } from '@adapty/capacitor';
|
|
337
|
+
*
|
|
338
|
+
* try {
|
|
339
|
+
* const paywall = await adapty.getPaywall({
|
|
340
|
+
* placementId: 'YOUR_PLACEMENT_ID',
|
|
341
|
+
* locale: 'en',
|
|
342
|
+
* });
|
|
343
|
+
* console.log('Paywall fetched successfully');
|
|
344
|
+
* } catch (error) {
|
|
345
|
+
* console.error('Failed to fetch paywall:', error);
|
|
346
|
+
* }
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
229
349
|
async getPaywall(options) {
|
|
230
350
|
const method = 'get_paywall';
|
|
231
351
|
const optionsWithDefault = mergeOptions(options, this.options[method]);
|
|
@@ -245,6 +365,43 @@ export class Adapty {
|
|
|
245
365
|
const args = filterUndefined(argsWithUndefined);
|
|
246
366
|
return await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
247
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* Fetches the paywall of the specified placement for the **All Users** audience.
|
|
370
|
+
*
|
|
371
|
+
* @remarks
|
|
372
|
+
* With Adapty, you can remotely configure the products and offers in your app
|
|
373
|
+
* by simply adding them to paywalls – no need for hardcoding them.
|
|
374
|
+
* The only thing you hardcode is the placement ID.
|
|
375
|
+
*
|
|
376
|
+
* However, it's crucial to understand that the recommended approach is to fetch the paywall
|
|
377
|
+
* through the placement ID by the {@link getPaywall} method.
|
|
378
|
+
* The `getPaywallForDefaultAudience` method should be a last resort due to its significant drawbacks:
|
|
379
|
+
* - Potential backward compatibility issues
|
|
380
|
+
* - Loss of targeting (all users see the same paywall)
|
|
381
|
+
*
|
|
382
|
+
* See {@link https://docs.adapty.io/docs/capacitor-get-pb-paywalls#get-a-paywall-for-a-default-audience-to-fetch-it-faster | documentation} for more details.
|
|
383
|
+
*
|
|
384
|
+
* @param options - The options for fetching the paywall
|
|
385
|
+
* @param options.placementId - The identifier of the desired placement.
|
|
386
|
+
* @param options.locale - Optional. The identifier of the paywall localization. Default: `'en'`.
|
|
387
|
+
* @param options.params - Optional. Additional parameters for fetching the paywall.
|
|
388
|
+
* @returns A promise that resolves with the requested {@link AdaptyPaywall}.
|
|
389
|
+
* @throws Error if the paywall with the specified ID is not found.
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* ```typescript
|
|
393
|
+
* import { adapty } from '@adapty/capacitor';
|
|
394
|
+
*
|
|
395
|
+
* try {
|
|
396
|
+
* const paywall = await adapty.getPaywallForDefaultAudience({
|
|
397
|
+
* placementId: 'YOUR_PLACEMENT_ID',
|
|
398
|
+
* locale: 'en',
|
|
399
|
+
* });
|
|
400
|
+
* } catch (error) {
|
|
401
|
+
* console.error('Failed to fetch paywall:', error);
|
|
402
|
+
* }
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
248
405
|
async getPaywallForDefaultAudience(options) {
|
|
249
406
|
var _a;
|
|
250
407
|
const method = 'get_paywall_for_default_audience';
|
|
@@ -264,6 +421,27 @@ export class Adapty {
|
|
|
264
421
|
const args = filterUndefined(argsWithUndefined);
|
|
265
422
|
return await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
266
423
|
}
|
|
424
|
+
/**
|
|
425
|
+
* Fetches a list of products associated with a provided paywall.
|
|
426
|
+
*
|
|
427
|
+
* @param options - The options object
|
|
428
|
+
* @param options.paywall - A paywall to fetch products for. You can get it using {@link getPaywall} method.
|
|
429
|
+
* @returns A promise that resolves with a list of {@link AdaptyPaywallProduct} associated with a provided paywall.
|
|
430
|
+
* @throws Error if an error occurs while fetching products.
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* ```typescript
|
|
434
|
+
* import { adapty } from '@adapty/capacitor';
|
|
435
|
+
*
|
|
436
|
+
* try {
|
|
437
|
+
* const paywall = await adapty.getPaywall({ placementId: 'YOUR_PLACEMENT_ID' });
|
|
438
|
+
* const products = await adapty.getPaywallProducts({ paywall });
|
|
439
|
+
* console.log('Products:', products);
|
|
440
|
+
* } catch (error) {
|
|
441
|
+
* console.error('Failed to fetch products:', error);
|
|
442
|
+
* }
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
267
445
|
async getPaywallProducts(options) {
|
|
268
446
|
const method = 'get_paywall_products';
|
|
269
447
|
const ctx = new LogContext();
|
|
@@ -277,6 +455,40 @@ export class Adapty {
|
|
|
277
455
|
const args = filterUndefined(argsWithUndefined);
|
|
278
456
|
return await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
279
457
|
}
|
|
458
|
+
/**
|
|
459
|
+
* Fetches the onboarding by the specified placement.
|
|
460
|
+
*
|
|
461
|
+
* @remarks
|
|
462
|
+
* When you create an onboarding with the no-code builder, it's stored as a container with configuration
|
|
463
|
+
* that your app needs to fetch and display. This container manages the entire experience - what content appears,
|
|
464
|
+
* how it's presented, and how user interactions are processed.
|
|
465
|
+
*
|
|
466
|
+
* @param options - The options for fetching the onboarding
|
|
467
|
+
* @param options.placementId - The identifier of the desired placement.
|
|
468
|
+
* @param options.locale - Optional. The identifier of the onboarding localization. Default: `'en'`.
|
|
469
|
+
* @param options.params - Optional. Additional parameters for fetching the onboarding.
|
|
470
|
+
* @returns A promise that resolves with the requested {@link AdaptyOnboarding}.
|
|
471
|
+
* @throws Error if the onboarding with the specified ID is not found.
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```typescript
|
|
475
|
+
* import { adapty } from '@adapty/capacitor';
|
|
476
|
+
*
|
|
477
|
+
* try {
|
|
478
|
+
* const onboarding = await adapty.getOnboarding({
|
|
479
|
+
* placementId: 'YOUR_PLACEMENT_ID',
|
|
480
|
+
* locale: 'en',
|
|
481
|
+
* params: {
|
|
482
|
+
* fetchPolicy: 'reload_revalidating_cache_data',
|
|
483
|
+
* loadTimeoutMs: 5000
|
|
484
|
+
* }
|
|
485
|
+
* });
|
|
486
|
+
* console.log('Onboarding fetched successfully');
|
|
487
|
+
* } catch (error) {
|
|
488
|
+
* console.error('Failed to fetch onboarding:', error);
|
|
489
|
+
* }
|
|
490
|
+
* ```
|
|
491
|
+
*/
|
|
280
492
|
async getOnboarding(options) {
|
|
281
493
|
const method = 'get_onboarding';
|
|
282
494
|
const optionsWithDefault = mergeOptions(options, this.options[method]);
|
|
@@ -296,6 +508,37 @@ export class Adapty {
|
|
|
296
508
|
const args = filterUndefined(argsWithUndefined);
|
|
297
509
|
return await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
298
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* Fetches the onboarding of the specified placement for the **All Users** audience.
|
|
513
|
+
*
|
|
514
|
+
* @remarks
|
|
515
|
+
* It's crucial to understand that the recommended approach is to fetch the onboarding
|
|
516
|
+
* by the {@link getOnboarding} method. The `getOnboardingForDefaultAudience` method
|
|
517
|
+
* should be used only if faster fetching outweighs the drawbacks:
|
|
518
|
+
* - Potential backward compatibility issues
|
|
519
|
+
* - Loss of personalization (no targeting based on country, attribution, or custom attributes)
|
|
520
|
+
*
|
|
521
|
+
* @param options - The options for fetching the onboarding
|
|
522
|
+
* @param options.placementId - The identifier of the desired placement.
|
|
523
|
+
* @param options.locale - Optional. The identifier of the onboarding localization. Default: `'en'`.
|
|
524
|
+
* @param options.params - Optional. Additional parameters for fetching the onboarding.
|
|
525
|
+
* @returns A promise that resolves with the requested {@link AdaptyOnboarding}.
|
|
526
|
+
* @throws Error if the onboarding with the specified ID is not found.
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* ```typescript
|
|
530
|
+
* import { adapty } from '@adapty/capacitor';
|
|
531
|
+
*
|
|
532
|
+
* try {
|
|
533
|
+
* const onboarding = await adapty.getOnboardingForDefaultAudience({
|
|
534
|
+
* placementId: 'YOUR_PLACEMENT_ID',
|
|
535
|
+
* locale: 'en',
|
|
536
|
+
* });
|
|
537
|
+
* } catch (error) {
|
|
538
|
+
* console.error('Failed to fetch onboarding:', error);
|
|
539
|
+
* }
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
299
542
|
async getOnboardingForDefaultAudience(options) {
|
|
300
543
|
var _a;
|
|
301
544
|
const method = 'get_onboarding_for_default_audience';
|
|
@@ -315,6 +558,38 @@ export class Adapty {
|
|
|
315
558
|
const args = filterUndefined(argsWithUndefined);
|
|
316
559
|
return await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
317
560
|
}
|
|
561
|
+
/**
|
|
562
|
+
* Fetches a user profile.
|
|
563
|
+
*
|
|
564
|
+
* @remarks
|
|
565
|
+
* The getProfile method provides the most up-to-date result
|
|
566
|
+
* as it always tries to query the API.
|
|
567
|
+
* If for some reason (e.g. no internet connection),
|
|
568
|
+
* the Adapty SDK fails to retrieve information from the server,
|
|
569
|
+
* the data from cache will be returned.
|
|
570
|
+
* It is also important to note
|
|
571
|
+
* that the Adapty SDK updates {@link AdaptyProfile} cache
|
|
572
|
+
* on a regular basis, in order
|
|
573
|
+
* to keep this information as up-to-date as possible.
|
|
574
|
+
*
|
|
575
|
+
* @returns A promise that resolves with the user's {@link AdaptyProfile}.
|
|
576
|
+
* @throws Error if an error occurs while fetching the profile.
|
|
577
|
+
*
|
|
578
|
+
* @example
|
|
579
|
+
* ```typescript
|
|
580
|
+
* import { adapty } from '@adapty/capacitor';
|
|
581
|
+
*
|
|
582
|
+
* try {
|
|
583
|
+
* const profile = await adapty.getProfile();
|
|
584
|
+
* const isSubscribed = profile.accessLevels['YOUR_ACCESS_LEVEL']?.isActive;
|
|
585
|
+
* if (isSubscribed) {
|
|
586
|
+
* console.log('User has access to premium features');
|
|
587
|
+
* }
|
|
588
|
+
* } catch (error) {
|
|
589
|
+
* console.error('Failed to get profile:', error);
|
|
590
|
+
* }
|
|
591
|
+
* ```
|
|
592
|
+
*/
|
|
318
593
|
async getProfile() {
|
|
319
594
|
const method = 'get_profile';
|
|
320
595
|
const ctx = new LogContext();
|
|
@@ -326,18 +601,74 @@ export class Adapty {
|
|
|
326
601
|
const args = filterUndefined(argsWithUndefined);
|
|
327
602
|
return await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
328
603
|
}
|
|
604
|
+
/**
|
|
605
|
+
* Logs in a user with a provided customerUserId.
|
|
606
|
+
*
|
|
607
|
+
* @remarks
|
|
608
|
+
* If you don't have a user id on SDK initialization,
|
|
609
|
+
* you can set it later at any time with this method.
|
|
610
|
+
* The most common cases are after registration/authorization
|
|
611
|
+
* when the user switches from being an anonymous user to an authenticated user.
|
|
612
|
+
*
|
|
613
|
+
* @param options - The identification options
|
|
614
|
+
* @param options.customerUserId - A unique user identifier.
|
|
615
|
+
* @param options.params - Optional. Additional parameters for identification, including platform-specific settings.
|
|
616
|
+
* @returns A promise that resolves when identification is complete.
|
|
617
|
+
* @throws Error if an error occurs during identification.
|
|
618
|
+
*
|
|
619
|
+
* @example
|
|
620
|
+
* ```typescript
|
|
621
|
+
* import { adapty } from '@adapty/capacitor';
|
|
622
|
+
*
|
|
623
|
+
* try {
|
|
624
|
+
* await adapty.identify({ customerUserId: 'YOUR_USER_ID' });
|
|
625
|
+
* console.log('User identified successfully');
|
|
626
|
+
* } catch (error) {
|
|
627
|
+
* console.error('Failed to identify user:', error);
|
|
628
|
+
* }
|
|
629
|
+
* ```
|
|
630
|
+
*/
|
|
329
631
|
async identify(options) {
|
|
330
632
|
const method = 'identify';
|
|
331
633
|
const ctx = new LogContext();
|
|
332
634
|
const log = ctx.call({ methodName: method });
|
|
333
635
|
log.start(() => ({ options }));
|
|
636
|
+
const identifyParamsCoder = new AdaptyIdentifyParamsCoder();
|
|
637
|
+
const parameters = identifyParamsCoder.encode(options.params);
|
|
334
638
|
const argsWithUndefined = {
|
|
335
639
|
method,
|
|
336
640
|
customer_user_id: options.customerUserId,
|
|
641
|
+
parameters,
|
|
337
642
|
};
|
|
338
643
|
const args = filterUndefined(argsWithUndefined);
|
|
339
644
|
await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
340
645
|
}
|
|
646
|
+
/**
|
|
647
|
+
* Logs a paywall view event.
|
|
648
|
+
*
|
|
649
|
+
* @remarks
|
|
650
|
+
* Adapty helps you to measure the performance of the paywalls.
|
|
651
|
+
* We automatically collect all the metrics related to purchases except for custom paywall views.
|
|
652
|
+
* This is because only you know when the paywall was shown to a customer.
|
|
653
|
+
*
|
|
654
|
+
* Whenever you show a paywall to your user,
|
|
655
|
+
* call this function to log the event,
|
|
656
|
+
* and it will be accumulated in the paywall metrics.
|
|
657
|
+
*
|
|
658
|
+
* @param options - The options object
|
|
659
|
+
* @param options.paywall - The paywall object that was shown to the user.
|
|
660
|
+
* @returns A promise that resolves when the event is logged.
|
|
661
|
+
* @throws Error if an error occurs while logging the event.
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* ```typescript
|
|
665
|
+
* import { adapty } from '@adapty/capacitor';
|
|
666
|
+
*
|
|
667
|
+
* const paywall = await adapty.getPaywall({ placementId: 'YOUR_PLACEMENT_ID' });
|
|
668
|
+
* // ...after opening the paywall
|
|
669
|
+
* await adapty.logShowPaywall({ paywall });
|
|
670
|
+
* ```
|
|
671
|
+
*/
|
|
341
672
|
async logShowPaywall(options) {
|
|
342
673
|
const method = 'log_show_paywall';
|
|
343
674
|
const ctx = new LogContext();
|
|
@@ -351,6 +682,26 @@ export class Adapty {
|
|
|
351
682
|
const args = filterUndefined(argsWithUndefined);
|
|
352
683
|
await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
353
684
|
}
|
|
685
|
+
/**
|
|
686
|
+
* Opens a web paywall in the default browser.
|
|
687
|
+
*
|
|
688
|
+
* @param options - The options object
|
|
689
|
+
* @param options.paywallOrProduct - The paywall or product to open as a web paywall.
|
|
690
|
+
* @returns A promise that resolves when the web paywall is opened.
|
|
691
|
+
* @throws Error if an error occurs while opening the web paywall.
|
|
692
|
+
*
|
|
693
|
+
* @example
|
|
694
|
+
* ```typescript
|
|
695
|
+
* import { adapty } from '@adapty/capacitor';
|
|
696
|
+
*
|
|
697
|
+
* try {
|
|
698
|
+
* const paywall = await adapty.getPaywall({ placementId: 'YOUR_PLACEMENT_ID' });
|
|
699
|
+
* await adapty.openWebPaywall({ paywallOrProduct: paywall });
|
|
700
|
+
* } catch (error) {
|
|
701
|
+
* console.error('Failed to open web paywall:', error);
|
|
702
|
+
* }
|
|
703
|
+
* ```
|
|
704
|
+
*/
|
|
354
705
|
async openWebPaywall(options) {
|
|
355
706
|
const method = 'open_web_paywall';
|
|
356
707
|
const ctx = new LogContext();
|
|
@@ -358,12 +709,37 @@ export class Adapty {
|
|
|
358
709
|
log.start(() => ({ options }));
|
|
359
710
|
const paywallCoder = new AdaptyPaywallCoder();
|
|
360
711
|
const productCoder = new AdaptyPaywallProductCoder();
|
|
361
|
-
const argsWithUndefined = Object.assign({ method }, (this.isPaywallProduct(options.paywallOrProduct)
|
|
712
|
+
const argsWithUndefined = Object.assign(Object.assign({ method }, (this.isPaywallProduct(options.paywallOrProduct)
|
|
362
713
|
? { product: this.encodeWithLogging(productCoder, options.paywallOrProduct, 'AdaptyPaywallProduct', ctx) }
|
|
363
|
-
: { paywall: this.encodeWithLogging(paywallCoder, options.paywallOrProduct, 'AdaptyPaywall', ctx) }));
|
|
714
|
+
: { paywall: this.encodeWithLogging(paywallCoder, options.paywallOrProduct, 'AdaptyPaywall', ctx) })), (options.openIn ? { open_in: options.openIn } : {}));
|
|
364
715
|
const args = filterUndefined(argsWithUndefined);
|
|
365
716
|
await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
366
717
|
}
|
|
718
|
+
/**
|
|
719
|
+
* Creates a URL for a web paywall.
|
|
720
|
+
*
|
|
721
|
+
* @remarks
|
|
722
|
+
* This method generates a URL that can be used to open a web version of the paywall.
|
|
723
|
+
* You can use this URL in a custom web view or a browser.
|
|
724
|
+
*
|
|
725
|
+
* @param options - The options object
|
|
726
|
+
* @param options.paywallOrProduct - The paywall or product to create a URL for.
|
|
727
|
+
* @returns A promise that resolves with the web paywall URL.
|
|
728
|
+
* @throws Error if an error occurs while creating the URL.
|
|
729
|
+
*
|
|
730
|
+
* @example
|
|
731
|
+
* ```typescript
|
|
732
|
+
* import { adapty } from '@adapty/capacitor';
|
|
733
|
+
*
|
|
734
|
+
* try {
|
|
735
|
+
* const paywall = await adapty.getPaywall({ placementId: 'YOUR_PLACEMENT_ID' });
|
|
736
|
+
* const url = await adapty.createWebPaywallUrl({ paywallOrProduct: paywall });
|
|
737
|
+
* console.log('Web paywall URL:', url);
|
|
738
|
+
* } catch (error) {
|
|
739
|
+
* console.error('Failed to create web paywall URL:', error);
|
|
740
|
+
* }
|
|
741
|
+
* ```
|
|
742
|
+
*/
|
|
367
743
|
async createWebPaywallUrl(options) {
|
|
368
744
|
const method = 'create_web_paywall_url';
|
|
369
745
|
const ctx = new LogContext();
|
|
@@ -377,6 +753,27 @@ export class Adapty {
|
|
|
377
753
|
const args = filterUndefined(argsWithUndefined);
|
|
378
754
|
return await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
379
755
|
}
|
|
756
|
+
/**
|
|
757
|
+
* Logs out the current user.
|
|
758
|
+
*
|
|
759
|
+
* @remarks
|
|
760
|
+
* You can then login the user using {@link identify} method.
|
|
761
|
+
*
|
|
762
|
+
* @returns A promise that resolves when the user is logged out.
|
|
763
|
+
* @throws Error if an error occurs during logout.
|
|
764
|
+
*
|
|
765
|
+
* @example
|
|
766
|
+
* ```typescript
|
|
767
|
+
* import { adapty } from '@adapty/capacitor';
|
|
768
|
+
*
|
|
769
|
+
* try {
|
|
770
|
+
* await adapty.logout();
|
|
771
|
+
* console.log('User logged out successfully');
|
|
772
|
+
* } catch (error) {
|
|
773
|
+
* console.error('Failed to logout user:', error);
|
|
774
|
+
* }
|
|
775
|
+
* ```
|
|
776
|
+
*/
|
|
380
777
|
async logout() {
|
|
381
778
|
const method = 'logout';
|
|
382
779
|
const ctx = new LogContext();
|
|
@@ -388,6 +785,38 @@ export class Adapty {
|
|
|
388
785
|
const args = filterUndefined(argsWithUndefined);
|
|
389
786
|
await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
390
787
|
}
|
|
788
|
+
/**
|
|
789
|
+
* Performs a purchase of the specified product.
|
|
790
|
+
*
|
|
791
|
+
* @remarks
|
|
792
|
+
* In paywalls built with Paywall Builder, purchases are processed automatically with no additional code.
|
|
793
|
+
*
|
|
794
|
+
* @param options - The purchase options
|
|
795
|
+
* @param options.product - The product to be purchased. You can get it using {@link getPaywallProducts} method.
|
|
796
|
+
* @param options.params - Optional. Additional parameters for the purchase, including Android subscription update params.
|
|
797
|
+
* @returns A promise that resolves with the {@link AdaptyPurchaseResult} object containing details about the purchase.
|
|
798
|
+
* If the result is `'success'`, it also includes the updated user's profile.
|
|
799
|
+
* @throws Error if an error occurs during the purchase process.
|
|
800
|
+
*
|
|
801
|
+
* @example
|
|
802
|
+
* Basic purchase
|
|
803
|
+
* ```typescript
|
|
804
|
+
* import { adapty } from '@adapty/capacitor';
|
|
805
|
+
*
|
|
806
|
+
* try {
|
|
807
|
+
* const result = await adapty.makePurchase({ product });
|
|
808
|
+
*
|
|
809
|
+
* if (result.type === 'success') {
|
|
810
|
+
* const isSubscribed = result.profile?.accessLevels['YOUR_ACCESS_LEVEL']?.isActive;
|
|
811
|
+
* if (isSubscribed) {
|
|
812
|
+
* console.log('User is now subscribed!');
|
|
813
|
+
* }
|
|
814
|
+
* }
|
|
815
|
+
* } catch (error) {
|
|
816
|
+
* console.error('Purchase failed:', error);
|
|
817
|
+
* }
|
|
818
|
+
* ```
|
|
819
|
+
*/
|
|
391
820
|
async makePurchase(options) {
|
|
392
821
|
var _a;
|
|
393
822
|
const method = 'make_purchase';
|
|
@@ -403,12 +832,32 @@ export class Adapty {
|
|
|
403
832
|
const argsWithUndefined = {
|
|
404
833
|
method,
|
|
405
834
|
product: productInput,
|
|
406
|
-
|
|
407
|
-
is_offer_personalized: purchaseParams.is_offer_personalized,
|
|
835
|
+
parameters: purchaseParams,
|
|
408
836
|
};
|
|
409
837
|
const args = filterUndefined(argsWithUndefined);
|
|
410
838
|
return await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
411
839
|
}
|
|
840
|
+
/**
|
|
841
|
+
* Opens a native modal screen to redeem Apple Offer Codes.
|
|
842
|
+
*
|
|
843
|
+
* @remarks
|
|
844
|
+
* iOS 14+ only. Since iOS 14.0, your users can redeem Offer Codes.
|
|
845
|
+
* To enable users to redeem offer codes, you can display the offer code redemption sheet.
|
|
846
|
+
*
|
|
847
|
+
* @returns A promise that resolves when the redemption sheet is presented.
|
|
848
|
+
* @throws Error if an error occurs or if called on Android.
|
|
849
|
+
*
|
|
850
|
+
* @example
|
|
851
|
+
* ```typescript
|
|
852
|
+
* import { adapty } from '@adapty/capacitor';
|
|
853
|
+
*
|
|
854
|
+
* try {
|
|
855
|
+
* await adapty.presentCodeRedemptionSheet();
|
|
856
|
+
* } catch (error) {
|
|
857
|
+
* console.error('Failed to present code redemption sheet:', error);
|
|
858
|
+
* }
|
|
859
|
+
* ```
|
|
860
|
+
*/
|
|
412
861
|
async presentCodeRedemptionSheet() {
|
|
413
862
|
const method = 'present_code_redemption_sheet';
|
|
414
863
|
const ctx = new LogContext();
|
|
@@ -420,6 +869,34 @@ export class Adapty {
|
|
|
420
869
|
const args = filterUndefined(argsWithUndefined);
|
|
421
870
|
await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
422
871
|
}
|
|
872
|
+
/**
|
|
873
|
+
* Sets the variation ID of the purchase.
|
|
874
|
+
*
|
|
875
|
+
* @remarks
|
|
876
|
+
* In Observer mode, Adapty SDK doesn't know where the purchase was made from.
|
|
877
|
+
* you can manually assign variation to the purchase.
|
|
878
|
+
* After doing this, you'll be able to see metrics in Adapty Dashboard.
|
|
879
|
+
*
|
|
880
|
+
* @param options - The options object
|
|
881
|
+
* @param options.transactionId - The transaction ID of the purchase.
|
|
882
|
+
* @param options.variationId - Optional. The variation ID from the {@link AdaptyPaywall}.
|
|
883
|
+
* @returns A promise that resolves when the transaction is reported.
|
|
884
|
+
* @throws Error if an error occurs while reporting the transaction.
|
|
885
|
+
*
|
|
886
|
+
* @example
|
|
887
|
+
* ```typescript
|
|
888
|
+
* import { adapty } from '@adapty/capacitor';
|
|
889
|
+
*
|
|
890
|
+
* try {
|
|
891
|
+
* await adapty.reportTransaction({
|
|
892
|
+
* transactionId: 'transaction_123',
|
|
893
|
+
* variationId: 'variation_456'
|
|
894
|
+
* });
|
|
895
|
+
* } catch (error) {
|
|
896
|
+
* console.error('Failed to report transaction:', error);
|
|
897
|
+
* }
|
|
898
|
+
* ```
|
|
899
|
+
*/
|
|
423
900
|
async reportTransaction(options) {
|
|
424
901
|
const method = 'report_transaction';
|
|
425
902
|
const ctx = new LogContext();
|
|
@@ -433,6 +910,38 @@ export class Adapty {
|
|
|
433
910
|
const args = filterUndefined(argsWithUndefined);
|
|
434
911
|
await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
435
912
|
}
|
|
913
|
+
/**
|
|
914
|
+
* Restores user purchases and updates the profile.
|
|
915
|
+
*
|
|
916
|
+
* @remarks
|
|
917
|
+
* Restoring purchases allows users to regain access to previously purchased content,
|
|
918
|
+
* such as subscriptions or in-app purchases, without being charged again.
|
|
919
|
+
* This feature is especially useful for users who may have uninstalled and reinstalled the app
|
|
920
|
+
* or switched to a new device.
|
|
921
|
+
*
|
|
922
|
+
* In paywalls built with Paywall Builder, purchases are restored automatically without additional code from you.
|
|
923
|
+
*
|
|
924
|
+
* @returns A promise that resolves with the updated user's {@link AdaptyProfile}.
|
|
925
|
+
* @throws Error if an error occurs during the restore process.
|
|
926
|
+
*
|
|
927
|
+
* @example
|
|
928
|
+
* ```typescript
|
|
929
|
+
* import { adapty } from '@adapty/capacitor';
|
|
930
|
+
*
|
|
931
|
+
* try {
|
|
932
|
+
* const profile = await adapty.restorePurchases();
|
|
933
|
+
* const isSubscribed = profile.accessLevels['YOUR_ACCESS_LEVEL']?.isActive;
|
|
934
|
+
*
|
|
935
|
+
* if (isSubscribed) {
|
|
936
|
+
* console.log('Access restored successfully!');
|
|
937
|
+
* } else {
|
|
938
|
+
* console.log('No active subscriptions found');
|
|
939
|
+
* }
|
|
940
|
+
* } catch (error) {
|
|
941
|
+
* console.error('Failed to restore purchases:', error);
|
|
942
|
+
* }
|
|
943
|
+
* ```
|
|
944
|
+
*/
|
|
436
945
|
async restorePurchases() {
|
|
437
946
|
const method = 'restore_purchases';
|
|
438
947
|
const ctx = new LogContext();
|
|
@@ -444,6 +953,36 @@ export class Adapty {
|
|
|
444
953
|
const args = filterUndefined(argsWithUndefined);
|
|
445
954
|
return await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
446
955
|
}
|
|
956
|
+
/**
|
|
957
|
+
* Sets the fallback paywalls.
|
|
958
|
+
*
|
|
959
|
+
* @remarks
|
|
960
|
+
* Fallback file will be used if the SDK fails
|
|
961
|
+
* to fetch the paywalls from the dashboard.
|
|
962
|
+
* It is not designed to be used for the offline flow,
|
|
963
|
+
* as products are not cached in Adapty.
|
|
964
|
+
*
|
|
965
|
+
* @param options - The options object
|
|
966
|
+
* @param options.fileLocation - The location of the fallback file for each platform.
|
|
967
|
+
* @returns A promise that resolves when fallback placements are saved.
|
|
968
|
+
* @throws Error if an error occurs while setting the fallback.
|
|
969
|
+
*
|
|
970
|
+
* @example
|
|
971
|
+
* ```typescript
|
|
972
|
+
* import { adapty } from '@adapty/capacitor';
|
|
973
|
+
*
|
|
974
|
+
* try {
|
|
975
|
+
* await adapty.setFallback({
|
|
976
|
+
* fileLocation: {
|
|
977
|
+
* ios: { fileName: 'fallback_paywalls.json' },
|
|
978
|
+
* android: { relativeAssetPath: 'fallback_paywalls.json' }
|
|
979
|
+
* }
|
|
980
|
+
* });
|
|
981
|
+
* } catch (error) {
|
|
982
|
+
* console.error('Failed to set fallback:', error);
|
|
983
|
+
* }
|
|
984
|
+
* ```
|
|
985
|
+
*/
|
|
447
986
|
async setFallback(options) {
|
|
448
987
|
const method = 'set_fallback';
|
|
449
988
|
const platform = Capacitor.getPlatform();
|
|
@@ -473,6 +1012,33 @@ export class Adapty {
|
|
|
473
1012
|
const args = filterUndefined(argsWithUndefined);
|
|
474
1013
|
await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
475
1014
|
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Sets an integration identifier for the current user.
|
|
1017
|
+
*
|
|
1018
|
+
* @remarks
|
|
1019
|
+
* Integration identifiers can be used to link Adapty profiles to external systems
|
|
1020
|
+
* and track users across different platforms.
|
|
1021
|
+
*
|
|
1022
|
+
* @param options - The options object
|
|
1023
|
+
* @param options.key - The key of the integration identifier.
|
|
1024
|
+
* @param options.value - The value of the integration identifier.
|
|
1025
|
+
* @returns A promise that resolves when the integration identifier is set.
|
|
1026
|
+
* @throws Error if an error occurs while setting the identifier.
|
|
1027
|
+
*
|
|
1028
|
+
* @example
|
|
1029
|
+
* ```typescript
|
|
1030
|
+
* import { adapty } from '@adapty/capacitor';
|
|
1031
|
+
*
|
|
1032
|
+
* try {
|
|
1033
|
+
* await adapty.setIntegrationIdentifier({
|
|
1034
|
+
* key: 'firebase_app_instance_id',
|
|
1035
|
+
* value: 'YOUR_FIREBASE_ID'
|
|
1036
|
+
* });
|
|
1037
|
+
* } catch (error) {
|
|
1038
|
+
* console.error('Failed to set integration identifier:', error);
|
|
1039
|
+
* }
|
|
1040
|
+
* ```
|
|
1041
|
+
*/
|
|
476
1042
|
async setIntegrationIdentifier(options) {
|
|
477
1043
|
const method = 'set_integration_identifiers';
|
|
478
1044
|
const ctx = new LogContext();
|
|
@@ -485,6 +1051,41 @@ export class Adapty {
|
|
|
485
1051
|
const args = filterUndefined(argsWithUndefined);
|
|
486
1052
|
await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
487
1053
|
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Sets the preferred log level and/or custom logger configuration.
|
|
1056
|
+
*
|
|
1057
|
+
* @remarks
|
|
1058
|
+
* By default, the log level is set to `error`.
|
|
1059
|
+
*
|
|
1060
|
+
* There are four levels available:
|
|
1061
|
+
* - `error`: only errors will be logged
|
|
1062
|
+
* - `warn`: messages from the SDK that do not cause critical errors, but are worth paying attention to
|
|
1063
|
+
* - `info`: various information messages, such as those that log the lifecycle of various modules
|
|
1064
|
+
* - `verbose`: any additional information that may be useful during debugging, such as function calls, API queries, etc.
|
|
1065
|
+
*
|
|
1066
|
+
* @param options - The options object
|
|
1067
|
+
* @param options.logLevel - Optional. The new preferred log level.
|
|
1068
|
+
* @param options.logger - Optional. Custom logger configuration.
|
|
1069
|
+
* @returns A promise that resolves when the log level is set.
|
|
1070
|
+
* @throws Error if the log level is invalid.
|
|
1071
|
+
*
|
|
1072
|
+
* @example
|
|
1073
|
+
* ```typescript
|
|
1074
|
+
* import { adapty } from '@adapty/capacitor';
|
|
1075
|
+
*
|
|
1076
|
+
* // Set log level
|
|
1077
|
+
* await adapty.setLogLevel({ logLevel: 'verbose' });
|
|
1078
|
+
*
|
|
1079
|
+
* // Or set custom logger
|
|
1080
|
+
* await adapty.setLogLevel({
|
|
1081
|
+
* logger: {
|
|
1082
|
+
* handler: (level, scope, message, data) => {
|
|
1083
|
+
* sendLogToYourServer(`[${level}] ${message}`, data);
|
|
1084
|
+
* }
|
|
1085
|
+
* }
|
|
1086
|
+
* });
|
|
1087
|
+
* ```
|
|
1088
|
+
*/
|
|
488
1089
|
async setLogLevel(options) {
|
|
489
1090
|
const method = 'set_log_level';
|
|
490
1091
|
if (options.logger) {
|
|
@@ -504,6 +1105,36 @@ export class Adapty {
|
|
|
504
1105
|
await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
505
1106
|
}
|
|
506
1107
|
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Updates attribution data for the current user.
|
|
1110
|
+
*
|
|
1111
|
+
* @remarks
|
|
1112
|
+
* Attribution data can be used to track marketing campaigns and user acquisition sources.
|
|
1113
|
+
*
|
|
1114
|
+
* @param options - The options object
|
|
1115
|
+
* @param options.attribution - An object containing attribution data.
|
|
1116
|
+
* @param options.source - The source of the attribution data (e.g., 'adjust', 'appsflyer').
|
|
1117
|
+
* @returns A promise that resolves when the attribution data is updated.
|
|
1118
|
+
* @throws Error if parameters are invalid or not provided.
|
|
1119
|
+
*
|
|
1120
|
+
* @example
|
|
1121
|
+
* ```typescript
|
|
1122
|
+
* import { adapty } from '@adapty/capacitor';
|
|
1123
|
+
*
|
|
1124
|
+
* try {
|
|
1125
|
+
* const attribution = {
|
|
1126
|
+
* 'Adjust Adid': 'adjust_adid',
|
|
1127
|
+
* 'Adjust Network': 'adjust_network',
|
|
1128
|
+
* 'Adjust Campaign': 'adjust_campaign',
|
|
1129
|
+
* 'Adjust Adgroup': 'adjust_adgroup',
|
|
1130
|
+
* };
|
|
1131
|
+
*
|
|
1132
|
+
* await adapty.updateAttribution({ attribution, source: 'adjust' });
|
|
1133
|
+
* } catch (error) {
|
|
1134
|
+
* console.error('Failed to update attribution:', error);
|
|
1135
|
+
* }
|
|
1136
|
+
* ```
|
|
1137
|
+
*/
|
|
507
1138
|
async updateAttribution(options) {
|
|
508
1139
|
const method = 'update_attribution_data';
|
|
509
1140
|
const ctx = new LogContext();
|
|
@@ -517,6 +1148,29 @@ export class Adapty {
|
|
|
517
1148
|
const args = filterUndefined(argsWithUndefined);
|
|
518
1149
|
await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
519
1150
|
}
|
|
1151
|
+
/**
|
|
1152
|
+
* Updates the user's consent for collecting refund data.
|
|
1153
|
+
*
|
|
1154
|
+
* @remarks
|
|
1155
|
+
* iOS only. This method has no effect on Android.
|
|
1156
|
+
* Use this method to update whether the SDK should collect refund data for the user.
|
|
1157
|
+
*
|
|
1158
|
+
* @param options - The options object
|
|
1159
|
+
* @param options.consent - Whether to collect refund data.
|
|
1160
|
+
* @returns A promise that resolves when the consent is updated (or immediately on Android).
|
|
1161
|
+
* @throws Error if an error occurs on iOS.
|
|
1162
|
+
*
|
|
1163
|
+
* @example
|
|
1164
|
+
* ```typescript
|
|
1165
|
+
* import { adapty } from '@adapty/capacitor';
|
|
1166
|
+
*
|
|
1167
|
+
* try {
|
|
1168
|
+
* await adapty.updateCollectingRefundDataConsent({ consent: true });
|
|
1169
|
+
* } catch (error) {
|
|
1170
|
+
* console.error('Failed to update consent:', error);
|
|
1171
|
+
* }
|
|
1172
|
+
* ```
|
|
1173
|
+
*/
|
|
520
1174
|
async updateCollectingRefundDataConsent(options) {
|
|
521
1175
|
const platform = Capacitor.getPlatform();
|
|
522
1176
|
if (platform === 'android') {
|
|
@@ -533,6 +1187,29 @@ export class Adapty {
|
|
|
533
1187
|
const args = filterUndefined(argsWithUndefined);
|
|
534
1188
|
await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
535
1189
|
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Updates the user's refund preference.
|
|
1192
|
+
*
|
|
1193
|
+
* @remarks
|
|
1194
|
+
* iOS only. This method has no effect on Android.
|
|
1195
|
+
* Use this method to set the user's preference for handling refunds.
|
|
1196
|
+
*
|
|
1197
|
+
* @param options - The options object
|
|
1198
|
+
* @param options.refundPreference - The refund preference setting.
|
|
1199
|
+
* @returns A promise that resolves when the preference is updated (or immediately on Android).
|
|
1200
|
+
* @throws Error if an error occurs on iOS.
|
|
1201
|
+
*
|
|
1202
|
+
* @example
|
|
1203
|
+
* ```typescript
|
|
1204
|
+
* import { adapty } from '@adapty/capacitor';
|
|
1205
|
+
*
|
|
1206
|
+
* try {
|
|
1207
|
+
* await adapty.updateRefundPreference({ refundPreference: 'ask_to_cancel' });
|
|
1208
|
+
* } catch (error) {
|
|
1209
|
+
* console.error('Failed to update refund preference:', error);
|
|
1210
|
+
* }
|
|
1211
|
+
* ```
|
|
1212
|
+
*/
|
|
536
1213
|
async updateRefundPreference(options) {
|
|
537
1214
|
const platform = Capacitor.getPlatform();
|
|
538
1215
|
if (platform === 'android') {
|
|
@@ -549,6 +1226,58 @@ export class Adapty {
|
|
|
549
1226
|
const args = filterUndefined(argsWithUndefined);
|
|
550
1227
|
await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
551
1228
|
}
|
|
1229
|
+
/**
|
|
1230
|
+
* Updates a profile for the current user.
|
|
1231
|
+
*
|
|
1232
|
+
* @remarks
|
|
1233
|
+
* You can set optional attributes such as email, phone number, etc. to the user of your app.
|
|
1234
|
+
* You can then use attributes to create user segments or just view them in CRM.
|
|
1235
|
+
*
|
|
1236
|
+
* The attributes that you've previously set won't be reset.
|
|
1237
|
+
* Custom attributes can be removed by passing `null` as their values.
|
|
1238
|
+
*
|
|
1239
|
+
* @param options - An object of parameters to update. Partial {@link AdaptyProfileParameters}.
|
|
1240
|
+
* @returns A promise that resolves when the profile is updated.
|
|
1241
|
+
* @throws Error if parameters are invalid or there is a network error.
|
|
1242
|
+
*
|
|
1243
|
+
* @example
|
|
1244
|
+
* Basic profile update
|
|
1245
|
+
* ```typescript
|
|
1246
|
+
* import { adapty } from '@adapty/capacitor';
|
|
1247
|
+
*
|
|
1248
|
+
* try {
|
|
1249
|
+
* await adapty.updateProfile({
|
|
1250
|
+
* email: 'email@email.com',
|
|
1251
|
+
* phoneNumber: '+18888888888',
|
|
1252
|
+
* firstName: 'John',
|
|
1253
|
+
* lastName: 'Appleseed',
|
|
1254
|
+
* gender: 'other',
|
|
1255
|
+
* birthday: new Date().toISOString(),
|
|
1256
|
+
* });
|
|
1257
|
+
* console.log('Profile updated successfully');
|
|
1258
|
+
* } catch (error) {
|
|
1259
|
+
* console.error('Failed to update profile:', error);
|
|
1260
|
+
* }
|
|
1261
|
+
* ```
|
|
1262
|
+
*
|
|
1263
|
+
* @example
|
|
1264
|
+
* Custom attributes
|
|
1265
|
+
* ```typescript
|
|
1266
|
+
* await adapty.updateProfile({
|
|
1267
|
+
* codableCustomAttributes: {
|
|
1268
|
+
* key_1: 'value_1',
|
|
1269
|
+
* key_2: 2,
|
|
1270
|
+
* },
|
|
1271
|
+
* });
|
|
1272
|
+
*
|
|
1273
|
+
* // To remove keys, pass null as their values
|
|
1274
|
+
* await adapty.updateProfile({
|
|
1275
|
+
* codableCustomAttributes: {
|
|
1276
|
+
* key_1: null,
|
|
1277
|
+
* },
|
|
1278
|
+
* });
|
|
1279
|
+
* ```
|
|
1280
|
+
*/
|
|
552
1281
|
async updateProfile(options) {
|
|
553
1282
|
const method = 'update_profile';
|
|
554
1283
|
const ctx = new LogContext();
|
|
@@ -562,6 +1291,24 @@ export class Adapty {
|
|
|
562
1291
|
const args = filterUndefined(argsWithUndefined);
|
|
563
1292
|
await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
|
|
564
1293
|
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Removes all attached event listeners.
|
|
1296
|
+
*
|
|
1297
|
+
* @remarks
|
|
1298
|
+
* This method removes all event listeners that were added via {@link addListener}.
|
|
1299
|
+
* It's recommended to call this method when cleaning up resources,
|
|
1300
|
+
* such as when unmounting a component.
|
|
1301
|
+
*
|
|
1302
|
+
* @returns A promise that resolves when all listeners are removed.
|
|
1303
|
+
*
|
|
1304
|
+
* @example
|
|
1305
|
+
* ```typescript
|
|
1306
|
+
* import { adapty } from '@adapty/capacitor';
|
|
1307
|
+
*
|
|
1308
|
+
* // Remove all listeners
|
|
1309
|
+
* await adapty.removeAllListeners();
|
|
1310
|
+
* ```
|
|
1311
|
+
*/
|
|
565
1312
|
async removeAllListeners() {
|
|
566
1313
|
await this.emitter.removeAllListeners();
|
|
567
1314
|
}
|