@wazo/sdk 0.40.8 → 0.41.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/wazo-sdk.js +3 -3
- package/esm/__tests__/api-client.test.js +0 -1
- package/esm/domain/__tests__/Session.test.js +1 -5
- package/esm/service/IssueReporter.js +1 -2
- package/esm/service/__tests__/IssueReporter.test.js +4 -7
- package/esm/simple/Auth.js +39 -17
- package/esm/types/service/IssueReporter.d.ts.map +1 -1
- package/esm/types/simple/Auth.d.ts.map +1 -1
- package/esm/types/utils/api-requester.d.ts +0 -1
- package/esm/types/utils/api-requester.d.ts.map +1 -1
- package/esm/utils/__tests__/api-requester.test.js +0 -2
- package/esm/utils/api-requester.js +3 -32
- package/lib/__tests__/api-client.test.js +0 -1
- package/lib/domain/__tests__/Session.test.js +1 -5
- package/lib/service/IssueReporter.js +1 -2
- package/lib/service/__tests__/IssueReporter.test.js +4 -7
- package/lib/simple/Auth.js +32 -8
- package/lib/types/service/IssueReporter.d.ts.map +1 -1
- package/lib/types/simple/Auth.d.ts.map +1 -1
- package/lib/types/utils/api-requester.d.ts +0 -1
- package/lib/types/utils/api-requester.d.ts.map +1 -1
- package/lib/utils/__tests__/api-requester.test.js +0 -2
- package/lib/utils/api-requester.js +3 -34
- package/package.json +2 -7
- package/src/__tests__/api-client.test.ts +0 -1
- package/src/domain/__tests__/Session.test.ts +1 -6
- package/src/service/IssueReporter.ts +1 -2
- package/src/service/__tests__/IssueReporter.test.ts +4 -7
- package/src/simple/Auth.ts +48 -17
- package/src/utils/__tests__/api-requester.test.ts +0 -3
- package/src/utils/api-requester.ts +3 -34
|
@@ -3,12 +3,8 @@ import Profile from '../Profile';
|
|
|
3
3
|
import Line from '../Line';
|
|
4
4
|
describe('Session domain', () => {
|
|
5
5
|
it('can parse a plain session to domain', () => {
|
|
6
|
-
// Can't use `new Headers` because it's not supported on node 16.
|
|
7
|
-
const headers = {
|
|
8
|
-
get: () => 'new-stack',
|
|
9
|
-
};
|
|
10
6
|
const plain = {
|
|
11
|
-
_headers:
|
|
7
|
+
_headers: new Headers({ 'wazo-stack-host': 'new-stack' }),
|
|
12
8
|
data: {
|
|
13
9
|
token: 'b93ae6bd-08d7-4001-9e61-057e72bbc4b3',
|
|
14
10
|
acl: ['calld.lines.*.presences.read', 'calld.switchboards.#', 'calld.transfers.*.complete.update', 'calld.transfers.*.delete', 'calld.transfers.*.read', 'calld.users.*.presences.read', 'calld.users.me.#', 'confd.infos.read', 'confd.users.me.#.read', 'confd.users.me.forwards.*.*', 'confd.users.me.funckeys.*', 'confd.users.me.funckeys.*.*', 'confd.users.me.read', 'confd.users.me.services.*.*', 'confd.users.me.update', 'dird.#.me.read', 'dird.directories.favorites.#', 'dird.directories.lookup.*.headers.read', 'dird.directories.lookup.*.read', 'dird.directories.personal.*.read', 'dird.personal.#', 'events.calls.me', 'events.chat.message.*.me', 'events.config.users.me.#', 'events.statuses.*', 'events.switchboards.#', 'events.transfers.me', 'events.users.me.#', 'events.directory.me.#', 'websocketd', 'call-logd.users.me.cdr.read'],
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* global window */
|
|
2
2
|
/* eslint-disable prefer-destructuring, no-param-reassign, no-underscore-dangle */
|
|
3
3
|
import moment from 'moment';
|
|
4
|
-
import { realFetch } from '../utils/api-requester';
|
|
5
4
|
import isMobile from '../utils/isMobile';
|
|
6
5
|
import { obfuscateToken } from '../utils/string';
|
|
7
6
|
const TRACE = 'trace';
|
|
@@ -288,7 +287,7 @@ class IssueReporter {
|
|
|
288
287
|
const isSecure = +port === 443;
|
|
289
288
|
const url = `http${isSecure ? 's' : ''}://${host}${isSecure ? '' : `:${port}`}/${tag}`;
|
|
290
289
|
const body = Array.isArray(payload) ? `[${payload.map(this._boundParseLoggerBody).join(',')}]` : this._parseLoggerBody(payload);
|
|
291
|
-
|
|
290
|
+
fetch(url, {
|
|
292
291
|
method: 'POST',
|
|
293
292
|
headers: {
|
|
294
293
|
Accept: 'application/json',
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
/* eslint-disable no-useless-escape */
|
|
3
3
|
/* eslint-disable no-console */
|
|
4
4
|
import IssueReporter from '../IssueReporter';
|
|
5
|
-
import { realFetch } from '../../utils/api-requester';
|
|
6
5
|
jest.mock('../../utils/api-requester');
|
|
7
6
|
let oldLog;
|
|
8
7
|
let oldError;
|
|
@@ -18,9 +17,7 @@ describe('IssueReporter', () => {
|
|
|
18
17
|
});
|
|
19
18
|
beforeEach(() => {
|
|
20
19
|
jest.resetAllMocks();
|
|
21
|
-
|
|
22
|
-
catch: () => { },
|
|
23
|
-
}));
|
|
20
|
+
jest.spyOn(global, 'fetch');
|
|
24
21
|
});
|
|
25
22
|
afterAll(() => {
|
|
26
23
|
console.log = oldLog;
|
|
@@ -41,7 +38,7 @@ describe('IssueReporter', () => {
|
|
|
41
38
|
level: 'trace',
|
|
42
39
|
});
|
|
43
40
|
IssueReporter._sendToRemoteLogger('info');
|
|
44
|
-
expect(
|
|
41
|
+
expect(fetch).toHaveBeenCalled();
|
|
45
42
|
});
|
|
46
43
|
it('should send if verbosity is equal than required', () => {
|
|
47
44
|
// Same level
|
|
@@ -49,7 +46,7 @@ describe('IssueReporter', () => {
|
|
|
49
46
|
level: 'trace',
|
|
50
47
|
});
|
|
51
48
|
IssueReporter._sendToRemoteLogger('trace');
|
|
52
|
-
expect(
|
|
49
|
+
expect(fetch).toHaveBeenCalled();
|
|
53
50
|
});
|
|
54
51
|
it('should not send if verbosity is lower than required', () => {
|
|
55
52
|
// Lower level
|
|
@@ -57,7 +54,7 @@ describe('IssueReporter', () => {
|
|
|
57
54
|
level: 'info',
|
|
58
55
|
});
|
|
59
56
|
IssueReporter._sendToRemoteLogger('trace');
|
|
60
|
-
expect(
|
|
57
|
+
expect(fetch).not.toHaveBeenCalled();
|
|
61
58
|
});
|
|
62
59
|
it('should log extra data', () => {
|
|
63
60
|
jest.spyOn(IssueReporter, '_sendToRemoteLogger').mockImplementation(() => { });
|
package/esm/simple/Auth.js
CHANGED
|
@@ -27,15 +27,13 @@ class Auth {
|
|
|
27
27
|
mobile;
|
|
28
28
|
BACKEND_WAZO;
|
|
29
29
|
BACKEND_LDAP;
|
|
30
|
-
|
|
31
|
-
shouldCheckUserUuidHeader;
|
|
30
|
+
usingEdgeServer;
|
|
32
31
|
constructor() {
|
|
33
32
|
this.expiration = DETAULT_EXPIRATION;
|
|
34
33
|
this.authenticated = false;
|
|
35
34
|
this.minSubscriptionType = null;
|
|
36
35
|
this.BACKEND_WAZO = DEFAULT_BACKEND_USER;
|
|
37
36
|
this.BACKEND_LDAP = BACKEND_LDAP_USER;
|
|
38
|
-
this.shouldCheckUserUuidHeader = true;
|
|
39
37
|
}
|
|
40
38
|
init(clientId, expiration, minSubscriptionType, authorizationName, mobile) {
|
|
41
39
|
this.clientId = clientId;
|
|
@@ -160,6 +158,7 @@ class Auth {
|
|
|
160
158
|
setRefreshToken(null);
|
|
161
159
|
this.session = null;
|
|
162
160
|
this.authenticated = false;
|
|
161
|
+
this.usingEdgeServer = undefined;
|
|
163
162
|
setFetchOptions({});
|
|
164
163
|
}
|
|
165
164
|
setOnHostFromHeaders(callback) {
|
|
@@ -241,26 +240,44 @@ class Auth {
|
|
|
241
240
|
getName() {
|
|
242
241
|
return `${this.getFirstName()} ${this.getLastName()}`;
|
|
243
242
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
const headers = {
|
|
243
|
+
_getHttpUserUuidHeaders(uuid) {
|
|
244
|
+
return {
|
|
249
245
|
...(getFetchOptions()?.headers || {}),
|
|
250
246
|
'X-User-UUID': uuid,
|
|
251
247
|
};
|
|
248
|
+
}
|
|
249
|
+
setHttpUserUuidHeader(uuid) {
|
|
250
|
+
logger.info('Setting http header user uuid', { uuid });
|
|
251
|
+
if (!uuid) {
|
|
252
|
+
logger.warn('attempting to set a null value to user uuid header');
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const headers = this._getHttpUserUuidHeaders(uuid);
|
|
256
|
+
setFetchOptions({
|
|
257
|
+
...getFetchOptions(),
|
|
258
|
+
headers,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
async checkHttpUserUuidHeader(uuid) {
|
|
262
|
+
logger.info('Checking user uuid http header', { uuid });
|
|
263
|
+
if (!uuid) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const headers = this._getHttpUserUuidHeaders(uuid);
|
|
252
267
|
try {
|
|
253
|
-
|
|
254
|
-
|
|
268
|
+
const response = await getApiClient().client.head('auth/0.1/status', null, headers, (r) => r);
|
|
269
|
+
const allowsUserUuidHeader = response.headers.get('access-control-allow-headers')?.includes('X-User-UUID');
|
|
270
|
+
if (this.mobile && !allowsUserUuidHeader) {
|
|
271
|
+
throw new Error('Server does not allow user UUID header on mobile');
|
|
255
272
|
}
|
|
256
273
|
// If the previous request went well, it means that the header is accepted
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
});
|
|
274
|
+
this.setHttpUserUuidHeader(uuid);
|
|
275
|
+
this.usingEdgeServer = true;
|
|
276
|
+
logger.info('Setting usingEdgeServer value to TRUE', { requestHeaders: headers, responseHeaders: response.headers, allowsUserUuidHeader });
|
|
261
277
|
}
|
|
262
|
-
catch (
|
|
263
|
-
|
|
278
|
+
catch (e) {
|
|
279
|
+
this.usingEdgeServer = false;
|
|
280
|
+
logger.info('Setting usingEdgeServer to FALSE', { justification: e });
|
|
264
281
|
}
|
|
265
282
|
}
|
|
266
283
|
async _onAuthenticated(rawSession) {
|
|
@@ -268,10 +285,15 @@ class Auth {
|
|
|
268
285
|
return this.session;
|
|
269
286
|
}
|
|
270
287
|
const session = rawSession;
|
|
271
|
-
await this.setHttpUserUuidHeader(session.uuid);
|
|
272
288
|
if (!session) {
|
|
273
289
|
return null;
|
|
274
290
|
}
|
|
291
|
+
if (this.usingEdgeServer) {
|
|
292
|
+
this.setHttpUserUuidHeader(session.uuid);
|
|
293
|
+
}
|
|
294
|
+
else if (typeof this.usingEdgeServer === 'undefined') {
|
|
295
|
+
await this.checkHttpUserUuidHeader(session.uuid);
|
|
296
|
+
}
|
|
275
297
|
setApiToken(session.token);
|
|
276
298
|
if (session.refreshToken) {
|
|
277
299
|
setRefreshToken(session.refreshToken);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IssueReporter.d.ts","sourceRoot":"","sources":["../../../src/service/IssueReporter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IssueReporter.d.ts","sourceRoot":"","sources":["../../../src/service/IssueReporter.ts"],"names":[],"mappings":"AAsDA,cAAM,aAAa;IACjB,KAAK,EAAE,MAAM,CAAC;IAEd,IAAI,EAAE,MAAM,CAAC;IAEb,GAAG,EAAE,MAAM,CAAC;IAEZ,IAAI,EAAE,MAAM,CAAC;IAEb,KAAK,EAAE,MAAM,CAAC;IAEd,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAE9C,OAAO,EAAE,OAAO,CAAC;IAEjB,yBAAyB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAElE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;IAE9B,aAAa,EAAE,GAAG,GAAG,IAAI,GAAG,SAAS,CAAC;IAEtC,mBAAmB,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;IAElD,qBAAqB,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;IAEpD,SAAS,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;;IAc7D,IAAI;IAIJ,WAAW,CAAC,EAAE,EAAE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C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAW5C,aAAa,CAAC,QAAQ,EAAE,MAAM;CAI/B;;AAED,wBAAmC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Auth.d.ts","sourceRoot":"","sources":["../../../src/simple/Auth.ts"],"names":[],"mappings":"AAsBA,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AACjD,qBAAa,oBAAqB,SAAQ,KAAK;CAAG;AAClD,qBAAa,eAAgB,SAAQ,KAAK;CAAG;AAC7C,qBAAa,iBAAkB,SAAQ,KAAK;CAAG;;
|
|
1
|
+
{"version":3,"file":"Auth.d.ts","sourceRoot":"","sources":["../../../src/simple/Auth.ts"],"names":[],"mappings":"AAsBA,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AACjD,qBAAa,oBAAqB,SAAQ,KAAK;CAAG;AAClD,qBAAa,eAAgB,SAAQ,KAAK;CAAG;AAC7C,qBAAa,iBAAkB,SAAQ,KAAK;CAAG;;AA8Z/C,wBAAuC"}
|
|
@@ -8,7 +8,6 @@ type ConstructorParams = {
|
|
|
8
8
|
fetchOptions: Record<string, any> | null | undefined;
|
|
9
9
|
requestTimeout?: number | null;
|
|
10
10
|
};
|
|
11
|
-
export declare const realFetch: () => any;
|
|
12
11
|
export default class ApiRequester {
|
|
13
12
|
server: string;
|
|
14
13
|
agent: Record<string, any> | null | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-requester.d.ts","sourceRoot":"","sources":["../../../src/utils/api-requester.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api-requester.d.ts","sourceRoot":"","sources":["../../../src/utils/api-requester.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAG7C,KAAK,iBAAiB,GAAG;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CA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,GAAG,CAAC,KAAK,GAAgC,EAAE,SAAS,UAAO,GAAG,OAAO,CAAC,GAAG,CAAC;IAyFvR,kBAAkB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAO1E,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAIzC,mBAAmB,CACjB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAgB,EACnD,OAAO,GAAE,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAQ,EACtF,KAAK,GAAE,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,GAAG,SAAqB;IA6B/D,UAAU,CAAC,MAAM,EAAE,CAAC,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAe9G,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM;IAK9F,IAAI,OAAO,IAAI,MAAM,CAEpB;CAEF"}
|
|
@@ -74,7 +74,6 @@ describe('Retrieving headers', () => {
|
|
|
74
74
|
});
|
|
75
75
|
describe('Calling fetch', () => {
|
|
76
76
|
it('should call fetch without body but query string in get method', async () => {
|
|
77
|
-
jest.mock('node-fetch/src/index', () => { });
|
|
78
77
|
global.fetch = jest.fn(() => Promise.resolve({
|
|
79
78
|
json: () => Promise.resolve({}),
|
|
80
79
|
headers: {
|
|
@@ -99,7 +98,6 @@ describe('Calling fetch', () => {
|
|
|
99
98
|
});
|
|
100
99
|
describe('With a refresh token', () => {
|
|
101
100
|
it('should retry the call with a new token', async () => {
|
|
102
|
-
jest.mock('node-fetch/src/index', () => { });
|
|
103
101
|
let calls = 0;
|
|
104
102
|
global.fetch = jest.fn(() => {
|
|
105
103
|
calls++;
|
|
@@ -1,39 +1,10 @@
|
|
|
1
|
-
/* global window */
|
|
2
|
-
/* eslint-disable global-require */
|
|
3
|
-
/* eslint-disable import/no-dynamic-require */
|
|
4
1
|
import { Base64 } from 'js-base64';
|
|
5
|
-
import { AbortController as NodeAbortController } from 'node-abort-controller';
|
|
6
2
|
import BadResponse from '../domain/BadResponse';
|
|
7
3
|
import ServerError from '../domain/ServerError';
|
|
8
|
-
import isMobile from './isMobile';
|
|
9
4
|
import IssueReporter from '../service/IssueReporter';
|
|
10
5
|
const methods = ['head', 'get', 'post', 'put', 'delete', 'options'];
|
|
11
6
|
const logger = IssueReporter ? IssueReporter.loggerFor('api') : console;
|
|
12
7
|
const REQUEST_TIMEOUT_MS = 300 * 1000; // 300s like the Chrome engine default value.
|
|
13
|
-
// Use a function here to be able to mock it in tests
|
|
14
|
-
export const realFetch = () => {
|
|
15
|
-
if (typeof fetch !== 'undefined') {
|
|
16
|
-
return fetch;
|
|
17
|
-
}
|
|
18
|
-
if (typeof document !== 'undefined' && window.fetch) {
|
|
19
|
-
// Browser
|
|
20
|
-
return window.fetch;
|
|
21
|
-
}
|
|
22
|
-
if (isMobile()) {
|
|
23
|
-
// React native
|
|
24
|
-
return fetch;
|
|
25
|
-
}
|
|
26
|
-
// nodejs
|
|
27
|
-
// this package is disabled for react-native in package.json because it requires nodejs modules
|
|
28
|
-
// Used to trick the optimizer to avoid requiring `node-fetch/lib/index` directly
|
|
29
|
-
// It causes to require it on browsers when delivered by a nodejs engine (cf: vitejs).
|
|
30
|
-
try {
|
|
31
|
-
return require(Math.random() >= 0 ? 'node-fetch/lib/index' : '');
|
|
32
|
-
}
|
|
33
|
-
catch (e) {
|
|
34
|
-
return fetch;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
8
|
export default class ApiRequester {
|
|
38
9
|
server;
|
|
39
10
|
agent;
|
|
@@ -113,9 +84,9 @@ export default class ApiRequester {
|
|
|
113
84
|
}
|
|
114
85
|
const isHead = method === 'head';
|
|
115
86
|
const hasEmptyResponse = method === 'delete' || isHead;
|
|
116
|
-
const newParse = hasEmptyResponse ? ApiRequester.successResponseParser : parse;
|
|
87
|
+
const newParse = hasEmptyResponse && parse === ApiRequester.defaultParser ? ApiRequester.successResponseParser : parse;
|
|
117
88
|
const fetchOptions = { ...(this.fetchOptions || {}) };
|
|
118
|
-
const controller =
|
|
89
|
+
const controller = new AbortController();
|
|
119
90
|
const extraHeaders = fetchOptions.headers || {};
|
|
120
91
|
delete fetchOptions.headers;
|
|
121
92
|
const options = {
|
|
@@ -136,7 +107,7 @@ export default class ApiRequester {
|
|
|
136
107
|
await this.refreshTokenPromise;
|
|
137
108
|
}
|
|
138
109
|
const start = new Date();
|
|
139
|
-
const requestPromise =
|
|
110
|
+
const requestPromise = fetch(url, options).then((response) => {
|
|
140
111
|
const contentType = response.headers.get('content-type') || '';
|
|
141
112
|
const isJson = contentType.indexOf('application/json') !== -1;
|
|
142
113
|
IssueReporter.logRequest(url, options, response, start);
|
|
@@ -17,12 +17,8 @@ const Profile_1 = __importDefault(require("../Profile"));
|
|
|
17
17
|
const Line_1 = __importDefault(require("../Line"));
|
|
18
18
|
describe('Session domain', () => {
|
|
19
19
|
it('can parse a plain session to domain', () => {
|
|
20
|
-
// Can't use `new Headers` because it's not supported on node 16.
|
|
21
|
-
const headers = {
|
|
22
|
-
get: () => 'new-stack',
|
|
23
|
-
};
|
|
24
20
|
const plain = {
|
|
25
|
-
_headers:
|
|
21
|
+
_headers: new Headers({ 'wazo-stack-host': 'new-stack' }),
|
|
26
22
|
data: {
|
|
27
23
|
token: 'b93ae6bd-08d7-4001-9e61-057e72bbc4b3',
|
|
28
24
|
acl: ['calld.lines.*.presences.read', 'calld.switchboards.#', 'calld.transfers.*.complete.update', 'calld.transfers.*.delete', 'calld.transfers.*.read', 'calld.users.*.presences.read', 'calld.users.me.#', 'confd.infos.read', 'confd.users.me.#.read', 'confd.users.me.forwards.*.*', 'confd.users.me.funckeys.*', 'confd.users.me.funckeys.*.*', 'confd.users.me.read', 'confd.users.me.services.*.*', 'confd.users.me.update', 'dird.#.me.read', 'dird.directories.favorites.#', 'dird.directories.lookup.*.headers.read', 'dird.directories.lookup.*.read', 'dird.directories.personal.*.read', 'dird.personal.#', 'events.calls.me', 'events.chat.message.*.me', 'events.config.users.me.#', 'events.statuses.*', 'events.switchboards.#', 'events.transfers.me', 'events.users.me.#', 'events.directory.me.#', 'websocketd', 'call-logd.users.me.cdr.read'],
|
|
@@ -6,7 +6,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
/* eslint-disable prefer-destructuring, no-param-reassign, no-underscore-dangle */
|
|
8
8
|
const moment_1 = __importDefault(require("moment"));
|
|
9
|
-
const api_requester_1 = require("../utils/api-requester");
|
|
10
9
|
const isMobile_1 = __importDefault(require("../utils/isMobile"));
|
|
11
10
|
const string_1 = require("../utils/string");
|
|
12
11
|
const TRACE = 'trace';
|
|
@@ -274,7 +273,7 @@ class IssueReporter {
|
|
|
274
273
|
const isSecure = +port === 443;
|
|
275
274
|
const url = `http${isSecure ? 's' : ''}://${host}${isSecure ? '' : `:${port}`}/${tag}`;
|
|
276
275
|
const body = Array.isArray(payload) ? `[${payload.map(this._boundParseLoggerBody).join(',')}]` : this._parseLoggerBody(payload);
|
|
277
|
-
(
|
|
276
|
+
fetch(url, {
|
|
278
277
|
method: 'POST',
|
|
279
278
|
headers: {
|
|
280
279
|
Accept: 'application/json',
|
|
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
/* eslint-disable no-useless-escape */
|
|
8
8
|
/* eslint-disable no-console */
|
|
9
9
|
const IssueReporter_1 = __importDefault(require("../IssueReporter"));
|
|
10
|
-
const api_requester_1 = require("../../utils/api-requester");
|
|
11
10
|
jest.mock('../../utils/api-requester');
|
|
12
11
|
let oldLog;
|
|
13
12
|
let oldError;
|
|
@@ -23,9 +22,7 @@ describe('IssueReporter', () => {
|
|
|
23
22
|
});
|
|
24
23
|
beforeEach(() => {
|
|
25
24
|
jest.resetAllMocks();
|
|
26
|
-
|
|
27
|
-
catch: () => { },
|
|
28
|
-
}));
|
|
25
|
+
jest.spyOn(global, 'fetch');
|
|
29
26
|
});
|
|
30
27
|
afterAll(() => {
|
|
31
28
|
console.log = oldLog;
|
|
@@ -46,7 +43,7 @@ describe('IssueReporter', () => {
|
|
|
46
43
|
level: 'trace',
|
|
47
44
|
});
|
|
48
45
|
IssueReporter_1.default._sendToRemoteLogger('info');
|
|
49
|
-
expect(
|
|
46
|
+
expect(fetch).toHaveBeenCalled();
|
|
50
47
|
});
|
|
51
48
|
it('should send if verbosity is equal than required', () => {
|
|
52
49
|
// Same level
|
|
@@ -54,7 +51,7 @@ describe('IssueReporter', () => {
|
|
|
54
51
|
level: 'trace',
|
|
55
52
|
});
|
|
56
53
|
IssueReporter_1.default._sendToRemoteLogger('trace');
|
|
57
|
-
expect(
|
|
54
|
+
expect(fetch).toHaveBeenCalled();
|
|
58
55
|
});
|
|
59
56
|
it('should not send if verbosity is lower than required', () => {
|
|
60
57
|
// Lower level
|
|
@@ -62,7 +59,7 @@ describe('IssueReporter', () => {
|
|
|
62
59
|
level: 'info',
|
|
63
60
|
});
|
|
64
61
|
IssueReporter_1.default._sendToRemoteLogger('trace');
|
|
65
|
-
expect(
|
|
62
|
+
expect(fetch).not.toHaveBeenCalled();
|
|
66
63
|
});
|
|
67
64
|
it('should log extra data', () => {
|
|
68
65
|
jest.spyOn(IssueReporter_1.default, '_sendToRemoteLogger').mockImplementation(() => { });
|
package/lib/simple/Auth.js
CHANGED
|
@@ -62,7 +62,6 @@ class Auth {
|
|
|
62
62
|
this.minSubscriptionType = null;
|
|
63
63
|
this.BACKEND_WAZO = auth_1.DEFAULT_BACKEND_USER;
|
|
64
64
|
this.BACKEND_LDAP = auth_1.BACKEND_LDAP_USER;
|
|
65
|
-
this.shouldCheckUserUuidHeader = true;
|
|
66
65
|
}
|
|
67
66
|
init(clientId, expiration, minSubscriptionType, authorizationName, mobile) {
|
|
68
67
|
this.clientId = clientId;
|
|
@@ -197,6 +196,7 @@ class Auth {
|
|
|
197
196
|
(0, getApiClient_1.setRefreshToken)(null);
|
|
198
197
|
this.session = null;
|
|
199
198
|
this.authenticated = false;
|
|
199
|
+
this.usingEdgeServer = undefined;
|
|
200
200
|
(0, getApiClient_1.setFetchOptions)({});
|
|
201
201
|
});
|
|
202
202
|
}
|
|
@@ -280,22 +280,41 @@ class Auth {
|
|
|
280
280
|
getName() {
|
|
281
281
|
return `${this.getFirstName()} ${this.getLastName()}`;
|
|
282
282
|
}
|
|
283
|
+
_getHttpUserUuidHeaders(uuid) {
|
|
284
|
+
var _a;
|
|
285
|
+
return Object.assign(Object.assign({}, (((_a = (0, getApiClient_1.getFetchOptions)()) === null || _a === void 0 ? void 0 : _a.headers) || {})), { 'X-User-UUID': uuid });
|
|
286
|
+
}
|
|
283
287
|
setHttpUserUuidHeader(uuid) {
|
|
288
|
+
logger.info('Setting http header user uuid', { uuid });
|
|
289
|
+
if (!uuid) {
|
|
290
|
+
logger.warn('attempting to set a null value to user uuid header');
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const headers = this._getHttpUserUuidHeaders(uuid);
|
|
294
|
+
(0, getApiClient_1.setFetchOptions)(Object.assign(Object.assign({}, (0, getApiClient_1.getFetchOptions)()), { headers }));
|
|
295
|
+
}
|
|
296
|
+
checkHttpUserUuidHeader(uuid) {
|
|
284
297
|
var _a;
|
|
285
298
|
return __awaiter(this, void 0, void 0, function* () {
|
|
299
|
+
logger.info('Checking user uuid http header', { uuid });
|
|
286
300
|
if (!uuid) {
|
|
287
301
|
return;
|
|
288
302
|
}
|
|
289
|
-
const headers =
|
|
303
|
+
const headers = this._getHttpUserUuidHeaders(uuid);
|
|
290
304
|
try {
|
|
291
|
-
|
|
292
|
-
|
|
305
|
+
const response = yield (0, getApiClient_1.default)().client.head('auth/0.1/status', null, headers, (r) => r);
|
|
306
|
+
const allowsUserUuidHeader = (_a = response.headers.get('access-control-allow-headers')) === null || _a === void 0 ? void 0 : _a.includes('X-User-UUID');
|
|
307
|
+
if (this.mobile && !allowsUserUuidHeader) {
|
|
308
|
+
throw new Error('Server does not allow user UUID header on mobile');
|
|
293
309
|
}
|
|
294
310
|
// If the previous request went well, it means that the header is accepted
|
|
295
|
-
|
|
311
|
+
this.setHttpUserUuidHeader(uuid);
|
|
312
|
+
this.usingEdgeServer = true;
|
|
313
|
+
logger.info('Setting usingEdgeServer value to TRUE', { requestHeaders: headers, responseHeaders: response.headers, allowsUserUuidHeader });
|
|
296
314
|
}
|
|
297
|
-
catch (
|
|
298
|
-
|
|
315
|
+
catch (e) {
|
|
316
|
+
this.usingEdgeServer = false;
|
|
317
|
+
logger.info('Setting usingEdgeServer to FALSE', { justification: e });
|
|
299
318
|
}
|
|
300
319
|
});
|
|
301
320
|
}
|
|
@@ -306,10 +325,15 @@ class Auth {
|
|
|
306
325
|
return this.session;
|
|
307
326
|
}
|
|
308
327
|
const session = rawSession;
|
|
309
|
-
yield this.setHttpUserUuidHeader(session.uuid);
|
|
310
328
|
if (!session) {
|
|
311
329
|
return null;
|
|
312
330
|
}
|
|
331
|
+
if (this.usingEdgeServer) {
|
|
332
|
+
this.setHttpUserUuidHeader(session.uuid);
|
|
333
|
+
}
|
|
334
|
+
else if (typeof this.usingEdgeServer === 'undefined') {
|
|
335
|
+
yield this.checkHttpUserUuidHeader(session.uuid);
|
|
336
|
+
}
|
|
313
337
|
(0, getApiClient_1.setApiToken)(session.token);
|
|
314
338
|
if (session.refreshToken) {
|
|
315
339
|
(0, getApiClient_1.setRefreshToken)(session.refreshToken);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IssueReporter.d.ts","sourceRoot":"","sources":["../../../src/service/IssueReporter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IssueReporter.d.ts","sourceRoot":"","sources":["../../../src/service/IssueReporter.ts"],"names":[],"mappings":"AAsDA,cAAM,aAAa;IACjB,KAAK,EAAE,MAAM,CAAC;IAEd,IAAI,EAAE,MAAM,CAAC;IAEb,GAAG,EAAE,MAAM,CAAC;IAEZ,IAAI,EAAE,MAAM,CAAC;IAEb,KAAK,EAAE,MAAM,CAAC;IAEd,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAE9C,OAAO,EAAE,OAAO,CAAC;IAEjB,yBAAyB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAElE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;IAE9B,aAAa,EAAE,GAAG,GAAG,IAAI,GAAG,SAAS,CAAC;IAEtC,mBAAmB,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;IAElD,qBAAqB,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;IAEpD,SAAS,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;;IAc7D,IAAI;IAIJ,WAAW,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAA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AM;IAW5C,aAAa,CAAC,QAAQ,EAAE,MAAM;CAI/B;;AAED,wBAAmC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Auth.d.ts","sourceRoot":"","sources":["../../../src/simple/Auth.ts"],"names":[],"mappings":"AAsBA,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AACjD,qBAAa,oBAAqB,SAAQ,KAAK;CAAG;AAClD,qBAAa,eAAgB,SAAQ,KAAK;CAAG;AAC7C,qBAAa,iBAAkB,SAAQ,KAAK;CAAG;;
|
|
1
|
+
{"version":3,"file":"Auth.d.ts","sourceRoot":"","sources":["../../../src/simple/Auth.ts"],"names":[],"mappings":"AAsBA,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AACjD,qBAAa,oBAAqB,SAAQ,KAAK;CAAG;AAClD,qBAAa,eAAgB,SAAQ,KAAK;CAAG;AAC7C,qBAAa,iBAAkB,SAAQ,KAAK;CAAG;;AA8Z/C,wBAAuC"}
|
|
@@ -8,7 +8,6 @@ type ConstructorParams = {
|
|
|
8
8
|
fetchOptions: Record<string, any> | null | undefined;
|
|
9
9
|
requestTimeout?: number | null;
|
|
10
10
|
};
|
|
11
|
-
export declare const realFetch: () => any;
|
|
12
11
|
export default class ApiRequester {
|
|
13
12
|
server: string;
|
|
14
13
|
agent: Record<string, any> | null | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-requester.d.ts","sourceRoot":"","sources":["../../../src/utils/api-requester.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api-requester.d.ts","sourceRoot":"","sources":["../../../src/utils/api-requester.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAG7C,KAAK,iBAAiB,GAAG;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAC9C,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AO,GAAG,OAAO,CAAC,GAAG,CAAC;IAyFvR,kBAAkB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAO1E,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAIzC,mBAAmB,CACjB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAgB,EACnD,OAAO,GAAE,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAQ,EACtF,KAAK,GAAE,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,GAAG,SAAqB;IA6B/D,UAAU,CAAC,MAAM,EAAE,CAAC,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAe9G,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM;IAK9F,IAAI,OAAO,IAAI,MAAM,CAEpB;CAEF"}
|
|
@@ -88,7 +88,6 @@ describe('Retrieving headers', () => {
|
|
|
88
88
|
});
|
|
89
89
|
describe('Calling fetch', () => {
|
|
90
90
|
it('should call fetch without body but query string in get method', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
-
jest.mock('node-fetch/src/index', () => { });
|
|
92
91
|
global.fetch = jest.fn(() => Promise.resolve({
|
|
93
92
|
json: () => Promise.resolve({}),
|
|
94
93
|
headers: {
|
|
@@ -113,7 +112,6 @@ describe('Calling fetch', () => {
|
|
|
113
112
|
});
|
|
114
113
|
describe('With a refresh token', () => {
|
|
115
114
|
it('should retry the call with a new token', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
116
|
-
jest.mock('node-fetch/src/index', () => { });
|
|
117
115
|
let calls = 0;
|
|
118
116
|
global.fetch = jest.fn(() => {
|
|
119
117
|
calls++;
|
|
@@ -12,44 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.realFetch = void 0;
|
|
16
|
-
/* global window */
|
|
17
|
-
/* eslint-disable global-require */
|
|
18
|
-
/* eslint-disable import/no-dynamic-require */
|
|
19
15
|
const js_base64_1 = require("js-base64");
|
|
20
|
-
const node_abort_controller_1 = require("node-abort-controller");
|
|
21
16
|
const BadResponse_1 = __importDefault(require("../domain/BadResponse"));
|
|
22
17
|
const ServerError_1 = __importDefault(require("../domain/ServerError"));
|
|
23
|
-
const isMobile_1 = __importDefault(require("./isMobile"));
|
|
24
18
|
const IssueReporter_1 = __importDefault(require("../service/IssueReporter"));
|
|
25
19
|
const methods = ['head', 'get', 'post', 'put', 'delete', 'options'];
|
|
26
20
|
const logger = IssueReporter_1.default ? IssueReporter_1.default.loggerFor('api') : console;
|
|
27
21
|
const REQUEST_TIMEOUT_MS = 300 * 1000; // 300s like the Chrome engine default value.
|
|
28
|
-
// Use a function here to be able to mock it in tests
|
|
29
|
-
const realFetch = () => {
|
|
30
|
-
if (typeof fetch !== 'undefined') {
|
|
31
|
-
return fetch;
|
|
32
|
-
}
|
|
33
|
-
if (typeof document !== 'undefined' && window.fetch) {
|
|
34
|
-
// Browser
|
|
35
|
-
return window.fetch;
|
|
36
|
-
}
|
|
37
|
-
if ((0, isMobile_1.default)()) {
|
|
38
|
-
// React native
|
|
39
|
-
return fetch;
|
|
40
|
-
}
|
|
41
|
-
// nodejs
|
|
42
|
-
// this package is disabled for react-native in package.json because it requires nodejs modules
|
|
43
|
-
// Used to trick the optimizer to avoid requiring `node-fetch/lib/index` directly
|
|
44
|
-
// It causes to require it on browsers when delivered by a nodejs engine (cf: vitejs).
|
|
45
|
-
try {
|
|
46
|
-
return require(Math.random() >= 0 ? 'node-fetch/lib/index' : '');
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
return fetch;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
exports.realFetch = realFetch;
|
|
53
22
|
class ApiRequester {
|
|
54
23
|
static successResponseParser(response) {
|
|
55
24
|
return response.status === 204 || response.status === 201 || response.status === 200;
|
|
@@ -114,9 +83,9 @@ class ApiRequester {
|
|
|
114
83
|
}
|
|
115
84
|
const isHead = method === 'head';
|
|
116
85
|
const hasEmptyResponse = method === 'delete' || isHead;
|
|
117
|
-
const newParse = hasEmptyResponse ? ApiRequester.successResponseParser : parse;
|
|
86
|
+
const newParse = hasEmptyResponse && parse === ApiRequester.defaultParser ? ApiRequester.successResponseParser : parse;
|
|
118
87
|
const fetchOptions = Object.assign({}, (this.fetchOptions || {}));
|
|
119
|
-
const controller =
|
|
88
|
+
const controller = new AbortController();
|
|
120
89
|
const extraHeaders = fetchOptions.headers || {};
|
|
121
90
|
delete fetchOptions.headers;
|
|
122
91
|
const options = Object.assign({ method, body: newBody, signal: controller ? controller.signal : null, headers: Object.assign(Object.assign({}, this.getHeaders(headers)), extraHeaders), agent: this.agent }, fetchOptions);
|
|
@@ -127,7 +96,7 @@ class ApiRequester {
|
|
|
127
96
|
yield this.refreshTokenPromise;
|
|
128
97
|
}
|
|
129
98
|
const start = new Date();
|
|
130
|
-
const requestPromise = (
|
|
99
|
+
const requestPromise = fetch(url, options).then((response) => {
|
|
131
100
|
const contentType = response.headers.get('content-type') || '';
|
|
132
101
|
const isJson = contentType.indexOf('application/json') !== -1;
|
|
133
102
|
IssueReporter_1.default.logRequest(url, options, response, start);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wazo/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"description": "Wazo's JavaScript Software Development Kit.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -55,8 +55,6 @@
|
|
|
55
55
|
"json-to-graphql-query": "^2.2.5",
|
|
56
56
|
"jsrsasign": "^11.0.0",
|
|
57
57
|
"moment": "^2.29.1",
|
|
58
|
-
"node-abort-controller": "^3.1.1",
|
|
59
|
-
"node-fetch": "^3.3.1",
|
|
60
58
|
"reconnecting-websocket": "^4.4.0",
|
|
61
59
|
"sdp-transform": "^2.14.1",
|
|
62
60
|
"sip.js": "^0.21.2",
|
|
@@ -97,9 +95,6 @@
|
|
|
97
95
|
"typescript": "^5.1.6"
|
|
98
96
|
},
|
|
99
97
|
"engines": {
|
|
100
|
-
"node": ">=
|
|
101
|
-
},
|
|
102
|
-
"react-native": {
|
|
103
|
-
"node-fetch/lib/index": false
|
|
98
|
+
"node": ">=18.0.0"
|
|
104
99
|
}
|
|
105
100
|
}
|