epicenter-libs 3.33.0 → 3.34.1
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/CHANGELOG.md +17 -0
- package/dist/browser/epicenter.js +105 -2
- package/dist/browser/epicenter.js.map +1 -1
- package/dist/cjs/epicenter.js +105 -2
- package/dist/cjs/epicenter.js.map +1 -1
- package/dist/epicenter.js +105 -2
- package/dist/epicenter.js.map +1 -1
- package/dist/epicenter.min.js +1 -1
- package/dist/epicenter.min.js.map +1 -1
- package/dist/module/epicenter.js +105 -2
- package/dist/module/epicenter.js.map +1 -1
- package/dist/types/adapters/chat.d.ts +63 -0
- package/package.json +1 -1
- package/src/adapters/chat.ts +95 -0
- package/src/utils/identification.ts +4 -0
- package/dist/test/_virtual/runtime.js +0 -3
- package/dist/test/_virtual/runtime2.js +0 -3
- package/dist/test/adapters/account.js +0 -169
- package/dist/test/adapters/admin.js +0 -53
- package/dist/test/adapters/asset.js +0 -425
- package/dist/test/adapters/authentication.js +0 -349
- package/dist/test/adapters/channel.js +0 -201
- package/dist/test/adapters/chat.js +0 -199
- package/dist/test/adapters/cometd.js +0 -514
- package/dist/test/adapters/consensus.js +0 -484
- package/dist/test/adapters/daily.js +0 -244
- package/dist/test/adapters/email.js +0 -179
- package/dist/test/adapters/episode.js +0 -175
- package/dist/test/adapters/group.js +0 -655
- package/dist/test/adapters/leaderboard.js +0 -162
- package/dist/test/adapters/matchmaker.js +0 -159
- package/dist/test/adapters/presence.js +0 -85
- package/dist/test/adapters/project.js +0 -94
- package/dist/test/adapters/recaptcha.js +0 -24
- package/dist/test/adapters/run.js +0 -1008
- package/dist/test/adapters/somebody.js +0 -154
- package/dist/test/adapters/task.js +0 -192
- package/dist/test/adapters/time.js +0 -28
- package/dist/test/adapters/user.js +0 -105
- package/dist/test/adapters/vault.js +0 -403
- package/dist/test/adapters/video.js +0 -249
- package/dist/test/adapters/vonage.js +0 -130
- package/dist/test/adapters/wallet.js +0 -130
- package/dist/test/adapters/world.js +0 -507
- package/dist/test/apis/video.js +0 -294
- package/dist/test/apis/vonage.js +0 -121
- package/dist/test/epicenter.js +0 -121
- package/dist/test/node_modules/@babel/runtime/helpers/esm/defineProperty.js +0 -12
- package/dist/test/node_modules/@babel/runtime/helpers/esm/toPrimitive.js +0 -14
- package/dist/test/node_modules/@babel/runtime/helpers/esm/toPropertyKey.js +0 -9
- package/dist/test/node_modules/@babel/runtime/helpers/esm/typeof.js +0 -11
- package/dist/test/node_modules/cometd/AckExtension.js +0 -91
- package/dist/test/node_modules/cometd/CallbackPollingTransport.js +0 -148
- package/dist/test/node_modules/cometd/Client.js +0 -2160
- package/dist/test/node_modules/cometd/Extension.js +0 -47
- package/dist/test/node_modules/cometd/LongPollingTransport.js +0 -135
- package/dist/test/node_modules/cometd/ReloadExtension.js +0 -214
- package/dist/test/node_modules/cometd/RequestTransport.js +0 -252
- package/dist/test/node_modules/cometd/Transport.js +0 -167
- package/dist/test/node_modules/cometd/TransportRegistry.js +0 -107
- package/dist/test/node_modules/cometd/WebSocketTransport.js +0 -384
- package/dist/test/node_modules/cometd/cometd.js +0 -9
- package/dist/test/node_modules/regenerator-runtime/runtime.js +0 -773
- package/dist/test/utilities.js +0 -17
- package/dist/test/utils/config.js +0 -189
- package/dist/test/utils/constants.js +0 -293
- package/dist/test/utils/cookies.js +0 -75
- package/dist/test/utils/error-manager.js +0 -57
- package/dist/test/utils/error.js +0 -12
- package/dist/test/utils/fault.js +0 -34
- package/dist/test/utils/filter-parser.js +0 -68
- package/dist/test/utils/helpers.js +0 -9
- package/dist/test/utils/identification.js +0 -161
- package/dist/test/utils/result.js +0 -20
- package/dist/test/utils/router.js +0 -551
- package/dist/test/utils/store.js +0 -79
|
@@ -1,551 +0,0 @@
|
|
|
1
|
-
import _defineProperty from '../node_modules/@babel/runtime/helpers/esm/defineProperty.js';
|
|
2
|
-
import fetch from 'cross-fetch';
|
|
3
|
-
import EpicenterError from './error.js';
|
|
4
|
-
import Fault from './fault.js';
|
|
5
|
-
import Result from './result.js';
|
|
6
|
-
import identification from './identification.js';
|
|
7
|
-
import errorManager from './error-manager.js';
|
|
8
|
-
import config from './config.js';
|
|
9
|
-
import { prefix, isBrowser } from './helpers.js';
|
|
10
|
-
|
|
11
|
-
const MAX_URL_LENGTH = 2048;
|
|
12
|
-
function paginate(json, url, options) {
|
|
13
|
-
var _options$parsePage;
|
|
14
|
-
const parsePage = (_options$parsePage = options.parsePage) !== null && _options$parsePage !== void 0 ? _options$parsePage : i => i;
|
|
15
|
-
const page = {
|
|
16
|
-
...json,
|
|
17
|
-
values: parsePage(json.values)
|
|
18
|
-
};
|
|
19
|
-
const prev = async function () {
|
|
20
|
-
const searchParams = new URLSearchParams(url.search);
|
|
21
|
-
if (page.firstResult === 0) {
|
|
22
|
-
console.warn('Pagination: cannot call "prev" on first page');
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
const first = page.firstResult - page.maxResults;
|
|
26
|
-
const max = page.maxResults + (first < 0 ? first : 0);
|
|
27
|
-
searchParams.set('first', Math.max(first, 0).toString());
|
|
28
|
-
searchParams.set('max', max.toString());
|
|
29
|
-
url.search = searchParams.toString();
|
|
30
|
-
// eslint-disable-next-line no-use-before-define
|
|
31
|
-
const prevPage = await request(url, {
|
|
32
|
-
...options,
|
|
33
|
-
paginated: false
|
|
34
|
-
}).then(({
|
|
35
|
-
body
|
|
36
|
-
}) => body);
|
|
37
|
-
prevPage.values = parsePage(prevPage.values);
|
|
38
|
-
Object.assign(page, prevPage);
|
|
39
|
-
return page.values;
|
|
40
|
-
};
|
|
41
|
-
const next = async function () {
|
|
42
|
-
const searchParams = new URLSearchParams(url.search);
|
|
43
|
-
const first = page.firstResult + page.maxResults;
|
|
44
|
-
if (first >= page.totalResults) {
|
|
45
|
-
console.warn('Pagination: cannot call "next" on final page');
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
searchParams.set('first', first.toString());
|
|
49
|
-
url.search = searchParams.toString();
|
|
50
|
-
// eslint-disable-next-line no-use-before-define
|
|
51
|
-
const nextPage = await request(url, {
|
|
52
|
-
...options,
|
|
53
|
-
paginated: false
|
|
54
|
-
}).then(({
|
|
55
|
-
body
|
|
56
|
-
}) => body);
|
|
57
|
-
nextPage.values = parsePage(nextPage.values);
|
|
58
|
-
Object.assign(page, nextPage);
|
|
59
|
-
return page.values;
|
|
60
|
-
};
|
|
61
|
-
const initialTotal = json.totalResults;
|
|
62
|
-
const all = async function (first = 0, allValues = []) {
|
|
63
|
-
if (first >= initialTotal) return allValues;
|
|
64
|
-
const searchParams = new URLSearchParams(url.search);
|
|
65
|
-
searchParams.set('first', first.toString());
|
|
66
|
-
searchParams.delete('max');
|
|
67
|
-
url.search = searchParams.toString();
|
|
68
|
-
// eslint-disable-next-line no-use-before-define
|
|
69
|
-
const nextPage = await request(url, {
|
|
70
|
-
...options,
|
|
71
|
-
paginated: false
|
|
72
|
-
}).then(({
|
|
73
|
-
body
|
|
74
|
-
}) => body);
|
|
75
|
-
allValues.push(...parsePage(nextPage.values));
|
|
76
|
-
return all(first + nextPage.maxResults, allValues);
|
|
77
|
-
};
|
|
78
|
-
page.prev = prev;
|
|
79
|
-
page.next = next;
|
|
80
|
-
page.all = all;
|
|
81
|
-
return page;
|
|
82
|
-
}
|
|
83
|
-
const parseQuery = query => {
|
|
84
|
-
if (query.constructor === URLSearchParams) {
|
|
85
|
-
return query;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/* 'query' should be either an array, or string. Objects will be coerced into [key, value] arrays */
|
|
89
|
-
if (typeof query === 'object' && query.constructor === Object) {
|
|
90
|
-
query = Object.entries(query).reduce((arr, [key, value]) => {
|
|
91
|
-
if (Array.isArray(value)) {
|
|
92
|
-
/* Special case for arrayed param values: use duplicated params here */
|
|
93
|
-
return [...arr, ...value.map(v => [key, v])];
|
|
94
|
-
}
|
|
95
|
-
if (value === undefined || value === null) {
|
|
96
|
-
/* Skip nullish values */
|
|
97
|
-
return arr;
|
|
98
|
-
}
|
|
99
|
-
arr.push([key, value.toString()]);
|
|
100
|
-
return arr;
|
|
101
|
-
}, []);
|
|
102
|
-
}
|
|
103
|
-
return new URLSearchParams(query);
|
|
104
|
-
};
|
|
105
|
-
const createMessage = (headersRaw, bodyRaw, includeAuthorization, authorization) => {
|
|
106
|
-
const headers = Object.assign({}, headersRaw);
|
|
107
|
-
let body = null;
|
|
108
|
-
if (isBrowser() && bodyRaw instanceof FormData) {
|
|
109
|
-
body = bodyRaw;
|
|
110
|
-
} else if (bodyRaw) {
|
|
111
|
-
headers['Content-type'] = 'application/json; charset=UTF-8';
|
|
112
|
-
body = JSON.stringify(bodyRaw);
|
|
113
|
-
}
|
|
114
|
-
if (!includeAuthorization) {
|
|
115
|
-
delete headers.Authorization;
|
|
116
|
-
return {
|
|
117
|
-
headers,
|
|
118
|
-
body
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
const {
|
|
122
|
-
session
|
|
123
|
-
} = identification;
|
|
124
|
-
if (!headers.Authorization) {
|
|
125
|
-
// "headers" option as primary everything
|
|
126
|
-
if (session) headers.Authorization = `Bearer ${session.token}`; // session token should be default
|
|
127
|
-
if (authorization) headers.Authorization = authorization; // Router option as tertiary override
|
|
128
|
-
if (config.authOverride) headers.Authorization = config.authOverride; // config fallback as secondary override
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
headers,
|
|
132
|
-
body
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
const NO_CONTENT = 204;
|
|
136
|
-
const BAD_REQUEST = 400;
|
|
137
|
-
const OK = 200;
|
|
138
|
-
async function request(url, options) {
|
|
139
|
-
// Different browsers have different max URL lengths; we limit to 2048 as a safe
|
|
140
|
-
// lower boundary to prevent truncation that might not be apparent to the user.
|
|
141
|
-
// This can occur in particular with GET requests with large query strings.
|
|
142
|
-
if (url.href.length > MAX_URL_LENGTH) {
|
|
143
|
-
throw new EpicenterError(`URL length exceeds maximum of ${MAX_URL_LENGTH} characters: ${url.href.length} characters.`);
|
|
144
|
-
}
|
|
145
|
-
const {
|
|
146
|
-
method,
|
|
147
|
-
headers,
|
|
148
|
-
body,
|
|
149
|
-
includeAuthorization,
|
|
150
|
-
inert,
|
|
151
|
-
paginated,
|
|
152
|
-
authorization
|
|
153
|
-
} = options;
|
|
154
|
-
const message = createMessage(headers, body, includeAuthorization, authorization);
|
|
155
|
-
const response = await fetch(url.toString(), {
|
|
156
|
-
method,
|
|
157
|
-
cache: 'no-cache',
|
|
158
|
-
redirect: 'follow',
|
|
159
|
-
headers: message.headers,
|
|
160
|
-
body: message.body
|
|
161
|
-
});
|
|
162
|
-
if (response.status === NO_CONTENT) {
|
|
163
|
-
return new Result(undefined, response);
|
|
164
|
-
}
|
|
165
|
-
const resContentType = response.headers.get('content-type');
|
|
166
|
-
if (!resContentType || !resContentType.includes('application/json')) {
|
|
167
|
-
throw new EpicenterError(`Response content-type '${resContentType}' does not include 'application/json' and my url is ${url.toString()}, ${method}`);
|
|
168
|
-
}
|
|
169
|
-
const json = await response.json();
|
|
170
|
-
if (response.status >= OK && response.status < BAD_REQUEST) {
|
|
171
|
-
const result = new Result(paginated ? paginate(json, url, options) : json, response);
|
|
172
|
-
return result;
|
|
173
|
-
}
|
|
174
|
-
const fault = new Fault(json, response);
|
|
175
|
-
if (inert === true) throw fault;
|
|
176
|
-
if (typeof inert === 'function' && inert(fault)) throw fault;
|
|
177
|
-
const retryOptions = {
|
|
178
|
-
...options,
|
|
179
|
-
inert: true
|
|
180
|
-
};
|
|
181
|
-
const retry = () => request(url, retryOptions);
|
|
182
|
-
retry.requestArguments = {
|
|
183
|
-
url,
|
|
184
|
-
...retryOptions
|
|
185
|
-
};
|
|
186
|
-
return errorManager.handle(fault, retry);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Used to make the network calls in all API adapters
|
|
191
|
-
*/
|
|
192
|
-
class Router {
|
|
193
|
-
constructor() {
|
|
194
|
-
_defineProperty(this, "_version", undefined);
|
|
195
|
-
_defineProperty(this, "_server", undefined);
|
|
196
|
-
_defineProperty(this, "_useProjectProxy", undefined);
|
|
197
|
-
_defineProperty(this, "_accountShortName", undefined);
|
|
198
|
-
_defineProperty(this, "_projectShortName", undefined);
|
|
199
|
-
_defineProperty(this, "_authorization", undefined);
|
|
200
|
-
_defineProperty(this, "_searchParams", new URLSearchParams());
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* The version of the Epicenter APIs being invoked; expected to stay at `3`
|
|
204
|
-
*/
|
|
205
|
-
get version() {
|
|
206
|
-
return this._version;
|
|
207
|
-
}
|
|
208
|
-
set version(value) {
|
|
209
|
-
this._version = value;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* The root path used for the call, essentially protocol + hostname
|
|
214
|
-
* @type {string}
|
|
215
|
-
*/
|
|
216
|
-
get server() {
|
|
217
|
-
return this._server;
|
|
218
|
-
}
|
|
219
|
-
set server(value) {
|
|
220
|
-
this._server = value;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* If true, requests are routed to project proxy server.
|
|
225
|
-
* The proxy server processes requests and forwards them to the Epicenter platform as appropriate,
|
|
226
|
-
* usually with some modification. Can be used to grant heightened privileges to a request.
|
|
227
|
-
*
|
|
228
|
-
* If true, prefixes all request pathnames with `proxy/${accountShortName}/${projectShortName}/`.
|
|
229
|
-
* @type {boolean}
|
|
230
|
-
*/
|
|
231
|
-
get useProjectProxy() {
|
|
232
|
-
return this._useProjectProxy;
|
|
233
|
-
}
|
|
234
|
-
set useProjectProxy(value) {
|
|
235
|
-
this._useProjectProxy = value;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Name of the account; for administrative use, this value should be set to 'epicenter'
|
|
240
|
-
* @type {string}
|
|
241
|
-
*/
|
|
242
|
-
get accountShortName() {
|
|
243
|
-
return this._accountShortName;
|
|
244
|
-
}
|
|
245
|
-
set accountShortName(value) {
|
|
246
|
-
this._accountShortName = value;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Name of the project; for administrative use, this value should be set to 'manager'
|
|
251
|
-
* @type {string}
|
|
252
|
-
*/
|
|
253
|
-
get projectShortName() {
|
|
254
|
-
return this._projectShortName;
|
|
255
|
-
}
|
|
256
|
-
set projectShortName(value) {
|
|
257
|
-
this._projectShortName = value;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Auth header; looks like `Bearer TOKEN` or `Basic TOKEN`
|
|
262
|
-
* @type {string}
|
|
263
|
-
*/
|
|
264
|
-
get authorization() {
|
|
265
|
-
return this._authorization;
|
|
266
|
-
}
|
|
267
|
-
set authorization(value) {
|
|
268
|
-
this._authorization = value;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* The search parameters for to use when making a network request. This property has should always return an instance of URLSearchParams or undefined. It has unique properties when used with the assignment operator (`=`); see the examples below for more details.
|
|
273
|
-
* @type {URLSearchParams}
|
|
274
|
-
*
|
|
275
|
-
* @example
|
|
276
|
-
* const router = new Router();
|
|
277
|
-
* router.searchParams = '?foo=123';
|
|
278
|
-
* console.log(router.searchParams); // always returns an instance object: URLSearchParams {}
|
|
279
|
-
* console.log(router.searchParams.toString()); // logs 'foo=123'
|
|
280
|
-
*
|
|
281
|
-
* router.searchParams = 'foo=123'; // can omit the question mark
|
|
282
|
-
* console.log(router.searchParams.toString()); // logs 'foo=123'
|
|
283
|
-
*
|
|
284
|
-
* router.searchParams = [['foo', '123'], ['bar', '456']]; // can accept arrays
|
|
285
|
-
* console.log(router.searchParams.toString()); // logs 'foo=123&bar=456'
|
|
286
|
-
*
|
|
287
|
-
* router.searchParams = { foo: '123', bar: '456' }; // can accept objects
|
|
288
|
-
* console.log(router.searchParams.toString()); // logs 'foo=123&bar=456'
|
|
289
|
-
*
|
|
290
|
-
* router.searchParams = { foo: '123', bar: ['4', '5', '6'] }; // can accept objects with arrayed values
|
|
291
|
-
* console.log(router.searchParams.toString()); // logs 'foo=123&bar=4&bar=5&bar=6'
|
|
292
|
-
*
|
|
293
|
-
* router.searchParams = new URLSearchParams('foo=123'); // can accept instances of URLSearchParams
|
|
294
|
-
* console.log(router.searchParams.toString()); // logs 'foo=123'
|
|
295
|
-
*
|
|
296
|
-
* @param {object|array|string|URLSearchParams} query Value used to set the search parameters
|
|
297
|
-
*/
|
|
298
|
-
get searchParams() {
|
|
299
|
-
return this._searchParams;
|
|
300
|
-
}
|
|
301
|
-
set searchParams(query) {
|
|
302
|
-
this._searchParams = parseQuery(query);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Sets the version. Does nothing if invoked with no input. This is a part of a series of convenience functions for chaining sets on values.
|
|
307
|
-
* @param {string} [version] Version to use
|
|
308
|
-
* @returns {Router} The Router instance
|
|
309
|
-
*/
|
|
310
|
-
withVersion(version) {
|
|
311
|
-
if (typeof version !== 'undefined') this.version = version;
|
|
312
|
-
return this;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Sets the root path. Does nothing if invoked with no input. This is a part of a series of convenience functions for chaining sets on values.
|
|
317
|
-
* @param {string} [server] Root path to use
|
|
318
|
-
* @returns {Router} The Router instance
|
|
319
|
-
*/
|
|
320
|
-
withServer(server) {
|
|
321
|
-
if (typeof server !== 'undefined') this.server = server;
|
|
322
|
-
return this;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Sets whether to route requests to project proxy server. Does nothing if invoked with no input. This is a part of a series of convenience functions for chaining sets on values.
|
|
327
|
-
* @param {string} [useProjectProxy] Whether to use the proxy server
|
|
328
|
-
* @returns {Router} The Router instance
|
|
329
|
-
*/
|
|
330
|
-
withProjectProxy(useProjectProxy) {
|
|
331
|
-
if (typeof useProjectProxy !== 'undefined') this.useProjectProxy = useProjectProxy;
|
|
332
|
-
return this;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Sets the account. Does nothing if invoked with no input. This is a part of a series of convenience functions for chaining sets on values.
|
|
337
|
-
* @param {string} [accountShortName] Account name to use
|
|
338
|
-
* @returns {Router} The Router instance
|
|
339
|
-
*/
|
|
340
|
-
withAccountShortName(accountShortName) {
|
|
341
|
-
if (typeof accountShortName !== 'undefined') this.accountShortName = accountShortName;
|
|
342
|
-
return this;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Sets the project. Does nothing if invoked with no input. This is a part of a series of convenience functions for chaining sets on values.
|
|
347
|
-
* @param {string} [projectShortName] Project name to use
|
|
348
|
-
* @returns {Router} The Router instance
|
|
349
|
-
*/
|
|
350
|
-
withProjectShortName(projectShortName) {
|
|
351
|
-
if (typeof projectShortName !== 'undefined') this.projectShortName = projectShortName;
|
|
352
|
-
return this;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Sets the project. Does nothing if invoked with no input. This is a part of a series of convenience functions for chaining sets on values.
|
|
357
|
-
* @param {string} [projectShortName] Project name to use
|
|
358
|
-
* @returns {Router} The Router instance
|
|
359
|
-
*/
|
|
360
|
-
withAuthorization(authorization) {
|
|
361
|
-
if (typeof authorization !== 'undefined') this.authorization = authorization;
|
|
362
|
-
return this;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* Sets the search parameters. Does nothing if invoked with no input. This is a part of a series of convenience functions for chaining sets on values.
|
|
367
|
-
* @param {string|array|object|URLSearchParams} [searchParams] Search parameters to use, utilizes the same setter as [searchParams](#Router-searchParams)
|
|
368
|
-
* @returns {Router} The Router instance
|
|
369
|
-
*/
|
|
370
|
-
withSearchParams(searchParams) {
|
|
371
|
-
if (typeof searchParams !== 'undefined') this.searchParams = searchParams;
|
|
372
|
-
return this;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Creates the URL that would be used for a network request. Should prioritize any overrides provided to it, falling back to any values set local to the Router instance, falling back to values set in the config
|
|
377
|
-
* @param uriComponent The URI component used to generate the URL object
|
|
378
|
-
* @param [overrides] Overrides for generating the URL object
|
|
379
|
-
* @param [overrides.server] Override for the root URL string -- composed of the protocol and the hostname; e.g., https://forio.com
|
|
380
|
-
* @param [overrides.useProjectProxy] Override for routing requests to the project proxy server
|
|
381
|
-
* @param [overrides.accountShortName] Override for the account short name
|
|
382
|
-
* @param [overrides.projectShortName] Override for the project short name
|
|
383
|
-
* @param [overrides.version] Override for the version (NIU, is set by the config)
|
|
384
|
-
* @param [overrides.query] Override for the URL search query
|
|
385
|
-
* @returns URL object
|
|
386
|
-
*/
|
|
387
|
-
getURL(uriComponent, overrides = {}) {
|
|
388
|
-
var _ref, _overrides$server, _ref2, _overrides$useProject, _ref3, _overrides$accountSho, _ref4, _overrides$projectSho, _ref5, _overrides$version, _this$searchParams;
|
|
389
|
-
const server = (_ref = (_overrides$server = overrides.server) !== null && _overrides$server !== void 0 ? _overrides$server : this.server) !== null && _ref !== void 0 ? _ref : `${config.apiProtocol}://${config.apiHost}`;
|
|
390
|
-
const useProjectProxy = (_ref2 = (_overrides$useProject = overrides.useProjectProxy) !== null && _overrides$useProject !== void 0 ? _overrides$useProject : this.useProjectProxy) !== null && _ref2 !== void 0 ? _ref2 : config.useProjectProxy;
|
|
391
|
-
const accountShortName = (_ref3 = (_overrides$accountSho = overrides.accountShortName) !== null && _overrides$accountSho !== void 0 ? _overrides$accountSho : this.accountShortName) !== null && _ref3 !== void 0 ? _ref3 : config.accountShortName;
|
|
392
|
-
const projectShortName = (_ref4 = (_overrides$projectSho = overrides.projectShortName) !== null && _overrides$projectSho !== void 0 ? _overrides$projectSho : this.projectShortName) !== null && _ref4 !== void 0 ? _ref4 : config.projectShortName;
|
|
393
|
-
const version = (_ref5 = (_overrides$version = overrides === null || overrides === void 0 ? void 0 : overrides.version) !== null && _overrides$version !== void 0 ? _overrides$version : this.version) !== null && _ref5 !== void 0 ? _ref5 : config.apiVersion;
|
|
394
|
-
const url = new URL(`${server}`);
|
|
395
|
-
const proxyPathComponent = useProjectProxy ? `proxy/${accountShortName}/${projectShortName}/` : '';
|
|
396
|
-
const commonPathComponent = `api/v${version}/${accountShortName}/${projectShortName}`;
|
|
397
|
-
const uniquePathComponent = prefix('/', uriComponent);
|
|
398
|
-
url.pathname = `${proxyPathComponent}${commonPathComponent}${uniquePathComponent}`;
|
|
399
|
-
url.search = overrides.query !== undefined ? parseQuery(overrides.query).toString() : ((_this$searchParams = this.searchParams) !== null && _this$searchParams !== void 0 ? _this$searchParams : new URLSearchParams()).toString();
|
|
400
|
-
return url;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
// Network Requests
|
|
404
|
-
async get(uriComponent, options = {}) {
|
|
405
|
-
const {
|
|
406
|
-
accountShortName,
|
|
407
|
-
projectShortName,
|
|
408
|
-
authorization,
|
|
409
|
-
server,
|
|
410
|
-
query,
|
|
411
|
-
useProjectProxy,
|
|
412
|
-
headers,
|
|
413
|
-
includeAuthorization,
|
|
414
|
-
inert,
|
|
415
|
-
paginated,
|
|
416
|
-
parsePage
|
|
417
|
-
} = options;
|
|
418
|
-
const url = this.getURL(uriComponent, {
|
|
419
|
-
server,
|
|
420
|
-
query,
|
|
421
|
-
accountShortName,
|
|
422
|
-
projectShortName,
|
|
423
|
-
useProjectProxy
|
|
424
|
-
});
|
|
425
|
-
return request(url, {
|
|
426
|
-
method: 'GET',
|
|
427
|
-
headers,
|
|
428
|
-
includeAuthorization: includeAuthorization !== null && includeAuthorization !== void 0 ? includeAuthorization : true,
|
|
429
|
-
authorization: authorization !== null && authorization !== void 0 ? authorization : this.authorization,
|
|
430
|
-
inert,
|
|
431
|
-
paginated,
|
|
432
|
-
parsePage
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
async delete(uriComponent, options = {}) {
|
|
436
|
-
const {
|
|
437
|
-
accountShortName,
|
|
438
|
-
projectShortName,
|
|
439
|
-
authorization,
|
|
440
|
-
server,
|
|
441
|
-
query,
|
|
442
|
-
useProjectProxy,
|
|
443
|
-
headers,
|
|
444
|
-
includeAuthorization,
|
|
445
|
-
inert
|
|
446
|
-
} = options;
|
|
447
|
-
const url = this.getURL(uriComponent, {
|
|
448
|
-
server,
|
|
449
|
-
query,
|
|
450
|
-
accountShortName,
|
|
451
|
-
projectShortName,
|
|
452
|
-
useProjectProxy
|
|
453
|
-
});
|
|
454
|
-
return request(url, {
|
|
455
|
-
method: 'DELETE',
|
|
456
|
-
headers,
|
|
457
|
-
includeAuthorization: includeAuthorization !== null && includeAuthorization !== void 0 ? includeAuthorization : true,
|
|
458
|
-
authorization: authorization !== null && authorization !== void 0 ? authorization : this.authorization,
|
|
459
|
-
inert
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
async patch(uriComponent, options = {}) {
|
|
463
|
-
const {
|
|
464
|
-
accountShortName,
|
|
465
|
-
projectShortName,
|
|
466
|
-
authorization,
|
|
467
|
-
server,
|
|
468
|
-
query,
|
|
469
|
-
useProjectProxy,
|
|
470
|
-
headers,
|
|
471
|
-
body,
|
|
472
|
-
includeAuthorization,
|
|
473
|
-
inert
|
|
474
|
-
} = options;
|
|
475
|
-
const url = this.getURL(uriComponent, {
|
|
476
|
-
server,
|
|
477
|
-
query,
|
|
478
|
-
accountShortName,
|
|
479
|
-
projectShortName,
|
|
480
|
-
useProjectProxy
|
|
481
|
-
});
|
|
482
|
-
return request(url, {
|
|
483
|
-
method: 'PATCH',
|
|
484
|
-
headers,
|
|
485
|
-
body,
|
|
486
|
-
includeAuthorization: includeAuthorization !== null && includeAuthorization !== void 0 ? includeAuthorization : true,
|
|
487
|
-
authorization: authorization !== null && authorization !== void 0 ? authorization : this.authorization,
|
|
488
|
-
inert
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
async post(uriComponent, options = {}) {
|
|
492
|
-
const {
|
|
493
|
-
accountShortName,
|
|
494
|
-
projectShortName,
|
|
495
|
-
authorization,
|
|
496
|
-
server,
|
|
497
|
-
query,
|
|
498
|
-
useProjectProxy,
|
|
499
|
-
headers,
|
|
500
|
-
body,
|
|
501
|
-
includeAuthorization,
|
|
502
|
-
inert
|
|
503
|
-
} = options;
|
|
504
|
-
const url = this.getURL(uriComponent, {
|
|
505
|
-
server,
|
|
506
|
-
query,
|
|
507
|
-
accountShortName,
|
|
508
|
-
projectShortName,
|
|
509
|
-
useProjectProxy
|
|
510
|
-
});
|
|
511
|
-
return request(url, {
|
|
512
|
-
method: 'POST',
|
|
513
|
-
headers,
|
|
514
|
-
body,
|
|
515
|
-
includeAuthorization: includeAuthorization !== null && includeAuthorization !== void 0 ? includeAuthorization : true,
|
|
516
|
-
authorization: authorization !== null && authorization !== void 0 ? authorization : this.authorization,
|
|
517
|
-
inert
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
async put(uriComponent, options = {}) {
|
|
521
|
-
const {
|
|
522
|
-
accountShortName,
|
|
523
|
-
projectShortName,
|
|
524
|
-
authorization,
|
|
525
|
-
server,
|
|
526
|
-
query,
|
|
527
|
-
useProjectProxy,
|
|
528
|
-
headers,
|
|
529
|
-
body,
|
|
530
|
-
includeAuthorization,
|
|
531
|
-
inert
|
|
532
|
-
} = options;
|
|
533
|
-
const url = this.getURL(uriComponent, {
|
|
534
|
-
server,
|
|
535
|
-
query,
|
|
536
|
-
accountShortName,
|
|
537
|
-
projectShortName,
|
|
538
|
-
useProjectProxy
|
|
539
|
-
});
|
|
540
|
-
return request(url, {
|
|
541
|
-
method: 'PUT',
|
|
542
|
-
headers,
|
|
543
|
-
body,
|
|
544
|
-
includeAuthorization: includeAuthorization !== null && includeAuthorization !== void 0 ? includeAuthorization : true,
|
|
545
|
-
authorization: authorization !== null && authorization !== void 0 ? authorization : this.authorization,
|
|
546
|
-
inert
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
export { MAX_URL_LENGTH, Router as default };
|
package/dist/test/utils/store.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import _defineProperty from '../node_modules/@babel/runtime/helpers/esm/defineProperty.js';
|
|
2
|
-
import cookies from './cookies.js';
|
|
3
|
-
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
-
|
|
6
|
-
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
7
|
-
|
|
8
|
-
class Store {
|
|
9
|
-
constructor(store) {
|
|
10
|
-
_defineProperty(this, "_store", void 0);
|
|
11
|
-
this._store = store;
|
|
12
|
-
}
|
|
13
|
-
clear() {
|
|
14
|
-
this._store.clear();
|
|
15
|
-
}
|
|
16
|
-
get store() {
|
|
17
|
-
return this._store;
|
|
18
|
-
}
|
|
19
|
-
set store(store) {
|
|
20
|
-
this._store = store;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
const nodeMap = new Map();
|
|
24
|
-
class NodeStore extends Store {
|
|
25
|
-
constructor() {
|
|
26
|
-
super(nodeMap);
|
|
27
|
-
}
|
|
28
|
-
getItem(key) {
|
|
29
|
-
return super.store.get(key);
|
|
30
|
-
}
|
|
31
|
-
setItem(key, value) {
|
|
32
|
-
return super.store.set(key, value);
|
|
33
|
-
}
|
|
34
|
-
removeItem(key) {
|
|
35
|
-
return super.store.delete(key);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
class SessionStore extends Store {
|
|
39
|
-
constructor() {
|
|
40
|
-
super(window.sessionStorage);
|
|
41
|
-
}
|
|
42
|
-
getItem(key) {
|
|
43
|
-
const item = super.store.getItem(key);
|
|
44
|
-
return item ? JSON.parse(item) : null;
|
|
45
|
-
}
|
|
46
|
-
setItem(key, value) {
|
|
47
|
-
return super.store.setItem(key, JSON.stringify(value));
|
|
48
|
-
}
|
|
49
|
-
removeItem(key) {
|
|
50
|
-
return super.store.removeItem(key);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
class CookieStore {
|
|
54
|
-
constructor(options = {}) {
|
|
55
|
-
_defineProperty(this, "options", {});
|
|
56
|
-
const defaults = {
|
|
57
|
-
path: '/'
|
|
58
|
-
};
|
|
59
|
-
this.options = {
|
|
60
|
-
...defaults,
|
|
61
|
-
...options
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
getItem(key) {
|
|
65
|
-
const item = cookies.getItem(key);
|
|
66
|
-
return item ? JSON.parse(item) : null;
|
|
67
|
-
}
|
|
68
|
-
setItem(key, value) {
|
|
69
|
-
return cookies.setItem(key, JSON.stringify(value), this.options);
|
|
70
|
-
}
|
|
71
|
-
removeItem(key) {
|
|
72
|
-
return cookies.removeItem(key, this.options);
|
|
73
|
-
}
|
|
74
|
-
clear() {
|
|
75
|
-
return cookies.clear();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export { CookieStore, NodeStore, SessionStore };
|