@qikdev/sdk 0.1.164 → 0.1.166
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/src/api/qik.api.js +349 -361
- package/src/api/qik.socket.js +304 -294
- package/src/version.js +1 -1
- package/.eslintcache +0 -1
package/src/api/qik.api.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
import axios from
|
|
2
|
-
import qs from
|
|
3
|
-
import { version } from
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import qs from "qs";
|
|
3
|
+
import { version } from "../version.js";
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from
|
|
10
|
-
|
|
6
|
+
cacheAdapterEnhancer,
|
|
7
|
+
throttleAdapterEnhancer,
|
|
8
|
+
Cache,
|
|
9
|
+
} from "axios-extensions";
|
|
11
10
|
|
|
12
11
|
function isString(value) {
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const type = typeof value;
|
|
13
|
+
return (
|
|
14
|
+
type === "string" ||
|
|
15
|
+
(type === "object" &&
|
|
16
|
+
value != null &&
|
|
17
|
+
!Array.isArray(value) &&
|
|
18
|
+
getTag(value) == "[object String]")
|
|
19
|
+
);
|
|
15
20
|
}
|
|
16
21
|
|
|
17
|
-
|
|
18
22
|
/**
|
|
19
23
|
* Creates a new instance of Axios, with automatic authentication and token refreshing functionality.
|
|
20
24
|
* This module provides all the underlying functions for making http requests and interacting with the REST API.
|
|
@@ -25,419 +29,403 @@ function isString(value) {
|
|
|
25
29
|
* @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.
|
|
26
30
|
*/
|
|
27
31
|
|
|
28
|
-
|
|
29
32
|
const CancelToken = axios.CancelToken;
|
|
30
33
|
|
|
31
34
|
///////////////////////////////////////
|
|
32
35
|
|
|
36
|
+
var QikAPI = function (qik) {
|
|
37
|
+
var defaultCache;
|
|
33
38
|
|
|
39
|
+
if (typeof window !== "undefined") {
|
|
40
|
+
defaultCache = qik.cache.get("api");
|
|
41
|
+
}
|
|
34
42
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var defaultCache;
|
|
38
|
-
|
|
39
|
-
if (typeof window !== 'undefined') {
|
|
40
|
-
defaultCache = qik.cache.get('api');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const defaultAdapter = axios.defaults.adapter
|
|
44
|
-
|
|
45
|
-
/////////////////////////////////////////////////////
|
|
46
|
-
|
|
47
|
-
function getRequestCacheKey(config) {
|
|
48
|
-
var key = [
|
|
49
|
-
config.method,
|
|
50
|
-
config.url,
|
|
51
|
-
config.headers?.Authorization,
|
|
52
|
-
config.headers.Accept,
|
|
53
|
-
JSON.stringify({
|
|
54
|
-
params: config.params,
|
|
55
|
-
data: config.data,
|
|
56
|
-
}),
|
|
57
|
-
|
|
58
|
-
].filter(Boolean).join('-')
|
|
59
|
-
|
|
60
|
-
return key;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
///////////////////////////////////////
|
|
64
|
-
|
|
65
|
-
const inflightRequests = {};
|
|
66
|
-
|
|
67
|
-
let cacheAdapter = function(config) {
|
|
68
|
-
|
|
69
|
-
var cacheKey = getRequestCacheKey(config);
|
|
70
|
-
|
|
71
|
-
// If there is already an identical request being made
|
|
72
|
-
if (!inflightRequests[cacheKey]) {
|
|
73
|
-
|
|
74
|
-
// Be more efficient and wait for the existing request
|
|
75
|
-
inflightRequests[cacheKey] = new Promise(function(resolve, reject) {
|
|
76
|
-
var useCache;
|
|
77
|
-
var cachedResponse;
|
|
78
|
-
|
|
79
|
-
///////////////////////////////////////
|
|
80
|
-
|
|
81
|
-
switch (String(config.method).toLowerCase()) {
|
|
82
|
-
case 'post':
|
|
83
|
-
case 'patch':
|
|
84
|
-
case 'put':
|
|
85
|
-
case 'delete':
|
|
86
|
-
//Unless we've specified we want a cache
|
|
87
|
-
if (!config.cache) {
|
|
88
|
-
//Don't use the cache
|
|
89
|
-
config.cache = false;
|
|
90
|
-
}
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
///////////////////////////////////////
|
|
95
|
-
|
|
96
|
-
if (config.cache === false) {
|
|
97
|
-
//No cache so make new request
|
|
98
|
-
} else {
|
|
99
|
-
|
|
100
|
-
//Use the cache specified or the default cache
|
|
101
|
-
useCache = config.cache || defaultCache;
|
|
102
|
-
|
|
103
|
-
//If there is a cache
|
|
104
|
-
if (useCache) {
|
|
105
|
-
//If we have the cachedResponse version
|
|
106
|
-
cachedResponse = useCache.get(cacheKey);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
43
|
+
const defaultAdapter = axios.defaults.adapter;
|
|
109
44
|
|
|
110
|
-
|
|
45
|
+
/////////////////////////////////////////////////////
|
|
111
46
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
47
|
+
function getRequestCacheKey(config) {
|
|
48
|
+
var key = [
|
|
49
|
+
config.method,
|
|
50
|
+
config.url,
|
|
51
|
+
config.headers?.Authorization,
|
|
52
|
+
config.headers.Accept,
|
|
53
|
+
JSON.stringify({
|
|
54
|
+
params: config.params,
|
|
55
|
+
data: config.data,
|
|
56
|
+
}),
|
|
57
|
+
]
|
|
58
|
+
.filter(Boolean)
|
|
59
|
+
.join("-");
|
|
115
60
|
|
|
116
|
-
|
|
61
|
+
return key;
|
|
62
|
+
}
|
|
117
63
|
|
|
118
|
-
|
|
119
|
-
.then(function(res) {
|
|
64
|
+
///////////////////////////////////////
|
|
120
65
|
|
|
121
|
-
|
|
122
|
-
resolve(res);
|
|
123
|
-
}, function(err) {
|
|
124
|
-
|
|
125
|
-
delete inflightRequests[cacheKey];
|
|
126
|
-
reject(err);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
return inflightRequests[cacheKey];
|
|
133
|
-
}
|
|
66
|
+
const inflightRequests = {};
|
|
134
67
|
|
|
68
|
+
let cacheAdapter = function (config) {
|
|
69
|
+
var cacheKey = getRequestCacheKey(config);
|
|
135
70
|
|
|
71
|
+
// If there is already an identical request being made
|
|
72
|
+
if (!inflightRequests[cacheKey]) {
|
|
73
|
+
// Be more efficient and wait for the existing request
|
|
74
|
+
inflightRequests[cacheKey] = new Promise(function (resolve, reject) {
|
|
75
|
+
var useCache;
|
|
76
|
+
var cachedResponse;
|
|
136
77
|
|
|
78
|
+
///////////////////////////////////////
|
|
137
79
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
* @param {String} endpoint The endpoint to generate a url for
|
|
150
|
-
* @param {Object} params Extra parameters for the url
|
|
151
|
-
* @param {Object} options Additional request configuration
|
|
152
|
-
* @param {Object} options.withoutToken Don't append the current user's access token to the url
|
|
153
|
-
* @param {Object} options.file Whether the response for this request is expected to be a binary file type
|
|
154
|
-
* @example
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* const result = sdk.api.generateEndpointURL('/image/61eca4746971e75c1fc670cf', {
|
|
158
|
-
* w:100,
|
|
159
|
-
* h:50,
|
|
160
|
-
* }, {file:true})
|
|
161
|
-
*
|
|
162
|
-
* // Would return something similar to:
|
|
163
|
-
* // https://api.qik.dev/image/61eca4746971e75c1fc670cf?w=100&h=50&access_token=XXXX...
|
|
164
|
-
*/
|
|
165
|
-
service.generateEndpointURL = function(endpoint, params, options) {
|
|
166
|
-
options = options || {}
|
|
167
|
-
params = params || {};
|
|
168
|
-
|
|
169
|
-
var token;
|
|
170
|
-
const apiURL = options.file ? qik.fileAPI || qik.apiURL : qik.apiURL;
|
|
171
|
-
|
|
172
|
-
//Append the access token to the url
|
|
173
|
-
if (!options.withoutToken) {
|
|
174
|
-
delete params.access_token;
|
|
175
|
-
token = qik.auth.getCurrentToken();
|
|
80
|
+
switch (String(config.method).toLowerCase()) {
|
|
81
|
+
case "post":
|
|
82
|
+
case "patch":
|
|
83
|
+
case "put":
|
|
84
|
+
case "delete":
|
|
85
|
+
//Unless we've specified we want a cache
|
|
86
|
+
if (!config.cache) {
|
|
87
|
+
//Don't use the cache
|
|
88
|
+
config.cache = false;
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
176
91
|
}
|
|
177
92
|
|
|
178
|
-
|
|
179
|
-
var parameterString = qik.utils.mapParameters(params);
|
|
93
|
+
///////////////////////////////////////
|
|
180
94
|
|
|
181
|
-
if (
|
|
182
|
-
|
|
95
|
+
if (config.cache === false) {
|
|
96
|
+
//No cache so make new request
|
|
183
97
|
} else {
|
|
184
|
-
|
|
98
|
+
//Use the cache specified or the default cache
|
|
99
|
+
useCache = config.cache || defaultCache;
|
|
100
|
+
|
|
101
|
+
//If there is a cache
|
|
102
|
+
if (useCache) {
|
|
103
|
+
//If we have the cachedResponse version
|
|
104
|
+
cachedResponse = useCache.get(cacheKey);
|
|
105
|
+
}
|
|
185
106
|
}
|
|
186
107
|
|
|
108
|
+
///////////////////////////////////////
|
|
187
109
|
|
|
188
|
-
|
|
110
|
+
if (cachedResponse) {
|
|
111
|
+
return resolve(cachedResponse);
|
|
112
|
+
}
|
|
189
113
|
|
|
190
|
-
|
|
114
|
+
var copy = Object.assign(config, { adapter: defaultAdapter });
|
|
115
|
+
|
|
116
|
+
return axios.request(config).then(
|
|
117
|
+
function (res) {
|
|
118
|
+
delete inflightRequests[cacheKey];
|
|
119
|
+
resolve(res);
|
|
120
|
+
},
|
|
121
|
+
function (err) {
|
|
122
|
+
delete inflightRequests[cacheKey];
|
|
123
|
+
reject(err);
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return inflightRequests[cacheKey];
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
132
|
+
|
|
133
|
+
const service = createNewAxios(cacheAdapter);
|
|
134
|
+
|
|
135
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
*
|
|
139
|
+
* Generate an Endpoint URL, complete with authentication.
|
|
140
|
+
* this function is helpful for generating authenticated links for the user to open in another window
|
|
141
|
+
* @alias api.generateEndpointURL
|
|
142
|
+
* @param {String} endpoint The endpoint to generate a url for
|
|
143
|
+
* @param {Object} params Extra parameters for the url
|
|
144
|
+
* @param {Object} options Additional request configuration
|
|
145
|
+
* @param {Object} options.withoutToken Don't append the current user's access token to the url
|
|
146
|
+
* @param {Object} options.file Whether the response for this request is expected to be a binary file type
|
|
147
|
+
* @example
|
|
148
|
+
*
|
|
149
|
+
*
|
|
150
|
+
* const result = sdk.api.generateEndpointURL('/image/61eca4746971e75c1fc670cf', {
|
|
151
|
+
* w:100,
|
|
152
|
+
* h:50,
|
|
153
|
+
* }, {file:true})
|
|
154
|
+
*
|
|
155
|
+
* // Would return something similar to:
|
|
156
|
+
* // https://api.qik.dev/image/61eca4746971e75c1fc670cf?w=100&h=50&access_token=XXXX...
|
|
157
|
+
*/
|
|
158
|
+
service.generateEndpointURL = function (endpoint, params, options) {
|
|
159
|
+
options = options || {};
|
|
160
|
+
params = params || {};
|
|
161
|
+
|
|
162
|
+
var token;
|
|
163
|
+
const apiURL = options.file ? qik.fileAPI || qik.apiURL : qik.apiURL;
|
|
164
|
+
|
|
165
|
+
//Append the access token to the url
|
|
166
|
+
if (!options.withoutToken) {
|
|
167
|
+
delete params.access_token;
|
|
168
|
+
token = qik.auth.getCurrentToken();
|
|
191
169
|
}
|
|
192
170
|
|
|
193
|
-
|
|
171
|
+
var stripLeadingTag = endpoint[0] == "/" ? endpoint.slice(1) : endpoint;
|
|
172
|
+
var parameterString = qik.utils.mapParameters(params);
|
|
194
173
|
|
|
195
|
-
|
|
196
|
-
|
|
174
|
+
if (token) {
|
|
175
|
+
parameterString = parameterString
|
|
176
|
+
? `?access_token=${token}&${parameterString}`
|
|
177
|
+
: `?access_token=${token}`;
|
|
178
|
+
} else {
|
|
179
|
+
parameterString = parameterString ? `?${parameterString}` : "";
|
|
197
180
|
}
|
|
198
181
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
182
|
+
var url = `${apiURL}${endpoint}${parameterString}`;
|
|
183
|
+
|
|
184
|
+
return url;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
188
|
+
|
|
189
|
+
service.wasCancelled = function (err) {
|
|
190
|
+
return axios.isCancel(err);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
*
|
|
197
|
+
* Make a GET request to the API
|
|
198
|
+
* @alias api.get
|
|
199
|
+
* @param {Object} endpoint The endpoint to request
|
|
200
|
+
* @param {Object} options The options to pass to axios for making the request
|
|
201
|
+
* @example
|
|
202
|
+
*
|
|
203
|
+
* const result = await sdk.api.get('/user');
|
|
204
|
+
*/
|
|
205
|
+
var f = function () {};
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
*
|
|
209
|
+
*
|
|
210
|
+
* @alias api.post
|
|
211
|
+
* @description Make a POST request to the API
|
|
212
|
+
* @param {Object} endpoint The endpoint to request
|
|
213
|
+
* @param {Object} body The post body to send with the request
|
|
214
|
+
* @param {Object} options The options to pass to axios for making the request
|
|
215
|
+
* @example
|
|
216
|
+
*
|
|
217
|
+
* const result = await sdk.api.post('/login', {username:'', password:''});
|
|
218
|
+
*/
|
|
219
|
+
var f = function () {};
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
*
|
|
223
|
+
* Make a PUT request to the API
|
|
224
|
+
* @alias api.put
|
|
225
|
+
* @param {Object} endpoint The endpoint to request
|
|
226
|
+
* @param {Object} body The post body to send with the request
|
|
227
|
+
* @param {Object} options The options to pass to axios for making the request
|
|
228
|
+
* @example
|
|
229
|
+
*
|
|
230
|
+
* const result = await sdk.api.put('/content/61eca4746971e75c1fc670cf', {title:'A new title'});
|
|
231
|
+
*/
|
|
232
|
+
var f = function () {};
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
*
|
|
236
|
+
* Make a PATCH request to the API
|
|
237
|
+
* @alias api.patch
|
|
238
|
+
* @param {Object} endpoint The endpoint to request
|
|
239
|
+
* @param {Object} body The post body to send with the request
|
|
240
|
+
* @param {Object} options The options to pass to axios for making the request
|
|
241
|
+
* @example
|
|
242
|
+
*
|
|
243
|
+
* const result = await sdk.api.patch('/content/61eca4746971e75c1fc670cf', {title:'A new title'});
|
|
244
|
+
*/
|
|
245
|
+
var f = function () {};
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
*
|
|
249
|
+
* Make a DELETE request to the API
|
|
250
|
+
* @alias api.delete
|
|
251
|
+
* @param {Object} endpoint The endpoint to request
|
|
252
|
+
* @param {Object} body The post body to send with the request
|
|
253
|
+
* @param {Object} options The options to pass to axios for making the request
|
|
254
|
+
* @example
|
|
255
|
+
*
|
|
256
|
+
* const result = await sdk.api.delete('/content/61eca4746971e75c1fc670cf');
|
|
257
|
+
*/
|
|
258
|
+
var f = function () {};
|
|
259
|
+
|
|
260
|
+
function createNewAxios(adapter) {
|
|
261
|
+
var instance = axios.create({
|
|
262
|
+
paramsSerializer: (params) =>
|
|
263
|
+
qs.stringify(params, { arrayFormat: "repeat" }),
|
|
264
|
+
adapter,
|
|
265
|
+
});
|
|
278
266
|
|
|
279
|
-
|
|
280
|
-
instance.defaults.headers.common.Accept = 'application/json';
|
|
267
|
+
///////////////////////////////////////
|
|
281
268
|
|
|
282
|
-
|
|
269
|
+
instance.defaults.baseURL = qik.apiURL;
|
|
270
|
+
instance.defaults.headers.common.Accept = "application/json";
|
|
283
271
|
|
|
284
|
-
|
|
285
|
-
instance.interceptors.request.use(function(config) {
|
|
272
|
+
/////////////////////////////////////////////////////
|
|
286
273
|
|
|
287
|
-
|
|
274
|
+
// Add relative date and timezone to every request
|
|
275
|
+
instance.interceptors.request.use(function (config) {
|
|
276
|
+
const inflightKey = getRequestCacheKey(config);
|
|
288
277
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
278
|
+
if (config.withoutToken) {
|
|
279
|
+
return config;
|
|
280
|
+
}
|
|
292
281
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
282
|
+
config.headers["qik-request-date"] = new Date().getTime();
|
|
283
|
+
if (Intl) {
|
|
284
|
+
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
285
|
+
if (timezone) {
|
|
286
|
+
config.headers["qik-request-timezone"] = timezone;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
299
289
|
|
|
300
|
-
|
|
301
|
-
if(qik?.socket?.windowID) {
|
|
302
|
-
config.headers['qik-socket-window'] = qik.socket.windowID;
|
|
303
|
-
}
|
|
290
|
+
config.headers["qik-api-version"] = version;
|
|
304
291
|
|
|
292
|
+
// Include the socket window id in the request
|
|
293
|
+
if (qik?.socket?.windowID) {
|
|
294
|
+
config.headers["qik-socket-window"] = qik.socket.windowID;
|
|
295
|
+
}
|
|
305
296
|
|
|
306
|
-
|
|
297
|
+
var token = qik.auth.getCurrentToken();
|
|
307
298
|
|
|
308
|
-
|
|
309
|
-
|
|
299
|
+
if (token) {
|
|
300
|
+
config.headers["Authorization"] = `Bearer ${token}`;
|
|
310
301
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
302
|
+
if (config.params && config.params.access_token) {
|
|
303
|
+
delete config.params.access_token;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
315
306
|
|
|
316
|
-
|
|
317
|
-
|
|
307
|
+
return config;
|
|
308
|
+
});
|
|
318
309
|
|
|
319
|
-
|
|
310
|
+
/////////////////////////////////////////////////////
|
|
320
311
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
break;
|
|
312
|
+
let retryCount = 0;
|
|
313
|
+
|
|
314
|
+
instance.interceptors.response.use(
|
|
315
|
+
function (response) {
|
|
316
|
+
var config = response.config;
|
|
317
|
+
|
|
318
|
+
//Get the response status
|
|
319
|
+
var status = response.status;
|
|
320
|
+
switch (status) {
|
|
321
|
+
case 204:
|
|
322
|
+
// No content give it another try
|
|
323
|
+
if (retryCount < 5) {
|
|
324
|
+
retryCount++;
|
|
325
|
+
// Wait a second and try again
|
|
326
|
+
return new Promise(function (resolve, reject) {
|
|
327
|
+
setTimeout(function () {
|
|
328
|
+
return instance.request(config).then(resolve, reject);
|
|
329
|
+
}, 800);
|
|
330
|
+
});
|
|
331
|
+
} else {
|
|
332
|
+
console.log("Failed after 5 retries");
|
|
333
|
+
retryCount = 0;
|
|
344
334
|
}
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
345
337
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
338
|
+
return response;
|
|
339
|
+
},
|
|
340
|
+
function (err) {
|
|
341
|
+
if (axios.isCancel(err)) {
|
|
342
|
+
return Promise.reject(err);
|
|
343
|
+
}
|
|
352
344
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
retryCount = 0;
|
|
376
|
-
}
|
|
377
|
-
break;
|
|
378
|
-
case 404:
|
|
379
|
-
//Not found
|
|
380
|
-
break;
|
|
381
|
-
default:
|
|
382
|
-
//Some other error, likely a problem connecting to the server
|
|
383
|
-
// console.log('qik.api > connection error', status, err);
|
|
384
|
-
break;
|
|
345
|
+
//Get the response status
|
|
346
|
+
var status = err?.response?.status || err.status;
|
|
347
|
+
|
|
348
|
+
//Check the status
|
|
349
|
+
switch (status) {
|
|
350
|
+
case 401:
|
|
351
|
+
//Ignore let QikAuth handle it
|
|
352
|
+
break;
|
|
353
|
+
|
|
354
|
+
case 502:
|
|
355
|
+
case 504:
|
|
356
|
+
if (retryCount < 5) {
|
|
357
|
+
retryCount++;
|
|
358
|
+
// Wait a second and try again
|
|
359
|
+
return new Promise(function (resolve, reject) {
|
|
360
|
+
setTimeout(function () {
|
|
361
|
+
return instance.request(err.config).then(resolve, reject);
|
|
362
|
+
}, 800);
|
|
363
|
+
});
|
|
364
|
+
} else {
|
|
365
|
+
console.log("Failed after 5 retries");
|
|
366
|
+
retryCount = 0;
|
|
385
367
|
}
|
|
368
|
+
break;
|
|
369
|
+
case 404:
|
|
370
|
+
//Not found
|
|
371
|
+
break;
|
|
372
|
+
default:
|
|
373
|
+
//Some other error, likely a problem connecting to the server
|
|
374
|
+
// console.log('qik.api > connection error', status, err);
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
386
377
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
return Promise.reject(err);
|
|
390
|
-
})
|
|
391
|
-
|
|
392
|
-
return instance;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/////////////////////////////////////////////////////
|
|
378
|
+
/////////////////////////////////////////////////////
|
|
396
379
|
|
|
397
|
-
|
|
380
|
+
return Promise.reject(err);
|
|
381
|
+
},
|
|
382
|
+
);
|
|
398
383
|
|
|
399
|
-
|
|
384
|
+
return instance;
|
|
385
|
+
}
|
|
400
386
|
|
|
401
|
-
|
|
402
|
-
dataString = data;
|
|
403
|
-
} else {
|
|
404
|
-
dataString = JSON.stringify(data);
|
|
405
|
-
}
|
|
387
|
+
/////////////////////////////////////////////////////
|
|
406
388
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
var matches = dataString.match(myregexp);
|
|
389
|
+
function retrieveIDs(data) {
|
|
390
|
+
var dataString;
|
|
410
391
|
|
|
411
|
-
|
|
412
|
-
|
|
392
|
+
if (_isString(data)) {
|
|
393
|
+
dataString = data;
|
|
394
|
+
} else {
|
|
395
|
+
dataString = JSON.stringify(data);
|
|
413
396
|
}
|
|
414
397
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
*
|
|
419
|
-
* Reference to the underlying axios package (https://www.npmjs.com/package/axios)
|
|
420
|
-
* Useful for creating new instances of axios if you want to create http requests to
|
|
421
|
-
* external APIs and not send tokens etc..
|
|
422
|
-
* @name api.axios
|
|
423
|
-
* @example
|
|
424
|
-
* const newRequest = await sdk.api.axios.get('https://otherapi.com/content/61eca4746971e75c1fc670cf');
|
|
425
|
-
*/
|
|
398
|
+
//Find all mongo ids included in the object
|
|
399
|
+
var myregexp = /[0-9a-fA-F]{24}/g;
|
|
400
|
+
var matches = dataString.match(myregexp);
|
|
426
401
|
|
|
427
|
-
|
|
428
|
-
|
|
402
|
+
//Make sure the matches are unique
|
|
403
|
+
return [...new Set(matches)];
|
|
404
|
+
}
|
|
429
405
|
|
|
430
|
-
|
|
406
|
+
///////////////////////////////////////
|
|
431
407
|
|
|
432
|
-
|
|
433
|
-
|
|
408
|
+
/**
|
|
409
|
+
*
|
|
410
|
+
* Reference to the underlying axios package (https://www.npmjs.com/package/axios)
|
|
411
|
+
* Useful for creating new instances of axios if you want to create http requests to
|
|
412
|
+
* external APIs and not send tokens etc..
|
|
413
|
+
* @name api.axios
|
|
414
|
+
* @example
|
|
415
|
+
* const newRequest = await sdk.api.axios.get('https://otherapi.com/content/61eca4746971e75c1fc670cf');
|
|
416
|
+
*/
|
|
434
417
|
|
|
418
|
+
service.CancelToken = CancelToken;
|
|
419
|
+
service.axios = axios;
|
|
435
420
|
|
|
421
|
+
///////////////////////////////////////
|
|
436
422
|
|
|
423
|
+
return service;
|
|
424
|
+
};
|
|
437
425
|
|
|
438
426
|
///////////////////////////////////////
|
|
439
427
|
///////////////////////////////////////
|
|
440
428
|
///////////////////////////////////////
|
|
441
429
|
|
|
442
430
|
export { CancelToken as CancelToken };
|
|
443
|
-
export default QikAPI;
|
|
431
|
+
export default QikAPI;
|