@wazo/sdk 0.40.3 → 0.40.5

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.
Files changed (88) hide show
  1. package/dist/wazo-sdk.js +2 -2
  2. package/esm/api/calld.js +1 -1
  3. package/esm/api/dird.js +9 -9
  4. package/esm/domain/Phone/CTIPhone.js +1 -1
  5. package/esm/domain/Phone/WebRTCPhone.js +3 -3
  6. package/esm/domain/Session.js +2 -1
  7. package/esm/index.js +1 -0
  8. package/esm/simple/Auth.js +1 -0
  9. package/esm/simple/Directory.js +2 -2
  10. package/esm/simple/Phone.js +1 -1
  11. package/esm/types/api/auth.d.ts +8 -8
  12. package/esm/types/api/auth.d.ts.map +1 -1
  13. package/esm/types/api/calld.d.ts +4 -4
  14. package/esm/types/api/calld.d.ts.map +1 -1
  15. package/esm/types/api/ctid-ng.d.ts +5 -5
  16. package/esm/types/api/ctid-ng.d.ts.map +1 -1
  17. package/esm/types/api/dird.d.ts +7 -21
  18. package/esm/types/api/dird.d.ts.map +1 -1
  19. package/esm/types/domain/ExternalApp.d.ts +1 -1
  20. package/esm/types/domain/ExternalApp.d.ts.map +1 -1
  21. package/esm/types/domain/Phone/CTIPhone.d.ts +2 -1
  22. package/esm/types/domain/Phone/CTIPhone.d.ts.map +1 -1
  23. package/esm/types/domain/Phone/Phone.d.ts +4 -3
  24. package/esm/types/domain/Phone/Phone.d.ts.map +1 -1
  25. package/esm/types/domain/Phone/WebRTCPhone.d.ts +21 -21
  26. package/esm/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
  27. package/esm/types/domain/Session.d.ts.map +1 -1
  28. package/esm/types/domain/types.d.ts +12 -9
  29. package/esm/types/domain/types.d.ts.map +1 -1
  30. package/esm/types/index.d.ts +1 -0
  31. package/esm/types/index.d.ts.map +1 -1
  32. package/esm/types/simple/Auth.d.ts.map +1 -1
  33. package/esm/types/web-rtc-client.d.ts.map +1 -1
  34. package/esm/types/websocket-client.d.ts.map +1 -1
  35. package/esm/web-rtc-client.js +3 -1
  36. package/esm/websocket-client.js +4 -0
  37. package/lib/api/calld.js +1 -1
  38. package/lib/api/dird.js +24 -15
  39. package/lib/domain/Phone/CTIPhone.js +1 -1
  40. package/lib/domain/Phone/WebRTCPhone.js +3 -3
  41. package/lib/domain/Session.js +2 -1
  42. package/lib/index.js +3 -1
  43. package/lib/simple/Auth.js +1 -0
  44. package/lib/simple/Directory.js +2 -2
  45. package/lib/simple/Phone.js +1 -1
  46. package/lib/types/api/auth.d.ts +8 -8
  47. package/lib/types/api/auth.d.ts.map +1 -1
  48. package/lib/types/api/calld.d.ts +4 -4
  49. package/lib/types/api/calld.d.ts.map +1 -1
  50. package/lib/types/api/ctid-ng.d.ts +5 -5
  51. package/lib/types/api/ctid-ng.d.ts.map +1 -1
  52. package/lib/types/api/dird.d.ts +7 -21
  53. package/lib/types/api/dird.d.ts.map +1 -1
  54. package/lib/types/domain/ExternalApp.d.ts +1 -1
  55. package/lib/types/domain/ExternalApp.d.ts.map +1 -1
  56. package/lib/types/domain/Phone/CTIPhone.d.ts +2 -1
  57. package/lib/types/domain/Phone/CTIPhone.d.ts.map +1 -1
  58. package/lib/types/domain/Phone/Phone.d.ts +4 -3
  59. package/lib/types/domain/Phone/Phone.d.ts.map +1 -1
  60. package/lib/types/domain/Phone/WebRTCPhone.d.ts +21 -21
  61. package/lib/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
  62. package/lib/types/domain/Session.d.ts.map +1 -1
  63. package/lib/types/domain/types.d.ts +12 -9
  64. package/lib/types/domain/types.d.ts.map +1 -1
  65. package/lib/types/index.d.ts +1 -0
  66. package/lib/types/index.d.ts.map +1 -1
  67. package/lib/types/simple/Auth.d.ts.map +1 -1
  68. package/lib/types/web-rtc-client.d.ts.map +1 -1
  69. package/lib/types/websocket-client.d.ts.map +1 -1
  70. package/lib/web-rtc-client.js +3 -1
  71. package/lib/websocket-client.js +4 -0
  72. package/package.json +7 -2
  73. package/src/api/auth.ts +15 -15
  74. package/src/api/calld.ts +7 -7
  75. package/src/api/ctid-ng.ts +9 -9
  76. package/src/api/dird.ts +16 -31
  77. package/src/domain/ExternalApp.ts +1 -1
  78. package/src/domain/Phone/CTIPhone.ts +3 -2
  79. package/src/domain/Phone/Phone.ts +4 -3
  80. package/src/domain/Phone/WebRTCPhone.ts +23 -23
  81. package/src/domain/Session.ts +2 -1
  82. package/src/domain/types.ts +15 -9
  83. package/src/index.ts +1 -0
  84. package/src/simple/Auth.ts +2 -0
  85. package/src/simple/Directory.ts +2 -2
  86. package/src/simple/Phone.ts +1 -1
  87. package/src/web-rtc-client.ts +3 -1
  88. package/src/websocket-client.ts +5 -0
package/src/api/auth.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import ApiRequester from '../utils/api-requester';
2
- import type { User, Tenant, Token, UUID, LogoutResponse, ListTenantsResponse, RequestError, ListUsersResponse, ListGroupsResponse, ListPoliciesResponse, GetTenantResponse, GetUserResponse } from '../domain/types';
2
+ import type { User, Tenant, Token, UUID, LogoutResponse, ListTenantsResponse, ListUsersResponse, ListGroupsResponse, ListPoliciesResponse, GetTenantResponse, GetUserResponse } from '../domain/types';
3
3
  import Session, { Response } from '../domain/Session';
4
4
 
5
5
  export const DEFAULT_BACKEND_USER = 'wazo_user';
@@ -34,7 +34,7 @@ export interface AuthD {
34
34
  sendResetPasswordEmail: (params: SendResetPasswordArgs) => Promise<boolean>;
35
35
  resetPassword: (userUuid: string, password: string) => Promise<boolean>;
36
36
  removeDeviceToken: (userUuid: UUID) => Promise<void>;
37
- createUser: (username: string, password: string, firstname: string, lastname: string) => Promise<User | RequestError>;
37
+ createUser: (username: string, password: string, firstname: string, lastname: string) => Promise<User>;
38
38
  addUserEmail: (userUuid: UUID, email: string, main?: boolean) => Promise<void>;
39
39
  addUserPolicy: (userUuid: UUID, policyUuid: UUID) => Promise<void>;
40
40
  getRestrictionPolicies: (scopes: string[]) => Promise<any>;
@@ -46,18 +46,18 @@ export interface AuthD {
46
46
  getUserSession: (userUuid: UUID) => Promise<any>; // @TODO
47
47
  deleteUserSession: (userUuid: UUID, sessionUuids: UUID) => Promise<void>;
48
48
  listUsers: () => Promise<ListUsersResponse>;
49
- deleteUser: (userUuid: UUID) => Promise<boolean | RequestError>;
49
+ deleteUser: (userUuid: UUID) => Promise<boolean>;
50
50
  listTenants: () => Promise<ListTenantsResponse>;
51
51
  getTenant: (tenantUuid: UUID) => Promise<GetTenantResponse>;
52
- createTenant: (name: string) => Promise<Tenant | RequestError>;
53
- updateTenant: (uuid: UUID, name: string, contact: string, phone: string, address: Array<Record<string, any>>) => Promise<Tenant | RequestError>;
54
- deleteTenant: (uuid: UUID) => Promise<boolean | RequestError>;
52
+ createTenant: (name: string) => Promise<Tenant>;
53
+ updateTenant: (uuid: UUID, name: string, contact: string, phone: string, address: Array<Record<string, any>>) => Promise<Tenant>;
54
+ deleteTenant: (uuid: UUID) => Promise<boolean>;
55
55
  createGroup: (name: string) => Promise<void>;
56
56
  listGroups: () => Promise<ListGroupsResponse>;
57
- deleteGroup: (uuid: UUID) => Promise<boolean | RequestError>;
57
+ deleteGroup: (uuid: UUID) => Promise<boolean>;
58
58
  createPolicy: (name: string, description: string, aclTemplates: Array<Record<string, any>>) => Promise<void>;
59
59
  listPolicies: () => Promise<ListPoliciesResponse>;
60
- deletePolicy: (policyUuid: UUID) => Promise<boolean | RequestError>;
60
+ deletePolicy: (policyUuid: UUID) => Promise<boolean>;
61
61
  getProviders: (userUuid: UUID) => Promise<any>; // @TODO
62
62
  getProviderToken: (userUuid: UUID, provider: string) => Promise<string>; // @TODO; validate
63
63
  getProviderAuthUrl: (userUuid: UUID, provider: string) => Promise<string>;
@@ -186,7 +186,7 @@ export default ((client: ApiRequester, baseUrl: string): AuthD => ({
186
186
  return client.post(`${baseUrl}/users/password/reset?user_uuid=${userUuid}`, body, null, ApiRequester.successResponseParser);
187
187
  },
188
188
  removeDeviceToken: (userUuid: UUID) => client.delete(`${baseUrl}/users/${userUuid}/external/mobile`),
189
- createUser: (username: string, password: string, firstname: string, lastname: string): Promise<User | RequestError> => {
189
+ createUser: (username: string, password: string, firstname: string, lastname: string): Promise<User> => {
190
190
  const body = {
191
191
  username,
192
192
  password,
@@ -216,13 +216,13 @@ export default ((client: ApiRequester, baseUrl: string): AuthD => ({
216
216
  getUserSession: (userUuid: UUID) => client.get(`${baseUrl}/users/${userUuid}/sessions`),
217
217
  deleteUserSession: (userUuid: UUID, sessionUuids: UUID) => client.delete(`${baseUrl}/users/${userUuid}/sessions/${sessionUuids}`),
218
218
  listUsers: (): Promise<ListUsersResponse> => client.get(`${baseUrl}/users`),
219
- deleteUser: (userUuid: UUID): Promise<boolean | RequestError> => client.delete(`${baseUrl}/users/${userUuid}`),
219
+ deleteUser: (userUuid: UUID): Promise<boolean> => client.delete(`${baseUrl}/users/${userUuid}`),
220
220
  listTenants: (): Promise<ListTenantsResponse> => client.get(`${baseUrl}/tenants`),
221
221
  getTenant: (tenantUuid: UUID): Promise<GetTenantResponse> => client.get(`${baseUrl}/tenants/${tenantUuid}`),
222
- createTenant: (name: string): Promise<Tenant | RequestError> => client.post(`${baseUrl}/tenants`, {
222
+ createTenant: (name: string): Promise<Tenant> => client.post(`${baseUrl}/tenants`, {
223
223
  name,
224
224
  }),
225
- updateTenant: (uuid: UUID, name: string, contact: string, phone: string, address: Array<Record<string, any>>): Promise<Tenant | RequestError> => {
225
+ updateTenant: (uuid: UUID, name: string, contact: string, phone: string, address: Array<Record<string, any>>): Promise<Tenant> => {
226
226
  const body = {
227
227
  name,
228
228
  contact,
@@ -231,12 +231,12 @@ export default ((client: ApiRequester, baseUrl: string): AuthD => ({
231
231
  };
232
232
  return client.put(`${baseUrl}/tenants/${uuid}`, body);
233
233
  },
234
- deleteTenant: (uuid: UUID): Promise<boolean | RequestError> => client.delete(`${baseUrl}/tenants/${uuid}`),
234
+ deleteTenant: (uuid: UUID): Promise<boolean> => client.delete(`${baseUrl}/tenants/${uuid}`),
235
235
  createGroup: (name: string) => client.post(`${baseUrl}/groups`, {
236
236
  name,
237
237
  }),
238
238
  listGroups: (): Promise<ListGroupsResponse> => client.get(`${baseUrl}/groups`),
239
- deleteGroup: (uuid: UUID): Promise<boolean | RequestError> => client.delete(`${baseUrl}/groups/${uuid}`),
239
+ deleteGroup: (uuid: UUID): Promise<boolean> => client.delete(`${baseUrl}/groups/${uuid}`),
240
240
  createPolicy: (name: string, description: string, aclTemplates: Array<Record<string, any>>) => {
241
241
  const body = {
242
242
  name,
@@ -248,7 +248,7 @@ export default ((client: ApiRequester, baseUrl: string): AuthD => ({
248
248
  return client.post(`${baseUrl}/policies`, body);
249
249
  },
250
250
  listPolicies: (): Promise<ListPoliciesResponse> => client.get(`${baseUrl}/policies`),
251
- deletePolicy: (policyUuid: UUID): Promise<boolean | RequestError> => client.delete(`${baseUrl}/policies/${policyUuid}`),
251
+ deletePolicy: (policyUuid: UUID): Promise<boolean> => client.delete(`${baseUrl}/policies/${policyUuid}`),
252
252
  getProviders: (userUuid: UUID) => client.get(`${baseUrl}/users/${userUuid}/external`),
253
253
  getProviderToken: (userUuid: UUID, provider: string) => client.get(`${baseUrl}/users/${userUuid}/external/${provider}`),
254
254
  getProviderAuthUrl: (userUuid: UUID, provider: string) => client.post(`${baseUrl}/users/${userUuid}/external/${provider}`, {}),
package/src/api/calld.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable camelcase */
2
2
  import ApiRequester from '../utils/api-requester';
3
- import type { UUID, RequestError } from '../domain/types';
3
+ import type { UUID } from '../domain/types';
4
4
  import Relocation, { RelocationResponse } from '../domain/Relocation';
5
5
  import ChatMessage, { ChatMessageListResponse } from '../domain/ChatMessage';
6
6
  import Voicemail from '../domain/Voicemail';
@@ -23,15 +23,15 @@ export interface CallD {
23
23
  cancelCall: (callId: string) => Promise<boolean>;
24
24
  listCalls: () => Promise<Array<Call>>;
25
25
  relocateCall: (callId: string, destination: string, lineId: number | null | undefined, contact?: string | null | undefined) => Promise<Relocation>;
26
- listVoicemails: () => Promise<RequestError | Array<Voicemail>>;
27
- deleteVoicemail: (voicemailId: number) => Promise<boolean>;
26
+ listVoicemails: () => Promise<Array<Voicemail>>;
27
+ deleteVoicemail: (voicemailId: string) => Promise<boolean>;
28
28
  getVoicemailUrl: (voicemail: Voicemail) => string;
29
29
  fetchSwitchboardHeldCalls: (switchboardUuid: UUID) => Promise<any>; // @TODO: replace `any`
30
30
  holdSwitchboardCall: (switchboardUuid: UUID, callId: string) => Promise<boolean>;
31
31
  answerSwitchboardHeldCall: (switchboardUuid: UUID, callId: string, lineId: string | null | undefined) => Promise<void>;
32
32
  fetchSwitchboardQueuedCalls: (switchboardUuid: UUID) => Promise<any>; // @TODO: replace `any`
33
33
  answerSwitchboardQueuedCall: (switchboardUuid: UUID, callId: string, lineId: string | null | undefined) => Promise<any>; // @TODO: replace `any`
34
- sendFax: (extension: string, fax: string, callerId: string | null | undefined) => Promise<void>;
34
+ sendFax: (extension: string, fax: string, callerId?: string) => Promise<void>;
35
35
  getConferenceParticipantsAsUser: (conferenceId: string) => Promise<Record<string, any>>; // @TODO: replace `any`
36
36
  getMeetingParticipantsAsUser: (meetingUuid: string) => Promise<Record<string, any>>; // @TODO: replace `any`
37
37
  banMeetingParticipant: (meetingUuid: string, participantUuid: string) => Promise<boolean>;
@@ -125,8 +125,8 @@ export default ((client: ApiRequester, baseUrl: string): CallD => ({
125
125
  return client.post(`${baseUrl}/users/me/relocates`, body).then((response: RelocationResponse) => Relocation.parse(response));
126
126
  },
127
127
 
128
- listVoicemails: (): Promise<RequestError | Array<Voicemail>> => client.get(`${baseUrl}/users/me/voicemails`).then((response: any) => Voicemail.parseMany(response)),
129
- deleteVoicemail: (voicemailId: number): Promise<boolean> => client.delete(`${baseUrl}/users/me/voicemails/messages/${voicemailId}`),
128
+ listVoicemails: (): Promise<Array<Voicemail>> => client.get(`${baseUrl}/users/me/voicemails`).then((response: any) => Voicemail.parseMany(response)),
129
+ deleteVoicemail: (voicemailId: string): Promise<boolean> => client.delete(`${baseUrl}/users/me/voicemails/messages/${voicemailId}`),
130
130
  getVoicemailUrl: (voicemail: Voicemail): string => {
131
131
  const body = {
132
132
  token: client.token,
@@ -138,7 +138,7 @@ export default ((client: ApiRequester, baseUrl: string): CallD => ({
138
138
  answerSwitchboardHeldCall: (switchboardUuid: UUID, callId: string, lineId: string | null | undefined = null) => client.put(`${baseUrl}/switchboards/${switchboardUuid}/calls/held/${callId}/answer${lineId ? `?line_id=${lineId}` : ''}`),
139
139
  fetchSwitchboardQueuedCalls: (switchboardUuid: UUID) => client.get(`${baseUrl}/switchboards/${switchboardUuid}/calls/queued`),
140
140
  answerSwitchboardQueuedCall: (switchboardUuid: UUID, callId: string, lineId: string | null | undefined = null) => client.put(`${baseUrl}/switchboards/${switchboardUuid}/calls/queued/${callId}/answer${lineId ? `?line_id=${lineId}` : ''}`),
141
- sendFax: (extension: string, fax: string, callerId: string | null | undefined = null) => {
141
+ sendFax: (extension: string, fax: string, callerId?: string) => {
142
142
  const headers = {
143
143
  'Content-type': 'application/pdf',
144
144
  'X-Auth-Token': client.token,
@@ -2,7 +2,7 @@
2
2
 
3
3
  /* DEPRECATED: USE CALLD INSTEAD CTID-NG */
4
4
  import ApiRequester from '../utils/api-requester';
5
- import type { UUID, RequestError, CTITransfer } from '../domain/types';
5
+ import type { UUID, CTITransfer } from '../domain/types';
6
6
  import Relocation from '../domain/Relocation';
7
7
  import ChatMessage from '../domain/ChatMessage';
8
8
  import Voicemail, { Response } from '../domain/Voicemail';
@@ -30,10 +30,10 @@ export interface CtidNg {
30
30
  cancelCall: (callId: number) => Promise<boolean>;
31
31
  listCalls: () => Promise<Array<Call>>;
32
32
  relocateCall: (callId: number, destination: string, lineId: number | null | undefined, contact?: string | null | undefined) => Promise<Relocation>;
33
- transferCall: (callId: number, number: string, flow: string) => Promise<RequestError | CTITransfer>;
34
- cancelCallTransfer: (transferId: string) => Promise<RequestError | void>;
35
- confirmCallTransfer: (transferId: string) => Promise<RequestError | void>;
36
- listVoicemails: () => Promise<RequestError | Array<Voicemail>>;
33
+ transferCall: (callId: number, number: string, flow: string) => Promise<CTITransfer>;
34
+ cancelCallTransfer: (transferId: string) => Promise<void>;
35
+ confirmCallTransfer: (transferId: string) => Promise<void>;
36
+ listVoicemails: () => Promise<Array<Voicemail>>;
37
37
  deleteVoicemail: (voicemailId: number) => Promise<boolean>;
38
38
  getPresence: (contactUuid: UUID) => Promise<GetPresenceResponse>;
39
39
  getStatus: (lineUuid: UUID) => Promise<string>;
@@ -112,7 +112,7 @@ export default ((client: ApiRequester, baseUrl: string): CtidNg => ({
112
112
  return client.post(`${baseUrl}/users/me/relocates`, body).then(Relocation.parse);
113
113
  },
114
114
 
115
- transferCall(callId: number, number: string, flow: string = TRANSFER_FLOW_BLIND): Promise<RequestError | CTITransfer> {
115
+ transferCall(callId: number, number: string, flow: string = TRANSFER_FLOW_BLIND): Promise<CTITransfer> {
116
116
  const body: Record<string, any> = {
117
117
  exten: number,
118
118
  flow,
@@ -122,10 +122,10 @@ export default ((client: ApiRequester, baseUrl: string): CtidNg => ({
122
122
  },
123
123
 
124
124
  // @TODO: fix response type
125
- cancelCallTransfer: (transferId: string): Promise<RequestError | void> => client.delete(`${baseUrl}/users/me/transfers/${transferId}`),
125
+ cancelCallTransfer: (transferId: string): Promise<void> => client.delete(`${baseUrl}/users/me/transfers/${transferId}`),
126
126
  // @TODO: fix response type
127
- confirmCallTransfer: (transferId: string): Promise<RequestError | void> => client.put(`${baseUrl}/users/me/transfers/${transferId}/complete`),
128
- listVoicemails: (): Promise<RequestError | Array<Voicemail>> => client.get(`${baseUrl}/users/me/voicemails`, null).then((response: Response) => Voicemail.parseMany(response)),
127
+ confirmCallTransfer: (transferId: string): Promise<void> => client.put(`${baseUrl}/users/me/transfers/${transferId}/complete`),
128
+ listVoicemails: (): Promise<Array<Voicemail>> => client.get(`${baseUrl}/users/me/voicemails`, null).then((response: Response) => Voicemail.parseMany(response)),
129
129
  deleteVoicemail: (voicemailId: number): Promise<boolean> => client.delete(`${baseUrl}/users/me/voicemails/messages/${voicemailId}`, null),
130
130
  getPresence: (contactUuid: UUID): Promise<{
131
131
  presence: string;
package/src/api/dird.ts CHANGED
@@ -1,16 +1,9 @@
1
1
  import { jsonToGraphQLQuery } from 'json-to-graphql-query/lib/jsonToGraphQLQuery';
2
2
  import ApiRequester from '../utils/api-requester';
3
- import type { PhonebookResponseItem, UUID } from '../domain/types';
3
+ import type { UuidSearchableQueryParams, SearchableQueryParams, PhonebookResponseItem, QueryParams, UUID } from '../domain/types';
4
4
  import { Contact, ContactsResponse } from '../index';
5
5
  import type { NewContact, DirectorySource, DirectorySources } from '../index';
6
6
 
7
- type PhoneBookSearchQueryParams = {
8
- order?: string;
9
- direction?: 'asc' | 'desc';
10
- limit?: number;
11
- offset?: number;
12
- };
13
-
14
7
  const getContactPayload = (contact: NewContact | Contact) => ({
15
8
  email: contact.email,
16
9
  firstname: (contact as any).firstName ? (contact as any).firstName : '',
@@ -24,7 +17,7 @@ const getContactPayload = (contact: NewContact | Contact) => ({
24
17
 
25
18
  export interface DirD {
26
19
  search: (context: string, term: string) => Promise<Array<Contact>>;
27
- listPersonalContacts: (queryParams?: ContactSearchQueryParams) => Promise<Array<Contact>>;
20
+ listPersonalContacts: (queryParams?: QueryParams) => Promise<Array<Contact>>;
28
21
  fetchPersonalContact: (contactUuid: string) => Promise<Contact>;
29
22
  addContact: (contact: NewContact) => Promise<Contact>;
30
23
  editContact: (contact: Contact) => Promise<Contact>;
@@ -34,35 +27,27 @@ export interface DirD {
34
27
  markAsFavorite: (source: string, sourceId: string) => Promise<boolean>;
35
28
  removeFavorite: (source: string, sourceId: string) => Promise<void>;
36
29
  fetchOffice365Source: (context: string) => Promise<DirectorySources>;
37
- fetchOffice365Contacts: (source: DirectorySource, queryParams: ContactSearchQueryParams) => Promise<Contact[]> ;
30
+ fetchOffice365Contacts: (source: DirectorySource, queryParams: SearchableQueryParams) => Promise<Contact[]> ;
38
31
  fetchWazoSource: (context: string) => Promise<DirectorySources>;
39
32
  fetchSourcesFor: (context: string, backend: string) => Promise<DirectorySources>;
40
- fetchWazoContacts: (source: DirectorySource, queryParams: ContactSearchQueryParams) => Promise<Contact[]>;
33
+ fetchWazoContacts: (source: DirectorySource, queryParams: UuidSearchableQueryParams) => Promise<Contact[]>;
41
34
  fetchGoogleSource: (context: string) => Promise<DirectorySources>;
42
- fetchGoogleContacts: (source: DirectorySource, queryParams: ContactSearchQueryParams) => Promise<Contact[]>;
35
+ fetchGoogleContacts: (source: DirectorySource, queryParams: SearchableQueryParams) => Promise<Contact[]>;
43
36
  fetchConferenceSource: (context: string) => Promise<DirectorySources>;
44
- fetchConferenceContacts: (source: DirectorySource) => Promise<Contact[]>;
45
- fetchPhonebookContacts: (source: DirectorySource, params?: PhoneBookSearchQueryParams) => Promise<{ items: PhonebookResponseItem[], total: number }>;
37
+ fetchConferenceContacts: (source: DirectorySource, queryParams?: SearchableQueryParams) => Promise<Contact[]>;
38
+ fetchPhonebookContacts: (source: DirectorySource, queryParams?: QueryParams) => Promise<{ items: PhonebookResponseItem[], total: number }>;
46
39
  findMultipleContactsByNumber: (numbers: string[], fields?: Record<string, any>) => Promise<Contact[]>;
47
40
  }
48
41
 
49
- type ContactSearchQueryParams = {
50
- order?: string;
51
- direction?: 'asc' | 'desc';
52
- limit?: number;
53
- offset?: number;
54
- search?: string;
55
- uuid?: string;
56
- } | null;
57
42
  export default ((client: ApiRequester, baseUrl: string): DirD => ({
58
43
  search: (context: string, term: string, offset = 0, limit: (number | null) = null): Promise<Array<Contact>> => client.get(`${baseUrl}/directories/lookup/${context}`, {
59
44
  term,
60
45
  }).then((response: ContactsResponse) => Contact.parseMany(response, offset, limit)),
61
- listPersonalContacts: (queryParams: ContactSearchQueryParams = null): Promise<Array<Contact>> => client.get(`${baseUrl}/personal`, queryParams).then((response: any) => Contact.parseManyPersonal(response.items)),
46
+ listPersonalContacts: (queryParams?: QueryParams): Promise<Array<Contact>> => client.get(`${baseUrl}/personal`, queryParams).then((response: any) => Contact.parseManyPersonal(response.items)),
62
47
  fetchPersonalContact: (contactUuid: string): Promise<Contact> => client.get(`${baseUrl}/personal/${contactUuid}`).then(Contact.parsePersonal),
63
48
  addContact: (contact: NewContact): Promise<Contact> => client.post(`${baseUrl}/personal`, getContactPayload(contact)).then(Contact.parsePersonal),
64
49
  editContact: (contact: Contact): Promise<Contact> => client.put(`${baseUrl}/personal/${contact.sourceId || contact.id || ''}`, getContactPayload(contact)).then(Contact.parsePersonal),
65
- importContacts: (csv: string): Promise<Contact[]> => {
50
+ importContacts: async (csv: string): Promise<Contact[]> => {
66
51
  const headers = {
67
52
  'Content-Type': 'text/csv; charset=utf-8',
68
53
  'X-Auth-Token': client.token,
@@ -79,7 +64,7 @@ export default ((client: ApiRequester, baseUrl: string): DirD => ({
79
64
  fetchOffice365Source: (context: string): Promise<DirectorySources> => client.get(`${baseUrl}/directories/${context}/sources`, {
80
65
  backend: 'office365',
81
66
  }),
82
- fetchOffice365Contacts: (source: DirectorySource, queryParams: ContactSearchQueryParams = null): Promise<Contact[]> => {
67
+ fetchOffice365Contacts: async (source: DirectorySource, queryParams?: SearchableQueryParams): Promise<Contact[]> => {
83
68
  if (!source) {
84
69
  return Promise.resolve([]);
85
70
  }
@@ -90,7 +75,7 @@ export default ((client: ApiRequester, baseUrl: string): DirD => ({
90
75
  backend: 'wazo',
91
76
  }),
92
77
  // Can be used with `queryParams = { uuid: uuid1, uuid2 }` to fetch multiple contacts
93
- fetchWazoContacts: (source: DirectorySource, queryParams: ContactSearchQueryParams = null): Promise<Contact[]> => {
78
+ fetchWazoContacts: async (source: DirectorySource, queryParams?: UuidSearchableQueryParams): Promise<Contact[]> => {
94
79
  if (!source) {
95
80
  return Promise.resolve([]);
96
81
  }
@@ -100,7 +85,7 @@ export default ((client: ApiRequester, baseUrl: string): DirD => ({
100
85
  fetchGoogleSource: (context: string): Promise<DirectorySources> => client.get(`${baseUrl}/directories/${context}/sources`, {
101
86
  backend: 'google',
102
87
  }),
103
- fetchGoogleContacts: (source: DirectorySource, queryParams: ContactSearchQueryParams = null): Promise<Contact[]> => {
88
+ fetchGoogleContacts: async (source: DirectorySource, queryParams?: SearchableQueryParams): Promise<Contact[]> => {
104
89
  if (!source) {
105
90
  return Promise.resolve([]);
106
91
  }
@@ -111,19 +96,19 @@ export default ((client: ApiRequester, baseUrl: string): DirD => ({
111
96
  backend: 'conference',
112
97
  }),
113
98
  fetchSourcesFor: (context: string, backend: string): Promise<DirectorySources> => client.get(`${baseUrl}/directories/${context}/sources`, { backend }),
114
- fetchPhonebookContacts: (source: DirectorySource, params?: PhoneBookSearchQueryParams): Promise<{ items: PhonebookResponseItem[], total: number }> => {
99
+ fetchPhonebookContacts: async (source: DirectorySource, queryParams?: QueryParams): Promise<{ items: PhonebookResponseItem[], total: number }> => {
115
100
  if (!source) {
116
101
  return Promise.resolve({ items: [], total: 0 });
117
102
  }
118
103
 
119
- return client.get(`${baseUrl}/backends/phonebook/sources/${source.uuid}/contacts`, params);
104
+ return client.get(`${baseUrl}/backends/phonebook/sources/${source.uuid}/contacts`, queryParams);
120
105
  },
121
- fetchConferenceContacts: (source: DirectorySource): Promise<Contact[]> => {
106
+ fetchConferenceContacts: async (source: DirectorySource, queryParams?: SearchableQueryParams): Promise<Contact[]> => {
122
107
  if (!source) {
123
108
  return Promise.resolve([]);
124
109
  }
125
110
 
126
- return client.get(`${baseUrl}/backends/conference/sources/${source.uuid}/contacts`).then((response: any) => Contact.parseManyConference(response.items, source));
111
+ return client.get(`${baseUrl}/backends/conference/sources/${source.uuid}/contacts`, queryParams).then((response: any) => Contact.parseManyConference(response.items, source));
127
112
  },
128
113
  // Graphql
129
114
  findMultipleContactsByNumber: (numbers: string[], fields?: Record<string, any>): Promise<Contact[]> => {
@@ -16,7 +16,7 @@ export default class ExternalApp {
16
16
 
17
17
  type: string;
18
18
 
19
- configuration: Record<string, any> | undefined;
19
+ configuration?: Record<string, any>;
20
20
 
21
21
  static parse(plain: Response): ExternalApp {
22
22
  return new ExternalApp({
@@ -6,6 +6,7 @@ import type { Phone, AvailablePhoneOptions } from './Phone';
6
6
  import Emitter from '../../utils/Emitter';
7
7
  import CallApi from '../../service/CallApi';
8
8
  import IssueReporter from '../../service/IssueReporter';
9
+ import IndirectTransfer from '../IndirectTransfer';
9
10
 
10
11
  export const TRANSFER_FLOW_ATTENDED = 'attended';
11
12
  export const TRANSFER_FLOW_BLIND = 'blind';
@@ -187,9 +188,9 @@ export default class CTIPhone extends Emitter implements Phone {
187
188
  return Promise.resolve(false);
188
189
  }
189
190
 
190
- async initiateCTIIndirectTransfer(callSession: CallSession, number: string): Promise<any> {
191
+ async initiateCTIIndirectTransfer(callSession: CallSession, number: string): Promise<IndirectTransfer | null> {
191
192
  if (!callSession) {
192
- return;
193
+ return Promise.resolve(null);
193
194
  }
194
195
 
195
196
  logger.info('indirect CTI transfer', {
@@ -3,6 +3,7 @@ import Line from '../Line';
3
3
  import CallSession from '../CallSession';
4
4
  import type WebRTCClient from '../../web-rtc-client';
5
5
  import { IEmitter } from '../../utils/Emitter';
6
+ import IndirectTransfer from '../IndirectTransfer';
6
7
 
7
8
  export type PhoneEventCallbacks = {
8
9
  onCallIncoming?: (number: string) => void;
@@ -29,7 +30,7 @@ export type AvailablePhoneOptions = {
29
30
  transfer: boolean;
30
31
  };
31
32
  export interface Phone extends IEmitter {
32
- accept(callSession: CallSession, enableVideo: boolean): Promise<string | null>;
33
+ accept(callSession: CallSession, enableVideo?: boolean): Promise<string | null>;
33
34
  changeAudioDevice(id: string): PhoneVoid;
34
35
  changeRingDevice(id: string): PhoneVoid;
35
36
  changeAudioVolume(volume: number): PhoneVoid;
@@ -46,11 +47,11 @@ export interface Phone extends IEmitter {
46
47
  getOptions(): AvailablePhoneOptions;
47
48
  getRemoteStreamForCall(callSession: CallSession): MediaStream | null | undefined;
48
49
  ignore(callSession: CallSession): PhoneVoid;
49
- hangup(callSession: CallSession): Promise<boolean>;
50
+ hangup(callSession?: CallSession): Promise<boolean>;
50
51
  hasAnActiveCall(): boolean;
51
52
  hold(callSession: CallSession): Promise<any> | null | undefined;
52
53
  indirectTransfer(source: CallSession, destination: CallSession): Promise<boolean>;
53
- initiateCTIIndirectTransfer(callSession: CallSession, number: string): PhoneVoid;
54
+ initiateCTIIndirectTransfer(callSession: CallSession, number: string): Promise<IndirectTransfer | null>;
54
55
  cancelCTIIndirectTransfer(transferId: string): PhoneVoid;
55
56
  confirmCTIIndirectTransfer(transferId: string): PhoneVoid;
56
57
  hasVideo(callSession: CallSession): boolean;
@@ -68,13 +68,13 @@ export default class WebRTCPhone extends Emitter implements Phone {
68
68
 
69
69
  incomingSessions: string[];
70
70
 
71
- currentSipSession: WazoSession | undefined;
71
+ currentSipSession?: WazoSession;
72
72
 
73
- currentCallSession: CallSession | null | undefined;
73
+ currentCallSession?: CallSession;
74
74
 
75
- audioOutputDeviceId: string | null | undefined;
75
+ audioOutputDeviceId?: string;
76
76
 
77
- audioRingDeviceId: string | null | undefined;
77
+ audioRingDeviceId?: string;
78
78
 
79
79
  audioOutputVolume: number;
80
80
 
@@ -94,7 +94,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
94
94
 
95
95
  shouldSendReinvite: boolean;
96
96
 
97
- constructor(client: WazoWebRTCClient, audioOutputDeviceId: string | null | undefined, allowVideo = false, audioRingDeviceId?: string) {
97
+ constructor(client: WazoWebRTCClient, audioOutputDeviceId: string | undefined, allowVideo = false, audioRingDeviceId?: string) {
98
98
  super();
99
99
  this.client = client;
100
100
  this.allowVideo = allowVideo;
@@ -156,7 +156,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
156
156
  return true;
157
157
  }
158
158
 
159
- async sendReinvite(callSession: CallSession | null | undefined, constraints: Record<string, any> | null | undefined = null, conference = false, audioOnly = false, iceRestart = false): Promise<OutgoingInviteRequest | void> {
159
+ async sendReinvite(callSession?: CallSession, constraints: Record<string, any> | null | undefined = null, conference = false, audioOnly = false, iceRestart = false): Promise<OutgoingInviteRequest | void> {
160
160
  const sipSession = this.findSipSession(callSession);
161
161
  logger.info('WebRTC phone - send reinvite', {
162
162
  sessionId: sipSession ? sipSession.id : null,
@@ -271,7 +271,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
271
271
  return this.client.onDisconnect();
272
272
  }
273
273
 
274
- _downgradeToAudio(callSession: CallSession | null | undefined, withMessage = true) {
274
+ _downgradeToAudio(callSession?: CallSession, withMessage = true) {
275
275
  const sipSession = this.findSipSession(callSession);
276
276
 
277
277
  if (!sipSession) {
@@ -298,7 +298,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
298
298
  }
299
299
 
300
300
  // Returns true if we need to send a re-INVITE request
301
- async _upgradeToVideo(callSession: CallSession | null | undefined, constraints: Record<string, any>, isConference: boolean): Promise<boolean> {
301
+ async _upgradeToVideo(callSession: CallSession | undefined, constraints: Record<string, any>, isConference: boolean): Promise<boolean> {
302
302
  const sipSession = this.findSipSession(callSession);
303
303
 
304
304
  if (!sipSession) {
@@ -342,7 +342,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
342
342
  return false;
343
343
  }
344
344
 
345
- _sendReinviteMessage(callSession: CallSession | null | undefined, isUpgrade: boolean) {
345
+ _sendReinviteMessage(callSession: CallSession | undefined, isUpgrade: boolean) {
346
346
  const sipSession = this.findSipSession(callSession);
347
347
  logger.info('Sending reinvite message', {
348
348
  id: callSession ? callSession.getId() : null,
@@ -506,7 +506,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
506
506
  return screenShareStream;
507
507
  }
508
508
 
509
- async stopScreenSharing(restoreLocalStream = true, callSession?: CallSession | null | undefined): Promise<OutgoingInviteRequest | void | null> {
509
+ async stopScreenSharing(restoreLocalStream = true, callSession?: CallSession): Promise<OutgoingInviteRequest | void | null> {
510
510
  if (!this.currentScreenShare) {
511
511
  return;
512
512
  }
@@ -983,7 +983,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
983
983
  return promise;
984
984
  }
985
985
 
986
- async holdSipSession(sipSession: WazoSession, callSession: CallSession | null | undefined, withEvent = true): Promise<OutgoingInviteRequest | void> {
986
+ async holdSipSession(sipSession: WazoSession, callSession?: CallSession, withEvent = true): Promise<OutgoingInviteRequest | void> {
987
987
  if (!sipSession) {
988
988
  return new Promise((resolve, reject) => reject(new Error('No session to hold')));
989
989
  }
@@ -1077,7 +1077,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1077
1077
  });
1078
1078
  }
1079
1079
 
1080
- mute(callSession: CallSession | null | undefined, withEvent = true): void {
1080
+ mute(callSession?: CallSession, withEvent = true): void {
1081
1081
  logger.info('WebRTC mute called', {
1082
1082
  id: callSession ? callSession.getId() : null,
1083
1083
  });
@@ -1105,7 +1105,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1105
1105
  }
1106
1106
  }
1107
1107
 
1108
- unmute(callSession: CallSession | null | undefined, withEvent = true): void {
1108
+ unmute(callSession?: CallSession, withEvent = true): void {
1109
1109
  logger.info('WebRTC unmute called', {
1110
1110
  id: callSession ? callSession.getId() : null,
1111
1111
  });
@@ -1171,7 +1171,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1171
1171
  this.eventEmitter.emit(ON_CAMERA_DISABLED, this._createCameraDisabledCallSession(sipSession, callSession));
1172
1172
  }
1173
1173
 
1174
- sendKey(callSession: CallSession | null | undefined, tone: string): void {
1174
+ sendKey(callSession: CallSession | undefined, tone: string): void {
1175
1175
  const sipSession = this.findSipSession(callSession);
1176
1176
 
1177
1177
  if (!sipSession) {
@@ -1248,7 +1248,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1248
1248
  return Promise.resolve(callSession);
1249
1249
  }
1250
1250
 
1251
- transfer(callSession: CallSession | null | undefined, target: string): void {
1251
+ transfer(callSession: CallSession, target: string): void {
1252
1252
  const sipSession = this.findSipSession(callSession);
1253
1253
 
1254
1254
  if (!sipSession) {
@@ -1290,13 +1290,13 @@ export default class WebRTCPhone extends Emitter implements Phone {
1290
1290
  });
1291
1291
  }
1292
1292
 
1293
- initiateCTIIndirectTransfer() {}
1293
+ initiateCTIIndirectTransfer() { return Promise.resolve(null); }
1294
1294
 
1295
1295
  cancelCTIIndirectTransfer() {}
1296
1296
 
1297
1297
  confirmCTIIndirectTransfer() {}
1298
1298
 
1299
- async hangup(callSession?: CallSession | null): Promise<boolean> {
1299
+ async hangup(callSession?: CallSession): Promise<boolean> {
1300
1300
  const sipSession = this.findSipSession(callSession);
1301
1301
 
1302
1302
  if (!sipSession) {
@@ -1322,17 +1322,17 @@ export default class WebRTCPhone extends Emitter implements Phone {
1322
1322
  return true;
1323
1323
  }
1324
1324
 
1325
- async getStats(callSession: CallSession | null | undefined): Promise<RTCStatsReport | null | undefined> {
1325
+ async getStats(callSession?: CallSession): Promise<RTCStatsReport | null | undefined> {
1326
1326
  const sipSession = this.findSipSession(callSession);
1327
1327
  return sipSession ? this.client.getStats(sipSession) : null;
1328
1328
  }
1329
1329
 
1330
- startNetworkMonitoring(callSession: CallSession | null | undefined, interval = 1000) {
1330
+ startNetworkMonitoring(callSession?: CallSession, interval = 1000) {
1331
1331
  const sipSession = this.findSipSession(callSession);
1332
1332
  return sipSession ? this.client.startNetworkMonitoring(sipSession, interval) : null;
1333
1333
  }
1334
1334
 
1335
- stopNetworkMonitoring(callSession: CallSession | null | undefined) {
1335
+ stopNetworkMonitoring(callSession?: CallSession) {
1336
1336
  const sipSession = this.findSipSession(callSession);
1337
1337
  return sipSession ? this.client.stopNetworkMonitoring(sipSession) : null;
1338
1338
  }
@@ -1360,7 +1360,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1360
1360
 
1361
1361
  if (isCurrent) {
1362
1362
  this.currentSipSession = undefined;
1363
- this.currentCallSession = null;
1363
+ this.currentCallSession = undefined;
1364
1364
  }
1365
1365
 
1366
1366
  this.eventEmitter.emit(ON_TERMINATE_SOUND, callSession, 'locally ended');
@@ -1392,7 +1392,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1392
1392
  this.unbind();
1393
1393
  this.incomingSessions = [];
1394
1394
  this.currentSipSession = undefined;
1395
- this.currentCallSession = null;
1395
+ this.currentCallSession = undefined;
1396
1396
  this.shouldSendReinvite = false;
1397
1397
  this.rejectedSessions = {};
1398
1398
  }
@@ -1667,7 +1667,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1667
1667
  }
1668
1668
 
1669
1669
  // Find a corresponding sipSession from a CallSession
1670
- findSipSession(callSession: CallSession | null | undefined): WazoSession | null | undefined {
1670
+ findSipSession(callSession?: CallSession): WazoSession | null | undefined {
1671
1671
  const keys = this.client.getSipSessionIds();
1672
1672
  const keyIndex = keys.findIndex(sessionId => callSession && callSession.isId(sessionId));
1673
1673
 
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable no-nested-ternary */
2
2
  import { KEYUTIL, KJUR, b64utoutf8 } from 'jsrsasign';
3
+ import moment from 'moment';
3
4
  import swarmPublicKey from '../pubkey';
4
5
  import Profile from './Profile';
5
6
  import Contact from './Contact';
@@ -126,7 +127,7 @@ export default class Session {
126
127
  authorizations,
127
128
  acl: plain.data.acls ? plain.data.acls : plain.data.acl ? plain.data.acl : [],
128
129
  tenantUuid: plain.data.metadata ? plain.data.metadata.tenant_uuid : undefined,
129
- expiresAt: new Date(`${plain.data.utc_expires_at}z`),
130
+ expiresAt: moment.utc(plain.data.utc_expires_at).toDate(),
130
131
  stackUuid: plain.data.xivo_uuid,
131
132
  // eslint-disable-next-line
132
133
  stackHostFromHeader: plain._headers?.get?.('wazo-stack-host'),
@@ -9,15 +9,6 @@ type GenericObject = Record<string, any>;
9
9
  export type Token = string;
10
10
  export type UUID = string;
11
11
  export type DateString = string;
12
- export type RequestError = {
13
- timestamp: number;
14
- message: string;
15
- resource: string;
16
- error_id: string;
17
- details: {
18
- uuid: string;
19
- };
20
- };
21
12
  export type LogoutResponse = {
22
13
  data: {
23
14
  message: string;
@@ -306,3 +297,18 @@ export type PresenceResponse = {
306
297
  user_uuid: string;
307
298
  last_activity?: string,
308
299
  };
300
+
301
+ export type QueryParams = {
302
+ order?: string;
303
+ direction?: 'asc' | 'desc';
304
+ limit?: number;
305
+ offset?: number;
306
+ };
307
+
308
+ export type SearchableQueryParams = QueryParams & {
309
+ search?: string;
310
+ };
311
+
312
+ export type UuidSearchableQueryParams = SearchableQueryParams & {
313
+ uuid?: string;
314
+ };
package/src/index.ts CHANGED
@@ -47,6 +47,7 @@ export { default as WebSocketClient, SOCKET_EVENTS } from './websocket-client';
47
47
  export { default as WebRTCClient } from './web-rtc-client';
48
48
  export { default as WazoApiClient } from './api-client';
49
49
  export { default as Agent, AgentResponse, AgentArguments } from './domain/Agent';
50
+ export { default as ExternalApp } from './domain/ExternalApp';
50
51
  export * from './types/WebSocketMessage';
51
52
  export * from './utils/PhoneNumberUtil';
52
53
  export * from './domain/types';
@@ -372,6 +372,8 @@ class Auth {
372
372
  this.checkSubscription(session, +this.minSubscriptionType);
373
373
  }
374
374
  } catch (e: any) {
375
+ logger.error('on authenticated error', e);
376
+
375
377
  // Destroy tokens when validation fails
376
378
  if (this.clientId) {
377
379
  await getApiClient().auth.deleteRefreshToken(this.clientId);
@@ -2,8 +2,8 @@ import type Contact from '../domain/Contact';
2
2
  import getApiClient from '../service/getApiClient';
3
3
 
4
4
  class Directory {
5
- async findMultipleContactsByNumber(numbers: string[]): Promise<Contact[]> {
6
- return getApiClient().dird.findMultipleContactsByNumber(numbers);
5
+ async findMultipleContactsByNumber(numbers: string[], fields?: Record<string, any>): Promise<Contact[]> {
6
+ return getApiClient().dird.findMultipleContactsByNumber(numbers, fields);
7
7
  }
8
8
 
9
9
  }
@@ -204,7 +204,7 @@ class Phone extends Emitter {
204
204
  if (this.phone) {
205
205
  if (this.phone.hasAnActiveCall()) {
206
206
  logger.info('hangup call on disconnect');
207
- await this.phone.hangup(null);
207
+ await this.phone.hangup();
208
208
  }
209
209
 
210
210
  await this.phone.close();