@adapty/capacitor 3.15.0 → 3.16.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/AdaptyCapacitor.podspec +1 -0
  2. package/Package.swift +1 -1
  3. package/README.md +9 -0
  4. package/android/build.gradle +23 -18
  5. package/dist/esm/adapty-emitter.js.map +1 -1
  6. package/dist/esm/adapty.js.map +1 -1
  7. package/dist/esm/shared/adapty-error.js.map +1 -1
  8. package/dist/esm/shared/coders/adapty-configuration.js.map +1 -1
  9. package/dist/esm/shared/coders/adapty-identify-params.js.map +1 -1
  10. package/dist/esm/shared/coders/adapty-installation-details.js.map +1 -1
  11. package/dist/esm/shared/coders/adapty-installation-status.js.map +1 -1
  12. package/dist/esm/shared/coders/adapty-paywall-product.js +1 -1
  13. package/dist/esm/shared/coders/adapty-paywall-product.js.map +1 -1
  14. package/dist/esm/shared/coders/adapty-purchase-params.js.map +1 -1
  15. package/dist/esm/shared/coders/adapty-purchase-result.js.map +1 -1
  16. package/dist/esm/shared/coders/adapty-subscription-offer.js.map +1 -1
  17. package/dist/esm/shared/coders/adapty-ui-create-onboarding-view-params.js.map +1 -1
  18. package/dist/esm/shared/coders/adapty-ui-create-paywall-view-params.js.map +1 -1
  19. package/dist/esm/shared/coders/adapty-ui-onboarding-state-updated-action.js.map +1 -1
  20. package/dist/esm/shared/coders/bridge-error.js.map +1 -1
  21. package/dist/esm/shared/coders/coder.js.map +1 -1
  22. package/dist/esm/shared/coders/date.js.map +1 -1
  23. package/dist/esm/shared/coders/json.js.map +1 -1
  24. package/dist/esm/shared/coders/parse-onboarding.js.map +1 -1
  25. package/dist/esm/shared/coders/parse-paywall.js.map +1 -1
  26. package/dist/esm/shared/coders/parse.js.map +1 -1
  27. package/dist/esm/shared/coders/utils.js.map +1 -1
  28. package/dist/esm/shared/logger/console-sink.js.map +1 -1
  29. package/dist/esm/shared/logger/log.js.map +1 -1
  30. package/dist/esm/shared/types/error.js.map +1 -1
  31. package/dist/esm/shared/utils/merge-options.js.map +1 -1
  32. package/dist/esm/shared/utils/with-error-context.js.map +1 -1
  33. package/dist/esm/ui-builder/base-view-emitter.js.map +1 -1
  34. package/dist/esm/ui-builder/onboarding-view-controller.js.map +1 -1
  35. package/dist/esm/ui-builder/onboarding-view-emitter.js.map +1 -1
  36. package/dist/esm/ui-builder/paywall-view-controller.js.map +1 -1
  37. package/dist/esm/ui-builder/paywall-view-emitter.js.map +1 -1
  38. package/dist/esm/ui-builder/types.js.map +1 -1
  39. package/dist/esm/version.d.ts +1 -1
  40. package/dist/esm/version.js +1 -1
  41. package/dist/esm/version.js.map +1 -1
  42. package/dist/plugin.cjs.js +2 -2
  43. package/dist/plugin.cjs.js.map +1 -1
  44. package/dist/plugin.js +2 -2
  45. package/dist/plugin.js.map +1 -1
  46. package/package.json +12 -13
@@ -1 +1 @@
1
- {"version":3,"file":"log.js","sourceRoot":"","sources":["../../../../src/shared/logger/log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,OAAO,MAAM,eAAe,CAAC;AAMpC,MAAM,OAAO,GAAG;IAKd,gCAAgC;IACxB,MAAM,CAAC,aAAa,CAAC,OAAe,EAAE,QAAgB;QAC5D,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACrC,MAAM,OAAO,GAAG,OAAO,CAAC;QAExB,OAAO,IAAI,GAAG,aAAa,OAAO,MAAM,QAAQ,MAAM,OAAO,EAAE,CAAC;IAClE,CAAC;IAGD,qEAAqE;IAC9D,MAAM,CAAC,SAAS,CAAC,MAAoB;;QAC1C,IAAI,MAAM,CAAC,KAAK,EAAE;YAChB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK;gBAAE,MAAA,IAAI,CAAC,OAAO,oDAAI,CAAC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CAAC,IAAI,CAChB,QAAgB,EAChB,OAAoB,EACpB,MAAmB;QAEnB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACrD,CAAC;IAEM,MAAM,CAAC,IAAI,CAChB,QAAgB,EAChB,OAAoB,EACpB,MAAmB;QAEnB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACrD,CAAC;IAEM,MAAM,CAAC,KAAK,CACjB,QAAgB,EAChB,OAAoB,EACpB,MAAmB;QAEnB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACtD,CAAC;IAEM,MAAM,CAAC,OAAO,CACnB,QAAgB,EAChB,OAAoB,EACpB,MAAmB;QAEnB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;;AAzIa,YAAQ,GAAoB,IAAI,CAAC;AAChC,SAAK,GAAc,CAAC,cAAc,CAAC,CAAC","sourcesContent":["import { LogLevel } from '../types/inputs';\nimport type { LogEvent, LogSink, LoggerConfig } from './types';\nimport { consoleLogSink } from './console-sink';\n\nimport VERSION from '../../version';\n\n// Type for lazy evaluation functions\ntype LazyMessage = () => string;\ntype LazyParams = () => Record<string, any>;\n\nexport class Log {\n public static logLevel: LogLevel | null = null;\n private static sinks: LogSink[] = [consoleLogSink];\n private static defaultMeta?: LoggerConfig['defaultMeta'];\n\n // Formats a message for logging\n private static formatMessage(message: string, funcName: string): string {\n const now = new Date().toISOString();\n const version = VERSION;\n\n return `[${now}] [adapty@${version}] \"${funcName}\": ${message}`;\n }\n\n\n /** Configure JS logger: replace sinks and/or set default metadata */\n public static configure(config: LoggerConfig): void {\n if (config.sinks) {\n for (const sink of this.sinks) sink.destroy?.();\n this.sinks = config.sinks.slice();\n }\n this.defaultMeta = config.defaultMeta;\n }\n\n /** Register additional sink */\n public static addSink(sink: LogSink): void {\n this.sinks.push(sink);\n }\n\n /** Remove sink by id and call its destroy if present */\n public static removeSink(id: string): void {\n const sink = this.sinks.find(sink => sink.id === id);\n this.sinks = this.sinks.filter(sink => sink.id !== id);\n sink?.destroy?.();\n }\n\n /** Clear all sinks and destroy them */\n public static clearSinks(): void {\n const prev = this.sinks;\n this.sinks = [];\n for (const sink of prev) sink.destroy?.();\n }\n\n /**\n * Gets the appropriate log level integer for a log level.\n * @internal\n */\n private static getLogLevelInt(logLevel: LogLevel): number {\n switch (logLevel) {\n case LogLevel.ERROR:\n return 0;\n case LogLevel.WARN:\n return 1;\n case LogLevel.INFO:\n return 2;\n case LogLevel.VERBOSE:\n return 3;\n }\n }\n\n /**\n * Logs a message to the console if the log level is appropriate.\n * Uses lazy evaluation to avoid unnecessary computations.\n * @internal\n */\n public static log(\n logLevel: LogLevel,\n funcName: string,\n message: LazyMessage,\n params?: LazyParams,\n ): void {\n if (!Log.logLevel) {\n return;\n }\n\n const currentLevel = Log.getLogLevelInt(Log.logLevel);\n const messageLevel = Log.getLogLevelInt(logLevel);\n\n if (messageLevel <= currentLevel) {\n // Lazy evaluation: only compute once per entry\n const resolvedMessage = message();\n const resolvedParams = params ? params() : undefined;\n const mergedParams =\n this.defaultMeta\n ? { ...(this.defaultMeta as Record<string, unknown>), ...(resolvedParams ?? {}) }\n : resolvedParams;\n\n const formatted = Log.formatMessage(resolvedMessage, funcName);\n const event: LogEvent = {\n timestamp: new Date().toISOString(),\n version: String(VERSION),\n level: logLevel,\n funcName,\n message: resolvedMessage,\n params: mergedParams,\n formatted,\n };\n\n for (const sink of this.sinks) {\n if (sink.levels && !sink.levels.includes(logLevel)) continue;\n try {\n sink.handle(event);\n } catch {\n // ignore sink errors\n }\n }\n }\n }\n\n public static info(\n funcName: string,\n message: LazyMessage,\n params?: LazyParams,\n ): void {\n this.log(LogLevel.INFO, funcName, message, params);\n }\n\n public static warn(\n funcName: string,\n message: LazyMessage,\n params?: LazyParams,\n ): void {\n this.log(LogLevel.WARN, funcName, message, params);\n }\n\n public static error(\n funcName: string,\n message: LazyMessage,\n params?: LazyParams,\n ): void {\n this.log(LogLevel.ERROR, funcName, message, params);\n }\n\n public static verbose(\n funcName: string,\n message: LazyMessage,\n params?: LazyParams,\n ): void {\n this.log(LogLevel.VERBOSE, funcName, message, params);\n }\n}\n"]}
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../../../../src/shared/logger/log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,OAAO,MAAM,eAAe,CAAC;AAMpC,MAAM,OAAO,GAAG;IAKd,gCAAgC;IACxB,MAAM,CAAC,aAAa,CAAC,OAAe,EAAE,QAAgB;QAC5D,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACrC,MAAM,OAAO,GAAG,OAAO,CAAC;QAExB,OAAO,IAAI,GAAG,aAAa,OAAO,MAAM,QAAQ,MAAM,OAAO,EAAE,CAAC;IAClE,CAAC;IAGD,qEAAqE;IAC9D,MAAM,CAAC,SAAS,CAAC,MAAoB;;QAC1C,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK;gBAAE,MAAA,IAAI,CAAC,OAAO,oDAAI,CAAC;YAChD,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACpC,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;IACxC,CAAC;IAED,+BAA+B;IACxB,MAAM,CAAC,OAAO,CAAC,IAAa;QACjC,IAAI,CAAC,KAAK,CAAC,IAAI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CAAC;IAEM,MAAM,CAAC,IAAI,CAChB,QAAgB,EAChB,OAAoB,EACpB,MAAmB;QAEnB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACrD,CAAC;IAEM,MAAM,CAAC,KAAK,CACjB,QAAgB,EAChB,OAAoB,EACpB,MAAmB;QAEnB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACtD,CAAC;IAEM,MAAM,CAAC,OAAO,CACnB,QAAgB,EAChB,OAAoB,EACpB,MAAmB;QAEnB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;;AAzIa,YAAQ,GAAoB,IAAI,CAAC;AAChC,SAAK,GAAc,CAAC,cAAc,CAAC,CAAC","sourcesContent":["import { LogLevel } from '../types/inputs';\nimport type { LogEvent, LogSink, LoggerConfig } from './types';\nimport { consoleLogSink } from './console-sink';\n\nimport VERSION from '../../version';\n\n// Type for lazy evaluation functions\ntype LazyMessage = () => string;\ntype LazyParams = () => Record<string, any>;\n\nexport class Log {\n public static logLevel: LogLevel | null = null;\n private static sinks: LogSink[] = [consoleLogSink];\n private static defaultMeta?: LoggerConfig['defaultMeta'];\n\n // Formats a message for logging\n private static formatMessage(message: string, funcName: string): string {\n const now = new Date().toISOString();\n const version = VERSION;\n\n return `[${now}] [adapty@${version}] \"${funcName}\": ${message}`;\n }\n\n\n /** Configure JS logger: replace sinks and/or set default metadata */\n public static configure(config: LoggerConfig): void {\n if (config.sinks) {\n for (const sink of this.sinks) sink.destroy?.();\n this.sinks = config.sinks.slice();\n }\n this.defaultMeta = config.defaultMeta;\n }\n\n /** Register additional sink */\n public static addSink(sink: LogSink): void {\n this.sinks.push(sink);\n }\n\n /** Remove sink by id and call its destroy if present */\n public static removeSink(id: string): void {\n const sink = this.sinks.find(sink => sink.id === id);\n this.sinks = this.sinks.filter(sink => sink.id !== id);\n sink?.destroy?.();\n }\n\n /** Clear all sinks and destroy them */\n public static clearSinks(): void {\n const prev = this.sinks;\n this.sinks = [];\n for (const sink of prev) sink.destroy?.();\n }\n\n /**\n * Gets the appropriate log level integer for a log level.\n * @internal\n */\n private static getLogLevelInt(logLevel: LogLevel): number {\n switch (logLevel) {\n case LogLevel.ERROR:\n return 0;\n case LogLevel.WARN:\n return 1;\n case LogLevel.INFO:\n return 2;\n case LogLevel.VERBOSE:\n return 3;\n }\n }\n\n /**\n * Logs a message to the console if the log level is appropriate.\n * Uses lazy evaluation to avoid unnecessary computations.\n * @internal\n */\n public static log(\n logLevel: LogLevel,\n funcName: string,\n message: LazyMessage,\n params?: LazyParams,\n ): void {\n if (!Log.logLevel) {\n return;\n }\n\n const currentLevel = Log.getLogLevelInt(Log.logLevel);\n const messageLevel = Log.getLogLevelInt(logLevel);\n\n if (messageLevel <= currentLevel) {\n // Lazy evaluation: only compute once per entry\n const resolvedMessage = message();\n const resolvedParams = params ? params() : undefined;\n const mergedParams =\n this.defaultMeta\n ? { ...(this.defaultMeta as Record<string, unknown>), ...(resolvedParams ?? {}) }\n : resolvedParams;\n\n const formatted = Log.formatMessage(resolvedMessage, funcName);\n const event: LogEvent = {\n timestamp: new Date().toISOString(),\n version: String(VERSION),\n level: logLevel,\n funcName,\n message: resolvedMessage,\n params: mergedParams,\n formatted,\n };\n\n for (const sink of this.sinks) {\n if (sink.levels && !sink.levels.includes(logLevel)) continue;\n try {\n sink.handle(event);\n } catch {\n // ignore sink errors\n }\n }\n }\n }\n\n public static info(\n funcName: string,\n message: LazyMessage,\n params?: LazyParams,\n ): void {\n this.log(LogLevel.INFO, funcName, message, params);\n }\n\n public static warn(\n funcName: string,\n message: LazyMessage,\n params?: LazyParams,\n ): void {\n this.log(LogLevel.WARN, funcName, message, params);\n }\n\n public static error(\n funcName: string,\n message: LazyMessage,\n params?: LazyParams,\n ): void {\n this.log(LogLevel.ERROR, funcName, message, params);\n }\n\n public static verbose(\n funcName: string,\n message: LazyMessage,\n params?: LazyParams,\n ): void {\n this.log(LogLevel.VERBOSE, funcName, message, params);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../../src/shared/types/error.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,+CAA+C;AAE/C,MAAM,gBAAgB,GAAG;IACvB;;OAEG;IACH,CAAC,EAAE,SAAS;IACZ;;OAEG;IACH,CAAC,EAAE,eAAe;IAClB;;OAEG;IACH,CAAC,EAAE,gBAAgB;IACnB;;OAEG;IACH,CAAC,EAAE,mBAAmB;IACtB;;OAEG;IACH,CAAC,EAAE,0BAA0B;IAE7B;;OAEG;IACH,CAAC,EAAE,8BAA8B;IAEjC;;OAEG;IACH,CAAC,EAAE,qCAAqC;IAExC;;OAEG;IACH,CAAC,EAAE,qBAAqB;IAExB;;OAEG;IACH,CAAC,EAAE,gCAAgC;IAEnC;;;OAGG;IACH,EAAE,EAAE,yBAAyB;IAE7B;;OAEG;IACH,EAAE,EAAE,wBAAwB;IAE5B;;OAEG;IACH,EAAE,EAAE,kBAAkB;IAEtB;;OAEG;IACH,EAAE,EAAE,oBAAoB;IAExB,EAAE,EAAE,mBAAmB;IAEvB;;OAEG;IACH,EAAE,EAAE,sBAAsB;IAC1B,EAAE,EAAE,iBAAiB;IACrB,EAAE,EAAE,8CAA8C;IAClD,EAAE,EAAE,uBAAuB;IAC3B,EAAE,EAAE,qBAAqB;IACzB,EAAE,EAAE,4BAA4B;IAChC,GAAG,EAAE,2BAA2B;IAChC,GAAG,EAAE,oBAAoB;IACzB,GAAG,EAAE,gBAAgB;IACrB,GAAG,EAAE,cAAc;IACnB,GAAG,EAAE,kBAAkB;IACvB,GAAG,EAAE,cAAc;IACnB,GAAG,EAAE,qBAAqB;IAE1B,IAAI,EAAE,mBAAmB;IACzB,IAAI,EAAE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AAE;IACvB,0BAA0B,EAAE,EAAE;IAC9B,yBAAyB,EAAE,GAAG;IAC9B,kBAAkB,EAAE,GAAG;IACvB,cAAc,EAAE,GAAG;IACnB,YAAY,EAAE,GAAG;IACjB,gBAAgB,EAAE,GAAG;IACrB,YAAY,EAAE,GAAG;IACjB,mBAAmB,EAAE,GAAG;IACxB,iBAAiB,EAAE,IAAI;IACvB,oBAAoB,EAAE,IAAI;IAC1B,gBAAgB,EAAE,IAAI;IACtB,oBAAoB,EAAE,IAAI;IAC1B,eAAe,EAAE,IAAI;IACrB,qBAAqB,EAAE,IAAI;IAC3B,oBAAoB,EAAE,IAAI;IAC1B,iCAAiC,EAAE,IAAI;IACvC,YAAY,EAAE,IAAI;IAClB,UAAU,EAAE,IAAI;IAChB,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,IAAI;IACnB,cAAc,EAAE,IAAI;IACpB,cAAc,EAAE,IAAI;IACpB,iBAAiB,EAAE,IAAI;IACvB,UAAU,EAAE,IAAI;IAChB,iBAAiB,EAAE,IAAI;IACvB,iBAAiB,EAAE,IAAI;IACvB,eAAe,EAAE,IAAI;IACrB,mBAAmB,EAAE,IAAI;IACzB,iBAAiB,EAAE,IAAI;IACvB,oBAAoB,EAAE,IAAI;CAClB,CAAC,CAAC;AAIZ,MAAM,CAAC,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAGlD,MAAM,UAAU,YAAY,CAAC,IAAmB;;IAC9C,OAAO,MAAA,aAAa,CAAC,IAAI,CAAC,mCAAI,SAAS,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAe;IAC5C,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAE/B,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,iBAAiB,IAAI,EAAmC,CAAC;KACjE;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// import SDK type to link to methods in docs.\n// import { AdaptyError } from '../sdk2/error';\n\nconst ErrorCodeMapping = {\n /**\n * System StoreKit codes\n */\n 0: 'unknown',\n /**\n * Client is not allowed to make a request, etc.\n */\n 1: 'clientInvalid',\n /**\n * Invalid purchase identifier, etc.\n */\n 3: 'paymentInvalid',\n /**\n * This device is not allowed to make the payment.\n */\n 4: 'paymentNotAllowed',\n /**\n * Product is not available in the current storefront.\n */\n 5: 'storeProductNotAvailable',\n\n /**\n * User has not allowed access to cloud service information.\n */\n 6: 'cloudServicePermissionDenied',\n\n /**\n * The device could not connect to the network.\n */\n 7: 'cloudServiceNetworkConnectionFailed',\n\n /**\n * User has revoked permission to use this cloud service.\n */\n 8: 'cloudServiceRevoked',\n\n /**\n * The user needs to acknowledge Apple's privacy policy.\n */\n 9: 'privacyAcknowledgementRequired',\n\n /**\n * The app is attempting to use SKPayment's requestData property,\n * but does not have the appropriate entitlement.\n */\n 10: 'unauthorizedRequestData',\n\n /**\n * The specified subscription offer identifier is not valid.\n */\n 11: 'invalidOfferIdentifier',\n\n /**\n * The cryptographic signature provided is not valid.\n */\n 12: 'invalidSignature',\n\n /**\n * One or more parameters from SKPaymentDiscount is missing.\n */\n 13: 'missingOfferParams',\n\n 14: 'invalidOfferPrice',\n\n /**\n * Custom Android codes.\n */\n 20: 'adaptyNotInitialized',\n 22: 'productNotFound',\n 24: 'currentSubscriptionToUpdateNotFoundInHistory',\n 97: 'billingServiceTimeout',\n 98: 'featureNotSupported',\n 99: 'billingServiceDisconnected',\n 102: 'billingServiceUnavailable',\n 103: 'billingUnavailable',\n 105: 'developerError',\n 106: 'billingError',\n 107: 'itemAlreadyOwned',\n 108: 'itemNotOwned',\n 112: 'billingNetworkError',\n\n 1000: 'noProductIDsFound',\n 1002: 'productRequestFailed',\n\n /**\n * In-App Purchases are not allowed on this device.\n */\n 1003: 'cantMakePayments',\n 1004: 'noPurchasesToRestore',\n 1005: 'cantReadReceipt',\n 1006: 'productPurchaseFailed',\n 1010: 'refreshReceiptFailed',\n 1011: 'receiveRestoredTransactionsFailed',\n\n /**\n * You need to be authenticated to perform requests.\n */\n 2002: 'notActivated',\n 2003: 'badRequest',\n 2004: 'serverError',\n 2005: 'networkFailed',\n 2006: 'decodingFailed',\n 2009: 'encodingFailed',\n\n 3000: 'analyticsDisabled',\n /**\n * Wrong parameter was passed.\n */\n 3001: 'wrongParam',\n /**\n * It is not possible to call `.activate` method more than once.\n */\n 3005: 'activateOnceError',\n /**\n * The user profile was changed during the operation.\n */\n 3006: 'profileWasChanged',\n 3007: 'unsupportedData',\n 3100: 'persistingDataError',\n 3101: 'fetchTimeoutError',\n 9000: 'operationInterrupted',\n} as const;\n\nexport const ErrorCode = Object.freeze(ErrorCodeMapping);\n\nconst ErrorCodeNameMapping = Object.freeze({\n unknown: 0,\n clientInvalid: 1,\n paymentInvalid: 3,\n paymentNotAllowed: 4,\n storeProductNotAvailable: 5,\n cloudServicePermissionDenied: 6,\n cloudServiceNetworkConnectionFailed: 7,\n cloudServiceRevoked: 8,\n privacyAcknowledgementRequired: 9,\n unauthorizedRequestData: 10,\n invalidOfferIdentifier: 11,\n invalidSignature: 12,\n missingOfferParams: 13,\n invalidOfferPrice: 14,\n adaptyNotInitialized: 20,\n productNotFound: 22,\n currentSubscriptionToUpdateNotFoundInHistory: 24,\n billingServiceTimeout: 97,\n featureNotSupported: 98,\n billingServiceDisconnected: 99,\n billingServiceUnavailable: 102,\n billingUnavailable: 103,\n developerError: 105,\n billingError: 106,\n itemAlreadyOwned: 107,\n itemNotOwned: 108,\n billingNetworkError: 112,\n noProductIDsFound: 1000,\n productRequestFailed: 1002,\n cantMakePayments: 1003,\n noPurchasesToRestore: 1004,\n cantReadReceipt: 1005,\n productPurchaseFailed: 1006,\n refreshReceiptFailed: 1010,\n receiveRestoredTransactionsFailed: 1011,\n notActivated: 2002,\n badRequest: 2003,\n serverError: 2004,\n networkFailed: 2005,\n decodingFailed: 2006,\n encodingFailed: 2009,\n analyticsDisabled: 3000,\n wrongParam: 3001,\n activateOnceError: 3005,\n profileWasChanged: 3006,\n unsupportedData: 3007,\n persistingDataError: 3100,\n fetchTimeoutError: 3101,\n operationInterrupted: 9000,\n} as const);\n\nexport type ErrorCode = keyof typeof ErrorCodeMapping;\n\nexport const ErrorCodeName = ErrorCodeNameMapping;\nexport type ErrorCodeName = keyof typeof ErrorCodeNameMapping;\n\nexport function getErrorCode(name: ErrorCodeName): ErrorCode | undefined {\n return ErrorCodeName[name] ?? undefined;\n}\n\nexport function getErrorPrompt(code: ErrorCode): (typeof ErrorCode)[ErrorCode] {\n const prompt = ErrorCode[code];\n\n if (!prompt) {\n return `Unknown code: ${code}` as (typeof ErrorCode)[ErrorCode];\n }\n\n return prompt;\n}\n"]}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../../src/shared/types/error.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,+CAA+C;AAE/C,MAAM,gBAAgB,GAAG;IACvB;;OAEG;IACH,CAAC,EAAE,SAAS;IACZ;;OAEG;IACH,CAAC,EAAE,eAAe;IAClB;;OAEG;IACH,CAAC,EAAE,gBAAgB;IACnB;;OAEG;IACH,CAAC,EAAE,mBAAmB;IACtB;;OAEG;IACH,CAAC,EAAE,0BAA0B;IAE7B;;OAEG;IACH,CAAC,EAAE,8BAA8B;IAEjC;;OAEG;IACH,CAAC,EAAE,qCAAqC;IAExC;;OAEG;IACH,CAAC,EAAE,qBAAqB;IAExB;;OAEG;IACH,CAAC,EAAE,gCAAgC;IAEnC;;;OAGG;IACH,EAAE,EAAE,yBAAyB;IAE7B;;OAEG;IACH,EAAE,EAAE,wBAAwB;IAE5B;;OAEG;IACH,EAAE,EAAE,kBAAkB;IAEtB;;OAEG;IACH,EAAE,EAAE,oBAAoB;IAExB,EAAE,EAAE,mBAAmB;IAEvB;;OAEG;IACH,EAAE,EAAE,sBAAsB;IAC1B,EAAE,EAAE,iBAAiB;IACrB,EAAE,EAAE,8CAA8C;IAClD,EAAE,EAAE,uBAAuB;IAC3B,EAAE,EAAE,qBAAqB;IACzB,EAAE,EAAE,4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C5C,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAE/B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,iBAAiB,IAAI,EAAmC,CAAC;IAClE,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// import SDK type to link to methods in docs.\n// import { AdaptyError } from '../sdk2/error';\n\nconst ErrorCodeMapping = {\n /**\n * System StoreKit codes\n */\n 0: 'unknown',\n /**\n * Client is not allowed to make a request, etc.\n */\n 1: 'clientInvalid',\n /**\n * Invalid purchase identifier, etc.\n */\n 3: 'paymentInvalid',\n /**\n * This device is not allowed to make the payment.\n */\n 4: 'paymentNotAllowed',\n /**\n * Product is not available in the current storefront.\n */\n 5: 'storeProductNotAvailable',\n\n /**\n * User has not allowed access to cloud service information.\n */\n 6: 'cloudServicePermissionDenied',\n\n /**\n * The device could not connect to the network.\n */\n 7: 'cloudServiceNetworkConnectionFailed',\n\n /**\n * User has revoked permission to use this cloud service.\n */\n 8: 'cloudServiceRevoked',\n\n /**\n * The user needs to acknowledge Apple's privacy policy.\n */\n 9: 'privacyAcknowledgementRequired',\n\n /**\n * The app is attempting to use SKPayment's requestData property,\n * but does not have the appropriate entitlement.\n */\n 10: 'unauthorizedRequestData',\n\n /**\n * The specified subscription offer identifier is not valid.\n */\n 11: 'invalidOfferIdentifier',\n\n /**\n * The cryptographic signature provided is not valid.\n */\n 12: 'invalidSignature',\n\n /**\n * One or more parameters from SKPaymentDiscount is missing.\n */\n 13: 'missingOfferParams',\n\n 14: 'invalidOfferPrice',\n\n /**\n * Custom Android codes.\n */\n 20: 'adaptyNotInitialized',\n 22: 'productNotFound',\n 24: 'currentSubscriptionToUpdateNotFoundInHistory',\n 97: 'billingServiceTimeout',\n 98: 'featureNotSupported',\n 99: 'billingServiceDisconnected',\n 102: 'billingServiceUnavailable',\n 103: 'billingUnavailable',\n 105: 'developerError',\n 106: 'billingError',\n 107: 'itemAlreadyOwned',\n 108: 'itemNotOwned',\n 112: 'billingNetworkError',\n\n 1000: 'noProductIDsFound',\n 1002: 'productRequestFailed',\n\n /**\n * In-App Purchases are not allowed on this device.\n */\n 1003: 'cantMakePayments',\n 1004: 'noPurchasesToRestore',\n 1005: 'cantReadReceipt',\n 1006: 'productPurchaseFailed',\n 1010: 'refreshReceiptFailed',\n 1011: 'receiveRestoredTransactionsFailed',\n\n /**\n * You need to be authenticated to perform requests.\n */\n 2002: 'notActivated',\n 2003: 'badRequest',\n 2004: 'serverError',\n 2005: 'networkFailed',\n 2006: 'decodingFailed',\n 2009: 'encodingFailed',\n\n 3000: 'analyticsDisabled',\n /**\n * Wrong parameter was passed.\n */\n 3001: 'wrongParam',\n /**\n * It is not possible to call `.activate` method more than once.\n */\n 3005: 'activateOnceError',\n /**\n * The user profile was changed during the operation.\n */\n 3006: 'profileWasChanged',\n 3007: 'unsupportedData',\n 3100: 'persistingDataError',\n 3101: 'fetchTimeoutError',\n 9000: 'operationInterrupted',\n} as const;\n\nexport const ErrorCode = Object.freeze(ErrorCodeMapping);\n\nconst ErrorCodeNameMapping = Object.freeze({\n unknown: 0,\n clientInvalid: 1,\n paymentInvalid: 3,\n paymentNotAllowed: 4,\n storeProductNotAvailable: 5,\n cloudServicePermissionDenied: 6,\n cloudServiceNetworkConnectionFailed: 7,\n cloudServiceRevoked: 8,\n privacyAcknowledgementRequired: 9,\n unauthorizedRequestData: 10,\n invalidOfferIdentifier: 11,\n invalidSignature: 12,\n missingOfferParams: 13,\n invalidOfferPrice: 14,\n adaptyNotInitialized: 20,\n productNotFound: 22,\n currentSubscriptionToUpdateNotFoundInHistory: 24,\n billingServiceTimeout: 97,\n featureNotSupported: 98,\n billingServiceDisconnected: 99,\n billingServiceUnavailable: 102,\n billingUnavailable: 103,\n developerError: 105,\n billingError: 106,\n itemAlreadyOwned: 107,\n itemNotOwned: 108,\n billingNetworkError: 112,\n noProductIDsFound: 1000,\n productRequestFailed: 1002,\n cantMakePayments: 1003,\n noPurchasesToRestore: 1004,\n cantReadReceipt: 1005,\n productPurchaseFailed: 1006,\n refreshReceiptFailed: 1010,\n receiveRestoredTransactionsFailed: 1011,\n notActivated: 2002,\n badRequest: 2003,\n serverError: 2004,\n networkFailed: 2005,\n decodingFailed: 2006,\n encodingFailed: 2009,\n analyticsDisabled: 3000,\n wrongParam: 3001,\n activateOnceError: 3005,\n profileWasChanged: 3006,\n unsupportedData: 3007,\n persistingDataError: 3100,\n fetchTimeoutError: 3101,\n operationInterrupted: 9000,\n} as const);\n\nexport type ErrorCode = keyof typeof ErrorCodeMapping;\n\nexport const ErrorCodeName = ErrorCodeNameMapping;\nexport type ErrorCodeName = keyof typeof ErrorCodeNameMapping;\n\nexport function getErrorCode(name: ErrorCodeName): ErrorCode | undefined {\n return ErrorCodeName[name] ?? undefined;\n}\n\nexport function getErrorPrompt(code: ErrorCode): (typeof ErrorCode)[ErrorCode] {\n const prompt = ErrorCode[code];\n\n if (!prompt) {\n return `Unknown code: ${code}` as (typeof ErrorCode)[ErrorCode];\n }\n\n return prompt;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"merge-options.js","sourceRoot":"","sources":["../../../../src/shared/utils/merge-options.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,SAAS,aAAa,CAAC,KAAU;IAC/B,OAAO,CACL,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACrB,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC;QACxB,CAAC,CAAC,KAAK,YAAY,MAAM,CAAC;QAC1B,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB,CAC5D,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,SAAS,CAAC,MAAW,EAAE,MAAW,EAAE,IAAI,GAAG,IAAI,GAAG,EAAE;IAC3D,8BAA8B;IAC9B,IAAI,MAAM,KAAK,IAAI,IAA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GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE;wBAClD,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;qBAC1D;oBACD,0CAA0C;oBAC1C,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;iBACzD;qBAAM;oBACL,+CAA+C;oBAC/C,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE;wBACzB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;qBAC1D;oBACD,gDAAgD;oBAChD,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;iBAC3B;aACF;iBAAM;gBACL,+CAA+C;gBAC/C,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE;oBACzB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;iBAC1D;gBACD,gDAAgD;gBAChD,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;aAC3B;SACF;QAED,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAEpB,OAAO,MAAM,CAAC;KACf;IAED,0EAA0E;IAC1E,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAY,EACZ,QAAa;IAEb,OAAO,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAY,CAAC;AACjD,CAAC","sourcesContent":["/**\n * Checks if a value is a plain object (not an array, null, Date, etc.)\n */\nfunction isPlainObject(value: any): boolean {\n return (\n value !== null &&\n typeof value === 'object' &&\n !Array.isArray(value) &&\n !(value instanceof Date) &&\n !(value instanceof RegExp) &&\n Object.prototype.toString.call(value) === '[object Object]'\n );\n}\n\n/**\n * Deep merge implementation that replaces arrays and merges objects\n */\nfunction deepMerge(target: any, source: any, seen = new Set()): any {\n // Handle null/undefined cases\n if (source === null || source === undefined) {\n return source;\n }\n \n if (target === null || target === undefined) {\n return source;\n }\n\n // Handle arrays - replace them (source overwrites target)\n if (Array.isArray(source)) {\n return source;\n }\n\n // If target is array but source is not, return source\n if (Array.isArray(target)) {\n return source;\n }\n\n // Handle plain objects - merge recursively\n if (isPlainObject(target) && isPlainObject(source)) {\n // Check for circular references\n if (seen.has(source) || seen.has(target)) {\n throw new Error('Converting circular structure to JSON');\n }\n \n seen.add(source);\n seen.add(target);\n \n const result: any = {};\n \n // Get all keys from both objects\n const allKeys = new Set([\n ...Object.keys(target),\n ...Object.keys(source)\n ]);\n\n for (const key of allKeys) {\n // Skip prototype pollution attempts\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') {\n continue;\n }\n\n if (key in source) {\n if (key in target) {\n // Check for circular reference in values\n if (seen.has(source[key]) || seen.has(target[key])) {\n throw new Error('Converting circular structure to JSON');\n }\n // Recursively merge if key exists in both\n result[key] = deepMerge(target[key], source[key], seen);\n } else {\n // Check for circular reference in source value\n if (seen.has(source[key])) {\n throw new Error('Converting circular structure to JSON');\n }\n // Use source value if key only exists in source\n result[key] = source[key];\n }\n } else {\n // Check for circular reference in target value\n if (seen.has(target[key])) {\n throw new Error('Converting circular structure to JSON');\n }\n // Use target value if key only exists in target\n result[key] = target[key];\n }\n }\n\n seen.delete(source);\n seen.delete(target);\n\n return result;\n }\n\n // For all other cases (primitives, functions, dates, etc.), return source\n return source;\n}\n\n/**\n * Universal method for merging options with defaults\n * @param options - input options\n * @param defaults - default values\n * @returns merged object with TResult type\n */\nexport function mergeOptions<TResult = any>(\n options: any,\n defaults: any\n): TResult {\n return deepMerge(defaults, options) as TResult;\n}\n\n"]}
1
+ {"version":3,"file":"merge-options.js","sourceRoot":"","sources":["../../../../src/shared/utils/merge-options.ts"],"names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AAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;oBAC1B,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;gBAC3D,CAAC;gBACD,gDAAgD;gBAChD,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAEpB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,0EAA0E;IAC1E,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAY,EACZ,QAAa;IAEb,OAAO,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAY,CAAC;AACjD,CAAC","sourcesContent":["/**\n * Checks if a value is a plain object (not an array, null, Date, etc.)\n */\nfunction isPlainObject(value: any): boolean {\n return (\n value !== null &&\n typeof value === 'object' &&\n !Array.isArray(value) &&\n !(value instanceof Date) &&\n !(value instanceof RegExp) &&\n Object.prototype.toString.call(value) === '[object Object]'\n );\n}\n\n/**\n * Deep merge implementation that replaces arrays and merges objects\n */\nfunction deepMerge(target: any, source: any, seen = new Set()): any {\n // Handle null/undefined cases\n if (source === null || source === undefined) {\n return source;\n }\n \n if (target === null || target === undefined) {\n return source;\n }\n\n // Handle arrays - replace them (source overwrites target)\n if (Array.isArray(source)) {\n return source;\n }\n\n // If target is array but source is not, return source\n if (Array.isArray(target)) {\n return source;\n }\n\n // Handle plain objects - merge recursively\n if (isPlainObject(target) && isPlainObject(source)) {\n // Check for circular references\n if (seen.has(source) || seen.has(target)) {\n throw new Error('Converting circular structure to JSON');\n }\n \n seen.add(source);\n seen.add(target);\n \n const result: any = {};\n \n // Get all keys from both objects\n const allKeys = new Set([\n ...Object.keys(target),\n ...Object.keys(source)\n ]);\n\n for (const key of allKeys) {\n // Skip prototype pollution attempts\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') {\n continue;\n }\n\n if (key in source) {\n if (key in target) {\n // Check for circular reference in values\n if (seen.has(source[key]) || seen.has(target[key])) {\n throw new Error('Converting circular structure to JSON');\n }\n // Recursively merge if key exists in both\n result[key] = deepMerge(target[key], source[key], seen);\n } else {\n // Check for circular reference in source value\n if (seen.has(source[key])) {\n throw new Error('Converting circular structure to JSON');\n }\n // Use source value if key only exists in source\n result[key] = source[key];\n }\n } else {\n // Check for circular reference in target value\n if (seen.has(target[key])) {\n throw new Error('Converting circular structure to JSON');\n }\n // Use target value if key only exists in target\n result[key] = target[key];\n }\n }\n\n seen.delete(source);\n seen.delete(target);\n\n return result;\n }\n\n // For all other cases (primitives, functions, dates, etc.), return source\n return source;\n}\n\n/**\n * Universal method for merging options with defaults\n * @param options - input options\n * @param defaults - default values\n * @returns merged object with TResult type\n */\nexport function mergeOptions<TResult = any>(\n options: any,\n defaults: any\n): TResult {\n return deepMerge(defaults, options) as TResult;\n}\n\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"with-error-context.js","sourceRoot":"","sources":["../../../../src/shared/utils/with-error-context.ts"],"names":[],"mappings":"AAEA,SAAS,MAAM;IACb,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,aAAa,EACX,IAAI,CAAC,aAAa,YAAY,KAAK;YACjC,CAAC,CAAC;gBACE,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,OAAO;gBACnC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI;aAC9B;YACH,CAAC,CAAC,IAAI,CAAC,aAAa;KACzB,CAAC;AACJ,CAAC;AACD;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAAW,EACX,WAAmB,EACnB,MAAc;IAEd,MAAM,OAAO,GAAG,UAAyB,GAAG,IAAmB;QAC7D,IAAI;YACF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SACnC;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,OAAO,GAAG,4CAA4C,MAAM,IAAI,WAAW,EAAE,CAAC;YAEpF,MAAM,YAAY,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;YACvC,YAAoB,CAAC,aAAa,GAAG,KAAK,CAAC;YAC3C,YAAoB,CAAC,MAAM,GAAG,MAAM,CAAC;YAEtC,MAAM,YAAY,CAAC;SACpB;IACH,CAAC,CAAC;IAEF,OAAO,OAA0B,CAAC;AACpC,CAAC","sourcesContent":["type AnyCallback = (...args: any[]) => any;\n\nfunction toJSON(this: Error & { originalError: any }) {\n return {\n message: this.message,\n name: this.name,\n stack: this.stack,\n originalError:\n this.originalError instanceof Error\n ? {\n message: this.originalError.message,\n name: this.originalError.name,\n }\n : this.originalError,\n };\n}\n/**\n * Wraps a user-provided callback with error context enrichment.\n * Catches exceptions and wraps them with source and handler information.\n */\nexport function withErrorContext<T extends AnyCallback>(\n callback: T,\n handlerName: string,\n source: string,\n): T & AnyCallback {\n const wrapped = function (this: unknown, ...args: Parameters<T>): ReturnType<T> {\n try {\n return callback.apply(this, args);\n } catch (error) {\n const message = `Unhandled exception in user's handler in ${source}.${handlerName}`;\n\n const wrappedError = new Error(message);\n (wrappedError as any).originalError = error;\n (wrappedError as any).toJSON = toJSON;\n\n throw wrappedError;\n }\n };\n\n return wrapped as T & AnyCallback;\n}\n\n"]}
1
+ {"version":3,"file":"with-error-context.js","sourceRoot":"","sources":["../../../../src/shared/utils/with-error-context.ts"],"names":[],"mappings":"AAEA,SAAS,MAAM;IACb,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,aAAa,EACX,IAAI,CAAC,aAAa,YAAY,KAAK;YACjC,CAAC,CAAC;gBACE,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,OAAO;gBACnC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI;aAC9B;YACH,CAAC,CAAC,IAAI,CAAC,aAAa;KACzB,CAAC;AACJ,CAAC;AACD;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAAW,EACX,WAAmB,EACnB,MAAc;IAEd,MAAM,OAAO,GAAG,UAAyB,GAAG,IAAmB;QAC7D,IAAI,CAAC;YACH,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACpC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,GAAG,4CAA4C,MAAM,IAAI,WAAW,EAAE,CAAC;YAEpF,MAAM,YAAY,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;YACvC,YAAoB,CAAC,aAAa,GAAG,KAAK,CAAC;YAC3C,YAAoB,CAAC,MAAM,GAAG,MAAM,CAAC;YAEtC,MAAM,YAAY,CAAC;QACrB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,OAA0B,CAAC;AACpC,CAAC","sourcesContent":["type AnyCallback = (...args: any[]) => any;\n\nfunction toJSON(this: Error & { originalError: any }) {\n return {\n message: this.message,\n name: this.name,\n stack: this.stack,\n originalError:\n this.originalError instanceof Error\n ? {\n message: this.originalError.message,\n name: this.originalError.name,\n }\n : this.originalError,\n };\n}\n/**\n * Wraps a user-provided callback with error context enrichment.\n * Catches exceptions and wraps them with source and handler information.\n */\nexport function withErrorContext<T extends AnyCallback>(\n callback: T,\n handlerName: string,\n source: string,\n): T & AnyCallback {\n const wrapped = function (this: unknown, ...args: Parameters<T>): ReturnType<T> {\n try {\n return callback.apply(this, args);\n } catch (error) {\n const message = `Unhandled exception in user's handler in ${source}.${handlerName}`;\n\n const wrappedError = new Error(message);\n (wrappedError as any).originalError = error;\n (wrappedError as any).toJSON = toJSON;\n\n throw wrappedError;\n }\n };\n\n return wrapped as T & AnyCallback;\n}\n\n"]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CAAC;SACjB;QAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;QAC7D,IAAI,CAAC,OAAO,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,mCAAmC,WAAW,EAAE,CAAC,CAAC;SACnE;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,kBAAkB,CAAC;AAW9C;;;GAGG;AACH,MAAM,OAAgB,eAAe;IAUnC,YAAY,MAAc;QAJhB,mBAAc,GAA4C,IAAI,GAAG,EAAE,CAA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C,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 +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,OA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AAc,CAAC,CAAC;oBACxG,GAAG,CAAC,OAAO,CACT,kBAAkB,EAClB,GAAG,EAAE,CAAC,+BAA+B,EACrC,GAAG,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CACtB,CAAC;iBACH;gBAAC,OAAO,KAAK,EAAE;oBACd,GAAG,CAAC,KAAK,CACP,kBAAkB,EAClB,GAAG,EAAE,CAAC,6CAA6C,SAAS,EAAE,EAC9D,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAClB,CAAC;iBACH;aACF;SACF;QAED,MAAM,WAAW,GAAG,GAAG,EAAE;YACvB,GAAG,CAAC,IAAI,CACN,kBAAkB,EAClB,GAAG,EAAE,CAAC,kDAAkD,EACxD,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CACxB,CAAC;YACF,IAAI,IAAI,CAAC,WAAW,EAAE;gBACpB,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAAE,CAAC;gBACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;aACzB;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;YACpB,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAAE,CAAC;YACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;SACzB;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"]}
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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H,CAAC;QACH,CAAC;QAED,MAAM,WAAW,GAAG,GAAG,EAAE;YACvB,GAAG,CAAC,IAAI,CACN,kBAAkB,EAClB,GAAG,EAAE,CAAC,kDAAkD,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"]}
@@ -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,mCAAmC,CAAC;AAEzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAGtE,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;YACX,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACrD;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,OAAO,uBAAuB,CAAC;IACjC,CAAC;CACF;AAED,MAAM,uBAAuB,GAA6C;IACxE,OAAO,EAAE,gCAAgC;IACzC,WAAW,EAAE,gCAAgC;IAC7C,iBAAiB,EAAE,+BAA+B;IAClD,OAAO,EAAE,4BAA4B;IACrC,QAAQ,EAAE,6BAA6B;IACvC,SAAS,EAAE,8BAA8B;IACzC,cAAc,EAAE,oCAAoC;CACrD,CAAC;AAEF,MAAM,qBAAqB,GAA6C;IACtE,8BAA8B,EAAE,SAAS;IACzC,8BAA8B,EAAE,aAAa;IAC7C,6BAA6B,EAAE,mBAAmB;IAClD,0BAA0B,EAAE,SAAS;IACrC,2BAA2B,EAAE,UAAU;IACvC,4BAA4B,EAAE,WAAW;IACzC,kCAAkC,EAAE,gBAAgB;CACrD,CAAC;AAIF,SAAS,mBAAmB,CAC1B,YAAe,EACf,KAA4B;IAE5B,QAAQ,KAAK,CAAC,EAAE,EAAE;QAChB,KAAK,iBAAiB,CAAC,KAAK,CAAC;QAC7B,KAAK,iBAAiB,CAAC,MAAM,CAAC;QAC9B,KAAK,iBAAiB,CAAC,OAAO;YAC5B,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAqB,CAAC;QAE1D,KAAK,iBAAiB,CAAC,YAAY;YACjC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAqB,CAAC;QAExD,KAAK,iBAAiB,CAAC,eAAe;YACpC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAqB,CAAC;QAE1C,KAAK,iBAAiB,CAAC,SAAS;YAC9B,OAAO;gDAEA,KAAK,CAAC,KAAK;oBACd,iEAAiE;oBACjE,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS;gBAEnC,KAAK,CAAC,IAAI;aACS,CAAC;QAExB,KAAK,iBAAiB,CAAC,KAAK;YAC1B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAqB,CAAC;KAC5C;AACH,CAAC","sourcesContent":["import { parseOnboardingEvent } from '../shared/coders/parse-onboarding';\nimport type { LogContext } from '../shared/logger';\nimport { OnboardingEventId } from '../shared/types/onboarding-events';\nimport type { OnboardingEventIdType, ParsedOnboardingEvent } from '../shared/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
+ {"version":3,"file":"onboarding-view-emitter.js","sourceRoot":"","sources":["../../../src/ui-builder/onboarding-view-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAGtE,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,MA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IAAI,CAAqB,CAAC;QAE1D,KAAK,iBAAiB,CAAC,YAAY;YACjC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAqB,CAAC;QAExD,KAAK,iBAAiB,CAAC,eAAe;YACpC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAqB,CAAC;QAE1C,KAAK,iBAAiB,CAAC,SAAS;YAC9B,OAAO;gDAEA,KAAK,CAAC,KAAK;oBACd,iEAAiE;oBACjE,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS;gBAEnC,KAAK,CAAC,IAAI;aACS,CAAC;QAExB,KAAK,iBAAiB,CAAC,KAAK;YAC1B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAqB,CAAC;IAC7C,CAAC;AACH,CAAC","sourcesContent":["import { parseOnboardingEvent } from '../shared/coders/parse-onboarding';\nimport type { LogContext } from '../shared/logger';\nimport { OnboardingEventId } from '../shared/types/onboarding-events';\nimport type { OnboardingEventIdType, ParsedOnboardingEvent } from '../shared/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 +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;AAEtE,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,YAAY,GAAG,IAAI,kBAAkB,EAAE,CAA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,IAAI,CAAC,WAAW,EAAE;YACpB,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAAE,CAAC;YACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;SACzB;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":"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;AAEtE,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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B;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 +1 @@
1
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AC,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,WAAW,KAAK,gBAAgB,EAAE;gBACpE,OAAO,CAAC,MAAA,KAAK,CAAC,MAAM,CAAC,KAAK,mCAAI,EAAE,CAAqB,CAAC;aACvD;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;KACjC;AACH,CAAC","sourcesContent":["import { parsePaywallEvent } from '../shared/coders/parse-paywall';\nimport type { LogContext } from '../shared/logger';\nimport { PaywallEventId } from '../shared/types/paywall-events';\nimport type { ParsedPaywallEvent, PaywallEventIdType } from '../shared/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' || handlerName === 'onCustomAction') {\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"]}
1
+ {"version":3,"file":"paywall-view-emitter.js","sourceRoot":"","sources":["../../../src/ui-builder/paywall-view-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGhE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAKtD;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,eAAsE;IAClG,cAAc,CAAC,YAAoB,EAAE,GAAe;QAC5D,MAAM,MAAM,GAAG,iBAAiB,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;QACpD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAES,wBAAwB,CAAC,KAA0B;QAC3D,OAAO,uBAAuB,CAAC,KAAkB,CAAC,CAAC;IACrD,CAAC;IAES,wBAAwB,CAChC,WAA+B,EAC/B,SAA6B;QAE7B,MAAM,QAAQ,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAC;QACpD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,QAAQ,CAAC,SAAS,CAA+B,CAAC;IAC3D,CAAC;IAES,mBAAmB,CAAC,WAAgC,EAAE,SAA6B;QAC3F,OAAO,mBAAmB,CAAC,WAAwB,EAAE,SAAS,CAAC,CAAC;IAClE,CAAC;IAES,cAAc,CAAC,SAA6B;;QACpD,OAAO,MAAA,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,0CAAE,EAAE,mCAAI,IAAI,CAAC;IACrC,CAAC;IAES,cAAc;QACtB,OAAO,oBAAoB,CAAC;IAC9B,CAAC;CACF;AAED,MAAM,qBAAqB,GAAgF;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AAC,KAAK,CAAC,OAAO,CAAqB,CAAC;QAE7C,KAAK,cAAc,CAAC,cAAc,CAAC;QACnC,KAAK,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,WAAW,KAAK,gBAAgB,EAAE,CAAC;gBACrE,OAAO,CAAC,MAAA,KAAK,CAAC,MAAM,CAAC,KAAK,mCAAI,EAAE,CAAqB,CAAC;YACxD,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 '../shared/coders/parse-paywall';\nimport type { LogContext } from '../shared/logger';\nimport { PaywallEventId } from '../shared/types/paywall-events';\nimport type { ParsedPaywallEvent, PaywallEventIdType } from '../shared/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' || handlerName === 'onCustomAction') {\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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/ui-builder/types.ts"],"names":[],"mappings":"AAiNA;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAkB;IACnD,kBAAkB,EAAE,GAAG,EAAE,CAAC,IAAI;IAC9B,mBAAmB,EAAE,GAAG,EAAE,CAAC,IAAI;IAC/B,UAAU,EAAE,CAAC,GAAW,EAAE,EAAE;QAC1B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;YACjC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;SAC5B;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,cAAc,EAAE,GAAG,EAAE,CAAC,KAAK;IAC3B,iBAAiB,EAAE,GAAG,EAAE,CAAC,KAAK;IAC9B,iBAAiB,EAAE,GAAG,EAAE,CAAC,KAAK;IAC9B,mBAAmB,EAAE,CAAC,cAAoC,EAAE,EAAE,CAAC,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,MAAK,gBAAgB;IACxG,gBAAgB,EAAE,GAAG,EAAE,CAAC,KAAK;IAC7B,gBAAgB,EAAE,GAAG,EAAE,CAAC,KAAK;IAC7B,kBAAkB,EAAE,GAAG,EAAE,CAAC,IAAI;IAC9B,eAAe,EAAE,GAAG,EAAE,CAAC,KAAK;IAC5B,UAAU,EAAE,GAAG,EAAE,CAAC,KAAK;IACvB,aAAa,EAAE,GAAG,EAAE,CAAC,KAAK;IAC1B,iBAAiB,EAAE,GAAG,EAAE,CAAC,IAAI;IAC7B,uBAAuB,EAAE,GAAG,EAAE,CAAC,KAAK;IACpC,8BAA8B,EAAE,GAAG,EAAE,CAAC,KAAK;CAC5C,CAAC;AA0DF,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,CAAC;IACpD,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;CACvB,CAAC,CAAC;AA8EH,MAAM,CAAC,MAAM,iCAAiC,GAAqC;IACjF,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI;CACpB,CAAC","sourcesContent":["import type {\n AdaptyPaywallProduct,\n AdaptyProductIdentifier,\n AdaptyProfile,\n AdaptyPurchaseResult,\n WebPresentation,\n} from '../shared/types';\nimport type { FileLocation, MakePurchaseParamsInput } from '../shared/types/inputs';\nimport type { AdaptyError } from '../shared/types/method-types';\n\n/**\n * @internal\n */\nexport type ArgType<T> = T extends () => any ? void : T extends (arg: infer U) => any ? U : void;\n\n/**\n * EventHandler callback should not return a promise,\n * because using `await` may postpone closing a paywall view.\n *\n * We don't want to block the UI thread.\n */\nexport type EventHandlerResult = boolean | void;\n\n/**\n * Purchase parameters keyed by AdaptyProductIdentifier objects\n */\nexport type ProductPurchaseParams = {\n productId: AdaptyProductIdentifier;\n params: MakePurchaseParamsInput;\n}[];\n\nexport type AdaptyCustomAsset =\n | AdaptyCustomImageAsset\n | AdaptyCustomVideoAsset\n | AdaptyCustomColorAsset\n | AdaptyCustomGradientAsset;\n\nexport type AdaptyCustomImageAsset =\n | { type: 'image'; base64: string }\n | { type: 'image'; relativeAssetPath: string } // shorthand: uses same path for both iOS fileName and Android relativeAssetPath\n | { type: 'image'; fileLocation: FileLocation }; // full control for platform-specific paths\n\nexport type AdaptyCustomVideoAsset =\n | { type: 'video'; relativeAssetPath: string } // shorthand: uses same path for both iOS fileName and Android relativeAssetPath\n | { type: 'video'; fileLocation: FileLocation }; // full control for platform-specific paths\n\nexport type AdaptyCustomColorAsset =\n | { type: 'color'; argb: number /* e.g. 0xFFFF0000 (opaque red) */ }\n | { type: 'color'; rgb: number /* e.g. 0xFF0000 (red) */ }\n | { type: 'color'; rgba: number /* e.g. 0xFF0000FF (opaque red) */ };\n\nexport type AdaptyCustomGradientAsset = {\n type: 'linear-gradient';\n values: ({ p: number; argb: number } | { p: number; rgb: number } | { p: number; rgba: number })[];\n points?: { x0?: number; y0?: number; x1?: number; y1?: number };\n};\n\nexport type AdaptyUiOnboardingMeta = {\n onboardingId: string;\n screenClientId: string;\n screenIndex: number;\n totalScreens: number;\n};\n\nexport type AdaptyUiOnboardingStateParams = {\n id: string;\n value: string;\n label: string;\n};\n\n/**\n * Paywall event handlers configuration\n *\n * @see {@link https://adapty.io/docs/capacitor-handling-events | [DOC] Handling View Events}\n */\nexport interface EventHandlers {\n /**\n * Called when a user taps the close button on the paywall view\n *\n * If you return `true`, the paywall view will be closed.\n * We strongly recommend to return `true` in this case.\n * @default true\n */\n onCloseButtonPress: () => EventHandlerResult;\n /**\n * Called when a user navigates back on Android\n *\n * If you return `true`, the paywall view will be closed.\n * We strongly recommend to return `true` in this case.\n * @default true\n */\n onAndroidSystemBack: () => EventHandlerResult;\n /**\n * Called when a user taps an URL in the paywall view\n *\n * If you return `true`, the paywall view will be closed.\n * @default false\n */\n onUrlPress: (url: string) => EventHandlerResult;\n /**\n * Called when a user performs a custom action in the paywall view\n *\n * If you return `true`, the paywall view will be closed.\n * @default false\n */\n onCustomAction: (actionId: string) => EventHandlerResult;\n /**\n * Called when a user selects a product in the paywall view\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * @default false\n */\n onProductSelected: (productId: string) => EventHandlerResult;\n /**\n * Called when a purchase process starts\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * @default false\n */\n onPurchaseStarted: (product: AdaptyPaywallProduct) => EventHandlerResult;\n /**\n * Called when the purchase succeeds, the user cancels their purchase, or the purchase appears to be pending\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * We strongly recommend returning `purchaseResult.type !== 'user_cancelled'` in this case.\n * @default `purchaseResult.type !== 'user_cancelled'`\n *\n * @param purchaseResult - object, which provides details about the purchase.\n * If the result is `'success'`, it also includes the updated user's profile.\n */\n onPurchaseCompleted: (purchaseResult: AdaptyPurchaseResult, product: AdaptyPaywallProduct) => EventHandlerResult;\n /**\n * Called if a purchase fails after a user taps the purchase button\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * @default false\n *\n * @param error - AdaptyError object with error code and message\n */\n onPurchaseFailed: (error: AdaptyError, product: AdaptyPaywallProduct) => EventHandlerResult;\n /**\n * Called when a user taps the restore button in the paywall view\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * @default false\n */\n onRestoreStarted: () => EventHandlerResult;\n /**\n * Called when a purchase is completed\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * We strongly recommend to return `true` in this case.\n * @default true\n *\n * @param profile - updated user profile\n */\n onRestoreCompleted: (profile: AdaptyProfile) => EventHandlerResult;\n /**\n * Called if a restore fails after a user taps the restore button\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * @default false\n *\n * @param error - AdaptyError object with error code and message\n */\n onRestoreFailed: (error: AdaptyError) => EventHandlerResult;\n /**\n * Called when the paywall view appears\n *\n * If you return `true`, the paywall view will be closed.\n * @default false\n */\n onAppeared: () => EventHandlerResult;\n /**\n * Called when the paywall view disappears\n *\n * If you return `true`, the paywall view will be closed.\n * @default false\n */\n onDisappeared: () => EventHandlerResult;\n /**\n * Called if a paywall view fails to render.\n * This should not ever happen, but if it does, feel free to report it to us.\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * @default true\n *\n * @param error - AdaptyError object with error code and message\n */\n onRenderingFailed: (error: AdaptyError) => EventHandlerResult;\n /**\n * Called if a product list fails to load on a presented view,\n * for example, if there is no internet connection\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * @default false\n *\n * @param error - AdaptyError object with error code and message\n */\n onLoadingProductsFailed: (error: AdaptyError) => EventHandlerResult;\n /**\n * Called when web payment navigation finishes\n *\n * If you return `true`, the paywall view will be closed.\n * @default false\n */\n onWebPaymentNavigationFinished: (product?: AdaptyPaywallProduct, error?: AdaptyError) => EventHandlerResult;\n}\n\n/**\n * Default event handlers that provide standard closing behavior\n */\nexport const DEFAULT_EVENT_HANDLERS: EventHandlers = {\n onCloseButtonPress: () => true,\n onAndroidSystemBack: () => true,\n onUrlPress: (url: string) => {\n if (typeof window !== 'undefined') {\n window.open(url, '_blank');\n }\n return false;\n },\n onCustomAction: () => false,\n onProductSelected: () => false,\n onPurchaseStarted: () => false,\n onPurchaseCompleted: (purchaseResult: AdaptyPurchaseResult) => purchaseResult?.type !== 'user_cancelled',\n onPurchaseFailed: () => false,\n onRestoreStarted: () => false,\n onRestoreCompleted: () => true,\n onRestoreFailed: () => false,\n onAppeared: () => false,\n onDisappeared: () => false,\n onRenderingFailed: () => true,\n onLoadingProductsFailed: () => false,\n onWebPaymentNavigationFinished: () => false,\n};\n\nexport type OnboardingStateUpdatedAction =\n | {\n elementId: string;\n elementType: 'select';\n value: AdaptyUiOnboardingStateParams;\n }\n | {\n elementId: string;\n elementType: 'multi_select';\n value: AdaptyUiOnboardingStateParams[];\n }\n | {\n elementId: string;\n elementType: 'input';\n value: { type: 'text' | 'email'; value: string } | { type: 'number'; value: number };\n }\n | {\n elementId: string;\n elementType: 'date_picker';\n value: {\n day?: number;\n month?: number;\n year?: number;\n };\n };\n\nexport interface AdaptyUiView {\n id: string;\n}\n\nexport interface AdaptyUiMediaCache {\n memoryStorageTotalCostLimit?: number;\n memoryStorageCountLimit?: number;\n diskStorageSizeLimit?: number;\n}\n\nexport interface AdaptyUiDialogConfig {\n /**\n * The action title to display as part of the dialog. If you provide two actions,\n * be sure `primaryAction` cancels the operation and leaves things unchanged.\n */\n primaryActionTitle: string;\n /**\n * The secondary action title to display as part of the dialog.\n */\n secondaryActionTitle?: string;\n /**\n * The title of the dialog.\n */\n title?: string;\n /**\n * Descriptive text that provides additional details about the reason for the dialog.\n */\n content?: string;\n}\n\nexport const AdaptyUiDialogActionType = Object.freeze({\n primary: 'primary',\n secondary: 'secondary',\n});\n\nexport type AdaptyUiDialogActionType = (typeof AdaptyUiDialogActionType)[keyof typeof AdaptyUiDialogActionType];\n\n/**\n * Additional options for creating a paywall view\n *\n * @see {@link https://adapty.io/docs/capacitor-present-paywalls | [DOC] Creating Paywall View}\n */\nexport interface CreatePaywallViewParamsInput {\n /**\n * `true` if you want to prefetch products before presenting a paywall view.\n */\n prefetchProducts?: boolean;\n /**\n * This value limits the timeout (in milliseconds) for this method.\n */\n loadTimeoutMs?: number;\n /**\n * If you are going to use custom tags functionality, pass an object with tags and corresponding replacement values\n *\n * ```\n * {\n * 'USERNAME': 'Bruce',\n * 'CITY': 'Philadelphia'\n * }\n * ```\n */\n customTags?: Record<string, string>;\n /**\n * If you are going to use custom timer functionality, pass an object with timer ids and corresponding dates the timers should end at\n */\n customTimers?: Record<string, Date>;\n /**\n * Use this when you need to override paywall assets with your own\n */\n customAssets?: Record<string, AdaptyCustomAsset>;\n /**\n * Provide per-product purchase parameters keyed by Adapty product identifier\n */\n productPurchaseParams?: ProductPurchaseParams;\n}\n\n/**\n * Additional options for creating an onboarding view\n *\n * @see {@link https://adapty.io/docs/capacitor-get-onboardings | [DOC] Creating Onboarding View}\n */\nexport interface CreateOnboardingViewParamsInput {\n /**\n * If you want to change the presentation behavior of external URLs, pass a preferred value.\n *\n * @default {@link WebPresentation.BrowserInApp}\n */\n externalUrlsPresentation?: WebPresentation;\n}\n\nexport interface OnboardingEventHandlers {\n onClose: (actionId: string, meta: AdaptyUiOnboardingMeta) => EventHandlerResult;\n onCustom: (actionId: string, meta: AdaptyUiOnboardingMeta) => EventHandlerResult;\n onPaywall: (actionId: string, meta: AdaptyUiOnboardingMeta) => EventHandlerResult;\n onStateUpdated: (action: OnboardingStateUpdatedAction, meta: AdaptyUiOnboardingMeta) => EventHandlerResult;\n onFinishedLoading: (meta: AdaptyUiOnboardingMeta) => EventHandlerResult;\n onAnalytics: (\n event: {\n name: string;\n /**\n * @deprecated Use `elementId` instead\n */\n element_id?: string;\n elementId?: string;\n reply?: string;\n },\n meta: AdaptyUiOnboardingMeta,\n ) => EventHandlerResult;\n onError: (error: AdaptyError) => EventHandlerResult;\n}\n\nexport const DEFAULT_ONBOARDING_EVENT_HANDLERS: Partial<OnboardingEventHandlers> = {\n onClose: () => true,\n};\n\n/**\n * iOS presentation style for paywall and onboarding views\n * @platform ios\n */\nexport type AdaptyIOSPresentationStyle = 'full_screen' | 'page_sheet';\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/ui-builder/types.ts"],"names":[],"mappings":"AAiNA;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAkB;IACnD,kBAAkB,EAAE,GAAG,EAAE,CAAC,IAAI;IAC9B,mBAAmB,EAAE,GAAG,EAAE,CAAC,IAAI;IAC/B,UAAU,EAAE,CAAC,GAAW,EAAE,EAAE;QAC1B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAClC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC7B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,cAAc,EAAE,GAAG,EAAE,CAAC,KAAK;IAC3B,iBAAiB,EAAE,GAAG,EAAE,CAAC,KAAK;IAC9B,iBAAiB,EAAE,GAAG,EAAE,CAAC,KAAK;IAC9B,mBAAmB,EAAE,CAAC,cAAoC,EAAE,EAAE,CAAC,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,MAAK,gBAAgB;IACxG,gBAAgB,EAAE,GAAG,EAAE,CAAC,KAAK;IAC7B,gBAAgB,EAAE,GAAG,EAAE,CAAC,KAAK;IAC7B,kBAAkB,EAAE,GAAG,EAAE,CAAC,IAAI;IAC9B,eAAe,EAAE,GAAG,EAAE,CAAC,KAAK;IAC5B,UAAU,EAAE,GAAG,EAAE,CAAC,KAAK;IACvB,aAAa,EAAE,GAAG,EAAE,CAAC,KAAK;IAC1B,iBAAiB,EAAE,GAAG,EAAE,CAAC,IAAI;IAC7B,uBAAuB,EAAE,GAAG,EAAE,CAAC,KAAK;IACpC,8BAA8B,EAAE,GAAG,EAAE,CAAC,KAAK;CAC5C,CAAC;AA0DF,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,CAAC;IACpD,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;CACvB,CAAC,CAAC;AA8EH,MAAM,CAAC,MAAM,iCAAiC,GAAqC;IACjF,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI;CACpB,CAAC","sourcesContent":["import type {\n AdaptyPaywallProduct,\n AdaptyProductIdentifier,\n AdaptyProfile,\n AdaptyPurchaseResult,\n WebPresentation,\n} from '../shared/types';\nimport type { FileLocation, MakePurchaseParamsInput } from '../shared/types/inputs';\nimport type { AdaptyError } from '../shared/types/method-types';\n\n/**\n * @internal\n */\nexport type ArgType<T> = T extends () => any ? void : T extends (arg: infer U) => any ? U : void;\n\n/**\n * EventHandler callback should not return a promise,\n * because using `await` may postpone closing a paywall view.\n *\n * We don't want to block the UI thread.\n */\nexport type EventHandlerResult = boolean | void;\n\n/**\n * Purchase parameters keyed by AdaptyProductIdentifier objects\n */\nexport type ProductPurchaseParams = {\n productId: AdaptyProductIdentifier;\n params: MakePurchaseParamsInput;\n}[];\n\nexport type AdaptyCustomAsset =\n | AdaptyCustomImageAsset\n | AdaptyCustomVideoAsset\n | AdaptyCustomColorAsset\n | AdaptyCustomGradientAsset;\n\nexport type AdaptyCustomImageAsset =\n | { type: 'image'; base64: string }\n | { type: 'image'; relativeAssetPath: string } // shorthand: uses same path for both iOS fileName and Android relativeAssetPath\n | { type: 'image'; fileLocation: FileLocation }; // full control for platform-specific paths\n\nexport type AdaptyCustomVideoAsset =\n | { type: 'video'; relativeAssetPath: string } // shorthand: uses same path for both iOS fileName and Android relativeAssetPath\n | { type: 'video'; fileLocation: FileLocation }; // full control for platform-specific paths\n\nexport type AdaptyCustomColorAsset =\n | { type: 'color'; argb: number /* e.g. 0xFFFF0000 (opaque red) */ }\n | { type: 'color'; rgb: number /* e.g. 0xFF0000 (red) */ }\n | { type: 'color'; rgba: number /* e.g. 0xFF0000FF (opaque red) */ };\n\nexport type AdaptyCustomGradientAsset = {\n type: 'linear-gradient';\n values: ({ p: number; argb: number } | { p: number; rgb: number } | { p: number; rgba: number })[];\n points?: { x0?: number; y0?: number; x1?: number; y1?: number };\n};\n\nexport type AdaptyUiOnboardingMeta = {\n onboardingId: string;\n screenClientId: string;\n screenIndex: number;\n totalScreens: number;\n};\n\nexport type AdaptyUiOnboardingStateParams = {\n id: string;\n value: string;\n label: string;\n};\n\n/**\n * Paywall event handlers configuration\n *\n * @see {@link https://adapty.io/docs/capacitor-handling-events | [DOC] Handling View Events}\n */\nexport interface EventHandlers {\n /**\n * Called when a user taps the close button on the paywall view\n *\n * If you return `true`, the paywall view will be closed.\n * We strongly recommend to return `true` in this case.\n * @default true\n */\n onCloseButtonPress: () => EventHandlerResult;\n /**\n * Called when a user navigates back on Android\n *\n * If you return `true`, the paywall view will be closed.\n * We strongly recommend to return `true` in this case.\n * @default true\n */\n onAndroidSystemBack: () => EventHandlerResult;\n /**\n * Called when a user taps an URL in the paywall view\n *\n * If you return `true`, the paywall view will be closed.\n * @default false\n */\n onUrlPress: (url: string) => EventHandlerResult;\n /**\n * Called when a user performs a custom action in the paywall view\n *\n * If you return `true`, the paywall view will be closed.\n * @default false\n */\n onCustomAction: (actionId: string) => EventHandlerResult;\n /**\n * Called when a user selects a product in the paywall view\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * @default false\n */\n onProductSelected: (productId: string) => EventHandlerResult;\n /**\n * Called when a purchase process starts\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * @default false\n */\n onPurchaseStarted: (product: AdaptyPaywallProduct) => EventHandlerResult;\n /**\n * Called when the purchase succeeds, the user cancels their purchase, or the purchase appears to be pending\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * We strongly recommend returning `purchaseResult.type !== 'user_cancelled'` in this case.\n * @default `purchaseResult.type !== 'user_cancelled'`\n *\n * @param purchaseResult - object, which provides details about the purchase.\n * If the result is `'success'`, it also includes the updated user's profile.\n */\n onPurchaseCompleted: (purchaseResult: AdaptyPurchaseResult, product: AdaptyPaywallProduct) => EventHandlerResult;\n /**\n * Called if a purchase fails after a user taps the purchase button\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * @default false\n *\n * @param error - AdaptyError object with error code and message\n */\n onPurchaseFailed: (error: AdaptyError, product: AdaptyPaywallProduct) => EventHandlerResult;\n /**\n * Called when a user taps the restore button in the paywall view\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * @default false\n */\n onRestoreStarted: () => EventHandlerResult;\n /**\n * Called when a purchase is completed\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * We strongly recommend to return `true` in this case.\n * @default true\n *\n * @param profile - updated user profile\n */\n onRestoreCompleted: (profile: AdaptyProfile) => EventHandlerResult;\n /**\n * Called if a restore fails after a user taps the restore button\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * @default false\n *\n * @param error - AdaptyError object with error code and message\n */\n onRestoreFailed: (error: AdaptyError) => EventHandlerResult;\n /**\n * Called when the paywall view appears\n *\n * If you return `true`, the paywall view will be closed.\n * @default false\n */\n onAppeared: () => EventHandlerResult;\n /**\n * Called when the paywall view disappears\n *\n * If you return `true`, the paywall view will be closed.\n * @default false\n */\n onDisappeared: () => EventHandlerResult;\n /**\n * Called if a paywall view fails to render.\n * This should not ever happen, but if it does, feel free to report it to us.\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * @default true\n *\n * @param error - AdaptyError object with error code and message\n */\n onRenderingFailed: (error: AdaptyError) => EventHandlerResult;\n /**\n * Called if a product list fails to load on a presented view,\n * for example, if there is no internet connection\n *\n * If you return `true` from this callback, the paywall view will be closed.\n * @default false\n *\n * @param error - AdaptyError object with error code and message\n */\n onLoadingProductsFailed: (error: AdaptyError) => EventHandlerResult;\n /**\n * Called when web payment navigation finishes\n *\n * If you return `true`, the paywall view will be closed.\n * @default false\n */\n onWebPaymentNavigationFinished: (product?: AdaptyPaywallProduct, error?: AdaptyError) => EventHandlerResult;\n}\n\n/**\n * Default event handlers that provide standard closing behavior\n */\nexport const DEFAULT_EVENT_HANDLERS: EventHandlers = {\n onCloseButtonPress: () => true,\n onAndroidSystemBack: () => true,\n onUrlPress: (url: string) => {\n if (typeof window !== 'undefined') {\n window.open(url, '_blank');\n }\n return false;\n },\n onCustomAction: () => false,\n onProductSelected: () => false,\n onPurchaseStarted: () => false,\n onPurchaseCompleted: (purchaseResult: AdaptyPurchaseResult) => purchaseResult?.type !== 'user_cancelled',\n onPurchaseFailed: () => false,\n onRestoreStarted: () => false,\n onRestoreCompleted: () => true,\n onRestoreFailed: () => false,\n onAppeared: () => false,\n onDisappeared: () => false,\n onRenderingFailed: () => true,\n onLoadingProductsFailed: () => false,\n onWebPaymentNavigationFinished: () => false,\n};\n\nexport type OnboardingStateUpdatedAction =\n | {\n elementId: string;\n elementType: 'select';\n value: AdaptyUiOnboardingStateParams;\n }\n | {\n elementId: string;\n elementType: 'multi_select';\n value: AdaptyUiOnboardingStateParams[];\n }\n | {\n elementId: string;\n elementType: 'input';\n value: { type: 'text' | 'email'; value: string } | { type: 'number'; value: number };\n }\n | {\n elementId: string;\n elementType: 'date_picker';\n value: {\n day?: number;\n month?: number;\n year?: number;\n };\n };\n\nexport interface AdaptyUiView {\n id: string;\n}\n\nexport interface AdaptyUiMediaCache {\n memoryStorageTotalCostLimit?: number;\n memoryStorageCountLimit?: number;\n diskStorageSizeLimit?: number;\n}\n\nexport interface AdaptyUiDialogConfig {\n /**\n * The action title to display as part of the dialog. If you provide two actions,\n * be sure `primaryAction` cancels the operation and leaves things unchanged.\n */\n primaryActionTitle: string;\n /**\n * The secondary action title to display as part of the dialog.\n */\n secondaryActionTitle?: string;\n /**\n * The title of the dialog.\n */\n title?: string;\n /**\n * Descriptive text that provides additional details about the reason for the dialog.\n */\n content?: string;\n}\n\nexport const AdaptyUiDialogActionType = Object.freeze({\n primary: 'primary',\n secondary: 'secondary',\n});\n\nexport type AdaptyUiDialogActionType = (typeof AdaptyUiDialogActionType)[keyof typeof AdaptyUiDialogActionType];\n\n/**\n * Additional options for creating a paywall view\n *\n * @see {@link https://adapty.io/docs/capacitor-present-paywalls | [DOC] Creating Paywall View}\n */\nexport interface CreatePaywallViewParamsInput {\n /**\n * `true` if you want to prefetch products before presenting a paywall view.\n */\n prefetchProducts?: boolean;\n /**\n * This value limits the timeout (in milliseconds) for this method.\n */\n loadTimeoutMs?: number;\n /**\n * If you are going to use custom tags functionality, pass an object with tags and corresponding replacement values\n *\n * ```\n * {\n * 'USERNAME': 'Bruce',\n * 'CITY': 'Philadelphia'\n * }\n * ```\n */\n customTags?: Record<string, string>;\n /**\n * If you are going to use custom timer functionality, pass an object with timer ids and corresponding dates the timers should end at\n */\n customTimers?: Record<string, Date>;\n /**\n * Use this when you need to override paywall assets with your own\n */\n customAssets?: Record<string, AdaptyCustomAsset>;\n /**\n * Provide per-product purchase parameters keyed by Adapty product identifier\n */\n productPurchaseParams?: ProductPurchaseParams;\n}\n\n/**\n * Additional options for creating an onboarding view\n *\n * @see {@link https://adapty.io/docs/capacitor-get-onboardings | [DOC] Creating Onboarding View}\n */\nexport interface CreateOnboardingViewParamsInput {\n /**\n * If you want to change the presentation behavior of external URLs, pass a preferred value.\n *\n * @default {@link WebPresentation.BrowserInApp}\n */\n externalUrlsPresentation?: WebPresentation;\n}\n\nexport interface OnboardingEventHandlers {\n onClose: (actionId: string, meta: AdaptyUiOnboardingMeta) => EventHandlerResult;\n onCustom: (actionId: string, meta: AdaptyUiOnboardingMeta) => EventHandlerResult;\n onPaywall: (actionId: string, meta: AdaptyUiOnboardingMeta) => EventHandlerResult;\n onStateUpdated: (action: OnboardingStateUpdatedAction, meta: AdaptyUiOnboardingMeta) => EventHandlerResult;\n onFinishedLoading: (meta: AdaptyUiOnboardingMeta) => EventHandlerResult;\n onAnalytics: (\n event: {\n name: string;\n /**\n * @deprecated Use `elementId` instead\n */\n element_id?: string;\n elementId?: string;\n reply?: string;\n },\n meta: AdaptyUiOnboardingMeta,\n ) => EventHandlerResult;\n onError: (error: AdaptyError) => EventHandlerResult;\n}\n\nexport const DEFAULT_ONBOARDING_EVENT_HANDLERS: Partial<OnboardingEventHandlers> = {\n onClose: () => true,\n};\n\n/**\n * iOS presentation style for paywall and onboarding views\n * @platform ios\n */\nexport type AdaptyIOSPresentationStyle = 'full_screen' | 'page_sheet';\n"]}
@@ -1,2 +1,2 @@
1
- declare const _default: "3.15.0";
1
+ declare const _default: "3.16.0-beta.0";
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- export default '3.15.0';
1
+ export default '3.16.0-beta.0';
2
2
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAe,QAAQ,CAAC","sourcesContent":["export default '3.15.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAe,eAAe,CAAC","sourcesContent":["export default '3.16.0-beta.0';\n"]}
@@ -860,7 +860,7 @@ class AdaptyPaywallProductCoder extends SimpleCoder {
860
860
  paywallName: { key: 'paywall_name', required: true, type: 'string' },
861
861
  price: {
862
862
  key: 'price',
863
- required: false,
863
+ required: false, // Native SDKs require this
864
864
  type: 'object',
865
865
  converter: new AdaptyPriceCoder(),
866
866
  },
@@ -1746,7 +1746,7 @@ const consoleLogSink = {
1746
1746
  },
1747
1747
  };
1748
1748
 
1749
- var version = '3.15.0';
1749
+ var version = '3.16.0-beta.0';
1750
1750
 
1751
1751
  class Log {
1752
1752
  // Formats a message for logging