@qikdev/sdk 1.0.1 → 1.0.2
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/dist/main.js +1100 -1125
- package/package.json +1 -1
- package/src/api/qik.access.js +2 -53
- package/src/api/qik.socket.js +38 -3
package/package.json
CHANGED
package/src/api/qik.access.js
CHANGED
|
@@ -27,42 +27,6 @@ var QikAccess = function (QikCore) {
|
|
|
27
27
|
|
|
28
28
|
///////////////////////////////////////////////
|
|
29
29
|
|
|
30
|
-
service.featureFlags = {
|
|
31
|
-
all: 1,
|
|
32
|
-
impersonation: 2,
|
|
33
|
-
products: 4,
|
|
34
|
-
checkin: 8,
|
|
35
|
-
events: 16,
|
|
36
|
-
ticketing: 32,
|
|
37
|
-
emails: 64,
|
|
38
|
-
sms: 128,
|
|
39
|
-
images: 256,
|
|
40
|
-
actions: 512,
|
|
41
|
-
timers: 1024,
|
|
42
|
-
listenertriggers: 2048,
|
|
43
|
-
builder: 4096,
|
|
44
|
-
scopes: 8192,
|
|
45
|
-
components: 16384,
|
|
46
|
-
video: 32768,
|
|
47
|
-
audio: 65536,
|
|
48
|
-
files: 131072,
|
|
49
|
-
developer: 262144,
|
|
50
|
-
notifications: 524288,
|
|
51
|
-
payments: 1048576,
|
|
52
|
-
comments: 2097152,
|
|
53
|
-
workflows: 4194304,
|
|
54
|
-
forms: 8388608,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
service.featureIsIncludedInByteflag = function (byteflag, feature) {
|
|
58
|
-
return (
|
|
59
|
-
(byteflag & service.featureFlags[feature]) ===
|
|
60
|
-
service.featureFlags[feature]
|
|
61
|
-
);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
///////////////////////////////////////////////
|
|
65
|
-
|
|
66
30
|
/**
|
|
67
31
|
* @alias access.hasFeature
|
|
68
32
|
* @description Checks if a user has a specific feature enabled for their organisation
|
|
@@ -73,26 +37,11 @@ var QikAccess = function (QikCore) {
|
|
|
73
37
|
* const formsFeatureIsEnabled = sdk.access.hasFeature(user, 'forms');
|
|
74
38
|
*/
|
|
75
39
|
service.hasFeature = function (user, feature) {
|
|
76
|
-
const
|
|
77
|
-
const features = organisation.features || {};
|
|
78
|
-
|
|
40
|
+
const features = user?.organisation?.features || {};
|
|
79
41
|
if (features.all) {
|
|
80
42
|
return true;
|
|
81
43
|
}
|
|
82
|
-
|
|
83
|
-
if (features[feature]) {
|
|
84
|
-
return true;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Check the byteflag
|
|
88
|
-
const byteflag = organisation.ff;
|
|
89
|
-
|
|
90
|
-
if (service.featureIsIncludedInByteflag(byteflag, "all")) {
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
//Let us know if there are any permissions for this user
|
|
95
|
-
return service.featureIsIncludedInByteflag(byteflag, feature);
|
|
44
|
+
return Boolean(features[feature]);
|
|
96
45
|
};
|
|
97
46
|
|
|
98
47
|
///////////////////////////////////////////////
|
package/src/api/qik.socket.js
CHANGED
|
@@ -90,10 +90,14 @@ const QikSocket = function(qik, mode) {
|
|
|
90
90
|
bucket.dispatch('message', message);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
// Destroy the
|
|
93
|
+
// Destroy this channel - stop receiving its events and tell the
|
|
94
|
+
// server to unsubscribe. Only touches this channel's own listeners,
|
|
95
|
+
// leaving every other channel (and connection-level listeners) intact.
|
|
94
96
|
bucket.destroy = function() {
|
|
95
|
-
service.
|
|
96
|
-
|
|
97
|
+
service.removeEventListener(key, dispatchMessage);
|
|
98
|
+
service.unsubscribe(key);
|
|
99
|
+
bucket.removeAllListeners();
|
|
100
|
+
delete buckets[key];
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
return buckets[key];
|
|
@@ -340,6 +344,37 @@ const QikSocket = function(qik, mode) {
|
|
|
340
344
|
|
|
341
345
|
///////////////////////////////////////////////////
|
|
342
346
|
|
|
347
|
+
// Reconnect the socket whenever the authenticated organisation changes.
|
|
348
|
+
// The WebSocket authenticates with an access token at connect time, so the
|
|
349
|
+
// connection stays bound to whichever organisation was active when it
|
|
350
|
+
// opened. Switching organisations issues a new token but leaves the socket
|
|
351
|
+
// untouched, so without this it keeps streaming the previous
|
|
352
|
+
// organisation's events. Reconnecting re-authenticates with the new token.
|
|
353
|
+
let currentOrganisationID = qik.utils.id(qik.auth.getCurrentUser()?.organisation);
|
|
354
|
+
|
|
355
|
+
qik.auth.addEventListener('change', async function(user) {
|
|
356
|
+
const organisationID = qik.utils.id(user?.organisation);
|
|
357
|
+
|
|
358
|
+
// Ignore auth changes that don't change the organisation (e.g. routine
|
|
359
|
+
// access token refreshes) so we don't churn the connection needlessly.
|
|
360
|
+
if (organisationID === currentOrganisationID) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
currentOrganisationID = organisationID;
|
|
365
|
+
|
|
366
|
+
// Nothing to reconnect if the socket was never opened.
|
|
367
|
+
if (!socket) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
service.debug ? console.log('[socket] - organisation changed, reconnecting') : null;
|
|
372
|
+
await service.close();
|
|
373
|
+
await service.reconnect();
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
///////////////////////////////////////////////////
|
|
377
|
+
|
|
343
378
|
return service;
|
|
344
379
|
|
|
345
380
|
}
|