@qikdev/sdk 0.1.134 → 0.1.136
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 +1 -1
- package/package.json +1 -1
- package/public/docs/access.html +8 -8
- package/public/docs/api.html +8 -8
- package/public/docs/auth.html +16 -16
- package/public/docs/cache.html +2 -2
- package/public/docs/content.html +14 -14
- package/public/docs/files.html +3 -3
- package/public/docs/filter.html +10 -10
- package/public/docs/index.html +2 -2
- package/public/docs/qik.access.js.html +3 -4
- package/public/docs/qik.api.js.html +36 -8
- package/public/docs/qik.auth.js.html +92 -161
- package/public/docs/qik.cache.js.html +2 -2
- package/public/docs/qik.content.js.html +82 -27
- package/public/docs/qik.core.js.html +2 -2
- package/public/docs/qik.files.js.html +9 -7
- package/public/docs/qik.filter.js.html +38 -17
- package/public/docs/qik.socket.js.html +67 -21
- package/public/docs/qik.system.js.html +2 -2
- package/public/docs/qik.utils.js.html +265 -137
- package/public/docs/socket.html +99 -7
- package/public/docs/system.html +2 -2
- package/src/api/qik.utils.js +78 -17
- package/src/version.js +1 -1
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
<nav >
|
|
29
29
|
|
|
30
|
-
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="access.html">access</a><ul class='methods'><li data-type='method'><a href="access.html#.actionableScopes">actionableScopes</a></li><li data-type='method'><a href="access.html#.allPermissions">allPermissions</a></li><li data-type='method'><a href="access.html#.allPermissionTypes">allPermissionTypes</a></li><li data-type='method'><a href="access.html#.allUserScopes">allUserScopes</a></li><li data-type='method'><a href="access.html#.canCreate">canCreate</a></li><li data-type='method'><a href="access.html#.canDeleteItem">canDeleteItem</a></li><li data-type='method'><a href="access.html#.canEditItem">canEditItem</a></li><li data-type='method'><a href="access.html#.canEraseItem">canEraseItem</a></li><li data-type='method'><a href="access.html#.canKnowOf">canKnowOf</a></li><li data-type='method'><a href="access.html#.canListItem">canListItem</a></li><li data-type='method'><a href="access.html#.canRestoreItem">canRestoreItem</a></li><li data-type='method'><a href="access.html#.canViewItem">canViewItem</a></li><li data-type='method'><a href="access.html#.checkActionAccess">checkActionAccess</a></li><li data-type='method'><a href="access.html#.getAllDescendants">getAllDescendants</a></li><li data-type='method'><a href="access.html#.has">has</a></li><li data-type='method'><a href="access.html#.hashPermissions">hashPermissions</a></li><li data-type='method'><a href="access.html#.isAdministrator">isAdministrator</a></li><li data-type='method'><a href="access.html#.isOwner">isOwner</a></li></ul></li><li><a href="api.html">api</a><ul class='methods'><li data-type='method'><a href="api.html#.delete">delete</a></li><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li><li data-type='method'><a href="api.html#.get">get</a></li><li data-type='method'><a href="api.html#.patch">patch</a></li><li data-type='method'><a href="api.html#.post">post</a></li><li data-type='method'><a href="api.html#.put">put</a></li></ul></li><li><a href="auth.html">auth</a><ul class='methods'><li data-type='method'><a href="auth.html#.changeOrganisation">changeOrganisation</a></li><li data-type='method'><a href="auth.html#.ensureValidToken">ensureValidToken</a></li><li data-type='method'><a href="auth.html#.getCurrentToken">getCurrentToken</a></li><li data-type='method'><a href="auth.html#.getCurrentUser">getCurrentUser</a></li><li data-type='method'><a href="auth.html#.impersonate">impersonate</a></li><li data-type='method'><a href="auth.html#.login">login</a></li><li data-type='method'><a href="auth.html#.logout">logout</a></li><li data-type='method'><a href="auth.html#.retrieveUserFromResetToken">retrieveUserFromResetToken</a></li><li data-type='method'><a href="auth.html#.sendResetPasswordRequest">sendResetPasswordRequest</a></li><li data-type='method'><a href="auth.html#.set">set</a></li><li data-type='method'><a href="auth.html#.sync">sync</a></li><li data-type='method'><a href="auth.html#.updateUserWithToken">updateUserWithToken</a></li></ul></li><li><a href="cache.html">cache</a><ul class='methods'><li data-type='method'><a href="cache.html#.get">get</a></li><li data-type='method'><a href="cache.html#.reset">reset</a></li></ul></li><li><a href="content.html">content</a><ul class='methods'><li data-type='method'><a href="content.html#.create">create</a></li><li data-type='method'><a href="content.html#.delete">delete</a></li><li data-type='method'><a href="content.html#.get">get</a></li><li data-type='method'><a href="content.html#.getFromSlug">getFromSlug</a></li><li data-type='method'><a href="content.html#.glossary">glossary</a></li><li data-type='method'><a href="content.html#.list">list</a></li><li data-type='method'><a href="content.html#.patch">patch</a></li><li data-type='method'><a href="content.html#.restore">restore</a></li><li data-type='method'><a href="content.html#.scopeGlossary">scopeGlossary</a></li><li data-type='method'><a href="content.html#.update">update</a></li><li data-type='method'><a href="content.html#.validateField">validateField</a></li><li data-type='method'><a href="content.html#.variables">variables</a></li></ul></li><li><a href="files.html">files</a><ul class='methods'><li data-type='method'><a href="files.html#.downloadUrl">downloadUrl</a></li><li data-type='method'><a href="files.html#.filesize">filesize</a></li><li data-type='method'><a href="files.html#.getBinaryTypeFromMime">getBinaryTypeFromMime</a></li><li data-type='method'><a href="files.html#.mediaUrl">mediaUrl</a></li></ul></li><li><a href="filter.html">filter</a><ul class='methods'><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterOperators">activeFilterOperators</a></li><li data-type='method'><a href="filter.html#.activeFilters">activeFilters</a></li><li data-type='method'><a href="filter.html#.activeFilterValues">activeFilterValues</a></li><li data-type='method'><a href="filter.html#.filterChangeString">filterChangeString</a></li><li data-type='method'><a href="filter.html#.isValidFilter">isValidFilter</a></li></ul></li><li><a href="socket.html">socket</a><ul class='methods'><li data-type='method'><a href="socket.html#.channel">channel</a></li><li data-type='method'><a href="socket.html#.close">close</a></li><li data-type='method'><a href="socket.html#.connect">connect</a></li><li data-type='method'><a href="socket.html#.subscribe">subscribe</a></li><li data-type='method'><a href="socket.html#.unsubscribe">unsubscribe</a></li></ul></li><li><a href="system.html">system</a><ul class='methods'><li data-type='method'><a href="system.html#.countries">countries</a></li></ul></li></ul>
|
|
30
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="access.html">access</a><ul class='methods'><li data-type='method'><a href="access.html#.actionableScopes">actionableScopes</a></li><li data-type='method'><a href="access.html#.allPermissions">allPermissions</a></li><li data-type='method'><a href="access.html#.allPermissionTypes">allPermissionTypes</a></li><li data-type='method'><a href="access.html#.allUserScopes">allUserScopes</a></li><li data-type='method'><a href="access.html#.canCreate">canCreate</a></li><li data-type='method'><a href="access.html#.canDeleteItem">canDeleteItem</a></li><li data-type='method'><a href="access.html#.canEditItem">canEditItem</a></li><li data-type='method'><a href="access.html#.canEraseItem">canEraseItem</a></li><li data-type='method'><a href="access.html#.canKnowOf">canKnowOf</a></li><li data-type='method'><a href="access.html#.canListItem">canListItem</a></li><li data-type='method'><a href="access.html#.canRestoreItem">canRestoreItem</a></li><li data-type='method'><a href="access.html#.canViewItem">canViewItem</a></li><li data-type='method'><a href="access.html#.checkActionAccess">checkActionAccess</a></li><li data-type='method'><a href="access.html#.getAllDescendants">getAllDescendants</a></li><li data-type='method'><a href="access.html#.has">has</a></li><li data-type='method'><a href="access.html#.hashPermissions">hashPermissions</a></li><li data-type='method'><a href="access.html#.isAdministrator">isAdministrator</a></li><li data-type='method'><a href="access.html#.isOwner">isOwner</a></li></ul></li><li><a href="api.html">api</a><ul class='methods'><li data-type='method'><a href="api.html#.delete">delete</a></li><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li><li data-type='method'><a href="api.html#.get">get</a></li><li data-type='method'><a href="api.html#.patch">patch</a></li><li data-type='method'><a href="api.html#.post">post</a></li><li data-type='method'><a href="api.html#.put">put</a></li></ul></li><li><a href="auth.html">auth</a><ul class='methods'><li data-type='method'><a href="auth.html#.changeOrganisation">changeOrganisation</a></li><li data-type='method'><a href="auth.html#.ensureValidToken">ensureValidToken</a></li><li data-type='method'><a href="auth.html#.getCurrentToken">getCurrentToken</a></li><li data-type='method'><a href="auth.html#.getCurrentUser">getCurrentUser</a></li><li data-type='method'><a href="auth.html#.impersonate">impersonate</a></li><li data-type='method'><a href="auth.html#.login">login</a></li><li data-type='method'><a href="auth.html#.logout">logout</a></li><li data-type='method'><a href="auth.html#.retrieveUserFromResetToken">retrieveUserFromResetToken</a></li><li data-type='method'><a href="auth.html#.sendResetPasswordRequest">sendResetPasswordRequest</a></li><li data-type='method'><a href="auth.html#.set">set</a></li><li data-type='method'><a href="auth.html#.sync">sync</a></li><li data-type='method'><a href="auth.html#.updateUserWithToken">updateUserWithToken</a></li></ul></li><li><a href="cache.html">cache</a><ul class='methods'><li data-type='method'><a href="cache.html#.get">get</a></li><li data-type='method'><a href="cache.html#.reset">reset</a></li></ul></li><li><a href="content.html">content</a><ul class='methods'><li data-type='method'><a href="content.html#.create">create</a></li><li data-type='method'><a href="content.html#.delete">delete</a></li><li data-type='method'><a href="content.html#.get">get</a></li><li data-type='method'><a href="content.html#.getFromSlug">getFromSlug</a></li><li data-type='method'><a href="content.html#.glossary">glossary</a></li><li data-type='method'><a href="content.html#.list">list</a></li><li data-type='method'><a href="content.html#.patch">patch</a></li><li data-type='method'><a href="content.html#.restore">restore</a></li><li data-type='method'><a href="content.html#.scopeGlossary">scopeGlossary</a></li><li data-type='method'><a href="content.html#.update">update</a></li><li data-type='method'><a href="content.html#.validateField">validateField</a></li><li data-type='method'><a href="content.html#.variables">variables</a></li></ul></li><li><a href="files.html">files</a><ul class='methods'><li data-type='method'><a href="files.html#.downloadUrl">downloadUrl</a></li><li data-type='method'><a href="files.html#.filesize">filesize</a></li><li data-type='method'><a href="files.html#.getBinaryTypeFromMime">getBinaryTypeFromMime</a></li><li data-type='method'><a href="files.html#.mediaUrl">mediaUrl</a></li></ul></li><li><a href="filter.html">filter</a><ul class='methods'><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterOperators">activeFilterOperators</a></li><li data-type='method'><a href="filter.html#.activeFilters">activeFilters</a></li><li data-type='method'><a href="filter.html#.activeFilterValues">activeFilterValues</a></li><li data-type='method'><a href="filter.html#.filterChangeString">filterChangeString</a></li><li data-type='method'><a href="filter.html#.isValidFilter">isValidFilter</a></li></ul></li><li><a href="socket.html">socket</a><ul class='methods'><li data-type='method'><a href="socket.html#.channel">channel</a></li><li data-type='method'><a href="socket.html#.close">close</a></li><li data-type='method'><a href="socket.html#.connect">connect</a></li><li data-type='method'><a href="socket.html#.reconnect">reconnect</a></li><li data-type='method'><a href="socket.html#.subscribe">subscribe</a></li><li data-type='method'><a href="socket.html#.unsubscribe">unsubscribe</a></li></ul></li><li><a href="system.html">system</a><ul class='methods'><li data-type='method'><a href="system.html#.countries">countries</a></li></ul></li></ul>
|
|
31
31
|
</nav>
|
|
32
32
|
|
|
33
33
|
<div id="main">
|
|
@@ -59,7 +59,7 @@ import { EventDispatcher } from './qik.utils.js';
|
|
|
59
59
|
var QikAuth = function(qik) {
|
|
60
60
|
|
|
61
61
|
if (!qik.api) {
|
|
62
|
-
throw new Error(`
|
|
62
|
+
throw new Error(`Please ensure that QikAPI exists before QikAuth`);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
//Keep track of any refresh requests
|
|
@@ -67,14 +67,13 @@ var QikAuth = function(qik) {
|
|
|
67
67
|
|
|
68
68
|
///////////////////////////////////////////////////
|
|
69
69
|
|
|
70
|
-
var
|
|
71
|
-
var store =
|
|
70
|
+
var sessionStorage = {};
|
|
71
|
+
var store = sessionStorage;
|
|
72
72
|
const tokenBufferSeconds = 10;
|
|
73
73
|
|
|
74
|
-
///////////////////////////////////////////////////
|
|
75
74
|
///////////////////////////////////////////////////
|
|
76
75
|
|
|
77
|
-
|
|
76
|
+
const service = {
|
|
78
77
|
debug: false,
|
|
79
78
|
}
|
|
80
79
|
|
|
@@ -83,13 +82,10 @@ var QikAuth = function(qik) {
|
|
|
83
82
|
writable: false,
|
|
84
83
|
});
|
|
85
84
|
|
|
86
|
-
|
|
87
85
|
//Create a new dispatcher
|
|
88
|
-
|
|
86
|
+
const dispatcher = new EventDispatcher();
|
|
89
87
|
dispatcher.bootstrap(service);
|
|
90
88
|
|
|
91
|
-
|
|
92
|
-
///////////////////////////////////////////////////
|
|
93
89
|
///////////////////////////////////////////////////
|
|
94
90
|
|
|
95
91
|
function dispatch(parameters) {
|
|
@@ -114,22 +110,22 @@ var QikAuth = function(qik) {
|
|
|
114
110
|
* @description Manually set current user session
|
|
115
111
|
* @param {Object} user The user session object to set as the current user session
|
|
116
112
|
* @param {Object} parameters Additional parameters to dispatch
|
|
117
|
-
* @param {Boolean}
|
|
113
|
+
* @param {Boolean} stopDispatch Whether to supress dispatching a 'change' event.
|
|
118
114
|
* @example
|
|
119
115
|
*
|
|
120
116
|
* const userSession = {_id:'61eca4746971e75c1fc670cf', firstName:'Daffy', lastName:'Duck' ...};
|
|
121
117
|
* sdk.auth.set(userSession);
|
|
122
118
|
*/
|
|
123
119
|
|
|
124
|
-
service.set = function(user, parameters,
|
|
120
|
+
service.set = function(user, parameters, stopDispatch) {
|
|
125
121
|
|
|
126
|
-
if(JSON.stringify(store.user) != JSON.stringify(user)) {
|
|
122
|
+
if (JSON.stringify(store.user) != JSON.stringify(user)) {
|
|
127
123
|
store.user = user;
|
|
128
|
-
if(!
|
|
124
|
+
if (!stopDispatch) {
|
|
129
125
|
return dispatch(parameters)
|
|
130
126
|
}
|
|
131
127
|
}
|
|
132
|
-
|
|
128
|
+
|
|
133
129
|
}
|
|
134
130
|
|
|
135
131
|
|
|
@@ -146,7 +142,6 @@ var QikAuth = function(qik) {
|
|
|
146
142
|
delete store.user;
|
|
147
143
|
qik.cache.reset();
|
|
148
144
|
return dispatch()
|
|
149
|
-
|
|
150
145
|
}
|
|
151
146
|
|
|
152
147
|
///////////////////////////////////////////////////
|
|
@@ -193,25 +188,21 @@ var QikAuth = function(qik) {
|
|
|
193
188
|
return new Promise(function(resolve, reject) {
|
|
194
189
|
|
|
195
190
|
|
|
196
|
-
|
|
197
|
-
|
|
191
|
+
qik.api.post(`/user/switch/${organisationID}`)
|
|
192
|
+
.then(function(response) {
|
|
198
193
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
resolve(response.data);
|
|
205
|
-
})
|
|
206
|
-
.catch(reject)
|
|
194
|
+
if (autoAuthenticate) {
|
|
195
|
+
qik.cache.reset();
|
|
196
|
+
service.set(response.data);
|
|
197
|
+
}
|
|
207
198
|
|
|
208
|
-
|
|
209
|
-
|
|
199
|
+
resolve(response.data);
|
|
200
|
+
})
|
|
201
|
+
.catch(reject)
|
|
210
202
|
|
|
203
|
+
})
|
|
211
204
|
}
|
|
212
205
|
|
|
213
|
-
|
|
214
|
-
|
|
215
206
|
///////////////////////////////////////////////////
|
|
216
207
|
|
|
217
208
|
/**
|
|
@@ -269,8 +260,8 @@ var QikAuth = function(qik) {
|
|
|
269
260
|
}
|
|
270
261
|
|
|
271
262
|
///////////////////////////////////////////////////
|
|
272
|
-
|
|
273
|
-
|
|
263
|
+
|
|
264
|
+
/**
|
|
274
265
|
* @alias auth.login
|
|
275
266
|
* @description Login and authenticate as a user
|
|
276
267
|
* @param {Object} credentials The credentials used to login
|
|
@@ -358,7 +349,7 @@ var QikAuth = function(qik) {
|
|
|
358
349
|
|
|
359
350
|
if (autoAuthenticate) {
|
|
360
351
|
service.set(res.data);
|
|
361
|
-
|
|
352
|
+
|
|
362
353
|
}
|
|
363
354
|
|
|
364
355
|
resolve(res);
|
|
@@ -503,30 +494,12 @@ var QikAuth = function(qik) {
|
|
|
503
494
|
options = {};
|
|
504
495
|
}
|
|
505
496
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
return new Promise(function(resolve, reject) {
|
|
509
|
-
|
|
510
|
-
var postOptions = {
|
|
497
|
+
var postOptions = {
|
|
511
498
|
bypassInterceptor: true
|
|
512
499
|
}
|
|
513
500
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
//If a full fledged Qik User
|
|
517
|
-
//then send directly to the API auth endpoint
|
|
518
|
-
var url = `${qik.apiURL}/user/reset/${resetToken}`;
|
|
519
|
-
|
|
520
|
-
/////////////////////////////////////////////
|
|
521
|
-
|
|
522
|
-
//If we have a specified url
|
|
523
|
-
if (options.url) {
|
|
524
|
-
url = options.url;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
/////////////////////////////////////////////
|
|
528
|
-
|
|
529
|
-
qik.api.get(url, postOptions).then(function(res) {
|
|
501
|
+
return new Promise(function(resolve, reject) {
|
|
502
|
+
qik.api.get(options.url || `${qik.apiURL}/user/reset/${resetToken}`, postOptions).then(function(res) {
|
|
530
503
|
return resolve(res.data);
|
|
531
504
|
}, reject);
|
|
532
505
|
});
|
|
@@ -574,22 +547,8 @@ var QikAuth = function(qik) {
|
|
|
574
547
|
bypassInterceptor: true
|
|
575
548
|
}
|
|
576
549
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
//If a full fledged user
|
|
580
|
-
//then send directly to the API auth endpoint
|
|
581
|
-
var url = `${qik.apiURL}/user/reset/${resetToken}`;
|
|
582
|
-
|
|
583
|
-
/////////////////////////////////////////////
|
|
584
|
-
|
|
585
|
-
//If we have a specified url
|
|
586
|
-
if (options.url) {
|
|
587
|
-
url = options.url;
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
/////////////////////////////////////////////
|
|
591
|
-
|
|
592
|
-
qik.api.post(url, body, postOptions).then(function(res) {
|
|
550
|
+
qik.api.post(options.url || `${qik.apiURL}/user/reset/${resetToken}`, body, postOptions)
|
|
551
|
+
.then(function(res) {
|
|
593
552
|
|
|
594
553
|
//If we should automatically authenticate
|
|
595
554
|
//once the request is successful
|
|
@@ -618,60 +577,32 @@ var QikAuth = function(qik) {
|
|
|
618
577
|
* // Retrieve the user session by providing a reset token
|
|
619
578
|
* const user = await sdk.auth.retrieveUserFromResetToken(resetToken);
|
|
620
579
|
*/
|
|
621
|
-
service.sendResetPasswordRequest = function(
|
|
580
|
+
service.sendResetPasswordRequest = function(details, options) {
|
|
622
581
|
|
|
623
582
|
if (!options) {
|
|
624
583
|
options = {};
|
|
625
584
|
}
|
|
626
585
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
if (!body) {
|
|
634
|
-
return reject({
|
|
635
|
-
message: 'No details provided',
|
|
636
|
-
})
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
if (!body.email || !body.email.length) {
|
|
640
|
-
return reject({
|
|
641
|
-
message: 'Email was not provided',
|
|
642
|
-
})
|
|
643
|
-
}
|
|
586
|
+
if (!details) {
|
|
587
|
+
return Promise.reject({
|
|
588
|
+
message: 'No details were provided for password reset request',
|
|
589
|
+
})
|
|
590
|
+
}
|
|
644
591
|
|
|
645
|
-
|
|
646
|
-
|
|
592
|
+
if (!details.email || !details.email.length) {
|
|
593
|
+
return Promise.reject({
|
|
594
|
+
message: 'Email is required but was not provided',
|
|
595
|
+
})
|
|
596
|
+
}
|
|
647
597
|
|
|
648
|
-
|
|
598
|
+
return new Promise(function(resolve, reject) {
|
|
649
599
|
|
|
650
600
|
var postOptions = {
|
|
651
601
|
bypassInterceptor: true
|
|
652
602
|
}
|
|
653
603
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
//If a full fledged Qik User
|
|
657
|
-
//then send directly to the API
|
|
658
|
-
var url = `${qik.apiURL}/user/forgot`;
|
|
659
|
-
|
|
660
|
-
/////////////////////////////////////////////
|
|
661
|
-
|
|
662
|
-
//If we have a specified url
|
|
663
|
-
if (options.url) {
|
|
664
|
-
url = options.url;
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
/////////////////////////////////////////////
|
|
668
|
-
|
|
669
|
-
qik.api.post(url, body, postOptions).then(resolve, reject);
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
//////////////////////////////////////
|
|
673
|
-
|
|
674
|
-
return promise;
|
|
604
|
+
qik.api.post(options.url || `${qik.apiURL}/user/forgot`, details, postOptions).then(resolve, reject);
|
|
605
|
+
})
|
|
675
606
|
}
|
|
676
607
|
|
|
677
608
|
|
|
@@ -692,46 +623,46 @@ var QikAuth = function(qik) {
|
|
|
692
623
|
*/
|
|
693
624
|
service.ensureValidToken = async function(forceRefresh) {
|
|
694
625
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
return Promise.reject('No user');
|
|
699
|
-
}
|
|
626
|
+
var currentUser = service.getCurrentUser();
|
|
627
|
+
if (!currentUser) {
|
|
700
628
|
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
return Promise.reject('No token');
|
|
705
|
-
}
|
|
629
|
+
return Promise.reject('No user');
|
|
630
|
+
}
|
|
706
631
|
|
|
707
|
-
|
|
632
|
+
var { token } = currentUser;
|
|
633
|
+
if (!token) {
|
|
708
634
|
|
|
709
|
-
|
|
710
|
-
|
|
635
|
+
return Promise.reject('No token');
|
|
636
|
+
}
|
|
711
637
|
|
|
712
|
-
|
|
713
|
-
//retiring the token
|
|
714
|
-
now.setSeconds(now.getSeconds() + tokenBufferSeconds);
|
|
638
|
+
/////////////////////////////////////////////////////
|
|
715
639
|
|
|
716
|
-
|
|
640
|
+
//Check our date
|
|
641
|
+
var now = new Date();
|
|
717
642
|
|
|
718
|
-
|
|
643
|
+
//Give us a bit of buffer so that the backend doesn't beat us to
|
|
644
|
+
//retiring the token
|
|
645
|
+
now.setSeconds(now.getSeconds() + tokenBufferSeconds);
|
|
719
646
|
|
|
720
|
-
|
|
721
|
-
console.log('force refresh valid token', token.refreshToken)
|
|
722
|
-
return await service.refreshAccessToken(token.refreshToken);
|
|
723
|
-
}
|
|
647
|
+
/////////////////////////////////////////////////////
|
|
724
648
|
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
649
|
+
var expires = new Date(token.expires);
|
|
650
|
+
|
|
651
|
+
if (forceRefresh) {
|
|
652
|
+
console.log('force refresh valid token', token.refreshToken)
|
|
653
|
+
return await service.refreshAccessToken(token.refreshToken);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
//If the token is still fresh
|
|
657
|
+
if (now < expires) {
|
|
658
|
+
|
|
659
|
+
return token;
|
|
660
|
+
} else {
|
|
661
|
+
|
|
662
|
+
return await service.refreshAccessToken(token.refreshToken);
|
|
663
|
+
}
|
|
730
664
|
|
|
731
|
-
return await service.refreshAccessToken(token.refreshToken);
|
|
732
|
-
}
|
|
733
665
|
|
|
734
|
-
|
|
735
666
|
}
|
|
736
667
|
|
|
737
668
|
///////////////////////////////////////////////////
|
|
@@ -743,23 +674,23 @@ var QikAuth = function(qik) {
|
|
|
743
674
|
// /////////////////////////////////////////////
|
|
744
675
|
|
|
745
676
|
// if (appContext) {
|
|
746
|
-
|
|
677
|
+
|
|
747
678
|
// } else {
|
|
748
|
-
|
|
679
|
+
|
|
749
680
|
// }
|
|
750
681
|
|
|
751
682
|
// /////////////////////////////////////////////
|
|
752
683
|
|
|
753
684
|
//If there is already a request in progress
|
|
754
685
|
if (refreshContext.inflightRefreshRequest) {
|
|
755
|
-
|
|
686
|
+
|
|
756
687
|
return refreshContext.inflightRefreshRequest;
|
|
757
688
|
}
|
|
758
689
|
|
|
759
690
|
/////////////////////////////////////////////////////
|
|
760
691
|
|
|
761
692
|
//Create an refresh request
|
|
762
|
-
|
|
693
|
+
|
|
763
694
|
refreshContext.inflightRefreshRequest = new Promise(function(resolve, reject) {
|
|
764
695
|
|
|
765
696
|
//Bypass the interceptor on all token refresh calls
|
|
@@ -776,14 +707,14 @@ var QikAuth = function(qik) {
|
|
|
776
707
|
//Update the user with any changes
|
|
777
708
|
//returned back from the refresh request
|
|
778
709
|
if (!res) {
|
|
779
|
-
|
|
710
|
+
|
|
780
711
|
refreshContext.inflightRefreshRequest = null;
|
|
781
712
|
return reject();
|
|
782
713
|
|
|
783
714
|
} else {
|
|
784
715
|
//Update with our new session
|
|
785
716
|
service.set(res.data);
|
|
786
|
-
|
|
717
|
+
|
|
787
718
|
|
|
788
719
|
dispatch();
|
|
789
720
|
}
|
|
@@ -799,12 +730,12 @@ var QikAuth = function(qik) {
|
|
|
799
730
|
|
|
800
731
|
})
|
|
801
732
|
.catch(function(err) {
|
|
802
|
-
|
|
733
|
+
|
|
803
734
|
|
|
804
735
|
//TODO Check if invalid_refresh_token
|
|
805
|
-
|
|
806
736
|
|
|
807
|
-
|
|
737
|
+
|
|
738
|
+
|
|
808
739
|
setTimeout(function() {
|
|
809
740
|
refreshContext.inflightRefreshRequest = null;
|
|
810
741
|
});
|
|
@@ -845,7 +776,7 @@ var QikAuth = function(qik) {
|
|
|
845
776
|
service.set(null);
|
|
846
777
|
}
|
|
847
778
|
|
|
848
|
-
|
|
779
|
+
|
|
849
780
|
retryCount = 0;
|
|
850
781
|
|
|
851
782
|
dispatch();
|
|
@@ -857,7 +788,7 @@ var QikAuth = function(qik) {
|
|
|
857
788
|
retryCount = 0;
|
|
858
789
|
dispatch();
|
|
859
790
|
// } else {
|
|
860
|
-
|
|
791
|
+
|
|
861
792
|
// retryCount++;
|
|
862
793
|
// service.sync();
|
|
863
794
|
// }
|
|
@@ -897,7 +828,7 @@ var QikAuth = function(qik) {
|
|
|
897
828
|
if (!user) {
|
|
898
829
|
|
|
899
830
|
//But there is an application token
|
|
900
|
-
if(qik.applicationToken) {
|
|
831
|
+
if (qik.applicationToken) {
|
|
901
832
|
//use that instead
|
|
902
833
|
return qik.applicationToken;
|
|
903
834
|
}
|
|
@@ -952,11 +883,11 @@ var QikAuth = function(qik) {
|
|
|
952
883
|
if (accessToken) {
|
|
953
884
|
//Set the token of the request as the user's access token
|
|
954
885
|
originalRequest.headers['Authorization'] = `Bearer ${accessToken}`;
|
|
955
|
-
|
|
886
|
+
|
|
956
887
|
|
|
957
888
|
} else {
|
|
958
889
|
//Return the original request without a token
|
|
959
|
-
|
|
890
|
+
|
|
960
891
|
return originalRequest;
|
|
961
892
|
}
|
|
962
893
|
|
|
@@ -964,7 +895,7 @@ var QikAuth = function(qik) {
|
|
|
964
895
|
|
|
965
896
|
//If no refresh token
|
|
966
897
|
if (!refreshToken) {
|
|
967
|
-
|
|
898
|
+
|
|
968
899
|
|
|
969
900
|
//Continue with the original request
|
|
970
901
|
return originalRequest;
|
|
@@ -997,14 +928,14 @@ var QikAuth = function(qik) {
|
|
|
997
928
|
//Refresh the token
|
|
998
929
|
await service.refreshAccessToken(refreshToken)
|
|
999
930
|
.then(function(newToken) {
|
|
1000
|
-
|
|
931
|
+
|
|
1001
932
|
//Update the original request with our new token
|
|
1002
933
|
originalRequest.headers['Authorization'] = `Bearer ${newToken}`;
|
|
1003
934
|
//And continue onward
|
|
1004
935
|
return resolve(originalRequest);
|
|
1005
936
|
})
|
|
1006
937
|
.catch(function(err) {
|
|
1007
|
-
|
|
938
|
+
|
|
1008
939
|
return reject(err);
|
|
1009
940
|
});
|
|
1010
941
|
});
|
|
@@ -1028,7 +959,7 @@ var QikAuth = function(qik) {
|
|
|
1028
959
|
//Get the response status
|
|
1029
960
|
var status = (err && err.response && err.response.status) || err.status;
|
|
1030
961
|
|
|
1031
|
-
|
|
962
|
+
|
|
1032
963
|
switch (status) {
|
|
1033
964
|
case 401:
|
|
1034
965
|
service.logout();
|
|
@@ -1062,7 +993,7 @@ export default QikAuth;</code></pre>
|
|
|
1062
993
|
<br class="clear">
|
|
1063
994
|
|
|
1064
995
|
<footer>
|
|
1065
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on
|
|
996
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Thu Sep 28 2023 07:24:39 GMT+1000 (Australian Eastern Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
1066
997
|
</footer>
|
|
1067
998
|
|
|
1068
999
|
<script>prettyPrint();</script>
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
<nav >
|
|
29
29
|
|
|
30
|
-
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="access.html">access</a><ul class='methods'><li data-type='method'><a href="access.html#.actionableScopes">actionableScopes</a></li><li data-type='method'><a href="access.html#.allPermissions">allPermissions</a></li><li data-type='method'><a href="access.html#.allPermissionTypes">allPermissionTypes</a></li><li data-type='method'><a href="access.html#.allUserScopes">allUserScopes</a></li><li data-type='method'><a href="access.html#.canCreate">canCreate</a></li><li data-type='method'><a href="access.html#.canDeleteItem">canDeleteItem</a></li><li data-type='method'><a href="access.html#.canEditItem">canEditItem</a></li><li data-type='method'><a href="access.html#.canEraseItem">canEraseItem</a></li><li data-type='method'><a href="access.html#.canKnowOf">canKnowOf</a></li><li data-type='method'><a href="access.html#.canListItem">canListItem</a></li><li data-type='method'><a href="access.html#.canRestoreItem">canRestoreItem</a></li><li data-type='method'><a href="access.html#.canViewItem">canViewItem</a></li><li data-type='method'><a href="access.html#.checkActionAccess">checkActionAccess</a></li><li data-type='method'><a href="access.html#.getAllDescendants">getAllDescendants</a></li><li data-type='method'><a href="access.html#.has">has</a></li><li data-type='method'><a href="access.html#.hashPermissions">hashPermissions</a></li><li data-type='method'><a href="access.html#.isAdministrator">isAdministrator</a></li><li data-type='method'><a href="access.html#.isOwner">isOwner</a></li></ul></li><li><a href="api.html">api</a><ul class='methods'><li data-type='method'><a href="api.html#.delete">delete</a></li><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li><li data-type='method'><a href="api.html#.get">get</a></li><li data-type='method'><a href="api.html#.patch">patch</a></li><li data-type='method'><a href="api.html#.post">post</a></li><li data-type='method'><a href="api.html#.put">put</a></li></ul></li><li><a href="auth.html">auth</a><ul class='methods'><li data-type='method'><a href="auth.html#.changeOrganisation">changeOrganisation</a></li><li data-type='method'><a href="auth.html#.ensureValidToken">ensureValidToken</a></li><li data-type='method'><a href="auth.html#.getCurrentToken">getCurrentToken</a></li><li data-type='method'><a href="auth.html#.getCurrentUser">getCurrentUser</a></li><li data-type='method'><a href="auth.html#.impersonate">impersonate</a></li><li data-type='method'><a href="auth.html#.login">login</a></li><li data-type='method'><a href="auth.html#.logout">logout</a></li><li data-type='method'><a href="auth.html#.retrieveUserFromResetToken">retrieveUserFromResetToken</a></li><li data-type='method'><a href="auth.html#.sendResetPasswordRequest">sendResetPasswordRequest</a></li><li data-type='method'><a href="auth.html#.set">set</a></li><li data-type='method'><a href="auth.html#.sync">sync</a></li><li data-type='method'><a href="auth.html#.updateUserWithToken">updateUserWithToken</a></li></ul></li><li><a href="cache.html">cache</a><ul class='methods'><li data-type='method'><a href="cache.html#.get">get</a></li><li data-type='method'><a href="cache.html#.reset">reset</a></li></ul></li><li><a href="content.html">content</a><ul class='methods'><li data-type='method'><a href="content.html#.create">create</a></li><li data-type='method'><a href="content.html#.delete">delete</a></li><li data-type='method'><a href="content.html#.get">get</a></li><li data-type='method'><a href="content.html#.getFromSlug">getFromSlug</a></li><li data-type='method'><a href="content.html#.glossary">glossary</a></li><li data-type='method'><a href="content.html#.list">list</a></li><li data-type='method'><a href="content.html#.patch">patch</a></li><li data-type='method'><a href="content.html#.restore">restore</a></li><li data-type='method'><a href="content.html#.scopeGlossary">scopeGlossary</a></li><li data-type='method'><a href="content.html#.update">update</a></li><li data-type='method'><a href="content.html#.validateField">validateField</a></li><li data-type='method'><a href="content.html#.variables">variables</a></li></ul></li><li><a href="files.html">files</a><ul class='methods'><li data-type='method'><a href="files.html#.downloadUrl">downloadUrl</a></li><li data-type='method'><a href="files.html#.filesize">filesize</a></li><li data-type='method'><a href="files.html#.getBinaryTypeFromMime">getBinaryTypeFromMime</a></li><li data-type='method'><a href="files.html#.mediaUrl">mediaUrl</a></li></ul></li><li><a href="filter.html">filter</a><ul class='methods'><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterOperators">activeFilterOperators</a></li><li data-type='method'><a href="filter.html#.activeFilters">activeFilters</a></li><li data-type='method'><a href="filter.html#.activeFilterValues">activeFilterValues</a></li><li data-type='method'><a href="filter.html#.filterChangeString">filterChangeString</a></li><li data-type='method'><a href="filter.html#.isValidFilter">isValidFilter</a></li></ul></li><li><a href="socket.html">socket</a><ul class='methods'><li data-type='method'><a href="socket.html#.channel">channel</a></li><li data-type='method'><a href="socket.html#.close">close</a></li><li data-type='method'><a href="socket.html#.connect">connect</a></li><li data-type='method'><a href="socket.html#.subscribe">subscribe</a></li><li data-type='method'><a href="socket.html#.unsubscribe">unsubscribe</a></li></ul></li><li><a href="system.html">system</a><ul class='methods'><li data-type='method'><a href="system.html#.countries">countries</a></li></ul></li></ul>
|
|
30
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="access.html">access</a><ul class='methods'><li data-type='method'><a href="access.html#.actionableScopes">actionableScopes</a></li><li data-type='method'><a href="access.html#.allPermissions">allPermissions</a></li><li data-type='method'><a href="access.html#.allPermissionTypes">allPermissionTypes</a></li><li data-type='method'><a href="access.html#.allUserScopes">allUserScopes</a></li><li data-type='method'><a href="access.html#.canCreate">canCreate</a></li><li data-type='method'><a href="access.html#.canDeleteItem">canDeleteItem</a></li><li data-type='method'><a href="access.html#.canEditItem">canEditItem</a></li><li data-type='method'><a href="access.html#.canEraseItem">canEraseItem</a></li><li data-type='method'><a href="access.html#.canKnowOf">canKnowOf</a></li><li data-type='method'><a href="access.html#.canListItem">canListItem</a></li><li data-type='method'><a href="access.html#.canRestoreItem">canRestoreItem</a></li><li data-type='method'><a href="access.html#.canViewItem">canViewItem</a></li><li data-type='method'><a href="access.html#.checkActionAccess">checkActionAccess</a></li><li data-type='method'><a href="access.html#.getAllDescendants">getAllDescendants</a></li><li data-type='method'><a href="access.html#.has">has</a></li><li data-type='method'><a href="access.html#.hashPermissions">hashPermissions</a></li><li data-type='method'><a href="access.html#.isAdministrator">isAdministrator</a></li><li data-type='method'><a href="access.html#.isOwner">isOwner</a></li></ul></li><li><a href="api.html">api</a><ul class='methods'><li data-type='method'><a href="api.html#.delete">delete</a></li><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li><li data-type='method'><a href="api.html#.get">get</a></li><li data-type='method'><a href="api.html#.patch">patch</a></li><li data-type='method'><a href="api.html#.post">post</a></li><li data-type='method'><a href="api.html#.put">put</a></li></ul></li><li><a href="auth.html">auth</a><ul class='methods'><li data-type='method'><a href="auth.html#.changeOrganisation">changeOrganisation</a></li><li data-type='method'><a href="auth.html#.ensureValidToken">ensureValidToken</a></li><li data-type='method'><a href="auth.html#.getCurrentToken">getCurrentToken</a></li><li data-type='method'><a href="auth.html#.getCurrentUser">getCurrentUser</a></li><li data-type='method'><a href="auth.html#.impersonate">impersonate</a></li><li data-type='method'><a href="auth.html#.login">login</a></li><li data-type='method'><a href="auth.html#.logout">logout</a></li><li data-type='method'><a href="auth.html#.retrieveUserFromResetToken">retrieveUserFromResetToken</a></li><li data-type='method'><a href="auth.html#.sendResetPasswordRequest">sendResetPasswordRequest</a></li><li data-type='method'><a href="auth.html#.set">set</a></li><li data-type='method'><a href="auth.html#.sync">sync</a></li><li data-type='method'><a href="auth.html#.updateUserWithToken">updateUserWithToken</a></li></ul></li><li><a href="cache.html">cache</a><ul class='methods'><li data-type='method'><a href="cache.html#.get">get</a></li><li data-type='method'><a href="cache.html#.reset">reset</a></li></ul></li><li><a href="content.html">content</a><ul class='methods'><li data-type='method'><a href="content.html#.create">create</a></li><li data-type='method'><a href="content.html#.delete">delete</a></li><li data-type='method'><a href="content.html#.get">get</a></li><li data-type='method'><a href="content.html#.getFromSlug">getFromSlug</a></li><li data-type='method'><a href="content.html#.glossary">glossary</a></li><li data-type='method'><a href="content.html#.list">list</a></li><li data-type='method'><a href="content.html#.patch">patch</a></li><li data-type='method'><a href="content.html#.restore">restore</a></li><li data-type='method'><a href="content.html#.scopeGlossary">scopeGlossary</a></li><li data-type='method'><a href="content.html#.update">update</a></li><li data-type='method'><a href="content.html#.validateField">validateField</a></li><li data-type='method'><a href="content.html#.variables">variables</a></li></ul></li><li><a href="files.html">files</a><ul class='methods'><li data-type='method'><a href="files.html#.downloadUrl">downloadUrl</a></li><li data-type='method'><a href="files.html#.filesize">filesize</a></li><li data-type='method'><a href="files.html#.getBinaryTypeFromMime">getBinaryTypeFromMime</a></li><li data-type='method'><a href="files.html#.mediaUrl">mediaUrl</a></li></ul></li><li><a href="filter.html">filter</a><ul class='methods'><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterOperators">activeFilterOperators</a></li><li data-type='method'><a href="filter.html#.activeFilters">activeFilters</a></li><li data-type='method'><a href="filter.html#.activeFilterValues">activeFilterValues</a></li><li data-type='method'><a href="filter.html#.filterChangeString">filterChangeString</a></li><li data-type='method'><a href="filter.html#.isValidFilter">isValidFilter</a></li></ul></li><li><a href="socket.html">socket</a><ul class='methods'><li data-type='method'><a href="socket.html#.channel">channel</a></li><li data-type='method'><a href="socket.html#.close">close</a></li><li data-type='method'><a href="socket.html#.connect">connect</a></li><li data-type='method'><a href="socket.html#.reconnect">reconnect</a></li><li data-type='method'><a href="socket.html#.subscribe">subscribe</a></li><li data-type='method'><a href="socket.html#.unsubscribe">unsubscribe</a></li></ul></li><li><a href="system.html">system</a><ul class='methods'><li data-type='method'><a href="system.html#.countries">countries</a></li></ul></li></ul>
|
|
31
31
|
</nav>
|
|
32
32
|
|
|
33
33
|
<div id="main">
|
|
@@ -118,7 +118,7 @@ export default QikCache;</code></pre>
|
|
|
118
118
|
<br class="clear">
|
|
119
119
|
|
|
120
120
|
<footer>
|
|
121
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on
|
|
121
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Thu Sep 28 2023 07:24:39 GMT+1000 (Australian Eastern Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
122
122
|
</footer>
|
|
123
123
|
|
|
124
124
|
<script>prettyPrint();</script>
|