@based/client 2.5.0 → 2.6.1
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 +305 -34
- package/dist/Client.d.ts +14 -2
- package/dist/Client.js +49 -20
- package/dist/Client.js.map +1 -1
- package/dist/Emitter.d.ts +0 -0
- package/dist/Emitter.js +0 -0
- package/dist/Emitter.js.map +0 -0
- package/dist/auth.d.ts +10 -0
- package/dist/auth.js +75 -0
- package/dist/auth.js.map +1 -0
- package/dist/createError.d.ts +2 -4
- package/dist/createError.js +2 -1
- package/dist/createError.js.map +1 -1
- package/dist/file/fetch.d.ts +0 -0
- package/dist/file/fetch.js +0 -0
- package/dist/file/fetch.js.map +0 -0
- package/dist/file/getUrl.d.ts +0 -0
- package/dist/file/getUrl.js +0 -0
- package/dist/file/getUrl.js.map +0 -0
- package/dist/file/index.d.ts +0 -0
- package/dist/file/index.js +0 -0
- package/dist/file/index.js.map +0 -0
- package/dist/file/stream/browser.d.ts +0 -0
- package/dist/file/stream/browser.js +0 -0
- package/dist/file/stream/browser.js.map +0 -0
- package/dist/file/stream/index.d.ts +0 -0
- package/dist/file/stream/index.js +0 -0
- package/dist/file/stream/index.js.map +0 -0
- package/dist/file/uploadFileBrowser.d.ts +0 -0
- package/dist/file/uploadFileBrowser.js +0 -0
- package/dist/file/uploadFileBrowser.js.map +0 -0
- package/dist/findPrefix.d.ts +0 -0
- package/dist/findPrefix.js +0 -0
- package/dist/findPrefix.js.map +0 -0
- package/dist/idleTimeout.d.ts +0 -0
- package/dist/idleTimeout.js +0 -0
- package/dist/idleTimeout.js.map +0 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/observable/index.d.ts +0 -0
- package/dist/observable/index.js +0 -0
- package/dist/observable/index.js.map +0 -0
- package/dist/printBasedObject.d.ts +0 -0
- package/dist/printBasedObject.js +0 -0
- package/dist/printBasedObject.js.map +0 -0
- package/dist/queue.d.ts +2 -2
- package/dist/queue.js +2 -1
- package/dist/queue.js.map +1 -1
- package/dist/request.d.ts +1 -1
- package/dist/request.js +21 -1
- package/dist/request.js.map +1 -1
- package/dist/selvaTypes/get.d.ts +0 -0
- package/dist/selvaTypes/get.js +0 -0
- package/dist/selvaTypes/get.js.map +0 -0
- package/dist/selvaTypes/schema.d.ts +0 -0
- package/dist/selvaTypes/schema.js +0 -0
- package/dist/selvaTypes/schema.js.map +0 -0
- package/dist/selvaTypes/set.d.ts +0 -0
- package/dist/selvaTypes/set.js +0 -0
- package/dist/selvaTypes/set.js.map +0 -0
- package/dist/subscriptions/addGetSubscriber.d.ts +0 -0
- package/dist/subscriptions/addGetSubscriber.js +0 -0
- package/dist/subscriptions/addGetSubscriber.js.map +0 -0
- package/dist/subscriptions/addSubscriber.d.ts +0 -0
- package/dist/subscriptions/addSubscriber.js +0 -0
- package/dist/subscriptions/addSubscriber.js.map +0 -0
- package/dist/subscriptions/generateId.d.ts +0 -0
- package/dist/subscriptions/generateId.js +0 -0
- package/dist/subscriptions/generateId.js.map +0 -0
- package/dist/subscriptions/incomingSubscription.d.ts +0 -0
- package/dist/subscriptions/incomingSubscription.js +0 -0
- package/dist/subscriptions/incomingSubscription.js.map +0 -0
- package/dist/subscriptions/incomingSubscriptionDiff.d.ts +0 -0
- package/dist/subscriptions/incomingSubscriptionDiff.js +0 -0
- package/dist/subscriptions/incomingSubscriptionDiff.js.map +0 -0
- package/dist/subscriptions/index.d.ts +0 -0
- package/dist/subscriptions/index.js +0 -0
- package/dist/subscriptions/index.js.map +0 -0
- package/dist/subscriptions/logoutSubscriptions.d.ts +0 -0
- package/dist/subscriptions/logoutSubscriptions.js +0 -0
- package/dist/subscriptions/logoutSubscriptions.js.map +0 -0
- package/dist/subscriptions/removeSendSubscriptionDataFromQueue.d.ts +0 -0
- package/dist/subscriptions/removeSendSubscriptionDataFromQueue.js +0 -0
- package/dist/subscriptions/removeSendSubscriptionDataFromQueue.js.map +0 -0
- package/dist/subscriptions/removeSubscriber.d.ts +0 -0
- package/dist/subscriptions/removeSubscriber.js +0 -0
- package/dist/subscriptions/removeSubscriber.js.map +0 -0
- package/dist/subscriptions/removeUnsubscribesFromQueue.d.ts +0 -0
- package/dist/subscriptions/removeUnsubscribesFromQueue.js +0 -0
- package/dist/subscriptions/removeUnsubscribesFromQueue.js.map +0 -0
- package/dist/subscriptions/sendAllSubscriptions.d.ts +0 -0
- package/dist/subscriptions/sendAllSubscriptions.js +0 -0
- package/dist/subscriptions/sendAllSubscriptions.js.map +0 -0
- package/dist/token.d.ts +0 -0
- package/dist/token.js +0 -0
- package/dist/token.js.map +0 -0
- package/dist/track.d.ts +0 -0
- package/dist/track.js +0 -0
- package/dist/track.js.map +0 -0
- package/dist/types.d.ts +253 -0
- package/dist/types.js +58 -0
- package/dist/types.js.map +1 -0
- package/dist/websocket/index.d.ts +0 -0
- package/dist/websocket/index.js +0 -0
- package/dist/websocket/index.js.map +0 -0
- package/dist/websocket/types.d.ts +0 -0
- package/dist/websocket/types.js +0 -0
- package/dist/websocket/types.js.map +0 -0
- package/dist/websocket/urlLoader.d.ts +0 -0
- package/dist/websocket/urlLoader.js +0 -0
- package/dist/websocket/urlLoader.js.map +0 -0
- package/docs/authorize.md +56 -0
- package/docs/files.md +66 -0
- package/docs/get-started.md +60 -0
- package/docs/get.md +759 -0
- package/docs/schema.md +218 -0
- package/docs/set.md +508 -0
- package/package.json +9 -7
package/README.md
CHANGED
|
@@ -1,79 +1,350 @@
|
|
|
1
1
|
# @based/client
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
### Index
|
|
4
|
+
|
|
5
|
+
- [Modify data](#modify-data)
|
|
6
|
+
- [Observe data](#observe-data)
|
|
7
|
+
- [Upload files](#upload-files)
|
|
8
|
+
- [Schema](#schema)
|
|
9
|
+
- [Analytics](#analytics)
|
|
5
10
|
|
|
6
11
|
---
|
|
7
12
|
|
|
8
|
-
|
|
13
|
+
This package allows to interact with a Based environment, set and observe data, upload files, track and see analytics, and authenticate users.
|
|
9
14
|
|
|
10
|
-
|
|
15
|
+
This page provides a quick first look at the main methods this package offers. Detailed information about each method is linked in the appropriate paragraph.
|
|
11
16
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
###### Example:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import based from '@based/client'
|
|
21
|
+
|
|
22
|
+
const client = based({
|
|
23
|
+
org: 'my-org',
|
|
24
|
+
project: 'someproject',
|
|
25
|
+
env: 'production',
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
// create a schema
|
|
29
|
+
await client.updateSchema({
|
|
30
|
+
schema: {
|
|
31
|
+
types: {
|
|
32
|
+
thing: {
|
|
33
|
+
fields: {
|
|
34
|
+
name: { type: 'string' },
|
|
35
|
+
quantity: { type: 'number' },
|
|
36
|
+
reason: { type: 'string' },
|
|
37
|
+
otherThings: { type: 'references' },
|
|
38
|
+
favouriteThing: { type: 'reference' },
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
})
|
|
17
44
|
|
|
18
|
-
|
|
45
|
+
// observe some data
|
|
46
|
+
await client.observe(
|
|
47
|
+
{ $id: 'root', children: { $all: true, $list: true } },
|
|
48
|
+
(data) => {
|
|
49
|
+
console.log(data)
|
|
50
|
+
}
|
|
51
|
+
)
|
|
19
52
|
|
|
53
|
+
// set data
|
|
54
|
+
await client.set({
|
|
55
|
+
type: 'thing',
|
|
56
|
+
name: 'book',
|
|
57
|
+
quantity: 3,
|
|
20
58
|
})
|
|
21
59
|
```
|
|
22
60
|
|
|
23
|
-
##
|
|
61
|
+
## Modify data
|
|
62
|
+
|
|
63
|
+
> Read more about `set` and its operators [here](docs/set.md)
|
|
24
64
|
|
|
65
|
+
### `set`
|
|
66
|
+
|
|
67
|
+
The `based.set()` method allows to create new nodes or modify data on existing nodes. To change an existing one, one can do the following:
|
|
68
|
+
|
|
69
|
+
###### Example:
|
|
70
|
+
|
|
71
|
+
<!-- prettier-ignore-start -->
|
|
72
|
+
```js
|
|
73
|
+
/*
|
|
74
|
+
Let's assume the following node in database:
|
|
75
|
+
{
|
|
76
|
+
id: 'maASxsd3',
|
|
77
|
+
type: 'match',
|
|
78
|
+
value: 10,
|
|
79
|
+
title: {
|
|
80
|
+
en: 'yes'
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
const result = await client.set({ // Value of result: maASxsd3
|
|
86
|
+
$id: 'maASxsd3', // Resulting node in database:
|
|
87
|
+
type: 'match', // { id: 'maASxsd3',
|
|
88
|
+
title: { // type: 'match',
|
|
89
|
+
en: 'hello', // value: 10, // existing value remains
|
|
90
|
+
de: 'hallo', // title: {
|
|
91
|
+
}, // en: 'hello', // .en is overwritten
|
|
92
|
+
name: 'match', // de: 'hallo' // .de is added
|
|
93
|
+
// },
|
|
94
|
+
// name: 'match' // name is added
|
|
95
|
+
})
|
|
25
96
|
```
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
97
|
+
<!-- prettier-ignore-end -->
|
|
98
|
+
|
|
99
|
+
Omitting the `$id` field would **create a new node instead**.
|
|
100
|
+
|
|
101
|
+
> :exclamation: **All set operations must still respect the schema, otherwise the set won't take effect.**
|
|
102
|
+
|
|
103
|
+
### `delete`
|
|
104
|
+
|
|
105
|
+
A node can be removed using `client.delete()`, by passing an object with a property named `$id` containing the node's ID.
|
|
106
|
+
|
|
107
|
+
###### Example:
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
await client.delete({
|
|
111
|
+
$id: 'maASxsd3',
|
|
29
112
|
})
|
|
30
113
|
```
|
|
31
114
|
|
|
32
|
-
##
|
|
115
|
+
## Observe data
|
|
116
|
+
|
|
117
|
+
> Read more about `observe` and the query language [here](docs/get.md)
|
|
118
|
+
|
|
119
|
+
Based is built from the ground up with realtime updates in mind. This is why the best way to retrieve data for the database is to _observe_ it. This allows to pass an `onData` function that will get called any time the data that the query points to changes.
|
|
120
|
+
|
|
121
|
+
> ❗ Warning: The `data` object that gets passed to the onData function should **NOT** be modified in place since, due to performance reasons, the object gets reused between calls.
|
|
122
|
+
|
|
123
|
+
Using this same method, it is also possible to observe a data function.
|
|
33
124
|
|
|
125
|
+
This method returns a `close` function that must be called in order to allow the subscription to close gracefully.
|
|
126
|
+
|
|
127
|
+
###### Example:
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
// This query observes all nodes of type `thing` and counts how many times any of them
|
|
131
|
+
// changes, is removed, or is added, while also logging all the entries every time.
|
|
132
|
+
let receivedCnt = 0
|
|
133
|
+
|
|
134
|
+
const close = await client.observe(
|
|
135
|
+
{
|
|
136
|
+
things: {
|
|
137
|
+
name: true,
|
|
138
|
+
id: true,
|
|
139
|
+
nested: true,
|
|
140
|
+
$list: {
|
|
141
|
+
$find: {
|
|
142
|
+
$traverse: 'children',
|
|
143
|
+
$filter: {
|
|
144
|
+
$operator: '=',
|
|
145
|
+
$value: 'thing',
|
|
146
|
+
$field: 'type',
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
(data) => {
|
|
153
|
+
console.log(data)
|
|
154
|
+
receivedCnt++
|
|
155
|
+
}
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
// when done ...
|
|
159
|
+
close()
|
|
34
160
|
```
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
161
|
+
|
|
162
|
+
**To observe a data function instead**, one can simply replace the query with the name of the function:
|
|
163
|
+
|
|
164
|
+
###### Example:
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
let receivedCnt = 0
|
|
168
|
+
|
|
169
|
+
const close = await client.observe('observeAllThings', (data) => {
|
|
170
|
+
console.log(data)
|
|
171
|
+
receivedCnt++
|
|
38
172
|
})
|
|
173
|
+
|
|
174
|
+
// when done ...
|
|
175
|
+
close()
|
|
39
176
|
```
|
|
40
177
|
|
|
41
|
-
|
|
178
|
+
#### `get`
|
|
179
|
+
|
|
180
|
+
It's also possible to simply get the data once, instead of observing it, using the `based.get()` method, which accepts a query or data function name as argument.
|
|
42
181
|
|
|
182
|
+
###### Example:
|
|
183
|
+
|
|
184
|
+
```js
|
|
185
|
+
// Gets every child of `root`
|
|
186
|
+
const data = await client.get({
|
|
187
|
+
$id: 'root',
|
|
188
|
+
children: { $all: true, $list: true },
|
|
189
|
+
})
|
|
43
190
|
```
|
|
44
|
-
|
|
45
|
-
|
|
191
|
+
|
|
192
|
+
## Upload files
|
|
193
|
+
|
|
194
|
+
> Details [here](docs/files.md)
|
|
195
|
+
|
|
196
|
+
Based provides a way to upload and serve user content without hassle using the `client.file()` API.
|
|
197
|
+
|
|
198
|
+
This sets a new node of type `file` in the database, which contains all its relevant information
|
|
199
|
+
|
|
200
|
+
###### Example:
|
|
201
|
+
|
|
202
|
+
```js
|
|
203
|
+
const fileId = await client.file({
|
|
204
|
+
contents: 'This is a string I want to store as plain text!',
|
|
205
|
+
mimeType: 'text/plain',
|
|
206
|
+
name: 'my-file-name',
|
|
46
207
|
})
|
|
47
208
|
```
|
|
48
209
|
|
|
49
|
-
|
|
210
|
+
Also supports browser file objects
|
|
211
|
+
|
|
212
|
+
```jsx
|
|
213
|
+
<input
|
|
214
|
+
type="file"
|
|
215
|
+
onChange={async (e) => {
|
|
216
|
+
const id = await client.file(e.target.files[0])
|
|
217
|
+
// const id = await client.file({ contents: e.target.files[0], name: 'custom name' });
|
|
218
|
+
}}
|
|
219
|
+
/>
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Or streams in node
|
|
223
|
+
|
|
224
|
+
```js
|
|
225
|
+
import fs from 'fs'
|
|
50
226
|
|
|
227
|
+
const id = await client.file(fs.createReadStream(aFile))
|
|
51
228
|
```
|
|
52
|
-
|
|
53
|
-
|
|
229
|
+
|
|
230
|
+
###### Retrieve the file node:
|
|
231
|
+
|
|
232
|
+
```js
|
|
233
|
+
const data = await client.get({
|
|
234
|
+
$id: fileId,
|
|
235
|
+
$all: true,
|
|
54
236
|
})
|
|
237
|
+
/*
|
|
238
|
+
data = {
|
|
239
|
+
id: "fi6a535226",
|
|
240
|
+
name: "eb3f67a3bc65325bf739ebddd94403e5",
|
|
241
|
+
mimeType: "text/plain",
|
|
242
|
+
version: "eb3f67a3bc65325bf739ebddd94403e5",
|
|
243
|
+
origin: "https://based-env-files-do-usproduction-enb-xz-apz--orn-t-v-...98446afcb87d",
|
|
244
|
+
src: "https://based-2129034536588.imgix.net/fi6a535226/84e62df3-75...98446afcb87d",
|
|
245
|
+
progress: 1,
|
|
246
|
+
size: 31,
|
|
247
|
+
type: "file",
|
|
248
|
+
createdAt: 1650360875043,
|
|
249
|
+
updatedAt: 1650360882865,
|
|
250
|
+
}
|
|
251
|
+
*/
|
|
55
252
|
```
|
|
56
253
|
|
|
57
|
-
##
|
|
254
|
+
## Schema
|
|
255
|
+
|
|
256
|
+
> Read more about schemas [here](docs/schema.md)
|
|
257
|
+
|
|
258
|
+
The schema describes what types of nodes can exist on the database. Each `type` can have several named `fields`, each with its own data type (i.e. `string`, `number`, `object`, and so on). Based on the data type, Based will validate the value passed.
|
|
259
|
+
|
|
260
|
+
One of the first things a Based user will have to do is set a schema for its database. This is done using the `client.updateSchema()` method.
|
|
58
261
|
|
|
262
|
+
###### Example:
|
|
263
|
+
|
|
264
|
+
```js
|
|
265
|
+
await client.updateSchema({
|
|
266
|
+
types: {
|
|
267
|
+
thing: {
|
|
268
|
+
fields: {
|
|
269
|
+
name: { type: 'string' },
|
|
270
|
+
nested: {
|
|
271
|
+
type: 'object',
|
|
272
|
+
properties: {
|
|
273
|
+
something: { type: 'string' },
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
})
|
|
59
280
|
```
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
281
|
+
|
|
282
|
+
## Analytics
|
|
283
|
+
|
|
284
|
+
Based is capable of tracking a client in realtime using the included `client.track()` method (and `client.untrack()`).
|
|
285
|
+
This method allows to track any user defined event, attaching a payload to it. The client stops being tracked when `client.untrack()` is called, or when the connection is closed.
|
|
286
|
+
|
|
287
|
+
###### Example:
|
|
288
|
+
|
|
289
|
+
<!-- prettier-ignore-start -->
|
|
290
|
+
```js
|
|
291
|
+
client.track('view', {
|
|
292
|
+
edition: '2022',
|
|
293
|
+
language: 'en',
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
// when the event is no longer happening (e.g. the user moves to a different view)...
|
|
297
|
+
client.untrack('view', {
|
|
298
|
+
edition: '2022', // The payload needs to be specified again, since it defines a unique event type
|
|
299
|
+
language: 'en',
|
|
63
300
|
})
|
|
64
301
|
```
|
|
302
|
+
<!-- prettier-ignore-end -->
|
|
65
303
|
|
|
66
|
-
|
|
304
|
+
To then retrieve the analytics data, Based provides the `client.analytics()` method, which takes as argument an object containg the event type and its payload.
|
|
305
|
+
This method can also take a `onData` function as a second argument, which turns it into an observer.
|
|
67
306
|
|
|
307
|
+
###### Example:
|
|
308
|
+
|
|
309
|
+
<!-- prettier-ignore-start -->
|
|
310
|
+
```js
|
|
311
|
+
const data = await client.analytics({ type: 'view' })
|
|
312
|
+
console.log(data) // prints an object { all, unique, active }
|
|
313
|
+
// `all` represents the total count of how many times the event was fired overall
|
|
314
|
+
// `unique` represents the total count of unique users that fired the event
|
|
315
|
+
// `active` are the users that are active right now (real time visitors)
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
// it's also possible to observe the analytics by passing an onData function to it
|
|
319
|
+
const close = await client.analytics(
|
|
320
|
+
{ type: 'view' },
|
|
321
|
+
(analyticsInfo) => console.log(analyticsInfo)
|
|
322
|
+
)
|
|
68
323
|
```
|
|
69
|
-
|
|
70
|
-
await b.auth(token)
|
|
324
|
+
<!-- prettier-ignore-end -->
|
|
71
325
|
|
|
72
|
-
|
|
73
|
-
} catch (e) {
|
|
326
|
+
### `$geo` and `$history`
|
|
74
327
|
|
|
75
|
-
|
|
328
|
+
Based analytics can provide more specific data by using the `$geo` and `$history` operators, which give information about the location of the user and the historical values of the event tracked, respectively.
|
|
329
|
+
|
|
330
|
+
###### Example:
|
|
331
|
+
|
|
332
|
+
<!-- prettier-ignore-start -->
|
|
333
|
+
```js
|
|
334
|
+
const data = await client.analytics({ type: 'view', $geo: true, $history: 30 })
|
|
335
|
+
console.log(data) // prints an object containing all the information as the normal
|
|
336
|
+
// client.analytics call, but with a geo property containig ISO value counts,
|
|
337
|
+
// and with the total counts turned into an array of max 30 tuples,
|
|
338
|
+
// with the first item in the tuple being a timestamp and the second one being the value at the time
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
// it's also possible to observe the analytics by passing an onData function to it
|
|
342
|
+
const close = await client.analytics(
|
|
343
|
+
{ type: 'view' },
|
|
344
|
+
(analyticsInfo) => console.log(analyticsInfo)
|
|
345
|
+
)
|
|
76
346
|
```
|
|
347
|
+
<!-- prettier-ignore-end -->
|
|
77
348
|
|
|
78
349
|
---
|
|
79
350
|
|
package/dist/Client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Connection } from './websocket/types';
|
|
2
|
-
import { GenericObject, RequestMessage, SubscriptionMessage, FunctionCallMessage, Configuration, TrackMessage, SendTokenOptions } from '@based/types';
|
|
2
|
+
import { RequestTypes, GenericObject, RequestMessage, SubscriptionMessage, FunctionCallMessage, Configuration, TrackMessage, SendTokenOptions, AuthMessage } from '@based/types';
|
|
3
3
|
import { Based } from './';
|
|
4
4
|
export * from '@based/types';
|
|
5
5
|
export declare class BasedClient {
|
|
@@ -7,7 +7,9 @@ export declare class BasedClient {
|
|
|
7
7
|
constructor(based: Based);
|
|
8
8
|
token: string;
|
|
9
9
|
sendTokenOptions: SendTokenOptions;
|
|
10
|
+
retryingRenewToken: boolean;
|
|
10
11
|
beingAuth: boolean;
|
|
12
|
+
isLogginIn: boolean;
|
|
11
13
|
auth: ((x?: any) => void)[];
|
|
12
14
|
subscriptions: {
|
|
13
15
|
[subscriptionId: string]: {
|
|
@@ -34,6 +36,16 @@ export declare class BasedClient {
|
|
|
34
36
|
};
|
|
35
37
|
};
|
|
36
38
|
requestCallbacks: {
|
|
39
|
+
[reqId: string]: {
|
|
40
|
+
resolve: (val?: any) => void;
|
|
41
|
+
reject: (err: Error) => void;
|
|
42
|
+
type?: Exclude<RequestTypes, RequestTypes.Subscription | RequestTypes.SubscriptionDiff | RequestTypes.SendSubscriptionData | RequestTypes.Unsubscribe | RequestTypes.GetSubscription | RequestTypes.Token | RequestTypes.Track>;
|
|
43
|
+
payload?: any;
|
|
44
|
+
name?: string;
|
|
45
|
+
isRetry?: boolean;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
authCallbacks: {
|
|
37
49
|
[reqId: string]: {
|
|
38
50
|
resolve: (val?: any) => void;
|
|
39
51
|
reject: (err: Error) => void;
|
|
@@ -44,7 +56,7 @@ export declare class BasedClient {
|
|
|
44
56
|
connected: boolean;
|
|
45
57
|
connection: Connection;
|
|
46
58
|
subscriptionQueue: SubscriptionMessage[];
|
|
47
|
-
queue: (RequestMessage | FunctionCallMessage | TrackMessage)[];
|
|
59
|
+
queue: (RequestMessage | FunctionCallMessage | TrackMessage | AuthMessage)[];
|
|
48
60
|
drainInProgress: boolean;
|
|
49
61
|
drainTimeout: ReturnType<typeof setTimeout>;
|
|
50
62
|
idlePing: ReturnType<typeof setTimeout>;
|
package/dist/Client.js
CHANGED
|
@@ -23,6 +23,8 @@ const subscriptions_1 = require("./subscriptions");
|
|
|
23
23
|
const queue_1 = require("./queue");
|
|
24
24
|
const request_1 = require("./request");
|
|
25
25
|
const token_1 = __importDefault(require("./token"));
|
|
26
|
+
const auth_1 = require("./auth");
|
|
27
|
+
const auth_2 = require("./auth");
|
|
26
28
|
__exportStar(require("@based/types"), exports);
|
|
27
29
|
class BasedClient {
|
|
28
30
|
constructor(based) {
|
|
@@ -30,6 +32,7 @@ class BasedClient {
|
|
|
30
32
|
this.subscriptions = {};
|
|
31
33
|
this.cache = {};
|
|
32
34
|
this.requestCallbacks = {};
|
|
35
|
+
this.authCallbacks = {};
|
|
33
36
|
this.connected = false;
|
|
34
37
|
this.subscriptionQueue = [];
|
|
35
38
|
// and more
|
|
@@ -71,35 +74,60 @@ class BasedClient {
|
|
|
71
74
|
onData(d) {
|
|
72
75
|
try {
|
|
73
76
|
const data = JSON.parse(d.data);
|
|
74
|
-
|
|
77
|
+
const [type, reqId, payload, err] = data;
|
|
78
|
+
if (type === types_1.RequestTypes.Token) {
|
|
79
|
+
this.retryingRenewToken = false;
|
|
75
80
|
// means stomething got de-auth wrong
|
|
76
|
-
if (
|
|
81
|
+
if (reqId.length) {
|
|
77
82
|
(0, subscriptions_1.logoutSubscriptions)(this, data);
|
|
78
83
|
}
|
|
79
|
-
// console.info(data, data[2])
|
|
80
84
|
for (const fn of this.auth) {
|
|
81
|
-
fn(!
|
|
85
|
+
fn(!payload);
|
|
82
86
|
}
|
|
83
87
|
this.beingAuth = false;
|
|
84
88
|
this.auth = [];
|
|
85
89
|
}
|
|
86
|
-
else if (
|
|
87
|
-
|
|
88
|
-
data[0] === types_1.RequestTypes.Configuration ||
|
|
89
|
-
data[0] === types_1.RequestTypes.GetConfiguration ||
|
|
90
|
-
data[0] === types_1.RequestTypes.Call ||
|
|
91
|
-
data[0] === types_1.RequestTypes.Delete ||
|
|
92
|
-
data[0] === types_1.RequestTypes.Copy ||
|
|
93
|
-
data[0] === types_1.RequestTypes.Digest ||
|
|
94
|
-
data[0] === types_1.RequestTypes.RemoveType ||
|
|
95
|
-
data[0] === types_1.RequestTypes.RemoveField) {
|
|
96
|
-
(0, request_1.incomingRequest)(this, data);
|
|
90
|
+
else if (type === types_1.RequestTypes.Auth) {
|
|
91
|
+
(0, auth_1.incomingAuthRequest)(this, data);
|
|
97
92
|
}
|
|
98
|
-
else
|
|
99
|
-
(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
93
|
+
else {
|
|
94
|
+
if (err?.code === types_1.BasedErrorCodes.TokenExpired &&
|
|
95
|
+
!this.retryingRenewToken) {
|
|
96
|
+
this.retryingRenewToken = true;
|
|
97
|
+
const refreshToken = this.sendTokenOptions?.refreshToken;
|
|
98
|
+
(0, auth_2.renewToken)(this, {
|
|
99
|
+
refreshToken,
|
|
100
|
+
})
|
|
101
|
+
.then((result) => {
|
|
102
|
+
(0, token_1.default)(this, result.token, this.sendTokenOptions);
|
|
103
|
+
(0, request_1.addRequest)(this,
|
|
104
|
+
// @ts-ignore
|
|
105
|
+
type, err?.payload, this.requestCallbacks[reqId].resolve, this.requestCallbacks[reqId].reject);
|
|
106
|
+
})
|
|
107
|
+
.catch((err) => {
|
|
108
|
+
this.requestCallbacks[reqId].reject(err);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
if (type === types_1.RequestTypes.Set ||
|
|
113
|
+
type === types_1.RequestTypes.Get ||
|
|
114
|
+
type === types_1.RequestTypes.Configuration ||
|
|
115
|
+
type === types_1.RequestTypes.GetConfiguration ||
|
|
116
|
+
type === types_1.RequestTypes.Call ||
|
|
117
|
+
type === types_1.RequestTypes.Delete ||
|
|
118
|
+
type === types_1.RequestTypes.Copy ||
|
|
119
|
+
type === types_1.RequestTypes.Digest ||
|
|
120
|
+
type === types_1.RequestTypes.RemoveType ||
|
|
121
|
+
type === types_1.RequestTypes.RemoveField) {
|
|
122
|
+
(0, request_1.incomingRequest)(this, data);
|
|
123
|
+
}
|
|
124
|
+
else if (type === types_1.RequestTypes.Subscription) {
|
|
125
|
+
(0, subscriptions_1.incomingSubscription)(this, data);
|
|
126
|
+
}
|
|
127
|
+
else if (type === types_1.RequestTypes.SubscriptionDiff) {
|
|
128
|
+
(0, subscriptions_1.incomingSubscriptionDiff)(this, data);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
103
131
|
}
|
|
104
132
|
}
|
|
105
133
|
catch (err) {
|
|
@@ -108,4 +136,5 @@ class BasedClient {
|
|
|
108
136
|
}
|
|
109
137
|
}
|
|
110
138
|
exports.BasedClient = BasedClient;
|
|
139
|
+
console.log('???');
|
|
111
140
|
//# sourceMappingURL=Client.js.map
|
package/dist/Client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../src/Client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../src/Client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,wCAcqB;AACrB,mDAOwB;AAExB,mCAAgE;AAChE,uCAAuD;AACvD,oDAA+B;AAC/B,iCAA4C;AAC5C,iCAAmC;AAEnC,+CAA4B;AAE5B,MAAa,WAAW;IAGtB,YAAY,KAAY;QAaxB,SAAI,GAA0B,EAAE,CAAA;QAEhC,kBAAa,GAuBT,EAAE,CAAA;QAEN,UAAK,GAKD,EAAE,CAAA;QAEN,qBAAgB,GAoBZ,EAAE,CAAA;QAEN,kBAAa,GAMT,EAAE,CAAA;QAMN,cAAS,GAAY,KAAK,CAAA;QAI1B,sBAAiB,GAA0B,EAAE,CAAA;QAE7C,WAAW;QACX,UAAK,GACH,EAAE,CAAA;QAEJ,oBAAe,GAAY,KAAK,CAAA;QA1F9B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IA+FD,OAAO;QACL,IAAI,CAAC,SAAS,GAAG,KAAK,CAAA;QACtB,IAAA,sBAAc,EAAC,IAAI,CAAC,CAAA;QACpB,IAAA,2CAA2B,EAAC,IAAI,CAAC,CAAA;QACjC,IAAA,kDAAkC,EAAC,IAAI,CAAC,CAAA;QACxC,qCAAqC;QACrC,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,EAAE;YACnC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAA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AAM;oBACL,IACE,IAAI,KAAK,oBAAY,CAAC,GAAG;wBACzB,IAAI,KAAK,oBAAY,CAAC,GAAG;wBACzB,IAAI,KAAK,oBAAY,CAAC,aAAa;wBACnC,IAAI,KAAK,oBAAY,CAAC,gBAAgB;wBACtC,IAAI,KAAK,oBAAY,CAAC,IAAI;wBAC1B,IAAI,KAAK,oBAAY,CAAC,MAAM;wBAC5B,IAAI,KAAK,oBAAY,CAAC,IAAI;wBAC1B,IAAI,KAAK,oBAAY,CAAC,MAAM;wBAC5B,IAAI,KAAK,oBAAY,CAAC,UAAU;wBAChC,IAAI,KAAK,oBAAY,CAAC,WAAW,EACjC;wBACA,IAAA,yBAAe,EAAC,IAAI,EAAE,IAAI,CAAC,CAAA;qBAC5B;yBAAM,IAAI,IAAI,KAAK,oBAAY,CAAC,YAAY,EAAE;wBAC7C,IAAA,oCAAoB,EAAC,IAAI,EAAE,IAAI,CAAC,CAAA;qBACjC;yBAAM,IAAI,IAAI,KAAK,oBAAY,CAAC,gBAAgB,EAAE;wBACjD,IAAA,wCAAwB,EAAC,IAAI,EAAE,IAAI,CAAC,CAAA;qBACrC;iBACF;aACF;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,CAAC,CAAC,CAAA;SAC7C;IACH,CAAC;CACF;AAzMD,kCAyMC;AAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA"}
|
package/dist/Emitter.d.ts
CHANGED
|
File without changes
|
package/dist/Emitter.js
CHANGED
|
File without changes
|
package/dist/Emitter.js.map
CHANGED
|
File without changes
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BasedClient } from '.';
|
|
2
|
+
import { AuthData, GenericObject, LoginOpts, RenewTokenOpts } from '@based/types';
|
|
3
|
+
export declare const login: (client: BasedClient, opts: LoginOpts) => Promise<{
|
|
4
|
+
token: string;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const renewToken: (client: BasedClient, opts: RenewTokenOpts) => Promise<{
|
|
7
|
+
token: string;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const incomingAuthRequest: (client: BasedClient, data: AuthData) => void;
|
|
10
|
+
export declare const logout: (client: BasedClient) => Promise<GenericObject>;
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.logout = exports.incomingAuthRequest = exports.renewToken = exports.login = void 0;
|
|
7
|
+
const queue_1 = require("./queue");
|
|
8
|
+
const types_1 = require("@based/types");
|
|
9
|
+
const createError_1 = __importDefault(require("./createError"));
|
|
10
|
+
const token_1 = __importDefault(require("./token"));
|
|
11
|
+
let loginCbId = 0;
|
|
12
|
+
const login = (client, opts) => {
|
|
13
|
+
const reqId = ++loginCbId;
|
|
14
|
+
(0, queue_1.addToQueue)(client, [types_1.RequestTypes.Auth, types_1.AuthRequestTypes.Login, reqId, opts]);
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
client.authCallbacks[reqId] = {
|
|
17
|
+
resolve: (response) => {
|
|
18
|
+
(0, token_1.default)(client, response.token, {
|
|
19
|
+
refreshToken: response.refreshToken,
|
|
20
|
+
});
|
|
21
|
+
resolve(response);
|
|
22
|
+
},
|
|
23
|
+
reject,
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
exports.login = login;
|
|
28
|
+
const renewToken = (client, opts) => {
|
|
29
|
+
const reqId = ++loginCbId;
|
|
30
|
+
(0, queue_1.addToQueue)(client, [
|
|
31
|
+
types_1.RequestTypes.Auth,
|
|
32
|
+
types_1.AuthRequestTypes.RenewToken,
|
|
33
|
+
reqId,
|
|
34
|
+
opts,
|
|
35
|
+
]);
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
client.authCallbacks[reqId] = {
|
|
38
|
+
resolve: (response) => {
|
|
39
|
+
(0, token_1.default)(client, response.token);
|
|
40
|
+
resolve(response);
|
|
41
|
+
},
|
|
42
|
+
reject,
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
exports.renewToken = renewToken;
|
|
47
|
+
const incomingAuthRequest = (client, data) => {
|
|
48
|
+
const [, reqId, payload, err] = data;
|
|
49
|
+
const cb = client.authCallbacks[reqId];
|
|
50
|
+
if (cb) {
|
|
51
|
+
delete client.authCallbacks[reqId];
|
|
52
|
+
if (err) {
|
|
53
|
+
cb.reject((0, createError_1.default)(err));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
cb.resolve(payload);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.incomingAuthRequest = incomingAuthRequest;
|
|
61
|
+
const logout = (client) => {
|
|
62
|
+
const reqId = ++loginCbId;
|
|
63
|
+
(0, queue_1.addToQueue)(client, [types_1.RequestTypes.Auth, types_1.AuthRequestTypes.Logout, reqId]);
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
client.authCallbacks[reqId] = {
|
|
66
|
+
resolve: (response) => {
|
|
67
|
+
(0, token_1.default)(client);
|
|
68
|
+
resolve(response);
|
|
69
|
+
},
|
|
70
|
+
reject,
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
exports.logout = logout;
|
|
75
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":";;;;;;AACA,mCAAoC;AACpC,wCAOqB;AACrB,gEAAuC;AACvC,oDAA+B;AAE/B,IAAI,SAAS,GAAG,CAAC,CAAA;AAEV,MAAM,KAAK,GAAG,CACnB,M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AAM,mBAAmB,GAAG,CAAC,MAAmB,EAAE,IAAc,EAAE,EAAE;IACzE,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;IACpC,MAAM,EAAE,GAAG,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;IACtC,IAAI,EAAE,EAAE;QACN,OAAO,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;QAClC,IAAI,GAAG,EAAE;YACP,EAAE,CAAC,MAAM,CAAC,IAAA,qBAAW,EAAC,GAAG,CAAC,CAAC,CAAA;SAC5B;aAAM;YACL,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;SACpB;KACF;AACH,CAAC,CAAA;AAXY,QAAA,mBAAmB,uBAW/B;AAEM,MAAM,MAAM,GAAG,CAAC,MAAmB,EAA0B,EAAE;IACpE,MAAM,KAAK,GAAG,EAAE,SAAS,CAAA;IACzB,IAAA,kBAAU,EAAC,MAAM,EAAE,CAAC,oBAAY,CAAC,IAAI,EAAE,wBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAA;IACvE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG;YAC5B,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE;gBACpB,IAAA,eAAS,EAAC,MAAM,CAAC,CAAA;gBACjB,OAAO,CAAC,QAAQ,CAAC,CAAA;YACnB,CAAC;YACD,MAAM;SACP,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAZY,QAAA,MAAM,UAYlB"}
|
package/dist/createError.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ErrorObject } from '@based/types';
|
|
2
|
-
declare const _default: (err: ErrorObject) =>
|
|
3
|
-
code?: string;
|
|
4
|
-
};
|
|
1
|
+
import { ErrorObject, BasedError } from '@based/types';
|
|
2
|
+
declare const _default: (err: ErrorObject) => BasedError;
|
|
5
3
|
export default _default;
|
package/dist/createError.js
CHANGED
|
@@ -23,9 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const types_1 = require("@based/types");
|
|
26
27
|
const printBasedObject_1 = __importStar(require("./printBasedObject"));
|
|
27
28
|
exports.default = (err) => {
|
|
28
|
-
const x = new
|
|
29
|
+
const x = new types_1.BasedError(err.message);
|
|
29
30
|
x.name = err.name ? `${err.type} from ${err.name}` : err.type;
|
|
30
31
|
x.stack = null;
|
|
31
32
|
if (err.query || err.payload) {
|