@retter/sdk 0.2.27 → 0.2.31

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 CHANGED
@@ -1,3 +1,179 @@
1
- ### Installation
1
+ ## Installation
2
2
 
3
- `npm install @retter/sdk`
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
+
21
+ ## Usage
22
+
23
+ ### Initialization
24
+
25
+ Clients should initialize with project id. Instances with same project id always be cached.
26
+
27
+ ```ts
28
+ const rio = Retter.getInstance({
29
+ projectId: '{PROJECT_ID}',
30
+ })
31
+ ```
32
+
33
+ **PROJECT_ID**: Unique id of a project created in [retter.io Console](https://retter.io)
34
+
35
+ ### Authentication
36
+
37
+ Retter uses custom token to authenticate. This custom tokens can be given by an action or a cloud object.
38
+
39
+ ```ts
40
+ await rio.authenticateWithCustomToken('{CUSTOM_TOKEN}')
41
+ ```
42
+
43
+ Authentication statuses can be listened. SDK will fire an event that clients can be subscribe on status change.
44
+
45
+ ```ts
46
+ rio.authStatus.subscribe((event: RetterAuthChangedEvent) => {
47
+ //
48
+ })
49
+ ```
50
+
51
+ Event gives information about current auth status. Clients can check the `authStatus` to determine if they need to show login/register pages or not.
52
+
53
+ ```ts
54
+ interface RetterAuthChangedEvent {
55
+ authStatus: RetterAuthStatus
56
+ identity?: string
57
+ uid?: string
58
+ message?: string
59
+ }
60
+
61
+ enum RetterAuthStatus {
62
+ SIGNED_IN = 'SIGNED_IN',
63
+ SIGNED_IN_ANONYM = 'SIGNED_IN_ANONYM',
64
+ SIGNED_OUT = 'SIGNED_OUT',
65
+ AUTH_FAILED = 'AUTH_FAILED',
66
+ }
67
+ ```
68
+
69
+ ## Cloud Objects
70
+
71
+ SDK will allow to use Retter Cloud Objects. Clients can subscribe realtime state changes, trigger cloud methods, ...
72
+
73
+ Firstly, a cloud object must be initilize with `classId`. Additional config options can be seen in interface below.
74
+
75
+ ```ts
76
+ const cloudObject = await rio.getCloudObject(config: RetterCloudObjectConfig)
77
+
78
+ interface RetterCloudObjectConfig {
79
+ classId: string
80
+ key?: {
81
+ name: string
82
+ value: string
83
+ }
84
+ instanceId?: string
85
+ method?: string
86
+ headers?: {
87
+ [key: string]: string
88
+ }
89
+ queryStringParams?: {
90
+ [key: string]: string
91
+ }
92
+ body?: {
93
+ [key: string]: any
94
+ }
95
+ httpMethod?: 'get' | 'delete' | 'post' | 'put'
96
+ }
97
+ ```
98
+
99
+ ### State Subscription
100
+
101
+ Clients can be subscribe to realtime state (public, user and role states) changes. On first subscription, it gives current state.
102
+
103
+ ```ts
104
+ cloudObject.state.public.subscribe((state: { [key: string]: any }) => {
105
+ //
106
+ })
107
+
108
+ cloudObject.state.user.subscribe((state: { [key: string]: any }) => {
109
+ //
110
+ })
111
+
112
+ cloudObject.state.role.subscribe((state: { [key: string]: any }) => {
113
+ //
114
+ })
115
+ ```
116
+
117
+ ### Method Calls
118
+
119
+ Any cloud method can be called via sdk. `method` parameter must be specified. Other parameters can be seen in interface below.
120
+
121
+ ```ts
122
+ const response = await cloudObject.call(params: RetterCloudObjectCall)
123
+
124
+ interface RetterCloudObjectCall {
125
+ method: string
126
+ headers?: {
127
+ [key: string]: string
128
+ }
129
+ queryStringParams?: {
130
+ [key: string]: string
131
+ }
132
+ body?: {
133
+ [key: string]: any
134
+ }
135
+ httpMethod?: 'get' | 'delete' | 'post' | 'put'
136
+ }
137
+ ```
138
+
139
+ Call method will return a response with `RetterCallResponse` type includes `data`, `status` and `headers`.
140
+
141
+ ### Getting State
142
+
143
+ Clients also access state via method call.
144
+
145
+ ```ts
146
+ const response = await cloudObject.getState(params: RetterCloudObjectRequest)
147
+
148
+ interface RetterCloudObjectRequest {
149
+ headers?: {
150
+ [key: string]: string
151
+ }
152
+ queryStringParams?: {
153
+ [key: string]: string
154
+ }
155
+ body?: {
156
+ [key: string]: any
157
+ }
158
+ httpMethod?: 'get' | 'delete' | 'post' | 'put'
159
+ }
160
+ ```
161
+
162
+ Get stae method will return a response with `RetterCallResponse` type includes `data<RetterCloudObjectState>`, `status` and `headers`.
163
+
164
+ ### Available Methods
165
+
166
+ Cloud objects available methods can be accessed on `methods` array/
167
+
168
+ ```ts
169
+ const methods = cloudObject.methods: RetterCloudObjectMethod[]
170
+
171
+ interface RetterCloudObjectMethod {
172
+ tag?: string
173
+ name: string
174
+ sync?: boolean
175
+ readonly?: boolean
176
+ inputModel?: string
177
+ outputModel?: string
178
+ }
179
+ ```