From 39ca61911fc34d4bea3274005be29aab91b6d6e9 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Wed, 16 Sep 2026 19:32:45 +0300 Subject: [PATCH 01/25] feat: add adapty_ui_destroy_flow_view to the cross-platform schema Mirrors the block that landed in AdaptySDK-iOS: an explicit method for releasing a cached native flow view, replacing the adapty_ui_dismiss_flow_view call with destroy: true that wrappers use today for a view that is already off screen. src/types/api.d.ts is regenerated from the yaml; MethodNames gains the entry bridge.test.ts checks against the schema. --- cross_platform.yaml | 18 ++++++++++++++++++ src/types/api.d.ts | 9 +++++++++ src/types/bridge.ts | 1 + 3 files changed, 28 insertions(+) diff --git a/cross_platform.yaml b/cross_platform.yaml index bbd1335..ec5036c 100644 --- a/cross_platform.yaml +++ b/cross_platform.yaml @@ -117,6 +117,24 @@ $requests: properties: success: { const: true } + ### destroyFlowView ### + AdaptyUIDestroyFlowView.Request: #request + type: object + required: [method, id] + properties: + method: { const: "adapty_ui_destroy_flow_view" } + id: { type: string, description: "View Id" } + + AdaptyUIDestroyFlowView.Response: #response + type: object + oneOf: + - required: [error] + properties: + error: { $ref: "#/$defs/AdaptyError" } + - required: [success] + properties: + success: { const: true } + ### presentOnboardingView ### AdaptyUIPresentOnboardingView.Request: #request type: object diff --git a/src/types/api.d.ts b/src/types/api.d.ts index 3ec5eb8..7862b12 100644 --- a/src/types/api.d.ts +++ b/src/types/api.d.ts @@ -78,6 +78,15 @@ export interface components { [{ error: components['defs']['AdaptyError'] }, { success: true }] >; + 'AdaptyUIDestroyFlowView.Request': { + method: 'adapty_ui_destroy_flow_view'; + id: string; + }; + + 'AdaptyUIDestroyFlowView.Response': OneOf< + [{ error: components['defs']['AdaptyError'] }, { success: true }] + >; + 'AdaptyUIPresentOnboardingView.Request': { method: 'adapty_ui_present_onboarding_view'; id: string; diff --git a/src/types/bridge.ts b/src/types/bridge.ts index 963e211..1e37cd0 100644 --- a/src/types/bridge.ts +++ b/src/types/bridge.ts @@ -11,6 +11,7 @@ import type { Event } from './schema'; export const MethodNames = [ 'activate', 'adapty_ui_create_flow_view', + 'adapty_ui_destroy_flow_view', 'adapty_ui_dismiss_flow_view', 'adapty_ui_present_flow_view', 'adapty_ui_show_dialog', From 3f2035827921feded75444050bfb243aff811c2c Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Fri, 18 Sep 2026 16:44:57 +0300 Subject: [PATCH 02/25] chore: bump version to 4.1.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 403ac53..fdd3bdf 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package", "name": "@adapty/core", - "version": "4.1.2", + "version": "4.1.3", "description": "Platform-agnostic core for Adapty JS SDKs", "license": "MIT", "author": "Adapty team ", From b23b7c1786d14420cddcc72e2ea8d38503fe97f8 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Mon, 21 Sep 2026 22:12:30 +0300 Subject: [PATCH 03/25] chore: update yaml from https://github.com/adaptyteam/AdaptySDK-iOS/commit/c1cd9cda2239cba6ffb50f1dc21dbe6e41612d26 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Schema 4.1.2 -> 4.2.0, package.json version aligned with the iOS SDK release. New requests: preload_flows, preload_flows_for_default_audience, preload_onboardings, preload_onboardings_for_default_audience, get_pending_store_message_types, show_store_messages (iOS 16+). New defs: StoreMessagesHandling, AdaptyStoreMessageType; AdaptyFlow gains variation_name; AdaptyConfiguration gains store_messages_handling. Breaking: adapty_ui_dismiss_flow_view now requires destroy. src/types/api.d.ts is regenerated from the yaml; MethodNames in src/types/bridge.ts gains the six new methods so bridge.test.ts stays in sync. Known gap: AdaptyStoreMessageType is emitted as bare `string` — the codegen script does not handle `type: string` + `anyOf`. Fixed separately. --- cross_platform.yaml | 187 ++++++++++++++++++++++++++++++++++++++++++-- package.json | 2 +- src/types/api.d.ts | 68 +++++++++++++++- src/types/bridge.ts | 6 ++ 4 files changed, 253 insertions(+), 10 deletions(-) diff --git a/cross_platform.yaml b/cross_platform.yaml index ec5036c..aa4db7c 100644 --- a/cross_platform.yaml +++ b/cross_platform.yaml @@ -1,5 +1,5 @@ $schema: "https://json-schema.org/draft/2020-12/schema" -$id: "https://adapty.io/crossPlatform/4.1.2/schema" +$id: "https://adapty.io/crossPlatform/4.2.0/schema" title: "Cross Platform Format" $requests: @@ -101,11 +101,11 @@ $requests: ### dismissFlowView ### AdaptyUIDismissFlowView.Request: #request type: object - required: [method, id] + required: [method, id, destroy] properties: method: { const: "adapty_ui_dismiss_flow_view" } id: { type: string, description: "View Id" } - destroy: { type: boolean, default: false } + destroy: { type: boolean, description: "Release the view after it is dismissed" } AdaptyUIDismissFlowView.Response: #response type: object @@ -309,6 +309,90 @@ $requests: properties: success: { $ref: "#/$defs/AdaptyFlow" } + ### preloadFlows ### + PreloadFlows.Request: #request + type: object + required: [method, placement_ids] + properties: + method: { const: "preload_flows" } + placement_ids: + type: array + items: { type: string } + load_timeout: { type: number, description: "seconds" } + + PreloadFlows.Response: #response + type: object + oneOf: + - required: [error] + properties: + error: { $ref: "#/$defs/AdaptyError" } + - required: [success] + properties: + success: { const: true } + + ### preloadFlowsForDefaultAudience ### + PreloadFlowsForDefaultAudience.Request: #request + type: object + required: [method, placement_ids] + properties: + method: { const: "preload_flows_for_default_audience" } + placement_ids: + type: array + items: { type: string } + + PreloadFlowsForDefaultAudience.Response: #response + type: object + oneOf: + - required: [error] + properties: + error: { $ref: "#/$defs/AdaptyError" } + - required: [success] + properties: + success: { const: true } + + ### preloadOnboardings ### + PreloadOnboardings.Request: #request + type: object + required: [method, placement_ids] + properties: + method: { const: "preload_onboardings" } + placement_ids: + type: array + items: { type: string } + locale: { $ref: "#/$defs/AdaptyLocale" } + load_timeout: { type: number, description: "seconds" } + + PreloadOnboardings.Response: #response + type: object + oneOf: + - required: [error] + properties: + error: { $ref: "#/$defs/AdaptyError" } + - required: [success] + properties: + success: { const: true } + + ### preloadOnboardingsForDefaultAudience ### + PreloadOnboardingsForDefaultAudience.Request: #request + type: object + required: [method, placement_ids] + properties: + method: { const: "preload_onboardings_for_default_audience" } + placement_ids: + type: array + items: { type: string } + locale: { $ref: "#/$defs/AdaptyLocale" } + + PreloadOnboardingsForDefaultAudience.Response: #response + type: object + oneOf: + - required: [error] + properties: + error: { $ref: "#/$defs/AdaptyError" } + - required: [success] + properties: + success: { const: true } + ### getPaywallProducts ### GetPaywallProducts.Request: #request type: object @@ -326,10 +410,10 @@ $requests: - required: [success] properties: success: - { - type: array, - items: { $ref: "#/$defs/AdaptyPaywallProduct.Response" }, - } + type: array + items: { $ref: "#/$defs/AdaptyPaywallProduct.Response" } + + ### getProfile ### GetProfile.Request: #request @@ -483,6 +567,46 @@ $requests: properties: success: { $ref: "#/$defs/AdaptyPurchaseResult" } + ### getPendingStoreMessageTypes ### + GetPendingStoreMessageTypes.Request: #request + type: object + description: "iOS Only. Requires iOS 16+" + required: [method] + properties: + method: { const: "get_pending_store_message_types" } + + GetPendingStoreMessageTypes.Response: #response + type: object + oneOf: + - required: [error] + properties: + error: { $ref: "#/$defs/AdaptyError" } + - required: [success] + properties: + success: + type: array + items: { $ref: "#/$defs/AdaptyStoreMessageType" } + + ### showStoreMessage ### + ShowStoreMessage.Request: #request + type: object + description: "iOS Only. Requires iOS 16+" + required: [method] + properties: + method: { const: "show_store_messages" } + filter: + type: array + items: { $ref: "#/$defs/AdaptyStoreMessageType" } + + ShowStoreMessage.Response: #response + type: object + oneOf: + - required: [error] + properties: + error: { $ref: "#/$defs/AdaptyError" } + - required: [success] + properties: + success: { const: true } OpenWebPaywall.Request: #request type: object required: [method] @@ -1142,7 +1266,34 @@ $defs: Date: #response #request type: string - format: "yyyy-MM-dd'T'HH:mm:ss.SSSZ" + description: | + UTC timestamp in ISO 8601 format. + + Requirements: + - Fractional seconds are required and must contain between 1 and 9 digits. In the `format` property, they are represented by `SSS`; the exact accepted length is defined by the `pattern` property. + - The time zone must be either `Z` or `+0000`. + - `+00:00` and non-zero UTC offsets are not allowed. + + format: "yyyy-MM-dd'T'HH:mm:ss.SSSZ" + Format components: + - `yyyy`: Four-digit year. + - `MM`: Two-digit month (`01`–`12`). + - `dd`: Two-digit day of the month (`01`–`31`). + - `'T'`: Literal separator between the date and time. + - `HH`: Two-digit hour in 24-hour format (`00`–`23`). + - `mm`: Two-digit minute (`00`–`59`). + - `ss`: Two-digit second (`00`–`59`). + - `SSS`: Fractional-seconds field. The accepted value contains between 1 and 9 digits. + - `Z`: Time-zone field. Only `Z` and `+0000` are accepted. + + Format: "yyyy-MM-dd'T'HH:mm:ss.SSSZ" + + Examples: + - 2026-08-24T09:34:24.727Z + - 2026-08-24T09:34:24.727000+0000 + + pattern: '^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]\.[0-9]{1,9}(Z|\+0000)$' + example: '2026-08-24T09:34:24.727000+0000' AdaptyConfiguration: #request type: object @@ -1153,6 +1304,11 @@ $defs: customer_identity_parameters: { $ref: "#/$defs/CustomerIdentityParameters" } observer_mode: { type: boolean, default: false } + store_messages_handling: + { + $ref: "#/$defs/StoreMessagesHandling", + description: "iOS Only. Requires iOS 16+", + } apple_idfa_collection_disabled: { type: boolean, default: false } google_adid_collection_disabled: { type: boolean, default: false } google_enable_pending_prepaid_plans: { type: boolean, default: false } @@ -1175,6 +1331,20 @@ $defs: memory_storage_count_limit: { type: integer } disk_storage_size_limit: { type: integer, description: "bytes" } + StoreMessagesHandling: #request + type: string + enum: ["auto", "manual", "default"] + + AdaptyStoreMessageType: #request #response + type: string + anyOf: + - enum: + - generic + - price_increase_consent + - billing_issue + - win_back_offer + - pattern: "^storekit_-?[0-9]+$" + CustomerIdentityParameters: #request type: object properties: @@ -1384,6 +1554,7 @@ $defs: flow_id: { type: string } flow_name: { type: string } variation_id: { type: string } + variation_name: { type: string } remote_configs: type: array items: { $ref: "#/$defs/AdaptyRemoteConfig" } diff --git a/package.json b/package.json index fdd3bdf..1259920 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package", "name": "@adapty/core", - "version": "4.1.3", + "version": "4.2.0", "description": "Platform-agnostic core for Adapty JS SDKs", "license": "MIT", "author": "Adapty team ", diff --git a/src/types/api.d.ts b/src/types/api.d.ts index 7862b12..7e69d90 100644 --- a/src/types/api.d.ts +++ b/src/types/api.d.ts @@ -71,7 +71,7 @@ export interface components { 'AdaptyUIDismissFlowView.Request': { method: 'adapty_ui_dismiss_flow_view'; id: string; - destroy?: boolean; + destroy: boolean; }; 'AdaptyUIDismissFlowView.Response': OneOf< @@ -194,6 +194,46 @@ export interface components { ] >; + 'PreloadFlows.Request': { + method: 'preload_flows'; + placement_ids: string[]; + load_timeout?: number; + }; + + 'PreloadFlows.Response': OneOf< + [{ error: components['defs']['AdaptyError'] }, { success: true }] + >; + + 'PreloadFlowsForDefaultAudience.Request': { + method: 'preload_flows_for_default_audience'; + placement_ids: string[]; + }; + + 'PreloadFlowsForDefaultAudience.Response': OneOf< + [{ error: components['defs']['AdaptyError'] }, { success: true }] + >; + + 'PreloadOnboardings.Request': { + method: 'preload_onboardings'; + placement_ids: string[]; + locale?: components['defs']['AdaptyLocale']; + load_timeout?: number; + }; + + 'PreloadOnboardings.Response': OneOf< + [{ error: components['defs']['AdaptyError'] }, { success: true }] + >; + + 'PreloadOnboardingsForDefaultAudience.Request': { + method: 'preload_onboardings_for_default_audience'; + placement_ids: string[]; + locale?: components['defs']['AdaptyLocale']; + }; + + 'PreloadOnboardingsForDefaultAudience.Response': OneOf< + [{ error: components['defs']['AdaptyError'] }, { success: true }] + >; + 'GetPaywallProducts.Request': { method: 'get_paywall_products'; flow: components['defs']['AdaptyFlow']; @@ -294,6 +334,26 @@ export interface components { ] >; + 'GetPendingStoreMessageTypes.Request': { + method: 'get_pending_store_message_types'; + }; + + 'GetPendingStoreMessageTypes.Response': OneOf< + [ + { error: components['defs']['AdaptyError'] }, + { success: components['defs']['AdaptyStoreMessageType'][] }, + ] + >; + + 'ShowStoreMessage.Request': { + method: 'show_store_messages'; + filter?: components['defs']['AdaptyStoreMessageType'][]; + }; + + 'ShowStoreMessage.Response': OneOf< + [{ error: components['defs']['AdaptyError'] }, { success: true }] + >; + 'OpenWebPaywall.Request': { method: 'open_web_paywall'; open_in?: components['defs']['AdaptyWebPresentation']; @@ -716,6 +776,7 @@ export interface components { customer_user_id?: string; customer_identity_parameters?: components['defs']['CustomerIdentityParameters']; observer_mode?: boolean; + store_messages_handling?: components['defs']['StoreMessagesHandling']; apple_idfa_collection_disabled?: boolean; google_adid_collection_disabled?: boolean; google_enable_pending_prepaid_plans?: boolean; @@ -737,6 +798,10 @@ export interface components { }; }; + StoreMessagesHandling: 'auto' | 'manual' | 'default'; + + AdaptyStoreMessageType: string; + CustomerIdentityParameters: { app_account_token?: string; obfuscated_account_id?: string; @@ -852,6 +917,7 @@ export interface components { flow_id: string; flow_name: string; variation_id: string; + variation_name?: string; remote_configs?: components['defs']['AdaptyRemoteConfig'][]; flow_version_id?: string; variations: components['defs']['AdaptyFlowPaywall'][]; diff --git a/src/types/bridge.ts b/src/types/bridge.ts index 1e37cd0..b1a9b5f 100644 --- a/src/types/bridge.ts +++ b/src/types/bridge.ts @@ -24,6 +24,7 @@ export const MethodNames = [ 'get_flow', 'get_flow_for_default_audience', 'get_paywall_products', + 'get_pending_store_message_types', 'get_onboarding', 'get_onboarding_for_default_audience', 'get_profile', @@ -35,12 +36,17 @@ export const MethodNames = [ 'make_promoted_purchase', 'make_purchase', 'open_web_paywall', + 'preload_flows', + 'preload_flows_for_default_audience', + 'preload_onboardings', + 'preload_onboardings_for_default_audience', 'present_code_redemption_sheet', 'report_transaction', 'restore_purchases', 'set_fallback', 'set_integration_identifiers', 'set_log_level', + 'show_store_messages', 'update_collecting_refund_data_consent', 'update_external_attribution_data', 'update_profile', From c8a11a81994e993e01005dccf547d19234d95b69 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Mon, 21 Sep 2026 22:13:59 +0300 Subject: [PATCH 04/25] fix(codegen): render `type: string` + `anyOf` as an open enum union MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolveTopLevelType had no `anyOf` branch, and the plain-string fallback only guarded `enum` and `oneOf`, so a def written as `type: string` + `anyOf` fell through to a bare `string` and its branches were dropped. resolveType does handle `anyOf`, but never got the chance. Output therefore depended on whether the node carried a redundant `type: string`: AdaptyUI.Permission (no `type`) rendered its literals, AdaptyStoreMessageType (with `type`) did not. isPrimitiveOneOf also rejected a branch that only narrows the parent `type: string` with a regex (`- pattern: "^storekit_-?[0-9]+$"`), which would have turned the union into `... | unknown`; such a branch now counts as string. renderPrimitiveUnion emits `(string & {})` instead of `string` when enum literals sit next to an open string branch — TS collapses `'a' | string` to `string`, so the documented values were lost from the type and from autocomplete. This matches the hand-written open enums in src/types. Regenerated: AdaptyStoreMessageType keeps its four literals, and AdaptyUI.Permission plus OnboardingViewEvent.OnAnalyticsEvent.event.name no longer collapse to `string`. --- scripts/generate-api-types.ts | 30 +++++++++++++++++++++++++----- src/types/api.d.ts | 11 ++++++++--- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/scripts/generate-api-types.ts b/scripts/generate-api-types.ts index e0e7c8a..48c25e1 100644 --- a/scripts/generate-api-types.ts +++ b/scripts/generate-api-types.ts @@ -212,13 +212,21 @@ function isPrimitiveOneOf(variants: SchemaNode[]): boolean { if (v.type === 'integer' && !v.properties && !v.oneOf) return true; if (v.type === 'boolean' && !v.properties && !v.oneOf) return true; if (v.enum) return true; + // A branch that only narrows the parent `type: string` with a regex, + // e.g. `- pattern: "^storekit_-?[0-9]+$"`. TS cannot express the pattern, + // so the branch contributes an open `string`. + if (v.pattern && !v.type && !v.properties && !v.oneOf) return true; return false; }); } /** * Renders a union of primitive types and enums. - * E.g., oneOf: [{type: string}, {enum: [a, b, c]}] → 'a' | 'b' | 'c' | string + * E.g., oneOf: [{type: string}, {enum: [a, b, c]}] → 'a' | 'b' | 'c' | (string & {}) + * + * An open `string` next to enum literals is emitted as `(string & {})`: a bare + * `string` would swallow them, since TS collapses `'a' | string` to `string`, + * and the documented values would be lost from both the type and autocomplete. */ function renderPrimitiveUnion(variants: SchemaNode[]): string { const parts: string[] = []; @@ -230,10 +238,14 @@ function renderPrimitiveUnion(variants: SchemaNode[]): string { ); } } + const hasEnumLiterals = parts.length > 0; for (const v of variants) { - if (!v.enum) { - parts.push(resolvePrimitive(v.type)); - } + if (v.enum) continue; + // A `pattern`-only branch inherits `string` from the parent node. + const rendered = !v.type && v.pattern ? 'string' : resolvePrimitive(v.type); + parts.push( + hasEnumLiterals && rendered === 'string' ? '(string & {})' : rendered, + ); } return parts.join(' | '); } @@ -522,6 +534,14 @@ function resolveTopLevelType(node: SchemaNode, depth: number): string { return renderOneOf(node.oneOf, depth); } + // type: string + anyOf → open enum union, e.g. 'a' | 'b' | (string & {}) + if (node.type === 'string' && node.anyOf) { + if (isPrimitiveOneOf(node.anyOf)) { + return renderPrimitiveUnion(node.anyOf); + } + return renderAnyOf(node.anyOf, depth); + } + // type: object with oneOf and no properties → OneOf or discriminated union if (node.type === 'object' && node.oneOf && !node.properties) { if (node.required) { @@ -536,7 +556,7 @@ function resolveTopLevelType(node: SchemaNode, depth: number): string { } // Simple string aliases - if (node.type === 'string' && !node.enum && !node.oneOf) { + if (node.type === 'string' && !node.enum && !node.oneOf && !node.anyOf) { return 'string'; } diff --git a/src/types/api.d.ts b/src/types/api.d.ts index 7e69d90..16b76b1 100644 --- a/src/types/api.d.ts +++ b/src/types/api.d.ts @@ -686,7 +686,7 @@ export interface components { | 'products_screen_presented' | 'user_email_collected' | 'onboarding_completed' - | string; + | (string & {}); element_id?: string; reply?: string; }; @@ -800,7 +800,12 @@ export interface components { StoreMessagesHandling: 'auto' | 'manual' | 'default'; - AdaptyStoreMessageType: string; + AdaptyStoreMessageType: + | 'generic' + | 'price_increase_consent' + | 'billing_issue' + | 'win_back_offer' + | (string & {}); CustomerIdentityParameters: { app_account_token?: string; @@ -1194,7 +1199,7 @@ export interface components { | 'health' | 'siri' | 'music' - | string; + | (string & {}); 'AdaptyUI.CustomTagsValues': { [key: string]: string; From d0ee01030fd54eee2de637f804b3decc8a7a91d2 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Mon, 21 Sep 2026 22:40:24 +0300 Subject: [PATCH 05/25] feat: add PreloadPlacementsParamsInput MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Params type for the placement preload methods landed in schema 4.2.0. Preloading has no fetch policy — it always hits the network and only warms the cache — so the type carries just loadTimeoutMs, and GetPlacementParamsInput would have exposed fetchPolicy/maxAgeSeconds that the requests do not accept. --- src/types/inputs.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/types/inputs.ts b/src/types/inputs.ts index c01e4b8..b0fbcf7 100644 --- a/src/types/inputs.ts +++ b/src/types/inputs.ts @@ -86,6 +86,26 @@ export type GetPlacementForDefaultAudienceParamsInput = maxAgeSeconds: number; }; +/** + * Describes optional parameters for the placement preload methods. + * + * @remarks + * Preloading has no fetch policy: it always goes to the network and only warms + * the placement cache, so unlike {@link GetPlacementParamsInput} the only knob + * is the timeout. + */ +export interface PreloadPlacementsParamsInput { + /** + * This value limits the timeout (in milliseconds) for this method. + * + * @remarks + * The native SDKs clamp anything below 1000 ms up to 1000 ms. Reaching the + * timeout is not an error by itself — the affected placements are retried + * against the default audience source. + */ + loadTimeoutMs?: number; +} + /** * Describes optional parameters for the {@link activate} method. */ From 1133336819102baaa153029bdb7a3b3f4f91835b Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Tue, 22 Sep 2026 15:23:44 +0300 Subject: [PATCH 06/25] feat: drop onboarding preload from the schema preload_onboardings and preload_onboardings_for_default_audience are removed: onboardings are deprecated since 4.0.0 in favour of the Flow Builder API, so there is no reason to carry preload for them into the JS SDKs. The flow variants stay. AdaptySDK-iOS dropped the same four requests in https://github.com/adaptyteam/AdaptySDK-iOS/commit/4a3a7d4b90826e0bdbd71810640aca2aaf6df706, so cross_platform.yaml here stays byte-identical to the one on release/4.2.0 and the next sync has nothing to undo. src/types/api.d.ts is regenerated from the yaml; MethodNames in src/types/bridge.ts loses the two entries so bridge.test.ts stays in sync. --- cross_platform.yaml | 43 ------------------------------------------- src/types/api.d.ts | 21 --------------------- src/types/bridge.ts | 2 -- 3 files changed, 66 deletions(-) diff --git a/cross_platform.yaml b/cross_platform.yaml index aa4db7c..588921d 100644 --- a/cross_platform.yaml +++ b/cross_platform.yaml @@ -350,49 +350,6 @@ $requests: properties: success: { const: true } - ### preloadOnboardings ### - PreloadOnboardings.Request: #request - type: object - required: [method, placement_ids] - properties: - method: { const: "preload_onboardings" } - placement_ids: - type: array - items: { type: string } - locale: { $ref: "#/$defs/AdaptyLocale" } - load_timeout: { type: number, description: "seconds" } - - PreloadOnboardings.Response: #response - type: object - oneOf: - - required: [error] - properties: - error: { $ref: "#/$defs/AdaptyError" } - - required: [success] - properties: - success: { const: true } - - ### preloadOnboardingsForDefaultAudience ### - PreloadOnboardingsForDefaultAudience.Request: #request - type: object - required: [method, placement_ids] - properties: - method: { const: "preload_onboardings_for_default_audience" } - placement_ids: - type: array - items: { type: string } - locale: { $ref: "#/$defs/AdaptyLocale" } - - PreloadOnboardingsForDefaultAudience.Response: #response - type: object - oneOf: - - required: [error] - properties: - error: { $ref: "#/$defs/AdaptyError" } - - required: [success] - properties: - success: { const: true } - ### getPaywallProducts ### GetPaywallProducts.Request: #request type: object diff --git a/src/types/api.d.ts b/src/types/api.d.ts index 16b76b1..7564265 100644 --- a/src/types/api.d.ts +++ b/src/types/api.d.ts @@ -213,27 +213,6 @@ export interface components { [{ error: components['defs']['AdaptyError'] }, { success: true }] >; - 'PreloadOnboardings.Request': { - method: 'preload_onboardings'; - placement_ids: string[]; - locale?: components['defs']['AdaptyLocale']; - load_timeout?: number; - }; - - 'PreloadOnboardings.Response': OneOf< - [{ error: components['defs']['AdaptyError'] }, { success: true }] - >; - - 'PreloadOnboardingsForDefaultAudience.Request': { - method: 'preload_onboardings_for_default_audience'; - placement_ids: string[]; - locale?: components['defs']['AdaptyLocale']; - }; - - 'PreloadOnboardingsForDefaultAudience.Response': OneOf< - [{ error: components['defs']['AdaptyError'] }, { success: true }] - >; - 'GetPaywallProducts.Request': { method: 'get_paywall_products'; flow: components['defs']['AdaptyFlow']; diff --git a/src/types/bridge.ts b/src/types/bridge.ts index b1a9b5f..3b29b4f 100644 --- a/src/types/bridge.ts +++ b/src/types/bridge.ts @@ -38,8 +38,6 @@ export const MethodNames = [ 'open_web_paywall', 'preload_flows', 'preload_flows_for_default_audience', - 'preload_onboardings', - 'preload_onboardings_for_default_audience', 'present_code_redemption_sheet', 'report_transaction', 'restore_purchases', From c2d9981f6d06593c3191d58db7a3f31886caf1d2 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Wed, 23 Sep 2026 11:27:36 +0300 Subject: [PATCH 07/25] feat: map the 4.2.0 schema additions onto the shared models The 4.2.0 yaml added fields that reached api.d.ts but not the hand-written layer, so they were unreachable from the SDKs: - store_messages_handling: exposed as ios.storeMessagesHandling in ActivateParamsInput and encoded by AdaptyConfigurationCoder on iOS only when set, leaving the native default ('auto') otherwise. - variation_name: added to AdaptyFlow as variationName and mapped in AdaptyFlowCoder, so it survives decode and the round-trip back to native. - AdaptyStoreMessageType: public open union for the pending/show store message methods. --- src/coders/adapty-configuration.test.ts | 17 +++++++++++++++++ src/coders/adapty-configuration.ts | 3 +++ src/coders/adapty-flow.test.ts | 2 ++ src/coders/adapty-flow.ts | 1 + src/types/index.ts | 21 +++++++++++++++++++++ src/types/inputs.ts | 12 ++++++++++++ 6 files changed, 56 insertions(+) diff --git a/src/coders/adapty-configuration.test.ts b/src/coders/adapty-configuration.test.ts index 2a5bc19..db5a374 100644 --- a/src/coders/adapty-configuration.test.ts +++ b/src/coders/adapty-configuration.test.ts @@ -210,6 +210,23 @@ describe('AdaptyConfigurationCoder', () => { expect(resultWithTrue.clear_data_on_backup).toBe(true); }); + it('should encode storeMessagesHandling only on ios when set', () => { + expect(coder.encode(apiKey, {}).store_messages_handling).toBeUndefined(); + expect( + coder.encode(apiKey, { ios: { storeMessagesHandling: 'manual' } }) + .store_messages_handling, + ).toBe('manual'); + expect( + coder.encode(apiKey, { ios: { storeMessagesHandling: 'auto' } }) + .store_messages_handling, + ).toBe('auto'); + expect( + createCoder('android').encode(apiKey, { + ios: { storeMessagesHandling: 'manual' }, + }).store_messages_handling, + ).toBeUndefined(); + }); + it('should default adaptyAttributionEnabled to false', () => { expect(coder.encode(apiKey, {}).adapty_attribution_enabled).toBe(false); expect( diff --git a/src/coders/adapty-configuration.ts b/src/coders/adapty-configuration.ts index 10d2fcd..6ec561d 100644 --- a/src/coders/adapty-configuration.ts +++ b/src/coders/adapty-configuration.ts @@ -68,6 +68,9 @@ export class AdaptyConfigurationCoder { if (params.ios?.clearDataOnBackup !== undefined) { config['clear_data_on_backup'] = params.ios.clearDataOnBackup; } + if (params.ios?.storeMessagesHandling) { + config['store_messages_handling'] = params.ios.storeMessagesHandling; + } } if (this.platform.OS === 'android') { diff --git a/src/coders/adapty-flow.test.ts b/src/coders/adapty-flow.test.ts index d1b32dc..430a193 100644 --- a/src/coders/adapty-flow.test.ts +++ b/src/coders/adapty-flow.test.ts @@ -23,6 +23,7 @@ const mocks: Def['AdaptyFlow'][] = [ flow_id: 'flow123', flow_name: 'Flow1', variation_id: 'var001', + variation_name: 'Variation1', response_created_at: 1630458390000, remote_configs: [{ lang: 'en', data: '{"key":"value"}' }], flow_version_id: 'fv1', @@ -109,6 +110,7 @@ function toModel(mock: (typeof mocks)[number]): Model { id: mock.flow_id, name: mock.flow_name, variationId: mock.variation_id, + ...(mock.variation_name && { variationName: mock.variation_name }), hasViewConfiguration: mock.flow_version_id !== undefined && mock.ui_schema !== undefined, ...(mock.remote_configs && { diff --git a/src/coders/adapty-flow.ts b/src/coders/adapty-flow.ts index 3af0647..2968e3c 100644 --- a/src/coders/adapty-flow.ts +++ b/src/coders/adapty-flow.ts @@ -25,6 +25,7 @@ export class AdaptyFlowCoder extends Coder { id: { key: 'flow_id', required: true, type: 'string' }, name: { key: 'flow_name', required: true, type: 'string' }, variationId: { key: 'variation_id', required: true, type: 'string' }, + variationName: { key: 'variation_name', required: false, type: 'string' }, remoteConfigs: { key: 'remote_configs', required: false, diff --git a/src/types/index.ts b/src/types/index.ts index eafb9ef..5f78a63 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -181,6 +181,11 @@ export interface AdaptyFlow { * @readonly */ readonly variationId: string; + /** + * A name of the variation. + * @readonly + */ + readonly variationName?: string; /** * Remote configs configured in Adapty Dashboard for this flow. * @readonly @@ -334,6 +339,22 @@ export type AdaptyExternalAttributionProvider = | 'custom' | (string & {}); +/** + * Reason StoreKit wants to show an App Store message. + * + * @remarks + * Reasons unknown to the SDK arrive as `storekit_`, + * so any string is accepted. + * Requires iOS 16+. + * @public + */ +export type AdaptyStoreMessageType = + | 'generic' + | 'price_increase_consent' + | 'billing_issue' + | 'win_back_offer' + | (string & {}); + /** * Interface representing a user profile in Adapty, * including details about the user's subscriptions and consumable products. diff --git a/src/types/inputs.ts b/src/types/inputs.ts index b0fbcf7..4e037a2 100644 --- a/src/types/inputs.ts +++ b/src/types/inputs.ts @@ -204,6 +204,18 @@ export interface ActivateParamsInput { * @defaultValue `false` */ clearDataOnBackup?: boolean; + /** + * Controls who decides when App Store messages (price increase consent, + * billing issue, win-back offer, etc.) are shown. + * + * @remarks + * - `'auto'` — StoreKit presents them automatically. + * - `'manual'` — the SDK captures them and the app decides when to show them. + * + * Requires iOS 16+. + * @defaultValue `'auto'` + */ + storeMessagesHandling?: 'auto' | 'manual'; }; android?: { /** From 8e324a29115f269488d03cabfb9f355c5206cbc6 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Wed, 23 Sep 2026 19:50:37 +0300 Subject: [PATCH 08/25] feat: make storeMessagesHandling a cross-platform activation param store_messages_handling is a single flat key of AdaptyConfiguration, and the Android crossplatform bridge (4.2.0) decodes it too: AUTO requests Google Play in-app messages on every Activity.onResume, MANUAL only on an explicit show_store_messages. Keeping it under ios.* hid half of the feature. ios.storeMessagesHandling moves to the top level of ActivateParamsInput and is encoded on both platforms, still only when set. It has not shipped in a release yet, so no alias is kept. --- src/coders/adapty-configuration.test.ts | 33 +++++++++++++------------ src/coders/adapty-configuration.ts | 7 +++--- src/types/inputs.ts | 27 +++++++++++--------- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/coders/adapty-configuration.test.ts b/src/coders/adapty-configuration.test.ts index db5a374..b1657c9 100644 --- a/src/coders/adapty-configuration.test.ts +++ b/src/coders/adapty-configuration.test.ts @@ -210,22 +210,23 @@ describe('AdaptyConfigurationCoder', () => { expect(resultWithTrue.clear_data_on_backup).toBe(true); }); - it('should encode storeMessagesHandling only on ios when set', () => { - expect(coder.encode(apiKey, {}).store_messages_handling).toBeUndefined(); - expect( - coder.encode(apiKey, { ios: { storeMessagesHandling: 'manual' } }) - .store_messages_handling, - ).toBe('manual'); - expect( - coder.encode(apiKey, { ios: { storeMessagesHandling: 'auto' } }) - .store_messages_handling, - ).toBe('auto'); - expect( - createCoder('android').encode(apiKey, { - ios: { storeMessagesHandling: 'manual' }, - }).store_messages_handling, - ).toBeUndefined(); - }); + it.each(['ios', 'android'] as const)( + 'should encode storeMessagesHandling on %s only when set', + os => { + const platformCoder = createCoder(os); + expect( + platformCoder.encode(apiKey, {}).store_messages_handling, + ).toBeUndefined(); + expect( + platformCoder.encode(apiKey, { storeMessagesHandling: 'manual' }) + .store_messages_handling, + ).toBe('manual'); + expect( + platformCoder.encode(apiKey, { storeMessagesHandling: 'auto' }) + .store_messages_handling, + ).toBe('auto'); + }, + ); it('should default adaptyAttributionEnabled to false', () => { expect(coder.encode(apiKey, {}).adapty_attribution_enabled).toBe(false); diff --git a/src/coders/adapty-configuration.ts b/src/coders/adapty-configuration.ts index 6ec561d..5018779 100644 --- a/src/coders/adapty-configuration.ts +++ b/src/coders/adapty-configuration.ts @@ -32,6 +32,10 @@ export class AdaptyConfigurationCoder { config['adapty_attribution_enabled'] = params.adaptyAttributionEnabled ?? false; + if (params.storeMessagesHandling) { + config['store_messages_handling'] = params.storeMessagesHandling; + } + if (params.logLevel) { config['log_level'] = params.logLevel; } @@ -68,9 +72,6 @@ export class AdaptyConfigurationCoder { if (params.ios?.clearDataOnBackup !== undefined) { config['clear_data_on_backup'] = params.ios.clearDataOnBackup; } - if (params.ios?.storeMessagesHandling) { - config['store_messages_handling'] = params.ios.storeMessagesHandling; - } } if (this.platform.OS === 'android') { diff --git a/src/types/inputs.ts b/src/types/inputs.ts index 4e037a2..cea2ff5 100644 --- a/src/types/inputs.ts +++ b/src/types/inputs.ts @@ -192,6 +192,21 @@ export interface ActivateParamsInput { * @defaultValue `false` */ adaptyAttributionEnabled?: boolean; + /** + * Controls who decides when store messages are shown: App Store messages + * (price increase consent, billing issue, win-back offer, etc.) on iOS, + * Google Play in-app messages (e.g. a declined payment) on Android. + * + * @remarks + * - `'auto'` — iOS: StoreKit presents them automatically. Android: the SDK + * requests them on every `Activity.onResume`. + * - `'manual'` — messages are shown only when the app calls `showStoreMessages`. + * On iOS the SDK also keeps them in a queue readable via `getPendingStoreMessageTypes`. + * + * Has no effect below iOS 16. + * @defaultValue `'auto'` + */ + storeMessagesHandling?: 'auto' | 'manual'; ios?: { /** * Disables IDFA collection @@ -204,18 +219,6 @@ export interface ActivateParamsInput { * @defaultValue `false` */ clearDataOnBackup?: boolean; - /** - * Controls who decides when App Store messages (price increase consent, - * billing issue, win-back offer, etc.) are shown. - * - * @remarks - * - `'auto'` — StoreKit presents them automatically. - * - `'manual'` — the SDK captures them and the app decides when to show them. - * - * Requires iOS 16+. - * @defaultValue `'auto'` - */ - storeMessagesHandling?: 'auto' | 'manual'; }; android?: { /** From a418038de9f6507420ddd048ed8ee41601bf0829 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Wed, 23 Sep 2026 19:50:39 +0300 Subject: [PATCH 09/25] feat: add the Array result type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit get_pending_store_message_types answers with a plain string array, and parseMethodResult had no result type that passes one through: every non-primitive type is routed to a coder. The new type is returned as is, like String and Boolean — the values are wire strings with no camelCase mapping. --- src/coders/parse.test.ts | 10 ++++++++++ src/coders/parse.ts | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/coders/parse.test.ts b/src/coders/parse.test.ts index 2e38127..bb096dc 100644 --- a/src/coders/parse.test.ts +++ b/src/coders/parse.test.ts @@ -116,6 +116,16 @@ describe('parseMethodResult', () => { ); expect(result).toBe('primary'); }); + + it('returns Array payload without decoding', () => { + const types = ['billing_issue', 'storekit_-42']; + const result = parseMethodResult( + factory, + JSON.stringify({ success: types }), + 'Array', + ); + expect(result).toEqual(types); + }); }); describe('success is routed to the matching coder', () => { diff --git a/src/coders/parse.ts b/src/coders/parse.ts index 165b9ed..fd19812 100644 --- a/src/coders/parse.ts +++ b/src/coders/parse.ts @@ -21,6 +21,7 @@ const AdaptyTypes = [ 'AdaptyUiOnboardingStateParams', 'AdaptyUiOnboardingStateUpdatedAction', 'Array', + 'Array', 'BridgeError', 'String', 'Boolean', @@ -73,6 +74,7 @@ export function parseMethodResult( 'Void', 'AdaptyUiView', 'AdaptyUiDialogActionType', + 'Array', ].includes(resultType) ) { return obj.success as T; From 410c4adb7d9158211db7795369ffb48398be5148 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Wed, 23 Sep 2026 19:50:40 +0300 Subject: [PATCH 10/25] feat: add error codes 3201 and 3202 AdaptySDK-iOS 4.2.0 introduced operationInProgress (3201) and resolverFailure (3202) with the store message API: a show already running and no foreground-active window scene to show in. Without them in the mapping an AdaptyError carrying these codes had no name. --- src/types/error.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/types/error.ts b/src/types/error.ts index bb0513d..28e91b7 100644 --- a/src/types/error.ts +++ b/src/types/error.ts @@ -122,6 +122,16 @@ const ErrorCodeMapping = Object.freeze({ 3007: 'unsupportedData', 3100: 'persistingDataError', 3101: 'fetchTimeoutError', + /** + * Another operation of the same kind is already in progress + * (e.g. a store message show). + */ + 3201: 'operationInProgress', + /** + * A required resource could not be resolved + * (e.g. no foreground-active window scene to show store messages). + */ + 3202: 'resolverFailure', 9000: 'operationInterrupted', }); @@ -177,6 +187,8 @@ export const ErrorCodeName = Object.freeze({ unsupportedData: 3007, persistingDataError: 3100, fetchTimeoutError: 3101, + operationInProgress: 3201, + resolverFailure: 3202, operationInterrupted: 9000, } as const); export type ErrorCodeName = keyof typeof ErrorCodeName; From 13e366e9c578e84ba81d59fc10f96861b0cb81b8 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Fri, 25 Sep 2026 19:38:50 +0300 Subject: [PATCH 11/25] docs: clarify the list of SDKs using the package --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0aab768..8db8fee 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ > > This package is an internal dependency of Adapty JavaScript SDKs. It is not intended for direct installation. -This package contains the shared TypeScript foundation used by Adapty JavaScript SDKs, like React Native and Capacitor. +This package contains the shared TypeScript foundation used by Adapty JavaScript SDKs: React Native and Capacitor. ## Documentation From 87d90d25a0c4a8c4f57e64d039fc61723c317db9 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Mon, 28 Sep 2026 17:32:48 +0300 Subject: [PATCH 12/25] feat: add the debug log level and order LogLevel by verbosity --- src/logger/console-sink.ts | 1 + src/logger/log.ts | 2 ++ src/types/inputs.ts | 29 ++++++++++++++++++----------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/logger/console-sink.ts b/src/logger/console-sink.ts index 96f2585..483afed 100644 --- a/src/logger/console-sink.ts +++ b/src/logger/console-sink.ts @@ -11,6 +11,7 @@ function getConsoleForLevel( case 'warn': return console.warn; case 'verbose': + case 'debug': return console.debug; case 'info': default: diff --git a/src/logger/log.ts b/src/logger/log.ts index 15a0887..d445758 100644 --- a/src/logger/log.ts +++ b/src/logger/log.ts @@ -69,6 +69,8 @@ export class Log { return 2; case LogLevel.VERBOSE: return 3; + case LogLevel.DEBUG: + return 4; } } diff --git a/src/types/inputs.ts b/src/types/inputs.ts index cea2ff5..3a65bf9 100644 --- a/src/types/inputs.ts +++ b/src/types/inputs.ts @@ -1,33 +1,40 @@ import { AdaptyUiMediaCache } from '@/ui-builder/types'; import type { AdaptyMockConfig } from '@/mock/types'; /** - * Log levels for the SDK + * Log levels for the SDK, ordered from the least to the most verbose: + * `ERROR` < `WARN` < `INFO` < `VERBOSE` < `DEBUG`. * * @remarks + * Setting a level enables it and all the levels above it in the list. * Logging is performed on a native side. * So you are expected to watch logs in Xcode or Android Studio. */ export const LogLevel = Object.freeze({ /** - * Logs any additional information that may be useful during debugging, - * such as function calls, API queries, etc. - */ - VERBOSE: 'verbose', - /** - * Logs only errors + * Level 0 — logs only errors. */ ERROR: 'error', /** - * Logs messages from the SDK + * Level 1 — logs errors and messages from the SDK * that do not cause critical errors, - * but are worth paying attention to + * but are worth paying attention to. */ WARN: 'warn', /** - * Logs various information messages, - * such as those that log the lifecycle of various modules + * Level 2 — additionally logs various information messages, + * such as those that log the lifecycle of various modules. */ INFO: 'info', + /** + * Level 3 — additionally logs any information that may be useful + * during debugging, such as function calls, API queries, etc. + */ + VERBOSE: 'verbose', + /** + * Level 4 — the most detailed level, additionally logs + * low-level internal details of the native SDK. + */ + DEBUG: 'debug', }); export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel]; From d1ecd750c1aed2dfd7f0650be722a30b3a3f36b1 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Tue, 13 Oct 2026 15:53:27 +0300 Subject: [PATCH 13/25] chore: bump version to 4.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1259920..1a1b68c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package", "name": "@adapty/core", - "version": "4.2.0", + "version": "4.3.0", "description": "Platform-agnostic core for Adapty JS SDKs", "license": "MIT", "author": "Adapty team ", From 5f3804fd8bc17ef6ecd9b4f29212541a02ebba7b Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Tue, 13 Oct 2026 18:53:22 +0300 Subject: [PATCH 14/25] chore: update yaml from https://github.com/adaptyteam/AdaptySDK-iOS/commit/b6bc4aa46b7ef77c337f74bcda784d87a7662445 --- cross_platform.yaml | 72 +++++++++++++++++++++++++++++++++++++++++---- src/types/api.d.ts | 38 ++++++++++++++++++++++-- 2 files changed, 103 insertions(+), 7 deletions(-) diff --git a/cross_platform.yaml b/cross_platform.yaml index 588921d..0d6c474 100644 --- a/cross_platform.yaml +++ b/cross_platform.yaml @@ -1,5 +1,5 @@ $schema: "https://json-schema.org/draft/2020-12/schema" -$id: "https://adapty.io/crossPlatform/4.2.0/schema" +$id: "https://adapty.io/crossPlatform/4.3.0/schema" title: "Cross Platform Format" $requests: @@ -1346,7 +1346,10 @@ $defs: AdaptyPrice: #response type: object - required: [amount] + required: + - amount + - currency_code # iOS Only + - localized_string # iOS Only properties: amount: { type: number } currency_code: { type: string } @@ -1356,12 +1359,19 @@ $defs: AdaptyPromotedProduct.Request: #request type: object required: + - purchase_intent_id # iOS Only - vendor_product_id properties: + purchase_intent_id: { type: string } # iOS Only vendor_product_id: { type: string } subscription: type: object properties: + pricing_terms: # iOS Only + type: object + required: [billing_plan_id] + properties: + billing_plan_id: { type: string } offer: type: object required: [offer_identifier] @@ -1373,12 +1383,14 @@ $defs: AdaptyPromotedProduct.Response: #event type: object required: + - purchase_intent_id # iOS Only - vendor_product_id - localized_description - localized_title - is_family_shareable # iOS Only - price properties: + purchase_intent_id: { type: string } # iOS Only vendor_product_id: { type: string } localized_description: { type: string } localized_title: { type: string } @@ -1389,17 +1401,41 @@ $defs: subscription: { $ref: "#/$defs/AdaptyProduct.Subscription" } payload_data: { type: string } + AdaptySubscriptionPricingTerms: #event #response + type: object + required: + - billing_plan_id + - billing_price + - billing_period + - commitment_info + properties: + billing_plan_id: { type: string } + billing_price: { $ref: "#/$defs/AdaptyPrice" } + billing_period: { $ref: "#/$defs/AdaptySubscriptionPeriod" } + commitment_info: { $ref: "#/$defs/AdaptySubscriptionCommitmentInfo" } + + AdaptySubscriptionCommitmentInfo: #event #response + type: object + required: + - price + - period + properties: + price: { $ref: "#/$defs/AdaptyPrice" } + period: { $ref: "#/$defs/AdaptySubscriptionPeriod" } + AdaptyProduct.Subscription: #event #response type: object required: - group_identifier # iOS Only - period + - pricing_terms # iOS Only - renewal_type # Android Only - base_plan_id # Android Only properties: group_identifier: { type: string, description: "iOS Only" } period: { $ref: "#/$defs/AdaptySubscriptionPeriod" } localized_period: { type: string } + pricing_terms: { $ref: "#/$defs/AdaptySubscriptionPricingTerms" } offer: { $ref: "#/$defs/AdaptySubscriptionOffer" } renewal_type: # Android Only type: string @@ -1430,6 +1466,11 @@ $defs: subscription: type: object properties: + pricing_terms: # iOS Only + type: object + required: [billing_plan_id] + properties: + billing_plan_id: { type: string } offer: type: object required: [offer_identifier] @@ -1637,10 +1678,18 @@ $defs: adapty_product_id: { type: string } access_level_id: { type: string } product_type: { type: string } - promotional_offer_id: { type: string, description: "iOS Only" } - win_back_offer_id: { type: string, description: "iOS Only" } base_plan_id: { type: string, description: "Android Only" } offer_id: { type: string, description: "Android Only" } + pricing_terms: # iOS only + type: array + items: + type: object + required: + - billing_plan_id # iOS only + properties: + billing_plan_id: { type: string } # iOS only + promotional_offer_id: { type: string } # iOS only + win_back_offer_id: { type: string } # iOS only AdaptySubscriptionPeriod: #response type: object @@ -1718,6 +1767,8 @@ $defs: billing_issue_detected_at: { $ref: "#/$defs/Date" } starts_at: { $ref: "#/$defs/Date" } cancellation_reason: { type: string } + billing_plan_id: { type: string, description: "iOS Only" } + commitment: { $ref: "#/$defs/AdaptyProfile.SubscriptionCommitmentInfo" } is_refund: { type: boolean } AdaptyProfile.NonSubscription: #response @@ -1754,6 +1805,7 @@ $defs: - is_refund - is_sandbox - will_renew + - billing_plan_id # iOS Only properties: store: { type: string } vendor_product_id: { type: string } @@ -1776,6 +1828,16 @@ $defs: active_promotional_offer_id: { type: string } offer_id: { type: string } cancellation_reason: { type: string } + billing_plan_id: { type: string, description: "iOS Only" } + commitment: { $ref: "#/$defs/AdaptyProfile.SubscriptionCommitmentInfo" } + + AdaptyProfile.SubscriptionCommitmentInfo: #response + type: object + required: [billing_period_number, total_billing_periods, expires_at] + properties: + billing_period_number: { type: integer, minimum: 0 } + total_billing_periods: { type: integer, minimum: 0 } + expires_at: { $ref: "#/$defs/Date" } AdaptyProfile.CustomAttributes: type: object @@ -1812,7 +1874,7 @@ $defs: analytics_disabled: { type: boolean } AdaptySubscriptionOffer.Identifier: #request #response - type: string + type: object oneOf: - required: [type] properties: diff --git a/src/types/api.d.ts b/src/types/api.d.ts index 7564265..45a0115 100644 --- a/src/types/api.d.ts +++ b/src/types/api.d.ts @@ -820,8 +820,12 @@ export interface components { }; 'AdaptyPromotedProduct.Request': { + purchase_intent_id?: string; vendor_product_id: string; subscription?: { + pricing_terms?: { + billing_plan_id: string; + }; offer?: { offer_identifier: components['defs']['AdaptySubscriptionOffer.Identifier']; }; @@ -830,6 +834,7 @@ export interface components { }; 'AdaptyPromotedProduct.Response': { + purchase_intent_id?: string; vendor_product_id: string; localized_description: string; localized_title: string; @@ -840,10 +845,23 @@ export interface components { payload_data?: string; }; + AdaptySubscriptionPricingTerms: { + billing_plan_id: string; + billing_price: components['defs']['AdaptyPrice']; + billing_period: components['defs']['AdaptySubscriptionPeriod']; + commitment_info: components['defs']['AdaptySubscriptionCommitmentInfo']; + }; + + AdaptySubscriptionCommitmentInfo: { + price: components['defs']['AdaptyPrice']; + period: components['defs']['AdaptySubscriptionPeriod']; + }; + 'AdaptyProduct.Subscription': { group_identifier?: string; period: components['defs']['AdaptySubscriptionPeriod']; localized_period?: string; + pricing_terms?: components['defs']['AdaptySubscriptionPricingTerms']; offer?: components['defs']['AdaptySubscriptionOffer']; renewal_type?: 'prepaid' | 'autorenewable'; base_plan_id?: string; @@ -856,6 +874,9 @@ export interface components { product_type: string; paywall_product_index: number; subscription?: { + pricing_terms?: { + billing_plan_id: string; + }; offer?: { offer_identifier: components['defs']['AdaptySubscriptionOffer.Identifier']; }; @@ -962,10 +983,13 @@ export interface components { adapty_product_id: string; access_level_id: string; product_type: string; - promotional_offer_id?: string; - win_back_offer_id?: string; base_plan_id?: string; offer_id?: string; + pricing_terms?: { + billing_plan_id: string; + promotional_offer_id?: string; + win_back_offer_id?: string; + }[]; }; AdaptySubscriptionPeriod: { @@ -1018,6 +1042,8 @@ export interface components { billing_issue_detected_at?: components['defs']['Date']; starts_at?: components['defs']['Date']; cancellation_reason?: string; + billing_plan_id?: string; + commitment?: components['defs']['AdaptyProfile.SubscriptionCommitmentInfo']; is_refund: boolean; }; @@ -1054,6 +1080,14 @@ export interface components { active_promotional_offer_id?: string; offer_id?: string; cancellation_reason?: string; + billing_plan_id?: string; + commitment?: components['defs']['AdaptyProfile.SubscriptionCommitmentInfo']; + }; + + 'AdaptyProfile.SubscriptionCommitmentInfo': { + billing_period_number: number; + total_billing_periods: number; + expires_at: components['defs']['Date']; }; 'AdaptyProfile.CustomAttributes': { From 14d54d494f10a91e9d785aafda6a92ea68c81a37 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Tue, 13 Oct 2026 19:17:58 +0300 Subject: [PATCH 15/25] feat: support subscription pricing terms, commitment info and purchase intent id in coders --- src/coders/adapty-access-level.test.ts | 17 +++ src/coders/adapty-access-level.ts | 12 ++ src/coders/adapty-flow-paywall.test.ts | 9 +- src/coders/adapty-paywall-product.test.ts | 28 ++++ src/coders/adapty-paywall-product.ts | 13 +- ...ty-profile-subscription-commitment-info.ts | 32 +++++ src/coders/adapty-promoted-product.test.ts | 45 +++++++ src/coders/adapty-promoted-product.ts | 19 +-- .../adapty-subscription-commitment-info.ts | 29 +++++ .../adapty-subscription-details.test.ts | 54 ++++++++ src/coders/adapty-subscription-details.ts | 25 ++++ .../adapty-subscription-pricing-terms.ts | 41 ++++++ src/coders/adapty-subscription.test.ts | 17 +++ src/coders/adapty-subscription.ts | 12 ++ src/coders/factory.ts | 20 +++ src/coders/product-reference-pricing-terms.ts | 32 +++++ src/coders/product-reference.test.ts | 30 +++-- src/coders/product-reference.ts | 16 +-- src/types/index.ts | 120 +++++++++++++++++- 19 files changed, 533 insertions(+), 38 deletions(-) create mode 100644 src/coders/adapty-profile-subscription-commitment-info.ts create mode 100644 src/coders/adapty-subscription-commitment-info.ts create mode 100644 src/coders/adapty-subscription-pricing-terms.ts create mode 100644 src/coders/product-reference-pricing-terms.ts diff --git a/src/coders/adapty-access-level.test.ts b/src/coders/adapty-access-level.test.ts index 1895e74..0d6b57c 100644 --- a/src/coders/adapty-access-level.test.ts +++ b/src/coders/adapty-access-level.test.ts @@ -2,6 +2,7 @@ import type { AdaptyAccessLevel, CancellationReason, OfferType, + SubscriptionBillingPlan, VendorStore, } from '@/types'; import type { Def } from '@/types/schema'; @@ -15,6 +16,12 @@ const mocks: Def['AdaptyProfile.AccessLevel'][] = [ active_promotional_offer_id: 'iosOffer1', active_promotional_offer_type: 'promo1', billing_issue_detected_at: '2023-08-08T12:00:00.000Z', + billing_plan_id: 'monthly', + commitment: { + billing_period_number: 3, + total_billing_periods: 12, + expires_at: '2024-08-08T12:00:00.000Z', + }, cancellation_reason: 'user_cancelled', expires_at: '2023-10-08T12:00:00.000Z', id: 'accessLevel1', @@ -77,6 +84,16 @@ function toModel(mock: (typeof mocks)[number]): Model { activePromotionalOfferType: mock.active_promotional_offer_type as OfferType, }), + ...(mock.billing_plan_id && { + billingPlan: mock.billing_plan_id as SubscriptionBillingPlan, + }), + ...(mock.commitment && { + commitmentInfo: { + billingPeriodNumber: mock.commitment.billing_period_number, + totalBillingPeriods: mock.commitment.total_billing_periods, + expiresAt: new Date(mock.commitment.expires_at), + }, + }), android: { ...(mock.offer_id && { offerId: mock.offer_id, diff --git a/src/coders/adapty-access-level.ts b/src/coders/adapty-access-level.ts index 5291e13..0007752 100644 --- a/src/coders/adapty-access-level.ts +++ b/src/coders/adapty-access-level.ts @@ -3,6 +3,7 @@ import type { AdaptyAccessLevel } from '../types'; import type { Properties } from './types'; import { SimpleCoder } from './coder'; import { DateCoder } from './date'; +import { AdaptyProfileSubscriptionCommitmentInfoCoder } from './adapty-profile-subscription-commitment-info'; type Model = AdaptyAccessLevel; type Serializable = Def['AdaptyProfile.AccessLevel']; @@ -105,6 +106,17 @@ export class AdaptyAccessLevelCoder extends SimpleCoder { required: true, type: 'boolean', }, + billingPlan: { + key: 'billing_plan_id', + required: false, + type: 'string', + }, + commitmentInfo: { + key: 'commitment', + required: false, + type: 'object', + converter: new AdaptyProfileSubscriptionCommitmentInfoCoder(), + }, android: { offerId: { key: 'offer_id', diff --git a/src/coders/adapty-flow-paywall.test.ts b/src/coders/adapty-flow-paywall.test.ts index f952c2b..2bf16c2 100644 --- a/src/coders/adapty-flow-paywall.test.ts +++ b/src/coders/adapty-flow-paywall.test.ts @@ -28,8 +28,13 @@ const mocks: Def['AdaptyFlowPaywall'][] = [ adapty_product_id: 'adaptyProduct1', access_level_id: 'premium', product_type: 'subscription', - promotional_offer_id: 'offer1', - win_back_offer_id: 'offer2', + pricing_terms: [ + { + billing_plan_id: 'up_front', + promotional_offer_id: 'offer1', + win_back_offer_id: 'offer2', + }, + ], base_plan_id: 'base1', offer_id: 'androidOffer1', }, diff --git a/src/coders/adapty-paywall-product.test.ts b/src/coders/adapty-paywall-product.test.ts index 5b4a900..3db55a5 100644 --- a/src/coders/adapty-paywall-product.test.ts +++ b/src/coders/adapty-paywall-product.test.ts @@ -89,6 +89,15 @@ const mocks: Def['AdaptyPaywallProduct.Response'][] = [ number_of_units: 1, }, localized_period: '1 year', + pricing_terms: { + billing_plan_id: 'monthly', + billing_price: { amount: 6.99, localized_string: '$6.99' }, + billing_period: { unit: 'month', number_of_units: 1 }, + commitment_info: { + price: { amount: 83.88, localized_string: '$83.88' }, + period: { unit: 'year', number_of_units: 1 }, + }, + }, offer: { offer_identifier: { type: 'promotional', @@ -166,4 +175,23 @@ describe('AdaptyPaywallProductCoder', () => { expect(encoded).toStrictEqual(mock); }); + + describe('getInput', () => { + it('should map the billing plan and the offer identifier', () => { + expect(coder.getInput(mocks[1]!).subscription).toStrictEqual({ + pricing_terms: { billing_plan_id: 'monthly' }, + offer: { + offer_identifier: { type: 'promotional', id: 'test_promo_offer' }, + }, + }); + }); + + it('should omit pricing terms when the product has none', () => { + expect(coder.getInput(mocks[0]!).subscription).toStrictEqual({ + offer: { + offer_identifier: { type: 'introductory', id: 'test_intro_offer' }, + }, + }); + }); + }); }); diff --git a/src/coders/adapty-paywall-product.ts b/src/coders/adapty-paywall-product.ts index c00bc0e..a11d951 100644 --- a/src/coders/adapty-paywall-product.ts +++ b/src/coders/adapty-paywall-product.ts @@ -3,7 +3,10 @@ import type { Def } from '@/types/schema'; import type { Properties } from './types'; import { SimpleCoder } from './coder'; import { AdaptyPriceCoder } from './adapty-price'; -import { AdaptySubscriptionDetailsCoder } from './adapty-subscription-details'; +import { + AdaptySubscriptionDetailsCoder, + getSubscriptionInput, +} from './adapty-subscription-details'; type Model = AdaptyPaywallProduct; type Serializable = Def['AdaptyPaywallProduct.Response']; @@ -85,13 +88,7 @@ export class AdaptyPaywallProductCoder extends SimpleCoder< payload_data: data.payload_data, paywall_name: data.paywall_name, paywall_variation_id: data.paywall_variation_id, - subscription: data.subscription?.offer - ? { - offer: { - offer_identifier: data.subscription.offer.offer_identifier, - }, - } - : undefined, + subscription: getSubscriptionInput(data.subscription), vendor_product_id: data.vendor_product_id, }; } diff --git a/src/coders/adapty-profile-subscription-commitment-info.ts b/src/coders/adapty-profile-subscription-commitment-info.ts new file mode 100644 index 0000000..e302235 --- /dev/null +++ b/src/coders/adapty-profile-subscription-commitment-info.ts @@ -0,0 +1,32 @@ +import type { AdaptyProfileSubscriptionCommitmentInfo } from '@/types'; +import type { Def } from '@/types/schema'; +import type { Properties } from './types'; +import { SimpleCoder } from './coder'; +import { DateCoder } from './date'; + +type Model = AdaptyProfileSubscriptionCommitmentInfo; +type Serializable = Def['AdaptyProfile.SubscriptionCommitmentInfo']; + +export class AdaptyProfileSubscriptionCommitmentInfoCoder extends SimpleCoder< + Model, + Serializable +> { + protected properties: Properties = { + billingPeriodNumber: { + key: 'billing_period_number', + required: true, + type: 'number', + }, + totalBillingPeriods: { + key: 'total_billing_periods', + required: true, + type: 'number', + }, + expiresAt: { + key: 'expires_at', + required: true, + type: 'string', + converter: new DateCoder(), + }, + }; +} diff --git a/src/coders/adapty-promoted-product.test.ts b/src/coders/adapty-promoted-product.test.ts index ff46116..0789e70 100644 --- a/src/coders/adapty-promoted-product.test.ts +++ b/src/coders/adapty-promoted-product.test.ts @@ -7,6 +7,7 @@ import { AdaptySubscriptionDetailsCoder } from './adapty-subscription-details'; type Model = AdaptyPromotedProduct; const mocks: Def['AdaptyPromotedProduct.Response'][] = [ { + purchase_intent_id: 'intent-1', is_family_shareable: false, localized_description: 'Get premium features with this plan', localized_title: 'Yearly Premium Plan', @@ -55,6 +56,7 @@ const mocks: Def['AdaptyPromotedProduct.Response'][] = [ }, }, { + purchase_intent_id: 'intent-2', is_family_shareable: true, localized_description: 'Get premium features with this plan', localized_title: 'Yearly Premium Plan', @@ -73,6 +75,31 @@ const mocks: Def['AdaptyPromotedProduct.Response'][] = [ number_of_units: 1, }, localized_period: '1 year', + pricing_terms: { + billing_plan_id: 'monthly', + billing_price: { + amount: 6.99, + currency_code: 'USD', + currency_symbol: '$', + localized_string: '$6.99', + }, + billing_period: { + unit: 'month', + number_of_units: 1, + }, + commitment_info: { + price: { + amount: 83.88, + currency_code: 'USD', + currency_symbol: '$', + localized_string: '$83.88', + }, + period: { + unit: 'year', + number_of_units: 1, + }, + }, + }, offer: { offer_identifier: { type: 'promotional', @@ -101,6 +128,7 @@ const mocks: Def['AdaptyPromotedProduct.Response'][] = [ }, { // Non-subscription product: no subscription, no optional fields + purchase_intent_id: 'intent-3', is_family_shareable: false, localized_description: 'Unlock all the things, once', localized_title: 'Lifetime Access', @@ -121,6 +149,7 @@ function toModel(mock: (typeof mocks)[number]): Model { return { ios: { isFamilyShareable: mock.is_family_shareable as boolean, + purchaseIntentId: mock.purchase_intent_id as string, }, localizedDescription: mock.localized_description, localizedTitle: mock.localized_title, @@ -159,6 +188,7 @@ describe('AdaptyPromotedProductCoder', () => { describe('getInput', () => { it('should map the nested subscription offer identifier', () => { expect(coder.getInput(mocks[0]!)).toStrictEqual({ + purchase_intent_id: 'intent-1', vendor_product_id: 'yearly.premium.6999', payload_data: 'examplePayloadData', subscription: { @@ -169,8 +199,23 @@ describe('AdaptyPromotedProductCoder', () => { }); }); + it('should map the billing plan alongside the offer identifier', () => { + expect(coder.getInput(mocks[1]!)).toStrictEqual({ + purchase_intent_id: 'intent-2', + vendor_product_id: 'yearly.premium.6999', + payload_data: undefined, + subscription: { + pricing_terms: { billing_plan_id: 'monthly' }, + offer: { + offer_identifier: { type: 'promotional', id: 'test_promo_offer' }, + }, + }, + }); + }); + it('should omit the subscription when the product has no offer', () => { expect(coder.getInput(mocks[2]!)).toStrictEqual({ + purchase_intent_id: 'intent-3', vendor_product_id: 'lifetime.access.9999', payload_data: undefined, subscription: undefined, diff --git a/src/coders/adapty-promoted-product.ts b/src/coders/adapty-promoted-product.ts index 63ec0ba..92d8c51 100644 --- a/src/coders/adapty-promoted-product.ts +++ b/src/coders/adapty-promoted-product.ts @@ -3,7 +3,10 @@ import type { Def } from '@/types/schema'; import type { Properties } from './types'; import { SimpleCoder } from './coder'; import { AdaptyPriceCoder } from './adapty-price'; -import { AdaptySubscriptionDetailsCoder } from './adapty-subscription-details'; +import { + AdaptySubscriptionDetailsCoder, + getSubscriptionInput, +} from './adapty-subscription-details'; type Model = AdaptyPromotedProduct; type Serializable = Def['AdaptyPromotedProduct.Response']; @@ -44,20 +47,20 @@ export class AdaptyPromotedProductCoder extends SimpleCoder< required: true, type: 'boolean', }, + purchaseIntentId: { + key: 'purchase_intent_id', + required: true, + type: 'string', + }, }, }; public getInput(data: Serializable): Def['AdaptyPromotedProduct.Request'] { return { + purchase_intent_id: data.purchase_intent_id, vendor_product_id: data.vendor_product_id, payload_data: data.payload_data, - subscription: data.subscription?.offer - ? { - offer: { - offer_identifier: data.subscription.offer.offer_identifier, - }, - } - : undefined, + subscription: getSubscriptionInput(data.subscription), }; } } diff --git a/src/coders/adapty-subscription-commitment-info.ts b/src/coders/adapty-subscription-commitment-info.ts new file mode 100644 index 0000000..2d7b37f --- /dev/null +++ b/src/coders/adapty-subscription-commitment-info.ts @@ -0,0 +1,29 @@ +import type { AdaptySubscriptionCommitmentInfo } from '@/types'; +import type { Def } from '@/types/schema'; +import type { Properties } from './types'; +import { SimpleCoder } from './coder'; +import { AdaptyPriceCoder } from './adapty-price'; +import { AdaptySubscriptionPeriodCoder } from './adapty-subscription-period'; + +type Model = AdaptySubscriptionCommitmentInfo; +type Serializable = Def['AdaptySubscriptionCommitmentInfo']; + +export class AdaptySubscriptionCommitmentInfoCoder extends SimpleCoder< + Model, + Serializable +> { + protected properties: Properties = { + price: { + key: 'price', + required: true, + type: 'object', + converter: new AdaptyPriceCoder(), + }, + period: { + key: 'period', + required: true, + type: 'object', + converter: new AdaptySubscriptionPeriodCoder(), + }, + }; +} diff --git a/src/coders/adapty-subscription-details.test.ts b/src/coders/adapty-subscription-details.test.ts index da5882b..2001045 100644 --- a/src/coders/adapty-subscription-details.test.ts +++ b/src/coders/adapty-subscription-details.test.ts @@ -3,6 +3,7 @@ import type { Def } from '@/types/schema'; import { AdaptySubscriptionDetailsCoder } from './adapty-subscription-details'; import { AdaptySubscriptionPeriodCoder } from './adapty-subscription-period'; import { AdaptySubscriptionOfferCoder } from '@/coders/adapty-subscription-offer'; +import { AdaptySubscriptionPricingTermsCoder } from './adapty-subscription-pricing-terms'; type Model = AdaptySubscriptionDetails; const mocks: Def['AdaptyProduct.Subscription'][] = [ @@ -47,6 +48,31 @@ const mocks: Def['AdaptyProduct.Subscription'][] = [ number_of_units: 1, }, localized_period: '1 year', + pricing_terms: { + billing_plan_id: 'monthly', + billing_price: { + amount: 6.99, + currency_code: 'USD', + currency_symbol: '$', + localized_string: '$6.99', + }, + billing_period: { + unit: 'month', + number_of_units: 1, + }, + commitment_info: { + price: { + amount: 83.88, + currency_code: 'USD', + currency_symbol: '$', + localized_string: '$83.88', + }, + period: { + unit: 'year', + number_of_units: 1, + }, + }, + }, offer: { offer_identifier: { type: 'promotional', @@ -77,6 +103,7 @@ const mocks: Def['AdaptyProduct.Subscription'][] = [ function toModel(mock: (typeof mocks)[number]): Model { const _period = new AdaptySubscriptionPeriodCoder(); const _offer = new AdaptySubscriptionOfferCoder(); + const _pricingTerms = new AdaptySubscriptionPricingTermsCoder(); return { subscriptionPeriod: _period.decode(mock.period), @@ -96,6 +123,9 @@ function toModel(mock: (typeof mocks)[number]): Model { : { ios: { subscriptionGroupIdentifier: mock.group_identifier, + ...(mock.pricing_terms && { + pricingTerms: _pricingTerms.decode(mock.pricing_terms), + }), }, }), }; @@ -120,4 +150,28 @@ describe('AdaptySubscriptionDetailsCoder', () => { expect(encoded).toStrictEqual(mock); }); + + it('should decode iOS pricing terms', () => { + const decoded = coder.decode(mocks[1]!); + + expect(decoded.ios?.pricingTerms).toStrictEqual({ + billingPlan: 'monthly', + billingPrice: { + amount: 6.99, + currencyCode: 'USD', + currencySymbol: '$', + localizedString: '$6.99', + }, + billingPeriod: { unit: 'month', numberOfUnits: 1 }, + commitmentInfo: { + price: { + amount: 83.88, + currencyCode: 'USD', + currencySymbol: '$', + localizedString: '$83.88', + }, + period: { unit: 'year', numberOfUnits: 1 }, + }, + }); + }); }); diff --git a/src/coders/adapty-subscription-details.ts b/src/coders/adapty-subscription-details.ts index 662529b..de5314e 100644 --- a/src/coders/adapty-subscription-details.ts +++ b/src/coders/adapty-subscription-details.ts @@ -4,9 +4,14 @@ import type { Properties } from './types'; import { SimpleCoder } from './coder'; import { AdaptySubscriptionPeriodCoder } from './adapty-subscription-period'; import { AdaptySubscriptionOfferCoder } from '@/coders/adapty-subscription-offer'; +import { AdaptySubscriptionPricingTermsCoder } from './adapty-subscription-pricing-terms'; type Model = AdaptySubscriptionDetails; type Serializable = Def['AdaptyProduct.Subscription']; +// Same shape for paywall and promoted product requests +type SubscriptionInput = NonNullable< + Def['AdaptyPaywallProduct.Request']['subscription'] +>; export class AdaptySubscriptionDetailsCoder extends SimpleCoder< Model, @@ -36,6 +41,12 @@ export class AdaptySubscriptionDetailsCoder extends SimpleCoder< required: false, type: 'string', }, + pricingTerms: { + key: 'pricing_terms', + required: false, + type: 'object', + converter: new AdaptySubscriptionPricingTermsCoder(), + }, }, android: { basePlanId: { @@ -58,3 +69,17 @@ export class AdaptySubscriptionDetailsCoder extends SimpleCoder< return partialData; } } + +// Picks the purchase-relevant subset of subscription details for native requests +export function getSubscriptionInput( + data: Serializable | undefined, +): SubscriptionInput | undefined { + const billingPlanId = data?.pricing_terms?.billing_plan_id; + const offerIdentifier = data?.offer?.offer_identifier; + if (!billingPlanId && !offerIdentifier) return undefined; + + return { + ...(billingPlanId && { pricing_terms: { billing_plan_id: billingPlanId } }), + ...(offerIdentifier && { offer: { offer_identifier: offerIdentifier } }), + }; +} diff --git a/src/coders/adapty-subscription-pricing-terms.ts b/src/coders/adapty-subscription-pricing-terms.ts new file mode 100644 index 0000000..e40a0c9 --- /dev/null +++ b/src/coders/adapty-subscription-pricing-terms.ts @@ -0,0 +1,41 @@ +import type { AdaptySubscriptionPricingTerms } from '@/types'; +import type { Def } from '@/types/schema'; +import type { Properties } from './types'; +import { SimpleCoder } from './coder'; +import { AdaptyPriceCoder } from './adapty-price'; +import { AdaptySubscriptionPeriodCoder } from './adapty-subscription-period'; +import { AdaptySubscriptionCommitmentInfoCoder } from './adapty-subscription-commitment-info'; + +type Model = AdaptySubscriptionPricingTerms; +type Serializable = Def['AdaptySubscriptionPricingTerms']; + +export class AdaptySubscriptionPricingTermsCoder extends SimpleCoder< + Model, + Serializable +> { + protected properties: Properties = { + billingPlan: { + key: 'billing_plan_id', + required: true, + type: 'string', + }, + billingPrice: { + key: 'billing_price', + required: true, + type: 'object', + converter: new AdaptyPriceCoder(), + }, + billingPeriod: { + key: 'billing_period', + required: true, + type: 'object', + converter: new AdaptySubscriptionPeriodCoder(), + }, + commitmentInfo: { + key: 'commitment_info', + required: true, + type: 'object', + converter: new AdaptySubscriptionCommitmentInfoCoder(), + }, + }; +} diff --git a/src/coders/adapty-subscription.test.ts b/src/coders/adapty-subscription.test.ts index 5a5af95..56bc69f 100644 --- a/src/coders/adapty-subscription.test.ts +++ b/src/coders/adapty-subscription.test.ts @@ -1,6 +1,7 @@ import type { AdaptySubscription, CancellationReason, + SubscriptionBillingPlan, VendorStore, } from '@/types'; import type { Def } from '@/types/schema'; @@ -10,6 +11,12 @@ type Model = AdaptySubscription; const mocks: Def['AdaptyProfile.Subscription'][] = [ { activated_at: '2023-08-09T12:34:56.789Z', + billing_plan_id: 'monthly', + commitment: { + billing_period_number: 3, + total_billing_periods: 12, + expires_at: '2024-08-08T12:00:00.000Z', + }, is_active: true, is_in_grace_period: false, is_lifetime: false, @@ -73,6 +80,16 @@ function toModel(mock: (typeof mocks)[number]): Model { vendorProductId: mock.vendor_product_id, vendorTransactionId: mock.vendor_transaction_id, willRenew: mock.will_renew, + ...(mock.billing_plan_id && { + billingPlan: mock.billing_plan_id as SubscriptionBillingPlan, + }), + ...(mock.commitment && { + commitmentInfo: { + billingPeriodNumber: mock.commitment.billing_period_number, + totalBillingPeriods: mock.commitment.total_billing_periods, + expiresAt: new Date(mock.commitment.expires_at), + }, + }), }; } diff --git a/src/coders/adapty-subscription.ts b/src/coders/adapty-subscription.ts index 1d85d2d..a8f39d2 100644 --- a/src/coders/adapty-subscription.ts +++ b/src/coders/adapty-subscription.ts @@ -3,6 +3,7 @@ import type { Def } from '@/types/schema'; import type { Properties } from './types'; import { SimpleCoder } from './coder'; import { DateCoder } from './date'; +import { AdaptyProfileSubscriptionCommitmentInfoCoder } from './adapty-profile-subscription-commitment-info'; type Model = AdaptySubscription; type Serializable = Def['AdaptyProfile.Subscription']; @@ -115,5 +116,16 @@ export class AdaptySubscriptionCoder extends SimpleCoder { required: false, type: 'string', }, + billingPlan: { + key: 'billing_plan_id', + required: false, + type: 'string', + }, + commitmentInfo: { + key: 'commitment', + required: false, + type: 'object', + converter: new AdaptyProfileSubscriptionCommitmentInfoCoder(), + }, }; } diff --git a/src/coders/factory.ts b/src/coders/factory.ts index 95cbb15..5ba0e18 100644 --- a/src/coders/factory.ts +++ b/src/coders/factory.ts @@ -21,14 +21,17 @@ import { AdaptyPlacementCoder } from './adapty-placement'; import { AdaptyPriceCoder } from './adapty-price'; import { AdaptyPromotedProductCoder } from './adapty-promoted-product'; import { AdaptyProfileParametersCoder } from './adapty-profile-parameters'; +import { AdaptyProfileSubscriptionCommitmentInfoCoder } from './adapty-profile-subscription-commitment-info'; import { AdaptyProfileCoder } from './adapty-profile'; import { AdaptyPurchaseParamsCoder } from './adapty-purchase-params'; import { AdaptyPurchaseResultCoder } from './adapty-purchase-result'; import { AdaptyRemoteConfigCoder } from './adapty-remote-config'; +import { AdaptySubscriptionCommitmentInfoCoder } from './adapty-subscription-commitment-info'; import { AdaptySubscriptionDetailsCoder } from './adapty-subscription-details'; import { AdaptySubscriptionOfferIdCoder } from './adapty-subscription-offer-identifier'; import { AdaptySubscriptionOfferCoder } from './adapty-subscription-offer'; import { AdaptySubscriptionPeriodCoder } from './adapty-subscription-period'; +import { AdaptySubscriptionPricingTermsCoder } from './adapty-subscription-pricing-terms'; import { AdaptySubscriptionCoder } from './adapty-subscription'; import { AdaptyUiDialogConfigCoder } from './adapty-ui-dialog-config'; import { AdaptyUICreateOnboardingViewParamsCoder } from './adapty-ui-create-onboarding-view-params'; @@ -43,6 +46,7 @@ import { DateCoder } from './date'; import { HashmapCoder } from './hashmap'; import { JSONCoder } from './json'; import { ProductReferenceCoder } from './product-reference'; +import { ProductReferencePricingTermsCoder } from './product-reference-pricing-terms'; import type { Converter } from './types'; /** @@ -151,10 +155,18 @@ export class CoderFactory { return new AdaptyProfileCoder(this.deps.platform); } + createProductReferencePricingTermsCoder(): ProductReferencePricingTermsCoder { + return new ProductReferencePricingTermsCoder(this.deps.platform); + } + createProfileParametersCoder(): AdaptyProfileParametersCoder { return new AdaptyProfileParametersCoder(this.deps.platform); } + createProfileSubscriptionCommitmentInfoCoder(): AdaptyProfileSubscriptionCommitmentInfoCoder { + return new AdaptyProfileSubscriptionCommitmentInfoCoder(this.deps.platform); + } + createPromotedProductCoder(): AdaptyPromotedProductCoder { return new AdaptyPromotedProductCoder(this.deps.platform); } @@ -167,6 +179,10 @@ export class CoderFactory { return new AdaptySubscriptionCoder(this.deps.platform); } + createSubscriptionCommitmentInfoCoder(): AdaptySubscriptionCommitmentInfoCoder { + return new AdaptySubscriptionCommitmentInfoCoder(this.deps.platform); + } + createSubscriptionDetailsCoder(): AdaptySubscriptionDetailsCoder { return new AdaptySubscriptionDetailsCoder(this.deps.platform); } @@ -183,6 +199,10 @@ export class CoderFactory { return new AdaptySubscriptionPeriodCoder(this.deps.platform); } + createSubscriptionPricingTermsCoder(): AdaptySubscriptionPricingTermsCoder { + return new AdaptySubscriptionPricingTermsCoder(this.deps.platform); + } + createUiCreateOnboardingViewParamsCoder(): AdaptyUICreateOnboardingViewParamsCoder { return new AdaptyUICreateOnboardingViewParamsCoder(); } diff --git a/src/coders/product-reference-pricing-terms.ts b/src/coders/product-reference-pricing-terms.ts new file mode 100644 index 0000000..7110ac3 --- /dev/null +++ b/src/coders/product-reference-pricing-terms.ts @@ -0,0 +1,32 @@ +import type { ProductReferencePricingTerms } from '@/types'; +import type { Def } from '@/types/schema'; +import type { Properties } from './types'; +import { SimpleCoder } from './coder'; + +type Model = ProductReferencePricingTerms; +type Serializable = NonNullable< + Def['AdaptyFlowPaywall.ProductReference']['pricing_terms'] +>[number]; + +export class ProductReferencePricingTermsCoder extends SimpleCoder< + Model, + Serializable +> { + protected properties: Properties = { + billingPlan: { + key: 'billing_plan_id', + required: true, + type: 'string', + }, + promotionalOfferId: { + key: 'promotional_offer_id', + required: false, + type: 'string', + }, + winBackOfferId: { + key: 'win_back_offer_id', + required: false, + type: 'string', + }, + }; +} diff --git a/src/coders/product-reference.test.ts b/src/coders/product-reference.test.ts index a716978..257788a 100644 --- a/src/coders/product-reference.test.ts +++ b/src/coders/product-reference.test.ts @@ -1,4 +1,4 @@ -import type { ProductReference } from '@/types'; +import type { ProductReference, SubscriptionBillingPlan } from '@/types'; import type { Def } from '@/types/schema'; import { ProductReferenceCoder } from './product-reference'; @@ -16,8 +16,14 @@ const mocks: Def['AdaptyFlowPaywall.ProductReference'][] = [ adapty_product_id: 'adaptyProduct456', access_level_id: 'premium', product_type: 'subscription', - promotional_offer_id: 'offer789', - win_back_offer_id: 'offer456', + pricing_terms: [ + { billing_plan_id: 'monthly', promotional_offer_id: 'offer789' }, + { + billing_plan_id: 'up_front', + promotional_offer_id: 'offer789', + win_back_offer_id: 'offer456', + }, + ], }, { vendor_product_id: 'product111', @@ -33,8 +39,7 @@ const mocks: Def['AdaptyFlowPaywall.ProductReference'][] = [ adapty_product_id: 'adaptyProductXYZ', access_level_id: 'premium', product_type: 'non_subscription', - promotional_offer_id: 'promoOfferIOS', - win_back_offer_id: 'winBackOfferIOS', + pricing_terms: [{ billing_plan_id: 'up_front' }], base_plan_id: 'baseAndroid', offer_id: 'offerAndroid', }, @@ -48,11 +53,16 @@ function toModel(mock: (typeof mocks)[number]): Model { accessLevelId: mock.access_level_id, productType: mock.product_type, ios: { - ...(mock.promotional_offer_id && { - promotionalOfferId: mock.promotional_offer_id, - }), - ...(mock.win_back_offer_id && { - winBackOfferId: mock.win_back_offer_id, + ...(mock.pricing_terms && { + pricingTerms: mock.pricing_terms.map(terms => ({ + billingPlan: terms.billing_plan_id as SubscriptionBillingPlan, + ...(terms.promotional_offer_id && { + promotionalOfferId: terms.promotional_offer_id, + }), + ...(terms.win_back_offer_id && { + winBackOfferId: terms.win_back_offer_id, + }), + })), }), }, android: { diff --git a/src/coders/product-reference.ts b/src/coders/product-reference.ts index bfeed97..3e5aad1 100644 --- a/src/coders/product-reference.ts +++ b/src/coders/product-reference.ts @@ -2,6 +2,8 @@ import type { Properties } from './types'; import type { ProductReference } from '@/types'; import type { Def } from '@/types/schema'; import { SimpleCoder } from './coder'; +import { ArrayCoder } from './array'; +import { ProductReferencePricingTermsCoder } from './product-reference-pricing-terms'; type Model = ProductReference; type Serializable = Def['AdaptyFlowPaywall.ProductReference']; @@ -34,15 +36,13 @@ export class ProductReferenceCoder extends SimpleCoder { type: 'string', }, ios: { - promotionalOfferId: { - key: 'promotional_offer_id', + pricingTerms: { + key: 'pricing_terms', required: false, - type: 'string', - }, - winBackOfferId: { - key: 'win_back_offer_id', - required: false, - type: 'string', + type: 'array', + converter: new ArrayCoder( + () => new ProductReferencePricingTermsCoder(), + ), }, }, android: { diff --git a/src/types/index.ts b/src/types/index.ts index 5f78a63..7f7b7d3 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -51,6 +51,13 @@ export const ProductPeriod = Object.freeze({ }); export type ProductPeriod = (typeof ProductPeriod)[keyof typeof ProductPeriod]; +export const SubscriptionBillingPlan = Object.freeze({ + UpFront: 'up_front', + Monthly: 'monthly', +}); +export type SubscriptionBillingPlan = + (typeof SubscriptionBillingPlan)[keyof typeof SubscriptionBillingPlan]; + export interface AdaptyPrice { /** * Price as number @@ -524,6 +531,19 @@ export interface AdaptyAccessLevel { */ readonly willRenew: boolean; + /** + * Billing plan of the subscription. + * iOS only. + * @readonly + */ + readonly billingPlan?: SubscriptionBillingPlan; + + /** + * Commitment progress of a subscription purchased with a commitment billing plan. + * @readonly + */ + readonly commitmentInfo?: AdaptyProfileSubscriptionCommitmentInfo; + android?: { offerId?: string; }; @@ -707,6 +727,41 @@ export interface AdaptySubscription { * @readonly */ readonly willRenew: boolean; + + /** + * Billing plan of the subscription. + * iOS only. + * @readonly + */ + readonly billingPlan?: SubscriptionBillingPlan; + + /** + * Commitment progress of a subscription purchased with a commitment billing plan. + * @readonly + */ + readonly commitmentInfo?: AdaptyProfileSubscriptionCommitmentInfo; +} + +/** + * Commitment progress of a subscription purchased with a commitment billing plan. + * @public + */ +export interface AdaptyProfileSubscriptionCommitmentInfo { + /** + * Number of the current billing period within the commitment. + * @readonly + */ + readonly billingPeriodNumber: number; + /** + * Total number of billing periods in the commitment. + * @readonly + */ + readonly totalBillingPeriods: number; + /** + * The date and time when the commitment expires. + * @readonly + */ + readonly expiresAt: Date; } /** @@ -823,6 +878,11 @@ export interface AdaptyPromotedProduct { * @see {@link https://developer.apple.com/documentation/storekit/skproduct/3564805-isfamilyshareable} */ readonly isFamilyShareable: boolean; + /** + * StoreKit purchase intent identifier, passed back to native on purchase. + * @internal + */ + readonly purchaseIntentId: string; }; } @@ -849,6 +909,11 @@ export interface AdaptySubscriptionDetails { * Will be `null` for iOS version below 12.0 and macOS version below 10.14. */ subscriptionGroupIdentifier?: string; + /** + * Billing terms of the subscription: billing plan, price per billing period + * and the total commitment. + */ + pricingTerms?: AdaptySubscriptionPricingTerms; }; android?: { @@ -857,6 +922,52 @@ export interface AdaptySubscriptionDetails { }; } +/** + * Billing terms of a subscription product. + * iOS only. + * @public + */ +export interface AdaptySubscriptionPricingTerms { + /** + * Billing plan of the subscription. + * @readonly + */ + readonly billingPlan: SubscriptionBillingPlan; + /** + * Price charged for each billing period. + * @readonly + */ + readonly billingPrice: AdaptyPrice; + /** + * Period between charges. + * @readonly + */ + readonly billingPeriod: AdaptySubscriptionPeriod; + /** + * Total price and period the user commits to. + * @readonly + */ + readonly commitmentInfo: AdaptySubscriptionCommitmentInfo; +} + +/** + * Total price and period of a subscription commitment. + * iOS only. + * @public + */ +export interface AdaptySubscriptionCommitmentInfo { + /** + * Total price of the commitment. + * @readonly + */ + readonly price: AdaptyPrice; + /** + * Total period of the commitment. + * @readonly + */ + readonly period: AdaptySubscriptionPeriod; +} + /** * Subscription offer model to products * @see {@link https://doc.adapty.io/docs/rn-api-reference#adaptysubscriptionoffer} @@ -951,8 +1062,7 @@ export interface ProductReference { productType: string; ios?: { - promotionalOfferId?: string; - winBackOfferId?: string; + pricingTerms?: ProductReferencePricingTerms[]; }; android?: { @@ -961,6 +1071,12 @@ export interface ProductReference { }; } +export interface ProductReferencePricingTerms { + billingPlan: SubscriptionBillingPlan; + promotionalOfferId?: string; + winBackOfferId?: string; +} + /** * Interface representing a product identifier with vendor and platform-specific information. * @public From dc8af8f2562eb4085956dbf77c262812fc452285 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Tue, 13 Oct 2026 19:29:05 +0300 Subject: [PATCH 16/25] feat: make SubscriptionBillingPlan an open string union --- src/types/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/types/index.ts b/src/types/index.ts index 7f7b7d3..6aad72a 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -55,8 +55,13 @@ export const SubscriptionBillingPlan = Object.freeze({ UpFront: 'up_front', Monthly: 'monthly', }); +/** + * Billing plan of a subscription. + * Open-ended: native SDKs may pass through plans unknown to this version. + */ export type SubscriptionBillingPlan = - (typeof SubscriptionBillingPlan)[keyof typeof SubscriptionBillingPlan]; + | (typeof SubscriptionBillingPlan)[keyof typeof SubscriptionBillingPlan] + | (string & {}); export interface AdaptyPrice { /** From 442b8dae1847882adeb922bd7bf5efb04c5746ea Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Tue, 13 Oct 2026 19:31:08 +0300 Subject: [PATCH 17/25] test: cover pricing terms coders and platform-specific decoding; mark ProductReferencePricingTerms internal --- src/coders/adapty-paywall-product.test.ts | 28 +++++++++ ...ofile-subscription-commitment-info.test.ts | 41 ++++++++++++ src/coders/adapty-promoted-product.test.ts | 48 ++++++++++++++ ...dapty-subscription-commitment-info.test.ts | 47 ++++++++++++++ .../adapty-subscription-details.test.ts | 27 ++++++++ .../adapty-subscription-pricing-terms.test.ts | 63 +++++++++++++++++++ src/coders/factory.ts | 8 +-- .../product-reference-pricing-terms.test.ts | 41 ++++++++++++ src/coders/product-reference.test.ts | 12 ++++ src/types/index.ts | 4 ++ 10 files changed, 315 insertions(+), 4 deletions(-) create mode 100644 src/coders/adapty-profile-subscription-commitment-info.test.ts create mode 100644 src/coders/adapty-subscription-commitment-info.test.ts create mode 100644 src/coders/adapty-subscription-pricing-terms.test.ts create mode 100644 src/coders/product-reference-pricing-terms.test.ts diff --git a/src/coders/adapty-paywall-product.test.ts b/src/coders/adapty-paywall-product.test.ts index 3db55a5..cb20c10 100644 --- a/src/coders/adapty-paywall-product.test.ts +++ b/src/coders/adapty-paywall-product.test.ts @@ -1,5 +1,6 @@ import type { AdaptyPaywallProduct } from '@/types'; import type { Def } from '@/types/schema'; +import type { IPlatformAdapter } from '@/adapters/interfaces'; import { AdaptyPriceCoder } from './adapty-price'; import { AdaptyPaywallProductCoder } from './adapty-paywall-product'; import { AdaptySubscriptionDetailsCoder } from './adapty-subscription-details'; @@ -194,4 +195,31 @@ describe('AdaptyPaywallProductCoder', () => { }); }); }); + + describe('getInput after a model round-trip', () => { + const ios = new AdaptyPaywallProductCoder({ + OS: 'ios', + } as IPlatformAdapter); + + it('should send the billing plan when there is no offer', () => { + const { offer: _offer, ...subscription } = mocks[1]!.subscription!; + const model = ios.decode({ ...mocks[1]!, subscription }); + + expect(ios.getInput(ios.encode(model)).subscription).toStrictEqual({ + pricing_terms: { billing_plan_id: 'monthly' }, + }); + }); + + it('should omit the subscription for Android products without an offer', () => { + const android = new AdaptyPaywallProductCoder({ + OS: 'android', + } as IPlatformAdapter); + const { offer: _offer, ...subscription } = mocks[0]!.subscription!; + const model = android.decode({ ...mocks[0]!, subscription }); + + expect(android.getInput(android.encode(model)).subscription).toBe( + undefined, + ); + }); + }); }); diff --git a/src/coders/adapty-profile-subscription-commitment-info.test.ts b/src/coders/adapty-profile-subscription-commitment-info.test.ts new file mode 100644 index 0000000..31eab46 --- /dev/null +++ b/src/coders/adapty-profile-subscription-commitment-info.test.ts @@ -0,0 +1,41 @@ +import type { AdaptyProfileSubscriptionCommitmentInfo } from '@/types'; +import type { Def } from '@/types/schema'; +import { AdaptyProfileSubscriptionCommitmentInfoCoder } from './adapty-profile-subscription-commitment-info'; + +type Model = AdaptyProfileSubscriptionCommitmentInfo; +const mocks: Def['AdaptyProfile.SubscriptionCommitmentInfo'][] = [ + { + billing_period_number: 3, + total_billing_periods: 12, + expires_at: '2024-08-08T12:00:00.000Z', + }, + { + billing_period_number: 0, + total_billing_periods: 12, + expires_at: '2025-01-01T00:00:00.000Z', + }, +]; + +function toModel(mock: (typeof mocks)[number]): Model { + return { + billingPeriodNumber: mock.billing_period_number, + totalBillingPeriods: mock.total_billing_periods, + expiresAt: new Date(mock.expires_at), + }; +} + +describe('AdaptyProfileSubscriptionCommitmentInfoCoder', () => { + let coder: AdaptyProfileSubscriptionCommitmentInfoCoder; + + beforeEach(() => { + coder = new AdaptyProfileSubscriptionCommitmentInfoCoder(); + }); + + it.each(mocks)('should decode to expected result', mock => { + expect(coder.decode(mock)).toStrictEqual(toModel(mock)); + }); + + it.each(mocks)('should decode/encode', mock => { + expect(coder.encode(coder.decode(mock))).toStrictEqual(mock); + }); +}); diff --git a/src/coders/adapty-promoted-product.test.ts b/src/coders/adapty-promoted-product.test.ts index 0789e70..1abdf30 100644 --- a/src/coders/adapty-promoted-product.test.ts +++ b/src/coders/adapty-promoted-product.test.ts @@ -1,5 +1,6 @@ import type { AdaptyPromotedProduct } from '@/types'; import type { Def } from '@/types/schema'; +import type { IPlatformAdapter } from '@/adapters/interfaces'; import { AdaptyPriceCoder } from './adapty-price'; import { AdaptyPromotedProductCoder } from './adapty-promoted-product'; import { AdaptySubscriptionDetailsCoder } from './adapty-subscription-details'; @@ -222,4 +223,51 @@ describe('AdaptyPromotedProductCoder', () => { }); }); }); + + describe('platform', () => { + const ios = new AdaptyPromotedProductCoder({ + OS: 'ios', + } as IPlatformAdapter); + const android = new AdaptyPromotedProductCoder({ + OS: 'android', + } as IPlatformAdapter); + const { purchase_intent_id: _, ...withoutIntent } = mocks[1]!; + + it('should require purchase_intent_id on iOS', () => { + expect(() => ios.decode(withoutIntent)).toThrow(/purchaseIntentId/); + }); + + it('should not require purchase_intent_id on Android', () => { + expect(android.decode(mocks[0]!).ios).toStrictEqual({ + isFamilyShareable: false, + purchaseIntentId: 'intent-1', + }); + expect(() => android.decode(withoutIntent)).not.toThrow(); + }); + + it('should send purchase intent and billing plan after a model round-trip', () => { + const model = ios.decode(mocks[1]!); + + expect(ios.getInput(ios.encode(model))).toStrictEqual({ + purchase_intent_id: 'intent-2', + vendor_product_id: 'yearly.premium.6999', + payload_data: undefined, + subscription: { + pricing_terms: { billing_plan_id: 'monthly' }, + offer: { + offer_identifier: { type: 'promotional', id: 'test_promo_offer' }, + }, + }, + }); + }); + + it('should send the billing plan when there is no offer', () => { + const { offer: _offer, ...subscription } = mocks[1]!.subscription!; + const model = ios.decode({ ...mocks[1]!, subscription }); + + expect(ios.getInput(ios.encode(model)).subscription).toStrictEqual({ + pricing_terms: { billing_plan_id: 'monthly' }, + }); + }); + }); }); diff --git a/src/coders/adapty-subscription-commitment-info.test.ts b/src/coders/adapty-subscription-commitment-info.test.ts new file mode 100644 index 0000000..6a4673c --- /dev/null +++ b/src/coders/adapty-subscription-commitment-info.test.ts @@ -0,0 +1,47 @@ +import type { AdaptySubscriptionCommitmentInfo, ProductPeriod } from '@/types'; +import type { Def } from '@/types/schema'; +import { AdaptySubscriptionCommitmentInfoCoder } from './adapty-subscription-commitment-info'; + +type Model = AdaptySubscriptionCommitmentInfo; +const mocks: Def['AdaptySubscriptionCommitmentInfo'][] = [ + { + price: { + amount: 83.88, + currency_code: 'USD', + currency_symbol: '$', + localized_string: '$83.88', + }, + period: { unit: 'year', number_of_units: 1 }, + }, +]; + +function toModel(mock: (typeof mocks)[number]): Model { + return { + price: { + amount: mock.price.amount, + currencyCode: mock.price.currency_code, + currencySymbol: mock.price.currency_symbol, + localizedString: mock.price.localized_string, + }, + period: { + unit: mock.period.unit as ProductPeriod, + numberOfUnits: mock.period.number_of_units, + }, + }; +} + +describe('AdaptySubscriptionCommitmentInfoCoder', () => { + let coder: AdaptySubscriptionCommitmentInfoCoder; + + beforeEach(() => { + coder = new AdaptySubscriptionCommitmentInfoCoder(); + }); + + it.each(mocks)('should decode to expected result', mock => { + expect(coder.decode(mock)).toStrictEqual(toModel(mock)); + }); + + it.each(mocks)('should decode/encode', mock => { + expect(coder.encode(coder.decode(mock))).toStrictEqual(mock); + }); +}); diff --git a/src/coders/adapty-subscription-details.test.ts b/src/coders/adapty-subscription-details.test.ts index 2001045..33c115f 100644 --- a/src/coders/adapty-subscription-details.test.ts +++ b/src/coders/adapty-subscription-details.test.ts @@ -1,5 +1,6 @@ import type { AdaptySubscriptionDetails } from '@/types'; import type { Def } from '@/types/schema'; +import type { IPlatformAdapter } from '@/adapters/interfaces'; import { AdaptySubscriptionDetailsCoder } from './adapty-subscription-details'; import { AdaptySubscriptionPeriodCoder } from './adapty-subscription-period'; import { AdaptySubscriptionOfferCoder } from '@/coders/adapty-subscription-offer'; @@ -174,4 +175,30 @@ describe('AdaptySubscriptionDetailsCoder', () => { }, }); }); + + it('should drop iOS pricing terms from Android subscriptions', () => { + const android = new AdaptySubscriptionDetailsCoder({ + OS: 'android', + } as IPlatformAdapter); + const decoded = android.decode({ + ...mocks[0]!, + pricing_terms: mocks[1]!.pricing_terms, + }); + + expect(decoded.ios).toBeUndefined(); + expect(decoded.android).toStrictEqual({ + basePlanId: 'androidPlan1', + renewalType: 'prepaid', + }); + }); + + it('should keep iOS pricing terms on iOS', () => { + const ios = new AdaptySubscriptionDetailsCoder({ + OS: 'ios', + } as IPlatformAdapter); + + expect(ios.decode(mocks[1]!).ios?.pricingTerms?.billingPlan).toBe( + 'monthly', + ); + }); }); diff --git a/src/coders/adapty-subscription-pricing-terms.test.ts b/src/coders/adapty-subscription-pricing-terms.test.ts new file mode 100644 index 0000000..044e3a8 --- /dev/null +++ b/src/coders/adapty-subscription-pricing-terms.test.ts @@ -0,0 +1,63 @@ +import type { AdaptySubscriptionPricingTerms, ProductPeriod } from '@/types'; +import type { Def } from '@/types/schema'; +import { AdaptySubscriptionPricingTermsCoder } from './adapty-subscription-pricing-terms'; + +type Model = AdaptySubscriptionPricingTerms; +const mocks: Def['AdaptySubscriptionPricingTerms'][] = [ + { + billing_plan_id: 'monthly', + billing_price: { amount: 6.99, localized_string: '$6.99' }, + billing_period: { unit: 'month', number_of_units: 1 }, + commitment_info: { + price: { amount: 83.88, localized_string: '$83.88' }, + period: { unit: 'year', number_of_units: 1 }, + }, + }, + { + // Unknown plans are passed through as is + billing_plan_id: 'quarterly', + billing_price: { amount: 59.99 }, + billing_period: { unit: 'year', number_of_units: 1 }, + commitment_info: { + price: { amount: 59.99 }, + period: { unit: 'year', number_of_units: 1 }, + }, + }, +]; + +function toModel(mock: (typeof mocks)[number]): Model { + const price = (p: Def['AdaptyPrice']) => ({ + amount: p.amount, + ...(p.localized_string && { localizedString: p.localized_string }), + }); + const period = (p: Def['AdaptySubscriptionPeriod']) => ({ + unit: p.unit as ProductPeriod, + numberOfUnits: p.number_of_units, + }); + + return { + billingPlan: mock.billing_plan_id, + billingPrice: price(mock.billing_price), + billingPeriod: period(mock.billing_period), + commitmentInfo: { + price: price(mock.commitment_info.price), + period: period(mock.commitment_info.period), + }, + }; +} + +describe('AdaptySubscriptionPricingTermsCoder', () => { + let coder: AdaptySubscriptionPricingTermsCoder; + + beforeEach(() => { + coder = new AdaptySubscriptionPricingTermsCoder(); + }); + + it.each(mocks)('should decode to expected result', mock => { + expect(coder.decode(mock)).toStrictEqual(toModel(mock)); + }); + + it.each(mocks)('should decode/encode', mock => { + expect(coder.encode(coder.decode(mock))).toStrictEqual(mock); + }); +}); diff --git a/src/coders/factory.ts b/src/coders/factory.ts index 5ba0e18..1100a5d 100644 --- a/src/coders/factory.ts +++ b/src/coders/factory.ts @@ -151,14 +151,14 @@ export class CoderFactory { return new ProductReferenceCoder(this.deps.platform); } - createProfileCoder(): AdaptyProfileCoder { - return new AdaptyProfileCoder(this.deps.platform); - } - createProductReferencePricingTermsCoder(): ProductReferencePricingTermsCoder { return new ProductReferencePricingTermsCoder(this.deps.platform); } + createProfileCoder(): AdaptyProfileCoder { + return new AdaptyProfileCoder(this.deps.platform); + } + createProfileParametersCoder(): AdaptyProfileParametersCoder { return new AdaptyProfileParametersCoder(this.deps.platform); } diff --git a/src/coders/product-reference-pricing-terms.test.ts b/src/coders/product-reference-pricing-terms.test.ts new file mode 100644 index 0000000..f8c8571 --- /dev/null +++ b/src/coders/product-reference-pricing-terms.test.ts @@ -0,0 +1,41 @@ +import type { ProductReferencePricingTerms } from '@/types'; +import type { Def } from '@/types/schema'; +import { ProductReferencePricingTermsCoder } from './product-reference-pricing-terms'; + +type Model = ProductReferencePricingTerms; +const mocks: NonNullable< + Def['AdaptyFlowPaywall.ProductReference']['pricing_terms'] +> = [ + { billing_plan_id: 'up_front' }, + { + billing_plan_id: 'monthly', + promotional_offer_id: 'promo1', + win_back_offer_id: 'winBack1', + }, +]; + +function toModel(mock: (typeof mocks)[number]): Model { + return { + billingPlan: mock.billing_plan_id, + ...(mock.promotional_offer_id && { + promotionalOfferId: mock.promotional_offer_id, + }), + ...(mock.win_back_offer_id && { winBackOfferId: mock.win_back_offer_id }), + }; +} + +describe('ProductReferencePricingTermsCoder', () => { + let coder: ProductReferencePricingTermsCoder; + + beforeEach(() => { + coder = new ProductReferencePricingTermsCoder(); + }); + + it.each(mocks)('should decode to expected result', mock => { + expect(coder.decode(mock)).toStrictEqual(toModel(mock)); + }); + + it.each(mocks)('should decode/encode', mock => { + expect(coder.encode(coder.decode(mock))).toStrictEqual(mock); + }); +}); diff --git a/src/coders/product-reference.test.ts b/src/coders/product-reference.test.ts index 257788a..f73b8d3 100644 --- a/src/coders/product-reference.test.ts +++ b/src/coders/product-reference.test.ts @@ -1,5 +1,6 @@ import type { ProductReference, SubscriptionBillingPlan } from '@/types'; import type { Def } from '@/types/schema'; +import type { IPlatformAdapter } from '@/adapters/interfaces'; import { ProductReferenceCoder } from './product-reference'; type Model = ProductReference; @@ -91,4 +92,15 @@ describe('ProductReferenceCoder', () => { expect(encoded).toStrictEqual(mock); }); + + it.each(['ios', 'android'] as const)( + 'should decode a reference without pricing terms on %s', + OS => { + const platformCoder = new ProductReferenceCoder({ + OS, + } as IPlatformAdapter); + + expect(platformCoder.decode(mocks[0]!).ios).toStrictEqual({}); + }, + ); }); diff --git a/src/types/index.ts b/src/types/index.ts index 6aad72a..5619243 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1076,6 +1076,10 @@ export interface ProductReference { }; } +/** + * Billing plan with the offers available for it, as configured for a paywall product. + * @internal + */ export interface ProductReferencePricingTerms { billingPlan: SubscriptionBillingPlan; promotionalOfferId?: string; From b4aa188a87d93d957807ba3040edc37004e248c2 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Wed, 14 Oct 2026 19:45:04 +0300 Subject: [PATCH 18/25] feat: decode android offer_id in AdaptySubscription --- src/coders/adapty-subscription.test.ts | 4 ++++ src/coders/adapty-subscription.ts | 7 +++++++ src/types/index.ts | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/src/coders/adapty-subscription.test.ts b/src/coders/adapty-subscription.test.ts index 56bc69f..85332b7 100644 --- a/src/coders/adapty-subscription.test.ts +++ b/src/coders/adapty-subscription.test.ts @@ -41,6 +41,7 @@ const mocks: Def['AdaptyProfile.Subscription'][] = [ renewed_at: '2023-07-09T12:34:56.789Z', starts_at: '2023-08-09T12:34:56.789Z', store: 'Google Play', + offer_id: 'androidOffer1', unsubscribed_at: '2023-08-09T12:34:56.789Z', vendor_original_transaction_id: 'originalTransaction456', vendor_product_id: 'product456', @@ -80,6 +81,9 @@ function toModel(mock: (typeof mocks)[number]): Model { vendorProductId: mock.vendor_product_id, vendorTransactionId: mock.vendor_transaction_id, willRenew: mock.will_renew, + android: { + ...(mock.offer_id && { offerId: mock.offer_id }), + }, ...(mock.billing_plan_id && { billingPlan: mock.billing_plan_id as SubscriptionBillingPlan, }), diff --git a/src/coders/adapty-subscription.ts b/src/coders/adapty-subscription.ts index a8f39d2..da45fa0 100644 --- a/src/coders/adapty-subscription.ts +++ b/src/coders/adapty-subscription.ts @@ -127,5 +127,12 @@ export class AdaptySubscriptionCoder extends SimpleCoder { type: 'object', converter: new AdaptyProfileSubscriptionCommitmentInfoCoder(), }, + android: { + offerId: { + key: 'offer_id', + required: false, + type: 'string', + }, + }, }; } diff --git a/src/types/index.ts b/src/types/index.ts index 5619243..f4d64f1 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -745,6 +745,10 @@ export interface AdaptySubscription { * @readonly */ readonly commitmentInfo?: AdaptyProfileSubscriptionCommitmentInfo; + + android?: { + offerId?: string; + }; } /** From 5f31d52f31c156eacd97b89121711303e26b43dd Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Thu, 15 Oct 2026 12:25:55 +0300 Subject: [PATCH 19/25] docs: describe profile billing plan fields as App Store-only, not iOS-only --- src/types/index.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/types/index.ts b/src/types/index.ts index f4d64f1..e386a97 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -537,14 +537,14 @@ export interface AdaptyAccessLevel { readonly willRenew: boolean; /** - * Billing plan of the subscription. - * iOS only. + * Billing plan of the subscription. Set for App Store purchases only, see {@link store}. * @readonly */ readonly billingPlan?: SubscriptionBillingPlan; /** - * Commitment progress of a subscription purchased with a commitment billing plan. + * Commitment progress of a subscription bought with a commitment billing plan. + * Set for App Store purchases only, see {@link store}. * @readonly */ readonly commitmentInfo?: AdaptyProfileSubscriptionCommitmentInfo; @@ -734,14 +734,14 @@ export interface AdaptySubscription { readonly willRenew: boolean; /** - * Billing plan of the subscription. - * iOS only. + * Billing plan of the subscription. Set for App Store purchases only, see {@link store}. * @readonly */ readonly billingPlan?: SubscriptionBillingPlan; /** - * Commitment progress of a subscription purchased with a commitment billing plan. + * Commitment progress of a subscription bought with a commitment billing plan. + * Set for App Store purchases only, see {@link store}. * @readonly */ readonly commitmentInfo?: AdaptyProfileSubscriptionCommitmentInfo; From 0bf7dcd699edaa03ca5acc9418407bfc4029e322 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Thu, 15 Oct 2026 13:40:51 +0300 Subject: [PATCH 20/25] chore: update yaml from https://github.com/adaptyteam/AdaptySDK-iOS/commit/bf6904fee51264cbac2c4eb3f69e1e73bd64a191 --- cross_platform.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cross_platform.yaml b/cross_platform.yaml index 0d6c474..c5135cd 100644 --- a/cross_platform.yaml +++ b/cross_platform.yaml @@ -1,5 +1,5 @@ $schema: "https://json-schema.org/draft/2020-12/schema" -$id: "https://adapty.io/crossPlatform/4.3.0/schema" +$id: "https://adapty.io/crossPlatform/4.3.1/schema" title: "Cross Platform Format" $requests: From e5d13f0452949c130750262798fc35691c077537 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Thu, 15 Oct 2026 15:44:13 +0300 Subject: [PATCH 21/25] feat: expose profile offerId at top level, deprecate AccessLevel android.offerId --- src/coders/adapty-access-level.test.ts | 1 + src/coders/adapty-access-level.ts | 6 ++++++ src/coders/adapty-subscription.test.ts | 4 +--- src/coders/adapty-subscription.ts | 10 ++++------ src/types/index.ts | 20 +++++++++++++++++--- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/coders/adapty-access-level.test.ts b/src/coders/adapty-access-level.test.ts index 0d6b57c..d17fc3b 100644 --- a/src/coders/adapty-access-level.test.ts +++ b/src/coders/adapty-access-level.test.ts @@ -94,6 +94,7 @@ function toModel(mock: (typeof mocks)[number]): Model { expiresAt: new Date(mock.commitment.expires_at), }, }), + ...(mock.offer_id && { offerId: mock.offer_id }), android: { ...(mock.offer_id && { offerId: mock.offer_id, diff --git a/src/coders/adapty-access-level.ts b/src/coders/adapty-access-level.ts index 0007752..d8b3c0b 100644 --- a/src/coders/adapty-access-level.ts +++ b/src/coders/adapty-access-level.ts @@ -117,6 +117,12 @@ export class AdaptyAccessLevelCoder extends SimpleCoder { type: 'object', converter: new AdaptyProfileSubscriptionCommitmentInfoCoder(), }, + offerId: { + key: 'offer_id', + required: false, + type: 'string', + }, + // Deprecated alias of the top-level offerId android: { offerId: { key: 'offer_id', diff --git a/src/coders/adapty-subscription.test.ts b/src/coders/adapty-subscription.test.ts index 85332b7..b77c2cb 100644 --- a/src/coders/adapty-subscription.test.ts +++ b/src/coders/adapty-subscription.test.ts @@ -81,9 +81,7 @@ function toModel(mock: (typeof mocks)[number]): Model { vendorProductId: mock.vendor_product_id, vendorTransactionId: mock.vendor_transaction_id, willRenew: mock.will_renew, - android: { - ...(mock.offer_id && { offerId: mock.offer_id }), - }, + ...(mock.offer_id && { offerId: mock.offer_id }), ...(mock.billing_plan_id && { billingPlan: mock.billing_plan_id as SubscriptionBillingPlan, }), diff --git a/src/coders/adapty-subscription.ts b/src/coders/adapty-subscription.ts index da45fa0..85ab174 100644 --- a/src/coders/adapty-subscription.ts +++ b/src/coders/adapty-subscription.ts @@ -127,12 +127,10 @@ export class AdaptySubscriptionCoder extends SimpleCoder { type: 'object', converter: new AdaptyProfileSubscriptionCommitmentInfoCoder(), }, - android: { - offerId: { - key: 'offer_id', - required: false, - type: 'string', - }, + offerId: { + key: 'offer_id', + required: false, + type: 'string', }, }; } diff --git a/src/types/index.ts b/src/types/index.ts index e386a97..1038c73 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -549,7 +549,18 @@ export interface AdaptyAccessLevel { */ readonly commitmentInfo?: AdaptyProfileSubscriptionCommitmentInfo; + /** + * Identifier of the Google Play offer the subscription was bought with. + * Set for Play Store purchases only, see {@link store}. + * @readonly + */ + readonly offerId?: string; + android?: { + /** + * @deprecated Use the top-level {@link AdaptyAccessLevel.offerId}: + * the value depends on the purchase store, not on the device OS. + */ offerId?: string; }; } @@ -746,9 +757,12 @@ export interface AdaptySubscription { */ readonly commitmentInfo?: AdaptyProfileSubscriptionCommitmentInfo; - android?: { - offerId?: string; - }; + /** + * Identifier of the Google Play offer the subscription was bought with. + * Set for Play Store purchases only, see {@link store}. + * @readonly + */ + readonly offerId?: string; } /** From 9a75c60906ee34410f6a4e56990c04704ba12bfb Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Thu, 15 Oct 2026 19:13:22 +0300 Subject: [PATCH 22/25] refactor: require a platform adapter in Coder and pass it to nested coders --- AGENTS.md | 2 + src/coders/adapty-access-level.test.ts | 3 +- src/coders/adapty-access-level.ts | 4 +- src/coders/adapty-configuration.ts | 2 +- src/coders/adapty-discount-phase.test.ts | 9 +- src/coders/adapty-discount-phase.ts | 4 +- src/coders/adapty-flow-paywall.test.ts | 7 +- src/coders/adapty-flow-paywall.ts | 56 +++--- src/coders/adapty-flow.test.ts | 11 +- src/coders/adapty-flow.ts | 10 +- src/coders/adapty-native-error.test.ts | 3 +- src/coders/adapty-non-subscription.test.ts | 3 +- src/coders/adapty-onboarding-builder.test.ts | 3 +- src/coders/adapty-onboarding.test.ts | 3 +- src/coders/adapty-onboarding.ts | 6 +- src/coders/adapty-paywall-product.test.ts | 9 +- src/coders/adapty-paywall-product.ts | 4 +- src/coders/adapty-placement.test.ts | 3 +- src/coders/adapty-price.test.ts | 3 +- src/coders/adapty-profile-parameters.test.ts | 3 +- ...ofile-subscription-commitment-info.test.ts | 5 +- src/coders/adapty-profile.test.ts | 15 +- src/coders/adapty-profile.ts | 6 +- src/coders/adapty-promoted-product.test.ts | 14 +- src/coders/adapty-promoted-product.ts | 4 +- src/coders/adapty-remote-config.test.ts | 3 +- ...dapty-subscription-commitment-info.test.ts | 5 +- .../adapty-subscription-commitment-info.ts | 4 +- .../adapty-subscription-details.test.ts | 13 +- src/coders/adapty-subscription-details.ts | 6 +- ...apty-subscription-offer-identifier.test.ts | 3 +- src/coders/adapty-subscription-offer.test.ts | 11 +- src/coders/adapty-subscription-offer.ts | 6 +- src/coders/adapty-subscription-period.test.ts | 3 +- .../adapty-subscription-pricing-terms.test.ts | 5 +- .../adapty-subscription-pricing-terms.ts | 6 +- src/coders/adapty-subscription.test.ts | 3 +- src/coders/adapty-subscription.ts | 4 +- src/coders/adapty-ui-dialog-config.test.ts | 3 +- src/coders/adapty-ui-media-cache.test.ts | 3 +- src/coders/adapty-ui-onboarding-meta.test.ts | 3 +- .../adapty-ui-onboarding-state-params.test.ts | 5 +- ...ui-onboarding-state-updated-action.test.ts | 5 +- ...apty-ui-onboarding-state-updated-action.ts | 4 +- src/coders/bridge-error.test.ts | 3 +- src/coders/coder.ts | 3 +- src/coders/nested-platform.test.ts | 160 ++++++++++++++++++ .../product-reference-pricing-terms.test.ts | 3 +- src/coders/product-reference.test.ts | 3 +- src/coders/product-reference.ts | 2 +- 50 files changed, 351 insertions(+), 110 deletions(-) create mode 100644 src/coders/nested-platform.test.ts diff --git a/AGENTS.md b/AGENTS.md index 9f9c5bc..e1a1a89 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -87,11 +87,13 @@ This repo uses platform dependency injection to keep `@adapty/core` platform-agn - `ILoggerAdapter` for logging - **Instantiation rule:** do not instantiate `*Coder` via `new` outside `src/coders/**`. In SDK / bridge / feature code, use `CoderFactory` as the single entry point. - **When adding a new coder:** add a corresponding `create*Coder()` method to `CoderFactory` and use it instead of direct construction. +- **Platform propagation:** `Coder` requires an `IPlatformAdapter` in its constructor. A coder that nests another coder (in `properties`, fields, methods, `ArrayCoder`/`HashmapCoder`) must pass `this.platform`; otherwise platform-gated `required` checks inside `ios`/`android` blocks of the nested coder never fire. ### Testing Guidance - Tests should create coders with mock adapters, not mutate `Platform` globals. - Prefer inline adapters: `{ OS: 'ios' }` / `{ OS: 'android' }`. +- Coder tests that do not care about the platform pass `new DefaultPlatformAdapter()` (OS `'unknown'`, platform-gated checks off). `src/coders/nested-platform.test.ts` verifies that every coder reachable from `CoderFactory` shares the factory's adapter. ### Usage in Downstream SDKs diff --git a/src/coders/adapty-access-level.test.ts b/src/coders/adapty-access-level.test.ts index d17fc3b..6539053 100644 --- a/src/coders/adapty-access-level.test.ts +++ b/src/coders/adapty-access-level.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { AdaptyAccessLevel, CancellationReason, @@ -107,7 +108,7 @@ describe('AdaptyAccessLevelCoder', () => { let coder: AdaptyAccessLevelCoder; beforeEach(() => { - coder = new AdaptyAccessLevelCoder(); + coder = new AdaptyAccessLevelCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-access-level.ts b/src/coders/adapty-access-level.ts index d8b3c0b..b607bb4 100644 --- a/src/coders/adapty-access-level.ts +++ b/src/coders/adapty-access-level.ts @@ -115,7 +115,9 @@ export class AdaptyAccessLevelCoder extends SimpleCoder { key: 'commitment', required: false, type: 'object', - converter: new AdaptyProfileSubscriptionCommitmentInfoCoder(), + converter: new AdaptyProfileSubscriptionCommitmentInfoCoder( + this.platform, + ), }, offerId: { key: 'offer_id', diff --git a/src/coders/adapty-configuration.ts b/src/coders/adapty-configuration.ts index 5018779..8df357e 100644 --- a/src/coders/adapty-configuration.ts +++ b/src/coders/adapty-configuration.ts @@ -52,7 +52,7 @@ export class AdaptyConfigurationCoder { config['activate_ui'] = params.activateUi ?? true; - const mediaCacheCoder = new AdaptyUiMediaCacheCoder(); + const mediaCacheCoder = new AdaptyUiMediaCacheCoder(this.platform); config['media_cache'] = mediaCacheCoder.encode( params.mediaCache ?? { memoryStorageTotalCostLimit: 100 * 1024 * 1024, diff --git a/src/coders/adapty-discount-phase.test.ts b/src/coders/adapty-discount-phase.test.ts index 971514b..87578d8 100644 --- a/src/coders/adapty-discount-phase.test.ts +++ b/src/coders/adapty-discount-phase.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { AdaptyDiscountPhase, OfferType } from '@/types'; import type { Def } from '@/types/schema'; import { AdaptyDiscountPhaseCoder } from './adapty-discount-phase'; @@ -33,8 +34,10 @@ const mocks: Def['AdaptySubscriptionOffer.Phase'][] = [ ]; function toModel(mock: (typeof mocks)[number]): Model { - const _price = new AdaptyPriceCoder(); - const _subscription = new AdaptySubscriptionPeriodCoder(); + const _price = new AdaptyPriceCoder(new DefaultPlatformAdapter()); + const _subscription = new AdaptySubscriptionPeriodCoder( + new DefaultPlatformAdapter(), + ); return { numberOfPeriods: mock.number_of_periods, @@ -54,7 +57,7 @@ describe('AdaptyDiscountPhaseCoder', () => { let coder: AdaptyDiscountPhaseCoder; beforeEach(() => { - coder = new AdaptyDiscountPhaseCoder(); + coder = new AdaptyDiscountPhaseCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-discount-phase.ts b/src/coders/adapty-discount-phase.ts index 5d7b092..80b4013 100644 --- a/src/coders/adapty-discount-phase.ts +++ b/src/coders/adapty-discount-phase.ts @@ -30,13 +30,13 @@ export class AdaptyDiscountPhaseCoder extends SimpleCoder { key: 'price', required: true, type: 'object', - converter: new AdaptyPriceCoder(), + converter: new AdaptyPriceCoder(this.platform), }, subscriptionPeriod: { key: 'subscription_period', required: true, type: 'object', - converter: new AdaptySubscriptionPeriodCoder(), + converter: new AdaptySubscriptionPeriodCoder(this.platform), }, }; } diff --git a/src/coders/adapty-flow-paywall.test.ts b/src/coders/adapty-flow-paywall.test.ts index 2bf16c2..2f1b7f4 100644 --- a/src/coders/adapty-flow-paywall.test.ts +++ b/src/coders/adapty-flow-paywall.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { AdaptyFlowPaywall } from '@/types'; import type { Def } from '@/types/schema'; import { AdaptyFlowPaywallCoder } from './adapty-flow-paywall'; @@ -64,7 +65,9 @@ const mocks: Def['AdaptyFlowPaywall'][] = [ ]; function toModel(mock: (typeof mocks)[number]): Model { - const _products = new ArrayCoder(() => new ProductReferenceCoder()); + const _products = new ArrayCoder( + () => new ProductReferenceCoder(new DefaultPlatformAdapter()), + ); // `products` is kept on the runtime object (matching the coder's decode // output) but is not part of the public `Model` type — hence the cast. @@ -96,7 +99,7 @@ describe('AdaptyFlowPaywallCoder', () => { let coder: AdaptyFlowPaywallCoder; beforeEach(() => { - coder = new AdaptyFlowPaywallCoder(); + coder = new AdaptyFlowPaywallCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-flow-paywall.ts b/src/coders/adapty-flow-paywall.ts index 4caf356..6508100 100644 --- a/src/coders/adapty-flow-paywall.ts +++ b/src/coders/adapty-flow-paywall.ts @@ -16,45 +16,43 @@ type CodableModel = Omit & { }; type Serializable = Def['AdaptyFlowPaywall']; -// Wire-level properties including the internal `products` field. -// The `as unknown as` cast is intentional: `products` is required on the wire -// but optional in CodableModel (so that Model extends CodableModel for -// override compatibility). The cast bridges the required/optional mismatch. -const PROPERTIES = { - placement: { - key: 'placement', - required: true, - type: 'object', - converter: new AdaptyPlacementCoder(), - }, - id: { key: 'paywall_id', required: true, type: 'string' }, - name: { key: 'paywall_name', required: true, type: 'string' }, - products: { - key: 'products', - required: true, - type: 'array', - converter: new ArrayCoder(() => new ProductReferenceCoder()), - }, - variationId: { key: 'variation_id', required: true, type: 'string' }, - webPurchaseUrl: { - key: 'web_purchase_url', - required: false, - type: 'string', - }, -} as unknown as Properties; - export class AdaptyFlowPaywallCoder extends Coder< Model, CodableModel, Serializable > { - protected properties: Properties = PROPERTIES; + // Wire-level properties including the internal `products` field. + // The `as unknown as` cast is intentional: `products` is required on the wire + // but optional in CodableModel (so that Model extends CodableModel for + // override compatibility). The cast bridges the required/optional mismatch. + protected properties: Properties = { + placement: { + key: 'placement', + required: true, + type: 'object', + converter: new AdaptyPlacementCoder(this.platform), + }, + id: { key: 'paywall_id', required: true, type: 'string' }, + name: { key: 'paywall_name', required: true, type: 'string' }, + products: { + key: 'products', + required: true, + type: 'array', + converter: new ArrayCoder(() => new ProductReferenceCoder(this.platform)), + }, + variationId: { key: 'variation_id', required: true, type: 'string' }, + webPurchaseUrl: { + key: 'web_purchase_url', + required: false, + type: 'string', + }, + } as unknown as Properties; override decode(data: Serializable): Model { const codablePart = super.decode(data); // Keep `products` on the runtime object (for encode round-trip) while // exposing only `productIdentifiers` on the public type. - // products is always present on the wire (required: true in PROPERTIES). + // products is always present on the wire (required: true in properties). return { ...codablePart, productIdentifiers: codablePart.products!.map(product => ({ diff --git a/src/coders/adapty-flow.test.ts b/src/coders/adapty-flow.test.ts index 430a193..25b7091 100644 --- a/src/coders/adapty-flow.test.ts +++ b/src/coders/adapty-flow.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { AdaptyFlow } from '@/types'; import type { Def } from '@/types/schema'; import { AdaptyFlowCoder } from './adapty-flow'; @@ -91,8 +92,12 @@ const mocks: Def['AdaptyFlow'][] = [ ]; function toModel(mock: (typeof mocks)[number]): Model { - const _remoteConfigs = new ArrayCoder(() => new AdaptyRemoteConfigCoder()); - const _paywalls = new ArrayCoder(() => new AdaptyFlowPaywallCoder()); + const _remoteConfigs = new ArrayCoder( + () => new AdaptyRemoteConfigCoder(new DefaultPlatformAdapter()), + ); + const _paywalls = new ArrayCoder( + () => new AdaptyFlowPaywallCoder(new DefaultPlatformAdapter()), + ); const decodedPlacement = { abTestName: mock.placement.ab_test_name, @@ -131,7 +136,7 @@ describe('AdaptyFlowCoder', () => { let coder: AdaptyFlowCoder; beforeEach(() => { - coder = new AdaptyFlowCoder(); + coder = new AdaptyFlowCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-flow.ts b/src/coders/adapty-flow.ts index 2968e3c..3c35623 100644 --- a/src/coders/adapty-flow.ts +++ b/src/coders/adapty-flow.ts @@ -20,7 +20,7 @@ export class AdaptyFlowCoder extends Coder { key: 'placement', required: true, type: 'object', - converter: new AdaptyPlacementCoder(), + converter: new AdaptyPlacementCoder(this.platform), }, id: { key: 'flow_id', required: true, type: 'string' }, name: { key: 'flow_name', required: true, type: 'string' }, @@ -30,7 +30,9 @@ export class AdaptyFlowCoder extends Coder { key: 'remote_configs', required: false, type: 'array', - converter: new ArrayCoder(() => new AdaptyRemoteConfigCoder()), + converter: new ArrayCoder( + () => new AdaptyRemoteConfigCoder(this.platform), + ), }, flowVersionId: { key: 'flow_version_id', @@ -41,7 +43,9 @@ export class AdaptyFlowCoder extends Coder { key: 'variations', required: true, type: 'array', - converter: new ArrayCoder(() => new AdaptyFlowPaywallCoder()), + converter: new ArrayCoder( + () => new AdaptyFlowPaywallCoder(this.platform), + ), }, uiSchema: { key: 'ui_schema', diff --git a/src/coders/adapty-native-error.test.ts b/src/coders/adapty-native-error.test.ts index 8c25da2..269fd90 100644 --- a/src/coders/adapty-native-error.test.ts +++ b/src/coders/adapty-native-error.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import { AdaptyNativeErrorCoder } from './adapty-native-error'; import { AdaptyError } from '@/adapty-error'; import type { AdaptyNativeError } from '@/types/bridge'; @@ -30,7 +31,7 @@ describe('AdaptyNativeErrorCoder', () => { let coder: AdaptyNativeErrorCoder; beforeEach(() => { - coder = new AdaptyNativeErrorCoder(); + coder = new AdaptyNativeErrorCoder(new DefaultPlatformAdapter()); }); // Important for analytics systems, etc. diff --git a/src/coders/adapty-non-subscription.test.ts b/src/coders/adapty-non-subscription.test.ts index c23e82c..55ce658 100644 --- a/src/coders/adapty-non-subscription.test.ts +++ b/src/coders/adapty-non-subscription.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { Def } from '@/types/schema'; import type { AdaptyNonSubscription, VendorStore } from '@/types'; import { AdaptyNonSubscriptionCoder } from './adapty-non-subscription'; @@ -44,7 +45,7 @@ describe('AdaptyNonSubscriptionCoder', () => { let coder: AdaptyNonSubscriptionCoder; beforeEach(() => { - coder = new AdaptyNonSubscriptionCoder(); + coder = new AdaptyNonSubscriptionCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-onboarding-builder.test.ts b/src/coders/adapty-onboarding-builder.test.ts index fcd129f..4902e57 100644 --- a/src/coders/adapty-onboarding-builder.test.ts +++ b/src/coders/adapty-onboarding-builder.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import { AdaptyOnboardingBuilderCoder } from './adapty-onboarding-builder'; import type { AdaptyOnboardingBuilder } from '@/types'; import type { Def } from '@/types/schema'; @@ -24,7 +25,7 @@ describe('AdaptyOnboardingBuilderCoder', () => { let coder: AdaptyOnboardingBuilderCoder; beforeEach(() => { - coder = new AdaptyOnboardingBuilderCoder(); + coder = new AdaptyOnboardingBuilderCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-onboarding.test.ts b/src/coders/adapty-onboarding.test.ts index e3bcf9b..8bd1cd7 100644 --- a/src/coders/adapty-onboarding.test.ts +++ b/src/coders/adapty-onboarding.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import { AdaptyOnboardingCoder } from './adapty-onboarding'; import type { AdaptyOnboarding } from '@/types'; import type { Def } from '@/types/schema'; @@ -84,7 +85,7 @@ describe('AdaptyOnboardingCoder', () => { let coder: AdaptyOnboardingCoder; beforeEach(() => { - coder = new AdaptyOnboardingCoder(); + coder = new AdaptyOnboardingCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-onboarding.ts b/src/coders/adapty-onboarding.ts index 6bace95..79707fd 100644 --- a/src/coders/adapty-onboarding.ts +++ b/src/coders/adapty-onboarding.ts @@ -20,7 +20,7 @@ export class AdaptyOnboardingCoder extends Coder< key: 'placement', required: true, type: 'object', - converter: new AdaptyPlacementCoder(), + converter: new AdaptyPlacementCoder(this.platform), }, id: { key: 'onboarding_id', required: true, type: 'string' }, name: { key: 'onboarding_name', required: true, type: 'string' }, @@ -28,7 +28,7 @@ export class AdaptyOnboardingCoder extends Coder< key: 'remote_config', required: false, type: 'object', - converter: new AdaptyRemoteConfigCoder(), + converter: new AdaptyRemoteConfigCoder(this.platform), }, variationId: { key: 'variation_id', required: true, type: 'string' }, version: { key: 'response_created_at', required: false, type: 'number' }, @@ -36,7 +36,7 @@ export class AdaptyOnboardingCoder extends Coder< key: 'onboarding_builder', required: true, type: 'object', - converter: new AdaptyOnboardingBuilderCoder(), + converter: new AdaptyOnboardingBuilderCoder(this.platform), }, payloadData: { key: 'payload_data', required: false, type: 'string' }, requestLocale: { key: 'request_locale', required: true, type: 'string' }, diff --git a/src/coders/adapty-paywall-product.test.ts b/src/coders/adapty-paywall-product.test.ts index cb20c10..f81f6a1 100644 --- a/src/coders/adapty-paywall-product.test.ts +++ b/src/coders/adapty-paywall-product.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { AdaptyPaywallProduct } from '@/types'; import type { Def } from '@/types/schema'; import type { IPlatformAdapter } from '@/adapters/interfaces'; @@ -128,8 +129,10 @@ const mocks: Def['AdaptyPaywallProduct.Response'][] = [ ]; function toModel(mock: (typeof mocks)[number]): Model { - const _price = new AdaptyPriceCoder(); - const _details = new AdaptySubscriptionDetailsCoder(); + const _price = new AdaptyPriceCoder(new DefaultPlatformAdapter()); + const _details = new AdaptySubscriptionDetailsCoder( + new DefaultPlatformAdapter(), + ); return { ios: { @@ -161,7 +164,7 @@ describe('AdaptyPaywallProductCoder', () => { let coder: AdaptyPaywallProductCoder; beforeEach(() => { - coder = new AdaptyPaywallProductCoder(); + coder = new AdaptyPaywallProductCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-paywall-product.ts b/src/coders/adapty-paywall-product.ts index a11d951..5f03b18 100644 --- a/src/coders/adapty-paywall-product.ts +++ b/src/coders/adapty-paywall-product.ts @@ -55,7 +55,7 @@ export class AdaptyPaywallProductCoder extends SimpleCoder< key: 'price', required: false, // Native SDKs require this type: 'object', - converter: new AdaptyPriceCoder(), + converter: new AdaptyPriceCoder(this.platform), }, webPurchaseUrl: { key: 'web_purchase_url', @@ -67,7 +67,7 @@ export class AdaptyPaywallProductCoder extends SimpleCoder< key: 'subscription', required: false, type: 'object', - converter: new AdaptySubscriptionDetailsCoder(), + converter: new AdaptySubscriptionDetailsCoder(this.platform), }, ios: { isFamilyShareable: { diff --git a/src/coders/adapty-placement.test.ts b/src/coders/adapty-placement.test.ts index c52008b..651b593 100644 --- a/src/coders/adapty-placement.test.ts +++ b/src/coders/adapty-placement.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import { AdaptyPlacementCoder } from './adapty-placement'; import type { AdaptyPlacement } from '@/types'; import type { Def } from '@/types/schema'; @@ -38,7 +39,7 @@ describe('AdaptyPlacementCoder', () => { let coder: AdaptyPlacementCoder; beforeEach(() => { - coder = new AdaptyPlacementCoder(); + coder = new AdaptyPlacementCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-price.test.ts b/src/coders/adapty-price.test.ts index a899bdb..763568b 100644 --- a/src/coders/adapty-price.test.ts +++ b/src/coders/adapty-price.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import { AdaptyPriceCoder } from './adapty-price'; import type { AdaptyPrice } from '@/types'; import type { Def } from '@/types/schema'; @@ -26,7 +27,7 @@ describe('AdaptyPriceCoder', () => { let coder: AdaptyPriceCoder; beforeEach(() => { - coder = new AdaptyPriceCoder(); + coder = new AdaptyPriceCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-profile-parameters.test.ts b/src/coders/adapty-profile-parameters.test.ts index c6d49fb..609e192 100644 --- a/src/coders/adapty-profile-parameters.test.ts +++ b/src/coders/adapty-profile-parameters.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import { Def } from '@/types/schema'; import { AdaptyProfileParametersCoder } from './adapty-profile-parameters'; @@ -16,7 +17,7 @@ const mocks: Def['AdaptyProfileParameters'][] = [ ]; describe('AdaptyProfileParametersCoder', () => { - const coder = new AdaptyProfileParametersCoder(); + const coder = new AdaptyProfileParametersCoder(new DefaultPlatformAdapter()); it.each(mocks)('should encode/decode', mock => { const decoded = coder.decode(mock); diff --git a/src/coders/adapty-profile-subscription-commitment-info.test.ts b/src/coders/adapty-profile-subscription-commitment-info.test.ts index 31eab46..b6386d0 100644 --- a/src/coders/adapty-profile-subscription-commitment-info.test.ts +++ b/src/coders/adapty-profile-subscription-commitment-info.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { AdaptyProfileSubscriptionCommitmentInfo } from '@/types'; import type { Def } from '@/types/schema'; import { AdaptyProfileSubscriptionCommitmentInfoCoder } from './adapty-profile-subscription-commitment-info'; @@ -28,7 +29,9 @@ describe('AdaptyProfileSubscriptionCommitmentInfoCoder', () => { let coder: AdaptyProfileSubscriptionCommitmentInfoCoder; beforeEach(() => { - coder = new AdaptyProfileSubscriptionCommitmentInfoCoder(); + coder = new AdaptyProfileSubscriptionCommitmentInfoCoder( + new DefaultPlatformAdapter(), + ); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-profile.test.ts b/src/coders/adapty-profile.test.ts index c998797..fccce59 100644 --- a/src/coders/adapty-profile.test.ts +++ b/src/coders/adapty-profile.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { Def } from '@/types/schema'; import type { AdaptyProfile } from '@/types'; import { AdaptyProfileCoder } from './adapty-profile'; @@ -185,10 +186,16 @@ const mocks: Omit< ]; function toModel(mock: (typeof mocks)[number]): Model { - const _levels = new HashmapCoder(new AdaptyAccessLevelCoder()); - const _subs = new HashmapCoder(new AdaptySubscriptionCoder()); + const _levels = new HashmapCoder( + new AdaptyAccessLevelCoder(new DefaultPlatformAdapter()), + ); + const _subs = new HashmapCoder( + new AdaptySubscriptionCoder(new DefaultPlatformAdapter()), + ); const _nonsubs = new HashmapCoder( - new ArrayCoder(() => new AdaptyNonSubscriptionCoder()), + new ArrayCoder( + () => new AdaptyNonSubscriptionCoder(new DefaultPlatformAdapter()), + ), ); return { @@ -214,7 +221,7 @@ describe('AdaptyProfileCoder', () => { let coder: AdaptyProfileCoder; beforeEach(() => { - coder = new AdaptyProfileCoder(); + coder = new AdaptyProfileCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-profile.ts b/src/coders/adapty-profile.ts index 8744a9f..c2b6f81 100644 --- a/src/coders/adapty-profile.ts +++ b/src/coders/adapty-profile.ts @@ -17,7 +17,7 @@ export class AdaptyProfileCoder extends SimpleCoder { key: 'paid_access_levels', required: false, type: 'object', - converter: new HashmapCoder(new AdaptyAccessLevelCoder()), + converter: new HashmapCoder(new AdaptyAccessLevelCoder(this.platform)), }, appliedExternalAttributionProviders: { key: 'applied_attribution_sources', @@ -39,7 +39,7 @@ export class AdaptyProfileCoder extends SimpleCoder { required: false, type: 'object', converter: new HashmapCoder( - new ArrayCoder(() => new AdaptyNonSubscriptionCoder()), + new ArrayCoder(() => new AdaptyNonSubscriptionCoder(this.platform)), ), }, profileId: { @@ -51,7 +51,7 @@ export class AdaptyProfileCoder extends SimpleCoder { key: 'subscriptions', required: false, type: 'object', - converter: new HashmapCoder(new AdaptySubscriptionCoder()), + converter: new HashmapCoder(new AdaptySubscriptionCoder(this.platform)), }, }; } diff --git a/src/coders/adapty-promoted-product.test.ts b/src/coders/adapty-promoted-product.test.ts index 1abdf30..3f9ef57 100644 --- a/src/coders/adapty-promoted-product.test.ts +++ b/src/coders/adapty-promoted-product.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { AdaptyPromotedProduct } from '@/types'; import type { Def } from '@/types/schema'; import type { IPlatformAdapter } from '@/adapters/interfaces'; @@ -144,8 +145,10 @@ const mocks: Def['AdaptyPromotedProduct.Response'][] = [ ]; function toModel(mock: (typeof mocks)[number]): Model { - const _price = new AdaptyPriceCoder(); - const _details = new AdaptySubscriptionDetailsCoder(); + const _price = new AdaptyPriceCoder(new DefaultPlatformAdapter()); + const _details = new AdaptySubscriptionDetailsCoder( + new DefaultPlatformAdapter(), + ); return { ios: { @@ -170,7 +173,7 @@ describe('AdaptyPromotedProductCoder', () => { let coder: AdaptyPromotedProductCoder; beforeEach(() => { - coder = new AdaptyPromotedProductCoder(); + coder = new AdaptyPromotedProductCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { @@ -232,6 +235,9 @@ describe('AdaptyPromotedProductCoder', () => { OS: 'android', } as IPlatformAdapter); const { purchase_intent_id: _, ...withoutIntent } = mocks[1]!; + // Android products always carry base_plan_id, so the Android case uses the Android-shaped mock + const { purchase_intent_id: _androidIntent, ...androidWithoutIntent } = + mocks[0]!; it('should require purchase_intent_id on iOS', () => { expect(() => ios.decode(withoutIntent)).toThrow(/purchaseIntentId/); @@ -242,7 +248,7 @@ describe('AdaptyPromotedProductCoder', () => { isFamilyShareable: false, purchaseIntentId: 'intent-1', }); - expect(() => android.decode(withoutIntent)).not.toThrow(); + expect(() => android.decode(androidWithoutIntent)).not.toThrow(); }); it('should send purchase intent and billing plan after a model round-trip', () => { diff --git a/src/coders/adapty-promoted-product.ts b/src/coders/adapty-promoted-product.ts index 92d8c51..91bc494 100644 --- a/src/coders/adapty-promoted-product.ts +++ b/src/coders/adapty-promoted-product.ts @@ -32,14 +32,14 @@ export class AdaptyPromotedProductCoder extends SimpleCoder< key: 'price', required: false, // Native SDKs require this type: 'object', - converter: new AdaptyPriceCoder(), + converter: new AdaptyPriceCoder(this.platform), }, payloadData: { key: 'payload_data', required: false, type: 'string' }, subscription: { key: 'subscription', required: false, type: 'object', - converter: new AdaptySubscriptionDetailsCoder(), + converter: new AdaptySubscriptionDetailsCoder(this.platform), }, ios: { isFamilyShareable: { diff --git a/src/coders/adapty-remote-config.test.ts b/src/coders/adapty-remote-config.test.ts index cc25802..c8794a4 100644 --- a/src/coders/adapty-remote-config.test.ts +++ b/src/coders/adapty-remote-config.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import { AdaptyRemoteConfigCoder } from './adapty-remote-config'; import type { AdaptyRemoteConfig } from '@/types'; import type { Def } from '@/types/schema'; @@ -26,7 +27,7 @@ describe('AdaptyRemoteConfigCoder', () => { let coder: AdaptyRemoteConfigCoder; beforeEach(() => { - coder = new AdaptyRemoteConfigCoder(); + coder = new AdaptyRemoteConfigCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-subscription-commitment-info.test.ts b/src/coders/adapty-subscription-commitment-info.test.ts index 6a4673c..5b6ff5b 100644 --- a/src/coders/adapty-subscription-commitment-info.test.ts +++ b/src/coders/adapty-subscription-commitment-info.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { AdaptySubscriptionCommitmentInfo, ProductPeriod } from '@/types'; import type { Def } from '@/types/schema'; import { AdaptySubscriptionCommitmentInfoCoder } from './adapty-subscription-commitment-info'; @@ -34,7 +35,9 @@ describe('AdaptySubscriptionCommitmentInfoCoder', () => { let coder: AdaptySubscriptionCommitmentInfoCoder; beforeEach(() => { - coder = new AdaptySubscriptionCommitmentInfoCoder(); + coder = new AdaptySubscriptionCommitmentInfoCoder( + new DefaultPlatformAdapter(), + ); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-subscription-commitment-info.ts b/src/coders/adapty-subscription-commitment-info.ts index 2d7b37f..53d9e70 100644 --- a/src/coders/adapty-subscription-commitment-info.ts +++ b/src/coders/adapty-subscription-commitment-info.ts @@ -17,13 +17,13 @@ export class AdaptySubscriptionCommitmentInfoCoder extends SimpleCoder< key: 'price', required: true, type: 'object', - converter: new AdaptyPriceCoder(), + converter: new AdaptyPriceCoder(this.platform), }, period: { key: 'period', required: true, type: 'object', - converter: new AdaptySubscriptionPeriodCoder(), + converter: new AdaptySubscriptionPeriodCoder(this.platform), }, }; } diff --git a/src/coders/adapty-subscription-details.test.ts b/src/coders/adapty-subscription-details.test.ts index 33c115f..1058dfc 100644 --- a/src/coders/adapty-subscription-details.test.ts +++ b/src/coders/adapty-subscription-details.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { AdaptySubscriptionDetails } from '@/types'; import type { Def } from '@/types/schema'; import type { IPlatformAdapter } from '@/adapters/interfaces'; @@ -102,9 +103,13 @@ const mocks: Def['AdaptyProduct.Subscription'][] = [ ]; function toModel(mock: (typeof mocks)[number]): Model { - const _period = new AdaptySubscriptionPeriodCoder(); - const _offer = new AdaptySubscriptionOfferCoder(); - const _pricingTerms = new AdaptySubscriptionPricingTermsCoder(); + const _period = new AdaptySubscriptionPeriodCoder( + new DefaultPlatformAdapter(), + ); + const _offer = new AdaptySubscriptionOfferCoder(new DefaultPlatformAdapter()); + const _pricingTerms = new AdaptySubscriptionPricingTermsCoder( + new DefaultPlatformAdapter(), + ); return { subscriptionPeriod: _period.decode(mock.period), @@ -136,7 +141,7 @@ describe('AdaptySubscriptionDetailsCoder', () => { let coder: AdaptySubscriptionDetailsCoder; beforeEach(() => { - coder = new AdaptySubscriptionDetailsCoder(); + coder = new AdaptySubscriptionDetailsCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-subscription-details.ts b/src/coders/adapty-subscription-details.ts index de5314e..a13d9a6 100644 --- a/src/coders/adapty-subscription-details.ts +++ b/src/coders/adapty-subscription-details.ts @@ -22,7 +22,7 @@ export class AdaptySubscriptionDetailsCoder extends SimpleCoder< key: 'period', required: true, type: 'object', - converter: new AdaptySubscriptionPeriodCoder(), + converter: new AdaptySubscriptionPeriodCoder(this.platform), }, localizedSubscriptionPeriod: { key: 'localized_period', @@ -33,7 +33,7 @@ export class AdaptySubscriptionDetailsCoder extends SimpleCoder< key: 'offer', required: false, type: 'object', - converter: new AdaptySubscriptionOfferCoder(), + converter: new AdaptySubscriptionOfferCoder(this.platform), }, ios: { subscriptionGroupIdentifier: { @@ -45,7 +45,7 @@ export class AdaptySubscriptionDetailsCoder extends SimpleCoder< key: 'pricing_terms', required: false, type: 'object', - converter: new AdaptySubscriptionPricingTermsCoder(), + converter: new AdaptySubscriptionPricingTermsCoder(this.platform), }, }, android: { diff --git a/src/coders/adapty-subscription-offer-identifier.test.ts b/src/coders/adapty-subscription-offer-identifier.test.ts index 8473106..21621c2 100644 --- a/src/coders/adapty-subscription-offer-identifier.test.ts +++ b/src/coders/adapty-subscription-offer-identifier.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { AdaptySubscriptionOfferId } from '@/types'; import type { Def } from '@/types/schema'; import { AdaptySubscriptionOfferIdCoder } from '@/coders/adapty-subscription-offer-identifier'; @@ -48,7 +49,7 @@ describe('AdaptySubscriptionOfferIdCoder', () => { let coder: AdaptySubscriptionOfferIdCoder; beforeEach(() => { - coder = new AdaptySubscriptionOfferIdCoder(); + coder = new AdaptySubscriptionOfferIdCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-subscription-offer.test.ts b/src/coders/adapty-subscription-offer.test.ts index f955ded..13791c5 100644 --- a/src/coders/adapty-subscription-offer.test.ts +++ b/src/coders/adapty-subscription-offer.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { AdaptySubscriptionOffer } from '@/types'; import type { Def } from '@/types/schema'; import { AdaptyDiscountPhaseCoder } from './adapty-discount-phase'; @@ -59,8 +60,12 @@ const mocks: Def['AdaptySubscriptionOffer'][] = [ ]; function toModel(mock: (typeof mocks)[number]): Model { - const _offerId = new AdaptySubscriptionOfferIdCoder(); - const _discounts = new ArrayCoder(() => new AdaptyDiscountPhaseCoder()); + const _offerId = new AdaptySubscriptionOfferIdCoder( + new DefaultPlatformAdapter(), + ); + const _discounts = new ArrayCoder( + () => new AdaptyDiscountPhaseCoder(new DefaultPlatformAdapter()), + ); return { identifier: _offerId.decode(mock.offer_identifier), @@ -77,7 +82,7 @@ describe('AdaptySubscriptionOfferCoder', () => { let coder: AdaptySubscriptionOfferCoder; beforeEach(() => { - coder = new AdaptySubscriptionOfferCoder(); + coder = new AdaptySubscriptionOfferCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-subscription-offer.ts b/src/coders/adapty-subscription-offer.ts index 0b9e3a3..8a4d089 100644 --- a/src/coders/adapty-subscription-offer.ts +++ b/src/coders/adapty-subscription-offer.ts @@ -18,13 +18,15 @@ export class AdaptySubscriptionOfferCoder extends SimpleCoder< key: 'offer_identifier', required: true, type: 'object', - converter: new AdaptySubscriptionOfferIdCoder(), + converter: new AdaptySubscriptionOfferIdCoder(this.platform), }, phases: { key: 'phases', required: true, type: 'array', - converter: new ArrayCoder(() => new AdaptyDiscountPhaseCoder()), + converter: new ArrayCoder( + () => new AdaptyDiscountPhaseCoder(this.platform), + ), }, android: { offerTags: { diff --git a/src/coders/adapty-subscription-period.test.ts b/src/coders/adapty-subscription-period.test.ts index d69982c..97c6299 100644 --- a/src/coders/adapty-subscription-period.test.ts +++ b/src/coders/adapty-subscription-period.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { AdaptySubscriptionPeriod, ProductPeriod } from '@/types'; import type { Def } from '@/types/schema'; import { AdaptySubscriptionPeriodCoder } from './adapty-subscription-period'; @@ -22,7 +23,7 @@ describe('AdaptySubscriptionPeriodCoder', () => { let coder: AdaptySubscriptionPeriodCoder; beforeEach(() => { - coder = new AdaptySubscriptionPeriodCoder(); + coder = new AdaptySubscriptionPeriodCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-subscription-pricing-terms.test.ts b/src/coders/adapty-subscription-pricing-terms.test.ts index 044e3a8..1a53808 100644 --- a/src/coders/adapty-subscription-pricing-terms.test.ts +++ b/src/coders/adapty-subscription-pricing-terms.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { AdaptySubscriptionPricingTerms, ProductPeriod } from '@/types'; import type { Def } from '@/types/schema'; import { AdaptySubscriptionPricingTermsCoder } from './adapty-subscription-pricing-terms'; @@ -50,7 +51,9 @@ describe('AdaptySubscriptionPricingTermsCoder', () => { let coder: AdaptySubscriptionPricingTermsCoder; beforeEach(() => { - coder = new AdaptySubscriptionPricingTermsCoder(); + coder = new AdaptySubscriptionPricingTermsCoder( + new DefaultPlatformAdapter(), + ); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-subscription-pricing-terms.ts b/src/coders/adapty-subscription-pricing-terms.ts index e40a0c9..7e7c973 100644 --- a/src/coders/adapty-subscription-pricing-terms.ts +++ b/src/coders/adapty-subscription-pricing-terms.ts @@ -23,19 +23,19 @@ export class AdaptySubscriptionPricingTermsCoder extends SimpleCoder< key: 'billing_price', required: true, type: 'object', - converter: new AdaptyPriceCoder(), + converter: new AdaptyPriceCoder(this.platform), }, billingPeriod: { key: 'billing_period', required: true, type: 'object', - converter: new AdaptySubscriptionPeriodCoder(), + converter: new AdaptySubscriptionPeriodCoder(this.platform), }, commitmentInfo: { key: 'commitment_info', required: true, type: 'object', - converter: new AdaptySubscriptionCommitmentInfoCoder(), + converter: new AdaptySubscriptionCommitmentInfoCoder(this.platform), }, }; } diff --git a/src/coders/adapty-subscription.test.ts b/src/coders/adapty-subscription.test.ts index b77c2cb..b3c7465 100644 --- a/src/coders/adapty-subscription.test.ts +++ b/src/coders/adapty-subscription.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { AdaptySubscription, CancellationReason, @@ -99,7 +100,7 @@ describe('AdaptySubscriptionCoder', () => { let coder: AdaptySubscriptionCoder; beforeEach(() => { - coder = new AdaptySubscriptionCoder(); + coder = new AdaptySubscriptionCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-subscription.ts b/src/coders/adapty-subscription.ts index 85ab174..01133ab 100644 --- a/src/coders/adapty-subscription.ts +++ b/src/coders/adapty-subscription.ts @@ -125,7 +125,9 @@ export class AdaptySubscriptionCoder extends SimpleCoder { key: 'commitment', required: false, type: 'object', - converter: new AdaptyProfileSubscriptionCommitmentInfoCoder(), + converter: new AdaptyProfileSubscriptionCommitmentInfoCoder( + this.platform, + ), }, offerId: { key: 'offer_id', diff --git a/src/coders/adapty-ui-dialog-config.test.ts b/src/coders/adapty-ui-dialog-config.test.ts index 3eb3b3c..49ecb37 100644 --- a/src/coders/adapty-ui-dialog-config.test.ts +++ b/src/coders/adapty-ui-dialog-config.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import { Def } from '@/types/schema'; import { AdaptyUiDialogConfigCoder } from '@/coders/adapty-ui-dialog-config'; @@ -14,7 +15,7 @@ const mocks: Def['AdaptyUI.DialogConfiguration'][] = [ ]; describe('AdaptyUiDialogConfigCoder', () => { - const coder = new AdaptyUiDialogConfigCoder(); + const coder = new AdaptyUiDialogConfigCoder(new DefaultPlatformAdapter()); it.each(mocks)('should encode/decode', mock => { const decoded = coder.decode(mock); diff --git a/src/coders/adapty-ui-media-cache.test.ts b/src/coders/adapty-ui-media-cache.test.ts index e908119..59ca5ce 100644 --- a/src/coders/adapty-ui-media-cache.test.ts +++ b/src/coders/adapty-ui-media-cache.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import { Def } from '@/types/schema'; import { AdaptyUiMediaCacheCoder } from '@/coders/adapty-ui-media-cache'; @@ -10,7 +11,7 @@ const mocks: Required['media_cache'][] = [ ]; describe('AdaptyUiMediaCacheCoder', () => { - const coder = new AdaptyUiMediaCacheCoder(); + const coder = new AdaptyUiMediaCacheCoder(new DefaultPlatformAdapter()); it.each(mocks)('should encode/decode', mock => { const decoded = coder.decode(mock); diff --git a/src/coders/adapty-ui-onboarding-meta.test.ts b/src/coders/adapty-ui-onboarding-meta.test.ts index 1a844ba..5d87a6d 100644 --- a/src/coders/adapty-ui-onboarding-meta.test.ts +++ b/src/coders/adapty-ui-onboarding-meta.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import { AdaptyUiOnboardingMetaCoder } from './adapty-ui-onboarding-meta'; import type { AdaptyUiOnboardingMeta } from '@/ui-builder/types'; import type { Def } from '@/types/schema'; @@ -31,7 +32,7 @@ describe('AdaptyUiOnboardingMetaCoder', () => { let coder: AdaptyUiOnboardingMetaCoder; beforeEach(() => { - coder = new AdaptyUiOnboardingMetaCoder(); + coder = new AdaptyUiOnboardingMetaCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-ui-onboarding-state-params.test.ts b/src/coders/adapty-ui-onboarding-state-params.test.ts index 6df65d5..8ed525c 100644 --- a/src/coders/adapty-ui-onboarding-state-params.test.ts +++ b/src/coders/adapty-ui-onboarding-state-params.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import { AdaptyUiOnboardingStateParamsCoder } from './adapty-ui-onboarding-state-params'; import type { AdaptyUiOnboardingStateParams } from '@/ui-builder/types'; import type { Def } from '@/types/schema'; @@ -28,7 +29,9 @@ describe('AdaptyUiOnboardingStateParamsCoder', () => { let coder: AdaptyUiOnboardingStateParamsCoder; beforeEach(() => { - coder = new AdaptyUiOnboardingStateParamsCoder(); + coder = new AdaptyUiOnboardingStateParamsCoder( + new DefaultPlatformAdapter(), + ); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/adapty-ui-onboarding-state-updated-action.test.ts b/src/coders/adapty-ui-onboarding-state-updated-action.test.ts index 8f9c519..edc66c3 100644 --- a/src/coders/adapty-ui-onboarding-state-updated-action.test.ts +++ b/src/coders/adapty-ui-onboarding-state-updated-action.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import { AdaptyUiOnboardingStateUpdatedActionCoder } from './adapty-ui-onboarding-state-updated-action'; import type { OnboardingStateUpdatedAction } from '@/ui-builder/types'; import type { Event } from '@/types/schema'; @@ -95,7 +96,9 @@ describe('AdaptyUiOnboardingStateUpdatedActionCoder', () => { let coder: AdaptyUiOnboardingStateUpdatedActionCoder; beforeEach(() => { - coder = new AdaptyUiOnboardingStateUpdatedActionCoder(); + coder = new AdaptyUiOnboardingStateUpdatedActionCoder( + new DefaultPlatformAdapter(), + ); }); it.each(mocks.map((mock, idx) => ({ mock, expected: expectedResults[idx] })))( diff --git a/src/coders/adapty-ui-onboarding-state-updated-action.ts b/src/coders/adapty-ui-onboarding-state-updated-action.ts index 1f74633..001a42e 100644 --- a/src/coders/adapty-ui-onboarding-state-updated-action.ts +++ b/src/coders/adapty-ui-onboarding-state-updated-action.ts @@ -13,7 +13,9 @@ export class AdaptyUiOnboardingStateUpdatedActionCoder extends SimpleCoder< BaseModel, Serializable > { - private readonly paramCoder = new AdaptyUiOnboardingStateParamsCoder(); + private readonly paramCoder = new AdaptyUiOnboardingStateParamsCoder( + this.platform, + ); protected properties: Properties = { elementId: { diff --git a/src/coders/bridge-error.test.ts b/src/coders/bridge-error.test.ts index a57fea7..7a68e8f 100644 --- a/src/coders/bridge-error.test.ts +++ b/src/coders/bridge-error.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import { AdaptyBridgeError } from '@/types/bridge'; import { BridgeErrorCoder } from './bridge-error'; import { AdaptyError } from '@/adapty-error'; @@ -12,7 +13,7 @@ describe('BridgeErrorCoder', () => { }; beforeEach(() => { - coder = new BridgeErrorCoder(); + coder = new BridgeErrorCoder(new DefaultPlatformAdapter()); }); it('should be Error', () => { diff --git a/src/coders/coder.ts b/src/coders/coder.ts index 0001fd3..c433b14 100644 --- a/src/coders/coder.ts +++ b/src/coders/coder.ts @@ -1,5 +1,4 @@ import { AdaptyError } from '@/adapty-error'; -import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { IPlatformAdapter } from '@/adapters/interfaces'; import { Converter, Properties, StrType } from './types'; @@ -11,7 +10,7 @@ export abstract class Coder< protected readonly platform: IPlatformAdapter; protected abstract properties: Properties; - constructor(platform: IPlatformAdapter = new DefaultPlatformAdapter()) { + constructor(platform: IPlatformAdapter) { this.platform = platform; } diff --git a/src/coders/nested-platform.test.ts b/src/coders/nested-platform.test.ts new file mode 100644 index 0000000..a1a0933 --- /dev/null +++ b/src/coders/nested-platform.test.ts @@ -0,0 +1,160 @@ +import type { + IPlatformAdapter, + ISdkMetadataAdapter, +} from '@/adapters/interfaces'; +import type { Def } from '@/types/schema'; +import { ArrayCoder } from './array'; +import { CoderFactory } from './factory'; + +const sdkMetadata: ISdkMetadataAdapter = { + sdkName: 'test', + sdkVersion: '0.0.0', +}; + +function createFactory(platform: IPlatformAdapter): CoderFactory { + return new CoderFactory({ platform, sdkMetadata }); +} + +const androidProduct: Def['AdaptyPaywallProduct.Response'] = { + vendor_product_id: 'yearly.premium', + adapty_product_id: 'adapty_yearly', + access_level_id: 'premium', + product_type: 'subscription', + paywall_product_index: 0, + paywall_variation_id: 'variation1', + paywall_ab_test_name: 'abTest1', + paywall_name: 'Paywall', + localized_description: 'Premium', + localized_title: 'Premium Yearly', + price: { amount: 69.99, localized_string: '$69.99' }, + subscription: { + base_plan_id: 'yearly-base', + renewal_type: 'autorenewable', + period: { unit: 'year', number_of_units: 1 }, + }, +}; + +const { base_plan_id: _basePlanId, ...subscriptionWithoutBasePlan } = + androidProduct.subscription!; +const androidProductWithoutBasePlan: Def['AdaptyPaywallProduct.Response'] = { + ...androidProduct, + subscription: subscriptionWithoutBasePlan, +}; + +const iosProduct: Def['AdaptyPaywallProduct.Response'] = { + ...androidProduct, + is_family_shareable: false, + subscription: { + group_identifier: 'group1', + period: { unit: 'year', number_of_units: 1 }, + }, +}; + +describe('nested coders and the platform adapter', () => { + describe('android.basePlanId in nested subscription details', () => { + const android = createFactory({ OS: 'android' }); + + it('should reject an Android product without base_plan_id', () => { + expect(() => + android + .createPaywallProductCoder() + .decode(androidProductWithoutBasePlan), + ).toThrow(/basePlanId/); + }); + + it('should reject the whole products array on Android', () => { + expect(() => + android + .createPaywallProductArrayCoder() + .decode([androidProduct, androidProductWithoutBasePlan]), + ).toThrow(/basePlanId/); + }); + + it('should decode an Android product with base_plan_id', () => { + const decoded = android + .createPaywallProductCoder() + .decode(androidProduct); + + expect(decoded.subscription?.android).toStrictEqual({ + basePlanId: 'yearly-base', + renewalType: 'autorenewable', + }); + }); + + it('should not require base_plan_id for iOS products on iOS', () => { + const ios = createFactory({ OS: 'ios' }); + + expect(() => + ios.createPaywallProductCoder().decode(iosProduct), + ).not.toThrow(); + }); + + it.each(['web', 'unknown'] as const)( + 'should keep platform checks off on %s', + OS => { + expect(() => + createFactory({ OS }) + .createPaywallProductCoder() + .decode(androidProductWithoutBasePlan), + ).not.toThrow(); + }, + ); + }); + + describe('platform adapter sharing', () => { + const platform: IPlatformAdapter = { OS: 'android' }; + const factory = createFactory(platform); + const proto = CoderFactory.prototype as unknown as Record< + string, + (this: CoderFactory) => unknown + >; + const methods = Object.getOwnPropertyNames(CoderFactory.prototype).filter( + name => name.startsWith('create') && proto[name]?.length === 0, + ); + + // Walks the object graph and returns every object that holds a `platform` field. + // Coders created inside methods are not reachable here; the required constructor parameter covers them. + function collectPlatformHolders(root: unknown): { platform: unknown }[] { + const holders: { platform: unknown }[] = []; + const seen = new Set(); + const visit = (value: unknown): void => { + if (value === null || typeof value !== 'object' || seen.has(value)) { + return; + } + seen.add(value); + if (value instanceof ArrayCoder) { + const inner = value as unknown as { coderFactory: () => unknown }; + visit(inner.coderFactory()); + } + if ('platform' in value) { + holders.push(value as { platform: unknown }); + } + Object.values(value).forEach(visit); + }; + visit(root); + return holders; + } + + it('should find factory methods to check', () => { + expect(methods.length).toBeGreaterThan(30); + }); + + it.each(methods)( + '%s should pass the factory platform to every nested coder', + name => { + const holders = collectPlatformHolders(proto[name]!.call(factory)); + + holders.forEach(holder => expect(holder.platform).toBe(platform)); + }, + ); + + it('should reach nested coders of the paywall product', () => { + const holders = collectPlatformHolders( + factory.createPaywallProductCoder(), + ); + + // product, price, subscription details and their nested coders + expect(holders.length).toBeGreaterThan(5); + }); + }); +}); diff --git a/src/coders/product-reference-pricing-terms.test.ts b/src/coders/product-reference-pricing-terms.test.ts index f8c8571..7ec646c 100644 --- a/src/coders/product-reference-pricing-terms.test.ts +++ b/src/coders/product-reference-pricing-terms.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { ProductReferencePricingTerms } from '@/types'; import type { Def } from '@/types/schema'; import { ProductReferencePricingTermsCoder } from './product-reference-pricing-terms'; @@ -28,7 +29,7 @@ describe('ProductReferencePricingTermsCoder', () => { let coder: ProductReferencePricingTermsCoder; beforeEach(() => { - coder = new ProductReferencePricingTermsCoder(); + coder = new ProductReferencePricingTermsCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/product-reference.test.ts b/src/coders/product-reference.test.ts index f73b8d3..57ad125 100644 --- a/src/coders/product-reference.test.ts +++ b/src/coders/product-reference.test.ts @@ -1,3 +1,4 @@ +import { DefaultPlatformAdapter } from '@/adapters/defaults'; import type { ProductReference, SubscriptionBillingPlan } from '@/types'; import type { Def } from '@/types/schema'; import type { IPlatformAdapter } from '@/adapters/interfaces'; @@ -77,7 +78,7 @@ describe('ProductReferenceCoder', () => { let coder: ProductReferenceCoder; beforeEach(() => { - coder = new ProductReferenceCoder(); + coder = new ProductReferenceCoder(new DefaultPlatformAdapter()); }); it.each(mocks)('should decode to expected result', mock => { diff --git a/src/coders/product-reference.ts b/src/coders/product-reference.ts index 3e5aad1..49e8ce8 100644 --- a/src/coders/product-reference.ts +++ b/src/coders/product-reference.ts @@ -41,7 +41,7 @@ export class ProductReferenceCoder extends SimpleCoder { required: false, type: 'array', converter: new ArrayCoder( - () => new ProductReferencePricingTermsCoder(), + () => new ProductReferencePricingTermsCoder(this.platform), ), }, }, From 4bb2d64ae1e01720d7706a6f25fceee7cad669ab Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Mon, 26 Oct 2026 12:40:00 +0300 Subject: [PATCH 23/25] chore: update yaml from https://github.com/adaptyteam/AdaptySDK-iOS/commit/bebad4dc155b35ec9b959f1e4f4aea100dfc214e --- cross_platform.yaml | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cross_platform.yaml b/cross_platform.yaml index c5135cd..022062a 100644 --- a/cross_platform.yaml +++ b/cross_platform.yaml @@ -547,7 +547,7 @@ $requests: ### showStoreMessage ### ShowStoreMessage.Request: #request type: object - description: "iOS Only. Requires iOS 16+" + description: "Requires iOS 16+ on iOS" required: [method] properties: method: { const: "show_store_messages" } @@ -1264,7 +1264,7 @@ $defs: store_messages_handling: { $ref: "#/$defs/StoreMessagesHandling", - description: "iOS Only. Requires iOS 16+", + description: "Requires iOS 16+ on iOS", } apple_idfa_collection_disabled: { type: boolean, default: false } google_adid_collection_disabled: { type: boolean, default: false } diff --git a/package.json b/package.json index 1a1b68c..eaed5c8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package", "name": "@adapty/core", - "version": "4.3.0", + "version": "4.3.1", "description": "Platform-agnostic core for Adapty JS SDKs", "license": "MIT", "author": "Adapty team ", From cf9a6413696b2a0d261f8e4f6dd71c8e9af8dc97 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Thu, 29 Oct 2026 18:55:33 +0300 Subject: [PATCH 24/25] chore: update yaml from https://github.com/adaptyteam/AdaptySDK-iOS/commit/61b8fab04ab69c3cde9bd04ccf816179640d0870 --- cross_platform.yaml | 3 ++- package.json | 2 +- src/types/api.d.ts | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cross_platform.yaml b/cross_platform.yaml index 022062a..e070b5d 100644 --- a/cross_platform.yaml +++ b/cross_platform.yaml @@ -1,5 +1,5 @@ $schema: "https://json-schema.org/draft/2020-12/schema" -$id: "https://adapty.io/crossPlatform/4.3.1/schema" +$id: "https://adapty.io/crossPlatform/4.3.2/schema" title: "Cross Platform Format" $requests: @@ -646,6 +646,7 @@ $requests: method: { const: "report_transaction" } variation_id: { type: string } transaction_id: { type: string } + apple_jws_transaction: { type: string } ReportTransaction.Response: #response type: object diff --git a/package.json b/package.json index eaed5c8..0ebddff 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package", "name": "@adapty/core", - "version": "4.3.1", + "version": "4.3.2", "description": "Platform-agnostic core for Adapty JS SDKs", "license": "MIT", "author": "Adapty team ", diff --git a/src/types/api.d.ts b/src/types/api.d.ts index 45a0115..fc85e76 100644 --- a/src/types/api.d.ts +++ b/src/types/api.d.ts @@ -383,6 +383,7 @@ export interface components { method: 'report_transaction'; variation_id?: string; transaction_id: string; + apple_jws_transaction?: string; }; 'ReportTransaction.Response': OneOf< From 66528b3e0804f77ad4a62e05f5e6adab11a5f9c8 Mon Sep 17 00:00:00 2001 From: Stanislav Mayorov Date: Thu, 29 Oct 2026 19:44:36 +0300 Subject: [PATCH 25/25] feat: add ReportTransactionParamsCoder --- .../adapty-report-transaction-params.test.ts | 54 +++++++++++++++++++ .../adapty-report-transaction-params.ts | 26 +++++++++ src/coders/factory.ts | 5 ++ src/types/inputs.ts | 9 ++++ 4 files changed, 94 insertions(+) create mode 100644 src/coders/adapty-report-transaction-params.test.ts create mode 100644 src/coders/adapty-report-transaction-params.ts diff --git a/src/coders/adapty-report-transaction-params.test.ts b/src/coders/adapty-report-transaction-params.test.ts new file mode 100644 index 0000000..0e2a287 --- /dev/null +++ b/src/coders/adapty-report-transaction-params.test.ts @@ -0,0 +1,54 @@ +import type { IPlatformAdapter, PlatformOS } from '@/adapters/interfaces'; +import { AdaptyReportTransactionParamsCoder } from '@/coders/adapty-report-transaction-params'; + +describe('AdaptyReportTransactionParamsCoder', () => { + const createCoder = (OS: PlatformOS = 'ios') => + new AdaptyReportTransactionParamsCoder({ OS } as IPlatformAdapter); + + const fullParams = { + transactionId: 'transaction_12345', + variationId: 'variation_abc', + ios: { jwsTransaction: 'jws_transaction_abc' }, + }; + + it('should encode only transaction_id when nothing else is set', () => { + const result = createCoder().encode({ transactionId: 'transaction_12345' }); + expect(result).toEqual({ transaction_id: 'transaction_12345' }); + }); + + it('should omit empty variation_id', () => { + const result = createCoder().encode({ + transactionId: 'transaction_12345', + variationId: '', + }); + expect(result).toEqual({ transaction_id: 'transaction_12345' }); + }); + + it('should encode all fields on iOS', () => { + const result = createCoder('ios').encode(fullParams); + expect(result).toEqual({ + transaction_id: 'transaction_12345', + variation_id: 'variation_abc', + apple_jws_transaction: 'jws_transaction_abc', + }); + }); + + it.each(['android', 'unknown'] as const)( + 'should omit apple_jws_transaction on %s', + OS => { + const result = createCoder(OS).encode(fullParams); + expect(result).toEqual({ + transaction_id: 'transaction_12345', + variation_id: 'variation_abc', + }); + }, + ); + + it('should omit empty jwsTransaction on iOS', () => { + const result = createCoder('ios').encode({ + transactionId: 'transaction_12345', + ios: { jwsTransaction: '' }, + }); + expect(result).toEqual({ transaction_id: 'transaction_12345' }); + }); +}); diff --git a/src/coders/adapty-report-transaction-params.ts b/src/coders/adapty-report-transaction-params.ts new file mode 100644 index 0000000..43cc092 --- /dev/null +++ b/src/coders/adapty-report-transaction-params.ts @@ -0,0 +1,26 @@ +import type { IPlatformAdapter } from '@/adapters/interfaces'; +import type { Req } from '@/types/schema'; +import * as Input from '@/types/inputs'; + +type Model = Input.ReportTransactionParamsInput; +type Serializable = Omit; + +export class AdaptyReportTransactionParamsCoder { + constructor(private readonly platform: IPlatformAdapter) {} + + encode(params: Model): Serializable { + const result: Serializable = { + transaction_id: params.transactionId, + }; + + if (params.variationId) { + result.variation_id = params.variationId; + } + + if (this.platform.OS === 'ios' && params.ios?.jwsTransaction) { + result.apple_jws_transaction = params.ios.jwsTransaction; + } + + return result; + } +} diff --git a/src/coders/factory.ts b/src/coders/factory.ts index 1100a5d..ef90205 100644 --- a/src/coders/factory.ts +++ b/src/coders/factory.ts @@ -25,6 +25,7 @@ import { AdaptyProfileSubscriptionCommitmentInfoCoder } from './adapty-profile-s import { AdaptyProfileCoder } from './adapty-profile'; import { AdaptyPurchaseParamsCoder } from './adapty-purchase-params'; import { AdaptyPurchaseResultCoder } from './adapty-purchase-result'; +import { AdaptyReportTransactionParamsCoder } from './adapty-report-transaction-params'; import { AdaptyRemoteConfigCoder } from './adapty-remote-config'; import { AdaptySubscriptionCommitmentInfoCoder } from './adapty-subscription-commitment-info'; import { AdaptySubscriptionDetailsCoder } from './adapty-subscription-details'; @@ -175,6 +176,10 @@ export class CoderFactory { return new AdaptyRemoteConfigCoder(this.deps.platform); } + createReportTransactionParamsCoder(): AdaptyReportTransactionParamsCoder { + return new AdaptyReportTransactionParamsCoder(this.deps.platform); + } + createSubscriptionCoder(): AdaptySubscriptionCoder { return new AdaptySubscriptionCoder(this.deps.platform); } diff --git a/src/types/inputs.ts b/src/types/inputs.ts index 3a65bf9..e0d953d 100644 --- a/src/types/inputs.ts +++ b/src/types/inputs.ts @@ -248,6 +248,15 @@ export interface IdentifyParamsInput { }; } +export interface ReportTransactionParamsInput { + transactionId: string; + variationId?: string; + ios?: { + /** StoreKit 2 JWS representation of the transaction */ + jwsTransaction?: string; + }; +} + export interface GetPaywallProductsParamsInput {} export const AdaptyAndroidSubscriptionUpdateReplacementMode = Object.freeze({