@adapty/capacitor 3.17.1 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Package.swift +1 -1
- package/README.md +8 -0
- package/android/build.gradle +2 -2
- package/dist/esm/adapty-instance.d.ts +7 -0
- package/dist/esm/adapty-instance.js +8 -0
- package/dist/esm/adapty-instance.js.map +1 -0
- package/dist/esm/adapty.d.ts +112 -59
- package/dist/esm/adapty.js +132 -69
- package/dist/esm/adapty.js.map +1 -1
- package/dist/esm/coders/parse-flow.d.ts +3 -0
- package/dist/esm/coders/parse-flow.js +4 -0
- package/dist/esm/coders/parse-flow.js.map +1 -0
- package/dist/esm/default-configs.js +2 -2
- package/dist/esm/default-configs.js.map +1 -1
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/adapty-plugin.d.ts +31 -17
- package/dist/esm/types/adapty-plugin.js.map +1 -1
- package/dist/esm/types/configs.d.ts +12 -14
- package/dist/esm/types/configs.js.map +1 -1
- package/dist/esm/types/flow-events.d.ts +1 -0
- package/dist/esm/types/flow-events.js +2 -0
- package/dist/esm/types/flow-events.js.map +1 -0
- package/dist/esm/types/index.d.ts +2 -2
- package/dist/esm/types/index.js +1 -1
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/inputs.d.ts +1 -1
- package/dist/esm/types/inputs.js.map +1 -1
- package/dist/esm/ui-builder/base-view-emitter.d.ts +6 -0
- package/dist/esm/ui-builder/base-view-emitter.js +12 -0
- package/dist/esm/ui-builder/base-view-emitter.js.map +1 -1
- package/dist/esm/ui-builder/create-flow-view.d.ts +14 -0
- package/dist/esm/ui-builder/create-flow-view.js +16 -0
- package/dist/esm/ui-builder/create-flow-view.js.map +1 -0
- package/dist/esm/ui-builder/create-onboarding-view.d.ts +2 -0
- package/dist/esm/ui-builder/create-onboarding-view.js +2 -0
- package/dist/esm/ui-builder/create-onboarding-view.js.map +1 -1
- package/dist/esm/ui-builder/{paywall-view-controller.d.ts → flow-view-controller.d.ts} +37 -37
- package/dist/esm/ui-builder/{paywall-view-controller.js → flow-view-controller.js} +54 -51
- package/dist/esm/ui-builder/flow-view-controller.js.map +1 -0
- package/dist/esm/ui-builder/flow-view-emitter.d.ts +38 -0
- package/dist/esm/ui-builder/flow-view-emitter.js +151 -0
- package/dist/esm/ui-builder/flow-view-emitter.js.map +1 -0
- package/dist/esm/ui-builder/index.d.ts +5 -5
- package/dist/esm/ui-builder/index.js +3 -2
- package/dist/esm/ui-builder/index.js.map +1 -1
- package/dist/esm/ui-builder/onboarding-view-controller.d.ts +7 -5
- package/dist/esm/ui-builder/onboarding-view-controller.js +7 -5
- package/dist/esm/ui-builder/onboarding-view-controller.js.map +1 -1
- package/dist/esm/ui-builder/types.d.ts +11 -358
- package/dist/esm/ui-builder/types.js +52 -22
- package/dist/esm/ui-builder/types.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/plugin.cjs.js +903 -679
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +903 -679
- package/dist/plugin.js.map +1 -1
- package/package.json +3 -5
- package/AdaptyCapacitor.podspec +0 -20
- package/dist/esm/coders/parse-paywall.d.ts +0 -3
- package/dist/esm/coders/parse-paywall.js +0 -4
- package/dist/esm/coders/parse-paywall.js.map +0 -1
- package/dist/esm/types/paywall-events.d.ts +0 -1
- package/dist/esm/types/paywall-events.js +0 -2
- package/dist/esm/types/paywall-events.js.map +0 -1
- package/dist/esm/ui-builder/create-paywall-view.d.ts +0 -25
- package/dist/esm/ui-builder/create-paywall-view.js +0 -29
- package/dist/esm/ui-builder/create-paywall-view.js.map +0 -1
- package/dist/esm/ui-builder/paywall-view-controller.js.map +0 -1
- package/dist/esm/ui-builder/paywall-view-emitter.d.ts +0 -16
- package/dist/esm/ui-builder/paywall-view-emitter.js +0 -114
- package/dist/esm/ui-builder/paywall-view-emitter.js.map +0 -1
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import type { AdaptyPaywallProduct } from './index';
|
|
2
2
|
import type { GetPlacementParamsInput, GetPlacementForDefaultAudienceParamsInput, MakePurchaseParamsInput } from './inputs';
|
|
3
3
|
/**
|
|
4
|
-
* Describes the options for the `
|
|
4
|
+
* Describes the options for the `getFlow` method.
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
7
|
-
export interface
|
|
7
|
+
export interface GetFlowOptions {
|
|
8
8
|
placementId: string;
|
|
9
|
-
locale?: string;
|
|
10
9
|
params?: GetPlacementParamsInput;
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
|
-
* Describes the options for the `
|
|
12
|
+
* Describes the options for the `getFlowForDefaultAudience` method.
|
|
14
13
|
* @public
|
|
15
14
|
*/
|
|
16
|
-
export interface
|
|
15
|
+
export interface GetFlowForDefaultAudienceOptions {
|
|
17
16
|
placementId: string;
|
|
18
|
-
locale?: string;
|
|
19
17
|
params?: GetPlacementForDefaultAudienceParamsInput;
|
|
20
18
|
}
|
|
21
19
|
/**
|
|
@@ -50,15 +48,15 @@ export interface MakePurchaseOptions {
|
|
|
50
48
|
*/
|
|
51
49
|
export interface AdaptyDefaultOptions {
|
|
52
50
|
/**
|
|
53
|
-
* Default options for the `
|
|
51
|
+
* Default options for the `getFlow` method.
|
|
54
52
|
*/
|
|
55
|
-
|
|
53
|
+
get_flow: {
|
|
56
54
|
params: Required<GetPlacementParamsInput>;
|
|
57
55
|
};
|
|
58
56
|
/**
|
|
59
|
-
* Default options for the `
|
|
57
|
+
* Default options for the `getFlowForDefaultAudience` method.
|
|
60
58
|
*/
|
|
61
|
-
|
|
59
|
+
get_flow_for_default_audience: {
|
|
62
60
|
params: GetPlacementForDefaultAudienceParamsInput;
|
|
63
61
|
};
|
|
64
62
|
/**
|
|
@@ -76,15 +74,15 @@ export interface AdaptyDefaultOptions {
|
|
|
76
74
|
};
|
|
77
75
|
}
|
|
78
76
|
/**
|
|
79
|
-
* Merged type that combines
|
|
77
|
+
* Merged type that combines GetFlowOptions with required params from AdaptyDefaultOptions
|
|
80
78
|
* @public
|
|
81
79
|
*/
|
|
82
|
-
export type
|
|
80
|
+
export type GetFlowOptionsWithDefaults = AdaptyDefaultOptions['get_flow'] & GetFlowOptions;
|
|
83
81
|
/**
|
|
84
|
-
* Merged type that combines
|
|
82
|
+
* Merged type that combines GetFlowForDefaultAudienceOptions with required params from AdaptyDefaultOptions
|
|
85
83
|
* @public
|
|
86
84
|
*/
|
|
87
|
-
export type
|
|
85
|
+
export type GetFlowForDefaultAudienceOptionsWithDefaults = AdaptyDefaultOptions['get_flow_for_default_audience'] & GetFlowForDefaultAudienceOptions;
|
|
88
86
|
/**
|
|
89
87
|
* Merged type for `getOnboarding` with defaults
|
|
90
88
|
* @public
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configs.js","sourceRoot":"","sources":["../../../src/types/configs.ts"],"names":[],"mappings":"","sourcesContent":["import type { AdaptyPaywallProduct } from './index';\nimport type {\n GetPlacementParamsInput,\n GetPlacementForDefaultAudienceParamsInput,\n MakePurchaseParamsInput,\n} from './inputs';\n\n/**\n * Describes the options for the `
|
|
1
|
+
{"version":3,"file":"configs.js","sourceRoot":"","sources":["../../../src/types/configs.ts"],"names":[],"mappings":"","sourcesContent":["import type { AdaptyPaywallProduct } from './index';\nimport type {\n GetPlacementParamsInput,\n GetPlacementForDefaultAudienceParamsInput,\n MakePurchaseParamsInput,\n} from './inputs';\n\n/**\n * Describes the options for the `getFlow` method.\n * @public\n */\nexport interface GetFlowOptions {\n placementId: string;\n params?: GetPlacementParamsInput;\n}\n\n/**\n * Describes the options for the `getFlowForDefaultAudience` method.\n * @public\n */\nexport interface GetFlowForDefaultAudienceOptions {\n placementId: string;\n params?: GetPlacementForDefaultAudienceParamsInput;\n}\n\n/**\n * Describes the options for the `getOnboarding` method.\n * @public\n */\nexport interface GetOnboardingOptions {\n placementId: string;\n locale?: string;\n params?: GetPlacementParamsInput;\n}\n\n/**\n * Describes the options for the `getOnboardingForDefaultAudience` method.\n * @public\n */\nexport interface GetOnboardingForDefaultAudienceOptions {\n placementId: string;\n locale?: string;\n // Keep same input shape as RN: allow loadTimeoutMs even though it is not used by schema\n params?: GetPlacementParamsInput;\n}\n\n/**\n * Describes the options for the `makePurchase` method.\n * @public\n */\nexport interface MakePurchaseOptions {\n product: AdaptyPaywallProduct;\n params?: MakePurchaseParamsInput;\n}\n\n/**\n * Describes the options for the Adapty constructor.\n * @public\n */\nexport interface AdaptyDefaultOptions {\n /**\n * Default options for the `getFlow` method.\n */\n get_flow: {\n params: Required<GetPlacementParamsInput>;\n };\n /**\n * Default options for the `getFlowForDefaultAudience` method.\n */\n get_flow_for_default_audience: {\n params: GetPlacementForDefaultAudienceParamsInput;\n };\n /**\n * Default options for the `getOnboarding` method.\n */\n get_onboarding: {\n params: Required<GetPlacementParamsInput>;\n };\n /**\n * Default options for the `getOnboardingForDefaultAudience` method.\n * Keep parity with RN by using `GetPlacementParamsInput`.\n */\n get_onboarding_for_default_audience: {\n params: GetPlacementParamsInput;\n };\n}\n\n/**\n * Merged type that combines GetFlowOptions with required params from AdaptyDefaultOptions\n * @public\n */\nexport type GetFlowOptionsWithDefaults = AdaptyDefaultOptions['get_flow'] & GetFlowOptions;\n\n/**\n * Merged type that combines GetFlowForDefaultAudienceOptions with required params from AdaptyDefaultOptions\n * @public\n */\nexport type GetFlowForDefaultAudienceOptionsWithDefaults = AdaptyDefaultOptions['get_flow_for_default_audience'] &\n GetFlowForDefaultAudienceOptions;\n\n/**\n * Merged type for `getOnboarding` with defaults\n * @public\n */\nexport type GetOnboardingOptionsWithDefaults = AdaptyDefaultOptions['get_onboarding'] & GetOnboardingOptions;\n\n/**\n * Merged type for `getOnboardingForDefaultAudience` with defaults\n * @public\n */\nexport type GetOnboardingForDefaultAudienceOptionsWithDefaults =\n AdaptyDefaultOptions['get_onboarding_for_default_audience'] & GetOnboardingForDefaultAudienceOptions;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FlowEventId, type FlowEventIdType, type FlowEventView, type ParsedFlowEvent, type AdaptyPermission, type FlowUserAction, type FlowDidAppearEvent, type FlowDidDisappearEvent, type FlowDidPerformActionEvent, type FlowDidSelectProductEvent, type FlowDidStartPurchaseEvent, type FlowDidFinishPurchaseEvent, type FlowDidFailPurchaseEvent, type FlowDidStartRestoreEvent, type FlowDidFinishRestoreEvent, type FlowDidFailRestoreEvent, type FlowDidReceiveErrorEvent, type FlowDidFailLoadingProductsEvent, type FlowDidFinishWebPaymentNavigationEvent, type FlowDidRequestAppReviewEvent, type FlowDidReceiveAnalyticEvent, type FlowDidAskPermissionEvent, type FlowObserverDidInitiatePurchaseEvent, type FlowObserverDidInitiateRestoreEvent, } from '@adapty/core';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-events.js","sourceRoot":"","sources":["../../../src/types/flow-events.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,GAwBZ,MAAM,cAAc,CAAC","sourcesContent":["export {\n FlowEventId,\n type FlowEventIdType,\n type FlowEventView,\n type ParsedFlowEvent,\n type AdaptyPermission,\n type FlowUserAction,\n type FlowDidAppearEvent,\n type FlowDidDisappearEvent,\n type FlowDidPerformActionEvent,\n type FlowDidSelectProductEvent,\n type FlowDidStartPurchaseEvent,\n type FlowDidFinishPurchaseEvent,\n type FlowDidFailPurchaseEvent,\n type FlowDidStartRestoreEvent,\n type FlowDidFinishRestoreEvent,\n type FlowDidFailRestoreEvent,\n type FlowDidReceiveErrorEvent,\n type FlowDidFailLoadingProductsEvent,\n type FlowDidFinishWebPaymentNavigationEvent,\n type FlowDidRequestAppReviewEvent,\n type FlowDidReceiveAnalyticEvent,\n type FlowDidAskPermissionEvent,\n type FlowObserverDidInitiatePurchaseEvent,\n type FlowObserverDidInitiateRestoreEvent,\n} from '@adapty/core';\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type { AdaptyPrice,
|
|
1
|
+
export type { AdaptyPrice, AdaptyFlow, AdaptyFlowPaywall, AdaptyOnboarding, AdaptyPlacement, AdaptyRemoteConfig, AdaptyOnboardingBuilder, AdaptyPurchaseResult, AdaptyProfile, AttributionSource, AdaptyAccessLevel, AdaptyNonSubscription, AdaptySubscription, AdaptyPaywallProduct, AdaptySubscriptionDetails, AdaptySubscriptionOffer, AdaptySubscriptionOfferId, AdaptyDiscountPhase, AdaptySubscriptionPeriod, AdaptyProfileParameters, AdaptyProductIdentifier, AdaptyInstallationStatus, AdaptyInstallationDetails, } from '@adapty/core';
|
|
2
2
|
export { WebPresentation, RefundPreference, VendorStore, OfferType, CancellationReason, Gender, AppTrackingTransparencyStatus, ProductPeriod, ErrorCode, ErrorCodeName, getErrorCode, getErrorPrompt, } from '@adapty/core';
|
|
3
3
|
export * from './inputs';
|
|
4
|
-
export * from './
|
|
4
|
+
export * from './flow-events';
|
|
5
5
|
export * from './onboarding-events';
|
package/dist/esm/types/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { WebPresentation, RefundPreference, VendorStore, OfferType, CancellationReason, Gender, AppTrackingTransparencyStatus, ProductPeriod, ErrorCode, ErrorCodeName, getErrorCode, getErrorPrompt, } from '@adapty/core';
|
|
2
2
|
// Re-export local modules that are NOT in core
|
|
3
3
|
export * from './inputs';
|
|
4
|
-
export * from './
|
|
4
|
+
export * from './flow-events';
|
|
5
5
|
export * from './onboarding-events';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AA2BA,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,kBAAkB,EAClB,MAAM,EACN,6BAA6B,EAC7B,aAAa,EACb,SAAS,EACT,aAAa,EACb,YAAY,EACZ,cAAc,GACf,MAAM,cAAc,CAAC;AAEtB,+CAA+C;AAC/C,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC","sourcesContent":["// Re-export all model types from @adapty/core\nexport type {\n AdaptyPrice,\n AdaptyFlow,\n AdaptyFlowPaywall,\n AdaptyOnboarding,\n AdaptyPlacement,\n AdaptyRemoteConfig,\n AdaptyOnboardingBuilder,\n AdaptyPurchaseResult,\n AdaptyProfile,\n AttributionSource,\n AdaptyAccessLevel,\n AdaptyNonSubscription,\n AdaptySubscription,\n AdaptyPaywallProduct,\n AdaptySubscriptionDetails,\n AdaptySubscriptionOffer,\n AdaptySubscriptionOfferId,\n AdaptyDiscountPhase,\n AdaptySubscriptionPeriod,\n AdaptyProfileParameters,\n AdaptyProductIdentifier,\n AdaptyInstallationStatus,\n AdaptyInstallationDetails,\n} from '@adapty/core';\n\nexport {\n WebPresentation,\n RefundPreference,\n VendorStore,\n OfferType,\n CancellationReason,\n Gender,\n AppTrackingTransparencyStatus,\n ProductPeriod,\n ErrorCode,\n ErrorCodeName,\n getErrorCode,\n getErrorPrompt,\n} from '@adapty/core';\n\n// Re-export local modules that are NOT in core\nexport * from './inputs';\nexport * from './flow-events';\nexport * from './onboarding-events';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { LogLevel, FetchPolicy, AdaptyAndroidSubscriptionUpdateReplacementMode, type ActivateParamsInput, type IdentifyParamsInput, type MakePurchaseParamsInput, type
|
|
1
|
+
export { LogLevel, FetchPolicy, AdaptyAndroidSubscriptionUpdateReplacementMode, type ActivateParamsInput, type IdentifyParamsInput, type MakePurchaseParamsInput, type AdaptyAndroidPurchaseParams, type GetPlacementParamsInput, type GetPlacementForDefaultAudienceParamsInput, type GetPaywallProductsParamsInput, type FileLocation, } from '@adapty/core';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputs.js","sourceRoot":"","sources":["../../../src/types/inputs.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,EACX,8CAA8C,
|
|
1
|
+
{"version":3,"file":"inputs.js","sourceRoot":"","sources":["../../../src/types/inputs.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,EACX,8CAA8C,GAS/C,MAAM,cAAc,CAAC","sourcesContent":["export {\n LogLevel,\n FetchPolicy,\n AdaptyAndroidSubscriptionUpdateReplacementMode,\n type ActivateParamsInput,\n type IdentifyParamsInput,\n type MakePurchaseParamsInput,\n type AdaptyAndroidPurchaseParams,\n type GetPlacementParamsInput,\n type GetPlacementForDefaultAudienceParamsInput,\n type GetPaywallProductsParamsInput,\n type FileLocation,\n} from '@adapty/core';\n"]}
|
|
@@ -43,6 +43,12 @@ export declare abstract class BaseViewEmitter<TEventHandlers extends Record<stri
|
|
|
43
43
|
* Abstract method to get emitter name for error messages
|
|
44
44
|
*/
|
|
45
45
|
protected abstract getEmitterName(): string;
|
|
46
|
+
/**
|
|
47
|
+
* Hook for subclasses to fully handle an event themselves (e.g. async
|
|
48
|
+
* request/response round-trips). Return true to skip the standard
|
|
49
|
+
* "call handler → maybe close view" dispatch for this event.
|
|
50
|
+
*/
|
|
51
|
+
protected handleSpecialEvent(_handlerName: keyof TEventHandlers, _eventData: TEventData): boolean;
|
|
46
52
|
addListener(event: keyof TEventHandlers, callback: TEventHandlers[keyof TEventHandlers], onRequestClose: () => Promise<void>): Promise<PluginListenerHandle>;
|
|
47
53
|
addInternalListener(event: keyof TEventHandlers, callback: (event: TEventData) => void): Promise<PluginListenerHandle>;
|
|
48
54
|
removeAllListeners(): void;
|
|
@@ -11,6 +11,14 @@ export class BaseViewEmitter {
|
|
|
11
11
|
this.internalHandlers = new Map();
|
|
12
12
|
this.viewId = viewId;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Hook for subclasses to fully handle an event themselves (e.g. async
|
|
16
|
+
* request/response round-trips). Return true to skip the standard
|
|
17
|
+
* "call handler → maybe close view" dispatch for this event.
|
|
18
|
+
*/
|
|
19
|
+
handleSpecialEvent(_handlerName, _eventData) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
14
22
|
async addListener(event, callback, onRequestClose) {
|
|
15
23
|
const nativeEvent = this.getNativeEventForHandler(event);
|
|
16
24
|
if (!nativeEvent) {
|
|
@@ -79,6 +87,10 @@ export class BaseViewEmitter {
|
|
|
79
87
|
if (!handlerName) {
|
|
80
88
|
return;
|
|
81
89
|
}
|
|
90
|
+
if (this.handleSpecialEvent(handlerName, eventData)) {
|
|
91
|
+
log.success(() => ({ message: 'Special event handled', handlerName }));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
82
94
|
// 1. Client handler (single)
|
|
83
95
|
const handlerData = this.handlers.get(handlerName);
|
|
84
96
|
if (handlerData) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-view-emitter.js","sourceRoot":"","sources":["../../../src/ui-builder/base-view-emitter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAWvC;;;GAGG;AACH,MAAM,OAAgB,eAAe;IAUnC,YAAY,MAAc;QAJhB,mBAAc,GAA4C,IAAI,GAAG,EAAE,CAAC;QACpE,aAAQ,GAAiF,IAAI,GAAG,EAAE,CAAC;QACnG,qBAAgB,GAAwE,IAAI,GAAG,EAAE,CAAC;QAG1G,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAmCM,KAAK,CAAC,WAAW,CACtB,KAA2B,EAC3B,QAA8C,EAC9C,cAAmC;QAEnC,MAAM,WAAW,GAAG,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;QACzD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,8CAA8C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W,EAAE,CAAC,CAAC,CAAC;gBAC7C,CAAC;YACH,CAAC;YAED,sBAAsB;YACtB,MAAM,mBAAmB,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;YACnE,IAAI,mBAAmB,EAAE,CAAC;gBACxB,IAAI,CAAC;oBACH,mBAAmB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;gBACzC,CAAC;gBAAC,OAAO,KAAc,EAAE,CAAC;oBACxB,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;gBAChF,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;QACnD,OAAO,YAAY,CAAC;IACtB,CAAC;IAEO,KAAK,CAAC,yBAAyB,CAAC,WAAyB;QAC/D,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACtD,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;QAC7D,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,mCAAmC,WAAW,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nimport { AdaptyCapacitorPlugin } from '../bridge/plugin';\nimport { LogContext } from '../logger';\n\nexport interface CapacitorEventArg {\n data: string; // JSON string from native\n}\n\nexport interface HandlerData<THandler> {\n handler: THandler;\n onRequestClose: () => Promise<void>;\n}\n\n/**\n * Base class for view event emitters that manages common event handling logic.\n * Each event type can have only one handler - new handlers replace existing ones.\n */\nexport abstract class BaseViewEmitter<\n TEventHandlers extends Record<string, any>,\n TEventData,\n TNativeEvent extends string = string,\n> {\n protected viewId: string;\n protected eventListeners: Map<TNativeEvent, PluginListenerHandle> = new Map();\n protected handlers: Map<keyof TEventHandlers, HandlerData<TEventHandlers[keyof TEventHandlers]>> = new Map();\n protected internalHandlers: Map<keyof TEventHandlers, { handler: (event: TEventData) => void }> = new Map();\n\n constructor(viewId: string) {\n this.viewId = viewId;\n }\n\n /**\n * Abstract method to parse event data from JSON string\n */\n protected abstract parseEventData(rawEventData: string, ctx: LogContext): TEventData;\n\n /**\n * Abstract method to get native event name for handler\n */\n protected abstract getNativeEventForHandler(event: keyof TEventHandlers): TNativeEvent | null;\n\n /**\n * Resolves handler name for incoming native event based on parsed data\n */\n protected abstract getHandlerForNativeEvent(\n nativeEvent: TNativeEvent,\n eventData: TEventData,\n ): keyof TEventHandlers | null;\n\n /**\n * Abstract method to extract callback arguments for a specific handler\n */\n protected abstract extractCallbackArgs(handlerName: keyof TEventHandlers, eventData: TEventData): unknown[];\n\n /**\n * Abstract method to get view ID from parsed event data\n */\n protected abstract getEventViewId(eventData: TEventData): string | null;\n\n /**\n * Abstract method to get emitter name for error messages\n */\n protected abstract getEmitterName(): string;\n\n public async addListener(\n event: keyof TEventHandlers,\n callback: TEventHandlers[keyof TEventHandlers],\n onRequestClose: () => Promise<void>,\n ): Promise<PluginListenerHandle> {\n const nativeEvent = this.getNativeEventForHandler(event);\n if (!nativeEvent) {\n throw new Error(`No native event mapping found for handler: ${String(event)}`);\n }\n\n // Replace existing handler for this event type\n this.handlers.set(event, {\n handler: callback,\n onRequestClose,\n });\n\n return await this.getOrCreateNativeListener(nativeEvent);\n }\n\n public async addInternalListener(\n event: keyof TEventHandlers,\n callback: (event: TEventData) => void,\n ): Promise<PluginListenerHandle> {\n const nativeEvent = this.getNativeEventForHandler(event);\n if (!nativeEvent) {\n throw new Error(`No native event mapping found for handler: ${String(event)}`);\n }\n\n this.internalHandlers.set(event, { handler: callback });\n\n return await this.getOrCreateNativeListener(nativeEvent);\n }\n\n public removeAllListeners(): void {\n this.eventListeners.forEach((subscription) => {\n subscription.remove().catch(() => {\n // intentionally ignore errors during cleanup\n });\n });\n this.eventListeners.clear();\n this.handlers.clear();\n this.internalHandlers.clear();\n }\n\n private async createNativeListener(nativeEvent: TNativeEvent): Promise<PluginListenerHandle> {\n const emitterName = this.getEmitterName();\n const viewId = this.viewId;\n\n const subscription = await AdaptyCapacitorPlugin.addListener(nativeEvent, (arg: CapacitorEventArg) => {\n const ctx = new LogContext();\n const log = ctx.event({ methodName: nativeEvent });\n log.start(() => ({ raw: arg }));\n\n // Strict validation: events must come in {data: \"json_string\"} format\n if (!arg || typeof arg !== 'object' || !arg.data) {\n const error = new Error(\n `[${emitterName}] Invalid event format received. Expected {data: \"json_string\"}, got: ${JSON.stringify(arg)}`,\n );\n log.failed(() => ({ error }));\n throw error;\n }\n\n const rawEventData: string = arg.data;\n\n // Parse JSON string using specific parser with decode logging\n let eventData: TEventData;\n if (typeof rawEventData === 'string') {\n try {\n eventData = this.parseEventData(rawEventData, ctx);\n } catch (error) {\n log.failed(() => ({ error }));\n throw error;\n }\n } else {\n const err = new Error(\n `[${emitterName}] Expected event data to be JSON string, got ${typeof rawEventData}: ${rawEventData}`,\n );\n log.failed(() => ({ error: err }));\n throw err;\n }\n\n const eventViewId = this.getEventViewId(eventData);\n if (viewId !== eventViewId) {\n return;\n }\n\n const handlerName = this.getHandlerForNativeEvent(nativeEvent, eventData);\n if (!handlerName) {\n return;\n }\n\n // 1. Client handler (single)\n const handlerData = this.handlers.get(handlerName);\n if (handlerData) {\n const { handler, onRequestClose } = handlerData;\n const callbackArgs = this.extractCallbackArgs(handlerName, eventData);\n\n const cb = handler as (...args: typeof callbackArgs) => boolean;\n try {\n const shouldClose = cb(...callbackArgs);\n if (shouldClose) {\n onRequestClose().catch((error) => {\n log.failed(() => ({ error, handlerName }));\n });\n }\n log.success(() => ({ message: 'Event handled successfully', handlerName }));\n } catch (error) {\n log.failed(() => ({ error, handlerName }));\n }\n }\n\n // 2. Internal handler\n const internalHandlerData = this.internalHandlers.get(handlerName);\n if (internalHandlerData) {\n try {\n internalHandlerData.handler(eventData);\n } catch (error: unknown) {\n log.failed(() => ({ error, handlerName: `internal:${String(handlerName)}` }));\n }\n }\n });\n\n this.eventListeners.set(nativeEvent, subscription);\n return subscription;\n }\n\n private async getOrCreateNativeListener(nativeEvent: TNativeEvent): Promise<PluginListenerHandle> {\n const existing = this.eventListeners.get(nativeEvent);\n if (existing) {\n return existing;\n }\n\n const created = await this.createNativeListener(nativeEvent);\n if (!created) {\n throw new Error(`Failed to register listener for ${nativeEvent}`);\n }\n return created;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base-view-emitter.js","sourceRoot":"","sources":["../../../src/ui-builder/base-view-emitter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAWvC;;;GAGG;AACH,MAAM,OAAgB,eAAe;IAUnC,YAAY,MAAc;QAJhB,mBAAc,GAA4C,IAAI,GAAG,EAAE,CAAC;QACpE,aAAQ,GAAiF,IAAI,GAAG,EAAE,CAAC;QACnG,qBAAgB,GAAwE,IAAI,GAAG,EAAE,CAAC;QAG1G,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAmCD;;;;OAIG;IACO,kBAAkB,CAAC,YAAkC,EAAE,UAAsB;QACrF,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,KAAK,CAAC,WAAW,CACtB,KAA2B,EAC3B,QAA8C,EAC9C,cAAmC;QAEnC,MAAM,WAAW,GAAG,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;QACzD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,8CAA8C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import type { PluginListenerHandle } from '@capacitor/core';\n\nimport { AdaptyCapacitorPlugin } from '../bridge/plugin';\nimport { LogContext } from '../logger';\n\nexport interface CapacitorEventArg {\n data: string; // JSON string from native\n}\n\nexport interface HandlerData<THandler> {\n handler: THandler;\n onRequestClose: () => Promise<void>;\n}\n\n/**\n * Base class for view event emitters that manages common event handling logic.\n * Each event type can have only one handler - new handlers replace existing ones.\n */\nexport abstract class BaseViewEmitter<\n TEventHandlers extends Record<string, any>,\n TEventData,\n TNativeEvent extends string = string,\n> {\n protected viewId: string;\n protected eventListeners: Map<TNativeEvent, PluginListenerHandle> = new Map();\n protected handlers: Map<keyof TEventHandlers, HandlerData<TEventHandlers[keyof TEventHandlers]>> = new Map();\n protected internalHandlers: Map<keyof TEventHandlers, { handler: (event: TEventData) => void }> = new Map();\n\n constructor(viewId: string) {\n this.viewId = viewId;\n }\n\n /**\n * Abstract method to parse event data from JSON string\n */\n protected abstract parseEventData(rawEventData: string, ctx: LogContext): TEventData;\n\n /**\n * Abstract method to get native event name for handler\n */\n protected abstract getNativeEventForHandler(event: keyof TEventHandlers): TNativeEvent | null;\n\n /**\n * Resolves handler name for incoming native event based on parsed data\n */\n protected abstract getHandlerForNativeEvent(\n nativeEvent: TNativeEvent,\n eventData: TEventData,\n ): keyof TEventHandlers | null;\n\n /**\n * Abstract method to extract callback arguments for a specific handler\n */\n protected abstract extractCallbackArgs(handlerName: keyof TEventHandlers, eventData: TEventData): unknown[];\n\n /**\n * Abstract method to get view ID from parsed event data\n */\n protected abstract getEventViewId(eventData: TEventData): string | null;\n\n /**\n * Abstract method to get emitter name for error messages\n */\n protected abstract getEmitterName(): string;\n\n /**\n * Hook for subclasses to fully handle an event themselves (e.g. async\n * request/response round-trips). Return true to skip the standard\n * \"call handler → maybe close view\" dispatch for this event.\n */\n protected handleSpecialEvent(_handlerName: keyof TEventHandlers, _eventData: TEventData): boolean {\n return false;\n }\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 if (this.handleSpecialEvent(handlerName, eventData)) {\n log.success(() => ({ message: 'Special event handled', 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"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AdaptyFlow } from '../types';
|
|
2
|
+
import { FlowViewController } from './flow-view-controller';
|
|
3
|
+
import type { CreateFlowViewParamsInput } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a flow view controller. Use it to further configure a view or present it.
|
|
6
|
+
*
|
|
7
|
+
* @see {@link https://adapty.io/docs/capacitor-present-paywalls | [DOC] Creating a flow view}
|
|
8
|
+
*
|
|
9
|
+
* @param {AdaptyFlow} flow - flow to present (from `adapty.getFlow(...)`).
|
|
10
|
+
* @param {CreateFlowViewParamsInput} [params] - additional params.
|
|
11
|
+
* @returns {Promise<FlowViewController>}
|
|
12
|
+
* @throws {AdaptyError} if the flow has no view configured or view creation fails.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createFlowView(flow: AdaptyFlow, params?: CreateFlowViewParamsInput): Promise<FlowViewController>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { adapty } from '../adapty-instance';
|
|
2
|
+
import { FlowViewController } from './flow-view-controller';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a flow view controller. Use it to further configure a view or present it.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://adapty.io/docs/capacitor-present-paywalls | [DOC] Creating a flow view}
|
|
7
|
+
*
|
|
8
|
+
* @param {AdaptyFlow} flow - flow to present (from `adapty.getFlow(...)`).
|
|
9
|
+
* @param {CreateFlowViewParamsInput} [params] - additional params.
|
|
10
|
+
* @returns {Promise<FlowViewController>}
|
|
11
|
+
* @throws {AdaptyError} if the flow has no view configured or view creation fails.
|
|
12
|
+
*/
|
|
13
|
+
export async function createFlowView(flow, params = {}) {
|
|
14
|
+
return FlowViewController.create(flow, params, adapty);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=create-flow-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-flow-view.js","sourceRoot":"","sources":["../../../src/ui-builder/create-flow-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAG5D;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,IAAgB,EAChB,SAAoC,EAAE;IAEtC,OAAO,kBAAkB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC","sourcesContent":["import { adapty } from '../adapty-instance';\nimport type { AdaptyFlow } from '../types';\n\nimport { FlowViewController } from './flow-view-controller';\nimport type { CreateFlowViewParamsInput } from './types';\n\n/**\n * Creates a flow view controller. Use it to further configure a view or present it.\n *\n * @see {@link https://adapty.io/docs/capacitor-present-paywalls | [DOC] Creating a flow view}\n *\n * @param {AdaptyFlow} flow - flow to present (from `adapty.getFlow(...)`).\n * @param {CreateFlowViewParamsInput} [params] - additional params.\n * @returns {Promise<FlowViewController>}\n * @throws {AdaptyError} if the flow has no view configured or view creation fails.\n */\nexport async function createFlowView(\n flow: AdaptyFlow,\n params: CreateFlowViewParamsInput = {},\n): Promise<FlowViewController> {\n return FlowViewController.create(flow, params, adapty);\n}\n"]}
|
|
@@ -5,6 +5,8 @@ import type { CreateOnboardingViewParamsInput } from './types';
|
|
|
5
5
|
* Creates an onboarding view controller.
|
|
6
6
|
* You can use it to further configure a view or present it.
|
|
7
7
|
*
|
|
8
|
+
* @deprecated Since 4.0.0. Migrate onboardings to the Flow Builder API.
|
|
9
|
+
*
|
|
8
10
|
* @see {@link https://adapty.io/docs/capacitor-get-onboardings | [DOC] Creating an onboarding view}
|
|
9
11
|
*
|
|
10
12
|
* @param {AdaptyOnboarding} onboarding - onboarding that you want to present.
|
|
@@ -5,6 +5,8 @@ const adaptyPlugin = new Adapty();
|
|
|
5
5
|
* Creates an onboarding view controller.
|
|
6
6
|
* You can use it to further configure a view or present it.
|
|
7
7
|
*
|
|
8
|
+
* @deprecated Since 4.0.0. Migrate onboardings to the Flow Builder API.
|
|
9
|
+
*
|
|
8
10
|
* @see {@link https://adapty.io/docs/capacitor-get-onboardings | [DOC] Creating an onboarding view}
|
|
9
11
|
*
|
|
10
12
|
* @param {AdaptyOnboarding} onboarding - onboarding that you want to present.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-onboarding-view.js","sourceRoot":"","sources":["../../../src/ui-builder/create-onboarding-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAGxE,MAAM,YAAY,GAAG,IAAI,MAAM,EAAE,CAAC;AAElC
|
|
1
|
+
{"version":3,"file":"create-onboarding-view.js","sourceRoot":"","sources":["../../../src/ui-builder/create-onboarding-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAGxE,MAAM,YAAY,GAAG,IAAI,MAAM,EAAE,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,UAA4B,EAC5B,SAA0C,EAAE;IAE5C,MAAM,UAAU,GAAG,MAAM,wBAAwB,CAAC,MAAM,CAAC,UAAU,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IAC3F,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { Adapty } from '../adapty';\nimport type { AdaptyOnboarding } from '../types';\n\nimport { OnboardingViewController } from './onboarding-view-controller';\nimport type { CreateOnboardingViewParamsInput } from './types';\n\nconst adaptyPlugin = new Adapty();\n\n/**\n * Creates an onboarding view controller.\n * You can use it to further configure a view or present it.\n *\n * @deprecated Since 4.0.0. Migrate onboardings to the Flow Builder API.\n *\n * @see {@link https://adapty.io/docs/capacitor-get-onboardings | [DOC] Creating an onboarding view}\n *\n * @param {AdaptyOnboarding} onboarding - onboarding that you want to present.\n * @param {CreateOnboardingViewParamsInput | undefined} [params] - additional params.\n * @returns {Promise<OnboardingViewController>} ViewController — A promise that resolves to a ViewController instance.\n *\n * @example\n * ```ts\n * const onboarding = await adapty.getOnboarding({ placementId: 'MY_PLACEMENT' });\n * const view = await createOnboardingView(onboarding);\n * view.present();\n * ```\n *\n * @example\n * ```ts\n * const view = await createOnboardingView(onboarding, {\n * externalUrlsPresentation: WebPresentation.BrowserOutApp\n * });\n * ```\n *\n * @throws {AdaptyError} — If onboarding is not found,\n * does not have a no-code view configured\n * or if there is an error while creating a view.\n */\nexport async function createOnboardingView(\n onboarding: AdaptyOnboarding,\n params: CreateOnboardingViewParamsInput = {},\n): Promise<OnboardingViewController> {\n const controller = await OnboardingViewController.create(onboarding, adaptyPlugin, params);\n return controller;\n}\n"]}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { Adapty } from '../adapty';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { AdaptyFlow } from '../types';
|
|
3
|
+
import type { CreateFlowViewParamsInput, AdaptyUiDialogConfig, AdaptyUiDialogActionType, FlowEventHandlers, AdaptyIOSPresentationStyle } from './types';
|
|
4
4
|
/**
|
|
5
|
-
* Controller for managing
|
|
5
|
+
* Controller for managing flow views.
|
|
6
6
|
*
|
|
7
7
|
* @remarks
|
|
8
|
-
* This class provides methods to present, dismiss, and handle events for
|
|
9
|
-
* created with the
|
|
8
|
+
* This class provides methods to present, dismiss, and handle events for flow views
|
|
9
|
+
* created with the Flow Builder. Create instances using the {@link createFlowView} function
|
|
10
10
|
* rather than directly constructing this class.
|
|
11
11
|
*
|
|
12
12
|
* @public
|
|
13
13
|
*/
|
|
14
|
-
export declare class
|
|
14
|
+
export declare class FlowViewController {
|
|
15
15
|
private id;
|
|
16
16
|
private adaptyPlugin;
|
|
17
17
|
private viewEmitter;
|
|
@@ -21,35 +21,35 @@ export declare class PaywallViewController {
|
|
|
21
21
|
* and creates reference between native controller and JS instance
|
|
22
22
|
* @internal
|
|
23
23
|
*/
|
|
24
|
-
static create(
|
|
24
|
+
static create(flow: AdaptyFlow, params: CreateFlowViewParamsInput, adaptyPlugin: Adapty): Promise<FlowViewController>;
|
|
25
25
|
/**
|
|
26
26
|
* Since constructors in JS cannot be async, it is not
|
|
27
27
|
* preferred to create ViewControllers in direct way.
|
|
28
|
-
* Consider using @link
|
|
28
|
+
* Consider using {@link FlowViewController.create} instead
|
|
29
29
|
*
|
|
30
30
|
* @internal
|
|
31
31
|
*/
|
|
32
32
|
private constructor();
|
|
33
33
|
/**
|
|
34
|
-
* Presents the
|
|
34
|
+
* Presents the flow view as a modal screen.
|
|
35
35
|
*
|
|
36
36
|
* @remarks
|
|
37
|
-
* Calling `present` on an already visible
|
|
38
|
-
* The
|
|
39
|
-
* On Android, the
|
|
37
|
+
* Calling `present` on an already visible flow view will result in an error.
|
|
38
|
+
* The flow will be displayed with the configured presentation style on iOS.
|
|
39
|
+
* On Android, the flow is always presented as a full-screen activity.
|
|
40
40
|
*
|
|
41
41
|
* @param options - Optional presentation options
|
|
42
42
|
* @param options.iosPresentationStyle - iOS presentation style. Available options: `'full_screen'` (default) or `'page_sheet'`. Only affects iOS platform.
|
|
43
|
-
* @returns A promise that resolves when the
|
|
43
|
+
* @returns A promise that resolves when the flow is presented.
|
|
44
44
|
* @throws {@link AdaptyError} if the view reference is invalid or the view is already presented.
|
|
45
45
|
*
|
|
46
46
|
* @example
|
|
47
47
|
* Present with default full-screen style
|
|
48
48
|
* ```typescript
|
|
49
|
-
* import { adapty,
|
|
49
|
+
* import { adapty, createFlowView } from '@adapty/capacitor';
|
|
50
50
|
*
|
|
51
|
-
* const
|
|
52
|
-
* const view = await
|
|
51
|
+
* const flow = await adapty.getFlow({ placementId: 'YOUR_PLACEMENT_ID' });
|
|
52
|
+
* const view = await createFlowView(flow);
|
|
53
53
|
* await view.present();
|
|
54
54
|
* ```
|
|
55
55
|
*
|
|
@@ -63,20 +63,20 @@ export declare class PaywallViewController {
|
|
|
63
63
|
iosPresentationStyle?: AdaptyIOSPresentationStyle;
|
|
64
64
|
}): Promise<void>;
|
|
65
65
|
/**
|
|
66
|
-
* Dismisses the
|
|
66
|
+
* Dismisses the flow view.
|
|
67
67
|
*
|
|
68
68
|
* @remarks
|
|
69
|
-
* This method closes the
|
|
69
|
+
* This method closes the flow and cleans up associated resources.
|
|
70
70
|
* After dismissing, the view controller instance cannot be reused.
|
|
71
71
|
*
|
|
72
|
-
* @returns A promise that resolves when the
|
|
72
|
+
* @returns A promise that resolves when the flow is dismissed.
|
|
73
73
|
* @throws {@link AdaptyError} if the view reference is invalid.
|
|
74
74
|
*
|
|
75
75
|
* @example
|
|
76
76
|
* ```typescript
|
|
77
|
-
* import {
|
|
77
|
+
* import { createFlowView } from '@adapty/capacitor';
|
|
78
78
|
*
|
|
79
|
-
* const view = await
|
|
79
|
+
* const view = await createFlowView(flow);
|
|
80
80
|
* await view.present();
|
|
81
81
|
* // ... later
|
|
82
82
|
* await view.dismiss();
|
|
@@ -87,7 +87,7 @@ export declare class PaywallViewController {
|
|
|
87
87
|
* Displays a dialog to the user.
|
|
88
88
|
*
|
|
89
89
|
* @remarks
|
|
90
|
-
* Use this method to show custom dialogs within the
|
|
90
|
+
* Use this method to show custom dialogs within the flow.
|
|
91
91
|
* If you provide two actions in the config, the primary action should cancel the operation
|
|
92
92
|
* and leave things unchanged, while the secondary action should confirm the operation.
|
|
93
93
|
*
|
|
@@ -117,20 +117,20 @@ export declare class PaywallViewController {
|
|
|
117
117
|
showDialog(config: AdaptyUiDialogConfig): Promise<AdaptyUiDialogActionType>;
|
|
118
118
|
private onRequestClose;
|
|
119
119
|
/**
|
|
120
|
-
* Registers event handlers for
|
|
120
|
+
* Registers event handlers for flow UI events.
|
|
121
121
|
*
|
|
122
122
|
* @remarks
|
|
123
123
|
* Each event type can have only one handler — new handlers replace existing ones.
|
|
124
|
-
* Default handlers are registered automatically in {@link
|
|
125
|
-
*
|
|
126
|
-
* - `
|
|
127
|
-
* - `
|
|
128
|
-
* -
|
|
129
|
-
*
|
|
124
|
+
* Default handlers are registered automatically in {@link createFlowView} (see `DEFAULT_FLOW_EVENT_HANDLERS`).
|
|
125
|
+
* Only two defaults close the view; all others keep it open:
|
|
126
|
+
* - `onCloseButtonPress` - closes the view (returns `true`)
|
|
127
|
+
* - `onError` - closes the view (returns `true`)
|
|
128
|
+
* - all other handlers keep the view open by default (return `false`),
|
|
129
|
+
* including `onAndroidSystemBack`, `onRestoreCompleted`, and `onPurchaseCompleted`
|
|
130
130
|
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
131
|
+
* Returning `true` from a handler closes the view; returning `false` keeps it open.
|
|
132
|
+
* To retain default behavior in a custom listener, return the same value as the default
|
|
133
|
+
* implementation (only `onCloseButtonPress` and `onError` close the view by default).
|
|
134
134
|
*
|
|
135
135
|
* Calling this method multiple times will replace previously registered handlers for provided events.
|
|
136
136
|
*
|
|
@@ -142,9 +142,9 @@ export declare class PaywallViewController {
|
|
|
142
142
|
* @example
|
|
143
143
|
* Register custom event handlers
|
|
144
144
|
* ```typescript
|
|
145
|
-
* import {
|
|
145
|
+
* import { createFlowView } from '@adapty/capacitor';
|
|
146
146
|
*
|
|
147
|
-
* const view = await
|
|
147
|
+
* const view = await createFlowView(flow);
|
|
148
148
|
*
|
|
149
149
|
* const unsubscribe = await view.setEventHandlers({
|
|
150
150
|
* onPurchaseStarted: (product) => {
|
|
@@ -152,7 +152,7 @@ export declare class PaywallViewController {
|
|
|
152
152
|
* },
|
|
153
153
|
* onPurchaseCompleted: (result) => {
|
|
154
154
|
* console.log('Purchase completed:', result.type);
|
|
155
|
-
* // Return true to
|
|
155
|
+
* // Return true to close the view after purchase (default keeps it open)
|
|
156
156
|
* return result.type !== 'user_cancelled';
|
|
157
157
|
* },
|
|
158
158
|
* onPurchaseFailed: (error) => {
|
|
@@ -166,7 +166,7 @@ export declare class PaywallViewController {
|
|
|
166
166
|
* unsubscribe();
|
|
167
167
|
* ```
|
|
168
168
|
*/
|
|
169
|
-
setEventHandlers(eventHandlers?: Partial<
|
|
169
|
+
setEventHandlers(eventHandlers?: Partial<FlowEventHandlers>): Promise<() => void>;
|
|
170
170
|
/**
|
|
171
171
|
* Clears all registered event handlers.
|
|
172
172
|
*
|
|
@@ -179,7 +179,7 @@ export declare class PaywallViewController {
|
|
|
179
179
|
*
|
|
180
180
|
* @example
|
|
181
181
|
* ```typescript
|
|
182
|
-
* const view = await
|
|
182
|
+
* const view = await createFlowView(flow);
|
|
183
183
|
* await view.setEventHandlers({ onPurchaseCompleted: handlePurchase });
|
|
184
184
|
*
|
|
185
185
|
* // Later, clear all handlers
|