@adapty/capacitor 3.17.1 → 4.0.0-beta.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.
Files changed (75) hide show
  1. package/Package.swift +1 -1
  2. package/README.md +8 -0
  3. package/android/build.gradle +2 -2
  4. package/dist/esm/adapty-instance.d.ts +7 -0
  5. package/dist/esm/adapty-instance.js +8 -0
  6. package/dist/esm/adapty-instance.js.map +1 -0
  7. package/dist/esm/adapty.d.ts +112 -59
  8. package/dist/esm/adapty.js +132 -69
  9. package/dist/esm/adapty.js.map +1 -1
  10. package/dist/esm/coders/parse-flow.d.ts +3 -0
  11. package/dist/esm/coders/parse-flow.js +4 -0
  12. package/dist/esm/coders/parse-flow.js.map +1 -0
  13. package/dist/esm/default-configs.js +2 -2
  14. package/dist/esm/default-configs.js.map +1 -1
  15. package/dist/esm/index.d.ts +4 -4
  16. package/dist/esm/index.js +3 -3
  17. package/dist/esm/index.js.map +1 -1
  18. package/dist/esm/types/adapty-plugin.d.ts +31 -17
  19. package/dist/esm/types/adapty-plugin.js.map +1 -1
  20. package/dist/esm/types/configs.d.ts +12 -14
  21. package/dist/esm/types/configs.js.map +1 -1
  22. package/dist/esm/types/flow-events.d.ts +1 -0
  23. package/dist/esm/types/flow-events.js +2 -0
  24. package/dist/esm/types/flow-events.js.map +1 -0
  25. package/dist/esm/types/index.d.ts +2 -2
  26. package/dist/esm/types/index.js +1 -1
  27. package/dist/esm/types/index.js.map +1 -1
  28. package/dist/esm/types/inputs.d.ts +1 -1
  29. package/dist/esm/types/inputs.js.map +1 -1
  30. package/dist/esm/ui-builder/base-view-emitter.d.ts +6 -0
  31. package/dist/esm/ui-builder/base-view-emitter.js +12 -0
  32. package/dist/esm/ui-builder/base-view-emitter.js.map +1 -1
  33. package/dist/esm/ui-builder/create-flow-view.d.ts +14 -0
  34. package/dist/esm/ui-builder/create-flow-view.js +16 -0
  35. package/dist/esm/ui-builder/create-flow-view.js.map +1 -0
  36. package/dist/esm/ui-builder/create-onboarding-view.d.ts +2 -0
  37. package/dist/esm/ui-builder/create-onboarding-view.js +2 -0
  38. package/dist/esm/ui-builder/create-onboarding-view.js.map +1 -1
  39. package/dist/esm/ui-builder/{paywall-view-controller.d.ts → flow-view-controller.d.ts} +37 -37
  40. package/dist/esm/ui-builder/{paywall-view-controller.js → flow-view-controller.js} +54 -51
  41. package/dist/esm/ui-builder/flow-view-controller.js.map +1 -0
  42. package/dist/esm/ui-builder/flow-view-emitter.d.ts +38 -0
  43. package/dist/esm/ui-builder/flow-view-emitter.js +151 -0
  44. package/dist/esm/ui-builder/flow-view-emitter.js.map +1 -0
  45. package/dist/esm/ui-builder/index.d.ts +5 -5
  46. package/dist/esm/ui-builder/index.js +3 -2
  47. package/dist/esm/ui-builder/index.js.map +1 -1
  48. package/dist/esm/ui-builder/onboarding-view-controller.d.ts +7 -5
  49. package/dist/esm/ui-builder/onboarding-view-controller.js +7 -5
  50. package/dist/esm/ui-builder/onboarding-view-controller.js.map +1 -1
  51. package/dist/esm/ui-builder/types.d.ts +11 -358
  52. package/dist/esm/ui-builder/types.js +52 -22
  53. package/dist/esm/ui-builder/types.js.map +1 -1
  54. package/dist/esm/version.d.ts +1 -1
  55. package/dist/esm/version.js +1 -1
  56. package/dist/esm/version.js.map +1 -1
  57. package/dist/plugin.cjs.js +903 -679
  58. package/dist/plugin.cjs.js.map +1 -1
  59. package/dist/plugin.js +903 -679
  60. package/dist/plugin.js.map +1 -1
  61. package/package.json +3 -5
  62. package/AdaptyCapacitor.podspec +0 -20
  63. package/dist/esm/coders/parse-paywall.d.ts +0 -3
  64. package/dist/esm/coders/parse-paywall.js +0 -4
  65. package/dist/esm/coders/parse-paywall.js.map +0 -1
  66. package/dist/esm/types/paywall-events.d.ts +0 -1
  67. package/dist/esm/types/paywall-events.js +0 -2
  68. package/dist/esm/types/paywall-events.js.map +0 -1
  69. package/dist/esm/ui-builder/create-paywall-view.d.ts +0 -25
  70. package/dist/esm/ui-builder/create-paywall-view.js +0 -29
  71. package/dist/esm/ui-builder/create-paywall-view.js.map +0 -1
  72. package/dist/esm/ui-builder/paywall-view-controller.js.map +0 -1
  73. package/dist/esm/ui-builder/paywall-view-emitter.d.ts +0 -16
  74. package/dist/esm/ui-builder/paywall-view-emitter.js +0 -114
  75. package/dist/esm/ui-builder/paywall-view-emitter.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adapty/capacitor",
3
- "version": "3.17.1",
3
+ "version": "4.0.0-beta.2",
4
4
  "description": "Official Adapty SDK for Capacitor",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -12,8 +12,7 @@
12
12
  "dist/",
13
13
  "ios/Sources",
14
14
  "ios/Tests",
15
- "Package.swift",
16
- "AdaptyCapacitor.podspec"
15
+ "Package.swift"
17
16
  ],
18
17
  "author": "Adapty team <support@adapty.io>",
19
18
  "license": "MIT",
@@ -60,7 +59,6 @@
60
59
  "dev-example-js": "yarn build && yarn dev-sync-all-files && cd ./examples/adapty-devtools && yarn build && yarn cap copy",
61
60
  "dev-example": "yarn build && yarn dev-sync-all-files && cd ./examples/adapty-devtools && yarn build && yarn cap sync --deployment",
62
61
  "dev-example-full": "yarn build && cd ./examples/adapty-devtools && yarn --force && yarn build && yarn cap sync",
63
- "patch-adaptyui-webview": "git apply --directory=examples/adapty-devtools/ios/App/Pods/AdaptyUI patches/adaptyui-inspectable-webview.patch",
64
62
  "prepare": "husky"
65
63
  },
66
64
  "devDependencies": {
@@ -92,7 +90,7 @@
92
90
  "@capacitor/core": ">=8.0.0"
93
91
  },
94
92
  "dependencies": {
95
- "@adapty/core": "3.17.2",
93
+ "@adapty/core": "4.0.0",
96
94
  "tslib": "^2.5.0"
97
95
  },
98
96
  "publishConfig": {
@@ -1,20 +0,0 @@
1
- require 'json'
2
-
3
- package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
-
5
- Pod::Spec.new do |s|
6
- s.name = 'AdaptyCapacitor'
7
- s.version = package['version']
8
- s.summary = package['description']
9
- s.license = package['license']
10
- s.homepage = package['repository']['url']
11
- s.author = package['author']
12
- s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
- s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '15.0'
15
- s.dependency 'Capacitor'
16
- s.dependency 'Adapty', '3.17.2'
17
- s.dependency 'AdaptyUI', '3.17.2'
18
- s.dependency 'AdaptyPlugin', '3.17.2'
19
- s.swift_version = '5.1'
20
- end
@@ -1,3 +0,0 @@
1
- import type { LogContext } from '../logger';
2
- import type { ParsedPaywallEvent } from '../types/paywall-events';
3
- export declare const parsePaywallEvent: (input: string, ctx?: LogContext) => ParsedPaywallEvent | null;
@@ -1,4 +0,0 @@
1
- import { parsePaywallEvent as _parsePaywallEvent } from '@adapty/core';
2
- import { coderFactory } from './factory';
3
- export const parsePaywallEvent = (input, ctx) => _parsePaywallEvent(coderFactory, input, ctx);
4
- //# sourceMappingURL=parse-paywall.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse-paywall.js","sourceRoot":"","sources":["../../../src/coders/parse-paywall.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,IAAI,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAKvE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAE,GAAgB,EAA6B,EAAE,CAC9F,kBAAkB,CAAC,YAAY,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC","sourcesContent":["import { parsePaywallEvent as _parsePaywallEvent } from '@adapty/core';\n\nimport type { LogContext } from '../logger';\nimport type { ParsedPaywallEvent } from '../types/paywall-events';\n\nimport { coderFactory } from './factory';\n\nexport const parsePaywallEvent = (input: string, ctx?: LogContext): ParsedPaywallEvent | null =>\n _parsePaywallEvent(coderFactory, input, ctx);\n"]}
@@ -1 +0,0 @@
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';
@@ -1,2 +0,0 @@
1
- export { PaywallEventId, } from '@adapty/core';
2
- //# sourceMappingURL=paywall-events.js.map
@@ -1 +0,0 @@
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,25 +0,0 @@
1
- import type { AdaptyPaywall } from '../types';
2
- import { PaywallViewController } from './paywall-view-controller';
3
- import type { CreatePaywallViewParamsInput } from './types';
4
- /**
5
- * Creates a paywall view controller.
6
- * You can use it to further configure a view or present it.
7
- *
8
- * @see {@link https://adapty.io/docs/capacitor-present-paywalls | [DOC] Creating a paywall view}
9
- *
10
- * @param {AdaptyPaywall} paywall - paywall that you want to present.
11
- * @param {CreatePaywallViewParamsInput | undefined} [params] - additional params.
12
- * @returns {Promise<PaywallViewController>} ViewController — A promise that resolves to a ViewController instance.
13
- *
14
- * @example
15
- * ```ts
16
- * const paywall = await adapty.getPaywall("MY_PAYWALL");
17
- * const view = await createPaywallView(paywall);
18
- * view.present();
19
- * ```
20
- *
21
- * @throws {AdaptyError} — If paywall is not found,
22
- * does not have a no-code view configured
23
- * or if there is an error while creating a view.
24
- */
25
- export declare function createPaywallView(paywall: AdaptyPaywall, params?: CreatePaywallViewParamsInput): Promise<PaywallViewController>;
@@ -1,29 +0,0 @@
1
- import { Adapty } from '../adapty';
2
- import { PaywallViewController } from './paywall-view-controller';
3
- const adaptyPlugin = new Adapty();
4
- /**
5
- * Creates a paywall view controller.
6
- * You can use it to further configure a view or present it.
7
- *
8
- * @see {@link https://adapty.io/docs/capacitor-present-paywalls | [DOC] Creating a paywall view}
9
- *
10
- * @param {AdaptyPaywall} paywall - paywall that you want to present.
11
- * @param {CreatePaywallViewParamsInput | undefined} [params] - additional params.
12
- * @returns {Promise<PaywallViewController>} ViewController — A promise that resolves to a ViewController instance.
13
- *
14
- * @example
15
- * ```ts
16
- * const paywall = await adapty.getPaywall("MY_PAYWALL");
17
- * const view = await createPaywallView(paywall);
18
- * view.present();
19
- * ```
20
- *
21
- * @throws {AdaptyError} — If paywall is not found,
22
- * does not have a no-code view configured
23
- * or if there is an error while creating a view.
24
- */
25
- export async function createPaywallView(paywall, params = {}) {
26
- const controller = await PaywallViewController.create(paywall, params, adaptyPlugin);
27
- return controller;
28
- }
29
- //# sourceMappingURL=create-paywall-view.js.map
@@ -1 +0,0 @@
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 +0,0 @@
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,g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CAAC,EAAE,SAAS,EAAE,CAAC,CACtB,CAAC;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 { 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,16 +0,0 @@
1
- import type { LogContext } from '../logger';
2
- import type { ParsedPaywallEvent, PaywallEventIdType } from '../types/paywall-events';
3
- import { BaseViewEmitter } from './base-view-emitter';
4
- import type { EventHandlers } from './types';
5
- /**
6
- * PaywallViewEmitter manages event handlers for paywall view events.
7
- * Each event type can have only one handler - new handlers replace existing ones.
8
- */
9
- export declare class PaywallViewEmitter extends BaseViewEmitter<EventHandlers, ParsedPaywallEvent, PaywallEventIdType> {
10
- protected parseEventData(rawEventData: string, ctx: LogContext): ParsedPaywallEvent;
11
- protected getNativeEventForHandler(event: keyof EventHandlers): PaywallEventIdType | null;
12
- protected getHandlerForNativeEvent(nativeEvent: PaywallEventIdType, eventData: ParsedPaywallEvent): keyof EventHandlers | null;
13
- protected extractCallbackArgs(handlerName: keyof EventHandlers, eventData: ParsedPaywallEvent): unknown[];
14
- protected getEventViewId(eventData: ParsedPaywallEvent): string | null;
15
- protected getEmitterName(): string;
16
- }
@@ -1,114 +0,0 @@
1
- import { parsePaywallEvent } from '../coders/parse-paywall';
2
- import { PaywallEventId } from '../types/paywall-events';
3
- import { BaseViewEmitter } from './base-view-emitter';
4
- /**
5
- * PaywallViewEmitter manages event handlers for paywall view events.
6
- * Each event type can have only one handler - new handlers replace existing ones.
7
- */
8
- export class PaywallViewEmitter extends BaseViewEmitter {
9
- parseEventData(rawEventData, ctx) {
10
- const result = parsePaywallEvent(rawEventData, ctx);
11
- if (!result) {
12
- throw new Error('Failed to parse paywall event');
13
- }
14
- return result;
15
- }
16
- getNativeEventForHandler(event) {
17
- return HANDLER_TO_NATIVE_EVENT[event];
18
- }
19
- getHandlerForNativeEvent(nativeEvent, eventData) {
20
- const resolver = NATIVE_EVENT_RESOLVER[nativeEvent];
21
- if (!resolver) {
22
- return null;
23
- }
24
- return resolver(eventData);
25
- }
26
- extractCallbackArgs(handlerName, eventData) {
27
- return extractCallbackArgs(handlerName, eventData);
28
- }
29
- getEventViewId(eventData) {
30
- var _a, _b;
31
- return (_b = (_a = eventData === null || eventData === void 0 ? void 0 : eventData.view) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null;
32
- }
33
- getEmitterName() {
34
- return 'PaywallViewEmitter';
35
- }
36
- }
37
- const NATIVE_EVENT_RESOLVER = {
38
- [PaywallEventId.DidPerformAction]: (event) => {
39
- var _a;
40
- if (event.id !== PaywallEventId.DidPerformAction) {
41
- return null;
42
- }
43
- const actionMap = {
44
- close: 'onCloseButtonPress',
45
- system_back: 'onAndroidSystemBack',
46
- open_url: 'onUrlPress',
47
- custom: 'onCustomAction',
48
- };
49
- return (_a = actionMap[event.action.type]) !== null && _a !== void 0 ? _a : null;
50
- },
51
- [PaywallEventId.DidAppear]: () => 'onAppeared',
52
- [PaywallEventId.DidDisappear]: () => 'onDisappeared',
53
- [PaywallEventId.DidSelectProduct]: () => 'onProductSelected',
54
- [PaywallEventId.DidStartPurchase]: () => 'onPurchaseStarted',
55
- [PaywallEventId.DidFinishPurchase]: () => 'onPurchaseCompleted',
56
- [PaywallEventId.DidFailPurchase]: () => 'onPurchaseFailed',
57
- [PaywallEventId.DidStartRestore]: () => 'onRestoreStarted',
58
- [PaywallEventId.DidFinishRestore]: () => 'onRestoreCompleted',
59
- [PaywallEventId.DidFailRestore]: () => 'onRestoreFailed',
60
- [PaywallEventId.DidFailRendering]: () => 'onRenderingFailed',
61
- [PaywallEventId.DidFailLoadingProducts]: () => 'onLoadingProductsFailed',
62
- [PaywallEventId.DidFinishWebPaymentNavigation]: () => 'onWebPaymentNavigationFinished',
63
- };
64
- const HANDLER_TO_NATIVE_EVENT = {
65
- onCloseButtonPress: PaywallEventId.DidPerformAction,
66
- onAndroidSystemBack: PaywallEventId.DidPerformAction,
67
- onUrlPress: PaywallEventId.DidPerformAction,
68
- onCustomAction: PaywallEventId.DidPerformAction,
69
- onProductSelected: PaywallEventId.DidSelectProduct,
70
- onPurchaseStarted: PaywallEventId.DidStartPurchase,
71
- onPurchaseCompleted: PaywallEventId.DidFinishPurchase,
72
- onPurchaseFailed: PaywallEventId.DidFailPurchase,
73
- onRestoreStarted: PaywallEventId.DidStartRestore,
74
- onRestoreCompleted: PaywallEventId.DidFinishRestore,
75
- onRestoreFailed: PaywallEventId.DidFailRestore,
76
- onAppeared: PaywallEventId.DidAppear,
77
- onDisappeared: PaywallEventId.DidDisappear,
78
- onRenderingFailed: PaywallEventId.DidFailRendering,
79
- onLoadingProductsFailed: PaywallEventId.DidFailLoadingProducts,
80
- onWebPaymentNavigationFinished: PaywallEventId.DidFinishWebPaymentNavigation,
81
- };
82
- function extractCallbackArgs(handlerName, event) {
83
- switch (event.id) {
84
- case PaywallEventId.DidSelectProduct:
85
- return [event.productId];
86
- case PaywallEventId.DidStartPurchase:
87
- return [event.product];
88
- case PaywallEventId.DidFinishPurchase:
89
- return [event.purchaseResult, event.product];
90
- case PaywallEventId.DidFailPurchase:
91
- return [event.error, event.product];
92
- case PaywallEventId.DidFinishRestore:
93
- return [event.profile];
94
- case PaywallEventId.DidFailRestore:
95
- case PaywallEventId.DidFailRendering:
96
- case PaywallEventId.DidFailLoadingProducts:
97
- return [event.error];
98
- case PaywallEventId.DidPerformAction:
99
- if (handlerName === 'onUrlPress' && event.action.type === 'open_url') {
100
- return [event.action.value, event.action.openIn];
101
- }
102
- if (handlerName === 'onCustomAction' && event.action.type === 'custom') {
103
- return [event.action.value];
104
- }
105
- return [];
106
- case PaywallEventId.DidFinishWebPaymentNavigation:
107
- return [event.product, event.error];
108
- case PaywallEventId.DidAppear:
109
- case PaywallEventId.DidDisappear:
110
- case PaywallEventId.DidStartRestore:
111
- return [];
112
- }
113
- }
114
- //# sourceMappingURL=paywall-view-emitter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"paywall-view-emitter.js","sourceRo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cAAc,CAAC,gBAAgB,CAAC;QACrC,KAAK,cAAc,CAAC,sBAAsB;YACxC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAqB,CAAC;QAE3C,KAAK,cAAc,CAAC,gBAAgB;YAClC,IAAI,WAAW,KAAK,YAAY,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBACrE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAqB,CAAC;YACvE,CAAC;YACD,IAAI,WAAW,KAAK,gBAAgB,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACvE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAqB,CAAC;YAClD,CAAC;YACD,OAAO,EAAsB,CAAC;QAEhC,KAAK,cAAc,CAAC,6BAA6B;YAC/C,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAgC,CAAC;QAErE,KAAK,cAAc,CAAC,SAAS,CAAC;QAC9B,KAAK,cAAc,CAAC,YAAY,CAAC;QACjC,KAAK,cAAc,CAAC,eAAe;YACjC,OAAO,EAAsB,CAAC;IAClC,CAAC;AACH,CAAC","sourcesContent":["import { parsePaywallEvent } from '../coders/parse-paywall';\nimport type { LogContext } from '../logger';\nimport { PaywallEventId } from '../types/paywall-events';\nimport type { ParsedPaywallEvent, PaywallEventIdType } from '../types/paywall-events';\n\nimport { BaseViewEmitter } from './base-view-emitter';\nimport type { EventHandlers } from './types';\n\ntype EventName = keyof EventHandlers;\n\n/**\n * PaywallViewEmitter manages event handlers for paywall view events.\n * Each event type can have only one handler - new handlers replace existing ones.\n */\nexport class PaywallViewEmitter extends BaseViewEmitter<EventHandlers, ParsedPaywallEvent, PaywallEventIdType> {\n protected parseEventData(rawEventData: string, ctx: LogContext): ParsedPaywallEvent {\n const result = parsePaywallEvent(rawEventData, ctx);\n if (!result) {\n throw new Error('Failed to parse paywall event');\n }\n return result;\n }\n\n protected getNativeEventForHandler(event: keyof EventHandlers): PaywallEventIdType | null {\n return HANDLER_TO_NATIVE_EVENT[event as EventName];\n }\n\n protected getHandlerForNativeEvent(\n nativeEvent: PaywallEventIdType,\n eventData: ParsedPaywallEvent,\n ): keyof EventHandlers | null {\n const resolver = NATIVE_EVENT_RESOLVER[nativeEvent];\n if (!resolver) {\n return null;\n }\n return resolver(eventData) as keyof EventHandlers | null;\n }\n\n protected extractCallbackArgs(handlerName: keyof EventHandlers, eventData: ParsedPaywallEvent): unknown[] {\n return extractCallbackArgs(handlerName as EventName, eventData);\n }\n\n protected getEventViewId(eventData: ParsedPaywallEvent): string | null {\n return eventData?.view?.id ?? null;\n }\n\n protected getEmitterName(): string {\n return 'PaywallViewEmitter';\n }\n}\n\nconst NATIVE_EVENT_RESOLVER: Record<PaywallEventIdType, (event: ParsedPaywallEvent) => EventName | null> = {\n [PaywallEventId.DidPerformAction]: (event) => {\n if (event.id !== PaywallEventId.DidPerformAction) {\n return null;\n }\n\n const actionMap: Record<string, EventName> = {\n close: 'onCloseButtonPress',\n system_back: 'onAndroidSystemBack',\n open_url: 'onUrlPress',\n custom: 'onCustomAction',\n };\n\n return actionMap[event.action.type] ?? null;\n },\n [PaywallEventId.DidAppear]: () => 'onAppeared',\n [PaywallEventId.DidDisappear]: () => 'onDisappeared',\n [PaywallEventId.DidSelectProduct]: () => 'onProductSelected',\n [PaywallEventId.DidStartPurchase]: () => 'onPurchaseStarted',\n [PaywallEventId.DidFinishPurchase]: () => 'onPurchaseCompleted',\n [PaywallEventId.DidFailPurchase]: () => 'onPurchaseFailed',\n [PaywallEventId.DidStartRestore]: () => 'onRestoreStarted',\n [PaywallEventId.DidFinishRestore]: () => 'onRestoreCompleted',\n [PaywallEventId.DidFailRestore]: () => 'onRestoreFailed',\n [PaywallEventId.DidFailRendering]: () => 'onRenderingFailed',\n [PaywallEventId.DidFailLoadingProducts]: () => 'onLoadingProductsFailed',\n [PaywallEventId.DidFinishWebPaymentNavigation]: () => 'onWebPaymentNavigationFinished',\n};\n\nconst HANDLER_TO_NATIVE_EVENT: Record<EventName, PaywallEventIdType> = {\n onCloseButtonPress: PaywallEventId.DidPerformAction,\n onAndroidSystemBack: PaywallEventId.DidPerformAction,\n onUrlPress: PaywallEventId.DidPerformAction,\n onCustomAction: PaywallEventId.DidPerformAction,\n onProductSelected: PaywallEventId.DidSelectProduct,\n onPurchaseStarted: PaywallEventId.DidStartPurchase,\n onPurchaseCompleted: PaywallEventId.DidFinishPurchase,\n onPurchaseFailed: PaywallEventId.DidFailPurchase,\n onRestoreStarted: PaywallEventId.DidStartRestore,\n onRestoreCompleted: PaywallEventId.DidFinishRestore,\n onRestoreFailed: PaywallEventId.DidFailRestore,\n onAppeared: PaywallEventId.DidAppear,\n onDisappeared: PaywallEventId.DidDisappear,\n onRenderingFailed: PaywallEventId.DidFailRendering,\n onLoadingProductsFailed: PaywallEventId.DidFailLoadingProducts,\n onWebPaymentNavigationFinished: PaywallEventId.DidFinishWebPaymentNavigation,\n};\n\ntype ExtractedArgs<T extends keyof EventHandlers> = Parameters<EventHandlers[T]>;\n\nfunction extractCallbackArgs<T extends keyof EventHandlers>(\n handlerName: T,\n event: ParsedPaywallEvent,\n): ExtractedArgs<T> {\n switch (event.id) {\n case PaywallEventId.DidSelectProduct:\n return [event.productId] as ExtractedArgs<T>;\n\n case PaywallEventId.DidStartPurchase:\n return [event.product] as ExtractedArgs<T>;\n\n case PaywallEventId.DidFinishPurchase:\n return [event.purchaseResult, event.product] as ExtractedArgs<T>;\n\n case PaywallEventId.DidFailPurchase:\n return [event.error, event.product] as ExtractedArgs<T>;\n\n case PaywallEventId.DidFinishRestore:\n return [event.profile] as ExtractedArgs<T>;\n\n case PaywallEventId.DidFailRestore:\n case PaywallEventId.DidFailRendering:\n case PaywallEventId.DidFailLoadingProducts:\n return [event.error] as ExtractedArgs<T>;\n\n case PaywallEventId.DidPerformAction:\n if (handlerName === 'onUrlPress' && event.action.type === 'open_url') {\n return [event.action.value, event.action.openIn] as ExtractedArgs<T>;\n }\n if (handlerName === 'onCustomAction' && event.action.type === 'custom') {\n return [event.action.value] as ExtractedArgs<T>;\n }\n return [] as ExtractedArgs<T>;\n\n case PaywallEventId.DidFinishWebPaymentNavigation:\n return [event.product, event.error] as unknown as ExtractedArgs<T>;\n\n case PaywallEventId.DidAppear:\n case PaywallEventId.DidDisappear:\n case PaywallEventId.DidStartRestore:\n return [] as ExtractedArgs<T>;\n }\n}\n"]}