@qikdev/sdk 1.0.2 → 1.0.5
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 +1 -1
- package/dist/{docs/access.html → access.html} +353 -20
- package/dist/api.html +444 -0
- package/dist/{docs/auth.html → auth.html} +14 -14
- package/dist/cache.html +351 -0
- package/dist/{docs/content.html → content.html} +46 -21
- package/dist/{docs/files.html → files.html} +147 -6
- package/dist/{docs/filter.html → filter.html} +9 -9
- package/dist/geo.html +1029 -0
- package/dist/global.html +240 -0
- package/dist/index.html +96 -0
- package/dist/main.js +2 -3
- package/dist/module-QikStorage-CookieStorageAdapter.html +407 -0
- package/dist/module-QikStorage-LocalStorageAdapter.html +193 -0
- package/dist/module-QikStorage-StorageAdapter.html +977 -0
- package/dist/module-QikStorage.html +433 -0
- package/dist/qik.access.js.html +904 -0
- package/dist/qik.api.js.html +409 -0
- package/dist/{docs/qik.auth.js.html → qik.auth.js.html} +142 -104
- package/dist/qik.cache.js.html +125 -0
- package/dist/qik.content.js.html +967 -0
- package/dist/qik.core.js.html +322 -0
- package/dist/qik.files.js.html +249 -0
- package/dist/{docs/qik.filter.js.html → qik.filter.js.html} +3 -3
- package/dist/qik.geo.js.html +963 -0
- package/dist/{docs/qik.socket.js.html → qik.socket.js.html} +53 -12
- package/dist/qik.storage.js.html +375 -0
- package/dist/qik.system.js.html +117 -0
- package/dist/qik.utils.js.html +1548 -0
- package/dist/{docs/socket.html → socket.html} +7 -7
- package/dist/{docs/styles → styles}/jsdoc.css +2 -2
- package/dist/system.html +197 -0
- package/dist/utils.html +4422 -0
- package/package.json +2 -2
- package/src/api/qik.filter.js +1 -1
- package/src/api/qik.geo.js +1 -1
- package/src/api/qik.socket.js +18 -12
- package/src/api/qik.utils.js +6 -0
- package/src/version.js +1 -1
- package/dist/docs/api.html +0 -1356
- package/dist/docs/cache.html +0 -351
- package/dist/docs/index.html +0 -96
- package/dist/docs/qik.access.js.html +0 -790
- package/dist/docs/qik.api.js.html +0 -511
- package/dist/docs/qik.cache.js.html +0 -131
- package/dist/docs/qik.content.js.html +0 -918
- package/dist/docs/qik.core.js.html +0 -301
- package/dist/docs/qik.files.js.html +0 -219
- package/dist/docs/qik.system.js.html +0 -117
- package/dist/docs/qik.utils.js.html +0 -1467
- package/dist/docs/system.html +0 -197
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.woff2 +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.woff2 +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- /package/dist/{docs/scripts → scripts}/collapse.js +0 -0
- /package/dist/{docs/scripts → scripts}/linenumber.js +0 -0
- /package/dist/{docs/scripts → scripts}/nav.js +0 -0
- /package/dist/{docs/scripts → scripts}/polyfill.js +0 -0
- /package/dist/{docs/scripts → scripts}/prettify/Apache-License-2.0.txt +0 -0
- /package/dist/{docs/scripts → scripts}/prettify/lang-css.js +0 -0
- /package/dist/{docs/scripts → scripts}/prettify/prettify.js +0 -0
- /package/dist/{docs/scripts → scripts}/search.js +0 -0
- /package/dist/{docs/styles → styles}/prettify.css +0 -0
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>qik.api.js - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
|
|
21
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
22
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
23
|
+
<div class="navicon"></div>
|
|
24
|
+
</label>
|
|
25
|
+
|
|
26
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
27
|
+
|
|
28
|
+
<nav >
|
|
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#.hasFeature">hasFeature</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#.isAssignee">isAssignee</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#.generateEndpointURL">generateEndpointURL</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#.duration">duration</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#.activeFilterComparators">activeFilterComparators</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="geo.html">geo</a><ul class='methods'><li data-type='method'><a href="geo.html#.distance">distance</a></li><li data-type='method'><a href="geo.html#.getDefaultCountry">getDefaultCountry</a></li><li data-type='method'><a href="geo.html#.getDefaultTimezone">getDefaultTimezone</a></li><li data-type='method'><a href="geo.html#.getPosition">getPosition</a></li><li data-type='method'><a href="geo.html#.stopWatchPosition">stopWatchPosition</a></li><li data-type='method'><a href="geo.html#.watchPosition">watchPosition</a></li></ul></li><li><a href="module-QikStorage-CookieStorageAdapter.html">CookieStorageAdapter</a><ul class='methods'><li data-type='method'><a href="module-QikStorage-CookieStorageAdapter.html#getCookieOptions">getCookieOptions</a></li><li data-type='method'><a href="module-QikStorage-CookieStorageAdapter.html#isCookieMode">isCookieMode</a></li></ul></li><li><a href="module-QikStorage-LocalStorageAdapter.html">LocalStorageAdapter</a></li><li><a href="module-QikStorage-StorageAdapter.html">StorageAdapter</a><ul class='methods'><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#clearUser">clearUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getAccessToken">getAccessToken</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getRefreshToken">getRefreshToken</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getTokenExpiry">getTokenExpiry</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getUser">getUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#isAvailable">isAvailable</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#setUser">setUser</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><li><a href="utils.html">utils</a><ul class='methods'><li data-type='method'><a href="utils.html#.cleanValue">cleanValue</a></li><li data-type='method'><a href="utils.html#.comma">comma</a></li><li data-type='method'><a href="utils.html#.errorMessage">errorMessage</a></li><li data-type='method'><a href="utils.html#.exists">exists</a></li><li data-type='method'><a href="utils.html#.extractFromArray">extractFromArray</a></li><li data-type='method'><a href="utils.html#.formatCurrency">formatCurrency</a></li><li data-type='method'><a href="utils.html#.getTypeFromID">getTypeFromID</a></li><li data-type='method'><a href="utils.html#.guid">guid</a></li><li data-type='method'><a href="utils.html#.hash">hash</a></li><li data-type='method'><a href="utils.html#.id">id</a></li><li data-type='method'><a href="utils.html#.ids">ids</a></li><li data-type='method'><a href="utils.html#.isValidEmailAddress">isValidEmailAddress</a></li><li data-type='method'><a href="utils.html#.loadExternalScript">loadExternalScript</a></li><li data-type='method'><a href="utils.html#.loadExternalStyle">loadExternalStyle</a></li><li data-type='method'><a href="utils.html#.machineName">machineName</a></li><li data-type='method'><a href="utils.html#.mapParameters">mapParameters</a></li><li data-type='method'><a href="utils.html#.matchInArray">matchInArray</a></li><li data-type='method'><a href="utils.html#.parseBoolean">parseBoolean</a></li><li data-type='method'><a href="utils.html#.parseDate">parseDate</a></li><li data-type='method'><a href="utils.html#.parseEmail">parseEmail</a></li><li data-type='method'><a href="utils.html#.parseInt">parseInt</a></li><li data-type='method'><a href="utils.html#.parseNumber">parseNumber</a></li><li data-type='method'><a href="utils.html#.parseURL">parseURL</a></li></ul></li></ul><h3>Modules</h3><ul><li><a href="module-QikStorage.html">QikStorage</a><ul class='methods'><li data-type='method'><a href="module-QikStorage.html#.createStorageAdapter">createStorageAdapter</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#EventDispatcher">EventDispatcher</a></li></ul>
|
|
31
|
+
</nav>
|
|
32
|
+
|
|
33
|
+
<div id="main">
|
|
34
|
+
|
|
35
|
+
<h1 class="page-title">qik.api.js</h1>
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
<section>
|
|
44
|
+
<article>
|
|
45
|
+
<pre class="prettyprint source linenums"><code>import axios from "axios";
|
|
46
|
+
import qs from "qs";
|
|
47
|
+
import { version } from "../version.js";
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new instance of Axios, with automatic authentication and token refreshing functionality.
|
|
53
|
+
* This module provides all the underlying functions for making http requests and interacting with the REST API.
|
|
54
|
+
* It is a wrapper around the axios library, a popular promise based javascript request package. The api module is used by most other modules in the SDK and will handle authentication, token refreshing and other headers automatically.
|
|
55
|
+
* @alias api
|
|
56
|
+
* @constructor
|
|
57
|
+
* @hideconstructor
|
|
58
|
+
* @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.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
const CancelToken = axios.CancelToken;
|
|
62
|
+
|
|
63
|
+
///////////////////////////////////////
|
|
64
|
+
|
|
65
|
+
var QikAPI = function (qik) {
|
|
66
|
+
var defaultCache;
|
|
67
|
+
|
|
68
|
+
if (typeof window !== "undefined") {
|
|
69
|
+
defaultCache = qik.cache.get("api");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// axios 1.x exposes defaults.adapter as an array of adapter names — resolve it to the underlying function
|
|
73
|
+
const defaultAdapter = axios.getAdapter(axios.defaults.adapter);
|
|
74
|
+
|
|
75
|
+
/////////////////////////////////////////////////////
|
|
76
|
+
|
|
77
|
+
function getRequestCacheKey(config) {
|
|
78
|
+
var key = [
|
|
79
|
+
config.method,
|
|
80
|
+
config.url,
|
|
81
|
+
config.headers?.Authorization,
|
|
82
|
+
config.headers.Accept,
|
|
83
|
+
JSON.stringify({
|
|
84
|
+
params: config.params,
|
|
85
|
+
data: config.data,
|
|
86
|
+
}),
|
|
87
|
+
]
|
|
88
|
+
.filter(Boolean)
|
|
89
|
+
.join("-");
|
|
90
|
+
|
|
91
|
+
return key;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
///////////////////////////////////////
|
|
95
|
+
|
|
96
|
+
const inflightRequests = {};
|
|
97
|
+
|
|
98
|
+
let cacheAdapter = function (config) {
|
|
99
|
+
var cacheKey = getRequestCacheKey(config);
|
|
100
|
+
|
|
101
|
+
// If there is already an identical request being made
|
|
102
|
+
if (!inflightRequests[cacheKey]) {
|
|
103
|
+
// Be more efficient and wait for the existing request
|
|
104
|
+
inflightRequests[cacheKey] = new Promise(function (resolve, reject) {
|
|
105
|
+
var useCache;
|
|
106
|
+
var cachedResponse;
|
|
107
|
+
|
|
108
|
+
///////////////////////////////////////
|
|
109
|
+
|
|
110
|
+
switch (String(config.method).toLowerCase()) {
|
|
111
|
+
case "post":
|
|
112
|
+
case "patch":
|
|
113
|
+
case "put":
|
|
114
|
+
case "delete":
|
|
115
|
+
//Unless we've specified we want a cache
|
|
116
|
+
if (!config.cache) {
|
|
117
|
+
//Don't use the cache
|
|
118
|
+
config.cache = false;
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
///////////////////////////////////////
|
|
124
|
+
|
|
125
|
+
if (config.cache === false) {
|
|
126
|
+
//No cache so make new request
|
|
127
|
+
} else {
|
|
128
|
+
//Use the cache specified or the default cache
|
|
129
|
+
useCache = config.cache || defaultCache;
|
|
130
|
+
|
|
131
|
+
//If there is a cache
|
|
132
|
+
if (useCache) {
|
|
133
|
+
//If we have the cachedResponse version
|
|
134
|
+
cachedResponse = useCache.get(cacheKey);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
///////////////////////////////////////
|
|
139
|
+
|
|
140
|
+
if (cachedResponse) {
|
|
141
|
+
return resolve(cachedResponse);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
var copy = Object.assign(config, { adapter: defaultAdapter });
|
|
145
|
+
|
|
146
|
+
return axios.request(config).then(
|
|
147
|
+
function (res) {
|
|
148
|
+
delete inflightRequests[cacheKey];
|
|
149
|
+
resolve(res);
|
|
150
|
+
},
|
|
151
|
+
function (err) {
|
|
152
|
+
delete inflightRequests[cacheKey];
|
|
153
|
+
reject(err);
|
|
154
|
+
},
|
|
155
|
+
);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return inflightRequests[cacheKey];
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
162
|
+
|
|
163
|
+
const service = createNewAxios(cacheAdapter);
|
|
164
|
+
|
|
165
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
*
|
|
169
|
+
* Generate an Endpoint URL, complete with authentication.
|
|
170
|
+
* this function is helpful for generating authenticated links for the user to open in another window
|
|
171
|
+
* @alias api.generateEndpointURL
|
|
172
|
+
* @param {String} endpoint The endpoint to generate a url for
|
|
173
|
+
* @param {Object} params Extra parameters for the url
|
|
174
|
+
* @param {Object} options Additional request configuration
|
|
175
|
+
* @param {Object} options.withoutToken Don't append the current user's access token to the url
|
|
176
|
+
* @param {Object} options.file Whether the response for this request is expected to be a binary file type
|
|
177
|
+
* @example
|
|
178
|
+
*
|
|
179
|
+
*
|
|
180
|
+
* const result = sdk.api.generateEndpointURL('/image/61eca4746971e75c1fc670cf', {
|
|
181
|
+
* w:100,
|
|
182
|
+
* h:50,
|
|
183
|
+
* }, {file:true})
|
|
184
|
+
*
|
|
185
|
+
* // Would return something similar to:
|
|
186
|
+
* // https://api.qik.dev/image/61eca4746971e75c1fc670cf?w=100&h=50&access_token=XXXX...
|
|
187
|
+
*/
|
|
188
|
+
service.generateEndpointURL = function (endpoint, params, options) {
|
|
189
|
+
options = options || {};
|
|
190
|
+
params = params || {};
|
|
191
|
+
|
|
192
|
+
var token;
|
|
193
|
+
const apiURL = options.file ? qik.fileAPI || qik.apiURL : qik.apiURL;
|
|
194
|
+
|
|
195
|
+
//Append the access token to the url
|
|
196
|
+
if (!options.withoutToken) {
|
|
197
|
+
delete params.access_token;
|
|
198
|
+
token = qik.auth.getCurrentToken();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
var stripLeadingTag = endpoint[0] == "/" ? endpoint.slice(1) : endpoint;
|
|
202
|
+
var parameterString = qik.utils.mapParameters(params);
|
|
203
|
+
|
|
204
|
+
if (token) {
|
|
205
|
+
parameterString = parameterString
|
|
206
|
+
? `?access_token=${token}&${parameterString}`
|
|
207
|
+
: `?access_token=${token}`;
|
|
208
|
+
} else {
|
|
209
|
+
parameterString = parameterString ? `?${parameterString}` : "";
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
var url = `${apiURL}${endpoint}${parameterString}`;
|
|
213
|
+
|
|
214
|
+
return url;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
218
|
+
|
|
219
|
+
service.wasCancelled = function (err) {
|
|
220
|
+
return axios.isCancel(err);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
224
|
+
|
|
225
|
+
function createNewAxios(adapter) {
|
|
226
|
+
var instance = axios.create({
|
|
227
|
+
paramsSerializer: {
|
|
228
|
+
serialize: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
|
|
229
|
+
},
|
|
230
|
+
adapter,
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
///////////////////////////////////////
|
|
234
|
+
|
|
235
|
+
instance.defaults.baseURL = qik.apiURL;
|
|
236
|
+
instance.defaults.headers.common.Accept = "application/json";
|
|
237
|
+
|
|
238
|
+
/////////////////////////////////////////////////////
|
|
239
|
+
|
|
240
|
+
// Add relative date and timezone to every request
|
|
241
|
+
instance.interceptors.request.use(function (config) {
|
|
242
|
+
const inflightKey = getRequestCacheKey(config);
|
|
243
|
+
|
|
244
|
+
if (config.withoutToken) {
|
|
245
|
+
return config;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
config.headers["qik-request-date"] = new Date().getTime();
|
|
249
|
+
if (Intl) {
|
|
250
|
+
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
251
|
+
if (tz) {
|
|
252
|
+
config.headers["qik-request-timezone"] = tz;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
config.headers["qik-api-version"] = version;
|
|
257
|
+
|
|
258
|
+
// Include the socket window id in the request
|
|
259
|
+
if (qik?.socket?.windowID) {
|
|
260
|
+
config.headers["qik-socket-window"] = qik.socket.windowID;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
var token = qik.auth.getCurrentToken();
|
|
264
|
+
|
|
265
|
+
if (token) {
|
|
266
|
+
config.headers["Authorization"] = `Bearer ${token}`;
|
|
267
|
+
|
|
268
|
+
if (config.params && config.params.access_token) {
|
|
269
|
+
delete config.params.access_token;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return config;
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
/////////////////////////////////////////////////////
|
|
277
|
+
|
|
278
|
+
let retryCount = 0;
|
|
279
|
+
|
|
280
|
+
instance.interceptors.response.use(
|
|
281
|
+
function (response) {
|
|
282
|
+
var config = response.config;
|
|
283
|
+
|
|
284
|
+
//Get the response status
|
|
285
|
+
var status = response.status;
|
|
286
|
+
switch (status) {
|
|
287
|
+
case 204:
|
|
288
|
+
// No content give it another try
|
|
289
|
+
if (retryCount < 5) {
|
|
290
|
+
retryCount++;
|
|
291
|
+
// Wait a second and try again
|
|
292
|
+
return new Promise(function (resolve, reject) {
|
|
293
|
+
setTimeout(function () {
|
|
294
|
+
return instance.request(config).then(resolve, reject);
|
|
295
|
+
}, 800);
|
|
296
|
+
});
|
|
297
|
+
} else {
|
|
298
|
+
console.log("Failed after 5 retries");
|
|
299
|
+
retryCount = 0;
|
|
300
|
+
}
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return response;
|
|
305
|
+
},
|
|
306
|
+
function (err) {
|
|
307
|
+
if (axios.isCancel(err)) {
|
|
308
|
+
return Promise.reject(err);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
//Get the response status
|
|
312
|
+
var status = err?.response?.status || err.status;
|
|
313
|
+
|
|
314
|
+
//Check the status
|
|
315
|
+
switch (status) {
|
|
316
|
+
case 401:
|
|
317
|
+
//Ignore let QikAuth handle it
|
|
318
|
+
break;
|
|
319
|
+
|
|
320
|
+
case 502:
|
|
321
|
+
case 504:
|
|
322
|
+
if (retryCount < 5) {
|
|
323
|
+
retryCount++;
|
|
324
|
+
// Wait a second and try again
|
|
325
|
+
return new Promise(function (resolve, reject) {
|
|
326
|
+
setTimeout(function () {
|
|
327
|
+
return instance.request(err.config).then(resolve, reject);
|
|
328
|
+
}, 800);
|
|
329
|
+
});
|
|
330
|
+
} else {
|
|
331
|
+
console.log("Failed after 5 retries");
|
|
332
|
+
retryCount = 0;
|
|
333
|
+
}
|
|
334
|
+
break;
|
|
335
|
+
case 404:
|
|
336
|
+
//Not found
|
|
337
|
+
break;
|
|
338
|
+
default:
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/////////////////////////////////////////////////////
|
|
343
|
+
|
|
344
|
+
return Promise.reject(err);
|
|
345
|
+
},
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
return instance;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/////////////////////////////////////////////////////
|
|
352
|
+
|
|
353
|
+
function retrieveIDs(data) {
|
|
354
|
+
const text = typeof data === "string" ? data : JSON.stringify(data);
|
|
355
|
+
const matches = text.match(/\b[0-9a-f]{24}\b/gi);
|
|
356
|
+
return matches ? [...new Set(matches)] : [];
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
///////////////////////////////////////
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
*
|
|
363
|
+
* Reference to the underlying axios package (https://www.npmjs.com/package/axios)
|
|
364
|
+
* Useful for creating new instances of axios if you want to create http requests to
|
|
365
|
+
* external APIs and not send tokens etc..
|
|
366
|
+
* @name api.axios
|
|
367
|
+
* @example
|
|
368
|
+
* const newRequest = await sdk.api.axios.get('https://otherapi.com/content/61eca4746971e75c1fc670cf');
|
|
369
|
+
*/
|
|
370
|
+
|
|
371
|
+
service.CancelToken = CancelToken;
|
|
372
|
+
service.axios = axios;
|
|
373
|
+
|
|
374
|
+
///////////////////////////////////////
|
|
375
|
+
|
|
376
|
+
return service;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
///////////////////////////////////////
|
|
380
|
+
///////////////////////////////////////
|
|
381
|
+
///////////////////////////////////////
|
|
382
|
+
|
|
383
|
+
export { CancelToken as CancelToken };
|
|
384
|
+
export default QikAPI;
|
|
385
|
+
</code></pre>
|
|
386
|
+
</article>
|
|
387
|
+
</section>
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
</div>
|
|
395
|
+
|
|
396
|
+
<br class="clear">
|
|
397
|
+
|
|
398
|
+
<footer>
|
|
399
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Mon Jul 13 2026 18:47:22 GMT+1000 (Australian Eastern Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
400
|
+
</footer>
|
|
401
|
+
|
|
402
|
+
<script>prettyPrint();</script>
|
|
403
|
+
<script src="scripts/polyfill.js"></script>
|
|
404
|
+
<script src="scripts/linenumber.js"></script>
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
</body>
|
|
409
|
+
</html>
|