Socket
Socket
Sign inDemoInstall

@aitmed/aitmed-ecos-sdk

Package Overview
Dependencies
188
Maintainers
6
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @aitmed/aitmed-ecos-sdk

> Application layer sdk for the AiTmed platform.


Version published
Weekly downloads
3
increased by200%
Maintainers
6
Created
Weekly downloads
 

Readme

Source

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

Store

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)
}

SDK

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

AiTmedError {
  readonly code: number
  readonly name: string
  readonly message: string

  constructor({
    code?: number,
    name?: string,
    message?: string
  })
}
AiTmedErrorNameDefault Message
-1UNKNOW_ERRORerror occurred
1PERMISSION_DENIEDpermission denied
2UNREGISTEREDaccount is not registered
3REGISTEREDaccount is already registered
/_ Accoutn _/
1000PHONE_NUMBER_INVALIDphone number is invalid
1001PASSWORD_INVALIDpassword is invalid
1002VERIFICATION_CODE_INVALIDverification code is invalid
1003REQUIRED_VERIFICATION_CODEverification code is required
1004REQUIRED_PASSWORDpassword is required
1005USER_NOT_FOUNDuser is not found
/_ Notebook _/
2000NOTEBOOK_NOT_EXISTnotebook is not exist
2001NOTEBOOK_PERMISSION_DENIEDnotebook permission denied
/_ Note _/
3000NOTE_NOT_EXISTnote is not exist
3001NOTE_PERMISSION_DENIEDnote permission denied
3002NOTE_CONTENT_INVALIDnote content is invalid

Account

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
logout(): Status
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>

Notebook

interface Notebook {
  id: Uint8Array | string
  owner_id: Uint8Array | string

  info: {
    title: string
    edit_mode: number
  }
}
account.getStatus
getStatus(): Status
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>

Note

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

FAQs

Last updated on 10 Dec 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc