@based/client 2.5.1 → 2.6.0

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.
Files changed (119) hide show
  1. package/README.md +305 -34
  2. package/dist/Client.d.ts +14 -2
  3. package/dist/Client.js +48 -20
  4. package/dist/Client.js.map +1 -1
  5. package/dist/Emitter.d.ts +0 -0
  6. package/dist/Emitter.js +0 -0
  7. package/dist/Emitter.js.map +0 -0
  8. package/dist/auth.d.ts +10 -0
  9. package/dist/auth.js +75 -0
  10. package/dist/auth.js.map +1 -0
  11. package/dist/createError.d.ts +2 -4
  12. package/dist/createError.js +2 -1
  13. package/dist/createError.js.map +1 -1
  14. package/dist/file/fetch.d.ts +0 -0
  15. package/dist/file/fetch.js +0 -0
  16. package/dist/file/fetch.js.map +0 -0
  17. package/dist/file/getUrl.d.ts +0 -0
  18. package/dist/file/getUrl.js +0 -0
  19. package/dist/file/getUrl.js.map +0 -0
  20. package/dist/file/index.d.ts +0 -0
  21. package/dist/file/index.js +0 -0
  22. package/dist/file/index.js.map +0 -0
  23. package/dist/file/stream/browser.d.ts +0 -0
  24. package/dist/file/stream/browser.js +0 -0
  25. package/dist/file/stream/browser.js.map +0 -0
  26. package/dist/file/stream/index.d.ts +0 -0
  27. package/dist/file/stream/index.js +0 -0
  28. package/dist/file/stream/index.js.map +0 -0
  29. package/dist/file/uploadFileBrowser.d.ts +0 -0
  30. package/dist/file/uploadFileBrowser.js +0 -0
  31. package/dist/file/uploadFileBrowser.js.map +0 -0
  32. package/dist/findPrefix.d.ts +0 -0
  33. package/dist/findPrefix.js +0 -0
  34. package/dist/findPrefix.js.map +0 -0
  35. package/dist/idleTimeout.d.ts +0 -0
  36. package/dist/idleTimeout.js +0 -0
  37. package/dist/idleTimeout.js.map +0 -0
  38. package/dist/index.d.ts +3 -1
  39. package/dist/index.js +7 -7
  40. package/dist/index.js.map +1 -1
  41. package/dist/observable/index.d.ts +0 -0
  42. package/dist/observable/index.js +0 -0
  43. package/dist/observable/index.js.map +0 -0
  44. package/dist/printBasedObject.d.ts +0 -0
  45. package/dist/printBasedObject.js +0 -0
  46. package/dist/printBasedObject.js.map +0 -0
  47. package/dist/queue.d.ts +2 -2
  48. package/dist/queue.js +2 -1
  49. package/dist/queue.js.map +1 -1
  50. package/dist/request.d.ts +1 -1
  51. package/dist/request.js +21 -1
  52. package/dist/request.js.map +1 -1
  53. package/dist/selvaTypes/get.d.ts +0 -0
  54. package/dist/selvaTypes/get.js +0 -0
  55. package/dist/selvaTypes/get.js.map +0 -0
  56. package/dist/selvaTypes/schema.d.ts +0 -0
  57. package/dist/selvaTypes/schema.js +0 -0
  58. package/dist/selvaTypes/schema.js.map +0 -0
  59. package/dist/selvaTypes/set.d.ts +0 -0
  60. package/dist/selvaTypes/set.js +0 -0
  61. package/dist/selvaTypes/set.js.map +0 -0
  62. package/dist/subscriptions/addGetSubscriber.d.ts +0 -0
  63. package/dist/subscriptions/addGetSubscriber.js +0 -0
  64. package/dist/subscriptions/addGetSubscriber.js.map +0 -0
  65. package/dist/subscriptions/addSubscriber.d.ts +0 -0
  66. package/dist/subscriptions/addSubscriber.js +0 -0
  67. package/dist/subscriptions/addSubscriber.js.map +0 -0
  68. package/dist/subscriptions/generateId.d.ts +0 -0
  69. package/dist/subscriptions/generateId.js +0 -0
  70. package/dist/subscriptions/generateId.js.map +0 -0
  71. package/dist/subscriptions/incomingSubscription.d.ts +0 -0
  72. package/dist/subscriptions/incomingSubscription.js +0 -0
  73. package/dist/subscriptions/incomingSubscription.js.map +0 -0
  74. package/dist/subscriptions/incomingSubscriptionDiff.d.ts +0 -0
  75. package/dist/subscriptions/incomingSubscriptionDiff.js +0 -0
  76. package/dist/subscriptions/incomingSubscriptionDiff.js.map +0 -0
  77. package/dist/subscriptions/index.d.ts +0 -0
  78. package/dist/subscriptions/index.js +0 -0
  79. package/dist/subscriptions/index.js.map +0 -0
  80. package/dist/subscriptions/logoutSubscriptions.d.ts +0 -0
  81. package/dist/subscriptions/logoutSubscriptions.js +0 -0
  82. package/dist/subscriptions/logoutSubscriptions.js.map +0 -0
  83. package/dist/subscriptions/removeSendSubscriptionDataFromQueue.d.ts +0 -0
  84. package/dist/subscriptions/removeSendSubscriptionDataFromQueue.js +0 -0
  85. package/dist/subscriptions/removeSendSubscriptionDataFromQueue.js.map +0 -0
  86. package/dist/subscriptions/removeSubscriber.d.ts +0 -0
  87. package/dist/subscriptions/removeSubscriber.js +0 -0
  88. package/dist/subscriptions/removeSubscriber.js.map +0 -0
  89. package/dist/subscriptions/removeUnsubscribesFromQueue.d.ts +0 -0
  90. package/dist/subscriptions/removeUnsubscribesFromQueue.js +0 -0
  91. package/dist/subscriptions/removeUnsubscribesFromQueue.js.map +0 -0
  92. package/dist/subscriptions/sendAllSubscriptions.d.ts +0 -0
  93. package/dist/subscriptions/sendAllSubscriptions.js +0 -0
  94. package/dist/subscriptions/sendAllSubscriptions.js.map +0 -0
  95. package/dist/token.d.ts +0 -0
  96. package/dist/token.js +0 -0
  97. package/dist/token.js.map +0 -0
  98. package/dist/track.d.ts +0 -0
  99. package/dist/track.js +0 -0
  100. package/dist/track.js.map +0 -0
  101. package/dist/types.d.ts +253 -0
  102. package/dist/types.js +58 -0
  103. package/dist/types.js.map +1 -0
  104. package/dist/websocket/index.d.ts +0 -0
  105. package/dist/websocket/index.js +0 -0
  106. package/dist/websocket/index.js.map +0 -0
  107. package/dist/websocket/types.d.ts +0 -0
  108. package/dist/websocket/types.js +0 -0
  109. package/dist/websocket/types.js.map +0 -0
  110. package/dist/websocket/urlLoader.d.ts +0 -0
  111. package/dist/websocket/urlLoader.js +0 -0
  112. package/dist/websocket/urlLoader.js.map +0 -0
  113. package/docs/authorize.md +56 -0
  114. package/docs/files.md +66 -0
  115. package/docs/get-started.md +60 -0
  116. package/docs/get.md +759 -0
  117. package/docs/schema.md +218 -0
  118. package/docs/set.md +508 -0
  119. package/package.json +6 -4
package/README.md CHANGED
@@ -1,79 +1,350 @@
1
1
  # @based/client
2
2
 
3
- ## 🔗 Links
4
- - [GitHub](https://github.com/atelier-saulx/based#readme)
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
- ## Description
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
- ## .observe(query, cb, err?)
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
- const unobserve = await b.observe({
14
- $id: 'sp1',
15
- title: true
16
- }, (data) => {
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
- }, (err) => {
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
- ## .get(query)
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
- const result = await b.get({
27
- $id: 'sp1',
28
- title: true
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
- ## .set(payload)
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
- const { id } = await b.set({
36
- $id: 'sp1',
37
- title: 'Yes, the best'
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
- ## .delete(payload)
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
- const { ids } = await b.delete({
45
- $id: 'sp1'
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
- ## .copy(payload)
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
- const { ids } = await b.copy({
53
- $id: 'sp1'
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
- ## .call(name, payload)
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
- const res = await b.call('email', {
61
- from: 'x',
62
- to: 'y'
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
- # auth
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
- try {
70
- await b.auth(token)
324
+ <!-- prettier-ignore-end -->
71
325
 
72
- await b.auth(false)
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
- if (data[0] === types_1.RequestTypes.Token) {
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 (data[1].length) {
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(!data[2]);
85
+ fn(!payload);
82
86
  }
83
87
  this.beingAuth = false;
84
88
  this.auth = [];
85
89
  }
86
- else if (data[0] === types_1.RequestTypes.Set ||
87
- data[0] === types_1.RequestTypes.Get ||
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 if (data[0] === types_1.RequestTypes.Subscription) {
99
- (0, subscriptions_1.incomingSubscription)(this, data);
100
- }
101
- else if (data[0] === types_1.RequestTypes.SubscriptionDiff) {
102
- (0, subscriptions_1.incomingSubscriptionDiff)(this, data);
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) {
@@ -1 +1 @@
1
- {"version":3,"file":"Client.js","sourceRoot":"","sources":["../src/Client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,wCAUqB;AACrB,mDAOwB;AAExB,mCAAgE;AAChE,uCAA2C;AAC3C,oDAA+B;AAE/B,+CAA4B;AAE5B,MAAa,WAAW;IAGtB,YAAY,KAAY;QASxB,SAAI,GAA0B,EAAE,CAAA;QAEhC,kBAAa,GAuBT,EAAE,CAAA;QAEN,UAAK,GAKD,EAAE,CAAA;QAEN,qBAAgB,GAMZ,EAAE,C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emitter.js CHANGED
File without changes
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
@@ -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,MAAmB,EACnB,IAAe,EACa,EAAE;IAC9B,MAAM,KAAK,GAAG,EAAE,SAAS,CAAA;IACzB,IAAA,kBAAU,EAAC,MAAM,EAAE,CAAC,oBAAY,CAAC,IAAI,EAAE,wBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAA;IAC5E,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,EAAE,QAAQ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AAO,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"}
@@ -1,5 +1,3 @@
1
- import { ErrorObject } from '@based/types';
2
- declare const _default: (err: ErrorObject) => Error & {
3
- code?: string;
4
- };
1
+ import { ErrorObject, BasedError } from '@based/types';
2
+ declare const _default: (err: ErrorObject) => BasedError;
5
3
  export default _default;
@@ -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 Error(err.message);
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) {
@@ -1 +1 @@
1
- {"version":3,"file":"createError.js","sourceRoot":"","sources":["../src/createError.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,uEAA4D;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