@wazo/sdk 0.43.13 → 0.43.15
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 +84 -57
- package/dist/wazo-sdk.js +2 -2
- package/esm/api-client.js +7 -132
- package/esm/base-api-client.js +125 -0
- package/esm/constants.js +11 -0
- package/esm/domain/CallLog.js +4 -1
- package/esm/domain/__tests__/CallLog.test.js +11 -0
- package/esm/index.js +1 -0
- package/esm/service/__tests__/getApiclient.test.js +37 -0
- package/esm/service/getApiClient.js +8 -6
- package/esm/types/api-client.d.ts +3 -41
- package/esm/types/api-client.d.ts.map +1 -1
- package/esm/types/base-api-client.d.ts +43 -0
- package/esm/types/base-api-client.d.ts.map +1 -0
- package/esm/types/constants.d.ts +12 -0
- package/esm/types/constants.d.ts.map +1 -0
- package/esm/types/domain/CallLog.d.ts.map +1 -1
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.d.ts.map +1 -1
- package/esm/types/service/__tests__/getApiclient.test.d.ts +2 -0
- package/esm/types/service/__tests__/getApiclient.test.d.ts.map +1 -0
- package/esm/types/service/getApiClient.d.ts +5 -2
- package/esm/types/service/getApiClient.d.ts.map +1 -1
- package/esm/types/simple/index.d.ts +1 -1
- package/esm/types/utils/api-requester.d.ts.map +1 -1
- package/esm/utils/api-requester.js +0 -1
- package/lib/api-client.js +17 -144
- package/lib/base-api-client.js +133 -0
- package/lib/constants.js +14 -0
- package/lib/domain/CallLog.js +4 -1
- package/lib/domain/__tests__/CallLog.test.js +3 -0
- package/lib/index.js +3 -1
- package/lib/service/__tests__/getApiclient.test.js +42 -0
- package/lib/service/getApiClient.js +8 -6
- package/lib/types/api-client.d.ts +3 -41
- package/lib/types/api-client.d.ts.map +1 -1
- package/lib/types/base-api-client.d.ts +43 -0
- package/lib/types/base-api-client.d.ts.map +1 -0
- package/lib/types/constants.d.ts +12 -0
- package/lib/types/constants.d.ts.map +1 -0
- package/lib/types/domain/CallLog.d.ts.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/service/__tests__/getApiclient.test.d.ts +2 -0
- package/lib/types/service/__tests__/getApiclient.test.d.ts.map +1 -0
- package/lib/types/service/getApiClient.d.ts +5 -2
- package/lib/types/service/getApiClient.d.ts.map +1 -1
- package/lib/types/simple/index.d.ts +1 -1
- package/lib/types/utils/api-requester.d.ts.map +1 -1
- package/lib/utils/api-requester.js +0 -1
- package/package.json +1 -1
- package/src/api-client.ts +20 -188
- package/src/base-api-client.ts +184 -0
- package/src/constants.ts +11 -0
- package/src/domain/CallLog.ts +4 -1
- package/src/domain/__tests__/CallLog.test.ts +12 -0
- package/src/index.ts +1 -0
- package/src/service/__tests__/getApiclient.test.ts +46 -0
- package/src/service/getApiClient.ts +15 -8
- package/src/utils/api-requester.ts +0 -1
package/lib/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,gBAAgB,CAAC;AAElC,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MA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YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACxJ,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAC3F,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAE/B,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getApiclient.test.d.ts","sourceRoot":"","sources":["../../../../src/service/__tests__/getApiclient.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import WazoApiClient from '../api-client';
|
|
2
|
+
import BaseApiClient from '../base-api-client';
|
|
2
3
|
export declare const setApiClientId: (clientId: string, forServer?: string | null | undefined) => void;
|
|
3
4
|
export declare const setCurrentServer: (newServer: string) => void;
|
|
4
5
|
export declare const setApiToken: (newToken: string | null | undefined, forServer?: string | null | undefined) => void;
|
|
@@ -13,6 +14,8 @@ export declare const setIsMobile: (isMobile: boolean, forServer?: string | null
|
|
|
13
14
|
export declare const setRequestTimeout: (requestTimeout: number, forServer?: string | null | undefined) => void;
|
|
14
15
|
export declare const setFetchOptions: (fetchOptions: Record<string, any>, forServer?: string | null | undefined) => void;
|
|
15
16
|
export declare const getFetchOptions: (forServer?: string | null | undefined) => any;
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
type ForServer = string | null;
|
|
18
|
+
type TClient = new (...args: any[]) => BaseApiClient;
|
|
19
|
+
declare const getApiClient: <T extends BaseApiClient = WazoApiClient>(forServer?: ForServer, Client?: TClient) => T;
|
|
20
|
+
export default getApiClient;
|
|
18
21
|
//# sourceMappingURL=getApiClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getApiClient.d.ts","sourceRoot":"","sources":["../../../src/service/getApiClient.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"getApiClient.d.ts","sourceRoot":"","sources":["../../../src/service/getApiClient.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,eAAe,CAAC;AAC1C,OAAO,aAAa,MAAM,oBAAoB,CAAC;AAkB/C,eAAO,MAAM,cAAc,aAAc,MAAM,cAAa,MAAM,GAAG,IAAI,GAAG,SAAS,SAEpF,CAAC;AACF,eAAO,MAAM,gBAAgB,cAAe,MAAM,SAEjD,CAAC;AACF,eAAO,MAAM,WAAW,aAAc,MAAM,GAAG,IAAI,GAAG,SAAS,cAAa,MAAM,GAAG,IAAI,GAAG,SAAS,SAEpG,CAAC;AACF,eAAO,MAAM,eAAe,oBAAqB,MAAM,GAAG,IAAI,GAAG,SAAS,cAAa,MAAM,GAAG,IAAI,GAAG,SAAS,SAE/G,CAAC;AACF,eAAO,MAAM,kBAAkB,oBAAqB,MAAM,GAAG,IAAI,GAAG,SAAS,cAAa,MAAM,GAAG,IAAI,GAAG,SAAS,SAGlH,CAAC;AACF,eA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45
|
Configuration: import("./Configuration").Configuration;
|
|
46
46
|
Directory: import("./Directory").Directory;
|
|
47
|
-
getApiClient: (forServer?: string | null | undefined) => import("..").
|
|
47
|
+
getApiClient: <T extends import("..").BaseApiClient = import("..").WazoApiClient>(forServer?: (string | null) | undefined, Client?: new (...args: any[]) => import("..").BaseApiClient) => T;
|
|
48
48
|
IssueReporter: {
|
|
49
49
|
TRACE: string;
|
|
50
50
|
INFO: string;
|
|
@@ -1 +1 @@
|
|
|
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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7 +40,6 @@ class ApiRequester {
|
|
|
40
40
|
}
|
|
41
41
|
return js_base64_1.Base64.encode(str);
|
|
42
42
|
}
|
|
43
|
-
// @see https://github.com/facebook/flow/issues/183#issuecomment-358607052
|
|
44
43
|
constructor({ server, refreshTokenCallback, clientId, agent = null, token = null, fetchOptions, requestTimeout = REQUEST_TIMEOUT_MS, }) {
|
|
45
44
|
this.server = server;
|
|
46
45
|
this.agent = agent;
|
package/package.json
CHANGED
package/src/api-client.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import authMethods, { AuthD } from './api/auth';
|
|
2
1
|
import applicationMethods, { ApplicationD } from './api/application';
|
|
3
2
|
import confdMethods, { ConfD } from './api/confd';
|
|
4
3
|
import ctidNgMethods, { CtidNg } from './api/ctid-ng';
|
|
@@ -9,35 +8,21 @@ import calldMethods, { CallD } from './api/calld';
|
|
|
9
8
|
import agentdMethods, { AgentD } from './api/agentd';
|
|
10
9
|
import webhookdMethods, { WebhookD } from './api/webhookd';
|
|
11
10
|
import amidMethods, { AmiD } from './api/amid';
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const CTIDNG_VERSION = '1.0';
|
|
28
|
-
const DIRD_VERSION = '0.1';
|
|
29
|
-
const CALL_LOGD_VERSION = '1.0';
|
|
30
|
-
const CHATD_VERSION = '1.0';
|
|
31
|
-
const CALLD_VERSION = '1.0';
|
|
32
|
-
const AGENTD_VERSION = '1.0';
|
|
33
|
-
const WEBHOOKD_VERSION = '1.0';
|
|
34
|
-
const AMID_VERSION = '1.0';
|
|
35
|
-
const logger = IssueReporter ? IssueReporter.loggerFor('api') : console;
|
|
36
|
-
export default class ApiClient {
|
|
37
|
-
client: ApiRequester;
|
|
38
|
-
|
|
39
|
-
auth: AuthD;
|
|
40
|
-
|
|
11
|
+
import {
|
|
12
|
+
APPLICATION_VERSION,
|
|
13
|
+
CONFD_VERSION,
|
|
14
|
+
CTIDNG_VERSION,
|
|
15
|
+
DIRD_VERSION,
|
|
16
|
+
CALL_LOGD_VERSION,
|
|
17
|
+
CHATD_VERSION,
|
|
18
|
+
CALLD_VERSION,
|
|
19
|
+
AGENTD_VERSION,
|
|
20
|
+
WEBHOOKD_VERSION,
|
|
21
|
+
AMID_VERSION,
|
|
22
|
+
} from './constants';
|
|
23
|
+
import BaseApiClient, { ConstructorParams } from './base-api-client';
|
|
24
|
+
|
|
25
|
+
export default class ApiClient extends BaseApiClient {
|
|
41
26
|
application: ApplicationD;
|
|
42
27
|
|
|
43
28
|
confd: ConfD;
|
|
@@ -58,45 +43,14 @@ export default class ApiClient {
|
|
|
58
43
|
|
|
59
44
|
amid: AmiD;
|
|
60
45
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
onRefreshTokenError: ((...args: Array<any>) => any) | null | undefined;
|
|
66
|
-
|
|
67
|
-
refreshExpiration: number | null | undefined;
|
|
68
|
-
|
|
69
|
-
refreshBackend: string | null | undefined;
|
|
70
|
-
|
|
71
|
-
refreshTenantId: string | null | undefined;
|
|
72
|
-
|
|
73
|
-
refreshDomainName: string | null | undefined;
|
|
74
|
-
|
|
75
|
-
isMobile: boolean;
|
|
76
|
-
|
|
77
|
-
fetchOptions: Record<string, any>;
|
|
78
|
-
|
|
79
|
-
// @see https://github.com/facebook/flow/issues/183#issuecomment-358607052
|
|
80
|
-
constructor({
|
|
81
|
-
server,
|
|
82
|
-
agent = null,
|
|
83
|
-
refreshToken,
|
|
84
|
-
clientId,
|
|
85
|
-
isMobile = false,
|
|
86
|
-
fetchOptions,
|
|
87
|
-
}: ConstructorParams) {
|
|
88
|
-
this.updateParameters({
|
|
89
|
-
server,
|
|
90
|
-
agent,
|
|
91
|
-
clientId,
|
|
92
|
-
fetchOptions,
|
|
93
|
-
});
|
|
94
|
-
this.refreshToken = refreshToken;
|
|
95
|
-
this.isMobile = isMobile || false;
|
|
46
|
+
constructor(args: ConstructorParams) {
|
|
47
|
+
super(args);
|
|
48
|
+
this.initializeEndpoints(); // Reinitialize sdk endpoints
|
|
96
49
|
}
|
|
97
50
|
|
|
98
51
|
initializeEndpoints(): void {
|
|
99
|
-
|
|
52
|
+
super.initializeEndpoints();
|
|
53
|
+
|
|
100
54
|
this.application = applicationMethods(this.client, `calld/${APPLICATION_VERSION}/applications`);
|
|
101
55
|
this.confd = confdMethods(this.client, `confd/${CONFD_VERSION}`);
|
|
102
56
|
this.ctidNg = ctidNgMethods(this.client, `ctid-ng/${CTIDNG_VERSION}`);
|
|
@@ -108,126 +62,4 @@ export default class ApiClient {
|
|
|
108
62
|
this.webhookd = webhookdMethods(this.client, `webhookd/${WEBHOOKD_VERSION}`);
|
|
109
63
|
this.amid = amidMethods(this.client, `amid/${AMID_VERSION}`);
|
|
110
64
|
}
|
|
111
|
-
|
|
112
|
-
updateParameters({
|
|
113
|
-
server,
|
|
114
|
-
agent,
|
|
115
|
-
clientId,
|
|
116
|
-
fetchOptions,
|
|
117
|
-
}: Record<string, any>) {
|
|
118
|
-
const refreshTokenCallback = this.refreshTokenCallback.bind(this);
|
|
119
|
-
this.client = new ApiRequester({
|
|
120
|
-
server,
|
|
121
|
-
agent,
|
|
122
|
-
refreshTokenCallback,
|
|
123
|
-
clientId,
|
|
124
|
-
fetchOptions,
|
|
125
|
-
});
|
|
126
|
-
this.initializeEndpoints();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async forceRefreshToken(): Promise<string | null> {
|
|
130
|
-
logger.info('forcing refresh token, calling callback');
|
|
131
|
-
return this.refreshTokenCallback();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
async refreshTokenCallback(): Promise<string | null> {
|
|
135
|
-
logger.info('refresh token callback called', {
|
|
136
|
-
refreshToken: obfuscateToken(this.refreshToken),
|
|
137
|
-
refreshBackend: this.refreshBackend,
|
|
138
|
-
refreshTenantId: this.refreshTenantId,
|
|
139
|
-
refreshDomainName: this.refreshDomainName,
|
|
140
|
-
refreshExpiration: this.refreshExpiration,
|
|
141
|
-
isMobile: this.isMobile,
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
if (!this.refreshToken) {
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
try {
|
|
149
|
-
const session = await this.auth.refreshToken(this.refreshToken, this.refreshBackend as string, this.refreshExpiration as number, this.isMobile, this.refreshTenantId as string, this.refreshDomainName as string);
|
|
150
|
-
if (!session) {
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
logger.info('token refreshed', {
|
|
155
|
-
token: obfuscateToken(session.token),
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
if (this.onRefreshToken) {
|
|
159
|
-
this.onRefreshToken(session.token, session);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
this.setToken(session.token);
|
|
163
|
-
return session.token;
|
|
164
|
-
} catch (error: any) {
|
|
165
|
-
logger.error('token refresh, error', error);
|
|
166
|
-
|
|
167
|
-
if (this.onRefreshTokenError) {
|
|
168
|
-
this.onRefreshTokenError(error);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
setToken(token: string) {
|
|
176
|
-
this.client.setToken(token);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
setTenant(tenant: string) {
|
|
180
|
-
this.client.setTenant(tenant);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
setRefreshToken(refreshToken: string | null | undefined) {
|
|
184
|
-
this.refreshToken = refreshToken;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
setRequestTimeout(requestTimeout: number) {
|
|
188
|
-
this.client.setRequestTimeout(requestTimeout);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
setClientId(clientId: string | null | undefined) {
|
|
192
|
-
this.client.clientId = clientId;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
setOnRefreshToken(onRefreshToken: (...args: Array<any>) => any) {
|
|
196
|
-
this.onRefreshToken = onRefreshToken;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
setOnRefreshTokenError(callback: (...args: Array<any>) => any) {
|
|
200
|
-
this.onRefreshTokenError = callback;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
setRefreshExpiration(refreshExpiration: number) {
|
|
204
|
-
this.refreshExpiration = refreshExpiration;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
setRefreshBackend(refreshBackend: string) {
|
|
208
|
-
this.refreshBackend = refreshBackend;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
setRefreshTenantId(tenantId: string | null | undefined) {
|
|
212
|
-
console.warn('Use of `setRefreshTenantId` is deprecated, use `setRefreshDomainName` instead');
|
|
213
|
-
this.refreshTenantId = tenantId;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
setRefreshDomainName(domainName: string | null | undefined) {
|
|
217
|
-
this.refreshDomainName = domainName;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
setIsMobile(isMobile: boolean) {
|
|
221
|
-
this.isMobile = isMobile;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
setFetchOptions(fetchOptions: Record<string, any>) {
|
|
225
|
-
this.fetchOptions = fetchOptions;
|
|
226
|
-
this.client.setFetchOptions(fetchOptions);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
disableErrorLogging() {
|
|
230
|
-
this.client.disableErrorLogging();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
65
|
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import authMethods, { AuthD } from './api/auth';
|
|
2
|
+
import ApiRequester from './utils/api-requester';
|
|
3
|
+
import IssueReporter from './service/IssueReporter';
|
|
4
|
+
import { obfuscateToken } from './utils/string';
|
|
5
|
+
import { AUTH_VERSION } from './constants';
|
|
6
|
+
|
|
7
|
+
export type ConstructorParams = {
|
|
8
|
+
server: string;
|
|
9
|
+
agent?: Record<string, any> | null | undefined;
|
|
10
|
+
clientId?: string;
|
|
11
|
+
refreshToken?: string | null | undefined;
|
|
12
|
+
isMobile?: boolean | null | undefined;
|
|
13
|
+
fetchOptions?: Record<string, any>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const logger = IssueReporter ? IssueReporter.loggerFor('api') : console;
|
|
17
|
+
|
|
18
|
+
export default class BaseApiClient {
|
|
19
|
+
client: ApiRequester;
|
|
20
|
+
|
|
21
|
+
auth: AuthD;
|
|
22
|
+
|
|
23
|
+
refreshToken: string | null | undefined;
|
|
24
|
+
|
|
25
|
+
onRefreshToken: ((...args: Array<any>) => any) | null | undefined;
|
|
26
|
+
|
|
27
|
+
onRefreshTokenError: ((...args: Array<any>) => any) | null | undefined;
|
|
28
|
+
|
|
29
|
+
refreshExpiration: number | null | undefined;
|
|
30
|
+
|
|
31
|
+
refreshBackend: string | null | undefined;
|
|
32
|
+
|
|
33
|
+
refreshTenantId: string | null | undefined;
|
|
34
|
+
|
|
35
|
+
refreshDomainName: string | null | undefined;
|
|
36
|
+
|
|
37
|
+
isMobile: boolean;
|
|
38
|
+
|
|
39
|
+
fetchOptions: Record<string, any>;
|
|
40
|
+
|
|
41
|
+
constructor({
|
|
42
|
+
server,
|
|
43
|
+
agent = null,
|
|
44
|
+
refreshToken,
|
|
45
|
+
clientId,
|
|
46
|
+
isMobile = false,
|
|
47
|
+
fetchOptions,
|
|
48
|
+
}: ConstructorParams) {
|
|
49
|
+
this.updateParameters({
|
|
50
|
+
server,
|
|
51
|
+
agent,
|
|
52
|
+
clientId,
|
|
53
|
+
fetchOptions,
|
|
54
|
+
});
|
|
55
|
+
this.refreshToken = refreshToken;
|
|
56
|
+
this.isMobile = isMobile || false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
initializeEndpoints(): void {
|
|
60
|
+
this.auth = authMethods(this.client, `auth/${AUTH_VERSION}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
updateParameters({
|
|
64
|
+
server,
|
|
65
|
+
agent,
|
|
66
|
+
clientId,
|
|
67
|
+
fetchOptions,
|
|
68
|
+
}: Record<string, any>) {
|
|
69
|
+
const refreshTokenCallback = this.refreshTokenCallback.bind(this);
|
|
70
|
+
this.client = new ApiRequester({
|
|
71
|
+
server,
|
|
72
|
+
agent,
|
|
73
|
+
refreshTokenCallback,
|
|
74
|
+
clientId,
|
|
75
|
+
fetchOptions,
|
|
76
|
+
});
|
|
77
|
+
this.initializeEndpoints();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async forceRefreshToken(): Promise<string | null> {
|
|
81
|
+
logger.info('forcing refresh token, calling callback');
|
|
82
|
+
return this.refreshTokenCallback();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async refreshTokenCallback(): Promise<string | null> {
|
|
86
|
+
logger.info('refresh token callback called', {
|
|
87
|
+
refreshToken: obfuscateToken(this.refreshToken),
|
|
88
|
+
refreshBackend: this.refreshBackend,
|
|
89
|
+
refreshTenantId: this.refreshTenantId,
|
|
90
|
+
refreshDomainName: this.refreshDomainName,
|
|
91
|
+
refreshExpiration: this.refreshExpiration,
|
|
92
|
+
isMobile: this.isMobile,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
if (!this.refreshToken) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const session = await this.auth.refreshToken(this.refreshToken, this.refreshBackend as string, this.refreshExpiration as number, this.isMobile, this.refreshTenantId as string, this.refreshDomainName as string);
|
|
101
|
+
if (!session) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
logger.info('token refreshed', {
|
|
106
|
+
token: obfuscateToken(session.token),
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
if (this.onRefreshToken) {
|
|
110
|
+
this.onRefreshToken(session.token, session);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
this.setToken(session.token);
|
|
114
|
+
return session.token;
|
|
115
|
+
} catch (error: any) {
|
|
116
|
+
logger.error('token refresh, error', error);
|
|
117
|
+
|
|
118
|
+
if (this.onRefreshTokenError) {
|
|
119
|
+
this.onRefreshTokenError(error);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
setToken(token: string) {
|
|
127
|
+
this.client.setToken(token);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
setTenant(tenant: string) {
|
|
131
|
+
this.client.setTenant(tenant);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
setRefreshToken(refreshToken: string | null | undefined) {
|
|
135
|
+
this.refreshToken = refreshToken;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
setRequestTimeout(requestTimeout: number) {
|
|
139
|
+
this.client.setRequestTimeout(requestTimeout);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
setClientId(clientId: string | null | undefined) {
|
|
143
|
+
this.client.clientId = clientId;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
setOnRefreshToken(onRefreshToken: (...args: Array<any>) => any) {
|
|
147
|
+
this.onRefreshToken = onRefreshToken;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
setOnRefreshTokenError(callback: (...args: Array<any>) => any) {
|
|
151
|
+
this.onRefreshTokenError = callback;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
setRefreshExpiration(refreshExpiration: number) {
|
|
155
|
+
this.refreshExpiration = refreshExpiration;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
setRefreshBackend(refreshBackend: string) {
|
|
159
|
+
this.refreshBackend = refreshBackend;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
setRefreshTenantId(tenantId: string | null | undefined) {
|
|
163
|
+
console.warn('Use of `setRefreshTenantId` is deprecated, use `setRefreshDomainName` instead');
|
|
164
|
+
this.refreshTenantId = tenantId;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
setRefreshDomainName(domainName: string | null | undefined) {
|
|
168
|
+
this.refreshDomainName = domainName;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
setIsMobile(isMobile: boolean) {
|
|
172
|
+
this.isMobile = isMobile;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
setFetchOptions(fetchOptions: Record<string, any>) {
|
|
176
|
+
this.fetchOptions = fetchOptions;
|
|
177
|
+
this.client.setFetchOptions(fetchOptions);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
disableErrorLogging() {
|
|
181
|
+
this.client.disableErrorLogging();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const AUTH_VERSION = '0.1';
|
|
2
|
+
export const APPLICATION_VERSION = '1.0';
|
|
3
|
+
export const CONFD_VERSION = '1.1';
|
|
4
|
+
export const CTIDNG_VERSION = '1.0';
|
|
5
|
+
export const DIRD_VERSION = '0.1';
|
|
6
|
+
export const CALL_LOGD_VERSION = '1.0';
|
|
7
|
+
export const CHATD_VERSION = '1.0';
|
|
8
|
+
export const CALLD_VERSION = '1.0';
|
|
9
|
+
export const AGENTD_VERSION = '1.0';
|
|
10
|
+
export const WEBHOOKD_VERSION = '1.0';
|
|
11
|
+
export const AMID_VERSION = '1.0';
|
package/src/domain/CallLog.ts
CHANGED
|
@@ -216,7 +216,10 @@ export default class CallLog {
|
|
|
216
216
|
|
|
217
217
|
isIncoming(session: Session): boolean {
|
|
218
218
|
if (this.callDirection === 'internal') {
|
|
219
|
-
return session.hasExtension(this.destination.plainExtension)
|
|
219
|
+
return session.hasExtension(this.destination.plainExtension)
|
|
220
|
+
|| session.hasExtension(this.requested.extension)
|
|
221
|
+
|| session.uuid === this.destination.uuid
|
|
222
|
+
|| session.uuid === this.requested.uuid;
|
|
220
223
|
}
|
|
221
224
|
|
|
222
225
|
return this.callDirection === 'inbound';
|
|
@@ -127,6 +127,18 @@ describe('CallLog Domain', () => {
|
|
|
127
127
|
});
|
|
128
128
|
expect(destinationCallLog.isIncomingAndForwarded(BOB_SESSION)).toBe(true);
|
|
129
129
|
|
|
130
|
+
// When destination is set to the same user with a changed extension
|
|
131
|
+
const destinationExtensionChangedCallLog = CallLog.parse({
|
|
132
|
+
...CALL_LOG_RESPONSE,
|
|
133
|
+
destination_extension: `${CALL_LOG_RESPONSE.requested_extension}9`,
|
|
134
|
+
destination_name: CALL_LOG_RESPONSE.requested_name,
|
|
135
|
+
destination_user_uuid: CALL_LOG_RESPONSE.requested_user_uuid,
|
|
136
|
+
requested_extension: `${CALL_LOG_RESPONSE.destination_extension}9`,
|
|
137
|
+
requested_name: CALL_LOG_RESPONSE.destination_name,
|
|
138
|
+
requested_user_uuid: CALL_LOG_RESPONSE.destination_user_uuid,
|
|
139
|
+
});
|
|
140
|
+
expect(destinationExtensionChangedCallLog.isIncomingAndForwarded(BOB_SESSION)).toBe(true);
|
|
141
|
+
|
|
130
142
|
// When call direction is inbound
|
|
131
143
|
const inboundCallLog = CallLog.parse({ ...CALL_LOG_RESPONSE, call_direction: 'inbound' });
|
|
132
144
|
expect(inboundCallLog.isIncomingAndForwarded(BOB_SESSION)).toBe(true);
|
package/src/index.ts
CHANGED
|
@@ -48,6 +48,7 @@ export { default as AdHocAPIConference } from './domain/AdHocAPIConference';
|
|
|
48
48
|
export { default as WebSocketClient, SOCKET_EVENTS } from './websocket-client';
|
|
49
49
|
export { default as WebRTCClient } from './web-rtc-client';
|
|
50
50
|
export { default as WazoApiClient } from './api-client';
|
|
51
|
+
export { default as BaseApiClient } from './base-api-client';
|
|
51
52
|
export { default as Agent, AgentResponse, AgentArguments } from './domain/Agent';
|
|
52
53
|
export { default as ExternalApp } from './domain/ExternalApp';
|
|
53
54
|
export { default as SessionDescriptionHandler } from './lib/WazoSessionDescriptionHandler';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ApiRequester, BaseApiClient, WazoApiClient } from '../..';
|
|
2
|
+
import { ConstructorParams } from '../../base-api-client';
|
|
3
|
+
import getApiClient from '../getApiClient';
|
|
4
|
+
|
|
5
|
+
describe('getApiClient', () => {
|
|
6
|
+
it('should return WazoApiClient by default', () => {
|
|
7
|
+
const globalClient = getApiClient();
|
|
8
|
+
expect(globalClient).toBeInstanceOf(WazoApiClient);
|
|
9
|
+
expect(globalClient.amid).toBeDefined();
|
|
10
|
+
|
|
11
|
+
const serverClient = getApiClient('wazo-platorm.org');
|
|
12
|
+
expect(serverClient).toBeInstanceOf(WazoApiClient);
|
|
13
|
+
expect(globalClient.amid).toBeDefined();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it.only('should return custom ApiClient', () => {
|
|
17
|
+
const fooMethods = (client: ApiRequester, baseUrl: string) => ({
|
|
18
|
+
test: (myString: string) => ({ client, myString, baseUrl }),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
class FooApiClient extends BaseApiClient {
|
|
22
|
+
public foo: ReturnType<typeof fooMethods>;
|
|
23
|
+
|
|
24
|
+
constructor(args: ConstructorParams) {
|
|
25
|
+
super(args);
|
|
26
|
+
this.initializeEndpoints();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
initializeEndpoints() {
|
|
30
|
+
super.initializeEndpoints();
|
|
31
|
+
this.foo = fooMethods(this.client, 'foo/0.1');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const extendedClient = getApiClient<FooApiClient>('foo.wazo-platform.org', FooApiClient);
|
|
36
|
+
expect(extendedClient).toBeInstanceOf(FooApiClient);
|
|
37
|
+
expect(extendedClient.auth).toBeDefined();
|
|
38
|
+
// @ts-ignore: we know amid is undefined, it's important to test it
|
|
39
|
+
expect(extendedClient.amid).not.toBeDefined();
|
|
40
|
+
|
|
41
|
+
const fooTest = extendedClient.foo?.test('foo');
|
|
42
|
+
expect(fooTest.myString).toBe('foo');
|
|
43
|
+
expect(fooTest.client).toBeInstanceOf(ApiRequester);
|
|
44
|
+
expect(fooTest.baseUrl).toBe('foo/0.1');
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable dot-notation */
|
|
2
2
|
import WazoApiClient from '../api-client';
|
|
3
|
+
import BaseApiClient from '../base-api-client';
|
|
3
4
|
|
|
4
5
|
// Can't use node cache mechanism here because when requiring lib/CallApi.js
|
|
5
6
|
// this file will be merge with CallApi.js and the cache will be lost.
|
|
@@ -60,7 +61,7 @@ export const setFetchOptions = (fetchOptions: Record<string, any>, forServer: st
|
|
|
60
61
|
export const getFetchOptions = (forServer: string | null | undefined = null) =>
|
|
61
62
|
(forServer ? global.wazoFetchOptions[forServer] : global.wazoFetchOptions.null) || global.wazoFetchOptions.null;
|
|
62
63
|
|
|
63
|
-
const fillClient = (apiClient:
|
|
64
|
+
const fillClient = (apiClient: InstanceType<typeof BaseApiClient>) => {
|
|
64
65
|
const {
|
|
65
66
|
server,
|
|
66
67
|
token,
|
|
@@ -88,19 +89,25 @@ const fillClient = (apiClient: WazoApiClient) => {
|
|
|
88
89
|
if (requestTimeout) {
|
|
89
90
|
apiClient.setRequestTimeout(requestTimeout);
|
|
90
91
|
}
|
|
91
|
-
|
|
92
|
-
return apiClient;
|
|
93
92
|
};
|
|
94
93
|
|
|
95
|
-
|
|
94
|
+
type ForServer = string | null;
|
|
95
|
+
type TClient = new (...args: any[]) => BaseApiClient;
|
|
96
|
+
|
|
97
|
+
const getApiClient = <T extends BaseApiClient = WazoApiClient>(forServer?: ForServer, Client: TClient = WazoApiClient): T => {
|
|
96
98
|
const server: string = forServer || global.wazoCurrentServer || '';
|
|
97
99
|
|
|
98
100
|
if (server in global.wazoClients) {
|
|
99
|
-
|
|
101
|
+
fillClient(global.wazoClients[server]);
|
|
102
|
+
return global.wazoClients[server];
|
|
100
103
|
}
|
|
101
104
|
|
|
102
|
-
global.wazoClients[server] = new
|
|
105
|
+
global.wazoClients[server] = new Client({
|
|
103
106
|
server,
|
|
104
107
|
});
|
|
105
|
-
|
|
106
|
-
|
|
108
|
+
|
|
109
|
+
fillClient(global.wazoClients[server]);
|
|
110
|
+
return global.wazoClients[server];
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export default getApiClient;
|