From d96d9272998dfa2ca25860820101faaa763e53a0 Mon Sep 17 00:00:00 2001 From: moughxyz Date: Thu, 7 Mar 2024 09:05:14 -0600 Subject: [PATCH] Use API v0 on iOS --- packages/api/src/Domain/Client/Auth/AuthApiService.ts | 9 ++++++--- .../Client/Subscription/SubscriptionApiService.ts | 11 +++++++---- packages/api/src/Domain/Client/User/UserApiService.ts | 5 +++-- packages/api/src/Domain/Http/HttpService.ts | 3 ++- packages/mobile/ios/Podfile.lock | 4 ++-- .../src/Domain/Application/Options/RequiredOptions.ts | 3 +++ .../snjs/lib/Application/Dependencies/Dependencies.ts | 6 ++++-- packages/snjs/mocha/lib/Applications.js | 1 + .../web/src/javascripts/Application/WebApplication.ts | 3 +++ 9 files changed, 31 insertions(+), 14 deletions(-) diff --git a/packages/api/src/Domain/Client/Auth/AuthApiService.ts b/packages/api/src/Domain/Client/Auth/AuthApiService.ts index 2c9fd86454e..d4e4a82f659 100644 --- a/packages/api/src/Domain/Client/Auth/AuthApiService.ts +++ b/packages/api/src/Domain/Client/Auth/AuthApiService.ts @@ -15,7 +15,10 @@ import { AuthApiServiceInterface } from './AuthApiServiceInterface' export class AuthApiService implements AuthApiServiceInterface { private operationsInProgress: Map - constructor(private authServer: AuthServerInterface) { + constructor( + private authServer: AuthServerInterface, + private apiVersion: ApiVersion, + ) { this.operationsInProgress = new Map() } @@ -50,7 +53,7 @@ export class AuthApiService implements AuthApiServiceInterface { try { const response = await this.authServer.recoveryKeyParams({ - api_version: ApiVersion.v1, + api_version: this.apiVersion, code_challenge: dto.codeChallenge, recovery_codes: dto.recoveryCodes, username: dto.username, @@ -78,7 +81,7 @@ export class AuthApiService implements AuthApiServiceInterface { try { const response = await this.authServer.signInWithRecoveryCodes({ - api_version: ApiVersion.v1, + api_version: this.apiVersion, code_verifier: dto.codeVerifier, password: dto.password, recovery_codes: dto.recoveryCodes, diff --git a/packages/api/src/Domain/Client/Subscription/SubscriptionApiService.ts b/packages/api/src/Domain/Client/Subscription/SubscriptionApiService.ts index ff2debb1da9..32c59cfe19b 100644 --- a/packages/api/src/Domain/Client/Subscription/SubscriptionApiService.ts +++ b/packages/api/src/Domain/Client/Subscription/SubscriptionApiService.ts @@ -23,7 +23,10 @@ import { GetUserSubscriptionRequestParams } from '../../Request/Subscription/Get export class SubscriptionApiService implements SubscriptionApiServiceInterface { private operationsInProgress: Map - constructor(private subscriptionServer: SubscriptionServerInterface) { + constructor( + private subscriptionServer: SubscriptionServerInterface, + private apiVersion: ApiVersion, + ) { this.operationsInProgress = new Map() } @@ -36,7 +39,7 @@ export class SubscriptionApiService implements SubscriptionApiServiceInterface { try { const response = await this.subscriptionServer.listInvites({ - [ApiEndpointParam.ApiVersion]: ApiVersion.v1, + [ApiEndpointParam.ApiVersion]: this.apiVersion, }) return response @@ -56,7 +59,7 @@ export class SubscriptionApiService implements SubscriptionApiServiceInterface { try { const response = await this.subscriptionServer.cancelInvite({ - [ApiEndpointParam.ApiVersion]: ApiVersion.v1, + [ApiEndpointParam.ApiVersion]: this.apiVersion, inviteUuid, }) @@ -77,7 +80,7 @@ export class SubscriptionApiService implements SubscriptionApiServiceInterface { try { const response = await this.subscriptionServer.invite({ - [ApiEndpointParam.ApiVersion]: ApiVersion.v1, + [ApiEndpointParam.ApiVersion]: this.apiVersion, identifier: inviteeEmail, }) diff --git a/packages/api/src/Domain/Client/User/UserApiService.ts b/packages/api/src/Domain/Client/User/UserApiService.ts index a45b5920ad9..146ad4a17fb 100644 --- a/packages/api/src/Domain/Client/User/UserApiService.ts +++ b/packages/api/src/Domain/Client/User/UserApiService.ts @@ -22,6 +22,7 @@ export class UserApiService implements UserApiServiceInterface { constructor( private userServer: UserServerInterface, private userRequestServer: UserRequestServerInterface, + private apiVersion: ApiVersion, ) { this.operationsInProgress = new Map() } @@ -72,7 +73,7 @@ export class UserApiService implements UserApiServiceInterface { try { const response = await this.userServer.register({ - [ApiEndpointParam.ApiVersion]: ApiVersion.v1, + [ApiEndpointParam.ApiVersion]: this.apiVersion, password: registerDTO.serverPassword, email: registerDTO.email, ephemeral: registerDTO.ephemeral, @@ -92,7 +93,7 @@ export class UserApiService implements UserApiServiceInterface { try { const response = await this.userServer.update({ - [ApiEndpointParam.ApiVersion]: ApiVersion.v1, + [ApiEndpointParam.ApiVersion]: this.apiVersion, user_uuid: updateDTO.userUuid, }) diff --git a/packages/api/src/Domain/Http/HttpService.ts b/packages/api/src/Domain/Http/HttpService.ts index a33da5fcd53..24d0e2be6b8 100644 --- a/packages/api/src/Domain/Http/HttpService.ts +++ b/packages/api/src/Domain/Http/HttpService.ts @@ -36,6 +36,7 @@ export class HttpService implements HttpServiceInterface { private environment: Environment, private appVersion: string, private snjsVersion: string, + private apiVersion: ApiVersion, private logger: LoggerInterface, ) { this.requestHandler = new FetchRequestHandler(this.snjsVersion, this.appVersion, this.environment, this.logger) @@ -247,7 +248,7 @@ export class HttpService implements HttpServiceInterface { const params = { ...inParams, ...{ - [ApiEndpointParam.ApiVersion]: ApiVersion.v1, + [ApiEndpointParam.ApiVersion]: this.apiVersion, }, } diff --git a/packages/mobile/ios/Podfile.lock b/packages/mobile/ios/Podfile.lock index 5ca7664176d..bc14010fe10 100644 --- a/packages/mobile/ios/Podfile.lock +++ b/packages/mobile/ios/Podfile.lock @@ -736,7 +736,7 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon/yoga" SPEC CHECKSUMS: - boost: 57d2868c099736d80fcd648bf211b4431e51a558 + boost: a7c83b31436843459a1961bfd74b96033dc77234 CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99 DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54 FBLazyVector: 71803c074f6325f10b5ec891c443b6bbabef0ca7 @@ -756,7 +756,7 @@ SPEC CHECKSUMS: MMKV: 9c6c3fa4ddd849f28c7b9a5c9d23aab84f14ee35 MMKVCore: 9bb7440b170181ac5b81f542ac258103542e693d OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c - RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1 + RCT-Folly: 0080d0a6ebf2577475bda044aa59e2ca1f909cda RCTRequired: df81ab637d35fac9e6eb94611cfd20f0feb05455 RCTTypeSafety: 4636e4a36c7c2df332bda6d59b19b41c443d4287 React: e0cc5197a804031a6c53fb38483c3485fcb9d6f3 diff --git a/packages/services/src/Domain/Application/Options/RequiredOptions.ts b/packages/services/src/Domain/Application/Options/RequiredOptions.ts index 99bf22bbc56..56e7e1c3860 100644 --- a/packages/services/src/Domain/Application/Options/RequiredOptions.ts +++ b/packages/services/src/Domain/Application/Options/RequiredOptions.ts @@ -1,3 +1,4 @@ +import { ApiVersion } from '@standardnotes/api' import { Environment, Platform, ApplicationIdentifier } from '@standardnotes/models' import { AlertService, DeviceInterface } from '@standardnotes/services' import { PureCryptoInterface } from '@standardnotes/sncrypto-common' @@ -39,4 +40,6 @@ export interface RequiredApplicationOptions { * Version of client application. */ appVersion: string + + apiVersion: ApiVersion } diff --git a/packages/snjs/lib/Application/Dependencies/Dependencies.ts b/packages/snjs/lib/Application/Dependencies/Dependencies.ts index d9bfbcb244d..c65c204c546 100644 --- a/packages/snjs/lib/Application/Dependencies/Dependencies.ts +++ b/packages/snjs/lib/Application/Dependencies/Dependencies.ts @@ -1090,7 +1090,7 @@ export class Dependencies { }) this.factory.set(TYPES.AuthApiService, () => { - return new AuthApiService(this.get(TYPES.AuthServer)) + return new AuthApiService(this.get(TYPES.AuthServer), this.options.apiVersion) }) this.factory.set(TYPES.AuthManager, () => { @@ -1432,13 +1432,14 @@ export class Dependencies { }) this.factory.set(TYPES.SubscriptionApiService, () => { - return new SubscriptionApiService(this.get(TYPES.SubscriptionServer)) + return new SubscriptionApiService(this.get(TYPES.SubscriptionServer), this.options.apiVersion) }) this.factory.set(TYPES.UserApiService, () => { return new UserApiService( this.get(TYPES.UserServer), this.get(TYPES.UserRequestServer), + this.options.apiVersion, ) }) @@ -1542,6 +1543,7 @@ export class Dependencies { this.options.environment, this.options.appVersion, SnjsVersion, + this.options.apiVersion, this.get(TYPES.Logger), ) }) diff --git a/packages/snjs/mocha/lib/Applications.js b/packages/snjs/mocha/lib/Applications.js index 7c15a02a603..958ed4a3246 100644 --- a/packages/snjs/mocha/lib/Applications.js +++ b/packages/snjs/mocha/lib/Applications.js @@ -22,6 +22,7 @@ export function createApplicationWithOptions({ identifier, environment, platform defaultHost: host || Defaults.getDefaultHost(), appVersion: Defaults.getAppVersion(), webSocketUrl: Defaults.getDefaultWebSocketUrl(), + apiVersion: ApiVersion.V1, syncCallsThresholdPerMinute, }) } diff --git a/packages/web/src/javascripts/Application/WebApplication.ts b/packages/web/src/javascripts/Application/WebApplication.ts index 3b2d380e5a9..1bb609c75a8 100644 --- a/packages/web/src/javascripts/Application/WebApplication.ts +++ b/packages/web/src/javascripts/Application/WebApplication.ts @@ -23,6 +23,7 @@ import { SNNote, DesktopManagerInterface, FileItem, + ApiVersion, } from '@standardnotes/snjs' import { action, computed, makeObservable, observable } from 'mobx' import { startAuthentication, startRegistration } from '@simplewebauthn/browser' @@ -112,6 +113,8 @@ export class WebApplication extends SNApplication implements WebApplicationInter defaultHost: defaultSyncServerHost, appVersion: deviceInterface.appVersion, webSocketUrl: webSocketUrl, + /** iOS file:// based origin does not work with production cookies */ + apiVersion: platform === Platform.Ios ? ApiVersion.v0 : ApiVersion.v1, loadBatchSize: deviceInterface.environment === Environment.Mobile ? 250 : ApplicationOptionsDefaults.loadBatchSize, sleepBetweenBatches: