@adapty/capacitor 3.12.0-beta.1 → 3.15.1

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