Skip to content

Commit

Permalink
fix: user-to-user header was not being transformed to lisp case
Browse files Browse the repository at this point in the history
  • Loading branch information
manchuck committed Jan 6, 2025
1 parent 3ecb978 commit 9a19df2
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 5 deletions.
102 changes: 102 additions & 0 deletions packages/voice/__tests__/__dataSets__/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,108 @@ export default [
error: false,
expected: undefined,
},
{
label: 'transfer call with NCCO with userToUser',
requests: [
[
`/v1/calls/${callPhone.uuid}`,
'PUT',
{
action: 'transfer',
destination: {
type: 'ncco',
ncco: [
{

Check failure on line 198 in packages/voice/__tests__/__dataSets__/update.ts

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Expected indentation of 14 spaces but found 13
action: NCCOActions.CONNECT,

Check failure on line 199 in packages/voice/__tests__/__dataSets__/update.ts

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Expected indentation of 16 spaces but found 15
endpoint: [

Check failure on line 200 in packages/voice/__tests__/__dataSets__/update.ts

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Expected indentation of 16 spaces but found 15
{

Check failure on line 201 in packages/voice/__tests__/__dataSets__/update.ts

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Expected indentation of 18 spaces but found 17
type: 'sip',

Check failure on line 202 in packages/voice/__tests__/__dataSets__/update.ts

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Expected indentation of 20 spaces but found 19
uri: 'xxx',

Check failure on line 203 in packages/voice/__tests__/__dataSets__/update.ts

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Expected indentation of 20 spaces but found 19
standardHeaders: {

Check failure on line 204 in packages/voice/__tests__/__dataSets__/update.ts

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Expected indentation of 20 spaces but found 19
'User-to-User': 'yyy'
}
},
]
},
],
},
},
],
],
responses: [[204]],
clientMethod: 'transferCallWithNCCO',
parameters: [
callPhone.uuid,
[
{
action: NCCOActions.CONNECT,
endpoint: [
{
type: 'sip',
uri: 'xxx',
standardHeaders: {
'userToUser': 'yyy'
}
},
],
},
],
],
generator: false,
error: false,
expected: undefined,
},
{
label: 'transfer call with NCCO with User-To-User',
requests: [
[
`/v1/calls/${callPhone.uuid}`,
'PUT',
{
action: 'transfer',
destination: {
type: 'ncco',
ncco: [
{

Check failure on line 249 in packages/voice/__tests__/__dataSets__/update.ts

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Expected indentation of 14 spaces but found 13
action: NCCOActions.CONNECT,

Check failure on line 250 in packages/voice/__tests__/__dataSets__/update.ts

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Expected indentation of 16 spaces but found 15
endpoint: [

Check failure on line 251 in packages/voice/__tests__/__dataSets__/update.ts

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Expected indentation of 16 spaces but found 15
{
type: 'sip',
uri: 'xxx',
standardHeaders: {
'User-to-User': 'yyy'
}
},
]
},
],
},
},
],
],
responses: [[204]],
clientMethod: 'transferCallWithNCCO',
parameters: [
callPhone.uuid,
[
{
action: NCCOActions.CONNECT,
endpoint: [
{
type: 'sip',
uri: 'xxx',
standardHeaders: {
'User-to-User': 'yyy'
}
},
],
},
],
],
generator: false,
error: false,
expected: undefined,
},
{
label: 'transfer call with NCCO',
requests: [
Expand Down
7 changes: 6 additions & 1 deletion packages/voice/lib/types/Endpoint/SIPEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ export type SIPEndpoint = {
*
* @link https://tools.ietf.org/html/rfc7433
*/
userToUser: string;
userToUser?: string;

/**
* Allows using the pure header that is expected in the API call.
*/
'User-to-User'?: string;
}
};

42 changes: 38 additions & 4 deletions packages/voice/lib/voice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import {
TalkAction,
OutboundCall,
CallWithNCCO,
SIPEndpoint,
} from './types';

import { ResponseTypes } from '@vonage/vetch';
import { NCCOActions } from './enums';

const apiCallsToCalls = (call: CallDetailResponse): CallDetail => {
delete call._links;
Expand All @@ -30,6 +32,34 @@ const apiCallsToCalls = (call: CallDetailResponse): CallDetail => {
} as CallDetail;
};

const NCCOToApiCalls = (ncco: Action[]): Array<Action> => ncco.map((action) => {
switch (action.action) {
case NCCOActions.CONNECT:
return {
...action,
endpoint: action.endpoint.map((endpoint) => {
switch (endpoint.type) {
case 'sip':
return {
type: 'sip',
uri: endpoint.uri,
headers: endpoint.headers,
standardHeaders: {
'User-to-User': Object.hasOwn(endpoint.standardHeaders || {} ,'User-to-User')
? {...endpoint.standardHeaders}['User-to-User']
: endpoint.standardHeaders?.userToUser,
}
} as SIPEndpoint;
default:
return endpoint;
}
})
};
default:
return action;
}
});

type NCCODestination = {
type: 'ncco';
url?: Array<string>;
Expand Down Expand Up @@ -443,10 +473,14 @@ export class Voice extends Client {
* ```
*/
async transferCallWithNCCO(uuid: string, ncco: Action[]): Promise<void> {
return this.callAction(uuid, 'transfer', {
type: 'ncco',
ncco: ncco,
});
return this.callAction(
uuid,
'transfer',
{
type: 'ncco',
ncco: NCCOToApiCalls(ncco),
},
);
}

/**
Expand Down

0 comments on commit 9a19df2

Please sign in to comment.