AiTmed's Ecos SDK
Usage
const sdk = new SDK({ apiVersion, env: 'development' })
const doSomething = async () => {
const phone_number = '+1 1234567890'
const password = '1234567890'
// Request Verification Code
const verification_code = await sdk.account.requestVerificationCode(phone_number)
// Create User
await sdk.account.create(
phone_number,
password,
parseInt(verification_code),
)
// Login
await sdk.account.login(
phone_number,
password,
verification_code,
)
}
API
type ApiVersion = 'v1beta1' | 'v1beta2'
type ENV = 'development' | 'production'
interface ResponseCatcher {
(response: Response): Response
}
interface ErrorCatcher {
(error: Level2Error): void
}
class Store {
constructor({
apiVersion: ApiVersion
env: ENV
})
public readonly level2SDK
public env: ENV
public apiVersion: ApiVersion
public responseCatcher: ResponseCatcher
public errorCatcher: ErrorCatcher
public setResponseCatcher(catcher?: ResponseCatcher)
public setErrorCatcher(catcher?: ErrorCatcher)
}
class SDK {
constructor({
apiVersion: ApiVersion
env: ENV
})
public readonly account: Account
public readonly notebook: Notebook
public readonly note: Note
public apiVersion: ApiVersion
public setResponseCatcher(catcher?: ResponseCatcher)
public setErrorCatcher(catcher?: ErrorCatcher)
}
AiTmedError {
readonly code: number
readonly name: string
readonly message: string
constructor({
code?: number,
name?: string,
message?: string
})
}
AiTmedError |
Name |
Default Message |
-1 |
UNKNOW_ERROR |
error occurred |
1 |
PERMISSION_DENIED |
permission denied |
2 |
UNREGISTERED |
account is not registered |
3 |
REGISTERED |
account is already registered |
/_ Accoutn _/ |
|
|
1000 |
PHONE_NUMBER_INVALID |
phone number is invalid |
1001 |
PASSWORD_INVALID |
password is invalid |
1002 |
VERIFICATION_CODE_INVALID |
verification code is invalid |
1003 |
REQUIRED_VERIFICATION_CODE |
verification code is required |
1004 |
REQUIRED_PASSWORD |
password is required |
1005 |
USER_NOT_FOUND |
user is not found |
/_ Notebook _/ |
|
|
2000 |
NOTEBOOK_NOT_EXIST |
notebook is not exist |
2001 |
NOTEBOOK_PERMISSION_DENIED |
notebook permission denied |
/_ Note _/ |
|
|
3000 |
NOTE_NOT_EXIST |
note is not exist |
3001 |
NOTE_PERMISSION_DENIED |
note permission denied |
3002 |
NOTE_CONTENT_INVALID |
note content is invalid |
interface User {
id: Uint8Array | string
phone_number: string
roles: number
first_name?: string
middle_name?: string
last_name?: string
profile_photo?: string
gender?: 'MALE' | 'FEMALE' | 'PNS'
birthday?: number
languages?: string[]
}
account.requestVerificationCode
requestVerificationCode(
phone_number: string
): Promise<string>
account.create
create(
phone_number: string,
password: string,
verification_code: number
): Promise<void>
account.login
login(
phone_number: string,
password: string,
verification_code: number
): Promise<void>
account.loginByPassword
login(
password: string
): Promise<void>
This method is only able to be used after login new device (loginByVerificationCode
)
account.loginByVerificationCode
login(
phone_number: string,
verification_code: number
): Promise<void>
account.logout
account.update
interface UpdateParams {
first_name?: string
middle_name?: string
last_name?: string
profile_photo?: string
gender?: 'MALE' | 'FEMALE' | 'PNS'
birthday?: number
languages?: string[]
}
update(
id: Uint8Array | string,
params: UpdateParams
): Promise<User>
account.updatePhoneNumber
NOT IMPLEMENT
updatePhoneNumber(params: {
phone_number: string,
new_phone_number: string,
verification_code: string,
}): Promise<User>
account.updatePassword
NOT IMPLEMENT
interface UdpatePasswordParams {
phone_number: string
new_password: string
verification_code?: string
password?: string
}
updatePassword(params: UdpatePasswordParams): Promise<void>
account.retrieve
updatePassword(id: Uint8Array | string): Promise<User>
interface Notebook {
id: Uint8Array | string
owner_id: Uint8Array | string
info: {
title: string
edit_mode: number
}
}
account.getStatus
notebook.create
create(title: string): Promise<NotebookType>
notebook.remove
remove(id: string | Uint8Array): Promise<NotebookType>
notebook.update
update(id: string | Uint8Array, fields: {
title?: string
}): Promise<NotebookType>
notebook.retrieve
retrieve(id: string | Uint8Array): Promise<NotebookType>
notebook.list
list(params: {
shared?: Boolean
count?: number
edit_mode?: number
sort_by?: 0 | 1 | 2
}): Promise<{
ids: Set<string | Uint8Array>
mapper: Map<string | Uint8Array, NotebookType>
}>
notebook.share
NOT IMPLEMENT
share(
id: string | Uint8Array,
invite_phone_number: string,
edit_mode: number
): Promise<void>
notebook.unshare
NOT IMPLEMENT
unshare(
id: string | Uint8Array,
invited_phone_number: string
): Promise<void>
interface NoteBase {
id: string
owner_id: string
notebook_id: string
edit_mode: number
title: string
tags: string[]
created_at: number
modified_at: number
modified_by: string
}
type NoteTypes =
| 0 // text
| 1 // form
interface Note extends NoteBase {
type: NoteTypes
content: string
}
type NoteFileTypes =
| 2 // image
| 3 // pdf
| 4 // vedio
interface NoteFile extends NoteBase {
// title will be the file name
type: NoteFileTypes
file: Blob
file_size: number
}
note.create
create(params: {
notebook_id: string
title: string
content: string | Blob
type: NoteTypes | NoteFileTypes
}): {
code: Code
data: {
note: Note | NoteFile | null
}
}
Return Code |
|
SUCCESS |
|
PERMISSION_DENIED |
|
NOTEBOOK_NOT_EXIST |
|
NOTEBOOK_PERMISSION_DENIED |
|
note.remove
remove(id: string): {
code: Code
data: {
note: Note | NoteFile | null
}
}
Return Code |
|
SUCCESS |
|
PERMISSION_DENIED |
|
NOTEBOOK_NOT_EXIST |
|
NOTEBOOK_PERMISSION_DENIED |
|
note.update
update(id: string, fields: {
notebook_id?: string
title?: string
content?: string | Blob
}): {
code: Code
data: {
note: Note | NoteFile | null
}
}
Return Code |
|
SUCCESS |
|
PERMISSION_DENIED |
|
NOTEBOOK_NOT_EXIST |
|
NOTEBOOK_PERMISSION_DENIED |
|
NOTE_NOT_EXIST |
|
NOTE_PERMISSION_DENIED |
|
NOTE_CONTENT_INVALID |
|
note.retrieve
retrieve(id: string): {
code: Code
data: {
note: Note | NoteFile | null
}
}
Return Code |
|
SUCCESS |
|
PERMISSION_DENIED |
|
NOTE_NOT_EXIST |
|
NOTE_PERMISSION_DENIED |
|
note.list
list(notebook_id: string, options: {
shared?: Boolean
types?: (NoteTypes | NoteFileTypes)[]
tags?: string[]
count?: number
edit_mode?: number
sort_by?: 0 | 1 | 2
}): {
code: Code
data: {
ids: string[]
mapper: {
[id: string]: Note | NoteFile
}
}
}
Return Code |
|
SUCCESS |
|
PERMISSION_DENIED |
|
NOTE_NOT_EXIST |
|
NOTE_PERMISSION_DENIED |
|
note.share
share(id: string, invite_phone_number: string, edit_mode: number): {
code: Code
}
Return Code |
|
SUCCESS |
|
PERMISSION_DENIED |
|
PHONE_NUMBER_INVALID |
|
NOTE_NOT_EXIST |
|
NOTE_PERMISSION_DENIED |
|
note.unshare
unshare(id: string, invited_phone_number: string): {
code: Code
}
Return Code |
|
SUCCESS |
|
PERMISSION_DENIED |
|
PHONE_NUMBER_INVALID |
|
NOTE_NOT_EXIST |
|
NOTE_PERMISSION_DENIED |
|