chore: send shared vault owner context when creating a shared vault file valet token (#2435)
* chore: send shared vault owner context when creating a shared vault file valet token * chore: remove unused shared vault upload bytes limit
This commit is contained in:
4
packages/api/src/Domain/Http/HttpRequestOptions.ts
Normal file
4
packages/api/src/Domain/Http/HttpRequestOptions.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface HttpRequestOptions {
|
||||
authentication?: string
|
||||
headers?: Record<string, string>[]
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import { Paths } from '../Server/Auth/Paths'
|
||||
import { SessionRefreshResponseBody } from '../Response/Auth/SessionRefreshResponseBody'
|
||||
import { FetchRequestHandler } from './FetchRequestHandler'
|
||||
import { RequestHandlerInterface } from './RequestHandlerInterface'
|
||||
import { HttpRequestOptions } from './HttpRequestOptions'
|
||||
|
||||
export class HttpService implements HttpServiceInterface {
|
||||
private session?: Session | LegacySession
|
||||
@@ -76,7 +77,7 @@ export class HttpService implements HttpServiceInterface {
|
||||
}
|
||||
}
|
||||
|
||||
async get<T>(path: string, params?: HttpRequestParams, authentication?: string): Promise<HttpResponse<T>> {
|
||||
async get<T>(path: string, params?: HttpRequestParams, options?: HttpRequestOptions): Promise<HttpResponse<T>> {
|
||||
if (!this.host) {
|
||||
throw new Error('Attempting to make network request before host is set')
|
||||
}
|
||||
@@ -85,7 +86,7 @@ export class HttpService implements HttpServiceInterface {
|
||||
url: joinPaths(this.host, path),
|
||||
params,
|
||||
verb: HttpVerb.Get,
|
||||
authentication: authentication ?? this.getSessionAccessToken(),
|
||||
authentication: options?.authentication ?? this.getSessionAccessToken(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -98,7 +99,7 @@ export class HttpService implements HttpServiceInterface {
|
||||
})
|
||||
}
|
||||
|
||||
async post<T>(path: string, params?: HttpRequestParams, authentication?: string): Promise<HttpResponse<T>> {
|
||||
async post<T>(path: string, params?: HttpRequestParams, options?: HttpRequestOptions): Promise<HttpResponse<T>> {
|
||||
if (!this.host) {
|
||||
throw new Error('Attempting to make network request before host is set')
|
||||
}
|
||||
@@ -107,34 +108,35 @@ export class HttpService implements HttpServiceInterface {
|
||||
url: joinPaths(this.host, path),
|
||||
params,
|
||||
verb: HttpVerb.Post,
|
||||
authentication: authentication ?? this.getSessionAccessToken(),
|
||||
authentication: options?.authentication ?? this.getSessionAccessToken(),
|
||||
customHeaders: options?.headers,
|
||||
})
|
||||
}
|
||||
|
||||
async put<T>(path: string, params?: HttpRequestParams, authentication?: string): Promise<HttpResponse<T>> {
|
||||
async put<T>(path: string, params?: HttpRequestParams, options?: HttpRequestOptions): Promise<HttpResponse<T>> {
|
||||
return this.runHttp({
|
||||
url: joinPaths(this.host, path),
|
||||
params,
|
||||
verb: HttpVerb.Put,
|
||||
authentication: authentication ?? this.getSessionAccessToken(),
|
||||
authentication: options?.authentication ?? this.getSessionAccessToken(),
|
||||
})
|
||||
}
|
||||
|
||||
async patch<T>(path: string, params: HttpRequestParams, authentication?: string): Promise<HttpResponse<T>> {
|
||||
async patch<T>(path: string, params: HttpRequestParams, options?: HttpRequestOptions): Promise<HttpResponse<T>> {
|
||||
return this.runHttp({
|
||||
url: joinPaths(this.host, path),
|
||||
params,
|
||||
verb: HttpVerb.Patch,
|
||||
authentication: authentication ?? this.getSessionAccessToken(),
|
||||
authentication: options?.authentication ?? this.getSessionAccessToken(),
|
||||
})
|
||||
}
|
||||
|
||||
async delete<T>(path: string, params?: HttpRequestParams, authentication?: string): Promise<HttpResponse<T>> {
|
||||
async delete<T>(path: string, params?: HttpRequestParams, options?: HttpRequestOptions): Promise<HttpResponse<T>> {
|
||||
return this.runHttp({
|
||||
url: joinPaths(this.host, path),
|
||||
params,
|
||||
verb: HttpVerb.Delete,
|
||||
authentication: authentication ?? this.getSessionAccessToken(),
|
||||
authentication: options?.authentication ?? this.getSessionAccessToken(),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import { LegacySession, Session } from '@standardnotes/domain-core'
|
||||
import { HttpRequest, HttpRequestParams, HttpResponse, HttpResponseMeta } from '@standardnotes/responses'
|
||||
|
||||
import { HttpRequestOptions } from './HttpRequestOptions'
|
||||
|
||||
export interface HttpServiceInterface {
|
||||
setHost(host: string): void
|
||||
getHost(): string
|
||||
|
||||
get<T>(path: string, params?: HttpRequestParams, authentication?: string): Promise<HttpResponse<T>>
|
||||
get<T>(path: string, params?: HttpRequestParams, options?: HttpRequestOptions): Promise<HttpResponse<T>>
|
||||
getExternal<T>(url: string, params?: HttpRequestParams): Promise<HttpResponse<T>>
|
||||
post<T>(path: string, params?: HttpRequestParams, authentication?: string): Promise<HttpResponse<T>>
|
||||
put<T>(path: string, params?: HttpRequestParams, authentication?: string): Promise<HttpResponse<T>>
|
||||
patch<T>(path: string, params: HttpRequestParams, authentication?: string): Promise<HttpResponse<T>>
|
||||
delete<T>(path: string, params?: HttpRequestParams, authentication?: string): Promise<HttpResponse<T>>
|
||||
post<T>(path: string, params?: HttpRequestParams, options?: HttpRequestOptions): Promise<HttpResponse<T>>
|
||||
put<T>(path: string, params?: HttpRequestParams, options?: HttpRequestOptions): Promise<HttpResponse<T>>
|
||||
patch<T>(path: string, params: HttpRequestParams, options?: HttpRequestOptions): Promise<HttpResponse<T>>
|
||||
delete<T>(path: string, params?: HttpRequestParams, options?: HttpRequestOptions): Promise<HttpResponse<T>>
|
||||
runHttp<T>(httpRequest: HttpRequest): Promise<HttpResponse<T>>
|
||||
|
||||
setSession(session: Session | LegacySession): void
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export * from './HttpService'
|
||||
export * from './FetchRequestHandler'
|
||||
export * from './HttpRequestOptions'
|
||||
export * from './HttpServiceInterface'
|
||||
export * from './XMLHttpRequestState'
|
||||
|
||||
@@ -8,4 +8,5 @@ export type CreateSharedVaultValetTokenParams = {
|
||||
unencryptedFileSize?: number
|
||||
moveOperationType?: SharedVaultMoveType
|
||||
sharedVaultToSharedVaultMoveTargetUuid?: string
|
||||
sharedVaultOwnerUuid?: string
|
||||
}
|
||||
|
||||
@@ -25,13 +25,23 @@ export class SharedVaultServer implements SharedVaultServerInterface {
|
||||
createSharedVaultFileValetToken(
|
||||
params: CreateSharedVaultValetTokenParams,
|
||||
): Promise<HttpResponse<CreateSharedVaultValetTokenResponse>> {
|
||||
return this.httpService.post(SharedVaultsPaths.createSharedVaultFileValetToken(params.sharedVaultUuid), {
|
||||
file_uuid: params.fileUuid,
|
||||
remote_identifier: params.remoteIdentifier,
|
||||
operation: params.operation,
|
||||
unencrypted_file_size: params.unencryptedFileSize,
|
||||
move_operation_type: params.moveOperationType,
|
||||
shared_vault_to_shared_vault_move_target_uuid: params.sharedVaultToSharedVaultMoveTargetUuid,
|
||||
})
|
||||
let headers = undefined
|
||||
if (params.sharedVaultOwnerUuid) {
|
||||
headers = [{ 'x-shared-vault-owner-context': params.sharedVaultOwnerUuid }]
|
||||
}
|
||||
return this.httpService.post(
|
||||
SharedVaultsPaths.createSharedVaultFileValetToken(params.sharedVaultUuid),
|
||||
{
|
||||
file_uuid: params.fileUuid,
|
||||
remote_identifier: params.remoteIdentifier,
|
||||
operation: params.operation,
|
||||
unencrypted_file_size: params.unencryptedFileSize,
|
||||
move_operation_type: params.moveOperationType,
|
||||
shared_vault_to_shared_vault_move_target_uuid: params.sharedVaultToSharedVaultMoveTargetUuid,
|
||||
},
|
||||
{
|
||||
headers,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user