@adapty/capacitor 3.16.0 → 3.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AdaptyCapacitor.podspec +3 -3
- package/Package.swift +1 -1
- package/README.md +1 -1
- package/dist/esm/adapters.d.ts +16 -0
- package/dist/esm/adapters.js +31 -0
- package/dist/esm/adapters.js.map +1 -0
- package/dist/esm/adapty-emitter.js +2 -2
- package/dist/esm/adapty-emitter.js.map +1 -1
- package/dist/esm/adapty.d.ts +8 -6
- package/dist/esm/adapty.js +40 -78
- package/dist/esm/adapty.js.map +1 -1
- package/dist/esm/coders/factory.d.ts +6 -0
- package/dist/esm/coders/factory.js +11 -0
- package/dist/esm/coders/factory.js.map +1 -0
- package/dist/esm/coders/parse-onboarding.d.ts +3 -0
- package/dist/esm/coders/parse-onboarding.js +4 -0
- package/dist/esm/coders/parse-onboarding.js.map +1 -0
- package/dist/esm/coders/parse-paywall.d.ts +3 -0
- package/dist/esm/coders/parse-paywall.js +4 -0
- package/dist/esm/coders/parse-paywall.js.map +1 -0
- package/dist/esm/coders/parse.d.ts +5 -0
- package/dist/esm/coders/parse.js +5 -0
- package/dist/esm/coders/parse.js.map +1 -0
- package/dist/esm/default-configs.js +1 -1
- package/dist/esm/default-configs.js.map +1 -1
- package/dist/esm/index.d.ts +5 -7
- package/dist/esm/index.js +3 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/logger/index.d.ts +2 -0
- package/dist/esm/logger/index.js +2 -0
- package/dist/esm/logger/index.js.map +1 -0
- package/dist/esm/types/adapty-plugin.d.ts +4 -4
- package/dist/esm/types/adapty-plugin.js.map +1 -1
- package/dist/esm/types/configs.d.ts +2 -2
- package/dist/esm/types/configs.js.map +1 -1
- package/dist/esm/types/index.d.ts +5 -0
- package/dist/esm/types/index.js +6 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/inputs.d.ts +1 -0
- package/dist/esm/types/inputs.js +2 -0
- package/dist/esm/types/inputs.js.map +1 -0
- package/dist/esm/types/method-types.d.ts +1 -0
- package/dist/esm/types/method-types.js +2 -0
- package/dist/esm/types/method-types.js.map +1 -0
- package/dist/esm/types/onboarding-events.d.ts +1 -0
- package/dist/esm/types/onboarding-events.js +2 -0
- package/dist/esm/types/onboarding-events.js.map +1 -0
- package/dist/esm/types/paywall-events.d.ts +1 -0
- package/dist/esm/types/paywall-events.js +2 -0
- package/dist/esm/types/paywall-events.js.map +1 -0
- package/dist/esm/ui-builder/base-view-emitter.d.ts +1 -1
- package/dist/esm/ui-builder/base-view-emitter.js +1 -1
- package/dist/esm/ui-builder/base-view-emitter.js.map +1 -1
- package/dist/esm/ui-builder/create-onboarding-view.d.ts +1 -1
- package/dist/esm/ui-builder/create-onboarding-view.js.map +1 -1
- package/dist/esm/ui-builder/create-paywall-view.d.ts +1 -1
- package/dist/esm/ui-builder/create-paywall-view.js.map +1 -1
- package/dist/esm/ui-builder/onboarding-view-controller.d.ts +1 -1
- package/dist/esm/ui-builder/onboarding-view-controller.js +7 -9
- package/dist/esm/ui-builder/onboarding-view-controller.js.map +1 -1
- package/dist/esm/ui-builder/onboarding-view-emitter.d.ts +2 -2
- package/dist/esm/ui-builder/onboarding-view-emitter.js +2 -2
- package/dist/esm/ui-builder/onboarding-view-emitter.js.map +1 -1
- package/dist/esm/ui-builder/paywall-view-controller.d.ts +1 -1
- package/dist/esm/ui-builder/paywall-view-controller.js +6 -8
- package/dist/esm/ui-builder/paywall-view-controller.js.map +1 -1
- package/dist/esm/ui-builder/paywall-view-emitter.d.ts +2 -2
- package/dist/esm/ui-builder/paywall-view-emitter.js +2 -2
- package/dist/esm/ui-builder/paywall-view-emitter.js.map +1 -1
- package/dist/esm/ui-builder/types.d.ts +3 -3
- package/dist/esm/ui-builder/types.js +1 -1
- package/dist/esm/ui-builder/types.js.map +1 -1
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/plugin.cjs.js +2882 -2777
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +5321 -5216
- package/dist/plugin.js.map +1 -1
- package/package.json +13 -7
- package/dist/esm/coder-registry.d.ts +0 -27
- package/dist/esm/coder-registry.js +0 -25
- package/dist/esm/coder-registry.js.map +0 -1
- package/dist/esm/shared/adapty-error.d.ts +0 -19
- package/dist/esm/shared/adapty-error.js +0 -46
- package/dist/esm/shared/adapty-error.js.map +0 -1
- package/dist/esm/shared/coders/adapty-access-level.d.ts +0 -10
- package/dist/esm/shared/coders/adapty-access-level.js +0 -113
- package/dist/esm/shared/coders/adapty-access-level.js.map +0 -1
- package/dist/esm/shared/coders/adapty-configuration.d.ts +0 -8
- package/dist/esm/shared/coders/adapty-configuration.js +0 -68
- package/dist/esm/shared/coders/adapty-configuration.js.map +0 -1
- package/dist/esm/shared/coders/adapty-discount-phase.d.ts +0 -10
- package/dist/esm/shared/coders/adapty-discount-phase.js +0 -39
- package/dist/esm/shared/coders/adapty-discount-phase.js.map +0 -1
- package/dist/esm/shared/coders/adapty-identify-params.d.ts +0 -11
- package/dist/esm/shared/coders/adapty-identify-params.js +0 -19
- package/dist/esm/shared/coders/adapty-identify-params.js.map +0 -1
- package/dist/esm/shared/coders/adapty-installation-details.d.ts +0 -7
- package/dist/esm/shared/coders/adapty-installation-details.js +0 -25
- package/dist/esm/shared/coders/adapty-installation-details.js.map +0 -1
- package/dist/esm/shared/coders/adapty-installation-status.d.ts +0 -7
- package/dist/esm/shared/coders/adapty-installation-status.js +0 -42
- package/dist/esm/shared/coders/adapty-installation-status.js.map +0 -1
- package/dist/esm/shared/coders/adapty-native-error.d.ts +0 -14
- package/dist/esm/shared/coders/adapty-native-error.js +0 -21
- package/dist/esm/shared/coders/adapty-native-error.js.map +0 -1
- package/dist/esm/shared/coders/adapty-non-subscription.d.ts +0 -10
- package/dist/esm/shared/coders/adapty-non-subscription.js +0 -31
- package/dist/esm/shared/coders/adapty-non-subscription.js.map +0 -1
- package/dist/esm/shared/coders/adapty-onboarding-builder.d.ts +0 -10
- package/dist/esm/shared/coders/adapty-onboarding-builder.js +0 -14
- package/dist/esm/shared/coders/adapty-onboarding-builder.js.map +0 -1
- package/dist/esm/shared/coders/adapty-onboarding.d.ts +0 -13
- package/dist/esm/shared/coders/adapty-onboarding.js +0 -55
- package/dist/esm/shared/coders/adapty-onboarding.js.map +0 -1
- package/dist/esm/shared/coders/adapty-paywall-builder.d.ts +0 -10
- package/dist/esm/shared/coders/adapty-paywall-builder.js +0 -19
- package/dist/esm/shared/coders/adapty-paywall-builder.js.map +0 -1
- package/dist/esm/shared/coders/adapty-paywall-product.d.ts +0 -11
- package/dist/esm/shared/coders/adapty-paywall-product.js +0 -94
- package/dist/esm/shared/coders/adapty-paywall-product.js.map +0 -1
- package/dist/esm/shared/coders/adapty-paywall.d.ts +0 -13
- package/dist/esm/shared/coders/adapty-paywall.js +0 -75
- package/dist/esm/shared/coders/adapty-paywall.js.map +0 -1
- package/dist/esm/shared/coders/adapty-placement.d.ts +0 -10
- package/dist/esm/shared/coders/adapty-placement.js +0 -23
- package/dist/esm/shared/coders/adapty-placement.js.map +0 -1
- package/dist/esm/shared/coders/adapty-price.d.ts +0 -10
- package/dist/esm/shared/coders/adapty-price.js +0 -29
- package/dist/esm/shared/coders/adapty-price.js.map +0 -1
- package/dist/esm/shared/coders/adapty-profile-parameters.d.ts +0 -10
- package/dist/esm/shared/coders/adapty-profile-parameters.js +0 -30
- package/dist/esm/shared/coders/adapty-profile-parameters.js.map +0 -1
- package/dist/esm/shared/coders/adapty-profile.d.ts +0 -10
- package/dist/esm/shared/coders/adapty-profile.js +0 -47
- package/dist/esm/shared/coders/adapty-profile.js.map +0 -1
- package/dist/esm/shared/coders/adapty-purchase-params.d.ts +0 -7
- package/dist/esm/shared/coders/adapty-purchase-params.js +0 -37
- package/dist/esm/shared/coders/adapty-purchase-params.js.map +0 -1
- package/dist/esm/shared/coders/adapty-purchase-result.d.ts +0 -12
- package/dist/esm/shared/coders/adapty-purchase-result.js +0 -54
- package/dist/esm/shared/coders/adapty-purchase-result.js.map +0 -1
- package/dist/esm/shared/coders/adapty-remote-config.d.ts +0 -13
- package/dist/esm/shared/coders/adapty-remote-config.js +0 -41
- package/dist/esm/shared/coders/adapty-remote-config.js.map +0 -1
- package/dist/esm/shared/coders/adapty-subscription-details.d.ts +0 -11
- package/dist/esm/shared/coders/adapty-subscription-details.js +0 -64
- package/dist/esm/shared/coders/adapty-subscription-details.js.map +0 -1
- package/dist/esm/shared/coders/adapty-subscription-offer-identifier.d.ts +0 -10
- package/dist/esm/shared/coders/adapty-subscription-offer-identifier.js +0 -19
- package/dist/esm/shared/coders/adapty-subscription-offer-identifier.js.map +0 -1
- package/dist/esm/shared/coders/adapty-subscription-offer.d.ts +0 -11
- package/dist/esm/shared/coders/adapty-subscription-offer.js +0 -50
- package/dist/esm/shared/coders/adapty-subscription-offer.js.map +0 -1
- package/dist/esm/shared/coders/adapty-subscription-period.d.ts +0 -10
- package/dist/esm/shared/coders/adapty-subscription-period.js +0 -11
- package/dist/esm/shared/coders/adapty-subscription-period.js.map +0 -1
- package/dist/esm/shared/coders/adapty-subscription.d.ts +0 -10
- package/dist/esm/shared/coders/adapty-subscription.js +0 -116
- package/dist/esm/shared/coders/adapty-subscription.js.map +0 -1
- package/dist/esm/shared/coders/adapty-ui-create-onboarding-view-params.d.ts +0 -8
- package/dist/esm/shared/coders/adapty-ui-create-onboarding-view-params.js +0 -10
- package/dist/esm/shared/coders/adapty-ui-create-onboarding-view-params.js.map +0 -1
- package/dist/esm/shared/coders/adapty-ui-create-paywall-view-params.d.ts +0 -18
- package/dist/esm/shared/coders/adapty-ui-create-paywall-view-params.js +0 -142
- package/dist/esm/shared/coders/adapty-ui-create-paywall-view-params.js.map +0 -1
- package/dist/esm/shared/coders/adapty-ui-media-cache.d.ts +0 -10
- package/dist/esm/shared/coders/adapty-ui-media-cache.js +0 -24
- package/dist/esm/shared/coders/adapty-ui-media-cache.js.map +0 -1
- package/dist/esm/shared/coders/adapty-ui-onboarding-meta.d.ts +0 -10
- package/dist/esm/shared/coders/adapty-ui-onboarding-meta.js +0 -29
- package/dist/esm/shared/coders/adapty-ui-onboarding-meta.js.map +0 -1
- package/dist/esm/shared/coders/adapty-ui-onboarding-state-params.d.ts +0 -10
- package/dist/esm/shared/coders/adapty-ui-onboarding-state-params.js +0 -24
- package/dist/esm/shared/coders/adapty-ui-onboarding-state-params.js.map +0 -1
- package/dist/esm/shared/coders/adapty-ui-onboarding-state-updated-action.d.ts +0 -14
- package/dist/esm/shared/coders/adapty-ui-onboarding-state-updated-action.js +0 -55
- package/dist/esm/shared/coders/adapty-ui-onboarding-state-updated-action.js.map +0 -1
- package/dist/esm/shared/coders/array.d.ts +0 -15
- package/dist/esm/shared/coders/array.js +0 -34
- package/dist/esm/shared/coders/array.js.map +0 -1
- package/dist/esm/shared/coders/bridge-error.d.ts +0 -13
- package/dist/esm/shared/coders/bridge-error.js +0 -78
- package/dist/esm/shared/coders/bridge-error.js.map +0 -1
- package/dist/esm/shared/coders/coder.d.ts +0 -13
- package/dist/esm/shared/coders/coder.js +0 -118
- package/dist/esm/shared/coders/coder.js.map +0 -1
- package/dist/esm/shared/coders/date.d.ts +0 -9
- package/dist/esm/shared/coders/date.js +0 -36
- package/dist/esm/shared/coders/date.js.map +0 -1
- package/dist/esm/shared/coders/error-coder.d.ts +0 -6
- package/dist/esm/shared/coders/error-coder.js +0 -2
- package/dist/esm/shared/coders/error-coder.js.map +0 -1
- package/dist/esm/shared/coders/hashmap.d.ts +0 -7
- package/dist/esm/shared/coders/hashmap.js +0 -25
- package/dist/esm/shared/coders/hashmap.js.map +0 -1
- package/dist/esm/shared/coders/json.d.ts +0 -8
- package/dist/esm/shared/coders/json.js +0 -15
- package/dist/esm/shared/coders/json.js.map +0 -1
- package/dist/esm/shared/coders/parse-onboarding.d.ts +0 -3
- package/dist/esm/shared/coders/parse-onboarding.js +0 -86
- package/dist/esm/shared/coders/parse-onboarding.js.map +0 -1
- package/dist/esm/shared/coders/parse-paywall.d.ts +0 -4
- package/dist/esm/shared/coders/parse-paywall.js +0 -141
- package/dist/esm/shared/coders/parse-paywall.js.map +0 -1
- package/dist/esm/shared/coders/parse.d.ts +0 -6
- package/dist/esm/shared/coders/parse.js +0 -135
- package/dist/esm/shared/coders/parse.js.map +0 -1
- package/dist/esm/shared/coders/product-reference.d.ts +0 -10
- package/dist/esm/shared/coders/product-reference.js +0 -53
- package/dist/esm/shared/coders/product-reference.js.map +0 -1
- package/dist/esm/shared/coders/types.d.ts +0 -23
- package/dist/esm/shared/coders/types.js +0 -2
- package/dist/esm/shared/coders/types.js.map +0 -1
- package/dist/esm/shared/coders/utils.d.ts +0 -18
- package/dist/esm/shared/coders/utils.js +0 -50
- package/dist/esm/shared/coders/utils.js.map +0 -1
- package/dist/esm/shared/constants.d.ts +0 -42
- package/dist/esm/shared/constants.js +0 -37
- package/dist/esm/shared/constants.js.map +0 -1
- package/dist/esm/shared/index.d.ts +0 -3
- package/dist/esm/shared/index.js +0 -4
- package/dist/esm/shared/index.js.map +0 -1
- package/dist/esm/shared/logger/console-sink.d.ts +0 -2
- package/dist/esm/shared/logger/console-sink.js +0 -23
- package/dist/esm/shared/logger/console-sink.js.map +0 -1
- package/dist/esm/shared/logger/index.d.ts +0 -5
- package/dist/esm/shared/logger/index.js +0 -5
- package/dist/esm/shared/logger/index.js.map +0 -1
- package/dist/esm/shared/logger/log-context.d.ts +0 -23
- package/dist/esm/shared/logger/log-context.js +0 -61
- package/dist/esm/shared/logger/log-context.js.map +0 -1
- package/dist/esm/shared/logger/log-scope.d.ts +0 -25
- package/dist/esm/shared/logger/log-scope.js +0 -26
- package/dist/esm/shared/logger/log-scope.js.map +0 -1
- package/dist/esm/shared/logger/log.d.ts +0 -34
- package/dist/esm/shared/logger/log.js +0 -110
- package/dist/esm/shared/logger/log.js.map +0 -1
- package/dist/esm/shared/logger/types.d.ts +0 -20
- package/dist/esm/shared/logger/types.js +0 -2
- package/dist/esm/shared/logger/types.js.map +0 -1
- package/dist/esm/shared/types/bridge.d.ts +0 -50
- package/dist/esm/shared/types/bridge.js +0 -78
- package/dist/esm/shared/types/bridge.js.map +0 -1
- package/dist/esm/shared/types/error.d.ts +0 -325
- package/dist/esm/shared/types/error.js +0 -176
- package/dist/esm/shared/types/error.js.map +0 -1
- package/dist/esm/shared/types/index.d.ts +0 -718
- package/dist/esm/shared/types/index.js +0 -14
- package/dist/esm/shared/types/index.js.map +0 -1
- package/dist/esm/shared/types/inputs.d.ts +0 -238
- package/dist/esm/shared/types/inputs.js +0 -42
- package/dist/esm/shared/types/inputs.js.map +0 -1
- package/dist/esm/shared/types/method-types.d.ts +0 -86
- package/dist/esm/shared/types/method-types.js +0 -13
- package/dist/esm/shared/types/method-types.js.map +0 -1
- package/dist/esm/shared/types/onboarding-events.d.ts +0 -60
- package/dist/esm/shared/types/onboarding-events.js +0 -11
- package/dist/esm/shared/types/onboarding-events.js.map +0 -1
- package/dist/esm/shared/types/paywall-events.d.ts +0 -84
- package/dist/esm/shared/types/paywall-events.js +0 -16
- package/dist/esm/shared/types/paywall-events.js.map +0 -1
- package/dist/esm/shared/utils/compact-object.d.ts +0 -6
- package/dist/esm/shared/utils/compact-object.js +0 -9
- package/dist/esm/shared/utils/compact-object.js.map +0 -1
- package/dist/esm/shared/utils/map-values.d.ts +0 -8
- package/dist/esm/shared/utils/map-values.js +0 -11
- package/dist/esm/shared/utils/map-values.js.map +0 -1
- package/dist/esm/shared/utils/merge-options.d.ts +0 -7
- package/dist/esm/shared/utils/merge-options.js +0 -93
- package/dist/esm/shared/utils/merge-options.js.map +0 -1
- package/dist/esm/shared/utils/platform.d.ts +0 -2
- package/dist/esm/shared/utils/platform.js +0 -5
- package/dist/esm/shared/utils/platform.js.map +0 -1
- package/dist/esm/shared/utils/with-error-context.d.ts +0 -7
- package/dist/esm/shared/utils/with-error-context.js +0 -33
- package/dist/esm/shared/utils/with-error-context.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configs.js","sourceRoot":"","sources":["../../../src/types/configs.ts"],"names":[],"mappings":"","sourcesContent":["import type { AdaptyPaywallProduct } from '
|
|
1
|
+
{"version":3,"file":"configs.js","sourceRoot":"","sources":["../../../src/types/configs.ts"],"names":[],"mappings":"","sourcesContent":["import type { AdaptyPaywallProduct } from './index';\nimport type {\n GetPlacementParamsInput,\n GetPlacementForDefaultAudienceParamsInput,\n MakePurchaseParamsInput,\n} from './inputs';\n\n/**\n * Describes the options for the `getPaywall` method.\n * @public\n */\nexport interface GetPaywallOptions {\n placementId: string;\n locale?: string;\n params?: GetPlacementParamsInput;\n}\n\n/**\n * Describes the options for the `getPaywallForDefaultAudience` method.\n * @public\n */\nexport interface GetPaywallForDefaultAudienceOptions {\n placementId: string;\n locale?: string;\n params?: GetPlacementForDefaultAudienceParamsInput;\n}\n\n/**\n * Describes the options for the `getOnboarding` method.\n * @public\n */\nexport interface GetOnboardingOptions {\n placementId: string;\n locale?: string;\n params?: GetPlacementParamsInput;\n}\n\n/**\n * Describes the options for the `getOnboardingForDefaultAudience` method.\n * @public\n */\nexport interface GetOnboardingForDefaultAudienceOptions {\n placementId: string;\n locale?: string;\n // Keep same input shape as RN: allow loadTimeoutMs even though it is not used by schema\n params?: GetPlacementParamsInput;\n}\n\n/**\n * Describes the options for the `makePurchase` method.\n * @public\n */\nexport interface MakePurchaseOptions {\n product: AdaptyPaywallProduct;\n params?: MakePurchaseParamsInput;\n}\n\n/**\n * Describes the options for the Adapty constructor.\n * @public\n */\nexport interface AdaptyDefaultOptions {\n /**\n * Default options for the `getPaywall` method.\n */\n get_paywall: {\n params: Required<GetPlacementParamsInput>;\n };\n /**\n * Default options for the `getPaywallForDefaultAudience` method.\n */\n get_paywall_for_default_audience: {\n params: GetPlacementForDefaultAudienceParamsInput;\n };\n /**\n * Default options for the `getOnboarding` method.\n */\n get_onboarding: {\n params: Required<GetPlacementParamsInput>;\n };\n /**\n * Default options for the `getOnboardingForDefaultAudience` method.\n * Keep parity with RN by using `GetPlacementParamsInput`.\n */\n get_onboarding_for_default_audience: {\n params: GetPlacementParamsInput;\n };\n}\n\n/**\n * Merged type that combines GetPaywallOptions with required params from AdaptyDefaultOptions\n * @public\n */\nexport type GetPaywallOptionsWithDefaults = AdaptyDefaultOptions['get_paywall'] & GetPaywallOptions;\n\n/**\n * Merged type that combines GetPaywallForDefaultAudienceOptions with required params from AdaptyDefaultOptions\n * @public\n */\nexport type GetPaywallForDefaultAudienceOptionsWithDefaults = AdaptyDefaultOptions['get_paywall_for_default_audience'] &\n GetPaywallForDefaultAudienceOptions;\n\n/**\n * Merged type for `getOnboarding` with defaults\n * @public\n */\nexport type GetOnboardingOptionsWithDefaults = AdaptyDefaultOptions['get_onboarding'] & GetOnboardingOptions;\n\n/**\n * Merged type for `getOnboardingForDefaultAudience` with defaults\n * @public\n */\nexport type GetOnboardingForDefaultAudienceOptionsWithDefaults =\n AdaptyDefaultOptions['get_onboarding_for_default_audience'] & GetOnboardingForDefaultAudienceOptions;\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { AdaptyPrice, AdaptyPaywall, AdaptyOnboarding, AdaptyPlacement, AdaptyRemoteConfig, AdaptyPaywallBuilder, AdaptyOnboardingBuilder, AdaptyPurchaseResult, AdaptyProfile, AdaptyAccessLevel, AdaptyNonSubscription, AdaptySubscription, AdaptyPaywallProduct, AdaptySubscriptionDetails, AdaptySubscriptionOffer, AdaptySubscriptionOfferId, AdaptyDiscountPhase, AdaptySubscriptionPeriod, AdaptyProfileParameters, ProductReference, AdaptyProductIdentifier, AdaptyInstallationStatus, AdaptyInstallationDetails, } from '@adapty/core';
|
|
2
|
+
export { WebPresentation, RefundPreference, VendorStore, OfferType, CancellationReason, Gender, AppTrackingTransparencyStatus, ProductPeriod, ErrorCode, ErrorCodeName, getErrorCode, getErrorPrompt, } from '@adapty/core';
|
|
3
|
+
export * from './inputs';
|
|
4
|
+
export * from './paywall-events';
|
|
5
|
+
export * from './onboarding-events';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { WebPresentation, RefundPreference, VendorStore, OfferType, CancellationReason, Gender, AppTrackingTransparencyStatus, ProductPeriod, ErrorCode, ErrorCodeName, getErrorCode, getErrorPrompt, } from '@adapty/core';
|
|
2
|
+
// Re-export local modules that are NOT in core
|
|
3
|
+
export * from './inputs';
|
|
4
|
+
export * from './paywall-events';
|
|
5
|
+
export * from './onboarding-events';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AA2BA,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,kBAAkB,EAClB,MAAM,EACN,6BAA6B,EAC7B,aAAa,EACb,SAAS,EACT,aAAa,EACb,YAAY,EACZ,cAAc,GACf,MAAM,cAAc,CAAC;AAEtB,+CAA+C;AAC/C,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC","sourcesContent":["// Re-export all model types from @adapty/core\nexport type {\n AdaptyPrice,\n AdaptyPaywall,\n AdaptyOnboarding,\n AdaptyPlacement,\n AdaptyRemoteConfig,\n AdaptyPaywallBuilder,\n AdaptyOnboardingBuilder,\n AdaptyPurchaseResult,\n AdaptyProfile,\n AdaptyAccessLevel,\n AdaptyNonSubscription,\n AdaptySubscription,\n AdaptyPaywallProduct,\n AdaptySubscriptionDetails,\n AdaptySubscriptionOffer,\n AdaptySubscriptionOfferId,\n AdaptyDiscountPhase,\n AdaptySubscriptionPeriod,\n AdaptyProfileParameters,\n ProductReference,\n AdaptyProductIdentifier,\n AdaptyInstallationStatus,\n AdaptyInstallationDetails,\n} from '@adapty/core';\n\nexport {\n WebPresentation,\n RefundPreference,\n VendorStore,\n OfferType,\n CancellationReason,\n Gender,\n AppTrackingTransparencyStatus,\n ProductPeriod,\n ErrorCode,\n ErrorCodeName,\n getErrorCode,\n getErrorPrompt,\n} from '@adapty/core';\n\n// Re-export local modules that are NOT in core\nexport * from './inputs';\nexport * from './paywall-events';\nexport * from './onboarding-events';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LogLevel, FetchPolicy, AdaptyAndroidSubscriptionUpdateReplacementMode, type ActivateParamsInput, type IdentifyParamsInput, type MakePurchaseParamsInput, type AdaptyAndroidSubscriptionUpdateParameters, type AdaptyAndroidPurchaseParams, type GetPlacementParamsInput, type GetPlacementForDefaultAudienceParamsInput, type GetPaywallProductsParamsInput, type FileLocation, } from '@adapty/core';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputs.js","sourceRoot":"","sources":["../../../src/types/inputs.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,EACX,8CAA8C,GAU/C,MAAM,cAAc,CAAC","sourcesContent":["export {\n LogLevel,\n FetchPolicy,\n AdaptyAndroidSubscriptionUpdateReplacementMode,\n type ActivateParamsInput,\n type IdentifyParamsInput,\n type MakePurchaseParamsInput,\n type AdaptyAndroidSubscriptionUpdateParameters,\n type AdaptyAndroidPurchaseParams,\n type GetPlacementParamsInput,\n type GetPlacementForDefaultAudienceParamsInput,\n type GetPaywallProductsParamsInput,\n type FileLocation,\n} from '@adapty/core';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { MethodName } from '@adapty/core';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"method-types.js","sourceRoot":"","sources":["../../../src/types/method-types.ts"],"names":[],"mappings":"","sourcesContent":["// Re-export method name types from @adapty/core\nexport type { MethodName } from '@adapty/core';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OnboardingEventId, type OnboardingEventIdType, type OnboardingEventView, type ParsedOnboardingEvent, type OnboardingCloseEvent, type OnboardingCustomEvent, type OnboardingPaywallEvent, type OnboardingStateUpdatedEvent, type OnboardingFinishedLoadingEvent, type OnboardingAnalyticsEvent, type OnboardingErrorEvent, } from '@adapty/core';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onboarding-events.js","sourceRoot":"","sources":["../../../src/types/onboarding-events.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAWlB,MAAM,cAAc,CAAC","sourcesContent":["export {\n OnboardingEventId,\n type OnboardingEventIdType,\n type OnboardingEventView,\n type ParsedOnboardingEvent,\n type OnboardingCloseEvent,\n type OnboardingCustomEvent,\n type OnboardingPaywallEvent,\n type OnboardingStateUpdatedEvent,\n type OnboardingFinishedLoadingEvent,\n type OnboardingAnalyticsEvent,\n type OnboardingErrorEvent,\n} from '@adapty/core';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PaywallEventId, type PaywallEventIdType, type PaywallEventView, type ParsedPaywallEvent, type PaywallDidAppearEvent, type PaywallDidDisappearEvent, type PaywallDidPerformActionEvent, type PaywallDidSelectProductEvent, type PaywallDidStartPurchaseEvent, type PaywallDidFinishPurchaseEvent, type PaywallDidFailPurchaseEvent, type PaywallDidStartRestoreEvent, type PaywallDidFinishRestoreEvent, type PaywallDidFailRestoreEvent, type PaywallDidFailRenderingEvent, type PaywallDidFailLoadingProductsEvent, type PaywallDidFinishWebPaymentNavigationEvent, } from '@adapty/core';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paywall-events.js","sourceRoot":"","sources":["../../../src/types/paywall-events.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,GAiBf,MAAM,cAAc,CAAC","sourcesContent":["export {\n PaywallEventId,\n type PaywallEventIdType,\n type PaywallEventView,\n type ParsedPaywallEvent,\n type PaywallDidAppearEvent,\n type PaywallDidDisappearEvent,\n type PaywallDidPerformActionEvent,\n type PaywallDidSelectProductEvent,\n type PaywallDidStartPurchaseEvent,\n type PaywallDidFinishPurchaseEvent,\n type PaywallDidFailPurchaseEvent,\n type PaywallDidStartRestoreEvent,\n type PaywallDidFinishRestoreEvent,\n type PaywallDidFailRestoreEvent,\n type PaywallDidFailRenderingEvent,\n type PaywallDidFailLoadingProductsEvent,\n type PaywallDidFinishWebPaymentNavigationEvent,\n} from '@adapty/core';\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AdaptyCapacitorPlugin } from '../bridge/plugin';
|
|
2
|
-
import { LogContext } from '../
|
|
2
|
+
import { LogContext } from '../logger';
|
|
3
3
|
/**
|
|
4
4
|
* Base class for view event emitters that manages common event handling logic.
|
|
5
5
|
* Each event type can have only one handler - new handlers replace existing ones.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-view-emitter.js","sourceRoot":"","sources":["../../../src/ui-builder/base-view-emitter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAW9C;;;GAGG;AACH,MAAM,OAAgB,eAAe;IAUnC,YAAY,MAAc;QAJhB,mBAAc,GAA4C,IAAI,GAAG,EAAE,CAAC;QACpE,aAAQ,GAAiF,IAAI,GAAG,EAAE,CAAC;QACnG,qBAAgB,GAAwE,IAAI,GAAG,EAAE,CAAC;QAG1G,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAmCM,KAAK,CAAC,WAAW,CACtB,KAA2B,EAC3B,QAA8C,EAC9C,cAAmC;QAEnC,MAAM,WAAW,GAAG,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;QACzD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,8CAA8C,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACjF,CAAC;QAED,+CAA+C;QAC/C,IAAI,CA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,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;YACnE,IAAI,mBAAmB,EAAE,CAAC;gBACxB,IAAI,CAAC;oBACH,mBAAmB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;gBACzC,CAAC;gBAAC,OAAO,KAAc,EAAE,CAAC;oBACxB,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;gBAChF,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;QACnD,OAAO,YAAY,CAAC;IACtB,CAAC;IAEO,KAAK,CAAC,yBAAyB,CAAC,WAAyB;QAC/D,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACtD,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;QAC7D,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,mCAAmC,WAAW,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nimport { AdaptyCapacitorPlugin } from '../bridge/plugin';\nimport { LogContext } from '../shared/logger';\n\nexport interface CapacitorEventArg {\n data: string; // JSON string from native\n}\n\nexport interface HandlerData<THandler> {\n handler: THandler;\n onRequestClose: () => Promise<void>;\n}\n\n/**\n * Base class for view event emitters that manages common event handling logic.\n * Each event type can have only one handler - new handlers replace existing ones.\n */\nexport abstract class BaseViewEmitter<\n TEventHandlers extends Record<string, any>,\n TEventData,\n TNativeEvent extends string = string,\n> {\n protected viewId: string;\n protected eventListeners: Map<TNativeEvent, PluginListenerHandle> = new Map();\n protected handlers: Map<keyof TEventHandlers, HandlerData<TEventHandlers[keyof TEventHandlers]>> = new Map();\n protected internalHandlers: Map<keyof TEventHandlers, { handler: (event: TEventData) => void }> = new Map();\n\n constructor(viewId: string) {\n this.viewId = viewId;\n }\n\n /**\n * Abstract method to parse event data from JSON string\n */\n protected abstract parseEventData(rawEventData: string, ctx: LogContext): TEventData;\n\n /**\n * Abstract method to get native event name for handler\n */\n protected abstract getNativeEventForHandler(event: keyof TEventHandlers): TNativeEvent | null;\n\n /**\n * Resolves handler name for incoming native event based on parsed data\n */\n protected abstract getHandlerForNativeEvent(\n nativeEvent: TNativeEvent,\n eventData: TEventData,\n ): keyof TEventHandlers | null;\n\n /**\n * Abstract method to extract callback arguments for a specific handler\n */\n protected abstract extractCallbackArgs(handlerName: keyof TEventHandlers, eventData: TEventData): unknown[];\n\n /**\n * Abstract method to get view ID from parsed event data\n */\n protected abstract getEventViewId(eventData: TEventData): string | null;\n\n /**\n * Abstract method to get emitter name for error messages\n */\n protected abstract getEmitterName(): string;\n\n public async addListener(\n event: keyof TEventHandlers,\n callback: TEventHandlers[keyof TEventHandlers],\n onRequestClose: () => Promise<void>,\n ): Promise<PluginListenerHandle> {\n const nativeEvent = this.getNativeEventForHandler(event);\n if (!nativeEvent) {\n throw new Error(`No native event mapping found for handler: ${String(event)}`);\n }\n\n // Replace existing handler for this event type\n this.handlers.set(event, {\n handler: callback,\n onRequestClose,\n });\n\n return await this.getOrCreateNativeListener(nativeEvent);\n }\n\n public async addInternalListener(\n event: keyof TEventHandlers,\n callback: (event: TEventData) => void,\n ): Promise<PluginListenerHandle> {\n const nativeEvent = this.getNativeEventForHandler(event);\n if (!nativeEvent) {\n throw new Error(`No native event mapping found for handler: ${String(event)}`);\n }\n\n this.internalHandlers.set(event, { handler: callback });\n\n return await this.getOrCreateNativeListener(nativeEvent);\n }\n\n public removeAllListeners(): void {\n this.eventListeners.forEach((subscription) => {\n subscription.remove().catch(() => {\n // intentionally ignore errors during cleanup\n });\n });\n this.eventListeners.clear();\n this.handlers.clear();\n this.internalHandlers.clear();\n }\n\n private async createNativeListener(nativeEvent: TNativeEvent): Promise<PluginListenerHandle> {\n const emitterName = this.getEmitterName();\n const viewId = this.viewId;\n\n const subscription = await AdaptyCapacitorPlugin.addListener(nativeEvent, (arg: CapacitorEventArg) => {\n const ctx = new LogContext();\n const log = ctx.event({ methodName: nativeEvent });\n log.start(() => ({ raw: arg }));\n\n // Strict validation: events must come in {data: \"json_string\"} format\n if (!arg || typeof arg !== 'object' || !arg.data) {\n const error = new Error(\n `[${emitterName}] Invalid event format received. Expected {data: \"json_string\"}, got: ${JSON.stringify(arg)}`,\n );\n log.failed(() => ({ error }));\n throw error;\n }\n\n const rawEventData: string = arg.data;\n\n // Parse JSON string using specific parser with decode logging\n let eventData: TEventData;\n if (typeof rawEventData === 'string') {\n try {\n eventData = this.parseEventData(rawEventData, ctx);\n } catch (error) {\n log.failed(() => ({ error }));\n throw error;\n }\n } else {\n const err = new Error(\n `[${emitterName}] Expected event data to be JSON string, got ${typeof rawEventData}: ${rawEventData}`,\n );\n log.failed(() => ({ error: err }));\n throw err;\n }\n\n const eventViewId = this.getEventViewId(eventData);\n if (viewId !== eventViewId) {\n return;\n }\n\n const handlerName = this.getHandlerForNativeEvent(nativeEvent, eventData);\n if (!handlerName) {\n return;\n }\n\n // 1. Client handler (single)\n const handlerData = this.handlers.get(handlerName);\n if (handlerData) {\n const { handler, onRequestClose } = handlerData;\n const callbackArgs = this.extractCallbackArgs(handlerName, eventData);\n\n const cb = handler as (...args: typeof callbackArgs) => boolean;\n try {\n const shouldClose = cb(...callbackArgs);\n if (shouldClose) {\n onRequestClose().catch((error) => {\n log.failed(() => ({ error, handlerName }));\n });\n }\n log.success(() => ({ message: 'Event handled successfully', handlerName }));\n } catch (error) {\n log.failed(() => ({ error, handlerName }));\n }\n }\n\n // 2. Internal handler\n const internalHandlerData = this.internalHandlers.get(handlerName);\n if (internalHandlerData) {\n try {\n internalHandlerData.handler(eventData);\n } catch (error: unknown) {\n log.failed(() => ({ error, handlerName: `internal:${String(handlerName)}` }));\n }\n }\n });\n\n this.eventListeners.set(nativeEvent, subscription);\n return subscription;\n }\n\n private async getOrCreateNativeListener(nativeEvent: TNativeEvent): Promise<PluginListenerHandle> {\n const existing = this.eventListeners.get(nativeEvent);\n if (existing) {\n return existing;\n }\n\n const created = await this.createNativeListener(nativeEvent);\n if (!created) {\n throw new Error(`Failed to register listener for ${nativeEvent}`);\n }\n return created;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base-view-emitter.js","sourceRoot":"","sources":["../../../src/ui-builder/base-view-emitter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAWvC;;;GAGG;AACH,MAAM,OAAgB,eAAe;IAUnC,YAAY,MAAc;QAJhB,mBAAc,GAA4C,IAAI,GAAG,EAAE,CAAC;QACpE,aAAQ,GAAiF,IAAI,GAAG,EAAE,CAAC;QACnG,qBAAgB,GAAwE,IAAI,GAAG,EAAE,CAAC;QAG1G,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAmCM,KAAK,CAAC,WAAW,CACtB,KAA2B,EAC3B,QAA8C,EAC9C,cAAmC;QAEnC,MAAM,WAAW,GAAG,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;QACzD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,8CAA8C,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACjF,CAAC;QAED,+CAA+C;QAC/C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE;YACvB,OAAO,EAAE,QAAQ;YACjB,cAAc;SACf,CAA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AE,CAAC;gBACxB,IAAI,CAAC;oBACH,mBAAmB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;gBACzC,CAAC;gBAAC,OAAO,KAAc,EAAE,CAAC;oBACxB,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;gBAChF,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;QACnD,OAAO,YAAY,CAAC;IACtB,CAAC;IAEO,KAAK,CAAC,yBAAyB,CAAC,WAAyB;QAC/D,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACtD,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;QAC7D,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,mCAAmC,WAAW,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nimport { AdaptyCapacitorPlugin } from '../bridge/plugin';\nimport { LogContext } from '../logger';\n\nexport interface CapacitorEventArg {\n data: string; // JSON string from native\n}\n\nexport interface HandlerData<THandler> {\n handler: THandler;\n onRequestClose: () => Promise<void>;\n}\n\n/**\n * Base class for view event emitters that manages common event handling logic.\n * Each event type can have only one handler - new handlers replace existing ones.\n */\nexport abstract class BaseViewEmitter<\n TEventHandlers extends Record<string, any>,\n TEventData,\n TNativeEvent extends string = string,\n> {\n protected viewId: string;\n protected eventListeners: Map<TNativeEvent, PluginListenerHandle> = new Map();\n protected handlers: Map<keyof TEventHandlers, HandlerData<TEventHandlers[keyof TEventHandlers]>> = new Map();\n protected internalHandlers: Map<keyof TEventHandlers, { handler: (event: TEventData) => void }> = new Map();\n\n constructor(viewId: string) {\n this.viewId = viewId;\n }\n\n /**\n * Abstract method to parse event data from JSON string\n */\n protected abstract parseEventData(rawEventData: string, ctx: LogContext): TEventData;\n\n /**\n * Abstract method to get native event name for handler\n */\n protected abstract getNativeEventForHandler(event: keyof TEventHandlers): TNativeEvent | null;\n\n /**\n * Resolves handler name for incoming native event based on parsed data\n */\n protected abstract getHandlerForNativeEvent(\n nativeEvent: TNativeEvent,\n eventData: TEventData,\n ): keyof TEventHandlers | null;\n\n /**\n * Abstract method to extract callback arguments for a specific handler\n */\n protected abstract extractCallbackArgs(handlerName: keyof TEventHandlers, eventData: TEventData): unknown[];\n\n /**\n * Abstract method to get view ID from parsed event data\n */\n protected abstract getEventViewId(eventData: TEventData): string | null;\n\n /**\n * Abstract method to get emitter name for error messages\n */\n protected abstract getEmitterName(): string;\n\n public async addListener(\n event: keyof TEventHandlers,\n callback: TEventHandlers[keyof TEventHandlers],\n onRequestClose: () => Promise<void>,\n ): Promise<PluginListenerHandle> {\n const nativeEvent = this.getNativeEventForHandler(event);\n if (!nativeEvent) {\n throw new Error(`No native event mapping found for handler: ${String(event)}`);\n }\n\n // Replace existing handler for this event type\n this.handlers.set(event, {\n handler: callback,\n onRequestClose,\n });\n\n return await this.getOrCreateNativeListener(nativeEvent);\n }\n\n public async addInternalListener(\n event: keyof TEventHandlers,\n callback: (event: TEventData) => void,\n ): Promise<PluginListenerHandle> {\n const nativeEvent = this.getNativeEventForHandler(event);\n if (!nativeEvent) {\n throw new Error(`No native event mapping found for handler: ${String(event)}`);\n }\n\n this.internalHandlers.set(event, { handler: callback });\n\n return await this.getOrCreateNativeListener(nativeEvent);\n }\n\n public removeAllListeners(): void {\n this.eventListeners.forEach((subscription) => {\n subscription.remove().catch(() => {\n // intentionally ignore errors during cleanup\n });\n });\n this.eventListeners.clear();\n this.handlers.clear();\n this.internalHandlers.clear();\n }\n\n private async createNativeListener(nativeEvent: TNativeEvent): Promise<PluginListenerHandle> {\n const emitterName = this.getEmitterName();\n const viewId = this.viewId;\n\n const subscription = await AdaptyCapacitorPlugin.addListener(nativeEvent, (arg: CapacitorEventArg) => {\n const ctx = new LogContext();\n const log = ctx.event({ methodName: nativeEvent });\n log.start(() => ({ raw: arg }));\n\n // Strict validation: events must come in {data: \"json_string\"} format\n if (!arg || typeof arg !== 'object' || !arg.data) {\n const error = new Error(\n `[${emitterName}] Invalid event format received. Expected {data: \"json_string\"}, got: ${JSON.stringify(arg)}`,\n );\n log.failed(() => ({ error }));\n throw error;\n }\n\n const rawEventData: string = arg.data;\n\n // Parse JSON string using specific parser with decode logging\n let eventData: TEventData;\n if (typeof rawEventData === 'string') {\n try {\n eventData = this.parseEventData(rawEventData, ctx);\n } catch (error) {\n log.failed(() => ({ error }));\n throw error;\n }\n } else {\n const err = new Error(\n `[${emitterName}] Expected event data to be JSON string, got ${typeof rawEventData}: ${rawEventData}`,\n );\n log.failed(() => ({ error: err }));\n throw err;\n }\n\n const eventViewId = this.getEventViewId(eventData);\n if (viewId !== eventViewId) {\n return;\n }\n\n const handlerName = this.getHandlerForNativeEvent(nativeEvent, eventData);\n if (!handlerName) {\n return;\n }\n\n // 1. Client handler (single)\n const handlerData = this.handlers.get(handlerName);\n if (handlerData) {\n const { handler, onRequestClose } = handlerData;\n const callbackArgs = this.extractCallbackArgs(handlerName, eventData);\n\n const cb = handler as (...args: typeof callbackArgs) => boolean;\n try {\n const shouldClose = cb(...callbackArgs);\n if (shouldClose) {\n onRequestClose().catch((error) => {\n log.failed(() => ({ error, handlerName }));\n });\n }\n log.success(() => ({ message: 'Event handled successfully', handlerName }));\n } catch (error) {\n log.failed(() => ({ error, handlerName }));\n }\n }\n\n // 2. Internal handler\n const internalHandlerData = this.internalHandlers.get(handlerName);\n if (internalHandlerData) {\n try {\n internalHandlerData.handler(eventData);\n } catch (error: unknown) {\n log.failed(() => ({ error, handlerName: `internal:${String(handlerName)}` }));\n }\n }\n });\n\n this.eventListeners.set(nativeEvent, subscription);\n return subscription;\n }\n\n private async getOrCreateNativeListener(nativeEvent: TNativeEvent): Promise<PluginListenerHandle> {\n const existing = this.eventListeners.get(nativeEvent);\n if (existing) {\n return existing;\n }\n\n const created = await this.createNativeListener(nativeEvent);\n if (!created) {\n throw new Error(`Failed to register listener for ${nativeEvent}`);\n }\n return created;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-onboarding-view.js","sourceRoot":"","sources":["../../../src/ui-builder/create-onboarding-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAGxE,MAAM,YAAY,GAAG,IAAI,MAAM,EAAE,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,UAA4B,EAC5B,SAA0C,EAAE;IAE5C,MAAM,UAAU,GAAG,MAAM,wBAAwB,CAAC,MAAM,CAAC,UAAU,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IAC3F,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { Adapty } from '../adapty';\nimport type { AdaptyOnboarding } from '../
|
|
1
|
+
{"version":3,"file":"create-onboarding-view.js","sourceRoot":"","sources":["../../../src/ui-builder/create-onboarding-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAGxE,MAAM,YAAY,GAAG,IAAI,MAAM,EAAE,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,UAA4B,EAC5B,SAA0C,EAAE;IAE5C,MAAM,UAAU,GAAG,MAAM,wBAAwB,CAAC,MAAM,CAAC,UAAU,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IAC3F,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { Adapty } from '../adapty';\nimport type { AdaptyOnboarding } from '../types';\n\nimport { OnboardingViewController } from './onboarding-view-controller';\nimport type { CreateOnboardingViewParamsInput } from './types';\n\nconst adaptyPlugin = new Adapty();\n\n/**\n * Creates an onboarding view controller.\n * You can use it to further configure a view or present it.\n *\n * @see {@link https://adapty.io/docs/capacitor-get-onboardings | [DOC] Creating an onboarding view}\n *\n * @param {AdaptyOnboarding} onboarding - onboarding that you want to present.\n * @param {CreateOnboardingViewParamsInput | undefined} [params] - additional params.\n * @returns {Promise<OnboardingViewController>} ViewController — A promise that resolves to a ViewController instance.\n *\n * @example\n * ```ts\n * const onboarding = await adapty.getOnboarding({ placementId: 'MY_PLACEMENT' });\n * const view = await createOnboardingView(onboarding);\n * view.present();\n * ```\n *\n * @example\n * ```ts\n * const view = await createOnboardingView(onboarding, {\n * externalUrlsPresentation: WebPresentation.BrowserOutApp\n * });\n * ```\n *\n * @throws {AdaptyError} — If onboarding is not found,\n * does not have a no-code view configured\n * or if there is an error while creating a view.\n */\nexport async function createOnboardingView(\n onboarding: AdaptyOnboarding,\n params: CreateOnboardingViewParamsInput = {},\n): Promise<OnboardingViewController> {\n const controller = await OnboardingViewController.create(onboarding, adaptyPlugin, params);\n return controller;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-paywall-view.js","sourceRoot":"","sources":["../../../src/ui-builder/create-paywall-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAGlE,MAAM,YAAY,GAAG,IAAI,MAAM,EAAE,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAsB,EACtB,SAAuC,EAAE;IAEzC,MAAM,UAAU,GAAG,MAAM,qBAAqB,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;IAErF,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { Adapty } from '../adapty';\nimport type { AdaptyPaywall } from '../
|
|
1
|
+
{"version":3,"file":"create-paywall-view.js","sourceRoot":"","sources":["../../../src/ui-builder/create-paywall-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAGlE,MAAM,YAAY,GAAG,IAAI,MAAM,EAAE,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAsB,EACtB,SAAuC,EAAE;IAEzC,MAAM,UAAU,GAAG,MAAM,qBAAqB,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;IAErF,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { Adapty } from '../adapty';\nimport type { AdaptyPaywall } from '../types';\n\nimport { PaywallViewController } from './paywall-view-controller';\nimport type { CreatePaywallViewParamsInput } from './types';\n\nconst adaptyPlugin = new Adapty();\n\n/**\n * Creates a paywall view controller.\n * You can use it to further configure a view or present it.\n *\n * @see {@link https://adapty.io/docs/capacitor-present-paywalls | [DOC] Creating a paywall view}\n *\n * @param {AdaptyPaywall} paywall - paywall that you want to present.\n * @param {CreatePaywallViewParamsInput | undefined} [params] - additional params.\n * @returns {Promise<PaywallViewController>} ViewController — A promise that resolves to a ViewController instance.\n *\n * @example\n * ```ts\n * const paywall = await adapty.getPaywall(\"MY_PAYWALL\");\n * const view = await createPaywallView(paywall);\n * view.present();\n * ```\n *\n * @throws {AdaptyError} — If paywall is not found,\n * does not have a no-code view configured\n * or if there is an error while creating a view.\n */\nexport async function createPaywallView(\n paywall: AdaptyPaywall,\n params: CreatePaywallViewParamsInput = {},\n): Promise<PaywallViewController> {\n const controller = await PaywallViewController.create(paywall, params, adaptyPlugin);\n\n return controller;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Adapty } from '../adapty';
|
|
2
|
-
import type { AdaptyOnboarding } from '../
|
|
2
|
+
import type { AdaptyOnboarding } from '../types';
|
|
3
3
|
import type { OnboardingEventHandlers, AdaptyIOSPresentationStyle, CreateOnboardingViewParamsInput } from './types';
|
|
4
4
|
export declare const DEFAULT_ONBOARDING_PARAMS: CreateOnboardingViewParamsInput;
|
|
5
5
|
/**
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { AdaptyError } from '
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { mapValues } from '../shared/utils/map-values';
|
|
7
|
-
import { withErrorContext } from '../shared/utils/with-error-context';
|
|
1
|
+
import { AdaptyError } from '@adapty/core';
|
|
2
|
+
import { coderFactory } from '../coders/factory';
|
|
3
|
+
import { LogContext, Log } from '../logger';
|
|
4
|
+
import { WebPresentation } from '../types';
|
|
5
|
+
import { mapValues, withErrorContext } from '../utils';
|
|
8
6
|
import { OnboardingViewEmitter } from './onboarding-view-emitter';
|
|
9
7
|
import { DEFAULT_ONBOARDING_EVENT_HANDLERS } from './types';
|
|
10
8
|
export const DEFAULT_ONBOARDING_PARAMS = {
|
|
@@ -33,9 +31,9 @@ export class OnboardingViewController {
|
|
|
33
31
|
const methodKey = 'adapty_ui_create_onboarding_view';
|
|
34
32
|
const log = ctx.call({ methodName: methodKey });
|
|
35
33
|
log.start(() => ({ onboarding, params }));
|
|
36
|
-
const coder =
|
|
34
|
+
const coder = coderFactory.createOnboardingCoder();
|
|
37
35
|
const paramsWithDefaults = Object.assign(Object.assign({}, DEFAULT_ONBOARDING_PARAMS), params);
|
|
38
|
-
const encodedParams =
|
|
36
|
+
const encodedParams = coderFactory.createUiCreateOnboardingViewParamsCoder().encode(paramsWithDefaults);
|
|
39
37
|
const data = Object.assign({ method: methodKey, onboarding: coder.encode(onboarding) }, encodedParams);
|
|
40
38
|
const result = (await controller.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log));
|
|
41
39
|
controller.id = result.id;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onboarding-view-controller.js","sourceRoot":"","sources":["../../../src/ui-builder/onboarding-view-controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,uCAAuC,EAAE,MAAM,0DAA0D,CAAC;AACnH,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,iCAAiC,EAAE,MAAM,SAAS,CAAC;AAU5D,MAAM,CAAC,MAAM,yBAAyB,GAAoC;IACxE,wBAAwB,EAAE,eAAe,CAAC,YAAY;CACvD,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,OAAO,wBAAwB;IAKnC;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,UAA4B,EAC5B,YAAoB,EACpB,SAA0C,EAAE;QAE5C,MAAM,UAAU,GAAG,IAAI,wBAAwB,CAAC,YAAY,CAAC,CAAC;QAE9D,MAAM,GAAG,GAAG,IAAI,UAAU,EAAE,CAAC;QAC7B,MAAM,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kD,EACxD,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CACxB,CAAC;YACF,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;gBACrB,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAAE,CAAC;gBACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;YAC1B,CAAC;QACH,CAAC,CAAC;QAEF,OAAO,WAAW,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACI,kBAAkB;QACvB,GAAG,CAAC,IAAI,CACN,oBAAoB,EACpB,GAAG,EAAE,CAAC,iDAAiD,EACvD,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CACxB,CAAC;QAEF,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAAE,CAAC;YACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAC1B,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { Adapty } from '../adapty';\nimport { AdaptyError } from '../shared/adapty-error';\nimport { AdaptyOnboardingCoder } from '../shared/coders/adapty-onboarding';\nimport { AdaptyUICreateOnboardingViewParamsCoder } from '../shared/coders/adapty-ui-create-onboarding-view-params';\nimport { LogContext, Log } from '../shared/logger';\nimport { WebPresentation } from '../shared/types';\nimport type { AdaptyOnboarding } from '../shared/types';\nimport type { components } from '../shared/types/api';\nimport { mapValues } from '../shared/utils/map-values';\nimport { withErrorContext } from '../shared/utils/with-error-context';\n\nimport { OnboardingViewEmitter } from './onboarding-view-emitter';\nimport { DEFAULT_ONBOARDING_EVENT_HANDLERS } from './types';\nimport type {\n AdaptyUiView,\n OnboardingEventHandlers,\n AdaptyIOSPresentationStyle,\n CreateOnboardingViewParamsInput,\n} from './types';\n\ntype Req = components['requests'];\n\nexport const DEFAULT_ONBOARDING_PARAMS: CreateOnboardingViewParamsInput = {\n externalUrlsPresentation: WebPresentation.BrowserInApp,\n};\n\n/**\n * Controller for managing onboarding views.\n *\n * @remarks\n * This class provides methods to present, dismiss, and handle events for onboarding views\n * created with the Onboarding Builder. Create instances using the {@link createOnboardingView} function\n * rather than directly constructing this class.\n *\n * @public\n */\nexport class OnboardingViewController {\n private id: string | null = null;\n private adaptyPlugin: Adapty;\n private viewEmitter: OnboardingViewEmitter | null = null;\n\n /**\n * Intended way to create a OnboardingViewController instance.\n * It prepares a native controller to be presented\n * and creates reference between native controller and JS instance\n * @internal\n */\n static async create(\n onboarding: AdaptyOnboarding,\n adaptyPlugin: Adapty,\n params: CreateOnboardingViewParamsInput = {},\n ): Promise<OnboardingViewController> {\n const controller = new OnboardingViewController(adaptyPlugin);\n\n const ctx = new LogContext();\n const methodKey = 'adapty_ui_create_onboarding_view';\n const log = ctx.call({ methodName: methodKey });\n log.start(() => ({ onboarding, params }));\n\n const coder = new AdaptyOnboardingCoder();\n const paramsWithDefaults = { ...DEFAULT_ONBOARDING_PARAMS, ...params };\n const encodedParams = new AdaptyUICreateOnboardingViewParamsCoder().encode(paramsWithDefaults);\n\n const data: Req['AdaptyUICreateOnboardingView.Request'] = {\n method: methodKey,\n onboarding: coder.encode(onboarding),\n ...encodedParams,\n };\n\n const result = (await controller.adaptyPlugin.handleMethodCall(\n methodKey,\n JSON.stringify(data),\n ctx,\n log,\n )) as AdaptyUiView;\n controller.id = result.id;\n\n await controller.setEventHandlers(DEFAULT_ONBOARDING_EVENT_HANDLERS);\n\n return controller;\n }\n\n /**\n * Since constructors in JS cannot be async, it is not\n * preferred to create ViewControllers in direct way.\n * Consider using @link{OnboardingViewController.create} instead\n *\n * @internal\n */\n private constructor(adaptyPlugin: Adapty) {\n this.adaptyPlugin = adaptyPlugin;\n }\n\n /**\n * Presents the onboarding view as a modal screen.\n *\n * @remarks\n * Calling `present` on an already visible onboarding view will result in an error.\n * The onboarding will be displayed with the configured presentation style on iOS.\n * On Android, the onboarding is always presented as a full-screen activity.\n *\n * @param options - Optional presentation options\n * @param options.iosPresentationStyle - iOS presentation style. Available options: `'full_screen'` (default) or `'page_sheet'`. Only affects iOS platform.\n * @returns A promise that resolves when the onboarding is presented.\n * @throws {@link AdaptyError} if the view reference is invalid or the view is already presented.\n *\n * @example\n * Present with default full-screen style\n * ```typescript\n * import { adapty, createOnboardingView } from '@adapty/capacitor';\n *\n * const onboarding = await adapty.getOnboarding({ placementId: 'YOUR_PLACEMENT_ID' });\n * const view = await createOnboardingView(onboarding);\n * await view.present();\n * ```\n *\n * @example\n * Present with page sheet style on iOS\n * ```typescript\n * await view.present({ iosPresentationStyle: 'page_sheet' });\n * ```\n */\n public async present(options: { iosPresentationStyle?: AdaptyIOSPresentationStyle } = {}): Promise<void> {\n const ctx = new LogContext();\n const methodKey = 'adapty_ui_present_onboarding_view';\n const log = ctx.call({ methodName: methodKey });\n log.start(() => ({ _id: this.id, iosPresentationStyle: options.iosPresentationStyle }));\n\n if (this.id === null) {\n throw new AdaptyError({ adaptyCode: 2002, message: 'No view reference' });\n }\n\n const data: any = {\n method: methodKey,\n id: this.id,\n ios_presentation_style: options.iosPresentationStyle ?? 'full_screen',\n };\n\n await this.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log);\n }\n\n /**\n * Dismisses the onboarding view.\n *\n * @remarks\n * This method closes the onboarding and cleans up associated resources.\n * After dismissing, the view controller instance cannot be reused.\n *\n * @returns A promise that resolves when the onboarding is dismissed.\n * @throws {@link AdaptyError} if the view reference is invalid.\n *\n * @example\n * ```typescript\n * import { createOnboardingView } from '@adapty/capacitor';\n *\n * const view = await createOnboardingView(onboarding);\n * await view.present();\n * // ... later\n * await view.dismiss();\n * ```\n */\n public async dismiss(): Promise<void> {\n const ctx = new LogContext();\n const methodKey = 'adapty_ui_dismiss_onboarding_view';\n const log = ctx.call({ methodName: methodKey });\n log.start(() => ({ _id: this.id }));\n\n if (this.id === null) {\n throw new AdaptyError({ adaptyCode: 2002, message: 'No view reference' });\n }\n\n const data: Req['AdaptyUIDismissOnboardingView.Request'] = {\n method: methodKey,\n id: this.id,\n destroy: true,\n };\n\n await this.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log);\n this.clearEventHandlers();\n }\n\n private onRequestClose = async () => {\n try {\n await this.dismiss();\n } catch (error) {\n Log.warn(\n 'setEventHandlers',\n () => 'Failed to dismiss onboarding',\n () => ({ error }),\n );\n }\n };\n\n /**\n * Registers event handlers for onboarding UI events.\n *\n * @remarks\n * Each event type can have only one handler — new handlers replace existing ones.\n * Default handlers are registered automatically in {@link createOnboardingView} and provide standard closing behavior:\n * - `onClose` - closes the onboarding when the close button is pressed or system back is used\n *\n * If you want to override the `onClose` listener, we strongly recommend returning `true`\n * from your custom listener to retain default closing behavior.\n *\n * Calling this method multiple times will replace previously registered handlers for provided events.\n *\n * @see {@link https://adapty.io/docs/capacitor-handling-onboarding-events | Handling Onboarding Events}\n *\n * @param eventHandlers - Set of event handling callbacks. Only provided handlers will be registered or updated.\n * @returns A promise that resolves to an unsubscribe function that removes all registered listeners.\n *\n * @example\n * Register custom event handlers\n * ```typescript\n * import { createOnboardingView } from '@adapty/capacitor';\n *\n * const view = await createOnboardingView(onboarding);\n *\n * const unsubscribe = await view.setEventHandlers({\n * onClose: () => {\n * console.log('Onboarding closed');\n * // Return true to keep default closing behavior\n * return true;\n * },\n * onActionPerformed: (action) => {\n * console.log('Action performed:', action.name);\n * },\n * onProductSelected: (product) => {\n * console.log('Product selected:', product.vendorProductId);\n * }\n * });\n *\n * await view.present();\n *\n * // Later, unsubscribe all handlers\n * unsubscribe();\n * ```\n */\n public async setEventHandlers(eventHandlers: Partial<OnboardingEventHandlers> = {}): Promise<() => void> {\n const ctx = new LogContext();\n const log = ctx.call({ methodName: 'setEventHandlers' });\n log.start(() => ({ _id: this.id }));\n\n if (this.id === null) {\n throw new AdaptyError({ adaptyCode: 2002, message: 'No view reference' });\n }\n\n Log.verbose(\n 'setEventHandlers',\n () => 'Registering onboarding event handlers for view',\n () => ({ id: this.id }),\n );\n\n const viewEmitter = this.viewEmitter ?? new OnboardingViewEmitter(this.id);\n this.viewEmitter = viewEmitter;\n\n const wrappedErrorLogEventHandlers = mapValues(eventHandlers, (handler, eventName) =>\n handler && typeof handler === 'function'\n ? withErrorContext(handler, eventName as string, 'OnboardingViewController')\n : undefined,\n );\n\n // Merge with defaults to ensure default behavior is preserved after unsubscribe/resubscribe cycles\n const finalEventHandlers: Partial<OnboardingEventHandlers> = {\n ...DEFAULT_ONBOARDING_EVENT_HANDLERS,\n ...wrappedErrorLogEventHandlers,\n };\n\n for (const [eventName, handler] of Object.entries(finalEventHandlers)) {\n if (handler && typeof handler === 'function') {\n try {\n await viewEmitter.addListener(eventName as keyof OnboardingEventHandlers, handler, this.onRequestClose);\n Log.verbose(\n 'setEventHandlers',\n () => 'Registered onboarding handler',\n () => ({ eventName }),\n );\n } catch (error) {\n Log.error(\n 'setEventHandlers',\n () => `Failed to register onboarding handler for ${eventName}`,\n () => ({ error }),\n );\n }\n }\n }\n\n const unsubscribe = () => {\n Log.info(\n 'setEventHandlers',\n () => 'Unsubscribing onboarding event handlers for view',\n () => ({ id: this.id }),\n );\n if (this.viewEmitter) {\n this.viewEmitter.removeAllListeners();\n this.viewEmitter = null;\n }\n };\n\n return unsubscribe;\n }\n\n /**\n * Clears all registered event handlers.\n *\n * @remarks\n * This method removes all previously registered event handlers.\n * After calling this method, no event handlers will be active\n * until you call {@link setEventHandlers} again.\n *\n * Use this after dismiss to remove all event handlers.\n *\n * @example\n * ```typescript\n * const view = await createOnboardingView(onboarding);\n * await view.setEventHandlers({ onClose: handleClose });\n *\n * // Later, clear all handlers\n * view.clearEventHandlers();\n * ```\n */\n public clearEventHandlers(): void {\n Log.info(\n 'clearEventHandlers',\n () => 'Clearing all onboarding event handlers for view',\n () => ({ id: this.id }),\n );\n\n if (this.viewEmitter) {\n this.viewEmitter.removeAllListeners();\n this.viewEmitter = null;\n }\n }\n}\n"]}
|
|
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G,EAAE,CAAC,iDAAiD,EACvD,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CACxB,CAAC;QAEF,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAAE,CAAC;YACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAC1B,CAAC;IACH,CAAC;CACF","sourcesContent":["import { AdaptyError } from '@adapty/core';\n\nimport type { Adapty } from '../adapty';\nimport { coderFactory } from '../coders/factory';\nimport { LogContext, Log } from '../logger';\nimport { WebPresentation } from '../types';\nimport type { AdaptyOnboarding } from '../types';\nimport type { components } from '../types/api';\nimport { mapValues, withErrorContext } from '../utils';\n\nimport { OnboardingViewEmitter } from './onboarding-view-emitter';\nimport { DEFAULT_ONBOARDING_EVENT_HANDLERS } from './types';\nimport type {\n AdaptyUiView,\n OnboardingEventHandlers,\n AdaptyIOSPresentationStyle,\n CreateOnboardingViewParamsInput,\n} from './types';\n\ntype Req = components['requests'];\n\nexport const DEFAULT_ONBOARDING_PARAMS: CreateOnboardingViewParamsInput = {\n externalUrlsPresentation: WebPresentation.BrowserInApp,\n};\n\n/**\n * Controller for managing onboarding views.\n *\n * @remarks\n * This class provides methods to present, dismiss, and handle events for onboarding views\n * created with the Onboarding Builder. Create instances using the {@link createOnboardingView} function\n * rather than directly constructing this class.\n *\n * @public\n */\nexport class OnboardingViewController {\n private id: string | null = null;\n private adaptyPlugin: Adapty;\n private viewEmitter: OnboardingViewEmitter | null = null;\n\n /**\n * Intended way to create a OnboardingViewController instance.\n * It prepares a native controller to be presented\n * and creates reference between native controller and JS instance\n * @internal\n */\n static async create(\n onboarding: AdaptyOnboarding,\n adaptyPlugin: Adapty,\n params: CreateOnboardingViewParamsInput = {},\n ): Promise<OnboardingViewController> {\n const controller = new OnboardingViewController(adaptyPlugin);\n\n const ctx = new LogContext();\n const methodKey = 'adapty_ui_create_onboarding_view';\n const log = ctx.call({ methodName: methodKey });\n log.start(() => ({ onboarding, params }));\n\n const coder = coderFactory.createOnboardingCoder();\n const paramsWithDefaults = { ...DEFAULT_ONBOARDING_PARAMS, ...params };\n const encodedParams = coderFactory.createUiCreateOnboardingViewParamsCoder().encode(paramsWithDefaults);\n\n const data: Req['AdaptyUICreateOnboardingView.Request'] = {\n method: methodKey,\n onboarding: coder.encode(onboarding),\n ...encodedParams,\n };\n\n const result = (await controller.adaptyPlugin.handleMethodCall(\n methodKey,\n JSON.stringify(data),\n ctx,\n log,\n )) as AdaptyUiView;\n controller.id = result.id;\n\n await controller.setEventHandlers(DEFAULT_ONBOARDING_EVENT_HANDLERS);\n\n return controller;\n }\n\n /**\n * Since constructors in JS cannot be async, it is not\n * preferred to create ViewControllers in direct way.\n * Consider using @link{OnboardingViewController.create} instead\n *\n * @internal\n */\n private constructor(adaptyPlugin: Adapty) {\n this.adaptyPlugin = adaptyPlugin;\n }\n\n /**\n * Presents the onboarding view as a modal screen.\n *\n * @remarks\n * Calling `present` on an already visible onboarding view will result in an error.\n * The onboarding will be displayed with the configured presentation style on iOS.\n * On Android, the onboarding is always presented as a full-screen activity.\n *\n * @param options - Optional presentation options\n * @param options.iosPresentationStyle - iOS presentation style. Available options: `'full_screen'` (default) or `'page_sheet'`. Only affects iOS platform.\n * @returns A promise that resolves when the onboarding is presented.\n * @throws {@link AdaptyError} if the view reference is invalid or the view is already presented.\n *\n * @example\n * Present with default full-screen style\n * ```typescript\n * import { adapty, createOnboardingView } from '@adapty/capacitor';\n *\n * const onboarding = await adapty.getOnboarding({ placementId: 'YOUR_PLACEMENT_ID' });\n * const view = await createOnboardingView(onboarding);\n * await view.present();\n * ```\n *\n * @example\n * Present with page sheet style on iOS\n * ```typescript\n * await view.present({ iosPresentationStyle: 'page_sheet' });\n * ```\n */\n public async present(options: { iosPresentationStyle?: AdaptyIOSPresentationStyle } = {}): Promise<void> {\n const ctx = new LogContext();\n const methodKey = 'adapty_ui_present_onboarding_view';\n const log = ctx.call({ methodName: methodKey });\n log.start(() => ({ _id: this.id, iosPresentationStyle: options.iosPresentationStyle }));\n\n if (this.id === null) {\n throw new AdaptyError({ adaptyCode: 2002, message: 'No view reference' });\n }\n\n const data: any = {\n method: methodKey,\n id: this.id,\n ios_presentation_style: options.iosPresentationStyle ?? 'full_screen',\n };\n\n await this.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log);\n }\n\n /**\n * Dismisses the onboarding view.\n *\n * @remarks\n * This method closes the onboarding and cleans up associated resources.\n * After dismissing, the view controller instance cannot be reused.\n *\n * @returns A promise that resolves when the onboarding is dismissed.\n * @throws {@link AdaptyError} if the view reference is invalid.\n *\n * @example\n * ```typescript\n * import { createOnboardingView } from '@adapty/capacitor';\n *\n * const view = await createOnboardingView(onboarding);\n * await view.present();\n * // ... later\n * await view.dismiss();\n * ```\n */\n public async dismiss(): Promise<void> {\n const ctx = new LogContext();\n const methodKey = 'adapty_ui_dismiss_onboarding_view';\n const log = ctx.call({ methodName: methodKey });\n log.start(() => ({ _id: this.id }));\n\n if (this.id === null) {\n throw new AdaptyError({ adaptyCode: 2002, message: 'No view reference' });\n }\n\n const data: Req['AdaptyUIDismissOnboardingView.Request'] = {\n method: methodKey,\n id: this.id,\n destroy: true,\n };\n\n await this.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log);\n this.clearEventHandlers();\n }\n\n private onRequestClose = async () => {\n try {\n await this.dismiss();\n } catch (error) {\n Log.warn(\n 'setEventHandlers',\n () => 'Failed to dismiss onboarding',\n () => ({ error }),\n );\n }\n };\n\n /**\n * Registers event handlers for onboarding UI events.\n *\n * @remarks\n * Each event type can have only one handler — new handlers replace existing ones.\n * Default handlers are registered automatically in {@link createOnboardingView} and provide standard closing behavior:\n * - `onClose` - closes the onboarding when the close button is pressed or system back is used\n *\n * If you want to override the `onClose` listener, we strongly recommend returning `true`\n * from your custom listener to retain default closing behavior.\n *\n * Calling this method multiple times will replace previously registered handlers for provided events.\n *\n * @see {@link https://adapty.io/docs/capacitor-handling-onboarding-events | Handling Onboarding Events}\n *\n * @param eventHandlers - Set of event handling callbacks. Only provided handlers will be registered or updated.\n * @returns A promise that resolves to an unsubscribe function that removes all registered listeners.\n *\n * @example\n * Register custom event handlers\n * ```typescript\n * import { createOnboardingView } from '@adapty/capacitor';\n *\n * const view = await createOnboardingView(onboarding);\n *\n * const unsubscribe = await view.setEventHandlers({\n * onClose: () => {\n * console.log('Onboarding closed');\n * // Return true to keep default closing behavior\n * return true;\n * },\n * onActionPerformed: (action) => {\n * console.log('Action performed:', action.name);\n * },\n * onProductSelected: (product) => {\n * console.log('Product selected:', product.vendorProductId);\n * }\n * });\n *\n * await view.present();\n *\n * // Later, unsubscribe all handlers\n * unsubscribe();\n * ```\n */\n public async setEventHandlers(eventHandlers: Partial<OnboardingEventHandlers> = {}): Promise<() => void> {\n const ctx = new LogContext();\n const log = ctx.call({ methodName: 'setEventHandlers' });\n log.start(() => ({ _id: this.id }));\n\n if (this.id === null) {\n throw new AdaptyError({ adaptyCode: 2002, message: 'No view reference' });\n }\n\n Log.verbose(\n 'setEventHandlers',\n () => 'Registering onboarding event handlers for view',\n () => ({ id: this.id }),\n );\n\n const viewEmitter = this.viewEmitter ?? new OnboardingViewEmitter(this.id);\n this.viewEmitter = viewEmitter;\n\n const wrappedErrorLogEventHandlers = mapValues(eventHandlers, (handler, eventName) =>\n handler && typeof handler === 'function'\n ? withErrorContext(handler, eventName as string, 'OnboardingViewController')\n : undefined,\n );\n\n // Merge with defaults to ensure default behavior is preserved after unsubscribe/resubscribe cycles\n const finalEventHandlers: Partial<OnboardingEventHandlers> = {\n ...DEFAULT_ONBOARDING_EVENT_HANDLERS,\n ...wrappedErrorLogEventHandlers,\n };\n\n for (const [eventName, handler] of Object.entries(finalEventHandlers)) {\n if (handler && typeof handler === 'function') {\n try {\n await viewEmitter.addListener(eventName as keyof OnboardingEventHandlers, handler, this.onRequestClose);\n Log.verbose(\n 'setEventHandlers',\n () => 'Registered onboarding handler',\n () => ({ eventName }),\n );\n } catch (error) {\n Log.error(\n 'setEventHandlers',\n () => `Failed to register onboarding handler for ${eventName}`,\n () => ({ error }),\n );\n }\n }\n }\n\n const unsubscribe = () => {\n Log.info(\n 'setEventHandlers',\n () => 'Unsubscribing onboarding event handlers for view',\n () => ({ id: this.id }),\n );\n if (this.viewEmitter) {\n this.viewEmitter.removeAllListeners();\n this.viewEmitter = null;\n }\n };\n\n return unsubscribe;\n }\n\n /**\n * Clears all registered event handlers.\n *\n * @remarks\n * This method removes all previously registered event handlers.\n * After calling this method, no event handlers will be active\n * until you call {@link setEventHandlers} again.\n *\n * Use this after dismiss to remove all event handlers.\n *\n * @example\n * ```typescript\n * const view = await createOnboardingView(onboarding);\n * await view.setEventHandlers({ onClose: handleClose });\n *\n * // Later, clear all handlers\n * view.clearEventHandlers();\n * ```\n */\n public clearEventHandlers(): void {\n Log.info(\n 'clearEventHandlers',\n () => 'Clearing all onboarding event handlers for view',\n () => ({ id: this.id }),\n );\n\n if (this.viewEmitter) {\n this.viewEmitter.removeAllListeners();\n this.viewEmitter = null;\n }\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { LogContext } from '../
|
|
2
|
-
import type { OnboardingEventIdType, ParsedOnboardingEvent } from '../
|
|
1
|
+
import type { LogContext } from '../logger';
|
|
2
|
+
import type { OnboardingEventIdType, ParsedOnboardingEvent } from '../types/onboarding-events';
|
|
3
3
|
import { BaseViewEmitter } from './base-view-emitter';
|
|
4
4
|
import type { OnboardingEventHandlers } from './types';
|
|
5
5
|
type OnboardingNativeEvent = OnboardingEventIdType;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { parseOnboardingEvent } from '../
|
|
2
|
-
import { OnboardingEventId } from '../
|
|
1
|
+
import { parseOnboardingEvent } from '../coders/parse-onboarding';
|
|
2
|
+
import { OnboardingEventId } from '../types/onboarding-events';
|
|
3
3
|
import { BaseViewEmitter } from './base-view-emitter';
|
|
4
4
|
/**
|
|
5
5
|
* OnboardingViewEmitter manages event handlers for onboarding view events.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onboarding-view-emitter.js","sourceRoot":"","sources":["../../../src/ui-builder/onboarding-view-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"onboarding-view-emitter.js","sourceRoot":"","sources":["../../../src/ui-builder/onboarding-view-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAG/D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAMtD;;;GAGG;AACH,MAAM,OAAO,qBAAsB,SAAQ,eAI1C;IACW,cAAc,CAAC,YAAoB,EAAE,GAAe;QAC5D,MAAM,MAAM,GAAG,oBAAoB,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;QACvD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAES,wBAAwB,CAAC,KAAoC;QACrE,OAAO,uBAAuB,CAAC,KAAkB,CAAC,CAAC;IACrD,CAAC;IAES,wBAAwB,CAAC,WAAkC;;QACnE,OAAO,MAAA,qBAAqB,CAAC,WAAW,CAAC,mCAAI,IAAI,CAAC;IACpD,CAAC;IAES,mBAAmB,CAC3B,WAA0C,EAC1C,SAAgC;QAEhC,OAAO,mBAAmB,CAAC,WAAwB,EAAE,SAAS,CAAC,CAAC;IAClE,CAAC;IAES,cAAc,CAAC,SAAgC;;QACvD,OAAO,MAAA,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,0CAAE,EAAE,mCAAI,IAAI,CAAC;IACrC,CAAC;IAES,cAAc;QACtB,OA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ACH,CAAC","sourcesContent":["import { parseOnboardingEvent } from '../coders/parse-onboarding';\nimport type { LogContext } from '../logger';\nimport { OnboardingEventId } from '../types/onboarding-events';\nimport type { OnboardingEventIdType, ParsedOnboardingEvent } from '../types/onboarding-events';\n\nimport { BaseViewEmitter } from './base-view-emitter';\nimport type { OnboardingEventHandlers } from './types';\n\ntype EventName = keyof OnboardingEventHandlers;\ntype OnboardingNativeEvent = OnboardingEventIdType;\n\n/**\n * OnboardingViewEmitter manages event handlers for onboarding view events.\n * Each event type can have only one handler - new handlers replace existing ones.\n */\nexport class OnboardingViewEmitter extends BaseViewEmitter<\n OnboardingEventHandlers,\n ParsedOnboardingEvent,\n OnboardingNativeEvent\n> {\n protected parseEventData(rawEventData: string, ctx: LogContext): ParsedOnboardingEvent {\n const result = parseOnboardingEvent(rawEventData, ctx);\n if (!result) {\n throw new Error('Failed to parse onboarding event');\n }\n return result;\n }\n\n protected getNativeEventForHandler(event: keyof OnboardingEventHandlers): OnboardingNativeEvent | null {\n return HANDLER_TO_NATIVE_EVENT[event as EventName];\n }\n\n protected getHandlerForNativeEvent(nativeEvent: OnboardingNativeEvent): keyof OnboardingEventHandlers | null {\n return NATIVE_EVENT_RESOLVER[nativeEvent] ?? null;\n }\n\n protected extractCallbackArgs(\n handlerName: keyof OnboardingEventHandlers,\n eventData: ParsedOnboardingEvent,\n ): unknown[] {\n return extractCallbackArgs(handlerName as EventName, eventData);\n }\n\n protected getEventViewId(eventData: ParsedOnboardingEvent): string | null {\n return eventData?.view?.id ?? null;\n }\n\n protected getEmitterName(): string {\n return 'OnboardingViewEmitter';\n }\n}\n\nconst HANDLER_TO_NATIVE_EVENT: Record<EventName, OnboardingNativeEvent> = {\n onError: 'onboarding_did_fail_with_error',\n onAnalytics: 'onboarding_on_analytics_action',\n onFinishedLoading: 'onboarding_did_finish_loading',\n onClose: 'onboarding_on_close_action',\n onCustom: 'onboarding_on_custom_action',\n onPaywall: 'onboarding_on_paywall_action',\n onStateUpdated: 'onboarding_on_state_updated_action',\n};\n\nconst NATIVE_EVENT_RESOLVER: Record<OnboardingNativeEvent, EventName> = {\n onboarding_did_fail_with_error: 'onError',\n onboarding_on_analytics_action: 'onAnalytics',\n onboarding_did_finish_loading: 'onFinishedLoading',\n onboarding_on_close_action: 'onClose',\n onboarding_on_custom_action: 'onCustom',\n onboarding_on_paywall_action: 'onPaywall',\n onboarding_on_state_updated_action: 'onStateUpdated',\n};\n\ntype ExtractedArgs<T extends keyof OnboardingEventHandlers> = Parameters<OnboardingEventHandlers[T]>;\n\nfunction extractCallbackArgs<T extends keyof OnboardingEventHandlers>(\n _handlerName: T,\n event: ParsedOnboardingEvent,\n): ExtractedArgs<T> {\n switch (event.id) {\n case OnboardingEventId.Close:\n case OnboardingEventId.Custom:\n case OnboardingEventId.Paywall:\n return [event.actionId, event.meta] as ExtractedArgs<T>;\n\n case OnboardingEventId.StateUpdated:\n return [event.action, event.meta] as ExtractedArgs<T>;\n\n case OnboardingEventId.FinishedLoading:\n return [event.meta] as ExtractedArgs<T>;\n\n case OnboardingEventId.Analytics:\n return [\n {\n ...event.event,\n // Add backward compatibility: populate element_id from elementId\n element_id: event.event.elementId,\n },\n event.meta,\n ] as ExtractedArgs<T>;\n\n case OnboardingEventId.Error:\n return [event.error] as ExtractedArgs<T>;\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Adapty } from '../adapty';
|
|
2
|
-
import type { AdaptyPaywall } from '../
|
|
2
|
+
import type { AdaptyPaywall } from '../types';
|
|
3
3
|
import type { CreatePaywallViewParamsInput, AdaptyUiDialogConfig, AdaptyUiDialogActionType, EventHandlers, AdaptyIOSPresentationStyle } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* Controller for managing paywall views.
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { AdaptyError } from '
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { mapValues } from '../shared/utils/map-values';
|
|
6
|
-
import { withErrorContext } from '../shared/utils/with-error-context';
|
|
1
|
+
import { AdaptyError } from '@adapty/core';
|
|
2
|
+
import { coderFactory } from '../coders/factory';
|
|
3
|
+
import { LogContext, Log } from '../logger';
|
|
4
|
+
import { mapValues, withErrorContext } from '../utils';
|
|
7
5
|
import { PaywallViewEmitter } from './paywall-view-emitter';
|
|
8
6
|
import { DEFAULT_EVENT_HANDLERS } from './types';
|
|
9
7
|
const DEFAULT_PARAMS = {
|
|
@@ -33,8 +31,8 @@ export class PaywallViewController {
|
|
|
33
31
|
const methodKey = 'adapty_ui_create_paywall_view';
|
|
34
32
|
const log = ctx.call({ methodName: methodKey });
|
|
35
33
|
log.start(() => ({ paywall, params }));
|
|
36
|
-
const paywallCoder =
|
|
37
|
-
const paramsCoder =
|
|
34
|
+
const paywallCoder = coderFactory.createPaywallCoder();
|
|
35
|
+
const paramsCoder = coderFactory.createUiCreatePaywallViewParamsCoder();
|
|
38
36
|
const paramsWithDefaults = Object.assign(Object.assign({}, DEFAULT_PARAMS), params);
|
|
39
37
|
const data = Object.assign({ method: methodKey, paywall: paywallCoder.encode(paywall) }, paramsCoder.encode(paramsWithDefaults));
|
|
40
38
|
const result = (await controller.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paywall-view-controller.js","sourceRoot":"","sources":["../../../src/ui-builder/paywall-view-controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,oCAAoC,EAAE,MAAM,uDAAuD,CAAC;AAC7G,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAGnD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;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;gBACJ,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,GAAG,CAAC,KAAK,CACP,kBAAkB,EAClB,GAAG,EAAE,CAAC,kCAAkC,SAAS,EAAE,EACnD,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAClB,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAED,8BAA8B;QAC9B,MAAM,WAAW,GAAG,GAAG,EAAE;YACvB,GAAG,CAAC,IAAI,CACN,kBAAkB,EAClB,GAAG,EAAE,CAAC,uCAAuC,EAC7C,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CACxB,CAAC;YACF,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;gBACrB,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAAE,CAAC;gBACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;YAC1B,CAAC;QACH,CAAC,CAAC;QAEF,OAAO,WAAW,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACI,kBAAkB;QACvB,GAAG,CAAC,IAAI,CACN,oBAAoB,EACpB,GAAG,EAAE,CAAC,sCAAsC,EAC5C,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CACxB,CAAC;QAEF,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAAE,CAAC;YACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAC1B,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { Adapty } from '../adapty';\nimport { AdaptyError } from '../shared/adapty-error';\nimport { AdaptyPaywallCoder } from '../shared/coders/adapty-paywall';\nimport { AdaptyUICreatePaywallViewParamsCoder } from '../shared/coders/adapty-ui-create-paywall-view-params';\nimport { LogContext, Log } from '../shared/logger';\nimport type { AdaptyPaywall } from '../shared/types';\nimport type { components } from '../shared/types/api';\nimport { mapValues } from '../shared/utils/map-values';\nimport { withErrorContext } from '../shared/utils/with-error-context';\n\nimport { PaywallViewEmitter } from './paywall-view-emitter';\nimport type {\n AdaptyUiView,\n CreatePaywallViewParamsInput,\n AdaptyUiDialogConfig,\n AdaptyUiDialogActionType,\n EventHandlers,\n AdaptyIOSPresentationStyle,\n} from './types';\nimport { DEFAULT_EVENT_HANDLERS } from './types';\n\ntype Req = components['requests'];\n\nconst DEFAULT_PARAMS: CreatePaywallViewParamsInput = {\n prefetchProducts: true,\n loadTimeoutMs: 5000,\n};\n\n/**\n * Controller for managing paywall views.\n *\n * @remarks\n * This class provides methods to present, dismiss, and handle events for paywall views\n * created with the Paywall Builder. Create instances using the {@link createPaywallView} function\n * rather than directly constructing this class.\n *\n * @public\n */\nexport class PaywallViewController {\n private id: string | null = null;\n private adaptyPlugin: Adapty;\n private viewEmitter: PaywallViewEmitter | null = null;\n\n /**\n * Intended way to create a ViewController instance.\n * It prepares a native controller to be presented\n * and creates reference between native controller and JS instance\n * @internal\n */\n static async create(\n paywall: AdaptyPaywall,\n params: CreatePaywallViewParamsInput,\n adaptyPlugin: Adapty,\n ): Promise<PaywallViewController> {\n const controller = new PaywallViewController(adaptyPlugin);\n\n const ctx = new LogContext();\n const methodKey = 'adapty_ui_create_paywall_view';\n const log = ctx.call({ methodName: methodKey });\n log.start(() => ({ paywall, params }));\n\n const paywallCoder = new AdaptyPaywallCoder();\n const paramsCoder = new AdaptyUICreatePaywallViewParamsCoder();\n const paramsWithDefaults: CreatePaywallViewParamsInput = {\n ...DEFAULT_PARAMS,\n ...params,\n };\n\n const data: Req['AdaptyUICreatePaywallView.Request'] = {\n method: methodKey,\n paywall: paywallCoder.encode(paywall),\n ...paramsCoder.encode(paramsWithDefaults),\n };\n\n const result = (await controller.adaptyPlugin.handleMethodCall(\n methodKey,\n JSON.stringify(data),\n ctx,\n log,\n )) as AdaptyUiView;\n controller.id = result.id;\n controller.viewEmitter = new PaywallViewEmitter(controller.id);\n\n await controller.setEventHandlers(DEFAULT_EVENT_HANDLERS);\n\n return controller;\n }\n\n /**\n * Since constructors in JS cannot be async, it is not\n * preferred to create ViewControllers in direct way.\n * Consider using @link{ViewController.create} instead\n *\n * @internal\n */\n private constructor(adaptyPlugin: Adapty) {\n this.adaptyPlugin = adaptyPlugin;\n }\n\n /**\n * Presents the paywall view as a modal screen.\n *\n * @remarks\n * Calling `present` on an already visible paywall view will result in an error.\n * The paywall will be displayed with the configured presentation style on iOS.\n * On Android, the paywall is always presented as a full-screen activity.\n *\n * @param options - Optional presentation options\n * @param options.iosPresentationStyle - iOS presentation style. Available options: `'full_screen'` (default) or `'page_sheet'`. Only affects iOS platform.\n * @returns A promise that resolves when the paywall is presented.\n * @throws {@link AdaptyError} if the view reference is invalid or the view is already presented.\n *\n * @example\n * Present with default full-screen style\n * ```typescript\n * import { adapty, createPaywallView } from '@adapty/capacitor';\n *\n * const paywall = await adapty.getPaywall({ placementId: 'YOUR_PLACEMENT_ID' });\n * const view = await createPaywallView(paywall);\n * await view.present();\n * ```\n *\n * @example\n * Present with page sheet style on iOS\n * ```typescript\n * await view.present({ iosPresentationStyle: 'page_sheet' });\n * ```\n */\n public async present(options: { iosPresentationStyle?: AdaptyIOSPresentationStyle } = {}): Promise<void> {\n const ctx = new LogContext();\n const methodKey = 'adapty_ui_present_paywall_view';\n const log = ctx.call({ methodName: methodKey });\n log.start(() => ({ _id: this.id, iosPresentationStyle: options.iosPresentationStyle }));\n\n if (this.id === null) {\n throw new AdaptyError({\n adaptyCode: 2002,\n message: 'No view reference',\n });\n }\n\n const data: any = {\n method: methodKey,\n id: this.id,\n ios_presentation_style: options.iosPresentationStyle ?? 'full_screen',\n };\n\n await this.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log);\n }\n\n /**\n * Dismisses the paywall view.\n *\n * @remarks\n * This method closes the paywall and cleans up associated resources.\n * After dismissing, the view controller instance cannot be reused.\n *\n * @returns A promise that resolves when the paywall is dismissed.\n * @throws {@link AdaptyError} if the view reference is invalid.\n *\n * @example\n * ```typescript\n * import { createPaywallView } from '@adapty/capacitor';\n *\n * const view = await createPaywallView(paywall);\n * await view.present();\n * // ... later\n * await view.dismiss();\n * ```\n */\n public async dismiss(): Promise<void> {\n const ctx = new LogContext();\n const methodKey = 'adapty_ui_dismiss_paywall_view';\n const log = ctx.call({ methodName: methodKey });\n log.start(() => ({ _id: this.id }));\n\n if (this.id === null) {\n throw new AdaptyError({\n adaptyCode: 2002,\n message: 'No view reference',\n });\n }\n\n const data: Req['AdaptyUIDismissPaywallView.Request'] = {\n method: methodKey,\n id: this.id,\n destroy: true,\n };\n\n await this.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log);\n this.clearEventHandlers();\n }\n\n /**\n * Displays a dialog to the user.\n *\n * @remarks\n * Use this method to show custom dialogs within the paywall flow.\n * If you provide two actions in the config, the primary action should cancel the operation\n * and leave things unchanged, while the secondary action should confirm the operation.\n *\n * @param config - Configuration for the dialog.\n * @param config.title - The dialog title.\n * @param config.content - The dialog message content.\n * @param config.primaryActionTitle - The title for the primary (default) action button.\n * @param config.secondaryActionTitle - Optional. The title for the secondary action button.\n * @returns A promise that resolves to the action type that the user selected: `'primary'` or `'secondary'`.\n * @throws {@link AdaptyError} if the view reference is invalid.\n *\n * @example\n * Show confirmation dialog\n * ```typescript\n * const action = await view.showDialog({\n * title: 'Confirm Purchase',\n * content: 'Are you sure you want to proceed with this purchase?',\n * primaryActionTitle: 'Cancel',\n * secondaryActionTitle: 'Continue'\n * });\n *\n * if (action === 'secondary') {\n * console.log('User confirmed');\n * }\n * ```\n */\n public async showDialog(config: AdaptyUiDialogConfig): Promise<AdaptyUiDialogActionType> {\n const ctx = new LogContext();\n const methodKey = 'adapty_ui_show_dialog';\n const log = ctx.call({ methodName: methodKey });\n log.start(() => ({ _id: this.id }));\n\n if (this.id === null) {\n throw new AdaptyError({\n adaptyCode: 2002,\n message: 'No view reference',\n });\n }\n\n const dialogConfig = {\n default_action_title: config.primaryActionTitle,\n secondary_action_title: config.secondaryActionTitle,\n title: config.title,\n content: config.content,\n };\n\n const data: Req['AdaptyUIShowDialog.Request'] = {\n method: methodKey,\n id: this.id,\n configuration: dialogConfig,\n };\n\n return await this.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log);\n }\n\n private onRequestClose = async () => {\n try {\n await this.dismiss();\n } catch (error) {\n Log.warn(\n 'setEventHandlers',\n () => 'Failed to dismiss paywall',\n () => ({ error }),\n );\n }\n };\n\n /**\n * Registers event handlers for paywall UI events.\n *\n * @remarks\n * Each event type can have only one handler — new handlers replace existing ones.\n * Default handlers are registered automatically in {@link createPaywallView} and provide standard closing behavior:\n * - `onCloseButtonPress` - closes the paywall\n * - `onAndroidSystemBack` - closes the paywall (Android only)\n * - `onRestoreCompleted` - closes the paywall after successful restore\n * - `onRenderingFailed` - closes the paywall when rendering fails\n * - `onPurchaseCompleted` - closes the paywall after successful purchase\n *\n * If you want to override these listeners, we strongly recommend returning `true`\n * (or `purchaseResult.type !== 'user_cancelled'` in case of `onPurchaseCompleted`)\n * from your custom listener to retain default closing behavior.\n *\n * Calling this method multiple times will replace previously registered handlers for provided events.\n *\n * @see {@link https://adapty.io/docs/capacitor-handling-events | Handling View Events}\n *\n * @param eventHandlers - Set of event handling callbacks. Only provided handlers will be registered or updated.\n * @returns A promise that resolves to an unsubscribe function that removes all registered listeners.\n *\n * @example\n * Register custom event handlers\n * ```typescript\n * import { createPaywallView } from '@adapty/capacitor';\n *\n * const view = await createPaywallView(paywall);\n *\n * const unsubscribe = await view.setEventHandlers({\n * onPurchaseStarted: (product) => {\n * console.log('Purchase started:', product.vendorProductId);\n * },\n * onPurchaseCompleted: (result) => {\n * console.log('Purchase completed:', result.type);\n * // Return true to keep default closing behavior\n * return result.type !== 'user_cancelled';\n * },\n * onPurchaseFailed: (error) => {\n * console.error('Purchase failed:', error);\n * }\n * });\n *\n * await view.present();\n *\n * // Later, unsubscribe all handlers\n * unsubscribe();\n * ```\n */\n public async setEventHandlers(eventHandlers: Partial<EventHandlers> = {}): Promise<() => void> {\n const ctx = new LogContext();\n const log = ctx.call({ methodName: 'setEventHandlers' });\n log.start(() => ({ _id: this.id }));\n\n if (this.id === null) {\n throw new AdaptyError({\n adaptyCode: 2002,\n message: 'No view reference',\n });\n }\n\n Log.verbose(\n 'setEventHandlers',\n () => 'Registering event handlers for view',\n () => ({ id: this.id }),\n );\n\n const viewEmitter = this.viewEmitter ?? new PaywallViewEmitter(this.id);\n this.viewEmitter = viewEmitter;\n\n const wrappedErrorLogEventHandlers = mapValues(eventHandlers, (handler, eventName) =>\n handler && typeof handler === 'function'\n ? withErrorContext(handler, eventName as string, 'PaywallViewController')\n : undefined,\n );\n\n // Merge with defaults to ensure default behavior is preserved after unsubscribe/resubscribe cycles\n const finalEventHandlers: EventHandlers = {\n ...DEFAULT_EVENT_HANDLERS,\n ...wrappedErrorLogEventHandlers,\n };\n\n for (const [eventName, handler] of Object.entries(finalEventHandlers)) {\n if (handler && typeof handler === 'function') {\n try {\n await viewEmitter.addListener(eventName as keyof EventHandlers, handler, this.onRequestClose);\n Log.verbose(\n 'setEventHandlers',\n () => 'Registered handler for',\n () => ({ eventName }),\n );\n } catch (error) {\n Log.error(\n 'setEventHandlers',\n () => `Failed to register handler for ${eventName}`,\n () => ({ error }),\n );\n }\n }\n }\n\n // Return unsubscribe function\n const unsubscribe = () => {\n Log.info(\n 'setEventHandlers',\n () => 'Unsubscribing event handlers for view',\n () => ({ id: this.id }),\n );\n if (this.viewEmitter) {\n this.viewEmitter.removeAllListeners();\n this.viewEmitter = null;\n }\n };\n\n return unsubscribe;\n }\n\n /**\n * Clears all registered event handlers.\n *\n * @remarks\n * This method removes all previously registered event handlers.\n * After calling this method, no event handlers will be active\n * until you call {@link setEventHandlers} again.\n *\n * Use this after dismiss to remove all event handlers\n *\n * @example\n * ```typescript\n * const view = await createPaywallView(paywall);\n * await view.setEventHandlers({ onPurchaseCompleted: handlePurchase });\n *\n * // Later, clear all handlers\n * view.clearEventHandlers();\n * ```\n */\n public clearEventHandlers(): void {\n Log.info(\n 'clearEventHandlers',\n () => 'Clearing all event handlers for view',\n () => ({ id: this.id }),\n );\n\n if (this.viewEmitter) {\n this.viewEmitter.removeAllListeners();\n this.viewEmitter = null;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"paywall-view-controller.js","sourceRoot":"","sources":["../../../src/ui-builder/paywall-view-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAG5C,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAS5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAIjD,MAAM,cAAc,GAAiC;IACnD,gBAAgB,EAAE,IAAI;IACtB,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,OAAO,qBAAqB;IAKhC;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,OAAsB,EACtB,MAAoC,EACpC,YAAoB;QAEpB,MAAM,UAAU,GAAG,IAAI,qBAAqB,CAAC,YAAY,CAAC,CAAC;QAE3D,MAAM,GAAG,GAAG,IAAI,UAAU,EAAE,CAAC;QAC7B,MAAM,SAAS,GAAG,+BAA+B,CAAC;QAClD,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC;QAChD,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QAEvC,MAAM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BAAkB;QACvB,GAAG,CAAC,IAAI,CACN,oBAAoB,EACpB,GAAG,EAAE,CAAC,sCAAsC,EAC5C,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CACxB,CAAC;QAEF,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAAE,CAAC;YACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAC1B,CAAC;IACH,CAAC;CACF","sourcesContent":["import { AdaptyError } from '@adapty/core';\n\nimport type { Adapty } from '../adapty';\nimport { coderFactory } from '../coders/factory';\nimport { LogContext, Log } from '../logger';\nimport type { AdaptyPaywall } from '../types';\nimport type { components } from '../types/api';\nimport { mapValues, withErrorContext } from '../utils';\n\nimport { PaywallViewEmitter } from './paywall-view-emitter';\nimport type {\n AdaptyUiView,\n CreatePaywallViewParamsInput,\n AdaptyUiDialogConfig,\n AdaptyUiDialogActionType,\n EventHandlers,\n AdaptyIOSPresentationStyle,\n} from './types';\nimport { DEFAULT_EVENT_HANDLERS } from './types';\n\ntype Req = components['requests'];\n\nconst DEFAULT_PARAMS: CreatePaywallViewParamsInput = {\n prefetchProducts: true,\n loadTimeoutMs: 5000,\n};\n\n/**\n * Controller for managing paywall views.\n *\n * @remarks\n * This class provides methods to present, dismiss, and handle events for paywall views\n * created with the Paywall Builder. Create instances using the {@link createPaywallView} function\n * rather than directly constructing this class.\n *\n * @public\n */\nexport class PaywallViewController {\n private id: string | null = null;\n private adaptyPlugin: Adapty;\n private viewEmitter: PaywallViewEmitter | null = null;\n\n /**\n * Intended way to create a ViewController instance.\n * It prepares a native controller to be presented\n * and creates reference between native controller and JS instance\n * @internal\n */\n static async create(\n paywall: AdaptyPaywall,\n params: CreatePaywallViewParamsInput,\n adaptyPlugin: Adapty,\n ): Promise<PaywallViewController> {\n const controller = new PaywallViewController(adaptyPlugin);\n\n const ctx = new LogContext();\n const methodKey = 'adapty_ui_create_paywall_view';\n const log = ctx.call({ methodName: methodKey });\n log.start(() => ({ paywall, params }));\n\n const paywallCoder = coderFactory.createPaywallCoder();\n const paramsCoder = coderFactory.createUiCreatePaywallViewParamsCoder();\n const paramsWithDefaults: CreatePaywallViewParamsInput = {\n ...DEFAULT_PARAMS,\n ...params,\n };\n\n const data: Req['AdaptyUICreatePaywallView.Request'] = {\n method: methodKey,\n paywall: paywallCoder.encode(paywall),\n ...paramsCoder.encode(paramsWithDefaults),\n };\n\n const result = (await controller.adaptyPlugin.handleMethodCall(\n methodKey,\n JSON.stringify(data),\n ctx,\n log,\n )) as AdaptyUiView;\n controller.id = result.id;\n controller.viewEmitter = new PaywallViewEmitter(controller.id);\n\n await controller.setEventHandlers(DEFAULT_EVENT_HANDLERS);\n\n return controller;\n }\n\n /**\n * Since constructors in JS cannot be async, it is not\n * preferred to create ViewControllers in direct way.\n * Consider using @link{ViewController.create} instead\n *\n * @internal\n */\n private constructor(adaptyPlugin: Adapty) {\n this.adaptyPlugin = adaptyPlugin;\n }\n\n /**\n * Presents the paywall view as a modal screen.\n *\n * @remarks\n * Calling `present` on an already visible paywall view will result in an error.\n * The paywall will be displayed with the configured presentation style on iOS.\n * On Android, the paywall is always presented as a full-screen activity.\n *\n * @param options - Optional presentation options\n * @param options.iosPresentationStyle - iOS presentation style. Available options: `'full_screen'` (default) or `'page_sheet'`. Only affects iOS platform.\n * @returns A promise that resolves when the paywall is presented.\n * @throws {@link AdaptyError} if the view reference is invalid or the view is already presented.\n *\n * @example\n * Present with default full-screen style\n * ```typescript\n * import { adapty, createPaywallView } from '@adapty/capacitor';\n *\n * const paywall = await adapty.getPaywall({ placementId: 'YOUR_PLACEMENT_ID' });\n * const view = await createPaywallView(paywall);\n * await view.present();\n * ```\n *\n * @example\n * Present with page sheet style on iOS\n * ```typescript\n * await view.present({ iosPresentationStyle: 'page_sheet' });\n * ```\n */\n public async present(options: { iosPresentationStyle?: AdaptyIOSPresentationStyle } = {}): Promise<void> {\n const ctx = new LogContext();\n const methodKey = 'adapty_ui_present_paywall_view';\n const log = ctx.call({ methodName: methodKey });\n log.start(() => ({ _id: this.id, iosPresentationStyle: options.iosPresentationStyle }));\n\n if (this.id === null) {\n throw new AdaptyError({\n adaptyCode: 2002,\n message: 'No view reference',\n });\n }\n\n const data: any = {\n method: methodKey,\n id: this.id,\n ios_presentation_style: options.iosPresentationStyle ?? 'full_screen',\n };\n\n await this.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log);\n }\n\n /**\n * Dismisses the paywall view.\n *\n * @remarks\n * This method closes the paywall and cleans up associated resources.\n * After dismissing, the view controller instance cannot be reused.\n *\n * @returns A promise that resolves when the paywall is dismissed.\n * @throws {@link AdaptyError} if the view reference is invalid.\n *\n * @example\n * ```typescript\n * import { createPaywallView } from '@adapty/capacitor';\n *\n * const view = await createPaywallView(paywall);\n * await view.present();\n * // ... later\n * await view.dismiss();\n * ```\n */\n public async dismiss(): Promise<void> {\n const ctx = new LogContext();\n const methodKey = 'adapty_ui_dismiss_paywall_view';\n const log = ctx.call({ methodName: methodKey });\n log.start(() => ({ _id: this.id }));\n\n if (this.id === null) {\n throw new AdaptyError({\n adaptyCode: 2002,\n message: 'No view reference',\n });\n }\n\n const data: Req['AdaptyUIDismissPaywallView.Request'] = {\n method: methodKey,\n id: this.id,\n destroy: true,\n };\n\n await this.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log);\n this.clearEventHandlers();\n }\n\n /**\n * Displays a dialog to the user.\n *\n * @remarks\n * Use this method to show custom dialogs within the paywall flow.\n * If you provide two actions in the config, the primary action should cancel the operation\n * and leave things unchanged, while the secondary action should confirm the operation.\n *\n * @param config - Configuration for the dialog.\n * @param config.title - The dialog title.\n * @param config.content - The dialog message content.\n * @param config.primaryActionTitle - The title for the primary (default) action button.\n * @param config.secondaryActionTitle - Optional. The title for the secondary action button.\n * @returns A promise that resolves to the action type that the user selected: `'primary'` or `'secondary'`.\n * @throws {@link AdaptyError} if the view reference is invalid.\n *\n * @example\n * Show confirmation dialog\n * ```typescript\n * const action = await view.showDialog({\n * title: 'Confirm Purchase',\n * content: 'Are you sure you want to proceed with this purchase?',\n * primaryActionTitle: 'Cancel',\n * secondaryActionTitle: 'Continue'\n * });\n *\n * if (action === 'secondary') {\n * console.log('User confirmed');\n * }\n * ```\n */\n public async showDialog(config: AdaptyUiDialogConfig): Promise<AdaptyUiDialogActionType> {\n const ctx = new LogContext();\n const methodKey = 'adapty_ui_show_dialog';\n const log = ctx.call({ methodName: methodKey });\n log.start(() => ({ _id: this.id }));\n\n if (this.id === null) {\n throw new AdaptyError({\n adaptyCode: 2002,\n message: 'No view reference',\n });\n }\n\n const dialogConfig = {\n default_action_title: config.primaryActionTitle,\n secondary_action_title: config.secondaryActionTitle,\n title: config.title,\n content: config.content,\n };\n\n const data: Req['AdaptyUIShowDialog.Request'] = {\n method: methodKey,\n id: this.id,\n configuration: dialogConfig,\n };\n\n return await this.adaptyPlugin.handleMethodCall(methodKey, JSON.stringify(data), ctx, log);\n }\n\n private onRequestClose = async () => {\n try {\n await this.dismiss();\n } catch (error) {\n Log.warn(\n 'setEventHandlers',\n () => 'Failed to dismiss paywall',\n () => ({ error }),\n );\n }\n };\n\n /**\n * Registers event handlers for paywall UI events.\n *\n * @remarks\n * Each event type can have only one handler — new handlers replace existing ones.\n * Default handlers are registered automatically in {@link createPaywallView} and provide standard closing behavior:\n * - `onCloseButtonPress` - closes the paywall\n * - `onAndroidSystemBack` - closes the paywall (Android only)\n * - `onRestoreCompleted` - closes the paywall after successful restore\n * - `onRenderingFailed` - closes the paywall when rendering fails\n * - `onPurchaseCompleted` - closes the paywall after successful purchase\n *\n * If you want to override these listeners, we strongly recommend returning `true`\n * (or `purchaseResult.type !== 'user_cancelled'` in case of `onPurchaseCompleted`)\n * from your custom listener to retain default closing behavior.\n *\n * Calling this method multiple times will replace previously registered handlers for provided events.\n *\n * @see {@link https://adapty.io/docs/capacitor-handling-events | Handling View Events}\n *\n * @param eventHandlers - Set of event handling callbacks. Only provided handlers will be registered or updated.\n * @returns A promise that resolves to an unsubscribe function that removes all registered listeners.\n *\n * @example\n * Register custom event handlers\n * ```typescript\n * import { createPaywallView } from '@adapty/capacitor';\n *\n * const view = await createPaywallView(paywall);\n *\n * const unsubscribe = await view.setEventHandlers({\n * onPurchaseStarted: (product) => {\n * console.log('Purchase started:', product.vendorProductId);\n * },\n * onPurchaseCompleted: (result) => {\n * console.log('Purchase completed:', result.type);\n * // Return true to keep default closing behavior\n * return result.type !== 'user_cancelled';\n * },\n * onPurchaseFailed: (error) => {\n * console.error('Purchase failed:', error);\n * }\n * });\n *\n * await view.present();\n *\n * // Later, unsubscribe all handlers\n * unsubscribe();\n * ```\n */\n public async setEventHandlers(eventHandlers: Partial<EventHandlers> = {}): Promise<() => void> {\n const ctx = new LogContext();\n const log = ctx.call({ methodName: 'setEventHandlers' });\n log.start(() => ({ _id: this.id }));\n\n if (this.id === null) {\n throw new AdaptyError({\n adaptyCode: 2002,\n message: 'No view reference',\n });\n }\n\n Log.verbose(\n 'setEventHandlers',\n () => 'Registering event handlers for view',\n () => ({ id: this.id }),\n );\n\n const viewEmitter = this.viewEmitter ?? new PaywallViewEmitter(this.id);\n this.viewEmitter = viewEmitter;\n\n const wrappedErrorLogEventHandlers = mapValues(eventHandlers, (handler, eventName) =>\n handler && typeof handler === 'function'\n ? withErrorContext(handler, eventName as string, 'PaywallViewController')\n : undefined,\n );\n\n // Merge with defaults to ensure default behavior is preserved after unsubscribe/resubscribe cycles\n const finalEventHandlers: EventHandlers = {\n ...DEFAULT_EVENT_HANDLERS,\n ...wrappedErrorLogEventHandlers,\n };\n\n for (const [eventName, handler] of Object.entries(finalEventHandlers)) {\n if (handler && typeof handler === 'function') {\n try {\n await viewEmitter.addListener(eventName as keyof EventHandlers, handler, this.onRequestClose);\n Log.verbose(\n 'setEventHandlers',\n () => 'Registered handler for',\n () => ({ eventName }),\n );\n } catch (error) {\n Log.error(\n 'setEventHandlers',\n () => `Failed to register handler for ${eventName}`,\n () => ({ error }),\n );\n }\n }\n }\n\n // Return unsubscribe function\n const unsubscribe = () => {\n Log.info(\n 'setEventHandlers',\n () => 'Unsubscribing event handlers for view',\n () => ({ id: this.id }),\n );\n if (this.viewEmitter) {\n this.viewEmitter.removeAllListeners();\n this.viewEmitter = null;\n }\n };\n\n return unsubscribe;\n }\n\n /**\n * Clears all registered event handlers.\n *\n * @remarks\n * This method removes all previously registered event handlers.\n * After calling this method, no event handlers will be active\n * until you call {@link setEventHandlers} again.\n *\n * Use this after dismiss to remove all event handlers\n *\n * @example\n * ```typescript\n * const view = await createPaywallView(paywall);\n * await view.setEventHandlers({ onPurchaseCompleted: handlePurchase });\n *\n * // Later, clear all handlers\n * view.clearEventHandlers();\n * ```\n */\n public clearEventHandlers(): void {\n Log.info(\n 'clearEventHandlers',\n () => 'Clearing all event handlers for view',\n () => ({ id: this.id }),\n );\n\n if (this.viewEmitter) {\n this.viewEmitter.removeAllListeners();\n this.viewEmitter = null;\n }\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { LogContext } from '../
|
|
2
|
-
import type { ParsedPaywallEvent, PaywallEventIdType } from '../
|
|
1
|
+
import type { LogContext } from '../logger';
|
|
2
|
+
import type { ParsedPaywallEvent, PaywallEventIdType } from '../types/paywall-events';
|
|
3
3
|
import { BaseViewEmitter } from './base-view-emitter';
|
|
4
4
|
import type { EventHandlers } from './types';
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { parsePaywallEvent } from '../
|
|
2
|
-
import { PaywallEventId } from '../
|
|
1
|
+
import { parsePaywallEvent } from '../coders/parse-paywall';
|
|
2
|
+
import { PaywallEventId } from '../types/paywall-events';
|
|
3
3
|
import { BaseViewEmitter } from './base-view-emitter';
|
|
4
4
|
/**
|
|
5
5
|
* PaywallViewEmitter manages event handlers for paywall view events.
|