@wazo/sdk 0.40.9 → 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 +42 -41985
- 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/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 +2 -31
- 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/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 +2 -33
- 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 +0 -1
- package/src/utils/__tests__/api-requester.test.ts +0 -3
- package/src/utils/api-requester.ts +2 -33
|
@@ -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(() => { });
|
|
@@ -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,GAAG,CAAC,KAAK,GAAG;IAI5C,qBAAqB,CAAC,aAAa,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAMtD;IAID,MAAM;IAQN,OAAO;IAIP,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG;IAQhC,aAAa,CAAC,GAAG,EAAE,MAAM;I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.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,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACpC,oBAAoB,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;IACnD,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACrD,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC;AAKF,MAAM,CAAC,OAAO,OAAO,YAAY;IAC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M,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;
|
|
@@ -115,7 +86,7 @@ export default class ApiRequester {
|
|
|
115
86
|
const hasEmptyResponse = method === 'delete' || isHead;
|
|
116
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(() => { });
|
|
@@ -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,MAA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AAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;IAuBpE,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAqB7C,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAuBzC,cAAc;IAWd,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,SAAO,EAAE,OAAO,SAAQ;IASnE,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EAAE,KAAK,SAAI;IAuC5F,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAQpG,aAAa,CAAC,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":"
|
|
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,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACpC,oBAAoB,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;IACnD,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACrD,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC;AAKF,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B,MAAM,EAAE,MAAM,CAAC;IAEf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAE9C,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAEpC,KAAK,EAAE,MAAM,CAAC;IAEd,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAElC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAElC,oBAAoB,EAAE,CAAC,GAAG,IAAI,EAAE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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;
|
|
@@ -116,7 +85,7 @@ class ApiRequester {
|
|
|
116
85
|
const hasEmptyResponse = method === 'delete' || isHead;
|
|
117
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
|
}
|
|
@@ -4,13 +4,8 @@ import Line from '../Line';
|
|
|
4
4
|
|
|
5
5
|
describe('Session domain', () => {
|
|
6
6
|
it('can parse a plain session to domain', () => {
|
|
7
|
-
// Can't use `new Headers` because it's not supported on node 16.
|
|
8
|
-
const headers = {
|
|
9
|
-
get: () => 'new-stack',
|
|
10
|
-
};
|
|
11
|
-
|
|
12
7
|
const plain = {
|
|
13
|
-
_headers:
|
|
8
|
+
_headers: new Headers({ 'wazo-stack-host': 'new-stack' }),
|
|
14
9
|
data: {
|
|
15
10
|
token: 'b93ae6bd-08d7-4001-9e61-057e72bbc4b3',
|
|
16
11
|
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'],
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
/* eslint-disable prefer-destructuring, no-param-reassign, no-underscore-dangle */
|
|
4
4
|
import moment from 'moment';
|
|
5
|
-
import { realFetch } from '../utils/api-requester';
|
|
6
5
|
import isMobile from '../utils/isMobile';
|
|
7
6
|
import { obfuscateToken } from '../utils/string';
|
|
8
7
|
|
|
@@ -383,7 +382,7 @@ class IssueReporter {
|
|
|
383
382
|
const url = `http${isSecure ? 's' : ''}://${host}${isSecure ? '' : `:${port}`}/${tag}`;
|
|
384
383
|
const body = Array.isArray(payload) ? `[${payload.map(this._boundParseLoggerBody).join(',')}]` : this._parseLoggerBody(payload as Record<string, any>);
|
|
385
384
|
|
|
386
|
-
|
|
385
|
+
fetch(url, {
|
|
387
386
|
method: 'POST',
|
|
388
387
|
headers: {
|
|
389
388
|
Accept: 'application/json',
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
/* eslint-disable no-console */
|
|
6
6
|
import IssueReporter from '../IssueReporter';
|
|
7
|
-
import { realFetch } from '../../utils/api-requester';
|
|
8
7
|
|
|
9
8
|
jest.mock('../../utils/api-requester');
|
|
10
9
|
let oldLog: any;
|
|
@@ -25,9 +24,7 @@ describe('IssueReporter', () => {
|
|
|
25
24
|
});
|
|
26
25
|
beforeEach(() => {
|
|
27
26
|
jest.resetAllMocks();
|
|
28
|
-
|
|
29
|
-
catch: () => {},
|
|
30
|
-
}));
|
|
27
|
+
jest.spyOn(global, 'fetch');
|
|
31
28
|
});
|
|
32
29
|
afterAll(() => {
|
|
33
30
|
console.log = oldLog;
|
|
@@ -50,7 +47,7 @@ describe('IssueReporter', () => {
|
|
|
50
47
|
|
|
51
48
|
IssueReporter._sendToRemoteLogger('info');
|
|
52
49
|
|
|
53
|
-
expect(
|
|
50
|
+
expect(fetch).toHaveBeenCalled();
|
|
54
51
|
});
|
|
55
52
|
it('should send if verbosity is equal than required', () => {
|
|
56
53
|
// Same level
|
|
@@ -60,7 +57,7 @@ describe('IssueReporter', () => {
|
|
|
60
57
|
|
|
61
58
|
IssueReporter._sendToRemoteLogger('trace');
|
|
62
59
|
|
|
63
|
-
expect(
|
|
60
|
+
expect(fetch).toHaveBeenCalled();
|
|
64
61
|
});
|
|
65
62
|
it('should not send if verbosity is lower than required', () => {
|
|
66
63
|
// Lower level
|
|
@@ -70,7 +67,7 @@ describe('IssueReporter', () => {
|
|
|
70
67
|
|
|
71
68
|
IssueReporter._sendToRemoteLogger('trace');
|
|
72
69
|
|
|
73
|
-
expect(
|
|
70
|
+
expect(fetch).not.toHaveBeenCalled();
|
|
74
71
|
});
|
|
75
72
|
it('should log extra data', () => {
|
|
76
73
|
jest.spyOn(IssueReporter, '_sendToRemoteLogger').mockImplementation(() => {});
|
package/src/simple/Auth.ts
CHANGED
|
@@ -79,8 +79,6 @@ describe('Retrieving headers', () => {
|
|
|
79
79
|
});
|
|
80
80
|
describe('Calling fetch', () => {
|
|
81
81
|
it('should call fetch without body but query string in get method', async () => {
|
|
82
|
-
jest.mock('node-fetch/src/index', () => {});
|
|
83
|
-
|
|
84
82
|
global.fetch = jest.fn(() => Promise.resolve({
|
|
85
83
|
json: () => Promise.resolve({}),
|
|
86
84
|
headers: {
|
|
@@ -108,7 +106,6 @@ describe('Calling fetch', () => {
|
|
|
108
106
|
|
|
109
107
|
describe('With a refresh token', () => {
|
|
110
108
|
it('should retry the call with a new token', async () => {
|
|
111
|
-
jest.mock('node-fetch/src/index', () => {});
|
|
112
109
|
let calls = 0;
|
|
113
110
|
|
|
114
111
|
global.fetch = jest.fn(() => {
|
|
@@ -1,12 +1,7 @@
|
|
|
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
|
|
|
7
3
|
import BadResponse from '../domain/BadResponse';
|
|
8
4
|
import ServerError from '../domain/ServerError';
|
|
9
|
-
import isMobile from './isMobile';
|
|
10
5
|
import type { Token } from '../domain/types';
|
|
11
6
|
import IssueReporter from '../service/IssueReporter';
|
|
12
7
|
|
|
@@ -23,32 +18,6 @@ const methods = ['head', 'get', 'post', 'put', 'delete', 'options'];
|
|
|
23
18
|
const logger = IssueReporter ? IssueReporter.loggerFor('api') : console;
|
|
24
19
|
const REQUEST_TIMEOUT_MS = 300 * 1000; // 300s like the Chrome engine default value.
|
|
25
20
|
|
|
26
|
-
// Use a function here to be able to mock it in tests
|
|
27
|
-
export const realFetch = () => {
|
|
28
|
-
if (typeof fetch !== 'undefined') {
|
|
29
|
-
return fetch;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (typeof document !== 'undefined' && window.fetch) {
|
|
33
|
-
// Browser
|
|
34
|
-
return window.fetch;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (isMobile()) {
|
|
38
|
-
// React native
|
|
39
|
-
return fetch;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// nodejs
|
|
43
|
-
// this package is disabled for react-native in package.json because it requires nodejs modules
|
|
44
|
-
// Used to trick the optimizer to avoid requiring `node-fetch/lib/index` directly
|
|
45
|
-
// It causes to require it on browsers when delivered by a nodejs engine (cf: vitejs).
|
|
46
|
-
try {
|
|
47
|
-
return require(Math.random() >= 0 ? 'node-fetch/lib/index' : '');
|
|
48
|
-
} catch (e: any) {
|
|
49
|
-
return fetch;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
21
|
export default class ApiRequester {
|
|
53
22
|
server: string;
|
|
54
23
|
|
|
@@ -169,7 +138,7 @@ export default class ApiRequester {
|
|
|
169
138
|
const hasEmptyResponse = method === 'delete' || isHead;
|
|
170
139
|
const newParse = hasEmptyResponse && parse === ApiRequester.defaultParser ? ApiRequester.successResponseParser : parse;
|
|
171
140
|
const fetchOptions = { ...(this.fetchOptions || {}) };
|
|
172
|
-
const controller =
|
|
141
|
+
const controller = new AbortController();
|
|
173
142
|
const extraHeaders = fetchOptions.headers || {};
|
|
174
143
|
delete fetchOptions.headers;
|
|
175
144
|
const options = {
|
|
@@ -192,7 +161,7 @@ export default class ApiRequester {
|
|
|
192
161
|
}
|
|
193
162
|
|
|
194
163
|
const start = new Date();
|
|
195
|
-
const requestPromise =
|
|
164
|
+
const requestPromise = fetch(url, options).then((response: any) => {
|
|
196
165
|
const contentType = response.headers.get('content-type') || '';
|
|
197
166
|
const isJson = contentType.indexOf('application/json') !== -1;
|
|
198
167
|
IssueReporter.logRequest(url, options, response, start);
|