Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions cross_platform.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$schema: "https://json-schema.org/draft/2020-12/schema"
$id: "https://adapty.io/crossPlatform/4.3.2/schema"
$id: "https://adapty.io/crossPlatform/4.4.1/schema"
title: "Cross Platform Format"

$requests:
Expand Down Expand Up @@ -135,6 +135,28 @@ $requests:
properties:
success: { const: true }

### sendAppMessage ###
AdaptyUISendAppMessage.Request: #request
type: object
required: [method, id, message_id, payload]
properties:
method: { const: "adapty_ui_send_app_message" }
id: { type: string, description: "View Id" }
message_id: { type: string, description: "Id of the message, generated by the wrapper; the flow script receives it as the event id" }
payload:
type: object
description: "Message for the flow script, delivered as the `applicationMsg` SDK event"

AdaptyUISendAppMessage.Response: #response
type: object
oneOf:
- required: [error]
properties:
error: { $ref: "#/$defs/AdaptyError" }
- required: [success]
properties:
success: { const: true }

### presentOnboardingView ###
AdaptyUIPresentOnboardingView.Request: #request
type: object
Expand Down Expand Up @@ -424,6 +446,7 @@ $requests:
### getLogLevel ###
GetLogLevel.Request: #request
type: object
description: "iOS Only"
required: [method]
properties:
method: { const: "get_log_level" }
Expand Down Expand Up @@ -509,6 +532,7 @@ $requests:
### makePromotedPurchase ###
MakePromotedPurchase.Request: #request
type: object
description: "iOS Only"
required: [method, product]
properties:
method: { const: "make_promoted_purchase" }
Expand Down Expand Up @@ -628,6 +652,7 @@ $requests:
### presentCodeRedemptionSheet ###
PresentCodeRedemptionSheet.Request: #request
type: object
description: "iOS Only"
required: [method]
properties:
method: { const: "present_code_redemption_sheet" }
Expand Down Expand Up @@ -756,6 +781,7 @@ $requests:
### updateCollectingRefundDataConsent ###
UpdateCollectingRefundDataConsent.Request: #request
type: object
description: "iOS Only"
required: [method, consent]
properties:
method: { const: "update_collecting_refund_data_consent" }
Expand Down Expand Up @@ -792,6 +818,7 @@ $requests:
### updateRefundPreference ###
UpdateRefundPreference.Request: #request
type: object
description: "iOS Only"
required: [method, refund_preference]
properties:
method: { const: "update_refund_preference" }
Expand Down Expand Up @@ -943,7 +970,9 @@ $events:
id: { const: "flow_view_did_receive_analytic_event" }
view: { $ref: "#/$defs/AdaptyUI.FlowView" }
name: { type: string }
params: { type: object }
params:
type: object
description: "Null fields of objects are dropped at every depth; nulls inside arrays are kept"

Event.DidLoadLatestProfile:
type: object
Expand All @@ -954,6 +983,7 @@ $events:

Event.DidReceivePromotedPurchase:
type: object
description: "iOS Only"
required: [id, product]
properties:
id: { const: "did_receive_promoted_purchase" }
Expand Down Expand Up @@ -1308,7 +1338,6 @@ $defs:
properties:
app_account_token: { $ref: "#/$defs/UUID", description: "iOS Only" }
obfuscated_account_id: { type: string, description: "Android Only" }
obfuscated_profile_id: { type: string, description: "Android Only" }

AdaptyPaywallProduct.Response: #response
type: object
Expand Down Expand Up @@ -1349,8 +1378,8 @@ $defs:
type: object
required:
- amount
- currency_code # iOS Only
- localized_string # iOS Only
- currency_code
- localized_string
properties:
amount: { type: number }
currency_code: { type: string }
Expand Down Expand Up @@ -1768,7 +1797,7 @@ $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" }
billing_plan_id: { type: string }
commitment: { $ref: "#/$defs/AdaptyProfile.SubscriptionCommitmentInfo" }
is_refund: { type: boolean }

Expand Down Expand Up @@ -1806,7 +1835,7 @@ $defs:
- is_refund
- is_sandbox
- will_renew
- billing_plan_id # iOS Only
- billing_plan_id
properties:
store: { type: string }
vendor_product_id: { type: string }
Expand All @@ -1829,7 +1858,7 @@ $defs:
active_promotional_offer_id: { type: string }
offer_id: { type: string }
cancellation_reason: { type: string }
billing_plan_id: { type: string, description: "iOS Only" }
billing_plan_id: { type: string }
commitment: { $ref: "#/$defs/AdaptyProfile.SubscriptionCommitmentInfo" }

AdaptyProfile.SubscriptionCommitmentInfo: #response
Expand Down Expand Up @@ -1982,6 +2011,7 @@ $defs:
properties:
type: { type: string, const: "custom" }
value: { type: string }
arguments: { type: object }

AdaptyUI.Permission: #event
description:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package",
"name": "@adapty/core",
"version": "4.3.4",
"version": "4.4.0",
"description": "Platform-agnostic core for Adapty JS SDKs",
"license": "MIT",
"author": "Adapty team <support@adapty.io>",
Expand Down
7 changes: 2 additions & 5 deletions src/coders/adapty-identify-params.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import type { IPlatformAdapter } from '@/adapters/interfaces';
import * as Input from '@/types/inputs';
import type { Def } from '@/types/schema';

type Model = Input.IdentifyParamsInput;
type Serializable = {
app_account_token?: string;
obfuscated_account_id?: string;
obfuscated_profile_id?: string;
};
type Serializable = Def['CustomerIdentityParameters'];

export class AdaptyIdentifyParamsCoder {
constructor(private readonly platform: IPlatformAdapter) {}
Expand Down
12 changes: 10 additions & 2 deletions src/coders/adapty-paywall-product.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,18 @@ const mocks: Def['AdaptyPaywallProduct.Response'][] = [
localized_period: '1 year',
pricing_terms: {
billing_plan_id: 'monthly',
billing_price: { amount: 6.99, localized_string: '$6.99' },
billing_price: {
amount: 6.99,
currency_code: 'USD',
localized_string: '$6.99',
},
billing_period: { unit: 'month', number_of_units: 1 },
commitment_info: {
price: { amount: 83.88, localized_string: '$83.88' },
price: {
amount: 83.88,
currency_code: 'USD',
localized_string: '$83.88',
},
period: { unit: 'year', number_of_units: 1 },
},
},
Expand Down
19 changes: 16 additions & 3 deletions src/coders/adapty-price.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ const mocks: Def['AdaptyPrice'][] = [
currency_symbol: '$',
localized_string: '$9.99',
},
{ amount: 9.99 },
{ amount: 9.99, currency_code: 'USD', localized_string: '$9.99' },
];

function toModel(mock: (typeof mocks)[number]): Model {
return {
amount: mock.amount,
...(mock.currency_code && { currencyCode: mock.currency_code }),
currencyCode: mock.currency_code,
...(mock.currency_symbol && { currencySymbol: mock.currency_symbol }),
...(mock.localized_string && { localizedString: mock.localized_string }),
localizedString: mock.localized_string,
};
}

Expand All @@ -42,4 +42,17 @@ describe('AdaptyPriceCoder', () => {

expect(encoded).toStrictEqual(mock);
});

it.each([
['currency_code', undefined],
['currency_code', null],
['localized_string', undefined],
['localized_string', null],
] as const)('should fail to decode when required %s is %p', (key, value) => {
const mock = { ...mocks[0]!, [key]: value };

expect(() => coder.decode(mock as Def['AdaptyPrice'])).toThrow(
key === 'currency_code' ? 'currencyCode' : 'localizedString',
);
});
});
12 changes: 10 additions & 2 deletions src/coders/adapty-price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class AdaptyPriceCoder extends SimpleCoder<Model, Serializable> {
},
currencyCode: {
key: 'currency_code',
required: false,
required: true,
type: 'string',
},
currencySymbol: {
Expand All @@ -25,8 +25,16 @@ export class AdaptyPriceCoder extends SimpleCoder<Model, Serializable> {
},
localizedString: {
key: 'localized_string',
required: false,
required: true,
type: 'string',
},
};
// Treat null as missing so required fields reject it
override decode(data: Serializable): Model {
return super.decode(
Object.fromEntries(
Object.entries(data).filter(([, value]) => value !== null),
) as Serializable,
);
}
}
5 changes: 5 additions & 0 deletions src/coders/adapty-profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const mocks: Omit<
custom_attributes: {},
subscriptions: {
'monthly.premium.999': {
billing_plan_id: 'up_front',
is_lifetime: false,
vendor_product_id: 'monthly.premium.999',
is_sandbox: true,
Expand All @@ -52,6 +53,7 @@ const mocks: Omit<
store: 'app_store',
},
'weekly.premium.599': {
billing_plan_id: 'up_front',
is_lifetime: false,
vendor_product_id: 'weekly.premium.599',
is_sandbox: true,
Expand Down Expand Up @@ -131,6 +133,7 @@ const mocks: Omit<
custom_attributes: {},
subscriptions: {
trial_sub_12: {
billing_plan_id: 'up_front',
is_lifetime: false,
vendor_product_id: 'trial_sub_12',
is_sandbox: true,
Expand All @@ -148,6 +151,7 @@ const mocks: Omit<
cancellation_reason: 'billing_error',
},
'weekly.premium.599': {
billing_plan_id: 'up_front',
is_lifetime: false,
vendor_product_id: 'weekly.premium.599',
is_sandbox: true,
Expand All @@ -165,6 +169,7 @@ const mocks: Omit<
cancellation_reason: 'voluntarily_cancelled',
},
'monthly.premium.999': {
billing_plan_id: 'up_front',
is_lifetime: false,
vendor_product_id: 'monthly.premium.999',
is_sandbox: true,
Expand Down
6 changes: 6 additions & 0 deletions src/coders/adapty-purchase-result.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const mocks: TestAdaptyPurchaseResultDef[] = [
custom_attributes: {},
subscriptions: {
'monthly.premium.999': {
billing_plan_id: 'up_front',
is_lifetime: false,
vendor_product_id: 'monthly.premium.999',
is_sandbox: true,
Expand All @@ -57,6 +58,7 @@ const mocks: TestAdaptyPurchaseResultDef[] = [
store: 'app_store',
},
'weekly.premium.599': {
billing_plan_id: 'up_front',
is_lifetime: false,
vendor_product_id: 'weekly.premium.599',
is_sandbox: true,
Expand Down Expand Up @@ -101,6 +103,7 @@ const mocks: TestAdaptyPurchaseResultDef[] = [
custom_attributes: {},
subscriptions: {
'monthly.premium.999': {
billing_plan_id: 'up_front',
is_lifetime: false,
vendor_product_id: 'monthly.premium.999',
is_sandbox: true,
Expand All @@ -117,6 +120,7 @@ const mocks: TestAdaptyPurchaseResultDef[] = [
store: 'app_store',
},
'weekly.premium.599': {
billing_plan_id: 'up_front',
is_lifetime: false,
vendor_product_id: 'weekly.premium.599',
is_sandbox: true,
Expand Down Expand Up @@ -162,6 +166,7 @@ const mocks: TestAdaptyPurchaseResultDef[] = [
custom_attributes: {},
subscriptions: {
'monthly.premium.999': {
billing_plan_id: 'up_front',
is_lifetime: false,
vendor_product_id: 'monthly.premium.999',
is_sandbox: true,
Expand All @@ -178,6 +183,7 @@ const mocks: TestAdaptyPurchaseResultDef[] = [
store: 'app_store',
},
'weekly.premium.599': {
billing_plan_id: 'up_front',
is_lifetime: false,
vendor_product_id: 'weekly.premium.599',
is_sandbox: true,
Expand Down
27 changes: 22 additions & 5 deletions src/coders/adapty-subscription-pricing-terms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,36 @@ type Model = AdaptySubscriptionPricingTerms;
const mocks: Def['AdaptySubscriptionPricingTerms'][] = [
{
billing_plan_id: 'monthly',
billing_price: { amount: 6.99, localized_string: '$6.99' },
billing_price: {
amount: 6.99,
currency_code: 'USD',
localized_string: '$6.99',
},
billing_period: { unit: 'month', number_of_units: 1 },
commitment_info: {
price: { amount: 83.88, localized_string: '$83.88' },
price: {
amount: 83.88,
currency_code: 'USD',
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_price: {
amount: 59.99,
currency_code: 'EUR',
localized_string: '59,99 €',
},
billing_period: { unit: 'year', number_of_units: 1 },
commitment_info: {
price: { amount: 59.99 },
price: {
amount: 59.99,
currency_code: 'EUR',
localized_string: '59,99 €',
},
period: { unit: 'year', number_of_units: 1 },
},
},
Expand All @@ -29,7 +45,8 @@ const mocks: Def['AdaptySubscriptionPricingTerms'][] = [
function toModel(mock: (typeof mocks)[number]): Model {
const price = (p: Def['AdaptyPrice']) => ({
amount: p.amount,
...(p.localized_string && { localizedString: p.localized_string }),
currencyCode: p.currency_code,
localizedString: p.localized_string,
});
const period = (p: Def['AdaptySubscriptionPeriod']) => ({
unit: p.unit as ProductPeriod,
Expand Down
Loading
Loading