diff --git a/CHANGELOG.md b/CHANGELOG.md index 94c96e7..0522652 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## v2 +### v2.0.0-beta.2 + +- Add missing `Texml` resource methods + ### v2.0.0-beta.1 - Fix `Queues` resource nested methods diff --git a/VERSION b/VERSION index 6060c31..e2d1981 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.0-beta.1 +2.0.0-beta.2 diff --git a/package-lock.json b/package-lock.json index 95e5336..7b1cf5f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "telnyx", - "version": "2.0.0-beta.1", + "version": "2.0.0-beta.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "telnyx", - "version": "2.0.0-beta.1", + "version": "2.0.0-beta.2", "license": "MIT", "devDependencies": { "@eslint/js": "^9.10.0", diff --git a/package.json b/package.json index 15f5088..393d156 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "telnyx", - "version": "2.0.0-beta.1", + "version": "2.0.0-beta.2", "description": "Telnyx API Node SDK", "keywords": [ "telnyx", diff --git a/src/resources/CallControlApplications.ts b/src/resources/CallControlApplications.ts index abfe4d5..f4cb8d9 100644 --- a/src/resources/CallControlApplications.ts +++ b/src/resources/CallControlApplications.ts @@ -34,7 +34,7 @@ function transformResponseData( export const CallControlApplications = TelnyxResource.extend({ path: 'call_control_applications', - includeBasic: ['list', 'update'], + includeBasic: ['list', 'update', 'del'], create: telnyxMethod({ method: 'POST', diff --git a/src/resources/Texml.ts b/src/resources/Texml.ts new file mode 100644 index 0000000..5f846f7 --- /dev/null +++ b/src/resources/Texml.ts @@ -0,0 +1,28 @@ +import TelnyxResource from '../TelnyxResource'; + +const telnyxMethod = TelnyxResource.method; + +export const Texml = TelnyxResource.extend({ + path: 'texml', + + createSecret: telnyxMethod({ + method: 'POST', + path: '/secrets', + methodType: 'create', + }), + + createCall: telnyxMethod({ + method: 'POST', + path: '/calls/{application_id}', + urlParams: ['application_id'], + paramsNames: ['application_id'], + methodType: 'create', + }), + + updateCall: telnyxMethod({ + method: 'POST', + path: '/calls/{call_sid}/update', + urlParams: ['call_sid'], + paramsNames: ['call_sid'], + }), +}); diff --git a/src/resources/TexmlApplications.ts b/src/resources/TexmlApplications.ts index 47f1d96..892020c 100644 --- a/src/resources/TexmlApplications.ts +++ b/src/resources/TexmlApplications.ts @@ -1,6 +1,52 @@ import TelnyxResource from '../TelnyxResource'; +import {ResponsePayload, TelnyxObject} from '../Types'; +import * as utils from '../utils'; + +const telnyxMethod = TelnyxResource.method; + +function transformResponseData( + response: ResponsePayload, + telnyx: TelnyxObject, +) { + return utils.addResourceToResponseData( + response, + telnyx, + 'texmlApplications', + { + del: telnyxMethod({ + method: 'DELETE', + path: '/{texmlApplicationId}', + urlParams: ['texmlApplicationId'], + paramsValues: [response.data.id as string], + paramsNames: ['texmlApplicationId'], + }), + + update: telnyxMethod({ + method: 'PATCH', + path: '/{texmlApplicationId}', + urlParams: ['texmlApplicationId'], + paramsValues: [response.data.id as string], + paramsNames: ['texmlApplicationId'], + }), + }, + ); +} export const TexmlApplications = TelnyxResource.extend({ path: 'texml_applications', - includeBasic: ['list', 'create', 'retrieve', 'del', 'update'], + includeBasic: ['list', 'update', 'del'], + + create: telnyxMethod({ + method: 'POST', + + transformResponseData: transformResponseData, + }), + + retrieve: telnyxMethod({ + method: 'GET', + path: '/{id}', + urlParams: ['id'], + + transformResponseData: transformResponseData, + }), }); diff --git a/src/telnyx.ts b/src/telnyx.ts index 92ad56f..4993593 100644 --- a/src/telnyx.ts +++ b/src/telnyx.ts @@ -131,6 +131,7 @@ import {SimCardOrders} from './resources/SimCardOrders'; import {SimCards} from './resources/SimCards'; import {StorageBuckets} from './resources/StorageBuckets'; import {TelephonyCredentials} from './resources/TelephonyCredentials'; +import {Texml} from './resources/Texml'; import {TexmlApplications} from './resources/TexmlApplications'; import {Verifications} from './resources/Verifications'; import {VerifiedNumbers} from './resources/VerifiedNumbers'; @@ -301,6 +302,7 @@ export function createTelnyx() { SimCards, StorageBuckets, TelephonyCredentials, + Texml, TexmlApplications, Verifications, VerifiedNumbers, diff --git a/src/test/resources/TexmlApplications.test.ts b/src/test/resources/TexmlApplications.test.ts index db1c5bf..dbe4a28 100644 --- a/src/test/resources/TexmlApplications.test.ts +++ b/src/test/resources/TexmlApplications.test.ts @@ -1,14 +1,21 @@ +import {TelnyxObject} from '../../Types'; import { type ResponsePayloadList, type ResponsePayload, utils as testUtils, } from '../utils'; -const telnyx = testUtils.getTelnyxMock(); const TEST_AUTH_KEY = testUtils.getUserTelnyxKey(); const TEST_UUID = '123e4567-e89b-12d3-a456-426614174000'; describe('TeXML Apps', function () { + let telnyxInstance: TelnyxObject; + + beforeEach(() => { + // make specs independent + telnyxInstance = testUtils.getTelnyxMock(); + }); + describe('list', function () { function responseFn(response: ResponsePayloadList) { expect(response).toHaveProperty('data'); @@ -23,7 +30,7 @@ describe('TeXML Apps', function () { test('Sends the correct request', function () { // @ts-expect-error TODO: import .d.ts files under src/test folder - return telnyx.texmlApplications + return telnyxInstance.texmlApplications .list({ page: { number: 1, @@ -41,7 +48,7 @@ describe('TeXML Apps', function () { test('Sends the correct request [with specified auth]', function () { // @ts-expect-error TODO: import .d.ts files under src/test folder - return telnyx.texmlApplications + return telnyxInstance.texmlApplications .list( { page: { @@ -69,7 +76,7 @@ describe('TeXML Apps', function () { test('Sends the correct request', function () { // @ts-expect-error TODO: import .d.ts files under src/test folder - return telnyx.texmlApplications + return telnyxInstance.texmlApplications .create({ active: false, anchorsite_override: 'Amsterdam, Netherlands', @@ -97,7 +104,7 @@ describe('TeXML Apps', function () { test('Sends the correct request [with specified auth]', function () { // @ts-expect-error TODO: import .d.ts files under src/test folder - return telnyx.texmlApplications + return telnyxInstance.texmlApplications .create( { active: false, @@ -127,40 +134,44 @@ describe('TeXML Apps', function () { }); }); - describe('del', function () { + describe('retrieve', function () { function responseFn(response: ResponsePayload) { expect(response).toHaveProperty('data'); } test('Sends the correct request', function () { // @ts-expect-error TODO: import .d.ts files under src/test folder - return telnyx.texmlApplications.del(TEST_UUID).then(responseFn); + return telnyxInstance.texmlApplications + .retrieve(TEST_UUID) + .then(responseFn); }); test('Sends the correct request [with specified auth]', function () { // @ts-expect-error TODO: import .d.ts files under src/test folder - return telnyx.texmlApplications - .del(TEST_UUID, TEST_AUTH_KEY) + return telnyxInstance.texmlApplications + .retrieve(TEST_UUID, TEST_AUTH_KEY) .then(responseFn); }); }); - describe('retrieve', function () { + + describe('del', function () { function responseFn(response: ResponsePayload) { expect(response).toHaveProperty('data'); } test('Sends the correct request', function () { // @ts-expect-error TODO: import .d.ts files under src/test folder - return telnyx.texmlApplications.retrieve(TEST_UUID).then(responseFn); + return telnyxInstance.texmlApplications.del(TEST_UUID).then(responseFn); }); test('Sends the correct request [with specified auth]', function () { // @ts-expect-error TODO: import .d.ts files under src/test folder - return telnyx.texmlApplications - .retrieve(TEST_UUID, TEST_AUTH_KEY) + return telnyxInstance.texmlApplications + .del(TEST_UUID, TEST_AUTH_KEY) .then(responseFn); }); }); + describe('update', function () { function responseFn(response: ResponsePayload) { expect(response).toHaveProperty('data'); @@ -190,7 +201,7 @@ describe('TeXML Apps', function () { voice_url: 'https://example.com', }; // @ts-expect-error TODO: import .d.ts files under src/test folder - return telnyx.texmlApplications + return telnyxInstance.texmlApplications .update(TEST_UUID, requestBody) .then(responseFn); }); @@ -219,7 +230,7 @@ describe('TeXML Apps', function () { voice_url: 'https://example.com', }; // @ts-expect-error TODO: import .d.ts files under src/test folder - return telnyx.texmlApplications + return telnyxInstance.texmlApplications .update(TEST_UUID, requestBody, TEST_AUTH_KEY) .then(responseFn); }); diff --git a/types/TexmlApplicationsResource.d.ts b/types/TexmlApplicationsResource.d.ts index 44cc4e6..f5fccda 100644 --- a/types/TexmlApplicationsResource.d.ts +++ b/types/TexmlApplicationsResource.d.ts @@ -41,6 +41,17 @@ declare module 'telnyx' { type TexmlApplicationsUpdateResponse = paths['/texml_applications/{id}']['patch']['responses']['200']['content']['application/json']; + type TexmlApplicationsNestedMethods = { + del( + options?: RequestOptions, + ): Promise>; + + update( + params: TexmlApplicationsUpdateParams, + options?: RequestOptions, + ): Promise>; + }; + class TexmlApplicationsResource { del( id: TexmlApplicationsDelId, @@ -50,12 +61,29 @@ declare module 'telnyx' { create( params: TexmlApplicationsCreateParams, options?: RequestOptions, - ): Promise>; + ): Promise< + Telnyx.Response< + Telnyx.TexmlApplicationsCreateResponse & + NestedResponseData< + TexmlApplicationsCreateResponse['data'], + TexmlApplicationsNestedMethods + > + > + >; retrieve( id: TexmlApplicationsRetrieveId, options?: RequestOptions, - ): Promise>; + ): Promise< + Telnyx.Response< + Telnyx.TexmlApplicationsRetrieveResponse & + NestedResponseData< + TexmlApplicationsRetrieveResponse['data'], + TexmlApplicationsNestedMethods + > + > + >; + // ): Promise>; list( params?: TexmlApplicationsListParams, diff --git a/types/TexmlResource.d.ts b/types/TexmlResource.d.ts new file mode 100644 index 0000000..f026c08 --- /dev/null +++ b/types/TexmlResource.d.ts @@ -0,0 +1,48 @@ +import {paths} from './TelnyxAPI.js'; + +declare module 'telnyx' { + namespace Telnyx { + type TexmlCreateSecretParams = + paths['/texml/secrets']['post']['requestBody']['content']['application/json']; + + type TexmlCreateSecretResponse = + paths['/texml/secrets']['post']['responses']['201']['content']['application/json']; + + type TexmlCreateCallApplicationId = + paths['/texml/calls/{application_id}']['post']['parameters']['path']['application_id']; + + type TexmlCreateCallParams = + paths['/texml/calls/{application_id}']['post']['requestBody']['content']['application/json']; + + type TexmlCreateCallResponse = + paths['/texml/calls/{application_id}']['post']['responses']['200']['content']['application/json']; + + type TexmlUpdateCallCallSid = + paths['/texml/calls/{call_sid}/update']['post']['parameters']['path']['call_sid']; + + type TexmlUpdateCallParams = + paths['/texml/calls/{call_sid}/update']['post']['requestBody']['content']['application/json']; + + type TexmlUpdateCallResponse = + paths['/texml/calls/{call_sid}/update']['post']['responses']['200']['content']['application/json']; + + class TexmlResource { + createSecret( + params: TexmlCreateSecretParams, + options?: RequestOptions, + ): Promise>; + + createCall( + applicationId: TexmlCreateCallApplicationId, + params: TexmlCreateCallParams, + options?: RequestOptions, + ): Promise>; + + updateCall( + callSid: TexmlUpdateCallCallSid, + params: TexmlUpdateCallParams, + options?: RequestOptions, + ): Promise>; + } + } +} diff --git a/types/index.d.ts b/types/index.d.ts index f358ad8..9abbb80 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -59,6 +59,7 @@ /// /// /// +/// /// /// /// @@ -131,6 +132,7 @@ declare module 'telnyx' { portingEvents: Telnyx.PortingEventsResource; portoutEvents: Telnyx.PortoutEventsResource; telephonyCredentials: Telnyx.TelephonyCredentialsResource; + texml: Telnyx.TexmlResource; texmlApplications: Telnyx.TexmlApplicationsResource; storageBuckets: Telnyx.StorageBucketsResource; verifications: Telnyx.VerificationsResource;