@adapty/capacitor 3.12.0-beta.1 → 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 (80) hide show
  1. package/AdaptyCapacitor.podspec +3 -3
  2. package/Package.swift +1 -1
  3. package/README.md +24 -11
  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 +2 -1
  7. package/dist/esm/adapty.js +2 -2
  8. package/dist/esm/adapty.js.map +1 -1
  9. package/dist/esm/index.d.ts +1 -1
  10. package/dist/esm/index.js.map +1 -1
  11. package/dist/esm/shared/coders/adapty-configuration.js +12 -17
  12. package/dist/esm/shared/coders/adapty-configuration.js.map +1 -1
  13. package/dist/esm/shared/coders/adapty-purchase-result.js +3 -3
  14. package/dist/esm/shared/coders/adapty-purchase-result.js.map +1 -1
  15. package/dist/esm/shared/coders/adapty-ui-create-onboarding-view-params.d.ts +8 -0
  16. package/dist/esm/shared/coders/adapty-ui-create-onboarding-view-params.js +10 -0
  17. package/dist/esm/shared/coders/adapty-ui-create-onboarding-view-params.js.map +1 -0
  18. package/dist/esm/shared/coders/adapty-ui-create-paywall-view-params.d.ts +18 -0
  19. package/dist/esm/shared/coders/adapty-ui-create-paywall-view-params.js +142 -0
  20. package/dist/esm/shared/coders/adapty-ui-create-paywall-view-params.js.map +1 -0
  21. package/dist/esm/shared/coders/parse-onboarding.d.ts +3 -0
  22. package/dist/esm/shared/coders/parse-onboarding.js +86 -0
  23. package/dist/esm/shared/coders/parse-onboarding.js.map +1 -0
  24. package/dist/esm/shared/coders/parse-paywall.d.ts +4 -0
  25. package/dist/esm/shared/coders/parse-paywall.js +141 -0
  26. package/dist/esm/shared/coders/parse-paywall.js.map +1 -0
  27. package/dist/esm/shared/coders/parse.d.ts +0 -2
  28. package/dist/esm/shared/coders/parse.js +0 -75
  29. package/dist/esm/shared/coders/parse.js.map +1 -1
  30. package/dist/esm/shared/coders/utils.d.ts +18 -0
  31. package/dist/esm/shared/coders/utils.js +50 -0
  32. package/dist/esm/shared/coders/utils.js.map +1 -0
  33. package/dist/esm/shared/types/index.d.ts +6 -0
  34. package/dist/esm/shared/types/index.js +5 -0
  35. package/dist/esm/shared/types/index.js.map +1 -1
  36. package/dist/esm/shared/types/inputs.d.ts +12 -4
  37. package/dist/esm/shared/types/inputs.js.map +1 -1
  38. package/dist/esm/shared/types/onboarding-events.d.ts +60 -0
  39. package/dist/esm/shared/types/onboarding-events.js +11 -0
  40. package/dist/esm/shared/types/onboarding-events.js.map +1 -0
  41. package/dist/esm/shared/types/paywall-events.d.ts +84 -0
  42. package/dist/esm/shared/types/paywall-events.js +16 -0
  43. package/dist/esm/shared/types/paywall-events.js.map +1 -0
  44. package/dist/esm/types/adapty-plugin.d.ts +2 -1
  45. package/dist/esm/types/adapty-plugin.js.map +1 -1
  46. package/dist/esm/ui-builder/base-view-emitter.d.ts +14 -20
  47. package/dist/esm/ui-builder/base-view-emitter.js +95 -73
  48. package/dist/esm/ui-builder/base-view-emitter.js.map +1 -1
  49. package/dist/esm/ui-builder/create-onboarding-view.d.ts +32 -0
  50. package/dist/esm/ui-builder/create-onboarding-view.js +36 -0
  51. package/dist/esm/ui-builder/create-onboarding-view.js.map +1 -0
  52. package/dist/esm/ui-builder/create-paywall-view.d.ts +25 -0
  53. package/dist/esm/ui-builder/create-paywall-view.js +29 -0
  54. package/dist/esm/ui-builder/create-paywall-view.js.map +1 -0
  55. package/dist/esm/ui-builder/index.d.ts +6 -37
  56. package/dist/esm/ui-builder/index.js +4 -41
  57. package/dist/esm/ui-builder/index.js.map +1 -1
  58. package/dist/esm/ui-builder/onboarding-view-controller.d.ts +3 -2
  59. package/dist/esm/ui-builder/onboarding-view-controller.js +11 -6
  60. package/dist/esm/ui-builder/onboarding-view-controller.js.map +1 -1
  61. package/dist/esm/ui-builder/onboarding-view-emitter.d.ts +10 -24
  62. package/dist/esm/ui-builder/onboarding-view-emitter.js +49 -56
  63. package/dist/esm/ui-builder/onboarding-view-emitter.js.map +1 -1
  64. package/dist/esm/ui-builder/paywall-view-controller.d.ts +1 -0
  65. package/dist/esm/ui-builder/paywall-view-controller.js +12 -41
  66. package/dist/esm/ui-builder/paywall-view-controller.js.map +1 -1
  67. package/dist/esm/ui-builder/paywall-view-emitter.d.ts +8 -28
  68. package/dist/esm/ui-builder/paywall-view-emitter.js +86 -118
  69. package/dist/esm/ui-builder/paywall-view-emitter.js.map +1 -1
  70. package/dist/esm/ui-builder/types.d.ts +84 -4
  71. package/dist/esm/ui-builder/types.js +3 -3
  72. package/dist/esm/ui-builder/types.js.map +1 -1
  73. package/dist/esm/version.d.ts +1 -1
  74. package/dist/esm/version.js +1 -1
  75. package/dist/esm/version.js.map +1 -1
  76. package/dist/plugin.cjs.js +938 -594
  77. package/dist/plugin.cjs.js.map +1 -1
  78. package/dist/plugin.js +938 -594
  79. package/dist/plugin.js.map +1 -1
  80. package/package.json +2 -2
package/dist/plugin.js CHANGED
@@ -463,7 +463,7 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
463
463
  }
464
464
  }
465
465
 
466
- var __rest$4 = (undefined && undefined.__rest) || function (s, e) {
466
+ var __rest$5 = (undefined && undefined.__rest) || function (s, e) {
467
467
  var t = {};
468
468
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
469
469
  t[p] = s[p];
@@ -497,7 +497,7 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
497
497
  return Object.assign(Object.assign({}, codablePart), { dataString: dataString.length < 4 ? '' : dataString });
498
498
  }
499
499
  encode(data) {
500
- const { dataString } = data, codablePart = __rest$4(data, ["dataString"]);
500
+ const { dataString } = data, codablePart = __rest$5(data, ["dataString"]);
501
501
  return super.encode(codablePart);
502
502
  }
503
503
  }
@@ -542,7 +542,7 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
542
542
  }
543
543
  }
544
544
 
545
- var __rest$3 = (undefined && undefined.__rest) || function (s, e) {
545
+ var __rest$4 = (undefined && undefined.__rest) || function (s, e) {
546
546
  var t = {};
547
547
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
548
548
  t[p] = s[p];
@@ -606,7 +606,7 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
606
606
  }) });
607
607
  }
608
608
  encode(data) {
609
- const { hasViewConfiguration, productIdentifiers } = data, codablePart = __rest$3(data, ["hasViewConfiguration", "productIdentifiers"]);
609
+ const { hasViewConfiguration, productIdentifiers } = data, codablePart = __rest$4(data, ["hasViewConfiguration", "productIdentifiers"]);
610
610
  return super.encode(codablePart);
611
611
  }
612
612
  }
@@ -703,7 +703,7 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
703
703
  }
704
704
  }
705
705
 
706
- var __rest$2 = (undefined && undefined.__rest) || function (s, e) {
706
+ var __rest$3 = (undefined && undefined.__rest) || function (s, e) {
707
707
  var t = {};
708
708
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
709
709
  t[p] = s[p];
@@ -742,14 +742,14 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
742
742
  decode(data) {
743
743
  const baseResult = super.decode(data);
744
744
  if (!data.offer_tags) {
745
- const { android } = baseResult, partialData = __rest$2(baseResult, ["android"]);
745
+ const { android } = baseResult, partialData = __rest$3(baseResult, ["android"]);
746
746
  return partialData;
747
747
  }
748
748
  return baseResult;
749
749
  }
750
750
  }
751
751
 
752
- var __rest$1 = (undefined && undefined.__rest) || function (s, e) {
752
+ var __rest$2 = (undefined && undefined.__rest) || function (s, e) {
753
753
  var t = {};
754
754
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
755
755
  t[p] = s[p];
@@ -805,7 +805,7 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
805
805
  decode(data) {
806
806
  const baseResult = super.decode(data);
807
807
  const propToRemove = data.base_plan_id ? 'ios' : 'android';
808
- const _a = baseResult, _b = propToRemove; _a[_b]; const partialData = __rest$1(_a, [typeof _b === "symbol" ? _b : _b + ""]);
808
+ const _a = baseResult, _b = propToRemove; _a[_b]; const partialData = __rest$2(_a, [typeof _b === "symbol" ? _b : _b + ""]);
809
809
  return partialData;
810
810
  }
811
811
  }
@@ -1355,8 +1355,8 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
1355
1355
  }
1356
1356
  const platform = getPlatform();
1357
1357
  const anyData = data;
1358
- return Object.assign(Object.assign(Object.assign(Object.assign({}, baseResult), { profile: new AdaptyProfileCoder().decode(data.profile) }), (platform === 'ios' && anyData.jws_transaction
1359
- ? { ios: { jwsTransaction: anyData.jws_transaction } }
1358
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, baseResult), { profile: new AdaptyProfileCoder().decode(data.profile) }), (platform === 'ios' && anyData.apple_jws_transaction
1359
+ ? { ios: { jwsTransaction: anyData.apple_jws_transaction } }
1360
1360
  : {})), (platform === 'android' && anyData.google_purchase_token
1361
1361
  ? { android: { purchaseToken: anyData.google_purchase_token } }
1362
1362
  : {}));
@@ -1376,7 +1376,7 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
1376
1376
  profile: new AdaptyProfileCoder().encode(data.profile),
1377
1377
  };
1378
1378
  if (platform === 'ios' && ((_a = data.ios) === null || _a === void 0 ? void 0 : _a.jwsTransaction)) {
1379
- result.jws_transaction = data.ios.jwsTransaction;
1379
+ result.apple_jws_transaction = data.ios.jwsTransaction;
1380
1380
  }
1381
1381
  if (platform === 'android' && ((_b = data.android) === null || _b === void 0 ? void 0 : _b.purchaseToken)) {
1382
1382
  result.google_purchase_token = data.android.purchaseToken;
@@ -1400,7 +1400,7 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
1400
1400
  }
1401
1401
  }
1402
1402
 
1403
- var __rest = (undefined && undefined.__rest) || function (s, e) {
1403
+ var __rest$1 = (undefined && undefined.__rest) || function (s, e) {
1404
1404
  var t = {};
1405
1405
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
1406
1406
  t[p] = s[p];
@@ -1446,7 +1446,7 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
1446
1446
  return Object.assign(Object.assign({}, codablePart), { hasViewConfiguration: codablePart.onboardingBuilder !== undefined });
1447
1447
  }
1448
1448
  encode(data) {
1449
- const { hasViewConfiguration } = data, codablePart = __rest(data, ["hasViewConfiguration"]);
1449
+ const { hasViewConfiguration } = data, codablePart = __rest$1(data, ["hasViewConfiguration"]);
1450
1450
  return super.encode(codablePart);
1451
1451
  }
1452
1452
  }
@@ -1640,81 +1640,6 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
1640
1640
  return null;
1641
1641
  }
1642
1642
  }
1643
- function parsePaywallEvent(input, ctx) {
1644
- var _a, _b, _c, _d;
1645
- const log = ctx === null || ctx === void 0 ? void 0 : ctx.decode({ methodName: 'parsePaywallEvent' });
1646
- log === null || log === void 0 ? void 0 : log.start(() => ({ input }));
1647
- let obj;
1648
- try {
1649
- obj = JSON.parse(input);
1650
- }
1651
- catch (error) {
1652
- throw AdaptyError.failedToDecode(`Failed to decode event: ${error === null || error === void 0 ? void 0 : error.message}`);
1653
- }
1654
- const result = {};
1655
- if (obj.hasOwnProperty('id')) {
1656
- result['id'] = obj['id'];
1657
- }
1658
- if (obj.hasOwnProperty('profile')) {
1659
- result['profile'] = (_a = getCoder$1('AdaptyProfile', ctx)) === null || _a === void 0 ? void 0 : _a.decode(obj['profile']);
1660
- }
1661
- if (obj.hasOwnProperty('product')) {
1662
- result['product'] = (_b = getCoder$1('AdaptyPaywallProduct', ctx)) === null || _b === void 0 ? void 0 : _b.decode(obj['product']);
1663
- }
1664
- if (obj.hasOwnProperty('error')) {
1665
- result['error'] = (_c = getCoder$1('AdaptyError', ctx)) === null || _c === void 0 ? void 0 : _c.decode(obj['error']);
1666
- }
1667
- if (obj.hasOwnProperty('action')) {
1668
- result['action'] = obj['action'];
1669
- }
1670
- if (obj.hasOwnProperty('view')) {
1671
- result['view'] = obj['view'];
1672
- }
1673
- if (obj.hasOwnProperty('product_id')) {
1674
- result['product_id'] = obj['product_id'];
1675
- }
1676
- if (obj.hasOwnProperty('purchased_result')) {
1677
- result['purchased_result'] = (_d = getCoder$1('AdaptyPurchaseResult', ctx)) === null || _d === void 0 ? void 0 : _d.decode(obj['purchased_result']);
1678
- }
1679
- return result;
1680
- }
1681
- function parseOnboardingEvent(input, ctx) {
1682
- var _a, _b, _c;
1683
- const log = ctx === null || ctx === void 0 ? void 0 : ctx.decode({ methodName: 'parseOnboardingEvent' });
1684
- log === null || log === void 0 ? void 0 : log.start(() => ({ input }));
1685
- let obj;
1686
- try {
1687
- obj = JSON.parse(input);
1688
- }
1689
- catch (error) {
1690
- throw AdaptyError.failedToDecode(`Failed to decode event: ${error === null || error === void 0 ? void 0 : error.message}`);
1691
- }
1692
- const result = {};
1693
- if (obj.hasOwnProperty('view')) {
1694
- result['view'] = obj['view'];
1695
- }
1696
- if (obj.hasOwnProperty('meta')) {
1697
- result['meta'] = (_a = getCoder$1('AdaptyUiOnboardingMeta', ctx)) === null || _a === void 0 ? void 0 : _a.decode(obj['meta']);
1698
- }
1699
- if (obj.hasOwnProperty('event')) {
1700
- result['event'] = obj['event'];
1701
- }
1702
- if (obj.hasOwnProperty('action_id')) {
1703
- result['id'] = obj['action_id'];
1704
- }
1705
- if (obj.hasOwnProperty('action')) {
1706
- try {
1707
- result['action'] = (_b = getCoder$1('AdaptyUiOnboardingStateUpdatedAction', ctx)) === null || _b === void 0 ? void 0 : _b.decode(obj['action']);
1708
- }
1709
- catch (_e) {
1710
- result['action'] = obj['action'];
1711
- }
1712
- }
1713
- if (obj.hasOwnProperty('error')) {
1714
- result['error'] = (_c = getCoder$1('AdaptyError', ctx)) === null || _c === void 0 ? void 0 : _c.decode(obj['error']);
1715
- }
1716
- return result;
1717
- }
1718
1643
  function getCoder$1(type, ctx) {
1719
1644
  ctx === null || ctx === void 0 ? void 0 : ctx.stack;
1720
1645
  switch (type) {
@@ -1820,7 +1745,7 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
1820
1745
  },
1821
1746
  };
1822
1747
 
1823
- var version = '3.12.0-beta.1';
1748
+ var version = '3.15.0';
1824
1749
 
1825
1750
  class Log {
1826
1751
  // Formats a message for logging
@@ -2265,7 +2190,7 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
2265
2190
 
2266
2191
  class AdaptyConfigurationCoder {
2267
2192
  encode(apiKey, params) {
2268
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2193
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
2269
2194
  const config = {
2270
2195
  api_key: apiKey,
2271
2196
  cross_platform_sdk_name: 'capacitor',
@@ -2281,18 +2206,6 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
2281
2206
  config['log_level'] = params.logLevel;
2282
2207
  }
2283
2208
  config['server_cluster'] = (_c = params.serverCluster) !== null && _c !== void 0 ? _c : 'default';
2284
- if (params.backendBaseUrl) {
2285
- config['backend_base_url'] = params.backendBaseUrl;
2286
- }
2287
- if (params.backendFallbackBaseUrl) {
2288
- config['backend_fallback_base_url'] = params.backendFallbackBaseUrl;
2289
- }
2290
- if (params.backendConfigsBaseUrl) {
2291
- config['backend_configs_base_url'] = params.backendConfigsBaseUrl;
2292
- }
2293
- if (params.backendUABaseUrl) {
2294
- config['backend_ua_base_url'] = params.backendUABaseUrl;
2295
- }
2296
2209
  if (params.backendProxyHost) {
2297
2210
  config['backend_proxy_host'] = params.backendProxyHost;
2298
2211
  }
@@ -2312,19 +2225,26 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
2312
2225
  if (((_f = params.ios) === null || _f === void 0 ? void 0 : _f.idfaCollectionDisabled) !== undefined) {
2313
2226
  config['apple_idfa_collection_disabled'] = params.ios.idfaCollectionDisabled;
2314
2227
  }
2315
- if (platform === 'ios' && ((_g = params.ios) === null || _g === void 0 ? void 0 : _g.appAccountToken)) {
2228
+ if (((_g = params.ios) === null || _g === void 0 ? void 0 : _g.clearDataOnBackup) !== undefined) {
2229
+ config['clear_data_on_backup'] = params.ios.clearDataOnBackup;
2230
+ }
2231
+ if (platform === 'ios' && ((_h = params.ios) === null || _h === void 0 ? void 0 : _h.appAccountToken)) {
2316
2232
  config['customer_identity_parameters'] = {
2317
2233
  app_account_token: params.ios.appAccountToken,
2318
2234
  };
2319
2235
  }
2320
- if (((_h = params.android) === null || _h === void 0 ? void 0 : _h.adIdCollectionDisabled) !== undefined) {
2236
+ if (((_j = params.android) === null || _j === void 0 ? void 0 : _j.adIdCollectionDisabled) !== undefined) {
2321
2237
  config['google_adid_collection_disabled'] = params.android.adIdCollectionDisabled;
2322
2238
  }
2323
- if (((_j = params.android) === null || _j === void 0 ? void 0 : _j.pendingPrepaidPlansEnabled) !== undefined) {
2239
+ if (((_k = params.android) === null || _k === void 0 ? void 0 : _k.pendingPrepaidPlansEnabled) !== undefined) {
2324
2240
  config['google_enable_pending_prepaid_plans'] =
2325
2241
  params.android.pendingPrepaidPlansEnabled;
2326
2242
  }
2327
- if (platform === 'android' && ((_k = params.android) === null || _k === void 0 ? void 0 : _k.obfuscatedAccountId)) {
2243
+ if (((_l = params.android) === null || _l === void 0 ? void 0 : _l.localAccessLevelAllowed) !== undefined) {
2244
+ config['google_local_access_level_allowed'] =
2245
+ params.android.localAccessLevelAllowed;
2246
+ }
2247
+ if (platform === 'android' && ((_m = params.android) === null || _m === void 0 ? void 0 : _m.obfuscatedAccountId)) {
2328
2248
  config['customer_identity_parameters'] = {
2329
2249
  obfuscated_account_id: params.android.obfuscatedAccountId,
2330
2250
  };
@@ -3260,9 +3180,9 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
3260
3180
  log.start(() => ({ options }));
3261
3181
  const paywallCoder = new AdaptyPaywallCoder();
3262
3182
  const productCoder = new AdaptyPaywallProductCoder();
3263
- const argsWithUndefined = Object.assign({ method }, (this.isPaywallProduct(options.paywallOrProduct)
3183
+ const argsWithUndefined = Object.assign(Object.assign({ method }, (this.isPaywallProduct(options.paywallOrProduct)
3264
3184
  ? { product: this.encodeWithLogging(productCoder, options.paywallOrProduct, 'AdaptyPaywallProduct', ctx) }
3265
- : { paywall: this.encodeWithLogging(paywallCoder, options.paywallOrProduct, 'AdaptyPaywall', ctx) }));
3185
+ : { paywall: this.encodeWithLogging(paywallCoder, options.paywallOrProduct, 'AdaptyPaywall', ctx) })), (options.openIn ? { open_in: options.openIn } : {}));
3266
3186
  const args = filterUndefined(argsWithUndefined);
3267
3187
  await this.handleMethodCall(method, JSON.stringify(args), ctx, log);
3268
3188
  }
@@ -3902,12 +3822,221 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
3902
3822
  Year: 'year',
3903
3823
  });
3904
3824
 
3825
+ const PaywallEventId = {
3826
+ DidAppear: 'paywall_view_did_appear',
3827
+ DidDisappear: 'paywall_view_did_disappear',
3828
+ DidPerformAction: 'paywall_view_did_perform_action',
3829
+ DidSelectProduct: 'paywall_view_did_select_product',
3830
+ DidStartPurchase: 'paywall_view_did_start_purchase',
3831
+ DidFinishPurchase: 'paywall_view_did_finish_purchase',
3832
+ DidFailPurchase: 'paywall_view_did_fail_purchase',
3833
+ DidStartRestore: 'paywall_view_did_start_restore',
3834
+ DidFinishRestore: 'paywall_view_did_finish_restore',
3835
+ DidFailRestore: 'paywall_view_did_fail_restore',
3836
+ DidFailRendering: 'paywall_view_did_fail_rendering',
3837
+ DidFailLoadingProducts: 'paywall_view_did_fail_loading_products',
3838
+ DidFinishWebPaymentNavigation: 'paywall_view_did_finish_web_payment_navigation',
3839
+ };
3840
+
3841
+ const WebPresentation = Object.freeze({
3842
+ BrowserOutApp: 'browser_out_app',
3843
+ BrowserInApp: 'browser_in_app',
3844
+ });
3905
3845
  const RefundPreference = Object.freeze({
3906
3846
  NoPreference: 'no_preference',
3907
3847
  Grant: 'grant',
3908
3848
  Decline: 'decline',
3909
3849
  });
3910
3850
 
3851
+ const formatDateUTC = (date) => {
3852
+ const pad = (num, digits = 2) => {
3853
+ const str = num.toString();
3854
+ const paddingLength = digits - str.length;
3855
+ return paddingLength > 0 ? '0'.repeat(paddingLength) + str : str;
3856
+ };
3857
+ const year = date.getUTCFullYear();
3858
+ const month = pad(date.getUTCMonth() + 1);
3859
+ const day = pad(date.getUTCDate());
3860
+ const hours = pad(date.getUTCHours());
3861
+ const minutes = pad(date.getUTCMinutes());
3862
+ const seconds = pad(date.getUTCSeconds());
3863
+ const millis = pad(date.getUTCMilliseconds(), 3);
3864
+ return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${millis}Z`;
3865
+ };
3866
+ const colorToHex = {
3867
+ fromARGB(value) {
3868
+ const hex = value.toString(16).padStart(8, '0');
3869
+ return `#${hex.slice(2)}${hex.slice(0, 2)}`;
3870
+ },
3871
+ fromRGBA(value) {
3872
+ return `#${value.toString(16).padStart(8, '0')}`;
3873
+ },
3874
+ fromRGB(value) {
3875
+ return `#${value.toString(16).padStart(6, '0')}ff`;
3876
+ },
3877
+ };
3878
+ const extractBase64Data = (input) => {
3879
+ const commaIndex = input.indexOf(',');
3880
+ if (input.startsWith('data:') && commaIndex !== -1) {
3881
+ return input.slice(commaIndex + 1);
3882
+ }
3883
+ return input;
3884
+ };
3885
+ const resolveAssetId = (asset, select) => {
3886
+ if ('relativeAssetPath' in asset) {
3887
+ return (select({
3888
+ ios: asset.relativeAssetPath,
3889
+ android: `${asset.relativeAssetPath}a`,
3890
+ }) || '');
3891
+ }
3892
+ const fileLocation = asset.fileLocation;
3893
+ return (select({
3894
+ ios: fileLocation.ios.fileName,
3895
+ android: 'relativeAssetPath' in fileLocation.android
3896
+ ? `${fileLocation.android.relativeAssetPath}a`
3897
+ : `${fileLocation.android.rawResName}r`,
3898
+ }) || '');
3899
+ };
3900
+
3901
+ var __rest = (undefined && undefined.__rest) || function (s, e) {
3902
+ var t = {};
3903
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
3904
+ t[p] = s[p];
3905
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
3906
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
3907
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3908
+ t[p[i]] = s[p[i]];
3909
+ }
3910
+ return t;
3911
+ };
3912
+ class AdaptyUICreatePaywallViewParamsCoder {
3913
+ encode(data) {
3914
+ const result = {};
3915
+ if (data.prefetchProducts !== undefined) {
3916
+ result.preload_products = data.prefetchProducts;
3917
+ }
3918
+ if (data.loadTimeoutMs !== undefined) {
3919
+ result.load_timeout = data.loadTimeoutMs / 1000;
3920
+ }
3921
+ if (data.customTags) {
3922
+ result.custom_tags = data.customTags;
3923
+ }
3924
+ if (data.customTimers) {
3925
+ result.custom_timers = this.encodeCustomTimers(data.customTimers);
3926
+ }
3927
+ if (data.customAssets) {
3928
+ result.custom_assets = this.encodeCustomAssets(data.customAssets);
3929
+ }
3930
+ if (data.productPurchaseParams) {
3931
+ result.product_purchase_parameters = this.encodeProductPurchaseParams(data.productPurchaseParams);
3932
+ }
3933
+ return result;
3934
+ }
3935
+ encodeCustomTimers(timers) {
3936
+ const result = {};
3937
+ for (const key in timers) {
3938
+ if (Object.prototype.hasOwnProperty.call(timers, key)) {
3939
+ const date = timers[key];
3940
+ if (date instanceof Date) {
3941
+ result[key] = formatDateUTC(date);
3942
+ }
3943
+ }
3944
+ }
3945
+ return result;
3946
+ }
3947
+ encodeCustomAssets(assets) {
3948
+ const getAssetId = (asset) => {
3949
+ return resolveAssetId(asset, selectPlatformValue) || '';
3950
+ };
3951
+ return Object.entries(assets)
3952
+ .map(([id, asset]) => {
3953
+ switch (asset.type) {
3954
+ case 'image':
3955
+ return 'base64' in asset
3956
+ ? {
3957
+ id,
3958
+ type: 'image',
3959
+ value: extractBase64Data(asset.base64),
3960
+ }
3961
+ : {
3962
+ id,
3963
+ type: 'image',
3964
+ asset_id: getAssetId(asset),
3965
+ };
3966
+ case 'video':
3967
+ return {
3968
+ id,
3969
+ type: 'video',
3970
+ asset_id: getAssetId(asset),
3971
+ };
3972
+ case 'color': {
3973
+ const color = encodeColor(asset);
3974
+ if (!color)
3975
+ return undefined;
3976
+ return {
3977
+ id,
3978
+ type: 'color',
3979
+ value: color,
3980
+ };
3981
+ }
3982
+ case 'linear-gradient': {
3983
+ const { values, points = {} } = asset;
3984
+ const { x0 = 0, y0 = 0, x1 = 1, y1 = 0 } = points;
3985
+ const colorStops = values
3986
+ .map((_a) => {
3987
+ var { p } = _a, colorInput = __rest(_a, ["p"]);
3988
+ const color = encodeColor(colorInput);
3989
+ if (!color)
3990
+ return undefined;
3991
+ return { color, p };
3992
+ })
3993
+ .filter((v) => v !== undefined);
3994
+ if (colorStops.length !== values.length)
3995
+ return undefined;
3996
+ return {
3997
+ id,
3998
+ type: 'linear-gradient',
3999
+ values: colorStops,
4000
+ points: { x0, y0, x1, y1 },
4001
+ };
4002
+ }
4003
+ default:
4004
+ return undefined;
4005
+ }
4006
+ })
4007
+ .filter((item) => item !== undefined);
4008
+ }
4009
+ encodeProductPurchaseParams(params) {
4010
+ if (!params)
4011
+ return {};
4012
+ const purchaseParamsCoder = new AdaptyPurchaseParamsCoder();
4013
+ return Object.fromEntries(params.map(({ productId, params: purchaseParams }) => [
4014
+ productId.adaptyProductId,
4015
+ purchaseParamsCoder.encode(purchaseParams),
4016
+ ]));
4017
+ }
4018
+ }
4019
+ const selectPlatformValue = (spec) => {
4020
+ const platform = core.Capacitor.getPlatform();
4021
+ if (platform === 'ios')
4022
+ return spec.ios;
4023
+ if (platform === 'android')
4024
+ return spec.android;
4025
+ return undefined;
4026
+ };
4027
+ const encodeColor = (asset) => {
4028
+ if ('argb' in asset) {
4029
+ return colorToHex.fromARGB(asset.argb);
4030
+ }
4031
+ if ('rgba' in asset) {
4032
+ return colorToHex.fromRGBA(asset.rgba);
4033
+ }
4034
+ if ('rgb' in asset) {
4035
+ return colorToHex.fromRGB(asset.rgb);
4036
+ }
4037
+ return undefined;
4038
+ };
4039
+
3911
4040
  /**
3912
4041
  * Maps over values of an object, transforming each value using the provided function.
3913
4042
  *
@@ -3919,6 +4048,140 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
3919
4048
  return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, fn(value, key)]));
3920
4049
  }
3921
4050
 
4051
+ function parsePaywallEvent(input, ctx) {
4052
+ var _a;
4053
+ let obj;
4054
+ try {
4055
+ obj = JSON.parse(input);
4056
+ }
4057
+ catch (error) {
4058
+ throw AdaptyError.failedToDecode(`Failed to decode event: ${error === null || error === void 0 ? void 0 : error.message}`);
4059
+ }
4060
+ const eventId = obj['id'];
4061
+ if (!(eventId === null || eventId === void 0 ? void 0 : eventId.startsWith('paywall_view_'))) {
4062
+ return null;
4063
+ }
4064
+ const viewObj = obj['view'];
4065
+ const view = {
4066
+ id: viewObj['id'],
4067
+ placementId: viewObj['placement_id'],
4068
+ variationId: viewObj['variation_id'],
4069
+ };
4070
+ switch (eventId) {
4071
+ case PaywallEventId.DidAppear:
4072
+ return { id: eventId, view };
4073
+ case PaywallEventId.DidDisappear:
4074
+ return { id: eventId, view };
4075
+ case PaywallEventId.DidPerformAction: {
4076
+ const actionObj = obj['action'];
4077
+ return {
4078
+ id: eventId,
4079
+ view,
4080
+ action: {
4081
+ type: actionObj['type'],
4082
+ value: actionObj['value'],
4083
+ },
4084
+ };
4085
+ }
4086
+ case PaywallEventId.DidSelectProduct:
4087
+ return {
4088
+ id: eventId,
4089
+ view,
4090
+ productId: (_a = obj['product_id']) !== null && _a !== void 0 ? _a : '',
4091
+ };
4092
+ case PaywallEventId.DidStartPurchase:
4093
+ return {
4094
+ id: eventId,
4095
+ view,
4096
+ product: getPaywallCoder('product').decode(obj['product']),
4097
+ };
4098
+ case PaywallEventId.DidFinishPurchase:
4099
+ return {
4100
+ id: eventId,
4101
+ view,
4102
+ purchaseResult: getPaywallCoder('purchaseResult').decode(obj['purchased_result']),
4103
+ product: getPaywallCoder('product').decode(obj['product']),
4104
+ };
4105
+ case PaywallEventId.DidFailPurchase: {
4106
+ const errorCoder = getPaywallCoder('error');
4107
+ const decodedError = errorCoder.decode(obj['error']);
4108
+ return {
4109
+ id: eventId,
4110
+ view,
4111
+ error: errorCoder.getError(decodedError),
4112
+ product: getPaywallCoder('product').decode(obj['product']),
4113
+ };
4114
+ }
4115
+ case PaywallEventId.DidStartRestore:
4116
+ return {
4117
+ id: eventId,
4118
+ view,
4119
+ };
4120
+ case PaywallEventId.DidFinishRestore:
4121
+ return {
4122
+ id: eventId,
4123
+ view,
4124
+ profile: getPaywallCoder('profile').decode(obj['profile']),
4125
+ };
4126
+ case PaywallEventId.DidFailRestore: {
4127
+ const errorCoder = getPaywallCoder('error');
4128
+ const decodedError = errorCoder.decode(obj['error']);
4129
+ return {
4130
+ id: eventId,
4131
+ view,
4132
+ error: errorCoder.getError(decodedError),
4133
+ };
4134
+ }
4135
+ case PaywallEventId.DidFailRendering: {
4136
+ const errorCoder = getPaywallCoder('error');
4137
+ const decodedError = errorCoder.decode(obj['error']);
4138
+ return {
4139
+ id: eventId,
4140
+ view,
4141
+ error: errorCoder.getError(decodedError),
4142
+ };
4143
+ }
4144
+ case PaywallEventId.DidFailLoadingProducts: {
4145
+ const errorCoder = getPaywallCoder('error');
4146
+ const decodedError = errorCoder.decode(obj['error']);
4147
+ return {
4148
+ id: eventId,
4149
+ view,
4150
+ error: errorCoder.getError(decodedError),
4151
+ };
4152
+ }
4153
+ case PaywallEventId.DidFinishWebPaymentNavigation:
4154
+ return {
4155
+ id: eventId,
4156
+ view,
4157
+ product: obj['product']
4158
+ ? getPaywallCoder('product').decode(obj['product'])
4159
+ : undefined,
4160
+ error: obj['error']
4161
+ ? (() => {
4162
+ const errorCoder = getPaywallCoder('error');
4163
+ const decodedError = errorCoder.decode(obj['error']);
4164
+ return errorCoder.getError(decodedError);
4165
+ })()
4166
+ : undefined,
4167
+ };
4168
+ default:
4169
+ return null;
4170
+ }
4171
+ }
4172
+ function getPaywallCoder(type, _ctx) {
4173
+ switch (type) {
4174
+ case 'product':
4175
+ return new AdaptyPaywallProductCoder();
4176
+ case 'profile':
4177
+ return new AdaptyProfileCoder();
4178
+ case 'purchaseResult':
4179
+ return new AdaptyPurchaseResultCoder();
4180
+ case 'error':
4181
+ return new AdaptyNativeErrorCoder();
4182
+ }
4183
+ }
4184
+
3922
4185
  /**
3923
4186
  * Base class for view event emitters that manages common event handling logic.
3924
4187
  * Each event type can have only one handler - new handlers replace existing ones.
@@ -3927,89 +4190,28 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
3927
4190
  constructor(viewId) {
3928
4191
  this.eventListeners = new Map();
3929
4192
  this.handlers = new Map();
4193
+ this.internalHandlers = new Map();
3930
4194
  this.viewId = viewId;
3931
4195
  }
3932
4196
  async addListener(event, callback, onRequestClose) {
3933
- const viewId = this.viewId;
3934
- const config = this.getEventConfig(event);
3935
- if (!config) {
3936
- throw new Error(`No event config found for handler: ${String(event)}`);
4197
+ const nativeEvent = this.getNativeEventForHandler(event);
4198
+ if (!nativeEvent) {
4199
+ throw new Error(`No native event mapping found for handler: ${String(event)}`);
3937
4200
  }
3938
4201
  // Replace existing handler for this event type
3939
4202
  this.handlers.set(event, {
3940
4203
  handler: callback,
3941
- config,
3942
4204
  onRequestClose,
3943
4205
  });
3944
- if (!this.eventListeners.has(config.nativeEvent)) {
3945
- const handlers = this.handlers;
3946
- const emitterName = this.getEmitterName();
3947
- const subscription = await AdaptyCapacitorPlugin.addListener(config.nativeEvent, (arg) => {
3948
- const ctx = new LogContext();
3949
- const log = ctx.event({ methodName: config.nativeEvent });
3950
- log.start(() => ({ raw: arg }));
3951
- // Strict validation: events must come in {data: "json_string"} format
3952
- if (!arg || typeof arg !== 'object' || !arg.data) {
3953
- const error = new Error(`[${emitterName}] Invalid event format received. Expected {data: "json_string"}, got: ${JSON.stringify(arg)}`);
3954
- log.failed(() => ({ error }));
3955
- throw error;
3956
- }
3957
- const rawEventData = arg.data;
3958
- // Parse JSON string using specific parser with decode logging
3959
- let eventData;
3960
- if (typeof rawEventData === 'string') {
3961
- try {
3962
- eventData = this.parseEventData(rawEventData, ctx);
3963
- }
3964
- catch (error) {
3965
- log.failed(() => ({ error }));
3966
- throw error;
3967
- }
3968
- }
3969
- else {
3970
- const err = new Error(`[${emitterName}] Expected event data to be JSON string, got ${typeof rawEventData}: ${rawEventData}`);
3971
- log.failed(() => ({ error: err }));
3972
- throw err;
3973
- }
3974
- const eventViewId = this.getEventViewId(eventData);
3975
- if (viewId !== eventViewId) {
3976
- return;
3977
- }
3978
- // Get all possible handler names for this native event
3979
- const possibleHandlers = this.getPossibleHandlers(config.nativeEvent);
3980
- for (const handlerName of possibleHandlers) {
3981
- const handlerData = handlers.get(handlerName);
3982
- if (!handlerData) {
3983
- continue; // Handler not registered for this view
3984
- }
3985
- const { handler, config: handlerConfig, onRequestClose } = handlerData;
3986
- if (!this.shouldCallHandler(handlerName, handlerConfig, eventData)) {
3987
- continue;
3988
- }
3989
- const callbackArgs = this.extractCallbackArgs(handlerName, eventData);
3990
- const cb = handler;
3991
- try {
3992
- const shouldClose = cb(...callbackArgs);
3993
- if (shouldClose) {
3994
- onRequestClose().catch((error) => {
3995
- log.failed(() => ({ error, handlerName }));
3996
- });
3997
- }
3998
- log.success(() => ({ message: 'Event handled successfully', handlerName }));
3999
- }
4000
- catch (error) {
4001
- log.failed(() => ({ error, handlerName }));
4002
- }
4003
- break; // Only one handler can match per event
4004
- }
4005
- });
4006
- this.eventListeners.set(config.nativeEvent, subscription);
4007
- }
4008
- const ensured = this.eventListeners.get(config.nativeEvent);
4009
- if (!ensured) {
4010
- throw new Error(`Failed to register listener for ${config.nativeEvent}`);
4206
+ return await this.getOrCreateNativeListener(nativeEvent);
4207
+ }
4208
+ async addInternalListener(event, callback) {
4209
+ const nativeEvent = this.getNativeEventForHandler(event);
4210
+ if (!nativeEvent) {
4211
+ throw new Error(`No native event mapping found for handler: ${String(event)}`);
4011
4212
  }
4012
- return ensured;
4213
+ this.internalHandlers.set(event, { handler: callback });
4214
+ return await this.getOrCreateNativeListener(nativeEvent);
4013
4215
  }
4014
4216
  removeAllListeners() {
4015
4217
  this.eventListeners.forEach((subscription) => {
@@ -4019,22 +4221,113 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4019
4221
  });
4020
4222
  this.eventListeners.clear();
4021
4223
  this.handlers.clear();
4224
+ this.internalHandlers.clear();
4225
+ }
4226
+ async createNativeListener(nativeEvent) {
4227
+ const emitterName = this.getEmitterName();
4228
+ const viewId = this.viewId;
4229
+ const subscription = await AdaptyCapacitorPlugin.addListener(nativeEvent, (arg) => {
4230
+ const ctx = new LogContext();
4231
+ const log = ctx.event({ methodName: nativeEvent });
4232
+ log.start(() => ({ raw: arg }));
4233
+ // Strict validation: events must come in {data: "json_string"} format
4234
+ if (!arg || typeof arg !== 'object' || !arg.data) {
4235
+ const error = new Error(`[${emitterName}] Invalid event format received. Expected {data: "json_string"}, got: ${JSON.stringify(arg)}`);
4236
+ log.failed(() => ({ error }));
4237
+ throw error;
4238
+ }
4239
+ const rawEventData = arg.data;
4240
+ // Parse JSON string using specific parser with decode logging
4241
+ let eventData;
4242
+ if (typeof rawEventData === 'string') {
4243
+ try {
4244
+ eventData = this.parseEventData(rawEventData, ctx);
4245
+ }
4246
+ catch (error) {
4247
+ log.failed(() => ({ error }));
4248
+ throw error;
4249
+ }
4250
+ }
4251
+ else {
4252
+ const err = new Error(`[${emitterName}] Expected event data to be JSON string, got ${typeof rawEventData}: ${rawEventData}`);
4253
+ log.failed(() => ({ error: err }));
4254
+ throw err;
4255
+ }
4256
+ const eventViewId = this.getEventViewId(eventData);
4257
+ if (viewId !== eventViewId) {
4258
+ return;
4259
+ }
4260
+ const handlerName = this.getHandlerForNativeEvent(nativeEvent, eventData);
4261
+ if (!handlerName) {
4262
+ return;
4263
+ }
4264
+ // 1. Client handler (single)
4265
+ const handlerData = this.handlers.get(handlerName);
4266
+ if (handlerData) {
4267
+ const { handler, onRequestClose } = handlerData;
4268
+ const callbackArgs = this.extractCallbackArgs(handlerName, eventData);
4269
+ const cb = handler;
4270
+ try {
4271
+ const shouldClose = cb(...callbackArgs);
4272
+ if (shouldClose) {
4273
+ onRequestClose().catch((error) => {
4274
+ log.failed(() => ({ error, handlerName }));
4275
+ });
4276
+ }
4277
+ log.success(() => ({ message: 'Event handled successfully', handlerName }));
4278
+ }
4279
+ catch (error) {
4280
+ log.failed(() => ({ error, handlerName }));
4281
+ }
4282
+ }
4283
+ // 2. Internal handler
4284
+ const internalHandlerData = this.internalHandlers.get(handlerName);
4285
+ if (internalHandlerData) {
4286
+ try {
4287
+ internalHandlerData.handler(eventData);
4288
+ }
4289
+ catch (error) {
4290
+ log.failed(() => ({ error, handlerName: `internal:${String(handlerName)}` }));
4291
+ }
4292
+ }
4293
+ });
4294
+ this.eventListeners.set(nativeEvent, subscription);
4295
+ return subscription;
4296
+ }
4297
+ async getOrCreateNativeListener(nativeEvent) {
4298
+ const existing = this.eventListeners.get(nativeEvent);
4299
+ if (existing) {
4300
+ return existing;
4301
+ }
4302
+ const created = await this.createNativeListener(nativeEvent);
4303
+ if (!created) {
4304
+ throw new Error(`Failed to register listener for ${nativeEvent}`);
4305
+ }
4306
+ return created;
4022
4307
  }
4023
4308
  }
4024
4309
 
4025
4310
  /**
4026
- * OnboardingViewEmitter manages event handlers for onboarding view events.
4311
+ * PaywallViewEmitter manages event handlers for paywall view events.
4027
4312
  * Each event type can have only one handler - new handlers replace existing ones.
4028
4313
  */
4029
- class OnboardingViewEmitter extends BaseViewEmitter {
4030
- getEventConfig(event) {
4031
- return HANDLER_TO_EVENT_CONFIG$1[event];
4032
- }
4314
+ class PaywallViewEmitter extends BaseViewEmitter {
4033
4315
  parseEventData(rawEventData, ctx) {
4034
- return parseOnboardingEvent(rawEventData, ctx);
4316
+ const result = parsePaywallEvent(rawEventData);
4317
+ if (!result) {
4318
+ throw new Error('Failed to parse paywall event');
4319
+ }
4320
+ return result;
4035
4321
  }
4036
- getPossibleHandlers(nativeEvent) {
4037
- return NATIVE_EVENT_TO_HANDLERS$1[nativeEvent] || [];
4322
+ getNativeEventForHandler(event) {
4323
+ return HANDLER_TO_NATIVE_EVENT$1[event];
4324
+ }
4325
+ getHandlerForNativeEvent(nativeEvent, eventData) {
4326
+ const resolver = NATIVE_EVENT_RESOLVER$1[nativeEvent];
4327
+ if (!resolver) {
4328
+ return null;
4329
+ }
4330
+ return resolver(eventData);
4038
4331
  }
4039
4332
  extractCallbackArgs(handlerName, eventData) {
4040
4333
  return extractCallbackArgs$1(handlerName, eventData);
@@ -4043,59 +4336,82 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4043
4336
  var _a, _b;
4044
4337
  return (_b = (_a = eventData === null || eventData === void 0 ? void 0 : eventData.view) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null;
4045
4338
  }
4046
- shouldCallHandler() {
4047
- // Onboarding events don't use propertyMap filtering
4048
- return true;
4049
- }
4050
4339
  getEmitterName() {
4051
- return 'OnboardingViewEmitter';
4340
+ return 'PaywallViewEmitter';
4052
4341
  }
4053
4342
  }
4054
- const ONBOARDING_EVENT_MAPPINGS = {
4055
- onboarding_did_fail_with_error: [{ handlerName: 'onError' }],
4056
- onboarding_on_analytics_action: [{ handlerName: 'onAnalytics' }],
4057
- onboarding_did_finish_loading: [{ handlerName: 'onFinishedLoading' }],
4058
- onboarding_on_close_action: [{ handlerName: 'onClose' }],
4059
- onboarding_on_custom_action: [{ handlerName: 'onCustom' }],
4060
- onboarding_on_paywall_action: [{ handlerName: 'onPaywall' }],
4061
- onboarding_on_state_updated_action: [{ handlerName: 'onStateUpdated' }],
4062
- };
4063
- const HANDLER_TO_EVENT_CONFIG$1 = Object.entries(ONBOARDING_EVENT_MAPPINGS).reduce((acc, [nativeEvent, mappings]) => {
4064
- mappings.forEach(({ handlerName }) => {
4065
- acc[handlerName] = {
4066
- nativeEvent,
4067
- handlerName,
4343
+ const NATIVE_EVENT_RESOLVER$1 = {
4344
+ [PaywallEventId.DidPerformAction]: (event) => {
4345
+ var _a;
4346
+ if (event.id !== PaywallEventId.DidPerformAction) {
4347
+ return null;
4348
+ }
4349
+ const actionMap = {
4350
+ close: 'onCloseButtonPress',
4351
+ system_back: 'onAndroidSystemBack',
4352
+ open_url: 'onUrlPress',
4353
+ custom: 'onCustomAction',
4068
4354
  };
4069
- });
4070
- return acc;
4071
- }, {});
4072
- // Reverse mapping: nativeEvent -> EventName[]
4073
- const NATIVE_EVENT_TO_HANDLERS$1 = Object.entries(HANDLER_TO_EVENT_CONFIG$1).reduce((acc, [handlerName, config]) => {
4074
- if (!acc[config.nativeEvent]) {
4075
- acc[config.nativeEvent] = [];
4076
- }
4077
- acc[config.nativeEvent].push(handlerName);
4078
- return acc;
4079
- }, {});
4080
- function extractCallbackArgs$1(handlerName, eventArg) {
4081
- const actionId = eventArg.id || '';
4082
- const meta = eventArg.meta;
4083
- const event = eventArg.event;
4084
- const action = eventArg.action;
4085
- switch (handlerName) {
4086
- case 'onClose':
4087
- case 'onCustom':
4088
- case 'onPaywall':
4089
- return [actionId, meta];
4090
- case 'onStateUpdated':
4091
- return [action, meta];
4092
- case 'onFinishedLoading':
4093
- return [meta];
4094
- case 'onAnalytics':
4095
- return [event, meta];
4096
- case 'onError':
4097
- return [eventArg.error];
4098
- default:
4355
+ return (_a = actionMap[event.action.type]) !== null && _a !== void 0 ? _a : null;
4356
+ },
4357
+ [PaywallEventId.DidAppear]: () => 'onAppeared',
4358
+ [PaywallEventId.DidDisappear]: () => 'onDisappeared',
4359
+ [PaywallEventId.DidSelectProduct]: () => 'onProductSelected',
4360
+ [PaywallEventId.DidStartPurchase]: () => 'onPurchaseStarted',
4361
+ [PaywallEventId.DidFinishPurchase]: () => 'onPurchaseCompleted',
4362
+ [PaywallEventId.DidFailPurchase]: () => 'onPurchaseFailed',
4363
+ [PaywallEventId.DidStartRestore]: () => 'onRestoreStarted',
4364
+ [PaywallEventId.DidFinishRestore]: () => 'onRestoreCompleted',
4365
+ [PaywallEventId.DidFailRestore]: () => 'onRestoreFailed',
4366
+ [PaywallEventId.DidFailRendering]: () => 'onRenderingFailed',
4367
+ [PaywallEventId.DidFailLoadingProducts]: () => 'onLoadingProductsFailed',
4368
+ [PaywallEventId.DidFinishWebPaymentNavigation]: () => 'onWebPaymentNavigationFinished',
4369
+ };
4370
+ const HANDLER_TO_NATIVE_EVENT$1 = {
4371
+ onCloseButtonPress: PaywallEventId.DidPerformAction,
4372
+ onAndroidSystemBack: PaywallEventId.DidPerformAction,
4373
+ onUrlPress: PaywallEventId.DidPerformAction,
4374
+ onCustomAction: PaywallEventId.DidPerformAction,
4375
+ onProductSelected: PaywallEventId.DidSelectProduct,
4376
+ onPurchaseStarted: PaywallEventId.DidStartPurchase,
4377
+ onPurchaseCompleted: PaywallEventId.DidFinishPurchase,
4378
+ onPurchaseFailed: PaywallEventId.DidFailPurchase,
4379
+ onRestoreStarted: PaywallEventId.DidStartRestore,
4380
+ onRestoreCompleted: PaywallEventId.DidFinishRestore,
4381
+ onRestoreFailed: PaywallEventId.DidFailRestore,
4382
+ onAppeared: PaywallEventId.DidAppear,
4383
+ onDisappeared: PaywallEventId.DidDisappear,
4384
+ onRenderingFailed: PaywallEventId.DidFailRendering,
4385
+ onLoadingProductsFailed: PaywallEventId.DidFailLoadingProducts,
4386
+ onWebPaymentNavigationFinished: PaywallEventId.DidFinishWebPaymentNavigation,
4387
+ };
4388
+ function extractCallbackArgs$1(handlerName, event) {
4389
+ var _a;
4390
+ switch (event.id) {
4391
+ case PaywallEventId.DidSelectProduct:
4392
+ return [event.productId];
4393
+ case PaywallEventId.DidStartPurchase:
4394
+ return [event.product];
4395
+ case PaywallEventId.DidFinishPurchase:
4396
+ return [event.purchaseResult, event.product];
4397
+ case PaywallEventId.DidFailPurchase:
4398
+ return [event.error, event.product];
4399
+ case PaywallEventId.DidFinishRestore:
4400
+ return [event.profile];
4401
+ case PaywallEventId.DidFailRestore:
4402
+ case PaywallEventId.DidFailRendering:
4403
+ case PaywallEventId.DidFailLoadingProducts:
4404
+ return [event.error];
4405
+ case PaywallEventId.DidPerformAction:
4406
+ if (handlerName === 'onUrlPress' || handlerName === 'onCustomAction') {
4407
+ return [(_a = event.action.value) !== null && _a !== void 0 ? _a : ''];
4408
+ }
4409
+ return [];
4410
+ case PaywallEventId.DidFinishWebPaymentNavigation:
4411
+ return [event.product, event.error];
4412
+ case PaywallEventId.DidAppear:
4413
+ case PaywallEventId.DidDisappear:
4414
+ case PaywallEventId.DidStartRestore:
4099
4415
  return [];
4100
4416
  }
4101
4417
  }
@@ -4120,9 +4436,9 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4120
4436
  onRestoreStarted: () => false,
4121
4437
  onRestoreCompleted: () => true,
4122
4438
  onRestoreFailed: () => false,
4123
- onPaywallShown: () => false,
4124
- onPaywallClosed: () => false,
4125
- onRenderingFailed: () => false,
4439
+ onAppeared: () => false,
4440
+ onDisappeared: () => false,
4441
+ onRenderingFailed: () => true,
4126
4442
  onLoadingProductsFailed: () => false,
4127
4443
  onWebPaymentNavigationFinished: () => false,
4128
4444
  };
@@ -4130,43 +4446,47 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4130
4446
  onClose: () => true,
4131
4447
  };
4132
4448
 
4449
+ const DEFAULT_PARAMS = {
4450
+ prefetchProducts: true,
4451
+ loadTimeoutMs: 5000,
4452
+ };
4133
4453
  /**
4134
- * Controller for managing onboarding views.
4454
+ * Controller for managing paywall views.
4135
4455
  *
4136
4456
  * @remarks
4137
- * This class provides methods to present, dismiss, and handle events for onboarding views
4138
- * created with the Onboarding Builder. Create instances using the {@link createOnboardingView} function
4457
+ * This class provides methods to present, dismiss, and handle events for paywall views
4458
+ * created with the Paywall Builder. Create instances using the {@link createPaywallView} function
4139
4459
  * rather than directly constructing this class.
4140
4460
  *
4141
4461
  * @public
4142
4462
  */
4143
- class OnboardingViewController {
4463
+ class PaywallViewController {
4144
4464
  /**
4145
- * Intended way to create a OnboardingViewController instance.
4465
+ * Intended way to create a ViewController instance.
4146
4466
  * It prepares a native controller to be presented
4147
4467
  * and creates reference between native controller and JS instance
4148
4468
  * @internal
4149
4469
  */
4150
- static async create(onboarding, adaptyPlugin) {
4151
- const controller = new OnboardingViewController(adaptyPlugin);
4470
+ static async create(paywall, params, adaptyPlugin) {
4471
+ const controller = new PaywallViewController(adaptyPlugin);
4152
4472
  const ctx = new LogContext();
4153
- const methodKey = 'adapty_ui_create_onboarding_view';
4473
+ const methodKey = 'adapty_ui_create_paywall_view';
4154
4474
  const log = ctx.call({ methodName: methodKey });
4155
- log.start(() => ({ onboarding }));
4156
- const coder = new AdaptyOnboardingCoder();
4157
- const data = {
4158
- method: methodKey,
4159
- onboarding: coder.encode(onboarding),
4160
- };
4475
+ log.start(() => ({ paywall, params }));
4476
+ const paywallCoder = new AdaptyPaywallCoder();
4477
+ const paramsCoder = new AdaptyUICreatePaywallViewParamsCoder();
4478
+ const paramsWithDefaults = Object.assign(Object.assign({}, DEFAULT_PARAMS), params);
4479
+ const data = Object.assign({ method: methodKey, paywall: paywallCoder.encode(paywall) }, paramsCoder.encode(paramsWithDefaults));
4161
4480
  const result = (await controller.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log));
4162
4481
  controller.id = result.id;
4163
- await controller.setEventHandlers(DEFAULT_ONBOARDING_EVENT_HANDLERS);
4482
+ controller.viewEmitter = new PaywallViewEmitter(controller.id);
4483
+ await controller.setEventHandlers(DEFAULT_EVENT_HANDLERS);
4164
4484
  return controller;
4165
4485
  }
4166
4486
  /**
4167
4487
  * Since constructors in JS cannot be async, it is not
4168
4488
  * preferred to create ViewControllers in direct way.
4169
- * Consider using @link{OnboardingViewController.create} instead
4489
+ * Consider using @link{ViewController.create} instead
4170
4490
  *
4171
4491
  * @internal
4172
4492
  */
@@ -4178,31 +4498,31 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4178
4498
  await this.dismiss();
4179
4499
  }
4180
4500
  catch (error) {
4181
- Log.warn('setEventHandlers', () => 'Failed to dismiss onboarding', () => ({ error }));
4501
+ Log.warn('setEventHandlers', () => 'Failed to dismiss paywall', () => ({ error }));
4182
4502
  }
4183
4503
  };
4184
4504
  this.adaptyPlugin = adaptyPlugin;
4185
4505
  }
4186
4506
  /**
4187
- * Presents the onboarding view as a modal screen.
4507
+ * Presents the paywall view as a modal screen.
4188
4508
  *
4189
4509
  * @remarks
4190
- * Calling `present` on an already visible onboarding view will result in an error.
4191
- * The onboarding will be displayed with the configured presentation style on iOS.
4192
- * On Android, the onboarding is always presented as a full-screen activity.
4510
+ * Calling `present` on an already visible paywall view will result in an error.
4511
+ * The paywall will be displayed with the configured presentation style on iOS.
4512
+ * On Android, the paywall is always presented as a full-screen activity.
4193
4513
  *
4194
4514
  * @param options - Optional presentation options
4195
4515
  * @param options.iosPresentationStyle - iOS presentation style. Available options: `'full_screen'` (default) or `'page_sheet'`. Only affects iOS platform.
4196
- * @returns A promise that resolves when the onboarding is presented.
4516
+ * @returns A promise that resolves when the paywall is presented.
4197
4517
  * @throws {@link AdaptyError} if the view reference is invalid or the view is already presented.
4198
4518
  *
4199
4519
  * @example
4200
4520
  * Present with default full-screen style
4201
4521
  * ```typescript
4202
- * import { adapty, createOnboardingView } from '@adapty/capacitor';
4522
+ * import { adapty, createPaywallView } from '@adapty/capacitor';
4203
4523
  *
4204
- * const onboarding = await adapty.getOnboarding({ placementId: 'YOUR_PLACEMENT_ID' });
4205
- * const view = await createOnboardingView(onboarding);
4524
+ * const paywall = await adapty.getPaywall({ placementId: 'YOUR_PLACEMENT_ID' });
4525
+ * const view = await createPaywallView(paywall);
4206
4526
  * await view.present();
4207
4527
  * ```
4208
4528
  *
@@ -4215,11 +4535,14 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4215
4535
  async present(options = {}) {
4216
4536
  var _a;
4217
4537
  const ctx = new LogContext();
4218
- const methodKey = 'adapty_ui_present_onboarding_view';
4538
+ const methodKey = 'adapty_ui_present_paywall_view';
4219
4539
  const log = ctx.call({ methodName: methodKey });
4220
4540
  log.start(() => ({ _id: this.id, iosPresentationStyle: options.iosPresentationStyle }));
4221
4541
  if (this.id === null) {
4222
- throw new AdaptyError({ adaptyCode: 2002, message: 'No view reference' });
4542
+ throw new AdaptyError({
4543
+ adaptyCode: 2002,
4544
+ message: 'No view reference',
4545
+ });
4223
4546
  }
4224
4547
  const data = {
4225
4548
  method: methodKey,
@@ -4229,20 +4552,20 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4229
4552
  await this.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log);
4230
4553
  }
4231
4554
  /**
4232
- * Dismisses the onboarding view.
4555
+ * Dismisses the paywall view.
4233
4556
  *
4234
4557
  * @remarks
4235
- * This method closes the onboarding and cleans up associated resources.
4558
+ * This method closes the paywall and cleans up associated resources.
4236
4559
  * After dismissing, the view controller instance cannot be reused.
4237
4560
  *
4238
- * @returns A promise that resolves when the onboarding is dismissed.
4561
+ * @returns A promise that resolves when the paywall is dismissed.
4239
4562
  * @throws {@link AdaptyError} if the view reference is invalid.
4240
4563
  *
4241
4564
  * @example
4242
4565
  * ```typescript
4243
- * import { createOnboardingView } from '@adapty/capacitor';
4566
+ * import { createPaywallView } from '@adapty/capacitor';
4244
4567
  *
4245
- * const view = await createOnboardingView(onboarding);
4568
+ * const view = await createPaywallView(paywall);
4246
4569
  * await view.present();
4247
4570
  * // ... later
4248
4571
  * await view.dismiss();
@@ -4250,11 +4573,14 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4250
4573
  */
4251
4574
  async dismiss() {
4252
4575
  const ctx = new LogContext();
4253
- const methodKey = 'adapty_ui_dismiss_onboarding_view';
4576
+ const methodKey = 'adapty_ui_dismiss_paywall_view';
4254
4577
  const log = ctx.call({ methodName: methodKey });
4255
4578
  log.start(() => ({ _id: this.id }));
4256
4579
  if (this.id === null) {
4257
- throw new AdaptyError({ adaptyCode: 2002, message: 'No view reference' });
4580
+ throw new AdaptyError({
4581
+ adaptyCode: 2002,
4582
+ message: 'No view reference',
4583
+ });
4258
4584
  }
4259
4585
  const data = {
4260
4586
  method: methodKey,
@@ -4262,21 +4588,82 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4262
4588
  destroy: true,
4263
4589
  };
4264
4590
  await this.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log);
4591
+ this.clearEventHandlers();
4265
4592
  }
4266
4593
  /**
4267
- * Registers event handlers for onboarding UI events.
4594
+ * Displays a dialog to the user.
4595
+ *
4596
+ * @remarks
4597
+ * Use this method to show custom dialogs within the paywall flow.
4598
+ * If you provide two actions in the config, the primary action should cancel the operation
4599
+ * and leave things unchanged, while the secondary action should confirm the operation.
4600
+ *
4601
+ * @param config - Configuration for the dialog.
4602
+ * @param config.title - The dialog title.
4603
+ * @param config.content - The dialog message content.
4604
+ * @param config.primaryActionTitle - The title for the primary (default) action button.
4605
+ * @param config.secondaryActionTitle - Optional. The title for the secondary action button.
4606
+ * @returns A promise that resolves to the action type that the user selected: `'primary'` or `'secondary'`.
4607
+ * @throws {@link AdaptyError} if the view reference is invalid.
4608
+ *
4609
+ * @example
4610
+ * Show confirmation dialog
4611
+ * ```typescript
4612
+ * const action = await view.showDialog({
4613
+ * title: 'Confirm Purchase',
4614
+ * content: 'Are you sure you want to proceed with this purchase?',
4615
+ * primaryActionTitle: 'Cancel',
4616
+ * secondaryActionTitle: 'Continue'
4617
+ * });
4618
+ *
4619
+ * if (action === 'secondary') {
4620
+ * console.log('User confirmed');
4621
+ * }
4622
+ * ```
4623
+ */
4624
+ async showDialog(config) {
4625
+ const ctx = new LogContext();
4626
+ const methodKey = 'adapty_ui_show_dialog';
4627
+ const log = ctx.call({ methodName: methodKey });
4628
+ log.start(() => ({ _id: this.id }));
4629
+ if (this.id === null) {
4630
+ throw new AdaptyError({
4631
+ adaptyCode: 2002,
4632
+ message: 'No view reference',
4633
+ });
4634
+ }
4635
+ const dialogConfig = {
4636
+ default_action_title: config.primaryActionTitle,
4637
+ secondary_action_title: config.secondaryActionTitle,
4638
+ title: config.title,
4639
+ content: config.content,
4640
+ };
4641
+ const data = {
4642
+ method: methodKey,
4643
+ id: this.id,
4644
+ configuration: dialogConfig,
4645
+ };
4646
+ return await this.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log);
4647
+ }
4648
+ /**
4649
+ * Registers event handlers for paywall UI events.
4268
4650
  *
4269
4651
  * @remarks
4270
4652
  * Each event type can have only one handler — new handlers replace existing ones.
4271
- * Default handlers are registered automatically in {@link createOnboardingView} and provide standard closing behavior:
4272
- * - `onClose` - closes the onboarding when the close button is pressed or system back is used
4653
+ * Default handlers are registered automatically in {@link createPaywallView} and provide standard closing behavior:
4654
+ * - `onCloseButtonPress` - closes the paywall
4655
+ * - `onAndroidSystemBack` - closes the paywall (Android only)
4656
+ * - `onRestoreCompleted` - closes the paywall after successful restore
4657
+ * - `onRenderingFailed` - closes the paywall when rendering fails
4658
+ * - `onPurchaseCompleted` - closes the paywall after successful purchase
4273
4659
  *
4274
- * If you want to override the `onClose` listener, we strongly recommend returning `true`
4660
+ * If you want to override these listeners, we strongly recommend returning `true`
4661
+ * (or `purchaseResult.type !== 'user_cancelled'` in case of `onPurchaseCompleted`)
4275
4662
  * from your custom listener to retain default closing behavior.
4276
4663
  *
4277
4664
  * Calling this method multiple times will replace previously registered handlers for provided events.
4278
4665
  *
4279
- * @see {@link https://adapty.io/docs/capacitor-handling-onboarding-events | Handling Onboarding Events}
4666
+ * @see {@link https://adapty.io/docs/capacitor-handling-events | Handling View Events}
4280
4667
  *
4281
4668
  * @param eventHandlers - Set of event handling callbacks. Only provided handlers will be registered or updated.
4282
4669
  * @returns A promise that resolves to an unsubscribe function that removes all registered listeners.
@@ -4284,21 +4671,21 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4284
4671
  * @example
4285
4672
  * Register custom event handlers
4286
4673
  * ```typescript
4287
- * import { createOnboardingView } from '@adapty/capacitor';
4674
+ * import { createPaywallView } from '@adapty/capacitor';
4288
4675
  *
4289
- * const view = await createOnboardingView(onboarding);
4676
+ * const view = await createPaywallView(paywall);
4290
4677
  *
4291
4678
  * const unsubscribe = await view.setEventHandlers({
4292
- * onClose: () => {
4293
- * console.log('Onboarding closed');
4294
- * // Return true to keep default closing behavior
4295
- * return true;
4679
+ * onPurchaseStarted: (product) => {
4680
+ * console.log('Purchase started:', product.vendorProductId);
4296
4681
  * },
4297
- * onActionPerformed: (action) => {
4298
- * console.log('Action performed:', action.name);
4682
+ * onPurchaseCompleted: (result) => {
4683
+ * console.log('Purchase completed:', result.type);
4684
+ * // Return true to keep default closing behavior
4685
+ * return result.type !== 'user_cancelled';
4299
4686
  * },
4300
- * onProductSelected: (product) => {
4301
- * console.log('Product selected:', product.vendorProductId);
4687
+ * onPurchaseFailed: (error) => {
4688
+ * console.error('Purchase failed:', error);
4302
4689
  * }
4303
4690
  * });
4304
4691
  *
@@ -4314,29 +4701,33 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4314
4701
  const log = ctx.call({ methodName: 'setEventHandlers' });
4315
4702
  log.start(() => ({ _id: this.id }));
4316
4703
  if (this.id === null) {
4317
- throw new AdaptyError({ adaptyCode: 2002, message: 'No view reference' });
4704
+ throw new AdaptyError({
4705
+ adaptyCode: 2002,
4706
+ message: 'No view reference',
4707
+ });
4318
4708
  }
4319
- Log.verbose('setEventHandlers', () => 'Registering onboarding event handlers for view', () => ({ id: this.id }));
4320
- const viewEmitter = (_a = this.viewEmitter) !== null && _a !== void 0 ? _a : new OnboardingViewEmitter(this.id);
4709
+ Log.verbose('setEventHandlers', () => 'Registering event handlers for view', () => ({ id: this.id }));
4710
+ const viewEmitter = (_a = this.viewEmitter) !== null && _a !== void 0 ? _a : new PaywallViewEmitter(this.id);
4321
4711
  this.viewEmitter = viewEmitter;
4322
4712
  const wrappedErrorLogEventHandlers = mapValues(eventHandlers, (handler, eventName) => handler && typeof handler === 'function'
4323
- ? withErrorContext(handler, eventName, 'OnboardingViewController')
4713
+ ? withErrorContext(handler, eventName, 'PaywallViewController')
4324
4714
  : undefined);
4325
4715
  // Merge with defaults to ensure default behavior is preserved after unsubscribe/resubscribe cycles
4326
- const finalEventHandlers = Object.assign(Object.assign({}, DEFAULT_ONBOARDING_EVENT_HANDLERS), wrappedErrorLogEventHandlers);
4716
+ const finalEventHandlers = Object.assign(Object.assign({}, DEFAULT_EVENT_HANDLERS), wrappedErrorLogEventHandlers);
4327
4717
  for (const [eventName, handler] of Object.entries(finalEventHandlers)) {
4328
4718
  if (handler && typeof handler === 'function') {
4329
4719
  try {
4330
4720
  await viewEmitter.addListener(eventName, handler, this.onRequestClose);
4331
- Log.verbose('setEventHandlers', () => 'Registered onboarding handler', () => ({ eventName }));
4721
+ Log.verbose('setEventHandlers', () => 'Registered handler for', () => ({ eventName }));
4332
4722
  }
4333
4723
  catch (error) {
4334
- Log.error('setEventHandlers', () => `Failed to register onboarding handler for ${eventName}`, () => ({ error }));
4724
+ Log.error('setEventHandlers', () => `Failed to register handler for ${eventName}`, () => ({ error }));
4335
4725
  }
4336
4726
  }
4337
4727
  }
4728
+ // Return unsubscribe function
4338
4729
  const unsubscribe = () => {
4339
- Log.info('setEventHandlers', () => 'Unsubscribing onboarding event handlers for view', () => ({ id: this.id }));
4730
+ Log.info('setEventHandlers', () => 'Unsubscribing event handlers for view', () => ({ id: this.id }));
4340
4731
  if (this.viewEmitter) {
4341
4732
  this.viewEmitter.removeAllListeners();
4342
4733
  this.viewEmitter = null;
@@ -4352,19 +4743,19 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4352
4743
  * After calling this method, no event handlers will be active
4353
4744
  * until you call {@link setEventHandlers} again.
4354
4745
  *
4355
- * Use this after dismiss to remove all event handlers.
4746
+ * Use this after dismiss to remove all event handlers
4356
4747
  *
4357
4748
  * @example
4358
4749
  * ```typescript
4359
- * const view = await createOnboardingView(onboarding);
4360
- * await view.setEventHandlers({ onClose: handleClose });
4750
+ * const view = await createPaywallView(paywall);
4751
+ * await view.setEventHandlers({ onPurchaseCompleted: handlePurchase });
4361
4752
  *
4362
4753
  * // Later, clear all handlers
4363
4754
  * view.clearEventHandlers();
4364
4755
  * ```
4365
4756
  */
4366
4757
  clearEventHandlers() {
4367
- Log.info('clearEventHandlers', () => 'Clearing all onboarding event handlers for view', () => ({ id: this.id }));
4758
+ Log.info('clearEventHandlers', () => 'Clearing all event handlers for view', () => ({ id: this.id }));
4368
4759
  if (this.viewEmitter) {
4369
4760
  this.viewEmitter.removeAllListeners();
4370
4761
  this.viewEmitter = null;
@@ -4372,19 +4763,126 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4372
4763
  }
4373
4764
  }
4374
4765
 
4766
+ class AdaptyUICreateOnboardingViewParamsCoder {
4767
+ encode(data) {
4768
+ const result = {};
4769
+ if (data.externalUrlsPresentation) {
4770
+ result.external_urls_presentation = data.externalUrlsPresentation;
4771
+ }
4772
+ return result;
4773
+ }
4774
+ }
4775
+
4776
+ // Onboarding Event IDs
4777
+ const OnboardingEventId = {
4778
+ Close: 'onboarding_on_close_action',
4779
+ Custom: 'onboarding_on_custom_action',
4780
+ Paywall: 'onboarding_on_paywall_action',
4781
+ StateUpdated: 'onboarding_on_state_updated_action',
4782
+ FinishedLoading: 'onboarding_did_finish_loading',
4783
+ Analytics: 'onboarding_on_analytics_action',
4784
+ Error: 'onboarding_did_fail_with_error',
4785
+ };
4786
+
4787
+ // Parser
4788
+ function parseOnboardingEvent(input, ctx) {
4789
+ var _a;
4790
+ let obj;
4791
+ try {
4792
+ obj = JSON.parse(input);
4793
+ }
4794
+ catch (error) {
4795
+ throw AdaptyError.failedToDecode(`Failed to decode event: ${error === null || error === void 0 ? void 0 : error.message}`);
4796
+ }
4797
+ const eventId = obj['id'];
4798
+ if (!(eventId === null || eventId === void 0 ? void 0 : eventId.startsWith('onboarding_'))) {
4799
+ return null;
4800
+ }
4801
+ const viewObj = obj['view'];
4802
+ const view = {
4803
+ id: viewObj['id'],
4804
+ placementId: viewObj['placement_id'],
4805
+ variationId: viewObj['variation_id'],
4806
+ };
4807
+ const decodeMeta = () => getOnboardingCoder('meta').decode(obj['meta']);
4808
+ switch (eventId) {
4809
+ case OnboardingEventId.Close:
4810
+ case OnboardingEventId.Custom:
4811
+ case OnboardingEventId.Paywall:
4812
+ return {
4813
+ id: eventId,
4814
+ view,
4815
+ actionId: (_a = obj['action_id']) !== null && _a !== void 0 ? _a : '',
4816
+ meta: decodeMeta(),
4817
+ };
4818
+ case OnboardingEventId.StateUpdated:
4819
+ return {
4820
+ id: eventId,
4821
+ view,
4822
+ action: getOnboardingCoder('action').decode(obj['action']),
4823
+ meta: decodeMeta(),
4824
+ };
4825
+ case OnboardingEventId.FinishedLoading:
4826
+ return {
4827
+ id: eventId,
4828
+ view,
4829
+ meta: decodeMeta(),
4830
+ };
4831
+ case OnboardingEventId.Analytics: {
4832
+ const eventObj = obj['event'];
4833
+ return {
4834
+ id: eventId,
4835
+ view,
4836
+ event: {
4837
+ name: eventObj['name'],
4838
+ elementId: eventObj['element_id'],
4839
+ reply: eventObj['reply'],
4840
+ },
4841
+ meta: decodeMeta(),
4842
+ };
4843
+ }
4844
+ case OnboardingEventId.Error: {
4845
+ const errorCoder = getOnboardingCoder('error');
4846
+ const decodedError = errorCoder.decode(obj['error']);
4847
+ return {
4848
+ id: eventId,
4849
+ view,
4850
+ error: errorCoder.getError(decodedError),
4851
+ };
4852
+ }
4853
+ default:
4854
+ return null;
4855
+ }
4856
+ }
4857
+ function getOnboardingCoder(type, _ctx) {
4858
+ switch (type) {
4859
+ case 'meta':
4860
+ return new AdaptyUiOnboardingMetaCoder();
4861
+ case 'action':
4862
+ return new AdaptyUiOnboardingStateUpdatedActionCoder();
4863
+ case 'error':
4864
+ return new AdaptyNativeErrorCoder();
4865
+ }
4866
+ }
4867
+
4375
4868
  /**
4376
- * PaywallViewEmitter manages event handlers for paywall view events.
4869
+ * OnboardingViewEmitter manages event handlers for onboarding view events.
4377
4870
  * Each event type can have only one handler - new handlers replace existing ones.
4378
4871
  */
4379
- class PaywallViewEmitter extends BaseViewEmitter {
4380
- getEventConfig(event) {
4381
- return HANDLER_TO_EVENT_CONFIG[event];
4382
- }
4872
+ class OnboardingViewEmitter extends BaseViewEmitter {
4383
4873
  parseEventData(rawEventData, ctx) {
4384
- return parsePaywallEvent(rawEventData, ctx);
4874
+ const result = parseOnboardingEvent(rawEventData);
4875
+ if (!result) {
4876
+ throw new Error('Failed to parse onboarding event');
4877
+ }
4878
+ return result;
4385
4879
  }
4386
- getPossibleHandlers(nativeEvent) {
4387
- return NATIVE_EVENT_TO_HANDLERS[nativeEvent] || [];
4880
+ getNativeEventForHandler(event) {
4881
+ return HANDLER_TO_NATIVE_EVENT[event];
4882
+ }
4883
+ getHandlerForNativeEvent(nativeEvent) {
4884
+ var _a;
4885
+ return (_a = NATIVE_EVENT_RESOLVER[nativeEvent]) !== null && _a !== void 0 ? _a : null;
4388
4886
  }
4389
4887
  extractCallbackArgs(handlerName, eventData) {
4390
4888
  return extractCallbackArgs(handlerName, eventData);
@@ -4393,200 +4891,89 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4393
4891
  var _a, _b;
4394
4892
  return (_b = (_a = eventData === null || eventData === void 0 ? void 0 : eventData.view) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null;
4395
4893
  }
4396
- shouldCallHandler(_handlerName, config, eventData) {
4397
- var _a;
4398
- if (config.propertyMap && ((_a = eventData === null || eventData === void 0 ? void 0 : eventData.action) === null || _a === void 0 ? void 0 : _a.type) !== config.propertyMap['action']) {
4399
- return false;
4400
- }
4401
- return true;
4402
- }
4403
4894
  getEmitterName() {
4404
- return 'PaywallViewEmitter';
4895
+ return 'OnboardingViewEmitter';
4405
4896
  }
4406
4897
  }
4407
- /**
4408
- * Mapping of native events to event handlers
4409
- * Each native event can trigger multiple handlers based on action type or other properties
4410
- *
4411
- * Event Flow:
4412
- * 1. Native code sends event (e.g., "paywall_view_did_perform_action")
4413
- * 2. ViewEmitter receives event and checks view ID match
4414
- * 3. For events with propertyMap, filters by action type (e.g., action.type === "close")
4415
- * 4. Calls appropriate handler function
4416
- * 5. If handler returns true, requests paywall close
4417
- */
4418
- const UI_EVENT_MAPPINGS = {
4419
- // User actions like close button, back button, URL taps, custom actions
4420
- paywall_view_did_perform_action: [
4421
- {
4422
- handlerName: 'onCloseButtonPress',
4423
- propertyMap: {
4424
- action: 'close',
4425
- },
4426
- },
4427
- {
4428
- handlerName: 'onAndroidSystemBack',
4429
- propertyMap: {
4430
- action: 'system_back',
4431
- },
4432
- },
4433
- {
4434
- handlerName: 'onUrlPress',
4435
- propertyMap: {
4436
- action: 'open_url',
4437
- },
4438
- },
4439
- {
4440
- handlerName: 'onCustomAction',
4441
- propertyMap: {
4442
- action: 'custom',
4443
- },
4444
- },
4445
- ],
4446
- // Product selection events
4447
- paywall_view_did_select_product: [{ handlerName: 'onProductSelected' }],
4448
- // Purchase flow events
4449
- paywall_view_did_start_purchase: [{ handlerName: 'onPurchaseStarted' }],
4450
- paywall_view_did_finish_purchase: [{ handlerName: 'onPurchaseCompleted' }],
4451
- paywall_view_did_fail_purchase: [{ handlerName: 'onPurchaseFailed' }],
4452
- // Restore flow events
4453
- paywall_view_did_start_restore: [{ handlerName: 'onRestoreStarted' }],
4454
- paywall_view_did_finish_restore: [{ handlerName: 'onRestoreCompleted' }],
4455
- paywall_view_did_fail_restore: [{ handlerName: 'onRestoreFailed' }],
4456
- // Paywall lifecycle events
4457
- paywall_view_did_appear: [{ handlerName: 'onPaywallShown' }],
4458
- paywall_view_did_disappear: [{ handlerName: 'onPaywallClosed' }],
4459
- // Error events
4460
- paywall_view_did_fail_rendering: [{ handlerName: 'onRenderingFailed' }],
4461
- paywall_view_did_fail_loading_products: [{ handlerName: 'onLoadingProductsFailed' }],
4462
- // Web payment events
4463
- paywall_view_did_finish_web_payment_navigation: [
4464
- { handlerName: 'onWebPaymentNavigationFinished' },
4465
- ],
4898
+ const HANDLER_TO_NATIVE_EVENT = {
4899
+ onError: 'onboarding_did_fail_with_error',
4900
+ onAnalytics: 'onboarding_on_analytics_action',
4901
+ onFinishedLoading: 'onboarding_did_finish_loading',
4902
+ onClose: 'onboarding_on_close_action',
4903
+ onCustom: 'onboarding_on_custom_action',
4904
+ onPaywall: 'onboarding_on_paywall_action',
4905
+ onStateUpdated: 'onboarding_on_state_updated_action',
4466
4906
  };
4467
- const HANDLER_TO_EVENT_CONFIG = Object.entries(UI_EVENT_MAPPINGS).reduce((acc, [nativeEvent, mappings]) => {
4468
- mappings.forEach(({ handlerName, propertyMap }) => {
4469
- acc[handlerName] = {
4470
- nativeEvent,
4471
- propertyMap,
4472
- handlerName,
4473
- };
4474
- });
4475
- return acc;
4476
- }, {});
4477
- // Reverse mapping: nativeEvent -> EventName[]
4478
- const NATIVE_EVENT_TO_HANDLERS = Object.entries(HANDLER_TO_EVENT_CONFIG).reduce((acc, [handlerName, config]) => {
4479
- if (!acc[config.nativeEvent]) {
4480
- acc[config.nativeEvent] = [];
4481
- }
4482
- acc[config.nativeEvent].push(handlerName);
4483
- return acc;
4484
- }, {});
4485
- function extractCallbackArgs(handlerName, eventArg) {
4486
- var _a;
4487
- switch (handlerName) {
4488
- case 'onProductSelected':
4489
- return [eventArg.product_id];
4490
- case 'onPurchaseStarted':
4491
- return [eventArg.product];
4492
- case 'onPurchaseCompleted':
4493
- return [eventArg.purchased_result, eventArg.product];
4494
- case 'onPurchaseFailed':
4495
- return [eventArg.error, eventArg.product];
4496
- case 'onRestoreCompleted':
4497
- return [eventArg.profile];
4498
- case 'onRestoreFailed':
4499
- case 'onRenderingFailed':
4500
- case 'onLoadingProductsFailed':
4501
- return [eventArg.error];
4502
- case 'onCustomAction':
4503
- case 'onUrlPress':
4504
- return [(_a = eventArg.action) === null || _a === void 0 ? void 0 : _a.value];
4505
- case 'onWebPaymentNavigationFinished':
4506
- return [eventArg.product, eventArg.error];
4507
- case 'onCloseButtonPress':
4508
- case 'onAndroidSystemBack':
4509
- case 'onPaywallShown':
4510
- case 'onPaywallClosed':
4511
- case 'onRestoreStarted':
4512
- default:
4513
- return [];
4907
+ const NATIVE_EVENT_RESOLVER = {
4908
+ onboarding_did_fail_with_error: 'onError',
4909
+ onboarding_on_analytics_action: 'onAnalytics',
4910
+ onboarding_did_finish_loading: 'onFinishedLoading',
4911
+ onboarding_on_close_action: 'onClose',
4912
+ onboarding_on_custom_action: 'onCustom',
4913
+ onboarding_on_paywall_action: 'onPaywall',
4914
+ onboarding_on_state_updated_action: 'onStateUpdated',
4915
+ };
4916
+ function extractCallbackArgs(_handlerName, event) {
4917
+ switch (event.id) {
4918
+ case OnboardingEventId.Close:
4919
+ case OnboardingEventId.Custom:
4920
+ case OnboardingEventId.Paywall:
4921
+ return [event.actionId, event.meta];
4922
+ case OnboardingEventId.StateUpdated:
4923
+ return [event.action, event.meta];
4924
+ case OnboardingEventId.FinishedLoading:
4925
+ return [event.meta];
4926
+ case OnboardingEventId.Analytics:
4927
+ return [
4928
+ Object.assign(Object.assign({}, event.event), {
4929
+ // Add backward compatibility: populate element_id from elementId
4930
+ element_id: event.event.elementId }),
4931
+ event.meta,
4932
+ ];
4933
+ case OnboardingEventId.Error:
4934
+ return [event.error];
4514
4935
  }
4515
4936
  }
4516
4937
 
4938
+ const DEFAULT_ONBOARDING_PARAMS = {
4939
+ externalUrlsPresentation: WebPresentation.BrowserInApp,
4940
+ };
4517
4941
  /**
4518
- * Controller for managing paywall views.
4942
+ * Controller for managing onboarding views.
4519
4943
  *
4520
4944
  * @remarks
4521
- * This class provides methods to present, dismiss, and handle events for paywall views
4522
- * created with the Paywall Builder. Create instances using the {@link createPaywallView} function
4945
+ * This class provides methods to present, dismiss, and handle events for onboarding views
4946
+ * created with the Onboarding Builder. Create instances using the {@link createOnboardingView} function
4523
4947
  * rather than directly constructing this class.
4524
4948
  *
4525
4949
  * @public
4526
4950
  */
4527
- class PaywallViewController {
4951
+ class OnboardingViewController {
4528
4952
  /**
4529
- * Intended way to create a ViewController instance.
4953
+ * Intended way to create a OnboardingViewController instance.
4530
4954
  * It prepares a native controller to be presented
4531
4955
  * and creates reference between native controller and JS instance
4532
4956
  * @internal
4533
4957
  */
4534
- static async create(paywall, params, adaptyPlugin) {
4535
- var _a, _b;
4536
- const controller = new PaywallViewController(adaptyPlugin);
4958
+ static async create(onboarding, adaptyPlugin, params = {}) {
4959
+ const controller = new OnboardingViewController(adaptyPlugin);
4537
4960
  const ctx = new LogContext();
4538
- const methodKey = 'adapty_ui_create_paywall_view';
4961
+ const methodKey = 'adapty_ui_create_onboarding_view';
4539
4962
  const log = ctx.call({ methodName: methodKey });
4540
- log.start(() => ({ paywall, params }));
4541
- const coder = new AdaptyPaywallCoder();
4542
- const data = {
4543
- method: methodKey,
4544
- paywall: coder.encode(paywall),
4545
- preload_products: (_a = params.prefetchProducts) !== null && _a !== void 0 ? _a : true,
4546
- load_timeout: ((_b = params.loadTimeoutMs) !== null && _b !== void 0 ? _b : 5000) / 1000,
4547
- };
4548
- if (params.customTags) {
4549
- data.custom_tags = params.customTags;
4550
- }
4551
- if (params.customTimers) {
4552
- const convertTimerInfo = (timerInfo) => {
4553
- const formatDate = (date) => {
4554
- const pad = (num, digits = 2) => {
4555
- const str = num.toString();
4556
- const paddingLength = digits - str.length;
4557
- return paddingLength > 0 ? '0'.repeat(paddingLength) + str : str;
4558
- };
4559
- const year = date.getUTCFullYear();
4560
- const month = pad(date.getUTCMonth() + 1);
4561
- const day = pad(date.getUTCDate());
4562
- const hours = pad(date.getUTCHours());
4563
- const minutes = pad(date.getUTCMinutes());
4564
- const seconds = pad(date.getUTCSeconds());
4565
- const millis = pad(date.getUTCMilliseconds(), 3);
4566
- return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${millis}Z`;
4567
- };
4568
- const result = {};
4569
- for (const key in timerInfo) {
4570
- if (Object.prototype.hasOwnProperty.call(timerInfo, key)) {
4571
- const date = timerInfo[key];
4572
- if (date instanceof Date) {
4573
- result[key] = formatDate(date);
4574
- }
4575
- }
4576
- }
4577
- return result;
4578
- };
4579
- data.custom_timers = convertTimerInfo(params.customTimers);
4580
- }
4963
+ log.start(() => ({ onboarding, params }));
4964
+ const coder = new AdaptyOnboardingCoder();
4965
+ const paramsWithDefaults = Object.assign(Object.assign({}, DEFAULT_ONBOARDING_PARAMS), params);
4966
+ const encodedParams = new AdaptyUICreateOnboardingViewParamsCoder().encode(paramsWithDefaults);
4967
+ const data = Object.assign({ method: methodKey, onboarding: coder.encode(onboarding) }, encodedParams);
4581
4968
  const result = (await controller.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log));
4582
4969
  controller.id = result.id;
4583
- await controller.setEventHandlers(DEFAULT_EVENT_HANDLERS);
4970
+ await controller.setEventHandlers(DEFAULT_ONBOARDING_EVENT_HANDLERS);
4584
4971
  return controller;
4585
4972
  }
4586
4973
  /**
4587
4974
  * Since constructors in JS cannot be async, it is not
4588
4975
  * preferred to create ViewControllers in direct way.
4589
- * Consider using @link{ViewController.create} instead
4976
+ * Consider using @link{OnboardingViewController.create} instead
4590
4977
  *
4591
4978
  * @internal
4592
4979
  */
@@ -4598,31 +4985,31 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4598
4985
  await this.dismiss();
4599
4986
  }
4600
4987
  catch (error) {
4601
- Log.warn('setEventHandlers', () => 'Failed to dismiss paywall', () => ({ error }));
4988
+ Log.warn('setEventHandlers', () => 'Failed to dismiss onboarding', () => ({ error }));
4602
4989
  }
4603
4990
  };
4604
4991
  this.adaptyPlugin = adaptyPlugin;
4605
4992
  }
4606
4993
  /**
4607
- * Presents the paywall view as a modal screen.
4994
+ * Presents the onboarding view as a modal screen.
4608
4995
  *
4609
4996
  * @remarks
4610
- * Calling `present` on an already visible paywall view will result in an error.
4611
- * The paywall will be displayed with the configured presentation style on iOS.
4612
- * On Android, the paywall is always presented as a full-screen activity.
4997
+ * Calling `present` on an already visible onboarding view will result in an error.
4998
+ * The onboarding will be displayed with the configured presentation style on iOS.
4999
+ * On Android, the onboarding is always presented as a full-screen activity.
4613
5000
  *
4614
5001
  * @param options - Optional presentation options
4615
5002
  * @param options.iosPresentationStyle - iOS presentation style. Available options: `'full_screen'` (default) or `'page_sheet'`. Only affects iOS platform.
4616
- * @returns A promise that resolves when the paywall is presented.
5003
+ * @returns A promise that resolves when the onboarding is presented.
4617
5004
  * @throws {@link AdaptyError} if the view reference is invalid or the view is already presented.
4618
5005
  *
4619
5006
  * @example
4620
5007
  * Present with default full-screen style
4621
5008
  * ```typescript
4622
- * import { adapty, createPaywallView } from '@adapty/capacitor';
5009
+ * import { adapty, createOnboardingView } from '@adapty/capacitor';
4623
5010
  *
4624
- * const paywall = await adapty.getPaywall({ placementId: 'YOUR_PLACEMENT_ID' });
4625
- * const view = await createPaywallView(paywall);
5011
+ * const onboarding = await adapty.getOnboarding({ placementId: 'YOUR_PLACEMENT_ID' });
5012
+ * const view = await createOnboardingView(onboarding);
4626
5013
  * await view.present();
4627
5014
  * ```
4628
5015
  *
@@ -4635,14 +5022,11 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4635
5022
  async present(options = {}) {
4636
5023
  var _a;
4637
5024
  const ctx = new LogContext();
4638
- const methodKey = 'adapty_ui_present_paywall_view';
5025
+ const methodKey = 'adapty_ui_present_onboarding_view';
4639
5026
  const log = ctx.call({ methodName: methodKey });
4640
5027
  log.start(() => ({ _id: this.id, iosPresentationStyle: options.iosPresentationStyle }));
4641
5028
  if (this.id === null) {
4642
- throw new AdaptyError({
4643
- adaptyCode: 2002,
4644
- message: 'No view reference',
4645
- });
5029
+ throw new AdaptyError({ adaptyCode: 2002, message: 'No view reference' });
4646
5030
  }
4647
5031
  const data = {
4648
5032
  method: methodKey,
@@ -4652,20 +5036,20 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4652
5036
  await this.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log);
4653
5037
  }
4654
5038
  /**
4655
- * Dismisses the paywall view.
5039
+ * Dismisses the onboarding view.
4656
5040
  *
4657
5041
  * @remarks
4658
- * This method closes the paywall and cleans up associated resources.
5042
+ * This method closes the onboarding and cleans up associated resources.
4659
5043
  * After dismissing, the view controller instance cannot be reused.
4660
5044
  *
4661
- * @returns A promise that resolves when the paywall is dismissed.
5045
+ * @returns A promise that resolves when the onboarding is dismissed.
4662
5046
  * @throws {@link AdaptyError} if the view reference is invalid.
4663
5047
  *
4664
5048
  * @example
4665
5049
  * ```typescript
4666
- * import { createPaywallView } from '@adapty/capacitor';
5050
+ * import { createOnboardingView } from '@adapty/capacitor';
4667
5051
  *
4668
- * const view = await createPaywallView(paywall);
5052
+ * const view = await createOnboardingView(onboarding);
4669
5053
  * await view.present();
4670
5054
  * // ... later
4671
5055
  * await view.dismiss();
@@ -4673,14 +5057,11 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4673
5057
  */
4674
5058
  async dismiss() {
4675
5059
  const ctx = new LogContext();
4676
- const methodKey = 'adapty_ui_dismiss_paywall_view';
5060
+ const methodKey = 'adapty_ui_dismiss_onboarding_view';
4677
5061
  const log = ctx.call({ methodName: methodKey });
4678
5062
  log.start(() => ({ _id: this.id }));
4679
5063
  if (this.id === null) {
4680
- throw new AdaptyError({
4681
- adaptyCode: 2002,
4682
- message: 'No view reference',
4683
- });
5064
+ throw new AdaptyError({ adaptyCode: 2002, message: 'No view reference' });
4684
5065
  }
4685
5066
  const data = {
4686
5067
  method: methodKey,
@@ -4688,80 +5069,22 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4688
5069
  destroy: true,
4689
5070
  };
4690
5071
  await this.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log);
5072
+ this.clearEventHandlers();
4691
5073
  }
4692
5074
  /**
4693
- * Displays a dialog to the user.
4694
- *
4695
- * @remarks
4696
- * Use this method to show custom dialogs within the paywall flow.
4697
- * If you provide two actions in the config, the primary action should cancel the operation
4698
- * and leave things unchanged, while the secondary action should confirm the operation.
4699
- *
4700
- * @param config - Configuration for the dialog.
4701
- * @param config.title - The dialog title.
4702
- * @param config.content - The dialog message content.
4703
- * @param config.primaryActionTitle - The title for the primary (default) action button.
4704
- * @param config.secondaryActionTitle - Optional. The title for the secondary action button.
4705
- * @returns A promise that resolves to the action type that the user selected: `'primary'` or `'secondary'`.
4706
- * @throws {@link AdaptyError} if the view reference is invalid.
4707
- *
4708
- * @example
4709
- * Show confirmation dialog
4710
- * ```typescript
4711
- * const action = await view.showDialog({
4712
- * title: 'Confirm Purchase',
4713
- * content: 'Are you sure you want to proceed with this purchase?',
4714
- * primaryActionTitle: 'Cancel',
4715
- * secondaryActionTitle: 'Continue'
4716
- * });
4717
- *
4718
- * if (action === 'secondary') {
4719
- * console.log('User confirmed');
4720
- * }
4721
- * ```
4722
- */
4723
- async showDialog(config) {
4724
- const ctx = new LogContext();
4725
- const methodKey = 'adapty_ui_show_dialog';
4726
- const log = ctx.call({ methodName: methodKey });
4727
- log.start(() => ({ _id: this.id }));
4728
- if (this.id === null) {
4729
- throw new AdaptyError({
4730
- adaptyCode: 2002,
4731
- message: 'No view reference',
4732
- });
4733
- }
4734
- const dialogConfig = {
4735
- default_action_title: config.primaryActionTitle,
4736
- secondary_action_title: config.secondaryActionTitle,
4737
- title: config.title,
4738
- content: config.content,
4739
- };
4740
- const data = {
4741
- method: methodKey,
4742
- id: this.id,
4743
- configuration: dialogConfig,
4744
- };
4745
- return await this.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log);
4746
- }
4747
- /**
4748
- * Registers event handlers for paywall UI events.
5075
+ * Registers event handlers for onboarding UI events.
4749
5076
  *
4750
5077
  * @remarks
4751
5078
  * Each event type can have only one handler — new handlers replace existing ones.
4752
- * Default handlers are registered automatically in {@link createPaywallView} and provide standard closing behavior:
4753
- * - `onCloseButtonPress` - closes the paywall
4754
- * - `onAndroidSystemBack` - closes the paywall (Android only)
4755
- * - `onRestoreCompleted` - closes the paywall after successful restore
4756
- * - `onPurchaseCompleted` - closes the paywall after successful purchase
5079
+ * Default handlers are registered automatically in {@link createOnboardingView} and provide standard closing behavior:
5080
+ * - `onClose` - closes the onboarding when the close button is pressed or system back is used
4757
5081
  *
4758
- * If you want to override these listeners, we strongly recommend returning `true`
4759
- * (or `purchaseResult.type !== 'user_cancelled'` in case of `onPurchaseCompleted`)
5082
+ * If you want to override the `onClose` listener, we strongly recommend returning `true`
4760
5083
  * from your custom listener to retain default closing behavior.
4761
5084
  *
4762
5085
  * Calling this method multiple times will replace previously registered handlers for provided events.
4763
5086
  *
4764
- * @see {@link https://adapty.io/docs/capacitor-handling-events | Handling View Events}
5087
+ * @see {@link https://adapty.io/docs/capacitor-handling-onboarding-events | Handling Onboarding Events}
4765
5088
  *
4766
5089
  * @param eventHandlers - Set of event handling callbacks. Only provided handlers will be registered or updated.
4767
5090
  * @returns A promise that resolves to an unsubscribe function that removes all registered listeners.
@@ -4769,21 +5092,21 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4769
5092
  * @example
4770
5093
  * Register custom event handlers
4771
5094
  * ```typescript
4772
- * import { createPaywallView } from '@adapty/capacitor';
5095
+ * import { createOnboardingView } from '@adapty/capacitor';
4773
5096
  *
4774
- * const view = await createPaywallView(paywall);
5097
+ * const view = await createOnboardingView(onboarding);
4775
5098
  *
4776
5099
  * const unsubscribe = await view.setEventHandlers({
4777
- * onPurchaseStarted: (product) => {
4778
- * console.log('Purchase started:', product.vendorProductId);
4779
- * },
4780
- * onPurchaseCompleted: (result) => {
4781
- * console.log('Purchase completed:', result.type);
5100
+ * onClose: () => {
5101
+ * console.log('Onboarding closed');
4782
5102
  * // Return true to keep default closing behavior
4783
- * return result.type !== 'user_cancelled';
5103
+ * return true;
4784
5104
  * },
4785
- * onPurchaseFailed: (error) => {
4786
- * console.error('Purchase failed:', error);
5105
+ * onActionPerformed: (action) => {
5106
+ * console.log('Action performed:', action.name);
5107
+ * },
5108
+ * onProductSelected: (product) => {
5109
+ * console.log('Product selected:', product.vendorProductId);
4787
5110
  * }
4788
5111
  * });
4789
5112
  *
@@ -4799,33 +5122,29 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4799
5122
  const log = ctx.call({ methodName: 'setEventHandlers' });
4800
5123
  log.start(() => ({ _id: this.id }));
4801
5124
  if (this.id === null) {
4802
- throw new AdaptyError({
4803
- adaptyCode: 2002,
4804
- message: 'No view reference',
4805
- });
5125
+ throw new AdaptyError({ adaptyCode: 2002, message: 'No view reference' });
4806
5126
  }
4807
- Log.verbose('setEventHandlers', () => 'Registering event handlers for view', () => ({ id: this.id }));
4808
- const viewEmitter = (_a = this.viewEmitter) !== null && _a !== void 0 ? _a : new PaywallViewEmitter(this.id);
5127
+ Log.verbose('setEventHandlers', () => 'Registering onboarding event handlers for view', () => ({ id: this.id }));
5128
+ const viewEmitter = (_a = this.viewEmitter) !== null && _a !== void 0 ? _a : new OnboardingViewEmitter(this.id);
4809
5129
  this.viewEmitter = viewEmitter;
4810
5130
  const wrappedErrorLogEventHandlers = mapValues(eventHandlers, (handler, eventName) => handler && typeof handler === 'function'
4811
- ? withErrorContext(handler, eventName, 'PaywallViewController')
5131
+ ? withErrorContext(handler, eventName, 'OnboardingViewController')
4812
5132
  : undefined);
4813
5133
  // Merge with defaults to ensure default behavior is preserved after unsubscribe/resubscribe cycles
4814
- const finalEventHandlers = Object.assign(Object.assign({}, DEFAULT_EVENT_HANDLERS), wrappedErrorLogEventHandlers);
5134
+ const finalEventHandlers = Object.assign(Object.assign({}, DEFAULT_ONBOARDING_EVENT_HANDLERS), wrappedErrorLogEventHandlers);
4815
5135
  for (const [eventName, handler] of Object.entries(finalEventHandlers)) {
4816
5136
  if (handler && typeof handler === 'function') {
4817
5137
  try {
4818
5138
  await viewEmitter.addListener(eventName, handler, this.onRequestClose);
4819
- Log.verbose('setEventHandlers', () => 'Registered handler for', () => ({ eventName }));
5139
+ Log.verbose('setEventHandlers', () => 'Registered onboarding handler', () => ({ eventName }));
4820
5140
  }
4821
5141
  catch (error) {
4822
- Log.error('setEventHandlers', () => `Failed to register handler for ${eventName}`, () => ({ error }));
5142
+ Log.error('setEventHandlers', () => `Failed to register onboarding handler for ${eventName}`, () => ({ error }));
4823
5143
  }
4824
5144
  }
4825
5145
  }
4826
- // Return unsubscribe function
4827
5146
  const unsubscribe = () => {
4828
- Log.info('setEventHandlers', () => 'Unsubscribing event handlers for view', () => ({ id: this.id }));
5147
+ Log.info('setEventHandlers', () => 'Unsubscribing onboarding event handlers for view', () => ({ id: this.id }));
4829
5148
  if (this.viewEmitter) {
4830
5149
  this.viewEmitter.removeAllListeners();
4831
5150
  this.viewEmitter = null;
@@ -4841,19 +5160,19 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4841
5160
  * After calling this method, no event handlers will be active
4842
5161
  * until you call {@link setEventHandlers} again.
4843
5162
  *
4844
- * Use this after dismiss to remove all event handlers
5163
+ * Use this after dismiss to remove all event handlers.
4845
5164
  *
4846
5165
  * @example
4847
5166
  * ```typescript
4848
- * const view = await createPaywallView(paywall);
4849
- * await view.setEventHandlers({ onPurchaseCompleted: handlePurchase });
5167
+ * const view = await createOnboardingView(onboarding);
5168
+ * await view.setEventHandlers({ onClose: handleClose });
4850
5169
  *
4851
5170
  * // Later, clear all handlers
4852
5171
  * view.clearEventHandlers();
4853
5172
  * ```
4854
5173
  */
4855
5174
  clearEventHandlers() {
4856
- Log.info('clearEventHandlers', () => 'Clearing all event handlers for view', () => ({ id: this.id }));
5175
+ Log.info('clearEventHandlers', () => 'Clearing all onboarding event handlers for view', () => ({ id: this.id }));
4857
5176
  if (this.viewEmitter) {
4858
5177
  this.viewEmitter.removeAllListeners();
4859
5178
  this.viewEmitter = null;
@@ -4861,7 +5180,7 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4861
5180
  }
4862
5181
  }
4863
5182
 
4864
- const adaptyPlugin = new Adapty();
5183
+ const adaptyPlugin$1 = new Adapty();
4865
5184
  /**
4866
5185
  * Creates a paywall view controller.
4867
5186
  * You can use it to further configure a view or present it.
@@ -4884,18 +5203,41 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4884
5203
  * or if there is an error while creating a view.
4885
5204
  */
4886
5205
  async function createPaywallView(paywall, params = {}) {
4887
- const controller = await PaywallViewController.create(paywall, params, adaptyPlugin);
5206
+ const controller = await PaywallViewController.create(paywall, params, adaptyPlugin$1);
4888
5207
  return controller;
4889
5208
  }
5209
+
5210
+ const adaptyPlugin = new Adapty();
4890
5211
  /**
4891
5212
  * Creates an onboarding view controller.
4892
5213
  * You can use it to further configure a view or present it.
4893
5214
  *
5215
+ * @see {@link https://adapty.io/docs/capacitor-get-onboardings | [DOC] Creating an onboarding view}
5216
+ *
4894
5217
  * @param {AdaptyOnboarding} onboarding - onboarding that you want to present.
5218
+ * @param {CreateOnboardingViewParamsInput | undefined} [params] - additional params.
4895
5219
  * @returns {Promise<OnboardingViewController>} ViewController — A promise that resolves to a ViewController instance.
5220
+ *
5221
+ * @example
5222
+ * ```ts
5223
+ * const onboarding = await adapty.getOnboarding({ placementId: 'MY_PLACEMENT' });
5224
+ * const view = await createOnboardingView(onboarding);
5225
+ * view.present();
5226
+ * ```
5227
+ *
5228
+ * @example
5229
+ * ```ts
5230
+ * const view = await createOnboardingView(onboarding, {
5231
+ * externalUrlsPresentation: WebPresentation.BrowserOutApp
5232
+ * });
5233
+ * ```
5234
+ *
5235
+ * @throws {AdaptyError} — If onboarding is not found,
5236
+ * does not have a no-code view configured
5237
+ * or if there is an error while creating a view.
4896
5238
  */
4897
- async function createOnboardingView(onboarding) {
4898
- const controller = await OnboardingViewController.create(onboarding, adaptyPlugin);
5239
+ async function createOnboardingView(onboarding, params = {}) {
5240
+ const controller = await OnboardingViewController.create(onboarding, adaptyPlugin, params);
4899
5241
  return controller;
4900
5242
  }
4901
5243
 
@@ -4932,10 +5274,12 @@ var capacitorAdaptyCapacitorPlugin = (function (exports, core) {
4932
5274
  exports.LogLevel = LogLevel;
4933
5275
  exports.OfferType = OfferType;
4934
5276
  exports.OnboardingViewController = OnboardingViewController;
5277
+ exports.PaywallEventId = PaywallEventId;
4935
5278
  exports.PaywallViewController = PaywallViewController;
4936
5279
  exports.ProductPeriod = ProductPeriod;
4937
5280
  exports.RefundPreference = RefundPreference;
4938
5281
  exports.VendorStore = VendorStore;
5282
+ exports.WebPresentation = WebPresentation;
4939
5283
  exports.adapty = adapty;
4940
5284
  exports.consoleLogSink = consoleLogSink;
4941
5285
  exports.createOnboardingView = createOnboardingView;