@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.
Files changed (93) hide show
  1. package/AdaptyCapacitor.podspec +3 -3
  2. package/Package.swift +1 -1
  3. package/README.md +45 -29
  4. package/android/build.gradle +4 -3
  5. package/android/src/main/kotlin/com/adapty/plugin/capacitor/AdaptyCapacitorImplementation.kt +2 -0
  6. package/dist/esm/adapty.d.ts +752 -6
  7. package/dist/esm/adapty.js +755 -8
  8. package/dist/esm/adapty.js.map +1 -1
  9. package/dist/esm/index.d.ts +2 -1
  10. package/dist/esm/index.js.map +1 -1
  11. package/dist/esm/shared/coders/adapty-configuration.js +25 -14
  12. package/dist/esm/shared/coders/adapty-configuration.js.map +1 -1
  13. package/dist/esm/shared/coders/adapty-identify-params.d.ts +11 -0
  14. package/dist/esm/shared/coders/adapty-identify-params.js +19 -0
  15. package/dist/esm/shared/coders/adapty-identify-params.js.map +1 -0
  16. package/dist/esm/shared/coders/adapty-paywall-product.d.ts +1 -1
  17. package/dist/esm/shared/coders/adapty-paywall-product.js +12 -0
  18. package/dist/esm/shared/coders/adapty-paywall-product.js.map +1 -1
  19. package/dist/esm/shared/coders/adapty-purchase-params.js +0 -8
  20. package/dist/esm/shared/coders/adapty-purchase-params.js.map +1 -1
  21. package/dist/esm/shared/coders/adapty-purchase-result.js +18 -2
  22. package/dist/esm/shared/coders/adapty-purchase-result.js.map +1 -1
  23. package/dist/esm/shared/coders/adapty-ui-create-onboarding-view-params.d.ts +8 -0
  24. package/dist/esm/shared/coders/adapty-ui-create-onboarding-view-params.js +10 -0
  25. package/dist/esm/shared/coders/adapty-ui-create-onboarding-view-params.js.map +1 -0
  26. package/dist/esm/shared/coders/adapty-ui-create-paywall-view-params.d.ts +18 -0
  27. package/dist/esm/shared/coders/adapty-ui-create-paywall-view-params.js +142 -0
  28. package/dist/esm/shared/coders/adapty-ui-create-paywall-view-params.js.map +1 -0
  29. package/dist/esm/shared/coders/parse-onboarding.d.ts +3 -0
  30. package/dist/esm/shared/coders/parse-onboarding.js +86 -0
  31. package/dist/esm/shared/coders/parse-onboarding.js.map +1 -0
  32. package/dist/esm/shared/coders/parse-paywall.d.ts +4 -0
  33. package/dist/esm/shared/coders/parse-paywall.js +141 -0
  34. package/dist/esm/shared/coders/parse-paywall.js.map +1 -0
  35. package/dist/esm/shared/coders/parse.d.ts +0 -2
  36. package/dist/esm/shared/coders/parse.js +0 -75
  37. package/dist/esm/shared/coders/parse.js.map +1 -1
  38. package/dist/esm/shared/coders/product-reference.js +10 -0
  39. package/dist/esm/shared/coders/product-reference.js.map +1 -1
  40. package/dist/esm/shared/coders/utils.d.ts +18 -0
  41. package/dist/esm/shared/coders/utils.js +50 -0
  42. package/dist/esm/shared/coders/utils.js.map +1 -0
  43. package/dist/esm/shared/types/index.d.ts +16 -0
  44. package/dist/esm/shared/types/index.js +5 -0
  45. package/dist/esm/shared/types/index.js.map +1 -1
  46. package/dist/esm/shared/types/inputs.d.ts +47 -14
  47. package/dist/esm/shared/types/inputs.js.map +1 -1
  48. package/dist/esm/shared/types/onboarding-events.d.ts +60 -0
  49. package/dist/esm/shared/types/onboarding-events.js +11 -0
  50. package/dist/esm/shared/types/onboarding-events.js.map +1 -0
  51. package/dist/esm/shared/types/paywall-events.d.ts +84 -0
  52. package/dist/esm/shared/types/paywall-events.js +16 -0
  53. package/dist/esm/shared/types/paywall-events.js.map +1 -0
  54. package/dist/esm/shared/utils/platform.d.ts +2 -0
  55. package/dist/esm/shared/utils/platform.js +5 -0
  56. package/dist/esm/shared/utils/platform.js.map +1 -0
  57. package/dist/esm/types/adapty-plugin.d.ts +2 -1
  58. package/dist/esm/types/adapty-plugin.js.map +1 -1
  59. package/dist/esm/ui-builder/base-view-emitter.d.ts +14 -20
  60. package/dist/esm/ui-builder/base-view-emitter.js +95 -73
  61. package/dist/esm/ui-builder/base-view-emitter.js.map +1 -1
  62. package/dist/esm/ui-builder/create-onboarding-view.d.ts +32 -0
  63. package/dist/esm/ui-builder/create-onboarding-view.js +36 -0
  64. package/dist/esm/ui-builder/create-onboarding-view.js.map +1 -0
  65. package/dist/esm/ui-builder/create-paywall-view.d.ts +25 -0
  66. package/dist/esm/ui-builder/create-paywall-view.js +29 -0
  67. package/dist/esm/ui-builder/create-paywall-view.js.map +1 -0
  68. package/dist/esm/ui-builder/index.d.ts +6 -37
  69. package/dist/esm/ui-builder/index.js +4 -41
  70. package/dist/esm/ui-builder/index.js.map +1 -1
  71. package/dist/esm/ui-builder/onboarding-view-controller.d.ts +103 -17
  72. package/dist/esm/ui-builder/onboarding-view-controller.js +112 -22
  73. package/dist/esm/ui-builder/onboarding-view-controller.js.map +1 -1
  74. package/dist/esm/ui-builder/onboarding-view-emitter.d.ts +10 -24
  75. package/dist/esm/ui-builder/onboarding-view-emitter.js +49 -56
  76. package/dist/esm/ui-builder/onboarding-view-emitter.js.map +1 -1
  77. package/dist/esm/ui-builder/paywall-view-controller.d.ts +130 -30
  78. package/dist/esm/ui-builder/paywall-view-controller.js +141 -71
  79. package/dist/esm/ui-builder/paywall-view-controller.js.map +1 -1
  80. package/dist/esm/ui-builder/paywall-view-emitter.d.ts +8 -28
  81. package/dist/esm/ui-builder/paywall-view-emitter.js +86 -118
  82. package/dist/esm/ui-builder/paywall-view-emitter.js.map +1 -1
  83. package/dist/esm/ui-builder/types.d.ts +89 -4
  84. package/dist/esm/ui-builder/types.js +3 -3
  85. package/dist/esm/ui-builder/types.js.map +1 -1
  86. package/dist/esm/version.d.ts +1 -1
  87. package/dist/esm/version.js +1 -1
  88. package/dist/esm/version.js.map +1 -1
  89. package/dist/plugin.cjs.js +1896 -556
  90. package/dist/plugin.cjs.js.map +1 -1
  91. package/dist/plugin.js +1896 -556
  92. package/dist/plugin.js.map +1 -1
  93. package/package.json +2 -2
@@ -1,10 +1,18 @@
1
1
  import { LogContext } from './shared/logger';
2
2
  import type { LoggerConfig, LogScope } from './shared/logger';
3
- import type { AdaptyPaywall, AdaptyPaywallProduct, AdaptyOnboarding, AdaptyProfile, AdaptyPurchaseResult, AdaptyProfileParameters, RefundPreference, AdaptyInstallationStatus } from './shared/types';
4
- import type { ActivateParamsInput, FileLocation, LogLevel } from './shared/types/inputs';
3
+ import type { AdaptyPaywall, AdaptyPaywallProduct, AdaptyOnboarding, AdaptyProfile, AdaptyPurchaseResult, AdaptyProfileParameters, RefundPreference, AdaptyInstallationStatus, WebPresentation } from './shared/types';
4
+ import type { ActivateParamsInput, FileLocation, LogLevel, IdentifyParamsInput } from './shared/types/inputs';
5
5
  import { type MethodName, type MethodResponseMap } from './shared/types/method-types';
6
6
  import type { AdaptyPlugin, AddListenerFn } from './types/adapty-plugin';
7
7
  import type { GetPaywallOptions, GetPaywallForDefaultAudienceOptions, MakePurchaseOptions, GetOnboardingOptions, GetOnboardingForDefaultAudienceOptions } from './types/configs';
8
+ /**
9
+ * Entry point for the Adapty SDK.
10
+ *
11
+ * @remarks
12
+ * This is the main Adapty class, excluding UI rendering functionality.
13
+ *
14
+ * @public
15
+ */
8
16
  export declare class Adapty implements AdaptyPlugin {
9
17
  private activating;
10
18
  private resolveHeldActivation?;
@@ -17,75 +25,813 @@ export declare class Adapty implements AdaptyPlugin {
17
25
  private encodeWithLogging;
18
26
  /**
19
27
  * Handle method calls through crossplatform bridge with type safety
28
+ * @internal
20
29
  */
21
30
  handleMethodCall<M extends MethodName>(methodName: M, args: string, ctx: LogContext, log: LogScope): Promise<MethodResponseMap[M]>;
22
31
  private isPaywallProduct;
23
32
  /**
24
33
  * Initializes the Adapty SDK.
25
34
  *
35
+ * @remarks
36
+ * This method must be called in order for the SDK to work.
37
+ * It is preferred to call it as early as possible in the app lifecycle,
38
+ * so background activities can be performed and cache can be updated.
39
+ *
40
+ * @example
41
+ *
42
+ * @example
43
+ * Usage with your user identifier from your system
44
+ * ```typescript
45
+ * await adapty.activate({
46
+ * apiKey: 'YOUR_PUBLIC_SDK_KEY',
47
+ * params: {
48
+ * customerUserId: 'YOUR_USER_ID'
49
+ * }
50
+ * });
51
+ * ```
52
+ *
26
53
  * @param options - The activation options
27
- * @param options.apiKey - Your Adapty API key
28
- * @param options.params - Optional activation parameters
29
- * @returns Promise that resolves when the SDK is activated
30
- * @throws Error if the API key is invalid or activation fails
54
+ * @param options.apiKey - You can find it in your app settings in Adapty Dashboard App settings > General.
55
+ * @param options.params - Optional activation parameters of type {@link ActivateParamsInput}.
56
+ * @returns A promise that resolves when the SDK is activated.
57
+ * @throws Error if the SDK is already activated or if the API key is invalid.
31
58
  */
32
59
  activate(options: {
33
60
  apiKey: string;
34
61
  params?: ActivateParamsInput;
35
62
  }): Promise<void>;
36
63
  private performActivation;
64
+ /**
65
+ * Checks if the Adapty SDK is activated.
66
+ *
67
+ * @returns A promise that resolves to `true` if the SDK is activated, `false` otherwise.
68
+ * @throws Error if an error occurs while checking activation status.
69
+ */
37
70
  isActivated(): Promise<boolean>;
71
+ /**
72
+ * Gets the current installation status.
73
+ *
74
+ * @remarks
75
+ * Installation status provides information about when the app was installed,
76
+ * how many times it has been launched, and other installation-related details.
77
+ * The status can be "not_available", "not_determined", or "determined" with details.
78
+ *
79
+ * @returns A promise that resolves with the installation status.
80
+ * @throws Error if an error occurs while retrieving the installation status.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * import { adapty } from '@adapty/capacitor';
85
+ *
86
+ * try {
87
+ * const status = await adapty.getCurrentInstallationStatus();
88
+ * if (status.status === 'determined') {
89
+ * console.log('Install time:', status.details.installTime);
90
+ * console.log('Launch count:', status.details.appLaunchCount);
91
+ * }
92
+ * } catch (error) {
93
+ * console.error('Failed to get installation status:', error);
94
+ * }
95
+ * ```
96
+ */
38
97
  getCurrentInstallationStatus(): Promise<AdaptyInstallationStatus>;
98
+ /**
99
+ * Fetches the paywall by the specified placement.
100
+ *
101
+ * @remarks
102
+ * With Adapty, you can remotely configure the products and offers in your app
103
+ * by simply adding them to paywalls – no need for hardcoding them.
104
+ * The only thing you hardcode is the placement ID.
105
+ * This flexibility allows you to easily update paywalls, products, and offers,
106
+ * or run A/B tests, all without the need for a new app release.
107
+ *
108
+ * @param options - The options for fetching the paywall
109
+ * @param options.placementId - The identifier of the desired placement. This is the value you specified when creating a placement in the Adapty Dashboard.
110
+ * @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.
111
+ * @param options.params - Optional. Additional parameters for fetching the paywall, including fetch policy and load timeout.
112
+ * @returns A promise that resolves with the requested {@link AdaptyPaywall}.
113
+ * @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.
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * import { adapty } from '@adapty/capacitor';
118
+ *
119
+ * try {
120
+ * const paywall = await adapty.getPaywall({
121
+ * placementId: 'YOUR_PLACEMENT_ID',
122
+ * locale: 'en',
123
+ * });
124
+ * console.log('Paywall fetched successfully');
125
+ * } catch (error) {
126
+ * console.error('Failed to fetch paywall:', error);
127
+ * }
128
+ * ```
129
+ */
39
130
  getPaywall(options: GetPaywallOptions): Promise<AdaptyPaywall>;
131
+ /**
132
+ * Fetches the paywall of the specified placement for the **All Users** audience.
133
+ *
134
+ * @remarks
135
+ * With Adapty, you can remotely configure the products and offers in your app
136
+ * by simply adding them to paywalls – no need for hardcoding them.
137
+ * The only thing you hardcode is the placement ID.
138
+ *
139
+ * However, it's crucial to understand that the recommended approach is to fetch the paywall
140
+ * through the placement ID by the {@link getPaywall} method.
141
+ * The `getPaywallForDefaultAudience` method should be a last resort due to its significant drawbacks:
142
+ * - Potential backward compatibility issues
143
+ * - Loss of targeting (all users see the same paywall)
144
+ *
145
+ * 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.
146
+ *
147
+ * @param options - The options for fetching the paywall
148
+ * @param options.placementId - The identifier of the desired placement.
149
+ * @param options.locale - Optional. The identifier of the paywall localization. Default: `'en'`.
150
+ * @param options.params - Optional. Additional parameters for fetching the paywall.
151
+ * @returns A promise that resolves with the requested {@link AdaptyPaywall}.
152
+ * @throws Error if the paywall with the specified ID is not found.
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * import { adapty } from '@adapty/capacitor';
157
+ *
158
+ * try {
159
+ * const paywall = await adapty.getPaywallForDefaultAudience({
160
+ * placementId: 'YOUR_PLACEMENT_ID',
161
+ * locale: 'en',
162
+ * });
163
+ * } catch (error) {
164
+ * console.error('Failed to fetch paywall:', error);
165
+ * }
166
+ * ```
167
+ */
40
168
  getPaywallForDefaultAudience(options: GetPaywallForDefaultAudienceOptions): Promise<AdaptyPaywall>;
169
+ /**
170
+ * Fetches a list of products associated with a provided paywall.
171
+ *
172
+ * @param options - The options object
173
+ * @param options.paywall - A paywall to fetch products for. You can get it using {@link getPaywall} method.
174
+ * @returns A promise that resolves with a list of {@link AdaptyPaywallProduct} associated with a provided paywall.
175
+ * @throws Error if an error occurs while fetching products.
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * import { adapty } from '@adapty/capacitor';
180
+ *
181
+ * try {
182
+ * const paywall = await adapty.getPaywall({ placementId: 'YOUR_PLACEMENT_ID' });
183
+ * const products = await adapty.getPaywallProducts({ paywall });
184
+ * console.log('Products:', products);
185
+ * } catch (error) {
186
+ * console.error('Failed to fetch products:', error);
187
+ * }
188
+ * ```
189
+ */
41
190
  getPaywallProducts(options: {
42
191
  paywall: AdaptyPaywall;
43
192
  }): Promise<AdaptyPaywallProduct[]>;
193
+ /**
194
+ * Fetches the onboarding by the specified placement.
195
+ *
196
+ * @remarks
197
+ * When you create an onboarding with the no-code builder, it's stored as a container with configuration
198
+ * that your app needs to fetch and display. This container manages the entire experience - what content appears,
199
+ * how it's presented, and how user interactions are processed.
200
+ *
201
+ * @param options - The options for fetching the onboarding
202
+ * @param options.placementId - The identifier of the desired placement.
203
+ * @param options.locale - Optional. The identifier of the onboarding localization. Default: `'en'`.
204
+ * @param options.params - Optional. Additional parameters for fetching the onboarding.
205
+ * @returns A promise that resolves with the requested {@link AdaptyOnboarding}.
206
+ * @throws Error if the onboarding with the specified ID is not found.
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * import { adapty } from '@adapty/capacitor';
211
+ *
212
+ * try {
213
+ * const onboarding = await adapty.getOnboarding({
214
+ * placementId: 'YOUR_PLACEMENT_ID',
215
+ * locale: 'en',
216
+ * params: {
217
+ * fetchPolicy: 'reload_revalidating_cache_data',
218
+ * loadTimeoutMs: 5000
219
+ * }
220
+ * });
221
+ * console.log('Onboarding fetched successfully');
222
+ * } catch (error) {
223
+ * console.error('Failed to fetch onboarding:', error);
224
+ * }
225
+ * ```
226
+ */
44
227
  getOnboarding(options: GetOnboardingOptions): Promise<AdaptyOnboarding>;
228
+ /**
229
+ * Fetches the onboarding of the specified placement for the **All Users** audience.
230
+ *
231
+ * @remarks
232
+ * It's crucial to understand that the recommended approach is to fetch the onboarding
233
+ * by the {@link getOnboarding} method. The `getOnboardingForDefaultAudience` method
234
+ * should be used only if faster fetching outweighs the drawbacks:
235
+ * - Potential backward compatibility issues
236
+ * - Loss of personalization (no targeting based on country, attribution, or custom attributes)
237
+ *
238
+ * @param options - The options for fetching the onboarding
239
+ * @param options.placementId - The identifier of the desired placement.
240
+ * @param options.locale - Optional. The identifier of the onboarding localization. Default: `'en'`.
241
+ * @param options.params - Optional. Additional parameters for fetching the onboarding.
242
+ * @returns A promise that resolves with the requested {@link AdaptyOnboarding}.
243
+ * @throws Error if the onboarding with the specified ID is not found.
244
+ *
245
+ * @example
246
+ * ```typescript
247
+ * import { adapty } from '@adapty/capacitor';
248
+ *
249
+ * try {
250
+ * const onboarding = await adapty.getOnboardingForDefaultAudience({
251
+ * placementId: 'YOUR_PLACEMENT_ID',
252
+ * locale: 'en',
253
+ * });
254
+ * } catch (error) {
255
+ * console.error('Failed to fetch onboarding:', error);
256
+ * }
257
+ * ```
258
+ */
45
259
  getOnboardingForDefaultAudience(options: GetOnboardingForDefaultAudienceOptions): Promise<AdaptyOnboarding>;
260
+ /**
261
+ * Fetches a user profile.
262
+ *
263
+ * @remarks
264
+ * The getProfile method provides the most up-to-date result
265
+ * as it always tries to query the API.
266
+ * If for some reason (e.g. no internet connection),
267
+ * the Adapty SDK fails to retrieve information from the server,
268
+ * the data from cache will be returned.
269
+ * It is also important to note
270
+ * that the Adapty SDK updates {@link AdaptyProfile} cache
271
+ * on a regular basis, in order
272
+ * to keep this information as up-to-date as possible.
273
+ *
274
+ * @returns A promise that resolves with the user's {@link AdaptyProfile}.
275
+ * @throws Error if an error occurs while fetching the profile.
276
+ *
277
+ * @example
278
+ * ```typescript
279
+ * import { adapty } from '@adapty/capacitor';
280
+ *
281
+ * try {
282
+ * const profile = await adapty.getProfile();
283
+ * const isSubscribed = profile.accessLevels['YOUR_ACCESS_LEVEL']?.isActive;
284
+ * if (isSubscribed) {
285
+ * console.log('User has access to premium features');
286
+ * }
287
+ * } catch (error) {
288
+ * console.error('Failed to get profile:', error);
289
+ * }
290
+ * ```
291
+ */
46
292
  getProfile(): Promise<AdaptyProfile>;
293
+ /**
294
+ * Logs in a user with a provided customerUserId.
295
+ *
296
+ * @remarks
297
+ * If you don't have a user id on SDK initialization,
298
+ * you can set it later at any time with this method.
299
+ * The most common cases are after registration/authorization
300
+ * when the user switches from being an anonymous user to an authenticated user.
301
+ *
302
+ * @param options - The identification options
303
+ * @param options.customerUserId - A unique user identifier.
304
+ * @param options.params - Optional. Additional parameters for identification, including platform-specific settings.
305
+ * @returns A promise that resolves when identification is complete.
306
+ * @throws Error if an error occurs during identification.
307
+ *
308
+ * @example
309
+ * ```typescript
310
+ * import { adapty } from '@adapty/capacitor';
311
+ *
312
+ * try {
313
+ * await adapty.identify({ customerUserId: 'YOUR_USER_ID' });
314
+ * console.log('User identified successfully');
315
+ * } catch (error) {
316
+ * console.error('Failed to identify user:', error);
317
+ * }
318
+ * ```
319
+ */
47
320
  identify(options: {
48
321
  customerUserId: string;
322
+ params?: IdentifyParamsInput;
49
323
  }): Promise<void>;
324
+ /**
325
+ * Logs a paywall view event.
326
+ *
327
+ * @remarks
328
+ * Adapty helps you to measure the performance of the paywalls.
329
+ * We automatically collect all the metrics related to purchases except for custom paywall views.
330
+ * This is because only you know when the paywall was shown to a customer.
331
+ *
332
+ * Whenever you show a paywall to your user,
333
+ * call this function to log the event,
334
+ * and it will be accumulated in the paywall metrics.
335
+ *
336
+ * @param options - The options object
337
+ * @param options.paywall - The paywall object that was shown to the user.
338
+ * @returns A promise that resolves when the event is logged.
339
+ * @throws Error if an error occurs while logging the event.
340
+ *
341
+ * @example
342
+ * ```typescript
343
+ * import { adapty } from '@adapty/capacitor';
344
+ *
345
+ * const paywall = await adapty.getPaywall({ placementId: 'YOUR_PLACEMENT_ID' });
346
+ * // ...after opening the paywall
347
+ * await adapty.logShowPaywall({ paywall });
348
+ * ```
349
+ */
50
350
  logShowPaywall(options: {
51
351
  paywall: AdaptyPaywall;
52
352
  }): Promise<void>;
353
+ /**
354
+ * Opens a web paywall in the default browser.
355
+ *
356
+ * @param options - The options object
357
+ * @param options.paywallOrProduct - The paywall or product to open as a web paywall.
358
+ * @returns A promise that resolves when the web paywall is opened.
359
+ * @throws Error if an error occurs while opening the web paywall.
360
+ *
361
+ * @example
362
+ * ```typescript
363
+ * import { adapty } from '@adapty/capacitor';
364
+ *
365
+ * try {
366
+ * const paywall = await adapty.getPaywall({ placementId: 'YOUR_PLACEMENT_ID' });
367
+ * await adapty.openWebPaywall({ paywallOrProduct: paywall });
368
+ * } catch (error) {
369
+ * console.error('Failed to open web paywall:', error);
370
+ * }
371
+ * ```
372
+ */
53
373
  openWebPaywall(options: {
54
374
  paywallOrProduct: AdaptyPaywall | AdaptyPaywallProduct;
375
+ openIn?: WebPresentation;
55
376
  }): Promise<void>;
377
+ /**
378
+ * Creates a URL for a web paywall.
379
+ *
380
+ * @remarks
381
+ * This method generates a URL that can be used to open a web version of the paywall.
382
+ * You can use this URL in a custom web view or a browser.
383
+ *
384
+ * @param options - The options object
385
+ * @param options.paywallOrProduct - The paywall or product to create a URL for.
386
+ * @returns A promise that resolves with the web paywall URL.
387
+ * @throws Error if an error occurs while creating the URL.
388
+ *
389
+ * @example
390
+ * ```typescript
391
+ * import { adapty } from '@adapty/capacitor';
392
+ *
393
+ * try {
394
+ * const paywall = await adapty.getPaywall({ placementId: 'YOUR_PLACEMENT_ID' });
395
+ * const url = await adapty.createWebPaywallUrl({ paywallOrProduct: paywall });
396
+ * console.log('Web paywall URL:', url);
397
+ * } catch (error) {
398
+ * console.error('Failed to create web paywall URL:', error);
399
+ * }
400
+ * ```
401
+ */
56
402
  createWebPaywallUrl(options: {
57
403
  paywallOrProduct: AdaptyPaywall | AdaptyPaywallProduct;
58
404
  }): Promise<string>;
405
+ /**
406
+ * Logs out the current user.
407
+ *
408
+ * @remarks
409
+ * You can then login the user using {@link identify} method.
410
+ *
411
+ * @returns A promise that resolves when the user is logged out.
412
+ * @throws Error if an error occurs during logout.
413
+ *
414
+ * @example
415
+ * ```typescript
416
+ * import { adapty } from '@adapty/capacitor';
417
+ *
418
+ * try {
419
+ * await adapty.logout();
420
+ * console.log('User logged out successfully');
421
+ * } catch (error) {
422
+ * console.error('Failed to logout user:', error);
423
+ * }
424
+ * ```
425
+ */
59
426
  logout(): Promise<void>;
427
+ /**
428
+ * Performs a purchase of the specified product.
429
+ *
430
+ * @remarks
431
+ * In paywalls built with Paywall Builder, purchases are processed automatically with no additional code.
432
+ *
433
+ * @param options - The purchase options
434
+ * @param options.product - The product to be purchased. You can get it using {@link getPaywallProducts} method.
435
+ * @param options.params - Optional. Additional parameters for the purchase, including Android subscription update params.
436
+ * @returns A promise that resolves with the {@link AdaptyPurchaseResult} object containing details about the purchase.
437
+ * If the result is `'success'`, it also includes the updated user's profile.
438
+ * @throws Error if an error occurs during the purchase process.
439
+ *
440
+ * @example
441
+ * Basic purchase
442
+ * ```typescript
443
+ * import { adapty } from '@adapty/capacitor';
444
+ *
445
+ * try {
446
+ * const result = await adapty.makePurchase({ product });
447
+ *
448
+ * if (result.type === 'success') {
449
+ * const isSubscribed = result.profile?.accessLevels['YOUR_ACCESS_LEVEL']?.isActive;
450
+ * if (isSubscribed) {
451
+ * console.log('User is now subscribed!');
452
+ * }
453
+ * }
454
+ * } catch (error) {
455
+ * console.error('Purchase failed:', error);
456
+ * }
457
+ * ```
458
+ */
60
459
  makePurchase(options: MakePurchaseOptions): Promise<AdaptyPurchaseResult>;
460
+ /**
461
+ * Opens a native modal screen to redeem Apple Offer Codes.
462
+ *
463
+ * @remarks
464
+ * iOS 14+ only. Since iOS 14.0, your users can redeem Offer Codes.
465
+ * To enable users to redeem offer codes, you can display the offer code redemption sheet.
466
+ *
467
+ * @returns A promise that resolves when the redemption sheet is presented.
468
+ * @throws Error if an error occurs or if called on Android.
469
+ *
470
+ * @example
471
+ * ```typescript
472
+ * import { adapty } from '@adapty/capacitor';
473
+ *
474
+ * try {
475
+ * await adapty.presentCodeRedemptionSheet();
476
+ * } catch (error) {
477
+ * console.error('Failed to present code redemption sheet:', error);
478
+ * }
479
+ * ```
480
+ */
61
481
  presentCodeRedemptionSheet(): Promise<void>;
482
+ /**
483
+ * Sets the variation ID of the purchase.
484
+ *
485
+ * @remarks
486
+ * In Observer mode, Adapty SDK doesn't know where the purchase was made from.
487
+ * you can manually assign variation to the purchase.
488
+ * After doing this, you'll be able to see metrics in Adapty Dashboard.
489
+ *
490
+ * @param options - The options object
491
+ * @param options.transactionId - The transaction ID of the purchase.
492
+ * @param options.variationId - Optional. The variation ID from the {@link AdaptyPaywall}.
493
+ * @returns A promise that resolves when the transaction is reported.
494
+ * @throws Error if an error occurs while reporting the transaction.
495
+ *
496
+ * @example
497
+ * ```typescript
498
+ * import { adapty } from '@adapty/capacitor';
499
+ *
500
+ * try {
501
+ * await adapty.reportTransaction({
502
+ * transactionId: 'transaction_123',
503
+ * variationId: 'variation_456'
504
+ * });
505
+ * } catch (error) {
506
+ * console.error('Failed to report transaction:', error);
507
+ * }
508
+ * ```
509
+ */
62
510
  reportTransaction(options: {
63
511
  transactionId: string;
64
512
  variationId?: string;
65
513
  }): Promise<void>;
514
+ /**
515
+ * Restores user purchases and updates the profile.
516
+ *
517
+ * @remarks
518
+ * Restoring purchases allows users to regain access to previously purchased content,
519
+ * such as subscriptions or in-app purchases, without being charged again.
520
+ * This feature is especially useful for users who may have uninstalled and reinstalled the app
521
+ * or switched to a new device.
522
+ *
523
+ * In paywalls built with Paywall Builder, purchases are restored automatically without additional code from you.
524
+ *
525
+ * @returns A promise that resolves with the updated user's {@link AdaptyProfile}.
526
+ * @throws Error if an error occurs during the restore process.
527
+ *
528
+ * @example
529
+ * ```typescript
530
+ * import { adapty } from '@adapty/capacitor';
531
+ *
532
+ * try {
533
+ * const profile = await adapty.restorePurchases();
534
+ * const isSubscribed = profile.accessLevels['YOUR_ACCESS_LEVEL']?.isActive;
535
+ *
536
+ * if (isSubscribed) {
537
+ * console.log('Access restored successfully!');
538
+ * } else {
539
+ * console.log('No active subscriptions found');
540
+ * }
541
+ * } catch (error) {
542
+ * console.error('Failed to restore purchases:', error);
543
+ * }
544
+ * ```
545
+ */
66
546
  restorePurchases(): Promise<AdaptyProfile>;
547
+ /**
548
+ * Sets the fallback paywalls.
549
+ *
550
+ * @remarks
551
+ * Fallback file will be used if the SDK fails
552
+ * to fetch the paywalls from the dashboard.
553
+ * It is not designed to be used for the offline flow,
554
+ * as products are not cached in Adapty.
555
+ *
556
+ * @param options - The options object
557
+ * @param options.fileLocation - The location of the fallback file for each platform.
558
+ * @returns A promise that resolves when fallback placements are saved.
559
+ * @throws Error if an error occurs while setting the fallback.
560
+ *
561
+ * @example
562
+ * ```typescript
563
+ * import { adapty } from '@adapty/capacitor';
564
+ *
565
+ * try {
566
+ * await adapty.setFallback({
567
+ * fileLocation: {
568
+ * ios: { fileName: 'fallback_paywalls.json' },
569
+ * android: { relativeAssetPath: 'fallback_paywalls.json' }
570
+ * }
571
+ * });
572
+ * } catch (error) {
573
+ * console.error('Failed to set fallback:', error);
574
+ * }
575
+ * ```
576
+ */
67
577
  setFallback(options: {
68
578
  fileLocation: FileLocation;
69
579
  }): Promise<void>;
580
+ /**
581
+ * Sets an integration identifier for the current user.
582
+ *
583
+ * @remarks
584
+ * Integration identifiers can be used to link Adapty profiles to external systems
585
+ * and track users across different platforms.
586
+ *
587
+ * @param options - The options object
588
+ * @param options.key - The key of the integration identifier.
589
+ * @param options.value - The value of the integration identifier.
590
+ * @returns A promise that resolves when the integration identifier is set.
591
+ * @throws Error if an error occurs while setting the identifier.
592
+ *
593
+ * @example
594
+ * ```typescript
595
+ * import { adapty } from '@adapty/capacitor';
596
+ *
597
+ * try {
598
+ * await adapty.setIntegrationIdentifier({
599
+ * key: 'firebase_app_instance_id',
600
+ * value: 'YOUR_FIREBASE_ID'
601
+ * });
602
+ * } catch (error) {
603
+ * console.error('Failed to set integration identifier:', error);
604
+ * }
605
+ * ```
606
+ */
70
607
  setIntegrationIdentifier(options: {
71
608
  key: string;
72
609
  value: string;
73
610
  }): Promise<void>;
611
+ /**
612
+ * Sets the preferred log level and/or custom logger configuration.
613
+ *
614
+ * @remarks
615
+ * By default, the log level is set to `error`.
616
+ *
617
+ * There are four levels available:
618
+ * - `error`: only errors will be logged
619
+ * - `warn`: messages from the SDK that do not cause critical errors, but are worth paying attention to
620
+ * - `info`: various information messages, such as those that log the lifecycle of various modules
621
+ * - `verbose`: any additional information that may be useful during debugging, such as function calls, API queries, etc.
622
+ *
623
+ * @param options - The options object
624
+ * @param options.logLevel - Optional. The new preferred log level.
625
+ * @param options.logger - Optional. Custom logger configuration.
626
+ * @returns A promise that resolves when the log level is set.
627
+ * @throws Error if the log level is invalid.
628
+ *
629
+ * @example
630
+ * ```typescript
631
+ * import { adapty } from '@adapty/capacitor';
632
+ *
633
+ * // Set log level
634
+ * await adapty.setLogLevel({ logLevel: 'verbose' });
635
+ *
636
+ * // Or set custom logger
637
+ * await adapty.setLogLevel({
638
+ * logger: {
639
+ * handler: (level, scope, message, data) => {
640
+ * sendLogToYourServer(`[${level}] ${message}`, data);
641
+ * }
642
+ * }
643
+ * });
644
+ * ```
645
+ */
74
646
  setLogLevel(options: {
75
647
  logLevel?: LogLevel;
76
648
  logger?: LoggerConfig;
77
649
  }): Promise<void>;
650
+ /**
651
+ * Updates attribution data for the current user.
652
+ *
653
+ * @remarks
654
+ * Attribution data can be used to track marketing campaigns and user acquisition sources.
655
+ *
656
+ * @param options - The options object
657
+ * @param options.attribution - An object containing attribution data.
658
+ * @param options.source - The source of the attribution data (e.g., 'adjust', 'appsflyer').
659
+ * @returns A promise that resolves when the attribution data is updated.
660
+ * @throws Error if parameters are invalid or not provided.
661
+ *
662
+ * @example
663
+ * ```typescript
664
+ * import { adapty } from '@adapty/capacitor';
665
+ *
666
+ * try {
667
+ * const attribution = {
668
+ * 'Adjust Adid': 'adjust_adid',
669
+ * 'Adjust Network': 'adjust_network',
670
+ * 'Adjust Campaign': 'adjust_campaign',
671
+ * 'Adjust Adgroup': 'adjust_adgroup',
672
+ * };
673
+ *
674
+ * await adapty.updateAttribution({ attribution, source: 'adjust' });
675
+ * } catch (error) {
676
+ * console.error('Failed to update attribution:', error);
677
+ * }
678
+ * ```
679
+ */
78
680
  updateAttribution(options: {
79
681
  attribution: Record<string, any>;
80
682
  source: string;
81
683
  }): Promise<void>;
684
+ /**
685
+ * Updates the user's consent for collecting refund data.
686
+ *
687
+ * @remarks
688
+ * iOS only. This method has no effect on Android.
689
+ * Use this method to update whether the SDK should collect refund data for the user.
690
+ *
691
+ * @param options - The options object
692
+ * @param options.consent - Whether to collect refund data.
693
+ * @returns A promise that resolves when the consent is updated (or immediately on Android).
694
+ * @throws Error if an error occurs on iOS.
695
+ *
696
+ * @example
697
+ * ```typescript
698
+ * import { adapty } from '@adapty/capacitor';
699
+ *
700
+ * try {
701
+ * await adapty.updateCollectingRefundDataConsent({ consent: true });
702
+ * } catch (error) {
703
+ * console.error('Failed to update consent:', error);
704
+ * }
705
+ * ```
706
+ */
82
707
  updateCollectingRefundDataConsent(options: {
83
708
  consent: boolean;
84
709
  }): Promise<void>;
710
+ /**
711
+ * Updates the user's refund preference.
712
+ *
713
+ * @remarks
714
+ * iOS only. This method has no effect on Android.
715
+ * Use this method to set the user's preference for handling refunds.
716
+ *
717
+ * @param options - The options object
718
+ * @param options.refundPreference - The refund preference setting.
719
+ * @returns A promise that resolves when the preference is updated (or immediately on Android).
720
+ * @throws Error if an error occurs on iOS.
721
+ *
722
+ * @example
723
+ * ```typescript
724
+ * import { adapty } from '@adapty/capacitor';
725
+ *
726
+ * try {
727
+ * await adapty.updateRefundPreference({ refundPreference: 'ask_to_cancel' });
728
+ * } catch (error) {
729
+ * console.error('Failed to update refund preference:', error);
730
+ * }
731
+ * ```
732
+ */
85
733
  updateRefundPreference(options: {
86
734
  refundPreference: RefundPreference;
87
735
  }): Promise<void>;
736
+ /**
737
+ * Updates a profile for the current user.
738
+ *
739
+ * @remarks
740
+ * You can set optional attributes such as email, phone number, etc. to the user of your app.
741
+ * You can then use attributes to create user segments or just view them in CRM.
742
+ *
743
+ * The attributes that you've previously set won't be reset.
744
+ * Custom attributes can be removed by passing `null` as their values.
745
+ *
746
+ * @param options - An object of parameters to update. Partial {@link AdaptyProfileParameters}.
747
+ * @returns A promise that resolves when the profile is updated.
748
+ * @throws Error if parameters are invalid or there is a network error.
749
+ *
750
+ * @example
751
+ * Basic profile update
752
+ * ```typescript
753
+ * import { adapty } from '@adapty/capacitor';
754
+ *
755
+ * try {
756
+ * await adapty.updateProfile({
757
+ * email: 'email@email.com',
758
+ * phoneNumber: '+18888888888',
759
+ * firstName: 'John',
760
+ * lastName: 'Appleseed',
761
+ * gender: 'other',
762
+ * birthday: new Date().toISOString(),
763
+ * });
764
+ * console.log('Profile updated successfully');
765
+ * } catch (error) {
766
+ * console.error('Failed to update profile:', error);
767
+ * }
768
+ * ```
769
+ *
770
+ * @example
771
+ * Custom attributes
772
+ * ```typescript
773
+ * await adapty.updateProfile({
774
+ * codableCustomAttributes: {
775
+ * key_1: 'value_1',
776
+ * key_2: 2,
777
+ * },
778
+ * });
779
+ *
780
+ * // To remove keys, pass null as their values
781
+ * await adapty.updateProfile({
782
+ * codableCustomAttributes: {
783
+ * key_1: null,
784
+ * },
785
+ * });
786
+ * ```
787
+ */
88
788
  updateProfile(options: Partial<AdaptyProfileParameters>): Promise<void>;
789
+ /**
790
+ * Adds an event listener for SDK events.
791
+ *
792
+ * @remarks
793
+ * You can listen to various events from the Adapty SDK such as profile updates.
794
+ * The listener will be called whenever the corresponding event occurs.
795
+ *
796
+ * @param eventName - The name of the event to listen to.
797
+ * @param listenerFunc - The function to call when the event occurs.
798
+ * @returns A listener handle that can be used to remove the listener.
799
+ *
800
+ * @example
801
+ * Listen to profile updates
802
+ * ```typescript
803
+ * import { adapty } from '@adapty/capacitor';
804
+ *
805
+ * const listener = adapty.addListener('onLatestProfileLoad', (profile) => {
806
+ * console.log('Profile updated:', profile);
807
+ * const isSubscribed = profile.accessLevels['YOUR_ACCESS_LEVEL']?.isActive;
808
+ * if (isSubscribed) {
809
+ * console.log('User has premium access');
810
+ * }
811
+ * });
812
+ *
813
+ * // Later, remove the listener
814
+ * listener.remove();
815
+ * ```
816
+ */
89
817
  addListener: AddListenerFn;
818
+ /**
819
+ * Removes all attached event listeners.
820
+ *
821
+ * @remarks
822
+ * This method removes all event listeners that were added via {@link addListener}.
823
+ * It's recommended to call this method when cleaning up resources,
824
+ * such as when unmounting a component.
825
+ *
826
+ * @returns A promise that resolves when all listeners are removed.
827
+ *
828
+ * @example
829
+ * ```typescript
830
+ * import { adapty } from '@adapty/capacitor';
831
+ *
832
+ * // Remove all listeners
833
+ * await adapty.removeAllListeners();
834
+ * ```
835
+ */
90
836
  removeAllListeners(): Promise<void>;
91
837
  }