0.5.0 • Published 4 months ago

@retter/rn-sdk v0.5.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

Installation

Using npm:

npm install @retter/rn-sdk

Using yarn:

yarn add @retter/rn-sdk

This package uses @react-native-async-storage/async-storage as a dependency. If you use bare react native project, head over to installation documents of this package. https://react-native-async-storage.github.io/async-storage/docs/install

Usage

Initialization

Clients should initialize with project id. Instances with same project id always be cached.

import Retter from '@retter/sdk'

const rio = Retter.getInstance(config: RetterClientConfig)

interface RetterClientConfig {
    projectId: string
    rootProjectId?: string
    region?: RetterRegion
    platform?: string
    culture?: string
}

projectId: Unique id of a project created in retter.io Console

region: Could be euWest1 or euWest1Beta

platform: ios, android, web, ...

culture: tr, en-US, vs....

Authentication

Retter uses custom token to authenticate. This custom tokens can be given by an action or a cloud object.

await rio.authenticateWithCustomToken('{CUSTOM_TOKEN}')

Authentication statuses can be listened. SDK will fire an event that clients can be subscribe on status change.

rio.authStatus.subscribe((event: RetterAuthChangedEvent) => {
    //
})

Event gives information about current auth status. Clients can check the authStatus to determine if they need to show login/register pages or not.

interface RetterAuthChangedEvent {
    authStatus: RetterAuthStatus
    identity?: string
    uid?: string
    message?: string
}

enum RetterAuthStatus {
    SIGNED_IN = 'SIGNED_IN',
    SIGNED_IN_ANONYM = 'SIGNED_IN_ANONYM',
    SIGNED_OUT = 'SIGNED_OUT',
    AUTH_FAILED = 'AUTH_FAILED',
}

Cloud Objects

SDK will allow to use Retter Cloud Objects. Clients can subscribe realtime state changes, trigger cloud methods, ...

Firstly, a cloud object must be initilize with classId. Additional config options can be seen in interface below.

const cloudObject = await rio.getCloudObject(config: RetterCloudObjectConfig)

interface RetterCloudObjectConfig {
    classId: string
    key?: {
        name: string
        value: string
    }
    instanceId?: string
    method?: string
    headers?: {
        [key: string]: string
    }
    queryStringParams?: {
        [key: string]: string
    }
    body?: {
        [key: string]: any
    }
    httpMethod?: 'get' | 'delete' | 'post' | 'put'
    base64Encode?: boolean // default: true, only get requests
}

State Subscription

Clients can be subscribe to realtime state (public, user and role states) changes. On first subscription, it gives current state.

cloudObject.state.public.subscribe((state: { [key: string]: any }) => {
    //
})

cloudObject.state.user.subscribe((state: { [key: string]: any }) => {
    //
})

cloudObject.state.role.subscribe((state: { [key: string]: any }) => {
    //
})

Method Calls

Any cloud method can be called via sdk. method parameter must be specified. Other parameters can be seen in interface below.

const response = await cloudObject.call(params: RetterCloudObjectCall)

interface RetterCloudObjectCall {
    method: string
    headers?: {
        [key: string]: string
    }
    queryStringParams?: {
        [key: string]: string
    }
    body?: {
        [key: string]: any
    }
    httpMethod?: 'get' | 'delete' | 'post' | 'put' // default: post
    base64Encode?: boolean // default: true, only get requests
    retryConfig: {
        delay?: number // 50ms
        count?: number // 3
        rate?: number // 1.5
    }
}

Call method will return a response with RetterCallResponse type includes data, status and headers.

Getting State

Clients also access state via method call.

const response = await cloudObject.getState(params: RetterCloudObjectRequest)

interface RetterCloudObjectRequest {
    headers?: {
        [key: string]: string
    }
    queryStringParams?: {
        [key: string]: string
    }
    body?: {
        [key: string]: any
    }
    httpMethod?: 'get' | 'delete' | 'post' | 'put'
}

Get stae method will return a response with RetterCallResponse type includes data<RetterCloudObjectState>, status and headers.

Available Methods

Cloud objects available methods can be accessed on methods array/

const methods = cloudObject.methods: RetterCloudObjectMethod[]

interface RetterCloudObjectMethod {
    tag?: string
    name: string
    sync?: boolean
    readonly?: boolean
    inputModel?: string
    outputModel?: string
    queryStringModel?: string
}

Instance List

const instanceIds = await cloudObject.listInstances()
0.5.0

4 months ago

0.4.9

9 months ago

0.4.8

9 months ago

0.3.20

9 months ago

0.3.22

9 months ago

0.3.21

9 months ago

0.3.19

9 months ago

0.3.18

9 months ago

0.3.6

9 months ago

0.3.5

9 months ago

0.3.8

9 months ago

0.3.7

9 months ago

0.3.4

9 months ago

0.4.20

8 months ago

0.4.21

8 months ago

0.3.9

9 months ago

0.3.17

9 months ago

0.3.16

9 months ago

0.4.26

8 months ago

0.3.15

9 months ago

0.4.27

7 months ago

0.3.14

9 months ago

0.4.24

8 months ago

0.3.13

9 months ago

0.4.25

8 months ago

0.3.12

9 months ago

0.4.22

8 months ago

0.3.11

9 months ago

0.4.23

8 months ago

0.3.10

9 months ago

0.4.19

8 months ago

0.4.10

9 months ago

0.4.17

8 months ago

0.4.18

8 months ago

0.4.15

8 months ago

0.4.16

8 months ago

0.4.13

9 months ago

0.4.14

9 months ago

0.4.11

9 months ago

0.4.12

9 months ago

0.4.5

9 months ago

0.4.4

9 months ago

0.4.7

9 months ago

0.4.6

9 months ago

0.4.1

9 months ago

0.4.0

9 months ago

0.4.3

9 months ago

0.4.2

9 months ago

0.3.0

1 year ago

0.2.1

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.2.2

1 year ago

0.3.3

1 year ago

0.1.4

1 year ago

0.2.0

1 year ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.3

2 years ago

0.1.0

2 years ago