feat: add responses package

This commit is contained in:
Karol Sójko
2022-07-06 11:59:04 +02:00
parent 67b0918ba8
commit 9d1f7043e5
73 changed files with 977 additions and 14 deletions

View File

@@ -0,0 +1,7 @@
export enum ApiEndpointParam {
LastSyncToken = 'sync_token',
PaginationToken = 'cursor_token',
SyncDlLimit = 'limit',
SyncPayloads = 'items',
ApiVersion = 'api',
}

View File

@@ -0,0 +1,8 @@
import { MinimalHttpResponse } from '../Http/MinimalHttpResponses'
import { IntegrityPayload } from './IntegrityPayload'
export type CheckIntegrityResponse = MinimalHttpResponse & {
data: {
mismatches: IntegrityPayload[]
}
}

View File

@@ -0,0 +1,11 @@
import { ConflictType } from './ConflictType'
import { ServerItemResponse } from './ServerItemResponse'
export type ConflictParams = {
type: ConflictType
server_item?: ServerItemResponse
unsaved_item?: ServerItemResponse
/** @legacay */
item?: ServerItemResponse
}

View File

@@ -0,0 +1,9 @@
export enum ConflictType {
ConflictingData = 'sync_conflict',
UuidConflict = 'uuid_conflict',
ContentTypeError = 'content_type_error',
ContentError = 'content_error',
ReadOnlyError = 'readonly_error',
UuidError = 'uuid_error',
SyncError = 'sync_error',
}

View File

@@ -0,0 +1,14 @@
import { MinimalHttpResponse } from '../Http/MinimalHttpResponses'
import { ServerItemResponse } from './ServerItemResponse'
export type GetSingleItemResponse = MinimalHttpResponse & {
data:
| {
success: true
item: ServerItemResponse
}
| {
success: false
message: string
}
}

View File

@@ -0,0 +1,6 @@
import { MicrosecondsTimestamp, Uuid } from '@standardnotes/common'
export type IntegrityPayload = {
uuid: Uuid
updated_at_timestamp: MicrosecondsTimestamp
}

View File

@@ -0,0 +1,14 @@
import { ApiEndpointParam } from './ApiEndpointParam'
import { ConflictParams } from './ConflictParams'
import { ServerItemResponse } from './ServerItemResponse'
export type RawSyncData = {
error?: unknown
[ApiEndpointParam.LastSyncToken]?: string
[ApiEndpointParam.PaginationToken]?: string
retrieved_items?: ServerItemResponse[]
saved_items?: ServerItemResponse[]
conflicts?: ConflictParams[]
unsaved?: ConflictParams[]
status?: number
}

View File

@@ -0,0 +1,4 @@
import { HttpResponse } from '../Http/HttpResponse'
import { RawSyncData } from './RawSyncData'
export type RawSyncResponse = HttpResponse & { data: RawSyncData }

View File

@@ -0,0 +1,10 @@
import { RoleName } from '@standardnotes/common'
export type RevisionListEntry = {
content_type: string
created_at: string
updated_at: string
/** The uuid of the revision */
uuid: string
required_role: RoleName
}

View File

@@ -0,0 +1,4 @@
import { HttpResponse } from '../Http/HttpResponse'
import { RevisionListEntry } from './RevisionListEntry'
export type RevisionListResponse = HttpResponse & { data: RevisionListEntry[] }

View File

@@ -0,0 +1,15 @@
import { ContentType, Uuid } from '@standardnotes/common'
export interface ServerItemResponse {
content_type: ContentType
content: string | undefined
created_at_timestamp: number
created_at: Date
deleted: boolean
duplicate_of?: Uuid
enc_item_key: string
items_key_id?: string
updated_at_timestamp: number
updated_at: Date
uuid: string
}

View File

@@ -0,0 +1,15 @@
import { ContentType, Uuid } from '@standardnotes/common'
export type SingleRevision = {
auth_hash?: string
content_type: ContentType
content: string
created_at: string
enc_item_key: string
/** The uuid of the item this revision was created with */
item_uuid: string
items_key_id: string
updated_at: string
/** The uuid of the revision */
uuid: Uuid
}

View File

@@ -0,0 +1,6 @@
import { HttpResponse } from '../Http/HttpResponse'
import { SingleRevision } from './SingleRevision'
export type SingleRevisionResponse = HttpResponse & {
data: SingleRevision
}