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