@allthings/sdk 7.3.0 → 8.1.0
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/cli.js +400 -330
- package/dist/lib.cjs.js +398 -328
- package/dist/lib.esm.js +398 -328
- package/dist/lib.umd.min.js +1 -1
- package/dist/src/oauth/authorizationCodeGrant.d.ts +4 -4
- package/dist/src/oauth/implicitGrant.d.ts +2 -2
- package/dist/src/oauth/makeFetchTokenRequester.d.ts +1 -1
- package/dist/src/oauth/passwordGrant.d.ts +2 -2
- package/dist/src/oauth/refreshTokenGrant.d.ts +2 -2
- package/dist/src/oauth/types.d.ts +1 -1
- package/dist/src/rest/delete.d.ts +2 -6
- package/dist/src/rest/get.d.ts +2 -6
- package/dist/src/rest/methods/idLookup.d.ts +1 -3
- package/dist/src/rest/methods/user.d.ts +2 -6
- package/dist/src/rest/patch.d.ts +2 -6
- package/dist/src/rest/post.d.ts +2 -6
- package/dist/src/rest/put.d.ts +2 -6
- package/dist/src/rest/request.d.ts +2 -6
- package/dist/src/rest/types.d.ts +1 -1
- package/dist/src/utils/functional.d.ts +3 -3
- package/dist/src/utils/logger.d.ts +0 -1
- package/dist/src/utils/object.d.ts +1 -5
- package/package.json +32 -29
package/dist/lib.cjs.js
CHANGED
|
@@ -10,6 +10,7 @@ var require$$3 = require('http');
|
|
|
10
10
|
var require$$4 = require('https');
|
|
11
11
|
var require$$5 = require('url');
|
|
12
12
|
var require$$6 = require('fs');
|
|
13
|
+
var require$$8 = require('crypto');
|
|
13
14
|
|
|
14
15
|
function createTokenStore(initialToken) {
|
|
15
16
|
const token = new Map(Object.entries(initialToken || {}));
|
|
@@ -20,7 +21,7 @@ function createTokenStore(initialToken) {
|
|
|
20
21
|
};
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
const version = "
|
|
24
|
+
const version = "8.1.0";
|
|
24
25
|
|
|
25
26
|
const REST_API_URL = 'https://api.allthings.me';
|
|
26
27
|
const OAUTH_URL = 'https://accounts.allthings.me';
|
|
@@ -45,30 +46,36 @@ const USER_AGENT = `Allthings Node SDK REST Client/${version}`;
|
|
|
45
46
|
|
|
46
47
|
const RESPONSE_TYPE$1 = 'code';
|
|
47
48
|
const GRANT_TYPE$3 = 'authorization_code';
|
|
48
|
-
const
|
|
49
|
-
const { redirectUri, clientId, scope, state } =
|
|
49
|
+
const castToAuthorizationRequestParameters$1 = (parameters) => {
|
|
50
|
+
const { redirectUri, clientId, scope, state } = parameters;
|
|
50
51
|
if (!clientId) {
|
|
51
52
|
throw new Error('Missing required "clientId" parameter to perform authorization code grant redirect');
|
|
52
53
|
}
|
|
53
54
|
if (!redirectUri) {
|
|
54
55
|
throw new Error('Missing required "redirectUri" parameter to perform authorization code grant redirect');
|
|
55
56
|
}
|
|
56
|
-
return
|
|
57
|
+
return {
|
|
58
|
+
client_id: clientId,
|
|
59
|
+
redirect_uri: redirectUri,
|
|
60
|
+
response_type: RESPONSE_TYPE$1,
|
|
61
|
+
...(scope ? { scope } : {}),
|
|
62
|
+
...(state ? { state } : {}),
|
|
63
|
+
};
|
|
57
64
|
};
|
|
58
|
-
const isEligibleForClientRedirect$1 = (
|
|
65
|
+
const isEligibleForClientRedirect$1 = (parameters) => {
|
|
59
66
|
try {
|
|
60
|
-
return !!
|
|
67
|
+
return !!castToAuthorizationRequestParameters$1(parameters);
|
|
61
68
|
}
|
|
62
|
-
catch
|
|
69
|
+
catch {
|
|
63
70
|
return false;
|
|
64
71
|
}
|
|
65
72
|
};
|
|
66
|
-
const getRedirectUrl$1 = (
|
|
73
|
+
const getRedirectUrl$1 = (parameters) => `${parameters.oauthUrl}/oauth/authorize?${querystring.stringify(castToAuthorizationRequestParameters$1(parameters), {
|
|
67
74
|
skipEmptyString: true,
|
|
68
75
|
skipNull: true,
|
|
69
76
|
})}`;
|
|
70
|
-
const
|
|
71
|
-
const { authorizationCode, redirectUri, clientId, clientSecret } =
|
|
77
|
+
const castToTokenRequestParameters$2 = (parameters) => {
|
|
78
|
+
const { authorizationCode, redirectUri, clientId, clientSecret } = parameters;
|
|
72
79
|
if (!clientId) {
|
|
73
80
|
throw new Error('Missing required "clientId" parameter to perform authorization code grant');
|
|
74
81
|
}
|
|
@@ -78,37 +85,44 @@ const castToTokenRequestParams$2 = (params) => {
|
|
|
78
85
|
if (!authorizationCode) {
|
|
79
86
|
throw new Error('Missing required "authorizationCode" parameter to perform authorization code grant');
|
|
80
87
|
}
|
|
81
|
-
return
|
|
88
|
+
return {
|
|
89
|
+
client_id: clientId,
|
|
90
|
+
code: authorizationCode,
|
|
91
|
+
grant_type: GRANT_TYPE$3,
|
|
92
|
+
redirect_uri: redirectUri,
|
|
93
|
+
...(clientSecret ? { client_secret: clientSecret } : {}),
|
|
94
|
+
};
|
|
82
95
|
};
|
|
83
|
-
const isEligible$3 = (
|
|
96
|
+
const isEligible$3 = (parameters) => {
|
|
84
97
|
try {
|
|
85
|
-
return !!
|
|
98
|
+
return !!castToTokenRequestParameters$2(parameters);
|
|
86
99
|
}
|
|
87
|
-
catch
|
|
100
|
+
catch {
|
|
88
101
|
return false;
|
|
89
102
|
}
|
|
90
103
|
};
|
|
91
|
-
const requestToken$3 = (tokenRequester,
|
|
104
|
+
const requestToken$3 = (tokenRequester, parameters) => tokenRequester(castToTokenRequestParameters$2(parameters));
|
|
92
105
|
|
|
93
|
-
const SUBSCRIPTIONS =
|
|
94
|
-
process.env.DEBUG.split(',').map((item) => item.trim())) ||
|
|
95
|
-
[];
|
|
106
|
+
const SUBSCRIPTIONS = process.env.DEBUG?.split(',').map((item) => item.trim()) || [];
|
|
96
107
|
function makeLogger(name) {
|
|
97
|
-
return ['log', 'info', 'warn', 'error'].reduce((logger, type) => (
|
|
108
|
+
return ['log', 'info', 'warn', 'error'].reduce((logger, type) => ({
|
|
109
|
+
...logger,
|
|
110
|
+
[type]: function log(...logs) {
|
|
98
111
|
if (SUBSCRIPTIONS.includes('*') ||
|
|
99
112
|
SUBSCRIPTIONS.includes(name) ||
|
|
100
113
|
SUBSCRIPTIONS.includes(name.toLocaleLowerCase())) {
|
|
101
114
|
console[type](`${name}:`, ...logs);
|
|
102
115
|
}
|
|
103
116
|
return true;
|
|
104
|
-
}
|
|
117
|
+
},
|
|
118
|
+
}), {});
|
|
105
119
|
}
|
|
106
120
|
|
|
107
121
|
const logger = makeLogger('OAuth Token Request');
|
|
108
|
-
const makeFetchTokenRequester = (url) => async (
|
|
122
|
+
const makeFetchTokenRequester = (url) => async (parameters) => {
|
|
109
123
|
try {
|
|
110
124
|
const response = await fetch(url, {
|
|
111
|
-
body: querystring.stringify(
|
|
125
|
+
body: querystring.stringify(parameters, {
|
|
112
126
|
skipEmptyString: true,
|
|
113
127
|
skipNull: true,
|
|
114
128
|
}),
|
|
@@ -143,25 +157,31 @@ const makeFetchTokenRequester = (url) => async (params) => {
|
|
|
143
157
|
};
|
|
144
158
|
|
|
145
159
|
const GRANT_TYPE$2 = 'refresh_token';
|
|
146
|
-
const
|
|
147
|
-
const { clientId, clientSecret, refreshToken, scope } =
|
|
160
|
+
const castToTokenRequestParameters$1 = (parameters) => {
|
|
161
|
+
const { clientId, clientSecret, refreshToken, scope } = parameters;
|
|
148
162
|
if (!clientId) {
|
|
149
163
|
throw new Error('Missing required "clientId" parameter to perform refresh token grant');
|
|
150
164
|
}
|
|
151
165
|
if (!refreshToken) {
|
|
152
166
|
throw new Error('Missing required "refreshToken" parameter to perform refresh token grant');
|
|
153
167
|
}
|
|
154
|
-
return
|
|
168
|
+
return {
|
|
169
|
+
client_id: clientId,
|
|
170
|
+
grant_type: GRANT_TYPE$2,
|
|
171
|
+
refresh_token: refreshToken,
|
|
172
|
+
...(clientSecret ? { client_secret: clientSecret } : {}),
|
|
173
|
+
...(scope ? { scope } : {}),
|
|
174
|
+
};
|
|
155
175
|
};
|
|
156
|
-
const isEligible$2 = (
|
|
176
|
+
const isEligible$2 = (parameters) => {
|
|
157
177
|
try {
|
|
158
|
-
return !!
|
|
178
|
+
return !!castToTokenRequestParameters$1(parameters);
|
|
159
179
|
}
|
|
160
|
-
catch
|
|
180
|
+
catch {
|
|
161
181
|
return false;
|
|
162
182
|
}
|
|
163
183
|
};
|
|
164
|
-
const requestToken$2 = (tokenRequester,
|
|
184
|
+
const requestToken$2 = (tokenRequester, parameters) => tokenRequester(castToTokenRequestParameters$1(parameters));
|
|
165
185
|
|
|
166
186
|
async function requestAndSaveToStore(requester, tokenStore) {
|
|
167
187
|
const response = await requester();
|
|
@@ -169,14 +189,14 @@ async function requestAndSaveToStore(requester, tokenStore) {
|
|
|
169
189
|
return response;
|
|
170
190
|
}
|
|
171
191
|
|
|
172
|
-
const partial = (
|
|
192
|
+
const partial = (function_, ...partialArguments) => (...arguments_) => function_(...partialArguments, ...arguments_);
|
|
173
193
|
async function until(predicate, transformer, initialValue, iterationCount = 0) {
|
|
174
194
|
const transformed = await transformer(initialValue, iterationCount);
|
|
175
195
|
return (await predicate(transformed, iterationCount))
|
|
176
196
|
? transformed
|
|
177
197
|
: until(predicate, transformer, transformed, iterationCount + 1);
|
|
178
198
|
}
|
|
179
|
-
function
|
|
199
|
+
function clearIntervalFunction(intervalId) {
|
|
180
200
|
clearInterval(intervalId);
|
|
181
201
|
return true;
|
|
182
202
|
}
|
|
@@ -184,9 +204,9 @@ function fnClearInterval(intervalId) {
|
|
|
184
204
|
function pseudoRandomString(length = 16) {
|
|
185
205
|
let token = '';
|
|
186
206
|
while (token.length < length) {
|
|
187
|
-
token += Math.random().toString(36).
|
|
207
|
+
token += Math.random().toString(36).slice(2);
|
|
188
208
|
}
|
|
189
|
-
return token.
|
|
209
|
+
return token.slice(0, Math.max(0, length));
|
|
190
210
|
}
|
|
191
211
|
|
|
192
212
|
async function del(request, method, body, returnRawResultObject, headers) {
|
|
@@ -197,17 +217,6 @@ async function get$1(request, method, query, returnRawResultObject, headers) {
|
|
|
197
217
|
return request('get', method, { headers, query }, returnRawResultObject);
|
|
198
218
|
}
|
|
199
219
|
|
|
200
|
-
var __rest$4 = (undefined && undefined.__rest) || function (s, e) {
|
|
201
|
-
var t = {};
|
|
202
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
203
|
-
t[p] = s[p];
|
|
204
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
205
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
206
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
207
|
-
t[p[i]] = s[p[i]];
|
|
208
|
-
}
|
|
209
|
-
return t;
|
|
210
|
-
};
|
|
211
220
|
var EnumGender;
|
|
212
221
|
(function (EnumGender) {
|
|
213
222
|
EnumGender["female"] = "female";
|
|
@@ -259,12 +268,16 @@ exports.EnumUserPermissionObjectType = void 0;
|
|
|
259
268
|
EnumUserPermissionObjectType["unit"] = "Unit";
|
|
260
269
|
})(exports.EnumUserPermissionObjectType || (exports.EnumUserPermissionObjectType = {}));
|
|
261
270
|
const remapUserResult = (user) => {
|
|
262
|
-
const { tenantIDs: tenantIds
|
|
263
|
-
return
|
|
271
|
+
const { tenantIDs: tenantIds, ...result } = user;
|
|
272
|
+
return { ...result, tenantIds };
|
|
264
273
|
};
|
|
265
274
|
const remapEmbeddedUser = (embedded) => embedded.users ? embedded.users.map(remapUserResult) : [];
|
|
266
275
|
async function userCreate(client, appId, username, data) {
|
|
267
|
-
return client.post('/v1/users',
|
|
276
|
+
return client.post('/v1/users', {
|
|
277
|
+
...data,
|
|
278
|
+
creationContext: appId,
|
|
279
|
+
username,
|
|
280
|
+
});
|
|
268
281
|
}
|
|
269
282
|
async function getUsers(client, page = 1, limit = -1, filter = {}) {
|
|
270
283
|
const { _embedded: { items: users }, total, } = await client.get('/v1/users', {
|
|
@@ -281,34 +294,40 @@ async function userGetById(client, userId) {
|
|
|
281
294
|
return remapUserResult(await client.get(`/v1/users/${userId}`));
|
|
282
295
|
}
|
|
283
296
|
async function userUpdateById(client, userId, data) {
|
|
284
|
-
const { tenantIds: tenantIDs
|
|
285
|
-
return remapUserResult(await client.patch(`/v1/users/${userId}`,
|
|
297
|
+
const { tenantIds: tenantIDs, ...rest } = data;
|
|
298
|
+
return remapUserResult(await client.patch(`/v1/users/${userId}`, { ...rest, tenantIDs }));
|
|
286
299
|
}
|
|
287
300
|
async function userCreatePermission(client, userId, data) {
|
|
288
|
-
const { objectId: objectID
|
|
289
|
-
const
|
|
290
|
-
|
|
301
|
+
const { objectId: objectID, ...rest } = data;
|
|
302
|
+
const { objectID: resultObjectId, ...result } = await client.post(`/v1/users/${userId}/permissions`, {
|
|
303
|
+
...rest,
|
|
304
|
+
objectID,
|
|
305
|
+
});
|
|
306
|
+
return {
|
|
307
|
+
...result,
|
|
308
|
+
objectId: resultObjectId,
|
|
309
|
+
};
|
|
291
310
|
}
|
|
292
311
|
async function userCreatePermissionBatch(client, userId, permissions) {
|
|
293
312
|
const { objectId, objectType, roles, startDate, endDate } = permissions;
|
|
294
313
|
const batch = {
|
|
295
314
|
batch: roles.map((role) => ({
|
|
296
|
-
endDate: endDate
|
|
315
|
+
endDate: endDate?.toISOString(),
|
|
297
316
|
objectID: objectId,
|
|
298
317
|
objectType,
|
|
299
318
|
restrictions: [],
|
|
300
319
|
role,
|
|
301
|
-
startDate: startDate
|
|
320
|
+
startDate: startDate?.toISOString(),
|
|
302
321
|
})),
|
|
303
322
|
};
|
|
304
323
|
return !(await client.post(`/v1/users/${userId}/permissions`, batch));
|
|
305
324
|
}
|
|
306
325
|
async function userGetPermissions(client, userId) {
|
|
307
326
|
const { _embedded: { items: permissions }, } = await client.get(`/v1/users/${userId}/roles?limit=-1`);
|
|
308
|
-
return permissions.map((
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
});
|
|
327
|
+
return permissions.map(({ objectID: objectId, ...result }) => ({
|
|
328
|
+
...result,
|
|
329
|
+
objectId,
|
|
330
|
+
}));
|
|
312
331
|
}
|
|
313
332
|
async function userDeletePermission(client, permissionId) {
|
|
314
333
|
return !(await client.delete(`/v1/permissions/${permissionId}`));
|
|
@@ -334,10 +353,19 @@ async function userChangePassword(client, userId, currentPassword, newPassword)
|
|
|
334
353
|
}
|
|
335
354
|
|
|
336
355
|
async function agentCreate(client, appId, propertyManagerId, username, data, sendInvitation, externalAgentCompany) {
|
|
337
|
-
const user = await client.userCreate(appId, username,
|
|
338
|
-
|
|
356
|
+
const user = await client.userCreate(appId, username, {
|
|
357
|
+
...data,
|
|
358
|
+
type: EnumUserType.customer,
|
|
359
|
+
});
|
|
360
|
+
const manager = await client.post(`/v1/property-managers/${propertyManagerId}/users`, {
|
|
361
|
+
userID: user.id,
|
|
362
|
+
...(externalAgentCompany && { externalAgentCompany }),
|
|
363
|
+
});
|
|
339
364
|
return (!((typeof sendInvitation !== 'undefined' ? sendInvitation : true) &&
|
|
340
|
-
(await client.post(`/v1/users/${user.id}/invitations`))) &&
|
|
365
|
+
(await client.post(`/v1/users/${user.id}/invitations`))) && {
|
|
366
|
+
...user,
|
|
367
|
+
...manager,
|
|
368
|
+
});
|
|
341
369
|
}
|
|
342
370
|
async function agentCreatePermissions(client, agentId, objectId, objectType, permissions, startDate, endDate) {
|
|
343
371
|
return client.userCreatePermissionBatch(agentId, {
|
|
@@ -351,7 +379,11 @@ async function agentCreatePermissions(client, agentId, objectId, objectType, per
|
|
|
351
379
|
}
|
|
352
380
|
|
|
353
381
|
async function appCreate(client, userId, data) {
|
|
354
|
-
return client.post(`/v1/users/${userId}/apps`,
|
|
382
|
+
return client.post(`/v1/users/${userId}/apps`, {
|
|
383
|
+
availableLocales: { '0': 'de_DE' },
|
|
384
|
+
...data,
|
|
385
|
+
siteUrl: data.siteUrl.replace('_', ''),
|
|
386
|
+
});
|
|
355
387
|
}
|
|
356
388
|
async function appGetById(client, appId) {
|
|
357
389
|
return client.get(`/v1/apps/${appId}`);
|
|
@@ -417,11 +449,12 @@ async function conversationGetById(client, conversationId) {
|
|
|
417
449
|
}
|
|
418
450
|
async function conversationCreateMessage(client, conversationId, messageData) {
|
|
419
451
|
const url = `/v1/conversations/${conversationId}/messages`;
|
|
420
|
-
const payload = messageData.attachments
|
|
452
|
+
const payload = messageData.attachments?.length
|
|
421
453
|
? {
|
|
422
454
|
content: {
|
|
423
455
|
description: messageData.body,
|
|
424
|
-
files: (await createManyFilesSorted(messageData.attachments, client))
|
|
456
|
+
files: (await createManyFilesSorted(messageData.attachments, client))
|
|
457
|
+
.success,
|
|
425
458
|
},
|
|
426
459
|
createdBy: messageData.createdBy,
|
|
427
460
|
inputChannel: messageData.inputChannel,
|
|
@@ -451,24 +484,16 @@ async function fileDelete(client, fileId) {
|
|
|
451
484
|
return (await client.delete(`/v1/files/${fileId}`)) === '';
|
|
452
485
|
}
|
|
453
486
|
|
|
454
|
-
var __rest$3 = (undefined && undefined.__rest) || function (s, e) {
|
|
455
|
-
var t = {};
|
|
456
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
457
|
-
t[p] = s[p];
|
|
458
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
459
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
460
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
461
|
-
t[p[i]] = s[p[i]];
|
|
462
|
-
}
|
|
463
|
-
return t;
|
|
464
|
-
};
|
|
465
487
|
async function groupCreate(client, propertyId, data) {
|
|
466
|
-
const { propertyManagerId
|
|
467
|
-
return client.post(`/v1/properties/${propertyId}/groups`,
|
|
488
|
+
const { propertyManagerId, ...rest } = data;
|
|
489
|
+
return client.post(`/v1/properties/${propertyId}/groups`, {
|
|
490
|
+
...rest,
|
|
491
|
+
propertyManagerID: propertyManagerId,
|
|
492
|
+
});
|
|
468
493
|
}
|
|
469
494
|
async function groupGetById(client, groupId) {
|
|
470
|
-
const
|
|
471
|
-
return
|
|
495
|
+
const { propertyManagerID: propertyManagerId, ...result } = await client.get(`/v1/groups/${groupId}`);
|
|
496
|
+
return { ...result, propertyManagerId };
|
|
472
497
|
}
|
|
473
498
|
async function groupUpdateById(client, groupId, data) {
|
|
474
499
|
return client.patch(`/v1/groups/${groupId}`, data);
|
|
@@ -486,9 +511,13 @@ async function lookupIds(client, appId, data) {
|
|
|
486
511
|
const url = data.dataSource
|
|
487
512
|
? `/v1/id-lookup/${appId}/${data.resource}/${data.dataSource}`
|
|
488
513
|
: `/v1/id-lookup/${appId}/${data.resource}`;
|
|
489
|
-
return client.post(url,
|
|
514
|
+
return client.post(url, {
|
|
515
|
+
externalIds: typeof data.externalIds === 'string'
|
|
490
516
|
? [data.externalIds]
|
|
491
|
-
: data.externalIds
|
|
517
|
+
: data.externalIds,
|
|
518
|
+
...(data.parentId ? { parentId: data.parentId } : {}),
|
|
519
|
+
...(data.userType ? { userType: data.userType } : {}),
|
|
520
|
+
});
|
|
492
521
|
}
|
|
493
522
|
|
|
494
523
|
function stringToDate(s) {
|
|
@@ -498,17 +527,6 @@ function dateToString(d) {
|
|
|
498
527
|
return d.toISOString();
|
|
499
528
|
}
|
|
500
529
|
|
|
501
|
-
var __rest$2 = (undefined && undefined.__rest) || function (s, e) {
|
|
502
|
-
var t = {};
|
|
503
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
504
|
-
t[p] = s[p];
|
|
505
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
506
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
507
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
508
|
-
t[p[i]] = s[p[i]];
|
|
509
|
-
}
|
|
510
|
-
return t;
|
|
511
|
-
};
|
|
512
530
|
var EnumNotificationCategory;
|
|
513
531
|
(function (EnumNotificationCategory) {
|
|
514
532
|
EnumNotificationCategory["events"] = "events";
|
|
@@ -541,9 +559,13 @@ var EnumNotificationType;
|
|
|
541
559
|
EnumNotificationType["ticketComment"] = "ticket-comment";
|
|
542
560
|
EnumNotificationType["welcomeNotification"] = "welcome-notification";
|
|
543
561
|
})(EnumNotificationType || (EnumNotificationType = {}));
|
|
544
|
-
function remapNotificationResult(
|
|
545
|
-
|
|
546
|
-
|
|
562
|
+
function remapNotificationResult({ createdAt, objectID, referencedObjectID, ...restNotification }) {
|
|
563
|
+
return {
|
|
564
|
+
createdAt: stringToDate(createdAt),
|
|
565
|
+
objectId: objectID,
|
|
566
|
+
referencedObjectId: referencedObjectID,
|
|
567
|
+
...restNotification,
|
|
568
|
+
};
|
|
547
569
|
}
|
|
548
570
|
async function notificationsGetByUser(client, userId, page = 1, limit = -1) {
|
|
549
571
|
const { _embedded: { items: notifications }, total, metaData, } = await client.get(`/v1/users/${userId}/notifications?page=${page}&limit=${limit}`);
|
|
@@ -562,8 +584,11 @@ async function notificationUpdateRead(client, notificationId) {
|
|
|
562
584
|
return remapNotificationResult(await client.patch(`/v1/notifications/${notificationId}`, { read: true }));
|
|
563
585
|
}
|
|
564
586
|
|
|
565
|
-
function remapKeys(input,
|
|
566
|
-
return Object.entries(input).reduce((
|
|
587
|
+
function remapKeys(input, mapFunction) {
|
|
588
|
+
return Object.entries(input).reduce((accumulator, entry) => ({
|
|
589
|
+
...accumulator,
|
|
590
|
+
[mapFunction(entry[0])]: entry[1],
|
|
591
|
+
}), {});
|
|
567
592
|
}
|
|
568
593
|
|
|
569
594
|
function camelCaseToDash(input) {
|
|
@@ -609,26 +634,20 @@ async function getProperties(client, page = 1, limit = -1, filter = {}) {
|
|
|
609
634
|
return { _embedded: { items: properties }, total };
|
|
610
635
|
}
|
|
611
636
|
|
|
612
|
-
var __rest$1 = (undefined && undefined.__rest) || function (s, e) {
|
|
613
|
-
var t = {};
|
|
614
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
615
|
-
t[p] = s[p];
|
|
616
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
617
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
618
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
619
|
-
t[p[i]] = s[p[i]];
|
|
620
|
-
}
|
|
621
|
-
return t;
|
|
622
|
-
};
|
|
623
637
|
const remapRegistationCodeResult = (registrationCode) => {
|
|
624
|
-
const { tenantID: externalId
|
|
625
|
-
return
|
|
638
|
+
const { tenantID: externalId, ...result } = registrationCode;
|
|
639
|
+
return { ...result, externalId };
|
|
626
640
|
};
|
|
627
641
|
async function registrationCodeCreate(client, code, utilisationPeriods, options = { permanent: false }) {
|
|
628
|
-
const { externalId
|
|
629
|
-
return remapRegistationCodeResult(await client.post('/v1/registration-codes',
|
|
642
|
+
const { externalId, ...moreOptions } = options;
|
|
643
|
+
return remapRegistationCodeResult(await client.post('/v1/registration-codes', {
|
|
644
|
+
code,
|
|
645
|
+
utilisationPeriods: typeof utilisationPeriods === 'string'
|
|
630
646
|
? [utilisationPeriods]
|
|
631
|
-
: utilisationPeriods
|
|
647
|
+
: utilisationPeriods,
|
|
648
|
+
...(externalId ? { externalId, tenantID: externalId } : {}),
|
|
649
|
+
...moreOptions,
|
|
650
|
+
}));
|
|
632
651
|
}
|
|
633
652
|
async function registrationCodeUpdateById(client, registrationCodeId, data) {
|
|
634
653
|
return remapRegistationCodeResult(await client.patch(`/v1/registration-codes/${registrationCodeId}`, data));
|
|
@@ -667,14 +686,21 @@ async function ticketGetById(client, ticketId) {
|
|
|
667
686
|
return client.get(`/v1/tickets/${ticketId}`);
|
|
668
687
|
}
|
|
669
688
|
async function ticketCreateOnUser(client, userId, utilisationPeriodId, payload) {
|
|
670
|
-
return client.post(`/v1/users/${userId}/tickets`,
|
|
689
|
+
return client.post(`/v1/users/${userId}/tickets`, {
|
|
690
|
+
...payload,
|
|
691
|
+
files: payload.files
|
|
671
692
|
? (await createManyFilesSorted(payload.files, client)).success
|
|
672
|
-
: [],
|
|
693
|
+
: [],
|
|
694
|
+
utilisationPeriod: utilisationPeriodId,
|
|
695
|
+
});
|
|
673
696
|
}
|
|
674
697
|
async function ticketCreateOnServiceProvider(client, serviceProviderId, payload) {
|
|
675
|
-
return client.post(`/v1/property-managers/${serviceProviderId}/tickets`,
|
|
698
|
+
return client.post(`/v1/property-managers/${serviceProviderId}/tickets`, {
|
|
699
|
+
...payload,
|
|
700
|
+
files: payload.files
|
|
676
701
|
? (await createManyFilesSorted(payload.files, client)).success
|
|
677
|
-
: []
|
|
702
|
+
: [],
|
|
703
|
+
});
|
|
678
704
|
}
|
|
679
705
|
|
|
680
706
|
exports.EnumUnitObjectType = void 0;
|
|
@@ -796,17 +822,6 @@ async function userRelationsGetByUser(client, userId) {
|
|
|
796
822
|
return client.get(`/v1/users/${userId}/user-relations`);
|
|
797
823
|
}
|
|
798
824
|
|
|
799
|
-
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
800
|
-
var t = {};
|
|
801
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
802
|
-
t[p] = s[p];
|
|
803
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
804
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
805
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
806
|
-
t[p[i]] = s[p[i]];
|
|
807
|
-
}
|
|
808
|
-
return t;
|
|
809
|
-
};
|
|
810
825
|
exports.EnumUtilisationPeriodType = void 0;
|
|
811
826
|
(function (EnumUtilisationPeriodType) {
|
|
812
827
|
EnumUtilisationPeriodType["tenant"] = "tenant";
|
|
@@ -814,16 +829,31 @@ exports.EnumUtilisationPeriodType = void 0;
|
|
|
814
829
|
EnumUtilisationPeriodType["vacant"] = "vacant";
|
|
815
830
|
})(exports.EnumUtilisationPeriodType || (exports.EnumUtilisationPeriodType = {}));
|
|
816
831
|
async function utilisationPeriodCreate(client, unitId, data) {
|
|
817
|
-
const
|
|
818
|
-
return
|
|
832
|
+
const { tenantIDs: tenantIds, _embedded, ...result } = await client.post(`/v1/units/${unitId}/utilisation-periods`, data);
|
|
833
|
+
return {
|
|
834
|
+
...result,
|
|
835
|
+
invitations: _embedded.invitations.map(remapRegistationCodeResult),
|
|
836
|
+
tenantIds,
|
|
837
|
+
users: remapEmbeddedUser(_embedded),
|
|
838
|
+
};
|
|
819
839
|
}
|
|
820
840
|
async function utilisationPeriodGetById(client, utilisationPeriodId) {
|
|
821
|
-
const
|
|
822
|
-
return
|
|
841
|
+
const { tenantIDs: tenantIds, _embedded, ...result } = await client.get(`/v1/utilisation-periods/${utilisationPeriodId}`);
|
|
842
|
+
return {
|
|
843
|
+
...result,
|
|
844
|
+
invitations: _embedded.invitations.map(remapRegistationCodeResult),
|
|
845
|
+
tenantIds,
|
|
846
|
+
users: remapEmbeddedUser(_embedded),
|
|
847
|
+
};
|
|
823
848
|
}
|
|
824
849
|
async function utilisationPeriodUpdateById(client, utilisationPeriodId, data) {
|
|
825
|
-
const
|
|
826
|
-
return
|
|
850
|
+
const { tenantIDs: tenantIds, _embedded, ...result } = await client.patch(`/v1/utilisation-periods/${utilisationPeriodId}`, data);
|
|
851
|
+
return {
|
|
852
|
+
...result,
|
|
853
|
+
invitations: _embedded.invitations.map(remapRegistationCodeResult),
|
|
854
|
+
tenantIds,
|
|
855
|
+
users: remapEmbeddedUser(_embedded),
|
|
856
|
+
};
|
|
827
857
|
}
|
|
828
858
|
async function utilisationPeriodDelete(client, utilisationPeriodId) {
|
|
829
859
|
return !(await client.delete(`/v1/utilisation-periods/${utilisationPeriodId}/soft`));
|
|
@@ -11927,7 +11957,7 @@ var hasRequiredMimeTypes;
|
|
|
11927
11957
|
function requireMimeTypes () {
|
|
11928
11958
|
if (hasRequiredMimeTypes) return mimeTypes;
|
|
11929
11959
|
hasRequiredMimeTypes = 1;
|
|
11930
|
-
(function (exports) {
|
|
11960
|
+
(function (exports$1) {
|
|
11931
11961
|
|
|
11932
11962
|
/**
|
|
11933
11963
|
* Module dependencies.
|
|
@@ -11950,16 +11980,16 @@ function requireMimeTypes () {
|
|
|
11950
11980
|
* @public
|
|
11951
11981
|
*/
|
|
11952
11982
|
|
|
11953
|
-
exports.charset = charset;
|
|
11954
|
-
exports.charsets = { lookup: charset };
|
|
11955
|
-
exports.contentType = contentType;
|
|
11956
|
-
exports.extension = extension;
|
|
11957
|
-
exports.extensions = Object.create(null);
|
|
11958
|
-
exports.lookup = lookup;
|
|
11959
|
-
exports.types = Object.create(null);
|
|
11983
|
+
exports$1.charset = charset;
|
|
11984
|
+
exports$1.charsets = { lookup: charset };
|
|
11985
|
+
exports$1.contentType = contentType;
|
|
11986
|
+
exports$1.extension = extension;
|
|
11987
|
+
exports$1.extensions = Object.create(null);
|
|
11988
|
+
exports$1.lookup = lookup;
|
|
11989
|
+
exports$1.types = Object.create(null);
|
|
11960
11990
|
|
|
11961
11991
|
// Populate the extensions/types maps
|
|
11962
|
-
populateMaps(exports.extensions, exports.types);
|
|
11992
|
+
populateMaps(exports$1.extensions, exports$1.types);
|
|
11963
11993
|
|
|
11964
11994
|
/**
|
|
11965
11995
|
* Get the default charset for a MIME type.
|
|
@@ -12003,7 +12033,7 @@ function requireMimeTypes () {
|
|
|
12003
12033
|
}
|
|
12004
12034
|
|
|
12005
12035
|
var mime = str.indexOf('/') === -1
|
|
12006
|
-
? exports.lookup(str)
|
|
12036
|
+
? exports$1.lookup(str)
|
|
12007
12037
|
: str;
|
|
12008
12038
|
|
|
12009
12039
|
if (!mime) {
|
|
@@ -12012,7 +12042,7 @@ function requireMimeTypes () {
|
|
|
12012
12042
|
|
|
12013
12043
|
// TODO: use content-type or other module
|
|
12014
12044
|
if (mime.indexOf('charset') === -1) {
|
|
12015
|
-
var charset = exports.charset(mime);
|
|
12045
|
+
var charset = exports$1.charset(mime);
|
|
12016
12046
|
if (charset) mime += '; charset=' + charset.toLowerCase();
|
|
12017
12047
|
}
|
|
12018
12048
|
|
|
@@ -12035,7 +12065,7 @@ function requireMimeTypes () {
|
|
|
12035
12065
|
var match = EXTRACT_TYPE_REGEXP.exec(type);
|
|
12036
12066
|
|
|
12037
12067
|
// get extensions
|
|
12038
|
-
var exts = match && exports.extensions[match[1].toLowerCase()];
|
|
12068
|
+
var exts = match && exports$1.extensions[match[1].toLowerCase()];
|
|
12039
12069
|
|
|
12040
12070
|
if (!exts || !exts.length) {
|
|
12041
12071
|
return false
|
|
@@ -12065,7 +12095,7 @@ function requireMimeTypes () {
|
|
|
12065
12095
|
return false
|
|
12066
12096
|
}
|
|
12067
12097
|
|
|
12068
|
-
return exports.types[extension] || false
|
|
12098
|
+
return exports$1.types[extension] || false
|
|
12069
12099
|
}
|
|
12070
12100
|
|
|
12071
12101
|
/**
|
|
@@ -13557,7 +13587,7 @@ function requireGetIntrinsic () {
|
|
|
13557
13587
|
if (!allowMissing) {
|
|
13558
13588
|
throw new $TypeError('base intrinsic for ' + name + ' exists, but the property is not available.');
|
|
13559
13589
|
}
|
|
13560
|
-
return void
|
|
13590
|
+
return void undefined$1;
|
|
13561
13591
|
}
|
|
13562
13592
|
if ($gOPD && (i + 1) >= parts.length) {
|
|
13563
13593
|
var desc = $gOPD(value, part);
|
|
@@ -13655,12 +13685,11 @@ var hasRequiredPopulate;
|
|
|
13655
13685
|
function requirePopulate () {
|
|
13656
13686
|
if (hasRequiredPopulate) return populate;
|
|
13657
13687
|
hasRequiredPopulate = 1;
|
|
13658
|
-
// populates missing values
|
|
13659
|
-
populate = function(dst, src) {
|
|
13660
13688
|
|
|
13661
|
-
|
|
13662
|
-
|
|
13663
|
-
|
|
13689
|
+
// populates missing values
|
|
13690
|
+
populate = function (dst, src) {
|
|
13691
|
+
Object.keys(src).forEach(function (prop) {
|
|
13692
|
+
dst[prop] = dst[prop] || src[prop]; // eslint-disable-line no-param-reassign
|
|
13664
13693
|
});
|
|
13665
13694
|
|
|
13666
13695
|
return dst;
|
|
@@ -13674,6 +13703,7 @@ var hasRequiredForm_data;
|
|
|
13674
13703
|
function requireForm_data () {
|
|
13675
13704
|
if (hasRequiredForm_data) return form_data;
|
|
13676
13705
|
hasRequiredForm_data = 1;
|
|
13706
|
+
|
|
13677
13707
|
var CombinedStream = requireCombined_stream();
|
|
13678
13708
|
var util = require$$1;
|
|
13679
13709
|
var path = require$$1$1;
|
|
@@ -13682,24 +13712,20 @@ function requireForm_data () {
|
|
|
13682
13712
|
var parseUrl = require$$5.parse;
|
|
13683
13713
|
var fs = require$$6;
|
|
13684
13714
|
var Stream = require$$0$1.Stream;
|
|
13715
|
+
var crypto = require$$8;
|
|
13685
13716
|
var mime = requireMimeTypes();
|
|
13686
13717
|
var asynckit = requireAsynckit();
|
|
13687
13718
|
var setToStringTag = /*@__PURE__*/ requireEsSetTostringtag();
|
|
13719
|
+
var hasOwn = /*@__PURE__*/ requireHasown();
|
|
13688
13720
|
var populate = requirePopulate();
|
|
13689
13721
|
|
|
13690
|
-
// Public API
|
|
13691
|
-
form_data = FormData;
|
|
13692
|
-
|
|
13693
|
-
// make it a Stream
|
|
13694
|
-
util.inherits(FormData, CombinedStream);
|
|
13695
|
-
|
|
13696
13722
|
/**
|
|
13697
13723
|
* Create readable "multipart/form-data" streams.
|
|
13698
13724
|
* Can be used to submit forms
|
|
13699
13725
|
* and file uploads to other web applications.
|
|
13700
13726
|
*
|
|
13701
13727
|
* @constructor
|
|
13702
|
-
* @param {
|
|
13728
|
+
* @param {object} options - Properties to be added/overriden for FormData and CombinedStream
|
|
13703
13729
|
*/
|
|
13704
13730
|
function FormData(options) {
|
|
13705
13731
|
if (!(this instanceof FormData)) {
|
|
@@ -13712,35 +13738,39 @@ function requireForm_data () {
|
|
|
13712
13738
|
|
|
13713
13739
|
CombinedStream.call(this);
|
|
13714
13740
|
|
|
13715
|
-
options = options || {};
|
|
13716
|
-
for (var option in options) {
|
|
13741
|
+
options = options || {}; // eslint-disable-line no-param-reassign
|
|
13742
|
+
for (var option in options) { // eslint-disable-line no-restricted-syntax
|
|
13717
13743
|
this[option] = options[option];
|
|
13718
13744
|
}
|
|
13719
13745
|
}
|
|
13720
13746
|
|
|
13747
|
+
// make it a Stream
|
|
13748
|
+
util.inherits(FormData, CombinedStream);
|
|
13749
|
+
|
|
13721
13750
|
FormData.LINE_BREAK = '\r\n';
|
|
13722
13751
|
FormData.DEFAULT_CONTENT_TYPE = 'application/octet-stream';
|
|
13723
13752
|
|
|
13724
|
-
FormData.prototype.append = function(field, value, options) {
|
|
13725
|
-
|
|
13726
|
-
options = options || {};
|
|
13753
|
+
FormData.prototype.append = function (field, value, options) {
|
|
13754
|
+
options = options || {}; // eslint-disable-line no-param-reassign
|
|
13727
13755
|
|
|
13728
13756
|
// allow filename as single option
|
|
13729
|
-
if (typeof options
|
|
13730
|
-
options = {filename: options};
|
|
13757
|
+
if (typeof options === 'string') {
|
|
13758
|
+
options = { filename: options }; // eslint-disable-line no-param-reassign
|
|
13731
13759
|
}
|
|
13732
13760
|
|
|
13733
13761
|
var append = CombinedStream.prototype.append.bind(this);
|
|
13734
13762
|
|
|
13735
13763
|
// all that streamy business can't handle numbers
|
|
13736
|
-
if (typeof value
|
|
13737
|
-
value =
|
|
13764
|
+
if (typeof value === 'number' || value == null) {
|
|
13765
|
+
value = String(value); // eslint-disable-line no-param-reassign
|
|
13738
13766
|
}
|
|
13739
13767
|
|
|
13740
13768
|
// https://github.com/felixge/node-form-data/issues/38
|
|
13741
13769
|
if (Array.isArray(value)) {
|
|
13742
|
-
|
|
13743
|
-
|
|
13770
|
+
/*
|
|
13771
|
+
* Please convert your array into string
|
|
13772
|
+
* the way web server expects it
|
|
13773
|
+
*/
|
|
13744
13774
|
this._error(new Error('Arrays are not supported.'));
|
|
13745
13775
|
return;
|
|
13746
13776
|
}
|
|
@@ -13756,15 +13786,17 @@ function requireForm_data () {
|
|
|
13756
13786
|
this._trackLength(header, value, options);
|
|
13757
13787
|
};
|
|
13758
13788
|
|
|
13759
|
-
FormData.prototype._trackLength = function(header, value, options) {
|
|
13789
|
+
FormData.prototype._trackLength = function (header, value, options) {
|
|
13760
13790
|
var valueLength = 0;
|
|
13761
13791
|
|
|
13762
|
-
|
|
13763
|
-
|
|
13764
|
-
|
|
13765
|
-
|
|
13792
|
+
/*
|
|
13793
|
+
* used w/ getLengthSync(), when length is known.
|
|
13794
|
+
* e.g. for streaming directly from a remote server,
|
|
13795
|
+
* w/ a known file a size, and not wanting to wait for
|
|
13796
|
+
* incoming file to finish to get its size.
|
|
13797
|
+
*/
|
|
13766
13798
|
if (options.knownLength != null) {
|
|
13767
|
-
valueLength +=
|
|
13799
|
+
valueLength += Number(options.knownLength);
|
|
13768
13800
|
} else if (Buffer.isBuffer(value)) {
|
|
13769
13801
|
valueLength = value.length;
|
|
13770
13802
|
} else if (typeof value === 'string') {
|
|
@@ -13774,12 +13806,10 @@ function requireForm_data () {
|
|
|
13774
13806
|
this._valueLength += valueLength;
|
|
13775
13807
|
|
|
13776
13808
|
// @check why add CRLF? does this account for custom/multiple CRLFs?
|
|
13777
|
-
this._overheadLength +=
|
|
13778
|
-
Buffer.byteLength(header) +
|
|
13779
|
-
FormData.LINE_BREAK.length;
|
|
13809
|
+
this._overheadLength += Buffer.byteLength(header) + FormData.LINE_BREAK.length;
|
|
13780
13810
|
|
|
13781
13811
|
// empty or either doesn't have path or not an http response or not a stream
|
|
13782
|
-
if (!value || (
|
|
13812
|
+
if (!value || (!value.path && !(value.readable && hasOwn(value, 'httpVersion')) && !(value instanceof Stream))) {
|
|
13783
13813
|
return;
|
|
13784
13814
|
}
|
|
13785
13815
|
|
|
@@ -13789,9 +13819,8 @@ function requireForm_data () {
|
|
|
13789
13819
|
}
|
|
13790
13820
|
};
|
|
13791
13821
|
|
|
13792
|
-
FormData.prototype._lengthRetriever = function(value, callback) {
|
|
13793
|
-
if (
|
|
13794
|
-
|
|
13822
|
+
FormData.prototype._lengthRetriever = function (value, callback) {
|
|
13823
|
+
if (hasOwn(value, 'fd')) {
|
|
13795
13824
|
// take read range into a account
|
|
13796
13825
|
// `end` = Infinity –> read file till the end
|
|
13797
13826
|
//
|
|
@@ -13800,54 +13829,52 @@ function requireForm_data () {
|
|
|
13800
13829
|
// Fix it when node fixes it.
|
|
13801
13830
|
// https://github.com/joyent/node/issues/7819
|
|
13802
13831
|
if (value.end != undefined && value.end != Infinity && value.start != undefined) {
|
|
13803
|
-
|
|
13804
13832
|
// when end specified
|
|
13805
13833
|
// no need to calculate range
|
|
13806
13834
|
// inclusive, starts with 0
|
|
13807
|
-
callback(null, value.end + 1 - (value.start ? value.start : 0));
|
|
13835
|
+
callback(null, value.end + 1 - (value.start ? value.start : 0)); // eslint-disable-line callback-return
|
|
13808
13836
|
|
|
13809
|
-
|
|
13837
|
+
// not that fast snoopy
|
|
13810
13838
|
} else {
|
|
13811
13839
|
// still need to fetch file size from fs
|
|
13812
|
-
fs.stat(value.path, function(err, stat) {
|
|
13813
|
-
|
|
13814
|
-
var fileSize;
|
|
13815
|
-
|
|
13840
|
+
fs.stat(value.path, function (err, stat) {
|
|
13816
13841
|
if (err) {
|
|
13817
13842
|
callback(err);
|
|
13818
13843
|
return;
|
|
13819
13844
|
}
|
|
13820
13845
|
|
|
13821
13846
|
// update final size based on the range options
|
|
13822
|
-
fileSize = stat.size - (value.start ? value.start : 0);
|
|
13847
|
+
var fileSize = stat.size - (value.start ? value.start : 0);
|
|
13823
13848
|
callback(null, fileSize);
|
|
13824
13849
|
});
|
|
13825
13850
|
}
|
|
13826
13851
|
|
|
13827
|
-
|
|
13828
|
-
} else if (
|
|
13829
|
-
callback(null,
|
|
13852
|
+
// or http response
|
|
13853
|
+
} else if (hasOwn(value, 'httpVersion')) {
|
|
13854
|
+
callback(null, Number(value.headers['content-length'])); // eslint-disable-line callback-return
|
|
13830
13855
|
|
|
13831
|
-
|
|
13832
|
-
} else if (
|
|
13856
|
+
// or request stream http://github.com/mikeal/request
|
|
13857
|
+
} else if (hasOwn(value, 'httpModule')) {
|
|
13833
13858
|
// wait till response come back
|
|
13834
|
-
value.on('response', function(response) {
|
|
13859
|
+
value.on('response', function (response) {
|
|
13835
13860
|
value.pause();
|
|
13836
|
-
callback(null,
|
|
13861
|
+
callback(null, Number(response.headers['content-length']));
|
|
13837
13862
|
});
|
|
13838
13863
|
value.resume();
|
|
13839
13864
|
|
|
13840
|
-
|
|
13865
|
+
// something else
|
|
13841
13866
|
} else {
|
|
13842
|
-
callback('Unknown stream');
|
|
13867
|
+
callback('Unknown stream'); // eslint-disable-line callback-return
|
|
13843
13868
|
}
|
|
13844
13869
|
};
|
|
13845
13870
|
|
|
13846
|
-
FormData.prototype._multiPartHeader = function(field, value, options) {
|
|
13847
|
-
|
|
13848
|
-
|
|
13849
|
-
|
|
13850
|
-
|
|
13871
|
+
FormData.prototype._multiPartHeader = function (field, value, options) {
|
|
13872
|
+
/*
|
|
13873
|
+
* custom header specified (as string)?
|
|
13874
|
+
* it becomes responsible for boundary
|
|
13875
|
+
* (e.g. to handle extra CRLFs on .NET servers)
|
|
13876
|
+
*/
|
|
13877
|
+
if (typeof options.header === 'string') {
|
|
13851
13878
|
return options.header;
|
|
13852
13879
|
}
|
|
13853
13880
|
|
|
@@ -13855,7 +13882,7 @@ function requireForm_data () {
|
|
|
13855
13882
|
var contentType = this._getContentType(value, options);
|
|
13856
13883
|
|
|
13857
13884
|
var contents = '';
|
|
13858
|
-
var headers
|
|
13885
|
+
var headers = {
|
|
13859
13886
|
// add custom disposition as third element or keep it two elements if not
|
|
13860
13887
|
'Content-Disposition': ['form-data', 'name="' + field + '"'].concat(contentDisposition || []),
|
|
13861
13888
|
// if no content type. allow it to be empty array
|
|
@@ -13863,18 +13890,18 @@ function requireForm_data () {
|
|
|
13863
13890
|
};
|
|
13864
13891
|
|
|
13865
13892
|
// allow custom headers.
|
|
13866
|
-
if (typeof options.header
|
|
13893
|
+
if (typeof options.header === 'object') {
|
|
13867
13894
|
populate(headers, options.header);
|
|
13868
13895
|
}
|
|
13869
13896
|
|
|
13870
13897
|
var header;
|
|
13871
|
-
for (var prop in headers) {
|
|
13872
|
-
if (
|
|
13898
|
+
for (var prop in headers) { // eslint-disable-line no-restricted-syntax
|
|
13899
|
+
if (hasOwn(headers, prop)) {
|
|
13873
13900
|
header = headers[prop];
|
|
13874
13901
|
|
|
13875
13902
|
// skip nullish headers.
|
|
13876
13903
|
if (header == null) {
|
|
13877
|
-
continue;
|
|
13904
|
+
continue; // eslint-disable-line no-restricted-syntax, no-continue
|
|
13878
13905
|
}
|
|
13879
13906
|
|
|
13880
13907
|
// convert all headers to arrays.
|
|
@@ -13892,49 +13919,45 @@ function requireForm_data () {
|
|
|
13892
13919
|
return '--' + this.getBoundary() + FormData.LINE_BREAK + contents + FormData.LINE_BREAK;
|
|
13893
13920
|
};
|
|
13894
13921
|
|
|
13895
|
-
FormData.prototype._getContentDisposition = function(value, options) {
|
|
13896
|
-
|
|
13897
|
-
var filename
|
|
13898
|
-
, contentDisposition
|
|
13899
|
-
;
|
|
13922
|
+
FormData.prototype._getContentDisposition = function (value, options) { // eslint-disable-line consistent-return
|
|
13923
|
+
var filename;
|
|
13900
13924
|
|
|
13901
13925
|
if (typeof options.filepath === 'string') {
|
|
13902
13926
|
// custom filepath for relative paths
|
|
13903
13927
|
filename = path.normalize(options.filepath).replace(/\\/g, '/');
|
|
13904
|
-
} else if (options.filename || value.name || value.path) {
|
|
13905
|
-
|
|
13906
|
-
|
|
13907
|
-
|
|
13908
|
-
|
|
13909
|
-
|
|
13928
|
+
} else if (options.filename || (value && (value.name || value.path))) {
|
|
13929
|
+
/*
|
|
13930
|
+
* custom filename take precedence
|
|
13931
|
+
* formidable and the browser add a name property
|
|
13932
|
+
* fs- and request- streams have path property
|
|
13933
|
+
*/
|
|
13934
|
+
filename = path.basename(options.filename || (value && (value.name || value.path)));
|
|
13935
|
+
} else if (value && value.readable && hasOwn(value, 'httpVersion')) {
|
|
13910
13936
|
// or try http response
|
|
13911
13937
|
filename = path.basename(value.client._httpMessage.path || '');
|
|
13912
13938
|
}
|
|
13913
13939
|
|
|
13914
13940
|
if (filename) {
|
|
13915
|
-
|
|
13941
|
+
return 'filename="' + filename + '"';
|
|
13916
13942
|
}
|
|
13917
|
-
|
|
13918
|
-
return contentDisposition;
|
|
13919
13943
|
};
|
|
13920
13944
|
|
|
13921
|
-
FormData.prototype._getContentType = function(value, options) {
|
|
13922
|
-
|
|
13945
|
+
FormData.prototype._getContentType = function (value, options) {
|
|
13923
13946
|
// use custom content-type above all
|
|
13924
13947
|
var contentType = options.contentType;
|
|
13925
13948
|
|
|
13926
13949
|
// or try `name` from formidable, browser
|
|
13927
|
-
if (!contentType && value.name) {
|
|
13950
|
+
if (!contentType && value && value.name) {
|
|
13928
13951
|
contentType = mime.lookup(value.name);
|
|
13929
13952
|
}
|
|
13930
13953
|
|
|
13931
13954
|
// or try `path` from fs-, request- streams
|
|
13932
|
-
if (!contentType && value.path) {
|
|
13955
|
+
if (!contentType && value && value.path) {
|
|
13933
13956
|
contentType = mime.lookup(value.path);
|
|
13934
13957
|
}
|
|
13935
13958
|
|
|
13936
13959
|
// or if it's http-reponse
|
|
13937
|
-
if (!contentType && value.readable &&
|
|
13960
|
+
if (!contentType && value && value.readable && hasOwn(value, 'httpVersion')) {
|
|
13938
13961
|
contentType = value.headers['content-type'];
|
|
13939
13962
|
}
|
|
13940
13963
|
|
|
@@ -13944,18 +13967,18 @@ function requireForm_data () {
|
|
|
13944
13967
|
}
|
|
13945
13968
|
|
|
13946
13969
|
// fallback to the default content type if `value` is not simple value
|
|
13947
|
-
if (!contentType && typeof value
|
|
13970
|
+
if (!contentType && value && typeof value === 'object') {
|
|
13948
13971
|
contentType = FormData.DEFAULT_CONTENT_TYPE;
|
|
13949
13972
|
}
|
|
13950
13973
|
|
|
13951
13974
|
return contentType;
|
|
13952
13975
|
};
|
|
13953
13976
|
|
|
13954
|
-
FormData.prototype._multiPartFooter = function() {
|
|
13955
|
-
return function(next) {
|
|
13977
|
+
FormData.prototype._multiPartFooter = function () {
|
|
13978
|
+
return function (next) {
|
|
13956
13979
|
var footer = FormData.LINE_BREAK;
|
|
13957
13980
|
|
|
13958
|
-
var lastPart =
|
|
13981
|
+
var lastPart = this._streams.length === 0;
|
|
13959
13982
|
if (lastPart) {
|
|
13960
13983
|
footer += this._lastBoundary();
|
|
13961
13984
|
}
|
|
@@ -13964,18 +13987,18 @@ function requireForm_data () {
|
|
|
13964
13987
|
}.bind(this);
|
|
13965
13988
|
};
|
|
13966
13989
|
|
|
13967
|
-
FormData.prototype._lastBoundary = function() {
|
|
13990
|
+
FormData.prototype._lastBoundary = function () {
|
|
13968
13991
|
return '--' + this.getBoundary() + '--' + FormData.LINE_BREAK;
|
|
13969
13992
|
};
|
|
13970
13993
|
|
|
13971
|
-
FormData.prototype.getHeaders = function(userHeaders) {
|
|
13994
|
+
FormData.prototype.getHeaders = function (userHeaders) {
|
|
13972
13995
|
var header;
|
|
13973
13996
|
var formHeaders = {
|
|
13974
13997
|
'content-type': 'multipart/form-data; boundary=' + this.getBoundary()
|
|
13975
13998
|
};
|
|
13976
13999
|
|
|
13977
|
-
for (header in userHeaders) {
|
|
13978
|
-
if (
|
|
14000
|
+
for (header in userHeaders) { // eslint-disable-line no-restricted-syntax
|
|
14001
|
+
if (hasOwn(userHeaders, header)) {
|
|
13979
14002
|
formHeaders[header.toLowerCase()] = userHeaders[header];
|
|
13980
14003
|
}
|
|
13981
14004
|
}
|
|
@@ -13983,11 +14006,14 @@ function requireForm_data () {
|
|
|
13983
14006
|
return formHeaders;
|
|
13984
14007
|
};
|
|
13985
14008
|
|
|
13986
|
-
FormData.prototype.setBoundary = function(boundary) {
|
|
14009
|
+
FormData.prototype.setBoundary = function (boundary) {
|
|
14010
|
+
if (typeof boundary !== 'string') {
|
|
14011
|
+
throw new TypeError('FormData boundary must be a string');
|
|
14012
|
+
}
|
|
13987
14013
|
this._boundary = boundary;
|
|
13988
14014
|
};
|
|
13989
14015
|
|
|
13990
|
-
FormData.prototype.getBoundary = function() {
|
|
14016
|
+
FormData.prototype.getBoundary = function () {
|
|
13991
14017
|
if (!this._boundary) {
|
|
13992
14018
|
this._generateBoundary();
|
|
13993
14019
|
}
|
|
@@ -13995,60 +14021,55 @@ function requireForm_data () {
|
|
|
13995
14021
|
return this._boundary;
|
|
13996
14022
|
};
|
|
13997
14023
|
|
|
13998
|
-
FormData.prototype.getBuffer = function() {
|
|
13999
|
-
var dataBuffer = new Buffer.alloc(0);
|
|
14024
|
+
FormData.prototype.getBuffer = function () {
|
|
14025
|
+
var dataBuffer = new Buffer.alloc(0); // eslint-disable-line new-cap
|
|
14000
14026
|
var boundary = this.getBoundary();
|
|
14001
14027
|
|
|
14002
14028
|
// Create the form content. Add Line breaks to the end of data.
|
|
14003
14029
|
for (var i = 0, len = this._streams.length; i < len; i++) {
|
|
14004
14030
|
if (typeof this._streams[i] !== 'function') {
|
|
14005
|
-
|
|
14006
14031
|
// Add content to the buffer.
|
|
14007
|
-
if(Buffer.isBuffer(this._streams[i])) {
|
|
14008
|
-
dataBuffer = Buffer.concat(
|
|
14009
|
-
}else {
|
|
14010
|
-
dataBuffer = Buffer.concat(
|
|
14032
|
+
if (Buffer.isBuffer(this._streams[i])) {
|
|
14033
|
+
dataBuffer = Buffer.concat([dataBuffer, this._streams[i]]);
|
|
14034
|
+
} else {
|
|
14035
|
+
dataBuffer = Buffer.concat([dataBuffer, Buffer.from(this._streams[i])]);
|
|
14011
14036
|
}
|
|
14012
14037
|
|
|
14013
14038
|
// Add break after content.
|
|
14014
|
-
if (typeof this._streams[i] !== 'string' || this._streams[i].substring(
|
|
14015
|
-
dataBuffer = Buffer.concat(
|
|
14039
|
+
if (typeof this._streams[i] !== 'string' || this._streams[i].substring(2, boundary.length + 2) !== boundary) {
|
|
14040
|
+
dataBuffer = Buffer.concat([dataBuffer, Buffer.from(FormData.LINE_BREAK)]);
|
|
14016
14041
|
}
|
|
14017
14042
|
}
|
|
14018
14043
|
}
|
|
14019
14044
|
|
|
14020
14045
|
// Add the footer and return the Buffer object.
|
|
14021
|
-
return Buffer.concat(
|
|
14046
|
+
return Buffer.concat([dataBuffer, Buffer.from(this._lastBoundary())]);
|
|
14022
14047
|
};
|
|
14023
14048
|
|
|
14024
|
-
FormData.prototype._generateBoundary = function() {
|
|
14049
|
+
FormData.prototype._generateBoundary = function () {
|
|
14025
14050
|
// This generates a 50 character boundary similar to those used by Firefox.
|
|
14026
|
-
// They are optimized for boyer-moore parsing.
|
|
14027
|
-
var boundary = '--------------------------';
|
|
14028
|
-
for (var i = 0; i < 24; i++) {
|
|
14029
|
-
boundary += Math.floor(Math.random() * 10).toString(16);
|
|
14030
|
-
}
|
|
14031
14051
|
|
|
14032
|
-
|
|
14052
|
+
// They are optimized for boyer-moore parsing.
|
|
14053
|
+
this._boundary = '--------------------------' + crypto.randomBytes(12).toString('hex');
|
|
14033
14054
|
};
|
|
14034
14055
|
|
|
14035
14056
|
// Note: getLengthSync DOESN'T calculate streams length
|
|
14036
|
-
// As workaround one can calculate file size manually
|
|
14037
|
-
|
|
14038
|
-
FormData.prototype.getLengthSync = function() {
|
|
14057
|
+
// As workaround one can calculate file size manually and add it as knownLength option
|
|
14058
|
+
FormData.prototype.getLengthSync = function () {
|
|
14039
14059
|
var knownLength = this._overheadLength + this._valueLength;
|
|
14040
14060
|
|
|
14041
|
-
// Don't get confused, there are 3 "internal" streams for each keyval pair
|
|
14042
|
-
// so it basically checks if there is any value added to the form
|
|
14061
|
+
// Don't get confused, there are 3 "internal" streams for each keyval pair so it basically checks if there is any value added to the form
|
|
14043
14062
|
if (this._streams.length) {
|
|
14044
14063
|
knownLength += this._lastBoundary().length;
|
|
14045
14064
|
}
|
|
14046
14065
|
|
|
14047
14066
|
// https://github.com/form-data/form-data/issues/40
|
|
14048
14067
|
if (!this.hasKnownLength()) {
|
|
14049
|
-
|
|
14050
|
-
|
|
14051
|
-
|
|
14068
|
+
/*
|
|
14069
|
+
* Some async length retrievers are present
|
|
14070
|
+
* therefore synchronous length calculation is false.
|
|
14071
|
+
* Please use getLength(callback) to get proper length
|
|
14072
|
+
*/
|
|
14052
14073
|
this._error(new Error('Cannot calculate proper length in synchronous way.'));
|
|
14053
14074
|
}
|
|
14054
14075
|
|
|
@@ -14058,7 +14079,7 @@ function requireForm_data () {
|
|
|
14058
14079
|
// Public API to check if length of added values is known
|
|
14059
14080
|
// https://github.com/form-data/form-data/issues/196
|
|
14060
14081
|
// https://github.com/form-data/form-data/issues/262
|
|
14061
|
-
FormData.prototype.hasKnownLength = function() {
|
|
14082
|
+
FormData.prototype.hasKnownLength = function () {
|
|
14062
14083
|
var hasKnownLength = true;
|
|
14063
14084
|
|
|
14064
14085
|
if (this._valuesToMeasure.length) {
|
|
@@ -14068,7 +14089,7 @@ function requireForm_data () {
|
|
|
14068
14089
|
return hasKnownLength;
|
|
14069
14090
|
};
|
|
14070
14091
|
|
|
14071
|
-
FormData.prototype.getLength = function(cb) {
|
|
14092
|
+
FormData.prototype.getLength = function (cb) {
|
|
14072
14093
|
var knownLength = this._overheadLength + this._valueLength;
|
|
14073
14094
|
|
|
14074
14095
|
if (this._streams.length) {
|
|
@@ -14080,13 +14101,13 @@ function requireForm_data () {
|
|
|
14080
14101
|
return;
|
|
14081
14102
|
}
|
|
14082
14103
|
|
|
14083
|
-
asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function(err, values) {
|
|
14104
|
+
asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function (err, values) {
|
|
14084
14105
|
if (err) {
|
|
14085
14106
|
cb(err);
|
|
14086
14107
|
return;
|
|
14087
14108
|
}
|
|
14088
14109
|
|
|
14089
|
-
values.forEach(function(length) {
|
|
14110
|
+
values.forEach(function (length) {
|
|
14090
14111
|
knownLength += length;
|
|
14091
14112
|
});
|
|
14092
14113
|
|
|
@@ -14094,31 +14115,26 @@ function requireForm_data () {
|
|
|
14094
14115
|
});
|
|
14095
14116
|
};
|
|
14096
14117
|
|
|
14097
|
-
FormData.prototype.submit = function(params, cb) {
|
|
14098
|
-
var request
|
|
14099
|
-
|
|
14100
|
-
|
|
14101
|
-
;
|
|
14102
|
-
|
|
14103
|
-
// parse provided url if it's string
|
|
14104
|
-
// or treat it as options object
|
|
14105
|
-
if (typeof params == 'string') {
|
|
14118
|
+
FormData.prototype.submit = function (params, cb) {
|
|
14119
|
+
var request;
|
|
14120
|
+
var options;
|
|
14121
|
+
var defaults = { method: 'post' };
|
|
14106
14122
|
|
|
14107
|
-
|
|
14123
|
+
// parse provided url if it's string or treat it as options object
|
|
14124
|
+
if (typeof params === 'string') {
|
|
14125
|
+
params = parseUrl(params); // eslint-disable-line no-param-reassign
|
|
14126
|
+
/* eslint sort-keys: 0 */
|
|
14108
14127
|
options = populate({
|
|
14109
14128
|
port: params.port,
|
|
14110
14129
|
path: params.pathname,
|
|
14111
14130
|
host: params.hostname,
|
|
14112
14131
|
protocol: params.protocol
|
|
14113
14132
|
}, defaults);
|
|
14114
|
-
|
|
14115
|
-
// use custom params
|
|
14116
|
-
} else {
|
|
14117
|
-
|
|
14133
|
+
} else { // use custom params
|
|
14118
14134
|
options = populate(params, defaults);
|
|
14119
14135
|
// if no port provided use default one
|
|
14120
14136
|
if (!options.port) {
|
|
14121
|
-
options.port = options.protocol
|
|
14137
|
+
options.port = options.protocol === 'https:' ? 443 : 80;
|
|
14122
14138
|
}
|
|
14123
14139
|
}
|
|
14124
14140
|
|
|
@@ -14126,14 +14142,14 @@ function requireForm_data () {
|
|
|
14126
14142
|
options.headers = this.getHeaders(params.headers);
|
|
14127
14143
|
|
|
14128
14144
|
// https if specified, fallback to http in any other case
|
|
14129
|
-
if (options.protocol
|
|
14145
|
+
if (options.protocol === 'https:') {
|
|
14130
14146
|
request = https.request(options);
|
|
14131
14147
|
} else {
|
|
14132
14148
|
request = http.request(options);
|
|
14133
14149
|
}
|
|
14134
14150
|
|
|
14135
14151
|
// get content length and fire away
|
|
14136
|
-
this.getLength(function(err, length) {
|
|
14152
|
+
this.getLength(function (err, length) {
|
|
14137
14153
|
if (err && err !== 'Unknown stream') {
|
|
14138
14154
|
this._error(err);
|
|
14139
14155
|
return;
|
|
@@ -14165,7 +14181,7 @@ function requireForm_data () {
|
|
|
14165
14181
|
return request;
|
|
14166
14182
|
};
|
|
14167
14183
|
|
|
14168
|
-
FormData.prototype._error = function(err) {
|
|
14184
|
+
FormData.prototype._error = function (err) {
|
|
14169
14185
|
if (!this.error) {
|
|
14170
14186
|
this.error = err;
|
|
14171
14187
|
this.pause();
|
|
@@ -14176,7 +14192,10 @@ function requireForm_data () {
|
|
|
14176
14192
|
FormData.prototype.toString = function () {
|
|
14177
14193
|
return '[object FormData]';
|
|
14178
14194
|
};
|
|
14179
|
-
setToStringTag(FormData, 'FormData');
|
|
14195
|
+
setToStringTag(FormData.prototype, 'FormData');
|
|
14196
|
+
|
|
14197
|
+
// Public API
|
|
14198
|
+
form_data = FormData;
|
|
14180
14199
|
return form_data;
|
|
14181
14200
|
}
|
|
14182
14201
|
|
|
@@ -14184,7 +14203,7 @@ var form_dataExports = requireForm_data();
|
|
|
14184
14203
|
var FormDataModule = /*@__PURE__*/getDefaultExportFromCjs(form_dataExports);
|
|
14185
14204
|
|
|
14186
14205
|
const GRANT_TYPE$1 = 'client_credentials';
|
|
14187
|
-
const
|
|
14206
|
+
const castClientOptionsToRequestParameters = (clientOptions) => {
|
|
14188
14207
|
const { scope, clientId, clientSecret } = clientOptions;
|
|
14189
14208
|
if (!clientId) {
|
|
14190
14209
|
throw new Error('Missing required "clientId" parameter to perform client credentials grant');
|
|
@@ -14192,42 +14211,53 @@ const castClientOptionsToRequestParams = (clientOptions) => {
|
|
|
14192
14211
|
if (!clientSecret) {
|
|
14193
14212
|
throw new Error('Missing required "clientSecret" parameter to perform client credentials grant');
|
|
14194
14213
|
}
|
|
14195
|
-
return
|
|
14214
|
+
return {
|
|
14215
|
+
client_id: clientId,
|
|
14216
|
+
client_secret: clientSecret,
|
|
14217
|
+
grant_type: GRANT_TYPE$1,
|
|
14218
|
+
...(scope ? { scope } : {}),
|
|
14219
|
+
};
|
|
14196
14220
|
};
|
|
14197
14221
|
const isEligible$1 = (clientOptions) => {
|
|
14198
14222
|
try {
|
|
14199
|
-
return !!
|
|
14223
|
+
return !!castClientOptionsToRequestParameters(clientOptions);
|
|
14200
14224
|
}
|
|
14201
|
-
catch
|
|
14225
|
+
catch {
|
|
14202
14226
|
return false;
|
|
14203
14227
|
}
|
|
14204
14228
|
};
|
|
14205
|
-
const requestToken$1 = (oauthTokenRequest, clientOptions) => oauthTokenRequest(
|
|
14229
|
+
const requestToken$1 = (oauthTokenRequest, clientOptions) => oauthTokenRequest(castClientOptionsToRequestParameters(clientOptions));
|
|
14206
14230
|
|
|
14207
14231
|
const RESPONSE_TYPE = 'token';
|
|
14208
|
-
const
|
|
14209
|
-
const { clientId, scope, state, redirectUri } =
|
|
14232
|
+
const castToAuthorizationRequestParameters = (parameters) => {
|
|
14233
|
+
const { clientId, scope, state, redirectUri } = parameters;
|
|
14210
14234
|
if (!clientId) {
|
|
14211
14235
|
throw new Error('Missing required "clientId" parameter to perform implicit grant');
|
|
14212
14236
|
}
|
|
14213
|
-
return
|
|
14237
|
+
return {
|
|
14238
|
+
client_id: clientId,
|
|
14239
|
+
redirect_uri: redirectUri || window.location.href,
|
|
14240
|
+
response_type: RESPONSE_TYPE,
|
|
14241
|
+
...(scope ? { scope } : {}),
|
|
14242
|
+
...(state ? { state } : {}),
|
|
14243
|
+
};
|
|
14214
14244
|
};
|
|
14215
|
-
const isEligibleForClientRedirect = (
|
|
14245
|
+
const isEligibleForClientRedirect = (parameters) => {
|
|
14216
14246
|
try {
|
|
14217
|
-
return !!
|
|
14247
|
+
return !!castToAuthorizationRequestParameters(parameters);
|
|
14218
14248
|
}
|
|
14219
|
-
catch
|
|
14249
|
+
catch {
|
|
14220
14250
|
return false;
|
|
14221
14251
|
}
|
|
14222
14252
|
};
|
|
14223
|
-
const getRedirectUrl = (
|
|
14253
|
+
const getRedirectUrl = (parameters) => `${parameters.oauthUrl}/oauth/authorize?${querystring.stringify(castToAuthorizationRequestParameters(parameters), {
|
|
14224
14254
|
skipEmptyString: true,
|
|
14225
14255
|
skipNull: true,
|
|
14226
14256
|
})}`;
|
|
14227
14257
|
|
|
14228
14258
|
const GRANT_TYPE = 'password';
|
|
14229
|
-
const
|
|
14230
|
-
const { username, password, scope, clientId, clientSecret } =
|
|
14259
|
+
const castToTokenRequestParameters = (parameters) => {
|
|
14260
|
+
const { username, password, scope, clientId, clientSecret } = parameters;
|
|
14231
14261
|
if (!clientId) {
|
|
14232
14262
|
throw new Error('Missing required "clientId" parameter to perform password grant');
|
|
14233
14263
|
}
|
|
@@ -14237,24 +14267,33 @@ const castToTokenRequestParams = (params) => {
|
|
|
14237
14267
|
if (!password) {
|
|
14238
14268
|
throw new Error('Missing required "password" parameter to perform password grant');
|
|
14239
14269
|
}
|
|
14240
|
-
return
|
|
14241
|
-
|
|
14270
|
+
return {
|
|
14271
|
+
client_id: clientId,
|
|
14272
|
+
grant_type: GRANT_TYPE,
|
|
14273
|
+
password,
|
|
14274
|
+
username,
|
|
14275
|
+
...(scope ? { scope } : {}),
|
|
14276
|
+
...(clientSecret ? { client_secret: clientSecret } : {}),
|
|
14277
|
+
};
|
|
14242
14278
|
};
|
|
14243
|
-
const isEligible = (
|
|
14279
|
+
const isEligible = (parameters) => {
|
|
14244
14280
|
try {
|
|
14245
|
-
return !!
|
|
14281
|
+
return !!castToTokenRequestParameters(parameters);
|
|
14246
14282
|
}
|
|
14247
|
-
catch
|
|
14283
|
+
catch {
|
|
14248
14284
|
return false;
|
|
14249
14285
|
}
|
|
14250
14286
|
};
|
|
14251
|
-
const requestToken = (tokenRequester,
|
|
14287
|
+
const requestToken = (tokenRequester, parameters) => tokenRequester(castToTokenRequestParameters(parameters));
|
|
14252
14288
|
|
|
14253
14289
|
async function maybeUpdateToken(oauthTokenStore, tokenFetcher, options, mustRefresh = false) {
|
|
14254
14290
|
if (!mustRefresh && oauthTokenStore.get('accessToken')) {
|
|
14255
14291
|
return;
|
|
14256
14292
|
}
|
|
14257
|
-
const refreshOptions =
|
|
14293
|
+
const refreshOptions = {
|
|
14294
|
+
...options,
|
|
14295
|
+
refreshToken: oauthTokenStore.get('refreshToken'),
|
|
14296
|
+
};
|
|
14258
14297
|
if (isEligible$2(refreshOptions)) {
|
|
14259
14298
|
return oauthTokenStore.set(await requestToken$2(tokenFetcher, refreshOptions));
|
|
14260
14299
|
}
|
|
@@ -14309,12 +14348,12 @@ function refillReservoir() {
|
|
|
14309
14348
|
const reservoir = (await queue.currentReservoir());
|
|
14310
14349
|
if (queue.empty() && (await queue.running()) === 0 && reservoir > 10) {
|
|
14311
14350
|
return ((await queue.incrementReservoir(1)) &&
|
|
14312
|
-
|
|
14351
|
+
clearIntervalFunction(interval) &&
|
|
14313
14352
|
refillIntervalSet.delete(interval));
|
|
14314
14353
|
}
|
|
14315
14354
|
return reservoir < QUEUE_RESERVOIR
|
|
14316
14355
|
? queue.incrementReservoir(1)
|
|
14317
|
-
:
|
|
14356
|
+
: clearIntervalFunction(interval) && refillIntervalSet.delete(interval);
|
|
14318
14357
|
}, QUEUE_RESERVOIR_REFILL_INTERVAL);
|
|
14319
14358
|
return refillIntervalSet.add(interval);
|
|
14320
14359
|
}
|
|
@@ -14354,7 +14393,7 @@ function makeApiRequest(oauthTokenStore, oauthTokenRequester, options, httpMetho
|
|
|
14354
14393
|
}
|
|
14355
14394
|
await maybeUpdateToken(oauthTokenStore, oauthTokenRequester, options, retryCount > 0 &&
|
|
14356
14395
|
TOKEN_REFRESH_STATUS_CODES.includes(previousResult.status));
|
|
14357
|
-
const payloadQuery =
|
|
14396
|
+
const payloadQuery = payload?.query
|
|
14358
14397
|
? (apiMethod.includes('?') ? '&' : '?') +
|
|
14359
14398
|
querystring.stringify(payload.query, {
|
|
14360
14399
|
skipEmptyString: true,
|
|
@@ -14368,21 +14407,31 @@ function makeApiRequest(oauthTokenStore, oauthTokenRequester, options, httpMetho
|
|
|
14368
14407
|
try {
|
|
14369
14408
|
return (refillReservoir() &&
|
|
14370
14409
|
(await queue.schedule(async () => {
|
|
14371
|
-
var _a, _b, _c;
|
|
14372
14410
|
const method = httpMethod.toUpperCase();
|
|
14373
|
-
const body = payload
|
|
14411
|
+
const body = payload?.body;
|
|
14374
14412
|
const hasForm = isFormData(body);
|
|
14375
14413
|
const form = isFormData(body) ? body.formData : {};
|
|
14376
14414
|
const formData = Object.entries(form).reduce((previous, [name, value]) => {
|
|
14377
14415
|
previous.append.apply(previous, [name].concat(value));
|
|
14378
14416
|
return previous;
|
|
14379
14417
|
}, new FormDataModule());
|
|
14380
|
-
const headers =
|
|
14418
|
+
const headers = {
|
|
14419
|
+
accept: 'application/json',
|
|
14420
|
+
authorization: `Bearer ${oauthTokenStore.get('accessToken')}`,
|
|
14421
|
+
'X-Allthings-Caller': `${options.serviceName
|
|
14381
14422
|
? options.serviceName
|
|
14382
|
-
:
|
|
14383
|
-
|
|
14384
|
-
|
|
14385
|
-
|
|
14423
|
+
:
|
|
14424
|
+
process.env.SEVICE_NAME
|
|
14425
|
+
? process.env.SEVICE_NAME
|
|
14426
|
+
: 'unknown service name'} --- clientID ${options.clientId?.split('_')[0] ??
|
|
14427
|
+
options.clientId ??
|
|
14428
|
+
'no client id present'}`,
|
|
14429
|
+
...(hasForm ? {} : { 'content-type': 'application/json' }),
|
|
14430
|
+
...(typeof window === 'undefined' &&
|
|
14431
|
+
typeof document === 'undefined' && { 'user-agent': USER_AGENT }),
|
|
14432
|
+
...payload?.headers,
|
|
14433
|
+
...(hasForm && formData.getHeaders ? formData.getHeaders() : {}),
|
|
14434
|
+
};
|
|
14386
14435
|
if (process.env.LOG_REQUEST) {
|
|
14387
14436
|
console.log({ sdkLogs: { method, url } });
|
|
14388
14437
|
}
|
|
@@ -14393,8 +14442,14 @@ function makeApiRequest(oauthTokenStore, oauthTokenRequester, options, httpMetho
|
|
|
14393
14442
|
const requestBody = {
|
|
14394
14443
|
body: hasForm ? formData : JSON.stringify(body),
|
|
14395
14444
|
};
|
|
14396
|
-
const response = await fetch(url,
|
|
14397
|
-
|
|
14445
|
+
const response = await fetch(url, {
|
|
14446
|
+
cache: 'no-cache',
|
|
14447
|
+
credentials: 'omit',
|
|
14448
|
+
headers,
|
|
14449
|
+
method,
|
|
14450
|
+
mode: 'cors',
|
|
14451
|
+
...(hasForm || body ? requestBody : {}),
|
|
14452
|
+
});
|
|
14398
14453
|
const result = await makeResultFromResponse(response);
|
|
14399
14454
|
responseLogger.log(method, url, result instanceof Error
|
|
14400
14455
|
? { error: result }
|
|
@@ -14493,11 +14548,14 @@ const API_METHODS = [
|
|
|
14493
14548
|
bookingGetById,
|
|
14494
14549
|
];
|
|
14495
14550
|
function restClient(userOptions = DEFAULT_API_WRAPPER_OPTIONS) {
|
|
14496
|
-
const options =
|
|
14497
|
-
|
|
14551
|
+
const options = {
|
|
14552
|
+
...DEFAULT_API_WRAPPER_OPTIONS,
|
|
14553
|
+
...userOptions,
|
|
14554
|
+
};
|
|
14555
|
+
if (options.apiUrl === undefined) {
|
|
14498
14556
|
throw new Error('API URL is undefined.');
|
|
14499
14557
|
}
|
|
14500
|
-
if (
|
|
14558
|
+
if (options.oauthUrl === undefined) {
|
|
14501
14559
|
throw new Error('OAuth2 URL is undefined.');
|
|
14502
14560
|
}
|
|
14503
14561
|
if (!options.clientId &&
|
|
@@ -14519,13 +14577,25 @@ function restClient(userOptions = DEFAULT_API_WRAPPER_OPTIONS) {
|
|
|
14519
14577
|
const put$1 = partial(put, request$1);
|
|
14520
14578
|
const oauth = {
|
|
14521
14579
|
authorizationCode: {
|
|
14522
|
-
getUri: (state = options.state || pseudoRandomString()) => partial(getRedirectUrl$1,
|
|
14523
|
-
|
|
14580
|
+
getUri: (state = options.state || pseudoRandomString()) => partial(getRedirectUrl$1, {
|
|
14581
|
+
...options,
|
|
14582
|
+
state,
|
|
14583
|
+
})(),
|
|
14584
|
+
requestToken: (authorizationCode) => requestAndSaveToStore(partial(requestToken$3, tokenRequester, {
|
|
14585
|
+
...options,
|
|
14586
|
+
authorizationCode: authorizationCode || options.authorizationCode,
|
|
14587
|
+
}), tokenStore),
|
|
14524
14588
|
},
|
|
14525
14589
|
generateState: pseudoRandomString,
|
|
14526
|
-
refreshToken: (refreshToken) => requestAndSaveToStore(partial(requestToken$2, tokenRequester,
|
|
14590
|
+
refreshToken: (refreshToken) => requestAndSaveToStore(partial(requestToken$2, tokenRequester, {
|
|
14591
|
+
...options,
|
|
14592
|
+
refreshToken: refreshToken || tokenStore.get('refreshToken'),
|
|
14593
|
+
}), tokenStore),
|
|
14527
14594
|
};
|
|
14528
|
-
const client = API_METHODS.reduce((methods, method) => (
|
|
14595
|
+
const client = API_METHODS.reduce((methods, method) => ({
|
|
14596
|
+
...methods,
|
|
14597
|
+
[method.name]: (...arguments_) => method(client, ...arguments_),
|
|
14598
|
+
}), {
|
|
14529
14599
|
delete: del$1,
|
|
14530
14600
|
get,
|
|
14531
14601
|
oauth,
|