@qikdev/sdk 0.1.10 → 0.1.16
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 +2 -2
- package/package.json +2 -2
- package/src/api/qik.api.js +33 -7
- package/src/api/qik.auth.js +50 -33
- package/src/api/qik.content.js +94 -0
- package/src/api/qik.core.js +20 -6
- package/src/index.js +2 -1
- package/src/version.js +1 -1
- package/test/index.spec.js +4 -0
- package/dist/index.js +0 -1
- package/dist/index.js.LICENSE.txt +0 -8
- package/webpack.config.js +0 -46
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qikdev/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Promise based Javascript SDK",
|
|
6
6
|
"scripts": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"test:watch": "mocha --colors -w ./test/*.spec.js",
|
|
11
11
|
"document": "jsdoc -r . -d docs -c jsdoc.conf README.md"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
13
|
+
"exports": "./src/index.js",
|
|
14
14
|
"homepage": "https://qik.dev",
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://support.qik.dev"
|
package/src/api/qik.api.js
CHANGED
|
@@ -44,7 +44,7 @@ var QikAPI = function(qik) {
|
|
|
44
44
|
*/
|
|
45
45
|
var defaultCache;
|
|
46
46
|
|
|
47
|
-
if (
|
|
47
|
+
if (typeof window !== 'undefined') {
|
|
48
48
|
defaultCache = qik.cache.get('api');
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -54,6 +54,18 @@ var QikAPI = function(qik) {
|
|
|
54
54
|
const defaultAdapter = axios.defaults.adapter
|
|
55
55
|
// console.log('DEFAULT ADAPTER', defaultAdapter)
|
|
56
56
|
|
|
57
|
+
/////////////////////////////////////////////////////
|
|
58
|
+
|
|
59
|
+
function getRequestCacheKey(config) {
|
|
60
|
+
|
|
61
|
+
var key = _.compact([
|
|
62
|
+
config.method,
|
|
63
|
+
config.url,
|
|
64
|
+
JSON.stringify({ user: qik.auth.getCurrentUser(), params: config.params, data: config.data }),
|
|
65
|
+
]).join('-')
|
|
66
|
+
|
|
67
|
+
return key;
|
|
68
|
+
}
|
|
57
69
|
|
|
58
70
|
///////////////////////////////////////
|
|
59
71
|
|
|
@@ -96,7 +108,7 @@ var QikAPI = function(qik) {
|
|
|
96
108
|
if (useCache) {
|
|
97
109
|
|
|
98
110
|
//Generate the cache key from the request
|
|
99
|
-
var cacheKey =
|
|
111
|
+
var cacheKey = getRequestCacheKey(config);
|
|
100
112
|
|
|
101
113
|
//If we have the cachedResponse version
|
|
102
114
|
cachedResponse = useCache.get(cacheKey);
|
|
@@ -165,6 +177,10 @@ var QikAPI = function(qik) {
|
|
|
165
177
|
// Add relative date and timezone to every request
|
|
166
178
|
instance.interceptors.request.use(function(config) {
|
|
167
179
|
|
|
180
|
+
if(config.withoutToken) {
|
|
181
|
+
return config;
|
|
182
|
+
}
|
|
183
|
+
|
|
168
184
|
config.headers['qik-request-date'] = new Date().getTime();
|
|
169
185
|
if (Intl) {
|
|
170
186
|
config.headers['qik-request-timezone'] = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
@@ -172,8 +188,18 @@ var QikAPI = function(qik) {
|
|
|
172
188
|
|
|
173
189
|
config.headers['qik-api-version'] = version;
|
|
174
190
|
|
|
175
|
-
return config;
|
|
176
191
|
|
|
192
|
+
var token = qik.auth.getCurrentToken();
|
|
193
|
+
|
|
194
|
+
if (token) {
|
|
195
|
+
config.headers['Authorization'] = `Bearer ${token}`;
|
|
196
|
+
|
|
197
|
+
if (config.params && config.params.access_token) {
|
|
198
|
+
delete config.params.access_token;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return config;
|
|
177
203
|
});
|
|
178
204
|
|
|
179
205
|
/////////////////////////////////////////////////////
|
|
@@ -184,7 +210,6 @@ var QikAPI = function(qik) {
|
|
|
184
210
|
}, function(err) {
|
|
185
211
|
|
|
186
212
|
if (axios.isCancel(err)) {
|
|
187
|
-
console.log('Request cancelled');
|
|
188
213
|
return Promise.reject(err);
|
|
189
214
|
}
|
|
190
215
|
|
|
@@ -199,7 +224,7 @@ var QikAPI = function(qik) {
|
|
|
199
224
|
case 502:
|
|
200
225
|
case 504:
|
|
201
226
|
//Retry until it works
|
|
202
|
-
console.log(`qik.api > ${status} connection error retrying`)
|
|
227
|
+
// console.log(`qik.api > ${status} connection error retrying`)
|
|
203
228
|
return instance.request(err.config);
|
|
204
229
|
break;
|
|
205
230
|
case 404:
|
|
@@ -207,7 +232,7 @@ var QikAPI = function(qik) {
|
|
|
207
232
|
break;
|
|
208
233
|
default:
|
|
209
234
|
//Some other error, likely a problem connecting to the server
|
|
210
|
-
console.log('qik.api > connection error', status, err);
|
|
235
|
+
// console.log('qik.api > connection error', status, err);
|
|
211
236
|
break;
|
|
212
237
|
}
|
|
213
238
|
|
|
@@ -338,7 +363,7 @@ var QikAPI = function(qik) {
|
|
|
338
363
|
var queryParameters = qik.utils.mapParameters(params);
|
|
339
364
|
|
|
340
365
|
if (queryParameters.length) {
|
|
341
|
-
url +=
|
|
366
|
+
url += `?${queryParameters}`;
|
|
342
367
|
}
|
|
343
368
|
|
|
344
369
|
return url;
|
|
@@ -354,6 +379,7 @@ var QikAPI = function(qik) {
|
|
|
354
379
|
//Get the current token from QikAuth
|
|
355
380
|
var CurrentQikToken = qik.auth.getCurrentToken();
|
|
356
381
|
|
|
382
|
+
|
|
357
383
|
//Check to see if we have a token and none has been explicity set
|
|
358
384
|
if (!params['access_token'] && CurrentQikToken) {
|
|
359
385
|
//Use the current token by default
|
package/src/api/qik.auth.js
CHANGED
|
@@ -30,7 +30,7 @@ var QikAuth = function(qik) {
|
|
|
30
30
|
///////////////////////////////////////////////////
|
|
31
31
|
|
|
32
32
|
var service = {
|
|
33
|
-
debug:
|
|
33
|
+
debug: true,
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
Object.defineProperty(service, 'store', {
|
|
@@ -43,7 +43,6 @@ var QikAuth = function(qik) {
|
|
|
43
43
|
var dispatcher = new EventDispatcher();
|
|
44
44
|
dispatcher.bootstrap(service);
|
|
45
45
|
|
|
46
|
-
// console.log('New Dispatcher!', dispatcher)
|
|
47
46
|
|
|
48
47
|
///////////////////////////////////////////////////
|
|
49
48
|
///////////////////////////////////////////////////
|
|
@@ -91,7 +90,6 @@ var QikAuth = function(qik) {
|
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
|
|
94
|
-
|
|
95
93
|
///////////////////////////////////////////////////
|
|
96
94
|
|
|
97
95
|
/**
|
|
@@ -262,7 +260,7 @@ var QikAuth = function(qik) {
|
|
|
262
260
|
* @param {Object} options.disableAutoAuthentication Disable automatic authentication, if true, will not set the current user session
|
|
263
261
|
* @return {Promise} Returns a promise that either resolves with the logged in user session, or rejects with the responding error from the server
|
|
264
262
|
*/
|
|
265
|
-
service.login = function(credentials, options) {
|
|
263
|
+
service.login = async function(credentials, options) {
|
|
266
264
|
|
|
267
265
|
if (!options) {
|
|
268
266
|
options = {};
|
|
@@ -359,7 +357,7 @@ var QikAuth = function(qik) {
|
|
|
359
357
|
* @param {Object} options Extra options and configuration for the request
|
|
360
358
|
* @return {Promise} Returns a promise that either resolves to the new authenticated session, or rejects with the responding error from the server
|
|
361
359
|
*/
|
|
362
|
-
service.signup = function(credentials, options) {
|
|
360
|
+
service.signup = async function(credentials, options) {
|
|
363
361
|
|
|
364
362
|
if (!options) {
|
|
365
363
|
options = {};
|
|
@@ -479,7 +477,7 @@ var QikAuth = function(qik) {
|
|
|
479
477
|
* If not specified or false, will assume it's a Qik global user that is resetting their password.
|
|
480
478
|
* @return {Promise} Returns a promise that resolves with the reset session details
|
|
481
479
|
*/
|
|
482
|
-
service.retrieveUserFromResetToken = function(resetToken, options) {
|
|
480
|
+
service.retrieveUserFromResetToken = async function(resetToken, options) {
|
|
483
481
|
|
|
484
482
|
if (!options) {
|
|
485
483
|
options = {};
|
|
@@ -526,7 +524,7 @@ var QikAuth = function(qik) {
|
|
|
526
524
|
* @param {Object} options other options for the request
|
|
527
525
|
* @return {Promise} Returns a promise that resolves with the reset session details
|
|
528
526
|
*/
|
|
529
|
-
service.updateUserWithToken = function(resetToken, body, options) {
|
|
527
|
+
service.updateUserWithToken = async function(resetToken, body, options) {
|
|
530
528
|
|
|
531
529
|
if (!options) {
|
|
532
530
|
options = {};
|
|
@@ -692,14 +690,16 @@ var QikAuth = function(qik) {
|
|
|
692
690
|
refreshContext.inflightRefreshRequest = new Promise(function(resolve, reject) {
|
|
693
691
|
|
|
694
692
|
|
|
695
|
-
log(`qik.auth > refresh token
|
|
693
|
+
log(`qik.auth > refresh token`);
|
|
696
694
|
|
|
697
695
|
//Bypass the interceptor on all token refresh calls
|
|
698
696
|
//Because we don't need to add the access token etc onto it
|
|
697
|
+
|
|
699
698
|
qik.api.post(`/user/refresh`, {
|
|
700
699
|
refreshToken: refreshToken
|
|
701
700
|
}, {
|
|
702
701
|
bypassInterceptor: true,
|
|
702
|
+
withoutToken:true,
|
|
703
703
|
})
|
|
704
704
|
.then(function tokenRefreshComplete(res) {
|
|
705
705
|
|
|
@@ -710,13 +710,10 @@ var QikAuth = function(qik) {
|
|
|
710
710
|
refreshContext.inflightRefreshRequest = null;
|
|
711
711
|
return reject();
|
|
712
712
|
|
|
713
|
-
} else {
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
store.user = res.data;
|
|
718
|
-
}
|
|
719
|
-
log(`qik.auth > token refreshed > ${res.data}`);
|
|
713
|
+
} else {
|
|
714
|
+
//Update with our new session
|
|
715
|
+
store.user = res.data;
|
|
716
|
+
log(`qik.auth > token refreshed`);
|
|
720
717
|
|
|
721
718
|
dispatch();
|
|
722
719
|
}
|
|
@@ -732,7 +729,7 @@ var QikAuth = function(qik) {
|
|
|
732
729
|
|
|
733
730
|
})
|
|
734
731
|
.catch(function(err) {
|
|
735
|
-
|
|
732
|
+
log('qik.auth > refresh token failed error', err);
|
|
736
733
|
|
|
737
734
|
//TODO Check if invalid_refresh_token
|
|
738
735
|
|
|
@@ -769,27 +766,26 @@ var QikAuth = function(qik) {
|
|
|
769
766
|
|
|
770
767
|
service.sync = function() {
|
|
771
768
|
|
|
772
|
-
// console.log('Sync with server', store.user)
|
|
773
769
|
return qik.api.get('/user')
|
|
774
770
|
.then(function(res) {
|
|
775
771
|
|
|
776
|
-
// console.log('sync response', res);
|
|
777
772
|
|
|
778
773
|
if (res.data) {
|
|
779
774
|
if (store.user) {
|
|
780
|
-
Object.assign(store.user, res.data);
|
|
775
|
+
Object.assign(store.user.session, res.data);
|
|
781
776
|
}
|
|
782
777
|
} else {
|
|
783
778
|
store.user = null;
|
|
784
779
|
}
|
|
785
|
-
|
|
780
|
+
|
|
781
|
+
log('qik.auth > server session synced');
|
|
786
782
|
retryCount = 0;
|
|
787
783
|
|
|
788
784
|
dispatch();
|
|
789
785
|
})
|
|
790
786
|
.catch(function(err) {
|
|
787
|
+
|
|
791
788
|
// if (retryCount > 2) {
|
|
792
|
-
console.log('auth sync not logged in');
|
|
793
789
|
store.user = null;
|
|
794
790
|
retryCount = 0;
|
|
795
791
|
dispatch();
|
|
@@ -816,17 +812,29 @@ var QikAuth = function(qik) {
|
|
|
816
812
|
|
|
817
813
|
|
|
818
814
|
service.getCurrentToken = function() {
|
|
819
|
-
|
|
815
|
+
|
|
816
|
+
var details = service.getCurrentUser();
|
|
817
|
+
|
|
818
|
+
if (!details) {
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
var { token } = details;
|
|
823
|
+
if (!token) {
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
return token.accessToken;
|
|
828
|
+
|
|
820
829
|
}
|
|
821
830
|
|
|
822
831
|
/////////////////////////////////////////////////////
|
|
823
832
|
|
|
824
|
-
qik.api.interceptors.request.use(function(config) {
|
|
833
|
+
qik.api.interceptors.request.use(async function(config) {
|
|
825
834
|
|
|
826
835
|
//If we want to bypass the interceptor
|
|
827
836
|
//then just return the request
|
|
828
837
|
if (config.bypassInterceptor) {
|
|
829
|
-
console.log('auth interceptor was bypassed');
|
|
830
838
|
return config;
|
|
831
839
|
}
|
|
832
840
|
|
|
@@ -838,9 +846,21 @@ var QikAuth = function(qik) {
|
|
|
838
846
|
//Get the original request
|
|
839
847
|
var originalRequest = config;
|
|
840
848
|
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
var
|
|
849
|
+
//////////////////////////////
|
|
850
|
+
|
|
851
|
+
var userDetails = await service.getCurrentUser();
|
|
852
|
+
var accessToken;
|
|
853
|
+
var refreshToken;
|
|
854
|
+
var expiryDate;
|
|
855
|
+
|
|
856
|
+
if (userDetails) {
|
|
857
|
+
var { token } = userDetails;
|
|
858
|
+
if (token) {
|
|
859
|
+
accessToken = token.accessToken;
|
|
860
|
+
refreshToken = token.refreshToken;
|
|
861
|
+
expiryDate = token.expires;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
844
864
|
|
|
845
865
|
//////////////////////////////
|
|
846
866
|
|
|
@@ -874,11 +894,10 @@ var QikAuth = function(qik) {
|
|
|
874
894
|
|
|
875
895
|
//Give us a bit of buffer incase some of our images
|
|
876
896
|
//are still loading
|
|
877
|
-
now.setSeconds(now.getSeconds() +
|
|
897
|
+
now.setSeconds(now.getSeconds() + 5);
|
|
878
898
|
|
|
879
899
|
/////////////////////////////////////////////////////
|
|
880
900
|
|
|
881
|
-
var expiryDate = _.get(store, 'user.expires');
|
|
882
901
|
var expires = new Date(expiryDate);
|
|
883
902
|
|
|
884
903
|
//If the token is still fresh
|
|
@@ -886,7 +905,7 @@ var QikAuth = function(qik) {
|
|
|
886
905
|
//Return the original request
|
|
887
906
|
return originalRequest;
|
|
888
907
|
}
|
|
889
|
-
|
|
908
|
+
|
|
890
909
|
/////////////////////////////////////////////////////
|
|
891
910
|
|
|
892
911
|
log('qik.auth > token expired');
|
|
@@ -896,14 +915,13 @@ var QikAuth = function(qik) {
|
|
|
896
915
|
//Refresh the token
|
|
897
916
|
service.refreshAccessToken(refreshToken)
|
|
898
917
|
.then(function(newToken) {
|
|
899
|
-
log('qik.auth > token refreshed'
|
|
918
|
+
log('qik.auth > token refreshed');
|
|
900
919
|
//Update the original request with our new token
|
|
901
920
|
originalRequest.headers['Authorization'] = `Bearer ${newToken}`;
|
|
902
921
|
//And continue onward
|
|
903
922
|
return resolve(originalRequest);
|
|
904
923
|
})
|
|
905
924
|
.catch(function(err) {
|
|
906
|
-
console.log('ERRRRRR', err);
|
|
907
925
|
log('qik.auth > token refresh rejected', err);
|
|
908
926
|
return reject(err);
|
|
909
927
|
});
|
|
@@ -928,7 +946,6 @@ var QikAuth = function(qik) {
|
|
|
928
946
|
log('qik.auth > error', status);
|
|
929
947
|
switch (status) {
|
|
930
948
|
case 401:
|
|
931
|
-
console.log('logout from 401')
|
|
932
949
|
service.logout();
|
|
933
950
|
break;
|
|
934
951
|
default:
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
|
|
4
|
+
///////////////////////////////////////////////////
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new QikContent instance.
|
|
8
|
+
* This module provides a number of helper functions for creating, reading, updating and deleting content
|
|
9
|
+
* @alias content
|
|
10
|
+
* @constructor
|
|
11
|
+
* @hideconstructor
|
|
12
|
+
* @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.
|
|
13
|
+
*/
|
|
14
|
+
export default function(qik) {
|
|
15
|
+
|
|
16
|
+
if (!qik.api) {
|
|
17
|
+
throw new Error(`Can't Instantiate QikContent before QikAPI exists`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
///////////////////////////////////////////////////
|
|
21
|
+
|
|
22
|
+
var service = {
|
|
23
|
+
debug: false,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
///////////////////////////////////////////////////
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* Retrieves a list of records matching the provided criteria
|
|
31
|
+
* @alias content.list
|
|
32
|
+
* @param {String} type The type or definition of records we want to retrieve
|
|
33
|
+
* @param {Object} options The options for our query
|
|
34
|
+
* @param {Object} options.search Freeform text keywords
|
|
35
|
+
* @param {Object} options.sort How to sort the results
|
|
36
|
+
* @param {Object} options.filter How to filter the results
|
|
37
|
+
* @example
|
|
38
|
+
*
|
|
39
|
+
*
|
|
40
|
+
* QikContent.list('profile', {
|
|
41
|
+
* search:'Jim',
|
|
42
|
+
* sort:{
|
|
43
|
+
* key:'age',
|
|
44
|
+
* direction:'asc',
|
|
45
|
+
* type:'integer',
|
|
46
|
+
* },
|
|
47
|
+
* filter:{
|
|
48
|
+
* operator:'and',
|
|
49
|
+
* filters:[{
|
|
50
|
+
* key:'age',
|
|
51
|
+
* comparator:'>',
|
|
52
|
+
* value:5,
|
|
53
|
+
* }],
|
|
54
|
+
* },
|
|
55
|
+
* })
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
service.list = async function(type, options) {
|
|
59
|
+
|
|
60
|
+
console.log('Get the things', type, options);
|
|
61
|
+
return qik.api.post(`/content/${type}/list`, options);
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
///////////////////////////////////////////////////
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* Create an item
|
|
70
|
+
* @alias content.create
|
|
71
|
+
* @param {String} type The type or definition of the record we want to create
|
|
72
|
+
* @param {Object} data The data for our new record
|
|
73
|
+
* @example
|
|
74
|
+
*
|
|
75
|
+
*
|
|
76
|
+
* QikContent.create('profile', {
|
|
77
|
+
* firstName:'Michael',
|
|
78
|
+
* lastName:'Jordan',
|
|
79
|
+
* gender:'male',
|
|
80
|
+
* meta:{
|
|
81
|
+
* scopes:['61eca4746971e75c1fc670cf'],
|
|
82
|
+
* }
|
|
83
|
+
* })
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
service.create = async function(type, data) {
|
|
87
|
+
return qik.api.post(`/content/${type}/create`, data);
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
return service;
|
|
93
|
+
|
|
94
|
+
}
|
package/src/api/qik.core.js
CHANGED
|
@@ -5,6 +5,7 @@ import QikAuth from './qik.auth.js';
|
|
|
5
5
|
import QikUtils from './qik.utils.js';
|
|
6
6
|
import QikCache from './qik.cache.js';
|
|
7
7
|
import QikAccess from './qik.access.js';
|
|
8
|
+
import QikContent from './qik.content.js';
|
|
8
9
|
import { EventDispatcher } from './qik.utils.js';
|
|
9
10
|
|
|
10
11
|
///////////////////////////////////////
|
|
@@ -88,7 +89,7 @@ export default function(options) {
|
|
|
88
89
|
* and storing API requests and other information in memory
|
|
89
90
|
* @type {QikCache}
|
|
90
91
|
*/
|
|
91
|
-
|
|
92
|
+
const cache = QikCache;
|
|
92
93
|
Object.defineProperty(core, 'cache', {
|
|
93
94
|
value: cache,
|
|
94
95
|
writable: false,
|
|
@@ -100,7 +101,7 @@ export default function(options) {
|
|
|
100
101
|
* with Qik data
|
|
101
102
|
* @type {QikUtils}
|
|
102
103
|
*/
|
|
103
|
-
|
|
104
|
+
const utils = QikUtils;
|
|
104
105
|
Object.defineProperty(core, 'utils', {
|
|
105
106
|
value: utils,
|
|
106
107
|
writable: false,
|
|
@@ -109,7 +110,7 @@ export default function(options) {
|
|
|
109
110
|
///////////////////////////////////////
|
|
110
111
|
|
|
111
112
|
//Create a new global dispatcher so we can trigger events
|
|
112
|
-
|
|
113
|
+
const dispatcher = new EventDispatcher();
|
|
113
114
|
dispatcher.bootstrap(core);
|
|
114
115
|
|
|
115
116
|
//Set the function
|
|
@@ -131,7 +132,7 @@ export default function(options) {
|
|
|
131
132
|
* that works in conjunction with the other Qik modules
|
|
132
133
|
* @type {QikAPI}
|
|
133
134
|
*/
|
|
134
|
-
|
|
135
|
+
const api = new QikAPI(core);
|
|
135
136
|
Object.defineProperty(core, 'api', {
|
|
136
137
|
value: api,
|
|
137
138
|
writable: false,
|
|
@@ -143,7 +144,7 @@ export default function(options) {
|
|
|
143
144
|
* and other user/application specific functionality
|
|
144
145
|
* @type {QikAuth}
|
|
145
146
|
*/
|
|
146
|
-
|
|
147
|
+
const auth = new QikAuth(core);
|
|
147
148
|
Object.defineProperty(core, 'auth', {
|
|
148
149
|
value: auth,
|
|
149
150
|
writable: false,
|
|
@@ -155,12 +156,25 @@ export default function(options) {
|
|
|
155
156
|
* A helper service for understanding a user's access permissions
|
|
156
157
|
* @type {QikAccess}
|
|
157
158
|
*/
|
|
158
|
-
|
|
159
|
+
const access = new QikAccess(core);
|
|
159
160
|
Object.defineProperty(core, 'access', {
|
|
160
161
|
value: access,
|
|
161
162
|
writable: false,
|
|
162
163
|
});
|
|
163
164
|
|
|
165
|
+
|
|
166
|
+
///////////////////////////////////////
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* A helper service for content create, update, read and delete operations.
|
|
170
|
+
* @type {QikContent}
|
|
171
|
+
*/
|
|
172
|
+
const content = new QikContent(core);
|
|
173
|
+
Object.defineProperty(core, 'content', {
|
|
174
|
+
value: content,
|
|
175
|
+
writable: false,
|
|
176
|
+
});
|
|
177
|
+
|
|
164
178
|
///////////////////////////////////////
|
|
165
179
|
|
|
166
180
|
return core;
|
package/src/index.js
CHANGED
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '0.1.
|
|
1
|
+
export const version = '0.1.16'
|
package/test/index.spec.js
CHANGED
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("axios"),require("lodash"),require("axios-extensions")):"function"==typeof define&&define.amd?define(["axios","lodash","axios-extensions"],r):"object"==typeof exports?exports["@qikdev/sdk"]=r(require("axios"),require("lodash"),require("axios-extensions")):e["@qikdev/sdk"]=r(e.axios,e._,e["axios-extensions"])}("undefined"!=typeof self?self:this,(function(e,r,t){return(()=>{"use strict";var n={818:(e,r)=>{var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};"undefined"!=typeof window&&window.document,"object"===("undefined"==typeof self?"undefined":t(self))&&self.constructor&&self.constructor.name,"undefined"!=typeof process&&null!=process.versions&&process.versions.node},798:e=>{var r=String.prototype.replace,t=/%20/g;e.exports={default:"RFC3986",formatters:{RFC1738:function(e){return r.call(e,t,"+")},RFC3986:function(e){return String(e)}},RFC1738:"RFC1738",RFC3986:"RFC3986"}},129:(e,r,t)=>{var n=t(261),o=t(235),i=t(798);e.exports={formats:i,parse:o,stringify:n}},235:(e,r,t)=>{var n=t(769),o=Object.prototype.hasOwnProperty,i={allowDots:!1,allowPrototypes:!1,arrayLimit:20,decoder:n.decode,delimiter:"&",depth:5,parameterLimit:1e3,plainObjects:!1,strictNullHandling:!1},a=function(e,r,t){if(e){var n=t.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,i=/(\[[^[\]]*])/g,a=/(\[[^[\]]*])/.exec(n),s=a?n.slice(0,a.index):n,u=[];if(s){if(!t.plainObjects&&o.call(Object.prototype,s)&&!t.allowPrototypes)return;u.push(s)}for(var c=0;null!==(a=i.exec(n))&&c<t.depth;){if(c+=1,!t.plainObjects&&o.call(Object.prototype,a[1].slice(1,-1))&&!t.allowPrototypes)return;u.push(a[1])}return a&&u.push("["+n.slice(a.index)+"]"),function(e,r,t){for(var n=r,o=e.length-1;o>=0;--o){var i,a=e[o];if("[]"===a&&t.parseArrays)i=[].concat(n);else{i=t.plainObjects?Object.create(null):{};var s="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,u=parseInt(s,10);t.parseArrays||""!==s?!isNaN(u)&&a!==s&&String(u)===s&&u>=0&&t.parseArrays&&u<=t.arrayLimit?(i=[])[u]=n:"__proto__"!==s&&(i[s]=n):i={0:n}}n=i}return n}(u,r,t)}};e.exports=function(e,r){var t=r?n.assign({},r):{};if(null!==t.decoder&&void 0!==t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(t.ignoreQueryPrefix=!0===t.ignoreQueryPrefix,t.delimiter="string"==typeof t.delimiter||n.isRegExp(t.delimiter)?t.delimiter:i.delimiter,t.depth="number"==typeof t.depth?t.depth:i.depth,t.arrayLimit="number"==typeof t.arrayLimit?t.arrayLimit:i.arrayLimit,t.parseArrays=!1!==t.parseArrays,t.decoder="function"==typeof t.decoder?t.decoder:i.decoder,t.allowDots="boolean"==typeof t.allowDots?t.allowDots:i.allowDots,t.plainObjects="boolean"==typeof t.plainObjects?t.plainObjects:i.plainObjects,t.allowPrototypes="boolean"==typeof t.allowPrototypes?t.allowPrototypes:i.allowPrototypes,t.parameterLimit="number"==typeof t.parameterLimit?t.parameterLimit:i.parameterLimit,t.strictNullHandling="boolean"==typeof t.strictNullHandling?t.strictNullHandling:i.strictNullHandling,""===e||null==e)return t.plainObjects?Object.create(null):{};for(var s="string"==typeof e?function(e,r){for(var t={},n=r.ignoreQueryPrefix?e.replace(/^\?/,""):e,a=r.parameterLimit===1/0?void 0:r.parameterLimit,s=n.split(r.delimiter,a),u=0;u<s.length;++u){var c,l,f=s[u],p=f.indexOf("]="),d=-1===p?f.indexOf("="):p+1;-1===d?(c=r.decoder(f,i.decoder),l=r.strictNullHandling?null:""):(c=r.decoder(f.slice(0,d),i.decoder),l=r.decoder(f.slice(d+1),i.decoder)),o.call(t,c)?t[c]=[].concat(t[c]).concat(l):t[c]=l}return t}(e,t):e,u=t.plainObjects?Object.create(null):{},c=Object.keys(s),l=0;l<c.length;++l){var f=c[l],p=a(f,s[f],t);u=n.merge(u,p,t)}return n.compact(u)}},261:(e,r,t)=>{var n=t(769),o=t(798),i={brackets:function(e){return e+"[]"},indices:function(e,r){return e+"["+r+"]"},repeat:function(e){return e}},a=Array.isArray,s=Array.prototype.push,u=function(e,r){s.apply(e,a(r)?r:[r])},c=Date.prototype.toISOString,l={delimiter:"&",encode:!0,encoder:n.encode,encodeValuesOnly:!1,serializeDate:function(e){return c.call(e)},skipNulls:!1,strictNullHandling:!1},f=function e(r,t,o,i,s,c,f,p,d,h,g,y){var m=r;if("function"==typeof f?m=f(t,m):m instanceof Date&&(m=h(m)),null===m){if(i)return c&&!y?c(t,l.encoder):t;m=""}if("string"==typeof m||"number"==typeof m||"boolean"==typeof m||n.isBuffer(m))return c?[g(y?t:c(t,l.encoder))+"="+g(c(m,l.encoder))]:[g(t)+"="+g(String(m))];var v,b=[];if(void 0===m)return b;if(a(f))v=f;else{var w=Object.keys(m);v=p?w.sort(p):w}for(var k=0;k<v.length;++k){var j=v[k];s&&null===m[j]||(a(m)?u(b,e(m[j],o(t,j),o,i,s,c,f,p,d,h,g,y)):u(b,e(m[j],t+(d?"."+j:"["+j+"]"),o,i,s,c,f,p,d,h,g,y)))}return b};e.exports=function(e,r){var t=e,s=r?n.assign({},r):{};if(null!==s.encoder&&void 0!==s.encoder&&"function"!=typeof s.encoder)throw new TypeError("Encoder has to be a function.");var c=void 0===s.delimiter?l.delimiter:s.delimiter,p="boolean"==typeof s.strictNullHandling?s.strictNullHandling:l.strictNullHandling,d="boolean"==typeof s.skipNulls?s.skipNulls:l.skipNulls,h="boolean"==typeof s.encode?s.encode:l.encode,g="function"==typeof s.encoder?s.encoder:l.encoder,y="function"==typeof s.sort?s.sort:null,m=void 0!==s.allowDots&&s.allowDots,v="function"==typeof s.serializeDate?s.serializeDate:l.serializeDate,b="boolean"==typeof s.encodeValuesOnly?s.encodeValuesOnly:l.encodeValuesOnly;if(void 0===s.format)s.format=o.default;else if(!Object.prototype.hasOwnProperty.call(o.formatters,s.format))throw new TypeError("Unknown format option provided.");var w,k,j=o.formatters[s.format];"function"==typeof s.filter?t=(k=s.filter)("",t):a(s.filter)&&(w=k=s.filter);var A,O=[];if("object"!=typeof t||null===t)return"";A=s.arrayFormat in i?s.arrayFormat:"indices"in s?s.indices?"indices":"repeat":"indices";var R=i[A];w||(w=Object.keys(t)),y&&w.sort(y);for(var q=0;q<w.length;++q){var x=w[q];d&&null===t[x]||u(O,f(t[x],x,R,p,d,h?g:null,k,y,m,v,j,b))}var S=O.join(c),P=!0===s.addQueryPrefix?"?":"";return S.length>0?P+S:""}},769:e=>{var r=Object.prototype.hasOwnProperty,t=function(){for(var e=[],r=0;r<256;++r)e.push("%"+((r<16?"0":"")+r.toString(16)).toUpperCase());return e}(),n=function(e,r){for(var t=r&&r.plainObjects?Object.create(null):{},n=0;n<e.length;++n)void 0!==e[n]&&(t[n]=e[n]);return t};e.exports={arrayToObject:n,assign:function(e,r){return Object.keys(r).reduce((function(e,t){return e[t]=r[t],e}),e)},compact:function(e){for(var r=[{obj:{o:e},prop:"o"}],t=[],n=0;n<r.length;++n)for(var o=r[n],i=o.obj[o.prop],a=Object.keys(i),s=0;s<a.length;++s){var u=a[s],c=i[u];"object"==typeof c&&null!==c&&-1===t.indexOf(c)&&(r.push({obj:i,prop:u}),t.push(c))}return function(e){for(var r;e.length;){var t=e.pop();if(r=t.obj[t.prop],Array.isArray(r)){for(var n=[],o=0;o<r.length;++o)void 0!==r[o]&&n.push(r[o]);t.obj[t.prop]=n}}return r}(r)},decode:function(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(r){return e}},encode:function(e){if(0===e.length)return e;for(var r="string"==typeof e?e:String(e),n="",o=0;o<r.length;++o){var i=r.charCodeAt(o);45===i||46===i||95===i||126===i||i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122?n+=r.charAt(o):i<128?n+=t[i]:i<2048?n+=t[192|i>>6]+t[128|63&i]:i<55296||i>=57344?n+=t[224|i>>12]+t[128|i>>6&63]+t[128|63&i]:(o+=1,i=65536+((1023&i)<<10|1023&r.charCodeAt(o)),n+=t[240|i>>18]+t[128|i>>12&63]+t[128|i>>6&63]+t[128|63&i])}return n},isBuffer:function(e){return null!=e&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},merge:function e(t,o,i){if(!o)return t;if("object"!=typeof o){if(Array.isArray(t))t.push(o);else{if(!t||"object"!=typeof t)return[t,o];(i&&(i.plainObjects||i.allowPrototypes)||!r.call(Object.prototype,o))&&(t[o]=!0)}return t}if(!t||"object"!=typeof t)return[t].concat(o);var a=t;return Array.isArray(t)&&!Array.isArray(o)&&(a=n(t,i)),Array.isArray(t)&&Array.isArray(o)?(o.forEach((function(n,o){if(r.call(t,o)){var a=t[o];a&&"object"==typeof a&&n&&"object"==typeof n?t[o]=e(a,n,i):t.push(n)}else t[o]=n})),t):Object.keys(o).reduce((function(t,n){var a=o[n];return r.call(t,n)?t[n]=e(t[n],a,i):t[n]=a,t}),a)}}},103:r=>{r.exports=e},757:e=>{e.exports=t},607:e=>{e.exports=r}},o={};function i(e){var r=o[e];if(void 0!==r)return r.exports;var t=o[e]={exports:{}};return n[e](t,t.exports,i),t.exports}i.d=(e,r)=>{for(var t in r)i.o(r,t)&&!i.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},i.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return(()=>{i.r(a),i.d(a,{default:()=>y});var e=i(103),r=i(607),t=i(129);const n="0.1.9";var o=i(757);const s=e.CancelToken,u=function(o){var i;process.browser&&(i=o.cache.get("api"));const a=e.defaults.adapter,u=(c=function(r){return new Promise((function(t,n){var o,s;switch(String(r.method).toLowerCase()){case"post":case"patch":case"put":case"delete":r.cache||(r.cache=!1)}if(!1===r.cache);else if(o=r.cache||i){var u=getCacheKeyFromConfig(r);s=o.get(u)}return s?t(s):(Object.assign(r,{adapter:a}),e.request(r).then((function(e){t(e)}),(function(e){n(e)})))}))},(l=e.create({paramsSerializer:e=>t.stringify(e,{arrayFormat:"repeat"}),adapter:c})).defaults.baseURL=o.apiURL,l.defaults.headers.common.Accept="application/json",l.interceptors.request.use((function(e){return e.headers["qik-request-date"]=(new Date).getTime(),Intl&&(e.headers["qik-request-timezone"]=Intl.DateTimeFormat().resolvedOptions().timeZone),e.headers["qik-api-version"]=n,e})),l.interceptors.response.use((function(e){return e.config,e}),(function(t){if(e.isCancel(t))return console.log("Request cancelled"),Promise.reject(t);var n=r.get(t,"response.status")||t.status;switch(n){case 401:case 404:break;case 502:case 504:return console.log(`qik.api > ${n} connection error retrying`),l.request(t.config);default:console.log("qik.api > connection error",n,t)}return Promise.reject(t)})),l);var c,l;return u.generateEndpointURL=function(e,r){if(e&&String(e).length){r||(r={});var t=`${o.apiURL}${e}`;t=function(e,r){if(!r.withoutToken){var t=o.auth.getCurrentToken();!r.access_token&&t&&(r.access_token=t)}return e}(t,r);var n=o.utils.mapParameters(r);return n.length&&(t+="?"+n),t}},u.CancelToken=s,u.axios=e,u};i(818);var c={mapParameters:function(e){return r.chain(e).reduce((function(e,t,n){return null==t||!1===t||(r.isArray(t)?r.each(t,(function(r){e.push(`${n}=${encodeURIComponent(r)}`)})):e.push(encodeURIComponent(n)+"="+encodeURIComponent(t))),e}),[]).compact().value().join("&")},formatCurrency:function(e,r){return e&&!isNaN(e)||(e=0),`${c.currencySymbol(r)}${parseFloat(parseInt(e)/100).toFixed(2)}`},currencySymbol:function(e){switch(e=String(e).toLowerCase(),String(e).toLowerCase()){case"gbp":return"£";case"eur":return"€";default:return"$"}},getAvailableCurrencies:function(e){var r=[];if(r.push({name:`USD (${c.currencySymbol("usd")})`,value:"usd",countryCode:{US:!0}}),r.push({name:`GBP (${c.currencySymbol("gbp")})`,value:"gbp",countryCode:{GB:!0,UK:!0}}),r.push({name:`CAD (${c.currencySymbol("cad")})`,value:"cad",countryCode:{CA:!0}}),r.push({name:`AUD (${c.currencySymbol("aud")})`,value:"aud",countryCode:{AU:!0}}),r.push({name:`NZD (${c.currencySymbol("nzd")})`,value:"nzd",countryCode:{NZ:!0}}),r.push({name:`SGD (${c.currencySymbol("sgd")})`,value:"sgd",countryCode:{SG:!0}}),e){var t=r.findIndex((function(r){return r.countryCode[e]}));const n=(e,r,t)=>{const n=[...e];return n.splice(t,0,...n.splice(r,1)),n};-1!=t&&(r=n(r,t,0))}return r},hash:function(e,t){return Array.isArray(e)||(e=[]),e.reduce((function(e,t){var n=r.get(t,n);return e[n]=t,e}),{})},guid:function(){var e=(new Date).getTime().toString(16)+Math.random().toString(16).substring(2)+"0".repeat(16);return e.substr(0,8)+"-"+e.substr(8,4)+"-4000-8"+e.substr(12,3)+"-"+e.substr(15,12)},extractFromArray:function(e,t,n,o,i,a,s){s||(s={}),n&&(s.sum=n),o&&(s.flatten=!0),i&&(s.unique=!0),a&&(s.excludeNull=!0);var u=r.reduce(e,(function(e,n){var o=r.get(n,t),i=!o&&!1!==o&&0!==o;return s.excludeNull&&i||e.push(o),e}),[]);return s.flatten&&(u=r.flatten(u)),s.unique&&(u=r.uniq(u)),s.sum&&(u=u.reduce((function(e,r){return e+r}),0)),u},matchInArray:function(e,t,n,o){return r.filter(e,(function(e){var i,a=r.get(e,t);switch(o){case">":i=a>n;break;case"<":i=a<n;break;case">=":i=a>=n;break;case"<=":i=a<=n;break;case"in":i=r.includes(a,n);break;default:i=void 0===n?a:a==n}return i}))},comma:function(e,t,n){return n&&(e=e.slice(0,n)),r.chain(e).compact().map((function(e){return t&&t.length?r.get(e,t):e})).value().join(", ")},id:function(e){var r;if(e&&(r=e._id?String(e._id):String(e),service.isValidID(r)))return r},ids:function(e){return r.chain(e).reduce((function(e,r){if(!r)return e;var t=service.id(r);return t&&(e[t]=1),e}),{}).keys().value()},isValidID:function(e){return new RegExp("^[0-9a-fA-F]{24}$").test(String(e))},errorMessage:function(e){r.isArray(e)&&(e=r.first(e));var t=r.chain(["response.data.message","response.data","message"]).map((function(t){return r.get(e,t)})).compact().first().value();return Array.isArray(t)&&(t=t[0]),t&&t.length?t:String(e)},machineName:function(e){if(e&&e.length)return e.replace(/[^a-zA-Z0-9-_]+/g,"")}};const l=c;function f(){var e={},r={removeAllListeners:function(){e={}},dispatch:function(r,t){e[r]&&e[r].forEach((function(e){return e(t)}))},addEventListener:function(r,t){e[r]||(e[r]=[]),-1==e[r].indexOf(t)&&e[r].push(t)},removeEventListener:function(r,t){e[r]||(e[r]=[]);var n=e[r].indexOf(t);-1!=n&&e[r].splice(n,1)},bootstrap:function(e){e&&(e.dispatch=r.dispatch,e.addEventListener=r.addEventListener,e.removeEventListener=r.removeEventListener,e.removeAllListeners=r.removeAllListeners)}};return r}const p=function(e){if(!e.api)throw new Error("Can't Instantiate QikAuth before QikAPI exists");var t={},n={debug:!1};Object.defineProperty(n,"store",{value:t,writable:!1});var o=new f;function i(e){var r=t.user;n.onChange&&n.onChange(r),o.dispatch("change",r,e)}function a(e){n.debug&&console.log(e)}o.bootstrap(n),n.set=function(e,r,n){return t.user=e,a("qik.auth > user set"),i(r)},n.logout=function(){return delete t.user,e.cache.reset(),a("qik.auth > user logout"),e.withCredentials&&(window.location.href="/qik/logout"),i()},n.changeOrganisation=function(r,t){r=e.utils.getStringID(r),t||(t={});var o=!0;t.disableAutoAuthentication&&(o=!1);var i=e.api.post(`/user/switch/${r}`);return i.then((function(r){o&&(e.cache.reset(),n.set(r.data))}),(function(e){})),i},n.impersonate=function(r,t){r=e.utils.getStringID(r),t||(t={});var o=!0;t.disableAutoAuthentication&&(o=!1);var i=e.api.post(`/user/impersonate/${r}`);return i.then((function(r){o&&(e.cache.reset(),n.set(r.data))}),(function(e){})),i},n.login=function(r,n){n||(n={});var o=!0;return n.disableAutoAuthentication&&(o=!1),new Promise((function(a,s){if(!r)return s({message:"Missing credentials!"});if(!r.email||!r.email.length)return s({message:"Username was not provided"});if(!r.password||!r.password.length)return s({message:"Password was not provided"});var u=`${e.apiURL}/user/login`;n.url&&(u=n.url),e.api.post(u,r,{bypassInterceptor:!0}).then((function(e){o&&(t.user=e.data,i()),a(e)}),s)}))},n.signup=function(r,n){n||(n={});var o=!0;return n.disableAutoAuthentication&&(o=!1),new Promise((function(a,s){if(!r)return s({message:"No details provided"});if(!r.firstName||!r.firstName.length)return s({message:"First Name was not provided"});if(!r.lastName||!r.lastName.length)return s({message:"Last Name was not provided"});if(!r.email||!r.email.length)return s({message:"Email/Username was not provided"});if(!r.password||!r.password.length)return s({message:"Password was not provided"});if(!r.confirmPassword||!r.confirmPassword.length)return s({message:"Confirm Password was not provided"});if(r.confirmPassword!=r.password)return s({message:"Your passwords do not match"});var u=`${e.apiURL}/user/signup`;n.application&&(u=`${e.domain||""}/qik/application/signup`),n.url&&(u=n.url),e.api.post(u,r,{bypassInterceptor:!0}).then((function(e){o&&(t.user=e.data,i()),a(e)}),s)}))},n.retrieveUserFromResetToken=function(r,t){return t||(t={}),new Promise((function(n,o){var i=`${e.apiURL}/user/reset/${r}`;t.url&&(i=t.url),e.api.get(i,{bypassInterceptor:!0}).then((function(e){return n(e.data)}),o)}))},n.updateUserWithToken=function(r,t,o){o||(o={});var i=!0;return o.disableAutoAuthentication&&(i=!1),new Promise((function(a,s){var u=`${e.apiURL}/user/reset/${r}`;o.url&&(u=o.url),e.api.post(u,t,{bypassInterceptor:!0}).then((function(r){return i&&(e.cache.reset(),n.set(r.data)),a(r.data)}),s)}))},n.sendResetPasswordRequest=function(r,t){return t||(t={}),new Promise((function(n,o){if(!r)return o({message:"No details provided"});if(!r.email||!r.email.length)return o({message:"Email was not provided"});r.email=r.email;var i=`${e.apiURL}/user/forgot`;t.url&&(i=t.url),e.api.post(i,r,{bypassInterceptor:!0}).then(n,o)}))};const s={};return n.refreshAccessToken=function(r){return s.inflightRefreshRequest?(a("qik.auth > use inflight request"),s.inflightRefreshRequest):(a("qik.auth > refresh token new request"),s.inflightRefreshRequest=new Promise((function(n,o){a(`qik.auth > refresh token ${r}`),e.api.post("/user/refresh",{refreshToken:r},{bypassInterceptor:!0}).then((function(e){if(!e)return a("qik.auth > no res"),s.inflightRefreshRequest=null,o();t.user?Object.assign(t.user,e.data):t.user=e.data,a(`qik.auth > token refreshed > ${e.data}`),i(),n(e.data.token),setTimeout((function(){s.inflightRefreshRequest=null}))})).catch((function(e){console.log("TOKEN REFRESH FAILED",e),setTimeout((function(){s.inflightRefreshRequest=null})),o(e)}))})),s.inflightRefreshRequest)},n.sync=function(){return e.api.get("/user").then((function(e){e.data?t.user&&Object.assign(t.user,e.data):t.user=null,a("qik.auth > server session refreshed"),i()})).catch((function(e){console.log("auth sync not logged in"),t.user=null,i()}))},n.getCurrentUser=function(){return t.user},n.getCurrentToken=function(){return n.getCurrentUser().accessToken},e.api.interceptors.request.use((function(e){if(e.bypassInterceptor)return console.log("auth interceptor was bypassed"),e;var o=e,i=r.get(t,"user.accessToken"),s=r.get(t,"user.refreshToken");if(!i)return a("qik.auth > no token"),o;if(o.headers.Authorization=`Bearer ${i}`,a("qik.auth > using user token"),!s)return a("qik.auth > no refresh token"),o;var u=new Date;u.setSeconds(u.getSeconds()+10);var c=r.get(t,"user.expires");return u<new Date(c)?o:(a("qik.auth > token expired"),new Promise((function(e,r){n.refreshAccessToken(s).then((function(r){return a("qik.auth > token refreshed",isManagedUser),o.headers.Authorization=`Bearer ${r}`,e(o)})).catch((function(e){return console.log("ERRRRRR",e),a("qik.auth > token refresh rejected"),r(e)}))})))}),(function(e){return Promise.reject(e)})),e.api.interceptors.response.use((function(e){return e}),(function(e){var t=r.get(e,"response.status")||e.status;return a("qik.auth > error"),401===t&&(console.log("logout from 401"),n.logout()),Promise.reject(e)})),n};var d={};const h={reset(){r.each(d,(function(e,r){e.reset()}))},get:(e,r)=>(d[e]||(d[e]=new o.Cache(r)),d[e])},g=function(e){if(!e.auth)throw new Error("Can't Instantiate QikAccess before QikAccess has been initialized");var t={};return(new f).bootstrap(t),t.has=function(e,n){var o=t.retrieveCurrentSession(n);if(!o)return!1;if(t.isQikAdmin()&&!n)return!0;var i=o.permissionSets,a=r.chain(i).reduce((function(e,r,t){return e.push(r.permissions),e}),[]).flattenDeep().compact().uniq().value();return r.includes(a,e)},t};console.log("BEFORE class"),console.log("qik 0.1.9"),console.log("WJAT OS","function");const y=function(e){switch(e||(e={}),e.apiURL&&e.apiURL.length||(e.apiURL="staging"),String(e.apiURL).toLowerCase()){case"production":e.apiURL="https://api.qik.dev";break;case"staging":e.apiURL="https://api.staging.qik.dev";break;case"local":e.apiURL="http://localhost:4001"}const r=Object.assign(e,{version:n});console.log("Instantiate class",r);var t=h;Object.defineProperty(r,"cache",{value:t,writable:!1});var o=l;Object.defineProperty(r,"utils",{value:o,writable:!1}),(new f).bootstrap(r),r.error=function(e){return r.dispatch("error",o.errorMessage(e))},r.notify=function(e,t){return r.dispatch("notification",{message:e,options:t})};var i=new u(r);Object.defineProperty(r,"api",{value:i,writable:!1});var a=new p(r);Object.defineProperty(r,"auth",{value:a,writable:!1});var s=new g(r);return Object.defineProperty(r,"access",{value:s,writable:!1}),r}})(),a})()}));
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Lodash <https://lodash.com/>
|
|
4
|
-
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
5
|
-
* Released under MIT license <https://lodash.com/license>
|
|
6
|
-
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
7
|
-
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
8
|
-
*/
|
package/webpack.config.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import {fileURLToPath} from 'url';
|
|
3
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
4
|
-
const __dirname = path.dirname(__filename);
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
entry: './src/index.js',
|
|
8
|
-
output: {
|
|
9
|
-
filename: 'index.js',
|
|
10
|
-
library: {
|
|
11
|
-
name:'@qikdev/sdk',
|
|
12
|
-
type:'umd',
|
|
13
|
-
},
|
|
14
|
-
path: path.resolve(__dirname, 'dist'),
|
|
15
|
-
globalObject: 'typeof self !== \'undefined\' ? self : this',
|
|
16
|
-
},
|
|
17
|
-
optimization: {
|
|
18
|
-
// splitChunks: {
|
|
19
|
-
// chunks: 'all'
|
|
20
|
-
// }
|
|
21
|
-
},
|
|
22
|
-
externals: {
|
|
23
|
-
'axios': {
|
|
24
|
-
commonjs: 'axios',
|
|
25
|
-
commonjs2: 'axios',
|
|
26
|
-
amd: 'axios',
|
|
27
|
-
root: 'axios'
|
|
28
|
-
},
|
|
29
|
-
'lodash': {
|
|
30
|
-
commonjs: 'lodash',
|
|
31
|
-
commonjs2: 'lodash',
|
|
32
|
-
amd: 'lodash',
|
|
33
|
-
root: '_'
|
|
34
|
-
},
|
|
35
|
-
'axios-extensions': {
|
|
36
|
-
commonjs: 'axios-extensions',
|
|
37
|
-
commonjs2: 'axios-extensions',
|
|
38
|
-
amd: 'axios-extensions',
|
|
39
|
-
root: 'axios-extensions'
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
// output: {
|
|
43
|
-
// filename: 'main.js',
|
|
44
|
-
// path: path.resolve(__dirname, 'dist')
|
|
45
|
-
// }
|
|
46
|
-
};
|