chore: switch api to cookie based sessions - skip e2e (#2854)

* chore: switch api to cookie based sessions - skip e2e

* chore: fix legacy http service to include api version in requests - skip e2e
This commit is contained in:
Karol Sójko
2024-03-05 09:25:53 +01:00
committed by GitHub
parent f3f5c63185
commit 1d0e8cfc7f
7 changed files with 42 additions and 13 deletions

View File

@@ -1,3 +1,4 @@
export enum ApiVersion {
v0 = '20200115',
v1 = '20240226',
}

View File

@@ -50,7 +50,7 @@ export class AuthApiService implements AuthApiServiceInterface {
try {
const response = await this.authServer.recoveryKeyParams({
api_version: ApiVersion.v0,
api_version: ApiVersion.v1,
code_challenge: dto.codeChallenge,
recovery_codes: dto.recoveryCodes,
username: dto.username,
@@ -78,7 +78,7 @@ export class AuthApiService implements AuthApiServiceInterface {
try {
const response = await this.authServer.signInWithRecoveryCodes({
api_version: ApiVersion.v0,
api_version: ApiVersion.v1,
code_verifier: dto.codeVerifier,
password: dto.password,
recovery_codes: dto.recoveryCodes,

View File

@@ -36,7 +36,7 @@ export class SubscriptionApiService implements SubscriptionApiServiceInterface {
try {
const response = await this.subscriptionServer.listInvites({
[ApiEndpointParam.ApiVersion]: ApiVersion.v0,
[ApiEndpointParam.ApiVersion]: ApiVersion.v1,
})
return response
@@ -56,7 +56,7 @@ export class SubscriptionApiService implements SubscriptionApiServiceInterface {
try {
const response = await this.subscriptionServer.cancelInvite({
[ApiEndpointParam.ApiVersion]: ApiVersion.v0,
[ApiEndpointParam.ApiVersion]: ApiVersion.v1,
inviteUuid,
})
@@ -77,7 +77,7 @@ export class SubscriptionApiService implements SubscriptionApiServiceInterface {
try {
const response = await this.subscriptionServer.invite({
[ApiEndpointParam.ApiVersion]: ApiVersion.v0,
[ApiEndpointParam.ApiVersion]: ApiVersion.v1,
identifier: inviteeEmail,
})

View File

@@ -72,7 +72,7 @@ export class UserApiService implements UserApiServiceInterface {
try {
const response = await this.userServer.register({
[ApiEndpointParam.ApiVersion]: ApiVersion.v0,
[ApiEndpointParam.ApiVersion]: ApiVersion.v1,
password: registerDTO.serverPassword,
email: registerDTO.email,
ephemeral: registerDTO.ephemeral,
@@ -92,7 +92,7 @@ export class UserApiService implements UserApiServiceInterface {
try {
const response = await this.userServer.update({
[ApiEndpointParam.ApiVersion]: ApiVersion.v0,
[ApiEndpointParam.ApiVersion]: ApiVersion.v1,
user_uuid: updateDTO.userUuid,
})

View File

@@ -9,9 +9,11 @@ import {
HttpResponse,
HttpResponseMeta,
isErrorResponse,
ApiEndpointParam,
} from '@standardnotes/responses'
import { HttpServiceInterface } from './HttpServiceInterface'
import { ApiVersion } from '../Api'
import { Paths } from '../Server/Auth/Paths'
import { SessionRefreshResponseBody } from '../Response/Auth/SessionRefreshResponseBody'
import { FetchRequestHandler } from './FetchRequestHandler'
@@ -145,6 +147,10 @@ export class HttpService implements HttpServiceInterface {
await sleep(this.__latencySimulatorMs, true)
}
httpRequest.params = httpRequest.params
? this.params(httpRequest.params as Record<string | number | symbol, unknown>)
: undefined
const isRefreshRequest = httpRequest.url === joinPaths(this.host, Paths.v1.refreshSession)
if (this.inProgressRefreshSessionPromise && !isRefreshRequest) {
await this.inProgressRefreshSessionPromise
@@ -236,4 +242,15 @@ export class HttpService implements HttpServiceInterface {
return true
}
private params(inParams: Record<string | number | symbol, unknown>): HttpRequestParams {
const params = {
...inParams,
...{
[ApiEndpointParam.ApiVersion]: ApiVersion.v1,
},
}
return params
}
}