@qikdev/sdk 0.1.166 → 0.1.169

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 (74) hide show
  1. package/dist/main.js +1 -1
  2. package/dist/sdk.js +2 -0
  3. package/dist/sdk.js.LICENSE.txt +8 -0
  4. package/package.json +12 -2
  5. package/.gitlab-ci.yml +0 -24
  6. package/.husky/pre-commit +0 -5
  7. package/eslint.config.js +0 -6
  8. package/jsdoc.conf +0 -10
  9. package/public/docs/access.html +0 -3826
  10. package/public/docs/api.html +0 -1356
  11. package/public/docs/auth.html +0 -2180
  12. package/public/docs/cache.html +0 -351
  13. package/public/docs/content.html +0 -2560
  14. package/public/docs/files.html +0 -779
  15. package/public/docs/filter.html +0 -1355
  16. package/public/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  17. package/public/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  18. package/public/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  19. package/public/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  20. package/public/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  21. package/public/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  22. package/public/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  23. package/public/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  24. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  25. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -978
  26. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  27. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  28. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  29. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  30. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -1049
  31. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  32. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  33. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  34. package/public/docs/index.html +0 -96
  35. package/public/docs/qik.access.js.html +0 -790
  36. package/public/docs/qik.api.js.html +0 -511
  37. package/public/docs/qik.auth.js.html +0 -1006
  38. package/public/docs/qik.cache.js.html +0 -131
  39. package/public/docs/qik.content.js.html +0 -918
  40. package/public/docs/qik.core.js.html +0 -301
  41. package/public/docs/qik.files.js.html +0 -219
  42. package/public/docs/qik.filter.js.html +0 -611
  43. package/public/docs/qik.socket.js.html +0 -416
  44. package/public/docs/qik.system.js.html +0 -117
  45. package/public/docs/qik.utils.js.html +0 -1467
  46. package/public/docs/scripts/collapse.js +0 -20
  47. package/public/docs/scripts/linenumber.js +0 -25
  48. package/public/docs/scripts/nav.js +0 -12
  49. package/public/docs/scripts/polyfill.js +0 -4
  50. package/public/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
  51. package/public/docs/scripts/prettify/lang-css.js +0 -2
  52. package/public/docs/scripts/prettify/prettify.js +0 -28
  53. package/public/docs/scripts/search.js +0 -83
  54. package/public/docs/socket.html +0 -810
  55. package/public/docs/styles/jsdoc.css +0 -765
  56. package/public/docs/styles/prettify.css +0 -79
  57. package/public/docs/system.html +0 -197
  58. package/src/api/qik.access.js +0 -825
  59. package/src/api/qik.api.js +0 -431
  60. package/src/api/qik.auth.js +0 -881
  61. package/src/api/qik.cache.js +0 -63
  62. package/src/api/qik.content.js +0 -839
  63. package/src/api/qik.core.js +0 -245
  64. package/src/api/qik.files.js +0 -186
  65. package/src/api/qik.filter.js +0 -543
  66. package/src/api/qik.geo.js +0 -895
  67. package/src/api/qik.socket.js +0 -358
  68. package/src/api/qik.system.js +0 -49
  69. package/src/api/qik.utils.js +0 -1412
  70. package/src/index.js +0 -20
  71. package/src/version.js +0 -1
  72. package/test/index.spec.js +0 -41
  73. package/test/mocha.opts +0 -0
  74. package/yarn-error.log +0 -3598
@@ -1,358 +0,0 @@
1
- import { EventDispatcher } from "./qik.utils.js";
2
-
3
- ///////////////////////////////////////////////////
4
-
5
- /**
6
- * Creates a new instance of QikSocket a module of the SDK
7
- * that contains all helper functions to do with realtime sockets
8
- * @name socket
9
- * @constructor
10
- * @hideconstructor
11
- * @param {QikAPI} qik A reference to the parent instance of the QikCore module. This module is usually created by a QikCore instance that passes itself in as the first argument.
12
- */
13
-
14
- const QikSocket = function (qik, mode) {
15
- mode = mode || "production";
16
-
17
- if (!qik.auth) {
18
- throw new Error(`Can't Instantiate QikSocket before QikAuth exists`);
19
- }
20
-
21
- const windowID = qik.utils.guid();
22
-
23
- ///////////////////////////////////////////////////
24
-
25
- let service = {
26
- debug: false,
27
- url: `wss://iqtm6zjz3l.execute-api.ap-southeast-2.amazonaws.com/${mode}`,
28
- connected: false,
29
- windowID,
30
- autoreconnect: true,
31
- };
32
-
33
- let socket;
34
- let timer;
35
- let buckets = {};
36
- const channels = {};
37
-
38
- //Create a new dispatcher
39
- const dispatcher = new EventDispatcher();
40
- dispatcher.bootstrap(service);
41
-
42
- ///////////////////////////////////////////////////
43
-
44
- function getSubscriptions() {
45
- return Object.keys(buckets);
46
- }
47
-
48
- ///////////////////////////////////////////////////
49
-
50
- /**
51
- * @description Create an event dispatcher instance and subscribe to a new socket channel.
52
- * This can then be used to receive socket events for this channel
53
- * @alias socket.channel
54
- * @param {String} key The key or name of the channel to subscribe to
55
- * @example
56
- * const socketChannel = await sdk.socket.channel('awesome:notifications')
57
- * socketChannel.addEventListener('message', function(message) {
58
- * console.log('Received a new message from the socket')
59
- * })
60
- *
61
- * // Disconnect from this channel and remove all listeners
62
- * socketChannel.destroy();
63
- *
64
- */
65
- service.channel = async function (key) {
66
- if (!buckets[key]) {
67
- // Create a new channel instance
68
- const bucket = new EventDispatcher();
69
- buckets[key] = bucket;
70
-
71
- // If the user isn't online
72
- if (!service.connected) {
73
- // Connect them now
74
- await service.connect();
75
- }
76
-
77
- // Subscribe to this key
78
- service.subscribe(key);
79
-
80
- // Listen for all relevant events
81
- service.addEventListener(key, dispatchMessage);
82
-
83
- function dispatchMessage(message) {
84
- bucket.dispatch("message", message);
85
- }
86
-
87
- // Destroy the service
88
- bucket.destroy = function () {
89
- service.unsubscribe(key);
90
- buckets[key].removeAllListeners();
91
- buckets[key] = null;
92
- };
93
- }
94
-
95
- // Return the channel instance
96
- return buckets[key];
97
- };
98
-
99
- ///////////////////////////////////////////////////
100
-
101
- function ping() {
102
- broadcast({
103
- action: "ping",
104
- });
105
- }
106
-
107
- function startHeartbeat() {
108
- if (timer) {
109
- return;
110
- }
111
- timer = setInterval(ping, 10000);
112
- }
113
-
114
- function stopHeartbeat() {
115
- if (!timer) {
116
- return;
117
- }
118
-
119
- clearInterval(timer);
120
- timer = null;
121
- }
122
-
123
- ///////////////////////////////////////////////////
124
-
125
- function socketOpened(event) {
126
- service.debug ? console.log("[socket] Connection open", event) : null;
127
- service.connected = true;
128
-
129
- dispatcher.dispatch("connected", event);
130
-
131
- // startHeartbeat();
132
- }
133
-
134
- async function socketClosed(event) {
135
- if (event.wasClean) {
136
- service.debug
137
- ? console.log(
138
- `[socket] Connection closed cleanly, code=${event.code} reason=${event.reason}`,
139
- )
140
- : null;
141
- } else {
142
- // e.g. server process killed or network down
143
- // event.code is usually 1006 in this case
144
- service.debug
145
- ? console.log("[socket] - connection closed due to error", event)
146
- : null;
147
- }
148
-
149
- service.connected = false;
150
- dispatcher.dispatch("disconnected", event);
151
- socket = null;
152
-
153
- if (service.autoreconnect) {
154
- service.reconnect();
155
- }
156
- }
157
-
158
- function socketError(error) {
159
- console.log("[event] socketError", event);
160
- service.debug ? console.log("[socket] Error", error) : null;
161
- dispatcher.dispatch("error", error);
162
- }
163
-
164
- function socketMessageReceived(event) {
165
- const eventData = JSON.parse(event.data);
166
- service.debug ? console.log("[socket] message received", eventData) : null;
167
-
168
- // Dispatch a generic message
169
- dispatcher.dispatch("message", eventData);
170
-
171
- if (eventData.channel) {
172
- dispatcher.dispatch(eventData.channel, eventData);
173
- }
174
- }
175
-
176
- async function broadcast(data) {
177
- socket.send(JSON.stringify(data));
178
- }
179
-
180
- ///////////////////////////////////////////////////
181
-
182
- function wait() {
183
- return new Promise(function (resolve) {
184
- function check() {
185
- if (service.connected) {
186
- return resolve(socket);
187
- }
188
-
189
- setTimeout(check, 1000);
190
- }
191
-
192
- check();
193
- });
194
- }
195
-
196
- ///////////////////////////////////////////////////
197
-
198
- /**
199
- * @description Connect to the socket service
200
- * @alias socket.connect
201
- * @example
202
- * const connected = await sdk.socket.connect()
203
- *
204
- */
205
- service.connect = async function () {
206
- if (socket) {
207
- if (!socket.connected) {
208
- return wait();
209
- }
210
-
211
- console.log("[socket] - Socket is already connected");
212
- return socket;
213
- }
214
-
215
- const accessToken = qik.auth.getCurrentToken();
216
-
217
- if (!accessToken) {
218
- service.debug
219
- ? console.log("[socket] - Must be authenticated to connect to socket")
220
- : null;
221
- return;
222
- }
223
-
224
- socket = new WebSocket(
225
- `${service.url}?access_token=${accessToken}&windowid=${windowID}`,
226
- );
227
- socket.addEventListener("close", socketClosed);
228
- socket.addEventListener("error", socketError);
229
- socket.addEventListener("open", socketOpened);
230
- socket.addEventListener("message", socketMessageReceived);
231
- service.debug
232
- ? console.log("[socket] - Connected with event listeners")
233
- : null;
234
-
235
- return wait();
236
- };
237
-
238
- /**
239
- * @description Reconnect to the socket service
240
- * @alias socket.reconnect
241
- * @example
242
- * const connected = await sdk.socket.reconnect()
243
- *
244
- */
245
- service.reconnect = async function () {
246
- if (service.connected) {
247
- return;
248
- }
249
-
250
- service.debug ? console.log(`[socket] reconnecting...`) : null;
251
-
252
- // Reconnect all listeners
253
- const result = await service.connect();
254
-
255
- // Resubscribe to all previously connected channels
256
- const subscribedChannels = Object.keys(channels);
257
- subscribedChannels.forEach(function (channel) {
258
- service.subscribe(channel);
259
- });
260
-
261
- return result;
262
- };
263
-
264
- ///////////////////////////////////////////////////
265
-
266
- /**
267
- * @description Close the connection to the socket service
268
- * @alias socket.close
269
- * @example
270
- * const closed = await sdk.socket.close()
271
- *
272
- */
273
- service.close = async function () {
274
- if (!socket) {
275
- console.log("[socket] - Socket is not connected");
276
- return;
277
- }
278
-
279
- const previousSetting = service.autoreconnect;
280
- service.autoreconnect = false;
281
- socket.close();
282
- socket.removeEventListener("close", socketClosed);
283
- socket.removeEventListener("error", socketError);
284
- socket.removeEventListener("open", socketOpened);
285
- socket.removeEventListener("message", socketMessageReceived);
286
- socket = null;
287
- socketClosed({ wasClean: true });
288
- service.autoreconnect = previousSetting;
289
- };
290
-
291
- service.disconnect = service.close;
292
-
293
- ///////////////////////////////////////////////////
294
-
295
- /**
296
- * @description Subscribe to a socket channel
297
- * @alias socket.subscribe
298
- * @param {String} key The name of the channel to subscribe to
299
- * @example
300
- * const subscribed = await sdk.socket.subscribe('some:cool:alert')
301
- *
302
- */
303
- service.subscribe = async function (channel) {
304
- if (!socket) {
305
- console.log(
306
- `[socket] - Can't subscribe to channel as socket is not connected`,
307
- );
308
- return;
309
- }
310
-
311
- broadcast({
312
- action: "subscribe",
313
- channel,
314
- });
315
-
316
- channels[channel] = true;
317
-
318
- dispatcher.dispatch("subscribe", channel);
319
- service.debug ? console.log(`[socket] - subscribed to ${channel}`) : null;
320
- };
321
-
322
- ///////////////////////////////////////////////////
323
-
324
- /**
325
- * @description Unsubscribe from a socket channel
326
- * @alias socket.unsubscribe
327
- * @param {String} key The name of the channel to unsubscribe from
328
- * @example
329
- * const unsubscribed = await sdk.socket.unsubscribe('some:cool:alert')
330
- *
331
- */
332
- service.unsubscribe = async function (channel) {
333
- if (!socket) {
334
- console.log(
335
- `[socket] - Can't unsubscribe from channel as socket is not connected`,
336
- );
337
- return;
338
- }
339
-
340
- broadcast({
341
- action: "unsubscribe",
342
- channel,
343
- });
344
-
345
- delete channels[channel];
346
-
347
- dispatcher.dispatch("unsubscribe", channel);
348
- service.debug
349
- ? console.log(`[socket] - unsubscribed from ${channel}`)
350
- : null;
351
- };
352
-
353
- ///////////////////////////////////////////////////
354
-
355
- return service;
356
- };
357
-
358
- export default QikSocket;
@@ -1,49 +0,0 @@
1
- ///////////////////////////////////////////////////
2
-
3
- /**
4
- * Creates a new QikSystem instance.
5
- * This module provides a number of helper functions for the system
6
- * @alias system
7
- * @constructor
8
- * @hideconstructor
9
- * @param {QikCore} qik A reference to the parent instance of the QikCore module. This module is usually created by a QikCore instance that passes itself in as the first argument.
10
- */
11
- export default function(qik) {
12
-
13
- ///////////////////////////////////////////////////
14
-
15
- var service = {}
16
-
17
-
18
- ///////////////////////////////////////////////////////////////////////////////
19
-
20
- var inflightCountries;
21
-
22
- /**
23
- * @alias system.countries
24
- * @description Helper function for retrieving a full list of all countries, their ISO codes
25
- * and phone number prefixes. Helpful for populating dropdown lists.
26
- * @example
27
- * const countries = await sdk.system.countries()
28
- */
29
- service.countries = async function() {
30
-
31
- if (!inflightCountries) {
32
-
33
- inflightCountries = new Promise(async function(resolve, reject) {
34
- qik.api.get(`/system/countries`)
35
- .then(function(res) {
36
- return resolve(res.data);
37
- })
38
- .catch(reject);
39
- })
40
- }
41
-
42
- return inflightCountries;
43
- }
44
-
45
- ///////////////////////////////////////////////////
46
-
47
- return service;
48
-
49
- }