1.0.122 • Published 4 years ago

@aitmed/prynote-sdk v1.0.122

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

AiTmed's Prynote SDK

Usage

const sdk = new SDK({ apiVersion: 'v1beta1', 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
1.0.122

4 years ago

1.0.121

4 years ago

1.0.120

4 years ago

1.0.119

4 years ago

1.0.118

4 years ago

1.0.117

4 years ago

1.0.116

4 years ago

1.0.115

4 years ago

1.0.114

4 years ago

1.0.113

4 years ago

1.0.112

4 years ago

1.0.110

4 years ago

1.0.109

4 years ago

1.0.105

4 years ago

1.0.103

4 years ago

1.0.101

4 years ago

1.0.99

4 years ago

1.0.97

4 years ago

1.0.95

4 years ago

1.0.93

4 years ago

1.0.92

4 years ago

1.0.91

4 years ago

1.0.90

4 years ago

1.0.88

4 years ago

1.0.89

4 years ago

1.0.87

4 years ago

1.0.86

4 years ago

1.0.85

4 years ago

1.0.84

4 years ago

1.0.83

4 years ago

1.0.82

4 years ago

1.0.81

4 years ago

1.0.80

4 years ago

1.0.79

4 years ago

1.0.78

4 years ago

1.0.77

4 years ago

1.0.76

4 years ago

1.0.75

4 years ago

1.0.74

4 years ago

1.0.73

4 years ago

1.0.72

4 years ago

1.0.71

4 years ago

1.0.70

4 years ago

1.0.69

4 years ago

1.0.68

4 years ago

1.0.67

4 years ago

1.0.66

4 years ago

1.0.65

4 years ago

1.0.64

4 years ago

1.0.63

4 years ago

1.0.62

4 years ago

1.0.61

4 years ago

1.0.60

4 years ago

1.0.59

4 years ago

1.0.58

4 years ago

1.0.57

4 years ago

1.0.56

4 years ago

1.0.55

4 years ago

1.0.54

4 years ago

1.0.53

4 years ago

1.0.51

4 years ago

1.0.52

4 years ago

1.0.50

4 years ago

1.0.48

4 years ago

1.0.49

4 years ago

1.0.47

4 years ago

1.0.46

4 years ago

1.0.45

4 years ago

1.0.44

4 years ago

1.0.43

4 years ago

1.0.42

4 years ago

1.0.41

4 years ago

1.0.40

4 years ago

1.0.39

4 years ago

1.0.38

4 years ago

1.0.37

4 years ago

1.0.36

4 years ago

1.0.35

4 years ago

1.0.34

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.31

4 years ago

1.0.30

4 years ago

1.0.29

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago