@retter/sdk 0.2.28 → 0.2.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +193 -2
- package/bundle/index.js +1 -1
- package/dist/Auth.js +5 -2
- package/dist/Auth.js.map +1 -1
- package/dist/Request.d.ts +2 -0
- package/dist/Request.js +10 -3
- package/dist/Request.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
package/README.MD
CHANGED
|
@@ -1,3 +1,194 @@
|
|
|
1
|
-
|
|
1
|
+
## Installation
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Using npm:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @retter/sdk
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Using yarn:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
yarn add @retter/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Using unkpg:
|
|
16
|
+
|
|
17
|
+
```html
|
|
18
|
+
<script src="https://unpkg.com/@retter/sdk/bundle/index.js"></script>
|
|
19
|
+
```
|
|
20
|
+
> You can use global `Retter` keyword.
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Initialization
|
|
25
|
+
|
|
26
|
+
Clients should initialize with project id. Instances with same project id always be cached.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import Retter from '@retter/sdk'
|
|
30
|
+
|
|
31
|
+
const rio = Retter.getInstance(config: RetterClientConfig)
|
|
32
|
+
|
|
33
|
+
interface RetterClientConfig {
|
|
34
|
+
projectId: string
|
|
35
|
+
rootProjectId?: string
|
|
36
|
+
region?: RetterRegion
|
|
37
|
+
platform?: string
|
|
38
|
+
culture?: string
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
> **projectId**: Unique id of a project created in [retter.io Console](https://retter.io)
|
|
43
|
+
>
|
|
44
|
+
> **region**: Could be `euWest1` or `euWest1Beta`
|
|
45
|
+
>
|
|
46
|
+
> **platform**: web, react-native, vs...
|
|
47
|
+
>
|
|
48
|
+
> **culture**: tr, en-US, vs....
|
|
49
|
+
|
|
50
|
+
### Authentication
|
|
51
|
+
|
|
52
|
+
Retter uses custom token to authenticate. This custom tokens can be given by an action or a cloud object.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
await rio.authenticateWithCustomToken('{CUSTOM_TOKEN}')
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Authentication statuses can be listened. SDK will fire an event that clients can be subscribe on status change.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
rio.authStatus.subscribe((event: RetterAuthChangedEvent) => {
|
|
62
|
+
//
|
|
63
|
+
})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Event gives information about current auth status. Clients can check the `authStatus` to determine if they need to show login/register pages or not.
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
interface RetterAuthChangedEvent {
|
|
70
|
+
authStatus: RetterAuthStatus
|
|
71
|
+
identity?: string
|
|
72
|
+
uid?: string
|
|
73
|
+
message?: string
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
enum RetterAuthStatus {
|
|
77
|
+
SIGNED_IN = 'SIGNED_IN',
|
|
78
|
+
SIGNED_IN_ANONYM = 'SIGNED_IN_ANONYM',
|
|
79
|
+
SIGNED_OUT = 'SIGNED_OUT',
|
|
80
|
+
AUTH_FAILED = 'AUTH_FAILED',
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Cloud Objects
|
|
85
|
+
|
|
86
|
+
SDK will allow to use Retter Cloud Objects. Clients can subscribe realtime state changes, trigger cloud methods, ...
|
|
87
|
+
|
|
88
|
+
Firstly, a cloud object must be initilize with `classId`. Additional config options can be seen in interface below.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
const cloudObject = await rio.getCloudObject(config: RetterCloudObjectConfig)
|
|
92
|
+
|
|
93
|
+
interface RetterCloudObjectConfig {
|
|
94
|
+
classId: string
|
|
95
|
+
key?: {
|
|
96
|
+
name: string
|
|
97
|
+
value: string
|
|
98
|
+
}
|
|
99
|
+
instanceId?: string
|
|
100
|
+
method?: string
|
|
101
|
+
headers?: {
|
|
102
|
+
[key: string]: string
|
|
103
|
+
}
|
|
104
|
+
queryStringParams?: {
|
|
105
|
+
[key: string]: string
|
|
106
|
+
}
|
|
107
|
+
body?: {
|
|
108
|
+
[key: string]: any
|
|
109
|
+
}
|
|
110
|
+
httpMethod?: 'get' | 'delete' | 'post' | 'put'
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### State Subscription
|
|
115
|
+
|
|
116
|
+
Clients can be subscribe to realtime state (public, user and role states) changes. On first subscription, it gives current state.
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
cloudObject.state.public.subscribe((state: { [key: string]: any }) => {
|
|
120
|
+
//
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
cloudObject.state.user.subscribe((state: { [key: string]: any }) => {
|
|
124
|
+
//
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
cloudObject.state.role.subscribe((state: { [key: string]: any }) => {
|
|
128
|
+
//
|
|
129
|
+
})
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Method Calls
|
|
133
|
+
|
|
134
|
+
Any cloud method can be called via sdk. `method` parameter must be specified. Other parameters can be seen in interface below.
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
const response = await cloudObject.call(params: RetterCloudObjectCall)
|
|
138
|
+
|
|
139
|
+
interface RetterCloudObjectCall {
|
|
140
|
+
method: string
|
|
141
|
+
headers?: {
|
|
142
|
+
[key: string]: string
|
|
143
|
+
}
|
|
144
|
+
queryStringParams?: {
|
|
145
|
+
[key: string]: string
|
|
146
|
+
}
|
|
147
|
+
body?: {
|
|
148
|
+
[key: string]: any
|
|
149
|
+
}
|
|
150
|
+
httpMethod?: 'get' | 'delete' | 'post' | 'put'
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Call method will return a response with `RetterCallResponse` type includes `data`, `status` and `headers`.
|
|
155
|
+
|
|
156
|
+
### Getting State
|
|
157
|
+
|
|
158
|
+
Clients also access state via method call.
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
const response = await cloudObject.getState(params: RetterCloudObjectRequest)
|
|
162
|
+
|
|
163
|
+
interface RetterCloudObjectRequest {
|
|
164
|
+
headers?: {
|
|
165
|
+
[key: string]: string
|
|
166
|
+
}
|
|
167
|
+
queryStringParams?: {
|
|
168
|
+
[key: string]: string
|
|
169
|
+
}
|
|
170
|
+
body?: {
|
|
171
|
+
[key: string]: any
|
|
172
|
+
}
|
|
173
|
+
httpMethod?: 'get' | 'delete' | 'post' | 'put'
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Get stae method will return a response with `RetterCallResponse` type includes `data<RetterCloudObjectState>`, `status` and `headers`.
|
|
178
|
+
|
|
179
|
+
### Available Methods
|
|
180
|
+
|
|
181
|
+
Cloud objects available methods can be accessed on `methods` array/
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
const methods = cloudObject.methods: RetterCloudObjectMethod[]
|
|
185
|
+
|
|
186
|
+
interface RetterCloudObjectMethod {
|
|
187
|
+
tag?: string
|
|
188
|
+
name: string
|
|
189
|
+
sync?: boolean
|
|
190
|
+
readonly?: boolean
|
|
191
|
+
inputModel?: string
|
|
192
|
+
outputModel?: string
|
|
193
|
+
}
|
|
194
|
+
```
|